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