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