flowctrl.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * arch/arm/mach-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 <soc/tegra/fuse.h>
  27. #include "flowctrl.h"
  28. static u8 flowctrl_offset_halt_cpu[] = {
  29. FLOW_CTRL_HALT_CPU0_EVENTS,
  30. FLOW_CTRL_HALT_CPU1_EVENTS,
  31. FLOW_CTRL_HALT_CPU1_EVENTS + 8,
  32. FLOW_CTRL_HALT_CPU1_EVENTS + 16,
  33. };
  34. static u8 flowctrl_offset_cpu_csr[] = {
  35. FLOW_CTRL_CPU0_CSR,
  36. FLOW_CTRL_CPU1_CSR,
  37. FLOW_CTRL_CPU1_CSR + 8,
  38. FLOW_CTRL_CPU1_CSR + 16,
  39. };
  40. static void __iomem *tegra_flowctrl_base;
  41. static void flowctrl_update(u8 offset, u32 value)
  42. {
  43. writel(value, tegra_flowctrl_base + offset);
  44. /* ensure the update has reached the flow controller */
  45. wmb();
  46. readl_relaxed(tegra_flowctrl_base + offset);
  47. }
  48. u32 flowctrl_read_cpu_csr(unsigned int cpuid)
  49. {
  50. u8 offset = flowctrl_offset_cpu_csr[cpuid];
  51. return readl(tegra_flowctrl_base + offset);
  52. }
  53. void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value)
  54. {
  55. return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value);
  56. }
  57. void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value)
  58. {
  59. return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value);
  60. }
  61. void flowctrl_cpu_suspend_enter(unsigned int cpuid)
  62. {
  63. unsigned int reg;
  64. int i;
  65. reg = flowctrl_read_cpu_csr(cpuid);
  66. switch (tegra_get_chip_id()) {
  67. case TEGRA20:
  68. /* clear wfe bitmap */
  69. reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
  70. /* clear wfi bitmap */
  71. reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
  72. /* pwr gating on wfe */
  73. reg |= TEGRA20_FLOW_CTRL_CSR_WFE_CPU0 << cpuid;
  74. break;
  75. case TEGRA30:
  76. case TEGRA114:
  77. case TEGRA124:
  78. /* clear wfe bitmap */
  79. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
  80. /* clear wfi bitmap */
  81. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
  82. /* pwr gating on wfi */
  83. reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid;
  84. break;
  85. }
  86. reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */
  87. reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */
  88. reg |= FLOW_CTRL_CSR_ENABLE; /* pwr gating */
  89. flowctrl_write_cpu_csr(cpuid, reg);
  90. for (i = 0; i < num_possible_cpus(); i++) {
  91. if (i == cpuid)
  92. continue;
  93. reg = flowctrl_read_cpu_csr(i);
  94. reg |= FLOW_CTRL_CSR_EVENT_FLAG;
  95. reg |= FLOW_CTRL_CSR_INTR_FLAG;
  96. flowctrl_write_cpu_csr(i, reg);
  97. }
  98. }
  99. void flowctrl_cpu_suspend_exit(unsigned int cpuid)
  100. {
  101. unsigned int reg;
  102. /* Disable powergating via flow controller for CPU0 */
  103. reg = flowctrl_read_cpu_csr(cpuid);
  104. switch (tegra_get_chip_id()) {
  105. case TEGRA20:
  106. /* clear wfe bitmap */
  107. reg &= ~TEGRA20_FLOW_CTRL_CSR_WFE_BITMAP;
  108. /* clear wfi bitmap */
  109. reg &= ~TEGRA20_FLOW_CTRL_CSR_WFI_BITMAP;
  110. break;
  111. case TEGRA30:
  112. case TEGRA114:
  113. case TEGRA124:
  114. /* clear wfe bitmap */
  115. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP;
  116. /* clear wfi bitmap */
  117. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP;
  118. break;
  119. }
  120. reg &= ~FLOW_CTRL_CSR_ENABLE; /* clear enable */
  121. reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr */
  122. reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event */
  123. flowctrl_write_cpu_csr(cpuid, reg);
  124. }
  125. static const struct of_device_id matches[] __initconst = {
  126. { .compatible = "nvidia,tegra124-flowctrl" },
  127. { .compatible = "nvidia,tegra114-flowctrl" },
  128. { .compatible = "nvidia,tegra30-flowctrl" },
  129. { .compatible = "nvidia,tegra20-flowctrl" },
  130. { }
  131. };
  132. void __init tegra_flowctrl_init(void)
  133. {
  134. /* hardcoded fallback if device tree node is missing */
  135. unsigned long base = 0x60007000;
  136. unsigned long size = SZ_4K;
  137. struct device_node *np;
  138. np = of_find_matching_node(NULL, matches);
  139. if (np) {
  140. struct resource res;
  141. if (of_address_to_resource(np, 0, &res) == 0) {
  142. size = resource_size(&res);
  143. base = res.start;
  144. }
  145. of_node_put(np);
  146. }
  147. tegra_flowctrl_base = ioremap_nocache(base, size);
  148. }