0072-soc-starfive-Extract-JH7110-pmu-private-operations.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. From 52e2ade50f3ec212468e284b1236aaa521ba5913 Mon Sep 17 00:00:00 2001
  2. From: Changhuang Liang <[email protected]>
  3. Date: Thu, 18 May 2023 23:02:01 -0700
  4. Subject: [PATCH 072/122] soc: starfive: Extract JH7110 pmu private operations
  5. Move JH7110 private operation into private data of compatible. Convenient
  6. to add AON PMU which would not have interrupts property.
  7. Signed-off-by: Changhuang Liang <[email protected]>
  8. Reviewed-by: Walker Chen <[email protected]>
  9. ---
  10. drivers/soc/starfive/jh71xx_pmu.c | 89 +++++++++++++++++++++----------
  11. 1 file changed, 62 insertions(+), 27 deletions(-)
  12. --- a/drivers/soc/starfive/jh71xx_pmu.c
  13. +++ b/drivers/soc/starfive/jh71xx_pmu.c
  14. @@ -51,9 +51,17 @@ struct jh71xx_domain_info {
  15. u8 bit;
  16. };
  17. +struct jh71xx_pmu;
  18. +struct jh71xx_pmu_dev;
  19. +
  20. struct jh71xx_pmu_match_data {
  21. const struct jh71xx_domain_info *domain_info;
  22. int num_domains;
  23. + unsigned int pmu_status;
  24. + int (*pmu_parse_irq)(struct platform_device *pdev,
  25. + struct jh71xx_pmu *pmu);
  26. + int (*pmu_set_state)(struct jh71xx_pmu_dev *pmd,
  27. + u32 mask, bool on);
  28. };
  29. struct jh71xx_pmu {
  30. @@ -79,12 +87,12 @@ static int jh71xx_pmu_get_state(struct j
  31. if (!mask)
  32. return -EINVAL;
  33. - *is_on = readl(pmu->base + JH71XX_PMU_CURR_POWER_MODE) & mask;
  34. + *is_on = readl(pmu->base + pmu->match_data->pmu_status) & mask;
  35. return 0;
  36. }
  37. -static int jh71xx_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on)
  38. +static int jh7110_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on)
  39. {
  40. struct jh71xx_pmu *pmu = pmd->pmu;
  41. unsigned long flags;
  42. @@ -92,22 +100,8 @@ static int jh71xx_pmu_set_state(struct j
  43. u32 mode;
  44. u32 encourage_lo;
  45. u32 encourage_hi;
  46. - bool is_on;
  47. int ret;
  48. - ret = jh71xx_pmu_get_state(pmd, mask, &is_on);
  49. - if (ret) {
  50. - dev_dbg(pmu->dev, "unable to get current state for %s\n",
  51. - pmd->genpd.name);
  52. - return ret;
  53. - }
  54. -
  55. - if (is_on == on) {
  56. - dev_dbg(pmu->dev, "pm domain [%s] is already %sable status.\n",
  57. - pmd->genpd.name, on ? "en" : "dis");
  58. - return 0;
  59. - }
  60. -
  61. spin_lock_irqsave(&pmu->lock, flags);
  62. /*
  63. @@ -166,6 +160,29 @@ static int jh71xx_pmu_set_state(struct j
  64. return 0;
  65. }
  66. +static int jh71xx_pmu_set_state(struct jh71xx_pmu_dev *pmd, u32 mask, bool on)
  67. +{
  68. + struct jh71xx_pmu *pmu = pmd->pmu;
  69. + const struct jh71xx_pmu_match_data *match_data = pmu->match_data;
  70. + bool is_on;
  71. + int ret;
  72. +
  73. + ret = jh71xx_pmu_get_state(pmd, mask, &is_on);
  74. + if (ret) {
  75. + dev_dbg(pmu->dev, "unable to get current state for %s\n",
  76. + pmd->genpd.name);
  77. + return ret;
  78. + }
  79. +
  80. + if (is_on == on) {
  81. + dev_dbg(pmu->dev, "pm domain [%s] is already %sable status.\n",
  82. + pmd->genpd.name, on ? "en" : "dis");
  83. + return 0;
  84. + }
  85. +
  86. + return match_data->pmu_set_state(pmd, mask, on);
  87. +}
  88. +
  89. static int jh71xx_pmu_on(struct generic_pm_domain *genpd)
  90. {
  91. struct jh71xx_pmu_dev *pmd = container_of(genpd,
  92. @@ -226,6 +243,25 @@ static irqreturn_t jh71xx_pmu_interrupt(
  93. return IRQ_HANDLED;
  94. }
  95. +static int jh7110_pmu_parse_irq(struct platform_device *pdev, struct jh71xx_pmu *pmu)
  96. +{
  97. + struct device *dev = &pdev->dev;
  98. + int ret;
  99. +
  100. + pmu->irq = platform_get_irq(pdev, 0);
  101. + if (pmu->irq < 0)
  102. + return pmu->irq;
  103. +
  104. + ret = devm_request_irq(dev, pmu->irq, jh71xx_pmu_interrupt,
  105. + 0, pdev->name, pmu);
  106. + if (ret)
  107. + dev_err(dev, "failed to request irq\n");
  108. +
  109. + jh71xx_pmu_int_enable(pmu, JH71XX_PMU_INT_ALL_MASK & ~JH71XX_PMU_INT_PCH_FAIL, true);
  110. +
  111. + return 0;
  112. +}
  113. +
  114. static int jh71xx_pmu_init_domain(struct jh71xx_pmu *pmu, int index)
  115. {
  116. struct jh71xx_pmu_dev *pmd;
  117. @@ -275,19 +311,18 @@ static int jh71xx_pmu_probe(struct platf
  118. if (IS_ERR(pmu->base))
  119. return PTR_ERR(pmu->base);
  120. - pmu->irq = platform_get_irq(pdev, 0);
  121. - if (pmu->irq < 0)
  122. - return pmu->irq;
  123. -
  124. - ret = devm_request_irq(dev, pmu->irq, jh71xx_pmu_interrupt,
  125. - 0, pdev->name, pmu);
  126. - if (ret)
  127. - dev_err(dev, "failed to request irq\n");
  128. + spin_lock_init(&pmu->lock);
  129. match_data = of_device_get_match_data(dev);
  130. if (!match_data)
  131. return -EINVAL;
  132. + ret = match_data->pmu_parse_irq(pdev, pmu);
  133. + if (ret) {
  134. + dev_err(dev, "failed to parse irq\n");
  135. + return ret;
  136. + }
  137. +
  138. pmu->genpd = devm_kcalloc(dev, match_data->num_domains,
  139. sizeof(struct generic_pm_domain *),
  140. GFP_KERNEL);
  141. @@ -307,9 +342,6 @@ static int jh71xx_pmu_probe(struct platf
  142. }
  143. }
  144. - spin_lock_init(&pmu->lock);
  145. - jh71xx_pmu_int_enable(pmu, JH71XX_PMU_INT_ALL_MASK & ~JH71XX_PMU_INT_PCH_FAIL, true);
  146. -
  147. ret = of_genpd_add_provider_onecell(np, &pmu->genpd_data);
  148. if (ret) {
  149. dev_err(dev, "failed to register genpd driver: %d\n", ret);
  150. @@ -357,6 +389,9 @@ static const struct jh71xx_domain_info j
  151. static const struct jh71xx_pmu_match_data jh7110_pmu = {
  152. .num_domains = ARRAY_SIZE(jh7110_power_domains),
  153. .domain_info = jh7110_power_domains,
  154. + .pmu_status = JH71XX_PMU_CURR_POWER_MODE,
  155. + .pmu_parse_irq = jh7110_pmu_parse_irq,
  156. + .pmu_set_state = jh7110_pmu_set_state,
  157. };
  158. static const struct of_device_id jh71xx_pmu_of_match[] = {