cpu.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) 2010-2014, 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 TPS62366A_I2C_ADDR 0xC0
  39. #define TPS62366A_SET1_REG 0x01
  40. #define TPS62366A_SET1_DATA (0x4600 | TPS62366A_SET1_REG)
  41. #define TPS62361B_I2C_ADDR 0xC0
  42. #define TPS62361B_SET3_REG 0x03
  43. #define TPS62361B_SET3_DATA (0x4600 | TPS62361B_SET3_REG)
  44. #define TPS65911_I2C_ADDR 0x5A
  45. #define TPS65911_VDDCTRL_OP_REG 0x28
  46. #define TPS65911_VDDCTRL_SR_REG 0x27
  47. #define TPS65911_VDDCTRL_OP_DATA (0x2400 | TPS65911_VDDCTRL_OP_REG)
  48. #define TPS65911_VDDCTRL_SR_DATA (0x0100 | TPS65911_VDDCTRL_SR_REG)
  49. #define I2C_SEND_2_BYTES 0x0A02
  50. static void enable_cpu_power_rail(void)
  51. {
  52. struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
  53. u32 reg;
  54. debug("enable_cpu_power_rail entry\n");
  55. reg = readl(&pmc->pmc_cntrl);
  56. reg |= CPUPWRREQ_OE;
  57. writel(reg, &pmc->pmc_cntrl);
  58. /* Set VDD_CORE to 1.200V. */
  59. #ifdef CONFIG_TEGRA_VDD_CORE_TPS62366A_SET1
  60. tegra_i2c_ll_write_addr(TPS62366A_I2C_ADDR, 2);
  61. tegra_i2c_ll_write_data(TPS62366A_SET1_DATA, I2C_SEND_2_BYTES);
  62. #endif
  63. #ifdef CONFIG_TEGRA_VDD_CORE_TPS62361B_SET3
  64. tegra_i2c_ll_write_addr(TPS62361B_I2C_ADDR, 2);
  65. tegra_i2c_ll_write_data(TPS62361B_SET3_DATA, I2C_SEND_2_BYTES);
  66. #endif
  67. udelay(1000);
  68. /*
  69. * Bring up CPU VDD via the TPS65911x PMIC on the DVC I2C bus.
  70. * First set VDD to 1.0125V, then enable the VDD regulator.
  71. */
  72. tegra_i2c_ll_write_addr(TPS65911_I2C_ADDR, 2);
  73. tegra_i2c_ll_write_data(TPS65911_VDDCTRL_OP_DATA, I2C_SEND_2_BYTES);
  74. udelay(1000);
  75. tegra_i2c_ll_write_data(TPS65911_VDDCTRL_SR_DATA, I2C_SEND_2_BYTES);
  76. udelay(10 * 1000);
  77. }
  78. /**
  79. * The T30 requires some special clock initialization, including setting up
  80. * the dvc i2c, turning on mselect and selecting the G CPU cluster
  81. */
  82. void t30_init_clocks(void)
  83. {
  84. struct clk_rst_ctlr *clkrst =
  85. (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
  86. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  87. u32 val;
  88. debug("t30_init_clocks entry\n");
  89. /* Set active CPU cluster to G */
  90. clrbits_le32(flow->cluster_control, 1 << 0);
  91. writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div);
  92. val = (0 << CLK_SYS_RATE_HCLK_DISABLE_SHIFT) |
  93. (1 << CLK_SYS_RATE_AHB_RATE_SHIFT) |
  94. (0 << CLK_SYS_RATE_PCLK_DISABLE_SHIFT) |
  95. (0 << CLK_SYS_RATE_APB_RATE_SHIFT);
  96. writel(val, &clkrst->crc_clk_sys_rate);
  97. /* Put i2c, mselect in reset and enable clocks */
  98. reset_set_enable(PERIPH_ID_DVC_I2C, 1);
  99. clock_set_enable(PERIPH_ID_DVC_I2C, 1);
  100. reset_set_enable(PERIPH_ID_MSELECT, 1);
  101. clock_set_enable(PERIPH_ID_MSELECT, 1);
  102. /* Switch MSELECT clock to PLLP (00) and use a divisor of 2 */
  103. clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0, 2);
  104. /*
  105. * Our high-level clock routines are not available prior to
  106. * relocation. We use the low-level functions which require a
  107. * hard-coded divisor. Use CLK_M with divide by (n + 1 = 17)
  108. */
  109. clock_ll_set_source_divisor(PERIPH_ID_DVC_I2C, 3, 16);
  110. /*
  111. * Give clocks time to stabilize, then take i2c and mselect out of
  112. * reset
  113. */
  114. udelay(1000);
  115. reset_set_enable(PERIPH_ID_DVC_I2C, 0);
  116. reset_set_enable(PERIPH_ID_MSELECT, 0);
  117. }
  118. static void set_cpu_running(int run)
  119. {
  120. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  121. debug("set_cpu_running entry, run = %d\n", run);
  122. writel(run ? FLOW_MODE_NONE : FLOW_MODE_STOP, &flow->halt_cpu_events);
  123. }
  124. void start_cpu(u32 reset_vector)
  125. {
  126. debug("start_cpu entry, reset_vector = %x\n", reset_vector);
  127. t30_init_clocks();
  128. /* Enable VDD_CPU */
  129. enable_cpu_power_rail();
  130. set_cpu_running(0);
  131. /* Hold the CPUs in reset */
  132. reset_A9_cpu(1);
  133. /* Disable the CPU clock */
  134. enable_cpu_clock(0);
  135. /* Enable CoreSight */
  136. clock_enable_coresight(1);
  137. /*
  138. * Set the entry point for CPU execution from reset,
  139. * if it's a non-zero value.
  140. */
  141. if (reset_vector)
  142. writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
  143. /* Enable the CPU clock */
  144. enable_cpu_clock(1);
  145. /* If the CPU doesn't already have power, power it up */
  146. powerup_cpu();
  147. /* Take the CPU out of reset */
  148. reset_A9_cpu(0);
  149. set_cpu_running(1);
  150. }