cpu.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 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.0V, 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. writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div);
  76. val = (0 << CLK_SYS_RATE_HCLK_DISABLE_SHIFT) |
  77. (1 << CLK_SYS_RATE_AHB_RATE_SHIFT) |
  78. (0 << CLK_SYS_RATE_PCLK_DISABLE_SHIFT) |
  79. (0 << CLK_SYS_RATE_APB_RATE_SHIFT);
  80. writel(val, &clkrst->crc_clk_sys_rate);
  81. /* Put i2c, mselect in reset and enable clocks */
  82. reset_set_enable(PERIPH_ID_DVC_I2C, 1);
  83. clock_set_enable(PERIPH_ID_DVC_I2C, 1);
  84. reset_set_enable(PERIPH_ID_MSELECT, 1);
  85. clock_set_enable(PERIPH_ID_MSELECT, 1);
  86. /* Switch MSELECT clock to PLLP (00) and use a divisor of 2 */
  87. clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0, 2);
  88. /*
  89. * Our high-level clock routines are not available prior to
  90. * relocation. We use the low-level functions which require a
  91. * hard-coded divisor. Use CLK_M with divide by (n + 1 = 17)
  92. */
  93. clock_ll_set_source_divisor(PERIPH_ID_DVC_I2C, 3, 16);
  94. /*
  95. * Give clocks time to stabilize, then take i2c and mselect out of
  96. * reset
  97. */
  98. udelay(1000);
  99. reset_set_enable(PERIPH_ID_DVC_I2C, 0);
  100. reset_set_enable(PERIPH_ID_MSELECT, 0);
  101. }
  102. static void set_cpu_running(int run)
  103. {
  104. struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
  105. debug("set_cpu_running entry, run = %d\n", run);
  106. writel(run ? FLOW_MODE_NONE : FLOW_MODE_STOP, &flow->halt_cpu_events);
  107. }
  108. void start_cpu(u32 reset_vector)
  109. {
  110. debug("start_cpu entry, reset_vector = %x\n", reset_vector);
  111. t30_init_clocks();
  112. /* Enable VDD_CPU */
  113. enable_cpu_power_rail();
  114. set_cpu_running(0);
  115. /* Hold the CPUs in reset */
  116. reset_A9_cpu(1);
  117. /* Disable the CPU clock */
  118. enable_cpu_clock(0);
  119. /* Enable CoreSight */
  120. clock_enable_coresight(1);
  121. /*
  122. * Set the entry point for CPU execution from reset,
  123. * if it's a non-zero value.
  124. */
  125. if (reset_vector)
  126. writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
  127. /* Enable the CPU clock */
  128. enable_cpu_clock(1);
  129. /* If the CPU doesn't already have power, power it up */
  130. powerup_cpu();
  131. /* Take the CPU out of reset */
  132. reset_A9_cpu(0);
  133. set_cpu_running(1);
  134. }