pm_domains.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * Exynos Generic power domain support.
  3. *
  4. * Copyright (c) 2012 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  6. *
  7. * Implementation of Exynos specific power domain control which is used in
  8. * conjunction with runtime-pm. Support for both device-tree and non-device-tree
  9. * based power domain support is included.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/io.h>
  16. #include <linux/err.h>
  17. #include <linux/slab.h>
  18. #include <linux/pm_domain.h>
  19. #include <linux/delay.h>
  20. #include <linux/of_address.h>
  21. #include <mach/regs-pmu.h>
  22. #include <plat/devs.h>
  23. /*
  24. * Exynos specific wrapper around the generic power domain
  25. */
  26. struct exynos_pm_domain {
  27. void __iomem *base;
  28. char const *name;
  29. bool is_off;
  30. struct generic_pm_domain pd;
  31. };
  32. static int exynos_pd_power(struct generic_pm_domain *domain, bool power_on)
  33. {
  34. struct exynos_pm_domain *pd;
  35. void __iomem *base;
  36. u32 timeout, pwr;
  37. char *op;
  38. pd = container_of(domain, struct exynos_pm_domain, pd);
  39. base = pd->base;
  40. pwr = power_on ? S5P_INT_LOCAL_PWR_EN : 0;
  41. __raw_writel(pwr, base);
  42. /* Wait max 1ms */
  43. timeout = 10;
  44. while ((__raw_readl(base + 0x4) & S5P_INT_LOCAL_PWR_EN) != pwr) {
  45. if (!timeout) {
  46. op = (power_on) ? "enable" : "disable";
  47. pr_err("Power domain %s %s failed\n", domain->name, op);
  48. return -ETIMEDOUT;
  49. }
  50. timeout--;
  51. cpu_relax();
  52. usleep_range(80, 100);
  53. }
  54. return 0;
  55. }
  56. static int exynos_pd_power_on(struct generic_pm_domain *domain)
  57. {
  58. return exynos_pd_power(domain, true);
  59. }
  60. static int exynos_pd_power_off(struct generic_pm_domain *domain)
  61. {
  62. return exynos_pd_power(domain, false);
  63. }
  64. #define EXYNOS_GPD(PD, BASE, NAME) \
  65. static struct exynos_pm_domain PD = { \
  66. .base = (void __iomem *)BASE, \
  67. .name = NAME, \
  68. .pd = { \
  69. .power_off = exynos_pd_power_off, \
  70. .power_on = exynos_pd_power_on, \
  71. }, \
  72. }
  73. #ifdef CONFIG_OF
  74. static __init int exynos_pm_dt_parse_domains(void)
  75. {
  76. struct device_node *np;
  77. for_each_compatible_node(np, NULL, "samsung,exynos4210-pd") {
  78. struct exynos_pm_domain *pd;
  79. pd = kzalloc(sizeof(*pd), GFP_KERNEL);
  80. if (!pd) {
  81. pr_err("%s: failed to allocate memory for domain\n",
  82. __func__);
  83. return -ENOMEM;
  84. }
  85. if (of_get_property(np, "samsung,exynos4210-pd-off", NULL))
  86. pd->is_off = true;
  87. pd->name = np->name;
  88. pd->base = of_iomap(np, 0);
  89. pd->pd.power_off = exynos_pd_power_off;
  90. pd->pd.power_on = exynos_pd_power_on;
  91. pd->pd.of_node = np;
  92. pm_genpd_init(&pd->pd, NULL, false);
  93. }
  94. return 0;
  95. }
  96. #else
  97. static __init int exynos_pm_dt_parse_domains(void)
  98. {
  99. return 0;
  100. }
  101. #endif /* CONFIG_OF */
  102. static __init void exynos_pm_add_dev_to_genpd(struct platform_device *pdev,
  103. struct exynos_pm_domain *pd)
  104. {
  105. if (pdev->dev.bus) {
  106. if (pm_genpd_add_device(&pd->pd, &pdev->dev))
  107. pr_info("%s: error in adding %s device to %s power"
  108. "domain\n", __func__, dev_name(&pdev->dev),
  109. pd->name);
  110. }
  111. }
  112. EXYNOS_GPD(exynos4_pd_mfc, S5P_PMU_MFC_CONF, "pd-mfc");
  113. EXYNOS_GPD(exynos4_pd_g3d, S5P_PMU_G3D_CONF, "pd-g3d");
  114. EXYNOS_GPD(exynos4_pd_lcd0, S5P_PMU_LCD0_CONF, "pd-lcd0");
  115. EXYNOS_GPD(exynos4_pd_lcd1, S5P_PMU_LCD1_CONF, "pd-lcd1");
  116. EXYNOS_GPD(exynos4_pd_tv, S5P_PMU_TV_CONF, "pd-tv");
  117. EXYNOS_GPD(exynos4_pd_cam, S5P_PMU_CAM_CONF, "pd-cam");
  118. EXYNOS_GPD(exynos4_pd_gps, S5P_PMU_GPS_CONF, "pd-gps");
  119. static struct exynos_pm_domain *exynos4_pm_domains[] = {
  120. &exynos4_pd_mfc,
  121. &exynos4_pd_g3d,
  122. &exynos4_pd_lcd0,
  123. &exynos4_pd_lcd1,
  124. &exynos4_pd_tv,
  125. &exynos4_pd_cam,
  126. &exynos4_pd_gps,
  127. };
  128. static __init int exynos4_pm_init_power_domain(void)
  129. {
  130. int idx;
  131. if (of_have_populated_dt())
  132. return exynos_pm_dt_parse_domains();
  133. for (idx = 0; idx < ARRAY_SIZE(exynos4_pm_domains); idx++)
  134. pm_genpd_init(&exynos4_pm_domains[idx]->pd, NULL,
  135. exynos4_pm_domains[idx]->is_off);
  136. #ifdef CONFIG_S5P_DEV_FIMD0
  137. exynos_pm_add_dev_to_genpd(&s5p_device_fimd0, &exynos4_pd_lcd0);
  138. #endif
  139. #ifdef CONFIG_S5P_DEV_TV
  140. exynos_pm_add_dev_to_genpd(&s5p_device_hdmi, &exynos4_pd_tv);
  141. exynos_pm_add_dev_to_genpd(&s5p_device_mixer, &exynos4_pd_tv);
  142. #endif
  143. #ifdef CONFIG_S5P_DEV_MFC
  144. exynos_pm_add_dev_to_genpd(&s5p_device_mfc, &exynos4_pd_mfc);
  145. #endif
  146. #ifdef CONFIG_S5P_DEV_FIMC0
  147. exynos_pm_add_dev_to_genpd(&s5p_device_fimc0, &exynos4_pd_cam);
  148. #endif
  149. #ifdef CONFIG_S5P_DEV_FIMC1
  150. exynos_pm_add_dev_to_genpd(&s5p_device_fimc1, &exynos4_pd_cam);
  151. #endif
  152. #ifdef CONFIG_S5P_DEV_FIMC2
  153. exynos_pm_add_dev_to_genpd(&s5p_device_fimc2, &exynos4_pd_cam);
  154. #endif
  155. #ifdef CONFIG_S5P_DEV_FIMC3
  156. exynos_pm_add_dev_to_genpd(&s5p_device_fimc3, &exynos4_pd_cam);
  157. #endif
  158. #ifdef CONFIG_S5P_DEV_CSIS0
  159. exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis0, &exynos4_pd_cam);
  160. #endif
  161. #ifdef CONFIG_S5P_DEV_CSIS1
  162. exynos_pm_add_dev_to_genpd(&s5p_device_mipi_csis1, &exynos4_pd_cam);
  163. #endif
  164. #ifdef CONFIG_S5P_DEV_G2D
  165. exynos_pm_add_dev_to_genpd(&s5p_device_g2d, &exynos4_pd_lcd0);
  166. #endif
  167. #ifdef CONFIG_S5P_DEV_JPEG
  168. exynos_pm_add_dev_to_genpd(&s5p_device_jpeg, &exynos4_pd_cam);
  169. #endif
  170. return 0;
  171. }
  172. arch_initcall(exynos4_pm_init_power_domain);
  173. static __init int exynos_pm_late_initcall(void)
  174. {
  175. pm_genpd_poweroff_unused();
  176. return 0;
  177. }
  178. late_initcall(exynos_pm_late_initcall);