1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0
209f455dcSMasahiro Yamada /*
309f455dcSMasahiro Yamada * Copyright (c) 2010-2014, NVIDIA CORPORATION. All rights reserved.
409f455dcSMasahiro Yamada */
509f455dcSMasahiro Yamada
609f455dcSMasahiro Yamada #include <common.h>
709f455dcSMasahiro Yamada #include <asm/io.h>
809f455dcSMasahiro Yamada #include <asm/arch/clock.h>
909f455dcSMasahiro Yamada #include <asm/arch/flow.h>
1009f455dcSMasahiro Yamada #include <asm/arch/tegra.h>
1109f455dcSMasahiro Yamada #include <asm/arch-tegra/clk_rst.h>
1209f455dcSMasahiro Yamada #include <asm/arch-tegra/pmc.h>
1309f455dcSMasahiro Yamada #include <asm/arch-tegra/tegra_i2c.h>
1409f455dcSMasahiro Yamada #include "../cpu.h"
1509f455dcSMasahiro Yamada
1609f455dcSMasahiro Yamada /* Tegra30-specific CPU init code */
tegra_i2c_ll_write_addr(uint addr,uint config)1709f455dcSMasahiro Yamada void tegra_i2c_ll_write_addr(uint addr, uint config)
1809f455dcSMasahiro Yamada {
1909f455dcSMasahiro Yamada struct i2c_ctlr *reg = (struct i2c_ctlr *)TEGRA_DVC_BASE;
2009f455dcSMasahiro Yamada
2109f455dcSMasahiro Yamada writel(addr, ®->cmd_addr0);
2209f455dcSMasahiro Yamada writel(config, ®->cnfg);
2309f455dcSMasahiro Yamada }
2409f455dcSMasahiro Yamada
tegra_i2c_ll_write_data(uint data,uint config)2509f455dcSMasahiro Yamada void tegra_i2c_ll_write_data(uint data, uint config)
2609f455dcSMasahiro Yamada {
2709f455dcSMasahiro Yamada struct i2c_ctlr *reg = (struct i2c_ctlr *)TEGRA_DVC_BASE;
2809f455dcSMasahiro Yamada
2909f455dcSMasahiro Yamada writel(data, ®->cmd_data1);
3009f455dcSMasahiro Yamada writel(config, ®->cnfg);
3109f455dcSMasahiro Yamada }
3209f455dcSMasahiro Yamada
3309f455dcSMasahiro Yamada #define TPS62366A_I2C_ADDR 0xC0
3409f455dcSMasahiro Yamada #define TPS62366A_SET1_REG 0x01
3509f455dcSMasahiro Yamada #define TPS62366A_SET1_DATA (0x4600 | TPS62366A_SET1_REG)
3609f455dcSMasahiro Yamada
3709f455dcSMasahiro Yamada #define TPS62361B_I2C_ADDR 0xC0
3809f455dcSMasahiro Yamada #define TPS62361B_SET3_REG 0x03
3909f455dcSMasahiro Yamada #define TPS62361B_SET3_DATA (0x4600 | TPS62361B_SET3_REG)
4009f455dcSMasahiro Yamada
4109f455dcSMasahiro Yamada #define TPS65911_I2C_ADDR 0x5A
4209f455dcSMasahiro Yamada #define TPS65911_VDDCTRL_OP_REG 0x28
4309f455dcSMasahiro Yamada #define TPS65911_VDDCTRL_SR_REG 0x27
4409f455dcSMasahiro Yamada #define TPS65911_VDDCTRL_OP_DATA (0x2400 | TPS65911_VDDCTRL_OP_REG)
4509f455dcSMasahiro Yamada #define TPS65911_VDDCTRL_SR_DATA (0x0100 | TPS65911_VDDCTRL_SR_REG)
4609f455dcSMasahiro Yamada #define I2C_SEND_2_BYTES 0x0A02
4709f455dcSMasahiro Yamada
enable_cpu_power_rail(void)4809f455dcSMasahiro Yamada static void enable_cpu_power_rail(void)
4909f455dcSMasahiro Yamada {
5009f455dcSMasahiro Yamada struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE;
5109f455dcSMasahiro Yamada u32 reg;
5209f455dcSMasahiro Yamada
5309f455dcSMasahiro Yamada debug("enable_cpu_power_rail entry\n");
5409f455dcSMasahiro Yamada reg = readl(&pmc->pmc_cntrl);
5509f455dcSMasahiro Yamada reg |= CPUPWRREQ_OE;
5609f455dcSMasahiro Yamada writel(reg, &pmc->pmc_cntrl);
5709f455dcSMasahiro Yamada
5809f455dcSMasahiro Yamada /* Set VDD_CORE to 1.200V. */
5909f455dcSMasahiro Yamada #ifdef CONFIG_TEGRA_VDD_CORE_TPS62366A_SET1
6009f455dcSMasahiro Yamada tegra_i2c_ll_write_addr(TPS62366A_I2C_ADDR, 2);
6109f455dcSMasahiro Yamada tegra_i2c_ll_write_data(TPS62366A_SET1_DATA, I2C_SEND_2_BYTES);
6209f455dcSMasahiro Yamada #endif
6309f455dcSMasahiro Yamada #ifdef CONFIG_TEGRA_VDD_CORE_TPS62361B_SET3
6409f455dcSMasahiro Yamada tegra_i2c_ll_write_addr(TPS62361B_I2C_ADDR, 2);
6509f455dcSMasahiro Yamada tegra_i2c_ll_write_data(TPS62361B_SET3_DATA, I2C_SEND_2_BYTES);
6609f455dcSMasahiro Yamada #endif
6709f455dcSMasahiro Yamada udelay(1000);
6809f455dcSMasahiro Yamada
6909f455dcSMasahiro Yamada /*
7009f455dcSMasahiro Yamada * Bring up CPU VDD via the TPS65911x PMIC on the DVC I2C bus.
7109f455dcSMasahiro Yamada * First set VDD to 1.0125V, then enable the VDD regulator.
7209f455dcSMasahiro Yamada */
7309f455dcSMasahiro Yamada tegra_i2c_ll_write_addr(TPS65911_I2C_ADDR, 2);
7409f455dcSMasahiro Yamada tegra_i2c_ll_write_data(TPS65911_VDDCTRL_OP_DATA, I2C_SEND_2_BYTES);
7509f455dcSMasahiro Yamada udelay(1000);
7609f455dcSMasahiro Yamada tegra_i2c_ll_write_data(TPS65911_VDDCTRL_SR_DATA, I2C_SEND_2_BYTES);
7709f455dcSMasahiro Yamada udelay(10 * 1000);
7809f455dcSMasahiro Yamada }
7909f455dcSMasahiro Yamada
8009f455dcSMasahiro Yamada /**
8109f455dcSMasahiro Yamada * The T30 requires some special clock initialization, including setting up
8209f455dcSMasahiro Yamada * the dvc i2c, turning on mselect and selecting the G CPU cluster
8309f455dcSMasahiro Yamada */
t30_init_clocks(void)8409f455dcSMasahiro Yamada void t30_init_clocks(void)
8509f455dcSMasahiro Yamada {
8609f455dcSMasahiro Yamada struct clk_rst_ctlr *clkrst =
8709f455dcSMasahiro Yamada (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE;
8809f455dcSMasahiro Yamada struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
8909f455dcSMasahiro Yamada u32 val;
9009f455dcSMasahiro Yamada
9109f455dcSMasahiro Yamada debug("t30_init_clocks entry\n");
9209f455dcSMasahiro Yamada /* Set active CPU cluster to G */
9309f455dcSMasahiro Yamada clrbits_le32(flow->cluster_control, 1 << 0);
9409f455dcSMasahiro Yamada
9509f455dcSMasahiro Yamada writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div);
9609f455dcSMasahiro Yamada
9709f455dcSMasahiro Yamada val = (0 << CLK_SYS_RATE_HCLK_DISABLE_SHIFT) |
9809f455dcSMasahiro Yamada (1 << CLK_SYS_RATE_AHB_RATE_SHIFT) |
9909f455dcSMasahiro Yamada (0 << CLK_SYS_RATE_PCLK_DISABLE_SHIFT) |
10009f455dcSMasahiro Yamada (0 << CLK_SYS_RATE_APB_RATE_SHIFT);
10109f455dcSMasahiro Yamada writel(val, &clkrst->crc_clk_sys_rate);
10209f455dcSMasahiro Yamada
10309f455dcSMasahiro Yamada /* Put i2c, mselect in reset and enable clocks */
10409f455dcSMasahiro Yamada reset_set_enable(PERIPH_ID_DVC_I2C, 1);
10509f455dcSMasahiro Yamada clock_set_enable(PERIPH_ID_DVC_I2C, 1);
10609f455dcSMasahiro Yamada reset_set_enable(PERIPH_ID_MSELECT, 1);
10709f455dcSMasahiro Yamada clock_set_enable(PERIPH_ID_MSELECT, 1);
10809f455dcSMasahiro Yamada
10909f455dcSMasahiro Yamada /* Switch MSELECT clock to PLLP (00) and use a divisor of 2 */
11009f455dcSMasahiro Yamada clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0, 2);
11109f455dcSMasahiro Yamada
11209f455dcSMasahiro Yamada /*
11309f455dcSMasahiro Yamada * Our high-level clock routines are not available prior to
11409f455dcSMasahiro Yamada * relocation. We use the low-level functions which require a
11509f455dcSMasahiro Yamada * hard-coded divisor. Use CLK_M with divide by (n + 1 = 17)
11609f455dcSMasahiro Yamada */
11709f455dcSMasahiro Yamada clock_ll_set_source_divisor(PERIPH_ID_DVC_I2C, 3, 16);
11809f455dcSMasahiro Yamada
11909f455dcSMasahiro Yamada /*
12009f455dcSMasahiro Yamada * Give clocks time to stabilize, then take i2c and mselect out of
12109f455dcSMasahiro Yamada * reset
12209f455dcSMasahiro Yamada */
12309f455dcSMasahiro Yamada udelay(1000);
12409f455dcSMasahiro Yamada reset_set_enable(PERIPH_ID_DVC_I2C, 0);
12509f455dcSMasahiro Yamada reset_set_enable(PERIPH_ID_MSELECT, 0);
12609f455dcSMasahiro Yamada }
12709f455dcSMasahiro Yamada
set_cpu_running(int run)12809f455dcSMasahiro Yamada static void set_cpu_running(int run)
12909f455dcSMasahiro Yamada {
13009f455dcSMasahiro Yamada struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE;
13109f455dcSMasahiro Yamada
13209f455dcSMasahiro Yamada debug("set_cpu_running entry, run = %d\n", run);
13309f455dcSMasahiro Yamada writel(run ? FLOW_MODE_NONE : FLOW_MODE_STOP, &flow->halt_cpu_events);
13409f455dcSMasahiro Yamada }
13509f455dcSMasahiro Yamada
start_cpu(u32 reset_vector)13609f455dcSMasahiro Yamada void start_cpu(u32 reset_vector)
13709f455dcSMasahiro Yamada {
13809f455dcSMasahiro Yamada debug("start_cpu entry, reset_vector = %x\n", reset_vector);
13909f455dcSMasahiro Yamada t30_init_clocks();
14009f455dcSMasahiro Yamada
14109f455dcSMasahiro Yamada /* Enable VDD_CPU */
14209f455dcSMasahiro Yamada enable_cpu_power_rail();
14309f455dcSMasahiro Yamada
14409f455dcSMasahiro Yamada set_cpu_running(0);
14509f455dcSMasahiro Yamada
14609f455dcSMasahiro Yamada /* Hold the CPUs in reset */
14709f455dcSMasahiro Yamada reset_A9_cpu(1);
14809f455dcSMasahiro Yamada
14909f455dcSMasahiro Yamada /* Disable the CPU clock */
15009f455dcSMasahiro Yamada enable_cpu_clock(0);
15109f455dcSMasahiro Yamada
15209f455dcSMasahiro Yamada /* Enable CoreSight */
15309f455dcSMasahiro Yamada clock_enable_coresight(1);
15409f455dcSMasahiro Yamada
15509f455dcSMasahiro Yamada /*
15609f455dcSMasahiro Yamada * Set the entry point for CPU execution from reset,
15709f455dcSMasahiro Yamada * if it's a non-zero value.
15809f455dcSMasahiro Yamada */
15909f455dcSMasahiro Yamada if (reset_vector)
16009f455dcSMasahiro Yamada writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR);
16109f455dcSMasahiro Yamada
16209f455dcSMasahiro Yamada /* Enable the CPU clock */
16309f455dcSMasahiro Yamada enable_cpu_clock(1);
16409f455dcSMasahiro Yamada
16509f455dcSMasahiro Yamada /* If the CPU doesn't already have power, power it up */
16609f455dcSMasahiro Yamada powerup_cpu();
16709f455dcSMasahiro Yamada
16809f455dcSMasahiro Yamada /* Take the CPU out of reset */
16909f455dcSMasahiro Yamada reset_A9_cpu(0);
17009f455dcSMasahiro Yamada
17109f455dcSMasahiro Yamada set_cpu_running(1);
17209f455dcSMasahiro Yamada }
173