Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 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 | |
| 17 | #include <common.h> |
| 18 | #include <asm/io.h> |
| 19 | #include <asm/arch/clock.h> |
| 20 | #include <asm/arch/flow.h> |
| 21 | #include <asm/arch/tegra.h> |
| 22 | #include <asm/arch-tegra/clk_rst.h> |
| 23 | #include <asm/arch-tegra/pmc.h> |
| 24 | #include <asm/arch-tegra/tegra_i2c.h> |
| 25 | #include "../tegra-common/cpu.h" |
| 26 | |
| 27 | /* Tegra30-specific CPU init code */ |
| 28 | void tegra_i2c_ll_write_addr(uint addr, uint config) |
| 29 | { |
| 30 | struct i2c_ctlr *reg = (struct i2c_ctlr *)TEGRA_DVC_BASE; |
| 31 | |
| 32 | writel(addr, ®->cmd_addr0); |
| 33 | writel(config, ®->cnfg); |
| 34 | } |
| 35 | |
| 36 | void tegra_i2c_ll_write_data(uint data, uint config) |
| 37 | { |
| 38 | struct i2c_ctlr *reg = (struct i2c_ctlr *)TEGRA_DVC_BASE; |
| 39 | |
| 40 | writel(data, ®->cmd_data1); |
| 41 | writel(config, ®->cnfg); |
| 42 | } |
| 43 | |
| 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 (0x2300 | TPS65911_VDDCTRL_OP_REG) |
| 48 | #define TPS65911_VDDCTRL_SR_DATA (0x0100 | TPS65911_VDDCTRL_SR_REG) |
| 49 | #define I2C_SEND_2_BYTES 0x0A02 |
| 50 | |
| 51 | static void enable_cpu_power_rail(void) |
| 52 | { |
| 53 | struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE; |
| 54 | u32 reg; |
| 55 | |
| 56 | debug("enable_cpu_power_rail entry\n"); |
| 57 | reg = readl(&pmc->pmc_cntrl); |
| 58 | reg |= CPUPWRREQ_OE; |
| 59 | writel(reg, &pmc->pmc_cntrl); |
| 60 | |
| 61 | /* |
| 62 | * Bring up CPU VDD via the TPS65911x PMIC on the DVC I2C bus. |
| 63 | * First set VDD to 1.4V, then enable the VDD regulator. |
| 64 | */ |
| 65 | tegra_i2c_ll_write_addr(TPS65911_I2C_ADDR, 2); |
| 66 | tegra_i2c_ll_write_data(TPS65911_VDDCTRL_OP_DATA, I2C_SEND_2_BYTES); |
| 67 | udelay(1000); |
| 68 | tegra_i2c_ll_write_data(TPS65911_VDDCTRL_SR_DATA, I2C_SEND_2_BYTES); |
| 69 | udelay(10 * 1000); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * The T30 requires some special clock initialization, including setting up |
| 74 | * the dvc i2c, turning on mselect and selecting the G CPU cluster |
| 75 | */ |
| 76 | void t30_init_clocks(void) |
| 77 | { |
| 78 | struct clk_rst_ctlr *clkrst = |
| 79 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 80 | struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE; |
| 81 | u32 val; |
| 82 | |
| 83 | debug("t30_init_clocks entry\n"); |
| 84 | /* Set active CPU cluster to G */ |
| 85 | clrbits_le32(flow->cluster_control, 1 << 0); |
| 86 | |
| 87 | /* |
| 88 | * Switch system clock to PLLP_OUT4 (108 MHz), AVP will now run |
| 89 | * at 108 MHz. This is glitch free as only the source is changed, no |
| 90 | * special precaution needed. |
| 91 | */ |
| 92 | val = (SCLK_SOURCE_PLLP_OUT4 << SCLK_SWAKEUP_FIQ_SOURCE_SHIFT) | |
| 93 | (SCLK_SOURCE_PLLP_OUT4 << SCLK_SWAKEUP_IRQ_SOURCE_SHIFT) | |
| 94 | (SCLK_SOURCE_PLLP_OUT4 << SCLK_SWAKEUP_RUN_SOURCE_SHIFT) | |
| 95 | (SCLK_SOURCE_PLLP_OUT4 << SCLK_SWAKEUP_IDLE_SOURCE_SHIFT) | |
| 96 | (SCLK_SYS_STATE_RUN << SCLK_SYS_STATE_SHIFT); |
| 97 | writel(val, &clkrst->crc_sclk_brst_pol); |
| 98 | |
| 99 | writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div); |
| 100 | |
| 101 | val = (0 << CLK_SYS_RATE_HCLK_DISABLE_SHIFT) | |
| 102 | (1 << CLK_SYS_RATE_AHB_RATE_SHIFT) | |
| 103 | (0 << CLK_SYS_RATE_PCLK_DISABLE_SHIFT) | |
| 104 | (0 << CLK_SYS_RATE_APB_RATE_SHIFT); |
| 105 | writel(val, &clkrst->crc_clk_sys_rate); |
| 106 | |
| 107 | /* Put i2c, mselect in reset and enable clocks */ |
| 108 | reset_set_enable(PERIPH_ID_DVC_I2C, 1); |
| 109 | clock_set_enable(PERIPH_ID_DVC_I2C, 1); |
| 110 | reset_set_enable(PERIPH_ID_MSELECT, 1); |
| 111 | clock_set_enable(PERIPH_ID_MSELECT, 1); |
| 112 | |
Tom Warren | d94c2db | 2013-04-03 14:39:30 -0700 | [diff] [blame^] | 113 | /* Switch MSELECT clock to PLLP (00) and use a divisor of 2 */ |
| 114 | clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0, 2); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * Our high-level clock routines are not available prior to |
| 118 | * relocation. We use the low-level functions which require a |
| 119 | * hard-coded divisor. Use CLK_M with divide by (n + 1 = 17) |
| 120 | */ |
| 121 | clock_ll_set_source_divisor(PERIPH_ID_DVC_I2C, 3, 16); |
| 122 | |
| 123 | /* |
| 124 | * Give clocks time to stabilize, then take i2c and mselect out of |
| 125 | * reset |
| 126 | */ |
| 127 | udelay(1000); |
| 128 | reset_set_enable(PERIPH_ID_DVC_I2C, 0); |
| 129 | reset_set_enable(PERIPH_ID_MSELECT, 0); |
| 130 | } |
| 131 | |
| 132 | static void set_cpu_running(int run) |
| 133 | { |
| 134 | struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE; |
| 135 | |
| 136 | debug("set_cpu_running entry, run = %d\n", run); |
| 137 | writel(run ? FLOW_MODE_NONE : FLOW_MODE_STOP, &flow->halt_cpu_events); |
| 138 | } |
| 139 | |
| 140 | void start_cpu(u32 reset_vector) |
| 141 | { |
| 142 | debug("start_cpu entry, reset_vector = %x\n", reset_vector); |
| 143 | t30_init_clocks(); |
| 144 | |
| 145 | /* Enable VDD_CPU */ |
| 146 | enable_cpu_power_rail(); |
| 147 | |
| 148 | set_cpu_running(0); |
| 149 | |
| 150 | /* Hold the CPUs in reset */ |
| 151 | reset_A9_cpu(1); |
| 152 | |
| 153 | /* Disable the CPU clock */ |
| 154 | enable_cpu_clock(0); |
| 155 | |
| 156 | /* Enable CoreSight */ |
| 157 | clock_enable_coresight(1); |
| 158 | |
| 159 | /* |
| 160 | * Set the entry point for CPU execution from reset, |
| 161 | * if it's a non-zero value. |
| 162 | */ |
| 163 | if (reset_vector) |
| 164 | writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR); |
| 165 | |
| 166 | /* Enable the CPU clock */ |
| 167 | enable_cpu_clock(1); |
| 168 | |
| 169 | /* If the CPU doesn't already have power, power it up */ |
| 170 | powerup_cpu(); |
| 171 | |
| 172 | /* Take the CPU out of reset */ |
| 173 | reset_A9_cpu(0); |
| 174 | |
| 175 | set_cpu_running(1); |
| 176 | } |