platsmp.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <asm/cacheflush.h>
  22. #include <asm/hardware/gic.h>
  23. #include <asm/mach-types.h>
  24. #include <asm/smp_scu.h>
  25. #include <mach/clk.h>
  26. #include <mach/iomap.h>
  27. #include <mach/powergate.h>
  28. #include "fuse.h"
  29. #include "flowctrl.h"
  30. #include "reset.h"
  31. #include "common.h"
  32. extern void tegra_secondary_startup(void);
  33. static void __iomem *scu_base = IO_ADDRESS(TEGRA_ARM_PERIF_BASE);
  34. #define EVP_CPU_RESET_VECTOR \
  35. (IO_ADDRESS(TEGRA_EXCEPTION_VECTORS_BASE) + 0x100)
  36. #define CLK_RST_CONTROLLER_CLK_CPU_CMPLX \
  37. (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x4c)
  38. #define CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET \
  39. (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x340)
  40. #define CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR \
  41. (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x344)
  42. #define CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR \
  43. (IO_ADDRESS(TEGRA_CLK_RESET_BASE) + 0x34c)
  44. #define CPU_CLOCK(cpu) (0x1<<(8+cpu))
  45. #define CPU_RESET(cpu) (0x1111ul<<(cpu))
  46. static void __cpuinit tegra_secondary_init(unsigned int cpu)
  47. {
  48. /*
  49. * if any interrupts are already enabled for the primary
  50. * core (e.g. timer irq), then they will not have been enabled
  51. * for us: do so
  52. */
  53. gic_secondary_init(0);
  54. }
  55. static int tegra20_power_up_cpu(unsigned int cpu)
  56. {
  57. u32 reg;
  58. /* Enable the CPU clock. */
  59. reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  60. writel(reg & ~CPU_CLOCK(cpu), CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  61. barrier();
  62. reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX);
  63. /* Clear flow controller CSR. */
  64. flowctrl_write_cpu_csr(cpu, 0);
  65. return 0;
  66. }
  67. static int tegra30_power_up_cpu(unsigned int cpu)
  68. {
  69. u32 reg;
  70. int ret, pwrgateid;
  71. unsigned long timeout;
  72. pwrgateid = tegra_cpu_powergate_id(cpu);
  73. if (pwrgateid < 0)
  74. return pwrgateid;
  75. /* If this is the first boot, toggle powergates directly. */
  76. if (!tegra_powergate_is_powered(pwrgateid)) {
  77. ret = tegra_powergate_power_on(pwrgateid);
  78. if (ret)
  79. return ret;
  80. /* Wait for the power to come up. */
  81. timeout = jiffies + 10*HZ;
  82. while (tegra_powergate_is_powered(pwrgateid)) {
  83. if (time_after(jiffies, timeout))
  84. return -ETIMEDOUT;
  85. udelay(10);
  86. }
  87. }
  88. /* CPU partition is powered. Enable the CPU clock. */
  89. writel(CPU_CLOCK(cpu), CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR);
  90. reg = readl(CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR);
  91. udelay(10);
  92. /* Remove I/O clamps. */
  93. ret = tegra_powergate_remove_clamping(pwrgateid);
  94. udelay(10);
  95. /* Clear flow controller CSR. */
  96. flowctrl_write_cpu_csr(cpu, 0);
  97. return 0;
  98. }
  99. static int __cpuinit tegra_boot_secondary(unsigned int cpu, struct task_struct *idle)
  100. {
  101. int status;
  102. /*
  103. * Force the CPU into reset. The CPU must remain in reset when the
  104. * flow controller state is cleared (which will cause the flow
  105. * controller to stop driving reset if the CPU has been power-gated
  106. * via the flow controller). This will have no effect on first boot
  107. * of the CPU since it should already be in reset.
  108. */
  109. writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET);
  110. dmb();
  111. /*
  112. * Unhalt the CPU. If the flow controller was used to power-gate the
  113. * CPU this will cause the flow controller to stop driving reset.
  114. * The CPU will remain in reset because the clock and reset block
  115. * is now driving reset.
  116. */
  117. flowctrl_write_cpu_halt(cpu, 0);
  118. switch (tegra_chip_id) {
  119. case TEGRA20:
  120. status = tegra20_power_up_cpu(cpu);
  121. break;
  122. case TEGRA30:
  123. status = tegra30_power_up_cpu(cpu);
  124. break;
  125. default:
  126. status = -EINVAL;
  127. break;
  128. }
  129. if (status)
  130. goto done;
  131. /* Take the CPU out of reset. */
  132. writel(CPU_RESET(cpu), CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR);
  133. wmb();
  134. done:
  135. return status;
  136. }
  137. /*
  138. * Initialise the CPU possible map early - this describes the CPUs
  139. * which may be present or become present in the system.
  140. */
  141. static void __init tegra_smp_init_cpus(void)
  142. {
  143. unsigned int i, ncores = scu_get_core_count(scu_base);
  144. if (ncores > nr_cpu_ids) {
  145. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  146. ncores, nr_cpu_ids);
  147. ncores = nr_cpu_ids;
  148. }
  149. for (i = 0; i < ncores; i++)
  150. set_cpu_possible(i, true);
  151. set_smp_cross_call(gic_raise_softirq);
  152. }
  153. static void __init tegra_smp_prepare_cpus(unsigned int max_cpus)
  154. {
  155. tegra_cpu_reset_handler_init();
  156. scu_enable(scu_base);
  157. }
  158. struct smp_operations tegra_smp_ops __initdata = {
  159. .smp_init_cpus = tegra_smp_init_cpus,
  160. .smp_prepare_cpus = tegra_smp_prepare_cpus,
  161. .smp_secondary_init = tegra_secondary_init,
  162. .smp_boot_secondary = tegra_boot_secondary,
  163. #ifdef CONFIG_HOTPLUG_CPU
  164. .cpu_die = tegra_cpu_die,
  165. #endif
  166. };