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