pm-rmobile.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. static int rmobile_pd_power_down(struct generic_pm_domain *genpd)
  28. {
  29. struct rmobile_pm_domain *rmobile_pd = to_rmobile_pd(genpd);
  30. unsigned int mask = 1 << rmobile_pd->bit_shift;
  31. if (rmobile_pd->suspend) {
  32. int ret = rmobile_pd->suspend();
  33. if (ret)
  34. return ret;
  35. }
  36. if (__raw_readl(PSTR) & mask) {
  37. unsigned int retry_count;
  38. __raw_writel(mask, SPDCR);
  39. for (retry_count = PSTR_RETRIES; retry_count; retry_count--) {
  40. if (!(__raw_readl(SPDCR) & mask))
  41. break;
  42. cpu_relax();
  43. }
  44. }
  45. if (!rmobile_pd->no_debug)
  46. pr_debug("%s: Power off, 0x%08x -> PSTR = 0x%08x\n",
  47. genpd->name, mask, __raw_readl(PSTR));
  48. return 0;
  49. }
  50. static int __rmobile_pd_power_up(struct rmobile_pm_domain *rmobile_pd,
  51. bool do_resume)
  52. {
  53. unsigned int mask = 1 << rmobile_pd->bit_shift;
  54. unsigned int retry_count;
  55. int ret = 0;
  56. if (__raw_readl(PSTR) & mask)
  57. goto out;
  58. __raw_writel(mask, SWUCR);
  59. for (retry_count = 2 * PSTR_RETRIES; retry_count; retry_count--) {
  60. if (!(__raw_readl(SWUCR) & mask))
  61. break;
  62. if (retry_count > PSTR_RETRIES)
  63. udelay(PSTR_DELAY_US);
  64. else
  65. cpu_relax();
  66. }
  67. if (!retry_count)
  68. ret = -EIO;
  69. if (!rmobile_pd->no_debug)
  70. pr_debug("%s: Power on, 0x%08x -> PSTR = 0x%08x\n",
  71. rmobile_pd->genpd.name, mask, __raw_readl(PSTR));
  72. out:
  73. if (ret == 0 && rmobile_pd->resume && do_resume)
  74. rmobile_pd->resume();
  75. return ret;
  76. }
  77. static int rmobile_pd_power_up(struct generic_pm_domain *genpd)
  78. {
  79. return __rmobile_pd_power_up(to_rmobile_pd(genpd), true);
  80. }
  81. static bool rmobile_pd_active_wakeup(struct device *dev)
  82. {
  83. return true;
  84. }
  85. static void rmobile_init_pm_domain(struct rmobile_pm_domain *rmobile_pd)
  86. {
  87. struct generic_pm_domain *genpd = &rmobile_pd->genpd;
  88. struct dev_power_governor *gov = rmobile_pd->gov;
  89. pm_genpd_init(genpd, gov ? : &simple_qos_governor, false);
  90. genpd->dev_ops.stop = pm_clk_suspend;
  91. genpd->dev_ops.start = pm_clk_resume;
  92. genpd->dev_ops.active_wakeup = rmobile_pd_active_wakeup;
  93. genpd->power_off = rmobile_pd_power_down;
  94. genpd->power_on = rmobile_pd_power_up;
  95. __rmobile_pd_power_up(rmobile_pd, false);
  96. }
  97. void rmobile_init_domains(struct rmobile_pm_domain domains[], int num)
  98. {
  99. int j;
  100. for (j = 0; j < num; j++)
  101. rmobile_init_pm_domain(&domains[j]);
  102. }
  103. void rmobile_add_device_to_domain_td(const char *domain_name,
  104. struct platform_device *pdev,
  105. struct gpd_timing_data *td)
  106. {
  107. struct device *dev = &pdev->dev;
  108. __pm_genpd_name_add_device(domain_name, dev, td);
  109. if (pm_clk_no_clocks(dev))
  110. pm_clk_add(dev, NULL);
  111. }
  112. void rmobile_add_devices_to_domains(struct pm_domain_device data[],
  113. int size)
  114. {
  115. struct gpd_timing_data latencies = {
  116. .stop_latency_ns = DEFAULT_DEV_LATENCY_NS,
  117. .start_latency_ns = DEFAULT_DEV_LATENCY_NS,
  118. .save_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
  119. .restore_state_latency_ns = DEFAULT_DEV_LATENCY_NS,
  120. };
  121. int j;
  122. for (j = 0; j < size; j++)
  123. rmobile_add_device_to_domain_td(data[j].domain_name,
  124. data[j].pdev, &latencies);
  125. }