blob: 6ac45af51aaa2d7cdeef3c69c269bf27e15fa99b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Tom Warren1b245fe2012-12-11 13:34:13 +00002/*
Jimmy Zhangb9dd6212014-01-24 10:37:36 -07003 * Copyright (c) 2010-2014, NVIDIA CORPORATION. All rights reserved.
Tom Warren1b245fe2012-12-11 13:34:13 +00004 */
5
6#include <common.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06007#include <log.h>
Tom Warren1b245fe2012-12-11 13:34:13 +00008#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 Glassc05ed002020-05-10 11:40:11 -060015#include <linux/delay.h>
Masahiro Yamada09f455d2015-02-20 17:04:04 +090016#include "../cpu.h"
Tom Warren1b245fe2012-12-11 13:34:13 +000017
Stephen Warren2364e152014-05-08 09:33:45 -060018#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 Warren1b245fe2012-12-11 13:34:13 +000026#define TPS65911_I2C_ADDR 0x5A
27#define TPS65911_VDDCTRL_OP_REG 0x28
28#define TPS65911_VDDCTRL_SR_REG 0x27
Stephen Warren2364e152014-05-08 09:33:45 -060029#define TPS65911_VDDCTRL_OP_DATA (0x2400 | TPS65911_VDDCTRL_OP_REG)
Tom Warren1b245fe2012-12-11 13:34:13 +000030#define TPS65911_VDDCTRL_SR_DATA (0x0100 | TPS65911_VDDCTRL_SR_REG)
Svyatoslav Ryhel4213d522023-02-14 19:35:32 +020031
32/* In case this function is not defined */
33__weak void pmic_enable_cpu_vdd(void) {}
Tom Warren1b245fe2012-12-11 13:34:13 +000034
35static 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 Warren2364e152014-05-08 09:33:45 -060045 /* Set VDD_CORE to 1.200V. */
46#ifdef CONFIG_TEGRA_VDD_CORE_TPS62366A_SET1
Svyatoslav Ryhel4213d522023-02-14 19:35:32 +020047 tegra_i2c_ll_write(TPS62366A_I2C_ADDR,
48 TPS62366A_SET1_DATA);
Stephen Warren2364e152014-05-08 09:33:45 -060049#endif
50#ifdef CONFIG_TEGRA_VDD_CORE_TPS62361B_SET3
Svyatoslav Ryhel4213d522023-02-14 19:35:32 +020051 tegra_i2c_ll_write(TPS62361B_I2C_ADDR,
52 TPS62361B_SET3_DATA);
Stephen Warren2364e152014-05-08 09:33:45 -060053#endif
54 udelay(1000);
55
Tom Warren1b245fe2012-12-11 13:34:13 +000056 /*
57 * Bring up CPU VDD via the TPS65911x PMIC on the DVC I2C bus.
Stephen Warren2364e152014-05-08 09:33:45 -060058 * First set VDD to 1.0125V, then enable the VDD regulator.
Tom Warren1b245fe2012-12-11 13:34:13 +000059 */
Svyatoslav Ryhel4213d522023-02-14 19:35:32 +020060 tegra_i2c_ll_write(TPS65911_I2C_ADDR,
61 TPS65911_VDDCTRL_OP_DATA);
Tom Warren1b245fe2012-12-11 13:34:13 +000062 udelay(1000);
Svyatoslav Ryhel4213d522023-02-14 19:35:32 +020063 tegra_i2c_ll_write(TPS65911_I2C_ADDR,
64 TPS65911_VDDCTRL_SR_DATA);
Tom Warren1b245fe2012-12-11 13:34:13 +000065 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 */
72void 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 Warren1b245fe2012-12-11 13:34:13 +000083 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 Warrend94c2db2013-04-03 14:39:30 -070097 /* Switch MSELECT clock to PLLP (00) and use a divisor of 2 */
98 clock_ll_set_source_divisor(PERIPH_ID_MSELECT, 0, 2);
Tom Warren1b245fe2012-12-11 13:34:13 +000099
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
116static 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
124void 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 Ryhel4213d522023-02-14 19:35:32 +0200131 pmic_enable_cpu_vdd();
Tom Warren1b245fe2012-12-11 13:34:13 +0000132
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}