Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (C) 2007 Google, Inc. |
Trilok Soni | ef18f6c | 2012-03-07 12:33:40 +0530 | [diff] [blame] | 4 | * Copyright (c) 2007-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software is licensed under the terms of the GNU General Public |
| 7 | * License version 2, as published by the Free Software Foundation, and |
| 8 | * may be copied, distributed, and modified under those terms. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/version.h> |
| 18 | #include <linux/kernel.h> |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 19 | #include <linux/module.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/clk.h> |
| 25 | #include <linux/cpufreq.h> |
| 26 | #include <linux/mutex.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/sort.h> |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 29 | #include <linux/platform_device.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | #include <mach/board.h> |
| 31 | #include <mach/msm_iomap.h> |
| 32 | #include <asm/mach-types.h> |
| 33 | |
| 34 | #include "smd_private.h" |
| 35 | #include "clock.h" |
| 36 | #include "acpuclock.h" |
| 37 | #include "spm.h" |
| 38 | |
Taniya Das | 298de8c | 2012-02-16 11:45:31 +0530 | [diff] [blame] | 39 | #define SCSS_CLK_CTL_ADDR (MSM_ACC0_BASE + 0x04) |
| 40 | #define SCSS_CLK_SEL_ADDR (MSM_ACC0_BASE + 0x08) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 41 | |
| 42 | #define PLL2_L_VAL_ADDR (MSM_CLK_CTL_BASE + 0x33C) |
| 43 | #define PLL2_M_VAL_ADDR (MSM_CLK_CTL_BASE + 0x340) |
| 44 | #define PLL2_N_VAL_ADDR (MSM_CLK_CTL_BASE + 0x344) |
| 45 | #define PLL2_CONFIG_ADDR (MSM_CLK_CTL_BASE + 0x34C) |
| 46 | |
| 47 | #define VREF_SEL 1 /* 0: 0.625V (50mV step), 1: 0.3125V (25mV step). */ |
| 48 | #define V_STEP (25 * (2 - VREF_SEL)) /* Minimum voltage step size. */ |
| 49 | #define VREG_DATA (VREG_CONFIG | (VREF_SEL << 5)) |
| 50 | #define VREG_CONFIG (BIT(7) | BIT(6)) /* Enable VREG, pull-down if disabled. */ |
| 51 | /* Cause a compile error if the voltage is not a multiple of the step size. */ |
| 52 | #define MV(mv) ((mv) / (!((mv) % V_STEP))) |
| 53 | /* mv = (750mV + (raw * 25mV)) * (2 - VREF_SEL) */ |
| 54 | #define VDD_RAW(mv) (((MV(mv) / V_STEP) - 30) | VREG_DATA) |
| 55 | |
| 56 | #define MAX_AXI_KHZ 192000 |
| 57 | |
| 58 | struct clock_state { |
| 59 | struct clkctl_acpu_speed *current_speed; |
| 60 | struct mutex lock; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 61 | struct clk *ebi1_clk; |
| 62 | }; |
| 63 | |
| 64 | struct pll { |
| 65 | unsigned int l; |
| 66 | unsigned int m; |
| 67 | unsigned int n; |
| 68 | unsigned int pre_div; |
| 69 | }; |
| 70 | |
| 71 | struct clkctl_acpu_speed { |
| 72 | unsigned int use_for_scaling; |
| 73 | unsigned int acpu_clk_khz; |
| 74 | int src; |
| 75 | unsigned int acpu_src_sel; |
| 76 | unsigned int acpu_src_div; |
| 77 | unsigned int axi_clk_hz; |
| 78 | unsigned int vdd_mv; |
| 79 | unsigned int vdd_raw; |
| 80 | struct pll *pll_rate; |
Taniya Das | bb0b6db | 2012-03-19 14:09:55 +0530 | [diff] [blame] | 81 | unsigned long lpj; /* loops_per_jiffy */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | static struct clock_state drv_state = { 0 }; |
| 85 | |
| 86 | /* Switch to this when reprogramming PLL2 */ |
| 87 | static struct clkctl_acpu_speed *backup_s; |
| 88 | |
| 89 | static struct pll pll2_tbl[] = { |
| 90 | { 42, 0, 1, 0 }, /* 806 MHz */ |
| 91 | { 53, 1, 3, 0 }, /* 1024 MHz */ |
| 92 | { 125, 0, 1, 1 }, /* 1200 MHz */ |
| 93 | { 73, 0, 1, 0 }, /* 1401 MHz */ |
| 94 | }; |
| 95 | |
| 96 | /* Use negative numbers for sources that can't be enabled/disabled */ |
| 97 | |
| 98 | enum acpuclk_source { |
| 99 | LPXO = -2, |
| 100 | AXI = -1, |
| 101 | PLL_0 = 0, |
| 102 | PLL_1, |
| 103 | PLL_2, |
| 104 | PLL_3, |
| 105 | MAX_SOURCE |
| 106 | }; |
| 107 | |
| 108 | static struct clk *acpuclk_sources[MAX_SOURCE]; |
| 109 | |
| 110 | /* |
| 111 | * Each ACPU frequency has a certain minimum MSMC1 voltage requirement |
| 112 | * that is implicitly met by voting for a specific minimum AXI frequency. |
| 113 | * Do NOT change the AXI frequency unless you are _absoulutely_ sure you |
| 114 | * know all the h/w requirements. |
| 115 | */ |
| 116 | static struct clkctl_acpu_speed acpu_freq_tbl[] = { |
| 117 | { 0, 24576, LPXO, 0, 0, 30720000, 900, VDD_RAW(900) }, |
| 118 | { 0, 61440, PLL_3, 5, 11, 61440000, 900, VDD_RAW(900) }, |
| 119 | { 1, 122880, PLL_3, 5, 5, 61440000, 900, VDD_RAW(900) }, |
| 120 | { 0, 184320, PLL_3, 5, 4, 61440000, 900, VDD_RAW(900) }, |
| 121 | { 0, MAX_AXI_KHZ, AXI, 1, 0, 61440000, 900, VDD_RAW(900) }, |
| 122 | { 1, 245760, PLL_3, 5, 2, 61440000, 900, VDD_RAW(900) }, |
| 123 | { 1, 368640, PLL_3, 5, 1, 122800000, 900, VDD_RAW(900) }, |
| 124 | /* AXI has MSMC1 implications. See above. */ |
| 125 | { 1, 768000, PLL_1, 2, 0, 153600000, 1050, VDD_RAW(1050) }, |
| 126 | /* |
| 127 | * AXI has MSMC1 implications. See above. |
| 128 | */ |
| 129 | { 1, 806400, PLL_2, 3, 0, UINT_MAX, 1100, VDD_RAW(1100), &pll2_tbl[0]}, |
| 130 | { 1, 1024000, PLL_2, 3, 0, UINT_MAX, 1200, VDD_RAW(1200), &pll2_tbl[1]}, |
| 131 | { 1, 1200000, PLL_2, 3, 0, UINT_MAX, 1200, VDD_RAW(1200), &pll2_tbl[2]}, |
| 132 | { 1, 1401600, PLL_2, 3, 0, UINT_MAX, 1250, VDD_RAW(1250), &pll2_tbl[3]}, |
| 133 | { 0 } |
| 134 | }; |
| 135 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 136 | static int acpuclk_set_acpu_vdd(struct clkctl_acpu_speed *s) |
| 137 | { |
| 138 | int ret = msm_spm_set_vdd(0, s->vdd_raw); |
| 139 | if (ret) |
| 140 | return ret; |
| 141 | |
| 142 | /* Wait for voltage to stabilize. */ |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 143 | udelay(62); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | /* Assumes PLL2 is off and the acpuclock isn't sourced from PLL2 */ |
| 148 | static void acpuclk_config_pll2(struct pll *pll) |
| 149 | { |
| 150 | uint32_t config = readl_relaxed(PLL2_CONFIG_ADDR); |
| 151 | |
| 152 | /* Make sure write to disable PLL_2 has completed |
| 153 | * before reconfiguring that PLL. */ |
| 154 | mb(); |
| 155 | writel_relaxed(pll->l, PLL2_L_VAL_ADDR); |
| 156 | writel_relaxed(pll->m, PLL2_M_VAL_ADDR); |
| 157 | writel_relaxed(pll->n, PLL2_N_VAL_ADDR); |
| 158 | if (pll->pre_div) |
| 159 | config |= BIT(15); |
| 160 | else |
| 161 | config &= ~BIT(15); |
| 162 | writel_relaxed(config, PLL2_CONFIG_ADDR); |
| 163 | /* Make sure PLL is programmed before returning. */ |
| 164 | mb(); |
| 165 | } |
| 166 | |
| 167 | /* Set clock source and divider given a clock speed */ |
| 168 | static void acpuclk_set_src(const struct clkctl_acpu_speed *s) |
| 169 | { |
| 170 | uint32_t reg_clksel, reg_clkctl, src_sel; |
| 171 | |
| 172 | reg_clksel = readl_relaxed(SCSS_CLK_SEL_ADDR); |
| 173 | |
| 174 | /* CLK_SEL_SRC1NO */ |
| 175 | src_sel = reg_clksel & 1; |
| 176 | |
| 177 | /* Program clock source and divider. */ |
| 178 | reg_clkctl = readl_relaxed(SCSS_CLK_CTL_ADDR); |
| 179 | reg_clkctl &= ~(0xFF << (8 * src_sel)); |
| 180 | reg_clkctl |= s->acpu_src_sel << (4 + 8 * src_sel); |
| 181 | reg_clkctl |= s->acpu_src_div << (0 + 8 * src_sel); |
| 182 | writel_relaxed(reg_clkctl, SCSS_CLK_CTL_ADDR); |
| 183 | |
| 184 | /* Toggle clock source. */ |
| 185 | reg_clksel ^= 1; |
| 186 | |
| 187 | /* Program clock source selection. */ |
| 188 | writel_relaxed(reg_clksel, SCSS_CLK_SEL_ADDR); |
| 189 | |
| 190 | /* Make sure switch to new source is complete. */ |
| 191 | mb(); |
| 192 | } |
| 193 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 194 | static int acpuclk_7x30_set_rate(int cpu, unsigned long rate, |
| 195 | enum setrate_reason reason) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 196 | { |
| 197 | struct clkctl_acpu_speed *tgt_s, *strt_s; |
| 198 | int res, rc = 0; |
| 199 | |
| 200 | if (reason == SETRATE_CPUFREQ) |
| 201 | mutex_lock(&drv_state.lock); |
| 202 | |
| 203 | strt_s = drv_state.current_speed; |
| 204 | |
| 205 | if (rate == strt_s->acpu_clk_khz) |
| 206 | goto out; |
| 207 | |
| 208 | for (tgt_s = acpu_freq_tbl; tgt_s->acpu_clk_khz != 0; tgt_s++) { |
| 209 | if (tgt_s->acpu_clk_khz == rate) |
| 210 | break; |
| 211 | } |
| 212 | if (tgt_s->acpu_clk_khz == 0) { |
| 213 | rc = -EINVAL; |
| 214 | goto out; |
| 215 | } |
| 216 | |
| 217 | if (reason == SETRATE_CPUFREQ) { |
| 218 | /* Increase VDD if needed. */ |
| 219 | if (tgt_s->vdd_mv > strt_s->vdd_mv) { |
| 220 | rc = acpuclk_set_acpu_vdd(tgt_s); |
| 221 | if (rc < 0) { |
| 222 | pr_err("ACPU VDD increase to %d mV failed " |
| 223 | "(%d)\n", tgt_s->vdd_mv, rc); |
| 224 | goto out; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | pr_debug("Switching from ACPU rate %u KHz -> %u KHz\n", |
| 230 | strt_s->acpu_clk_khz, tgt_s->acpu_clk_khz); |
| 231 | |
| 232 | /* Increase the AXI bus frequency if needed. This must be done before |
| 233 | * increasing the ACPU frequency, since voting for high AXI rates |
| 234 | * implicitly takes care of increasing the MSMC1 voltage, as needed. */ |
| 235 | if (tgt_s->axi_clk_hz > strt_s->axi_clk_hz) { |
Matt Wagantall | e0eecf0 | 2011-11-08 14:07:54 -0800 | [diff] [blame] | 236 | rc = clk_set_rate(drv_state.ebi1_clk, tgt_s->axi_clk_hz); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 237 | if (rc < 0) { |
| 238 | pr_err("Setting AXI min rate failed (%d)\n", rc); |
| 239 | goto out; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /* Move off of PLL2 if we're reprogramming it */ |
| 244 | if (tgt_s->src == PLL_2 && strt_s->src == PLL_2) { |
| 245 | clk_enable(acpuclk_sources[backup_s->src]); |
| 246 | acpuclk_set_src(backup_s); |
| 247 | clk_disable(acpuclk_sources[strt_s->src]); |
| 248 | } |
| 249 | |
| 250 | /* Reconfigure PLL2 if we're moving to it */ |
| 251 | if (tgt_s->src == PLL_2) |
| 252 | acpuclk_config_pll2(tgt_s->pll_rate); |
| 253 | |
| 254 | /* Make sure target PLL is on. */ |
| 255 | if ((strt_s->src != tgt_s->src && tgt_s->src >= 0) || |
| 256 | (tgt_s->src == PLL_2 && strt_s->src == PLL_2)) { |
| 257 | pr_debug("Enabling PLL %d\n", tgt_s->src); |
| 258 | clk_enable(acpuclk_sources[tgt_s->src]); |
| 259 | } |
| 260 | |
| 261 | /* Perform the frequency switch */ |
| 262 | acpuclk_set_src(tgt_s); |
| 263 | drv_state.current_speed = tgt_s; |
Taniya Das | bb0b6db | 2012-03-19 14:09:55 +0530 | [diff] [blame] | 264 | loops_per_jiffy = tgt_s->lpj; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 265 | |
| 266 | if (tgt_s->src == PLL_2 && strt_s->src == PLL_2) |
| 267 | clk_disable(acpuclk_sources[backup_s->src]); |
| 268 | |
| 269 | /* Nothing else to do for SWFI. */ |
| 270 | if (reason == SETRATE_SWFI) |
| 271 | goto out; |
| 272 | |
| 273 | /* Turn off previous PLL if not used. */ |
| 274 | if (strt_s->src != tgt_s->src && strt_s->src >= 0) { |
| 275 | pr_debug("Disabling PLL %d\n", strt_s->src); |
| 276 | clk_disable(acpuclk_sources[strt_s->src]); |
| 277 | } |
| 278 | |
| 279 | /* Decrease the AXI bus frequency if we can. */ |
| 280 | if (tgt_s->axi_clk_hz < strt_s->axi_clk_hz) { |
Matt Wagantall | e0eecf0 | 2011-11-08 14:07:54 -0800 | [diff] [blame] | 281 | res = clk_set_rate(drv_state.ebi1_clk, tgt_s->axi_clk_hz); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 282 | if (res < 0) |
| 283 | pr_warning("Setting AXI min rate failed (%d)\n", res); |
| 284 | } |
| 285 | |
| 286 | /* Nothing else to do for power collapse. */ |
| 287 | if (reason == SETRATE_PC) |
| 288 | goto out; |
| 289 | |
| 290 | /* Drop VDD level if we can. */ |
| 291 | if (tgt_s->vdd_mv < strt_s->vdd_mv) { |
| 292 | res = acpuclk_set_acpu_vdd(tgt_s); |
| 293 | if (res) |
| 294 | pr_warning("ACPU VDD decrease to %d mV failed (%d)\n", |
| 295 | tgt_s->vdd_mv, res); |
| 296 | } |
| 297 | |
| 298 | pr_debug("ACPU speed change complete\n"); |
| 299 | out: |
| 300 | if (reason == SETRATE_CPUFREQ) |
| 301 | mutex_unlock(&drv_state.lock); |
| 302 | |
| 303 | return rc; |
| 304 | } |
| 305 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 306 | static unsigned long acpuclk_7x30_get_rate(int cpu) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 307 | { |
| 308 | WARN_ONCE(drv_state.current_speed == NULL, |
| 309 | "acpuclk_get_rate: not initialized\n"); |
| 310 | if (drv_state.current_speed) |
| 311 | return drv_state.current_speed->acpu_clk_khz; |
| 312 | else |
| 313 | return 0; |
| 314 | } |
| 315 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 316 | /*---------------------------------------------------------------------------- |
| 317 | * Clock driver initialization |
| 318 | *---------------------------------------------------------------------------*/ |
| 319 | |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 320 | static void __devinit acpuclk_hw_init(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 321 | { |
| 322 | struct clkctl_acpu_speed *s; |
| 323 | uint32_t div, sel, src_num; |
| 324 | uint32_t reg_clksel, reg_clkctl; |
| 325 | int res; |
| 326 | u8 pll2_l = readl_relaxed(PLL2_L_VAL_ADDR) & 0xFF; |
| 327 | |
| 328 | drv_state.ebi1_clk = clk_get(NULL, "ebi1_clk"); |
| 329 | BUG_ON(IS_ERR(drv_state.ebi1_clk)); |
| 330 | |
| 331 | reg_clksel = readl_relaxed(SCSS_CLK_SEL_ADDR); |
| 332 | |
| 333 | /* Determine the ACPU clock rate. */ |
| 334 | switch ((reg_clksel >> 1) & 0x3) { |
| 335 | case 0: /* Running off the output of the raw clock source mux. */ |
| 336 | reg_clkctl = readl_relaxed(SCSS_CLK_CTL_ADDR); |
| 337 | src_num = reg_clksel & 0x1; |
| 338 | sel = (reg_clkctl >> (12 - (8 * src_num))) & 0x7; |
| 339 | div = (reg_clkctl >> (8 - (8 * src_num))) & 0xF; |
| 340 | |
| 341 | /* Check frequency table for matching sel/div pair. */ |
| 342 | for (s = acpu_freq_tbl; s->acpu_clk_khz != 0; s++) { |
| 343 | if (s->acpu_src_sel == sel && s->acpu_src_div == div) |
| 344 | break; |
| 345 | } |
| 346 | if (s->acpu_clk_khz == 0) { |
| 347 | pr_err("Error - ACPU clock reports invalid speed\n"); |
| 348 | return; |
| 349 | } |
| 350 | break; |
| 351 | case 2: /* Running off of the SCPLL selected through the core mux. */ |
| 352 | /* Switch to run off of the SCPLL selected through the raw |
| 353 | * clock source mux. */ |
| 354 | for (s = acpu_freq_tbl; s->acpu_clk_khz != 0 |
| 355 | && s->src != PLL_2 && s->acpu_src_div == 0; s++) |
| 356 | ; |
| 357 | if (s->acpu_clk_khz != 0) { |
| 358 | /* Program raw clock source mux. */ |
| 359 | acpuclk_set_src(s); |
| 360 | |
| 361 | /* Switch to raw clock source input of the core mux. */ |
| 362 | reg_clksel = readl_relaxed(SCSS_CLK_SEL_ADDR); |
| 363 | reg_clksel &= ~(0x3 << 1); |
| 364 | writel_relaxed(reg_clksel, SCSS_CLK_SEL_ADDR); |
| 365 | break; |
| 366 | } |
| 367 | /* else fall through */ |
| 368 | default: |
| 369 | pr_err("Error - ACPU clock reports invalid source\n"); |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | /* Look at PLL2's L val to determine what speed PLL2 is running at */ |
| 374 | if (s->src == PLL_2) |
| 375 | for ( ; s->acpu_clk_khz; s++) |
| 376 | if (s->pll_rate && s->pll_rate->l == pll2_l) |
| 377 | break; |
| 378 | |
| 379 | /* Set initial ACPU VDD. */ |
| 380 | acpuclk_set_acpu_vdd(s); |
| 381 | |
| 382 | drv_state.current_speed = s; |
| 383 | |
| 384 | /* Initialize current PLL's reference count. */ |
| 385 | if (s->src >= 0) |
| 386 | clk_enable(acpuclk_sources[s->src]); |
| 387 | |
Matt Wagantall | e0eecf0 | 2011-11-08 14:07:54 -0800 | [diff] [blame] | 388 | res = clk_set_rate(drv_state.ebi1_clk, s->axi_clk_hz); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 389 | if (res < 0) |
| 390 | pr_warning("Setting AXI min rate failed!\n"); |
| 391 | |
| 392 | pr_info("ACPU running at %d KHz\n", s->acpu_clk_khz); |
| 393 | |
| 394 | return; |
| 395 | } |
| 396 | |
Taniya Das | bb0b6db | 2012-03-19 14:09:55 +0530 | [diff] [blame] | 397 | /* Initalize the lpj field in the acpu_freq_tbl. */ |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 398 | static void __devinit lpj_init(void) |
Taniya Das | bb0b6db | 2012-03-19 14:09:55 +0530 | [diff] [blame] | 399 | { |
| 400 | int i; |
| 401 | const struct clkctl_acpu_speed *base_clk = drv_state.current_speed; |
| 402 | |
| 403 | for (i = 0; acpu_freq_tbl[i].acpu_clk_khz; i++) { |
| 404 | acpu_freq_tbl[i].lpj = cpufreq_scale(loops_per_jiffy, |
| 405 | base_clk->acpu_clk_khz, |
| 406 | acpu_freq_tbl[i].acpu_clk_khz); |
| 407 | } |
| 408 | } |
| 409 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 410 | #ifdef CONFIG_CPU_FREQ_MSM |
| 411 | static struct cpufreq_frequency_table cpufreq_tbl[ARRAY_SIZE(acpu_freq_tbl)]; |
| 412 | |
| 413 | static void setup_cpufreq_table(void) |
| 414 | { |
| 415 | unsigned i = 0; |
| 416 | const struct clkctl_acpu_speed *speed; |
| 417 | |
| 418 | for (speed = acpu_freq_tbl; speed->acpu_clk_khz; speed++) |
| 419 | if (speed->use_for_scaling) { |
| 420 | cpufreq_tbl[i].index = i; |
| 421 | cpufreq_tbl[i].frequency = speed->acpu_clk_khz; |
| 422 | i++; |
| 423 | } |
| 424 | cpufreq_tbl[i].frequency = CPUFREQ_TABLE_END; |
| 425 | |
| 426 | cpufreq_frequency_table_get_attr(cpufreq_tbl, smp_processor_id()); |
| 427 | } |
| 428 | #else |
| 429 | static inline void setup_cpufreq_table(void) { } |
| 430 | #endif |
| 431 | |
| 432 | /* |
| 433 | * Truncate the frequency table at the current PLL2 rate and determine the |
| 434 | * backup PLL to use when scaling PLL2. |
| 435 | */ |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 436 | void __devinit pll2_fixup(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 437 | { |
| 438 | struct clkctl_acpu_speed *speed = acpu_freq_tbl; |
| 439 | u8 pll2_l = readl_relaxed(PLL2_L_VAL_ADDR) & 0xFF; |
| 440 | |
| 441 | for ( ; speed->acpu_clk_khz; speed++) { |
| 442 | if (speed->src != PLL_2) |
| 443 | backup_s = speed; |
| 444 | if (speed->pll_rate && speed->pll_rate->l == pll2_l) { |
| 445 | speed++; |
| 446 | speed->acpu_clk_khz = 0; |
| 447 | return; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | pr_err("Unknown PLL2 lval %d\n", pll2_l); |
| 452 | BUG(); |
| 453 | } |
| 454 | |
| 455 | #define RPM_BYPASS_MASK (1 << 3) |
| 456 | #define PMIC_MODE_MASK (1 << 4) |
| 457 | |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 458 | static void __devinit populate_plls(void) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 459 | { |
| 460 | acpuclk_sources[PLL_1] = clk_get_sys("acpu", "pll1_clk"); |
| 461 | BUG_ON(IS_ERR(acpuclk_sources[PLL_1])); |
| 462 | acpuclk_sources[PLL_2] = clk_get_sys("acpu", "pll2_clk"); |
| 463 | BUG_ON(IS_ERR(acpuclk_sources[PLL_2])); |
| 464 | acpuclk_sources[PLL_3] = clk_get_sys("acpu", "pll3_clk"); |
| 465 | BUG_ON(IS_ERR(acpuclk_sources[PLL_3])); |
Stephen Boyd | beb23f5 | 2012-01-25 10:09:30 -0800 | [diff] [blame] | 466 | /* |
| 467 | * Prepare all the PLLs because we enable/disable them |
| 468 | * from atomic context and can't always ensure they're |
| 469 | * all prepared in non-atomic context. |
| 470 | */ |
| 471 | BUG_ON(clk_prepare(acpuclk_sources[PLL_1])); |
| 472 | BUG_ON(clk_prepare(acpuclk_sources[PLL_2])); |
| 473 | BUG_ON(clk_prepare(acpuclk_sources[PLL_3])); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 476 | static struct acpuclk_data acpuclk_7x30_data = { |
| 477 | .set_rate = acpuclk_7x30_set_rate, |
| 478 | .get_rate = acpuclk_7x30_get_rate, |
| 479 | .power_collapse_khz = MAX_AXI_KHZ, |
| 480 | .wait_for_irq_khz = MAX_AXI_KHZ, |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 481 | .switch_time_us = 50, |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 482 | }; |
| 483 | |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 484 | static int __devinit acpuclk_7x30_probe(struct platform_device *pdev) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 485 | { |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 486 | pr_info("%s()\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 487 | |
| 488 | mutex_init(&drv_state.lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 489 | pll2_fixup(); |
| 490 | populate_plls(); |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 491 | acpuclk_hw_init(); |
Taniya Das | bb0b6db | 2012-03-19 14:09:55 +0530 | [diff] [blame] | 492 | lpj_init(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 493 | setup_cpufreq_table(); |
Matt Wagantall | 6d9ebee | 2011-08-26 12:15:24 -0700 | [diff] [blame] | 494 | acpuclk_register(&acpuclk_7x30_data); |
| 495 | |
| 496 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 497 | } |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 498 | |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 499 | static struct platform_driver acpuclk_7x30_driver = { |
| 500 | .probe = acpuclk_7x30_probe, |
| 501 | .driver = { |
| 502 | .name = "acpuclk-7x30", |
| 503 | .owner = THIS_MODULE, |
| 504 | }, |
Matt Wagantall | ec57f06 | 2011-08-16 23:54:46 -0700 | [diff] [blame] | 505 | }; |
Matt Wagantall | bf430eb | 2012-03-22 11:45:49 -0700 | [diff] [blame^] | 506 | |
| 507 | static int __init acpuclk_7x30_init(void) |
| 508 | { |
| 509 | return platform_driver_register(&acpuclk_7x30_driver); |
| 510 | } |
| 511 | postcore_initcall(acpuclk_7x30_init); |