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