src.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright 2011 Freescale Semiconductor, Inc.
  3. * Copyright 2011 Linaro Ltd.
  4. *
  5. * The code contained herein is licensed under the GNU General Public
  6. * License. You may obtain a copy of the GNU General Public License
  7. * Version 2 or later at the following locations:
  8. *
  9. * http://www.opensource.org/licenses/gpl-license.html
  10. * http://www.gnu.org/copyleft/gpl.html
  11. */
  12. #include <linux/init.h>
  13. #include <linux/io.h>
  14. #include <linux/of.h>
  15. #include <linux/of_address.h>
  16. #include <linux/reset-controller.h>
  17. #include <linux/smp.h>
  18. #include <asm/smp_plat.h>
  19. #include "common.h"
  20. #define SRC_SCR 0x000
  21. #define SRC_GPR1 0x020
  22. #define BP_SRC_SCR_WARM_RESET_ENABLE 0
  23. #define BP_SRC_SCR_SW_GPU_RST 1
  24. #define BP_SRC_SCR_SW_VPU_RST 2
  25. #define BP_SRC_SCR_SW_IPU1_RST 3
  26. #define BP_SRC_SCR_SW_OPEN_VG_RST 4
  27. #define BP_SRC_SCR_SW_IPU2_RST 12
  28. #define BP_SRC_SCR_CORE1_RST 14
  29. #define BP_SRC_SCR_CORE1_ENABLE 22
  30. static void __iomem *src_base;
  31. static DEFINE_SPINLOCK(scr_lock);
  32. static const int sw_reset_bits[5] = {
  33. BP_SRC_SCR_SW_GPU_RST,
  34. BP_SRC_SCR_SW_VPU_RST,
  35. BP_SRC_SCR_SW_IPU1_RST,
  36. BP_SRC_SCR_SW_OPEN_VG_RST,
  37. BP_SRC_SCR_SW_IPU2_RST
  38. };
  39. static int imx_src_reset_module(struct reset_controller_dev *rcdev,
  40. unsigned long sw_reset_idx)
  41. {
  42. unsigned long timeout;
  43. unsigned long flags;
  44. int bit;
  45. u32 val;
  46. if (!src_base)
  47. return -ENODEV;
  48. if (sw_reset_idx >= ARRAY_SIZE(sw_reset_bits))
  49. return -EINVAL;
  50. bit = 1 << sw_reset_bits[sw_reset_idx];
  51. spin_lock_irqsave(&scr_lock, flags);
  52. val = readl_relaxed(src_base + SRC_SCR);
  53. val |= bit;
  54. writel_relaxed(val, src_base + SRC_SCR);
  55. spin_unlock_irqrestore(&scr_lock, flags);
  56. timeout = jiffies + msecs_to_jiffies(1000);
  57. while (readl(src_base + SRC_SCR) & bit) {
  58. if (time_after(jiffies, timeout))
  59. return -ETIME;
  60. cpu_relax();
  61. }
  62. return 0;
  63. }
  64. static struct reset_control_ops imx_src_ops = {
  65. .reset = imx_src_reset_module,
  66. };
  67. static struct reset_controller_dev imx_reset_controller = {
  68. .ops = &imx_src_ops,
  69. .nr_resets = ARRAY_SIZE(sw_reset_bits),
  70. };
  71. void imx_enable_cpu(int cpu, bool enable)
  72. {
  73. u32 mask, val;
  74. cpu = cpu_logical_map(cpu);
  75. mask = 1 << (BP_SRC_SCR_CORE1_ENABLE + cpu - 1);
  76. spin_lock(&scr_lock);
  77. val = readl_relaxed(src_base + SRC_SCR);
  78. val = enable ? val | mask : val & ~mask;
  79. writel_relaxed(val, src_base + SRC_SCR);
  80. spin_unlock(&scr_lock);
  81. }
  82. void imx_set_cpu_jump(int cpu, void *jump_addr)
  83. {
  84. cpu = cpu_logical_map(cpu);
  85. writel_relaxed(virt_to_phys(jump_addr),
  86. src_base + SRC_GPR1 + cpu * 8);
  87. }
  88. u32 imx_get_cpu_arg(int cpu)
  89. {
  90. cpu = cpu_logical_map(cpu);
  91. return readl_relaxed(src_base + SRC_GPR1 + cpu * 8 + 4);
  92. }
  93. void imx_set_cpu_arg(int cpu, u32 arg)
  94. {
  95. cpu = cpu_logical_map(cpu);
  96. writel_relaxed(arg, src_base + SRC_GPR1 + cpu * 8 + 4);
  97. }
  98. void imx_src_prepare_restart(void)
  99. {
  100. u32 val;
  101. /* clear enable bits of secondary cores */
  102. spin_lock(&scr_lock);
  103. val = readl_relaxed(src_base + SRC_SCR);
  104. val &= ~(0x7 << BP_SRC_SCR_CORE1_ENABLE);
  105. writel_relaxed(val, src_base + SRC_SCR);
  106. spin_unlock(&scr_lock);
  107. /* clear persistent entry register of primary core */
  108. writel_relaxed(0, src_base + SRC_GPR1);
  109. }
  110. void __init imx_src_init(void)
  111. {
  112. struct device_node *np;
  113. u32 val;
  114. np = of_find_compatible_node(NULL, NULL, "fsl,imx51-src");
  115. if (!np)
  116. return;
  117. src_base = of_iomap(np, 0);
  118. WARN_ON(!src_base);
  119. imx_reset_controller.of_node = np;
  120. if (IS_ENABLED(CONFIG_RESET_CONTROLLER))
  121. reset_controller_register(&imx_reset_controller);
  122. /*
  123. * force warm reset sources to generate cold reset
  124. * for a more reliable restart
  125. */
  126. spin_lock(&scr_lock);
  127. val = readl_relaxed(src_base + SRC_SCR);
  128. val &= ~(1 << BP_SRC_SCR_WARM_RESET_ENABLE);
  129. writel_relaxed(val, src_base + SRC_SCR);
  130. spin_unlock(&scr_lock);
  131. }