flowctrl.c 5.2 KB

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