Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP Voltage Controller (VC) interface |
| 3 | * |
| 4 | * Copyright (C) 2011 Texas Instruments, Inc. |
| 5 | * |
| 6 | * This file is licensed under the terms of the GNU General Public |
| 7 | * License version 2. This program is licensed "as is" without any |
| 8 | * warranty of any kind, whether express or implied. |
| 9 | */ |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <linux/init.h> |
Tony Lindgren | 4647ca5 | 2012-03-08 10:20:14 -0800 | [diff] [blame] | 13 | #include <linux/bug.h> |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 14 | |
Tony Lindgren | dbc0416 | 2012-08-31 10:59:07 -0700 | [diff] [blame] | 15 | #include "soc.h" |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 16 | #include "voltage.h" |
| 17 | #include "vc.h" |
| 18 | #include "prm-regbits-34xx.h" |
| 19 | #include "prm-regbits-44xx.h" |
| 20 | #include "prm44xx.h" |
| 21 | |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 22 | /** |
| 23 | * struct omap_vc_channel_cfg - describe the cfg_channel bitfield |
| 24 | * @sa: bit for slave address |
| 25 | * @rav: bit for voltage configuration register |
| 26 | * @rac: bit for command configuration register |
| 27 | * @racen: enable bit for RAC |
| 28 | * @cmd: bit for command value set selection |
| 29 | * |
| 30 | * Channel configuration bits, common for OMAP3+ |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 31 | * OMAP3 register: PRM_VC_CH_CONF |
| 32 | * OMAP4 register: PRM_VC_CFG_CHANNEL |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 33 | * OMAP5 register: PRM_VC_SMPS_<voltdm>_CONFIG |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 34 | */ |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 35 | struct omap_vc_channel_cfg { |
| 36 | u8 sa; |
| 37 | u8 rav; |
| 38 | u8 rac; |
| 39 | u8 racen; |
| 40 | u8 cmd; |
| 41 | }; |
| 42 | |
| 43 | static struct omap_vc_channel_cfg vc_default_channel_cfg = { |
| 44 | .sa = BIT(0), |
| 45 | .rav = BIT(1), |
| 46 | .rac = BIT(2), |
| 47 | .racen = BIT(3), |
| 48 | .cmd = BIT(4), |
| 49 | }; |
| 50 | |
| 51 | /* |
| 52 | * On OMAP3+, all VC channels have the above default bitfield |
| 53 | * configuration, except the OMAP4 MPU channel. This appears |
| 54 | * to be a freak accident as every other VC channel has the |
| 55 | * default configuration, thus creating a mutant channel config. |
| 56 | */ |
| 57 | static struct omap_vc_channel_cfg vc_mutant_channel_cfg = { |
| 58 | .sa = BIT(0), |
| 59 | .rav = BIT(2), |
| 60 | .rac = BIT(3), |
| 61 | .racen = BIT(4), |
| 62 | .cmd = BIT(1), |
| 63 | }; |
| 64 | |
| 65 | static struct omap_vc_channel_cfg *vc_cfg_bits; |
| 66 | #define CFG_CHANNEL_MASK 0x1f |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * omap_vc_config_channel - configure VC channel to PMIC mappings |
| 70 | * @voltdm: pointer to voltagdomain defining the desired VC channel |
| 71 | * |
| 72 | * Configures the VC channel to PMIC mappings for the following |
| 73 | * PMIC settings |
| 74 | * - i2c slave address (SA) |
| 75 | * - voltage configuration address (RAV) |
| 76 | * - command configuration address (RAC) and enable bit (RACEN) |
| 77 | * - command values for ON, ONLP, RET and OFF (CMD) |
| 78 | * |
| 79 | * This function currently only allows flexible configuration of the |
| 80 | * non-default channel. Starting with OMAP4, there are more than 2 |
| 81 | * channels, with one defined as the default (on OMAP4, it's MPU.) |
| 82 | * Only the non-default channel can be configured. |
| 83 | */ |
| 84 | static int omap_vc_config_channel(struct voltagedomain *voltdm) |
| 85 | { |
| 86 | struct omap_vc_channel *vc = voltdm->vc; |
| 87 | |
| 88 | /* |
| 89 | * For default channel, the only configurable bit is RACEN. |
| 90 | * All others must stay at zero (see function comment above.) |
| 91 | */ |
| 92 | if (vc->flags & OMAP_VC_CHANNEL_DEFAULT) |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 93 | vc->cfg_channel &= vc_cfg_bits->racen; |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 94 | |
| 95 | voltdm->rmw(CFG_CHANNEL_MASK << vc->cfg_channel_sa_shift, |
| 96 | vc->cfg_channel << vc->cfg_channel_sa_shift, |
Kevin Hilman | 5876c94 | 2011-07-20 16:35:46 -0700 | [diff] [blame] | 97 | vc->cfg_channel_reg); |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 102 | /* Voltage scale and accessory APIs */ |
| 103 | int omap_vc_pre_scale(struct voltagedomain *voltdm, |
| 104 | unsigned long target_volt, |
| 105 | u8 *target_vsel, u8 *current_vsel) |
| 106 | { |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 107 | struct omap_vc_channel *vc = voltdm->vc; |
Kevin Hilman | 76ea742 | 2011-04-05 15:15:31 -0700 | [diff] [blame] | 108 | u32 vc_cmdval; |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 109 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 110 | /* Check if sufficient pmic info is available for this vdd */ |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 111 | if (!voltdm->pmic) { |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 112 | pr_err("%s: Insufficient pmic info to scale the vdd_%s\n", |
| 113 | __func__, voltdm->name); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 117 | if (!voltdm->pmic->uv_to_vsel) { |
Paul Walmsley | 7852ec0 | 2012-07-26 00:54:26 -0600 | [diff] [blame] | 118 | pr_err("%s: PMIC function to convert voltage in uV to vsel not registered. Hence unable to scale voltage for vdd_%s\n", |
| 119 | __func__, voltdm->name); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 120 | return -ENODATA; |
| 121 | } |
| 122 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 123 | if (!voltdm->read || !voltdm->write) { |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 124 | pr_err("%s: No read/write API for accessing vdd_%s regs\n", |
| 125 | __func__, voltdm->name); |
| 126 | return -EINVAL; |
| 127 | } |
| 128 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 129 | *target_vsel = voltdm->pmic->uv_to_vsel(target_volt); |
Kevin Hilman | 7590f60 | 2011-04-05 16:55:22 -0700 | [diff] [blame] | 130 | *current_vsel = voltdm->pmic->uv_to_vsel(voltdm->nominal_volt); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 131 | |
| 132 | /* Setting the ON voltage to the new target voltage */ |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 133 | vc_cmdval = voltdm->read(vc->cmdval_reg); |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 134 | vc_cmdval &= ~vc->common->cmd_on_mask; |
| 135 | vc_cmdval |= (*target_vsel << vc->common->cmd_on_shift); |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 136 | voltdm->write(vc_cmdval, vc->cmdval_reg); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 137 | |
Tero Kristo | 8b5d8c0 | 2012-09-25 19:33:35 +0300 | [diff] [blame] | 138 | voltdm->vc_param->on = target_volt; |
| 139 | |
Kevin Hilman | 76ea742 | 2011-04-05 15:15:31 -0700 | [diff] [blame] | 140 | omap_vp_update_errorgain(voltdm, target_volt); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | void omap_vc_post_scale(struct voltagedomain *voltdm, |
| 146 | unsigned long target_volt, |
| 147 | u8 target_vsel, u8 current_vsel) |
| 148 | { |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 149 | u32 smps_steps = 0, smps_delay = 0; |
| 150 | |
| 151 | smps_steps = abs(target_vsel - current_vsel); |
| 152 | /* SMPS slew rate / step size. 2us added as buffer. */ |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 153 | smps_delay = ((smps_steps * voltdm->pmic->step_size) / |
| 154 | voltdm->pmic->slew_rate) + 2; |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 155 | udelay(smps_delay); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 158 | /* vc_bypass_scale - VC bypass method of voltage scaling */ |
| 159 | int omap_vc_bypass_scale(struct voltagedomain *voltdm, |
| 160 | unsigned long target_volt) |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 161 | { |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 162 | struct omap_vc_channel *vc = voltdm->vc; |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 163 | u32 loop_cnt = 0, retries_cnt = 0; |
| 164 | u32 vc_valid, vc_bypass_val_reg, vc_bypass_value; |
| 165 | u8 target_vsel, current_vsel; |
| 166 | int ret; |
| 167 | |
| 168 | ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, ¤t_vsel); |
| 169 | if (ret) |
| 170 | return ret; |
| 171 | |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 172 | vc_valid = vc->common->valid; |
| 173 | vc_bypass_val_reg = vc->common->bypass_val_reg; |
| 174 | vc_bypass_value = (target_vsel << vc->common->data_shift) | |
Kevin Hilman | 78614e0 | 2011-03-29 14:24:47 -0700 | [diff] [blame] | 175 | (vc->volt_reg_addr << vc->common->regaddr_shift) | |
| 176 | (vc->i2c_slave_addr << vc->common->slaveaddr_shift); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 177 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 178 | voltdm->write(vc_bypass_value, vc_bypass_val_reg); |
| 179 | voltdm->write(vc_bypass_value | vc_valid, vc_bypass_val_reg); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 180 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 181 | vc_bypass_value = voltdm->read(vc_bypass_val_reg); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 182 | /* |
| 183 | * Loop till the bypass command is acknowledged from the SMPS. |
| 184 | * NOTE: This is legacy code. The loop count and retry count needs |
| 185 | * to be revisited. |
| 186 | */ |
| 187 | while (!(vc_bypass_value & vc_valid)) { |
| 188 | loop_cnt++; |
| 189 | |
| 190 | if (retries_cnt > 10) { |
| 191 | pr_warning("%s: Retry count exceeded\n", __func__); |
| 192 | return -ETIMEDOUT; |
| 193 | } |
| 194 | |
| 195 | if (loop_cnt > 50) { |
| 196 | retries_cnt++; |
| 197 | loop_cnt = 0; |
| 198 | udelay(10); |
| 199 | } |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 200 | vc_bypass_value = voltdm->read(vc_bypass_val_reg); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel); |
| 204 | return 0; |
| 205 | } |
| 206 | |
Tero Kristo | c589eb3 | 2012-09-25 19:33:36 +0300 | [diff] [blame] | 207 | /** |
| 208 | * omap3_set_i2c_timings - sets i2c sleep timings for a channel |
| 209 | * @voltdm: channel to configure |
| 210 | * @off_mode: select whether retention or off mode values used |
| 211 | * |
| 212 | * Calculates and sets up voltage controller to use I2C based |
| 213 | * voltage scaling for sleep modes. This can be used for either off mode |
| 214 | * or retention. Off mode has additionally an option to use sys_off_mode |
| 215 | * pad, which uses a global signal to program the whole power IC to |
| 216 | * off-mode. |
| 217 | */ |
| 218 | static void omap3_set_i2c_timings(struct voltagedomain *voltdm, bool off_mode) |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 219 | { |
Tero Kristo | c589eb3 | 2012-09-25 19:33:36 +0300 | [diff] [blame] | 220 | unsigned long voltsetup1; |
| 221 | u32 tgt_volt; |
| 222 | |
| 223 | if (off_mode) |
| 224 | tgt_volt = voltdm->vc_param->off; |
| 225 | else |
| 226 | tgt_volt = voltdm->vc_param->ret; |
| 227 | |
| 228 | voltsetup1 = (voltdm->vc_param->on - tgt_volt) / |
| 229 | voltdm->pmic->slew_rate; |
| 230 | |
| 231 | voltsetup1 = voltsetup1 * voltdm->sys_clk.rate / 8 / 1000000 + 1; |
| 232 | |
| 233 | voltdm->rmw(voltdm->vfsm->voltsetup_mask, |
| 234 | voltsetup1 << __ffs(voltdm->vfsm->voltsetup_mask), |
| 235 | voltdm->vfsm->voltsetup_reg); |
| 236 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 237 | /* |
Tero Kristo | c589eb3 | 2012-09-25 19:33:36 +0300 | [diff] [blame] | 238 | * pmic is not controlling the voltage scaling during retention, |
| 239 | * thus set voltsetup2 to 0 |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 240 | */ |
Tero Kristo | c589eb3 | 2012-09-25 19:33:36 +0300 | [diff] [blame] | 241 | voltdm->write(0, OMAP3_PRM_VOLTSETUP2_OFFSET); |
| 242 | } |
| 243 | |
| 244 | /** |
| 245 | * omap3_set_off_timings - sets off-mode timings for a channel |
| 246 | * @voltdm: channel to configure |
| 247 | * |
| 248 | * Calculates and sets up off-mode timings for a channel. Off-mode |
| 249 | * can use either I2C based voltage scaling, or alternatively |
| 250 | * sys_off_mode pad can be used to send a global command to power IC. |
| 251 | * This function first checks which mode is being used, and calls |
| 252 | * omap3_set_i2c_timings() if the system is using I2C control mode. |
| 253 | * sys_off_mode has the additional benefit that voltages can be |
| 254 | * scaled to zero volt level with TWL4030 / TWL5030, I2C can only |
| 255 | * scale to 600mV. |
| 256 | */ |
| 257 | static void omap3_set_off_timings(struct voltagedomain *voltdm) |
| 258 | { |
| 259 | unsigned long clksetup; |
| 260 | unsigned long voltsetup2; |
| 261 | unsigned long voltsetup2_old; |
| 262 | u32 val; |
| 263 | |
| 264 | /* check if sys_off_mode is used to control off-mode voltages */ |
| 265 | val = voltdm->read(OMAP3_PRM_VOLTCTRL_OFFSET); |
| 266 | if (!(val & OMAP3430_SEL_OFF_MASK)) { |
| 267 | /* No, omap is controlling them over I2C */ |
| 268 | omap3_set_i2c_timings(voltdm, true); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | clksetup = voltdm->read(OMAP3_PRM_CLKSETUP_OFFSET); |
| 273 | |
| 274 | /* voltsetup 2 in us */ |
| 275 | voltsetup2 = voltdm->vc_param->on / voltdm->pmic->slew_rate; |
| 276 | |
| 277 | /* convert to 32k clk cycles */ |
| 278 | voltsetup2 = DIV_ROUND_UP(voltsetup2 * 32768, 1000000); |
| 279 | |
| 280 | voltsetup2_old = voltdm->read(OMAP3_PRM_VOLTSETUP2_OFFSET); |
| 281 | |
| 282 | /* |
| 283 | * Update voltsetup2 if higher than current value (needed because |
| 284 | * we have multiple channels with different ramp times), also |
| 285 | * update voltoffset always to value recommended by TRM |
| 286 | */ |
| 287 | if (voltsetup2 > voltsetup2_old) { |
| 288 | voltdm->write(voltsetup2, OMAP3_PRM_VOLTSETUP2_OFFSET); |
| 289 | voltdm->write(clksetup - voltsetup2, |
| 290 | OMAP3_PRM_VOLTOFFSET_OFFSET); |
| 291 | } else |
| 292 | voltdm->write(clksetup - voltsetup2_old, |
| 293 | OMAP3_PRM_VOLTOFFSET_OFFSET); |
| 294 | |
| 295 | /* |
| 296 | * omap is not controlling voltage scaling during off-mode, |
| 297 | * thus set voltsetup1 to 0 |
| 298 | */ |
| 299 | voltdm->rmw(voltdm->vfsm->voltsetup_mask, 0, |
| 300 | voltdm->vfsm->voltsetup_reg); |
| 301 | |
| 302 | /* voltoffset must be clksetup minus voltsetup2 according to TRM */ |
| 303 | voltdm->write(clksetup - voltsetup2, OMAP3_PRM_VOLTOFFSET_OFFSET); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | static void __init omap3_vc_init_channel(struct voltagedomain *voltdm) |
| 307 | { |
Tero Kristo | c589eb3 | 2012-09-25 19:33:36 +0300 | [diff] [blame] | 308 | omap3_set_off_timings(voltdm); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 311 | /* OMAP4 specific voltage init functions */ |
| 312 | static void __init omap4_vc_init_channel(struct voltagedomain *voltdm) |
| 313 | { |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 314 | static bool is_initialized; |
| 315 | u32 vc_val; |
| 316 | |
| 317 | if (is_initialized) |
| 318 | return; |
| 319 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 320 | /* XXX These are magic numbers and do not belong! */ |
| 321 | vc_val = (0x60 << OMAP4430_SCLL_SHIFT | 0x26 << OMAP4430_SCLH_SHIFT); |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 322 | voltdm->write(vc_val, OMAP4_PRM_VC_CFG_I2C_CLK_OFFSET); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 323 | |
| 324 | is_initialized = true; |
| 325 | } |
| 326 | |
Kevin Hilman | f539548 | 2011-03-30 16:36:30 -0700 | [diff] [blame] | 327 | /** |
| 328 | * omap_vc_i2c_init - initialize I2C interface to PMIC |
| 329 | * @voltdm: voltage domain containing VC data |
| 330 | * |
Russell King | 2d5b479 | 2012-02-07 10:13:02 +0000 | [diff] [blame] | 331 | * Use PMIC supplied settings for I2C high-speed mode and |
Kevin Hilman | f539548 | 2011-03-30 16:36:30 -0700 | [diff] [blame] | 332 | * master code (if set) and program the VC I2C configuration |
| 333 | * register. |
| 334 | * |
| 335 | * The VC I2C configuration is common to all VC channels, |
| 336 | * so this function only configures I2C for the first VC |
| 337 | * channel registers. All other VC channels will use the |
| 338 | * same configuration. |
| 339 | */ |
| 340 | static void __init omap_vc_i2c_init(struct voltagedomain *voltdm) |
| 341 | { |
| 342 | struct omap_vc_channel *vc = voltdm->vc; |
| 343 | static bool initialized; |
| 344 | static bool i2c_high_speed; |
| 345 | u8 mcode; |
| 346 | |
| 347 | if (initialized) { |
| 348 | if (voltdm->pmic->i2c_high_speed != i2c_high_speed) |
Russell King | 0bf68f5 | 2012-02-07 10:23:43 +0000 | [diff] [blame] | 349 | pr_warn("%s: I2C config for vdd_%s does not match other channels (%u).", |
| 350 | __func__, voltdm->name, i2c_high_speed); |
Kevin Hilman | f539548 | 2011-03-30 16:36:30 -0700 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | |
| 354 | i2c_high_speed = voltdm->pmic->i2c_high_speed; |
| 355 | if (i2c_high_speed) |
| 356 | voltdm->rmw(vc->common->i2c_cfg_hsen_mask, |
| 357 | vc->common->i2c_cfg_hsen_mask, |
| 358 | vc->common->i2c_cfg_reg); |
| 359 | |
| 360 | mcode = voltdm->pmic->i2c_mcode; |
| 361 | if (mcode) |
| 362 | voltdm->rmw(vc->common->i2c_mcode_mask, |
| 363 | mcode << __ffs(vc->common->i2c_mcode_mask), |
| 364 | vc->common->i2c_cfg_reg); |
| 365 | |
| 366 | initialized = true; |
| 367 | } |
| 368 | |
Tero Kristo | 8b5d8c0 | 2012-09-25 19:33:35 +0300 | [diff] [blame] | 369 | /** |
| 370 | * omap_vc_calc_vsel - calculate vsel value for a channel |
| 371 | * @voltdm: channel to calculate value for |
| 372 | * @uvolt: microvolt value to convert to vsel |
| 373 | * |
| 374 | * Converts a microvolt value to vsel value for the used PMIC. |
| 375 | * This checks whether the microvolt value is out of bounds, and |
| 376 | * adjusts the value accordingly. If unsupported value detected, |
| 377 | * warning is thrown. |
| 378 | */ |
| 379 | static u8 omap_vc_calc_vsel(struct voltagedomain *voltdm, u32 uvolt) |
| 380 | { |
| 381 | if (voltdm->pmic->vddmin > uvolt) |
| 382 | uvolt = voltdm->pmic->vddmin; |
| 383 | if (voltdm->pmic->vddmax < uvolt) { |
| 384 | WARN(1, "%s: voltage not supported by pmic: %u vs max %u\n", |
| 385 | __func__, uvolt, voltdm->pmic->vddmax); |
| 386 | /* Lets try maximum value anyway */ |
| 387 | uvolt = voltdm->pmic->vddmax; |
| 388 | } |
| 389 | |
| 390 | return voltdm->pmic->uv_to_vsel(uvolt); |
| 391 | } |
| 392 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 393 | void __init omap_vc_init_channel(struct voltagedomain *voltdm) |
| 394 | { |
Kevin Hilman | d84adcf | 2011-03-22 16:14:57 -0700 | [diff] [blame] | 395 | struct omap_vc_channel *vc = voltdm->vc; |
Kevin Hilman | 08d1c9a | 2011-03-29 15:14:38 -0700 | [diff] [blame] | 396 | u8 on_vsel, onlp_vsel, ret_vsel, off_vsel; |
| 397 | u32 val; |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 398 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 399 | if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) { |
Russell King | 2d5b479 | 2012-02-07 10:13:02 +0000 | [diff] [blame] | 400 | pr_err("%s: No PMIC info for vdd_%s\n", __func__, voltdm->name); |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 401 | return; |
| 402 | } |
| 403 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 404 | if (!voltdm->read || !voltdm->write) { |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 405 | pr_err("%s: No read/write API for accessing vdd_%s regs\n", |
| 406 | __func__, voltdm->name); |
| 407 | return; |
| 408 | } |
| 409 | |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 410 | vc->cfg_channel = 0; |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 411 | if (vc->flags & OMAP_VC_CHANNEL_CFG_MUTANT) |
| 412 | vc_cfg_bits = &vc_mutant_channel_cfg; |
| 413 | else |
| 414 | vc_cfg_bits = &vc_default_channel_cfg; |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 415 | |
Kevin Hilman | ba112a4 | 2011-03-29 14:02:36 -0700 | [diff] [blame] | 416 | /* get PMIC/board specific settings */ |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 417 | vc->i2c_slave_addr = voltdm->pmic->i2c_slave_addr; |
| 418 | vc->volt_reg_addr = voltdm->pmic->volt_reg_addr; |
| 419 | vc->cmd_reg_addr = voltdm->pmic->cmd_reg_addr; |
Kevin Hilman | ba112a4 | 2011-03-29 14:02:36 -0700 | [diff] [blame] | 420 | |
| 421 | /* Configure the i2c slave address for this VC */ |
| 422 | voltdm->rmw(vc->smps_sa_mask, |
| 423 | vc->i2c_slave_addr << __ffs(vc->smps_sa_mask), |
Kevin Hilman | 5876c94 | 2011-07-20 16:35:46 -0700 | [diff] [blame] | 424 | vc->smps_sa_reg); |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 425 | vc->cfg_channel |= vc_cfg_bits->sa; |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 426 | |
Kevin Hilman | e4e021c | 2011-06-09 11:01:55 -0700 | [diff] [blame] | 427 | /* |
| 428 | * Configure the PMIC register addresses. |
| 429 | */ |
| 430 | voltdm->rmw(vc->smps_volra_mask, |
| 431 | vc->volt_reg_addr << __ffs(vc->smps_volra_mask), |
Kevin Hilman | 5876c94 | 2011-07-20 16:35:46 -0700 | [diff] [blame] | 432 | vc->smps_volra_reg); |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 433 | vc->cfg_channel |= vc_cfg_bits->rav; |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 434 | |
| 435 | if (vc->cmd_reg_addr) { |
Kevin Hilman | e4e021c | 2011-06-09 11:01:55 -0700 | [diff] [blame] | 436 | voltdm->rmw(vc->smps_cmdra_mask, |
| 437 | vc->cmd_reg_addr << __ffs(vc->smps_cmdra_mask), |
Kevin Hilman | 5876c94 | 2011-07-20 16:35:46 -0700 | [diff] [blame] | 438 | vc->smps_cmdra_reg); |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 439 | vc->cfg_channel |= vc_cfg_bits->rac | vc_cfg_bits->racen; |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 440 | } |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 441 | |
Kevin Hilman | 08d1c9a | 2011-03-29 15:14:38 -0700 | [diff] [blame] | 442 | /* Set up the on, inactive, retention and off voltage */ |
Tero Kristo | 8b5d8c0 | 2012-09-25 19:33:35 +0300 | [diff] [blame] | 443 | on_vsel = omap_vc_calc_vsel(voltdm, voltdm->vc_param->on); |
| 444 | onlp_vsel = omap_vc_calc_vsel(voltdm, voltdm->vc_param->onlp); |
| 445 | ret_vsel = omap_vc_calc_vsel(voltdm, voltdm->vc_param->ret); |
| 446 | off_vsel = omap_vc_calc_vsel(voltdm, voltdm->vc_param->off); |
| 447 | |
Kevin Hilman | 08d1c9a | 2011-03-29 15:14:38 -0700 | [diff] [blame] | 448 | val = ((on_vsel << vc->common->cmd_on_shift) | |
| 449 | (onlp_vsel << vc->common->cmd_onlp_shift) | |
| 450 | (ret_vsel << vc->common->cmd_ret_shift) | |
| 451 | (off_vsel << vc->common->cmd_off_shift)); |
| 452 | voltdm->write(val, vc->cmdval_reg); |
Kevin Hilman | 8abc0b5 | 2011-06-02 17:28:13 -0700 | [diff] [blame] | 453 | vc->cfg_channel |= vc_cfg_bits->cmd; |
Kevin Hilman | 24d3194 | 2011-03-29 15:57:16 -0700 | [diff] [blame] | 454 | |
| 455 | /* Channel configuration */ |
| 456 | omap_vc_config_channel(voltdm); |
Kevin Hilman | 08d1c9a | 2011-03-29 15:14:38 -0700 | [diff] [blame] | 457 | |
Kevin Hilman | f539548 | 2011-03-30 16:36:30 -0700 | [diff] [blame] | 458 | omap_vc_i2c_init(voltdm); |
| 459 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame] | 460 | if (cpu_is_omap34xx()) |
| 461 | omap3_vc_init_channel(voltdm); |
| 462 | else if (cpu_is_omap44xx()) |
| 463 | omap4_vc_init_channel(voltdm); |
| 464 | } |
| 465 | |