platsmp.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * linux/arch/arm/mach-tegra/platsmp.c
  4. *
  5. * Copyright (C) 2002 ARM Ltd.
  6. * All Rights Reserved
  7. *
  8. * Copyright (C) 2009 Palm
  9. * All Rights Reserved
  10. */
  11. #include <linux/clk/tegra.h>
  12. #include <linux/delay.h>
  13. #include <linux/device.h>
  14. #include <linux/errno.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <linux/jiffies.h>
  18. #include <linux/smp.h>
  19. #include <soc/tegra/flowctrl.h>
  20. #include <soc/tegra/fuse.h>
  21. #include <soc/tegra/pmc.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/mach-types.h>
  24. #include <asm/smp_plat.h>
  25. #include <asm/smp_scu.h>
  26. #include "common.h"
  27. #include "iomap.h"
  28. #include "reset.h"
  29. static cpumask_t tegra_cpu_init_mask;
  30. static void tegra_secondary_init(unsigned int cpu)
  31. {
  32. cpumask_set_cpu(cpu, &tegra_cpu_init_mask);
  33. }
  34. static int tegra20_boot_secondary(unsigned int cpu, struct task_struct *idle)
  35. {
  36. cpu = cpu_logical_map(cpu);
  37. /*
  38. * Force the CPU into reset. The CPU must remain in reset when
  39. * the flow controller state is cleared (which will cause the
  40. * flow controller to stop driving reset if the CPU has been
  41. * power-gated via the flow controller). This will have no
  42. * effect on first boot of the CPU since it should already be
  43. * in reset.
  44. */
  45. tegra_put_cpu_in_reset(cpu);
  46. /*
  47. * Unhalt the CPU. If the flow controller was used to
  48. * power-gate the CPU this will cause the flow controller to
  49. * stop driving reset. The CPU will remain in reset because the
  50. * clock and reset block is now driving reset.
  51. */
  52. flowctrl_write_cpu_halt(cpu, 0);
  53. tegra_enable_cpu_clock(cpu);
  54. flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */
  55. tegra_cpu_out_of_reset(cpu);
  56. return 0;
  57. }
  58. static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
  59. {
  60. int ret;
  61. unsigned long timeout;
  62. cpu = cpu_logical_map(cpu);
  63. tegra_put_cpu_in_reset(cpu);
  64. flowctrl_write_cpu_halt(cpu, 0);
  65. /*
  66. * The power up sequence of cold boot CPU and warm boot CPU
  67. * was different.
  68. *
  69. * For warm boot CPU that was resumed from CPU hotplug, the
  70. * power will be resumed automatically after un-halting the
  71. * flow controller of the warm boot CPU. We need to wait for
  72. * the confirmation that the CPU is powered then removing
  73. * the IO clamps.
  74. * For cold boot CPU, do not wait. After the cold boot CPU be
  75. * booted, it will run to tegra_secondary_init() and set
  76. * tegra_cpu_init_mask which influences what tegra30_boot_secondary()
  77. * next time around.
  78. */
  79. if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
  80. timeout = jiffies + msecs_to_jiffies(50);
  81. do {
  82. if (tegra_pmc_cpu_is_powered(cpu))
  83. goto remove_clamps;
  84. udelay(10);
  85. } while (time_before(jiffies, timeout));
  86. }
  87. /*
  88. * The power status of the cold boot CPU is power gated as
  89. * default. To power up the cold boot CPU, the power should
  90. * be un-gated by un-toggling the power gate register
  91. * manually.
  92. */
  93. ret = tegra_pmc_cpu_power_on(cpu);
  94. if (ret)
  95. return ret;
  96. remove_clamps:
  97. /* CPU partition is powered. Enable the CPU clock. */
  98. tegra_enable_cpu_clock(cpu);
  99. udelay(10);
  100. /* Remove I/O clamps. */
  101. ret = tegra_pmc_cpu_remove_clamping(cpu);
  102. if (ret)
  103. return ret;
  104. udelay(10);
  105. flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */
  106. tegra_cpu_out_of_reset(cpu);
  107. return 0;
  108. }
  109. static int tegra114_boot_secondary(unsigned int cpu, struct task_struct *idle)
  110. {
  111. int ret = 0;
  112. cpu = cpu_logical_map(cpu);
  113. if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
  114. /*
  115. * Warm boot flow
  116. * The flow controller in charge of the power state and
  117. * control for each CPU.
  118. */
  119. /* set SCLK as event trigger for flow controller */
  120. flowctrl_write_cpu_csr(cpu, 1);
  121. flowctrl_write_cpu_halt(cpu,
  122. FLOW_CTRL_WAITEVENT | FLOW_CTRL_SCLK_RESUME);
  123. } else {
  124. /*
  125. * Cold boot flow
  126. * The CPU is powered up by toggling PMC directly. It will
  127. * also initial power state in flow controller. After that,
  128. * the CPU's power state is maintained by flow controller.
  129. */
  130. ret = tegra_pmc_cpu_power_on(cpu);
  131. }
  132. return ret;
  133. }
  134. static int tegra_boot_secondary(unsigned int cpu,
  135. struct task_struct *idle)
  136. {
  137. if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && tegra_get_chip_id() == TEGRA20)
  138. return tegra20_boot_secondary(cpu, idle);
  139. if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_get_chip_id() == TEGRA30)
  140. return tegra30_boot_secondary(cpu, idle);
  141. if (IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) && tegra_get_chip_id() == TEGRA114)
  142. return tegra114_boot_secondary(cpu, idle);
  143. if (IS_ENABLED(CONFIG_ARCH_TEGRA_124_SOC) && tegra_get_chip_id() == TEGRA124)
  144. return tegra114_boot_secondary(cpu, idle);
  145. return -EINVAL;
  146. }
  147. static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
  148. {
  149. /* Always mark the boot CPU (CPU0) as initialized. */
  150. cpumask_set_cpu(0, &tegra_cpu_init_mask);
  151. if (scu_a9_has_base())
  152. scu_enable(IO_ADDRESS(scu_a9_get_base()));
  153. }
  154. const struct smp_operations tegra_smp_ops __initconst = {
  155. .smp_prepare_cpus = tegra_smp_prepare_cpus,
  156. .smp_secondary_init = tegra_secondary_init,
  157. .smp_boot_secondary = tegra_boot_secondary,
  158. #ifdef CONFIG_HOTPLUG_CPU
  159. .cpu_kill = tegra_cpu_kill,
  160. .cpu_die = tegra_cpu_die,
  161. #endif
  162. };