platsmp.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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/init.h>
  15. #include <linux/errno.h>
  16. #include <linux/delay.h>
  17. #include <linux/device.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/smp.h>
  20. #include <linux/io.h>
  21. #include <linux/clk/tegra.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/mach-types.h>
  24. #include <asm/smp_scu.h>
  25. #include <asm/smp_plat.h>
  26. #include "fuse.h"
  27. #include "flowctrl.h"
  28. #include "reset.h"
  29. #include "pmc.h"
  30. #include "common.h"
  31. #include "iomap.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. if (!tegra_pmc_cpu_is_powered(cpu)) {
  97. ret = tegra_pmc_cpu_power_on(cpu);
  98. if (ret)
  99. return ret;
  100. /* Wait for the power to come up. */
  101. timeout = jiffies + msecs_to_jiffies(100);
  102. while (tegra_pmc_cpu_is_powered(cpu)) {
  103. if (time_after(jiffies, timeout))
  104. return -ETIMEDOUT;
  105. udelay(10);
  106. }
  107. }
  108. remove_clamps:
  109. /* CPU partition is powered. Enable the CPU clock. */
  110. tegra_enable_cpu_clock(cpu);
  111. udelay(10);
  112. /* Remove I/O clamps. */
  113. ret = tegra_pmc_cpu_remove_clamping(cpu);
  114. if (ret)
  115. return ret;
  116. udelay(10);
  117. flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */
  118. tegra_cpu_out_of_reset(cpu);
  119. return 0;
  120. }
  121. static int tegra114_boot_secondary(unsigned int cpu, struct task_struct *idle)
  122. {
  123. int ret = 0;
  124. cpu = cpu_logical_map(cpu);
  125. if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
  126. /*
  127. * Warm boot flow
  128. * The flow controller in charge of the power state and
  129. * control for each CPU.
  130. */
  131. /* set SCLK as event trigger for flow controller */
  132. flowctrl_write_cpu_csr(cpu, 1);
  133. flowctrl_write_cpu_halt(cpu,
  134. FLOW_CTRL_WAITEVENT | FLOW_CTRL_SCLK_RESUME);
  135. } else {
  136. /*
  137. * Cold boot flow
  138. * The CPU is powered up by toggling PMC directly. It will
  139. * also initial power state in flow controller. After that,
  140. * the CPU's power state is maintained by flow controller.
  141. */
  142. ret = tegra_pmc_cpu_power_on(cpu);
  143. }
  144. return ret;
  145. }
  146. static int tegra_boot_secondary(unsigned int cpu,
  147. struct task_struct *idle)
  148. {
  149. if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && tegra_chip_id == TEGRA20)
  150. return tegra20_boot_secondary(cpu, idle);
  151. if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_chip_id == TEGRA30)
  152. return tegra30_boot_secondary(cpu, idle);
  153. if (IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) && tegra_chip_id == TEGRA114)
  154. return tegra114_boot_secondary(cpu, idle);
  155. return -EINVAL;
  156. }
  157. static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
  158. {
  159. /* Always mark the boot CPU (CPU0) as initialized. */
  160. cpumask_set_cpu(0, &tegra_cpu_init_mask);
  161. if (scu_a9_has_base())
  162. scu_enable(IO_ADDRESS(scu_a9_get_base()));
  163. }
  164. struct smp_operations tegra_smp_ops __initdata = {
  165. .smp_prepare_cpus = tegra_smp_prepare_cpus,
  166. .smp_secondary_init = tegra_secondary_init,
  167. .smp_boot_secondary = tegra_boot_secondary,
  168. #ifdef CONFIG_HOTPLUG_CPU
  169. .cpu_kill = tegra_cpu_kill,
  170. .cpu_die = tegra_cpu_die,
  171. .cpu_disable = tegra_cpu_disable,
  172. #endif
  173. };