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