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