flowctrl.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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/init.h>
  21. #include <linux/kernel.h>
  22. #include <linux/io.h>
  23. #include <linux/cpumask.h>
  24. #include "flowctrl.h"
  25. #include "iomap.h"
  26. u8 flowctrl_offset_halt_cpu[] = {
  27. FLOW_CTRL_HALT_CPU0_EVENTS,
  28. FLOW_CTRL_HALT_CPU1_EVENTS,
  29. FLOW_CTRL_HALT_CPU1_EVENTS + 8,
  30. FLOW_CTRL_HALT_CPU1_EVENTS + 16,
  31. };
  32. u8 flowctrl_offset_cpu_csr[] = {
  33. FLOW_CTRL_CPU0_CSR,
  34. FLOW_CTRL_CPU1_CSR,
  35. FLOW_CTRL_CPU1_CSR + 8,
  36. FLOW_CTRL_CPU1_CSR + 16,
  37. };
  38. static void flowctrl_update(u8 offset, u32 value)
  39. {
  40. void __iomem *addr = IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + offset;
  41. writel(value, addr);
  42. /* ensure the update has reached the flow controller */
  43. wmb();
  44. readl_relaxed(addr);
  45. }
  46. u32 flowctrl_read_cpu_csr(unsigned int cpuid)
  47. {
  48. u8 offset = flowctrl_offset_cpu_csr[cpuid];
  49. void __iomem *addr = IO_ADDRESS(TEGRA_FLOW_CTRL_BASE) + offset;
  50. return readl(addr);
  51. }
  52. void flowctrl_write_cpu_csr(unsigned int cpuid, u32 value)
  53. {
  54. return flowctrl_update(flowctrl_offset_cpu_csr[cpuid], value);
  55. }
  56. void flowctrl_write_cpu_halt(unsigned int cpuid, u32 value)
  57. {
  58. return flowctrl_update(flowctrl_offset_halt_cpu[cpuid], value);
  59. }
  60. void flowctrl_cpu_suspend_enter(unsigned int cpuid)
  61. {
  62. unsigned int reg;
  63. int i;
  64. reg = flowctrl_read_cpu_csr(cpuid);
  65. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP; /* clear wfe bitmap */
  66. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP; /* clear wfi bitmap */
  67. reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr flag */
  68. reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event flag */
  69. reg |= TEGRA30_FLOW_CTRL_CSR_WFI_CPU0 << cpuid; /* pwr gating on wfi */
  70. reg |= FLOW_CTRL_CSR_ENABLE; /* pwr gating */
  71. flowctrl_write_cpu_csr(cpuid, reg);
  72. for (i = 0; i < num_possible_cpus(); i++) {
  73. if (i == cpuid)
  74. continue;
  75. reg = flowctrl_read_cpu_csr(i);
  76. reg |= FLOW_CTRL_CSR_EVENT_FLAG;
  77. reg |= FLOW_CTRL_CSR_INTR_FLAG;
  78. flowctrl_write_cpu_csr(i, reg);
  79. }
  80. }
  81. void flowctrl_cpu_suspend_exit(unsigned int cpuid)
  82. {
  83. unsigned int reg;
  84. /* Disable powergating via flow controller for CPU0 */
  85. reg = flowctrl_read_cpu_csr(cpuid);
  86. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFE_BITMAP; /* clear wfe bitmap */
  87. reg &= ~TEGRA30_FLOW_CTRL_CSR_WFI_BITMAP; /* clear wfi bitmap */
  88. reg &= ~FLOW_CTRL_CSR_ENABLE; /* clear enable */
  89. reg |= FLOW_CTRL_CSR_INTR_FLAG; /* clear intr */
  90. reg |= FLOW_CTRL_CSR_EVENT_FLAG; /* clear event */
  91. flowctrl_write_cpu_csr(cpuid, reg);
  92. }