pm-rmobile.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 <mach/pm-rmobile.h>
  21. /* SYSC */
  22. #define SPDCR 0xe6180008
  23. #define SWUCR 0xe6180014
  24. #define PSTR 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. bool (*active_wakeup)(struct device *dev);
  85. active_wakeup = dev_gpd_data(dev)->ops.active_wakeup;
  86. return active_wakeup ? active_wakeup(dev) : true;
  87. }
  88. static int rmobile_pd_stop_dev(struct device *dev)
  89. {
  90. int (*stop)(struct device *dev);
  91. stop = dev_gpd_data(dev)->ops.stop;
  92. if (stop) {
  93. int ret = stop(dev);
  94. if (ret)
  95. return ret;
  96. }
  97. return pm_clk_suspend(dev);
  98. }
  99. static int rmobile_pd_start_dev(struct device *dev)
  100. {
  101. int (*start)(struct device *dev);
  102. int ret;
  103. ret = pm_clk_resume(dev);
  104. if (ret)
  105. return ret;
  106. start = dev_gpd_data(dev)->ops.start;
  107. if (start)
  108. ret = start(dev);
  109. return ret;
  110. }
  111. void rmobile_init_pm_domain(struct rmobile_pm_domain *rmobile_pd)
  112. {
  113. struct generic_pm_domain *genpd = &rmobile_pd->genpd;
  114. struct dev_power_governor *gov = rmobile_pd->gov;
  115. pm_genpd_init(genpd, gov ? : &simple_qos_governor, false);
  116. genpd->dev_ops.stop = rmobile_pd_stop_dev;
  117. genpd->dev_ops.start = rmobile_pd_start_dev;
  118. genpd->dev_ops.active_wakeup = rmobile_pd_active_wakeup;
  119. genpd->dev_irq_safe = true;
  120. genpd->power_off = rmobile_pd_power_down;
  121. genpd->power_on = rmobile_pd_power_up;
  122. __rmobile_pd_power_up(rmobile_pd, false);
  123. }
  124. void rmobile_add_device_to_domain(struct rmobile_pm_domain *rmobile_pd,
  125. struct platform_device *pdev)
  126. {
  127. struct device *dev = &pdev->dev;
  128. pm_genpd_add_device(&rmobile_pd->genpd, dev);
  129. if (pm_clk_no_clocks(dev))
  130. pm_clk_add(dev, NULL);
  131. }
  132. void rmobile_pm_add_subdomain(struct rmobile_pm_domain *rmobile_pd,
  133. struct rmobile_pm_domain *rmobile_sd)
  134. {
  135. pm_genpd_add_subdomain(&rmobile_pd->genpd, &rmobile_sd->genpd);
  136. }
  137. #endif /* CONFIG_PM */