platsmp.c 5.2 KB

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