platsmp.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 <mach/powergate.h>
  28. #include "fuse.h"
  29. #include "flowctrl.h"
  30. #include "reset.h"
  31. #include "common.h"
  32. #include "iomap.h"
  33. extern void tegra_secondary_startup(void);
  34. static cpumask_t tegra_cpu_init_mask;
  35. #define EVP_CPU_RESET_VECTOR \
  36. (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
  37. static void __cpuinit tegra_secondary_init(unsigned int cpu)
  38. {
  39. /*
  40. * if any interrupts are already enabled for the primary
  41. * core (e.g. timer irq), then they will not have been enabled
  42. * for us: do so
  43. */
  44. gic_secondary_init(0);
  45. cpumask_set_cpu(cpu, &tegra_cpu_init_mask);
  46. }
  47. static int tegra20_power_up_cpu(unsigned int cpu)
  48. {
  49. /* Enable the CPU clock. */
  50. tegra_enable_cpu_clock(cpu);
  51. /* Clear flow controller CSR. */
  52. flowctrl_write_cpu_csr(cpu, 0);
  53. return 0;
  54. }
  55. static int tegra30_power_up_cpu(unsigned int cpu)
  56. {
  57. int ret, pwrgateid;
  58. unsigned long timeout;
  59. pwrgateid = tegra_cpu_powergate_id(cpu);
  60. if (pwrgateid < 0)
  61. return pwrgateid;
  62. /*
  63. * The power up sequence of cold boot CPU and warm boot CPU
  64. * was different.
  65. *
  66. * For warm boot CPU that was resumed from CPU hotplug, the
  67. * power will be resumed automatically after un-halting the
  68. * flow controller of the warm boot CPU. We need to wait for
  69. * the confirmaiton that the CPU is powered then removing
  70. * the IO clamps.
  71. * For cold boot CPU, do not wait. After the cold boot CPU be
  72. * booted, it will run to tegra_secondary_init() and set
  73. * tegra_cpu_init_mask which influences what tegra30_power_up_cpu()
  74. * next time around.
  75. */
  76. if (cpumask_test_cpu(cpu, &tegra_cpu_init_mask)) {
  77. timeout = jiffies + msecs_to_jiffies(50);
  78. do {
  79. if (!tegra_powergate_is_powered(pwrgateid))
  80. goto remove_clamps;
  81. udelay(10);
  82. } while (time_before(jiffies, timeout));
  83. }
  84. /*
  85. * The power status of the cold boot CPU is power gated as
  86. * default. To power up the cold boot CPU, the power should
  87. * be un-gated by un-toggling the power gate register
  88. * manually.
  89. */
  90. if (!tegra_powergate_is_powered(pwrgateid)) {
  91. ret = tegra_powergate_power_on(pwrgateid);
  92. if (ret)
  93. return ret;
  94. /* Wait for the power to come up. */
  95. timeout = jiffies + msecs_to_jiffies(100);
  96. while (tegra_powergate_is_powered(pwrgateid)) {
  97. if (time_after(jiffies, timeout))
  98. return -ETIMEDOUT;
  99. udelay(10);
  100. }
  101. }
  102. remove_clamps:
  103. /* CPU partition is powered. Enable the CPU clock. */
  104. tegra_enable_cpu_clock(cpu);
  105. udelay(10);
  106. /* Remove I/O clamps. */
  107. ret = tegra_powergate_remove_clamping(pwrgateid);
  108. udelay(10);
  109. /* Clear flow controller CSR. */
  110. flowctrl_write_cpu_csr(cpu, 0);
  111. return 0;
  112. }
  113. static int __cpuinit tegra_boot_secondary(unsigned int cpu, struct task_struct *idle)
  114. {
  115. int status;
  116. cpu = cpu_logical_map(cpu);
  117. /*
  118. * Force the CPU into reset. The CPU must remain in reset when the
  119. * flow controller state is cleared (which will cause the flow
  120. * controller to stop driving reset if the CPU has been power-gated
  121. * via the flow controller). This will have no effect on first boot
  122. * of the CPU since it should already be in reset.
  123. */
  124. tegra_put_cpu_in_reset(cpu);
  125. /*
  126. * Unhalt the CPU. If the flow controller was used to power-gate the
  127. * CPU this will cause the flow controller to stop driving reset.
  128. * The CPU will remain in reset because the clock and reset block
  129. * is now driving reset.
  130. */
  131. flowctrl_write_cpu_halt(cpu, 0);
  132. switch (tegra_chip_id) {
  133. case TEGRA20:
  134. status = tegra20_power_up_cpu(cpu);
  135. break;
  136. case TEGRA30:
  137. status = tegra30_power_up_cpu(cpu);
  138. break;
  139. default:
  140. status = -EINVAL;
  141. break;
  142. }
  143. if (status)
  144. goto done;
  145. /* Take the CPU out of reset. */
  146. tegra_cpu_out_of_reset(cpu);
  147. done:
  148. return status;
  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. struct smp_operations tegra_smp_ops __initdata = {
  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. .cpu_disable = tegra_cpu_disable,
  165. #endif
  166. };