platsmp.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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/irqchip/arm-gic.h>
  22. #include <linux/clk/tegra.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/mach-types.h>
  25. #include <asm/smp_scu.h>
  26. #include <asm/smp_plat.h>
  27. #include "fuse.h"
  28. #include "flowctrl.h"
  29. #include "reset.h"
  30. #include "pmc.h"
  31. #include "common.h"
  32. #include "iomap.h"
  33. static cpumask_t tegra_cpu_init_mask;
  34. static void __cpuinit tegra_secondary_init(unsigned int cpu)
  35. {
  36. /*
  37. * if any interrupts are already enabled for the primary
  38. * core (e.g. timer irq), then they will not have been enabled
  39. * for us: do so
  40. */
  41. gic_secondary_init(0);
  42. cpumask_set_cpu(cpu, &tegra_cpu_init_mask);
  43. }
  44. static int tegra20_boot_secondary(unsigned int cpu, struct task_struct *idle)
  45. {
  46. cpu = cpu_logical_map(cpu);
  47. /*
  48. * Force the CPU into reset. The CPU must remain in reset when
  49. * the flow controller state is cleared (which will cause the
  50. * flow controller to stop driving reset if the CPU has been
  51. * power-gated via the flow controller). This will have no
  52. * effect on first boot of the CPU since it should already be
  53. * in reset.
  54. */
  55. tegra_put_cpu_in_reset(cpu);
  56. /*
  57. * Unhalt the CPU. If the flow controller was used to
  58. * power-gate the CPU this will cause the flow controller to
  59. * stop driving reset. The CPU will remain in reset because the
  60. * clock and reset block is now driving reset.
  61. */
  62. flowctrl_write_cpu_halt(cpu, 0);
  63. tegra_enable_cpu_clock(cpu);
  64. flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */
  65. tegra_cpu_out_of_reset(cpu);
  66. return 0;
  67. }
  68. static int tegra30_boot_secondary(unsigned int cpu, struct task_struct *idle)
  69. {
  70. int ret;
  71. unsigned long timeout;
  72. cpu = cpu_logical_map(cpu);
  73. tegra_put_cpu_in_reset(cpu);
  74. flowctrl_write_cpu_halt(cpu, 0);
  75. /*
  76. * The power up sequence of cold boot CPU and warm boot CPU
  77. * was different.
  78. *
  79. * For warm boot CPU that was resumed from CPU hotplug, the
  80. * power will be resumed automatically after un-halting the
  81. * flow controller of the warm boot CPU. We need to wait for
  82. * the confirmaiton that the CPU is powered then removing
  83. * the IO clamps.
  84. * For cold boot CPU, do not wait. After the cold boot CPU be
  85. * booted, it will run to tegra_secondary_init() and set
  86. * tegra_cpu_init_mask which influences what tegra30_boot_secondary()
  87. * next time around.
  88. */
  89. if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
  90. timeout = jiffies + msecs_to_jiffies(50);
  91. do {
  92. if (tegra_pmc_cpu_is_powered(cpu))
  93. goto remove_clamps;
  94. udelay(10);
  95. } while (time_before(jiffies, timeout));
  96. }
  97. /*
  98. * The power status of the cold boot CPU is power gated as
  99. * default. To power up the cold boot CPU, the power should
  100. * be un-gated by un-toggling the power gate register
  101. * manually.
  102. */
  103. if (!tegra_pmc_cpu_is_powered(cpu)) {
  104. ret = tegra_pmc_cpu_power_on(cpu);
  105. if (ret)
  106. return ret;
  107. /* Wait for the power to come up. */
  108. timeout = jiffies + msecs_to_jiffies(100);
  109. while (tegra_pmc_cpu_is_powered(cpu)) {
  110. if (time_after(jiffies, timeout))
  111. return -ETIMEDOUT;
  112. udelay(10);
  113. }
  114. }
  115. remove_clamps:
  116. /* CPU partition is powered. Enable the CPU clock. */
  117. tegra_enable_cpu_clock(cpu);
  118. udelay(10);
  119. /* Remove I/O clamps. */
  120. ret = tegra_pmc_cpu_remove_clamping(cpu);
  121. if (ret)
  122. return ret;
  123. udelay(10);
  124. flowctrl_write_cpu_csr(cpu, 0); /* Clear flow controller CSR. */
  125. tegra_cpu_out_of_reset(cpu);
  126. return 0;
  127. }
  128. static int tegra114_boot_secondary(unsigned int cpu, struct task_struct *idle)
  129. {
  130. cpu = cpu_logical_map(cpu);
  131. return tegra_pmc_cpu_power_on(cpu);
  132. }
  133. static int __cpuinit tegra_boot_secondary(unsigned int cpu,
  134. struct task_struct *idle)
  135. {
  136. if (IS_ENABLED(CONFIG_ARCH_TEGRA_2x_SOC) && tegra_chip_id == TEGRA20)
  137. return tegra20_boot_secondary(cpu, idle);
  138. if (IS_ENABLED(CONFIG_ARCH_TEGRA_3x_SOC) && tegra_chip_id == TEGRA30)
  139. return tegra30_boot_secondary(cpu, idle);
  140. if (IS_ENABLED(CONFIG_ARCH_TEGRA_114_SOC) && tegra_chip_id == TEGRA114)
  141. return tegra114_boot_secondary(cpu, idle);
  142. return -EINVAL;
  143. }
  144. static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
  145. {
  146. /* Always mark the boot CPU (CPU0) as initialized. */
  147. cpumask_set_cpu(0, &tegra_cpu_init_mask);
  148. if (scu_a9_has_base())
  149. scu_enable(IO_ADDRESS(scu_a9_get_base()));
  150. }
  151. struct smp_operations tegra_smp_ops __initdata = {
  152. .smp_prepare_cpus = tegra_smp_prepare_cpus,
  153. .smp_secondary_init = tegra_secondary_init,
  154. .smp_boot_secondary = tegra_boot_secondary,
  155. #ifdef CONFIG_HOTPLUG_CPU
  156. .cpu_kill = tegra_cpu_kill,
  157. .cpu_die = tegra_cpu_die,
  158. .cpu_disable = tegra_cpu_disable,
  159. #endif
  160. };