platsmp.c 4.6 KB

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