Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 2 | /* |
Jimmy Zhang | b9dd621 | 2014-01-24 10:37:36 -0700 | [diff] [blame] | 3 | * Copyright (c) 2010-2014, NVIDIA CORPORATION. All rights reserved. |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/clock.h> |
| 10 | #include <asm/arch/flow.h> |
| 11 | #include <asm/arch/tegra.h> |
| 12 | #include <asm/arch-tegra/clk_rst.h> |
| 13 | #include <asm/arch-tegra/pmc.h> |
| 14 | #include <asm/arch-tegra/tegra_i2c.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
Masahiro Yamada | 09f455d | 2015-02-20 17:04:04 +0900 | [diff] [blame] | 16 | #include "../cpu.h" |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 17 | |
Stephen Warren | 2364e15 | 2014-05-08 09:33:45 -0600 | [diff] [blame] | 18 | #define TPS62366A_I2C_ADDR 0xC0 |
| 19 | #define TPS62366A_SET1_REG 0x01 |
| 20 | #define TPS62366A_SET1_DATA (0x4600 | TPS62366A_SET1_REG) |
| 21 | |
| 22 | #define TPS62361B_I2C_ADDR 0xC0 |
| 23 | #define TPS62361B_SET3_REG 0x03 |
| 24 | #define TPS62361B_SET3_DATA (0x4600 | TPS62361B_SET3_REG) |
| 25 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 26 | #define TPS65911_I2C_ADDR 0x5A |
| 27 | #define TPS65911_VDDCTRL_OP_REG 0x28 |
| 28 | #define TPS65911_VDDCTRL_SR_REG 0x27 |
Stephen Warren | 2364e15 | 2014-05-08 09:33:45 -0600 | [diff] [blame] | 29 | #define TPS65911_VDDCTRL_OP_DATA (0x2400 | TPS65911_VDDCTRL_OP_REG) |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 30 | #define TPS65911_VDDCTRL_SR_DATA (0x0100 | TPS65911_VDDCTRL_SR_REG) |
Svyatoslav Ryhel | 4213d52 | 2023-02-14 19:35:32 +0200 | [diff] [blame^] | 31 | |
| 32 | /* In case this function is not defined */ |
| 33 | __weak void pmic_enable_cpu_vdd(void) {} |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 34 | |
| 35 | static void enable_cpu_power_rail(void) |
| 36 | { |
| 37 | struct pmc_ctlr *pmc = (struct pmc_ctlr *)NV_PA_PMC_BASE; |
| 38 | u32 reg; |
| 39 | |
| 40 | debug("enable_cpu_power_rail entry\n"); |
| 41 | reg = readl(&pmc->pmc_cntrl); |
| 42 | reg |= CPUPWRREQ_OE; |
| 43 | writel(reg, &pmc->pmc_cntrl); |
| 44 | |
Stephen Warren | 2364e15 | 2014-05-08 09:33:45 -0600 | [diff] [blame] | 45 | /* Set VDD_CORE to 1.200V. */ |
| 46 | #ifdef CONFIG_TEGRA_VDD_CORE_TPS62366A_SET1 |
Svyatoslav Ryhel | 4213d52 | 2023-02-14 19:35:32 +0200 | [diff] [blame^] | 47 | tegra_i2c_ll_write(TPS62366A_I2C_ADDR, |
| 48 | TPS62366A_SET1_DATA); |
Stephen Warren | 2364e15 | 2014-05-08 09:33:45 -0600 | [diff] [blame] | 49 | #endif |
| 50 | #ifdef CONFIG_TEGRA_VDD_CORE_TPS62361B_SET3 |
Svyatoslav Ryhel | 4213d52 | 2023-02-14 19:35:32 +0200 | [diff] [blame^] | 51 | tegra_i2c_ll_write(TPS62361B_I2C_ADDR, |
| 52 | TPS62361B_SET3_DATA); |
Stephen Warren | 2364e15 | 2014-05-08 09:33:45 -0600 | [diff] [blame] | 53 | #endif |
| 54 | udelay(1000); |
| 55 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 56 | /* |
| 57 | * Bring up CPU VDD via the TPS65911x PMIC on the DVC I2C bus. |
Stephen Warren | 2364e15 | 2014-05-08 09:33:45 -0600 | [diff] [blame] | 58 | * First set VDD to 1.0125V, then enable the VDD regulator. |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 59 | */ |
Svyatoslav Ryhel | 4213d52 | 2023-02-14 19:35:32 +0200 | [diff] [blame^] | 60 | tegra_i2c_ll_write(TPS65911_I2C_ADDR, |
| 61 | TPS65911_VDDCTRL_OP_DATA); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 62 | udelay(1000); |
Svyatoslav Ryhel | 4213d52 | 2023-02-14 19:35:32 +0200 | [diff] [blame^] | 63 | tegra_i2c_ll_write(TPS65911_I2C_ADDR, |
| 64 | TPS65911_VDDCTRL_SR_DATA); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 65 | udelay(10 * 1000); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * The T30 requires some special clock initialization, including setting up |
| 70 | * the dvc i2c, turning on mselect and selecting the G CPU cluster |
| 71 | */ |
| 72 | void t30_init_clocks(void) |
| 73 | { |
| 74 | struct clk_rst_ctlr *clkrst = |
| 75 | (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 76 | struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE; |
| 77 | u32 val; |
| 78 | |
| 79 | debug("t30_init_clocks entry\n"); |
| 80 | /* Set active CPU cluster to G */ |
| 81 | clrbits_le32(flow->cluster_control, 1 << 0); |
| 82 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 83 | writel(SUPER_SCLK_ENB_MASK, &clkrst->crc_super_sclk_div); |
| 84 | |
| 85 | val = (0 << CLK_SYS_RATE_HCLK_DISABLE_SHIFT) | |
| 86 | (1 << CLK_SYS_RATE_AHB_RATE_SHIFT) | |
| 87 | (0 << CLK_SYS_RATE_PCLK_DISABLE_SHIFT) | |
| 88 | (0 << CLK_SYS_RATE_APB_RATE_SHIFT); |
| 89 | writel(val, &clkrst->crc_clk_sys_rate); |
| 90 | |
| 91 | /* Put i2c, mselect in reset and enable clocks */ |
| 92 | reset_set_enable(PERIPH_ID_DVC_I2C, 1); |
| 93 | clock_set_enable(PERIPH_ID_DVC_I2C, 1); |
| 94 | reset_set_enable(PERIPH_ID_MSELECT, 1); |
| 95 | clock_set_enable(PERIPH_ID_MSELECT, 1); |
| 96 | |
Tom Warren | d94c2db | 2013-04-03 14:39:30 -0700 | [diff] [blame] | 97 | /* Switch MSELECT clock to PLLP (00) and use a divisor of 2 */ |
| 98 | clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0, 2); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 99 | |
| 100 | /* |
| 101 | * Our high-level clock routines are not available prior to |
| 102 | * relocation. We use the low-level functions which require a |
| 103 | * hard-coded divisor. Use CLK_M with divide by (n + 1 = 17) |
| 104 | */ |
| 105 | clock_ll_set_source_divisor(PERIPH_ID_DVC_I2C, 3, 16); |
| 106 | |
| 107 | /* |
| 108 | * Give clocks time to stabilize, then take i2c and mselect out of |
| 109 | * reset |
| 110 | */ |
| 111 | udelay(1000); |
| 112 | reset_set_enable(PERIPH_ID_DVC_I2C, 0); |
| 113 | reset_set_enable(PERIPH_ID_MSELECT, 0); |
| 114 | } |
| 115 | |
| 116 | static void set_cpu_running(int run) |
| 117 | { |
| 118 | struct flow_ctlr *flow = (struct flow_ctlr *)NV_PA_FLOW_BASE; |
| 119 | |
| 120 | debug("set_cpu_running entry, run = %d\n", run); |
| 121 | writel(run ? FLOW_MODE_NONE : FLOW_MODE_STOP, &flow->halt_cpu_events); |
| 122 | } |
| 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 | |
| 129 | /* Enable VDD_CPU */ |
| 130 | enable_cpu_power_rail(); |
Svyatoslav Ryhel | 4213d52 | 2023-02-14 19:35:32 +0200 | [diff] [blame^] | 131 | pmic_enable_cpu_vdd(); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 132 | |
| 133 | set_cpu_running(0); |
| 134 | |
| 135 | /* Hold the CPUs in reset */ |
| 136 | reset_A9_cpu(1); |
| 137 | |
| 138 | /* Disable the CPU clock */ |
| 139 | enable_cpu_clock(0); |
| 140 | |
| 141 | /* Enable CoreSight */ |
| 142 | clock_enable_coresight(1); |
| 143 | |
| 144 | /* |
| 145 | * Set the entry point for CPU execution from reset, |
| 146 | * if it's a non-zero value. |
| 147 | */ |
| 148 | if (reset_vector) |
| 149 | writel(reset_vector, EXCEP_VECTOR_CPU_RESET_VECTOR); |
| 150 | |
| 151 | /* Enable the CPU clock */ |
| 152 | enable_cpu_clock(1); |
| 153 | |
| 154 | /* If the CPU doesn't already have power, power it up */ |
| 155 | powerup_cpu(); |
| 156 | |
| 157 | /* Take the CPU out of reset */ |
| 158 | reset_A9_cpu(0); |
| 159 | |
| 160 | set_cpu_running(1); |
| 161 | } |