flowctrl.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * drivers/soc/tegra/flowctrl.c
  3. *
  4. * Functions and macros to control the flowcontroller
  5. *
  6. * Copyright (c) 2010-2012, NVIDIA Corporation. All rights reserved.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <linux/cpumask.h>
  21. #include <linux/init.h>
  22. #include <linux/io.h>
  23. #include <linux/kernel.h>
  24. #include <linux/of.h>
  25. #include <linux/of_address.h>
  26. #include <linux/platform_device.h>
  27. #include <soc/tegra/common.h>
  28. #include <soc/tegra/flowctrl.h>
  29. #include <soc/tegra/fuse.h>
  30. static u8 flowctrl_offset_halt_cpu[] = {
  31. FLOW_CTRL_HALT_CPU0_EVENTS,
  32. FLOW_CTRL_HALT_CPU1_EVENTS,
  33. FLOW_CTRL_HALT_CPU1_EVENTS + 8,
  34. FLOW_CTRL_HALT_CPU1_EVENTS + 16,
  35. };
  36. static u8 flowctrl_offset_cpu_csr[] = {
  37. FLOW_CTRL_CPU0_CSR,
  38. FLOW_CTRL_CPU1_CSR,
  39. FLOW_CTRL_CPU1_CSR + 8,
  40. FLOW_CTRL_CPU1_CSR + 16,
  41. };
  42. static void __iomem *tegra_flowctrl_base;
  43. static void flowctrl_update(u8 offset, u32 value)
  44. {
  45. if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base),
  46. "Tegra flowctrl not initialised!\n"))
  47. return;
  48. writel(value, tegra_flowctrl_base + offset);
  49. /* ensure the update has reached the flow controller */
  50. wmb();
  51. readl_relaxed(tegra_flowctrl_base + offset);
  52. }
  53. u32 flowctrl_read_cpu_csr(unsigned int cpuid)
  54. {
  55. u8 offset = flowctrl_offset_cpu_csr[cpuid];
  56. if (WARN_ONCE(IS_ERR_OR_NULL(tegra_flowctrl_base),
  57. "Tegra flowctrl not initialised!\n"))
  58. return 0;
  59. return readl(tegra_flowctrl_base + offset);
  60. }
  61. void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value)
  62. {
  63. return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value);
  64. }
  65. void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value)
  66. {
  67. return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value);
  68. }
  69. void flowctrl_cpu_suspend_enter(unsigned int cpuid)
  70. {
  71. unsigned int reg;
  72. int i;
  73. reg = flowctrl_read_cpu_csr(cpuid);
  74. switch (tegra_get_chip_id()) {
  75. case TEGRA20:
  76. /* clear wfe bitmap */
  77. reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
  78. /* clear wfi bitmap */
  79. reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
  80. /* pwr gating on wfe */
  81. reg |= TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 << cpuid;
  82. break;
  83. case TEGRA30:
  84. case TEGRA114:
  85. case TEGRA124:
  86. /* clear wfe bitmap */
  87. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
  88. /* clear wfi bitmap */
  89. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
  90. /* pwr gating on wfi */
  91. reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid;
  92. break;
  93. }
  94. reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */
  95. reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */
  96. reg |= FLOW_CTRL_CSR_ENABLE; /* pwr gating */
  97. flowctrl_write_cpu_csr(cpuid, reg);
  98. for (i = 0; i < num_possible_cpus(); i++) {
  99. if (i == cpuid)
  100. continue;
  101. reg = flowctrl_read_cpu_csr(i);
  102. reg |= FLOW_CTRL_CSR_EVENT_FLAG;
  103. reg |= FLOW_CTRL_CSR_INTR_FLAG;
  104. flowctrl_write_cpu_csr(i, reg);
  105. }
  106. }
  107. void flowctrl_cpu_suspend_exit(unsigned int cpuid)
  108. {
  109. unsigned int reg;
  110. /* Disable powergating via flow controller for CPU0 */
  111. reg = flowctrl_read_cpu_csr(cpuid);
  112. switch (tegra_get_chip_id()) {
  113. case TEGRA20:
  114. /* clear wfe bitmap */
  115. reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
  116. /* clear wfi bitmap */
  117. reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
  118. break;
  119. case TEGRA30:
  120. case TEGRA114:
  121. case TEGRA124:
  122. /* clear wfe bitmap */
  123. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
  124. /* clear wfi bitmap */
  125. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
  126. break;
  127. }
  128. reg &= ~FLOW_CTRL_CSR_ENABLE; /* clear enable */
  129. reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr */
  130. reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event */
  131. flowctrl_write_cpu_csr(cpuid, reg);
  132. }
  133. static int tegra_flowctrl_probe(struct platform_device *pdev)
  134. {
  135. void __iomem *base = tegra_flowctrl_base;
  136. struct resource *res;
  137. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  138. tegra_flowctrl_base = devm_ioremap_resource(&pdev->dev, res);
  139. if (IS_ERR(tegra_flowctrl_base))
  140. return PTR_ERR(tegra_flowctrl_base);
  141. iounmap(base);
  142. return 0;
  143. }
  144. static const struct of_device_id tegra_flowctrl_match[] = {
  145. { .compatible = "nvidia,tegra210-flowctrl" },
  146. { .compatible = "nvidia,tegra124-flowctrl" },
  147. { .compatible = "nvidia,tegra114-flowctrl" },
  148. { .compatible = "nvidia,tegra30-flowctrl" },
  149. { .compatible = "nvidia,tegra20-flowctrl" },
  150. { }
  151. };
  152. static struct platform_driver tegra_flowctrl_driver = {
  153. .driver = {
  154. .name = "tegra-flowctrl",
  155. .suppress_bind_attrs = true,
  156. .of_match_table = tegra_flowctrl_match,
  157. },
  158. .probe = tegra_flowctrl_probe,
  159. };
  160. builtin_platform_driver(tegra_flowctrl_driver);
  161. static int __init tegra_flowctrl_init(void)
  162. {
  163. struct resource res;
  164. struct device_node *np;
  165. if (!soc_is_tegra())
  166. return 0;
  167. np = of_find_matching_node(NULL, tegra_flowctrl_match);
  168. if (np) {
  169. if (of_address_to_resource(np, 0, &res) < 0) {
  170. pr_err("failed to get flowctrl register\n");
  171. return -ENXIO;
  172. }
  173. of_node_put(np);
  174. } else if (IS_ENABLED(CONFIG_ARM)) {
  175. /*
  176. * Hardcoded fallback for 32-bit Tegra
  177. * devices if device tree node is missing.
  178. */
  179. res.start = 0x60007000;
  180. res.end = 0x60007fff;
  181. res.flags = IORESOURCE_MEM;
  182. } else {
  183. /*
  184. * At this point we're running on a Tegra,
  185. * that doesn't support the flow controller
  186. * (eg. Tegra186), so just return.
  187. */
  188. return 0;
  189. }
  190. tegra_flowctrl_base = ioremap_nocache(res.start, resource_size(&res));
  191. if (!tegra_flowctrl_base)
  192. return -ENXIO;
  193. return 0;
  194. }
  195. early_initcall(tegra_flowctrl_init);