Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/init.h> |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 3 | |
| 4 | #include <plat/common.h> |
| 5 | |
| 6 | #include "voltage.h" |
| 7 | #include "vp.h" |
| 8 | #include "prm-regbits-34xx.h" |
| 9 | #include "prm-regbits-44xx.h" |
| 10 | #include "prm44xx.h" |
| 11 | |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 12 | static void vp_latch_vsel(struct voltagedomain *voltdm) |
| 13 | { |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 14 | struct omap_vp_instance *vp = voltdm->vp; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 15 | u32 vpconfig; |
| 16 | unsigned long uvdc; |
| 17 | char vsel; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 18 | |
| 19 | uvdc = omap_voltage_get_nom_volt(voltdm); |
| 20 | if (!uvdc) { |
| 21 | pr_warning("%s: unable to find current voltage for vdd_%s\n", |
| 22 | __func__, voltdm->name); |
| 23 | return; |
| 24 | } |
| 25 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 26 | if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) { |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 27 | pr_warning("%s: PMIC function to convert voltage in uV to" |
| 28 | " vsel not registered\n", __func__); |
| 29 | return; |
| 30 | } |
| 31 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 32 | vsel = voltdm->pmic->uv_to_vsel(uvdc); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 33 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 34 | vpconfig = voltdm->read(vp->vpconfig); |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 35 | vpconfig &= ~(vp->common->vpconfig_initvoltage_mask | |
| 36 | vp->common->vpconfig_initvdd); |
Kevin Hilman | 0ec3041 | 2011-04-04 16:02:28 -0700 | [diff] [blame] | 37 | vpconfig |= vsel << __ffs(vp->common->vpconfig_initvoltage_mask); |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 38 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 39 | |
| 40 | /* Trigger initVDD value copy to voltage processor */ |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 41 | voltdm->write((vpconfig | vp->common->vpconfig_initvdd), |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 42 | vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 43 | |
| 44 | /* Clear initVDD copy trigger bit */ |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 45 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /* Generic voltage init functions */ |
| 49 | void __init omap_vp_init(struct voltagedomain *voltdm) |
| 50 | { |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 51 | struct omap_vp_instance *vp = voltdm->vp; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 52 | struct omap_vdd_info *vdd = voltdm->vdd; |
Kevin Hilman | 6f56727 | 2011-07-14 11:10:27 -0700 | [diff] [blame] | 53 | u32 vp_val, sys_clk_rate, timeout_val, waittime; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 54 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 55 | if (!voltdm->read || !voltdm->write) { |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 56 | pr_err("%s: No read/write API for accessing vdd_%s regs\n", |
| 57 | __func__, voltdm->name); |
| 58 | return; |
| 59 | } |
| 60 | |
Kevin Hilman | 6f56727 | 2011-07-14 11:10:27 -0700 | [diff] [blame] | 61 | vp->enabled = false; |
| 62 | |
| 63 | /* Divide to avoid overflow */ |
| 64 | sys_clk_rate = voltdm->sys_clk.rate / 1000; |
| 65 | |
| 66 | vdd->vp_rt_data.vpconfig_erroroffset = |
| 67 | (voltdm->pmic->vp_erroroffset << |
| 68 | __ffs(voltdm->vp->common->vpconfig_erroroffset_mask)); |
| 69 | |
| 70 | timeout_val = (sys_clk_rate * voltdm->pmic->vp_timeout_us) / 1000; |
| 71 | vdd->vp_rt_data.vlimitto_timeout = timeout_val; |
| 72 | vdd->vp_rt_data.vlimitto_vddmin = voltdm->pmic->vp_vddmin; |
| 73 | vdd->vp_rt_data.vlimitto_vddmax = voltdm->pmic->vp_vddmax; |
| 74 | |
| 75 | waittime = ((voltdm->pmic->step_size / voltdm->pmic->slew_rate) * |
| 76 | sys_clk_rate) / 1000; |
| 77 | vdd->vp_rt_data.vstepmin_smpswaittimemin = waittime; |
| 78 | vdd->vp_rt_data.vstepmax_smpswaittimemax = waittime; |
| 79 | vdd->vp_rt_data.vstepmin_stepmin = voltdm->pmic->vp_vstepmin; |
| 80 | vdd->vp_rt_data.vstepmax_stepmax = voltdm->pmic->vp_vstepmax; |
| 81 | |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 82 | vp_val = vdd->vp_rt_data.vpconfig_erroroffset | |
| 83 | (vdd->vp_rt_data.vpconfig_errorgain << |
Kevin Hilman | 0ec3041 | 2011-04-04 16:02:28 -0700 | [diff] [blame] | 84 | __ffs(vp->common->vpconfig_errorgain_mask)) | |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 85 | vp->common->vpconfig_timeouten; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 86 | voltdm->write(vp_val, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 87 | |
| 88 | vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin << |
Kevin Hilman | 0ec3041 | 2011-04-04 16:02:28 -0700 | [diff] [blame] | 89 | vp->common->vstepmin_smpswaittimemin_shift) | |
| 90 | (vdd->vp_rt_data.vstepmin_stepmin << |
| 91 | vp->common->vstepmin_stepmin_shift)); |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 92 | voltdm->write(vp_val, vp->vstepmin); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 93 | |
| 94 | vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax << |
Kevin Hilman | 0ec3041 | 2011-04-04 16:02:28 -0700 | [diff] [blame] | 95 | vp->common->vstepmax_smpswaittimemax_shift) | |
| 96 | (vdd->vp_rt_data.vstepmax_stepmax << |
| 97 | vp->common->vstepmax_stepmax_shift)); |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 98 | voltdm->write(vp_val, vp->vstepmax); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 99 | |
| 100 | vp_val = ((vdd->vp_rt_data.vlimitto_vddmax << |
Kevin Hilman | 0ec3041 | 2011-04-04 16:02:28 -0700 | [diff] [blame] | 101 | vp->common->vlimitto_vddmax_shift) | |
| 102 | (vdd->vp_rt_data.vlimitto_vddmin << |
| 103 | vp->common->vlimitto_vddmin_shift) | |
| 104 | (vdd->vp_rt_data.vlimitto_timeout << |
| 105 | vp->common->vlimitto_timeout_shift)); |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 106 | voltdm->write(vp_val, vp->vlimitto); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Kevin Hilman | 76ea742 | 2011-04-05 15:15:31 -0700 | [diff] [blame^] | 109 | int omap_vp_update_errorgain(struct voltagedomain *voltdm, |
| 110 | unsigned long target_volt) |
| 111 | { |
| 112 | struct omap_volt_data *volt_data; |
| 113 | |
| 114 | /* Get volt_data corresponding to target_volt */ |
| 115 | volt_data = omap_voltage_get_voltdata(voltdm, target_volt); |
| 116 | if (IS_ERR(volt_data)) |
| 117 | return -EINVAL; |
| 118 | |
| 119 | /* Setting vp errorgain based on the voltage */ |
| 120 | voltdm->rmw(voltdm->vp->common->vpconfig_errorgain_mask, |
| 121 | volt_data->vp_errgain << |
| 122 | __ffs(voltdm->vp->common->vpconfig_errorgain_mask), |
| 123 | voltdm->vp->vpconfig); |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 128 | /* VP force update method of voltage scaling */ |
| 129 | int omap_vp_forceupdate_scale(struct voltagedomain *voltdm, |
| 130 | unsigned long target_volt) |
| 131 | { |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 132 | struct omap_vp_instance *vp = voltdm->vp; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 133 | u32 vpconfig; |
| 134 | u8 target_vsel, current_vsel; |
| 135 | int ret, timeout = 0; |
| 136 | |
| 137 | ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, ¤t_vsel); |
| 138 | if (ret) |
| 139 | return ret; |
| 140 | |
| 141 | /* |
| 142 | * Clear all pending TransactionDone interrupt/status. Typical latency |
| 143 | * is <3us |
| 144 | */ |
| 145 | while (timeout++ < VP_TRANXDONE_TIMEOUT) { |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 146 | vp->common->ops->clear_txdone(vp->id); |
| 147 | if (!vp->common->ops->check_txdone(vp->id)) |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 148 | break; |
| 149 | udelay(1); |
| 150 | } |
| 151 | if (timeout >= VP_TRANXDONE_TIMEOUT) { |
| 152 | pr_warning("%s: vdd_%s TRANXDONE timeout exceeded." |
| 153 | "Voltage change aborted", __func__, voltdm->name); |
| 154 | return -ETIMEDOUT; |
| 155 | } |
| 156 | |
| 157 | /* Configure for VP-Force Update */ |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 158 | vpconfig = voltdm->read(vp->vpconfig); |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 159 | vpconfig &= ~(vp->common->vpconfig_initvdd | |
| 160 | vp->common->vpconfig_forceupdate | |
| 161 | vp->common->vpconfig_initvoltage_mask); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 162 | vpconfig |= ((target_vsel << |
Kevin Hilman | 0ec3041 | 2011-04-04 16:02:28 -0700 | [diff] [blame] | 163 | __ffs(vp->common->vpconfig_initvoltage_mask))); |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 164 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 165 | |
| 166 | /* Trigger initVDD value copy to voltage processor */ |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 167 | vpconfig |= vp->common->vpconfig_initvdd; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 168 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 169 | |
| 170 | /* Force update of voltage */ |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 171 | vpconfig |= vp->common->vpconfig_forceupdate; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 172 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Wait for TransactionDone. Typical latency is <200us. |
| 176 | * Depends on SMPSWAITTIMEMIN/MAX and voltage change |
| 177 | */ |
| 178 | timeout = 0; |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 179 | omap_test_timeout(vp->common->ops->check_txdone(vp->id), |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 180 | VP_TRANXDONE_TIMEOUT, timeout); |
| 181 | if (timeout >= VP_TRANXDONE_TIMEOUT) |
| 182 | pr_err("%s: vdd_%s TRANXDONE timeout exceeded." |
| 183 | "TRANXDONE never got set after the voltage update\n", |
| 184 | __func__, voltdm->name); |
| 185 | |
| 186 | omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel); |
| 187 | |
| 188 | /* |
| 189 | * Disable TransactionDone interrupt , clear all status, clear |
| 190 | * control registers |
| 191 | */ |
| 192 | timeout = 0; |
| 193 | while (timeout++ < VP_TRANXDONE_TIMEOUT) { |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 194 | vp->common->ops->clear_txdone(vp->id); |
| 195 | if (!vp->common->ops->check_txdone(vp->id)) |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 196 | break; |
| 197 | udelay(1); |
| 198 | } |
| 199 | |
| 200 | if (timeout >= VP_TRANXDONE_TIMEOUT) |
| 201 | pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying" |
| 202 | "to clear the TRANXDONE status\n", |
| 203 | __func__, voltdm->name); |
| 204 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 205 | vpconfig = voltdm->read(vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 206 | /* Clear initVDD copy trigger bit */ |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 207 | vpconfig &= ~vp->common->vpconfig_initvdd; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 208 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 209 | /* Clear force bit */ |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 210 | vpconfig &= ~vp->common->vpconfig_forceupdate; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 211 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * omap_vp_get_curr_volt() - API to get the current vp voltage. |
| 218 | * @voltdm: pointer to the VDD. |
| 219 | * |
| 220 | * This API returns the current voltage for the specified voltage processor |
| 221 | */ |
| 222 | unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) |
| 223 | { |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 224 | struct omap_vp_instance *vp = voltdm->vp; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 225 | u8 curr_vsel; |
| 226 | |
| 227 | if (!voltdm || IS_ERR(voltdm)) { |
| 228 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 229 | return 0; |
| 230 | } |
| 231 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 232 | if (!voltdm->read) { |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 233 | pr_err("%s: No read API for reading vdd_%s regs\n", |
| 234 | __func__, voltdm->name); |
| 235 | return 0; |
| 236 | } |
| 237 | |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 238 | curr_vsel = voltdm->read(vp->voltage); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 239 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 240 | if (!voltdm->pmic || !voltdm->pmic->vsel_to_uv) { |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 241 | pr_warning("%s: PMIC function to convert vsel to voltage" |
| 242 | "in uV not registerd\n", __func__); |
| 243 | return 0; |
| 244 | } |
| 245 | |
Kevin Hilman | ce8ebe0 | 2011-03-30 11:01:10 -0700 | [diff] [blame] | 246 | return voltdm->pmic->vsel_to_uv(curr_vsel); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /** |
| 250 | * omap_vp_enable() - API to enable a particular VP |
| 251 | * @voltdm: pointer to the VDD whose VP is to be enabled. |
| 252 | * |
| 253 | * This API enables a particular voltage processor. Needed by the smartreflex |
| 254 | * class drivers. |
| 255 | */ |
| 256 | void omap_vp_enable(struct voltagedomain *voltdm) |
| 257 | { |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 258 | struct omap_vp_instance *vp; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 259 | u32 vpconfig; |
| 260 | |
| 261 | if (!voltdm || IS_ERR(voltdm)) { |
| 262 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 263 | return; |
| 264 | } |
| 265 | |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 266 | vp = voltdm->vp; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 267 | if (!voltdm->read || !voltdm->write) { |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 268 | pr_err("%s: No read/write API for accessing vdd_%s regs\n", |
| 269 | __func__, voltdm->name); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | /* If VP is already enabled, do nothing. Return */ |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 274 | if (vp->enabled) |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 275 | return; |
| 276 | |
| 277 | vp_latch_vsel(voltdm); |
| 278 | |
| 279 | /* Enable VP */ |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 280 | vpconfig = voltdm->read(vp->vpconfig); |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 281 | vpconfig |= vp->common->vpconfig_vpenable; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 282 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 283 | vp->enabled = true; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | /** |
| 287 | * omap_vp_disable() - API to disable a particular VP |
| 288 | * @voltdm: pointer to the VDD whose VP is to be disabled. |
| 289 | * |
| 290 | * This API disables a particular voltage processor. Needed by the smartreflex |
| 291 | * class drivers. |
| 292 | */ |
| 293 | void omap_vp_disable(struct voltagedomain *voltdm) |
| 294 | { |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 295 | struct omap_vp_instance *vp; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 296 | u32 vpconfig; |
| 297 | int timeout; |
| 298 | |
| 299 | if (!voltdm || IS_ERR(voltdm)) { |
| 300 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 301 | return; |
| 302 | } |
| 303 | |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 304 | vp = voltdm->vp; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 305 | if (!voltdm->read || !voltdm->write) { |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 306 | pr_err("%s: No read/write API for accessing vdd_%s regs\n", |
| 307 | __func__, voltdm->name); |
| 308 | return; |
| 309 | } |
| 310 | |
| 311 | /* If VP is already disabled, do nothing. Return */ |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 312 | if (!vp->enabled) { |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 313 | pr_warning("%s: Trying to disable VP for vdd_%s when" |
| 314 | "it is already disabled\n", __func__, voltdm->name); |
| 315 | return; |
| 316 | } |
| 317 | |
| 318 | /* Disable VP */ |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 319 | vpconfig = voltdm->read(vp->vpconfig); |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 320 | vpconfig &= ~vp->common->vpconfig_vpenable; |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 321 | voltdm->write(vpconfig, vp->vpconfig); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 322 | |
| 323 | /* |
| 324 | * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us |
| 325 | */ |
Kevin Hilman | 4bcc475 | 2011-03-28 10:40:15 -0700 | [diff] [blame] | 326 | omap_test_timeout((voltdm->read(vp->vstatus)), |
| 327 | VP_IDLE_TIMEOUT, timeout); |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 328 | |
| 329 | if (timeout >= VP_IDLE_TIMEOUT) |
| 330 | pr_warning("%s: vdd_%s idle timedout\n", |
| 331 | __func__, voltdm->name); |
| 332 | |
Kevin Hilman | b7ea803 | 2011-04-04 15:25:07 -0700 | [diff] [blame] | 333 | vp->enabled = false; |
Kevin Hilman | 01f48d3 | 2011-03-21 14:29:13 -0700 | [diff] [blame] | 334 | |
| 335 | return; |
| 336 | } |