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 | /* |
Thierry Reding | f9ec2ec | 2019-04-15 11:32:25 +0200 | [diff] [blame] | 3 | * Copyright (c) 2010-2019, 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/gp_padctrl.h> |
| 11 | #include <asm/arch/pinmux.h> |
| 12 | #include <asm/arch/tegra.h> |
| 13 | #include <asm/arch-tegra/clk_rst.h> |
| 14 | #include <asm/arch-tegra/pmc.h> |
| 15 | #include <asm/arch-tegra/scu.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 16 | #include <linux/delay.h> |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 17 | #include "cpu.h" |
| 18 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 19 | int get_num_cpus(void) |
| 20 | { |
Tom Warren | 4040ec1 | 2013-01-28 13:32:08 +0000 | [diff] [blame] | 21 | struct apb_misc_gp_ctlr *gp; |
| 22 | uint rev; |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 23 | debug("%s entry\n", __func__); |
Tom Warren | 4040ec1 | 2013-01-28 13:32:08 +0000 | [diff] [blame] | 24 | |
| 25 | gp = (struct apb_misc_gp_ctlr *)NV_PA_APB_MISC_GP_BASE; |
| 26 | rev = (readl(&gp->hidrev) & HIDREV_CHIPID_MASK) >> HIDREV_CHIPID_SHIFT; |
| 27 | |
| 28 | switch (rev) { |
| 29 | case CHIPID_TEGRA20: |
| 30 | return 2; |
| 31 | break; |
| 32 | case CHIPID_TEGRA30: |
| 33 | case CHIPID_TEGRA114: |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 34 | case CHIPID_TEGRA124: |
| 35 | case CHIPID_TEGRA210: |
Tom Warren | 4040ec1 | 2013-01-28 13:32:08 +0000 | [diff] [blame] | 36 | default: |
| 37 | return 4; |
| 38 | break; |
| 39 | } |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* |
| 43 | * Timing tables for each SOC for all four oscillator options. |
| 44 | */ |
| 45 | struct clk_pll_table tegra_pll_x_table[TEGRA_SOC_CNT][CLOCK_OSC_FREQ_COUNT] = { |
Jimmy Zhang | 44de8e2 | 2013-09-23 22:07:49 +0200 | [diff] [blame] | 46 | /* |
| 47 | * T20: 1 GHz |
| 48 | * |
| 49 | * Register Field Bits Width |
| 50 | * ------------------------------ |
| 51 | * PLLX_BASE p 22:20 3 |
| 52 | * PLLX_BASE n 17: 8 10 |
| 53 | * PLLX_BASE m 4: 0 5 |
| 54 | * PLLX_MISC cpcon 11: 8 4 |
| 55 | */ |
| 56 | { |
| 57 | { .n = 1000, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */ |
| 58 | { .n = 625, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */ |
| 59 | { .n = 1000, .m = 12, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */ |
| 60 | { .n = 1000, .m = 26, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */ |
Tom Warren | 3e8650c | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 61 | { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 38.4 MHz (N/A) */ |
| 62 | { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 48.0 MHz (N/A) */ |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 63 | }, |
Jimmy Zhang | 44de8e2 | 2013-09-23 22:07:49 +0200 | [diff] [blame] | 64 | /* |
| 65 | * T25: 1.2 GHz |
| 66 | * |
| 67 | * Register Field Bits Width |
| 68 | * ------------------------------ |
| 69 | * PLLX_BASE p 22:20 3 |
| 70 | * PLLX_BASE n 17: 8 10 |
| 71 | * PLLX_BASE m 4: 0 5 |
| 72 | * PLLX_MISC cpcon 11: 8 4 |
| 73 | */ |
| 74 | { |
| 75 | { .n = 923, .m = 10, .p = 0, .cpcon = 12 }, /* OSC: 13.0 MHz */ |
| 76 | { .n = 750, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */ |
| 77 | { .n = 600, .m = 6, .p = 0, .cpcon = 12 }, /* OSC: 12.0 MHz */ |
| 78 | { .n = 600, .m = 13, .p = 0, .cpcon = 12 }, /* OSC: 26.0 MHz */ |
Tom Warren | 3e8650c | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 79 | { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 38.4 MHz (N/A) */ |
| 80 | { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 48.0 MHz (N/A) */ |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 81 | }, |
Jimmy Zhang | 44de8e2 | 2013-09-23 22:07:49 +0200 | [diff] [blame] | 82 | /* |
Stephen Warren | 2364e15 | 2014-05-08 09:33:45 -0600 | [diff] [blame] | 83 | * T30: 600 MHz |
Jimmy Zhang | 44de8e2 | 2013-09-23 22:07:49 +0200 | [diff] [blame] | 84 | * |
| 85 | * Register Field Bits Width |
| 86 | * ------------------------------ |
| 87 | * PLLX_BASE p 22:20 3 |
| 88 | * PLLX_BASE n 17: 8 10 |
| 89 | * PLLX_BASE m 4: 0 5 |
| 90 | * PLLX_MISC cpcon 11: 8 4 |
| 91 | */ |
| 92 | { |
Stephen Warren | 2364e15 | 2014-05-08 09:33:45 -0600 | [diff] [blame] | 93 | { .n = 600, .m = 13, .p = 0, .cpcon = 8 }, /* OSC: 13.0 MHz */ |
| 94 | { .n = 500, .m = 16, .p = 0, .cpcon = 8 }, /* OSC: 19.2 MHz */ |
| 95 | { .n = 600, .m = 12, .p = 0, .cpcon = 8 }, /* OSC: 12.0 MHz */ |
| 96 | { .n = 600, .m = 26, .p = 0, .cpcon = 8 }, /* OSC: 26.0 MHz */ |
Tom Warren | 3e8650c | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 97 | { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 38.4 MHz (N/A) */ |
| 98 | { .n = 0, .m = 0, .p = 0, .cpcon = 0 }, /* OSC: 48.0 MHz (N/A) */ |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 99 | }, |
Jimmy Zhang | 44de8e2 | 2013-09-23 22:07:49 +0200 | [diff] [blame] | 100 | /* |
| 101 | * T114: 700 MHz |
| 102 | * |
| 103 | * Register Field Bits Width |
| 104 | * ------------------------------ |
| 105 | * PLLX_BASE p 23:20 4 |
| 106 | * PLLX_BASE n 15: 8 8 |
| 107 | * PLLX_BASE m 7: 0 8 |
| 108 | */ |
| 109 | { |
| 110 | { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */ |
| 111 | { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */ |
| 112 | { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */ |
| 113 | { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */ |
Tom Warren | 3e8650c | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 114 | { .n = 0, .m = 0, .p = 0 }, /* OSC: 38.4 MHz (N/A) */ |
| 115 | { .n = 0, .m = 0, .p = 0 }, /* OSC: 48.0 MHz (N/A) */ |
Tom Warren | 4040ec1 | 2013-01-28 13:32:08 +0000 | [diff] [blame] | 116 | }, |
Tom Warren | 32edd2e | 2014-01-24 12:46:14 -0700 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * T124: 700 MHz |
| 120 | * |
| 121 | * Register Field Bits Width |
| 122 | * ------------------------------ |
| 123 | * PLLX_BASE p 23:20 4 |
| 124 | * PLLX_BASE n 15: 8 8 |
| 125 | * PLLX_BASE m 7: 0 8 |
| 126 | */ |
| 127 | { |
| 128 | { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz */ |
| 129 | { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz */ |
| 130 | { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz */ |
| 131 | { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz */ |
Tom Warren | 3e8650c | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 132 | { .n = 0, .m = 0, .p = 0 }, /* OSC: 38.4 MHz (N/A) */ |
| 133 | { .n = 0, .m = 0, .p = 0 }, /* OSC: 48.0 MHz (N/A) */ |
Tom Warren | 32edd2e | 2014-01-24 12:46:14 -0700 | [diff] [blame] | 134 | }, |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * T210: 700 MHz |
| 138 | * |
| 139 | * Register Field Bits Width |
| 140 | * ------------------------------ |
| 141 | * PLLX_BASE p 24:20 5 |
| 142 | * PLLX_BASE n 15: 8 8 |
| 143 | * PLLX_BASE m 7: 0 8 |
| 144 | */ |
| 145 | { |
| 146 | { .n = 108, .m = 1, .p = 1 }, /* OSC: 13.0 MHz = 702 MHz*/ |
| 147 | { .n = 73, .m = 1, .p = 1 }, /* OSC: 19.2 MHz = 700.8 MHz*/ |
| 148 | { .n = 116, .m = 1, .p = 1 }, /* OSC: 12.0 MHz = 696 MHz*/ |
| 149 | { .n = 108, .m = 2, .p = 1 }, /* OSC: 26.0 MHz = 702 MHz*/ |
Tom Warren | 3e8650c | 2015-06-22 13:03:44 -0700 | [diff] [blame] | 150 | { .n = 36, .m = 1, .p = 1 }, /* OSC: 38.4 MHz = 691.2 MHz */ |
| 151 | { .n = 58, .m = 2, .p = 1 }, /* OSC: 48.0 MHz = 696 MHz */ |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 152 | }, |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
Tom Warren | 32edd2e | 2014-01-24 12:46:14 -0700 | [diff] [blame] | 155 | static inline void pllx_set_iddq(void) |
| 156 | { |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 157 | #if defined(CONFIG_TEGRA124) || defined(CONFIG_TEGRA210) |
Tom Warren | 32edd2e | 2014-01-24 12:46:14 -0700 | [diff] [blame] | 158 | struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 159 | u32 reg; |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 160 | debug("%s entry\n", __func__); |
Tom Warren | 32edd2e | 2014-01-24 12:46:14 -0700 | [diff] [blame] | 161 | |
| 162 | /* Disable IDDQ */ |
| 163 | reg = readl(&clkrst->crc_pllx_misc3); |
| 164 | reg &= ~PLLX_IDDQ_MASK; |
| 165 | writel(reg, &clkrst->crc_pllx_misc3); |
| 166 | udelay(2); |
| 167 | debug("%s: IDDQ: PLLX IDDQ = 0x%08X\n", __func__, |
| 168 | readl(&clkrst->crc_pllx_misc3)); |
| 169 | #endif |
| 170 | } |
| 171 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 172 | int pllx_set_rate(struct clk_pll_simple *pll , u32 divn, u32 divm, |
| 173 | u32 divp, u32 cpcon) |
| 174 | { |
Tom Warren | 722e000 | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 175 | struct clk_pll_info *pllinfo = &tegra_pll_info_table[CLOCK_ID_XCPU]; |
Thierry Reding | 4475c77 | 2013-10-01 17:04:45 +0200 | [diff] [blame] | 176 | int chip = tegra_get_chip(); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 177 | u32 reg; |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 178 | debug("%s entry\n", __func__); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 179 | |
| 180 | /* If PLLX is already enabled, just return */ |
| 181 | if (readl(&pll->pll_base) & PLL_ENABLE_MASK) { |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 182 | debug("%s: PLLX already enabled, returning\n", __func__); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 183 | return 0; |
| 184 | } |
| 185 | |
Tom Warren | 32edd2e | 2014-01-24 12:46:14 -0700 | [diff] [blame] | 186 | pllx_set_iddq(); |
| 187 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 188 | /* Set BYPASS, m, n and p to PLLX_BASE */ |
Tom Warren | 722e000 | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 189 | reg = PLL_BYPASS_MASK | (divm << pllinfo->m_shift); |
| 190 | reg |= (divn << pllinfo->n_shift) | (divp << pllinfo->p_shift); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 191 | writel(reg, &pll->pll_base); |
| 192 | |
| 193 | /* Set cpcon to PLLX_MISC */ |
Thierry Reding | 4475c77 | 2013-10-01 17:04:45 +0200 | [diff] [blame] | 194 | if (chip == CHIPID_TEGRA20 || chip == CHIPID_TEGRA30) |
Tom Warren | 722e000 | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 195 | reg = (cpcon << pllinfo->kcp_shift); |
Thierry Reding | 4475c77 | 2013-10-01 17:04:45 +0200 | [diff] [blame] | 196 | else |
| 197 | reg = 0; |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 198 | |
Tom Warren | 722e000 | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 199 | /* |
| 200 | * TODO(twarren@nvidia.com) Check which SoCs use DCCON |
| 201 | * and add to pllinfo table if needed! |
| 202 | */ |
| 203 | /* Set dccon to PLLX_MISC if freq > 600MHz */ |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 204 | if (divn > 600) |
| 205 | reg |= (1 << PLL_DCCON_SHIFT); |
| 206 | writel(reg, &pll->pll_misc); |
| 207 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 208 | /* Disable BYPASS */ |
Stephen Warren | 41447fb | 2014-01-24 12:46:09 -0700 | [diff] [blame] | 209 | reg = readl(&pll->pll_base); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 210 | reg &= ~PLL_BYPASS_MASK; |
| 211 | writel(reg, &pll->pll_base); |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 212 | debug("%s: base = 0x%08X\n", __func__, reg); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 213 | |
Tom Warren | 722e000 | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 214 | /* Set lock_enable to PLLX_MISC if lock_ena is valid (i.e. 0-31) */ |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 215 | reg = readl(&pll->pll_misc); |
Tom Warren | 722e000 | 2015-06-25 09:50:44 -0700 | [diff] [blame] | 216 | if (pllinfo->lock_ena < 32) |
| 217 | reg |= (1 << pllinfo->lock_ena); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 218 | writel(reg, &pll->pll_misc); |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 219 | debug("%s: misc = 0x%08X\n", __func__, reg); |
Stephen Warren | 41447fb | 2014-01-24 12:46:09 -0700 | [diff] [blame] | 220 | |
| 221 | /* Enable PLLX last, once it's all configured */ |
| 222 | reg = readl(&pll->pll_base); |
| 223 | reg |= PLL_ENABLE_MASK; |
| 224 | writel(reg, &pll->pll_base); |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 225 | debug("%s: base final = 0x%08X\n", __func__, reg); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | |
| 230 | void init_pllx(void) |
| 231 | { |
| 232 | struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 233 | struct clk_pll_simple *pll = &clkrst->crc_pll_simple[SIMPLE_PLLX]; |
Tom Warren | 49493cb | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 234 | int soc_type, sku_info, chip_sku; |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 235 | enum clock_osc_freq osc; |
| 236 | struct clk_pll_table *sel; |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 237 | debug("%s entry\n", __func__); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 238 | |
Tom Warren | 49493cb | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 239 | /* get SOC (chip) type */ |
| 240 | soc_type = tegra_get_chip(); |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 241 | debug("%s: SoC = 0x%02X\n", __func__, soc_type); |
Tom Warren | 49493cb | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 242 | |
| 243 | /* get SKU info */ |
| 244 | sku_info = tegra_get_sku_info(); |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 245 | debug("%s: SKU info byte = 0x%02X\n", __func__, sku_info); |
Tom Warren | 49493cb | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 246 | |
| 247 | /* get chip SKU, combo of the above info */ |
| 248 | chip_sku = tegra_get_chip_sku(); |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 249 | debug("%s: Chip SKU = %d\n", __func__, chip_sku); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 250 | |
| 251 | /* get osc freq */ |
| 252 | osc = clock_get_osc_freq(); |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 253 | debug("%s: osc = %d\n", __func__, osc); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 254 | |
| 255 | /* set pllx */ |
Tom Warren | 49493cb | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 256 | sel = &tegra_pll_x_table[chip_sku][osc]; |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 257 | pllx_set_rate(pll, sel->n, sel->m, sel->p, sel->cpcon); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | void enable_cpu_clock(int enable) |
| 261 | { |
| 262 | struct clk_rst_ctlr *clkrst = (struct clk_rst_ctlr *)NV_PA_CLK_RST_BASE; |
| 263 | u32 clk; |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 264 | debug("%s entry\n", __func__); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * NOTE: |
| 268 | * Regardless of whether the request is to enable or disable the CPU |
| 269 | * clock, every processor in the CPU complex except the master (CPU 0) |
| 270 | * will have it's clock stopped because the AVP only talks to the |
| 271 | * master. |
| 272 | */ |
| 273 | |
| 274 | if (enable) { |
| 275 | /* Initialize PLLX */ |
| 276 | init_pllx(); |
| 277 | |
| 278 | /* Wait until all clocks are stable */ |
| 279 | udelay(PLL_STABILIZATION_DELAY); |
| 280 | |
| 281 | writel(CCLK_BURST_POLICY, &clkrst->crc_cclk_brst_pol); |
| 282 | writel(SUPER_CCLK_DIVIDER, &clkrst->crc_super_cclk_div); |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * Read the register containing the individual CPU clock enables and |
| 287 | * always stop the clocks to CPUs > 0. |
| 288 | */ |
| 289 | clk = readl(&clkrst->crc_clk_cpu_cmplx); |
| 290 | clk |= 1 << CPU1_CLK_STP_SHIFT; |
Tom Warren | 4040ec1 | 2013-01-28 13:32:08 +0000 | [diff] [blame] | 291 | if (get_num_cpus() == 4) |
| 292 | clk |= (1 << CPU2_CLK_STP_SHIFT) + (1 << CPU3_CLK_STP_SHIFT); |
| 293 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 294 | /* Stop/Unstop the CPU clock */ |
| 295 | clk &= ~CPU0_CLK_STP_MASK; |
| 296 | clk |= !enable << CPU0_CLK_STP_SHIFT; |
| 297 | writel(clk, &clkrst->crc_clk_cpu_cmplx); |
| 298 | |
| 299 | clock_enable(PERIPH_ID_CPU); |
| 300 | } |
| 301 | |
| 302 | static int is_cpu_powered(void) |
| 303 | { |
Thierry Reding | f9ec2ec | 2019-04-15 11:32:25 +0200 | [diff] [blame] | 304 | return (tegra_pmc_readl(offsetof(struct pmc_ctlr, |
| 305 | pmc_pwrgate_status)) & CPU_PWRED) ? 1 : 0; |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | static void remove_cpu_io_clamps(void) |
| 309 | { |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 310 | u32 reg; |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 311 | debug("%s entry\n", __func__); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 312 | |
| 313 | /* Remove the clamps on the CPU I/O signals */ |
Thierry Reding | f9ec2ec | 2019-04-15 11:32:25 +0200 | [diff] [blame] | 314 | reg = tegra_pmc_readl(offsetof(struct pmc_ctlr, pmc_remove_clamping)); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 315 | reg |= CPU_CLMP; |
Thierry Reding | f9ec2ec | 2019-04-15 11:32:25 +0200 | [diff] [blame] | 316 | tegra_pmc_writel(reg, offsetof(struct pmc_ctlr, pmc_remove_clamping)); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 317 | |
| 318 | /* Give I/O signals time to stabilize */ |
| 319 | udelay(IO_STABILIZATION_DELAY); |
| 320 | } |
| 321 | |
| 322 | void powerup_cpu(void) |
| 323 | { |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 324 | u32 reg; |
| 325 | int timeout = IO_STABILIZATION_DELAY; |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 326 | debug("%s entry\n", __func__); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 327 | |
| 328 | if (!is_cpu_powered()) { |
| 329 | /* Toggle the CPU power state (OFF -> ON) */ |
Thierry Reding | f9ec2ec | 2019-04-15 11:32:25 +0200 | [diff] [blame] | 330 | reg = tegra_pmc_readl(offsetof(struct pmc_ctlr, |
| 331 | pmc_pwrgate_toggle)); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 332 | reg &= PARTID_CP; |
| 333 | reg |= START_CP; |
Thierry Reding | f9ec2ec | 2019-04-15 11:32:25 +0200 | [diff] [blame] | 334 | tegra_pmc_writel(reg, |
| 335 | offsetof(struct pmc_ctlr, |
| 336 | pmc_pwrgate_toggle)); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 337 | |
| 338 | /* Wait for the power to come up */ |
| 339 | while (!is_cpu_powered()) { |
| 340 | if (timeout-- == 0) |
| 341 | printf("CPU failed to power up!\n"); |
| 342 | else |
| 343 | udelay(10); |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Remove the I/O clamps from CPU power partition. |
| 348 | * Recommended only on a Warm boot, if the CPU partition gets |
| 349 | * power gated. Shouldn't cause any harm when called after a |
| 350 | * cold boot according to HW, probably just redundant. |
| 351 | */ |
| 352 | remove_cpu_io_clamps(); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | void reset_A9_cpu(int reset) |
| 357 | { |
| 358 | /* |
| 359 | * NOTE: Regardless of whether the request is to hold the CPU in reset |
| 360 | * or take it out of reset, every processor in the CPU complex |
| 361 | * except the master (CPU 0) will be held in reset because the |
| 362 | * AVP only talks to the master. The AVP does not know that there |
| 363 | * are multiple processors in the CPU complex. |
| 364 | */ |
| 365 | int mask = crc_rst_cpu | crc_rst_de | crc_rst_debug; |
| 366 | int num_cpus = get_num_cpus(); |
| 367 | int cpu; |
| 368 | |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 369 | debug("%s entry\n", __func__); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 370 | /* Hold CPUs 1 onwards in reset, and CPU 0 if asked */ |
| 371 | for (cpu = 1; cpu < num_cpus; cpu++) |
| 372 | reset_cmplx_set_enable(cpu, mask, 1); |
| 373 | reset_cmplx_set_enable(0, mask, reset); |
| 374 | |
| 375 | /* Enable/Disable master CPU reset */ |
| 376 | reset_set_enable(PERIPH_ID_CPU, reset); |
| 377 | } |
| 378 | |
| 379 | void clock_enable_coresight(int enable) |
| 380 | { |
Tom Warren | 4040ec1 | 2013-01-28 13:32:08 +0000 | [diff] [blame] | 381 | u32 rst, src = 2; |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 382 | |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 383 | debug("%s entry\n", __func__); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 384 | clock_set_enable(PERIPH_ID_CORESIGHT, enable); |
| 385 | reset_set_enable(PERIPH_ID_CORESIGHT, !enable); |
| 386 | |
| 387 | if (enable) { |
| 388 | /* |
Tom Warren | 49493cb | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 389 | * Put CoreSight on PLLP_OUT0 and divide it down as per |
Tom Warren | 32edd2e | 2014-01-24 12:46:14 -0700 | [diff] [blame] | 390 | * PLLP base frequency based on SoC type (T20/T30+). |
Tom Warren | 49493cb | 2013-04-10 10:32:32 -0700 | [diff] [blame] | 391 | * Clock divider request would setup CSITE clock as 144MHz |
| 392 | * for PLLP base 216MHz and 204MHz for PLLP base 408MHz |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 393 | */ |
Stephen Warren | a4bcd67 | 2014-01-24 12:46:10 -0700 | [diff] [blame] | 394 | src = CLK_DIVIDER(NVBL_PLLP_KHZ, CSITE_KHZ); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 395 | clock_ll_set_source_divisor(PERIPH_ID_CSI, 0, src); |
| 396 | |
| 397 | /* Unlock the CPU CoreSight interfaces */ |
| 398 | rst = CORESIGHT_UNLOCK; |
| 399 | writel(rst, CSITE_CPU_DBG0_LAR); |
| 400 | writel(rst, CSITE_CPU_DBG1_LAR); |
Tom Warren | 4040ec1 | 2013-01-28 13:32:08 +0000 | [diff] [blame] | 401 | if (get_num_cpus() == 4) { |
| 402 | writel(rst, CSITE_CPU_DBG2_LAR); |
| 403 | writel(rst, CSITE_CPU_DBG3_LAR); |
| 404 | } |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
| 408 | void halt_avp(void) |
| 409 | { |
Tom Warren | 7aaa5a6 | 2015-03-04 16:36:00 -0700 | [diff] [blame] | 410 | debug("%s entry\n", __func__); |
| 411 | |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 412 | for (;;) { |
Stephen Warren | 716ff5c | 2014-02-03 14:03:27 -0700 | [diff] [blame] | 413 | writel(HALT_COP_EVENT_JTAG | (FLOW_MODE_STOP << 29), |
| 414 | FLOW_CTLR_HALT_COP_EVENTS); |
Tom Warren | 1b245fe | 2012-12-11 13:34:13 +0000 | [diff] [blame] | 415 | } |
| 416 | } |