platsmp.c 4.3 KB

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