pm-rmobile.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * rmobile power management support
  3. *
  4. * Copyright (C) 2012 Renesas Solutions Corp.
  5. * Copyright (C) 2012 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
  6. *
  7. * based on pm-sh7372.c
  8. * Copyright (C) 2011 Magnus Damm
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/console.h>
  15. #include <linux/delay.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/pm.h>
  18. #include <linux/pm_clock.h>
  19. #include <asm/io.h>
  20. #include "pm-rmobile.h"
  21. /* SYSC */
  22. #define SPDCR IOMEM(0xe6180008)
  23. #define SWUCR IOMEM(0xe6180014)
  24. #define PSTR IOMEM(0xe6180080)
  25. #define PSTR_RETRIES 100
  26. #define PSTR_DELAY_US 10
  27. #ifdef CONFIG_PM
  28. static int rmobile_pd_power_down(struct generic_pm_domain *genpd)
  29. {
  30. struct rmobile_pm_domain *rmobile_pd = to_rmobile_pd(genpd);
  31. unsigned int mask = 1 << rmobile_pd->bit_shift;
  32. if (rmobile_pd->suspend) {
  33. int ret = rmobile_pd->suspend();
  34. if (ret)
  35. return ret;
  36. }
  37. if (__raw_readl(PSTR) & mask) {
  38. unsigned int retry_count;
  39. __raw_writel(mask, SPDCR);
  40. for (retry_count = PSTR_RETRIES; retry_count; retry_count--) {
  41. if (!(__raw_readl(SPDCR) & mask))
  42. break;
  43. cpu_relax();
  44. }
  45. }
  46. if (!rmobile_pd->no_debug)
  47. pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n",
  48. genpd->name, mask, __raw_readl(PSTR));
  49. return 0;
  50. }
  51. static int __rmobile_pd_power_up(struct rmobile_pm_domain *rmobile_pd,
  52. bool do_resume)
  53. {
  54. unsigned int mask = 1 << rmobile_pd->bit_shift;
  55. unsigned int retry_count;
  56. int ret = 0;
  57. if (__raw_readl(PSTR) & mask)
  58. goto out;
  59. __raw_writel(mask, SWUCR);
  60. for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) {
  61. if (!(__raw_readl(SWUCR) & mask))
  62. break;
  63. if (retry_count > PSTR_RETRIES)
  64. udelay(PSTR_DELAY_US);
  65. else
  66. cpu_relax();
  67. }
  68. if (!retry_count)
  69. ret = -EIO;
  70. if (!rmobile_pd->no_debug)
  71. pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n",
  72. rmobile_pd->genpd.name, mask, __raw_readl(PSTR));
  73. out:
  74. if (ret == 0 && rmobile_pd->resume && do_resume)
  75. rmobile_pd->resume();
  76. return ret;
  77. }
  78. static int rmobile_pd_power_up(struct generic_pm_domain *genpd)
  79. {
  80. return __rmobile_pd_power_up(to_rmobile_pd(genpd), true);
  81. }
  82. static bool rmobile_pd_active_wakeup(struct device *dev)
  83. {
  84. return true;
  85. }
  86. static void rmobile_init_pm_domain(struct rmobile_pm_domain *rmobile_pd)
  87. {
  88. struct generic_pm_domain *genpd = &rmobile_pd->genpd;
  89. struct dev_power_governor *gov = rmobile_pd->gov;
  90. pm_genpd_init(genpd, gov ? : &simple_qos_governor, false);
  91. genpd->dev_ops.stop = pm_clk_suspend;
  92. genpd->dev_ops.start = pm_clk_resume;
  93. genpd->dev_ops.active_wakeup = rmobile_pd_active_wakeup;
  94. genpd->dev_irq_safe = true;
  95. genpd->power_off = rmobile_pd_power_down;
  96. genpd->power_on = rmobile_pd_power_up;
  97. __rmobile_pd_power_up(rmobile_pd, false);
  98. }
  99. void rmobile_init_domains(struct rmobile_pm_domain domains[], int num)
  100. {
  101. int j;
  102. for (j = 0; j < num; j++)
  103. rmobile_init_pm_domain(&domains[j]);
  104. }
  105. void rmobile_add_device_to_domain_td(const char *domain_name,
  106. struct platform_device *pdev,
  107. struct gpd_timing_data *td)
  108. {
  109. struct device *dev = &pdev->dev;
  110. __pm_genpd_name_add_device(domain_name, dev, td);
  111. if (pm_clk_no_clocks(dev))
  112. pm_clk_add(dev, NULL);
  113. }
  114. void rmobile_add_devices_to_domains(struct pm_domain_device data[],
  115. int size)
  116. {
  117. struct gpd_timing_data latencies = {
  118. .stop_latency_ns = DEFAULT_DEV_LATENCY_NS,
  119. .start_latency_ns = DEFAULT_DEV_LATENCY_NS,
  120. .save_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
  121. .restore_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
  122. };
  123. int j;
  124. for (j = 0; j < size; j++)
  125. rmobile_add_device_to_domain_td(data[j].domain_name,
  126. data[j].pdev, &latencies);
  127. }
  128. #endif /* CONFIG_PM */