cpu.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) 2010-2012, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <common.h>
  17. #include <asm/io.h>
  18. #include <asm/arch/clock.h>
  19. #include <asm/arch/flow.h>
  20. #include <asm/arch/tegra.h>
  21. #include <asm/arch-tegra/clk_rst.h>
  22. #include <asm/arch-tegra/pmc.h>
  23. #include <asm/arch-tegra/tegra_i2c.h>
  24. #include "../tegra-common/cpu.h"
  25. /* Tegra30-specific CPU init code */
  26. void tegra_i2c_ll_write_addr(uint addr, uint config)
  27. {
  28. struct i2c_ctlr *reg = (struct i2c_ctlr *)TEGRA_DVC_BASE;
  29. writel(addr, &reg->cmd_addr0);
  30. writel(config, &reg->cnfg);
  31. }
  32. void tegra_i2c_ll_write_data(uint data, uint config)
  33. {
  34. struct i2c_ctlr *reg = (struct i2c_ctlr *)TEGRA_DVC_BASE;
  35. writel(data, &reg->cmd_data1);
  36. writel(config, &reg->cnfg);
  37. }
  38. #define TPS65911_I2C_ADDR 0x5A
  39. #define TPS65911_VDDCTRL_OP_REG 0x28
  40. #define TPS65911_VDDCTRL_SR_REG 0x27
  41. #define TPS65911_VDDCTRL_OP_DATA (0x2300 | TPS65911_VDDCTRL_OP_REG)
  42. #define TPS65911_VDDCTRL_SR_DATA (0x0100 | TPS65911_VDDCTRL_SR_REG)
  43. #define I2C_SEND_2_BYTES 0x0A02
  44. static void enable_cpu_power_rail(void)
  45. {
  46. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  47. u32 reg;
  48. debug("enable_cpu_power_rail entry\n");
  49. reg = readl(&pmc->pmc_cntrl);
  50. reg |= CPUPWRREQ_OE;
  51. writel(reg, &pmc->pmc_cntrl);
  52. /*
  53. * Bring up CPU VDD via the TPS65911x PMIC on the DVC I2C bus.
  54. * First set VDD to 1.4V, then enable the VDD regulator.
  55. */
  56. tegra_i2c_ll_write_addr(TPS65911_I2C_ADDR, 2);
  57. tegra_i2c_ll_write_data(TPS65911_VDDCTRL_OP_DATA, I2C_SEND_2_BYTES);
  58. udelay(1000);
  59. tegra_i2c_ll_write_data(TPS65911_VDDCTRL_SR_DATA, I2C_SEND_2_BYTES);
  60. udelay(10 * 1000);
  61. }
  62. /**
  63. * The T30 requires some special clock initialization, including setting up
  64. * the dvc i2c, turning on mselect and selecting the G CPU cluster
  65. */
  66. void t30_init_clocks(void)
  67. {
  68. struct clk_rst_ctlr *clkrst =
  69. (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  70. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  71. u32 val;
  72. debug("t30_init_clocks entry\n");
  73. /* Set active CPU cluster to G */
  74. clrbits_le32(flow->cluster_control, 1 << 0);
  75. /*
  76. * Switch system clock to PLLP_OUT4 (108 MHz), AVP will now run
  77. * at 108 MHz. This is glitch free as only the source is changed, no
  78. * special precaution needed.
  79. */
  80. val = (SCLK_SOURCE_PLLP_OUT4 << SCLK_SWAKEUP_FIQ_SOURCE_SHIFT) |
  81. (SCLK_SOURCE_PLLP_OUT4 << SCLK_SWAKEUP_IRQ_SOURCE_SHIFT) |
  82. (SCLK_SOURCE_PLLP_OUT4 << SCLK_SWAKEUP_RUN_SOURCE_SHIFT) |
  83. (SCLK_SOURCE_PLLP_OUT4 << SCLK_SWAKEUP_IDLE_SOURCE_SHIFT) |
  84. (SCLK_SYS_STATE_RUN << SCLK_SYS_STATE_SHIFT);
  85. writel(val, &clkrst->crc_sclk_brst_pol);
  86. writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div);
  87. val = (0 << CLK_SYS_RATE_HCLK_DISABLE_SHIFT) |
  88. (1 << CLK_SYS_RATE_AHB_RATE_SHIFT) |
  89. (0 << CLK_SYS_RATE_PCLK_DISABLE_SHIFT) |
  90. (0 << CLK_SYS_RATE_APB_RATE_SHIFT);
  91. writel(val, &clkrst->crc_clk_sys_rate);
  92. /* Put i2c, mselect in reset and enable clocks */
  93. reset_set_enable(PERIPH_ID_DVC_I2C, 1);
  94. clock_set_enable(PERIPH_ID_DVC_I2C, 1);
  95. reset_set_enable(PERIPH_ID_MSELECT, 1);
  96. clock_set_enable(PERIPH_ID_MSELECT, 1);
  97. /* Switch MSELECT clock to PLLP (00) */
  98. clock_ll_set_source(PERIPH_ID_MSELECT, 0);
  99. /*
  100. * Our high-level clock routines are not available prior to
  101. * relocation. We use the low-level functions which require a
  102. * hard-coded divisor. Use CLK_M with divide by (n + 1 = 17)
  103. */
  104. clock_ll_set_source_divisor(PERIPH_ID_DVC_I2C, 3, 16);
  105. /*
  106. * Give clocks time to stabilize, then take i2c and mselect out of
  107. * reset
  108. */
  109. udelay(1000);
  110. reset_set_enable(PERIPH_ID_DVC_I2C, 0);
  111. reset_set_enable(PERIPH_ID_MSELECT, 0);
  112. }
  113. static void set_cpu_running(int run)
  114. {
  115. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  116. debug("set_cpu_running entry, run = %d\n", run);
  117. writel(run ? FLOW_MODE_NONE : FLOW_MODE_STOP, &flow->halt_cpu_events);
  118. }
  119. void start_cpu(u32 reset_vector)
  120. {
  121. debug("start_cpu entry, reset_vector = %x\n", reset_vector);
  122. t30_init_clocks();
  123. /* Enable VDD_CPU */
  124. enable_cpu_power_rail();
  125. set_cpu_running(0);
  126. /* Hold the CPUs in reset */
  127. reset_A9_cpu(1);
  128. /* Disable the CPU clock */
  129. enable_cpu_clock(0);
  130. /* Enable CoreSight */
  131. clock_enable_coresight(1);
  132. /*
  133. * Set the entry point for CPU execution from reset,
  134. * if it's a non-zero value.
  135. */
  136. if (reset_vector)
  137. writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
  138. /* Enable the CPU clock */
  139. enable_cpu_clock(1);
  140. /* If the CPU doesn't already have power, power it up */
  141. powerup_cpu();
  142. /* Take the CPU out of reset */
  143. reset_A9_cpu(0);
  144. set_cpu_running(1);
  145. }