1 /* 2 * Copyright (c) 2012-2014 NVIDIA CORPORATION. All rights reserved. 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/io.h> 18 #include <linux/clk.h> 19 #include <linux/clk-provider.h> 20 #include <linux/clkdev.h> 21 #include <linux/of.h> 22 #include <linux/of_address.h> 23 #include <linux/delay.h> 24 #include <linux/export.h> 25 #include <linux/clk/tegra.h> 26 #include <dt-bindings/clock/tegra210-car.h> 27 28 #include "clk.h" 29 #include "clk-id.h" 30 31 /* 32 * TEGRA210_CAR_BANK_COUNT: the number of peripheral clock register 33 * banks present in the Tegra210 CAR IP block. The banks are 34 * identified by single letters, e.g.: L, H, U, V, W, X, Y. See 35 * periph_regs[] in drivers/clk/tegra/clk.c 36 */ 37 #define TEGRA210_CAR_BANK_COUNT 7 38 39 #define CLK_SOURCE_CSITE 0x1d4 40 #define CLK_SOURCE_EMC 0x19c 41 42 #define PLLC_BASE 0x80 43 #define PLLC_OUT 0x84 44 #define PLLC_MISC0 0x88 45 #define PLLC_MISC1 0x8c 46 #define PLLC_MISC2 0x5d0 47 #define PLLC_MISC3 0x5d4 48 49 #define PLLC2_BASE 0x4e8 50 #define PLLC2_MISC0 0x4ec 51 #define PLLC2_MISC1 0x4f0 52 #define PLLC2_MISC2 0x4f4 53 #define PLLC2_MISC3 0x4f8 54 55 #define PLLC3_BASE 0x4fc 56 #define PLLC3_MISC0 0x500 57 #define PLLC3_MISC1 0x504 58 #define PLLC3_MISC2 0x508 59 #define PLLC3_MISC3 0x50c 60 61 #define PLLM_BASE 0x90 62 #define PLLM_MISC1 0x98 63 #define PLLM_MISC2 0x9c 64 #define PLLP_BASE 0xa0 65 #define PLLP_MISC0 0xac 66 #define PLLP_MISC1 0x680 67 #define PLLA_BASE 0xb0 68 #define PLLA_MISC0 0xbc 69 #define PLLA_MISC1 0xb8 70 #define PLLA_MISC2 0x5d8 71 #define PLLD_BASE 0xd0 72 #define PLLD_MISC0 0xdc 73 #define PLLD_MISC1 0xd8 74 #define PLLU_BASE 0xc0 75 #define PLLU_OUTA 0xc4 76 #define PLLU_MISC0 0xcc 77 #define PLLU_MISC1 0xc8 78 #define PLLX_BASE 0xe0 79 #define PLLX_MISC0 0xe4 80 #define PLLX_MISC1 0x510 81 #define PLLX_MISC2 0x514 82 #define PLLX_MISC3 0x518 83 #define PLLX_MISC4 0x5f0 84 #define PLLX_MISC5 0x5f4 85 #define PLLE_BASE 0xe8 86 #define PLLE_MISC0 0xec 87 #define PLLD2_BASE 0x4b8 88 #define PLLD2_MISC0 0x4bc 89 #define PLLD2_MISC1 0x570 90 #define PLLD2_MISC2 0x574 91 #define PLLD2_MISC3 0x578 92 #define PLLE_AUX 0x48c 93 #define PLLRE_BASE 0x4c4 94 #define PLLRE_MISC0 0x4c8 95 #define PLLRE_OUT1 0x4cc 96 #define PLLDP_BASE 0x590 97 #define PLLDP_MISC 0x594 98 99 #define PLLC4_BASE 0x5a4 100 #define PLLC4_MISC0 0x5a8 101 #define PLLC4_OUT 0x5e4 102 #define PLLMB_BASE 0x5e8 103 #define PLLMB_MISC1 0x5ec 104 #define PLLA1_BASE 0x6a4 105 #define PLLA1_MISC0 0x6a8 106 #define PLLA1_MISC1 0x6ac 107 #define PLLA1_MISC2 0x6b0 108 #define PLLA1_MISC3 0x6b4 109 110 #define PLLU_IDDQ_BIT 31 111 #define PLLCX_IDDQ_BIT 27 112 #define PLLRE_IDDQ_BIT 24 113 #define PLLA_IDDQ_BIT 25 114 #define PLLD_IDDQ_BIT 20 115 #define PLLSS_IDDQ_BIT 18 116 #define PLLM_IDDQ_BIT 5 117 #define PLLMB_IDDQ_BIT 17 118 #define PLLXP_IDDQ_BIT 3 119 120 #define PLLCX_RESET_BIT 30 121 122 #define PLL_BASE_LOCK BIT(27) 123 #define PLLCX_BASE_LOCK BIT(26) 124 #define PLLE_MISC_LOCK BIT(11) 125 #define PLLRE_MISC_LOCK BIT(27) 126 127 #define PLL_MISC_LOCK_ENABLE 18 128 #define PLLC_MISC_LOCK_ENABLE 24 129 #define PLLDU_MISC_LOCK_ENABLE 22 130 #define PLLU_MISC_LOCK_ENABLE 29 131 #define PLLE_MISC_LOCK_ENABLE 9 132 #define PLLRE_MISC_LOCK_ENABLE 30 133 #define PLLSS_MISC_LOCK_ENABLE 30 134 #define PLLP_MISC_LOCK_ENABLE 18 135 #define PLLM_MISC_LOCK_ENABLE 4 136 #define PLLMB_MISC_LOCK_ENABLE 16 137 #define PLLA_MISC_LOCK_ENABLE 28 138 #define PLLU_MISC_LOCK_ENABLE 29 139 #define PLLD_MISC_LOCK_ENABLE 18 140 141 #define PLLA_SDM_DIN_MASK 0xffff 142 #define PLLA_SDM_EN_MASK BIT(26) 143 144 #define PLLD_SDM_EN_MASK BIT(16) 145 146 #define PLLD2_SDM_EN_MASK BIT(31) 147 #define PLLD2_SSC_EN_MASK BIT(30) 148 149 #define PLLDP_SS_CFG 0x598 150 #define PLLDP_SDM_EN_MASK BIT(31) 151 #define PLLDP_SSC_EN_MASK BIT(30) 152 #define PLLDP_SS_CTRL1 0x59c 153 #define PLLDP_SS_CTRL2 0x5a0 154 155 #define PMC_PLLM_WB0_OVERRIDE 0x1dc 156 #define PMC_PLLM_WB0_OVERRIDE_2 0x2b0 157 158 #define UTMIP_PLL_CFG2 0x488 159 #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6) 160 #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18) 161 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN BIT(0) 162 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP BIT(1) 163 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN BIT(2) 164 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP BIT(3) 165 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN BIT(4) 166 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERUP BIT(5) 167 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN BIT(24) 168 #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP BIT(25) 169 170 #define UTMIP_PLL_CFG1 0x484 171 #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) 172 #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) 173 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERUP BIT(17) 174 #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN BIT(16) 175 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP BIT(15) 176 #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN BIT(14) 177 #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN BIT(12) 178 179 #define SATA_PLL_CFG0 0x490 180 #define SATA_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0) 181 #define SATA_PLL_CFG0_PADPLL_USE_LOCKDET BIT(2) 182 #define SATA_PLL_CFG0_PADPLL_SLEEP_IDDQ BIT(13) 183 #define SATA_PLL_CFG0_SEQ_ENABLE BIT(24) 184 185 #define XUSBIO_PLL_CFG0 0x51c 186 #define XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL BIT(0) 187 #define XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL BIT(2) 188 #define XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET BIT(6) 189 #define XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ BIT(13) 190 #define XUSBIO_PLL_CFG0_SEQ_ENABLE BIT(24) 191 192 #define UTMIPLL_HW_PWRDN_CFG0 0x52c 193 #define UTMIPLL_HW_PWRDN_CFG0_UTMIPLL_LOCK BIT(31) 194 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_START_STATE BIT(25) 195 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24) 196 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(7) 197 #define UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET BIT(6) 198 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_RESET_INPUT_VALUE BIT(5) 199 #define UTMIPLL_HW_PWRDN_CFG0_SEQ_IN_SWCTL BIT(4) 200 #define UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2) 201 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE BIT(1) 202 #define UTMIPLL_HW_PWRDN_CFG0_IDDQ_SWCTL BIT(0) 203 204 #define PLLU_HW_PWRDN_CFG0 0x530 205 #define PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE BIT(28) 206 #define PLLU_HW_PWRDN_CFG0_SEQ_ENABLE BIT(24) 207 #define PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT BIT(7) 208 #define PLLU_HW_PWRDN_CFG0_USE_LOCKDET BIT(6) 209 #define PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL BIT(2) 210 #define PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL BIT(0) 211 212 #define XUSB_PLL_CFG0 0x534 213 #define XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY 0x3ff 214 #define XUSB_PLL_CFG0_PLLU_LOCK_DLY_MASK (0x3ff << 14) 215 216 #define SPARE_REG0 0x55c 217 #define CLK_M_DIVISOR_SHIFT 2 218 #define CLK_M_DIVISOR_MASK 0x3 219 220 /* 221 * SDM fractional divisor is 16-bit 2's complement signed number within 222 * (-2^12 ... 2^12-1) range. Represented in PLL data structure as unsigned 223 * 16-bit value, with "0" divisor mapped to 0xFFFF. Data "0" is used to 224 * indicate that SDM is disabled. 225 * 226 * Effective ndiv value when SDM is enabled: ndiv + 1/2 + sdm_din/2^13 227 */ 228 #define PLL_SDM_COEFF BIT(13) 229 #define sdin_din_to_data(din) ((u16)((din) ? : 0xFFFFU)) 230 #define sdin_data_to_din(dat) (((dat) == 0xFFFFU) ? 0 : (s16)dat) 231 232 /* Tegra CPU clock and reset control regs */ 233 #define CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470 234 235 #ifdef CONFIG_PM_SLEEP 236 static struct cpu_clk_suspend_context { 237 u32 clk_csite_src; 238 } tegra210_cpu_clk_sctx; 239 #endif 240 241 static void __iomem *clk_base; 242 static void __iomem *pmc_base; 243 244 static unsigned long osc_freq; 245 static unsigned long pll_ref_freq; 246 247 static DEFINE_SPINLOCK(pll_d_lock); 248 static DEFINE_SPINLOCK(pll_e_lock); 249 static DEFINE_SPINLOCK(pll_re_lock); 250 static DEFINE_SPINLOCK(pll_u_lock); 251 static DEFINE_SPINLOCK(emc_lock); 252 253 /* possible OSC frequencies in Hz */ 254 static unsigned long tegra210_input_freq[] = { 255 [5] = 38400000, 256 [8] = 12000000, 257 }; 258 259 static const char *mux_pllmcp_clkm[] = { 260 "pll_m", "pll_c", "pll_p", "clk_m", "pll_m_ud", "pll_mb", "pll_mb", 261 "pll_p", 262 }; 263 #define mux_pllmcp_clkm_idx NULL 264 265 #define PLL_ENABLE (1 << 30) 266 267 #define PLLCX_MISC1_IDDQ (1 << 27) 268 #define PLLCX_MISC0_RESET (1 << 30) 269 270 #define PLLCX_MISC0_DEFAULT_VALUE 0x40080000 271 #define PLLCX_MISC0_WRITE_MASK 0x400ffffb 272 #define PLLCX_MISC1_DEFAULT_VALUE 0x08000000 273 #define PLLCX_MISC1_WRITE_MASK 0x08003cff 274 #define PLLCX_MISC2_DEFAULT_VALUE 0x1f720f05 275 #define PLLCX_MISC2_WRITE_MASK 0xffffff17 276 #define PLLCX_MISC3_DEFAULT_VALUE 0x000000c4 277 #define PLLCX_MISC3_WRITE_MASK 0x00ffffff 278 279 /* PLLA */ 280 #define PLLA_BASE_IDDQ (1 << 25) 281 #define PLLA_BASE_LOCK (1 << 27) 282 283 #define PLLA_MISC0_LOCK_ENABLE (1 << 28) 284 #define PLLA_MISC0_LOCK_OVERRIDE (1 << 27) 285 286 #define PLLA_MISC2_EN_SDM (1 << 26) 287 #define PLLA_MISC2_EN_DYNRAMP (1 << 25) 288 289 #define PLLA_MISC0_DEFAULT_VALUE 0x12000020 290 #define PLLA_MISC0_WRITE_MASK 0x7fffffff 291 #define PLLA_MISC2_DEFAULT_VALUE 0x0 292 #define PLLA_MISC2_WRITE_MASK 0x06ffffff 293 294 /* PLLD */ 295 #define PLLD_MISC0_EN_SDM (1 << 16) 296 #define PLLD_MISC0_LOCK_OVERRIDE (1 << 17) 297 #define PLLD_MISC0_LOCK_ENABLE (1 << 18) 298 #define PLLD_MISC0_IDDQ (1 << 20) 299 #define PLLD_MISC0_DSI_CLKENABLE (1 << 21) 300 301 #define PLLD_MISC0_DEFAULT_VALUE 0x00140000 302 #define PLLD_MISC0_WRITE_MASK 0x3ff7ffff 303 #define PLLD_MISC1_DEFAULT_VALUE 0x20 304 #define PLLD_MISC1_WRITE_MASK 0x00ffffff 305 306 /* PLLD2 and PLLDP and PLLC4 */ 307 #define PLLDSS_BASE_LOCK (1 << 27) 308 #define PLLDSS_BASE_LOCK_OVERRIDE (1 << 24) 309 #define PLLDSS_BASE_IDDQ (1 << 18) 310 #define PLLDSS_BASE_REF_SEL_SHIFT 25 311 #define PLLDSS_BASE_REF_SEL_MASK (0x3 << PLLDSS_BASE_REF_SEL_SHIFT) 312 313 #define PLLDSS_MISC0_LOCK_ENABLE (1 << 30) 314 315 #define PLLDSS_MISC1_CFG_EN_SDM (1 << 31) 316 #define PLLDSS_MISC1_CFG_EN_SSC (1 << 30) 317 318 #define PLLD2_MISC0_DEFAULT_VALUE 0x40000020 319 #define PLLD2_MISC1_CFG_DEFAULT_VALUE 0x10000000 320 #define PLLD2_MISC2_CTRL1_DEFAULT_VALUE 0x0 321 #define PLLD2_MISC3_CTRL2_DEFAULT_VALUE 0x0 322 323 #define PLLDP_MISC0_DEFAULT_VALUE 0x40000020 324 #define PLLDP_MISC1_CFG_DEFAULT_VALUE 0xc0000000 325 #define PLLDP_MISC2_CTRL1_DEFAULT_VALUE 0xf400f0da 326 #define PLLDP_MISC3_CTRL2_DEFAULT_VALUE 0x2004f400 327 328 #define PLLDSS_MISC0_WRITE_MASK 0x47ffffff 329 #define PLLDSS_MISC1_CFG_WRITE_MASK 0xf8000000 330 #define PLLDSS_MISC2_CTRL1_WRITE_MASK 0xffffffff 331 #define PLLDSS_MISC3_CTRL2_WRITE_MASK 0xffffffff 332 333 #define PLLC4_MISC0_DEFAULT_VALUE 0x40000000 334 335 /* PLLRE */ 336 #define PLLRE_MISC0_LOCK_ENABLE (1 << 30) 337 #define PLLRE_MISC0_LOCK_OVERRIDE (1 << 29) 338 #define PLLRE_MISC0_LOCK (1 << 27) 339 #define PLLRE_MISC0_IDDQ (1 << 24) 340 341 #define PLLRE_BASE_DEFAULT_VALUE 0x0 342 #define PLLRE_MISC0_DEFAULT_VALUE 0x41000000 343 344 #define PLLRE_BASE_DEFAULT_MASK 0x1c000000 345 #define PLLRE_MISC0_WRITE_MASK 0x67ffffff 346 347 /* PLLX */ 348 #define PLLX_USE_DYN_RAMP 1 349 #define PLLX_BASE_LOCK (1 << 27) 350 351 #define PLLX_MISC0_FO_G_DISABLE (0x1 << 28) 352 #define PLLX_MISC0_LOCK_ENABLE (0x1 << 18) 353 354 #define PLLX_MISC2_DYNRAMP_STEPB_SHIFT 24 355 #define PLLX_MISC2_DYNRAMP_STEPB_MASK (0xFF << PLLX_MISC2_DYNRAMP_STEPB_SHIFT) 356 #define PLLX_MISC2_DYNRAMP_STEPA_SHIFT 16 357 #define PLLX_MISC2_DYNRAMP_STEPA_MASK (0xFF << PLLX_MISC2_DYNRAMP_STEPA_SHIFT) 358 #define PLLX_MISC2_NDIV_NEW_SHIFT 8 359 #define PLLX_MISC2_NDIV_NEW_MASK (0xFF << PLLX_MISC2_NDIV_NEW_SHIFT) 360 #define PLLX_MISC2_LOCK_OVERRIDE (0x1 << 4) 361 #define PLLX_MISC2_DYNRAMP_DONE (0x1 << 2) 362 #define PLLX_MISC2_EN_DYNRAMP (0x1 << 0) 363 364 #define PLLX_MISC3_IDDQ (0x1 << 3) 365 366 #define PLLX_MISC0_DEFAULT_VALUE PLLX_MISC0_LOCK_ENABLE 367 #define PLLX_MISC0_WRITE_MASK 0x10c40000 368 #define PLLX_MISC1_DEFAULT_VALUE 0x20 369 #define PLLX_MISC1_WRITE_MASK 0x00ffffff 370 #define PLLX_MISC2_DEFAULT_VALUE 0x0 371 #define PLLX_MISC2_WRITE_MASK 0xffffff11 372 #define PLLX_MISC3_DEFAULT_VALUE PLLX_MISC3_IDDQ 373 #define PLLX_MISC3_WRITE_MASK 0x01ff0f0f 374 #define PLLX_MISC4_DEFAULT_VALUE 0x0 375 #define PLLX_MISC4_WRITE_MASK 0x8000ffff 376 #define PLLX_MISC5_DEFAULT_VALUE 0x0 377 #define PLLX_MISC5_WRITE_MASK 0x0000ffff 378 379 #define PLLX_HW_CTRL_CFG 0x548 380 #define PLLX_HW_CTRL_CFG_SWCTRL (0x1 << 0) 381 382 /* PLLMB */ 383 #define PLLMB_BASE_LOCK (1 << 27) 384 385 #define PLLMB_MISC1_LOCK_OVERRIDE (1 << 18) 386 #define PLLMB_MISC1_IDDQ (1 << 17) 387 #define PLLMB_MISC1_LOCK_ENABLE (1 << 16) 388 389 #define PLLMB_MISC1_DEFAULT_VALUE 0x00030000 390 #define PLLMB_MISC1_WRITE_MASK 0x0007ffff 391 392 /* PLLP */ 393 #define PLLP_BASE_OVERRIDE (1 << 28) 394 #define PLLP_BASE_LOCK (1 << 27) 395 396 #define PLLP_MISC0_LOCK_ENABLE (1 << 18) 397 #define PLLP_MISC0_LOCK_OVERRIDE (1 << 17) 398 #define PLLP_MISC0_IDDQ (1 << 3) 399 400 #define PLLP_MISC1_HSIO_EN_SHIFT 29 401 #define PLLP_MISC1_HSIO_EN (1 << PLLP_MISC1_HSIO_EN_SHIFT) 402 #define PLLP_MISC1_XUSB_EN_SHIFT 28 403 #define PLLP_MISC1_XUSB_EN (1 << PLLP_MISC1_XUSB_EN_SHIFT) 404 405 #define PLLP_MISC0_DEFAULT_VALUE 0x00040008 406 #define PLLP_MISC1_DEFAULT_VALUE 0x0 407 408 #define PLLP_MISC0_WRITE_MASK 0xdc6000f 409 #define PLLP_MISC1_WRITE_MASK 0x70ffffff 410 411 /* PLLU */ 412 #define PLLU_BASE_LOCK (1 << 27) 413 #define PLLU_BASE_OVERRIDE (1 << 24) 414 #define PLLU_BASE_CLKENABLE_USB (1 << 21) 415 #define PLLU_BASE_CLKENABLE_HSIC (1 << 22) 416 #define PLLU_BASE_CLKENABLE_ICUSB (1 << 23) 417 #define PLLU_BASE_CLKENABLE_48M (1 << 25) 418 #define PLLU_BASE_CLKENABLE_ALL (PLLU_BASE_CLKENABLE_USB |\ 419 PLLU_BASE_CLKENABLE_HSIC |\ 420 PLLU_BASE_CLKENABLE_ICUSB |\ 421 PLLU_BASE_CLKENABLE_48M) 422 423 #define PLLU_MISC0_IDDQ (1 << 31) 424 #define PLLU_MISC0_LOCK_ENABLE (1 << 29) 425 #define PLLU_MISC1_LOCK_OVERRIDE (1 << 0) 426 427 #define PLLU_MISC0_DEFAULT_VALUE 0xa0000000 428 #define PLLU_MISC1_DEFAULT_VALUE 0x0 429 430 #define PLLU_MISC0_WRITE_MASK 0xbfffffff 431 #define PLLU_MISC1_WRITE_MASK 0x00000007 432 433 void tegra210_xusb_pll_hw_control_enable(void) 434 { 435 u32 val; 436 437 val = readl_relaxed(clk_base + XUSBIO_PLL_CFG0); 438 val &= ~(XUSBIO_PLL_CFG0_CLK_ENABLE_SWCTL | 439 XUSBIO_PLL_CFG0_PADPLL_RESET_SWCTL); 440 val |= XUSBIO_PLL_CFG0_PADPLL_USE_LOCKDET | 441 XUSBIO_PLL_CFG0_PADPLL_SLEEP_IDDQ; 442 writel_relaxed(val, clk_base + XUSBIO_PLL_CFG0); 443 } 444 EXPORT_SYMBOL_GPL(tegra210_xusb_pll_hw_control_enable); 445 446 void tegra210_xusb_pll_hw_sequence_start(void) 447 { 448 u32 val; 449 450 val = readl_relaxed(clk_base + XUSBIO_PLL_CFG0); 451 val |= XUSBIO_PLL_CFG0_SEQ_ENABLE; 452 writel_relaxed(val, clk_base + XUSBIO_PLL_CFG0); 453 } 454 EXPORT_SYMBOL_GPL(tegra210_xusb_pll_hw_sequence_start); 455 456 void tegra210_sata_pll_hw_control_enable(void) 457 { 458 u32 val; 459 460 val = readl_relaxed(clk_base + SATA_PLL_CFG0); 461 val &= ~SATA_PLL_CFG0_PADPLL_RESET_SWCTL; 462 val |= SATA_PLL_CFG0_PADPLL_USE_LOCKDET | 463 SATA_PLL_CFG0_PADPLL_SLEEP_IDDQ; 464 writel_relaxed(val, clk_base + SATA_PLL_CFG0); 465 } 466 EXPORT_SYMBOL_GPL(tegra210_sata_pll_hw_control_enable); 467 468 void tegra210_sata_pll_hw_sequence_start(void) 469 { 470 u32 val; 471 472 val = readl_relaxed(clk_base + SATA_PLL_CFG0); 473 val |= SATA_PLL_CFG0_SEQ_ENABLE; 474 writel_relaxed(val, clk_base + SATA_PLL_CFG0); 475 } 476 EXPORT_SYMBOL_GPL(tegra210_sata_pll_hw_sequence_start); 477 478 static inline void _pll_misc_chk_default(void __iomem *base, 479 struct tegra_clk_pll_params *params, 480 u8 misc_num, u32 default_val, u32 mask) 481 { 482 u32 boot_val = readl_relaxed(base + params->ext_misc_reg[misc_num]); 483 484 boot_val &= mask; 485 default_val &= mask; 486 if (boot_val != default_val) { 487 pr_warn("boot misc%d 0x%x: expected 0x%x\n", 488 misc_num, boot_val, default_val); 489 pr_warn(" (comparison mask = 0x%x)\n", mask); 490 params->defaults_set = false; 491 } 492 } 493 494 /* 495 * PLLCX: PLLC, PLLC2, PLLC3, PLLA1 496 * Hybrid PLLs with dynamic ramp. Dynamic ramp is allowed for any transition 497 * that changes NDIV only, while PLL is already locked. 498 */ 499 static void pllcx_check_defaults(struct tegra_clk_pll_params *params) 500 { 501 u32 default_val; 502 503 default_val = PLLCX_MISC0_DEFAULT_VALUE & (~PLLCX_MISC0_RESET); 504 _pll_misc_chk_default(clk_base, params, 0, default_val, 505 PLLCX_MISC0_WRITE_MASK); 506 507 default_val = PLLCX_MISC1_DEFAULT_VALUE & (~PLLCX_MISC1_IDDQ); 508 _pll_misc_chk_default(clk_base, params, 1, default_val, 509 PLLCX_MISC1_WRITE_MASK); 510 511 default_val = PLLCX_MISC2_DEFAULT_VALUE; 512 _pll_misc_chk_default(clk_base, params, 2, default_val, 513 PLLCX_MISC2_WRITE_MASK); 514 515 default_val = PLLCX_MISC3_DEFAULT_VALUE; 516 _pll_misc_chk_default(clk_base, params, 3, default_val, 517 PLLCX_MISC3_WRITE_MASK); 518 } 519 520 static void tegra210_pllcx_set_defaults(const char *name, 521 struct tegra_clk_pll *pllcx) 522 { 523 pllcx->params->defaults_set = true; 524 525 if (readl_relaxed(clk_base + pllcx->params->base_reg) & 526 PLL_ENABLE) { 527 /* PLL is ON: only check if defaults already set */ 528 pllcx_check_defaults(pllcx->params); 529 pr_warn("%s already enabled. Postponing set full defaults\n", 530 name); 531 return; 532 } 533 534 /* Defaults assert PLL reset, and set IDDQ */ 535 writel_relaxed(PLLCX_MISC0_DEFAULT_VALUE, 536 clk_base + pllcx->params->ext_misc_reg[0]); 537 writel_relaxed(PLLCX_MISC1_DEFAULT_VALUE, 538 clk_base + pllcx->params->ext_misc_reg[1]); 539 writel_relaxed(PLLCX_MISC2_DEFAULT_VALUE, 540 clk_base + pllcx->params->ext_misc_reg[2]); 541 writel_relaxed(PLLCX_MISC3_DEFAULT_VALUE, 542 clk_base + pllcx->params->ext_misc_reg[3]); 543 udelay(1); 544 } 545 546 static void _pllc_set_defaults(struct tegra_clk_pll *pllcx) 547 { 548 tegra210_pllcx_set_defaults("PLL_C", pllcx); 549 } 550 551 static void _pllc2_set_defaults(struct tegra_clk_pll *pllcx) 552 { 553 tegra210_pllcx_set_defaults("PLL_C2", pllcx); 554 } 555 556 static void _pllc3_set_defaults(struct tegra_clk_pll *pllcx) 557 { 558 tegra210_pllcx_set_defaults("PLL_C3", pllcx); 559 } 560 561 static void _plla1_set_defaults(struct tegra_clk_pll *pllcx) 562 { 563 tegra210_pllcx_set_defaults("PLL_A1", pllcx); 564 } 565 566 /* 567 * PLLA 568 * PLL with dynamic ramp and fractional SDM. Dynamic ramp is not used. 569 * Fractional SDM is allowed to provide exact audio rates. 570 */ 571 static void tegra210_plla_set_defaults(struct tegra_clk_pll *plla) 572 { 573 u32 mask; 574 u32 val = readl_relaxed(clk_base + plla->params->base_reg); 575 576 plla->params->defaults_set = true; 577 578 if (val & PLL_ENABLE) { 579 /* 580 * PLL is ON: check if defaults already set, then set those 581 * that can be updated in flight. 582 */ 583 if (val & PLLA_BASE_IDDQ) { 584 pr_warn("PLL_A boot enabled with IDDQ set\n"); 585 plla->params->defaults_set = false; 586 } 587 588 pr_warn("PLL_A already enabled. Postponing set full defaults\n"); 589 590 val = PLLA_MISC0_DEFAULT_VALUE; /* ignore lock enable */ 591 mask = PLLA_MISC0_LOCK_ENABLE | PLLA_MISC0_LOCK_OVERRIDE; 592 _pll_misc_chk_default(clk_base, plla->params, 0, val, 593 ~mask & PLLA_MISC0_WRITE_MASK); 594 595 val = PLLA_MISC2_DEFAULT_VALUE; /* ignore all but control bit */ 596 _pll_misc_chk_default(clk_base, plla->params, 2, val, 597 PLLA_MISC2_EN_DYNRAMP); 598 599 /* Enable lock detect */ 600 val = readl_relaxed(clk_base + plla->params->ext_misc_reg[0]); 601 val &= ~mask; 602 val |= PLLA_MISC0_DEFAULT_VALUE & mask; 603 writel_relaxed(val, clk_base + plla->params->ext_misc_reg[0]); 604 udelay(1); 605 606 return; 607 } 608 609 /* set IDDQ, enable lock detect, disable dynamic ramp and SDM */ 610 val |= PLLA_BASE_IDDQ; 611 writel_relaxed(val, clk_base + plla->params->base_reg); 612 writel_relaxed(PLLA_MISC0_DEFAULT_VALUE, 613 clk_base + plla->params->ext_misc_reg[0]); 614 writel_relaxed(PLLA_MISC2_DEFAULT_VALUE, 615 clk_base + plla->params->ext_misc_reg[2]); 616 udelay(1); 617 } 618 619 /* 620 * PLLD 621 * PLL with fractional SDM. 622 */ 623 static void tegra210_plld_set_defaults(struct tegra_clk_pll *plld) 624 { 625 u32 val; 626 u32 mask = 0xffff; 627 628 plld->params->defaults_set = true; 629 630 if (readl_relaxed(clk_base + plld->params->base_reg) & 631 PLL_ENABLE) { 632 pr_warn("PLL_D already enabled. Postponing set full defaults\n"); 633 634 /* 635 * PLL is ON: check if defaults already set, then set those 636 * that can be updated in flight. 637 */ 638 val = PLLD_MISC1_DEFAULT_VALUE; 639 _pll_misc_chk_default(clk_base, plld->params, 1, 640 val, PLLD_MISC1_WRITE_MASK); 641 642 /* ignore lock, DSI and SDM controls, make sure IDDQ not set */ 643 val = PLLD_MISC0_DEFAULT_VALUE & (~PLLD_MISC0_IDDQ); 644 mask |= PLLD_MISC0_DSI_CLKENABLE | PLLD_MISC0_LOCK_ENABLE | 645 PLLD_MISC0_LOCK_OVERRIDE | PLLD_MISC0_EN_SDM; 646 _pll_misc_chk_default(clk_base, plld->params, 0, val, 647 ~mask & PLLD_MISC0_WRITE_MASK); 648 649 /* Enable lock detect */ 650 mask = PLLD_MISC0_LOCK_ENABLE | PLLD_MISC0_LOCK_OVERRIDE; 651 val = readl_relaxed(clk_base + plld->params->ext_misc_reg[0]); 652 val &= ~mask; 653 val |= PLLD_MISC0_DEFAULT_VALUE & mask; 654 writel_relaxed(val, clk_base + plld->params->ext_misc_reg[0]); 655 udelay(1); 656 657 return; 658 } 659 660 val = readl_relaxed(clk_base + plld->params->ext_misc_reg[0]); 661 val &= PLLD_MISC0_DSI_CLKENABLE; 662 val |= PLLD_MISC0_DEFAULT_VALUE; 663 /* set IDDQ, enable lock detect, disable SDM */ 664 writel_relaxed(val, clk_base + plld->params->ext_misc_reg[0]); 665 writel_relaxed(PLLD_MISC1_DEFAULT_VALUE, clk_base + 666 plld->params->ext_misc_reg[1]); 667 udelay(1); 668 } 669 670 /* 671 * PLLD2, PLLDP 672 * PLL with fractional SDM and Spread Spectrum (SDM is a must if SSC is used). 673 */ 674 static void plldss_defaults(const char *pll_name, struct tegra_clk_pll *plldss, 675 u32 misc0_val, u32 misc1_val, u32 misc2_val, u32 misc3_val) 676 { 677 u32 default_val; 678 u32 val = readl_relaxed(clk_base + plldss->params->base_reg); 679 680 plldss->params->defaults_set = true; 681 682 if (val & PLL_ENABLE) { 683 pr_warn("%s already enabled. Postponing set full defaults\n", 684 pll_name); 685 686 /* 687 * PLL is ON: check if defaults already set, then set those 688 * that can be updated in flight. 689 */ 690 if (val & PLLDSS_BASE_IDDQ) { 691 pr_warn("plldss boot enabled with IDDQ set\n"); 692 plldss->params->defaults_set = false; 693 } 694 695 /* ignore lock enable */ 696 default_val = misc0_val; 697 _pll_misc_chk_default(clk_base, plldss->params, 0, default_val, 698 PLLDSS_MISC0_WRITE_MASK & 699 (~PLLDSS_MISC0_LOCK_ENABLE)); 700 701 /* 702 * If SSC is used, check all settings, otherwise just confirm 703 * that SSC is not used on boot as well. Do nothing when using 704 * this function for PLLC4 that has only MISC0. 705 */ 706 if (plldss->params->ssc_ctrl_en_mask) { 707 default_val = misc1_val; 708 _pll_misc_chk_default(clk_base, plldss->params, 1, 709 default_val, PLLDSS_MISC1_CFG_WRITE_MASK); 710 default_val = misc2_val; 711 _pll_misc_chk_default(clk_base, plldss->params, 2, 712 default_val, PLLDSS_MISC2_CTRL1_WRITE_MASK); 713 default_val = misc3_val; 714 _pll_misc_chk_default(clk_base, plldss->params, 3, 715 default_val, PLLDSS_MISC3_CTRL2_WRITE_MASK); 716 } else if (plldss->params->ext_misc_reg[1]) { 717 default_val = misc1_val; 718 _pll_misc_chk_default(clk_base, plldss->params, 1, 719 default_val, PLLDSS_MISC1_CFG_WRITE_MASK & 720 (~PLLDSS_MISC1_CFG_EN_SDM)); 721 } 722 723 /* Enable lock detect */ 724 if (val & PLLDSS_BASE_LOCK_OVERRIDE) { 725 val &= ~PLLDSS_BASE_LOCK_OVERRIDE; 726 writel_relaxed(val, clk_base + 727 plldss->params->base_reg); 728 } 729 730 val = readl_relaxed(clk_base + plldss->params->ext_misc_reg[0]); 731 val &= ~PLLDSS_MISC0_LOCK_ENABLE; 732 val |= misc0_val & PLLDSS_MISC0_LOCK_ENABLE; 733 writel_relaxed(val, clk_base + plldss->params->ext_misc_reg[0]); 734 udelay(1); 735 736 return; 737 } 738 739 /* set IDDQ, enable lock detect, configure SDM/SSC */ 740 val |= PLLDSS_BASE_IDDQ; 741 val &= ~PLLDSS_BASE_LOCK_OVERRIDE; 742 writel_relaxed(val, clk_base + plldss->params->base_reg); 743 744 /* When using this function for PLLC4 exit here */ 745 if (!plldss->params->ext_misc_reg[1]) { 746 writel_relaxed(misc0_val, clk_base + 747 plldss->params->ext_misc_reg[0]); 748 udelay(1); 749 return; 750 } 751 752 writel_relaxed(misc0_val, clk_base + 753 plldss->params->ext_misc_reg[0]); 754 /* if SSC used set by 1st enable */ 755 writel_relaxed(misc1_val & (~PLLDSS_MISC1_CFG_EN_SSC), 756 clk_base + plldss->params->ext_misc_reg[1]); 757 writel_relaxed(misc2_val, clk_base + plldss->params->ext_misc_reg[2]); 758 writel_relaxed(misc3_val, clk_base + plldss->params->ext_misc_reg[3]); 759 udelay(1); 760 } 761 762 static void tegra210_plld2_set_defaults(struct tegra_clk_pll *plld2) 763 { 764 plldss_defaults("PLL_D2", plld2, PLLD2_MISC0_DEFAULT_VALUE, 765 PLLD2_MISC1_CFG_DEFAULT_VALUE, 766 PLLD2_MISC2_CTRL1_DEFAULT_VALUE, 767 PLLD2_MISC3_CTRL2_DEFAULT_VALUE); 768 } 769 770 static void tegra210_plldp_set_defaults(struct tegra_clk_pll *plldp) 771 { 772 plldss_defaults("PLL_DP", plldp, PLLDP_MISC0_DEFAULT_VALUE, 773 PLLDP_MISC1_CFG_DEFAULT_VALUE, 774 PLLDP_MISC2_CTRL1_DEFAULT_VALUE, 775 PLLDP_MISC3_CTRL2_DEFAULT_VALUE); 776 } 777 778 /* 779 * PLLC4 780 * Base and misc0 layout is the same as PLLD2/PLLDP, but no SDM/SSC support. 781 * VCO is exposed to the clock tree via fixed 1/3 and 1/5 dividers. 782 */ 783 static void tegra210_pllc4_set_defaults(struct tegra_clk_pll *pllc4) 784 { 785 plldss_defaults("PLL_C4", pllc4, PLLC4_MISC0_DEFAULT_VALUE, 0, 0, 0); 786 } 787 788 /* 789 * PLLRE 790 * VCO is exposed to the clock tree directly along with post-divider output 791 */ 792 static void tegra210_pllre_set_defaults(struct tegra_clk_pll *pllre) 793 { 794 u32 mask; 795 u32 val = readl_relaxed(clk_base + pllre->params->base_reg); 796 797 pllre->params->defaults_set = true; 798 799 if (val & PLL_ENABLE) { 800 pr_warn("PLL_RE already enabled. Postponing set full defaults\n"); 801 802 /* 803 * PLL is ON: check if defaults already set, then set those 804 * that can be updated in flight. 805 */ 806 val &= PLLRE_BASE_DEFAULT_MASK; 807 if (val != PLLRE_BASE_DEFAULT_VALUE) { 808 pr_warn("pllre boot base 0x%x : expected 0x%x\n", 809 val, PLLRE_BASE_DEFAULT_VALUE); 810 pr_warn("(comparison mask = 0x%x)\n", 811 PLLRE_BASE_DEFAULT_MASK); 812 pllre->params->defaults_set = false; 813 } 814 815 /* Ignore lock enable */ 816 val = PLLRE_MISC0_DEFAULT_VALUE & (~PLLRE_MISC0_IDDQ); 817 mask = PLLRE_MISC0_LOCK_ENABLE | PLLRE_MISC0_LOCK_OVERRIDE; 818 _pll_misc_chk_default(clk_base, pllre->params, 0, val, 819 ~mask & PLLRE_MISC0_WRITE_MASK); 820 821 /* Enable lock detect */ 822 val = readl_relaxed(clk_base + pllre->params->ext_misc_reg[0]); 823 val &= ~mask; 824 val |= PLLRE_MISC0_DEFAULT_VALUE & mask; 825 writel_relaxed(val, clk_base + pllre->params->ext_misc_reg[0]); 826 udelay(1); 827 828 return; 829 } 830 831 /* set IDDQ, enable lock detect */ 832 val &= ~PLLRE_BASE_DEFAULT_MASK; 833 val |= PLLRE_BASE_DEFAULT_VALUE & PLLRE_BASE_DEFAULT_MASK; 834 writel_relaxed(val, clk_base + pllre->params->base_reg); 835 writel_relaxed(PLLRE_MISC0_DEFAULT_VALUE, 836 clk_base + pllre->params->ext_misc_reg[0]); 837 udelay(1); 838 } 839 840 static void pllx_get_dyn_steps(struct clk_hw *hw, u32 *step_a, u32 *step_b) 841 { 842 unsigned long input_rate; 843 844 /* cf rate */ 845 if (!IS_ERR_OR_NULL(hw->clk)) 846 input_rate = clk_hw_get_rate(clk_hw_get_parent(hw)); 847 else 848 input_rate = 38400000; 849 850 input_rate /= tegra_pll_get_fixed_mdiv(hw, input_rate); 851 852 switch (input_rate) { 853 case 12000000: 854 case 12800000: 855 case 13000000: 856 *step_a = 0x2B; 857 *step_b = 0x0B; 858 return; 859 case 19200000: 860 *step_a = 0x12; 861 *step_b = 0x08; 862 return; 863 case 38400000: 864 *step_a = 0x04; 865 *step_b = 0x05; 866 return; 867 default: 868 pr_err("%s: Unexpected reference rate %lu\n", 869 __func__, input_rate); 870 BUG(); 871 } 872 } 873 874 static void pllx_check_defaults(struct tegra_clk_pll *pll) 875 { 876 u32 default_val; 877 878 default_val = PLLX_MISC0_DEFAULT_VALUE; 879 /* ignore lock enable */ 880 _pll_misc_chk_default(clk_base, pll->params, 0, default_val, 881 PLLX_MISC0_WRITE_MASK & (~PLLX_MISC0_LOCK_ENABLE)); 882 883 default_val = PLLX_MISC1_DEFAULT_VALUE; 884 _pll_misc_chk_default(clk_base, pll->params, 1, default_val, 885 PLLX_MISC1_WRITE_MASK); 886 887 /* ignore all but control bit */ 888 default_val = PLLX_MISC2_DEFAULT_VALUE; 889 _pll_misc_chk_default(clk_base, pll->params, 2, 890 default_val, PLLX_MISC2_EN_DYNRAMP); 891 892 default_val = PLLX_MISC3_DEFAULT_VALUE & (~PLLX_MISC3_IDDQ); 893 _pll_misc_chk_default(clk_base, pll->params, 3, default_val, 894 PLLX_MISC3_WRITE_MASK); 895 896 default_val = PLLX_MISC4_DEFAULT_VALUE; 897 _pll_misc_chk_default(clk_base, pll->params, 4, default_val, 898 PLLX_MISC4_WRITE_MASK); 899 900 default_val = PLLX_MISC5_DEFAULT_VALUE; 901 _pll_misc_chk_default(clk_base, pll->params, 5, default_val, 902 PLLX_MISC5_WRITE_MASK); 903 } 904 905 static void tegra210_pllx_set_defaults(struct tegra_clk_pll *pllx) 906 { 907 u32 val; 908 u32 step_a, step_b; 909 910 pllx->params->defaults_set = true; 911 912 /* Get ready dyn ramp state machine settings */ 913 pllx_get_dyn_steps(&pllx->hw, &step_a, &step_b); 914 val = PLLX_MISC2_DEFAULT_VALUE & (~PLLX_MISC2_DYNRAMP_STEPA_MASK) & 915 (~PLLX_MISC2_DYNRAMP_STEPB_MASK); 916 val |= step_a << PLLX_MISC2_DYNRAMP_STEPA_SHIFT; 917 val |= step_b << PLLX_MISC2_DYNRAMP_STEPB_SHIFT; 918 919 if (readl_relaxed(clk_base + pllx->params->base_reg) & PLL_ENABLE) { 920 pr_warn("PLL_X already enabled. Postponing set full defaults\n"); 921 922 /* 923 * PLL is ON: check if defaults already set, then set those 924 * that can be updated in flight. 925 */ 926 pllx_check_defaults(pllx); 927 928 /* Configure dyn ramp, disable lock override */ 929 writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); 930 931 /* Enable lock detect */ 932 val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[0]); 933 val &= ~PLLX_MISC0_LOCK_ENABLE; 934 val |= PLLX_MISC0_DEFAULT_VALUE & PLLX_MISC0_LOCK_ENABLE; 935 writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[0]); 936 udelay(1); 937 938 return; 939 } 940 941 /* Enable lock detect and CPU output */ 942 writel_relaxed(PLLX_MISC0_DEFAULT_VALUE, clk_base + 943 pllx->params->ext_misc_reg[0]); 944 945 /* Setup */ 946 writel_relaxed(PLLX_MISC1_DEFAULT_VALUE, clk_base + 947 pllx->params->ext_misc_reg[1]); 948 949 /* Configure dyn ramp state machine, disable lock override */ 950 writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); 951 952 /* Set IDDQ */ 953 writel_relaxed(PLLX_MISC3_DEFAULT_VALUE, clk_base + 954 pllx->params->ext_misc_reg[3]); 955 956 /* Disable SDM */ 957 writel_relaxed(PLLX_MISC4_DEFAULT_VALUE, clk_base + 958 pllx->params->ext_misc_reg[4]); 959 writel_relaxed(PLLX_MISC5_DEFAULT_VALUE, clk_base + 960 pllx->params->ext_misc_reg[5]); 961 udelay(1); 962 } 963 964 /* PLLMB */ 965 static void tegra210_pllmb_set_defaults(struct tegra_clk_pll *pllmb) 966 { 967 u32 mask, val = readl_relaxed(clk_base + pllmb->params->base_reg); 968 969 pllmb->params->defaults_set = true; 970 971 if (val & PLL_ENABLE) { 972 pr_warn("PLL_MB already enabled. Postponing set full defaults\n"); 973 974 /* 975 * PLL is ON: check if defaults already set, then set those 976 * that can be updated in flight. 977 */ 978 val = PLLMB_MISC1_DEFAULT_VALUE & (~PLLMB_MISC1_IDDQ); 979 mask = PLLMB_MISC1_LOCK_ENABLE | PLLMB_MISC1_LOCK_OVERRIDE; 980 _pll_misc_chk_default(clk_base, pllmb->params, 0, val, 981 ~mask & PLLMB_MISC1_WRITE_MASK); 982 983 /* Enable lock detect */ 984 val = readl_relaxed(clk_base + pllmb->params->ext_misc_reg[0]); 985 val &= ~mask; 986 val |= PLLMB_MISC1_DEFAULT_VALUE & mask; 987 writel_relaxed(val, clk_base + pllmb->params->ext_misc_reg[0]); 988 udelay(1); 989 990 return; 991 } 992 993 /* set IDDQ, enable lock detect */ 994 writel_relaxed(PLLMB_MISC1_DEFAULT_VALUE, 995 clk_base + pllmb->params->ext_misc_reg[0]); 996 udelay(1); 997 } 998 999 /* 1000 * PLLP 1001 * VCO is exposed to the clock tree directly along with post-divider output. 1002 * Both VCO and post-divider output rates are fixed at 408MHz and 204MHz, 1003 * respectively. 1004 */ 1005 static void pllp_check_defaults(struct tegra_clk_pll *pll, bool enabled) 1006 { 1007 u32 val, mask; 1008 1009 /* Ignore lock enable (will be set), make sure not in IDDQ if enabled */ 1010 val = PLLP_MISC0_DEFAULT_VALUE & (~PLLP_MISC0_IDDQ); 1011 mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE; 1012 if (!enabled) 1013 mask |= PLLP_MISC0_IDDQ; 1014 _pll_misc_chk_default(clk_base, pll->params, 0, val, 1015 ~mask & PLLP_MISC0_WRITE_MASK); 1016 1017 /* Ignore branch controls */ 1018 val = PLLP_MISC1_DEFAULT_VALUE; 1019 mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN; 1020 _pll_misc_chk_default(clk_base, pll->params, 1, val, 1021 ~mask & PLLP_MISC1_WRITE_MASK); 1022 } 1023 1024 static void tegra210_pllp_set_defaults(struct tegra_clk_pll *pllp) 1025 { 1026 u32 mask; 1027 u32 val = readl_relaxed(clk_base + pllp->params->base_reg); 1028 1029 pllp->params->defaults_set = true; 1030 1031 if (val & PLL_ENABLE) { 1032 pr_warn("PLL_P already enabled. Postponing set full defaults\n"); 1033 1034 /* 1035 * PLL is ON: check if defaults already set, then set those 1036 * that can be updated in flight. 1037 */ 1038 pllp_check_defaults(pllp, true); 1039 1040 /* Enable lock detect */ 1041 val = readl_relaxed(clk_base + pllp->params->ext_misc_reg[0]); 1042 mask = PLLP_MISC0_LOCK_ENABLE | PLLP_MISC0_LOCK_OVERRIDE; 1043 val &= ~mask; 1044 val |= PLLP_MISC0_DEFAULT_VALUE & mask; 1045 writel_relaxed(val, clk_base + pllp->params->ext_misc_reg[0]); 1046 udelay(1); 1047 1048 return; 1049 } 1050 1051 /* set IDDQ, enable lock detect */ 1052 writel_relaxed(PLLP_MISC0_DEFAULT_VALUE, 1053 clk_base + pllp->params->ext_misc_reg[0]); 1054 1055 /* Preserve branch control */ 1056 val = readl_relaxed(clk_base + pllp->params->ext_misc_reg[1]); 1057 mask = PLLP_MISC1_HSIO_EN | PLLP_MISC1_XUSB_EN; 1058 val &= mask; 1059 val |= ~mask & PLLP_MISC1_DEFAULT_VALUE; 1060 writel_relaxed(val, clk_base + pllp->params->ext_misc_reg[1]); 1061 udelay(1); 1062 } 1063 1064 /* 1065 * PLLU 1066 * VCO is exposed to the clock tree directly along with post-divider output. 1067 * Both VCO and post-divider output rates are fixed at 480MHz and 240MHz, 1068 * respectively. 1069 */ 1070 static void pllu_check_defaults(struct tegra_clk_pll *pll, bool hw_control) 1071 { 1072 u32 val, mask; 1073 1074 /* Ignore lock enable (will be set) and IDDQ if under h/w control */ 1075 val = PLLU_MISC0_DEFAULT_VALUE & (~PLLU_MISC0_IDDQ); 1076 mask = PLLU_MISC0_LOCK_ENABLE | (hw_control ? PLLU_MISC0_IDDQ : 0); 1077 _pll_misc_chk_default(clk_base, pll->params, 0, val, 1078 ~mask & PLLU_MISC0_WRITE_MASK); 1079 1080 val = PLLU_MISC1_DEFAULT_VALUE; 1081 mask = PLLU_MISC1_LOCK_OVERRIDE; 1082 _pll_misc_chk_default(clk_base, pll->params, 1, val, 1083 ~mask & PLLU_MISC1_WRITE_MASK); 1084 } 1085 1086 static void tegra210_pllu_set_defaults(struct tegra_clk_pll *pllu) 1087 { 1088 u32 val = readl_relaxed(clk_base + pllu->params->base_reg); 1089 1090 pllu->params->defaults_set = true; 1091 1092 if (val & PLL_ENABLE) { 1093 pr_warn("PLL_U already enabled. Postponing set full defaults\n"); 1094 1095 /* 1096 * PLL is ON: check if defaults already set, then set those 1097 * that can be updated in flight. 1098 */ 1099 pllu_check_defaults(pllu, false); 1100 1101 /* Enable lock detect */ 1102 val = readl_relaxed(clk_base + pllu->params->ext_misc_reg[0]); 1103 val &= ~PLLU_MISC0_LOCK_ENABLE; 1104 val |= PLLU_MISC0_DEFAULT_VALUE & PLLU_MISC0_LOCK_ENABLE; 1105 writel_relaxed(val, clk_base + pllu->params->ext_misc_reg[0]); 1106 1107 val = readl_relaxed(clk_base + pllu->params->ext_misc_reg[1]); 1108 val &= ~PLLU_MISC1_LOCK_OVERRIDE; 1109 val |= PLLU_MISC1_DEFAULT_VALUE & PLLU_MISC1_LOCK_OVERRIDE; 1110 writel_relaxed(val, clk_base + pllu->params->ext_misc_reg[1]); 1111 udelay(1); 1112 1113 return; 1114 } 1115 1116 /* set IDDQ, enable lock detect */ 1117 writel_relaxed(PLLU_MISC0_DEFAULT_VALUE, 1118 clk_base + pllu->params->ext_misc_reg[0]); 1119 writel_relaxed(PLLU_MISC1_DEFAULT_VALUE, 1120 clk_base + pllu->params->ext_misc_reg[1]); 1121 udelay(1); 1122 } 1123 1124 #define mask(w) ((1 << (w)) - 1) 1125 #define divm_mask(p) mask(p->params->div_nmp->divm_width) 1126 #define divn_mask(p) mask(p->params->div_nmp->divn_width) 1127 #define divp_mask(p) (p->params->flags & TEGRA_PLLU ? PLLU_POST_DIVP_MASK :\ 1128 mask(p->params->div_nmp->divp_width)) 1129 1130 #define divm_shift(p) ((p)->params->div_nmp->divm_shift) 1131 #define divn_shift(p) ((p)->params->div_nmp->divn_shift) 1132 #define divp_shift(p) ((p)->params->div_nmp->divp_shift) 1133 1134 #define divm_mask_shifted(p) (divm_mask(p) << divm_shift(p)) 1135 #define divn_mask_shifted(p) (divn_mask(p) << divn_shift(p)) 1136 #define divp_mask_shifted(p) (divp_mask(p) << divp_shift(p)) 1137 1138 #define PLL_LOCKDET_DELAY 2 /* Lock detection safety delays */ 1139 static int tegra210_wait_for_mask(struct tegra_clk_pll *pll, 1140 u32 reg, u32 mask) 1141 { 1142 int i; 1143 u32 val = 0; 1144 1145 for (i = 0; i < pll->params->lock_delay / PLL_LOCKDET_DELAY + 1; i++) { 1146 udelay(PLL_LOCKDET_DELAY); 1147 val = readl_relaxed(clk_base + reg); 1148 if ((val & mask) == mask) { 1149 udelay(PLL_LOCKDET_DELAY); 1150 return 0; 1151 } 1152 } 1153 return -ETIMEDOUT; 1154 } 1155 1156 static int tegra210_pllx_dyn_ramp(struct tegra_clk_pll *pllx, 1157 struct tegra_clk_pll_freq_table *cfg) 1158 { 1159 u32 val, base, ndiv_new_mask; 1160 1161 ndiv_new_mask = (divn_mask(pllx) >> pllx->params->div_nmp->divn_shift) 1162 << PLLX_MISC2_NDIV_NEW_SHIFT; 1163 1164 val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[2]); 1165 val &= (~ndiv_new_mask); 1166 val |= cfg->n << PLLX_MISC2_NDIV_NEW_SHIFT; 1167 writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); 1168 udelay(1); 1169 1170 val = readl_relaxed(clk_base + pllx->params->ext_misc_reg[2]); 1171 val |= PLLX_MISC2_EN_DYNRAMP; 1172 writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); 1173 udelay(1); 1174 1175 tegra210_wait_for_mask(pllx, pllx->params->ext_misc_reg[2], 1176 PLLX_MISC2_DYNRAMP_DONE); 1177 1178 base = readl_relaxed(clk_base + pllx->params->base_reg) & 1179 (~divn_mask_shifted(pllx)); 1180 base |= cfg->n << pllx->params->div_nmp->divn_shift; 1181 writel_relaxed(base, clk_base + pllx->params->base_reg); 1182 udelay(1); 1183 1184 val &= ~PLLX_MISC2_EN_DYNRAMP; 1185 writel_relaxed(val, clk_base + pllx->params->ext_misc_reg[2]); 1186 udelay(1); 1187 1188 pr_debug("%s: dynamic ramp to m = %u n = %u p = %u, Fout = %lu kHz\n", 1189 __clk_get_name(pllx->hw.clk), cfg->m, cfg->n, cfg->p, 1190 cfg->input_rate / cfg->m * cfg->n / 1191 pllx->params->pdiv_tohw[cfg->p].pdiv / 1000); 1192 1193 return 0; 1194 } 1195 1196 /* 1197 * Common configuration for PLLs with fixed input divider policy: 1198 * - always set fixed M-value based on the reference rate 1199 * - always set P-value value 1:1 for output rates above VCO minimum, and 1200 * choose minimum necessary P-value for output rates below VCO maximum 1201 * - calculate N-value based on selected M and P 1202 * - calculate SDM_DIN fractional part 1203 */ 1204 static int tegra210_pll_fixed_mdiv_cfg(struct clk_hw *hw, 1205 struct tegra_clk_pll_freq_table *cfg, 1206 unsigned long rate, unsigned long input_rate) 1207 { 1208 struct tegra_clk_pll *pll = to_clk_pll(hw); 1209 struct tegra_clk_pll_params *params = pll->params; 1210 int p; 1211 unsigned long cf, p_rate; 1212 u32 pdiv; 1213 1214 if (!rate) 1215 return -EINVAL; 1216 1217 if (!(params->flags & TEGRA_PLL_VCO_OUT)) { 1218 p = DIV_ROUND_UP(params->vco_min, rate); 1219 p = params->round_p_to_pdiv(p, &pdiv); 1220 } else { 1221 p = rate >= params->vco_min ? 1 : -EINVAL; 1222 } 1223 1224 if (p < 0) 1225 return -EINVAL; 1226 1227 cfg->m = tegra_pll_get_fixed_mdiv(hw, input_rate); 1228 cfg->p = p; 1229 1230 /* Store P as HW value, as that is what is expected */ 1231 cfg->p = tegra_pll_p_div_to_hw(pll, cfg->p); 1232 1233 p_rate = rate * p; 1234 if (p_rate > params->vco_max) 1235 p_rate = params->vco_max; 1236 cf = input_rate / cfg->m; 1237 cfg->n = p_rate / cf; 1238 1239 cfg->sdm_data = 0; 1240 if (params->sdm_ctrl_reg) { 1241 unsigned long rem = p_rate - cf * cfg->n; 1242 /* If ssc is enabled SDM enabled as well, even for integer n */ 1243 if (rem || params->ssc_ctrl_reg) { 1244 u64 s = rem * PLL_SDM_COEFF; 1245 1246 do_div(s, cf); 1247 s -= PLL_SDM_COEFF / 2; 1248 cfg->sdm_data = sdin_din_to_data(s); 1249 } 1250 } 1251 1252 cfg->input_rate = input_rate; 1253 cfg->output_rate = rate; 1254 1255 return 0; 1256 } 1257 1258 /* 1259 * clk_pll_set_gain - set gain to m, n to calculate correct VCO rate 1260 * 1261 * @cfg: struct tegra_clk_pll_freq_table * cfg 1262 * 1263 * For Normal mode: 1264 * Fvco = Fref * NDIV / MDIV 1265 * 1266 * For fractional mode: 1267 * Fvco = Fref * (NDIV + 0.5 + SDM_DIN / PLL_SDM_COEFF) / MDIV 1268 */ 1269 static void tegra210_clk_pll_set_gain(struct tegra_clk_pll_freq_table *cfg) 1270 { 1271 cfg->n = cfg->n * PLL_SDM_COEFF + PLL_SDM_COEFF/2 + 1272 sdin_data_to_din(cfg->sdm_data); 1273 cfg->m *= PLL_SDM_COEFF; 1274 } 1275 1276 static unsigned long 1277 tegra210_clk_adjust_vco_min(struct tegra_clk_pll_params *params, 1278 unsigned long parent_rate) 1279 { 1280 unsigned long vco_min = params->vco_min; 1281 1282 params->vco_min += DIV_ROUND_UP(parent_rate, PLL_SDM_COEFF); 1283 vco_min = min(vco_min, params->vco_min); 1284 1285 return vco_min; 1286 } 1287 1288 static struct div_nmp pllx_nmp = { 1289 .divm_shift = 0, 1290 .divm_width = 8, 1291 .divn_shift = 8, 1292 .divn_width = 8, 1293 .divp_shift = 20, 1294 .divp_width = 5, 1295 }; 1296 /* 1297 * PLL post divider maps - two types: quasi-linear and exponential 1298 * post divider. 1299 */ 1300 #define PLL_QLIN_PDIV_MAX 16 1301 static const struct pdiv_map pll_qlin_pdiv_to_hw[] = { 1302 { .pdiv = 1, .hw_val = 0 }, 1303 { .pdiv = 2, .hw_val = 1 }, 1304 { .pdiv = 3, .hw_val = 2 }, 1305 { .pdiv = 4, .hw_val = 3 }, 1306 { .pdiv = 5, .hw_val = 4 }, 1307 { .pdiv = 6, .hw_val = 5 }, 1308 { .pdiv = 8, .hw_val = 6 }, 1309 { .pdiv = 9, .hw_val = 7 }, 1310 { .pdiv = 10, .hw_val = 8 }, 1311 { .pdiv = 12, .hw_val = 9 }, 1312 { .pdiv = 15, .hw_val = 10 }, 1313 { .pdiv = 16, .hw_val = 11 }, 1314 { .pdiv = 18, .hw_val = 12 }, 1315 { .pdiv = 20, .hw_val = 13 }, 1316 { .pdiv = 24, .hw_val = 14 }, 1317 { .pdiv = 30, .hw_val = 15 }, 1318 { .pdiv = 32, .hw_val = 16 }, 1319 }; 1320 1321 static u32 pll_qlin_p_to_pdiv(u32 p, u32 *pdiv) 1322 { 1323 int i; 1324 1325 if (p) { 1326 for (i = 0; i <= PLL_QLIN_PDIV_MAX; i++) { 1327 if (p <= pll_qlin_pdiv_to_hw[i].pdiv) { 1328 if (pdiv) 1329 *pdiv = i; 1330 return pll_qlin_pdiv_to_hw[i].pdiv; 1331 } 1332 } 1333 } 1334 1335 return -EINVAL; 1336 } 1337 1338 #define PLL_EXPO_PDIV_MAX 7 1339 static const struct pdiv_map pll_expo_pdiv_to_hw[] = { 1340 { .pdiv = 1, .hw_val = 0 }, 1341 { .pdiv = 2, .hw_val = 1 }, 1342 { .pdiv = 4, .hw_val = 2 }, 1343 { .pdiv = 8, .hw_val = 3 }, 1344 { .pdiv = 16, .hw_val = 4 }, 1345 { .pdiv = 32, .hw_val = 5 }, 1346 { .pdiv = 64, .hw_val = 6 }, 1347 { .pdiv = 128, .hw_val = 7 }, 1348 }; 1349 1350 static u32 pll_expo_p_to_pdiv(u32 p, u32 *pdiv) 1351 { 1352 if (p) { 1353 u32 i = fls(p); 1354 1355 if (i == ffs(p)) 1356 i--; 1357 1358 if (i <= PLL_EXPO_PDIV_MAX) { 1359 if (pdiv) 1360 *pdiv = i; 1361 return 1 << i; 1362 } 1363 } 1364 return -EINVAL; 1365 } 1366 1367 static struct tegra_clk_pll_freq_table pll_x_freq_table[] = { 1368 /* 1 GHz */ 1369 { 12000000, 1000000000, 166, 1, 1, 0 }, /* actual: 996.0 MHz */ 1370 { 13000000, 1000000000, 153, 1, 1, 0 }, /* actual: 994.0 MHz */ 1371 { 38400000, 1000000000, 156, 3, 1, 0 }, /* actual: 998.4 MHz */ 1372 { 0, 0, 0, 0, 0, 0 }, 1373 }; 1374 1375 static struct tegra_clk_pll_params pll_x_params = { 1376 .input_min = 12000000, 1377 .input_max = 800000000, 1378 .cf_min = 12000000, 1379 .cf_max = 38400000, 1380 .vco_min = 1350000000, 1381 .vco_max = 3000000000UL, 1382 .base_reg = PLLX_BASE, 1383 .misc_reg = PLLX_MISC0, 1384 .lock_mask = PLL_BASE_LOCK, 1385 .lock_enable_bit_idx = PLL_MISC_LOCK_ENABLE, 1386 .lock_delay = 300, 1387 .ext_misc_reg[0] = PLLX_MISC0, 1388 .ext_misc_reg[1] = PLLX_MISC1, 1389 .ext_misc_reg[2] = PLLX_MISC2, 1390 .ext_misc_reg[3] = PLLX_MISC3, 1391 .ext_misc_reg[4] = PLLX_MISC4, 1392 .ext_misc_reg[5] = PLLX_MISC5, 1393 .iddq_reg = PLLX_MISC3, 1394 .iddq_bit_idx = PLLXP_IDDQ_BIT, 1395 .max_p = PLL_QLIN_PDIV_MAX, 1396 .mdiv_default = 2, 1397 .dyn_ramp_reg = PLLX_MISC2, 1398 .stepa_shift = 16, 1399 .stepb_shift = 24, 1400 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1401 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1402 .div_nmp = &pllx_nmp, 1403 .freq_table = pll_x_freq_table, 1404 .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, 1405 .dyn_ramp = tegra210_pllx_dyn_ramp, 1406 .set_defaults = tegra210_pllx_set_defaults, 1407 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1408 }; 1409 1410 static struct div_nmp pllc_nmp = { 1411 .divm_shift = 0, 1412 .divm_width = 8, 1413 .divn_shift = 10, 1414 .divn_width = 8, 1415 .divp_shift = 20, 1416 .divp_width = 5, 1417 }; 1418 1419 static struct tegra_clk_pll_freq_table pll_cx_freq_table[] = { 1420 { 12000000, 510000000, 85, 1, 1, 0 }, 1421 { 13000000, 510000000, 78, 1, 1, 0 }, /* actual: 507.0 MHz */ 1422 { 38400000, 510000000, 79, 3, 1, 0 }, /* actual: 505.6 MHz */ 1423 { 0, 0, 0, 0, 0, 0 }, 1424 }; 1425 1426 static struct tegra_clk_pll_params pll_c_params = { 1427 .input_min = 12000000, 1428 .input_max = 700000000, 1429 .cf_min = 12000000, 1430 .cf_max = 50000000, 1431 .vco_min = 600000000, 1432 .vco_max = 1200000000, 1433 .base_reg = PLLC_BASE, 1434 .misc_reg = PLLC_MISC0, 1435 .lock_mask = PLL_BASE_LOCK, 1436 .lock_delay = 300, 1437 .iddq_reg = PLLC_MISC1, 1438 .iddq_bit_idx = PLLCX_IDDQ_BIT, 1439 .reset_reg = PLLC_MISC0, 1440 .reset_bit_idx = PLLCX_RESET_BIT, 1441 .max_p = PLL_QLIN_PDIV_MAX, 1442 .ext_misc_reg[0] = PLLC_MISC0, 1443 .ext_misc_reg[1] = PLLC_MISC1, 1444 .ext_misc_reg[2] = PLLC_MISC2, 1445 .ext_misc_reg[3] = PLLC_MISC3, 1446 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1447 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1448 .mdiv_default = 3, 1449 .div_nmp = &pllc_nmp, 1450 .freq_table = pll_cx_freq_table, 1451 .flags = TEGRA_PLL_USE_LOCK, 1452 .set_defaults = _pllc_set_defaults, 1453 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1454 }; 1455 1456 static struct div_nmp pllcx_nmp = { 1457 .divm_shift = 0, 1458 .divm_width = 8, 1459 .divn_shift = 10, 1460 .divn_width = 8, 1461 .divp_shift = 20, 1462 .divp_width = 5, 1463 }; 1464 1465 static struct tegra_clk_pll_params pll_c2_params = { 1466 .input_min = 12000000, 1467 .input_max = 700000000, 1468 .cf_min = 12000000, 1469 .cf_max = 50000000, 1470 .vco_min = 600000000, 1471 .vco_max = 1200000000, 1472 .base_reg = PLLC2_BASE, 1473 .misc_reg = PLLC2_MISC0, 1474 .iddq_reg = PLLC2_MISC1, 1475 .iddq_bit_idx = PLLCX_IDDQ_BIT, 1476 .reset_reg = PLLC2_MISC0, 1477 .reset_bit_idx = PLLCX_RESET_BIT, 1478 .lock_mask = PLLCX_BASE_LOCK, 1479 .lock_delay = 300, 1480 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1481 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1482 .mdiv_default = 3, 1483 .div_nmp = &pllcx_nmp, 1484 .max_p = PLL_QLIN_PDIV_MAX, 1485 .ext_misc_reg[0] = PLLC2_MISC0, 1486 .ext_misc_reg[1] = PLLC2_MISC1, 1487 .ext_misc_reg[2] = PLLC2_MISC2, 1488 .ext_misc_reg[3] = PLLC2_MISC3, 1489 .freq_table = pll_cx_freq_table, 1490 .flags = TEGRA_PLL_USE_LOCK, 1491 .set_defaults = _pllc2_set_defaults, 1492 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1493 }; 1494 1495 static struct tegra_clk_pll_params pll_c3_params = { 1496 .input_min = 12000000, 1497 .input_max = 700000000, 1498 .cf_min = 12000000, 1499 .cf_max = 50000000, 1500 .vco_min = 600000000, 1501 .vco_max = 1200000000, 1502 .base_reg = PLLC3_BASE, 1503 .misc_reg = PLLC3_MISC0, 1504 .lock_mask = PLLCX_BASE_LOCK, 1505 .lock_delay = 300, 1506 .iddq_reg = PLLC3_MISC1, 1507 .iddq_bit_idx = PLLCX_IDDQ_BIT, 1508 .reset_reg = PLLC3_MISC0, 1509 .reset_bit_idx = PLLCX_RESET_BIT, 1510 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1511 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1512 .mdiv_default = 3, 1513 .div_nmp = &pllcx_nmp, 1514 .max_p = PLL_QLIN_PDIV_MAX, 1515 .ext_misc_reg[0] = PLLC3_MISC0, 1516 .ext_misc_reg[1] = PLLC3_MISC1, 1517 .ext_misc_reg[2] = PLLC3_MISC2, 1518 .ext_misc_reg[3] = PLLC3_MISC3, 1519 .freq_table = pll_cx_freq_table, 1520 .flags = TEGRA_PLL_USE_LOCK, 1521 .set_defaults = _pllc3_set_defaults, 1522 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1523 }; 1524 1525 static struct div_nmp pllss_nmp = { 1526 .divm_shift = 0, 1527 .divm_width = 8, 1528 .divn_shift = 8, 1529 .divn_width = 8, 1530 .divp_shift = 19, 1531 .divp_width = 5, 1532 }; 1533 1534 static struct tegra_clk_pll_freq_table pll_c4_vco_freq_table[] = { 1535 { 12000000, 600000000, 50, 1, 0, 0 }, 1536 { 13000000, 600000000, 46, 1, 0, 0 }, /* actual: 598.0 MHz */ 1537 { 38400000, 600000000, 62, 4, 0, 0 }, /* actual: 595.2 MHz */ 1538 { 0, 0, 0, 0, 0, 0 }, 1539 }; 1540 1541 static const struct clk_div_table pll_vco_post_div_table[] = { 1542 { .val = 0, .div = 1 }, 1543 { .val = 1, .div = 2 }, 1544 { .val = 2, .div = 3 }, 1545 { .val = 3, .div = 4 }, 1546 { .val = 4, .div = 5 }, 1547 { .val = 5, .div = 6 }, 1548 { .val = 6, .div = 8 }, 1549 { .val = 7, .div = 10 }, 1550 { .val = 8, .div = 12 }, 1551 { .val = 9, .div = 16 }, 1552 { .val = 10, .div = 12 }, 1553 { .val = 11, .div = 16 }, 1554 { .val = 12, .div = 20 }, 1555 { .val = 13, .div = 24 }, 1556 { .val = 14, .div = 32 }, 1557 { .val = 0, .div = 0 }, 1558 }; 1559 1560 static struct tegra_clk_pll_params pll_c4_vco_params = { 1561 .input_min = 9600000, 1562 .input_max = 800000000, 1563 .cf_min = 9600000, 1564 .cf_max = 19200000, 1565 .vco_min = 500000000, 1566 .vco_max = 1080000000, 1567 .base_reg = PLLC4_BASE, 1568 .misc_reg = PLLC4_MISC0, 1569 .lock_mask = PLL_BASE_LOCK, 1570 .lock_delay = 300, 1571 .max_p = PLL_QLIN_PDIV_MAX, 1572 .ext_misc_reg[0] = PLLC4_MISC0, 1573 .iddq_reg = PLLC4_BASE, 1574 .iddq_bit_idx = PLLSS_IDDQ_BIT, 1575 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1576 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1577 .mdiv_default = 3, 1578 .div_nmp = &pllss_nmp, 1579 .freq_table = pll_c4_vco_freq_table, 1580 .set_defaults = tegra210_pllc4_set_defaults, 1581 .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT, 1582 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1583 }; 1584 1585 static struct tegra_clk_pll_freq_table pll_m_freq_table[] = { 1586 { 12000000, 800000000, 66, 1, 0, 0 }, /* actual: 792.0 MHz */ 1587 { 13000000, 800000000, 61, 1, 0, 0 }, /* actual: 793.0 MHz */ 1588 { 38400000, 297600000, 93, 4, 2, 0 }, 1589 { 38400000, 400000000, 125, 4, 2, 0 }, 1590 { 38400000, 532800000, 111, 4, 1, 0 }, 1591 { 38400000, 665600000, 104, 3, 1, 0 }, 1592 { 38400000, 800000000, 125, 3, 1, 0 }, 1593 { 38400000, 931200000, 97, 4, 0, 0 }, 1594 { 38400000, 1065600000, 111, 4, 0, 0 }, 1595 { 38400000, 1200000000, 125, 4, 0, 0 }, 1596 { 38400000, 1331200000, 104, 3, 0, 0 }, 1597 { 38400000, 1459200000, 76, 2, 0, 0 }, 1598 { 38400000, 1600000000, 125, 3, 0, 0 }, 1599 { 0, 0, 0, 0, 0, 0 }, 1600 }; 1601 1602 static struct div_nmp pllm_nmp = { 1603 .divm_shift = 0, 1604 .divm_width = 8, 1605 .override_divm_shift = 0, 1606 .divn_shift = 8, 1607 .divn_width = 8, 1608 .override_divn_shift = 8, 1609 .divp_shift = 20, 1610 .divp_width = 5, 1611 .override_divp_shift = 27, 1612 }; 1613 1614 static struct tegra_clk_pll_params pll_m_params = { 1615 .input_min = 9600000, 1616 .input_max = 500000000, 1617 .cf_min = 9600000, 1618 .cf_max = 19200000, 1619 .vco_min = 800000000, 1620 .vco_max = 1866000000, 1621 .base_reg = PLLM_BASE, 1622 .misc_reg = PLLM_MISC2, 1623 .lock_mask = PLL_BASE_LOCK, 1624 .lock_enable_bit_idx = PLLM_MISC_LOCK_ENABLE, 1625 .lock_delay = 300, 1626 .iddq_reg = PLLM_MISC2, 1627 .iddq_bit_idx = PLLM_IDDQ_BIT, 1628 .max_p = PLL_QLIN_PDIV_MAX, 1629 .ext_misc_reg[0] = PLLM_MISC2, 1630 .ext_misc_reg[1] = PLLM_MISC1, 1631 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1632 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1633 .div_nmp = &pllm_nmp, 1634 .pmc_divnm_reg = PMC_PLLM_WB0_OVERRIDE, 1635 .pmc_divp_reg = PMC_PLLM_WB0_OVERRIDE_2, 1636 .freq_table = pll_m_freq_table, 1637 .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_HAS_LOCK_ENABLE, 1638 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1639 }; 1640 1641 static struct tegra_clk_pll_params pll_mb_params = { 1642 .input_min = 9600000, 1643 .input_max = 500000000, 1644 .cf_min = 9600000, 1645 .cf_max = 19200000, 1646 .vco_min = 800000000, 1647 .vco_max = 1866000000, 1648 .base_reg = PLLMB_BASE, 1649 .misc_reg = PLLMB_MISC1, 1650 .lock_mask = PLL_BASE_LOCK, 1651 .lock_delay = 300, 1652 .iddq_reg = PLLMB_MISC1, 1653 .iddq_bit_idx = PLLMB_IDDQ_BIT, 1654 .max_p = PLL_QLIN_PDIV_MAX, 1655 .ext_misc_reg[0] = PLLMB_MISC1, 1656 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1657 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1658 .div_nmp = &pllm_nmp, 1659 .freq_table = pll_m_freq_table, 1660 .flags = TEGRA_PLL_USE_LOCK, 1661 .set_defaults = tegra210_pllmb_set_defaults, 1662 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1663 }; 1664 1665 1666 static struct tegra_clk_pll_freq_table pll_e_freq_table[] = { 1667 /* PLLE special case: use cpcon field to store cml divider value */ 1668 { 672000000, 100000000, 125, 42, 0, 13 }, 1669 { 624000000, 100000000, 125, 39, 0, 13 }, 1670 { 336000000, 100000000, 125, 21, 0, 13 }, 1671 { 312000000, 100000000, 200, 26, 0, 14 }, 1672 { 38400000, 100000000, 125, 2, 0, 14 }, 1673 { 12000000, 100000000, 200, 1, 0, 14 }, 1674 { 0, 0, 0, 0, 0, 0 }, 1675 }; 1676 1677 static struct div_nmp plle_nmp = { 1678 .divm_shift = 0, 1679 .divm_width = 8, 1680 .divn_shift = 8, 1681 .divn_width = 8, 1682 .divp_shift = 24, 1683 .divp_width = 5, 1684 }; 1685 1686 static struct tegra_clk_pll_params pll_e_params = { 1687 .input_min = 12000000, 1688 .input_max = 800000000, 1689 .cf_min = 12000000, 1690 .cf_max = 38400000, 1691 .vco_min = 1600000000, 1692 .vco_max = 2500000000U, 1693 .base_reg = PLLE_BASE, 1694 .misc_reg = PLLE_MISC0, 1695 .aux_reg = PLLE_AUX, 1696 .lock_mask = PLLE_MISC_LOCK, 1697 .lock_enable_bit_idx = PLLE_MISC_LOCK_ENABLE, 1698 .lock_delay = 300, 1699 .div_nmp = &plle_nmp, 1700 .freq_table = pll_e_freq_table, 1701 .flags = TEGRA_PLL_FIXED | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_USE_LOCK | 1702 TEGRA_PLL_HAS_LOCK_ENABLE, 1703 .fixed_rate = 100000000, 1704 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1705 }; 1706 1707 static struct tegra_clk_pll_freq_table pll_re_vco_freq_table[] = { 1708 { 12000000, 672000000, 56, 1, 0, 0 }, 1709 { 13000000, 672000000, 51, 1, 0, 0 }, /* actual: 663.0 MHz */ 1710 { 38400000, 672000000, 70, 4, 0, 0 }, 1711 { 0, 0, 0, 0, 0, 0 }, 1712 }; 1713 1714 static struct div_nmp pllre_nmp = { 1715 .divm_shift = 0, 1716 .divm_width = 8, 1717 .divn_shift = 8, 1718 .divn_width = 8, 1719 .divp_shift = 16, 1720 .divp_width = 5, 1721 }; 1722 1723 static struct tegra_clk_pll_params pll_re_vco_params = { 1724 .input_min = 9600000, 1725 .input_max = 800000000, 1726 .cf_min = 9600000, 1727 .cf_max = 19200000, 1728 .vco_min = 350000000, 1729 .vco_max = 700000000, 1730 .base_reg = PLLRE_BASE, 1731 .misc_reg = PLLRE_MISC0, 1732 .lock_mask = PLLRE_MISC_LOCK, 1733 .lock_delay = 300, 1734 .max_p = PLL_QLIN_PDIV_MAX, 1735 .ext_misc_reg[0] = PLLRE_MISC0, 1736 .iddq_reg = PLLRE_MISC0, 1737 .iddq_bit_idx = PLLRE_IDDQ_BIT, 1738 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1739 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1740 .div_nmp = &pllre_nmp, 1741 .freq_table = pll_re_vco_freq_table, 1742 .flags = TEGRA_PLL_USE_LOCK | TEGRA_PLL_LOCK_MISC | TEGRA_PLL_VCO_OUT, 1743 .set_defaults = tegra210_pllre_set_defaults, 1744 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1745 }; 1746 1747 static struct div_nmp pllp_nmp = { 1748 .divm_shift = 0, 1749 .divm_width = 8, 1750 .divn_shift = 10, 1751 .divn_width = 8, 1752 .divp_shift = 20, 1753 .divp_width = 5, 1754 }; 1755 1756 static struct tegra_clk_pll_freq_table pll_p_freq_table[] = { 1757 { 12000000, 408000000, 34, 1, 0, 0 }, 1758 { 38400000, 408000000, 85, 8, 0, 0 }, /* cf = 4.8MHz, allowed exception */ 1759 { 0, 0, 0, 0, 0, 0 }, 1760 }; 1761 1762 static struct tegra_clk_pll_params pll_p_params = { 1763 .input_min = 9600000, 1764 .input_max = 800000000, 1765 .cf_min = 9600000, 1766 .cf_max = 19200000, 1767 .vco_min = 350000000, 1768 .vco_max = 700000000, 1769 .base_reg = PLLP_BASE, 1770 .misc_reg = PLLP_MISC0, 1771 .lock_mask = PLL_BASE_LOCK, 1772 .lock_delay = 300, 1773 .iddq_reg = PLLP_MISC0, 1774 .iddq_bit_idx = PLLXP_IDDQ_BIT, 1775 .ext_misc_reg[0] = PLLP_MISC0, 1776 .ext_misc_reg[1] = PLLP_MISC1, 1777 .div_nmp = &pllp_nmp, 1778 .freq_table = pll_p_freq_table, 1779 .fixed_rate = 408000000, 1780 .flags = TEGRA_PLL_FIXED | TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT, 1781 .set_defaults = tegra210_pllp_set_defaults, 1782 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1783 }; 1784 1785 static struct tegra_clk_pll_params pll_a1_params = { 1786 .input_min = 12000000, 1787 .input_max = 700000000, 1788 .cf_min = 12000000, 1789 .cf_max = 50000000, 1790 .vco_min = 600000000, 1791 .vco_max = 1200000000, 1792 .base_reg = PLLA1_BASE, 1793 .misc_reg = PLLA1_MISC0, 1794 .lock_mask = PLLCX_BASE_LOCK, 1795 .lock_delay = 300, 1796 .iddq_reg = PLLA1_MISC0, 1797 .iddq_bit_idx = PLLCX_IDDQ_BIT, 1798 .reset_reg = PLLA1_MISC0, 1799 .reset_bit_idx = PLLCX_RESET_BIT, 1800 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1801 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1802 .div_nmp = &pllc_nmp, 1803 .ext_misc_reg[0] = PLLA1_MISC0, 1804 .ext_misc_reg[1] = PLLA1_MISC1, 1805 .ext_misc_reg[2] = PLLA1_MISC2, 1806 .ext_misc_reg[3] = PLLA1_MISC3, 1807 .freq_table = pll_cx_freq_table, 1808 .flags = TEGRA_PLL_USE_LOCK, 1809 .set_defaults = _plla1_set_defaults, 1810 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1811 }; 1812 1813 static struct div_nmp plla_nmp = { 1814 .divm_shift = 0, 1815 .divm_width = 8, 1816 .divn_shift = 8, 1817 .divn_width = 8, 1818 .divp_shift = 20, 1819 .divp_width = 5, 1820 }; 1821 1822 static struct tegra_clk_pll_freq_table pll_a_freq_table[] = { 1823 { 12000000, 282240000, 47, 1, 1, 1, 0xf148 }, /* actual: 282240234 */ 1824 { 12000000, 368640000, 61, 1, 1, 1, 0xfe15 }, /* actual: 368640381 */ 1825 { 12000000, 240000000, 60, 1, 2, 1, 0 }, 1826 { 13000000, 282240000, 43, 1, 1, 1, 0xfd7d }, /* actual: 282239807 */ 1827 { 13000000, 368640000, 56, 1, 1, 1, 0x06d8 }, /* actual: 368640137 */ 1828 { 13000000, 240000000, 55, 1, 2, 1, 0 }, /* actual: 238.3 MHz */ 1829 { 38400000, 282240000, 44, 3, 1, 1, 0xf333 }, /* actual: 282239844 */ 1830 { 38400000, 368640000, 57, 3, 1, 1, 0x0333 }, /* actual: 368639844 */ 1831 { 38400000, 240000000, 75, 3, 3, 1, 0 }, 1832 { 0, 0, 0, 0, 0, 0, 0 }, 1833 }; 1834 1835 static struct tegra_clk_pll_params pll_a_params = { 1836 .input_min = 12000000, 1837 .input_max = 800000000, 1838 .cf_min = 12000000, 1839 .cf_max = 19200000, 1840 .vco_min = 500000000, 1841 .vco_max = 1000000000, 1842 .base_reg = PLLA_BASE, 1843 .misc_reg = PLLA_MISC0, 1844 .lock_mask = PLL_BASE_LOCK, 1845 .lock_delay = 300, 1846 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1847 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1848 .iddq_reg = PLLA_BASE, 1849 .iddq_bit_idx = PLLA_IDDQ_BIT, 1850 .div_nmp = &plla_nmp, 1851 .sdm_din_reg = PLLA_MISC1, 1852 .sdm_din_mask = PLLA_SDM_DIN_MASK, 1853 .sdm_ctrl_reg = PLLA_MISC2, 1854 .sdm_ctrl_en_mask = PLLA_SDM_EN_MASK, 1855 .ext_misc_reg[0] = PLLA_MISC0, 1856 .ext_misc_reg[1] = PLLA_MISC1, 1857 .ext_misc_reg[2] = PLLA_MISC2, 1858 .freq_table = pll_a_freq_table, 1859 .flags = TEGRA_PLL_USE_LOCK | TEGRA_MDIV_NEW, 1860 .set_defaults = tegra210_plla_set_defaults, 1861 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1862 .set_gain = tegra210_clk_pll_set_gain, 1863 .adjust_vco = tegra210_clk_adjust_vco_min, 1864 }; 1865 1866 static struct div_nmp plld_nmp = { 1867 .divm_shift = 0, 1868 .divm_width = 8, 1869 .divn_shift = 11, 1870 .divn_width = 8, 1871 .divp_shift = 20, 1872 .divp_width = 3, 1873 }; 1874 1875 static struct tegra_clk_pll_freq_table pll_d_freq_table[] = { 1876 { 12000000, 594000000, 99, 1, 1, 0, 0 }, 1877 { 13000000, 594000000, 91, 1, 1, 0, 0xfc4f }, /* actual: 594000183 */ 1878 { 38400000, 594000000, 30, 1, 1, 0, 0x0e00 }, 1879 { 0, 0, 0, 0, 0, 0, 0 }, 1880 }; 1881 1882 static struct tegra_clk_pll_params pll_d_params = { 1883 .input_min = 12000000, 1884 .input_max = 800000000, 1885 .cf_min = 12000000, 1886 .cf_max = 38400000, 1887 .vco_min = 750000000, 1888 .vco_max = 1500000000, 1889 .base_reg = PLLD_BASE, 1890 .misc_reg = PLLD_MISC0, 1891 .lock_mask = PLL_BASE_LOCK, 1892 .lock_delay = 1000, 1893 .iddq_reg = PLLD_MISC0, 1894 .iddq_bit_idx = PLLD_IDDQ_BIT, 1895 .round_p_to_pdiv = pll_expo_p_to_pdiv, 1896 .pdiv_tohw = pll_expo_pdiv_to_hw, 1897 .div_nmp = &plld_nmp, 1898 .sdm_din_reg = PLLD_MISC0, 1899 .sdm_din_mask = PLLA_SDM_DIN_MASK, 1900 .sdm_ctrl_reg = PLLD_MISC0, 1901 .sdm_ctrl_en_mask = PLLD_SDM_EN_MASK, 1902 .ext_misc_reg[0] = PLLD_MISC0, 1903 .ext_misc_reg[1] = PLLD_MISC1, 1904 .freq_table = pll_d_freq_table, 1905 .flags = TEGRA_PLL_USE_LOCK, 1906 .mdiv_default = 1, 1907 .set_defaults = tegra210_plld_set_defaults, 1908 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1909 .set_gain = tegra210_clk_pll_set_gain, 1910 .adjust_vco = tegra210_clk_adjust_vco_min, 1911 }; 1912 1913 static struct tegra_clk_pll_freq_table tegra210_pll_d2_freq_table[] = { 1914 { 12000000, 594000000, 99, 1, 1, 0, 0xf000 }, 1915 { 13000000, 594000000, 91, 1, 1, 0, 0xfc4f }, /* actual: 594000183 */ 1916 { 38400000, 594000000, 30, 1, 1, 0, 0x0e00 }, 1917 { 0, 0, 0, 0, 0, 0, 0 }, 1918 }; 1919 1920 /* s/w policy, always tegra_pll_ref */ 1921 static struct tegra_clk_pll_params pll_d2_params = { 1922 .input_min = 12000000, 1923 .input_max = 800000000, 1924 .cf_min = 12000000, 1925 .cf_max = 38400000, 1926 .vco_min = 750000000, 1927 .vco_max = 1500000000, 1928 .base_reg = PLLD2_BASE, 1929 .misc_reg = PLLD2_MISC0, 1930 .lock_mask = PLL_BASE_LOCK, 1931 .lock_delay = 300, 1932 .iddq_reg = PLLD2_BASE, 1933 .iddq_bit_idx = PLLSS_IDDQ_BIT, 1934 .sdm_din_reg = PLLD2_MISC3, 1935 .sdm_din_mask = PLLA_SDM_DIN_MASK, 1936 .sdm_ctrl_reg = PLLD2_MISC1, 1937 .sdm_ctrl_en_mask = PLLD2_SDM_EN_MASK, 1938 .ssc_ctrl_reg = PLLD2_MISC1, 1939 .ssc_ctrl_en_mask = PLLD2_SSC_EN_MASK, 1940 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1941 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1942 .div_nmp = &pllss_nmp, 1943 .ext_misc_reg[0] = PLLD2_MISC0, 1944 .ext_misc_reg[1] = PLLD2_MISC1, 1945 .ext_misc_reg[2] = PLLD2_MISC2, 1946 .ext_misc_reg[3] = PLLD2_MISC3, 1947 .max_p = PLL_QLIN_PDIV_MAX, 1948 .mdiv_default = 1, 1949 .freq_table = tegra210_pll_d2_freq_table, 1950 .set_defaults = tegra210_plld2_set_defaults, 1951 .flags = TEGRA_PLL_USE_LOCK, 1952 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1953 .set_gain = tegra210_clk_pll_set_gain, 1954 .adjust_vco = tegra210_clk_adjust_vco_min, 1955 }; 1956 1957 static struct tegra_clk_pll_freq_table pll_dp_freq_table[] = { 1958 { 12000000, 270000000, 90, 1, 3, 0, 0xf000 }, 1959 { 13000000, 270000000, 83, 1, 3, 0, 0xf000 }, /* actual: 269.8 MHz */ 1960 { 38400000, 270000000, 28, 1, 3, 0, 0xf400 }, 1961 { 0, 0, 0, 0, 0, 0, 0 }, 1962 }; 1963 1964 static struct tegra_clk_pll_params pll_dp_params = { 1965 .input_min = 12000000, 1966 .input_max = 800000000, 1967 .cf_min = 12000000, 1968 .cf_max = 38400000, 1969 .vco_min = 750000000, 1970 .vco_max = 1500000000, 1971 .base_reg = PLLDP_BASE, 1972 .misc_reg = PLLDP_MISC, 1973 .lock_mask = PLL_BASE_LOCK, 1974 .lock_delay = 300, 1975 .iddq_reg = PLLDP_BASE, 1976 .iddq_bit_idx = PLLSS_IDDQ_BIT, 1977 .sdm_din_reg = PLLDP_SS_CTRL2, 1978 .sdm_din_mask = PLLA_SDM_DIN_MASK, 1979 .sdm_ctrl_reg = PLLDP_SS_CFG, 1980 .sdm_ctrl_en_mask = PLLDP_SDM_EN_MASK, 1981 .ssc_ctrl_reg = PLLDP_SS_CFG, 1982 .ssc_ctrl_en_mask = PLLDP_SSC_EN_MASK, 1983 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 1984 .pdiv_tohw = pll_qlin_pdiv_to_hw, 1985 .div_nmp = &pllss_nmp, 1986 .ext_misc_reg[0] = PLLDP_MISC, 1987 .ext_misc_reg[1] = PLLDP_SS_CFG, 1988 .ext_misc_reg[2] = PLLDP_SS_CTRL1, 1989 .ext_misc_reg[3] = PLLDP_SS_CTRL2, 1990 .max_p = PLL_QLIN_PDIV_MAX, 1991 .mdiv_default = 1, 1992 .freq_table = pll_dp_freq_table, 1993 .set_defaults = tegra210_plldp_set_defaults, 1994 .flags = TEGRA_PLL_USE_LOCK, 1995 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 1996 .set_gain = tegra210_clk_pll_set_gain, 1997 .adjust_vco = tegra210_clk_adjust_vco_min, 1998 }; 1999 2000 static struct div_nmp pllu_nmp = { 2001 .divm_shift = 0, 2002 .divm_width = 8, 2003 .divn_shift = 8, 2004 .divn_width = 8, 2005 .divp_shift = 16, 2006 .divp_width = 5, 2007 }; 2008 2009 static struct tegra_clk_pll_freq_table pll_u_freq_table[] = { 2010 { 12000000, 480000000, 40, 1, 0, 0 }, 2011 { 13000000, 480000000, 36, 1, 0, 0 }, /* actual: 468.0 MHz */ 2012 { 38400000, 480000000, 25, 2, 0, 0 }, 2013 { 0, 0, 0, 0, 0, 0 }, 2014 }; 2015 2016 static struct tegra_clk_pll_params pll_u_vco_params = { 2017 .input_min = 9600000, 2018 .input_max = 800000000, 2019 .cf_min = 9600000, 2020 .cf_max = 19200000, 2021 .vco_min = 350000000, 2022 .vco_max = 700000000, 2023 .base_reg = PLLU_BASE, 2024 .misc_reg = PLLU_MISC0, 2025 .lock_mask = PLL_BASE_LOCK, 2026 .lock_delay = 1000, 2027 .iddq_reg = PLLU_MISC0, 2028 .iddq_bit_idx = PLLU_IDDQ_BIT, 2029 .ext_misc_reg[0] = PLLU_MISC0, 2030 .ext_misc_reg[1] = PLLU_MISC1, 2031 .round_p_to_pdiv = pll_qlin_p_to_pdiv, 2032 .pdiv_tohw = pll_qlin_pdiv_to_hw, 2033 .div_nmp = &pllu_nmp, 2034 .freq_table = pll_u_freq_table, 2035 .flags = TEGRA_PLLU | TEGRA_PLL_USE_LOCK | TEGRA_PLL_VCO_OUT, 2036 .set_defaults = tegra210_pllu_set_defaults, 2037 .calc_rate = tegra210_pll_fixed_mdiv_cfg, 2038 }; 2039 2040 struct utmi_clk_param { 2041 /* Oscillator Frequency in KHz */ 2042 u32 osc_frequency; 2043 /* UTMIP PLL Enable Delay Count */ 2044 u8 enable_delay_count; 2045 /* UTMIP PLL Stable count */ 2046 u16 stable_count; 2047 /* UTMIP PLL Active delay count */ 2048 u8 active_delay_count; 2049 /* UTMIP PLL Xtal frequency count */ 2050 u16 xtal_freq_count; 2051 }; 2052 2053 static const struct utmi_clk_param utmi_parameters[] = { 2054 { 2055 .osc_frequency = 38400000, .enable_delay_count = 0x0, 2056 .stable_count = 0x0, .active_delay_count = 0x6, 2057 .xtal_freq_count = 0x80 2058 }, { 2059 .osc_frequency = 13000000, .enable_delay_count = 0x02, 2060 .stable_count = 0x33, .active_delay_count = 0x05, 2061 .xtal_freq_count = 0x7f 2062 }, { 2063 .osc_frequency = 19200000, .enable_delay_count = 0x03, 2064 .stable_count = 0x4b, .active_delay_count = 0x06, 2065 .xtal_freq_count = 0xbb 2066 }, { 2067 .osc_frequency = 12000000, .enable_delay_count = 0x02, 2068 .stable_count = 0x2f, .active_delay_count = 0x08, 2069 .xtal_freq_count = 0x76 2070 }, { 2071 .osc_frequency = 26000000, .enable_delay_count = 0x04, 2072 .stable_count = 0x66, .active_delay_count = 0x09, 2073 .xtal_freq_count = 0xfe 2074 }, { 2075 .osc_frequency = 16800000, .enable_delay_count = 0x03, 2076 .stable_count = 0x41, .active_delay_count = 0x0a, 2077 .xtal_freq_count = 0xa4 2078 }, 2079 }; 2080 2081 static struct tegra_clk tegra210_clks[tegra_clk_max] __initdata = { 2082 [tegra_clk_ispb] = { .dt_id = TEGRA210_CLK_ISPB, .present = true }, 2083 [tegra_clk_rtc] = { .dt_id = TEGRA210_CLK_RTC, .present = true }, 2084 [tegra_clk_timer] = { .dt_id = TEGRA210_CLK_TIMER, .present = true }, 2085 [tegra_clk_uarta_8] = { .dt_id = TEGRA210_CLK_UARTA, .present = true }, 2086 [tegra_clk_sdmmc2_9] = { .dt_id = TEGRA210_CLK_SDMMC2, .present = true }, 2087 [tegra_clk_i2s1] = { .dt_id = TEGRA210_CLK_I2S1, .present = true }, 2088 [tegra_clk_i2c1] = { .dt_id = TEGRA210_CLK_I2C1, .present = true }, 2089 [tegra_clk_sdmmc1_9] = { .dt_id = TEGRA210_CLK_SDMMC1, .present = true }, 2090 [tegra_clk_sdmmc4_9] = { .dt_id = TEGRA210_CLK_SDMMC4, .present = true }, 2091 [tegra_clk_pwm] = { .dt_id = TEGRA210_CLK_PWM, .present = true }, 2092 [tegra_clk_i2s2] = { .dt_id = TEGRA210_CLK_I2S2, .present = true }, 2093 [tegra_clk_usbd] = { .dt_id = TEGRA210_CLK_USBD, .present = true }, 2094 [tegra_clk_isp_9] = { .dt_id = TEGRA210_CLK_ISP, .present = true }, 2095 [tegra_clk_disp2_8] = { .dt_id = TEGRA210_CLK_DISP2, .present = true }, 2096 [tegra_clk_disp1_8] = { .dt_id = TEGRA210_CLK_DISP1, .present = true }, 2097 [tegra_clk_host1x_9] = { .dt_id = TEGRA210_CLK_HOST1X, .present = true }, 2098 [tegra_clk_i2s0] = { .dt_id = TEGRA210_CLK_I2S0, .present = true }, 2099 [tegra_clk_apbdma] = { .dt_id = TEGRA210_CLK_APBDMA, .present = true }, 2100 [tegra_clk_kfuse] = { .dt_id = TEGRA210_CLK_KFUSE, .present = true }, 2101 [tegra_clk_sbc1_9] = { .dt_id = TEGRA210_CLK_SBC1, .present = true }, 2102 [tegra_clk_sbc2_9] = { .dt_id = TEGRA210_CLK_SBC2, .present = true }, 2103 [tegra_clk_sbc3_9] = { .dt_id = TEGRA210_CLK_SBC3, .present = true }, 2104 [tegra_clk_i2c5] = { .dt_id = TEGRA210_CLK_I2C5, .present = true }, 2105 [tegra_clk_csi] = { .dt_id = TEGRA210_CLK_CSI, .present = true }, 2106 [tegra_clk_i2c2] = { .dt_id = TEGRA210_CLK_I2C2, .present = true }, 2107 [tegra_clk_uartc_8] = { .dt_id = TEGRA210_CLK_UARTC, .present = true }, 2108 [tegra_clk_mipi_cal] = { .dt_id = TEGRA210_CLK_MIPI_CAL, .present = true }, 2109 [tegra_clk_emc] = { .dt_id = TEGRA210_CLK_EMC, .present = true }, 2110 [tegra_clk_usb2] = { .dt_id = TEGRA210_CLK_USB2, .present = true }, 2111 [tegra_clk_bsev] = { .dt_id = TEGRA210_CLK_BSEV, .present = true }, 2112 [tegra_clk_uartd_8] = { .dt_id = TEGRA210_CLK_UARTD, .present = true }, 2113 [tegra_clk_i2c3] = { .dt_id = TEGRA210_CLK_I2C3, .present = true }, 2114 [tegra_clk_sbc4_9] = { .dt_id = TEGRA210_CLK_SBC4, .present = true }, 2115 [tegra_clk_sdmmc3_9] = { .dt_id = TEGRA210_CLK_SDMMC3, .present = true }, 2116 [tegra_clk_pcie] = { .dt_id = TEGRA210_CLK_PCIE, .present = true }, 2117 [tegra_clk_owr_8] = { .dt_id = TEGRA210_CLK_OWR, .present = true }, 2118 [tegra_clk_afi] = { .dt_id = TEGRA210_CLK_AFI, .present = true }, 2119 [tegra_clk_csite_8] = { .dt_id = TEGRA210_CLK_CSITE, .present = true }, 2120 [tegra_clk_soc_therm_8] = { .dt_id = TEGRA210_CLK_SOC_THERM, .present = true }, 2121 [tegra_clk_dtv] = { .dt_id = TEGRA210_CLK_DTV, .present = true }, 2122 [tegra_clk_i2cslow] = { .dt_id = TEGRA210_CLK_I2CSLOW, .present = true }, 2123 [tegra_clk_tsec_8] = { .dt_id = TEGRA210_CLK_TSEC, .present = true }, 2124 [tegra_clk_xusb_host] = { .dt_id = TEGRA210_CLK_XUSB_HOST, .present = true }, 2125 [tegra_clk_csus] = { .dt_id = TEGRA210_CLK_CSUS, .present = true }, 2126 [tegra_clk_mselect] = { .dt_id = TEGRA210_CLK_MSELECT, .present = true }, 2127 [tegra_clk_tsensor] = { .dt_id = TEGRA210_CLK_TSENSOR, .present = true }, 2128 [tegra_clk_i2s3] = { .dt_id = TEGRA210_CLK_I2S3, .present = true }, 2129 [tegra_clk_i2s4] = { .dt_id = TEGRA210_CLK_I2S4, .present = true }, 2130 [tegra_clk_i2c4] = { .dt_id = TEGRA210_CLK_I2C4, .present = true }, 2131 [tegra_clk_d_audio] = { .dt_id = TEGRA210_CLK_D_AUDIO, .present = true }, 2132 [tegra_clk_hda2codec_2x_8] = { .dt_id = TEGRA210_CLK_HDA2CODEC_2X, .present = true }, 2133 [tegra_clk_spdif_2x] = { .dt_id = TEGRA210_CLK_SPDIF_2X, .present = true }, 2134 [tegra_clk_actmon] = { .dt_id = TEGRA210_CLK_ACTMON, .present = true }, 2135 [tegra_clk_extern1] = { .dt_id = TEGRA210_CLK_EXTERN1, .present = true }, 2136 [tegra_clk_extern2] = { .dt_id = TEGRA210_CLK_EXTERN2, .present = true }, 2137 [tegra_clk_extern3] = { .dt_id = TEGRA210_CLK_EXTERN3, .present = true }, 2138 [tegra_clk_sata_oob_8] = { .dt_id = TEGRA210_CLK_SATA_OOB, .present = true }, 2139 [tegra_clk_sata_8] = { .dt_id = TEGRA210_CLK_SATA, .present = true }, 2140 [tegra_clk_hda_8] = { .dt_id = TEGRA210_CLK_HDA, .present = true }, 2141 [tegra_clk_hda2hdmi] = { .dt_id = TEGRA210_CLK_HDA2HDMI, .present = true }, 2142 [tegra_clk_cilab] = { .dt_id = TEGRA210_CLK_CILAB, .present = true }, 2143 [tegra_clk_cilcd] = { .dt_id = TEGRA210_CLK_CILCD, .present = true }, 2144 [tegra_clk_cile] = { .dt_id = TEGRA210_CLK_CILE, .present = true }, 2145 [tegra_clk_dsialp] = { .dt_id = TEGRA210_CLK_DSIALP, .present = true }, 2146 [tegra_clk_dsiblp] = { .dt_id = TEGRA210_CLK_DSIBLP, .present = true }, 2147 [tegra_clk_entropy_8] = { .dt_id = TEGRA210_CLK_ENTROPY, .present = true }, 2148 [tegra_clk_xusb_ss] = { .dt_id = TEGRA210_CLK_XUSB_SS, .present = true }, 2149 [tegra_clk_i2c6] = { .dt_id = TEGRA210_CLK_I2C6, .present = true }, 2150 [tegra_clk_vim2_clk] = { .dt_id = TEGRA210_CLK_VIM2_CLK, .present = true }, 2151 [tegra_clk_clk72Mhz_8] = { .dt_id = TEGRA210_CLK_CLK72MHZ, .present = true }, 2152 [tegra_clk_vic03_8] = { .dt_id = TEGRA210_CLK_VIC03, .present = true }, 2153 [tegra_clk_dpaux] = { .dt_id = TEGRA210_CLK_DPAUX, .present = true }, 2154 [tegra_clk_dpaux1] = { .dt_id = TEGRA210_CLK_DPAUX1, .present = true }, 2155 [tegra_clk_sor0] = { .dt_id = TEGRA210_CLK_SOR0, .present = true }, 2156 [tegra_clk_sor0_lvds] = { .dt_id = TEGRA210_CLK_SOR0_LVDS, .present = true }, 2157 [tegra_clk_gpu] = { .dt_id = TEGRA210_CLK_GPU, .present = true }, 2158 [tegra_clk_pll_g_ref] = { .dt_id = TEGRA210_CLK_PLL_G_REF, .present = true, }, 2159 [tegra_clk_uartb_8] = { .dt_id = TEGRA210_CLK_UARTB, .present = true }, 2160 [tegra_clk_vfir] = { .dt_id = TEGRA210_CLK_VFIR, .present = true }, 2161 [tegra_clk_spdif_in_8] = { .dt_id = TEGRA210_CLK_SPDIF_IN, .present = true }, 2162 [tegra_clk_spdif_out] = { .dt_id = TEGRA210_CLK_SPDIF_OUT, .present = true }, 2163 [tegra_clk_vi_10] = { .dt_id = TEGRA210_CLK_VI, .present = true }, 2164 [tegra_clk_vi_sensor_8] = { .dt_id = TEGRA210_CLK_VI_SENSOR, .present = true }, 2165 [tegra_clk_fuse] = { .dt_id = TEGRA210_CLK_FUSE, .present = true }, 2166 [tegra_clk_fuse_burn] = { .dt_id = TEGRA210_CLK_FUSE_BURN, .present = true }, 2167 [tegra_clk_clk_32k] = { .dt_id = TEGRA210_CLK_CLK_32K, .present = true }, 2168 [tegra_clk_clk_m] = { .dt_id = TEGRA210_CLK_CLK_M, .present = true }, 2169 [tegra_clk_clk_m_div2] = { .dt_id = TEGRA210_CLK_CLK_M_DIV2, .present = true }, 2170 [tegra_clk_clk_m_div4] = { .dt_id = TEGRA210_CLK_CLK_M_DIV4, .present = true }, 2171 [tegra_clk_pll_ref] = { .dt_id = TEGRA210_CLK_PLL_REF, .present = true }, 2172 [tegra_clk_pll_c] = { .dt_id = TEGRA210_CLK_PLL_C, .present = true }, 2173 [tegra_clk_pll_c_out1] = { .dt_id = TEGRA210_CLK_PLL_C_OUT1, .present = true }, 2174 [tegra_clk_pll_c2] = { .dt_id = TEGRA210_CLK_PLL_C2, .present = true }, 2175 [tegra_clk_pll_c3] = { .dt_id = TEGRA210_CLK_PLL_C3, .present = true }, 2176 [tegra_clk_pll_m] = { .dt_id = TEGRA210_CLK_PLL_M, .present = true }, 2177 [tegra_clk_pll_m_out1] = { .dt_id = TEGRA210_CLK_PLL_M_OUT1, .present = true }, 2178 [tegra_clk_pll_p] = { .dt_id = TEGRA210_CLK_PLL_P, .present = true }, 2179 [tegra_clk_pll_p_out1] = { .dt_id = TEGRA210_CLK_PLL_P_OUT1, .present = true }, 2180 [tegra_clk_pll_p_out3] = { .dt_id = TEGRA210_CLK_PLL_P_OUT3, .present = true }, 2181 [tegra_clk_pll_p_out4_cpu] = { .dt_id = TEGRA210_CLK_PLL_P_OUT4, .present = true }, 2182 [tegra_clk_pll_p_out_hsio] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_HSIO, .present = true }, 2183 [tegra_clk_pll_p_out_xusb] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_XUSB, .present = true }, 2184 [tegra_clk_pll_p_out_cpu] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_CPU, .present = true }, 2185 [tegra_clk_pll_p_out_adsp] = { .dt_id = TEGRA210_CLK_PLL_P_OUT_ADSP, .present = true }, 2186 [tegra_clk_pll_a] = { .dt_id = TEGRA210_CLK_PLL_A, .present = true }, 2187 [tegra_clk_pll_a_out0] = { .dt_id = TEGRA210_CLK_PLL_A_OUT0, .present = true }, 2188 [tegra_clk_pll_d] = { .dt_id = TEGRA210_CLK_PLL_D, .present = true }, 2189 [tegra_clk_pll_d_out0] = { .dt_id = TEGRA210_CLK_PLL_D_OUT0, .present = true }, 2190 [tegra_clk_pll_d2] = { .dt_id = TEGRA210_CLK_PLL_D2, .present = true }, 2191 [tegra_clk_pll_d2_out0] = { .dt_id = TEGRA210_CLK_PLL_D2_OUT0, .present = true }, 2192 [tegra_clk_pll_u] = { .dt_id = TEGRA210_CLK_PLL_U, .present = true }, 2193 [tegra_clk_pll_u_out] = { .dt_id = TEGRA210_CLK_PLL_U_OUT, .present = true }, 2194 [tegra_clk_pll_u_out1] = { .dt_id = TEGRA210_CLK_PLL_U_OUT1, .present = true }, 2195 [tegra_clk_pll_u_out2] = { .dt_id = TEGRA210_CLK_PLL_U_OUT2, .present = true }, 2196 [tegra_clk_pll_u_480m] = { .dt_id = TEGRA210_CLK_PLL_U_480M, .present = true }, 2197 [tegra_clk_pll_u_60m] = { .dt_id = TEGRA210_CLK_PLL_U_60M, .present = true }, 2198 [tegra_clk_pll_u_48m] = { .dt_id = TEGRA210_CLK_PLL_U_48M, .present = true }, 2199 [tegra_clk_pll_x] = { .dt_id = TEGRA210_CLK_PLL_X, .present = true }, 2200 [tegra_clk_pll_x_out0] = { .dt_id = TEGRA210_CLK_PLL_X_OUT0, .present = true }, 2201 [tegra_clk_pll_re_vco] = { .dt_id = TEGRA210_CLK_PLL_RE_VCO, .present = true }, 2202 [tegra_clk_pll_re_out] = { .dt_id = TEGRA210_CLK_PLL_RE_OUT, .present = true }, 2203 [tegra_clk_spdif_in_sync] = { .dt_id = TEGRA210_CLK_SPDIF_IN_SYNC, .present = true }, 2204 [tegra_clk_i2s0_sync] = { .dt_id = TEGRA210_CLK_I2S0_SYNC, .present = true }, 2205 [tegra_clk_i2s1_sync] = { .dt_id = TEGRA210_CLK_I2S1_SYNC, .present = true }, 2206 [tegra_clk_i2s2_sync] = { .dt_id = TEGRA210_CLK_I2S2_SYNC, .present = true }, 2207 [tegra_clk_i2s3_sync] = { .dt_id = TEGRA210_CLK_I2S3_SYNC, .present = true }, 2208 [tegra_clk_i2s4_sync] = { .dt_id = TEGRA210_CLK_I2S4_SYNC, .present = true }, 2209 [tegra_clk_vimclk_sync] = { .dt_id = TEGRA210_CLK_VIMCLK_SYNC, .present = true }, 2210 [tegra_clk_audio0] = { .dt_id = TEGRA210_CLK_AUDIO0, .present = true }, 2211 [tegra_clk_audio1] = { .dt_id = TEGRA210_CLK_AUDIO1, .present = true }, 2212 [tegra_clk_audio2] = { .dt_id = TEGRA210_CLK_AUDIO2, .present = true }, 2213 [tegra_clk_audio3] = { .dt_id = TEGRA210_CLK_AUDIO3, .present = true }, 2214 [tegra_clk_audio4] = { .dt_id = TEGRA210_CLK_AUDIO4, .present = true }, 2215 [tegra_clk_spdif] = { .dt_id = TEGRA210_CLK_SPDIF, .present = true }, 2216 [tegra_clk_clk_out_1] = { .dt_id = TEGRA210_CLK_CLK_OUT_1, .present = true }, 2217 [tegra_clk_clk_out_2] = { .dt_id = TEGRA210_CLK_CLK_OUT_2, .present = true }, 2218 [tegra_clk_clk_out_3] = { .dt_id = TEGRA210_CLK_CLK_OUT_3, .present = true }, 2219 [tegra_clk_blink] = { .dt_id = TEGRA210_CLK_BLINK, .present = true }, 2220 [tegra_clk_xusb_gate] = { .dt_id = TEGRA210_CLK_XUSB_GATE, .present = true }, 2221 [tegra_clk_xusb_host_src_8] = { .dt_id = TEGRA210_CLK_XUSB_HOST_SRC, .present = true }, 2222 [tegra_clk_xusb_falcon_src_8] = { .dt_id = TEGRA210_CLK_XUSB_FALCON_SRC, .present = true }, 2223 [tegra_clk_xusb_fs_src] = { .dt_id = TEGRA210_CLK_XUSB_FS_SRC, .present = true }, 2224 [tegra_clk_xusb_ss_src_8] = { .dt_id = TEGRA210_CLK_XUSB_SS_SRC, .present = true }, 2225 [tegra_clk_xusb_ss_div2] = { .dt_id = TEGRA210_CLK_XUSB_SS_DIV2, .present = true }, 2226 [tegra_clk_xusb_dev_src_8] = { .dt_id = TEGRA210_CLK_XUSB_DEV_SRC, .present = true }, 2227 [tegra_clk_xusb_dev] = { .dt_id = TEGRA210_CLK_XUSB_DEV, .present = true }, 2228 [tegra_clk_xusb_hs_src_4] = { .dt_id = TEGRA210_CLK_XUSB_HS_SRC, .present = true }, 2229 [tegra_clk_xusb_ssp_src] = { .dt_id = TEGRA210_CLK_XUSB_SSP_SRC, .present = true }, 2230 [tegra_clk_usb2_hsic_trk] = { .dt_id = TEGRA210_CLK_USB2_HSIC_TRK, .present = true }, 2231 [tegra_clk_hsic_trk] = { .dt_id = TEGRA210_CLK_HSIC_TRK, .present = true }, 2232 [tegra_clk_usb2_trk] = { .dt_id = TEGRA210_CLK_USB2_TRK, .present = true }, 2233 [tegra_clk_sclk] = { .dt_id = TEGRA210_CLK_SCLK, .present = true }, 2234 [tegra_clk_sclk_mux] = { .dt_id = TEGRA210_CLK_SCLK_MUX, .present = true }, 2235 [tegra_clk_hclk] = { .dt_id = TEGRA210_CLK_HCLK, .present = true }, 2236 [tegra_clk_pclk] = { .dt_id = TEGRA210_CLK_PCLK, .present = true }, 2237 [tegra_clk_cclk_g] = { .dt_id = TEGRA210_CLK_CCLK_G, .present = true }, 2238 [tegra_clk_cclk_lp] = { .dt_id = TEGRA210_CLK_CCLK_LP, .present = true }, 2239 [tegra_clk_dfll_ref] = { .dt_id = TEGRA210_CLK_DFLL_REF, .present = true }, 2240 [tegra_clk_dfll_soc] = { .dt_id = TEGRA210_CLK_DFLL_SOC, .present = true }, 2241 [tegra_clk_vi_sensor2_8] = { .dt_id = TEGRA210_CLK_VI_SENSOR2, .present = true }, 2242 [tegra_clk_pll_p_out5] = { .dt_id = TEGRA210_CLK_PLL_P_OUT5, .present = true }, 2243 [tegra_clk_pll_c4] = { .dt_id = TEGRA210_CLK_PLL_C4, .present = true }, 2244 [tegra_clk_pll_dp] = { .dt_id = TEGRA210_CLK_PLL_DP, .present = true }, 2245 [tegra_clk_audio0_mux] = { .dt_id = TEGRA210_CLK_AUDIO0_MUX, .present = true }, 2246 [tegra_clk_audio1_mux] = { .dt_id = TEGRA210_CLK_AUDIO1_MUX, .present = true }, 2247 [tegra_clk_audio2_mux] = { .dt_id = TEGRA210_CLK_AUDIO2_MUX, .present = true }, 2248 [tegra_clk_audio3_mux] = { .dt_id = TEGRA210_CLK_AUDIO3_MUX, .present = true }, 2249 [tegra_clk_audio4_mux] = { .dt_id = TEGRA210_CLK_AUDIO4_MUX, .present = true }, 2250 [tegra_clk_spdif_mux] = { .dt_id = TEGRA210_CLK_SPDIF_MUX, .present = true }, 2251 [tegra_clk_clk_out_1_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_1_MUX, .present = true }, 2252 [tegra_clk_clk_out_2_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_2_MUX, .present = true }, 2253 [tegra_clk_clk_out_3_mux] = { .dt_id = TEGRA210_CLK_CLK_OUT_3_MUX, .present = true }, 2254 [tegra_clk_maud] = { .dt_id = TEGRA210_CLK_MAUD, .present = true }, 2255 [tegra_clk_mipibif] = { .dt_id = TEGRA210_CLK_MIPIBIF, .present = true }, 2256 [tegra_clk_qspi] = { .dt_id = TEGRA210_CLK_QSPI, .present = true }, 2257 [tegra_clk_sdmmc_legacy] = { .dt_id = TEGRA210_CLK_SDMMC_LEGACY, .present = true }, 2258 [tegra_clk_tsecb] = { .dt_id = TEGRA210_CLK_TSECB, .present = true }, 2259 [tegra_clk_uartape] = { .dt_id = TEGRA210_CLK_UARTAPE, .present = true }, 2260 [tegra_clk_vi_i2c] = { .dt_id = TEGRA210_CLK_VI_I2C, .present = true }, 2261 [tegra_clk_ape] = { .dt_id = TEGRA210_CLK_APE, .present = true }, 2262 [tegra_clk_dbgapb] = { .dt_id = TEGRA210_CLK_DBGAPB, .present = true }, 2263 [tegra_clk_nvdec] = { .dt_id = TEGRA210_CLK_NVDEC, .present = true }, 2264 [tegra_clk_nvenc] = { .dt_id = TEGRA210_CLK_NVENC, .present = true }, 2265 [tegra_clk_nvjpg] = { .dt_id = TEGRA210_CLK_NVJPG, .present = true }, 2266 [tegra_clk_pll_c4_out0] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT0, .present = true }, 2267 [tegra_clk_pll_c4_out1] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT1, .present = true }, 2268 [tegra_clk_pll_c4_out2] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT2, .present = true }, 2269 [tegra_clk_pll_c4_out3] = { .dt_id = TEGRA210_CLK_PLL_C4_OUT3, .present = true }, 2270 [tegra_clk_apb2ape] = { .dt_id = TEGRA210_CLK_APB2APE, .present = true }, 2271 }; 2272 2273 static struct tegra_devclk devclks[] __initdata = { 2274 { .con_id = "clk_m", .dt_id = TEGRA210_CLK_CLK_M }, 2275 { .con_id = "pll_ref", .dt_id = TEGRA210_CLK_PLL_REF }, 2276 { .con_id = "clk_32k", .dt_id = TEGRA210_CLK_CLK_32K }, 2277 { .con_id = "clk_m_div2", .dt_id = TEGRA210_CLK_CLK_M_DIV2 }, 2278 { .con_id = "clk_m_div4", .dt_id = TEGRA210_CLK_CLK_M_DIV4 }, 2279 { .con_id = "pll_c", .dt_id = TEGRA210_CLK_PLL_C }, 2280 { .con_id = "pll_c_out1", .dt_id = TEGRA210_CLK_PLL_C_OUT1 }, 2281 { .con_id = "pll_c2", .dt_id = TEGRA210_CLK_PLL_C2 }, 2282 { .con_id = "pll_c3", .dt_id = TEGRA210_CLK_PLL_C3 }, 2283 { .con_id = "pll_p", .dt_id = TEGRA210_CLK_PLL_P }, 2284 { .con_id = "pll_p_out1", .dt_id = TEGRA210_CLK_PLL_P_OUT1 }, 2285 { .con_id = "pll_p_out2", .dt_id = TEGRA210_CLK_PLL_P_OUT2 }, 2286 { .con_id = "pll_p_out3", .dt_id = TEGRA210_CLK_PLL_P_OUT3 }, 2287 { .con_id = "pll_p_out4", .dt_id = TEGRA210_CLK_PLL_P_OUT4 }, 2288 { .con_id = "pll_m", .dt_id = TEGRA210_CLK_PLL_M }, 2289 { .con_id = "pll_m_out1", .dt_id = TEGRA210_CLK_PLL_M_OUT1 }, 2290 { .con_id = "pll_x", .dt_id = TEGRA210_CLK_PLL_X }, 2291 { .con_id = "pll_x_out0", .dt_id = TEGRA210_CLK_PLL_X_OUT0 }, 2292 { .con_id = "pll_u", .dt_id = TEGRA210_CLK_PLL_U }, 2293 { .con_id = "pll_u_out", .dt_id = TEGRA210_CLK_PLL_U_OUT }, 2294 { .con_id = "pll_u_out1", .dt_id = TEGRA210_CLK_PLL_U_OUT1 }, 2295 { .con_id = "pll_u_out2", .dt_id = TEGRA210_CLK_PLL_U_OUT2 }, 2296 { .con_id = "pll_u_480M", .dt_id = TEGRA210_CLK_PLL_U_480M }, 2297 { .con_id = "pll_u_60M", .dt_id = TEGRA210_CLK_PLL_U_60M }, 2298 { .con_id = "pll_u_48M", .dt_id = TEGRA210_CLK_PLL_U_48M }, 2299 { .con_id = "pll_d", .dt_id = TEGRA210_CLK_PLL_D }, 2300 { .con_id = "pll_d_out0", .dt_id = TEGRA210_CLK_PLL_D_OUT0 }, 2301 { .con_id = "pll_d2", .dt_id = TEGRA210_CLK_PLL_D2 }, 2302 { .con_id = "pll_d2_out0", .dt_id = TEGRA210_CLK_PLL_D2_OUT0 }, 2303 { .con_id = "pll_a", .dt_id = TEGRA210_CLK_PLL_A }, 2304 { .con_id = "pll_a_out0", .dt_id = TEGRA210_CLK_PLL_A_OUT0 }, 2305 { .con_id = "pll_re_vco", .dt_id = TEGRA210_CLK_PLL_RE_VCO }, 2306 { .con_id = "pll_re_out", .dt_id = TEGRA210_CLK_PLL_RE_OUT }, 2307 { .con_id = "spdif_in_sync", .dt_id = TEGRA210_CLK_SPDIF_IN_SYNC }, 2308 { .con_id = "i2s0_sync", .dt_id = TEGRA210_CLK_I2S0_SYNC }, 2309 { .con_id = "i2s1_sync", .dt_id = TEGRA210_CLK_I2S1_SYNC }, 2310 { .con_id = "i2s2_sync", .dt_id = TEGRA210_CLK_I2S2_SYNC }, 2311 { .con_id = "i2s3_sync", .dt_id = TEGRA210_CLK_I2S3_SYNC }, 2312 { .con_id = "i2s4_sync", .dt_id = TEGRA210_CLK_I2S4_SYNC }, 2313 { .con_id = "vimclk_sync", .dt_id = TEGRA210_CLK_VIMCLK_SYNC }, 2314 { .con_id = "audio0", .dt_id = TEGRA210_CLK_AUDIO0 }, 2315 { .con_id = "audio1", .dt_id = TEGRA210_CLK_AUDIO1 }, 2316 { .con_id = "audio2", .dt_id = TEGRA210_CLK_AUDIO2 }, 2317 { .con_id = "audio3", .dt_id = TEGRA210_CLK_AUDIO3 }, 2318 { .con_id = "audio4", .dt_id = TEGRA210_CLK_AUDIO4 }, 2319 { .con_id = "spdif", .dt_id = TEGRA210_CLK_SPDIF }, 2320 { .con_id = "spdif_2x", .dt_id = TEGRA210_CLK_SPDIF_2X }, 2321 { .con_id = "extern1", .dev_id = "clk_out_1", .dt_id = TEGRA210_CLK_EXTERN1 }, 2322 { .con_id = "extern2", .dev_id = "clk_out_2", .dt_id = TEGRA210_CLK_EXTERN2 }, 2323 { .con_id = "extern3", .dev_id = "clk_out_3", .dt_id = TEGRA210_CLK_EXTERN3 }, 2324 { .con_id = "blink", .dt_id = TEGRA210_CLK_BLINK }, 2325 { .con_id = "cclk_g", .dt_id = TEGRA210_CLK_CCLK_G }, 2326 { .con_id = "cclk_lp", .dt_id = TEGRA210_CLK_CCLK_LP }, 2327 { .con_id = "sclk", .dt_id = TEGRA210_CLK_SCLK }, 2328 { .con_id = "hclk", .dt_id = TEGRA210_CLK_HCLK }, 2329 { .con_id = "pclk", .dt_id = TEGRA210_CLK_PCLK }, 2330 { .con_id = "fuse", .dt_id = TEGRA210_CLK_FUSE }, 2331 { .dev_id = "rtc-tegra", .dt_id = TEGRA210_CLK_RTC }, 2332 { .dev_id = "timer", .dt_id = TEGRA210_CLK_TIMER }, 2333 { .con_id = "pll_c4_out0", .dt_id = TEGRA210_CLK_PLL_C4_OUT0 }, 2334 { .con_id = "pll_c4_out1", .dt_id = TEGRA210_CLK_PLL_C4_OUT1 }, 2335 { .con_id = "pll_c4_out2", .dt_id = TEGRA210_CLK_PLL_C4_OUT2 }, 2336 { .con_id = "pll_c4_out3", .dt_id = TEGRA210_CLK_PLL_C4_OUT3 }, 2337 { .con_id = "dpaux", .dt_id = TEGRA210_CLK_DPAUX }, 2338 { .con_id = "sor0", .dt_id = TEGRA210_CLK_SOR0 }, 2339 }; 2340 2341 static struct tegra_audio_clk_info tegra210_audio_plls[] = { 2342 { "pll_a", &pll_a_params, tegra_clk_pll_a, "pll_ref" }, 2343 { "pll_a1", &pll_a1_params, tegra_clk_pll_a1, "pll_ref" }, 2344 }; 2345 2346 static struct clk **clks; 2347 2348 static void tegra210_utmi_param_configure(void __iomem *clk_base) 2349 { 2350 u32 reg; 2351 int i; 2352 2353 for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) { 2354 if (osc_freq == utmi_parameters[i].osc_frequency) 2355 break; 2356 } 2357 2358 if (i >= ARRAY_SIZE(utmi_parameters)) { 2359 pr_err("%s: Unexpected oscillator freq %lu\n", __func__, 2360 osc_freq); 2361 return; 2362 } 2363 2364 reg = readl_relaxed(clk_base + PLLU_HW_PWRDN_CFG0); 2365 reg |= PLLU_HW_PWRDN_CFG0_IDDQ_PD_INCLUDE | 2366 PLLU_HW_PWRDN_CFG0_USE_SWITCH_DETECT | 2367 PLLU_HW_PWRDN_CFG0_USE_LOCKDET; 2368 reg &= ~(PLLU_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL | 2369 PLLU_HW_PWRDN_CFG0_CLK_SWITCH_SWCTL); 2370 writel_relaxed(reg, clk_base + PLLU_HW_PWRDN_CFG0); 2371 2372 reg = readl_relaxed(clk_base + PLLU_HW_PWRDN_CFG0); 2373 reg |= PLLU_HW_PWRDN_CFG0_SEQ_ENABLE; 2374 writel_relaxed(reg, clk_base + PLLU_HW_PWRDN_CFG0); 2375 udelay(1); 2376 2377 reg = readl_relaxed(clk_base + PLLU_BASE); 2378 reg &= ~PLLU_BASE_CLKENABLE_USB; 2379 writel_relaxed(reg, clk_base + PLLU_BASE); 2380 2381 reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); 2382 reg &= ~UTMIPLL_HW_PWRDN_CFG0_IDDQ_OVERRIDE; 2383 writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0); 2384 2385 udelay(10); 2386 2387 reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2); 2388 2389 /* Program UTMIP PLL stable and active counts */ 2390 /* [FIXME] arclk_rst.h says WRONG! This should be 1ms -> 0x50 Check! */ 2391 reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0); 2392 reg |= UTMIP_PLL_CFG2_STABLE_COUNT(utmi_parameters[i].stable_count); 2393 2394 reg &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0); 2395 2396 reg |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(utmi_parameters[i]. 2397 active_delay_count); 2398 writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2); 2399 2400 /* Program UTMIP PLL delay and oscillator frequency counts */ 2401 reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1); 2402 reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0); 2403 2404 reg |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(utmi_parameters[i]. 2405 enable_delay_count); 2406 2407 reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0); 2408 reg |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(utmi_parameters[i]. 2409 xtal_freq_count); 2410 2411 reg |= UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN; 2412 writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1); 2413 2414 /* Remove power downs from UTMIP PLL control bits */ 2415 reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1); 2416 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN; 2417 reg |= UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP; 2418 writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1); 2419 udelay(1); 2420 2421 /* Enable samplers for SNPS, XUSB_HOST, XUSB_DEV */ 2422 reg = readl_relaxed(clk_base + UTMIP_PLL_CFG2); 2423 reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERUP; 2424 reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERUP; 2425 reg |= UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERUP; 2426 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN; 2427 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN; 2428 reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_D_POWERDOWN; 2429 writel_relaxed(reg, clk_base + UTMIP_PLL_CFG2); 2430 2431 /* Setup HW control of UTMIPLL */ 2432 reg = readl_relaxed(clk_base + UTMIP_PLL_CFG1); 2433 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN; 2434 reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERUP; 2435 writel_relaxed(reg, clk_base + UTMIP_PLL_CFG1); 2436 2437 reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); 2438 reg |= UTMIPLL_HW_PWRDN_CFG0_USE_LOCKDET; 2439 reg &= ~UTMIPLL_HW_PWRDN_CFG0_CLK_ENABLE_SWCTL; 2440 writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0); 2441 2442 udelay(1); 2443 2444 reg = readl_relaxed(clk_base + XUSB_PLL_CFG0); 2445 reg &= ~XUSB_PLL_CFG0_UTMIPLL_LOCK_DLY; 2446 writel_relaxed(reg, clk_base + XUSB_PLL_CFG0); 2447 2448 udelay(1); 2449 2450 /* Enable HW control UTMIPLL */ 2451 reg = readl_relaxed(clk_base + UTMIPLL_HW_PWRDN_CFG0); 2452 reg |= UTMIPLL_HW_PWRDN_CFG0_SEQ_ENABLE; 2453 writel_relaxed(reg, clk_base + UTMIPLL_HW_PWRDN_CFG0); 2454 } 2455 2456 static __init void tegra210_periph_clk_init(void __iomem *clk_base, 2457 void __iomem *pmc_base) 2458 { 2459 struct clk *clk; 2460 2461 /* xusb_ss_div2 */ 2462 clk = clk_register_fixed_factor(NULL, "xusb_ss_div2", "xusb_ss_src", 0, 2463 1, 2); 2464 clks[TEGRA210_CLK_XUSB_SS_DIV2] = clk; 2465 2466 clk = tegra_clk_register_periph_fixed("dpaux", "pll_p", 0, clk_base, 2467 1, 17, 181); 2468 clks[TEGRA210_CLK_DPAUX] = clk; 2469 2470 clk = tegra_clk_register_periph_fixed("dpaux1", "pll_p", 0, clk_base, 2471 1, 17, 207); 2472 clks[TEGRA210_CLK_DPAUX1] = clk; 2473 2474 clk = tegra_clk_register_periph_fixed("sor_safe", "pll_p", 0, clk_base, 2475 1, 17, 222); 2476 clks[TEGRA210_CLK_SOR_SAFE] = clk; 2477 2478 /* pll_d_dsi_out */ 2479 clk = clk_register_gate(NULL, "pll_d_dsi_out", "pll_d_out0", 0, 2480 clk_base + PLLD_MISC0, 21, 0, &pll_d_lock); 2481 clks[TEGRA210_CLK_PLL_D_DSI_OUT] = clk; 2482 2483 /* dsia */ 2484 clk = tegra_clk_register_periph_gate("dsia", "pll_d_dsi_out", 0, 2485 clk_base, 0, 48, 2486 periph_clk_enb_refcnt); 2487 clks[TEGRA210_CLK_DSIA] = clk; 2488 2489 /* dsib */ 2490 clk = tegra_clk_register_periph_gate("dsib", "pll_d_dsi_out", 0, 2491 clk_base, 0, 82, 2492 periph_clk_enb_refcnt); 2493 clks[TEGRA210_CLK_DSIB] = clk; 2494 2495 /* emc mux */ 2496 clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm, 2497 ARRAY_SIZE(mux_pllmcp_clkm), 0, 2498 clk_base + CLK_SOURCE_EMC, 2499 29, 3, 0, &emc_lock); 2500 2501 clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC, 2502 &emc_lock); 2503 clks[TEGRA210_CLK_MC] = clk; 2504 2505 /* cml0 */ 2506 clk = clk_register_gate(NULL, "cml0", "pll_e", 0, clk_base + PLLE_AUX, 2507 0, 0, &pll_e_lock); 2508 clk_register_clkdev(clk, "cml0", NULL); 2509 clks[TEGRA210_CLK_CML0] = clk; 2510 2511 /* cml1 */ 2512 clk = clk_register_gate(NULL, "cml1", "pll_e", 0, clk_base + PLLE_AUX, 2513 1, 0, &pll_e_lock); 2514 clk_register_clkdev(clk, "cml1", NULL); 2515 clks[TEGRA210_CLK_CML1] = clk; 2516 2517 tegra_periph_clk_init(clk_base, pmc_base, tegra210_clks, &pll_p_params); 2518 } 2519 2520 static void __init tegra210_pll_init(void __iomem *clk_base, 2521 void __iomem *pmc) 2522 { 2523 u32 val; 2524 struct clk *clk; 2525 2526 /* PLLC */ 2527 clk = tegra_clk_register_pllxc_tegra210("pll_c", "pll_ref", clk_base, 2528 pmc, 0, &pll_c_params, NULL); 2529 if (!WARN_ON(IS_ERR(clk))) 2530 clk_register_clkdev(clk, "pll_c", NULL); 2531 clks[TEGRA210_CLK_PLL_C] = clk; 2532 2533 /* PLLC_OUT1 */ 2534 clk = tegra_clk_register_divider("pll_c_out1_div", "pll_c", 2535 clk_base + PLLC_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 2536 8, 8, 1, NULL); 2537 clk = tegra_clk_register_pll_out("pll_c_out1", "pll_c_out1_div", 2538 clk_base + PLLC_OUT, 1, 0, 2539 CLK_SET_RATE_PARENT, 0, NULL); 2540 clk_register_clkdev(clk, "pll_c_out1", NULL); 2541 clks[TEGRA210_CLK_PLL_C_OUT1] = clk; 2542 2543 /* PLLC_UD */ 2544 clk = clk_register_fixed_factor(NULL, "pll_c_ud", "pll_c", 2545 CLK_SET_RATE_PARENT, 1, 1); 2546 clk_register_clkdev(clk, "pll_c_ud", NULL); 2547 clks[TEGRA210_CLK_PLL_C_UD] = clk; 2548 2549 /* PLLC2 */ 2550 clk = tegra_clk_register_pllc_tegra210("pll_c2", "pll_ref", clk_base, 2551 pmc, 0, &pll_c2_params, NULL); 2552 clk_register_clkdev(clk, "pll_c2", NULL); 2553 clks[TEGRA210_CLK_PLL_C2] = clk; 2554 2555 /* PLLC3 */ 2556 clk = tegra_clk_register_pllc_tegra210("pll_c3", "pll_ref", clk_base, 2557 pmc, 0, &pll_c3_params, NULL); 2558 clk_register_clkdev(clk, "pll_c3", NULL); 2559 clks[TEGRA210_CLK_PLL_C3] = clk; 2560 2561 /* PLLM */ 2562 clk = tegra_clk_register_pllm("pll_m", "osc", clk_base, pmc, 2563 CLK_SET_RATE_GATE, &pll_m_params, NULL); 2564 clk_register_clkdev(clk, "pll_m", NULL); 2565 clks[TEGRA210_CLK_PLL_M] = clk; 2566 2567 /* PLLMB */ 2568 clk = tegra_clk_register_pllmb("pll_mb", "osc", clk_base, pmc, 2569 CLK_SET_RATE_GATE, &pll_mb_params, NULL); 2570 clk_register_clkdev(clk, "pll_mb", NULL); 2571 clks[TEGRA210_CLK_PLL_MB] = clk; 2572 2573 clk_register_clkdev(clk, "pll_m_out1", NULL); 2574 clks[TEGRA210_CLK_PLL_M_OUT1] = clk; 2575 2576 /* PLLM_UD */ 2577 clk = clk_register_fixed_factor(NULL, "pll_m_ud", "pll_m", 2578 CLK_SET_RATE_PARENT, 1, 1); 2579 clk_register_clkdev(clk, "pll_m_ud", NULL); 2580 clks[TEGRA210_CLK_PLL_M_UD] = clk; 2581 2582 /* PLLU_VCO */ 2583 val = readl(clk_base + pll_u_vco_params.base_reg); 2584 val &= ~PLLU_BASE_OVERRIDE; /* disable PLLU_OVERRIDE */ 2585 writel(val, clk_base + pll_u_vco_params.base_reg); 2586 2587 clk = tegra_clk_register_pllre("pll_u_vco", "pll_ref", clk_base, pmc, 2588 0, &pll_u_vco_params, &pll_u_lock, pll_ref_freq); 2589 clk_register_clkdev(clk, "pll_u_vco", NULL); 2590 clks[TEGRA210_CLK_PLL_U] = clk; 2591 2592 /* PLLU_OUT */ 2593 clk = clk_register_divider_table(NULL, "pll_u_out", "pll_u_vco", 0, 2594 clk_base + PLLU_BASE, 16, 4, 0, 2595 pll_vco_post_div_table, NULL); 2596 clk_register_clkdev(clk, "pll_u_out", NULL); 2597 clks[TEGRA210_CLK_PLL_U_OUT] = clk; 2598 2599 /* PLLU_OUT1 */ 2600 clk = tegra_clk_register_divider("pll_u_out1_div", "pll_u_out", 2601 clk_base + PLLU_OUTA, 0, 2602 TEGRA_DIVIDER_ROUND_UP, 2603 8, 8, 1, &pll_u_lock); 2604 clk = tegra_clk_register_pll_out("pll_u_out1", "pll_u_out1_div", 2605 clk_base + PLLU_OUTA, 1, 0, 2606 CLK_SET_RATE_PARENT, 0, &pll_u_lock); 2607 clk_register_clkdev(clk, "pll_u_out1", NULL); 2608 clks[TEGRA210_CLK_PLL_U_OUT1] = clk; 2609 2610 /* PLLU_OUT2 */ 2611 clk = tegra_clk_register_divider("pll_u_out2_div", "pll_u_out", 2612 clk_base + PLLU_OUTA, 0, 2613 TEGRA_DIVIDER_ROUND_UP, 2614 24, 8, 1, &pll_u_lock); 2615 clk = tegra_clk_register_pll_out("pll_u_out2", "pll_u_out2_div", 2616 clk_base + PLLU_OUTA, 17, 16, 2617 CLK_SET_RATE_PARENT, 0, &pll_u_lock); 2618 clk_register_clkdev(clk, "pll_u_out2", NULL); 2619 clks[TEGRA210_CLK_PLL_U_OUT2] = clk; 2620 2621 tegra210_utmi_param_configure(clk_base); 2622 2623 /* PLLU_480M */ 2624 clk = clk_register_gate(NULL, "pll_u_480M", "pll_u_vco", 2625 CLK_SET_RATE_PARENT, clk_base + PLLU_BASE, 2626 22, 0, &pll_u_lock); 2627 clk_register_clkdev(clk, "pll_u_480M", NULL); 2628 clks[TEGRA210_CLK_PLL_U_480M] = clk; 2629 2630 /* PLLU_60M */ 2631 clk = clk_register_gate(NULL, "pll_u_60M", "pll_u_out2", 2632 CLK_SET_RATE_PARENT, clk_base + PLLU_BASE, 2633 23, 0, NULL); 2634 clk_register_clkdev(clk, "pll_u_60M", NULL); 2635 clks[TEGRA210_CLK_PLL_U_60M] = clk; 2636 2637 /* PLLU_48M */ 2638 clk = clk_register_gate(NULL, "pll_u_48M", "pll_u_out1", 2639 CLK_SET_RATE_PARENT, clk_base + PLLU_BASE, 2640 25, 0, NULL); 2641 clk_register_clkdev(clk, "pll_u_48M", NULL); 2642 clks[TEGRA210_CLK_PLL_U_48M] = clk; 2643 2644 /* PLLD */ 2645 clk = tegra_clk_register_pll("pll_d", "pll_ref", clk_base, pmc, 0, 2646 &pll_d_params, &pll_d_lock); 2647 clk_register_clkdev(clk, "pll_d", NULL); 2648 clks[TEGRA210_CLK_PLL_D] = clk; 2649 2650 /* PLLD_OUT0 */ 2651 clk = clk_register_fixed_factor(NULL, "pll_d_out0", "pll_d", 2652 CLK_SET_RATE_PARENT, 1, 2); 2653 clk_register_clkdev(clk, "pll_d_out0", NULL); 2654 clks[TEGRA210_CLK_PLL_D_OUT0] = clk; 2655 2656 /* PLLRE */ 2657 clk = tegra_clk_register_pllre_tegra210("pll_re_vco", "pll_ref", 2658 clk_base, pmc, 0, 2659 &pll_re_vco_params, 2660 &pll_re_lock, pll_ref_freq); 2661 clk_register_clkdev(clk, "pll_re_vco", NULL); 2662 clks[TEGRA210_CLK_PLL_RE_VCO] = clk; 2663 2664 clk = clk_register_divider_table(NULL, "pll_re_out", "pll_re_vco", 0, 2665 clk_base + PLLRE_BASE, 16, 5, 0, 2666 pll_vco_post_div_table, &pll_re_lock); 2667 clk_register_clkdev(clk, "pll_re_out", NULL); 2668 clks[TEGRA210_CLK_PLL_RE_OUT] = clk; 2669 2670 clk = tegra_clk_register_divider("pll_re_out1_div", "pll_re_vco", 2671 clk_base + PLLRE_OUT1, 0, 2672 TEGRA_DIVIDER_ROUND_UP, 2673 8, 8, 1, NULL); 2674 clk = tegra_clk_register_pll_out("pll_re_out1", "pll_re_out1_div", 2675 clk_base + PLLRE_OUT1, 1, 0, 2676 CLK_SET_RATE_PARENT, 0, NULL); 2677 clks[TEGRA210_CLK_PLL_RE_OUT1] = clk; 2678 2679 /* PLLE */ 2680 clk = tegra_clk_register_plle_tegra210("pll_e", "pll_ref", 2681 clk_base, 0, &pll_e_params, NULL); 2682 clk_register_clkdev(clk, "pll_e", NULL); 2683 clks[TEGRA210_CLK_PLL_E] = clk; 2684 2685 /* PLLC4 */ 2686 clk = tegra_clk_register_pllre("pll_c4_vco", "pll_ref", clk_base, pmc, 2687 0, &pll_c4_vco_params, NULL, pll_ref_freq); 2688 clk_register_clkdev(clk, "pll_c4_vco", NULL); 2689 clks[TEGRA210_CLK_PLL_C4] = clk; 2690 2691 /* PLLC4_OUT0 */ 2692 clk = clk_register_divider_table(NULL, "pll_c4_out0", "pll_c4_vco", 0, 2693 clk_base + PLLC4_BASE, 19, 4, 0, 2694 pll_vco_post_div_table, NULL); 2695 clk_register_clkdev(clk, "pll_c4_out0", NULL); 2696 clks[TEGRA210_CLK_PLL_C4_OUT0] = clk; 2697 2698 /* PLLC4_OUT1 */ 2699 clk = clk_register_fixed_factor(NULL, "pll_c4_out1", "pll_c4_vco", 2700 CLK_SET_RATE_PARENT, 1, 3); 2701 clk_register_clkdev(clk, "pll_c4_out1", NULL); 2702 clks[TEGRA210_CLK_PLL_C4_OUT1] = clk; 2703 2704 /* PLLC4_OUT2 */ 2705 clk = clk_register_fixed_factor(NULL, "pll_c4_out2", "pll_c4_vco", 2706 CLK_SET_RATE_PARENT, 1, 5); 2707 clk_register_clkdev(clk, "pll_c4_out2", NULL); 2708 clks[TEGRA210_CLK_PLL_C4_OUT2] = clk; 2709 2710 /* PLLC4_OUT3 */ 2711 clk = tegra_clk_register_divider("pll_c4_out3_div", "pll_c4_out0", 2712 clk_base + PLLC4_OUT, 0, TEGRA_DIVIDER_ROUND_UP, 2713 8, 8, 1, NULL); 2714 clk = tegra_clk_register_pll_out("pll_c4_out3", "pll_c4_out3_div", 2715 clk_base + PLLC4_OUT, 1, 0, 2716 CLK_SET_RATE_PARENT, 0, NULL); 2717 clk_register_clkdev(clk, "pll_c4_out3", NULL); 2718 clks[TEGRA210_CLK_PLL_C4_OUT3] = clk; 2719 2720 /* PLLDP */ 2721 clk = tegra_clk_register_pllss_tegra210("pll_dp", "pll_ref", clk_base, 2722 0, &pll_dp_params, NULL); 2723 clk_register_clkdev(clk, "pll_dp", NULL); 2724 clks[TEGRA210_CLK_PLL_DP] = clk; 2725 2726 /* PLLD2 */ 2727 clk = tegra_clk_register_pllss_tegra210("pll_d2", "pll_ref", clk_base, 2728 0, &pll_d2_params, NULL); 2729 clk_register_clkdev(clk, "pll_d2", NULL); 2730 clks[TEGRA210_CLK_PLL_D2] = clk; 2731 2732 /* PLLD2_OUT0 */ 2733 clk = clk_register_fixed_factor(NULL, "pll_d2_out0", "pll_d2", 2734 CLK_SET_RATE_PARENT, 1, 1); 2735 clk_register_clkdev(clk, "pll_d2_out0", NULL); 2736 clks[TEGRA210_CLK_PLL_D2_OUT0] = clk; 2737 2738 /* PLLP_OUT2 */ 2739 clk = clk_register_fixed_factor(NULL, "pll_p_out2", "pll_p", 2740 CLK_SET_RATE_PARENT, 1, 2); 2741 clk_register_clkdev(clk, "pll_p_out2", NULL); 2742 clks[TEGRA210_CLK_PLL_P_OUT2] = clk; 2743 2744 } 2745 2746 /* Tegra210 CPU clock and reset control functions */ 2747 static void tegra210_wait_cpu_in_reset(u32 cpu) 2748 { 2749 unsigned int reg; 2750 2751 do { 2752 reg = readl(clk_base + CLK_RST_CONTROLLER_CPU_CMPLX_STATUS); 2753 cpu_relax(); 2754 } while (!(reg & (1 << cpu))); /* check CPU been reset or not */ 2755 } 2756 2757 static void tegra210_disable_cpu_clock(u32 cpu) 2758 { 2759 /* flow controller would take care in the power sequence. */ 2760 } 2761 2762 #ifdef CONFIG_PM_SLEEP 2763 static void tegra210_cpu_clock_suspend(void) 2764 { 2765 /* switch coresite to clk_m, save off original source */ 2766 tegra210_cpu_clk_sctx.clk_csite_src = 2767 readl(clk_base + CLK_SOURCE_CSITE); 2768 writel(3 << 30, clk_base + CLK_SOURCE_CSITE); 2769 } 2770 2771 static void tegra210_cpu_clock_resume(void) 2772 { 2773 writel(tegra210_cpu_clk_sctx.clk_csite_src, 2774 clk_base + CLK_SOURCE_CSITE); 2775 } 2776 #endif 2777 2778 static struct tegra_cpu_car_ops tegra210_cpu_car_ops = { 2779 .wait_for_reset = tegra210_wait_cpu_in_reset, 2780 .disable_clock = tegra210_disable_cpu_clock, 2781 #ifdef CONFIG_PM_SLEEP 2782 .suspend = tegra210_cpu_clock_suspend, 2783 .resume = tegra210_cpu_clock_resume, 2784 #endif 2785 }; 2786 2787 static const struct of_device_id pmc_match[] __initconst = { 2788 { .compatible = "nvidia,tegra210-pmc" }, 2789 { }, 2790 }; 2791 2792 static struct tegra_clk_init_table init_table[] __initdata = { 2793 { TEGRA210_CLK_UARTA, TEGRA210_CLK_PLL_P, 408000000, 0 }, 2794 { TEGRA210_CLK_UARTB, TEGRA210_CLK_PLL_P, 408000000, 0 }, 2795 { TEGRA210_CLK_UARTC, TEGRA210_CLK_PLL_P, 408000000, 0 }, 2796 { TEGRA210_CLK_UARTD, TEGRA210_CLK_PLL_P, 408000000, 0 }, 2797 { TEGRA210_CLK_PLL_A, TEGRA210_CLK_CLK_MAX, 564480000, 1 }, 2798 { TEGRA210_CLK_PLL_A_OUT0, TEGRA210_CLK_CLK_MAX, 11289600, 1 }, 2799 { TEGRA210_CLK_EXTERN1, TEGRA210_CLK_PLL_A_OUT0, 0, 1 }, 2800 { TEGRA210_CLK_CLK_OUT_1_MUX, TEGRA210_CLK_EXTERN1, 0, 1 }, 2801 { TEGRA210_CLK_CLK_OUT_1, TEGRA210_CLK_CLK_MAX, 0, 1 }, 2802 { TEGRA210_CLK_I2S0, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, 2803 { TEGRA210_CLK_I2S1, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, 2804 { TEGRA210_CLK_I2S2, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, 2805 { TEGRA210_CLK_I2S3, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, 2806 { TEGRA210_CLK_I2S4, TEGRA210_CLK_PLL_A_OUT0, 11289600, 0 }, 2807 { TEGRA210_CLK_HOST1X, TEGRA210_CLK_PLL_P, 136000000, 1 }, 2808 { TEGRA210_CLK_SCLK_MUX, TEGRA210_CLK_PLL_P, 0, 1 }, 2809 { TEGRA210_CLK_SCLK, TEGRA210_CLK_CLK_MAX, 102000000, 1 }, 2810 { TEGRA210_CLK_DFLL_SOC, TEGRA210_CLK_PLL_P, 51000000, 1 }, 2811 { TEGRA210_CLK_DFLL_REF, TEGRA210_CLK_PLL_P, 51000000, 1 }, 2812 { TEGRA210_CLK_SBC4, TEGRA210_CLK_PLL_P, 12000000, 1 }, 2813 { TEGRA210_CLK_PLL_RE_VCO, TEGRA210_CLK_CLK_MAX, 672000000, 1 }, 2814 { TEGRA210_CLK_XUSB_GATE, TEGRA210_CLK_CLK_MAX, 0, 1 }, 2815 { TEGRA210_CLK_XUSB_SS_SRC, TEGRA210_CLK_PLL_U_480M, 120000000, 0 }, 2816 { TEGRA210_CLK_XUSB_FS_SRC, TEGRA210_CLK_PLL_U_48M, 48000000, 0 }, 2817 { TEGRA210_CLK_XUSB_HS_SRC, TEGRA210_CLK_XUSB_SS_SRC, 120000000, 0 }, 2818 { TEGRA210_CLK_XUSB_SSP_SRC, TEGRA210_CLK_XUSB_SS_SRC, 120000000, 0 }, 2819 { TEGRA210_CLK_XUSB_FALCON_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 204000000, 0 }, 2820 { TEGRA210_CLK_XUSB_HOST_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 }, 2821 { TEGRA210_CLK_XUSB_DEV_SRC, TEGRA210_CLK_PLL_P_OUT_XUSB, 102000000, 0 }, 2822 { TEGRA210_CLK_SATA, TEGRA210_CLK_PLL_P, 104000000, 0 }, 2823 { TEGRA210_CLK_SATA_OOB, TEGRA210_CLK_PLL_P, 204000000, 0 }, 2824 { TEGRA210_CLK_EMC, TEGRA210_CLK_CLK_MAX, 0, 1 }, 2825 { TEGRA210_CLK_MSELECT, TEGRA210_CLK_CLK_MAX, 0, 1 }, 2826 { TEGRA210_CLK_CSITE, TEGRA210_CLK_CLK_MAX, 0, 1 }, 2827 { TEGRA210_CLK_TSENSOR, TEGRA210_CLK_CLK_M, 400000, 0 }, 2828 { TEGRA210_CLK_I2C1, TEGRA210_CLK_PLL_P, 0, 0 }, 2829 { TEGRA210_CLK_I2C2, TEGRA210_CLK_PLL_P, 0, 0 }, 2830 { TEGRA210_CLK_I2C3, TEGRA210_CLK_PLL_P, 0, 0 }, 2831 { TEGRA210_CLK_I2C4, TEGRA210_CLK_PLL_P, 0, 0 }, 2832 { TEGRA210_CLK_I2C5, TEGRA210_CLK_PLL_P, 0, 0 }, 2833 { TEGRA210_CLK_I2C6, TEGRA210_CLK_PLL_P, 0, 0 }, 2834 { TEGRA210_CLK_PLL_DP, TEGRA210_CLK_CLK_MAX, 270000000, 0 }, 2835 { TEGRA210_CLK_SOC_THERM, TEGRA210_CLK_PLL_P, 51000000, 0 }, 2836 { TEGRA210_CLK_CCLK_G, TEGRA210_CLK_CLK_MAX, 0, 1 }, 2837 /* This MUST be the last entry. */ 2838 { TEGRA210_CLK_CLK_MAX, TEGRA210_CLK_CLK_MAX, 0, 0 }, 2839 }; 2840 2841 /** 2842 * tegra210_clock_apply_init_table - initialize clocks on Tegra210 SoCs 2843 * 2844 * Program an initial clock rate and enable or disable clocks needed 2845 * by the rest of the kernel, for Tegra210 SoCs. It is intended to be 2846 * called by assigning a pointer to it to tegra_clk_apply_init_table - 2847 * this will be called as an arch_initcall. No return value. 2848 */ 2849 static void __init tegra210_clock_apply_init_table(void) 2850 { 2851 tegra_init_from_table(init_table, clks, TEGRA210_CLK_CLK_MAX); 2852 } 2853 2854 /** 2855 * tegra210_clock_init - Tegra210-specific clock initialization 2856 * @np: struct device_node * of the DT node for the SoC CAR IP block 2857 * 2858 * Register most SoC clocks for the Tegra210 system-on-chip. Intended 2859 * to be called by the OF init code when a DT node with the 2860 * "nvidia,tegra210-car" string is encountered, and declared with 2861 * CLK_OF_DECLARE. No return value. 2862 */ 2863 static void __init tegra210_clock_init(struct device_node *np) 2864 { 2865 struct device_node *node; 2866 u32 value, clk_m_div; 2867 2868 clk_base = of_iomap(np, 0); 2869 if (!clk_base) { 2870 pr_err("ioremap tegra210 CAR failed\n"); 2871 return; 2872 } 2873 2874 node = of_find_matching_node(NULL, pmc_match); 2875 if (!node) { 2876 pr_err("Failed to find pmc node\n"); 2877 WARN_ON(1); 2878 return; 2879 } 2880 2881 pmc_base = of_iomap(node, 0); 2882 if (!pmc_base) { 2883 pr_err("Can't map pmc registers\n"); 2884 WARN_ON(1); 2885 return; 2886 } 2887 2888 clks = tegra_clk_init(clk_base, TEGRA210_CLK_CLK_MAX, 2889 TEGRA210_CAR_BANK_COUNT); 2890 if (!clks) 2891 return; 2892 2893 value = clk_readl(clk_base + SPARE_REG0) >> CLK_M_DIVISOR_SHIFT; 2894 clk_m_div = (value & CLK_M_DIVISOR_MASK) + 1; 2895 2896 if (tegra_osc_clk_init(clk_base, tegra210_clks, tegra210_input_freq, 2897 ARRAY_SIZE(tegra210_input_freq), clk_m_div, 2898 &osc_freq, &pll_ref_freq) < 0) 2899 return; 2900 2901 tegra_fixed_clk_init(tegra210_clks); 2902 tegra210_pll_init(clk_base, pmc_base); 2903 tegra210_periph_clk_init(clk_base, pmc_base); 2904 tegra_audio_clk_init(clk_base, pmc_base, tegra210_clks, 2905 tegra210_audio_plls, 2906 ARRAY_SIZE(tegra210_audio_plls)); 2907 tegra_pmc_clk_init(pmc_base, tegra210_clks); 2908 2909 /* For Tegra210, PLLD is the only source for DSIA & DSIB */ 2910 value = clk_readl(clk_base + PLLD_BASE); 2911 value &= ~BIT(25); 2912 clk_writel(value, clk_base + PLLD_BASE); 2913 2914 tegra_clk_apply_init_table = tegra210_clock_apply_init_table; 2915 2916 tegra_super_clk_gen5_init(clk_base, pmc_base, tegra210_clks, 2917 &pll_x_params); 2918 tegra_add_of_provider(np); 2919 tegra_register_devclks(devclks, ARRAY_SIZE(devclks)); 2920 2921 tegra_cpu_car_ops = &tegra210_cpu_car_ops; 2922 } 2923 CLK_OF_DECLARE(tegra210, "nvidia,tegra210-car", tegra210_clock_init); 2924