Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/mach-tegra/tegra30_clocks.c |
| 3 | * |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 4 | * Copyright (c) 2010-2012 NVIDIA CORPORATION. All rights reserved. |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/list.h> |
| 24 | #include <linux/spinlock.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/err.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/clk.h> |
| 29 | #include <linux/cpufreq.h> |
| 30 | #include <linux/syscore_ops.h> |
| 31 | |
| 32 | #include <asm/clkdev.h> |
| 33 | |
Joseph Lo | a6e293e | 2012-10-31 17:41:19 +0800 | [diff] [blame^] | 34 | #include <mach/powergate.h> |
| 35 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 36 | #include "clock.h" |
| 37 | #include "fuse.h" |
Stephen Warren | 2be39c0 | 2012-10-04 14:24:09 -0600 | [diff] [blame] | 38 | #include "iomap.h" |
Joseph Lo | dab403e | 2012-08-16 17:31:48 +0800 | [diff] [blame] | 39 | #include "tegra_cpu_car.h" |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 40 | |
| 41 | #define USE_PLL_LOCK_BITS 0 |
| 42 | |
| 43 | #define RST_DEVICES_L 0x004 |
| 44 | #define RST_DEVICES_H 0x008 |
| 45 | #define RST_DEVICES_U 0x00C |
| 46 | #define RST_DEVICES_V 0x358 |
| 47 | #define RST_DEVICES_W 0x35C |
| 48 | #define RST_DEVICES_SET_L 0x300 |
| 49 | #define RST_DEVICES_CLR_L 0x304 |
| 50 | #define RST_DEVICES_SET_V 0x430 |
| 51 | #define RST_DEVICES_CLR_V 0x434 |
| 52 | #define RST_DEVICES_NUM 5 |
| 53 | |
| 54 | #define CLK_OUT_ENB_L 0x010 |
| 55 | #define CLK_OUT_ENB_H 0x014 |
| 56 | #define CLK_OUT_ENB_U 0x018 |
| 57 | #define CLK_OUT_ENB_V 0x360 |
| 58 | #define CLK_OUT_ENB_W 0x364 |
| 59 | #define CLK_OUT_ENB_SET_L 0x320 |
| 60 | #define CLK_OUT_ENB_CLR_L 0x324 |
| 61 | #define CLK_OUT_ENB_SET_V 0x440 |
| 62 | #define CLK_OUT_ENB_CLR_V 0x444 |
| 63 | #define CLK_OUT_ENB_NUM 5 |
| 64 | |
| 65 | #define RST_DEVICES_V_SWR_CPULP_RST_DIS (0x1 << 1) |
| 66 | #define CLK_OUT_ENB_V_CLK_ENB_CPULP_EN (0x1 << 1) |
| 67 | |
| 68 | #define PERIPH_CLK_TO_BIT(c) (1 << (c->u.periph.clk_num % 32)) |
| 69 | #define PERIPH_CLK_TO_RST_REG(c) \ |
| 70 | periph_clk_to_reg((c), RST_DEVICES_L, RST_DEVICES_V, 4) |
| 71 | #define PERIPH_CLK_TO_RST_SET_REG(c) \ |
| 72 | periph_clk_to_reg((c), RST_DEVICES_SET_L, RST_DEVICES_SET_V, 8) |
| 73 | #define PERIPH_CLK_TO_RST_CLR_REG(c) \ |
| 74 | periph_clk_to_reg((c), RST_DEVICES_CLR_L, RST_DEVICES_CLR_V, 8) |
| 75 | |
| 76 | #define PERIPH_CLK_TO_ENB_REG(c) \ |
| 77 | periph_clk_to_reg((c), CLK_OUT_ENB_L, CLK_OUT_ENB_V, 4) |
| 78 | #define PERIPH_CLK_TO_ENB_SET_REG(c) \ |
| 79 | periph_clk_to_reg((c), CLK_OUT_ENB_SET_L, CLK_OUT_ENB_SET_V, 8) |
| 80 | #define PERIPH_CLK_TO_ENB_CLR_REG(c) \ |
| 81 | periph_clk_to_reg((c), CLK_OUT_ENB_CLR_L, CLK_OUT_ENB_CLR_V, 8) |
| 82 | |
| 83 | #define CLK_MASK_ARM 0x44 |
| 84 | #define MISC_CLK_ENB 0x48 |
| 85 | |
| 86 | #define OSC_CTRL 0x50 |
| 87 | #define OSC_CTRL_OSC_FREQ_MASK (0xF<<28) |
| 88 | #define OSC_CTRL_OSC_FREQ_13MHZ (0x0<<28) |
| 89 | #define OSC_CTRL_OSC_FREQ_19_2MHZ (0x4<<28) |
| 90 | #define OSC_CTRL_OSC_FREQ_12MHZ (0x8<<28) |
| 91 | #define OSC_CTRL_OSC_FREQ_26MHZ (0xC<<28) |
| 92 | #define OSC_CTRL_OSC_FREQ_16_8MHZ (0x1<<28) |
| 93 | #define OSC_CTRL_OSC_FREQ_38_4MHZ (0x5<<28) |
| 94 | #define OSC_CTRL_OSC_FREQ_48MHZ (0x9<<28) |
| 95 | #define OSC_CTRL_MASK (0x3f2 | OSC_CTRL_OSC_FREQ_MASK) |
| 96 | |
| 97 | #define OSC_CTRL_PLL_REF_DIV_MASK (3<<26) |
| 98 | #define OSC_CTRL_PLL_REF_DIV_1 (0<<26) |
| 99 | #define OSC_CTRL_PLL_REF_DIV_2 (1<<26) |
| 100 | #define OSC_CTRL_PLL_REF_DIV_4 (2<<26) |
| 101 | |
| 102 | #define OSC_FREQ_DET 0x58 |
| 103 | #define OSC_FREQ_DET_TRIG (1<<31) |
| 104 | |
| 105 | #define OSC_FREQ_DET_STATUS 0x5C |
| 106 | #define OSC_FREQ_DET_BUSY (1<<31) |
| 107 | #define OSC_FREQ_DET_CNT_MASK 0xFFFF |
| 108 | |
| 109 | #define PERIPH_CLK_SOURCE_I2S1 0x100 |
| 110 | #define PERIPH_CLK_SOURCE_EMC 0x19c |
| 111 | #define PERIPH_CLK_SOURCE_OSC 0x1fc |
| 112 | #define PERIPH_CLK_SOURCE_NUM1 \ |
| 113 | ((PERIPH_CLK_SOURCE_OSC - PERIPH_CLK_SOURCE_I2S1) / 4) |
| 114 | |
| 115 | #define PERIPH_CLK_SOURCE_G3D2 0x3b0 |
| 116 | #define PERIPH_CLK_SOURCE_SE 0x42c |
| 117 | #define PERIPH_CLK_SOURCE_NUM2 \ |
| 118 | ((PERIPH_CLK_SOURCE_SE - PERIPH_CLK_SOURCE_G3D2) / 4 + 1) |
| 119 | |
| 120 | #define AUDIO_DLY_CLK 0x49c |
| 121 | #define AUDIO_SYNC_CLK_SPDIF 0x4b4 |
| 122 | #define PERIPH_CLK_SOURCE_NUM3 \ |
| 123 | ((AUDIO_SYNC_CLK_SPDIF - AUDIO_DLY_CLK) / 4 + 1) |
| 124 | |
| 125 | #define PERIPH_CLK_SOURCE_NUM (PERIPH_CLK_SOURCE_NUM1 + \ |
| 126 | PERIPH_CLK_SOURCE_NUM2 + \ |
| 127 | PERIPH_CLK_SOURCE_NUM3) |
| 128 | |
| 129 | #define CPU_SOFTRST_CTRL 0x380 |
| 130 | |
| 131 | #define PERIPH_CLK_SOURCE_DIVU71_MASK 0xFF |
| 132 | #define PERIPH_CLK_SOURCE_DIVU16_MASK 0xFFFF |
| 133 | #define PERIPH_CLK_SOURCE_DIV_SHIFT 0 |
| 134 | #define PERIPH_CLK_SOURCE_DIVIDLE_SHIFT 8 |
| 135 | #define PERIPH_CLK_SOURCE_DIVIDLE_VAL 50 |
| 136 | #define PERIPH_CLK_UART_DIV_ENB (1<<24) |
| 137 | #define PERIPH_CLK_VI_SEL_EX_SHIFT 24 |
| 138 | #define PERIPH_CLK_VI_SEL_EX_MASK (0x3<<PERIPH_CLK_VI_SEL_EX_SHIFT) |
| 139 | #define PERIPH_CLK_NAND_DIV_EX_ENB (1<<8) |
| 140 | #define PERIPH_CLK_DTV_POLARITY_INV (1<<25) |
| 141 | |
| 142 | #define AUDIO_SYNC_SOURCE_MASK 0x0F |
| 143 | #define AUDIO_SYNC_DISABLE_BIT 0x10 |
| 144 | #define AUDIO_SYNC_TAP_NIBBLE_SHIFT(c) ((c->reg_shift - 24) * 4) |
| 145 | |
| 146 | #define PLL_BASE 0x0 |
| 147 | #define PLL_BASE_BYPASS (1<<31) |
| 148 | #define PLL_BASE_ENABLE (1<<30) |
| 149 | #define PLL_BASE_REF_ENABLE (1<<29) |
| 150 | #define PLL_BASE_OVERRIDE (1<<28) |
| 151 | #define PLL_BASE_LOCK (1<<27) |
| 152 | #define PLL_BASE_DIVP_MASK (0x7<<20) |
| 153 | #define PLL_BASE_DIVP_SHIFT 20 |
| 154 | #define PLL_BASE_DIVN_MASK (0x3FF<<8) |
| 155 | #define PLL_BASE_DIVN_SHIFT 8 |
| 156 | #define PLL_BASE_DIVM_MASK (0x1F) |
| 157 | #define PLL_BASE_DIVM_SHIFT 0 |
| 158 | |
| 159 | #define PLL_OUT_RATIO_MASK (0xFF<<8) |
| 160 | #define PLL_OUT_RATIO_SHIFT 8 |
| 161 | #define PLL_OUT_OVERRIDE (1<<2) |
| 162 | #define PLL_OUT_CLKEN (1<<1) |
| 163 | #define PLL_OUT_RESET_DISABLE (1<<0) |
| 164 | |
| 165 | #define PLL_MISC(c) \ |
| 166 | (((c)->flags & PLL_ALT_MISC_REG) ? 0x4 : 0xc) |
| 167 | #define PLL_MISC_LOCK_ENABLE(c) \ |
| 168 | (((c)->flags & (PLLU | PLLD)) ? (1<<22) : (1<<18)) |
| 169 | |
| 170 | #define PLL_MISC_DCCON_SHIFT 20 |
| 171 | #define PLL_MISC_CPCON_SHIFT 8 |
| 172 | #define PLL_MISC_CPCON_MASK (0xF<<PLL_MISC_CPCON_SHIFT) |
| 173 | #define PLL_MISC_LFCON_SHIFT 4 |
| 174 | #define PLL_MISC_LFCON_MASK (0xF<<PLL_MISC_LFCON_SHIFT) |
| 175 | #define PLL_MISC_VCOCON_SHIFT 0 |
| 176 | #define PLL_MISC_VCOCON_MASK (0xF<<PLL_MISC_VCOCON_SHIFT) |
| 177 | #define PLLD_MISC_CLKENABLE (1<<30) |
| 178 | |
| 179 | #define PLLU_BASE_POST_DIV (1<<20) |
| 180 | |
| 181 | #define PLLD_BASE_DSIB_MUX_SHIFT 25 |
| 182 | #define PLLD_BASE_DSIB_MUX_MASK (1<<PLLD_BASE_DSIB_MUX_SHIFT) |
| 183 | #define PLLD_BASE_CSI_CLKENABLE (1<<26) |
| 184 | #define PLLD_MISC_DSI_CLKENABLE (1<<30) |
| 185 | #define PLLD_MISC_DIV_RST (1<<23) |
| 186 | #define PLLD_MISC_DCCON_SHIFT 12 |
| 187 | |
| 188 | #define PLLDU_LFCON_SET_DIVN 600 |
| 189 | |
| 190 | /* FIXME: OUT_OF_TABLE_CPCON per pll */ |
| 191 | #define OUT_OF_TABLE_CPCON 0x8 |
| 192 | |
| 193 | #define SUPER_CLK_MUX 0x00 |
| 194 | #define SUPER_STATE_SHIFT 28 |
| 195 | #define SUPER_STATE_MASK (0xF << SUPER_STATE_SHIFT) |
| 196 | #define SUPER_STATE_STANDBY (0x0 << SUPER_STATE_SHIFT) |
| 197 | #define SUPER_STATE_IDLE (0x1 << SUPER_STATE_SHIFT) |
| 198 | #define SUPER_STATE_RUN (0x2 << SUPER_STATE_SHIFT) |
| 199 | #define SUPER_STATE_IRQ (0x3 << SUPER_STATE_SHIFT) |
| 200 | #define SUPER_STATE_FIQ (0x4 << SUPER_STATE_SHIFT) |
| 201 | #define SUPER_LP_DIV2_BYPASS (0x1 << 16) |
| 202 | #define SUPER_SOURCE_MASK 0xF |
| 203 | #define SUPER_FIQ_SOURCE_SHIFT 12 |
| 204 | #define SUPER_IRQ_SOURCE_SHIFT 8 |
| 205 | #define SUPER_RUN_SOURCE_SHIFT 4 |
| 206 | #define SUPER_IDLE_SOURCE_SHIFT 0 |
| 207 | |
| 208 | #define SUPER_CLK_DIVIDER 0x04 |
| 209 | #define SUPER_CLOCK_DIV_U71_SHIFT 16 |
| 210 | #define SUPER_CLOCK_DIV_U71_MASK (0xff << SUPER_CLOCK_DIV_U71_SHIFT) |
| 211 | /* guarantees safe cpu backup */ |
| 212 | #define SUPER_CLOCK_DIV_U71_MIN 0x2 |
| 213 | |
| 214 | #define BUS_CLK_DISABLE (1<<3) |
| 215 | #define BUS_CLK_DIV_MASK 0x3 |
| 216 | |
| 217 | #define PMC_CTRL 0x0 |
| 218 | #define PMC_CTRL_BLINK_ENB (1 << 7) |
| 219 | |
| 220 | #define PMC_DPD_PADS_ORIDE 0x1c |
| 221 | #define PMC_DPD_PADS_ORIDE_BLINK_ENB (1 << 20) |
| 222 | |
| 223 | #define PMC_BLINK_TIMER_DATA_ON_SHIFT 0 |
| 224 | #define PMC_BLINK_TIMER_DATA_ON_MASK 0x7fff |
| 225 | #define PMC_BLINK_TIMER_ENB (1 << 15) |
| 226 | #define PMC_BLINK_TIMER_DATA_OFF_SHIFT 16 |
| 227 | #define PMC_BLINK_TIMER_DATA_OFF_MASK 0xffff |
| 228 | |
| 229 | #define PMC_PLLP_WB0_OVERRIDE 0xf8 |
| 230 | #define PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE (1 << 12) |
| 231 | |
| 232 | #define UTMIP_PLL_CFG2 0x488 |
| 233 | #define UTMIP_PLL_CFG2_STABLE_COUNT(x) (((x) & 0xfff) << 6) |
| 234 | #define UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(x) (((x) & 0x3f) << 18) |
| 235 | #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN (1 << 0) |
| 236 | #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN (1 << 2) |
| 237 | #define UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN (1 << 4) |
| 238 | |
| 239 | #define UTMIP_PLL_CFG1 0x484 |
| 240 | #define UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(x) (((x) & 0x1f) << 27) |
| 241 | #define UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(x) (((x) & 0xfff) << 0) |
| 242 | #define UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN (1 << 14) |
| 243 | #define UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN (1 << 12) |
| 244 | #define UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN (1 << 16) |
| 245 | |
| 246 | #define PLLE_BASE_CML_ENABLE (1<<31) |
| 247 | #define PLLE_BASE_ENABLE (1<<30) |
| 248 | #define PLLE_BASE_DIVCML_SHIFT 24 |
| 249 | #define PLLE_BASE_DIVCML_MASK (0xf<<PLLE_BASE_DIVCML_SHIFT) |
| 250 | #define PLLE_BASE_DIVP_SHIFT 16 |
| 251 | #define PLLE_BASE_DIVP_MASK (0x3f<<PLLE_BASE_DIVP_SHIFT) |
| 252 | #define PLLE_BASE_DIVN_SHIFT 8 |
| 253 | #define PLLE_BASE_DIVN_MASK (0xFF<<PLLE_BASE_DIVN_SHIFT) |
| 254 | #define PLLE_BASE_DIVM_SHIFT 0 |
| 255 | #define PLLE_BASE_DIVM_MASK (0xFF<<PLLE_BASE_DIVM_SHIFT) |
| 256 | #define PLLE_BASE_DIV_MASK \ |
| 257 | (PLLE_BASE_DIVCML_MASK | PLLE_BASE_DIVP_MASK | \ |
| 258 | PLLE_BASE_DIVN_MASK | PLLE_BASE_DIVM_MASK) |
| 259 | #define PLLE_BASE_DIV(m, n, p, cml) \ |
| 260 | (((cml)<<PLLE_BASE_DIVCML_SHIFT) | ((p)<<PLLE_BASE_DIVP_SHIFT) | \ |
| 261 | ((n)<<PLLE_BASE_DIVN_SHIFT) | ((m)<<PLLE_BASE_DIVM_SHIFT)) |
| 262 | |
| 263 | #define PLLE_MISC_SETUP_BASE_SHIFT 16 |
| 264 | #define PLLE_MISC_SETUP_BASE_MASK (0xFFFF<<PLLE_MISC_SETUP_BASE_SHIFT) |
| 265 | #define PLLE_MISC_READY (1<<15) |
| 266 | #define PLLE_MISC_LOCK (1<<11) |
| 267 | #define PLLE_MISC_LOCK_ENABLE (1<<9) |
| 268 | #define PLLE_MISC_SETUP_EX_SHIFT 2 |
| 269 | #define PLLE_MISC_SETUP_EX_MASK (0x3<<PLLE_MISC_SETUP_EX_SHIFT) |
| 270 | #define PLLE_MISC_SETUP_MASK \ |
| 271 | (PLLE_MISC_SETUP_BASE_MASK | PLLE_MISC_SETUP_EX_MASK) |
| 272 | #define PLLE_MISC_SETUP_VALUE \ |
| 273 | ((0x7<<PLLE_MISC_SETUP_BASE_SHIFT) | (0x0<<PLLE_MISC_SETUP_EX_SHIFT)) |
| 274 | |
| 275 | #define PLLE_SS_CTRL 0x68 |
| 276 | #define PLLE_SS_INCINTRV_SHIFT 24 |
| 277 | #define PLLE_SS_INCINTRV_MASK (0x3f<<PLLE_SS_INCINTRV_SHIFT) |
| 278 | #define PLLE_SS_INC_SHIFT 16 |
| 279 | #define PLLE_SS_INC_MASK (0xff<<PLLE_SS_INC_SHIFT) |
| 280 | #define PLLE_SS_MAX_SHIFT 0 |
| 281 | #define PLLE_SS_MAX_MASK (0x1ff<<PLLE_SS_MAX_SHIFT) |
| 282 | #define PLLE_SS_COEFFICIENTS_MASK \ |
| 283 | (PLLE_SS_INCINTRV_MASK | PLLE_SS_INC_MASK | PLLE_SS_MAX_MASK) |
| 284 | #define PLLE_SS_COEFFICIENTS_12MHZ \ |
| 285 | ((0x18<<PLLE_SS_INCINTRV_SHIFT) | (0x1<<PLLE_SS_INC_SHIFT) | \ |
| 286 | (0x24<<PLLE_SS_MAX_SHIFT)) |
| 287 | #define PLLE_SS_DISABLE ((1<<12) | (1<<11) | (1<<10)) |
| 288 | |
| 289 | #define PLLE_AUX 0x48c |
| 290 | #define PLLE_AUX_PLLP_SEL (1<<2) |
| 291 | #define PLLE_AUX_CML_SATA_ENABLE (1<<1) |
| 292 | #define PLLE_AUX_CML_PCIE_ENABLE (1<<0) |
| 293 | |
| 294 | #define PMC_SATA_PWRGT 0x1ac |
| 295 | #define PMC_SATA_PWRGT_PLLE_IDDQ_VALUE (1<<5) |
| 296 | #define PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL (1<<4) |
| 297 | |
| 298 | #define ROUND_DIVIDER_UP 0 |
| 299 | #define ROUND_DIVIDER_DOWN 1 |
| 300 | |
| 301 | /* FIXME: recommended safety delay after lock is detected */ |
| 302 | #define PLL_POST_LOCK_DELAY 100 |
| 303 | |
Joseph Lo | dab403e | 2012-08-16 17:31:48 +0800 | [diff] [blame] | 304 | /* Tegra CPU clock and reset control regs */ |
| 305 | #define TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX 0x4c |
| 306 | #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET 0x340 |
| 307 | #define TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR 0x344 |
| 308 | #define TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR 0x34c |
| 309 | #define TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS 0x470 |
| 310 | |
| 311 | #define CPU_CLOCK(cpu) (0x1 << (8 + cpu)) |
| 312 | #define CPU_RESET(cpu) (0x1111ul << (cpu)) |
| 313 | |
Joseph Lo | a6e293e | 2012-10-31 17:41:19 +0800 | [diff] [blame^] | 314 | #define CLK_RESET_CCLK_BURST 0x20 |
| 315 | #define CLK_RESET_CCLK_DIVIDER 0x24 |
| 316 | #define CLK_RESET_PLLX_BASE 0xe0 |
| 317 | #define CLK_RESET_PLLX_MISC 0xe4 |
| 318 | |
| 319 | #define CLK_RESET_SOURCE_CSITE 0x1d4 |
| 320 | |
| 321 | #define CLK_RESET_CCLK_BURST_POLICY_SHIFT 28 |
| 322 | #define CLK_RESET_CCLK_RUN_POLICY_SHIFT 4 |
| 323 | #define CLK_RESET_CCLK_IDLE_POLICY_SHIFT 0 |
| 324 | #define CLK_RESET_CCLK_IDLE_POLICY 1 |
| 325 | #define CLK_RESET_CCLK_RUN_POLICY 2 |
| 326 | #define CLK_RESET_CCLK_BURST_POLICY_PLLX 8 |
| 327 | |
| 328 | #ifdef CONFIG_PM_SLEEP |
| 329 | static struct cpu_clk_suspend_context { |
| 330 | u32 pllx_misc; |
| 331 | u32 pllx_base; |
| 332 | |
| 333 | u32 cpu_burst; |
| 334 | u32 clk_csite_src; |
| 335 | u32 cclk_divider; |
| 336 | } tegra30_cpu_clk_sctx; |
| 337 | #endif |
| 338 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 339 | /** |
| 340 | * Structure defining the fields for USB UTMI clocks Parameters. |
| 341 | */ |
| 342 | struct utmi_clk_param { |
| 343 | /* Oscillator Frequency in KHz */ |
| 344 | u32 osc_frequency; |
| 345 | /* UTMIP PLL Enable Delay Count */ |
| 346 | u8 enable_delay_count; |
| 347 | /* UTMIP PLL Stable count */ |
| 348 | u8 stable_count; |
| 349 | /* UTMIP PLL Active delay count */ |
| 350 | u8 active_delay_count; |
| 351 | /* UTMIP PLL Xtal frequency count */ |
| 352 | u8 xtal_freq_count; |
| 353 | }; |
| 354 | |
| 355 | static const struct utmi_clk_param utmi_parameters[] = { |
| 356 | { |
| 357 | .osc_frequency = 13000000, |
| 358 | .enable_delay_count = 0x02, |
| 359 | .stable_count = 0x33, |
| 360 | .active_delay_count = 0x05, |
| 361 | .xtal_freq_count = 0x7F |
| 362 | }, |
| 363 | { |
| 364 | .osc_frequency = 19200000, |
| 365 | .enable_delay_count = 0x03, |
| 366 | .stable_count = 0x4B, |
| 367 | .active_delay_count = 0x06, |
| 368 | .xtal_freq_count = 0xBB}, |
| 369 | { |
| 370 | .osc_frequency = 12000000, |
| 371 | .enable_delay_count = 0x02, |
| 372 | .stable_count = 0x2F, |
| 373 | .active_delay_count = 0x04, |
| 374 | .xtal_freq_count = 0x76 |
| 375 | }, |
| 376 | { |
| 377 | .osc_frequency = 26000000, |
| 378 | .enable_delay_count = 0x04, |
| 379 | .stable_count = 0x66, |
| 380 | .active_delay_count = 0x09, |
| 381 | .xtal_freq_count = 0xFE |
| 382 | }, |
| 383 | { |
| 384 | .osc_frequency = 16800000, |
| 385 | .enable_delay_count = 0x03, |
| 386 | .stable_count = 0x41, |
| 387 | .active_delay_count = 0x0A, |
| 388 | .xtal_freq_count = 0xA4 |
| 389 | }, |
| 390 | }; |
| 391 | |
| 392 | static void __iomem *reg_clk_base = IO_ADDRESS(TEGRA_CLK_RESET_BASE); |
| 393 | static void __iomem *reg_pmc_base = IO_ADDRESS(TEGRA_PMC_BASE); |
| 394 | static void __iomem *misc_gp_hidrev_base = IO_ADDRESS(TEGRA_APB_MISC_BASE); |
| 395 | |
| 396 | #define MISC_GP_HIDREV 0x804 |
| 397 | |
| 398 | /* |
| 399 | * Some peripheral clocks share an enable bit, so refcount the enable bits |
| 400 | * in registers CLK_ENABLE_L, ... CLK_ENABLE_W |
| 401 | */ |
| 402 | static int tegra_periph_clk_enable_refcount[CLK_OUT_ENB_NUM * 32]; |
| 403 | |
| 404 | #define clk_writel(value, reg) \ |
Prashant Gaikwad | fa67ccb | 2012-09-07 11:10:55 +0530 | [diff] [blame] | 405 | __raw_writel(value, reg_clk_base + (reg)) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 406 | #define clk_readl(reg) \ |
Prashant Gaikwad | fa67ccb | 2012-09-07 11:10:55 +0530 | [diff] [blame] | 407 | __raw_readl(reg_clk_base + (reg)) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 408 | #define pmc_writel(value, reg) \ |
Prashant Gaikwad | fa67ccb | 2012-09-07 11:10:55 +0530 | [diff] [blame] | 409 | __raw_writel(value, reg_pmc_base + (reg)) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 410 | #define pmc_readl(reg) \ |
Prashant Gaikwad | fa67ccb | 2012-09-07 11:10:55 +0530 | [diff] [blame] | 411 | __raw_readl(reg_pmc_base + (reg)) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 412 | #define chipid_readl() \ |
Prashant Gaikwad | fa67ccb | 2012-09-07 11:10:55 +0530 | [diff] [blame] | 413 | __raw_readl(misc_gp_hidrev_base + MISC_GP_HIDREV) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 414 | |
| 415 | #define clk_writel_delay(value, reg) \ |
| 416 | do { \ |
Prashant Gaikwad | fa67ccb | 2012-09-07 11:10:55 +0530 | [diff] [blame] | 417 | __raw_writel((value), reg_clk_base + (reg)); \ |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 418 | udelay(2); \ |
| 419 | } while (0) |
| 420 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 421 | static inline int clk_set_div(struct clk_tegra *c, u32 n) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 422 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 423 | struct clk *clk = c->hw.clk; |
| 424 | |
| 425 | return clk_set_rate(clk, |
| 426 | (__clk_get_rate(__clk_get_parent(clk)) + n - 1) / n); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static inline u32 periph_clk_to_reg( |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 430 | struct clk_tegra *c, u32 reg_L, u32 reg_V, int offs) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 431 | { |
| 432 | u32 reg = c->u.periph.clk_num / 32; |
| 433 | BUG_ON(reg >= RST_DEVICES_NUM); |
| 434 | if (reg < 3) |
| 435 | reg = reg_L + (reg * offs); |
| 436 | else |
| 437 | reg = reg_V + ((reg - 3) * offs); |
| 438 | return reg; |
| 439 | } |
| 440 | |
| 441 | static unsigned long clk_measure_input_freq(void) |
| 442 | { |
| 443 | u32 clock_autodetect; |
| 444 | clk_writel(OSC_FREQ_DET_TRIG | 1, OSC_FREQ_DET); |
| 445 | do {} while (clk_readl(OSC_FREQ_DET_STATUS) & OSC_FREQ_DET_BUSY); |
| 446 | clock_autodetect = clk_readl(OSC_FREQ_DET_STATUS); |
| 447 | if (clock_autodetect >= 732 - 3 && clock_autodetect <= 732 + 3) { |
| 448 | return 12000000; |
| 449 | } else if (clock_autodetect >= 794 - 3 && clock_autodetect <= 794 + 3) { |
| 450 | return 13000000; |
| 451 | } else if (clock_autodetect >= 1172 - 3 && clock_autodetect <= 1172 + 3) { |
| 452 | return 19200000; |
| 453 | } else if (clock_autodetect >= 1587 - 3 && clock_autodetect <= 1587 + 3) { |
| 454 | return 26000000; |
| 455 | } else if (clock_autodetect >= 1025 - 3 && clock_autodetect <= 1025 + 3) { |
| 456 | return 16800000; |
| 457 | } else if (clock_autodetect >= 2344 - 3 && clock_autodetect <= 2344 + 3) { |
| 458 | return 38400000; |
| 459 | } else if (clock_autodetect >= 2928 - 3 && clock_autodetect <= 2928 + 3) { |
| 460 | return 48000000; |
| 461 | } else { |
| 462 | pr_err("%s: Unexpected clock autodetect value %d", __func__, |
| 463 | clock_autodetect); |
| 464 | BUG(); |
| 465 | return 0; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | static int clk_div71_get_divider(unsigned long parent_rate, unsigned long rate, |
| 470 | u32 flags, u32 round_mode) |
| 471 | { |
| 472 | s64 divider_u71 = parent_rate; |
| 473 | if (!rate) |
| 474 | return -EINVAL; |
| 475 | |
| 476 | if (!(flags & DIV_U71_INT)) |
| 477 | divider_u71 *= 2; |
| 478 | if (round_mode == ROUND_DIVIDER_UP) |
| 479 | divider_u71 += rate - 1; |
| 480 | do_div(divider_u71, rate); |
| 481 | if (flags & DIV_U71_INT) |
| 482 | divider_u71 *= 2; |
| 483 | |
| 484 | if (divider_u71 - 2 < 0) |
| 485 | return 0; |
| 486 | |
| 487 | if (divider_u71 - 2 > 255) |
| 488 | return -EINVAL; |
| 489 | |
| 490 | return divider_u71 - 2; |
| 491 | } |
| 492 | |
| 493 | static int clk_div16_get_divider(unsigned long parent_rate, unsigned long rate) |
| 494 | { |
| 495 | s64 divider_u16; |
| 496 | |
| 497 | divider_u16 = parent_rate; |
| 498 | if (!rate) |
| 499 | return -EINVAL; |
| 500 | divider_u16 += rate - 1; |
| 501 | do_div(divider_u16, rate); |
| 502 | |
| 503 | if (divider_u16 - 1 < 0) |
| 504 | return 0; |
| 505 | |
| 506 | if (divider_u16 - 1 > 0xFFFF) |
| 507 | return -EINVAL; |
| 508 | |
| 509 | return divider_u16 - 1; |
| 510 | } |
| 511 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 512 | static unsigned long tegra30_clk_fixed_recalc_rate(struct clk_hw *hw, |
| 513 | unsigned long parent_rate) |
| 514 | { |
| 515 | return to_clk_tegra(hw)->fixed_rate; |
| 516 | } |
| 517 | |
Joseph Lo | b78c030 | 2012-08-17 14:51:21 +0800 | [diff] [blame] | 518 | struct clk_ops tegra30_clk_32k_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 519 | .recalc_rate = tegra30_clk_fixed_recalc_rate, |
| 520 | }; |
| 521 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 522 | /* clk_m functions */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 523 | static unsigned long tegra30_clk_m_recalc_rate(struct clk_hw *hw, |
| 524 | unsigned long parent_rate) |
| 525 | { |
| 526 | if (!to_clk_tegra(hw)->fixed_rate) |
| 527 | to_clk_tegra(hw)->fixed_rate = clk_measure_input_freq(); |
| 528 | return to_clk_tegra(hw)->fixed_rate; |
| 529 | } |
| 530 | |
| 531 | static void tegra30_clk_m_init(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 532 | { |
| 533 | u32 osc_ctrl = clk_readl(OSC_CTRL); |
| 534 | u32 auto_clock_control = osc_ctrl & ~OSC_CTRL_OSC_FREQ_MASK; |
| 535 | u32 pll_ref_div = osc_ctrl & OSC_CTRL_PLL_REF_DIV_MASK; |
| 536 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 537 | switch (to_clk_tegra(hw)->fixed_rate) { |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 538 | case 12000000: |
| 539 | auto_clock_control |= OSC_CTRL_OSC_FREQ_12MHZ; |
| 540 | BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); |
| 541 | break; |
| 542 | case 13000000: |
| 543 | auto_clock_control |= OSC_CTRL_OSC_FREQ_13MHZ; |
| 544 | BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); |
| 545 | break; |
| 546 | case 19200000: |
| 547 | auto_clock_control |= OSC_CTRL_OSC_FREQ_19_2MHZ; |
| 548 | BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); |
| 549 | break; |
| 550 | case 26000000: |
| 551 | auto_clock_control |= OSC_CTRL_OSC_FREQ_26MHZ; |
| 552 | BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); |
| 553 | break; |
| 554 | case 16800000: |
| 555 | auto_clock_control |= OSC_CTRL_OSC_FREQ_16_8MHZ; |
| 556 | BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_1); |
| 557 | break; |
| 558 | case 38400000: |
| 559 | auto_clock_control |= OSC_CTRL_OSC_FREQ_38_4MHZ; |
| 560 | BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_2); |
| 561 | break; |
| 562 | case 48000000: |
| 563 | auto_clock_control |= OSC_CTRL_OSC_FREQ_48MHZ; |
| 564 | BUG_ON(pll_ref_div != OSC_CTRL_PLL_REF_DIV_4); |
| 565 | break; |
| 566 | default: |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 567 | pr_err("%s: Unexpected clock rate %ld", __func__, |
| 568 | to_clk_tegra(hw)->fixed_rate); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 569 | BUG(); |
| 570 | } |
| 571 | clk_writel(auto_clock_control, OSC_CTRL); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 574 | struct clk_ops tegra30_clk_m_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 575 | .init = tegra30_clk_m_init, |
| 576 | .recalc_rate = tegra30_clk_m_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 577 | }; |
| 578 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 579 | static unsigned long tegra30_clk_m_div_recalc_rate(struct clk_hw *hw, |
| 580 | unsigned long parent_rate) |
| 581 | { |
| 582 | struct clk_tegra *c = to_clk_tegra(hw); |
| 583 | u64 rate = parent_rate; |
| 584 | |
| 585 | if (c->mul != 0 && c->div != 0) { |
| 586 | rate *= c->mul; |
| 587 | rate += c->div - 1; /* round up */ |
| 588 | do_div(rate, c->div); |
| 589 | } |
| 590 | |
| 591 | return rate; |
| 592 | } |
| 593 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 594 | struct clk_ops tegra_clk_m_div_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 595 | .recalc_rate = tegra30_clk_m_div_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 596 | }; |
| 597 | |
| 598 | /* PLL reference divider functions */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 599 | static unsigned long tegra30_pll_ref_recalc_rate(struct clk_hw *hw, |
| 600 | unsigned long parent_rate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 601 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 602 | struct clk_tegra *c = to_clk_tegra(hw); |
| 603 | unsigned long rate = parent_rate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 604 | u32 pll_ref_div = clk_readl(OSC_CTRL) & OSC_CTRL_PLL_REF_DIV_MASK; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 605 | |
| 606 | switch (pll_ref_div) { |
| 607 | case OSC_CTRL_PLL_REF_DIV_1: |
| 608 | c->div = 1; |
| 609 | break; |
| 610 | case OSC_CTRL_PLL_REF_DIV_2: |
| 611 | c->div = 2; |
| 612 | break; |
| 613 | case OSC_CTRL_PLL_REF_DIV_4: |
| 614 | c->div = 4; |
| 615 | break; |
| 616 | default: |
| 617 | pr_err("%s: Invalid pll ref divider %d", __func__, pll_ref_div); |
| 618 | BUG(); |
| 619 | } |
| 620 | c->mul = 1; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 621 | |
| 622 | if (c->mul != 0 && c->div != 0) { |
| 623 | rate *= c->mul; |
| 624 | rate += c->div - 1; /* round up */ |
| 625 | do_div(rate, c->div); |
| 626 | } |
| 627 | |
| 628 | return rate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 629 | } |
| 630 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 631 | struct clk_ops tegra_pll_ref_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 632 | .recalc_rate = tegra30_pll_ref_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 633 | }; |
| 634 | |
| 635 | /* super clock functions */ |
| 636 | /* "super clocks" on tegra30 have two-stage muxes, fractional 7.1 divider and |
| 637 | * clock skipping super divider. We will ignore the clock skipping divider, |
| 638 | * since we can't lower the voltage when using the clock skip, but we can if |
| 639 | * we lower the PLL frequency. We will use 7.1 divider for CPU super-clock |
| 640 | * only when its parent is a fixed rate PLL, since we can't change PLL rate |
| 641 | * in this case. |
| 642 | */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 643 | static void tegra30_super_clk_init(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 644 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 645 | struct clk_tegra *c = to_clk_tegra(hw); |
| 646 | struct clk_tegra *p = |
| 647 | to_clk_tegra(__clk_get_hw(__clk_get_parent(hw->clk))); |
| 648 | |
| 649 | c->state = ON; |
| 650 | if (c->flags & DIV_U71) { |
| 651 | /* Init safe 7.1 divider value (does not affect PLLX path) */ |
| 652 | clk_writel(SUPER_CLOCK_DIV_U71_MIN << SUPER_CLOCK_DIV_U71_SHIFT, |
| 653 | c->reg + SUPER_CLK_DIVIDER); |
| 654 | c->mul = 2; |
| 655 | c->div = 2; |
| 656 | if (!(p->flags & PLLX)) |
| 657 | c->div += SUPER_CLOCK_DIV_U71_MIN; |
| 658 | } else |
| 659 | clk_writel(0, c->reg + SUPER_CLK_DIVIDER); |
| 660 | } |
| 661 | |
| 662 | static u8 tegra30_super_clk_get_parent(struct clk_hw *hw) |
| 663 | { |
| 664 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 665 | u32 val; |
| 666 | int source; |
| 667 | int shift; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 668 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 669 | val = clk_readl(c->reg + SUPER_CLK_MUX); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 670 | BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) && |
| 671 | ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE)); |
| 672 | shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ? |
| 673 | SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT; |
| 674 | source = (val >> shift) & SUPER_SOURCE_MASK; |
| 675 | if (c->flags & DIV_2) |
| 676 | source |= val & SUPER_LP_DIV2_BYPASS; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 677 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 678 | return source; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 679 | } |
| 680 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 681 | static int tegra30_super_clk_set_parent(struct clk_hw *hw, u8 index) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 682 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 683 | struct clk_tegra *c = to_clk_tegra(hw); |
| 684 | struct clk_tegra *p = |
| 685 | to_clk_tegra(__clk_get_hw(clk_get_parent(hw->clk))); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 686 | u32 val; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 687 | int shift; |
| 688 | |
| 689 | val = clk_readl(c->reg + SUPER_CLK_MUX); |
| 690 | BUG_ON(((val & SUPER_STATE_MASK) != SUPER_STATE_RUN) && |
| 691 | ((val & SUPER_STATE_MASK) != SUPER_STATE_IDLE)); |
| 692 | shift = ((val & SUPER_STATE_MASK) == SUPER_STATE_IDLE) ? |
| 693 | SUPER_IDLE_SOURCE_SHIFT : SUPER_RUN_SOURCE_SHIFT; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 694 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 695 | /* For LP mode super-clock switch between PLLX direct |
| 696 | and divided-by-2 outputs is allowed only when other |
| 697 | than PLLX clock source is current parent */ |
| 698 | if ((c->flags & DIV_2) && (p->flags & PLLX) && |
| 699 | ((index ^ val) & SUPER_LP_DIV2_BYPASS)) { |
| 700 | if (p->flags & PLLX) |
| 701 | return -EINVAL; |
| 702 | val ^= SUPER_LP_DIV2_BYPASS; |
| 703 | clk_writel_delay(val, c->reg); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 704 | } |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 705 | val &= ~(SUPER_SOURCE_MASK << shift); |
| 706 | val |= (index & SUPER_SOURCE_MASK) << shift; |
| 707 | |
| 708 | /* 7.1 divider for CPU super-clock does not affect |
| 709 | PLLX path */ |
| 710 | if (c->flags & DIV_U71) { |
| 711 | u32 div = 0; |
| 712 | if (!(p->flags & PLLX)) { |
| 713 | div = clk_readl(c->reg + |
| 714 | SUPER_CLK_DIVIDER); |
| 715 | div &= SUPER_CLOCK_DIV_U71_MASK; |
| 716 | div >>= SUPER_CLOCK_DIV_U71_SHIFT; |
| 717 | } |
| 718 | c->div = div + 2; |
| 719 | c->mul = 2; |
| 720 | } |
| 721 | clk_writel_delay(val, c->reg); |
| 722 | |
| 723 | return 0; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | /* |
| 727 | * Do not use super clocks "skippers", since dividing using a clock skipper |
| 728 | * does not allow the voltage to be scaled down. Instead adjust the rate of |
| 729 | * the parent clock. This requires that the parent of a super clock have no |
| 730 | * other children, otherwise the rate will change underneath the other |
| 731 | * children. Special case: if fixed rate PLL is CPU super clock parent the |
| 732 | * rate of this PLL can't be changed, and it has many other children. In |
| 733 | * this case use 7.1 fractional divider to adjust the super clock rate. |
| 734 | */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 735 | static int tegra30_super_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 736 | unsigned long parent_rate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 737 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 738 | struct clk_tegra *c = to_clk_tegra(hw); |
| 739 | struct clk *parent = __clk_get_parent(hw->clk); |
| 740 | struct clk_tegra *cparent = to_clk_tegra(__clk_get_hw(parent)); |
| 741 | |
| 742 | if ((c->flags & DIV_U71) && (cparent->flags & PLL_FIXED)) { |
| 743 | int div = clk_div71_get_divider(parent_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 744 | rate, c->flags, ROUND_DIVIDER_DOWN); |
| 745 | div = max(div, SUPER_CLOCK_DIV_U71_MIN); |
| 746 | |
| 747 | clk_writel(div << SUPER_CLOCK_DIV_U71_SHIFT, |
| 748 | c->reg + SUPER_CLK_DIVIDER); |
| 749 | c->div = div + 2; |
| 750 | c->mul = 2; |
| 751 | return 0; |
| 752 | } |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 753 | return 0; |
| 754 | } |
| 755 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 756 | static unsigned long tegra30_super_clk_recalc_rate(struct clk_hw *hw, |
| 757 | unsigned long parent_rate) |
| 758 | { |
| 759 | struct clk_tegra *c = to_clk_tegra(hw); |
| 760 | u64 rate = parent_rate; |
| 761 | |
| 762 | if (c->mul != 0 && c->div != 0) { |
| 763 | rate *= c->mul; |
| 764 | rate += c->div - 1; /* round up */ |
| 765 | do_div(rate, c->div); |
| 766 | } |
| 767 | |
| 768 | return rate; |
| 769 | } |
| 770 | |
| 771 | static long tegra30_super_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 772 | unsigned long *prate) |
| 773 | { |
| 774 | struct clk_tegra *c = to_clk_tegra(hw); |
| 775 | struct clk *parent = __clk_get_parent(hw->clk); |
| 776 | struct clk_tegra *cparent = to_clk_tegra(__clk_get_hw(parent)); |
| 777 | int mul = 2; |
| 778 | int div; |
| 779 | |
| 780 | if ((c->flags & DIV_U71) && (cparent->flags & PLL_FIXED)) { |
| 781 | div = clk_div71_get_divider(*prate, |
| 782 | rate, c->flags, ROUND_DIVIDER_DOWN); |
| 783 | div = max(div, SUPER_CLOCK_DIV_U71_MIN) + 2; |
| 784 | rate = *prate * mul; |
| 785 | rate += div - 1; /* round up */ |
| 786 | do_div(rate, c->div); |
| 787 | |
| 788 | return rate; |
| 789 | } |
| 790 | return *prate; |
| 791 | } |
| 792 | |
| 793 | struct clk_ops tegra30_super_ops = { |
| 794 | .init = tegra30_super_clk_init, |
| 795 | .set_parent = tegra30_super_clk_set_parent, |
| 796 | .get_parent = tegra30_super_clk_get_parent, |
| 797 | .recalc_rate = tegra30_super_clk_recalc_rate, |
| 798 | .round_rate = tegra30_super_clk_round_rate, |
| 799 | .set_rate = tegra30_super_clk_set_rate, |
| 800 | }; |
| 801 | |
| 802 | static unsigned long tegra30_twd_clk_recalc_rate(struct clk_hw *hw, |
| 803 | unsigned long parent_rate) |
| 804 | { |
| 805 | struct clk_tegra *c = to_clk_tegra(hw); |
| 806 | u64 rate = parent_rate; |
| 807 | |
| 808 | if (c->mul != 0 && c->div != 0) { |
| 809 | rate *= c->mul; |
| 810 | rate += c->div - 1; /* round up */ |
| 811 | do_div(rate, c->div); |
| 812 | } |
| 813 | |
| 814 | return rate; |
| 815 | } |
| 816 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 817 | struct clk_ops tegra30_twd_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 818 | .recalc_rate = tegra30_twd_clk_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 819 | }; |
| 820 | |
Joseph Lo | d534b5d | 2012-10-29 18:25:29 +0800 | [diff] [blame] | 821 | /* bus clock functions */ |
| 822 | static int tegra30_bus_clk_is_enabled(struct clk_hw *hw) |
| 823 | { |
| 824 | struct clk_tegra *c = to_clk_tegra(hw); |
| 825 | u32 val = clk_readl(c->reg); |
| 826 | |
| 827 | c->state = ((val >> c->reg_shift) & BUS_CLK_DISABLE) ? OFF : ON; |
| 828 | return c->state; |
| 829 | } |
| 830 | |
| 831 | static int tegra30_bus_clk_enable(struct clk_hw *hw) |
| 832 | { |
| 833 | struct clk_tegra *c = to_clk_tegra(hw); |
| 834 | u32 val; |
| 835 | |
| 836 | val = clk_readl(c->reg); |
| 837 | val &= ~(BUS_CLK_DISABLE << c->reg_shift); |
| 838 | clk_writel(val, c->reg); |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static void tegra30_bus_clk_disable(struct clk_hw *hw) |
| 844 | { |
| 845 | struct clk_tegra *c = to_clk_tegra(hw); |
| 846 | u32 val; |
| 847 | |
| 848 | val = clk_readl(c->reg); |
| 849 | val |= BUS_CLK_DISABLE << c->reg_shift; |
| 850 | clk_writel(val, c->reg); |
| 851 | } |
| 852 | |
| 853 | static unsigned long tegra30_bus_clk_recalc_rate(struct clk_hw *hw, |
| 854 | unsigned long prate) |
| 855 | { |
| 856 | struct clk_tegra *c = to_clk_tegra(hw); |
| 857 | u32 val = clk_readl(c->reg); |
| 858 | u64 rate = prate; |
| 859 | |
| 860 | c->div = ((val >> c->reg_shift) & BUS_CLK_DIV_MASK) + 1; |
| 861 | c->mul = 1; |
| 862 | |
| 863 | if (c->mul != 0 && c->div != 0) { |
| 864 | rate *= c->mul; |
| 865 | rate += c->div - 1; /* round up */ |
| 866 | do_div(rate, c->div); |
| 867 | } |
| 868 | return rate; |
| 869 | } |
| 870 | |
| 871 | static int tegra30_bus_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 872 | unsigned long parent_rate) |
| 873 | { |
| 874 | struct clk_tegra *c = to_clk_tegra(hw); |
| 875 | int ret = -EINVAL; |
| 876 | u32 val; |
| 877 | int i; |
| 878 | |
| 879 | val = clk_readl(c->reg); |
| 880 | for (i = 1; i <= 4; i++) { |
| 881 | if (rate == parent_rate / i) { |
| 882 | val &= ~(BUS_CLK_DIV_MASK << c->reg_shift); |
| 883 | val |= (i - 1) << c->reg_shift; |
| 884 | clk_writel(val, c->reg); |
| 885 | c->div = i; |
| 886 | c->mul = 1; |
| 887 | ret = 0; |
| 888 | break; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | return ret; |
| 893 | } |
| 894 | |
| 895 | static long tegra30_bus_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 896 | unsigned long *prate) |
| 897 | { |
| 898 | unsigned long parent_rate = *prate; |
| 899 | s64 divider; |
| 900 | |
| 901 | if (rate >= parent_rate) |
| 902 | return parent_rate; |
| 903 | |
| 904 | divider = parent_rate; |
| 905 | divider += rate - 1; |
| 906 | do_div(divider, rate); |
| 907 | |
| 908 | if (divider < 0) |
| 909 | return divider; |
| 910 | |
| 911 | if (divider > 4) |
| 912 | divider = 4; |
| 913 | do_div(parent_rate, divider); |
| 914 | |
| 915 | return parent_rate; |
| 916 | } |
| 917 | |
| 918 | struct clk_ops tegra30_bus_ops = { |
| 919 | .is_enabled = tegra30_bus_clk_is_enabled, |
| 920 | .enable = tegra30_bus_clk_enable, |
| 921 | .disable = tegra30_bus_clk_disable, |
| 922 | .set_rate = tegra30_bus_clk_set_rate, |
| 923 | .round_rate = tegra30_bus_clk_round_rate, |
| 924 | .recalc_rate = tegra30_bus_clk_recalc_rate, |
| 925 | }; |
| 926 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 927 | /* Blink output functions */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 928 | static int tegra30_blink_clk_is_enabled(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 929 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 930 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 931 | u32 val; |
| 932 | |
| 933 | val = pmc_readl(PMC_CTRL); |
| 934 | c->state = (val & PMC_CTRL_BLINK_ENB) ? ON : OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 935 | return c->state; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 936 | } |
| 937 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 938 | static int tegra30_blink_clk_enable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 939 | { |
| 940 | u32 val; |
| 941 | |
| 942 | val = pmc_readl(PMC_DPD_PADS_ORIDE); |
| 943 | pmc_writel(val | PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE); |
| 944 | |
| 945 | val = pmc_readl(PMC_CTRL); |
| 946 | pmc_writel(val | PMC_CTRL_BLINK_ENB, PMC_CTRL); |
| 947 | |
| 948 | return 0; |
| 949 | } |
| 950 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 951 | static void tegra30_blink_clk_disable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 952 | { |
| 953 | u32 val; |
| 954 | |
| 955 | val = pmc_readl(PMC_CTRL); |
| 956 | pmc_writel(val & ~PMC_CTRL_BLINK_ENB, PMC_CTRL); |
| 957 | |
| 958 | val = pmc_readl(PMC_DPD_PADS_ORIDE); |
| 959 | pmc_writel(val & ~PMC_DPD_PADS_ORIDE_BLINK_ENB, PMC_DPD_PADS_ORIDE); |
| 960 | } |
| 961 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 962 | static int tegra30_blink_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 963 | unsigned long parent_rate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 964 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 965 | struct clk_tegra *c = to_clk_tegra(hw); |
| 966 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 967 | if (rate >= parent_rate) { |
| 968 | c->div = 1; |
| 969 | pmc_writel(0, c->reg); |
| 970 | } else { |
| 971 | unsigned int on_off; |
| 972 | u32 val; |
| 973 | |
| 974 | on_off = DIV_ROUND_UP(parent_rate / 8, rate); |
| 975 | c->div = on_off * 8; |
| 976 | |
| 977 | val = (on_off & PMC_BLINK_TIMER_DATA_ON_MASK) << |
| 978 | PMC_BLINK_TIMER_DATA_ON_SHIFT; |
| 979 | on_off &= PMC_BLINK_TIMER_DATA_OFF_MASK; |
| 980 | on_off <<= PMC_BLINK_TIMER_DATA_OFF_SHIFT; |
| 981 | val |= on_off; |
| 982 | val |= PMC_BLINK_TIMER_ENB; |
| 983 | pmc_writel(val, c->reg); |
| 984 | } |
| 985 | |
| 986 | return 0; |
| 987 | } |
| 988 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 989 | static unsigned long tegra30_blink_clk_recalc_rate(struct clk_hw *hw, |
| 990 | unsigned long parent_rate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 991 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 992 | struct clk_tegra *c = to_clk_tegra(hw); |
| 993 | u64 rate = parent_rate; |
| 994 | u32 val; |
| 995 | u32 mul; |
| 996 | u32 div; |
| 997 | u32 on_off; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 998 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 999 | mul = 1; |
| 1000 | val = pmc_readl(c->reg); |
| 1001 | |
| 1002 | if (val & PMC_BLINK_TIMER_ENB) { |
| 1003 | on_off = (val >> PMC_BLINK_TIMER_DATA_ON_SHIFT) & |
| 1004 | PMC_BLINK_TIMER_DATA_ON_MASK; |
| 1005 | val >>= PMC_BLINK_TIMER_DATA_OFF_SHIFT; |
| 1006 | val &= PMC_BLINK_TIMER_DATA_OFF_MASK; |
| 1007 | on_off += val; |
| 1008 | /* each tick in the blink timer is 4 32KHz clocks */ |
| 1009 | div = on_off * 4; |
| 1010 | } else { |
| 1011 | div = 1; |
| 1012 | } |
| 1013 | |
| 1014 | if (mul != 0 && div != 0) { |
| 1015 | rate *= mul; |
| 1016 | rate += div - 1; /* round up */ |
| 1017 | do_div(rate, div); |
| 1018 | } |
| 1019 | return rate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1020 | } |
| 1021 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1022 | static long tegra30_blink_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 1023 | unsigned long *prate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1024 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1025 | int div; |
| 1026 | int mul; |
| 1027 | long round_rate = *prate; |
| 1028 | |
| 1029 | mul = 1; |
| 1030 | |
| 1031 | if (rate >= *prate) { |
| 1032 | div = 1; |
| 1033 | } else { |
| 1034 | div = DIV_ROUND_UP(*prate / 8, rate); |
| 1035 | div *= 8; |
| 1036 | } |
| 1037 | |
| 1038 | round_rate *= mul; |
| 1039 | round_rate += div - 1; |
| 1040 | do_div(round_rate, div); |
| 1041 | |
| 1042 | return round_rate; |
| 1043 | } |
| 1044 | |
| 1045 | struct clk_ops tegra30_blink_clk_ops = { |
| 1046 | .is_enabled = tegra30_blink_clk_is_enabled, |
| 1047 | .enable = tegra30_blink_clk_enable, |
| 1048 | .disable = tegra30_blink_clk_disable, |
| 1049 | .recalc_rate = tegra30_blink_clk_recalc_rate, |
| 1050 | .round_rate = tegra30_blink_clk_round_rate, |
| 1051 | .set_rate = tegra30_blink_clk_set_rate, |
| 1052 | }; |
| 1053 | |
| 1054 | static void tegra30_utmi_param_configure(struct clk_hw *hw) |
| 1055 | { |
| 1056 | unsigned long main_rate = |
| 1057 | __clk_get_rate(__clk_get_parent(__clk_get_parent(hw->clk))); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1058 | u32 reg; |
| 1059 | int i; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1060 | |
| 1061 | for (i = 0; i < ARRAY_SIZE(utmi_parameters); i++) { |
| 1062 | if (main_rate == utmi_parameters[i].osc_frequency) |
| 1063 | break; |
| 1064 | } |
| 1065 | |
| 1066 | if (i >= ARRAY_SIZE(utmi_parameters)) { |
| 1067 | pr_err("%s: Unexpected main rate %lu\n", __func__, main_rate); |
| 1068 | return; |
| 1069 | } |
| 1070 | |
| 1071 | reg = clk_readl(UTMIP_PLL_CFG2); |
| 1072 | |
| 1073 | /* Program UTMIP PLL stable and active counts */ |
| 1074 | /* [FIXME] arclk_rst.h says WRONG! This should be 1ms -> 0x50 Check! */ |
| 1075 | reg &= ~UTMIP_PLL_CFG2_STABLE_COUNT(~0); |
| 1076 | reg |= UTMIP_PLL_CFG2_STABLE_COUNT( |
| 1077 | utmi_parameters[i].stable_count); |
| 1078 | |
| 1079 | reg &= ~UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT(~0); |
| 1080 | |
| 1081 | reg |= UTMIP_PLL_CFG2_ACTIVE_DLY_COUNT( |
| 1082 | utmi_parameters[i].active_delay_count); |
| 1083 | |
| 1084 | /* Remove power downs from UTMIP PLL control bits */ |
| 1085 | reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_A_POWERDOWN; |
| 1086 | reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_B_POWERDOWN; |
| 1087 | reg &= ~UTMIP_PLL_CFG2_FORCE_PD_SAMP_C_POWERDOWN; |
| 1088 | |
| 1089 | clk_writel(reg, UTMIP_PLL_CFG2); |
| 1090 | |
| 1091 | /* Program UTMIP PLL delay and oscillator frequency counts */ |
| 1092 | reg = clk_readl(UTMIP_PLL_CFG1); |
| 1093 | reg &= ~UTMIP_PLL_CFG1_ENABLE_DLY_COUNT(~0); |
| 1094 | |
| 1095 | reg |= UTMIP_PLL_CFG1_ENABLE_DLY_COUNT( |
| 1096 | utmi_parameters[i].enable_delay_count); |
| 1097 | |
| 1098 | reg &= ~UTMIP_PLL_CFG1_XTAL_FREQ_COUNT(~0); |
| 1099 | reg |= UTMIP_PLL_CFG1_XTAL_FREQ_COUNT( |
| 1100 | utmi_parameters[i].xtal_freq_count); |
| 1101 | |
| 1102 | /* Remove power downs from UTMIP PLL control bits */ |
| 1103 | reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ENABLE_POWERDOWN; |
| 1104 | reg &= ~UTMIP_PLL_CFG1_FORCE_PLL_ACTIVE_POWERDOWN; |
| 1105 | reg &= ~UTMIP_PLL_CFG1_FORCE_PLLU_POWERDOWN; |
| 1106 | |
| 1107 | clk_writel(reg, UTMIP_PLL_CFG1); |
| 1108 | } |
| 1109 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1110 | /* PLL Functions */ |
| 1111 | static int tegra30_pll_clk_wait_for_lock(struct clk_tegra *c, u32 lock_reg, |
| 1112 | u32 lock_bit) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1113 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1114 | int ret = 0; |
| 1115 | |
| 1116 | #if USE_PLL_LOCK_BITS |
| 1117 | int i; |
| 1118 | for (i = 0; i < c->u.pll.lock_delay; i++) { |
| 1119 | if (clk_readl(lock_reg) & lock_bit) { |
| 1120 | udelay(PLL_POST_LOCK_DELAY); |
| 1121 | return 0; |
| 1122 | } |
| 1123 | udelay(2); /* timeout = 2 * lock time */ |
| 1124 | } |
| 1125 | pr_err("Timed out waiting for lock bit on pll %s", |
| 1126 | __clk_get_name(hw->clk)); |
| 1127 | ret = -1; |
| 1128 | #else |
| 1129 | udelay(c->u.pll.lock_delay); |
| 1130 | #endif |
| 1131 | return ret; |
| 1132 | } |
| 1133 | |
| 1134 | static int tegra30_pll_clk_is_enabled(struct clk_hw *hw) |
| 1135 | { |
| 1136 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1137 | u32 val = clk_readl(c->reg + PLL_BASE); |
| 1138 | |
| 1139 | c->state = (val & PLL_BASE_ENABLE) ? ON : OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1140 | return c->state; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1143 | static void tegra30_pll_clk_init(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1144 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1145 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1146 | |
| 1147 | if (c->flags & PLLU) |
| 1148 | tegra30_utmi_param_configure(hw); |
| 1149 | } |
| 1150 | |
| 1151 | static int tegra30_pll_clk_enable(struct clk_hw *hw) |
| 1152 | { |
| 1153 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1154 | u32 val; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1155 | pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk)); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1156 | |
| 1157 | #if USE_PLL_LOCK_BITS |
| 1158 | val = clk_readl(c->reg + PLL_MISC(c)); |
| 1159 | val |= PLL_MISC_LOCK_ENABLE(c); |
| 1160 | clk_writel(val, c->reg + PLL_MISC(c)); |
| 1161 | #endif |
| 1162 | val = clk_readl(c->reg + PLL_BASE); |
| 1163 | val &= ~PLL_BASE_BYPASS; |
| 1164 | val |= PLL_BASE_ENABLE; |
| 1165 | clk_writel(val, c->reg + PLL_BASE); |
| 1166 | |
| 1167 | if (c->flags & PLLM) { |
| 1168 | val = pmc_readl(PMC_PLLP_WB0_OVERRIDE); |
| 1169 | val |= PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE; |
| 1170 | pmc_writel(val, PMC_PLLP_WB0_OVERRIDE); |
| 1171 | } |
| 1172 | |
| 1173 | tegra30_pll_clk_wait_for_lock(c, c->reg + PLL_BASE, PLL_BASE_LOCK); |
| 1174 | |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1178 | static void tegra30_pll_clk_disable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1179 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1180 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1181 | u32 val; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1182 | pr_debug("%s on clock %s\n", __func__, __clk_get_name(hw->clk)); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1183 | |
| 1184 | val = clk_readl(c->reg); |
| 1185 | val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE); |
| 1186 | clk_writel(val, c->reg); |
| 1187 | |
| 1188 | if (c->flags & PLLM) { |
| 1189 | val = pmc_readl(PMC_PLLP_WB0_OVERRIDE); |
| 1190 | val &= ~PMC_PLLP_WB0_OVERRIDE_PLLM_ENABLE; |
| 1191 | pmc_writel(val, PMC_PLLP_WB0_OVERRIDE); |
| 1192 | } |
| 1193 | } |
| 1194 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1195 | static int tegra30_pll_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1196 | unsigned long parent_rate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1197 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1198 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1199 | u32 val, p_div, old_base; |
| 1200 | unsigned long input_rate; |
| 1201 | const struct clk_pll_freq_table *sel; |
| 1202 | struct clk_pll_freq_table cfg; |
| 1203 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1204 | if (c->flags & PLL_FIXED) { |
| 1205 | int ret = 0; |
| 1206 | if (rate != c->u.pll.fixed_rate) { |
| 1207 | pr_err("%s: Can not change %s fixed rate %lu to %lu\n", |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1208 | __func__, __clk_get_name(hw->clk), |
| 1209 | c->u.pll.fixed_rate, rate); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1210 | ret = -EINVAL; |
| 1211 | } |
| 1212 | return ret; |
| 1213 | } |
| 1214 | |
| 1215 | if (c->flags & PLLM) { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1216 | if (rate != __clk_get_rate(hw->clk)) { |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1217 | pr_err("%s: Can not change memory %s rate in flight\n", |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1218 | __func__, __clk_get_name(hw->clk)); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1219 | return -EINVAL; |
| 1220 | } |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | p_div = 0; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1224 | input_rate = parent_rate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1225 | |
| 1226 | /* Check if the target rate is tabulated */ |
| 1227 | for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) { |
| 1228 | if (sel->input_rate == input_rate && sel->output_rate == rate) { |
| 1229 | if (c->flags & PLLU) { |
| 1230 | BUG_ON(sel->p < 1 || sel->p > 2); |
| 1231 | if (sel->p == 1) |
| 1232 | p_div = PLLU_BASE_POST_DIV; |
| 1233 | } else { |
| 1234 | BUG_ON(sel->p < 1); |
| 1235 | for (val = sel->p; val > 1; val >>= 1) |
| 1236 | p_div++; |
| 1237 | p_div <<= PLL_BASE_DIVP_SHIFT; |
| 1238 | } |
| 1239 | break; |
| 1240 | } |
| 1241 | } |
| 1242 | |
| 1243 | /* Configure out-of-table rate */ |
| 1244 | if (sel->input_rate == 0) { |
| 1245 | unsigned long cfreq; |
| 1246 | BUG_ON(c->flags & PLLU); |
| 1247 | sel = &cfg; |
| 1248 | |
| 1249 | switch (input_rate) { |
| 1250 | case 12000000: |
| 1251 | case 26000000: |
| 1252 | cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000; |
| 1253 | break; |
| 1254 | case 13000000: |
| 1255 | cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000; |
| 1256 | break; |
| 1257 | case 16800000: |
| 1258 | case 19200000: |
| 1259 | cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000; |
| 1260 | break; |
| 1261 | default: |
| 1262 | pr_err("%s: Unexpected reference rate %lu\n", |
| 1263 | __func__, input_rate); |
| 1264 | BUG(); |
| 1265 | } |
| 1266 | |
| 1267 | /* Raise VCO to guarantee 0.5% accuracy */ |
| 1268 | for (cfg.output_rate = rate; cfg.output_rate < 200 * cfreq; |
| 1269 | cfg.output_rate <<= 1) |
| 1270 | p_div++; |
| 1271 | |
| 1272 | cfg.p = 0x1 << p_div; |
| 1273 | cfg.m = input_rate / cfreq; |
| 1274 | cfg.n = cfg.output_rate / cfreq; |
| 1275 | cfg.cpcon = OUT_OF_TABLE_CPCON; |
| 1276 | |
| 1277 | if ((cfg.m > (PLL_BASE_DIVM_MASK >> PLL_BASE_DIVM_SHIFT)) || |
| 1278 | (cfg.n > (PLL_BASE_DIVN_MASK >> PLL_BASE_DIVN_SHIFT)) || |
| 1279 | (p_div > (PLL_BASE_DIVP_MASK >> PLL_BASE_DIVP_SHIFT)) || |
| 1280 | (cfg.output_rate > c->u.pll.vco_max)) { |
| 1281 | pr_err("%s: Failed to set %s out-of-table rate %lu\n", |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1282 | __func__, __clk_get_name(hw->clk), rate); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1283 | return -EINVAL; |
| 1284 | } |
| 1285 | p_div <<= PLL_BASE_DIVP_SHIFT; |
| 1286 | } |
| 1287 | |
| 1288 | c->mul = sel->n; |
| 1289 | c->div = sel->m * sel->p; |
| 1290 | |
| 1291 | old_base = val = clk_readl(c->reg + PLL_BASE); |
| 1292 | val &= ~(PLL_BASE_DIVM_MASK | PLL_BASE_DIVN_MASK | |
| 1293 | ((c->flags & PLLU) ? PLLU_BASE_POST_DIV : PLL_BASE_DIVP_MASK)); |
| 1294 | val |= (sel->m << PLL_BASE_DIVM_SHIFT) | |
| 1295 | (sel->n << PLL_BASE_DIVN_SHIFT) | p_div; |
| 1296 | if (val == old_base) |
| 1297 | return 0; |
| 1298 | |
| 1299 | if (c->state == ON) { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1300 | tegra30_pll_clk_disable(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1301 | val &= ~(PLL_BASE_BYPASS | PLL_BASE_ENABLE); |
| 1302 | } |
| 1303 | clk_writel(val, c->reg + PLL_BASE); |
| 1304 | |
| 1305 | if (c->flags & PLL_HAS_CPCON) { |
| 1306 | val = clk_readl(c->reg + PLL_MISC(c)); |
| 1307 | val &= ~PLL_MISC_CPCON_MASK; |
| 1308 | val |= sel->cpcon << PLL_MISC_CPCON_SHIFT; |
| 1309 | if (c->flags & (PLLU | PLLD)) { |
| 1310 | val &= ~PLL_MISC_LFCON_MASK; |
| 1311 | if (sel->n >= PLLDU_LFCON_SET_DIVN) |
| 1312 | val |= 0x1 << PLL_MISC_LFCON_SHIFT; |
| 1313 | } else if (c->flags & (PLLX | PLLM)) { |
| 1314 | val &= ~(0x1 << PLL_MISC_DCCON_SHIFT); |
| 1315 | if (rate >= (c->u.pll.vco_max >> 1)) |
| 1316 | val |= 0x1 << PLL_MISC_DCCON_SHIFT; |
| 1317 | } |
| 1318 | clk_writel(val, c->reg + PLL_MISC(c)); |
| 1319 | } |
| 1320 | |
| 1321 | if (c->state == ON) |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1322 | tegra30_pll_clk_enable(hw); |
| 1323 | |
| 1324 | c->u.pll.fixed_rate = rate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1325 | |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1329 | static long tegra30_pll_round_rate(struct clk_hw *hw, unsigned long rate, |
| 1330 | unsigned long *prate) |
| 1331 | { |
| 1332 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1333 | unsigned long input_rate = *prate; |
Mark Zhang | 7866213 | 2012-10-16 16:31:49 +0800 | [diff] [blame] | 1334 | u64 output_rate = *prate; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1335 | const struct clk_pll_freq_table *sel; |
| 1336 | struct clk_pll_freq_table cfg; |
| 1337 | int mul; |
| 1338 | int div; |
| 1339 | u32 p_div; |
| 1340 | u32 val; |
| 1341 | |
| 1342 | if (c->flags & PLL_FIXED) |
| 1343 | return c->u.pll.fixed_rate; |
| 1344 | |
| 1345 | if (c->flags & PLLM) |
| 1346 | return __clk_get_rate(hw->clk); |
| 1347 | |
| 1348 | p_div = 0; |
| 1349 | /* Check if the target rate is tabulated */ |
| 1350 | for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) { |
| 1351 | if (sel->input_rate == input_rate && sel->output_rate == rate) { |
| 1352 | if (c->flags & PLLU) { |
| 1353 | BUG_ON(sel->p < 1 || sel->p > 2); |
| 1354 | if (sel->p == 1) |
| 1355 | p_div = PLLU_BASE_POST_DIV; |
| 1356 | } else { |
| 1357 | BUG_ON(sel->p < 1); |
| 1358 | for (val = sel->p; val > 1; val >>= 1) |
| 1359 | p_div++; |
| 1360 | p_div <<= PLL_BASE_DIVP_SHIFT; |
| 1361 | } |
| 1362 | break; |
| 1363 | } |
| 1364 | } |
| 1365 | |
| 1366 | if (sel->input_rate == 0) { |
| 1367 | unsigned long cfreq; |
| 1368 | BUG_ON(c->flags & PLLU); |
| 1369 | sel = &cfg; |
| 1370 | |
| 1371 | switch (input_rate) { |
| 1372 | case 12000000: |
| 1373 | case 26000000: |
| 1374 | cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2000000; |
| 1375 | break; |
| 1376 | case 13000000: |
| 1377 | cfreq = (rate <= 1000000 * 1000) ? 1000000 : 2600000; |
| 1378 | break; |
| 1379 | case 16800000: |
| 1380 | case 19200000: |
| 1381 | cfreq = (rate <= 1200000 * 1000) ? 1200000 : 2400000; |
| 1382 | break; |
| 1383 | default: |
| 1384 | pr_err("%s: Unexpected reference rate %lu\n", |
| 1385 | __func__, input_rate); |
| 1386 | BUG(); |
| 1387 | } |
| 1388 | |
| 1389 | /* Raise VCO to guarantee 0.5% accuracy */ |
| 1390 | for (cfg.output_rate = rate; cfg.output_rate < 200 * cfreq; |
| 1391 | cfg.output_rate <<= 1) |
| 1392 | p_div++; |
| 1393 | |
| 1394 | cfg.p = 0x1 << p_div; |
| 1395 | cfg.m = input_rate / cfreq; |
| 1396 | cfg.n = cfg.output_rate / cfreq; |
| 1397 | } |
| 1398 | |
| 1399 | mul = sel->n; |
| 1400 | div = sel->m * sel->p; |
| 1401 | |
| 1402 | output_rate *= mul; |
| 1403 | output_rate += div - 1; /* round up */ |
| 1404 | do_div(output_rate, div); |
| 1405 | |
| 1406 | return output_rate; |
| 1407 | } |
| 1408 | |
| 1409 | static unsigned long tegra30_pll_recalc_rate(struct clk_hw *hw, |
| 1410 | unsigned long parent_rate) |
| 1411 | { |
| 1412 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1413 | u64 rate = parent_rate; |
| 1414 | u32 val = clk_readl(c->reg + PLL_BASE); |
| 1415 | |
| 1416 | if (c->flags & PLL_FIXED && !(val & PLL_BASE_OVERRIDE)) { |
| 1417 | const struct clk_pll_freq_table *sel; |
| 1418 | for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) { |
| 1419 | if (sel->input_rate == parent_rate && |
| 1420 | sel->output_rate == c->u.pll.fixed_rate) { |
| 1421 | c->mul = sel->n; |
| 1422 | c->div = sel->m * sel->p; |
| 1423 | break; |
| 1424 | } |
| 1425 | } |
| 1426 | pr_err("Clock %s has unknown fixed frequency\n", |
| 1427 | __clk_get_name(hw->clk)); |
| 1428 | BUG(); |
| 1429 | } else if (val & PLL_BASE_BYPASS) { |
| 1430 | c->mul = 1; |
| 1431 | c->div = 1; |
| 1432 | } else { |
| 1433 | c->mul = (val & PLL_BASE_DIVN_MASK) >> PLL_BASE_DIVN_SHIFT; |
| 1434 | c->div = (val & PLL_BASE_DIVM_MASK) >> PLL_BASE_DIVM_SHIFT; |
| 1435 | if (c->flags & PLLU) |
| 1436 | c->div *= (val & PLLU_BASE_POST_DIV) ? 1 : 2; |
| 1437 | else |
| 1438 | c->div *= (0x1 << ((val & PLL_BASE_DIVP_MASK) >> |
| 1439 | PLL_BASE_DIVP_SHIFT)); |
| 1440 | } |
| 1441 | |
| 1442 | if (c->mul != 0 && c->div != 0) { |
| 1443 | rate *= c->mul; |
| 1444 | rate += c->div - 1; /* round up */ |
| 1445 | do_div(rate, c->div); |
| 1446 | } |
| 1447 | |
| 1448 | return rate; |
| 1449 | } |
| 1450 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 1451 | struct clk_ops tegra30_pll_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1452 | .is_enabled = tegra30_pll_clk_is_enabled, |
| 1453 | .init = tegra30_pll_clk_init, |
| 1454 | .enable = tegra30_pll_clk_enable, |
| 1455 | .disable = tegra30_pll_clk_disable, |
| 1456 | .recalc_rate = tegra30_pll_recalc_rate, |
| 1457 | .round_rate = tegra30_pll_round_rate, |
| 1458 | .set_rate = tegra30_pll_clk_set_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1459 | }; |
| 1460 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1461 | int tegra30_plld_clk_cfg_ex(struct clk_hw *hw, |
| 1462 | enum tegra_clk_ex_param p, u32 setting) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1463 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1464 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1465 | u32 val, mask, reg; |
| 1466 | |
| 1467 | switch (p) { |
| 1468 | case TEGRA_CLK_PLLD_CSI_OUT_ENB: |
| 1469 | mask = PLLD_BASE_CSI_CLKENABLE; |
| 1470 | reg = c->reg + PLL_BASE; |
| 1471 | break; |
| 1472 | case TEGRA_CLK_PLLD_DSI_OUT_ENB: |
| 1473 | mask = PLLD_MISC_DSI_CLKENABLE; |
| 1474 | reg = c->reg + PLL_MISC(c); |
| 1475 | break; |
| 1476 | case TEGRA_CLK_PLLD_MIPI_MUX_SEL: |
| 1477 | if (!(c->flags & PLL_ALT_MISC_REG)) { |
| 1478 | mask = PLLD_BASE_DSIB_MUX_MASK; |
| 1479 | reg = c->reg + PLL_BASE; |
| 1480 | break; |
| 1481 | } |
| 1482 | /* fall through - error since PLLD2 does not have MUX_SEL control */ |
| 1483 | default: |
| 1484 | return -EINVAL; |
| 1485 | } |
| 1486 | |
| 1487 | val = clk_readl(reg); |
| 1488 | if (setting) |
| 1489 | val |= mask; |
| 1490 | else |
| 1491 | val &= ~mask; |
| 1492 | clk_writel(val, reg); |
| 1493 | return 0; |
| 1494 | } |
| 1495 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1496 | static int tegra30_plle_clk_is_enabled(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1497 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1498 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1499 | u32 val; |
| 1500 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1501 | val = clk_readl(c->reg + PLL_BASE); |
| 1502 | c->state = (val & PLLE_BASE_ENABLE) ? ON : OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1503 | return c->state; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1506 | static void tegra30_plle_clk_disable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1507 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1508 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1509 | u32 val; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1510 | |
| 1511 | val = clk_readl(c->reg + PLL_BASE); |
| 1512 | val &= ~(PLLE_BASE_CML_ENABLE | PLLE_BASE_ENABLE); |
| 1513 | clk_writel(val, c->reg + PLL_BASE); |
| 1514 | } |
| 1515 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1516 | static void tegra30_plle_training(struct clk_tegra *c) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1517 | { |
| 1518 | u32 val; |
| 1519 | |
| 1520 | /* PLLE is already disabled, and setup cleared; |
| 1521 | * create falling edge on PLLE IDDQ input */ |
| 1522 | val = pmc_readl(PMC_SATA_PWRGT); |
| 1523 | val |= PMC_SATA_PWRGT_PLLE_IDDQ_VALUE; |
| 1524 | pmc_writel(val, PMC_SATA_PWRGT); |
| 1525 | |
| 1526 | val = pmc_readl(PMC_SATA_PWRGT); |
| 1527 | val |= PMC_SATA_PWRGT_PLLE_IDDQ_SWCTL; |
| 1528 | pmc_writel(val, PMC_SATA_PWRGT); |
| 1529 | |
| 1530 | val = pmc_readl(PMC_SATA_PWRGT); |
| 1531 | val &= ~PMC_SATA_PWRGT_PLLE_IDDQ_VALUE; |
| 1532 | pmc_writel(val, PMC_SATA_PWRGT); |
| 1533 | |
| 1534 | do { |
| 1535 | val = clk_readl(c->reg + PLL_MISC(c)); |
| 1536 | } while (!(val & PLLE_MISC_READY)); |
| 1537 | } |
| 1538 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1539 | static int tegra30_plle_configure(struct clk_hw *hw, bool force_training) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1540 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1541 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1542 | struct clk *parent = __clk_get_parent(hw->clk); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1543 | const struct clk_pll_freq_table *sel; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1544 | u32 val; |
| 1545 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1546 | unsigned long rate = c->u.pll.fixed_rate; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1547 | unsigned long input_rate = __clk_get_rate(parent); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1548 | |
| 1549 | for (sel = c->u.pll.freq_table; sel->input_rate != 0; sel++) { |
| 1550 | if (sel->input_rate == input_rate && sel->output_rate == rate) |
| 1551 | break; |
| 1552 | } |
| 1553 | |
| 1554 | if (sel->input_rate == 0) |
| 1555 | return -ENOSYS; |
| 1556 | |
| 1557 | /* disable PLLE, clear setup fiels */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1558 | tegra30_plle_clk_disable(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1559 | |
| 1560 | val = clk_readl(c->reg + PLL_MISC(c)); |
| 1561 | val &= ~(PLLE_MISC_LOCK_ENABLE | PLLE_MISC_SETUP_MASK); |
| 1562 | clk_writel(val, c->reg + PLL_MISC(c)); |
| 1563 | |
| 1564 | /* training */ |
| 1565 | val = clk_readl(c->reg + PLL_MISC(c)); |
| 1566 | if (force_training || (!(val & PLLE_MISC_READY))) |
| 1567 | tegra30_plle_training(c); |
| 1568 | |
| 1569 | /* configure dividers, setup, disable SS */ |
| 1570 | val = clk_readl(c->reg + PLL_BASE); |
| 1571 | val &= ~PLLE_BASE_DIV_MASK; |
| 1572 | val |= PLLE_BASE_DIV(sel->m, sel->n, sel->p, sel->cpcon); |
| 1573 | clk_writel(val, c->reg + PLL_BASE); |
| 1574 | c->mul = sel->n; |
| 1575 | c->div = sel->m * sel->p; |
| 1576 | |
| 1577 | val = clk_readl(c->reg + PLL_MISC(c)); |
| 1578 | val |= PLLE_MISC_SETUP_VALUE; |
| 1579 | val |= PLLE_MISC_LOCK_ENABLE; |
| 1580 | clk_writel(val, c->reg + PLL_MISC(c)); |
| 1581 | |
| 1582 | val = clk_readl(PLLE_SS_CTRL); |
| 1583 | val |= PLLE_SS_DISABLE; |
| 1584 | clk_writel(val, PLLE_SS_CTRL); |
| 1585 | |
| 1586 | /* enable and lock PLLE*/ |
| 1587 | val = clk_readl(c->reg + PLL_BASE); |
| 1588 | val |= (PLLE_BASE_CML_ENABLE | PLLE_BASE_ENABLE); |
| 1589 | clk_writel(val, c->reg + PLL_BASE); |
| 1590 | |
| 1591 | tegra30_pll_clk_wait_for_lock(c, c->reg + PLL_MISC(c), PLLE_MISC_LOCK); |
| 1592 | |
| 1593 | return 0; |
| 1594 | } |
| 1595 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1596 | static int tegra30_plle_clk_enable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1597 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1598 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1599 | |
| 1600 | return tegra30_plle_configure(hw, !c->set); |
| 1601 | } |
| 1602 | |
| 1603 | static unsigned long tegra30_plle_clk_recalc_rate(struct clk_hw *hw, |
| 1604 | unsigned long parent_rate) |
| 1605 | { |
| 1606 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1607 | unsigned long rate = parent_rate; |
| 1608 | u32 val; |
| 1609 | |
| 1610 | val = clk_readl(c->reg + PLL_BASE); |
| 1611 | c->mul = (val & PLLE_BASE_DIVN_MASK) >> PLLE_BASE_DIVN_SHIFT; |
| 1612 | c->div = (val & PLLE_BASE_DIVM_MASK) >> PLLE_BASE_DIVM_SHIFT; |
| 1613 | c->div *= (val & PLLE_BASE_DIVP_MASK) >> PLLE_BASE_DIVP_SHIFT; |
| 1614 | |
| 1615 | if (c->mul != 0 && c->div != 0) { |
| 1616 | rate *= c->mul; |
| 1617 | rate += c->div - 1; /* round up */ |
| 1618 | do_div(rate, c->div); |
| 1619 | } |
| 1620 | return rate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 1623 | struct clk_ops tegra30_plle_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1624 | .is_enabled = tegra30_plle_clk_is_enabled, |
| 1625 | .enable = tegra30_plle_clk_enable, |
| 1626 | .disable = tegra30_plle_clk_disable, |
| 1627 | .recalc_rate = tegra30_plle_clk_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1628 | }; |
| 1629 | |
| 1630 | /* Clock divider ops */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1631 | static int tegra30_pll_div_clk_is_enabled(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1632 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1633 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1634 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1635 | if (c->flags & DIV_U71) { |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1636 | u32 val = clk_readl(c->reg); |
| 1637 | val >>= c->reg_shift; |
| 1638 | c->state = (val & PLL_OUT_CLKEN) ? ON : OFF; |
| 1639 | if (!(val & PLL_OUT_RESET_DISABLE)) |
| 1640 | c->state = OFF; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1641 | } else { |
| 1642 | c->state = ON; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1643 | } |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1644 | return c->state; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1647 | static int tegra30_pll_div_clk_enable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1648 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1649 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1650 | u32 val; |
| 1651 | u32 new_val; |
| 1652 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1653 | pr_debug("%s: %s\n", __func__, __clk_get_name(hw->clk)); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1654 | if (c->flags & DIV_U71) { |
| 1655 | val = clk_readl(c->reg); |
| 1656 | new_val = val >> c->reg_shift; |
| 1657 | new_val &= 0xFFFF; |
| 1658 | |
| 1659 | new_val |= PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE; |
| 1660 | |
| 1661 | val &= ~(0xFFFF << c->reg_shift); |
| 1662 | val |= new_val << c->reg_shift; |
| 1663 | clk_writel_delay(val, c->reg); |
| 1664 | return 0; |
| 1665 | } else if (c->flags & DIV_2) { |
| 1666 | return 0; |
| 1667 | } |
| 1668 | return -EINVAL; |
| 1669 | } |
| 1670 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1671 | static void tegra30_pll_div_clk_disable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1672 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1673 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1674 | u32 val; |
| 1675 | u32 new_val; |
| 1676 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1677 | pr_debug("%s: %s\n", __func__, __clk_get_name(hw->clk)); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1678 | if (c->flags & DIV_U71) { |
| 1679 | val = clk_readl(c->reg); |
| 1680 | new_val = val >> c->reg_shift; |
| 1681 | new_val &= 0xFFFF; |
| 1682 | |
| 1683 | new_val &= ~(PLL_OUT_CLKEN | PLL_OUT_RESET_DISABLE); |
| 1684 | |
| 1685 | val &= ~(0xFFFF << c->reg_shift); |
| 1686 | val |= new_val << c->reg_shift; |
| 1687 | clk_writel_delay(val, c->reg); |
| 1688 | } |
| 1689 | } |
| 1690 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1691 | static int tegra30_pll_div_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1692 | unsigned long parent_rate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1693 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1694 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1695 | u32 val; |
| 1696 | u32 new_val; |
| 1697 | int divider_u71; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1698 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1699 | if (c->flags & DIV_U71) { |
| 1700 | divider_u71 = clk_div71_get_divider( |
| 1701 | parent_rate, rate, c->flags, ROUND_DIVIDER_UP); |
| 1702 | if (divider_u71 >= 0) { |
| 1703 | val = clk_readl(c->reg); |
| 1704 | new_val = val >> c->reg_shift; |
| 1705 | new_val &= 0xFFFF; |
| 1706 | if (c->flags & DIV_U71_FIXED) |
| 1707 | new_val |= PLL_OUT_OVERRIDE; |
| 1708 | new_val &= ~PLL_OUT_RATIO_MASK; |
| 1709 | new_val |= divider_u71 << PLL_OUT_RATIO_SHIFT; |
| 1710 | |
| 1711 | val &= ~(0xFFFF << c->reg_shift); |
| 1712 | val |= new_val << c->reg_shift; |
| 1713 | clk_writel_delay(val, c->reg); |
| 1714 | c->div = divider_u71 + 2; |
| 1715 | c->mul = 2; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1716 | c->fixed_rate = rate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1717 | return 0; |
| 1718 | } |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1719 | } else if (c->flags & DIV_2) { |
| 1720 | c->fixed_rate = rate; |
| 1721 | return 0; |
| 1722 | } |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1723 | |
| 1724 | return -EINVAL; |
| 1725 | } |
| 1726 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1727 | static unsigned long tegra30_pll_div_clk_recalc_rate(struct clk_hw *hw, |
| 1728 | unsigned long parent_rate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1729 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1730 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1731 | u64 rate = parent_rate; |
| 1732 | |
| 1733 | if (c->flags & DIV_U71) { |
| 1734 | u32 divu71; |
| 1735 | u32 val = clk_readl(c->reg); |
| 1736 | val >>= c->reg_shift; |
| 1737 | |
| 1738 | divu71 = (val & PLL_OUT_RATIO_MASK) >> PLL_OUT_RATIO_SHIFT; |
| 1739 | c->div = (divu71 + 2); |
| 1740 | c->mul = 2; |
| 1741 | } else if (c->flags & DIV_2) { |
| 1742 | if (c->flags & (PLLD | PLLX)) { |
| 1743 | c->div = 2; |
| 1744 | c->mul = 1; |
| 1745 | } else |
| 1746 | BUG(); |
| 1747 | } else { |
| 1748 | c->div = 1; |
| 1749 | c->mul = 1; |
| 1750 | } |
| 1751 | if (c->mul != 0 && c->div != 0) { |
| 1752 | rate *= c->mul; |
| 1753 | rate += c->div - 1; /* round up */ |
| 1754 | do_div(rate, c->div); |
| 1755 | } |
| 1756 | |
| 1757 | return rate; |
| 1758 | } |
| 1759 | |
| 1760 | static long tegra30_pll_div_clk_round_rate(struct clk_hw *hw, |
| 1761 | unsigned long rate, unsigned long *prate) |
| 1762 | { |
| 1763 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1764 | unsigned long parent_rate = __clk_get_rate(__clk_get_parent(hw->clk)); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1765 | int divider; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1766 | |
| 1767 | if (prate) |
| 1768 | parent_rate = *prate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1769 | |
| 1770 | if (c->flags & DIV_U71) { |
| 1771 | divider = clk_div71_get_divider( |
| 1772 | parent_rate, rate, c->flags, ROUND_DIVIDER_UP); |
| 1773 | if (divider < 0) |
| 1774 | return divider; |
| 1775 | return DIV_ROUND_UP(parent_rate * 2, divider + 2); |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1776 | } else if (c->flags & DIV_2) { |
| 1777 | *prate = rate * 2; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1778 | return rate; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1779 | } |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1780 | |
| 1781 | return -EINVAL; |
| 1782 | } |
| 1783 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 1784 | struct clk_ops tegra30_pll_div_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1785 | .is_enabled = tegra30_pll_div_clk_is_enabled, |
| 1786 | .enable = tegra30_pll_div_clk_enable, |
| 1787 | .disable = tegra30_pll_div_clk_disable, |
| 1788 | .set_rate = tegra30_pll_div_clk_set_rate, |
| 1789 | .recalc_rate = tegra30_pll_div_clk_recalc_rate, |
| 1790 | .round_rate = tegra30_pll_div_clk_round_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1791 | }; |
| 1792 | |
| 1793 | /* Periph clk ops */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1794 | static inline u32 periph_clk_source_mask(struct clk_tegra *c) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1795 | { |
| 1796 | if (c->flags & MUX8) |
| 1797 | return 7 << 29; |
| 1798 | else if (c->flags & MUX_PWM) |
| 1799 | return 3 << 28; |
| 1800 | else if (c->flags & MUX_CLK_OUT) |
| 1801 | return 3 << (c->u.periph.clk_num + 4); |
| 1802 | else if (c->flags & PLLD) |
| 1803 | return PLLD_BASE_DSIB_MUX_MASK; |
| 1804 | else |
| 1805 | return 3 << 30; |
| 1806 | } |
| 1807 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1808 | static inline u32 periph_clk_source_shift(struct clk_tegra *c) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1809 | { |
| 1810 | if (c->flags & MUX8) |
| 1811 | return 29; |
| 1812 | else if (c->flags & MUX_PWM) |
| 1813 | return 28; |
| 1814 | else if (c->flags & MUX_CLK_OUT) |
| 1815 | return c->u.periph.clk_num + 4; |
| 1816 | else if (c->flags & PLLD) |
| 1817 | return PLLD_BASE_DSIB_MUX_SHIFT; |
| 1818 | else |
| 1819 | return 30; |
| 1820 | } |
| 1821 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1822 | static int tegra30_periph_clk_is_enabled(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1823 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1824 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1825 | |
| 1826 | c->state = ON; |
| 1827 | if (!(clk_readl(PERIPH_CLK_TO_ENB_REG(c)) & PERIPH_CLK_TO_BIT(c))) |
| 1828 | c->state = OFF; |
| 1829 | if (!(c->flags & PERIPH_NO_RESET)) |
| 1830 | if (clk_readl(PERIPH_CLK_TO_RST_REG(c)) & PERIPH_CLK_TO_BIT(c)) |
| 1831 | c->state = OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1832 | return c->state; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1835 | static int tegra30_periph_clk_enable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1836 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1837 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1838 | |
| 1839 | tegra_periph_clk_enable_refcount[c->u.periph.clk_num]++; |
| 1840 | if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 1) |
| 1841 | return 0; |
| 1842 | |
| 1843 | clk_writel_delay(PERIPH_CLK_TO_BIT(c), PERIPH_CLK_TO_ENB_SET_REG(c)); |
| 1844 | if (!(c->flags & PERIPH_NO_RESET) && |
| 1845 | !(c->flags & PERIPH_MANUAL_RESET)) { |
| 1846 | if (clk_readl(PERIPH_CLK_TO_RST_REG(c)) & |
| 1847 | PERIPH_CLK_TO_BIT(c)) { |
| 1848 | udelay(5); /* reset propagation delay */ |
| 1849 | clk_writel(PERIPH_CLK_TO_BIT(c), |
| 1850 | PERIPH_CLK_TO_RST_CLR_REG(c)); |
| 1851 | } |
| 1852 | } |
| 1853 | return 0; |
| 1854 | } |
| 1855 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1856 | static void tegra30_periph_clk_disable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1857 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1858 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1859 | unsigned long val; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1860 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1861 | tegra_periph_clk_enable_refcount[c->u.periph.clk_num]--; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1862 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1863 | if (tegra_periph_clk_enable_refcount[c->u.periph.clk_num] > 0) |
| 1864 | return; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1865 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1866 | /* If peripheral is in the APB bus then read the APB bus to |
| 1867 | * flush the write operation in apb bus. This will avoid the |
| 1868 | * peripheral access after disabling clock*/ |
| 1869 | if (c->flags & PERIPH_ON_APB) |
| 1870 | val = chipid_readl(); |
| 1871 | |
| 1872 | clk_writel_delay(PERIPH_CLK_TO_BIT(c), PERIPH_CLK_TO_ENB_CLR_REG(c)); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1873 | } |
| 1874 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1875 | void tegra30_periph_clk_reset(struct clk_hw *hw, bool assert) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1876 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1877 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1878 | unsigned long val; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1879 | |
| 1880 | if (!(c->flags & PERIPH_NO_RESET)) { |
| 1881 | if (assert) { |
| 1882 | /* If peripheral is in the APB bus then read the APB |
| 1883 | * bus to flush the write operation in apb bus. This |
| 1884 | * will avoid the peripheral access after disabling |
| 1885 | * clock */ |
| 1886 | if (c->flags & PERIPH_ON_APB) |
| 1887 | val = chipid_readl(); |
| 1888 | |
| 1889 | clk_writel(PERIPH_CLK_TO_BIT(c), |
| 1890 | PERIPH_CLK_TO_RST_SET_REG(c)); |
| 1891 | } else |
| 1892 | clk_writel(PERIPH_CLK_TO_BIT(c), |
| 1893 | PERIPH_CLK_TO_RST_CLR_REG(c)); |
| 1894 | } |
| 1895 | } |
| 1896 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1897 | static int tegra30_periph_clk_set_parent(struct clk_hw *hw, u8 index) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1898 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1899 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1900 | u32 val; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1901 | |
| 1902 | if (!(c->flags & MUX)) |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1903 | return (index == 0) ? 0 : (-EINVAL); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1904 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1905 | val = clk_readl(c->reg); |
| 1906 | val &= ~periph_clk_source_mask(c); |
| 1907 | val |= (index << periph_clk_source_shift(c)); |
| 1908 | clk_writel_delay(val, c->reg); |
| 1909 | return 0; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1912 | static u8 tegra30_periph_clk_get_parent(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1913 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1914 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1915 | u32 val = clk_readl(c->reg); |
| 1916 | int source = (val & periph_clk_source_mask(c)) >> |
| 1917 | periph_clk_source_shift(c); |
| 1918 | |
| 1919 | if (!(c->flags & MUX)) |
| 1920 | return 0; |
| 1921 | |
| 1922 | return source; |
| 1923 | } |
| 1924 | |
| 1925 | static int tegra30_periph_clk_set_rate(struct clk_hw *hw, unsigned long rate, |
| 1926 | unsigned long parent_rate) |
| 1927 | { |
| 1928 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1929 | u32 val; |
| 1930 | int divider; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1931 | |
| 1932 | if (c->flags & DIV_U71) { |
| 1933 | divider = clk_div71_get_divider( |
| 1934 | parent_rate, rate, c->flags, ROUND_DIVIDER_UP); |
| 1935 | if (divider >= 0) { |
| 1936 | val = clk_readl(c->reg); |
| 1937 | val &= ~PERIPH_CLK_SOURCE_DIVU71_MASK; |
| 1938 | val |= divider; |
| 1939 | if (c->flags & DIV_U71_UART) { |
| 1940 | if (divider) |
| 1941 | val |= PERIPH_CLK_UART_DIV_ENB; |
| 1942 | else |
| 1943 | val &= ~PERIPH_CLK_UART_DIV_ENB; |
| 1944 | } |
| 1945 | clk_writel_delay(val, c->reg); |
| 1946 | c->div = divider + 2; |
| 1947 | c->mul = 2; |
| 1948 | return 0; |
| 1949 | } |
| 1950 | } else if (c->flags & DIV_U16) { |
| 1951 | divider = clk_div16_get_divider(parent_rate, rate); |
| 1952 | if (divider >= 0) { |
| 1953 | val = clk_readl(c->reg); |
| 1954 | val &= ~PERIPH_CLK_SOURCE_DIVU16_MASK; |
| 1955 | val |= divider; |
| 1956 | clk_writel_delay(val, c->reg); |
| 1957 | c->div = divider + 1; |
| 1958 | c->mul = 1; |
| 1959 | return 0; |
| 1960 | } |
| 1961 | } else if (parent_rate <= rate) { |
| 1962 | c->div = 1; |
| 1963 | c->mul = 1; |
| 1964 | return 0; |
| 1965 | } |
| 1966 | return -EINVAL; |
| 1967 | } |
| 1968 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1969 | static long tegra30_periph_clk_round_rate(struct clk_hw *hw, unsigned long rate, |
| 1970 | unsigned long *prate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1971 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1972 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1973 | unsigned long parent_rate = __clk_get_rate(__clk_get_parent(hw->clk)); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1974 | int divider; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1975 | |
| 1976 | if (prate) |
| 1977 | parent_rate = *prate; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 1978 | |
| 1979 | if (c->flags & DIV_U71) { |
| 1980 | divider = clk_div71_get_divider( |
| 1981 | parent_rate, rate, c->flags, ROUND_DIVIDER_UP); |
| 1982 | if (divider < 0) |
| 1983 | return divider; |
| 1984 | |
| 1985 | return DIV_ROUND_UP(parent_rate * 2, divider + 2); |
| 1986 | } else if (c->flags & DIV_U16) { |
| 1987 | divider = clk_div16_get_divider(parent_rate, rate); |
| 1988 | if (divider < 0) |
| 1989 | return divider; |
| 1990 | return DIV_ROUND_UP(parent_rate, divider + 1); |
| 1991 | } |
| 1992 | return -EINVAL; |
| 1993 | } |
| 1994 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 1995 | static unsigned long tegra30_periph_clk_recalc_rate(struct clk_hw *hw, |
| 1996 | unsigned long parent_rate) |
| 1997 | { |
| 1998 | struct clk_tegra *c = to_clk_tegra(hw); |
| 1999 | u64 rate = parent_rate; |
| 2000 | u32 val = clk_readl(c->reg); |
| 2001 | |
| 2002 | if (c->flags & DIV_U71) { |
| 2003 | u32 divu71 = val & PERIPH_CLK_SOURCE_DIVU71_MASK; |
| 2004 | if ((c->flags & DIV_U71_UART) && |
| 2005 | (!(val & PERIPH_CLK_UART_DIV_ENB))) { |
| 2006 | divu71 = 0; |
| 2007 | } |
| 2008 | if (c->flags & DIV_U71_IDLE) { |
| 2009 | val &= ~(PERIPH_CLK_SOURCE_DIVU71_MASK << |
| 2010 | PERIPH_CLK_SOURCE_DIVIDLE_SHIFT); |
| 2011 | val |= (PERIPH_CLK_SOURCE_DIVIDLE_VAL << |
| 2012 | PERIPH_CLK_SOURCE_DIVIDLE_SHIFT); |
| 2013 | clk_writel(val, c->reg); |
| 2014 | } |
| 2015 | c->div = divu71 + 2; |
| 2016 | c->mul = 2; |
| 2017 | } else if (c->flags & DIV_U16) { |
| 2018 | u32 divu16 = val & PERIPH_CLK_SOURCE_DIVU16_MASK; |
| 2019 | c->div = divu16 + 1; |
| 2020 | c->mul = 1; |
| 2021 | } else { |
| 2022 | c->div = 1; |
| 2023 | c->mul = 1; |
| 2024 | } |
| 2025 | |
| 2026 | if (c->mul != 0 && c->div != 0) { |
| 2027 | rate *= c->mul; |
| 2028 | rate += c->div - 1; /* round up */ |
| 2029 | do_div(rate, c->div); |
| 2030 | } |
| 2031 | return rate; |
| 2032 | } |
| 2033 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 2034 | struct clk_ops tegra30_periph_clk_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2035 | .is_enabled = tegra30_periph_clk_is_enabled, |
| 2036 | .enable = tegra30_periph_clk_enable, |
| 2037 | .disable = tegra30_periph_clk_disable, |
| 2038 | .set_parent = tegra30_periph_clk_set_parent, |
| 2039 | .get_parent = tegra30_periph_clk_get_parent, |
| 2040 | .set_rate = tegra30_periph_clk_set_rate, |
| 2041 | .round_rate = tegra30_periph_clk_round_rate, |
| 2042 | .recalc_rate = tegra30_periph_clk_recalc_rate, |
| 2043 | }; |
| 2044 | |
| 2045 | static int tegra30_dsib_clk_set_parent(struct clk_hw *hw, u8 index) |
| 2046 | { |
| 2047 | struct clk *d = clk_get_sys(NULL, "pll_d"); |
| 2048 | /* The DSIB parent selection bit is in PLLD base |
| 2049 | register - can not do direct r-m-w, must be |
| 2050 | protected by PLLD lock */ |
| 2051 | tegra_clk_cfg_ex( |
| 2052 | d, TEGRA_CLK_PLLD_MIPI_MUX_SEL, index); |
| 2053 | |
| 2054 | return 0; |
| 2055 | } |
| 2056 | |
| 2057 | struct clk_ops tegra30_dsib_clk_ops = { |
| 2058 | .is_enabled = tegra30_periph_clk_is_enabled, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2059 | .enable = &tegra30_periph_clk_enable, |
| 2060 | .disable = &tegra30_periph_clk_disable, |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2061 | .set_parent = &tegra30_dsib_clk_set_parent, |
| 2062 | .get_parent = &tegra30_periph_clk_get_parent, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2063 | .set_rate = &tegra30_periph_clk_set_rate, |
| 2064 | .round_rate = &tegra30_periph_clk_round_rate, |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2065 | .recalc_rate = &tegra30_periph_clk_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2066 | }; |
| 2067 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2068 | /* Periph extended clock configuration ops */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2069 | int tegra30_vi_clk_cfg_ex(struct clk_hw *hw, |
| 2070 | enum tegra_clk_ex_param p, u32 setting) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2071 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2072 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2073 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2074 | if (p == TEGRA_CLK_VI_INP_SEL) { |
| 2075 | u32 val = clk_readl(c->reg); |
| 2076 | val &= ~PERIPH_CLK_VI_SEL_EX_MASK; |
| 2077 | val |= (setting << PERIPH_CLK_VI_SEL_EX_SHIFT) & |
| 2078 | PERIPH_CLK_VI_SEL_EX_MASK; |
| 2079 | clk_writel(val, c->reg); |
| 2080 | return 0; |
| 2081 | } |
| 2082 | return -EINVAL; |
| 2083 | } |
| 2084 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2085 | int tegra30_nand_clk_cfg_ex(struct clk_hw *hw, |
| 2086 | enum tegra_clk_ex_param p, u32 setting) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2087 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2088 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2089 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2090 | if (p == TEGRA_CLK_NAND_PAD_DIV2_ENB) { |
| 2091 | u32 val = clk_readl(c->reg); |
| 2092 | if (setting) |
| 2093 | val |= PERIPH_CLK_NAND_DIV_EX_ENB; |
| 2094 | else |
| 2095 | val &= ~PERIPH_CLK_NAND_DIV_EX_ENB; |
| 2096 | clk_writel(val, c->reg); |
| 2097 | return 0; |
| 2098 | } |
| 2099 | return -EINVAL; |
| 2100 | } |
| 2101 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2102 | int tegra30_dtv_clk_cfg_ex(struct clk_hw *hw, |
| 2103 | enum tegra_clk_ex_param p, u32 setting) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2104 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2105 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2106 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2107 | if (p == TEGRA_CLK_DTV_INVERT) { |
| 2108 | u32 val = clk_readl(c->reg); |
| 2109 | if (setting) |
| 2110 | val |= PERIPH_CLK_DTV_POLARITY_INV; |
| 2111 | else |
| 2112 | val &= ~PERIPH_CLK_DTV_POLARITY_INV; |
| 2113 | clk_writel(val, c->reg); |
| 2114 | return 0; |
| 2115 | } |
| 2116 | return -EINVAL; |
| 2117 | } |
| 2118 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2119 | /* Output clock ops */ |
| 2120 | |
| 2121 | static DEFINE_SPINLOCK(clk_out_lock); |
| 2122 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2123 | static int tegra30_clk_out_is_enabled(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2124 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2125 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2126 | u32 val = pmc_readl(c->reg); |
| 2127 | |
| 2128 | c->state = (val & (0x1 << c->u.periph.clk_num)) ? ON : OFF; |
| 2129 | c->mul = 1; |
| 2130 | c->div = 1; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2131 | return c->state; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2134 | static int tegra30_clk_out_enable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2135 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2136 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2137 | u32 val; |
| 2138 | unsigned long flags; |
| 2139 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2140 | spin_lock_irqsave(&clk_out_lock, flags); |
| 2141 | val = pmc_readl(c->reg); |
| 2142 | val |= (0x1 << c->u.periph.clk_num); |
| 2143 | pmc_writel(val, c->reg); |
| 2144 | spin_unlock_irqrestore(&clk_out_lock, flags); |
| 2145 | |
| 2146 | return 0; |
| 2147 | } |
| 2148 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2149 | static void tegra30_clk_out_disable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2150 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2151 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2152 | u32 val; |
| 2153 | unsigned long flags; |
| 2154 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2155 | spin_lock_irqsave(&clk_out_lock, flags); |
| 2156 | val = pmc_readl(c->reg); |
| 2157 | val &= ~(0x1 << c->u.periph.clk_num); |
| 2158 | pmc_writel(val, c->reg); |
| 2159 | spin_unlock_irqrestore(&clk_out_lock, flags); |
| 2160 | } |
| 2161 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2162 | static int tegra30_clk_out_set_parent(struct clk_hw *hw, u8 index) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2163 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2164 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2165 | u32 val; |
| 2166 | unsigned long flags; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2167 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2168 | spin_lock_irqsave(&clk_out_lock, flags); |
| 2169 | val = pmc_readl(c->reg); |
| 2170 | val &= ~periph_clk_source_mask(c); |
| 2171 | val |= (index << periph_clk_source_shift(c)); |
| 2172 | pmc_writel(val, c->reg); |
| 2173 | spin_unlock_irqrestore(&clk_out_lock, flags); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2174 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2175 | return 0; |
| 2176 | } |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2177 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2178 | static u8 tegra30_clk_out_get_parent(struct clk_hw *hw) |
| 2179 | { |
| 2180 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2181 | u32 val = pmc_readl(c->reg); |
| 2182 | int source; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2183 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2184 | source = (val & periph_clk_source_mask(c)) >> |
| 2185 | periph_clk_source_shift(c); |
| 2186 | return source; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 2189 | struct clk_ops tegra_clk_out_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2190 | .is_enabled = tegra30_clk_out_is_enabled, |
| 2191 | .enable = tegra30_clk_out_enable, |
| 2192 | .disable = tegra30_clk_out_disable, |
| 2193 | .set_parent = tegra30_clk_out_set_parent, |
| 2194 | .get_parent = tegra30_clk_out_get_parent, |
| 2195 | .recalc_rate = tegra30_clk_fixed_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2196 | }; |
| 2197 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2198 | /* Clock doubler ops */ |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2199 | static int tegra30_clk_double_is_enabled(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2200 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2201 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2202 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2203 | c->state = ON; |
| 2204 | if (!(clk_readl(PERIPH_CLK_TO_ENB_REG(c)) & PERIPH_CLK_TO_BIT(c))) |
| 2205 | c->state = OFF; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2206 | return c->state; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2207 | }; |
| 2208 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2209 | static int tegra30_clk_double_set_rate(struct clk_hw *hw, unsigned long rate, |
| 2210 | unsigned long parent_rate) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2211 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2212 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2213 | u32 val; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2214 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2215 | if (rate == parent_rate) { |
| 2216 | val = clk_readl(c->reg) | (0x1 << c->reg_shift); |
| 2217 | clk_writel(val, c->reg); |
| 2218 | c->mul = 1; |
| 2219 | c->div = 1; |
| 2220 | return 0; |
| 2221 | } else if (rate == 2 * parent_rate) { |
| 2222 | val = clk_readl(c->reg) & (~(0x1 << c->reg_shift)); |
| 2223 | clk_writel(val, c->reg); |
| 2224 | c->mul = 2; |
| 2225 | c->div = 1; |
| 2226 | return 0; |
| 2227 | } |
| 2228 | return -EINVAL; |
| 2229 | } |
| 2230 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2231 | static unsigned long tegra30_clk_double_recalc_rate(struct clk_hw *hw, |
| 2232 | unsigned long parent_rate) |
| 2233 | { |
| 2234 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2235 | u64 rate = parent_rate; |
| 2236 | |
| 2237 | u32 val = clk_readl(c->reg); |
| 2238 | c->mul = val & (0x1 << c->reg_shift) ? 1 : 2; |
| 2239 | c->div = 1; |
| 2240 | |
| 2241 | if (c->mul != 0 && c->div != 0) { |
| 2242 | rate *= c->mul; |
| 2243 | rate += c->div - 1; /* round up */ |
| 2244 | do_div(rate, c->div); |
| 2245 | } |
| 2246 | |
| 2247 | return rate; |
| 2248 | } |
| 2249 | |
| 2250 | static long tegra30_clk_double_round_rate(struct clk_hw *hw, unsigned long rate, |
| 2251 | unsigned long *prate) |
| 2252 | { |
| 2253 | unsigned long output_rate = *prate; |
| 2254 | |
| 2255 | do_div(output_rate, 2); |
| 2256 | return output_rate; |
| 2257 | } |
| 2258 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 2259 | struct clk_ops tegra30_clk_double_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2260 | .is_enabled = tegra30_clk_double_is_enabled, |
| 2261 | .enable = tegra30_periph_clk_enable, |
| 2262 | .disable = tegra30_periph_clk_disable, |
| 2263 | .recalc_rate = tegra30_clk_double_recalc_rate, |
| 2264 | .round_rate = tegra30_clk_double_round_rate, |
| 2265 | .set_rate = tegra30_clk_double_set_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2266 | }; |
| 2267 | |
| 2268 | /* Audio sync clock ops */ |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 2269 | struct clk_ops tegra_sync_source_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2270 | .recalc_rate = tegra30_clk_fixed_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2271 | }; |
| 2272 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2273 | static int tegra30_audio_sync_clk_is_enabled(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2274 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2275 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2276 | u32 val = clk_readl(c->reg); |
| 2277 | c->state = (val & AUDIO_SYNC_DISABLE_BIT) ? OFF : ON; |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2278 | return c->state; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2279 | } |
| 2280 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2281 | static int tegra30_audio_sync_clk_enable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2282 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2283 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2284 | u32 val = clk_readl(c->reg); |
| 2285 | clk_writel((val & (~AUDIO_SYNC_DISABLE_BIT)), c->reg); |
| 2286 | return 0; |
| 2287 | } |
| 2288 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2289 | static void tegra30_audio_sync_clk_disable(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2290 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2291 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2292 | u32 val = clk_readl(c->reg); |
| 2293 | clk_writel((val | AUDIO_SYNC_DISABLE_BIT), c->reg); |
| 2294 | } |
| 2295 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2296 | static int tegra30_audio_sync_clk_set_parent(struct clk_hw *hw, u8 index) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2297 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2298 | struct clk_tegra *c = to_clk_tegra(hw); |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2299 | u32 val; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2300 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2301 | val = clk_readl(c->reg); |
| 2302 | val &= ~AUDIO_SYNC_SOURCE_MASK; |
| 2303 | val |= index; |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2304 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2305 | clk_writel(val, c->reg); |
| 2306 | return 0; |
| 2307 | } |
| 2308 | |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2309 | static u8 tegra30_audio_sync_clk_get_parent(struct clk_hw *hw) |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2310 | { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2311 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2312 | u32 val = clk_readl(c->reg); |
| 2313 | int source; |
| 2314 | |
| 2315 | source = val & AUDIO_SYNC_SOURCE_MASK; |
| 2316 | return source; |
| 2317 | } |
| 2318 | |
| 2319 | struct clk_ops tegra30_audio_sync_clk_ops = { |
| 2320 | .is_enabled = tegra30_audio_sync_clk_is_enabled, |
| 2321 | .enable = tegra30_audio_sync_clk_enable, |
| 2322 | .disable = tegra30_audio_sync_clk_disable, |
| 2323 | .set_parent = tegra30_audio_sync_clk_set_parent, |
| 2324 | .get_parent = tegra30_audio_sync_clk_get_parent, |
| 2325 | .recalc_rate = tegra30_clk_fixed_recalc_rate, |
| 2326 | }; |
| 2327 | |
| 2328 | /* cml0 (pcie), and cml1 (sata) clock ops */ |
| 2329 | static int tegra30_cml_clk_is_enabled(struct clk_hw *hw) |
| 2330 | { |
| 2331 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2332 | u32 val = clk_readl(c->reg); |
| 2333 | c->state = val & (0x1 << c->u.periph.clk_num) ? ON : OFF; |
| 2334 | return c->state; |
| 2335 | } |
| 2336 | |
| 2337 | static int tegra30_cml_clk_enable(struct clk_hw *hw) |
| 2338 | { |
| 2339 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2340 | |
| 2341 | u32 val = clk_readl(c->reg); |
| 2342 | val |= (0x1 << c->u.periph.clk_num); |
| 2343 | clk_writel(val, c->reg); |
| 2344 | |
| 2345 | return 0; |
| 2346 | } |
| 2347 | |
| 2348 | static void tegra30_cml_clk_disable(struct clk_hw *hw) |
| 2349 | { |
| 2350 | struct clk_tegra *c = to_clk_tegra(hw); |
| 2351 | |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2352 | u32 val = clk_readl(c->reg); |
| 2353 | val &= ~(0x1 << c->u.periph.clk_num); |
| 2354 | clk_writel(val, c->reg); |
| 2355 | } |
| 2356 | |
Prashant Gaikwad | 88e790a | 2012-08-06 11:57:39 +0530 | [diff] [blame] | 2357 | struct clk_ops tegra_cml_clk_ops = { |
Prashant Gaikwad | 92fe58f | 2012-08-06 11:57:43 +0530 | [diff] [blame] | 2358 | .is_enabled = tegra30_cml_clk_is_enabled, |
| 2359 | .enable = tegra30_cml_clk_enable, |
| 2360 | .disable = tegra30_cml_clk_disable, |
| 2361 | .recalc_rate = tegra30_clk_fixed_recalc_rate, |
| 2362 | }; |
| 2363 | |
| 2364 | struct clk_ops tegra_pciex_clk_ops = { |
| 2365 | .recalc_rate = tegra30_clk_fixed_recalc_rate, |
Peter De Schrijver | d9cc6f7 | 2012-01-09 05:35:12 +0000 | [diff] [blame] | 2366 | }; |
Joseph Lo | dab403e | 2012-08-16 17:31:48 +0800 | [diff] [blame] | 2367 | |
| 2368 | /* Tegra30 CPU clock and reset control functions */ |
| 2369 | static void tegra30_wait_cpu_in_reset(u32 cpu) |
| 2370 | { |
| 2371 | unsigned int reg; |
| 2372 | |
| 2373 | do { |
| 2374 | reg = readl(reg_clk_base + |
| 2375 | TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS); |
| 2376 | cpu_relax(); |
| 2377 | } while (!(reg & (1 << cpu))); /* check CPU been reset or not */ |
| 2378 | |
| 2379 | return; |
| 2380 | } |
| 2381 | |
| 2382 | static void tegra30_put_cpu_in_reset(u32 cpu) |
| 2383 | { |
| 2384 | writel(CPU_RESET(cpu), |
| 2385 | reg_clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_SET); |
| 2386 | dmb(); |
| 2387 | } |
| 2388 | |
| 2389 | static void tegra30_cpu_out_of_reset(u32 cpu) |
| 2390 | { |
| 2391 | writel(CPU_RESET(cpu), |
| 2392 | reg_clk_base + TEGRA_CLK_RST_CONTROLLER_RST_CPU_CMPLX_CLR); |
| 2393 | wmb(); |
| 2394 | } |
| 2395 | |
| 2396 | static void tegra30_enable_cpu_clock(u32 cpu) |
| 2397 | { |
| 2398 | unsigned int reg; |
| 2399 | |
| 2400 | writel(CPU_CLOCK(cpu), |
| 2401 | reg_clk_base + TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR); |
| 2402 | reg = readl(reg_clk_base + |
| 2403 | TEGRA30_CLK_RST_CONTROLLER_CLK_CPU_CMPLX_CLR); |
| 2404 | } |
| 2405 | |
| 2406 | static void tegra30_disable_cpu_clock(u32 cpu) |
| 2407 | { |
| 2408 | |
| 2409 | unsigned int reg; |
| 2410 | |
| 2411 | reg = readl(reg_clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 2412 | writel(reg | CPU_CLOCK(cpu), |
| 2413 | reg_clk_base + TEGRA_CLK_RST_CONTROLLER_CLK_CPU_CMPLX); |
| 2414 | } |
| 2415 | |
Joseph Lo | a6e293e | 2012-10-31 17:41:19 +0800 | [diff] [blame^] | 2416 | #ifdef CONFIG_PM_SLEEP |
| 2417 | static bool tegra30_cpu_rail_off_ready(void) |
| 2418 | { |
| 2419 | unsigned int cpu_rst_status; |
| 2420 | int cpu_pwr_status; |
| 2421 | |
| 2422 | cpu_rst_status = readl(reg_clk_base + |
| 2423 | TEGRA30_CLK_RST_CONTROLLER_CPU_CMPLX_STATUS); |
| 2424 | cpu_pwr_status = tegra_powergate_is_powered(TEGRA_POWERGATE_CPU1) || |
| 2425 | tegra_powergate_is_powered(TEGRA_POWERGATE_CPU2) || |
| 2426 | tegra_powergate_is_powered(TEGRA_POWERGATE_CPU3); |
| 2427 | |
| 2428 | if (((cpu_rst_status & 0xE) != 0xE) || cpu_pwr_status) |
| 2429 | return false; |
| 2430 | |
| 2431 | return true; |
| 2432 | } |
| 2433 | |
| 2434 | static void tegra30_cpu_clock_suspend(void) |
| 2435 | { |
| 2436 | /* switch coresite to clk_m, save off original source */ |
| 2437 | tegra30_cpu_clk_sctx.clk_csite_src = |
| 2438 | readl(reg_clk_base + CLK_RESET_SOURCE_CSITE); |
| 2439 | writel(3<<30, reg_clk_base + CLK_RESET_SOURCE_CSITE); |
| 2440 | |
| 2441 | tegra30_cpu_clk_sctx.cpu_burst = |
| 2442 | readl(reg_clk_base + CLK_RESET_CCLK_BURST); |
| 2443 | tegra30_cpu_clk_sctx.pllx_base = |
| 2444 | readl(reg_clk_base + CLK_RESET_PLLX_BASE); |
| 2445 | tegra30_cpu_clk_sctx.pllx_misc = |
| 2446 | readl(reg_clk_base + CLK_RESET_PLLX_MISC); |
| 2447 | tegra30_cpu_clk_sctx.cclk_divider = |
| 2448 | readl(reg_clk_base + CLK_RESET_CCLK_DIVIDER); |
| 2449 | } |
| 2450 | |
| 2451 | static void tegra30_cpu_clock_resume(void) |
| 2452 | { |
| 2453 | unsigned int reg, policy; |
| 2454 | |
| 2455 | /* Is CPU complex already running on PLLX? */ |
| 2456 | reg = readl(reg_clk_base + CLK_RESET_CCLK_BURST); |
| 2457 | policy = (reg >> CLK_RESET_CCLK_BURST_POLICY_SHIFT) & 0xF; |
| 2458 | |
| 2459 | if (policy == CLK_RESET_CCLK_IDLE_POLICY) |
| 2460 | reg = (reg >> CLK_RESET_CCLK_IDLE_POLICY_SHIFT) & 0xF; |
| 2461 | else if (policy == CLK_RESET_CCLK_RUN_POLICY) |
| 2462 | reg = (reg >> CLK_RESET_CCLK_RUN_POLICY_SHIFT) & 0xF; |
| 2463 | else |
| 2464 | BUG(); |
| 2465 | |
| 2466 | if (reg != CLK_RESET_CCLK_BURST_POLICY_PLLX) { |
| 2467 | /* restore PLLX settings if CPU is on different PLL */ |
| 2468 | writel(tegra30_cpu_clk_sctx.pllx_misc, |
| 2469 | reg_clk_base + CLK_RESET_PLLX_MISC); |
| 2470 | writel(tegra30_cpu_clk_sctx.pllx_base, |
| 2471 | reg_clk_base + CLK_RESET_PLLX_BASE); |
| 2472 | |
| 2473 | /* wait for PLL stabilization if PLLX was enabled */ |
| 2474 | if (tegra30_cpu_clk_sctx.pllx_base & (1 << 30)) |
| 2475 | udelay(300); |
| 2476 | } |
| 2477 | |
| 2478 | /* |
| 2479 | * Restore original burst policy setting for calls resulting from CPU |
| 2480 | * LP2 in idle or system suspend. |
| 2481 | */ |
| 2482 | writel(tegra30_cpu_clk_sctx.cclk_divider, |
| 2483 | reg_clk_base + CLK_RESET_CCLK_DIVIDER); |
| 2484 | writel(tegra30_cpu_clk_sctx.cpu_burst, |
| 2485 | reg_clk_base + CLK_RESET_CCLK_BURST); |
| 2486 | |
| 2487 | writel(tegra30_cpu_clk_sctx.clk_csite_src, |
| 2488 | reg_clk_base + CLK_RESET_SOURCE_CSITE); |
| 2489 | } |
| 2490 | #endif |
| 2491 | |
Joseph Lo | dab403e | 2012-08-16 17:31:48 +0800 | [diff] [blame] | 2492 | static struct tegra_cpu_car_ops tegra30_cpu_car_ops = { |
| 2493 | .wait_for_reset = tegra30_wait_cpu_in_reset, |
| 2494 | .put_in_reset = tegra30_put_cpu_in_reset, |
| 2495 | .out_of_reset = tegra30_cpu_out_of_reset, |
| 2496 | .enable_clock = tegra30_enable_cpu_clock, |
| 2497 | .disable_clock = tegra30_disable_cpu_clock, |
Joseph Lo | a6e293e | 2012-10-31 17:41:19 +0800 | [diff] [blame^] | 2498 | #ifdef CONFIG_PM_SLEEP |
| 2499 | .rail_off_ready = tegra30_cpu_rail_off_ready, |
| 2500 | .suspend = tegra30_cpu_clock_suspend, |
| 2501 | .resume = tegra30_cpu_clock_resume, |
| 2502 | #endif |
Joseph Lo | dab403e | 2012-08-16 17:31:48 +0800 | [diff] [blame] | 2503 | }; |
| 2504 | |
| 2505 | void __init tegra30_cpu_car_ops_init(void) |
| 2506 | { |
| 2507 | tegra_cpu_car_ops = &tegra30_cpu_car_ops; |
| 2508 | } |