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