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