Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 14 | #include <linux/kernel.h> |
Matt Wagantall | 9515bc2 | 2012-07-19 18:13:40 -0700 | [diff] [blame] | 15 | #include <linux/module.h> |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/io.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/mutex.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/errno.h> |
| 22 | #include <linux/cpufreq.h> |
| 23 | #include <linux/cpu.h> |
| 24 | #include <linux/regulator/consumer.h> |
| 25 | |
| 26 | #include <asm/mach-types.h> |
| 27 | #include <asm/cpu.h> |
| 28 | |
| 29 | #include <mach/board.h> |
| 30 | #include <mach/msm_iomap.h> |
| 31 | #include <mach/socinfo.h> |
| 32 | #include <mach/msm-krait-l2-accessors.h> |
| 33 | #include <mach/rpm-regulator.h> |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 34 | #include <mach/rpm-regulator-smd.h> |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 35 | #include <mach/msm_bus.h> |
| 36 | |
| 37 | #include "acpuclock.h" |
| 38 | #include "acpuclock-krait.h" |
Stephen Boyd | a86214a | 2012-09-14 11:25:34 -0700 | [diff] [blame] | 39 | #include "avs.h" |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 40 | |
| 41 | /* MUX source selects. */ |
| 42 | #define PRI_SRC_SEL_SEC_SRC 0 |
| 43 | #define PRI_SRC_SEL_HFPLL 1 |
| 44 | #define PRI_SRC_SEL_HFPLL_DIV2 2 |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 45 | |
Matt Wagantall | af4669b | 2012-09-25 12:47:24 -0700 | [diff] [blame] | 46 | #define SECCLKAGD BIT(4) |
| 47 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 48 | static DEFINE_MUTEX(driver_lock); |
| 49 | static DEFINE_SPINLOCK(l2_lock); |
| 50 | |
Matt Wagantall | 488bef3 | 2012-07-13 19:42:11 -0700 | [diff] [blame] | 51 | static struct drv_data drv; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 52 | |
| 53 | static unsigned long acpuclk_krait_get_rate(int cpu) |
| 54 | { |
| 55 | return drv.scalable[cpu].cur_speed->khz; |
| 56 | } |
| 57 | |
| 58 | /* Select a source on the primary MUX. */ |
| 59 | static void set_pri_clk_src(struct scalable *sc, u32 pri_src_sel) |
| 60 | { |
| 61 | u32 regval; |
| 62 | |
| 63 | regval = get_l2_indirect_reg(sc->l2cpmr_iaddr); |
| 64 | regval &= ~0x3; |
| 65 | regval |= (pri_src_sel & 0x3); |
| 66 | set_l2_indirect_reg(sc->l2cpmr_iaddr, regval); |
| 67 | /* Wait for switch to complete. */ |
| 68 | mb(); |
| 69 | udelay(1); |
| 70 | } |
| 71 | |
| 72 | /* Select a source on the secondary MUX. */ |
Matt Wagantall | 6cd5d75 | 2012-09-27 19:56:57 -0700 | [diff] [blame] | 73 | static void __cpuinit set_sec_clk_src(struct scalable *sc, u32 sec_src_sel) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 74 | { |
| 75 | u32 regval; |
| 76 | |
Matt Wagantall | af4669b | 2012-09-25 12:47:24 -0700 | [diff] [blame] | 77 | /* 8064 Errata: disable sec_src clock gating during switch. */ |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 78 | regval = get_l2_indirect_reg(sc->l2cpmr_iaddr); |
Matt Wagantall | af4669b | 2012-09-25 12:47:24 -0700 | [diff] [blame] | 79 | regval |= SECCLKAGD; |
| 80 | set_l2_indirect_reg(sc->l2cpmr_iaddr, regval); |
| 81 | |
| 82 | /* Program the MUX */ |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 83 | regval &= ~(0x3 << 2); |
| 84 | regval |= ((sec_src_sel & 0x3) << 2); |
| 85 | set_l2_indirect_reg(sc->l2cpmr_iaddr, regval); |
Matt Wagantall | af4669b | 2012-09-25 12:47:24 -0700 | [diff] [blame] | 86 | |
| 87 | /* 8064 Errata: re-enabled sec_src clock gating. */ |
| 88 | regval &= ~SECCLKAGD; |
| 89 | set_l2_indirect_reg(sc->l2cpmr_iaddr, regval); |
| 90 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 91 | /* Wait for switch to complete. */ |
| 92 | mb(); |
| 93 | udelay(1); |
| 94 | } |
| 95 | |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 96 | static int enable_rpm_vreg(struct vreg *vreg) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 97 | { |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 98 | int ret = 0; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 99 | |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 100 | if (vreg->rpm_reg) { |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 101 | ret = rpm_regulator_enable(vreg->rpm_reg); |
| 102 | if (ret) |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 103 | dev_err(drv.dev, "%s regulator enable failed (%d)\n", |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 104 | vreg->name, ret); |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 105 | } |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 106 | |
| 107 | return ret; |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | static void disable_rpm_vreg(struct vreg *vreg) |
| 111 | { |
| 112 | int rc; |
| 113 | |
| 114 | if (vreg->rpm_reg) { |
| 115 | rc = rpm_regulator_disable(vreg->rpm_reg); |
| 116 | if (rc) |
| 117 | dev_err(drv.dev, "%s regulator disable failed (%d)\n", |
| 118 | vreg->name, rc); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /* Enable an already-configured HFPLL. */ |
| 123 | static void hfpll_enable(struct scalable *sc, bool skip_regulators) |
| 124 | { |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 125 | if (!skip_regulators) { |
| 126 | /* Enable regulators required by the HFPLL. */ |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 127 | enable_rpm_vreg(&sc->vreg[VREG_HFPLL_A]); |
| 128 | enable_rpm_vreg(&sc->vreg[VREG_HFPLL_B]); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /* Disable PLL bypass mode. */ |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 132 | writel_relaxed(0x2, sc->hfpll_base + drv.hfpll_data->mode_offset); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * H/W requires a 5us delay between disabling the bypass and |
| 136 | * de-asserting the reset. Delay 10us just to be safe. |
| 137 | */ |
| 138 | mb(); |
| 139 | udelay(10); |
| 140 | |
| 141 | /* De-assert active-low PLL reset. */ |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 142 | writel_relaxed(0x6, sc->hfpll_base + drv.hfpll_data->mode_offset); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 143 | |
| 144 | /* Wait for PLL to lock. */ |
| 145 | mb(); |
| 146 | udelay(60); |
| 147 | |
| 148 | /* Enable PLL output. */ |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 149 | writel_relaxed(0x7, sc->hfpll_base + drv.hfpll_data->mode_offset); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* Disable a HFPLL for power-savings or while it's being reprogrammed. */ |
| 153 | static void hfpll_disable(struct scalable *sc, bool skip_regulators) |
| 154 | { |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 155 | /* |
| 156 | * Disable the PLL output, disable test mode, enable the bypass mode, |
| 157 | * and assert the reset. |
| 158 | */ |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 159 | writel_relaxed(0, sc->hfpll_base + drv.hfpll_data->mode_offset); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 160 | |
| 161 | if (!skip_regulators) { |
| 162 | /* Remove voltage votes required by the HFPLL. */ |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 163 | disable_rpm_vreg(&sc->vreg[VREG_HFPLL_B]); |
| 164 | disable_rpm_vreg(&sc->vreg[VREG_HFPLL_A]); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| 168 | /* Program the HFPLL rate. Assumes HFPLL is already disabled. */ |
| 169 | static void hfpll_set_rate(struct scalable *sc, const struct core_speed *tgt_s) |
| 170 | { |
Matt Wagantall | a77b7f3 | 2012-07-18 16:32:01 -0700 | [diff] [blame] | 171 | void __iomem *base = sc->hfpll_base; |
| 172 | u32 regval; |
| 173 | |
| 174 | writel_relaxed(tgt_s->pll_l_val, base + drv.hfpll_data->l_offset); |
| 175 | |
| 176 | if (drv.hfpll_data->has_user_reg) { |
| 177 | regval = readl_relaxed(base + drv.hfpll_data->user_offset); |
| 178 | if (tgt_s->pll_l_val <= drv.hfpll_data->low_vco_l_max) |
| 179 | regval &= ~drv.hfpll_data->user_vco_mask; |
| 180 | else |
| 181 | regval |= drv.hfpll_data->user_vco_mask; |
| 182 | writel_relaxed(regval, base + drv.hfpll_data->user_offset); |
| 183 | } |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /* Return the L2 speed that should be applied. */ |
Matt Wagantall | 600ea50 | 2012-06-08 18:49:53 -0700 | [diff] [blame] | 187 | static unsigned int compute_l2_level(struct scalable *sc, unsigned int vote_l) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 188 | { |
Matt Wagantall | 600ea50 | 2012-06-08 18:49:53 -0700 | [diff] [blame] | 189 | unsigned int new_l = 0; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 190 | int cpu; |
| 191 | |
| 192 | /* Find max L2 speed vote. */ |
| 193 | sc->l2_vote = vote_l; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 194 | for_each_present_cpu(cpu) |
| 195 | new_l = max(new_l, drv.scalable[cpu].l2_vote); |
| 196 | |
| 197 | return new_l; |
| 198 | } |
| 199 | |
| 200 | /* Update the bus bandwidth request. */ |
| 201 | static void set_bus_bw(unsigned int bw) |
| 202 | { |
| 203 | int ret; |
| 204 | |
| 205 | /* Update bandwidth if request has changed. This may sleep. */ |
| 206 | ret = msm_bus_scale_client_update_request(drv.bus_perf_client, bw); |
| 207 | if (ret) |
| 208 | dev_err(drv.dev, "bandwidth request failed (%d)\n", ret); |
| 209 | } |
| 210 | |
| 211 | /* Set the CPU or L2 clock speed. */ |
| 212 | static void set_speed(struct scalable *sc, const struct core_speed *tgt_s) |
| 213 | { |
| 214 | const struct core_speed *strt_s = sc->cur_speed; |
| 215 | |
Stephen Boyd | 14a4739 | 2012-08-06 20:15:15 -0700 | [diff] [blame] | 216 | if (strt_s == tgt_s) |
| 217 | return; |
| 218 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 219 | if (strt_s->src == HFPLL && tgt_s->src == HFPLL) { |
| 220 | /* |
| 221 | * Move to an always-on source running at a frequency |
| 222 | * that does not require an elevated CPU voltage. |
| 223 | */ |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 224 | set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC); |
| 225 | |
| 226 | /* Re-program HFPLL. */ |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 227 | hfpll_disable(sc, true); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 228 | hfpll_set_rate(sc, tgt_s); |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 229 | hfpll_enable(sc, true); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 230 | |
| 231 | /* Move to HFPLL. */ |
| 232 | set_pri_clk_src(sc, tgt_s->pri_src_sel); |
| 233 | } else if (strt_s->src == HFPLL && tgt_s->src != HFPLL) { |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 234 | set_pri_clk_src(sc, tgt_s->pri_src_sel); |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 235 | hfpll_disable(sc, false); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 236 | } else if (strt_s->src != HFPLL && tgt_s->src == HFPLL) { |
| 237 | hfpll_set_rate(sc, tgt_s); |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 238 | hfpll_enable(sc, false); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 239 | set_pri_clk_src(sc, tgt_s->pri_src_sel); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | sc->cur_speed = tgt_s; |
| 243 | } |
| 244 | |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 245 | struct vdd_data { |
| 246 | int vdd_mem; |
| 247 | int vdd_dig; |
| 248 | int vdd_core; |
| 249 | int ua_core; |
| 250 | }; |
| 251 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 252 | /* Apply any per-cpu voltage increases. */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 253 | static int increase_vdd(int cpu, struct vdd_data *data, |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 254 | enum setrate_reason reason) |
| 255 | { |
| 256 | struct scalable *sc = &drv.scalable[cpu]; |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 257 | int rc; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | * Increase vdd_mem active-set before vdd_dig. |
| 261 | * vdd_mem should be >= vdd_dig. |
| 262 | */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 263 | if (data->vdd_mem > sc->vreg[VREG_MEM].cur_vdd) { |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 264 | rc = rpm_regulator_set_voltage(sc->vreg[VREG_MEM].rpm_reg, |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 265 | data->vdd_mem, sc->vreg[VREG_MEM].max_vdd); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 266 | if (rc) { |
| 267 | dev_err(drv.dev, |
| 268 | "vdd_mem (cpu%d) increase failed (%d)\n", |
| 269 | cpu, rc); |
| 270 | return rc; |
| 271 | } |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 272 | sc->vreg[VREG_MEM].cur_vdd = data->vdd_mem; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | /* Increase vdd_dig active-set vote. */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 276 | if (data->vdd_dig > sc->vreg[VREG_DIG].cur_vdd) { |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 277 | rc = rpm_regulator_set_voltage(sc->vreg[VREG_DIG].rpm_reg, |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 278 | data->vdd_dig, sc->vreg[VREG_DIG].max_vdd); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 279 | if (rc) { |
| 280 | dev_err(drv.dev, |
| 281 | "vdd_dig (cpu%d) increase failed (%d)\n", |
| 282 | cpu, rc); |
| 283 | return rc; |
| 284 | } |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 285 | sc->vreg[VREG_DIG].cur_vdd = data->vdd_dig; |
| 286 | } |
| 287 | |
| 288 | /* Increase current request. */ |
| 289 | if (data->ua_core > sc->vreg[VREG_CORE].cur_ua) { |
| 290 | rc = regulator_set_optimum_mode(sc->vreg[VREG_CORE].reg, |
| 291 | data->ua_core); |
| 292 | if (rc < 0) { |
| 293 | dev_err(drv.dev, "regulator_set_optimum_mode(%s) failed (%d)\n", |
| 294 | sc->vreg[VREG_CORE].name, rc); |
| 295 | return rc; |
| 296 | } |
| 297 | sc->vreg[VREG_CORE].cur_ua = data->ua_core; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | /* |
| 301 | * Update per-CPU core voltage. Don't do this for the hotplug path for |
| 302 | * which it should already be correct. Attempting to set it is bad |
| 303 | * because we don't know what CPU we are running on at this point, but |
| 304 | * the CPU regulator API requires we call it from the affected CPU. |
| 305 | */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 306 | if (data->vdd_core > sc->vreg[VREG_CORE].cur_vdd |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 307 | && reason != SETRATE_HOTPLUG) { |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 308 | rc = regulator_set_voltage(sc->vreg[VREG_CORE].reg, |
| 309 | data->vdd_core, sc->vreg[VREG_CORE].max_vdd); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 310 | if (rc) { |
| 311 | dev_err(drv.dev, |
| 312 | "vdd_core (cpu%d) increase failed (%d)\n", |
| 313 | cpu, rc); |
| 314 | return rc; |
| 315 | } |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 316 | sc->vreg[VREG_CORE].cur_vdd = data->vdd_core; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 319 | return 0; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /* Apply any per-cpu voltage decreases. */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 323 | static void decrease_vdd(int cpu, struct vdd_data *data, |
| 324 | enum setrate_reason reason) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 325 | { |
| 326 | struct scalable *sc = &drv.scalable[cpu]; |
| 327 | int ret; |
| 328 | |
| 329 | /* |
| 330 | * Update per-CPU core voltage. This must be called on the CPU |
| 331 | * that's being affected. Don't do this in the hotplug remove path, |
| 332 | * where the rail is off and we're executing on the other CPU. |
| 333 | */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 334 | if (data->vdd_core < sc->vreg[VREG_CORE].cur_vdd |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 335 | && reason != SETRATE_HOTPLUG) { |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 336 | ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, |
| 337 | data->vdd_core, sc->vreg[VREG_CORE].max_vdd); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 338 | if (ret) { |
| 339 | dev_err(drv.dev, |
| 340 | "vdd_core (cpu%d) decrease failed (%d)\n", |
| 341 | cpu, ret); |
| 342 | return; |
| 343 | } |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 344 | sc->vreg[VREG_CORE].cur_vdd = data->vdd_core; |
| 345 | } |
| 346 | |
| 347 | /* Decrease current request. */ |
| 348 | if (data->ua_core < sc->vreg[VREG_CORE].cur_ua) { |
| 349 | ret = regulator_set_optimum_mode(sc->vreg[VREG_CORE].reg, |
| 350 | data->ua_core); |
| 351 | if (ret < 0) { |
| 352 | dev_err(drv.dev, "regulator_set_optimum_mode(%s) failed (%d)\n", |
| 353 | sc->vreg[VREG_CORE].name, ret); |
| 354 | return; |
| 355 | } |
| 356 | sc->vreg[VREG_CORE].cur_ua = data->ua_core; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /* Decrease vdd_dig active-set vote. */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 360 | if (data->vdd_dig < sc->vreg[VREG_DIG].cur_vdd) { |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 361 | ret = rpm_regulator_set_voltage(sc->vreg[VREG_DIG].rpm_reg, |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 362 | data->vdd_dig, sc->vreg[VREG_DIG].max_vdd); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 363 | if (ret) { |
| 364 | dev_err(drv.dev, |
| 365 | "vdd_dig (cpu%d) decrease failed (%d)\n", |
| 366 | cpu, ret); |
| 367 | return; |
| 368 | } |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 369 | sc->vreg[VREG_DIG].cur_vdd = data->vdd_dig; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Decrease vdd_mem active-set after vdd_dig. |
| 374 | * vdd_mem should be >= vdd_dig. |
| 375 | */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 376 | if (data->vdd_mem < sc->vreg[VREG_MEM].cur_vdd) { |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 377 | ret = rpm_regulator_set_voltage(sc->vreg[VREG_MEM].rpm_reg, |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 378 | data->vdd_mem, sc->vreg[VREG_MEM].max_vdd); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 379 | if (ret) { |
| 380 | dev_err(drv.dev, |
| 381 | "vdd_mem (cpu%d) decrease failed (%d)\n", |
| 382 | cpu, ret); |
| 383 | return; |
| 384 | } |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 385 | sc->vreg[VREG_MEM].cur_vdd = data->vdd_mem; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
| 389 | static int calculate_vdd_mem(const struct acpu_level *tgt) |
| 390 | { |
Matt Wagantall | 600ea50 | 2012-06-08 18:49:53 -0700 | [diff] [blame] | 391 | return drv.l2_freq_tbl[tgt->l2_level].vdd_mem; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Matt Wagantall | 72a3800 | 2012-07-18 13:42:55 -0700 | [diff] [blame] | 394 | static int get_src_dig(const struct core_speed *s) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 395 | { |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 396 | const int *hfpll_vdd = drv.hfpll_data->vdd; |
| 397 | const u32 low_vdd_l_max = drv.hfpll_data->low_vdd_l_max; |
Matt Wagantall | 87465f5 | 2012-07-23 22:03:06 -0700 | [diff] [blame] | 398 | const u32 nom_vdd_l_max = drv.hfpll_data->nom_vdd_l_max; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 399 | |
Matt Wagantall | 72a3800 | 2012-07-18 13:42:55 -0700 | [diff] [blame] | 400 | if (s->src != HFPLL) |
| 401 | return hfpll_vdd[HFPLL_VDD_NONE]; |
Matt Wagantall | 87465f5 | 2012-07-23 22:03:06 -0700 | [diff] [blame] | 402 | else if (s->pll_l_val > nom_vdd_l_max) |
| 403 | return hfpll_vdd[HFPLL_VDD_HIGH]; |
Matt Wagantall | 72a3800 | 2012-07-18 13:42:55 -0700 | [diff] [blame] | 404 | else if (s->pll_l_val > low_vdd_l_max) |
| 405 | return hfpll_vdd[HFPLL_VDD_NOM]; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 406 | else |
Matt Wagantall | 72a3800 | 2012-07-18 13:42:55 -0700 | [diff] [blame] | 407 | return hfpll_vdd[HFPLL_VDD_LOW]; |
| 408 | } |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 409 | |
Matt Wagantall | 72a3800 | 2012-07-18 13:42:55 -0700 | [diff] [blame] | 410 | static int calculate_vdd_dig(const struct acpu_level *tgt) |
| 411 | { |
| 412 | int l2_pll_vdd_dig, cpu_pll_vdd_dig; |
| 413 | |
| 414 | l2_pll_vdd_dig = get_src_dig(&drv.l2_freq_tbl[tgt->l2_level].speed); |
| 415 | cpu_pll_vdd_dig = get_src_dig(&tgt->speed); |
| 416 | |
| 417 | return max(drv.l2_freq_tbl[tgt->l2_level].vdd_dig, |
| 418 | max(l2_pll_vdd_dig, cpu_pll_vdd_dig)); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 419 | } |
| 420 | |
Matt Wagantall | 9515bc2 | 2012-07-19 18:13:40 -0700 | [diff] [blame] | 421 | static bool enable_boost = true; |
| 422 | module_param_named(boost, enable_boost, bool, S_IRUGO | S_IWUSR); |
| 423 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 424 | static int calculate_vdd_core(const struct acpu_level *tgt) |
| 425 | { |
Matt Wagantall | 9515bc2 | 2012-07-19 18:13:40 -0700 | [diff] [blame] | 426 | return tgt->vdd_core + (enable_boost ? drv.boost_uv : 0); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | /* Set the CPU's clock rate and adjust the L2 rate, voltage and BW requests. */ |
| 430 | static int acpuclk_krait_set_rate(int cpu, unsigned long rate, |
| 431 | enum setrate_reason reason) |
| 432 | { |
| 433 | const struct core_speed *strt_acpu_s, *tgt_acpu_s; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 434 | const struct acpu_level *tgt; |
Matt Wagantall | 600ea50 | 2012-06-08 18:49:53 -0700 | [diff] [blame] | 435 | int tgt_l2_l; |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 436 | struct vdd_data vdd_data; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 437 | unsigned long flags; |
| 438 | int rc = 0; |
| 439 | |
Matt Wagantall | 5941a33 | 2012-07-10 23:20:44 -0700 | [diff] [blame] | 440 | if (cpu > num_possible_cpus()) |
| 441 | return -EINVAL; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 442 | |
| 443 | if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) |
| 444 | mutex_lock(&driver_lock); |
| 445 | |
| 446 | strt_acpu_s = drv.scalable[cpu].cur_speed; |
| 447 | |
| 448 | /* Return early if rate didn't change. */ |
| 449 | if (rate == strt_acpu_s->khz) |
| 450 | goto out; |
| 451 | |
| 452 | /* Find target frequency. */ |
| 453 | for (tgt = drv.acpu_freq_tbl; tgt->speed.khz != 0; tgt++) { |
| 454 | if (tgt->speed.khz == rate) { |
| 455 | tgt_acpu_s = &tgt->speed; |
| 456 | break; |
| 457 | } |
| 458 | } |
| 459 | if (tgt->speed.khz == 0) { |
| 460 | rc = -EINVAL; |
| 461 | goto out; |
| 462 | } |
| 463 | |
| 464 | /* Calculate voltage requirements for the current CPU. */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 465 | vdd_data.vdd_mem = calculate_vdd_mem(tgt); |
| 466 | vdd_data.vdd_dig = calculate_vdd_dig(tgt); |
| 467 | vdd_data.vdd_core = calculate_vdd_core(tgt); |
| 468 | vdd_data.ua_core = tgt->ua_core; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 469 | |
Stephen Boyd | a86214a | 2012-09-14 11:25:34 -0700 | [diff] [blame] | 470 | /* Disable AVS before voltage switch */ |
| 471 | if (reason == SETRATE_CPUFREQ && drv.scalable[cpu].avs_enabled) { |
| 472 | AVS_DISABLE(cpu); |
| 473 | drv.scalable[cpu].avs_enabled = false; |
| 474 | } |
| 475 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 476 | /* Increase VDD levels if needed. */ |
| 477 | if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) { |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 478 | rc = increase_vdd(cpu, &vdd_data, reason); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 479 | if (rc) |
| 480 | goto out; |
| 481 | } |
| 482 | |
Matt Wagantall | bd1b404 | 2012-07-24 11:20:03 -0700 | [diff] [blame] | 483 | dev_dbg(drv.dev, "Switching from ACPU%d rate %lu KHz -> %lu KHz\n", |
| 484 | cpu, strt_acpu_s->khz, tgt_acpu_s->khz); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 485 | |
| 486 | /* Set the new CPU speed. */ |
| 487 | set_speed(&drv.scalable[cpu], tgt_acpu_s); |
| 488 | |
| 489 | /* |
| 490 | * Update the L2 vote and apply the rate change. A spinlock is |
| 491 | * necessary to ensure L2 rate is calculated and set atomically |
| 492 | * with the CPU frequency, even if acpuclk_krait_set_rate() is |
| 493 | * called from an atomic context and the driver_lock mutex is not |
| 494 | * acquired. |
| 495 | */ |
| 496 | spin_lock_irqsave(&l2_lock, flags); |
| 497 | tgt_l2_l = compute_l2_level(&drv.scalable[cpu], tgt->l2_level); |
Matt Wagantall | 600ea50 | 2012-06-08 18:49:53 -0700 | [diff] [blame] | 498 | set_speed(&drv.scalable[L2], &drv.l2_freq_tbl[tgt_l2_l].speed); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 499 | spin_unlock_irqrestore(&l2_lock, flags); |
| 500 | |
| 501 | /* Nothing else to do for power collapse or SWFI. */ |
| 502 | if (reason == SETRATE_PC || reason == SETRATE_SWFI) |
| 503 | goto out; |
| 504 | |
| 505 | /* Update bus bandwith request. */ |
Matt Wagantall | 600ea50 | 2012-06-08 18:49:53 -0700 | [diff] [blame] | 506 | set_bus_bw(drv.l2_freq_tbl[tgt_l2_l].bw_level); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 507 | |
| 508 | /* Drop VDD levels if we can. */ |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 509 | decrease_vdd(cpu, &vdd_data, reason); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 510 | |
Stephen Boyd | a86214a | 2012-09-14 11:25:34 -0700 | [diff] [blame] | 511 | /* Re-enable AVS */ |
| 512 | if (reason == SETRATE_CPUFREQ && tgt->avsdscr_setting) { |
| 513 | AVS_ENABLE(cpu, tgt->avsdscr_setting); |
| 514 | drv.scalable[cpu].avs_enabled = true; |
| 515 | } |
| 516 | |
Matt Wagantall | bd1b404 | 2012-07-24 11:20:03 -0700 | [diff] [blame] | 517 | dev_dbg(drv.dev, "ACPU%d speed change complete\n", cpu); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 518 | |
| 519 | out: |
| 520 | if (reason == SETRATE_CPUFREQ || reason == SETRATE_HOTPLUG) |
| 521 | mutex_unlock(&driver_lock); |
| 522 | return rc; |
| 523 | } |
| 524 | |
Matt Wagantall | b7c231b | 2012-07-24 18:40:17 -0700 | [diff] [blame] | 525 | static struct acpuclk_data acpuclk_krait_data = { |
| 526 | .set_rate = acpuclk_krait_set_rate, |
| 527 | .get_rate = acpuclk_krait_get_rate, |
| 528 | }; |
| 529 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 530 | /* Initialize a HFPLL at a given rate and enable it. */ |
Matt Wagantall | 980d067 | 2012-10-17 13:50:07 -0700 | [diff] [blame] | 531 | static void __cpuinit hfpll_init(struct scalable *sc, |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 532 | const struct core_speed *tgt_s) |
| 533 | { |
Matt Wagantall | bd1b404 | 2012-07-24 11:20:03 -0700 | [diff] [blame] | 534 | dev_dbg(drv.dev, "Initializing HFPLL%d\n", sc - drv.scalable); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 535 | |
| 536 | /* Disable the PLL for re-programming. */ |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 537 | hfpll_disable(sc, true); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 538 | |
| 539 | /* Configure PLL parameters for integer mode. */ |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 540 | writel_relaxed(drv.hfpll_data->config_val, |
| 541 | sc->hfpll_base + drv.hfpll_data->config_offset); |
| 542 | writel_relaxed(0, sc->hfpll_base + drv.hfpll_data->m_offset); |
| 543 | writel_relaxed(1, sc->hfpll_base + drv.hfpll_data->n_offset); |
Matt Wagantall | a77b7f3 | 2012-07-18 16:32:01 -0700 | [diff] [blame] | 544 | if (drv.hfpll_data->has_user_reg) |
| 545 | writel_relaxed(drv.hfpll_data->user_val, |
| 546 | sc->hfpll_base + drv.hfpll_data->user_offset); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 547 | |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 548 | /* Program droop controller, if supported */ |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 549 | if (drv.hfpll_data->has_droop_ctl) |
| 550 | writel_relaxed(drv.hfpll_data->droop_val, |
| 551 | sc->hfpll_base + drv.hfpll_data->droop_offset); |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 552 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 553 | /* Set an initial rate and enable the PLL. */ |
| 554 | hfpll_set_rate(sc, tgt_s); |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 555 | hfpll_enable(sc, false); |
| 556 | } |
| 557 | |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 558 | static int __cpuinit rpm_regulator_init(struct scalable *sc, enum vregs vreg, |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 559 | int vdd, bool enable) |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 560 | { |
| 561 | int ret; |
| 562 | |
| 563 | if (!sc->vreg[vreg].name) |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 564 | return 0; |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 565 | |
| 566 | sc->vreg[vreg].rpm_reg = rpm_regulator_get(drv.dev, |
| 567 | sc->vreg[vreg].name); |
| 568 | if (IS_ERR(sc->vreg[vreg].rpm_reg)) { |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 569 | ret = PTR_ERR(sc->vreg[vreg].rpm_reg); |
| 570 | dev_err(drv.dev, "rpm_regulator_get(%s) failed (%d)\n", |
| 571 | sc->vreg[vreg].name, ret); |
| 572 | goto err_get; |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | ret = rpm_regulator_set_voltage(sc->vreg[vreg].rpm_reg, vdd, |
| 576 | sc->vreg[vreg].max_vdd); |
| 577 | if (ret) { |
| 578 | dev_err(drv.dev, "%s initialization failed (%d)\n", |
| 579 | sc->vreg[vreg].name, ret); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 580 | goto err_conf; |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 581 | } |
| 582 | sc->vreg[vreg].cur_vdd = vdd; |
| 583 | |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 584 | if (enable) { |
| 585 | ret = enable_rpm_vreg(&sc->vreg[vreg]); |
| 586 | if (ret) |
| 587 | goto err_conf; |
| 588 | } |
| 589 | |
| 590 | return 0; |
| 591 | |
| 592 | err_conf: |
| 593 | rpm_regulator_put(sc->vreg[vreg].rpm_reg); |
| 594 | err_get: |
| 595 | return ret; |
| 596 | } |
| 597 | |
| 598 | static void __cpuinit rpm_regulator_cleanup(struct scalable *sc, |
| 599 | enum vregs vreg) |
| 600 | { |
| 601 | if (!sc->vreg[vreg].rpm_reg) |
| 602 | return; |
| 603 | |
| 604 | disable_rpm_vreg(&sc->vreg[vreg]); |
| 605 | rpm_regulator_put(sc->vreg[vreg].rpm_reg); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | /* Voltage regulator initialization. */ |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 609 | static int __cpuinit regulator_init(struct scalable *sc, |
| 610 | const struct acpu_level *acpu_level) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 611 | { |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 612 | int ret, vdd_mem, vdd_dig, vdd_core; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 613 | |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 614 | vdd_mem = calculate_vdd_mem(acpu_level); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 615 | ret = rpm_regulator_init(sc, VREG_MEM, vdd_mem, true); |
| 616 | if (ret) |
| 617 | goto err_mem; |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 618 | |
| 619 | vdd_dig = calculate_vdd_dig(acpu_level); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 620 | ret = rpm_regulator_init(sc, VREG_DIG, vdd_dig, true); |
| 621 | if (ret) |
| 622 | goto err_dig; |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 623 | |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 624 | ret = rpm_regulator_init(sc, VREG_HFPLL_A, |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 625 | sc->vreg[VREG_HFPLL_A].max_vdd, false); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 626 | if (ret) |
| 627 | goto err_hfpll_a; |
| 628 | ret = rpm_regulator_init(sc, VREG_HFPLL_B, |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 629 | sc->vreg[VREG_HFPLL_B].max_vdd, false); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 630 | if (ret) |
| 631 | goto err_hfpll_b; |
Matt Wagantall | 75473eb | 2012-05-31 15:23:22 -0700 | [diff] [blame] | 632 | |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 633 | /* Setup Krait CPU regulators and initial core voltage. */ |
| 634 | sc->vreg[VREG_CORE].reg = regulator_get(drv.dev, |
| 635 | sc->vreg[VREG_CORE].name); |
| 636 | if (IS_ERR(sc->vreg[VREG_CORE].reg)) { |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 637 | ret = PTR_ERR(sc->vreg[VREG_CORE].reg); |
| 638 | dev_err(drv.dev, "regulator_get(%s) failed (%d)\n", |
| 639 | sc->vreg[VREG_CORE].name, ret); |
| 640 | goto err_core_get; |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 641 | } |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 642 | ret = regulator_set_optimum_mode(sc->vreg[VREG_CORE].reg, |
| 643 | acpu_level->ua_core); |
| 644 | if (ret < 0) { |
| 645 | dev_err(drv.dev, "regulator_set_optimum_mode(%s) failed (%d)\n", |
| 646 | sc->vreg[VREG_CORE].name, ret); |
| 647 | goto err_core_conf; |
| 648 | } |
| 649 | sc->vreg[VREG_CORE].cur_ua = acpu_level->ua_core; |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 650 | vdd_core = calculate_vdd_core(acpu_level); |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 651 | ret = regulator_set_voltage(sc->vreg[VREG_CORE].reg, vdd_core, |
| 652 | sc->vreg[VREG_CORE].max_vdd); |
| 653 | if (ret) { |
| 654 | dev_err(drv.dev, "regulator_set_voltage(%s) (%d)\n", |
| 655 | sc->vreg[VREG_CORE].name, ret); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 656 | goto err_core_conf; |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 657 | } |
| 658 | sc->vreg[VREG_CORE].cur_vdd = vdd_core; |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 659 | ret = regulator_enable(sc->vreg[VREG_CORE].reg); |
| 660 | if (ret) { |
| 661 | dev_err(drv.dev, "regulator_enable(%s) failed (%d)\n", |
| 662 | sc->vreg[VREG_CORE].name, ret); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 663 | goto err_core_conf; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 664 | } |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 665 | |
| 666 | return 0; |
| 667 | |
| 668 | err_core_conf: |
| 669 | regulator_put(sc->vreg[VREG_CORE].reg); |
| 670 | err_core_get: |
| 671 | rpm_regulator_cleanup(sc, VREG_HFPLL_B); |
| 672 | err_hfpll_b: |
| 673 | rpm_regulator_cleanup(sc, VREG_HFPLL_A); |
| 674 | err_hfpll_a: |
| 675 | rpm_regulator_cleanup(sc, VREG_DIG); |
| 676 | err_dig: |
| 677 | rpm_regulator_cleanup(sc, VREG_MEM); |
| 678 | err_mem: |
| 679 | return ret; |
| 680 | } |
| 681 | |
| 682 | static void __cpuinit regulator_cleanup(struct scalable *sc) |
| 683 | { |
| 684 | regulator_disable(sc->vreg[VREG_CORE].reg); |
| 685 | regulator_put(sc->vreg[VREG_CORE].reg); |
| 686 | rpm_regulator_cleanup(sc, VREG_HFPLL_B); |
| 687 | rpm_regulator_cleanup(sc, VREG_HFPLL_A); |
| 688 | rpm_regulator_cleanup(sc, VREG_DIG); |
| 689 | rpm_regulator_cleanup(sc, VREG_MEM); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /* Set initial rate for a given core. */ |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 693 | static int __cpuinit init_clock_sources(struct scalable *sc, |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 694 | const struct core_speed *tgt_s) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 695 | { |
| 696 | u32 regval; |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 697 | void __iomem *aux_reg; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 698 | |
| 699 | /* Program AUX source input to the secondary MUX. */ |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 700 | if (sc->aux_clk_sel_phys) { |
| 701 | aux_reg = ioremap(sc->aux_clk_sel_phys, 4); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 702 | if (!aux_reg) |
| 703 | return -ENOMEM; |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 704 | writel_relaxed(sc->aux_clk_sel, aux_reg); |
| 705 | iounmap(aux_reg); |
| 706 | } |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 707 | |
| 708 | /* Switch away from the HFPLL while it's re-initialized. */ |
Matt Wagantall | 6cd5d75 | 2012-09-27 19:56:57 -0700 | [diff] [blame] | 709 | set_sec_clk_src(sc, sc->sec_clk_sel); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 710 | set_pri_clk_src(sc, PRI_SRC_SEL_SEC_SRC); |
| 711 | hfpll_init(sc, tgt_s); |
| 712 | |
| 713 | /* Set PRI_SRC_SEL_HFPLL_DIV2 divider to div-2. */ |
| 714 | regval = get_l2_indirect_reg(sc->l2cpmr_iaddr); |
| 715 | regval &= ~(0x3 << 6); |
| 716 | set_l2_indirect_reg(sc->l2cpmr_iaddr, regval); |
| 717 | |
| 718 | /* Switch to the target clock source. */ |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 719 | set_pri_clk_src(sc, tgt_s->pri_src_sel); |
| 720 | sc->cur_speed = tgt_s; |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 721 | |
| 722 | return 0; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 723 | } |
| 724 | |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 725 | static void __cpuinit fill_cur_core_speed(struct core_speed *s, |
| 726 | struct scalable *sc) |
| 727 | { |
| 728 | s->pri_src_sel = get_l2_indirect_reg(sc->l2cpmr_iaddr) & 0x3; |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 729 | s->pll_l_val = readl_relaxed(sc->hfpll_base + drv.hfpll_data->l_offset); |
| 730 | } |
| 731 | |
| 732 | static bool __cpuinit speed_equal(const struct core_speed *s1, |
| 733 | const struct core_speed *s2) |
| 734 | { |
| 735 | return (s1->pri_src_sel == s2->pri_src_sel && |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 736 | s1->pll_l_val == s2->pll_l_val); |
| 737 | } |
| 738 | |
| 739 | static const struct acpu_level __cpuinit *find_cur_acpu_level(int cpu) |
| 740 | { |
| 741 | struct scalable *sc = &drv.scalable[cpu]; |
| 742 | const struct acpu_level *l; |
| 743 | struct core_speed cur_speed; |
| 744 | |
| 745 | fill_cur_core_speed(&cur_speed, sc); |
| 746 | for (l = drv.acpu_freq_tbl; l->speed.khz != 0; l++) |
| 747 | if (speed_equal(&l->speed, &cur_speed)) |
| 748 | return l; |
| 749 | return NULL; |
| 750 | } |
| 751 | |
| 752 | static const struct l2_level __init *find_cur_l2_level(void) |
| 753 | { |
| 754 | struct scalable *sc = &drv.scalable[L2]; |
| 755 | const struct l2_level *l; |
| 756 | struct core_speed cur_speed; |
| 757 | |
| 758 | fill_cur_core_speed(&cur_speed, sc); |
| 759 | for (l = drv.l2_freq_tbl; l->speed.khz != 0; l++) |
| 760 | if (speed_equal(&l->speed, &cur_speed)) |
| 761 | return l; |
| 762 | return NULL; |
| 763 | } |
| 764 | |
| 765 | static const struct acpu_level __cpuinit *find_min_acpu_level(void) |
| 766 | { |
| 767 | struct acpu_level *l; |
| 768 | |
| 769 | for (l = drv.acpu_freq_tbl; l->speed.khz != 0; l++) |
| 770 | if (l->use_for_scaling) |
| 771 | return l; |
| 772 | |
| 773 | return NULL; |
| 774 | } |
| 775 | |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 776 | static int __cpuinit per_cpu_init(int cpu) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 777 | { |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 778 | struct scalable *sc = &drv.scalable[cpu]; |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 779 | const struct acpu_level *acpu_level; |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 780 | int ret; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 781 | |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 782 | sc->hfpll_base = ioremap(sc->hfpll_phys_base, SZ_32); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 783 | if (!sc->hfpll_base) { |
| 784 | ret = -ENOMEM; |
| 785 | goto err_ioremap; |
| 786 | } |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 787 | |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 788 | acpu_level = find_cur_acpu_level(cpu); |
Matt Wagantall | b7c231b | 2012-07-24 18:40:17 -0700 | [diff] [blame] | 789 | if (!acpu_level) { |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 790 | acpu_level = find_min_acpu_level(); |
| 791 | if (!acpu_level) { |
| 792 | ret = -ENODEV; |
| 793 | goto err_table; |
| 794 | } |
| 795 | dev_dbg(drv.dev, "CPU%d is running at an unknown rate. Defaulting to %lu KHz.\n", |
| 796 | cpu, acpu_level->speed.khz); |
| 797 | } else { |
| 798 | dev_dbg(drv.dev, "CPU%d is running at %lu KHz\n", cpu, |
| 799 | acpu_level->speed.khz); |
| 800 | } |
| 801 | |
| 802 | ret = regulator_init(sc, acpu_level); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 803 | if (ret) |
| 804 | goto err_regulators; |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 805 | |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 806 | ret = init_clock_sources(sc, &acpu_level->speed); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 807 | if (ret) |
| 808 | goto err_clocks; |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 809 | |
| 810 | sc->l2_vote = acpu_level->l2_level; |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 811 | sc->initialized = true; |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 812 | |
| 813 | return 0; |
| 814 | |
| 815 | err_clocks: |
| 816 | regulator_cleanup(sc); |
| 817 | err_regulators: |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 818 | err_table: |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 819 | iounmap(sc->hfpll_base); |
| 820 | err_ioremap: |
| 821 | return ret; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | /* Register with bus driver. */ |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 825 | static void __init bus_init(const struct l2_level *l2_level) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 826 | { |
| 827 | int ret; |
| 828 | |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 829 | drv.bus_perf_client = msm_bus_scale_register_client(drv.bus_scale); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 830 | if (!drv.bus_perf_client) { |
| 831 | dev_err(drv.dev, "unable to register bus client\n"); |
| 832 | BUG(); |
| 833 | } |
| 834 | |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 835 | ret = msm_bus_scale_client_update_request(drv.bus_perf_client, |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 836 | l2_level->bw_level); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 837 | if (ret) |
| 838 | dev_err(drv.dev, "initial bandwidth req failed (%d)\n", ret); |
| 839 | } |
| 840 | |
| 841 | #ifdef CONFIG_CPU_FREQ_MSM |
| 842 | static struct cpufreq_frequency_table freq_table[NR_CPUS][35]; |
| 843 | |
| 844 | static void __init cpufreq_table_init(void) |
| 845 | { |
| 846 | int cpu; |
| 847 | |
| 848 | for_each_possible_cpu(cpu) { |
| 849 | int i, freq_cnt = 0; |
| 850 | /* Construct the freq_table tables from acpu_freq_tbl. */ |
| 851 | for (i = 0; drv.acpu_freq_tbl[i].speed.khz != 0 |
| 852 | && freq_cnt < ARRAY_SIZE(*freq_table); i++) { |
| 853 | if (drv.acpu_freq_tbl[i].use_for_scaling) { |
| 854 | freq_table[cpu][freq_cnt].index = freq_cnt; |
| 855 | freq_table[cpu][freq_cnt].frequency |
| 856 | = drv.acpu_freq_tbl[i].speed.khz; |
| 857 | freq_cnt++; |
| 858 | } |
| 859 | } |
| 860 | /* freq_table not big enough to store all usable freqs. */ |
| 861 | BUG_ON(drv.acpu_freq_tbl[i].speed.khz != 0); |
| 862 | |
| 863 | freq_table[cpu][freq_cnt].index = freq_cnt; |
| 864 | freq_table[cpu][freq_cnt].frequency = CPUFREQ_TABLE_END; |
| 865 | |
| 866 | dev_info(drv.dev, "CPU%d: %d frequencies supported\n", |
| 867 | cpu, freq_cnt); |
| 868 | |
| 869 | /* Register table with CPUFreq. */ |
| 870 | cpufreq_frequency_table_get_attr(freq_table[cpu], cpu); |
| 871 | } |
| 872 | } |
| 873 | #else |
| 874 | static void __init cpufreq_table_init(void) {} |
| 875 | #endif |
| 876 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 877 | static int __cpuinit acpuclk_cpu_callback(struct notifier_block *nfb, |
| 878 | unsigned long action, void *hcpu) |
| 879 | { |
| 880 | static int prev_khz[NR_CPUS]; |
| 881 | int rc, cpu = (int)hcpu; |
| 882 | struct scalable *sc = &drv.scalable[cpu]; |
Matt Wagantall | b7c231b | 2012-07-24 18:40:17 -0700 | [diff] [blame] | 883 | unsigned long hot_unplug_khz = acpuclk_krait_data.power_collapse_khz; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 884 | |
| 885 | switch (action & ~CPU_TASKS_FROZEN) { |
| 886 | case CPU_DEAD: |
| 887 | prev_khz[cpu] = acpuclk_krait_get_rate(cpu); |
| 888 | /* Fall through. */ |
| 889 | case CPU_UP_CANCELED: |
Matt Wagantall | b7c231b | 2012-07-24 18:40:17 -0700 | [diff] [blame] | 890 | acpuclk_krait_set_rate(cpu, hot_unplug_khz, SETRATE_HOTPLUG); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 891 | regulator_set_optimum_mode(sc->vreg[VREG_CORE].reg, 0); |
| 892 | break; |
| 893 | case CPU_UP_PREPARE: |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 894 | if (!sc->initialized) { |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 895 | rc = per_cpu_init(cpu); |
| 896 | if (rc) |
| 897 | return NOTIFY_BAD; |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 898 | break; |
| 899 | } |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 900 | if (WARN_ON(!prev_khz[cpu])) |
| 901 | return NOTIFY_BAD; |
| 902 | rc = regulator_set_optimum_mode(sc->vreg[VREG_CORE].reg, |
Matt Wagantall | 6d9c416 | 2012-07-16 18:58:16 -0700 | [diff] [blame] | 903 | sc->vreg[VREG_CORE].cur_ua); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 904 | if (rc < 0) |
| 905 | return NOTIFY_BAD; |
| 906 | acpuclk_krait_set_rate(cpu, prev_khz[cpu], SETRATE_HOTPLUG); |
| 907 | break; |
| 908 | default: |
| 909 | break; |
| 910 | } |
| 911 | |
| 912 | return NOTIFY_OK; |
| 913 | } |
| 914 | |
| 915 | static struct notifier_block __cpuinitdata acpuclk_cpu_notifier = { |
| 916 | .notifier_call = acpuclk_cpu_callback, |
| 917 | }; |
| 918 | |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 919 | static const int krait_needs_vmin(void) |
| 920 | { |
| 921 | switch (read_cpuid_id()) { |
| 922 | case 0x511F04D0: /* KR28M2A20 */ |
| 923 | case 0x511F04D1: /* KR28M2A21 */ |
| 924 | case 0x510F06F0: /* KR28M4A10 */ |
| 925 | return 1; |
| 926 | default: |
| 927 | return 0; |
| 928 | }; |
| 929 | } |
| 930 | |
| 931 | static void krait_apply_vmin(struct acpu_level *tbl) |
| 932 | { |
Stephen Boyd | a86214a | 2012-09-14 11:25:34 -0700 | [diff] [blame] | 933 | for (; tbl->speed.khz != 0; tbl++) { |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 934 | if (tbl->vdd_core < 1150000) |
| 935 | tbl->vdd_core = 1150000; |
Stephen Boyd | a86214a | 2012-09-14 11:25:34 -0700 | [diff] [blame] | 936 | tbl->avsdscr_setting = 0; |
| 937 | } |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 938 | } |
| 939 | |
Patrick Daly | 18d2d48 | 2012-08-24 14:22:06 -0700 | [diff] [blame] | 940 | static int __init get_speed_bin(u32 pte_efuse) |
| 941 | { |
| 942 | uint32_t speed_bin; |
| 943 | |
| 944 | speed_bin = pte_efuse & 0xF; |
| 945 | if (speed_bin == 0xF) |
| 946 | speed_bin = (pte_efuse >> 4) & 0xF; |
| 947 | |
| 948 | if (speed_bin == 0xF) { |
| 949 | speed_bin = 0; |
| 950 | dev_warn(drv.dev, "SPEED BIN: Defaulting to %d\n", speed_bin); |
| 951 | } else { |
| 952 | dev_info(drv.dev, "SPEED BIN: %d\n", speed_bin); |
| 953 | } |
| 954 | |
| 955 | return speed_bin; |
| 956 | } |
| 957 | |
| 958 | static int __init get_pvs_bin(u32 pte_efuse) |
| 959 | { |
| 960 | uint32_t pvs_bin; |
| 961 | |
| 962 | pvs_bin = (pte_efuse >> 10) & 0x7; |
| 963 | if (pvs_bin == 0x7) |
| 964 | pvs_bin = (pte_efuse >> 13) & 0x7; |
| 965 | |
| 966 | if (pvs_bin == 0x7) { |
| 967 | pvs_bin = 0; |
| 968 | dev_warn(drv.dev, "ACPU PVS: Defaulting to %d\n", pvs_bin); |
| 969 | } else { |
| 970 | dev_info(drv.dev, "ACPU PVS: %d\n", pvs_bin); |
| 971 | } |
| 972 | |
| 973 | return pvs_bin; |
| 974 | } |
| 975 | |
| 976 | static struct pvs_table * __init select_freq_plan(u32 pte_efuse_phys, |
| 977 | struct pvs_table (*pvs_tables)[NUM_PVS]) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 978 | { |
Matt Wagantall | ee2b437 | 2012-09-17 17:51:06 -0700 | [diff] [blame] | 979 | void __iomem *pte_efuse; |
Matt Wagantall | 488bef3 | 2012-07-13 19:42:11 -0700 | [diff] [blame] | 980 | u32 pte_efuse_val; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 981 | |
Matt Wagantall | ee2b437 | 2012-09-17 17:51:06 -0700 | [diff] [blame] | 982 | pte_efuse = ioremap(pte_efuse_phys, 4); |
Patrick Daly | 18d2d48 | 2012-08-24 14:22:06 -0700 | [diff] [blame] | 983 | if (!pte_efuse) { |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 984 | dev_err(drv.dev, "Unable to map QFPROM base\n"); |
Patrick Daly | 18d2d48 | 2012-08-24 14:22:06 -0700 | [diff] [blame] | 985 | return NULL; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 986 | } |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 987 | |
Patrick Daly | 18d2d48 | 2012-08-24 14:22:06 -0700 | [diff] [blame] | 988 | pte_efuse_val = readl_relaxed(pte_efuse); |
| 989 | iounmap(pte_efuse); |
| 990 | |
| 991 | /* Select frequency tables. */ |
Matt Wagantall | 488bef3 | 2012-07-13 19:42:11 -0700 | [diff] [blame] | 992 | drv.speed_bin = get_speed_bin(pte_efuse_val); |
| 993 | drv.pvs_bin = get_pvs_bin(pte_efuse_val); |
Patrick Daly | 18d2d48 | 2012-08-24 14:22:06 -0700 | [diff] [blame] | 994 | |
Matt Wagantall | 488bef3 | 2012-07-13 19:42:11 -0700 | [diff] [blame] | 995 | return &pvs_tables[drv.speed_bin][drv.pvs_bin]; |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 996 | } |
Matt Wagantall | 06e4a1f | 2012-06-07 18:38:13 -0700 | [diff] [blame] | 997 | |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 998 | static void __init drv_data_init(struct device *dev, |
| 999 | const struct acpuclk_krait_params *params) |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 1000 | { |
Patrick Daly | 18d2d48 | 2012-08-24 14:22:06 -0700 | [diff] [blame] | 1001 | struct pvs_table *pvs; |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 1002 | |
| 1003 | drv.dev = dev; |
| 1004 | drv.scalable = kmemdup(params->scalable, params->scalable_size, |
| 1005 | GFP_KERNEL); |
| 1006 | BUG_ON(!drv.scalable); |
| 1007 | |
| 1008 | drv.hfpll_data = kmemdup(params->hfpll_data, sizeof(*drv.hfpll_data), |
| 1009 | GFP_KERNEL); |
| 1010 | BUG_ON(!drv.hfpll_data); |
| 1011 | |
| 1012 | drv.l2_freq_tbl = kmemdup(params->l2_freq_tbl, params->l2_freq_tbl_size, |
| 1013 | GFP_KERNEL); |
| 1014 | BUG_ON(!drv.l2_freq_tbl); |
| 1015 | |
| 1016 | drv.bus_scale = kmemdup(params->bus_scale, sizeof(*drv.bus_scale), |
| 1017 | GFP_KERNEL); |
| 1018 | BUG_ON(!drv.bus_scale); |
| 1019 | drv.bus_scale->usecase = kmemdup(drv.bus_scale->usecase, |
| 1020 | drv.bus_scale->num_usecases * sizeof(*drv.bus_scale->usecase), |
| 1021 | GFP_KERNEL); |
| 1022 | BUG_ON(!drv.bus_scale->usecase); |
| 1023 | |
Patrick Daly | 18d2d48 | 2012-08-24 14:22:06 -0700 | [diff] [blame] | 1024 | pvs = select_freq_plan(params->pte_efuse_phys, params->pvs_tables); |
| 1025 | BUG_ON(!pvs->table); |
| 1026 | |
| 1027 | drv.acpu_freq_tbl = kmemdup(pvs->table, pvs->size, GFP_KERNEL); |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 1028 | BUG_ON(!drv.acpu_freq_tbl); |
Patrick Daly | 18d2d48 | 2012-08-24 14:22:06 -0700 | [diff] [blame] | 1029 | drv.boost_uv = pvs->boost_uv; |
Matt Wagantall | b7c231b | 2012-07-24 18:40:17 -0700 | [diff] [blame] | 1030 | |
| 1031 | acpuclk_krait_data.power_collapse_khz = params->stby_khz; |
| 1032 | acpuclk_krait_data.wait_for_irq_khz = params->stby_khz; |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| 1035 | static void __init hw_init(void) |
| 1036 | { |
| 1037 | struct scalable *l2 = &drv.scalable[L2]; |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 1038 | const struct l2_level *l2_level; |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 1039 | int cpu, rc; |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 1040 | |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 1041 | if (krait_needs_vmin()) |
| 1042 | krait_apply_vmin(drv.acpu_freq_tbl); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 1043 | |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 1044 | l2->hfpll_base = ioremap(l2->hfpll_phys_base, SZ_32); |
| 1045 | BUG_ON(!l2->hfpll_base); |
Matt Wagantall | 754ee27 | 2012-06-18 13:40:26 -0700 | [diff] [blame] | 1046 | |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 1047 | rc = rpm_regulator_init(l2, VREG_HFPLL_A, |
| 1048 | l2->vreg[VREG_HFPLL_A].max_vdd, false); |
| 1049 | BUG_ON(rc); |
| 1050 | rc = rpm_regulator_init(l2, VREG_HFPLL_B, |
| 1051 | l2->vreg[VREG_HFPLL_B].max_vdd, false); |
| 1052 | BUG_ON(rc); |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 1053 | |
| 1054 | l2_level = find_cur_l2_level(); |
Matt Wagantall | b7c231b | 2012-07-24 18:40:17 -0700 | [diff] [blame] | 1055 | if (!l2_level) { |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 1056 | l2_level = drv.l2_freq_tbl; |
Matt Wagantall | b7c231b | 2012-07-24 18:40:17 -0700 | [diff] [blame] | 1057 | dev_dbg(drv.dev, "L2 is running at an unknown rate. Defaulting to %lu KHz.\n", |
| 1058 | l2_level->speed.khz); |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 1059 | } else { |
| 1060 | dev_dbg(drv.dev, "L2 is running at %lu KHz\n", |
| 1061 | l2_level->speed.khz); |
| 1062 | } |
| 1063 | |
| 1064 | rc = init_clock_sources(l2, &l2_level->speed); |
Matt Wagantall | 302d9a3 | 2012-07-03 13:37:29 -0700 | [diff] [blame] | 1065 | BUG_ON(rc); |
| 1066 | |
| 1067 | for_each_online_cpu(cpu) { |
| 1068 | rc = per_cpu_init(cpu); |
| 1069 | BUG_ON(rc); |
| 1070 | } |
Matt Wagantall | 9c8cb6e | 2012-07-13 19:39:15 -0700 | [diff] [blame] | 1071 | |
| 1072 | bus_init(l2_level); |
Matt Wagantall | 1f3762d | 2012-06-08 19:08:48 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | int __init acpuclk_krait_init(struct device *dev, |
| 1076 | const struct acpuclk_krait_params *params) |
| 1077 | { |
| 1078 | drv_data_init(dev, params); |
| 1079 | hw_init(); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 1080 | |
| 1081 | cpufreq_table_init(); |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 1082 | acpuclk_register(&acpuclk_krait_data); |
| 1083 | register_hotcpu_notifier(&acpuclk_cpu_notifier); |
| 1084 | |
Matt Wagantall | 488bef3 | 2012-07-13 19:42:11 -0700 | [diff] [blame] | 1085 | acpuclk_krait_debug_init(&drv); |
| 1086 | |
Matt Wagantall | e9b715a | 2012-01-04 18:16:14 -0800 | [diff] [blame] | 1087 | return 0; |
| 1088 | } |