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