Blame view
arch/arm/mach-omap2/vc.c
10.2 KB
ccd5ca778 OMAP2+: voltage: ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * OMAP Voltage Controller (VC) interface * * Copyright (C) 2011 Texas Instruments, Inc. * * This file is licensed under the terms of the GNU General Public * License version 2. This program is licensed "as is" without any * warranty of any kind, whether express or implied. */ #include <linux/kernel.h> #include <linux/delay.h> #include <linux/init.h> #include <plat/cpu.h> |
536a4c8bb arm: omap: am33x:... |
15 16 |
#include <plat/voltage.h> #include <plat/vc.h> |
ccd5ca778 OMAP2+: voltage: ... |
17 |
|
ccd5ca778 OMAP2+: voltage: ... |
18 19 20 |
#include "prm-regbits-34xx.h" #include "prm-regbits-44xx.h" #include "prm44xx.h" |
8abc0b58f OMAP3+: PM: VC: h... |
21 22 23 24 25 26 27 28 29 |
/** * struct omap_vc_channel_cfg - describe the cfg_channel bitfield * @sa: bit for slave address * @rav: bit for voltage configuration register * @rac: bit for command configuration register * @racen: enable bit for RAC * @cmd: bit for command value set selection * * Channel configuration bits, common for OMAP3+ |
24d3194a2 OMAP3+: VC: abstr... |
30 31 |
* OMAP3 register: PRM_VC_CH_CONF * OMAP4 register: PRM_VC_CFG_CHANNEL |
8abc0b58f OMAP3+: PM: VC: h... |
32 |
* OMAP5 register: PRM_VC_SMPS_<voltdm>_CONFIG |
24d3194a2 OMAP3+: VC: abstr... |
33 |
*/ |
8abc0b58f OMAP3+: PM: VC: h... |
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
struct omap_vc_channel_cfg { u8 sa; u8 rav; u8 rac; u8 racen; u8 cmd; }; static struct omap_vc_channel_cfg vc_default_channel_cfg = { .sa = BIT(0), .rav = BIT(1), .rac = BIT(2), .racen = BIT(3), .cmd = BIT(4), }; /* * On OMAP3+, all VC channels have the above default bitfield * configuration, except the OMAP4 MPU channel. This appears * to be a freak accident as every other VC channel has the * default configuration, thus creating a mutant channel config. */ static struct omap_vc_channel_cfg vc_mutant_channel_cfg = { .sa = BIT(0), .rav = BIT(2), .rac = BIT(3), .racen = BIT(4), .cmd = BIT(1), }; static struct omap_vc_channel_cfg *vc_cfg_bits; #define CFG_CHANNEL_MASK 0x1f |
24d3194a2 OMAP3+: VC: abstr... |
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
/** * omap_vc_config_channel - configure VC channel to PMIC mappings * @voltdm: pointer to voltagdomain defining the desired VC channel * * Configures the VC channel to PMIC mappings for the following * PMIC settings * - i2c slave address (SA) * - voltage configuration address (RAV) * - command configuration address (RAC) and enable bit (RACEN) * - command values for ON, ONLP, RET and OFF (CMD) * * This function currently only allows flexible configuration of the * non-default channel. Starting with OMAP4, there are more than 2 * channels, with one defined as the default (on OMAP4, it's MPU.) * Only the non-default channel can be configured. */ static int omap_vc_config_channel(struct voltagedomain *voltdm) { struct omap_vc_channel *vc = voltdm->vc; /* * For default channel, the only configurable bit is RACEN. * All others must stay at zero (see function comment above.) */ if (vc->flags & OMAP_VC_CHANNEL_DEFAULT) |
8abc0b58f OMAP3+: PM: VC: h... |
92 |
vc->cfg_channel &= vc_cfg_bits->racen; |
24d3194a2 OMAP3+: VC: abstr... |
93 94 95 |
voltdm->rmw(CFG_CHANNEL_MASK << vc->cfg_channel_sa_shift, vc->cfg_channel << vc->cfg_channel_sa_shift, |
5876c940c OMAP2+: VC: more ... |
96 |
vc->cfg_channel_reg); |
24d3194a2 OMAP3+: VC: abstr... |
97 98 99 |
return 0; } |
ccd5ca778 OMAP2+: voltage: ... |
100 101 102 103 104 |
/* Voltage scale and accessory APIs */ int omap_vc_pre_scale(struct voltagedomain *voltdm, unsigned long target_volt, u8 *target_vsel, u8 *current_vsel) { |
d84adcf46 OMAP2+: voltage: ... |
105 |
struct omap_vc_channel *vc = voltdm->vc; |
76ea7424f OMAP3+: VP: creat... |
106 |
u32 vc_cmdval; |
ccd5ca778 OMAP2+: voltage: ... |
107 |
|
ccd5ca778 OMAP2+: voltage: ... |
108 |
/* Check if sufficient pmic info is available for this vdd */ |
ce8ebe0df OMAP3+: voltage d... |
109 |
if (!voltdm->pmic) { |
ccd5ca778 OMAP2+: voltage: ... |
110 111 112 113 114 |
pr_err("%s: Insufficient pmic info to scale the vdd_%s ", __func__, voltdm->name); return -EINVAL; } |
ce8ebe0df OMAP3+: voltage d... |
115 |
if (!voltdm->pmic->uv_to_vsel) { |
ccd5ca778 OMAP2+: voltage: ... |
116 117 118 119 120 121 |
pr_err("%s: PMIC function to convert voltage in uV to" "vsel not registered. Hence unable to scale voltage" "for vdd_%s ", __func__, voltdm->name); return -ENODATA; } |
4bcc475eb OMAP3+: voltage: ... |
122 |
if (!voltdm->read || !voltdm->write) { |
ccd5ca778 OMAP2+: voltage: ... |
123 124 125 126 127 |
pr_err("%s: No read/write API for accessing vdd_%s regs ", __func__, voltdm->name); return -EINVAL; } |
ce8ebe0df OMAP3+: voltage d... |
128 |
*target_vsel = voltdm->pmic->uv_to_vsel(target_volt); |
7590f608a OMAP3+: voltage: ... |
129 |
*current_vsel = voltdm->pmic->uv_to_vsel(voltdm->nominal_volt); |
ccd5ca778 OMAP2+: voltage: ... |
130 131 |
/* Setting the ON voltage to the new target voltage */ |
4bcc475eb OMAP3+: voltage: ... |
132 |
vc_cmdval = voltdm->read(vc->cmdval_reg); |
d84adcf46 OMAP2+: voltage: ... |
133 134 |
vc_cmdval &= ~vc->common->cmd_on_mask; vc_cmdval |= (*target_vsel << vc->common->cmd_on_shift); |
4bcc475eb OMAP3+: voltage: ... |
135 |
voltdm->write(vc_cmdval, vc->cmdval_reg); |
ccd5ca778 OMAP2+: voltage: ... |
136 |
|
76ea7424f OMAP3+: VP: creat... |
137 |
omap_vp_update_errorgain(voltdm, target_volt); |
ccd5ca778 OMAP2+: voltage: ... |
138 139 140 141 142 143 144 145 |
return 0; } void omap_vc_post_scale(struct voltagedomain *voltdm, unsigned long target_volt, u8 target_vsel, u8 current_vsel) { |
ccd5ca778 OMAP2+: voltage: ... |
146 147 148 149 |
u32 smps_steps = 0, smps_delay = 0; smps_steps = abs(target_vsel - current_vsel); /* SMPS slew rate / step size. 2us added as buffer. */ |
ce8ebe0df OMAP3+: voltage d... |
150 151 |
smps_delay = ((smps_steps * voltdm->pmic->step_size) / voltdm->pmic->slew_rate) + 2; |
ccd5ca778 OMAP2+: voltage: ... |
152 |
udelay(smps_delay); |
ccd5ca778 OMAP2+: voltage: ... |
153 |
} |
d84adcf46 OMAP2+: voltage: ... |
154 155 156 |
/* vc_bypass_scale - VC bypass method of voltage scaling */ int omap_vc_bypass_scale(struct voltagedomain *voltdm, unsigned long target_volt) |
ccd5ca778 OMAP2+: voltage: ... |
157 |
{ |
d84adcf46 OMAP2+: voltage: ... |
158 |
struct omap_vc_channel *vc = voltdm->vc; |
ccd5ca778 OMAP2+: voltage: ... |
159 160 161 162 163 164 165 166 |
u32 loop_cnt = 0, retries_cnt = 0; u32 vc_valid, vc_bypass_val_reg, vc_bypass_value; u8 target_vsel, current_vsel; int ret; ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, ¤t_vsel); if (ret) return ret; |
d84adcf46 OMAP2+: voltage: ... |
167 168 169 |
vc_valid = vc->common->valid; vc_bypass_val_reg = vc->common->bypass_val_reg; vc_bypass_value = (target_vsel << vc->common->data_shift) | |
78614e0f8 OMAP3+: VC bypass... |
170 171 |
(vc->volt_reg_addr << vc->common->regaddr_shift) | (vc->i2c_slave_addr << vc->common->slaveaddr_shift); |
ccd5ca778 OMAP2+: voltage: ... |
172 |
|
4bcc475eb OMAP3+: voltage: ... |
173 174 |
voltdm->write(vc_bypass_value, vc_bypass_val_reg); voltdm->write(vc_bypass_value | vc_valid, vc_bypass_val_reg); |
ccd5ca778 OMAP2+: voltage: ... |
175 |
|
4bcc475eb OMAP3+: voltage: ... |
176 |
vc_bypass_value = voltdm->read(vc_bypass_val_reg); |
ccd5ca778 OMAP2+: voltage: ... |
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
/* * Loop till the bypass command is acknowledged from the SMPS. * NOTE: This is legacy code. The loop count and retry count needs * to be revisited. */ while (!(vc_bypass_value & vc_valid)) { loop_cnt++; if (retries_cnt > 10) { pr_warning("%s: Retry count exceeded ", __func__); return -ETIMEDOUT; } if (loop_cnt > 50) { retries_cnt++; loop_cnt = 0; udelay(10); } |
4bcc475eb OMAP3+: voltage: ... |
196 |
vc_bypass_value = voltdm->read(vc_bypass_val_reg); |
ccd5ca778 OMAP2+: voltage: ... |
197 198 199 200 201 202 203 204 |
} omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel); return 0; } static void __init omap3_vfsm_init(struct voltagedomain *voltdm) { |
ccd5ca778 OMAP2+: voltage: ... |
205 206 207 208 |
/* * Voltage Manager FSM parameters init * XXX This data should be passed in from the board file */ |
4bcc475eb OMAP3+: voltage: ... |
209 210 211 |
voltdm->write(OMAP3_CLKSETUP, OMAP3_PRM_CLKSETUP_OFFSET); voltdm->write(OMAP3_VOLTOFFSET, OMAP3_PRM_VOLTOFFSET_OFFSET); voltdm->write(OMAP3_VOLTSETUP2, OMAP3_PRM_VOLTSETUP2_OFFSET); |
ccd5ca778 OMAP2+: voltage: ... |
212 213 214 215 |
} static void __init omap3_vc_init_channel(struct voltagedomain *voltdm) { |
ccd5ca778 OMAP2+: voltage: ... |
216 |
static bool is_initialized; |
ccd5ca778 OMAP2+: voltage: ... |
217 218 219 |
if (is_initialized) return; |
ccd5ca778 OMAP2+: voltage: ... |
220 221 222 223 224 225 226 227 228 |
omap3_vfsm_init(voltdm); is_initialized = true; } /* OMAP4 specific voltage init functions */ static void __init omap4_vc_init_channel(struct voltagedomain *voltdm) { |
ccd5ca778 OMAP2+: voltage: ... |
229 230 231 232 233 |
static bool is_initialized; u32 vc_val; if (is_initialized) return; |
ccd5ca778 OMAP2+: voltage: ... |
234 235 |
/* XXX These are magic numbers and do not belong! */ vc_val = (0x60 << OMAP4430_SCLL_SHIFT | 0x26 << OMAP4430_SCLH_SHIFT); |
4bcc475eb OMAP3+: voltage: ... |
236 |
voltdm->write(vc_val, OMAP4_PRM_VC_CFG_I2C_CLK_OFFSET); |
ccd5ca778 OMAP2+: voltage: ... |
237 238 239 |
is_initialized = true; } |
f5395480f OMAP3+: VC: make ... |
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
/** * omap_vc_i2c_init - initialize I2C interface to PMIC * @voltdm: voltage domain containing VC data * * Use PMIC supplied seetings for I2C high-speed mode and * master code (if set) and program the VC I2C configuration * register. * * The VC I2C configuration is common to all VC channels, * so this function only configures I2C for the first VC * channel registers. All other VC channels will use the * same configuration. */ static void __init omap_vc_i2c_init(struct voltagedomain *voltdm) { struct omap_vc_channel *vc = voltdm->vc; static bool initialized; static bool i2c_high_speed; u8 mcode; if (initialized) { if (voltdm->pmic->i2c_high_speed != i2c_high_speed) pr_warn("%s: I2C config for all channels must match.", __func__); return; } i2c_high_speed = voltdm->pmic->i2c_high_speed; if (i2c_high_speed) voltdm->rmw(vc->common->i2c_cfg_hsen_mask, vc->common->i2c_cfg_hsen_mask, vc->common->i2c_cfg_reg); mcode = voltdm->pmic->i2c_mcode; if (mcode) voltdm->rmw(vc->common->i2c_mcode_mask, mcode << __ffs(vc->common->i2c_mcode_mask), vc->common->i2c_cfg_reg); initialized = true; } |
ccd5ca778 OMAP2+: voltage: ... |
281 282 |
void __init omap_vc_init_channel(struct voltagedomain *voltdm) { |
d84adcf46 OMAP2+: voltage: ... |
283 |
struct omap_vc_channel *vc = voltdm->vc; |
08d1c9a3e OMAP3+: VC: move ... |
284 285 |
u8 on_vsel, onlp_vsel, ret_vsel, off_vsel; u32 val; |
ccd5ca778 OMAP2+: voltage: ... |
286 |
|
ce8ebe0df OMAP3+: voltage d... |
287 |
if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) { |
ccd5ca778 OMAP2+: voltage: ... |
288 289 290 291 292 293 |
pr_err("%s: PMIC info requried to configure vc for" "vdd_%s not populated.Hence cannot initialize vc ", __func__, voltdm->name); return; } |
4bcc475eb OMAP3+: voltage: ... |
294 |
if (!voltdm->read || !voltdm->write) { |
ccd5ca778 OMAP2+: voltage: ... |
295 296 297 298 299 |
pr_err("%s: No read/write API for accessing vdd_%s regs ", __func__, voltdm->name); return; } |
24d3194a2 OMAP3+: VC: abstr... |
300 |
vc->cfg_channel = 0; |
8abc0b58f OMAP3+: PM: VC: h... |
301 302 303 304 |
if (vc->flags & OMAP_VC_CHANNEL_CFG_MUTANT) vc_cfg_bits = &vc_mutant_channel_cfg; else vc_cfg_bits = &vc_default_channel_cfg; |
24d3194a2 OMAP3+: VC: abstr... |
305 |
|
ba112a4e8 OMAP3+: VC: clean... |
306 |
/* get PMIC/board specific settings */ |
ce8ebe0df OMAP3+: voltage d... |
307 308 309 310 |
vc->i2c_slave_addr = voltdm->pmic->i2c_slave_addr; vc->volt_reg_addr = voltdm->pmic->volt_reg_addr; vc->cmd_reg_addr = voltdm->pmic->cmd_reg_addr; vc->setup_time = voltdm->pmic->volt_setup_time; |
ba112a4e8 OMAP3+: VC: clean... |
311 312 313 314 |
/* Configure the i2c slave address for this VC */ voltdm->rmw(vc->smps_sa_mask, vc->i2c_slave_addr << __ffs(vc->smps_sa_mask), |
5876c940c OMAP2+: VC: more ... |
315 |
vc->smps_sa_reg); |
8abc0b58f OMAP3+: PM: VC: h... |
316 |
vc->cfg_channel |= vc_cfg_bits->sa; |
ccd5ca778 OMAP2+: voltage: ... |
317 |
|
e4e021c54 OMAP3+: VC: clean... |
318 319 320 321 322 |
/* * Configure the PMIC register addresses. */ voltdm->rmw(vc->smps_volra_mask, vc->volt_reg_addr << __ffs(vc->smps_volra_mask), |
5876c940c OMAP2+: VC: more ... |
323 |
vc->smps_volra_reg); |
8abc0b58f OMAP3+: PM: VC: h... |
324 |
vc->cfg_channel |= vc_cfg_bits->rav; |
24d3194a2 OMAP3+: VC: abstr... |
325 326 |
if (vc->cmd_reg_addr) { |
e4e021c54 OMAP3+: VC: clean... |
327 328 |
voltdm->rmw(vc->smps_cmdra_mask, vc->cmd_reg_addr << __ffs(vc->smps_cmdra_mask), |
5876c940c OMAP2+: VC: more ... |
329 |
vc->smps_cmdra_reg); |
8abc0b58f OMAP3+: PM: VC: h... |
330 |
vc->cfg_channel |= vc_cfg_bits->rac | vc_cfg_bits->racen; |
24d3194a2 OMAP3+: VC: abstr... |
331 |
} |
ccd5ca778 OMAP2+: voltage: ... |
332 |
|
08d1c9a3e OMAP3+: VC: move ... |
333 |
/* Set up the on, inactive, retention and off voltage */ |
ce8ebe0df OMAP3+: voltage d... |
334 335 336 337 |
on_vsel = voltdm->pmic->uv_to_vsel(voltdm->pmic->on_volt); onlp_vsel = voltdm->pmic->uv_to_vsel(voltdm->pmic->onlp_volt); ret_vsel = voltdm->pmic->uv_to_vsel(voltdm->pmic->ret_volt); off_vsel = voltdm->pmic->uv_to_vsel(voltdm->pmic->off_volt); |
08d1c9a3e OMAP3+: VC: move ... |
338 339 340 341 342 |
val = ((on_vsel << vc->common->cmd_on_shift) | (onlp_vsel << vc->common->cmd_onlp_shift) | (ret_vsel << vc->common->cmd_ret_shift) | (off_vsel << vc->common->cmd_off_shift)); voltdm->write(val, vc->cmdval_reg); |
8abc0b58f OMAP3+: PM: VC: h... |
343 |
vc->cfg_channel |= vc_cfg_bits->cmd; |
24d3194a2 OMAP3+: VC: abstr... |
344 345 346 |
/* Channel configuration */ omap_vc_config_channel(voltdm); |
08d1c9a3e OMAP3+: VC: move ... |
347 |
|
ccd5ca778 OMAP2+: voltage: ... |
348 |
/* Configure the setup times */ |
5892bb1fc OMAP3+: VC: clean... |
349 350 351 |
voltdm->rmw(voltdm->vfsm->voltsetup_mask, vc->setup_time << __ffs(voltdm->vfsm->voltsetup_mask), voltdm->vfsm->voltsetup_reg); |
ccd5ca778 OMAP2+: voltage: ... |
352 |
|
f5395480f OMAP3+: VC: make ... |
353 |
omap_vc_i2c_init(voltdm); |
ccd5ca778 OMAP2+: voltage: ... |
354 355 356 357 358 |
if (cpu_is_omap34xx()) omap3_vc_init_channel(voltdm); else if (cpu_is_omap44xx()) omap4_vc_init_channel(voltdm); } |