Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1 | /* |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 2 | * Copyright (c) 2012, 2013, NVIDIA CORPORATION. All rights reserved. |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/slab.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/err.h> |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 21 | #include <linux/clk.h> |
Stephen Boyd | 584ac4e | 2015-06-19 15:00:46 -0700 | [diff] [blame] | 22 | #include <linux/clk-provider.h> |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 23 | |
| 24 | #include "clk.h" |
| 25 | |
| 26 | #define PLL_BASE_BYPASS BIT(31) |
| 27 | #define PLL_BASE_ENABLE BIT(30) |
| 28 | #define PLL_BASE_REF_ENABLE BIT(29) |
| 29 | #define PLL_BASE_OVERRIDE BIT(28) |
| 30 | |
| 31 | #define PLL_BASE_DIVP_SHIFT 20 |
| 32 | #define PLL_BASE_DIVP_WIDTH 3 |
| 33 | #define PLL_BASE_DIVN_SHIFT 8 |
| 34 | #define PLL_BASE_DIVN_WIDTH 10 |
| 35 | #define PLL_BASE_DIVM_SHIFT 0 |
| 36 | #define PLL_BASE_DIVM_WIDTH 5 |
| 37 | #define PLLU_POST_DIVP_MASK 0x1 |
| 38 | |
| 39 | #define PLL_MISC_DCCON_SHIFT 20 |
| 40 | #define PLL_MISC_CPCON_SHIFT 8 |
| 41 | #define PLL_MISC_CPCON_WIDTH 4 |
| 42 | #define PLL_MISC_CPCON_MASK ((1 << PLL_MISC_CPCON_WIDTH) - 1) |
| 43 | #define PLL_MISC_LFCON_SHIFT 4 |
| 44 | #define PLL_MISC_LFCON_WIDTH 4 |
| 45 | #define PLL_MISC_LFCON_MASK ((1 << PLL_MISC_LFCON_WIDTH) - 1) |
| 46 | #define PLL_MISC_VCOCON_SHIFT 0 |
| 47 | #define PLL_MISC_VCOCON_WIDTH 4 |
| 48 | #define PLL_MISC_VCOCON_MASK ((1 << PLL_MISC_VCOCON_WIDTH) - 1) |
| 49 | |
| 50 | #define OUT_OF_TABLE_CPCON 8 |
| 51 | |
| 52 | #define PMC_PLLP_WB0_OVERRIDE 0xf8 |
| 53 | #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE BIT(12) |
| 54 | #define PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE BIT(11) |
| 55 | |
| 56 | #define PLL_POST_LOCK_DELAY 50 |
| 57 | |
| 58 | #define PLLDU_LFCON_SET_DIVN 600 |
| 59 | |
| 60 | #define PLLE_BASE_DIVCML_SHIFT 24 |
Thierry Reding | d0f02ce | 2014-04-04 15:55:13 +0200 | [diff] [blame] | 61 | #define PLLE_BASE_DIVCML_MASK 0xf |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 62 | #define PLLE_BASE_DIVP_SHIFT 16 |
Thierry Reding | d0f02ce | 2014-04-04 15:55:13 +0200 | [diff] [blame] | 63 | #define PLLE_BASE_DIVP_WIDTH 6 |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 64 | #define PLLE_BASE_DIVN_SHIFT 8 |
| 65 | #define PLLE_BASE_DIVN_WIDTH 8 |
| 66 | #define PLLE_BASE_DIVM_SHIFT 0 |
| 67 | #define PLLE_BASE_DIVM_WIDTH 8 |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 68 | #define PLLE_BASE_ENABLE BIT(31) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 69 | |
| 70 | #define PLLE_MISC_SETUP_BASE_SHIFT 16 |
| 71 | #define PLLE_MISC_SETUP_BASE_MASK (0xffff << PLLE_MISC_SETUP_BASE_SHIFT) |
| 72 | #define PLLE_MISC_LOCK_ENABLE BIT(9) |
| 73 | #define PLLE_MISC_READY BIT(15) |
| 74 | #define PLLE_MISC_SETUP_EX_SHIFT 2 |
| 75 | #define PLLE_MISC_SETUP_EX_MASK (3 << PLLE_MISC_SETUP_EX_SHIFT) |
| 76 | #define PLLE_MISC_SETUP_MASK (PLLE_MISC_SETUP_BASE_MASK | \ |
| 77 | PLLE_MISC_SETUP_EX_MASK) |
| 78 | #define PLLE_MISC_SETUP_VALUE (7 << PLLE_MISC_SETUP_BASE_SHIFT) |
| 79 | |
| 80 | #define PLLE_SS_CTRL 0x68 |
Peter De Schrijver | 642fb0c | 2013-09-26 18:30:01 +0300 | [diff] [blame] | 81 | #define PLLE_SS_CNTL_BYPASS_SS BIT(10) |
| 82 | #define PLLE_SS_CNTL_INTERP_RESET BIT(11) |
| 83 | #define PLLE_SS_CNTL_SSC_BYP BIT(12) |
| 84 | #define PLLE_SS_CNTL_CENTER BIT(14) |
| 85 | #define PLLE_SS_CNTL_INVERT BIT(15) |
| 86 | #define PLLE_SS_DISABLE (PLLE_SS_CNTL_BYPASS_SS | PLLE_SS_CNTL_INTERP_RESET |\ |
| 87 | PLLE_SS_CNTL_SSC_BYP) |
| 88 | #define PLLE_SS_MAX_MASK 0x1ff |
Mark Kuo | 442f53f | 2016-01-14 14:26:42 -0500 | [diff] [blame] | 89 | #define PLLE_SS_MAX_VAL_TEGRA114 0x25 |
| 90 | #define PLLE_SS_MAX_VAL_TEGRA210 0x21 |
Peter De Schrijver | 642fb0c | 2013-09-26 18:30:01 +0300 | [diff] [blame] | 91 | #define PLLE_SS_INC_MASK (0xff << 16) |
| 92 | #define PLLE_SS_INC_VAL (0x1 << 16) |
| 93 | #define PLLE_SS_INCINTRV_MASK (0x3f << 24) |
Mark Kuo | 442f53f | 2016-01-14 14:26:42 -0500 | [diff] [blame] | 94 | #define PLLE_SS_INCINTRV_VAL_TEGRA114 (0x20 << 24) |
| 95 | #define PLLE_SS_INCINTRV_VAL_TEGRA210 (0x23 << 24) |
Peter De Schrijver | 642fb0c | 2013-09-26 18:30:01 +0300 | [diff] [blame] | 96 | #define PLLE_SS_COEFFICIENTS_MASK \ |
| 97 | (PLLE_SS_MAX_MASK | PLLE_SS_INC_MASK | PLLE_SS_INCINTRV_MASK) |
Mark Kuo | 442f53f | 2016-01-14 14:26:42 -0500 | [diff] [blame] | 98 | #define PLLE_SS_COEFFICIENTS_VAL_TEGRA114 \ |
| 99 | (PLLE_SS_MAX_VAL_TEGRA114 | PLLE_SS_INC_VAL |\ |
| 100 | PLLE_SS_INCINTRV_VAL_TEGRA114) |
| 101 | #define PLLE_SS_COEFFICIENTS_VAL_TEGRA210 \ |
| 102 | (PLLE_SS_MAX_VAL_TEGRA210 | PLLE_SS_INC_VAL |\ |
| 103 | PLLE_SS_INCINTRV_VAL_TEGRA210) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 104 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 105 | #define PLLE_AUX_PLLP_SEL BIT(2) |
Jim Lin | 2cfe167 | 2014-05-14 17:32:57 -0700 | [diff] [blame] | 106 | #define PLLE_AUX_USE_LOCKDET BIT(3) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 107 | #define PLLE_AUX_ENABLE_SWCTL BIT(4) |
Jim Lin | 2cfe167 | 2014-05-14 17:32:57 -0700 | [diff] [blame] | 108 | #define PLLE_AUX_SS_SWCTL BIT(6) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 109 | #define PLLE_AUX_SEQ_ENABLE BIT(24) |
Jim Lin | 2cfe167 | 2014-05-14 17:32:57 -0700 | [diff] [blame] | 110 | #define PLLE_AUX_SEQ_START_STATE BIT(25) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 111 | #define PLLE_AUX_PLLRE_SEL BIT(28) |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 112 | #define PLLE_AUX_SS_SEQ_INCLUDE BIT(31) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 113 | |
Jim Lin | 2cfe167 | 2014-05-14 17:32:57 -0700 | [diff] [blame] | 114 | #define XUSBIO_PLL_CFG0 0x51c |
| 115 | #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0) |
| 116 | #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL BIT(2) |
| 117 | #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET BIT(6) |
| 118 | #define XUSBIO_PLL_CFG0_SEQ_ENABLE BIT(24) |
| 119 | #define XUSBIO_PLL_CFG0_SEQ_START_STATE BIT(25) |
| 120 | |
Mikko Perttunen | 37ab366 | 2014-06-18 17:23:23 +0300 | [diff] [blame] | 121 | #define SATA_PLL_CFG0 0x490 |
| 122 | #define SATA_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0) |
Mikko Perttunen | 0e548d50b | 2014-07-08 09:30:15 +0200 | [diff] [blame] | 123 | #define SATA_PLL_CFG0_PADPLL_USE_LOCKDET BIT(2) |
| 124 | #define SATA_PLL_CFG0_SEQ_ENABLE BIT(24) |
| 125 | #define SATA_PLL_CFG0_SEQ_START_STATE BIT(25) |
Mikko Perttunen | 37ab366 | 2014-06-18 17:23:23 +0300 | [diff] [blame] | 126 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 127 | #define PLLE_MISC_PLLE_PTS BIT(8) |
| 128 | #define PLLE_MISC_IDDQ_SW_VALUE BIT(13) |
| 129 | #define PLLE_MISC_IDDQ_SW_CTRL BIT(14) |
| 130 | #define PLLE_MISC_VREG_BG_CTRL_SHIFT 4 |
| 131 | #define PLLE_MISC_VREG_BG_CTRL_MASK (3 << PLLE_MISC_VREG_BG_CTRL_SHIFT) |
| 132 | #define PLLE_MISC_VREG_CTRL_SHIFT 2 |
| 133 | #define PLLE_MISC_VREG_CTRL_MASK (2 << PLLE_MISC_VREG_CTRL_SHIFT) |
| 134 | |
| 135 | #define PLLCX_MISC_STROBE BIT(31) |
| 136 | #define PLLCX_MISC_RESET BIT(30) |
| 137 | #define PLLCX_MISC_SDM_DIV_SHIFT 28 |
| 138 | #define PLLCX_MISC_SDM_DIV_MASK (0x3 << PLLCX_MISC_SDM_DIV_SHIFT) |
| 139 | #define PLLCX_MISC_FILT_DIV_SHIFT 26 |
| 140 | #define PLLCX_MISC_FILT_DIV_MASK (0x3 << PLLCX_MISC_FILT_DIV_SHIFT) |
| 141 | #define PLLCX_MISC_ALPHA_SHIFT 18 |
| 142 | #define PLLCX_MISC_DIV_LOW_RANGE \ |
| 143 | ((0x1 << PLLCX_MISC_SDM_DIV_SHIFT) | \ |
| 144 | (0x1 << PLLCX_MISC_FILT_DIV_SHIFT)) |
| 145 | #define PLLCX_MISC_DIV_HIGH_RANGE \ |
| 146 | ((0x2 << PLLCX_MISC_SDM_DIV_SHIFT) | \ |
| 147 | (0x2 << PLLCX_MISC_FILT_DIV_SHIFT)) |
| 148 | #define PLLCX_MISC_COEF_LOW_RANGE \ |
| 149 | ((0x14 << PLLCX_MISC_KA_SHIFT) | (0x38 << PLLCX_MISC_KB_SHIFT)) |
| 150 | #define PLLCX_MISC_KA_SHIFT 2 |
| 151 | #define PLLCX_MISC_KB_SHIFT 9 |
| 152 | #define PLLCX_MISC_DEFAULT (PLLCX_MISC_COEF_LOW_RANGE | \ |
| 153 | (0x19 << PLLCX_MISC_ALPHA_SHIFT) | \ |
| 154 | PLLCX_MISC_DIV_LOW_RANGE | \ |
| 155 | PLLCX_MISC_RESET) |
| 156 | #define PLLCX_MISC1_DEFAULT 0x000d2308 |
| 157 | #define PLLCX_MISC2_DEFAULT 0x30211200 |
| 158 | #define PLLCX_MISC3_DEFAULT 0x200 |
| 159 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 160 | #define PMC_SATA_PWRGT 0x1ac |
| 161 | #define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE BIT(5) |
| 162 | #define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL BIT(4) |
| 163 | |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 164 | #define PLLSS_MISC_KCP 0 |
| 165 | #define PLLSS_MISC_KVCO 0 |
| 166 | #define PLLSS_MISC_SETUP 0 |
| 167 | #define PLLSS_EN_SDM 0 |
| 168 | #define PLLSS_EN_SSC 0 |
| 169 | #define PLLSS_EN_DITHER2 0 |
| 170 | #define PLLSS_EN_DITHER 1 |
| 171 | #define PLLSS_SDM_RESET 0 |
| 172 | #define PLLSS_CLAMP 0 |
| 173 | #define PLLSS_SDM_SSC_MAX 0 |
| 174 | #define PLLSS_SDM_SSC_MIN 0 |
| 175 | #define PLLSS_SDM_SSC_STEP 0 |
| 176 | #define PLLSS_SDM_DIN 0 |
| 177 | #define PLLSS_MISC_DEFAULT ((PLLSS_MISC_KCP << 25) | \ |
| 178 | (PLLSS_MISC_KVCO << 24) | \ |
| 179 | PLLSS_MISC_SETUP) |
| 180 | #define PLLSS_CFG_DEFAULT ((PLLSS_EN_SDM << 31) | \ |
| 181 | (PLLSS_EN_SSC << 30) | \ |
| 182 | (PLLSS_EN_DITHER2 << 29) | \ |
| 183 | (PLLSS_EN_DITHER << 28) | \ |
| 184 | (PLLSS_SDM_RESET) << 27 | \ |
| 185 | (PLLSS_CLAMP << 22)) |
| 186 | #define PLLSS_CTRL1_DEFAULT \ |
| 187 | ((PLLSS_SDM_SSC_MAX << 16) | PLLSS_SDM_SSC_MIN) |
| 188 | #define PLLSS_CTRL2_DEFAULT \ |
| 189 | ((PLLSS_SDM_SSC_STEP << 16) | PLLSS_SDM_DIN) |
| 190 | #define PLLSS_LOCK_OVERRIDE BIT(24) |
| 191 | #define PLLSS_REF_SRC_SEL_SHIFT 25 |
| 192 | #define PLLSS_REF_SRC_SEL_MASK (3 << PLLSS_REF_SRC_SEL_SHIFT) |
| 193 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 194 | #define pll_readl(offset, p) readl_relaxed(p->clk_base + offset) |
| 195 | #define pll_readl_base(p) pll_readl(p->params->base_reg, p) |
| 196 | #define pll_readl_misc(p) pll_readl(p->params->misc_reg, p) |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 197 | #define pll_override_readl(offset, p) readl_relaxed(p->pmc + offset) |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 198 | #define pll_readl_sdm_din(p) pll_readl(p->params->sdm_din_reg, p) |
| 199 | #define pll_readl_sdm_ctrl(p) pll_readl(p->params->sdm_ctrl_reg, p) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 200 | |
| 201 | #define pll_writel(val, offset, p) writel_relaxed(val, p->clk_base + offset) |
| 202 | #define pll_writel_base(val, p) pll_writel(val, p->params->base_reg, p) |
| 203 | #define pll_writel_misc(val, p) pll_writel(val, p->params->misc_reg, p) |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 204 | #define pll_override_writel(val, offset, p) writel(val, p->pmc + offset) |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 205 | #define pll_writel_sdm_din(val, p) pll_writel(val, p->params->sdm_din_reg, p) |
| 206 | #define pll_writel_sdm_ctrl(val, p) pll_writel(val, p->params->sdm_ctrl_reg, p) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 207 | |
| 208 | #define mask(w) ((1 << (w)) - 1) |
Peter De Schrijver | aa6fefd | 2013-06-05 16:51:25 +0300 | [diff] [blame] | 209 | #define divm_mask(p) mask(p->params->div_nmp->divm_width) |
| 210 | #define divn_mask(p) mask(p->params->div_nmp->divn_width) |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 211 | #define divp_mask(p) (p->params->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :\ |
Peter De Schrijver | aa6fefd | 2013-06-05 16:51:25 +0300 | [diff] [blame] | 212 | mask(p->params->div_nmp->divp_width)) |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 213 | #define sdm_din_mask(p) p->params->sdm_din_mask |
| 214 | #define sdm_en_mask(p) p->params->sdm_ctrl_en_mask |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 215 | |
Thierry Reding | c61e4e7 | 2014-04-04 15:55:14 +0200 | [diff] [blame] | 216 | #define divm_shift(p) (p)->params->div_nmp->divm_shift |
| 217 | #define divn_shift(p) (p)->params->div_nmp->divn_shift |
| 218 | #define divp_shift(p) (p)->params->div_nmp->divp_shift |
| 219 | |
| 220 | #define divm_mask_shifted(p) (divm_mask(p) << divm_shift(p)) |
| 221 | #define divn_mask_shifted(p) (divn_mask(p) << divn_shift(p)) |
| 222 | #define divp_mask_shifted(p) (divp_mask(p) << divp_shift(p)) |
| 223 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 224 | #define divm_max(p) (divm_mask(p)) |
| 225 | #define divn_max(p) (divn_mask(p)) |
| 226 | #define divp_max(p) (1 << (divp_mask(p))) |
| 227 | |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 228 | #define sdin_din_to_data(din) ((u16)((din) ? : 0xFFFFU)) |
| 229 | #define sdin_data_to_din(dat) (((dat) == 0xFFFFU) ? 0 : (s16)dat) |
| 230 | |
Peter De Schrijver | aa6fefd | 2013-06-05 16:51:25 +0300 | [diff] [blame] | 231 | static struct div_nmp default_nmp = { |
| 232 | .divn_shift = PLL_BASE_DIVN_SHIFT, |
| 233 | .divn_width = PLL_BASE_DIVN_WIDTH, |
| 234 | .divm_shift = PLL_BASE_DIVM_SHIFT, |
| 235 | .divm_width = PLL_BASE_DIVM_WIDTH, |
| 236 | .divp_shift = PLL_BASE_DIVP_SHIFT, |
| 237 | .divp_width = PLL_BASE_DIVP_WIDTH, |
| 238 | }; |
| 239 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 240 | static void clk_pll_enable_lock(struct tegra_clk_pll *pll) |
| 241 | { |
| 242 | u32 val; |
| 243 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 244 | if (!(pll->params->flags & TEGRA_PLL_USE_LOCK)) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 245 | return; |
| 246 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 247 | if (!(pll->params->flags & TEGRA_PLL_HAS_LOCK_ENABLE)) |
Peter De Schrijver | 7ba2881 | 2013-04-03 17:40:38 +0300 | [diff] [blame] | 248 | return; |
| 249 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 250 | val = pll_readl_misc(pll); |
| 251 | val |= BIT(pll->params->lock_enable_bit_idx); |
| 252 | pll_writel_misc(val, pll); |
| 253 | } |
| 254 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 255 | static int clk_pll_wait_for_lock(struct tegra_clk_pll *pll) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 256 | { |
| 257 | int i; |
Peter De Schrijver | 3e72771 | 2013-04-03 17:40:40 +0300 | [diff] [blame] | 258 | u32 val, lock_mask; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 259 | void __iomem *lock_addr; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 260 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 261 | if (!(pll->params->flags & TEGRA_PLL_USE_LOCK)) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 262 | udelay(pll->params->lock_delay); |
| 263 | return 0; |
| 264 | } |
| 265 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 266 | lock_addr = pll->clk_base; |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 267 | if (pll->params->flags & TEGRA_PLL_LOCK_MISC) |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 268 | lock_addr += pll->params->misc_reg; |
| 269 | else |
| 270 | lock_addr += pll->params->base_reg; |
| 271 | |
Peter De Schrijver | 3e72771 | 2013-04-03 17:40:40 +0300 | [diff] [blame] | 272 | lock_mask = pll->params->lock_mask; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 273 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 274 | for (i = 0; i < pll->params->lock_delay; i++) { |
| 275 | val = readl_relaxed(lock_addr); |
Peter De Schrijver | 3e72771 | 2013-04-03 17:40:40 +0300 | [diff] [blame] | 276 | if ((val & lock_mask) == lock_mask) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 277 | udelay(PLL_POST_LOCK_DELAY); |
| 278 | return 0; |
| 279 | } |
| 280 | udelay(2); /* timeout = 2 * lock time */ |
| 281 | } |
| 282 | |
| 283 | pr_err("%s: Timed out waiting for pll %s lock\n", __func__, |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 284 | clk_hw_get_name(&pll->hw)); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 285 | |
| 286 | return -1; |
| 287 | } |
| 288 | |
Rhyland Klein | 6583a63 | 2015-06-18 17:28:19 -0400 | [diff] [blame] | 289 | int tegra_pll_wait_for_lock(struct tegra_clk_pll *pll) |
| 290 | { |
| 291 | return clk_pll_wait_for_lock(pll); |
| 292 | } |
| 293 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 294 | static int clk_pll_is_enabled(struct clk_hw *hw) |
| 295 | { |
| 296 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 297 | u32 val; |
| 298 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 299 | if (pll->params->flags & TEGRA_PLLM) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 300 | val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE); |
| 301 | if (val & PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE) |
| 302 | return val & PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE ? 1 : 0; |
| 303 | } |
| 304 | |
| 305 | val = pll_readl_base(pll); |
| 306 | |
| 307 | return val & PLL_BASE_ENABLE ? 1 : 0; |
| 308 | } |
| 309 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 310 | static void _clk_pll_enable(struct clk_hw *hw) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 311 | { |
| 312 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 313 | u32 val; |
| 314 | |
Rhyland Klein | 7db864c | 2015-06-18 17:28:20 -0400 | [diff] [blame] | 315 | if (pll->params->iddq_reg) { |
| 316 | val = pll_readl(pll->params->iddq_reg, pll); |
| 317 | val &= ~BIT(pll->params->iddq_bit_idx); |
| 318 | pll_writel(val, pll->params->iddq_reg, pll); |
| 319 | udelay(2); |
| 320 | } |
| 321 | |
Bill Huang | fde207e | 2015-06-18 17:28:26 -0400 | [diff] [blame] | 322 | if (pll->params->reset_reg) { |
| 323 | val = pll_readl(pll->params->reset_reg, pll); |
| 324 | val &= ~BIT(pll->params->reset_bit_idx); |
| 325 | pll_writel(val, pll->params->reset_reg, pll); |
| 326 | } |
| 327 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 328 | clk_pll_enable_lock(pll); |
| 329 | |
| 330 | val = pll_readl_base(pll); |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 331 | if (pll->params->flags & TEGRA_PLL_BYPASS) |
Peter De Schrijver | dd93587 | 2013-04-03 17:40:37 +0300 | [diff] [blame] | 332 | val &= ~PLL_BASE_BYPASS; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 333 | val |= PLL_BASE_ENABLE; |
| 334 | pll_writel_base(val, pll); |
| 335 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 336 | if (pll->params->flags & TEGRA_PLLM) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 337 | val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE); |
| 338 | val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE; |
| 339 | writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE); |
| 340 | } |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | static void _clk_pll_disable(struct clk_hw *hw) |
| 344 | { |
| 345 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 346 | u32 val; |
| 347 | |
| 348 | val = pll_readl_base(pll); |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 349 | if (pll->params->flags & TEGRA_PLL_BYPASS) |
Peter De Schrijver | dd93587 | 2013-04-03 17:40:37 +0300 | [diff] [blame] | 350 | val &= ~PLL_BASE_BYPASS; |
| 351 | val &= ~PLL_BASE_ENABLE; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 352 | pll_writel_base(val, pll); |
| 353 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 354 | if (pll->params->flags & TEGRA_PLLM) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 355 | val = readl_relaxed(pll->pmc + PMC_PLLP_WB0_OVERRIDE); |
| 356 | val &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE; |
| 357 | writel_relaxed(val, pll->pmc + PMC_PLLP_WB0_OVERRIDE); |
| 358 | } |
Rhyland Klein | 7db864c | 2015-06-18 17:28:20 -0400 | [diff] [blame] | 359 | |
Bill Huang | fde207e | 2015-06-18 17:28:26 -0400 | [diff] [blame] | 360 | if (pll->params->reset_reg) { |
| 361 | val = pll_readl(pll->params->reset_reg, pll); |
| 362 | val |= BIT(pll->params->reset_bit_idx); |
| 363 | pll_writel(val, pll->params->reset_reg, pll); |
| 364 | } |
| 365 | |
Rhyland Klein | 7db864c | 2015-06-18 17:28:20 -0400 | [diff] [blame] | 366 | if (pll->params->iddq_reg) { |
| 367 | val = pll_readl(pll->params->iddq_reg, pll); |
| 368 | val |= BIT(pll->params->iddq_bit_idx); |
| 369 | pll_writel(val, pll->params->iddq_reg, pll); |
| 370 | udelay(2); |
| 371 | } |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static int clk_pll_enable(struct clk_hw *hw) |
| 375 | { |
| 376 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 377 | unsigned long flags = 0; |
| 378 | int ret; |
| 379 | |
| 380 | if (pll->lock) |
| 381 | spin_lock_irqsave(pll->lock, flags); |
| 382 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 383 | _clk_pll_enable(hw); |
| 384 | |
| 385 | ret = clk_pll_wait_for_lock(pll); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 386 | |
| 387 | if (pll->lock) |
| 388 | spin_unlock_irqrestore(pll->lock, flags); |
| 389 | |
| 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | static void clk_pll_disable(struct clk_hw *hw) |
| 394 | { |
| 395 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 396 | unsigned long flags = 0; |
| 397 | |
| 398 | if (pll->lock) |
| 399 | spin_lock_irqsave(pll->lock, flags); |
| 400 | |
| 401 | _clk_pll_disable(hw); |
| 402 | |
| 403 | if (pll->lock) |
| 404 | spin_unlock_irqrestore(pll->lock, flags); |
| 405 | } |
| 406 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 407 | static int _p_div_to_hw(struct clk_hw *hw, u8 p_div) |
| 408 | { |
| 409 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
Thierry Reding | 385f9ad | 2015-11-19 16:34:06 +0100 | [diff] [blame] | 410 | const struct pdiv_map *p_tohw = pll->params->pdiv_tohw; |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 411 | |
| 412 | if (p_tohw) { |
| 413 | while (p_tohw->pdiv) { |
| 414 | if (p_div <= p_tohw->pdiv) |
| 415 | return p_tohw->hw_val; |
| 416 | p_tohw++; |
| 417 | } |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | return -EINVAL; |
| 421 | } |
| 422 | |
Rhyland Klein | 6b301a0 | 2015-06-18 17:28:36 -0400 | [diff] [blame] | 423 | int tegra_pll_p_div_to_hw(struct tegra_clk_pll *pll, u8 p_div) |
| 424 | { |
| 425 | return _p_div_to_hw(&pll->hw, p_div); |
| 426 | } |
| 427 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 428 | static int _hw_to_p_div(struct clk_hw *hw, u8 p_div_hw) |
| 429 | { |
| 430 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
Thierry Reding | 385f9ad | 2015-11-19 16:34:06 +0100 | [diff] [blame] | 431 | const struct pdiv_map *p_tohw = pll->params->pdiv_tohw; |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 432 | |
| 433 | if (p_tohw) { |
| 434 | while (p_tohw->pdiv) { |
| 435 | if (p_div_hw == p_tohw->hw_val) |
| 436 | return p_tohw->pdiv; |
| 437 | p_tohw++; |
| 438 | } |
| 439 | return -EINVAL; |
| 440 | } |
| 441 | |
| 442 | return 1 << p_div_hw; |
| 443 | } |
| 444 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 445 | static int _get_table_rate(struct clk_hw *hw, |
| 446 | struct tegra_clk_pll_freq_table *cfg, |
| 447 | unsigned long rate, unsigned long parent_rate) |
| 448 | { |
| 449 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 450 | struct tegra_clk_pll_freq_table *sel; |
Rhyland Klein | 86c679a | 2015-06-18 17:28:34 -0400 | [diff] [blame] | 451 | int p; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 452 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 453 | for (sel = pll->params->freq_table; sel->input_rate != 0; sel++) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 454 | if (sel->input_rate == parent_rate && |
| 455 | sel->output_rate == rate) |
| 456 | break; |
| 457 | |
| 458 | if (sel->input_rate == 0) |
| 459 | return -EINVAL; |
| 460 | |
Rhyland Klein | 86c679a | 2015-06-18 17:28:34 -0400 | [diff] [blame] | 461 | if (pll->params->pdiv_tohw) { |
| 462 | p = _p_div_to_hw(hw, sel->p); |
| 463 | if (p < 0) |
| 464 | return p; |
| 465 | } else { |
| 466 | p = ilog2(sel->p); |
| 467 | } |
| 468 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 469 | cfg->input_rate = sel->input_rate; |
| 470 | cfg->output_rate = sel->output_rate; |
| 471 | cfg->m = sel->m; |
| 472 | cfg->n = sel->n; |
Rhyland Klein | 86c679a | 2015-06-18 17:28:34 -0400 | [diff] [blame] | 473 | cfg->p = p; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 474 | cfg->cpcon = sel->cpcon; |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 475 | cfg->sdm_data = sel->sdm_data; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | static int _calc_rate(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, |
| 481 | unsigned long rate, unsigned long parent_rate) |
| 482 | { |
| 483 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 484 | unsigned long cfreq; |
| 485 | u32 p_div = 0; |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 486 | int ret; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 487 | |
| 488 | switch (parent_rate) { |
| 489 | case 12000000: |
| 490 | case 26000000: |
| 491 | cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000; |
| 492 | break; |
| 493 | case 13000000: |
| 494 | cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000; |
| 495 | break; |
| 496 | case 16800000: |
| 497 | case 19200000: |
| 498 | cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000; |
| 499 | break; |
| 500 | case 9600000: |
| 501 | case 28800000: |
| 502 | /* |
| 503 | * PLL_P_OUT1 rate is not listed in PLLA table |
| 504 | */ |
Thierry Reding | e52d7c0 | 2015-11-18 14:04:20 +0100 | [diff] [blame] | 505 | cfreq = parent_rate / (parent_rate / 1000000); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 506 | break; |
| 507 | default: |
| 508 | pr_err("%s Unexpected reference rate %lu\n", |
| 509 | __func__, parent_rate); |
| 510 | BUG(); |
| 511 | } |
| 512 | |
| 513 | /* Raise VCO to guarantee 0.5% accuracy */ |
| 514 | for (cfg->output_rate = rate; cfg->output_rate < 200 * cfreq; |
| 515 | cfg->output_rate <<= 1) |
| 516 | p_div++; |
| 517 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 518 | cfg->m = parent_rate / cfreq; |
| 519 | cfg->n = cfg->output_rate / cfreq; |
| 520 | cfg->cpcon = OUT_OF_TABLE_CPCON; |
| 521 | |
| 522 | if (cfg->m > divm_max(pll) || cfg->n > divn_max(pll) || |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 523 | (1 << p_div) > divp_max(pll) |
| 524 | || cfg->output_rate > pll->params->vco_max) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 525 | return -EINVAL; |
| 526 | } |
| 527 | |
Thierry Reding | 00c674e | 2013-11-18 16:11:35 +0100 | [diff] [blame] | 528 | cfg->output_rate >>= p_div; |
| 529 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 530 | if (pll->params->pdiv_tohw) { |
| 531 | ret = _p_div_to_hw(hw, 1 << p_div); |
| 532 | if (ret < 0) |
| 533 | return ret; |
| 534 | else |
| 535 | cfg->p = ret; |
Peter De Schrijver | 0b6525a | 2013-04-03 17:40:39 +0300 | [diff] [blame] | 536 | } else |
| 537 | cfg->p = p_div; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 538 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 539 | return 0; |
| 540 | } |
| 541 | |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 542 | /* |
| 543 | * SDM (Sigma Delta Modulator) divisor is 16-bit 2's complement signed number |
| 544 | * within (-2^12 ... 2^12-1) range. Represented in PLL data structure as |
| 545 | * unsigned 16-bit value, with "0" divisor mapped to 0xFFFF. Data "0" is used |
| 546 | * to indicate that SDM is disabled. |
| 547 | * |
| 548 | * Effective ndiv value when SDM is enabled: ndiv + 1/2 + sdm_din/2^13 |
| 549 | */ |
| 550 | static void clk_pll_set_sdm_data(struct clk_hw *hw, |
| 551 | struct tegra_clk_pll_freq_table *cfg) |
| 552 | { |
| 553 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 554 | u32 val; |
| 555 | bool enabled; |
| 556 | |
| 557 | if (!pll->params->sdm_din_reg) |
| 558 | return; |
| 559 | |
| 560 | if (cfg->sdm_data) { |
| 561 | val = pll_readl_sdm_din(pll) & (~sdm_din_mask(pll)); |
| 562 | val |= sdin_data_to_din(cfg->sdm_data) & sdm_din_mask(pll); |
| 563 | pll_writel_sdm_din(val, pll); |
| 564 | } |
| 565 | |
| 566 | val = pll_readl_sdm_ctrl(pll); |
| 567 | enabled = (val & sdm_en_mask(pll)); |
| 568 | |
| 569 | if (cfg->sdm_data == 0 && enabled) |
| 570 | val &= ~pll->params->sdm_ctrl_en_mask; |
| 571 | |
| 572 | if (cfg->sdm_data != 0 && !enabled) |
| 573 | val |= pll->params->sdm_ctrl_en_mask; |
| 574 | |
| 575 | pll_writel_sdm_ctrl(val, pll); |
| 576 | } |
| 577 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 578 | static void _update_pll_mnp(struct tegra_clk_pll *pll, |
| 579 | struct tegra_clk_pll_freq_table *cfg) |
| 580 | { |
| 581 | u32 val; |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 582 | struct tegra_clk_pll_params *params = pll->params; |
| 583 | struct div_nmp *div_nmp = params->div_nmp; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 584 | |
Rhyland Klein | 6929715 | 2015-06-18 17:28:29 -0400 | [diff] [blame] | 585 | if ((params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) && |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 586 | (pll_override_readl(PMC_PLLP_WB0_OVERRIDE, pll) & |
| 587 | PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)) { |
| 588 | val = pll_override_readl(params->pmc_divp_reg, pll); |
| 589 | val &= ~(divp_mask(pll) << div_nmp->override_divp_shift); |
| 590 | val |= cfg->p << div_nmp->override_divp_shift; |
| 591 | pll_override_writel(val, params->pmc_divp_reg, pll); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 592 | |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 593 | val = pll_override_readl(params->pmc_divnm_reg, pll); |
| 594 | val &= ~(divm_mask(pll) << div_nmp->override_divm_shift) | |
| 595 | ~(divn_mask(pll) << div_nmp->override_divn_shift); |
| 596 | val |= (cfg->m << div_nmp->override_divm_shift) | |
| 597 | (cfg->n << div_nmp->override_divn_shift); |
| 598 | pll_override_writel(val, params->pmc_divnm_reg, pll); |
| 599 | } else { |
| 600 | val = pll_readl_base(pll); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 601 | |
Thierry Reding | c61e4e7 | 2014-04-04 15:55:14 +0200 | [diff] [blame] | 602 | val &= ~(divm_mask_shifted(pll) | divn_mask_shifted(pll) | |
| 603 | divp_mask_shifted(pll)); |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 604 | |
Thierry Reding | c61e4e7 | 2014-04-04 15:55:14 +0200 | [diff] [blame] | 605 | val |= (cfg->m << divm_shift(pll)) | |
| 606 | (cfg->n << divn_shift(pll)) | |
| 607 | (cfg->p << divp_shift(pll)); |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 608 | |
| 609 | pll_writel_base(val, pll); |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 610 | |
| 611 | clk_pll_set_sdm_data(&pll->hw, cfg); |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 612 | } |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static void _get_pll_mnp(struct tegra_clk_pll *pll, |
| 616 | struct tegra_clk_pll_freq_table *cfg) |
| 617 | { |
| 618 | u32 val; |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 619 | struct tegra_clk_pll_params *params = pll->params; |
| 620 | struct div_nmp *div_nmp = params->div_nmp; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 621 | |
Rhyland Klein | 6929715 | 2015-06-18 17:28:29 -0400 | [diff] [blame] | 622 | if ((params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) && |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 623 | (pll_override_readl(PMC_PLLP_WB0_OVERRIDE, pll) & |
| 624 | PMC_PLLP_WB0_OVERRIDE_PLLM_OVERRIDE)) { |
| 625 | val = pll_override_readl(params->pmc_divp_reg, pll); |
| 626 | cfg->p = (val >> div_nmp->override_divp_shift) & divp_mask(pll); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 627 | |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 628 | val = pll_override_readl(params->pmc_divnm_reg, pll); |
| 629 | cfg->m = (val >> div_nmp->override_divm_shift) & divm_mask(pll); |
| 630 | cfg->n = (val >> div_nmp->override_divn_shift) & divn_mask(pll); |
| 631 | } else { |
| 632 | val = pll_readl_base(pll); |
| 633 | |
| 634 | cfg->m = (val >> div_nmp->divm_shift) & divm_mask(pll); |
| 635 | cfg->n = (val >> div_nmp->divn_shift) & divn_mask(pll); |
| 636 | cfg->p = (val >> div_nmp->divp_shift) & divp_mask(pll); |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 637 | |
| 638 | if (pll->params->sdm_din_reg) { |
| 639 | if (sdm_en_mask(pll) & pll_readl_sdm_ctrl(pll)) { |
| 640 | val = pll_readl_sdm_din(pll); |
| 641 | val &= sdm_din_mask(pll); |
| 642 | cfg->sdm_data = sdin_din_to_data(val); |
| 643 | } |
| 644 | } |
Peter De Schrijver | 408a24f | 2013-06-06 13:47:31 +0300 | [diff] [blame] | 645 | } |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static void _update_pll_cpcon(struct tegra_clk_pll *pll, |
| 649 | struct tegra_clk_pll_freq_table *cfg, |
| 650 | unsigned long rate) |
| 651 | { |
| 652 | u32 val; |
| 653 | |
| 654 | val = pll_readl_misc(pll); |
| 655 | |
| 656 | val &= ~(PLL_MISC_CPCON_MASK << PLL_MISC_CPCON_SHIFT); |
| 657 | val |= cfg->cpcon << PLL_MISC_CPCON_SHIFT; |
| 658 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 659 | if (pll->params->flags & TEGRA_PLL_SET_LFCON) { |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 660 | val &= ~(PLL_MISC_LFCON_MASK << PLL_MISC_LFCON_SHIFT); |
| 661 | if (cfg->n >= PLLDU_LFCON_SET_DIVN) |
| 662 | val |= 1 << PLL_MISC_LFCON_SHIFT; |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 663 | } else if (pll->params->flags & TEGRA_PLL_SET_DCCON) { |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 664 | val &= ~(1 << PLL_MISC_DCCON_SHIFT); |
| 665 | if (rate >= (pll->params->vco_max >> 1)) |
| 666 | val |= 1 << PLL_MISC_DCCON_SHIFT; |
| 667 | } |
| 668 | |
| 669 | pll_writel_misc(val, pll); |
| 670 | } |
| 671 | |
Bill Huang | 0ef9db6 | 2015-06-18 17:28:33 -0400 | [diff] [blame] | 672 | static void pll_clk_start_ss(struct tegra_clk_pll *pll) |
| 673 | { |
| 674 | if (pll->params->defaults_set && pll->params->ssc_ctrl_reg) { |
| 675 | u32 val = pll_readl(pll->params->ssc_ctrl_reg, pll); |
| 676 | |
| 677 | val |= pll->params->ssc_ctrl_en_mask; |
| 678 | pll_writel(val, pll->params->ssc_ctrl_reg, pll); |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | static void pll_clk_stop_ss(struct tegra_clk_pll *pll) |
| 683 | { |
| 684 | if (pll->params->defaults_set && pll->params->ssc_ctrl_reg) { |
| 685 | u32 val = pll_readl(pll->params->ssc_ctrl_reg, pll); |
| 686 | |
| 687 | val &= ~pll->params->ssc_ctrl_en_mask; |
| 688 | pll_writel(val, pll->params->ssc_ctrl_reg, pll); |
| 689 | } |
| 690 | } |
| 691 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 692 | static int _program_pll(struct clk_hw *hw, struct tegra_clk_pll_freq_table *cfg, |
| 693 | unsigned long rate) |
| 694 | { |
| 695 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
Bill Huang | b985114 | 2015-06-18 17:28:31 -0400 | [diff] [blame] | 696 | struct tegra_clk_pll_freq_table old_cfg; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 697 | int state, ret = 0; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 698 | |
| 699 | state = clk_pll_is_enabled(hw); |
| 700 | |
Bill Huang | b985114 | 2015-06-18 17:28:31 -0400 | [diff] [blame] | 701 | _get_pll_mnp(pll, &old_cfg); |
| 702 | |
Rhyland Klein | 17e9273 | 2015-06-18 17:28:32 -0400 | [diff] [blame] | 703 | if (state && pll->params->defaults_set && pll->params->dyn_ramp && |
| 704 | (cfg->m == old_cfg.m) && (cfg->p == old_cfg.p)) { |
| 705 | ret = pll->params->dyn_ramp(pll, cfg); |
| 706 | if (!ret) |
| 707 | return 0; |
| 708 | } |
| 709 | |
Bill Huang | 0ef9db6 | 2015-06-18 17:28:33 -0400 | [diff] [blame] | 710 | if (state) { |
| 711 | pll_clk_stop_ss(pll); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 712 | _clk_pll_disable(hw); |
Bill Huang | 0ef9db6 | 2015-06-18 17:28:33 -0400 | [diff] [blame] | 713 | } |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 714 | |
Bill Huang | b985114 | 2015-06-18 17:28:31 -0400 | [diff] [blame] | 715 | if (!pll->params->defaults_set && pll->params->set_defaults) |
| 716 | pll->params->set_defaults(pll); |
| 717 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 718 | _update_pll_mnp(pll, cfg); |
| 719 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 720 | if (pll->params->flags & TEGRA_PLL_HAS_CPCON) |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 721 | _update_pll_cpcon(pll, cfg, rate); |
| 722 | |
| 723 | if (state) { |
| 724 | _clk_pll_enable(hw); |
| 725 | ret = clk_pll_wait_for_lock(pll); |
Bill Huang | 0ef9db6 | 2015-06-18 17:28:33 -0400 | [diff] [blame] | 726 | pll_clk_start_ss(pll); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | return ret; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | static int clk_pll_set_rate(struct clk_hw *hw, unsigned long rate, |
| 733 | unsigned long parent_rate) |
| 734 | { |
| 735 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 736 | struct tegra_clk_pll_freq_table cfg, old_cfg; |
| 737 | unsigned long flags = 0; |
| 738 | int ret = 0; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 739 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 740 | if (pll->params->flags & TEGRA_PLL_FIXED) { |
| 741 | if (rate != pll->params->fixed_rate) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 742 | pr_err("%s: Can not change %s fixed rate %lu to %lu\n", |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 743 | __func__, clk_hw_get_name(hw), |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 744 | pll->params->fixed_rate, rate); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 745 | return -EINVAL; |
| 746 | } |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | if (_get_table_rate(hw, &cfg, rate, parent_rate) && |
Rhyland Klein | 407254d | 2015-06-18 17:28:25 -0400 | [diff] [blame] | 751 | pll->params->calc_rate(hw, &cfg, rate, parent_rate)) { |
Thierry Reding | 8ba4b3b | 2013-11-27 17:26:03 +0100 | [diff] [blame] | 752 | pr_err("%s: Failed to set %s rate %lu\n", __func__, |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 753 | clk_hw_get_name(hw), rate); |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 754 | WARN_ON(1); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 755 | return -EINVAL; |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 756 | } |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 757 | if (pll->lock) |
| 758 | spin_lock_irqsave(pll->lock, flags); |
| 759 | |
| 760 | _get_pll_mnp(pll, &old_cfg); |
Andrew Bresticker | afff455 | 2015-06-18 17:28:37 -0400 | [diff] [blame] | 761 | if (pll->params->flags & TEGRA_PLL_VCO_OUT) |
| 762 | cfg.p = old_cfg.p; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 763 | |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 764 | if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p || |
| 765 | old_cfg.sdm_data != cfg.sdm_data) |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 766 | ret = _program_pll(hw, &cfg, rate); |
| 767 | |
| 768 | if (pll->lock) |
| 769 | spin_unlock_irqrestore(pll->lock, flags); |
| 770 | |
| 771 | return ret; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | static long clk_pll_round_rate(struct clk_hw *hw, unsigned long rate, |
| 775 | unsigned long *prate) |
| 776 | { |
| 777 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 778 | struct tegra_clk_pll_freq_table cfg; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 779 | |
Danny Huang | 267b62a | 2015-06-18 17:28:27 -0400 | [diff] [blame] | 780 | if (pll->params->flags & TEGRA_PLL_FIXED) { |
Rhyland Klein | 6929715 | 2015-06-18 17:28:29 -0400 | [diff] [blame] | 781 | /* PLLM/MB are used for memory; we do not change rate */ |
| 782 | if (pll->params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) |
Danny Huang | 267b62a | 2015-06-18 17:28:27 -0400 | [diff] [blame] | 783 | return clk_hw_get_rate(hw); |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 784 | return pll->params->fixed_rate; |
Danny Huang | 267b62a | 2015-06-18 17:28:27 -0400 | [diff] [blame] | 785 | } |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 786 | |
| 787 | if (_get_table_rate(hw, &cfg, rate, *prate) && |
Rhyland Klein | 407254d | 2015-06-18 17:28:25 -0400 | [diff] [blame] | 788 | pll->params->calc_rate(hw, &cfg, rate, *prate)) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 789 | return -EINVAL; |
| 790 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 791 | return cfg.output_rate; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | static unsigned long clk_pll_recalc_rate(struct clk_hw *hw, |
| 795 | unsigned long parent_rate) |
| 796 | { |
| 797 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 798 | struct tegra_clk_pll_freq_table cfg; |
| 799 | u32 val; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 800 | u64 rate = parent_rate; |
Peter De Schrijver | 0b6525a | 2013-04-03 17:40:39 +0300 | [diff] [blame] | 801 | int pdiv; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 802 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 803 | val = pll_readl_base(pll); |
| 804 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 805 | if ((pll->params->flags & TEGRA_PLL_BYPASS) && (val & PLL_BASE_BYPASS)) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 806 | return parent_rate; |
| 807 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 808 | if ((pll->params->flags & TEGRA_PLL_FIXED) && |
Rhyland Klein | 6929715 | 2015-06-18 17:28:29 -0400 | [diff] [blame] | 809 | !(pll->params->flags & (TEGRA_PLLM | TEGRA_PLLMB)) && |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 810 | !(val & PLL_BASE_OVERRIDE)) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 811 | struct tegra_clk_pll_freq_table sel; |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 812 | if (_get_table_rate(hw, &sel, pll->params->fixed_rate, |
| 813 | parent_rate)) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 814 | pr_err("Clock %s has unknown fixed frequency\n", |
Stephen Boyd | 836ee0f | 2015-08-12 11:42:23 -0700 | [diff] [blame] | 815 | clk_hw_get_name(hw)); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 816 | BUG(); |
| 817 | } |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 818 | return pll->params->fixed_rate; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 819 | } |
| 820 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 821 | _get_pll_mnp(pll, &cfg); |
| 822 | |
Andrew Bresticker | afff455 | 2015-06-18 17:28:37 -0400 | [diff] [blame] | 823 | if (pll->params->flags & TEGRA_PLL_VCO_OUT) { |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 824 | pdiv = 1; |
Andrew Bresticker | afff455 | 2015-06-18 17:28:37 -0400 | [diff] [blame] | 825 | } else { |
| 826 | pdiv = _hw_to_p_div(hw, cfg.p); |
| 827 | if (pdiv < 0) { |
| 828 | WARN(1, "Clock %s has invalid pdiv value : 0x%x\n", |
| 829 | clk_hw_get_name(hw), cfg.p); |
| 830 | pdiv = 1; |
| 831 | } |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 832 | } |
Peter De Schrijver | 0b6525a | 2013-04-03 17:40:39 +0300 | [diff] [blame] | 833 | |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 834 | if (pll->params->set_gain) |
| 835 | pll->params->set_gain(&cfg); |
| 836 | |
Peter De Schrijver | 0b6525a | 2013-04-03 17:40:39 +0300 | [diff] [blame] | 837 | cfg.m *= pdiv; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 838 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 839 | rate *= cfg.n; |
| 840 | do_div(rate, cfg.m); |
| 841 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 842 | return rate; |
| 843 | } |
| 844 | |
| 845 | static int clk_plle_training(struct tegra_clk_pll *pll) |
| 846 | { |
| 847 | u32 val; |
| 848 | unsigned long timeout; |
| 849 | |
| 850 | if (!pll->pmc) |
| 851 | return -ENOSYS; |
| 852 | |
| 853 | /* |
| 854 | * PLLE is already disabled, and setup cleared; |
| 855 | * create falling edge on PLLE IDDQ input. |
| 856 | */ |
| 857 | val = readl(pll->pmc + PMC_SATA_PWRGT); |
| 858 | val |= PMC_SATA_PWRGT_PLLE_IDDQ_VALUE; |
| 859 | writel(val, pll->pmc + PMC_SATA_PWRGT); |
| 860 | |
| 861 | val = readl(pll->pmc + PMC_SATA_PWRGT); |
| 862 | val |= PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL; |
| 863 | writel(val, pll->pmc + PMC_SATA_PWRGT); |
| 864 | |
| 865 | val = readl(pll->pmc + PMC_SATA_PWRGT); |
| 866 | val &= ~PMC_SATA_PWRGT_PLLE_IDDQ_VALUE; |
| 867 | writel(val, pll->pmc + PMC_SATA_PWRGT); |
| 868 | |
| 869 | val = pll_readl_misc(pll); |
| 870 | |
| 871 | timeout = jiffies + msecs_to_jiffies(100); |
| 872 | while (1) { |
| 873 | val = pll_readl_misc(pll); |
| 874 | if (val & PLLE_MISC_READY) |
| 875 | break; |
| 876 | if (time_after(jiffies, timeout)) { |
| 877 | pr_err("%s: timeout waiting for PLLE\n", __func__); |
| 878 | return -EBUSY; |
| 879 | } |
| 880 | udelay(300); |
| 881 | } |
| 882 | |
| 883 | return 0; |
| 884 | } |
| 885 | |
| 886 | static int clk_plle_enable(struct clk_hw *hw) |
| 887 | { |
| 888 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
Andrew Bresticker | 3eb6156 | 2016-01-14 14:24:34 -0500 | [diff] [blame] | 889 | unsigned long input_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 890 | struct tegra_clk_pll_freq_table sel; |
| 891 | u32 val; |
| 892 | int err; |
| 893 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 894 | if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate)) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 895 | return -EINVAL; |
| 896 | |
| 897 | clk_pll_disable(hw); |
| 898 | |
| 899 | val = pll_readl_misc(pll); |
| 900 | val &= ~(PLLE_MISC_LOCK_ENABLE | PLLE_MISC_SETUP_MASK); |
| 901 | pll_writel_misc(val, pll); |
| 902 | |
| 903 | val = pll_readl_misc(pll); |
| 904 | if (!(val & PLLE_MISC_READY)) { |
| 905 | err = clk_plle_training(pll); |
| 906 | if (err) |
| 907 | return err; |
| 908 | } |
| 909 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 910 | if (pll->params->flags & TEGRA_PLLE_CONFIGURE) { |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 911 | /* configure dividers */ |
| 912 | val = pll_readl_base(pll); |
Thierry Reding | c61e4e7 | 2014-04-04 15:55:14 +0200 | [diff] [blame] | 913 | val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) | |
| 914 | divm_mask_shifted(pll)); |
Thierry Reding | d0f02ce | 2014-04-04 15:55:13 +0200 | [diff] [blame] | 915 | val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT); |
Thierry Reding | c61e4e7 | 2014-04-04 15:55:14 +0200 | [diff] [blame] | 916 | val |= sel.m << divm_shift(pll); |
| 917 | val |= sel.n << divn_shift(pll); |
| 918 | val |= sel.p << divp_shift(pll); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 919 | val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT; |
| 920 | pll_writel_base(val, pll); |
| 921 | } |
| 922 | |
| 923 | val = pll_readl_misc(pll); |
| 924 | val |= PLLE_MISC_SETUP_VALUE; |
| 925 | val |= PLLE_MISC_LOCK_ENABLE; |
| 926 | pll_writel_misc(val, pll); |
| 927 | |
| 928 | val = readl(pll->clk_base + PLLE_SS_CTRL); |
Thierry Reding | d0f02ce | 2014-04-04 15:55:13 +0200 | [diff] [blame] | 929 | val &= ~PLLE_SS_COEFFICIENTS_MASK; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 930 | val |= PLLE_SS_DISABLE; |
| 931 | writel(val, pll->clk_base + PLLE_SS_CTRL); |
| 932 | |
Thierry Reding | 4ccc402 | 2014-04-04 15:55:15 +0200 | [diff] [blame] | 933 | val = pll_readl_base(pll); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 934 | val |= (PLL_BASE_BYPASS | PLL_BASE_ENABLE); |
| 935 | pll_writel_base(val, pll); |
| 936 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 937 | clk_pll_wait_for_lock(pll); |
| 938 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 939 | return 0; |
| 940 | } |
| 941 | |
| 942 | static unsigned long clk_plle_recalc_rate(struct clk_hw *hw, |
| 943 | unsigned long parent_rate) |
| 944 | { |
| 945 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 946 | u32 val = pll_readl_base(pll); |
| 947 | u32 divn = 0, divm = 0, divp = 0; |
| 948 | u64 rate = parent_rate; |
| 949 | |
Peter De Schrijver | aa6fefd | 2013-06-05 16:51:25 +0300 | [diff] [blame] | 950 | divp = (val >> pll->params->div_nmp->divp_shift) & (divp_mask(pll)); |
| 951 | divn = (val >> pll->params->div_nmp->divn_shift) & (divn_mask(pll)); |
| 952 | divm = (val >> pll->params->div_nmp->divm_shift) & (divm_mask(pll)); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 953 | divm *= divp; |
| 954 | |
| 955 | rate *= divn; |
| 956 | do_div(rate, divm); |
| 957 | return rate; |
| 958 | } |
| 959 | |
| 960 | const struct clk_ops tegra_clk_pll_ops = { |
| 961 | .is_enabled = clk_pll_is_enabled, |
| 962 | .enable = clk_pll_enable, |
| 963 | .disable = clk_pll_disable, |
| 964 | .recalc_rate = clk_pll_recalc_rate, |
| 965 | .round_rate = clk_pll_round_rate, |
| 966 | .set_rate = clk_pll_set_rate, |
| 967 | }; |
| 968 | |
| 969 | const struct clk_ops tegra_clk_plle_ops = { |
| 970 | .recalc_rate = clk_plle_recalc_rate, |
| 971 | .is_enabled = clk_pll_is_enabled, |
| 972 | .disable = clk_pll_disable, |
| 973 | .enable = clk_plle_enable, |
| 974 | }; |
| 975 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 976 | static int _pll_fixed_mdiv(struct tegra_clk_pll_params *pll_params, |
| 977 | unsigned long parent_rate) |
| 978 | { |
Rhyland Klein | 407254d | 2015-06-18 17:28:25 -0400 | [diff] [blame] | 979 | u16 mdiv = parent_rate / pll_params->cf_min; |
| 980 | |
| 981 | if (pll_params->flags & TEGRA_MDIV_NEW) |
| 982 | return (!pll_params->mdiv_default ? mdiv : |
| 983 | min(mdiv, pll_params->mdiv_default)); |
| 984 | |
| 985 | if (pll_params->mdiv_default) |
| 986 | return pll_params->mdiv_default; |
| 987 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 988 | if (parent_rate > pll_params->cf_max) |
| 989 | return 2; |
| 990 | else |
| 991 | return 1; |
| 992 | } |
| 993 | |
Rhyland Klein | 86c679a | 2015-06-18 17:28:34 -0400 | [diff] [blame] | 994 | static int _calc_dynamic_ramp_rate(struct clk_hw *hw, |
| 995 | struct tegra_clk_pll_freq_table *cfg, |
| 996 | unsigned long rate, unsigned long parent_rate) |
| 997 | { |
| 998 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 999 | unsigned int p; |
| 1000 | int p_div; |
| 1001 | |
| 1002 | if (!rate) |
| 1003 | return -EINVAL; |
| 1004 | |
| 1005 | p = DIV_ROUND_UP(pll->params->vco_min, rate); |
| 1006 | cfg->m = _pll_fixed_mdiv(pll->params, parent_rate); |
| 1007 | cfg->output_rate = rate * p; |
| 1008 | cfg->n = cfg->output_rate * cfg->m / parent_rate; |
| 1009 | cfg->input_rate = parent_rate; |
| 1010 | |
| 1011 | p_div = _p_div_to_hw(hw, p); |
| 1012 | if (p_div < 0) |
| 1013 | return p_div; |
| 1014 | |
| 1015 | cfg->p = p_div; |
| 1016 | |
| 1017 | if (cfg->n > divn_max(pll) || cfg->output_rate > pll->params->vco_max) |
| 1018 | return -EINVAL; |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
| 1023 | #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \ |
| 1024 | defined(CONFIG_ARCH_TEGRA_124_SOC) || \ |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 1025 | defined(CONFIG_ARCH_TEGRA_132_SOC) || \ |
| 1026 | defined(CONFIG_ARCH_TEGRA_210_SOC) |
Rhyland Klein | 86c679a | 2015-06-18 17:28:34 -0400 | [diff] [blame] | 1027 | |
Rhyland Klein | 407254d | 2015-06-18 17:28:25 -0400 | [diff] [blame] | 1028 | u16 tegra_pll_get_fixed_mdiv(struct clk_hw *hw, unsigned long input_rate) |
| 1029 | { |
| 1030 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1031 | |
| 1032 | return (u16)_pll_fixed_mdiv(pll->params, input_rate); |
| 1033 | } |
| 1034 | |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1035 | static unsigned long _clip_vco_min(unsigned long vco_min, |
| 1036 | unsigned long parent_rate) |
| 1037 | { |
| 1038 | return DIV_ROUND_UP(vco_min, parent_rate) * parent_rate; |
| 1039 | } |
| 1040 | |
| 1041 | static int _setup_dynamic_ramp(struct tegra_clk_pll_params *pll_params, |
| 1042 | void __iomem *clk_base, |
| 1043 | unsigned long parent_rate) |
| 1044 | { |
| 1045 | u32 val; |
| 1046 | u32 step_a, step_b; |
| 1047 | |
| 1048 | switch (parent_rate) { |
| 1049 | case 12000000: |
| 1050 | case 13000000: |
| 1051 | case 26000000: |
| 1052 | step_a = 0x2B; |
| 1053 | step_b = 0x0B; |
| 1054 | break; |
| 1055 | case 16800000: |
| 1056 | step_a = 0x1A; |
| 1057 | step_b = 0x09; |
| 1058 | break; |
| 1059 | case 19200000: |
| 1060 | step_a = 0x12; |
| 1061 | step_b = 0x08; |
| 1062 | break; |
| 1063 | default: |
| 1064 | pr_err("%s: Unexpected reference rate %lu\n", |
| 1065 | __func__, parent_rate); |
| 1066 | WARN_ON(1); |
| 1067 | return -EINVAL; |
| 1068 | } |
| 1069 | |
| 1070 | val = step_a << pll_params->stepa_shift; |
| 1071 | val |= step_b << pll_params->stepb_shift; |
| 1072 | writel_relaxed(val, clk_base + pll_params->dyn_ramp_reg); |
| 1073 | |
| 1074 | return 0; |
| 1075 | } |
| 1076 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1077 | static int _pll_ramp_calc_pll(struct clk_hw *hw, |
| 1078 | struct tegra_clk_pll_freq_table *cfg, |
| 1079 | unsigned long rate, unsigned long parent_rate) |
| 1080 | { |
| 1081 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
Rhyland Klein | 86c679a | 2015-06-18 17:28:34 -0400 | [diff] [blame] | 1082 | int err = 0; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1083 | |
| 1084 | err = _get_table_rate(hw, cfg, rate, parent_rate); |
| 1085 | if (err < 0) |
| 1086 | err = _calc_dynamic_ramp_rate(hw, cfg, rate, parent_rate); |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1087 | else { |
| 1088 | if (cfg->m != _pll_fixed_mdiv(pll->params, parent_rate)) { |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1089 | WARN_ON(1); |
| 1090 | err = -EINVAL; |
| 1091 | goto out; |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1092 | } |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1093 | } |
| 1094 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1095 | if (cfg->p > pll->params->max_p) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1096 | err = -EINVAL; |
| 1097 | |
| 1098 | out: |
| 1099 | return err; |
| 1100 | } |
| 1101 | |
| 1102 | static int clk_pllxc_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1103 | unsigned long parent_rate) |
| 1104 | { |
| 1105 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1106 | struct tegra_clk_pll_freq_table cfg, old_cfg; |
| 1107 | unsigned long flags = 0; |
Thierry Reding | 44a6f3db | 2015-02-18 16:25:16 +0100 | [diff] [blame] | 1108 | int ret; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1109 | |
| 1110 | ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate); |
| 1111 | if (ret < 0) |
| 1112 | return ret; |
| 1113 | |
| 1114 | if (pll->lock) |
| 1115 | spin_lock_irqsave(pll->lock, flags); |
| 1116 | |
| 1117 | _get_pll_mnp(pll, &old_cfg); |
Andrew Bresticker | afff455 | 2015-06-18 17:28:37 -0400 | [diff] [blame] | 1118 | if (pll->params->flags & TEGRA_PLL_VCO_OUT) |
| 1119 | cfg.p = old_cfg.p; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1120 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1121 | if (old_cfg.m != cfg.m || old_cfg.n != cfg.n || old_cfg.p != cfg.p) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1122 | ret = _program_pll(hw, &cfg, rate); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1123 | |
| 1124 | if (pll->lock) |
| 1125 | spin_unlock_irqrestore(pll->lock, flags); |
| 1126 | |
| 1127 | return ret; |
| 1128 | } |
| 1129 | |
| 1130 | static long clk_pll_ramp_round_rate(struct clk_hw *hw, unsigned long rate, |
| 1131 | unsigned long *prate) |
| 1132 | { |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 1133 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1134 | struct tegra_clk_pll_freq_table cfg; |
Thierry Reding | 44a6f3db | 2015-02-18 16:25:16 +0100 | [diff] [blame] | 1135 | int ret, p_div; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1136 | u64 output_rate = *prate; |
| 1137 | |
| 1138 | ret = _pll_ramp_calc_pll(hw, &cfg, rate, *prate); |
| 1139 | if (ret < 0) |
| 1140 | return ret; |
| 1141 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1142 | p_div = _hw_to_p_div(hw, cfg.p); |
| 1143 | if (p_div < 0) |
| 1144 | return p_div; |
| 1145 | |
Rhyland Klein | d907f4b | 2015-06-18 17:28:24 -0400 | [diff] [blame] | 1146 | if (pll->params->set_gain) |
| 1147 | pll->params->set_gain(&cfg); |
| 1148 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1149 | output_rate *= cfg.n; |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1150 | do_div(output_rate, cfg.m * p_div); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1151 | |
| 1152 | return output_rate; |
| 1153 | } |
| 1154 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1155 | static void _pllcx_strobe(struct tegra_clk_pll *pll) |
| 1156 | { |
| 1157 | u32 val; |
| 1158 | |
| 1159 | val = pll_readl_misc(pll); |
| 1160 | val |= PLLCX_MISC_STROBE; |
| 1161 | pll_writel_misc(val, pll); |
| 1162 | udelay(2); |
| 1163 | |
| 1164 | val &= ~PLLCX_MISC_STROBE; |
| 1165 | pll_writel_misc(val, pll); |
| 1166 | } |
| 1167 | |
| 1168 | static int clk_pllc_enable(struct clk_hw *hw) |
| 1169 | { |
| 1170 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1171 | u32 val; |
Thierry Reding | 44a6f3db | 2015-02-18 16:25:16 +0100 | [diff] [blame] | 1172 | int ret; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1173 | unsigned long flags = 0; |
| 1174 | |
| 1175 | if (pll->lock) |
| 1176 | spin_lock_irqsave(pll->lock, flags); |
| 1177 | |
| 1178 | _clk_pll_enable(hw); |
| 1179 | udelay(2); |
| 1180 | |
| 1181 | val = pll_readl_misc(pll); |
| 1182 | val &= ~PLLCX_MISC_RESET; |
| 1183 | pll_writel_misc(val, pll); |
| 1184 | udelay(2); |
| 1185 | |
| 1186 | _pllcx_strobe(pll); |
| 1187 | |
| 1188 | ret = clk_pll_wait_for_lock(pll); |
| 1189 | |
| 1190 | if (pll->lock) |
| 1191 | spin_unlock_irqrestore(pll->lock, flags); |
| 1192 | |
| 1193 | return ret; |
| 1194 | } |
| 1195 | |
| 1196 | static void _clk_pllc_disable(struct clk_hw *hw) |
| 1197 | { |
| 1198 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1199 | u32 val; |
| 1200 | |
| 1201 | _clk_pll_disable(hw); |
| 1202 | |
| 1203 | val = pll_readl_misc(pll); |
| 1204 | val |= PLLCX_MISC_RESET; |
| 1205 | pll_writel_misc(val, pll); |
| 1206 | udelay(2); |
| 1207 | } |
| 1208 | |
| 1209 | static void clk_pllc_disable(struct clk_hw *hw) |
| 1210 | { |
| 1211 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1212 | unsigned long flags = 0; |
| 1213 | |
| 1214 | if (pll->lock) |
| 1215 | spin_lock_irqsave(pll->lock, flags); |
| 1216 | |
| 1217 | _clk_pllc_disable(hw); |
| 1218 | |
| 1219 | if (pll->lock) |
| 1220 | spin_unlock_irqrestore(pll->lock, flags); |
| 1221 | } |
| 1222 | |
| 1223 | static int _pllcx_update_dynamic_coef(struct tegra_clk_pll *pll, |
| 1224 | unsigned long input_rate, u32 n) |
| 1225 | { |
| 1226 | u32 val, n_threshold; |
| 1227 | |
| 1228 | switch (input_rate) { |
| 1229 | case 12000000: |
| 1230 | n_threshold = 70; |
| 1231 | break; |
| 1232 | case 13000000: |
| 1233 | case 26000000: |
| 1234 | n_threshold = 71; |
| 1235 | break; |
| 1236 | case 16800000: |
| 1237 | n_threshold = 55; |
| 1238 | break; |
| 1239 | case 19200000: |
| 1240 | n_threshold = 48; |
| 1241 | break; |
| 1242 | default: |
| 1243 | pr_err("%s: Unexpected reference rate %lu\n", |
| 1244 | __func__, input_rate); |
| 1245 | return -EINVAL; |
| 1246 | } |
| 1247 | |
| 1248 | val = pll_readl_misc(pll); |
| 1249 | val &= ~(PLLCX_MISC_SDM_DIV_MASK | PLLCX_MISC_FILT_DIV_MASK); |
| 1250 | val |= n <= n_threshold ? |
| 1251 | PLLCX_MISC_DIV_LOW_RANGE : PLLCX_MISC_DIV_HIGH_RANGE; |
| 1252 | pll_writel_misc(val, pll); |
| 1253 | |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | static int clk_pllc_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1258 | unsigned long parent_rate) |
| 1259 | { |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1260 | struct tegra_clk_pll_freq_table cfg, old_cfg; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1261 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1262 | unsigned long flags = 0; |
| 1263 | int state, ret = 0; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1264 | |
| 1265 | if (pll->lock) |
| 1266 | spin_lock_irqsave(pll->lock, flags); |
| 1267 | |
| 1268 | ret = _pll_ramp_calc_pll(hw, &cfg, rate, parent_rate); |
| 1269 | if (ret < 0) |
| 1270 | goto out; |
| 1271 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1272 | _get_pll_mnp(pll, &old_cfg); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1273 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1274 | if (cfg.m != old_cfg.m) { |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1275 | WARN_ON(1); |
| 1276 | goto out; |
| 1277 | } |
| 1278 | |
Peter De Schrijver | 053b525 | 2013-06-05 15:56:41 +0300 | [diff] [blame] | 1279 | if (old_cfg.n == cfg.n && old_cfg.p == cfg.p) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1280 | goto out; |
| 1281 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1282 | state = clk_pll_is_enabled(hw); |
| 1283 | if (state) |
| 1284 | _clk_pllc_disable(hw); |
| 1285 | |
| 1286 | ret = _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n); |
| 1287 | if (ret < 0) |
| 1288 | goto out; |
| 1289 | |
| 1290 | _update_pll_mnp(pll, &cfg); |
| 1291 | |
| 1292 | if (state) |
| 1293 | ret = clk_pllc_enable(hw); |
| 1294 | |
| 1295 | out: |
| 1296 | if (pll->lock) |
| 1297 | spin_unlock_irqrestore(pll->lock, flags); |
| 1298 | |
| 1299 | return ret; |
| 1300 | } |
| 1301 | |
| 1302 | static long _pllre_calc_rate(struct tegra_clk_pll *pll, |
| 1303 | struct tegra_clk_pll_freq_table *cfg, |
| 1304 | unsigned long rate, unsigned long parent_rate) |
| 1305 | { |
| 1306 | u16 m, n; |
| 1307 | u64 output_rate = parent_rate; |
| 1308 | |
| 1309 | m = _pll_fixed_mdiv(pll->params, parent_rate); |
| 1310 | n = rate * m / parent_rate; |
| 1311 | |
| 1312 | output_rate *= n; |
| 1313 | do_div(output_rate, m); |
| 1314 | |
| 1315 | if (cfg) { |
| 1316 | cfg->m = m; |
| 1317 | cfg->n = n; |
| 1318 | } |
| 1319 | |
| 1320 | return output_rate; |
| 1321 | } |
Thierry Reding | 6bb18c5 | 2014-08-01 10:44:20 +0200 | [diff] [blame] | 1322 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1323 | static int clk_pllre_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1324 | unsigned long parent_rate) |
| 1325 | { |
| 1326 | struct tegra_clk_pll_freq_table cfg, old_cfg; |
| 1327 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1328 | unsigned long flags = 0; |
| 1329 | int state, ret = 0; |
| 1330 | |
| 1331 | if (pll->lock) |
| 1332 | spin_lock_irqsave(pll->lock, flags); |
| 1333 | |
| 1334 | _pllre_calc_rate(pll, &cfg, rate, parent_rate); |
| 1335 | _get_pll_mnp(pll, &old_cfg); |
| 1336 | cfg.p = old_cfg.p; |
| 1337 | |
| 1338 | if (cfg.m != old_cfg.m || cfg.n != old_cfg.n) { |
| 1339 | state = clk_pll_is_enabled(hw); |
| 1340 | if (state) |
| 1341 | _clk_pll_disable(hw); |
| 1342 | |
| 1343 | _update_pll_mnp(pll, &cfg); |
| 1344 | |
| 1345 | if (state) { |
| 1346 | _clk_pll_enable(hw); |
| 1347 | ret = clk_pll_wait_for_lock(pll); |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | if (pll->lock) |
| 1352 | spin_unlock_irqrestore(pll->lock, flags); |
| 1353 | |
| 1354 | return ret; |
| 1355 | } |
| 1356 | |
| 1357 | static unsigned long clk_pllre_recalc_rate(struct clk_hw *hw, |
| 1358 | unsigned long parent_rate) |
| 1359 | { |
| 1360 | struct tegra_clk_pll_freq_table cfg; |
| 1361 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1362 | u64 rate = parent_rate; |
| 1363 | |
| 1364 | _get_pll_mnp(pll, &cfg); |
| 1365 | |
| 1366 | rate *= cfg.n; |
| 1367 | do_div(rate, cfg.m); |
| 1368 | |
| 1369 | return rate; |
| 1370 | } |
| 1371 | |
| 1372 | static long clk_pllre_round_rate(struct clk_hw *hw, unsigned long rate, |
| 1373 | unsigned long *prate) |
| 1374 | { |
| 1375 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1376 | |
| 1377 | return _pllre_calc_rate(pll, NULL, rate, *prate); |
| 1378 | } |
| 1379 | |
| 1380 | static int clk_plle_tegra114_enable(struct clk_hw *hw) |
| 1381 | { |
| 1382 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1383 | struct tegra_clk_pll_freq_table sel; |
| 1384 | u32 val; |
| 1385 | int ret; |
| 1386 | unsigned long flags = 0; |
Andrew Bresticker | 3eb6156 | 2016-01-14 14:24:34 -0500 | [diff] [blame] | 1387 | unsigned long input_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1388 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1389 | if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate)) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1390 | return -EINVAL; |
| 1391 | |
| 1392 | if (pll->lock) |
| 1393 | spin_lock_irqsave(pll->lock, flags); |
| 1394 | |
| 1395 | val = pll_readl_base(pll); |
| 1396 | val &= ~BIT(29); /* Disable lock override */ |
| 1397 | pll_writel_base(val, pll); |
| 1398 | |
| 1399 | val = pll_readl(pll->params->aux_reg, pll); |
| 1400 | val |= PLLE_AUX_ENABLE_SWCTL; |
| 1401 | val &= ~PLLE_AUX_SEQ_ENABLE; |
| 1402 | pll_writel(val, pll->params->aux_reg, pll); |
| 1403 | udelay(1); |
| 1404 | |
| 1405 | val = pll_readl_misc(pll); |
| 1406 | val |= PLLE_MISC_LOCK_ENABLE; |
| 1407 | val |= PLLE_MISC_IDDQ_SW_CTRL; |
| 1408 | val &= ~PLLE_MISC_IDDQ_SW_VALUE; |
| 1409 | val |= PLLE_MISC_PLLE_PTS; |
Rhyland Klein | fd2963b | 2016-01-14 14:24:37 -0500 | [diff] [blame] | 1410 | val &= ~(PLLE_MISC_VREG_BG_CTRL_MASK | PLLE_MISC_VREG_CTRL_MASK); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1411 | pll_writel_misc(val, pll); |
| 1412 | udelay(5); |
| 1413 | |
| 1414 | val = pll_readl(PLLE_SS_CTRL, pll); |
| 1415 | val |= PLLE_SS_DISABLE; |
| 1416 | pll_writel(val, PLLE_SS_CTRL, pll); |
| 1417 | |
| 1418 | val = pll_readl_base(pll); |
Thierry Reding | c61e4e7 | 2014-04-04 15:55:14 +0200 | [diff] [blame] | 1419 | val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) | |
| 1420 | divm_mask_shifted(pll)); |
Thierry Reding | d0f02ce | 2014-04-04 15:55:13 +0200 | [diff] [blame] | 1421 | val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT); |
Thierry Reding | c61e4e7 | 2014-04-04 15:55:14 +0200 | [diff] [blame] | 1422 | val |= sel.m << divm_shift(pll); |
| 1423 | val |= sel.n << divn_shift(pll); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1424 | val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT; |
| 1425 | pll_writel_base(val, pll); |
| 1426 | udelay(1); |
| 1427 | |
| 1428 | _clk_pll_enable(hw); |
| 1429 | ret = clk_pll_wait_for_lock(pll); |
| 1430 | |
| 1431 | if (ret < 0) |
| 1432 | goto out; |
| 1433 | |
Peter De Schrijver | 642fb0c | 2013-09-26 18:30:01 +0300 | [diff] [blame] | 1434 | val = pll_readl(PLLE_SS_CTRL, pll); |
| 1435 | val &= ~(PLLE_SS_CNTL_CENTER | PLLE_SS_CNTL_INVERT); |
| 1436 | val &= ~PLLE_SS_COEFFICIENTS_MASK; |
Mark Kuo | 442f53f | 2016-01-14 14:26:42 -0500 | [diff] [blame] | 1437 | val |= PLLE_SS_COEFFICIENTS_VAL_TEGRA114; |
Peter De Schrijver | 642fb0c | 2013-09-26 18:30:01 +0300 | [diff] [blame] | 1438 | pll_writel(val, PLLE_SS_CTRL, pll); |
| 1439 | val &= ~(PLLE_SS_CNTL_SSC_BYP | PLLE_SS_CNTL_BYPASS_SS); |
| 1440 | pll_writel(val, PLLE_SS_CTRL, pll); |
| 1441 | udelay(1); |
| 1442 | val &= ~PLLE_SS_CNTL_INTERP_RESET; |
| 1443 | pll_writel(val, PLLE_SS_CTRL, pll); |
| 1444 | udelay(1); |
| 1445 | |
Jim Lin | 2cfe167 | 2014-05-14 17:32:57 -0700 | [diff] [blame] | 1446 | /* Enable hw control of xusb brick pll */ |
| 1447 | val = pll_readl_misc(pll); |
| 1448 | val &= ~PLLE_MISC_IDDQ_SW_CTRL; |
| 1449 | pll_writel_misc(val, pll); |
| 1450 | |
| 1451 | val = pll_readl(pll->params->aux_reg, pll); |
| 1452 | val |= (PLLE_AUX_USE_LOCKDET | PLLE_AUX_SEQ_START_STATE); |
| 1453 | val &= ~(PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL); |
| 1454 | pll_writel(val, pll->params->aux_reg, pll); |
| 1455 | udelay(1); |
| 1456 | val |= PLLE_AUX_SEQ_ENABLE; |
| 1457 | pll_writel(val, pll->params->aux_reg, pll); |
| 1458 | |
| 1459 | val = pll_readl(XUSBIO_PLL_CFG0, pll); |
| 1460 | val |= (XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET | |
| 1461 | XUSBIO_PLL_CFG0_SEQ_START_STATE); |
| 1462 | val &= ~(XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL | |
| 1463 | XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL); |
| 1464 | pll_writel(val, XUSBIO_PLL_CFG0, pll); |
| 1465 | udelay(1); |
| 1466 | val |= XUSBIO_PLL_CFG0_SEQ_ENABLE; |
| 1467 | pll_writel(val, XUSBIO_PLL_CFG0, pll); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1468 | |
Mikko Perttunen | 37ab366 | 2014-06-18 17:23:23 +0300 | [diff] [blame] | 1469 | /* Enable hw control of SATA pll */ |
| 1470 | val = pll_readl(SATA_PLL_CFG0, pll); |
| 1471 | val &= ~SATA_PLL_CFG0_PADPLL_RESET_SWCTL; |
Mikko Perttunen | 0e548d50b | 2014-07-08 09:30:15 +0200 | [diff] [blame] | 1472 | val |= SATA_PLL_CFG0_PADPLL_USE_LOCKDET; |
| 1473 | val |= SATA_PLL_CFG0_SEQ_START_STATE; |
| 1474 | pll_writel(val, SATA_PLL_CFG0, pll); |
| 1475 | |
| 1476 | udelay(1); |
| 1477 | |
| 1478 | val = pll_readl(SATA_PLL_CFG0, pll); |
| 1479 | val |= SATA_PLL_CFG0_SEQ_ENABLE; |
Mikko Perttunen | 37ab366 | 2014-06-18 17:23:23 +0300 | [diff] [blame] | 1480 | pll_writel(val, SATA_PLL_CFG0, pll); |
| 1481 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1482 | out: |
| 1483 | if (pll->lock) |
| 1484 | spin_unlock_irqrestore(pll->lock, flags); |
| 1485 | |
| 1486 | return ret; |
| 1487 | } |
| 1488 | |
| 1489 | static void clk_plle_tegra114_disable(struct clk_hw *hw) |
| 1490 | { |
| 1491 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 1492 | unsigned long flags = 0; |
| 1493 | u32 val; |
| 1494 | |
| 1495 | if (pll->lock) |
| 1496 | spin_lock_irqsave(pll->lock, flags); |
| 1497 | |
| 1498 | _clk_pll_disable(hw); |
| 1499 | |
| 1500 | val = pll_readl_misc(pll); |
| 1501 | val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE; |
| 1502 | pll_writel_misc(val, pll); |
| 1503 | udelay(1); |
| 1504 | |
| 1505 | if (pll->lock) |
| 1506 | spin_unlock_irqrestore(pll->lock, flags); |
| 1507 | } |
| 1508 | #endif |
| 1509 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 1510 | static struct tegra_clk_pll *_tegra_init_pll(void __iomem *clk_base, |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1511 | void __iomem *pmc, struct tegra_clk_pll_params *pll_params, |
| 1512 | spinlock_t *lock) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1513 | { |
| 1514 | struct tegra_clk_pll *pll; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1515 | |
| 1516 | pll = kzalloc(sizeof(*pll), GFP_KERNEL); |
| 1517 | if (!pll) |
| 1518 | return ERR_PTR(-ENOMEM); |
| 1519 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1520 | pll->clk_base = clk_base; |
| 1521 | pll->pmc = pmc; |
| 1522 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1523 | pll->params = pll_params; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1524 | pll->lock = lock; |
| 1525 | |
Peter De Schrijver | aa6fefd | 2013-06-05 16:51:25 +0300 | [diff] [blame] | 1526 | if (!pll_params->div_nmp) |
| 1527 | pll_params->div_nmp = &default_nmp; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1528 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 1529 | return pll; |
| 1530 | } |
| 1531 | |
| 1532 | static struct clk *_tegra_clk_register_pll(struct tegra_clk_pll *pll, |
| 1533 | const char *name, const char *parent_name, unsigned long flags, |
| 1534 | const struct clk_ops *ops) |
| 1535 | { |
| 1536 | struct clk_init_data init; |
| 1537 | |
| 1538 | init.name = name; |
| 1539 | init.ops = ops; |
| 1540 | init.flags = flags; |
| 1541 | init.parent_names = (parent_name ? &parent_name : NULL); |
| 1542 | init.num_parents = (parent_name ? 1 : 0); |
| 1543 | |
Rhyland Klein | 407254d | 2015-06-18 17:28:25 -0400 | [diff] [blame] | 1544 | /* Default to _calc_rate if unspecified */ |
Rhyland Klein | 86c679a | 2015-06-18 17:28:34 -0400 | [diff] [blame] | 1545 | if (!pll->params->calc_rate) { |
| 1546 | if (pll->params->flags & TEGRA_PLLM) |
| 1547 | pll->params->calc_rate = _calc_dynamic_ramp_rate; |
| 1548 | else |
| 1549 | pll->params->calc_rate = _calc_rate; |
| 1550 | } |
Rhyland Klein | 407254d | 2015-06-18 17:28:25 -0400 | [diff] [blame] | 1551 | |
Bill Huang | b985114 | 2015-06-18 17:28:31 -0400 | [diff] [blame] | 1552 | if (pll->params->set_defaults) |
| 1553 | pll->params->set_defaults(pll); |
| 1554 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1555 | /* Data in .init is copied by clk_register(), so stack variable OK */ |
| 1556 | pll->hw.init = &init; |
| 1557 | |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 1558 | return clk_register(NULL, &pll->hw); |
| 1559 | } |
| 1560 | |
| 1561 | struct clk *tegra_clk_register_pll(const char *name, const char *parent_name, |
| 1562 | void __iomem *clk_base, void __iomem *pmc, |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1563 | unsigned long flags, struct tegra_clk_pll_params *pll_params, |
| 1564 | spinlock_t *lock) |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 1565 | { |
| 1566 | struct tegra_clk_pll *pll; |
| 1567 | struct clk *clk; |
| 1568 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1569 | pll_params->flags |= TEGRA_PLL_BYPASS; |
Rhyland Klein | 3706b43 | 2015-06-18 17:28:23 -0400 | [diff] [blame] | 1570 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1571 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 1572 | if (IS_ERR(pll)) |
| 1573 | return ERR_CAST(pll); |
| 1574 | |
| 1575 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 1576 | &tegra_clk_pll_ops); |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1577 | if (IS_ERR(clk)) |
| 1578 | kfree(pll); |
| 1579 | |
| 1580 | return clk; |
| 1581 | } |
| 1582 | |
Thierry Reding | d0f02ce | 2014-04-04 15:55:13 +0200 | [diff] [blame] | 1583 | static struct div_nmp pll_e_nmp = { |
| 1584 | .divn_shift = PLLE_BASE_DIVN_SHIFT, |
| 1585 | .divn_width = PLLE_BASE_DIVN_WIDTH, |
| 1586 | .divm_shift = PLLE_BASE_DIVM_SHIFT, |
| 1587 | .divm_width = PLLE_BASE_DIVM_WIDTH, |
| 1588 | .divp_shift = PLLE_BASE_DIVP_SHIFT, |
| 1589 | .divp_width = PLLE_BASE_DIVP_WIDTH, |
| 1590 | }; |
| 1591 | |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1592 | struct clk *tegra_clk_register_plle(const char *name, const char *parent_name, |
| 1593 | void __iomem *clk_base, void __iomem *pmc, |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1594 | unsigned long flags, struct tegra_clk_pll_params *pll_params, |
| 1595 | spinlock_t *lock) |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1596 | { |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 1597 | struct tegra_clk_pll *pll; |
| 1598 | struct clk *clk; |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 1599 | |
Rhyland Klein | 3706b43 | 2015-06-18 17:28:23 -0400 | [diff] [blame] | 1600 | pll_params->flags |= TEGRA_PLL_BYPASS; |
Thierry Reding | d0f02ce | 2014-04-04 15:55:13 +0200 | [diff] [blame] | 1601 | |
| 1602 | if (!pll_params->div_nmp) |
| 1603 | pll_params->div_nmp = &pll_e_nmp; |
| 1604 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1605 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
Peter De Schrijver | dba4072 | 2013-04-03 17:40:36 +0300 | [diff] [blame] | 1606 | if (IS_ERR(pll)) |
| 1607 | return ERR_CAST(pll); |
| 1608 | |
| 1609 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 1610 | &tegra_clk_plle_ops); |
| 1611 | if (IS_ERR(clk)) |
| 1612 | kfree(pll); |
| 1613 | |
| 1614 | return clk; |
Prashant Gaikwad | 8f8f484 | 2013-01-11 13:16:20 +0530 | [diff] [blame] | 1615 | } |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1616 | |
Paul Walmsley | 08acae3 | 2014-12-16 12:38:29 -0800 | [diff] [blame] | 1617 | #if defined(CONFIG_ARCH_TEGRA_114_SOC) || \ |
| 1618 | defined(CONFIG_ARCH_TEGRA_124_SOC) || \ |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 1619 | defined(CONFIG_ARCH_TEGRA_132_SOC) || \ |
| 1620 | defined(CONFIG_ARCH_TEGRA_210_SOC) |
Sachin Kamat | e47e12f | 2013-10-08 16:47:41 +0530 | [diff] [blame] | 1621 | static const struct clk_ops tegra_clk_pllxc_ops = { |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1622 | .is_enabled = clk_pll_is_enabled, |
Rhyland Klein | 7db864c | 2015-06-18 17:28:20 -0400 | [diff] [blame] | 1623 | .enable = clk_pll_enable, |
| 1624 | .disable = clk_pll_disable, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1625 | .recalc_rate = clk_pll_recalc_rate, |
| 1626 | .round_rate = clk_pll_ramp_round_rate, |
| 1627 | .set_rate = clk_pllxc_set_rate, |
| 1628 | }; |
| 1629 | |
Sachin Kamat | e47e12f | 2013-10-08 16:47:41 +0530 | [diff] [blame] | 1630 | static const struct clk_ops tegra_clk_pllc_ops = { |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1631 | .is_enabled = clk_pll_is_enabled, |
| 1632 | .enable = clk_pllc_enable, |
| 1633 | .disable = clk_pllc_disable, |
| 1634 | .recalc_rate = clk_pll_recalc_rate, |
| 1635 | .round_rate = clk_pll_ramp_round_rate, |
| 1636 | .set_rate = clk_pllc_set_rate, |
| 1637 | }; |
| 1638 | |
Sachin Kamat | e47e12f | 2013-10-08 16:47:41 +0530 | [diff] [blame] | 1639 | static const struct clk_ops tegra_clk_pllre_ops = { |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1640 | .is_enabled = clk_pll_is_enabled, |
Rhyland Klein | 7db864c | 2015-06-18 17:28:20 -0400 | [diff] [blame] | 1641 | .enable = clk_pll_enable, |
| 1642 | .disable = clk_pll_disable, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1643 | .recalc_rate = clk_pllre_recalc_rate, |
| 1644 | .round_rate = clk_pllre_round_rate, |
| 1645 | .set_rate = clk_pllre_set_rate, |
| 1646 | }; |
| 1647 | |
Sachin Kamat | e47e12f | 2013-10-08 16:47:41 +0530 | [diff] [blame] | 1648 | static const struct clk_ops tegra_clk_plle_tegra114_ops = { |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1649 | .is_enabled = clk_pll_is_enabled, |
| 1650 | .enable = clk_plle_tegra114_enable, |
| 1651 | .disable = clk_plle_tegra114_disable, |
| 1652 | .recalc_rate = clk_pll_recalc_rate, |
| 1653 | }; |
| 1654 | |
| 1655 | |
| 1656 | struct clk *tegra_clk_register_pllxc(const char *name, const char *parent_name, |
| 1657 | void __iomem *clk_base, void __iomem *pmc, |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1658 | unsigned long flags, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1659 | struct tegra_clk_pll_params *pll_params, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1660 | spinlock_t *lock) |
| 1661 | { |
| 1662 | struct tegra_clk_pll *pll; |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1663 | struct clk *clk, *parent; |
| 1664 | unsigned long parent_rate; |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1665 | u32 val, val_iddq; |
| 1666 | |
| 1667 | parent = __clk_lookup(parent_name); |
Wei Yongjun | 62ce7cd | 2013-10-29 03:07:57 +0100 | [diff] [blame] | 1668 | if (!parent) { |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1669 | WARN(1, "parent clk %s of %s must be registered first\n", |
Tomeu Vizoso | ca036b2 | 2014-09-30 09:22:00 +0200 | [diff] [blame] | 1670 | parent_name, name); |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1671 | return ERR_PTR(-EINVAL); |
| 1672 | } |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1673 | |
| 1674 | if (!pll_params->pdiv_tohw) |
| 1675 | return ERR_PTR(-EINVAL); |
| 1676 | |
Stephen Boyd | 5cdb1dc | 2015-07-30 17:20:57 -0700 | [diff] [blame] | 1677 | parent_rate = clk_get_rate(parent); |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1678 | |
| 1679 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 1680 | |
Bill Huang | b5512b4 | 2015-06-18 17:28:30 -0400 | [diff] [blame] | 1681 | if (pll_params->adjust_vco) |
| 1682 | pll_params->vco_min = pll_params->adjust_vco(pll_params, |
| 1683 | parent_rate); |
| 1684 | |
Bill Huang | b985114 | 2015-06-18 17:28:31 -0400 | [diff] [blame] | 1685 | /* |
| 1686 | * If the pll has a set_defaults callback, it will take care of |
| 1687 | * configuring dynamic ramping and setting IDDQ in that path. |
| 1688 | */ |
| 1689 | if (!pll_params->set_defaults) { |
| 1690 | int err; |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1691 | |
Bill Huang | b985114 | 2015-06-18 17:28:31 -0400 | [diff] [blame] | 1692 | err = _setup_dynamic_ramp(pll_params, clk_base, parent_rate); |
| 1693 | if (err) |
| 1694 | return ERR_PTR(err); |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1695 | |
Bill Huang | b985114 | 2015-06-18 17:28:31 -0400 | [diff] [blame] | 1696 | val = readl_relaxed(clk_base + pll_params->base_reg); |
| 1697 | val_iddq = readl_relaxed(clk_base + pll_params->iddq_reg); |
| 1698 | |
| 1699 | if (val & PLL_BASE_ENABLE) |
| 1700 | WARN_ON(val_iddq & BIT(pll_params->iddq_bit_idx)); |
| 1701 | else { |
| 1702 | val_iddq |= BIT(pll_params->iddq_bit_idx); |
| 1703 | writel_relaxed(val_iddq, |
| 1704 | clk_base + pll_params->iddq_reg); |
| 1705 | } |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1706 | } |
| 1707 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1708 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1709 | if (IS_ERR(pll)) |
| 1710 | return ERR_CAST(pll); |
| 1711 | |
| 1712 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 1713 | &tegra_clk_pllxc_ops); |
| 1714 | if (IS_ERR(clk)) |
| 1715 | kfree(pll); |
| 1716 | |
| 1717 | return clk; |
| 1718 | } |
| 1719 | |
| 1720 | struct clk *tegra_clk_register_pllre(const char *name, const char *parent_name, |
| 1721 | void __iomem *clk_base, void __iomem *pmc, |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1722 | unsigned long flags, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1723 | struct tegra_clk_pll_params *pll_params, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1724 | spinlock_t *lock, unsigned long parent_rate) |
| 1725 | { |
| 1726 | u32 val; |
| 1727 | struct tegra_clk_pll *pll; |
| 1728 | struct clk *clk; |
| 1729 | |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1730 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 1731 | |
Bill Huang | b5512b4 | 2015-06-18 17:28:30 -0400 | [diff] [blame] | 1732 | if (pll_params->adjust_vco) |
| 1733 | pll_params->vco_min = pll_params->adjust_vco(pll_params, |
| 1734 | parent_rate); |
| 1735 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1736 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1737 | if (IS_ERR(pll)) |
| 1738 | return ERR_CAST(pll); |
| 1739 | |
| 1740 | /* program minimum rate by default */ |
| 1741 | |
| 1742 | val = pll_readl_base(pll); |
| 1743 | if (val & PLL_BASE_ENABLE) |
Bill Huang | a4ca2b2 | 2015-06-18 17:28:38 -0400 | [diff] [blame] | 1744 | WARN_ON(readl_relaxed(clk_base + pll_params->iddq_reg) & |
| 1745 | BIT(pll_params->iddq_bit_idx)); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1746 | else { |
| 1747 | int m; |
| 1748 | |
| 1749 | m = _pll_fixed_mdiv(pll_params, parent_rate); |
Thierry Reding | c61e4e7 | 2014-04-04 15:55:14 +0200 | [diff] [blame] | 1750 | val = m << divm_shift(pll); |
| 1751 | val |= (pll_params->vco_min / parent_rate) << divn_shift(pll); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1752 | pll_writel_base(val, pll); |
| 1753 | } |
| 1754 | |
| 1755 | /* disable lock override */ |
| 1756 | |
| 1757 | val = pll_readl_misc(pll); |
| 1758 | val &= ~BIT(29); |
| 1759 | pll_writel_misc(val, pll); |
| 1760 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1761 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 1762 | &tegra_clk_pllre_ops); |
| 1763 | if (IS_ERR(clk)) |
| 1764 | kfree(pll); |
| 1765 | |
| 1766 | return clk; |
| 1767 | } |
| 1768 | |
| 1769 | struct clk *tegra_clk_register_pllm(const char *name, const char *parent_name, |
| 1770 | void __iomem *clk_base, void __iomem *pmc, |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1771 | unsigned long flags, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1772 | struct tegra_clk_pll_params *pll_params, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1773 | spinlock_t *lock) |
| 1774 | { |
| 1775 | struct tegra_clk_pll *pll; |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1776 | struct clk *clk, *parent; |
| 1777 | unsigned long parent_rate; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1778 | |
| 1779 | if (!pll_params->pdiv_tohw) |
| 1780 | return ERR_PTR(-EINVAL); |
| 1781 | |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1782 | parent = __clk_lookup(parent_name); |
Wei Yongjun | 62ce7cd | 2013-10-29 03:07:57 +0100 | [diff] [blame] | 1783 | if (!parent) { |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1784 | WARN(1, "parent clk %s of %s must be registered first\n", |
Tomeu Vizoso | ca036b2 | 2014-09-30 09:22:00 +0200 | [diff] [blame] | 1785 | parent_name, name); |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1786 | return ERR_PTR(-EINVAL); |
| 1787 | } |
| 1788 | |
Stephen Boyd | 5cdb1dc | 2015-07-30 17:20:57 -0700 | [diff] [blame] | 1789 | parent_rate = clk_get_rate(parent); |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1790 | |
| 1791 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 1792 | |
Bill Huang | b5512b4 | 2015-06-18 17:28:30 -0400 | [diff] [blame] | 1793 | if (pll_params->adjust_vco) |
| 1794 | pll_params->vco_min = pll_params->adjust_vco(pll_params, |
| 1795 | parent_rate); |
| 1796 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1797 | pll_params->flags |= TEGRA_PLL_BYPASS; |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1798 | pll_params->flags |= TEGRA_PLLM; |
| 1799 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1800 | if (IS_ERR(pll)) |
| 1801 | return ERR_CAST(pll); |
| 1802 | |
| 1803 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
Danny Huang | 267b62a | 2015-06-18 17:28:27 -0400 | [diff] [blame] | 1804 | &tegra_clk_pll_ops); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1805 | if (IS_ERR(clk)) |
| 1806 | kfree(pll); |
| 1807 | |
| 1808 | return clk; |
| 1809 | } |
| 1810 | |
| 1811 | struct clk *tegra_clk_register_pllc(const char *name, const char *parent_name, |
| 1812 | void __iomem *clk_base, void __iomem *pmc, |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1813 | unsigned long flags, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1814 | struct tegra_clk_pll_params *pll_params, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1815 | spinlock_t *lock) |
| 1816 | { |
| 1817 | struct clk *parent, *clk; |
Thierry Reding | 385f9ad | 2015-11-19 16:34:06 +0100 | [diff] [blame] | 1818 | const struct pdiv_map *p_tohw = pll_params->pdiv_tohw; |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1819 | struct tegra_clk_pll *pll; |
| 1820 | struct tegra_clk_pll_freq_table cfg; |
| 1821 | unsigned long parent_rate; |
| 1822 | |
| 1823 | if (!p_tohw) |
| 1824 | return ERR_PTR(-EINVAL); |
| 1825 | |
| 1826 | parent = __clk_lookup(parent_name); |
Wei Yongjun | 62ce7cd | 2013-10-29 03:07:57 +0100 | [diff] [blame] | 1827 | if (!parent) { |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1828 | WARN(1, "parent clk %s of %s must be registered first\n", |
Tomeu Vizoso | ca036b2 | 2014-09-30 09:22:00 +0200 | [diff] [blame] | 1829 | parent_name, name); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1830 | return ERR_PTR(-EINVAL); |
| 1831 | } |
| 1832 | |
Stephen Boyd | 5cdb1dc | 2015-07-30 17:20:57 -0700 | [diff] [blame] | 1833 | parent_rate = clk_get_rate(parent); |
Peter De Schrijver | 04edb09 | 2013-09-06 14:37:37 +0300 | [diff] [blame] | 1834 | |
| 1835 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 1836 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1837 | pll_params->flags |= TEGRA_PLL_BYPASS; |
| 1838 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1839 | if (IS_ERR(pll)) |
| 1840 | return ERR_CAST(pll); |
| 1841 | |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1842 | /* |
| 1843 | * Most of PLLC register fields are shadowed, and can not be read |
| 1844 | * directly from PLL h/w. Hence, actual PLLC boot state is unknown. |
| 1845 | * Initialize PLL to default state: disabled, reset; shadow registers |
| 1846 | * loaded with default parameters; dividers are preset for half of |
| 1847 | * minimum VCO rate (the latter assured that shadowed divider settings |
| 1848 | * are within supported range). |
| 1849 | */ |
| 1850 | |
| 1851 | cfg.m = _pll_fixed_mdiv(pll_params, parent_rate); |
| 1852 | cfg.n = cfg.m * pll_params->vco_min / parent_rate; |
| 1853 | |
| 1854 | while (p_tohw->pdiv) { |
| 1855 | if (p_tohw->pdiv == 2) { |
| 1856 | cfg.p = p_tohw->hw_val; |
| 1857 | break; |
| 1858 | } |
| 1859 | p_tohw++; |
| 1860 | } |
| 1861 | |
| 1862 | if (!p_tohw->pdiv) { |
| 1863 | WARN_ON(1); |
| 1864 | return ERR_PTR(-EINVAL); |
| 1865 | } |
| 1866 | |
| 1867 | pll_writel_base(0, pll); |
| 1868 | _update_pll_mnp(pll, &cfg); |
| 1869 | |
| 1870 | pll_writel_misc(PLLCX_MISC_DEFAULT, pll); |
| 1871 | pll_writel(PLLCX_MISC1_DEFAULT, pll_params->ext_misc_reg[0], pll); |
| 1872 | pll_writel(PLLCX_MISC2_DEFAULT, pll_params->ext_misc_reg[1], pll); |
| 1873 | pll_writel(PLLCX_MISC3_DEFAULT, pll_params->ext_misc_reg[2], pll); |
| 1874 | |
| 1875 | _pllcx_update_dynamic_coef(pll, parent_rate, cfg.n); |
| 1876 | |
| 1877 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 1878 | &tegra_clk_pllc_ops); |
| 1879 | if (IS_ERR(clk)) |
| 1880 | kfree(pll); |
| 1881 | |
| 1882 | return clk; |
| 1883 | } |
| 1884 | |
| 1885 | struct clk *tegra_clk_register_plle_tegra114(const char *name, |
| 1886 | const char *parent_name, |
| 1887 | void __iomem *clk_base, unsigned long flags, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1888 | struct tegra_clk_pll_params *pll_params, |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1889 | spinlock_t *lock) |
| 1890 | { |
| 1891 | struct tegra_clk_pll *pll; |
| 1892 | struct clk *clk; |
| 1893 | u32 val, val_aux; |
| 1894 | |
Peter De Schrijver | ebe142b | 2013-10-04 17:28:34 +0300 | [diff] [blame] | 1895 | pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1896 | if (IS_ERR(pll)) |
| 1897 | return ERR_CAST(pll); |
| 1898 | |
| 1899 | /* ensure parent is set to pll_re_vco */ |
| 1900 | |
| 1901 | val = pll_readl_base(pll); |
| 1902 | val_aux = pll_readl(pll_params->aux_reg, pll); |
| 1903 | |
| 1904 | if (val & PLL_BASE_ENABLE) { |
Peter De Schrijver | 8e9cc80 | 2013-11-25 14:44:13 +0200 | [diff] [blame] | 1905 | if ((val_aux & PLLE_AUX_PLLRE_SEL) || |
| 1906 | (val_aux & PLLE_AUX_PLLP_SEL)) |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1907 | WARN(1, "pll_e enabled with unsupported parent %s\n", |
Peter De Schrijver | 8e9cc80 | 2013-11-25 14:44:13 +0200 | [diff] [blame] | 1908 | (val_aux & PLLE_AUX_PLLP_SEL) ? "pllp_out0" : |
| 1909 | "pll_re_vco"); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1910 | } else { |
Peter De Schrijver | 8e9cc80 | 2013-11-25 14:44:13 +0200 | [diff] [blame] | 1911 | val_aux &= ~(PLLE_AUX_PLLRE_SEL | PLLE_AUX_PLLP_SEL); |
Tuomas Tynkkynen | d2c834a | 2014-05-16 16:50:20 +0300 | [diff] [blame] | 1912 | pll_writel(val_aux, pll_params->aux_reg, pll); |
Peter De Schrijver | c1d1939 | 2013-04-03 17:40:41 +0300 | [diff] [blame] | 1913 | } |
| 1914 | |
| 1915 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 1916 | &tegra_clk_plle_tegra114_ops); |
| 1917 | if (IS_ERR(clk)) |
| 1918 | kfree(pll); |
| 1919 | |
| 1920 | return clk; |
| 1921 | } |
| 1922 | #endif |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1923 | |
Paul Walmsley | 08acae3 | 2014-12-16 12:38:29 -0800 | [diff] [blame] | 1924 | #if defined(CONFIG_ARCH_TEGRA_124_SOC) || defined(CONFIG_ARCH_TEGRA_132_SOC) |
Sachin Kamat | e47e12f | 2013-10-08 16:47:41 +0530 | [diff] [blame] | 1925 | static const struct clk_ops tegra_clk_pllss_ops = { |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1926 | .is_enabled = clk_pll_is_enabled, |
Rhyland Klein | 7db864c | 2015-06-18 17:28:20 -0400 | [diff] [blame] | 1927 | .enable = clk_pll_enable, |
| 1928 | .disable = clk_pll_disable, |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1929 | .recalc_rate = clk_pll_recalc_rate, |
| 1930 | .round_rate = clk_pll_ramp_round_rate, |
| 1931 | .set_rate = clk_pllxc_set_rate, |
| 1932 | }; |
| 1933 | |
| 1934 | struct clk *tegra_clk_register_pllss(const char *name, const char *parent_name, |
| 1935 | void __iomem *clk_base, unsigned long flags, |
| 1936 | struct tegra_clk_pll_params *pll_params, |
| 1937 | spinlock_t *lock) |
| 1938 | { |
| 1939 | struct tegra_clk_pll *pll; |
| 1940 | struct clk *clk, *parent; |
| 1941 | struct tegra_clk_pll_freq_table cfg; |
| 1942 | unsigned long parent_rate; |
Bill Huang | 2d7f61f3 | 2015-06-18 17:28:39 -0400 | [diff] [blame] | 1943 | u32 val, val_iddq; |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1944 | int i; |
| 1945 | |
| 1946 | if (!pll_params->div_nmp) |
| 1947 | return ERR_PTR(-EINVAL); |
| 1948 | |
| 1949 | parent = __clk_lookup(parent_name); |
Wei Yongjun | 62ce7cd | 2013-10-29 03:07:57 +0100 | [diff] [blame] | 1950 | if (!parent) { |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1951 | WARN(1, "parent clk %s of %s must be registered first\n", |
Tomeu Vizoso | ca036b2 | 2014-09-30 09:22:00 +0200 | [diff] [blame] | 1952 | parent_name, name); |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1953 | return ERR_PTR(-EINVAL); |
| 1954 | } |
| 1955 | |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1956 | pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); |
| 1957 | if (IS_ERR(pll)) |
| 1958 | return ERR_CAST(pll); |
| 1959 | |
| 1960 | val = pll_readl_base(pll); |
| 1961 | val &= ~PLLSS_REF_SRC_SEL_MASK; |
| 1962 | pll_writel_base(val, pll); |
| 1963 | |
Stephen Boyd | 5cdb1dc | 2015-07-30 17:20:57 -0700 | [diff] [blame] | 1964 | parent_rate = clk_get_rate(parent); |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1965 | |
| 1966 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 1967 | |
| 1968 | /* initialize PLL to minimum rate */ |
| 1969 | |
| 1970 | cfg.m = _pll_fixed_mdiv(pll_params, parent_rate); |
| 1971 | cfg.n = cfg.m * pll_params->vco_min / parent_rate; |
| 1972 | |
| 1973 | for (i = 0; pll_params->pdiv_tohw[i].pdiv; i++) |
| 1974 | ; |
| 1975 | if (!i) { |
| 1976 | kfree(pll); |
| 1977 | return ERR_PTR(-EINVAL); |
| 1978 | } |
| 1979 | |
| 1980 | cfg.p = pll_params->pdiv_tohw[i-1].hw_val; |
| 1981 | |
| 1982 | _update_pll_mnp(pll, &cfg); |
| 1983 | |
| 1984 | pll_writel_misc(PLLSS_MISC_DEFAULT, pll); |
| 1985 | pll_writel(PLLSS_CFG_DEFAULT, pll_params->ext_misc_reg[0], pll); |
| 1986 | pll_writel(PLLSS_CTRL1_DEFAULT, pll_params->ext_misc_reg[1], pll); |
| 1987 | pll_writel(PLLSS_CTRL1_DEFAULT, pll_params->ext_misc_reg[2], pll); |
| 1988 | |
| 1989 | val = pll_readl_base(pll); |
Bill Huang | 2d7f61f3 | 2015-06-18 17:28:39 -0400 | [diff] [blame] | 1990 | val_iddq = readl_relaxed(clk_base + pll_params->iddq_reg); |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1991 | if (val & PLL_BASE_ENABLE) { |
Bill Huang | 2d7f61f3 | 2015-06-18 17:28:39 -0400 | [diff] [blame] | 1992 | if (val_iddq & BIT(pll_params->iddq_bit_idx)) { |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 1993 | WARN(1, "%s is on but IDDQ set\n", name); |
| 1994 | kfree(pll); |
| 1995 | return ERR_PTR(-EINVAL); |
| 1996 | } |
Bill Huang | 2d7f61f3 | 2015-06-18 17:28:39 -0400 | [diff] [blame] | 1997 | } else { |
| 1998 | val_iddq |= BIT(pll_params->iddq_bit_idx); |
| 1999 | writel_relaxed(val_iddq, clk_base + pll_params->iddq_reg); |
| 2000 | } |
Peter De Schrijver | 798e910 | 2013-09-09 13:22:55 +0300 | [diff] [blame] | 2001 | |
| 2002 | val &= ~PLLSS_LOCK_OVERRIDE; |
| 2003 | pll_writel_base(val, pll); |
| 2004 | |
| 2005 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 2006 | &tegra_clk_pllss_ops); |
| 2007 | |
| 2008 | if (IS_ERR(clk)) |
| 2009 | kfree(pll); |
| 2010 | |
| 2011 | return clk; |
| 2012 | } |
| 2013 | #endif |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2014 | |
| 2015 | #if defined(CONFIG_ARCH_TEGRA_210_SOC) |
Rhyland Klein | 926655f | 2016-03-21 15:58:52 -0400 | [diff] [blame^] | 2016 | struct clk *tegra_clk_register_pllre_tegra210(const char *name, |
| 2017 | const char *parent_name, void __iomem *clk_base, |
| 2018 | void __iomem *pmc, unsigned long flags, |
| 2019 | struct tegra_clk_pll_params *pll_params, |
| 2020 | spinlock_t *lock, unsigned long parent_rate) |
| 2021 | { |
| 2022 | u32 val; |
| 2023 | struct tegra_clk_pll *pll; |
| 2024 | struct clk *clk; |
| 2025 | |
| 2026 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 2027 | |
| 2028 | if (pll_params->adjust_vco) |
| 2029 | pll_params->vco_min = pll_params->adjust_vco(pll_params, |
| 2030 | parent_rate); |
| 2031 | |
| 2032 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
| 2033 | if (IS_ERR(pll)) |
| 2034 | return ERR_CAST(pll); |
| 2035 | |
| 2036 | /* program minimum rate by default */ |
| 2037 | |
| 2038 | val = pll_readl_base(pll); |
| 2039 | if (val & PLL_BASE_ENABLE) |
| 2040 | WARN_ON(readl_relaxed(clk_base + pll_params->iddq_reg) & |
| 2041 | BIT(pll_params->iddq_bit_idx)); |
| 2042 | else { |
| 2043 | val = 0x4 << divm_shift(pll); |
| 2044 | val |= 0x41 << divn_shift(pll); |
| 2045 | pll_writel_base(val, pll); |
| 2046 | } |
| 2047 | |
| 2048 | /* disable lock override */ |
| 2049 | |
| 2050 | val = pll_readl_misc(pll); |
| 2051 | val &= ~BIT(29); |
| 2052 | pll_writel_misc(val, pll); |
| 2053 | |
| 2054 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 2055 | &tegra_clk_pllre_ops); |
| 2056 | if (IS_ERR(clk)) |
| 2057 | kfree(pll); |
| 2058 | |
| 2059 | return clk; |
| 2060 | } |
| 2061 | |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2062 | static int clk_plle_tegra210_enable(struct clk_hw *hw) |
| 2063 | { |
| 2064 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 2065 | struct tegra_clk_pll_freq_table sel; |
| 2066 | u32 val; |
Mark Kuo | f59b016 | 2016-01-14 14:24:36 -0500 | [diff] [blame] | 2067 | int ret = 0; |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2068 | unsigned long flags = 0; |
Andrew Bresticker | 3eb6156 | 2016-01-14 14:24:34 -0500 | [diff] [blame] | 2069 | unsigned long input_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2070 | |
| 2071 | if (_get_table_rate(hw, &sel, pll->params->fixed_rate, input_rate)) |
| 2072 | return -EINVAL; |
| 2073 | |
| 2074 | if (pll->lock) |
| 2075 | spin_lock_irqsave(pll->lock, flags); |
| 2076 | |
Mark Kuo | f59b016 | 2016-01-14 14:24:36 -0500 | [diff] [blame] | 2077 | val = pll_readl(pll->params->aux_reg, pll); |
| 2078 | if (val & PLLE_AUX_SEQ_ENABLE) |
| 2079 | goto out; |
| 2080 | |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2081 | val = pll_readl_base(pll); |
| 2082 | val &= ~BIT(30); /* Disable lock override */ |
| 2083 | pll_writel_base(val, pll); |
| 2084 | |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2085 | val = pll_readl_misc(pll); |
| 2086 | val |= PLLE_MISC_LOCK_ENABLE; |
| 2087 | val |= PLLE_MISC_IDDQ_SW_CTRL; |
| 2088 | val &= ~PLLE_MISC_IDDQ_SW_VALUE; |
| 2089 | val |= PLLE_MISC_PLLE_PTS; |
Rhyland Klein | fd2963b | 2016-01-14 14:24:37 -0500 | [diff] [blame] | 2090 | val &= ~(PLLE_MISC_VREG_BG_CTRL_MASK | PLLE_MISC_VREG_CTRL_MASK); |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2091 | pll_writel_misc(val, pll); |
| 2092 | udelay(5); |
| 2093 | |
| 2094 | val = pll_readl(PLLE_SS_CTRL, pll); |
| 2095 | val |= PLLE_SS_DISABLE; |
| 2096 | pll_writel(val, PLLE_SS_CTRL, pll); |
| 2097 | |
| 2098 | val = pll_readl_base(pll); |
| 2099 | val &= ~(divp_mask_shifted(pll) | divn_mask_shifted(pll) | |
| 2100 | divm_mask_shifted(pll)); |
| 2101 | val &= ~(PLLE_BASE_DIVCML_MASK << PLLE_BASE_DIVCML_SHIFT); |
| 2102 | val |= sel.m << divm_shift(pll); |
| 2103 | val |= sel.n << divn_shift(pll); |
| 2104 | val |= sel.cpcon << PLLE_BASE_DIVCML_SHIFT; |
| 2105 | pll_writel_base(val, pll); |
| 2106 | udelay(1); |
| 2107 | |
| 2108 | val = pll_readl_base(pll); |
| 2109 | val |= PLLE_BASE_ENABLE; |
| 2110 | pll_writel_base(val, pll); |
| 2111 | |
| 2112 | ret = clk_pll_wait_for_lock(pll); |
| 2113 | |
| 2114 | if (ret < 0) |
| 2115 | goto out; |
| 2116 | |
| 2117 | val = pll_readl(PLLE_SS_CTRL, pll); |
| 2118 | val &= ~(PLLE_SS_CNTL_CENTER | PLLE_SS_CNTL_INVERT); |
| 2119 | val &= ~PLLE_SS_COEFFICIENTS_MASK; |
Mark Kuo | 442f53f | 2016-01-14 14:26:42 -0500 | [diff] [blame] | 2120 | val |= PLLE_SS_COEFFICIENTS_VAL_TEGRA210; |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2121 | pll_writel(val, PLLE_SS_CTRL, pll); |
| 2122 | val &= ~(PLLE_SS_CNTL_SSC_BYP | PLLE_SS_CNTL_BYPASS_SS); |
| 2123 | pll_writel(val, PLLE_SS_CTRL, pll); |
| 2124 | udelay(1); |
| 2125 | val &= ~PLLE_SS_CNTL_INTERP_RESET; |
| 2126 | pll_writel(val, PLLE_SS_CTRL, pll); |
| 2127 | udelay(1); |
| 2128 | |
| 2129 | val = pll_readl_misc(pll); |
| 2130 | val &= ~PLLE_MISC_IDDQ_SW_CTRL; |
| 2131 | pll_writel_misc(val, pll); |
| 2132 | |
| 2133 | val = pll_readl(pll->params->aux_reg, pll); |
| 2134 | val |= (PLLE_AUX_USE_LOCKDET | PLLE_AUX_SS_SEQ_INCLUDE); |
| 2135 | val &= ~(PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL); |
| 2136 | pll_writel(val, pll->params->aux_reg, pll); |
| 2137 | udelay(1); |
| 2138 | val |= PLLE_AUX_SEQ_ENABLE; |
| 2139 | pll_writel(val, pll->params->aux_reg, pll); |
| 2140 | |
| 2141 | out: |
| 2142 | if (pll->lock) |
| 2143 | spin_unlock_irqrestore(pll->lock, flags); |
| 2144 | |
| 2145 | return ret; |
| 2146 | } |
| 2147 | |
| 2148 | static void clk_plle_tegra210_disable(struct clk_hw *hw) |
| 2149 | { |
| 2150 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 2151 | unsigned long flags = 0; |
| 2152 | u32 val; |
| 2153 | |
| 2154 | if (pll->lock) |
| 2155 | spin_lock_irqsave(pll->lock, flags); |
| 2156 | |
Mark Kuo | f59b016 | 2016-01-14 14:24:36 -0500 | [diff] [blame] | 2157 | /* If PLLE HW sequencer is enabled, SW should not disable PLLE */ |
| 2158 | val = pll_readl(pll->params->aux_reg, pll); |
| 2159 | if (val & PLLE_AUX_SEQ_ENABLE) |
| 2160 | goto out; |
| 2161 | |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2162 | val = pll_readl_base(pll); |
| 2163 | val &= ~PLLE_BASE_ENABLE; |
| 2164 | pll_writel_base(val, pll); |
| 2165 | |
Mark Kuo | f59b016 | 2016-01-14 14:24:36 -0500 | [diff] [blame] | 2166 | val = pll_readl(pll->params->aux_reg, pll); |
| 2167 | val |= PLLE_AUX_ENABLE_SWCTL | PLLE_AUX_SS_SWCTL; |
| 2168 | pll_writel(val, pll->params->aux_reg, pll); |
| 2169 | |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2170 | val = pll_readl_misc(pll); |
| 2171 | val |= PLLE_MISC_IDDQ_SW_CTRL | PLLE_MISC_IDDQ_SW_VALUE; |
| 2172 | pll_writel_misc(val, pll); |
| 2173 | udelay(1); |
| 2174 | |
Mark Kuo | f59b016 | 2016-01-14 14:24:36 -0500 | [diff] [blame] | 2175 | out: |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2176 | if (pll->lock) |
| 2177 | spin_unlock_irqrestore(pll->lock, flags); |
| 2178 | } |
| 2179 | |
| 2180 | static int clk_plle_tegra210_is_enabled(struct clk_hw *hw) |
| 2181 | { |
| 2182 | struct tegra_clk_pll *pll = to_clk_pll(hw); |
| 2183 | u32 val; |
| 2184 | |
| 2185 | val = pll_readl_base(pll); |
| 2186 | |
| 2187 | return val & PLLE_BASE_ENABLE ? 1 : 0; |
| 2188 | } |
| 2189 | |
| 2190 | static const struct clk_ops tegra_clk_plle_tegra210_ops = { |
| 2191 | .is_enabled = clk_plle_tegra210_is_enabled, |
| 2192 | .enable = clk_plle_tegra210_enable, |
| 2193 | .disable = clk_plle_tegra210_disable, |
| 2194 | .recalc_rate = clk_pll_recalc_rate, |
| 2195 | }; |
| 2196 | |
| 2197 | struct clk *tegra_clk_register_plle_tegra210(const char *name, |
| 2198 | const char *parent_name, |
| 2199 | void __iomem *clk_base, unsigned long flags, |
| 2200 | struct tegra_clk_pll_params *pll_params, |
| 2201 | spinlock_t *lock) |
| 2202 | { |
| 2203 | struct tegra_clk_pll *pll; |
| 2204 | struct clk *clk; |
| 2205 | u32 val, val_aux; |
| 2206 | |
| 2207 | pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); |
| 2208 | if (IS_ERR(pll)) |
| 2209 | return ERR_CAST(pll); |
| 2210 | |
| 2211 | /* ensure parent is set to pll_re_vco */ |
| 2212 | |
| 2213 | val = pll_readl_base(pll); |
| 2214 | val_aux = pll_readl(pll_params->aux_reg, pll); |
| 2215 | |
| 2216 | if (val & PLLE_BASE_ENABLE) { |
| 2217 | if ((val_aux & PLLE_AUX_PLLRE_SEL) || |
| 2218 | (val_aux & PLLE_AUX_PLLP_SEL)) |
| 2219 | WARN(1, "pll_e enabled with unsupported parent %s\n", |
| 2220 | (val_aux & PLLE_AUX_PLLP_SEL) ? "pllp_out0" : |
| 2221 | "pll_re_vco"); |
| 2222 | } else { |
| 2223 | val_aux &= ~(PLLE_AUX_PLLRE_SEL | PLLE_AUX_PLLP_SEL); |
| 2224 | pll_writel(val_aux, pll_params->aux_reg, pll); |
| 2225 | } |
| 2226 | |
| 2227 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 2228 | &tegra_clk_plle_tegra210_ops); |
| 2229 | if (IS_ERR(clk)) |
| 2230 | kfree(pll); |
| 2231 | |
| 2232 | return clk; |
| 2233 | } |
| 2234 | |
| 2235 | struct clk *tegra_clk_register_pllc_tegra210(const char *name, |
| 2236 | const char *parent_name, void __iomem *clk_base, |
| 2237 | void __iomem *pmc, unsigned long flags, |
| 2238 | struct tegra_clk_pll_params *pll_params, |
| 2239 | spinlock_t *lock) |
| 2240 | { |
| 2241 | struct clk *parent, *clk; |
| 2242 | const struct pdiv_map *p_tohw = pll_params->pdiv_tohw; |
| 2243 | struct tegra_clk_pll *pll; |
| 2244 | unsigned long parent_rate; |
| 2245 | |
| 2246 | if (!p_tohw) |
| 2247 | return ERR_PTR(-EINVAL); |
| 2248 | |
| 2249 | parent = __clk_lookup(parent_name); |
| 2250 | if (!parent) { |
| 2251 | WARN(1, "parent clk %s of %s must be registered first\n", |
| 2252 | name, parent_name); |
| 2253 | return ERR_PTR(-EINVAL); |
| 2254 | } |
| 2255 | |
| 2256 | parent_rate = clk_get_rate(parent); |
| 2257 | |
| 2258 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 2259 | |
Bill Huang | b5512b4 | 2015-06-18 17:28:30 -0400 | [diff] [blame] | 2260 | if (pll_params->adjust_vco) |
| 2261 | pll_params->vco_min = pll_params->adjust_vco(pll_params, |
| 2262 | parent_rate); |
| 2263 | |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2264 | pll_params->flags |= TEGRA_PLL_BYPASS; |
| 2265 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
| 2266 | if (IS_ERR(pll)) |
| 2267 | return ERR_CAST(pll); |
| 2268 | |
| 2269 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 2270 | &tegra_clk_pll_ops); |
| 2271 | if (IS_ERR(clk)) |
| 2272 | kfree(pll); |
| 2273 | |
| 2274 | return clk; |
| 2275 | } |
| 2276 | |
| 2277 | struct clk *tegra_clk_register_pllxc_tegra210(const char *name, |
| 2278 | const char *parent_name, void __iomem *clk_base, |
| 2279 | void __iomem *pmc, unsigned long flags, |
| 2280 | struct tegra_clk_pll_params *pll_params, |
| 2281 | spinlock_t *lock) |
| 2282 | { |
| 2283 | struct tegra_clk_pll *pll; |
| 2284 | struct clk *clk, *parent; |
| 2285 | unsigned long parent_rate; |
| 2286 | |
| 2287 | parent = __clk_lookup(parent_name); |
| 2288 | if (!parent) { |
| 2289 | WARN(1, "parent clk %s of %s must be registered first\n", |
| 2290 | name, parent_name); |
| 2291 | return ERR_PTR(-EINVAL); |
| 2292 | } |
| 2293 | |
| 2294 | if (!pll_params->pdiv_tohw) |
| 2295 | return ERR_PTR(-EINVAL); |
| 2296 | |
| 2297 | parent_rate = clk_get_rate(parent); |
| 2298 | |
| 2299 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 2300 | |
Bill Huang | b5512b4 | 2015-06-18 17:28:30 -0400 | [diff] [blame] | 2301 | if (pll_params->adjust_vco) |
| 2302 | pll_params->vco_min = pll_params->adjust_vco(pll_params, |
| 2303 | parent_rate); |
| 2304 | |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2305 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
| 2306 | if (IS_ERR(pll)) |
| 2307 | return ERR_CAST(pll); |
| 2308 | |
| 2309 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 2310 | &tegra_clk_pll_ops); |
| 2311 | if (IS_ERR(clk)) |
| 2312 | kfree(pll); |
| 2313 | |
| 2314 | return clk; |
| 2315 | } |
| 2316 | |
| 2317 | struct clk *tegra_clk_register_pllss_tegra210(const char *name, |
| 2318 | const char *parent_name, void __iomem *clk_base, |
| 2319 | unsigned long flags, |
| 2320 | struct tegra_clk_pll_params *pll_params, |
| 2321 | spinlock_t *lock) |
| 2322 | { |
| 2323 | struct tegra_clk_pll *pll; |
| 2324 | struct clk *clk, *parent; |
| 2325 | struct tegra_clk_pll_freq_table cfg; |
| 2326 | unsigned long parent_rate; |
| 2327 | u32 val; |
| 2328 | int i; |
| 2329 | |
| 2330 | if (!pll_params->div_nmp) |
| 2331 | return ERR_PTR(-EINVAL); |
| 2332 | |
| 2333 | parent = __clk_lookup(parent_name); |
| 2334 | if (!parent) { |
| 2335 | WARN(1, "parent clk %s of %s must be registered first\n", |
| 2336 | name, parent_name); |
| 2337 | return ERR_PTR(-EINVAL); |
| 2338 | } |
| 2339 | |
| 2340 | pll = _tegra_init_pll(clk_base, NULL, pll_params, lock); |
| 2341 | if (IS_ERR(pll)) |
| 2342 | return ERR_CAST(pll); |
| 2343 | |
| 2344 | val = pll_readl_base(pll); |
| 2345 | val &= ~PLLSS_REF_SRC_SEL_MASK; |
| 2346 | pll_writel_base(val, pll); |
| 2347 | |
| 2348 | parent_rate = clk_get_rate(parent); |
| 2349 | |
| 2350 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 2351 | |
Bill Huang | b5512b4 | 2015-06-18 17:28:30 -0400 | [diff] [blame] | 2352 | if (pll_params->adjust_vco) |
| 2353 | pll_params->vco_min = pll_params->adjust_vco(pll_params, |
| 2354 | parent_rate); |
| 2355 | |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2356 | /* initialize PLL to minimum rate */ |
| 2357 | |
| 2358 | cfg.m = _pll_fixed_mdiv(pll_params, parent_rate); |
| 2359 | cfg.n = cfg.m * pll_params->vco_min / parent_rate; |
| 2360 | |
| 2361 | for (i = 0; pll_params->pdiv_tohw[i].pdiv; i++) |
| 2362 | ; |
| 2363 | if (!i) { |
| 2364 | kfree(pll); |
| 2365 | return ERR_PTR(-EINVAL); |
| 2366 | } |
| 2367 | |
| 2368 | cfg.p = pll_params->pdiv_tohw[i-1].hw_val; |
| 2369 | |
| 2370 | _update_pll_mnp(pll, &cfg); |
| 2371 | |
| 2372 | pll_writel_misc(PLLSS_MISC_DEFAULT, pll); |
| 2373 | |
| 2374 | val = pll_readl_base(pll); |
| 2375 | if (val & PLL_BASE_ENABLE) { |
| 2376 | if (val & BIT(pll_params->iddq_bit_idx)) { |
| 2377 | WARN(1, "%s is on but IDDQ set\n", name); |
| 2378 | kfree(pll); |
| 2379 | return ERR_PTR(-EINVAL); |
| 2380 | } |
| 2381 | } else |
| 2382 | val |= BIT(pll_params->iddq_bit_idx); |
| 2383 | |
| 2384 | val &= ~PLLSS_LOCK_OVERRIDE; |
| 2385 | pll_writel_base(val, pll); |
| 2386 | |
| 2387 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 2388 | &tegra_clk_pll_ops); |
| 2389 | |
| 2390 | if (IS_ERR(clk)) |
| 2391 | kfree(pll); |
| 2392 | |
| 2393 | return clk; |
| 2394 | } |
Rhyland Klein | 6929715 | 2015-06-18 17:28:29 -0400 | [diff] [blame] | 2395 | |
| 2396 | struct clk *tegra_clk_register_pllmb(const char *name, const char *parent_name, |
| 2397 | void __iomem *clk_base, void __iomem *pmc, |
| 2398 | unsigned long flags, |
| 2399 | struct tegra_clk_pll_params *pll_params, |
| 2400 | spinlock_t *lock) |
| 2401 | { |
| 2402 | struct tegra_clk_pll *pll; |
| 2403 | struct clk *clk, *parent; |
| 2404 | unsigned long parent_rate; |
| 2405 | |
| 2406 | if (!pll_params->pdiv_tohw) |
| 2407 | return ERR_PTR(-EINVAL); |
| 2408 | |
| 2409 | parent = __clk_lookup(parent_name); |
| 2410 | if (!parent) { |
| 2411 | WARN(1, "parent clk %s of %s must be registered first\n", |
| 2412 | parent_name, name); |
| 2413 | return ERR_PTR(-EINVAL); |
| 2414 | } |
| 2415 | |
| 2416 | parent_rate = clk_get_rate(parent); |
| 2417 | |
| 2418 | pll_params->vco_min = _clip_vco_min(pll_params->vco_min, parent_rate); |
| 2419 | |
Bill Huang | b5512b4 | 2015-06-18 17:28:30 -0400 | [diff] [blame] | 2420 | if (pll_params->adjust_vco) |
| 2421 | pll_params->vco_min = pll_params->adjust_vco(pll_params, |
| 2422 | parent_rate); |
| 2423 | |
Rhyland Klein | 6929715 | 2015-06-18 17:28:29 -0400 | [diff] [blame] | 2424 | pll_params->flags |= TEGRA_PLL_BYPASS; |
| 2425 | pll_params->flags |= TEGRA_PLLMB; |
| 2426 | pll = _tegra_init_pll(clk_base, pmc, pll_params, lock); |
| 2427 | if (IS_ERR(pll)) |
| 2428 | return ERR_CAST(pll); |
| 2429 | |
| 2430 | clk = _tegra_clk_register_pll(pll, name, parent_name, flags, |
| 2431 | &tegra_clk_pll_ops); |
| 2432 | if (IS_ERR(clk)) |
| 2433 | kfree(pll); |
| 2434 | |
| 2435 | return clk; |
| 2436 | } |
Rhyland Klein | dd322f0 | 2015-06-18 17:28:28 -0400 | [diff] [blame] | 2437 | #endif |