Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 1 | /* |
| 2 | * OMAP3/OMAP4 Voltage Management Routines |
| 3 | * |
| 4 | * Author: Thara Gopinath <thara@ti.com> |
| 5 | * |
| 6 | * Copyright (C) 2007 Texas Instruments, Inc. |
| 7 | * Rajendra Nayak <rnayak@ti.com> |
| 8 | * Lesly A M <x0080970@ti.com> |
| 9 | * |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 10 | * Copyright (C) 2008, 2011 Nokia Corporation |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 11 | * Kalle Jokiniemi |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 12 | * Paul Walmsley |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 13 | * |
| 14 | * Copyright (C) 2010 Texas Instruments, Inc. |
| 15 | * Thara Gopinath <thara@ti.com> |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU General Public License version 2 as |
| 19 | * published by the Free Software Foundation. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/io.h> |
| 24 | #include <linux/clk.h> |
| 25 | #include <linux/err.h> |
| 26 | #include <linux/debugfs.h> |
| 27 | #include <linux/slab.h> |
| 28 | |
| 29 | #include <plat/common.h> |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 30 | |
| 31 | #include "prm-regbits-34xx.h" |
Thara Gopinath | bd38107 | 2010-12-10 23:15:23 +0530 | [diff] [blame] | 32 | #include "prm-regbits-44xx.h" |
| 33 | #include "prm44xx.h" |
| 34 | #include "prcm44xx.h" |
| 35 | #include "prminst44xx.h" |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 36 | #include "control.h" |
| 37 | |
Paul Walmsley | e1d6f47 | 2011-02-25 15:54:33 -0700 | [diff] [blame] | 38 | #include "voltage.h" |
Kevin Hilman | e69c22b | 2011-03-16 16:13:15 -0700 | [diff] [blame] | 39 | #include "powerdomain.h" |
Paul Walmsley | e1d6f47 | 2011-02-25 15:54:33 -0700 | [diff] [blame] | 40 | |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 41 | #include "vc.h" |
| 42 | #include "vp.h" |
| 43 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 44 | static LIST_HEAD(voltdm_list); |
| 45 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 46 | #define VOLTAGE_DIR_SIZE 16 |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 47 | static struct dentry *voltage_dir; |
| 48 | |
| 49 | /* Init function pointers */ |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 50 | static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 51 | unsigned long target_volt); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 52 | |
| 53 | static u32 omap3_voltage_read_reg(u16 mod, u8 offset) |
| 54 | { |
| 55 | return omap2_prm_read_mod_reg(mod, offset); |
| 56 | } |
| 57 | |
| 58 | static void omap3_voltage_write_reg(u32 val, u16 mod, u8 offset) |
| 59 | { |
| 60 | omap2_prm_write_mod_reg(val, mod, offset); |
| 61 | } |
| 62 | |
Thara Gopinath | bd38107 | 2010-12-10 23:15:23 +0530 | [diff] [blame] | 63 | static u32 omap4_voltage_read_reg(u16 mod, u8 offset) |
| 64 | { |
| 65 | return omap4_prminst_read_inst_reg(OMAP4430_PRM_PARTITION, |
| 66 | mod, offset); |
| 67 | } |
| 68 | |
| 69 | static void omap4_voltage_write_reg(u32 val, u16 mod, u8 offset) |
| 70 | { |
| 71 | omap4_prminst_write_inst_reg(val, OMAP4430_PRM_PARTITION, mod, offset); |
| 72 | } |
| 73 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 74 | static int __init _config_common_vdd_data(struct voltagedomain *voltdm) |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 75 | { |
| 76 | char *sys_ck_name; |
| 77 | struct clk *sys_ck; |
| 78 | u32 sys_clk_speed, timeout_val, waittime; |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 79 | struct omap_vdd_info *vdd = voltdm->vdd; |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 80 | |
| 81 | /* |
| 82 | * XXX Clockfw should handle this, or this should be in a |
| 83 | * struct record |
| 84 | */ |
| 85 | if (cpu_is_omap24xx() || cpu_is_omap34xx()) |
| 86 | sys_ck_name = "sys_ck"; |
| 87 | else if (cpu_is_omap44xx()) |
| 88 | sys_ck_name = "sys_clkin_ck"; |
| 89 | else |
| 90 | return -EINVAL; |
| 91 | |
| 92 | /* |
| 93 | * Sys clk rate is require to calculate vp timeout value and |
| 94 | * smpswaittimemin and smpswaittimemax. |
| 95 | */ |
| 96 | sys_ck = clk_get(NULL, sys_ck_name); |
| 97 | if (IS_ERR(sys_ck)) { |
| 98 | pr_warning("%s: Could not get the sys clk to calculate" |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 99 | "various vdd_%s params\n", __func__, voltdm->name); |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 100 | return -EINVAL; |
| 101 | } |
| 102 | sys_clk_speed = clk_get_rate(sys_ck); |
| 103 | clk_put(sys_ck); |
| 104 | /* Divide to avoid overflow */ |
| 105 | sys_clk_speed /= 1000; |
| 106 | |
| 107 | /* Generic voltage parameters */ |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 108 | vdd->volt_scale = vp_forceupdate_scale_voltage; |
| 109 | vdd->vp_enabled = false; |
| 110 | |
| 111 | vdd->vp_rt_data.vpconfig_erroroffset = |
| 112 | (vdd->pmic_info->vp_erroroffset << |
| 113 | vdd->vp_data->vp_common->vpconfig_erroroffset_shift); |
| 114 | |
| 115 | timeout_val = (sys_clk_speed * vdd->pmic_info->vp_timeout_us) / 1000; |
| 116 | vdd->vp_rt_data.vlimitto_timeout = timeout_val; |
| 117 | vdd->vp_rt_data.vlimitto_vddmin = vdd->pmic_info->vp_vddmin; |
| 118 | vdd->vp_rt_data.vlimitto_vddmax = vdd->pmic_info->vp_vddmax; |
| 119 | |
| 120 | waittime = ((vdd->pmic_info->step_size / vdd->pmic_info->slew_rate) * |
| 121 | sys_clk_speed) / 1000; |
| 122 | vdd->vp_rt_data.vstepmin_smpswaittimemin = waittime; |
| 123 | vdd->vp_rt_data.vstepmax_smpswaittimemax = waittime; |
| 124 | vdd->vp_rt_data.vstepmin_stepmin = vdd->pmic_info->vp_vstepmin; |
| 125 | vdd->vp_rt_data.vstepmax_stepmax = vdd->pmic_info->vp_vstepmax; |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 130 | /* Voltage debugfs support */ |
| 131 | static int vp_volt_debug_get(void *data, u64 *val) |
| 132 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 133 | struct voltagedomain *voltdm = (struct voltagedomain *)data; |
| 134 | struct omap_vdd_info *vdd = voltdm->vdd; |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 135 | u8 vsel; |
| 136 | |
| 137 | if (!vdd) { |
| 138 | pr_warning("Wrong paramater passed\n"); |
| 139 | return -EINVAL; |
| 140 | } |
| 141 | |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 142 | vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 143 | |
| 144 | if (!vdd->pmic_info->vsel_to_uv) { |
| 145 | pr_warning("PMIC function to convert vsel to voltage" |
| 146 | "in uV not registerd\n"); |
| 147 | return -EINVAL; |
| 148 | } |
| 149 | |
| 150 | *val = vdd->pmic_info->vsel_to_uv(vsel); |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | static int nom_volt_debug_get(void *data, u64 *val) |
| 155 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 156 | struct voltagedomain *voltdm = (struct voltagedomain *)data; |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 157 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 158 | if (!voltdm) { |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 159 | pr_warning("Wrong paramater passed\n"); |
| 160 | return -EINVAL; |
| 161 | } |
| 162 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 163 | *val = omap_voltage_get_nom_volt(voltdm); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | DEFINE_SIMPLE_ATTRIBUTE(vp_volt_debug_fops, vp_volt_debug_get, NULL, "%llu\n"); |
| 169 | DEFINE_SIMPLE_ATTRIBUTE(nom_volt_debug_fops, nom_volt_debug_get, NULL, |
| 170 | "%llu\n"); |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 171 | static void vp_latch_vsel(struct voltagedomain *voltdm) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 172 | { |
| 173 | u32 vpconfig; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 174 | unsigned long uvdc; |
| 175 | char vsel; |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 176 | struct omap_vdd_info *vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 177 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 178 | uvdc = omap_voltage_get_nom_volt(voltdm); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 179 | if (!uvdc) { |
| 180 | pr_warning("%s: unable to find current voltage for vdd_%s\n", |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 181 | __func__, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 182 | return; |
| 183 | } |
| 184 | |
| 185 | if (!vdd->pmic_info || !vdd->pmic_info->uv_to_vsel) { |
| 186 | pr_warning("%s: PMIC function to convert voltage in uV to" |
| 187 | " vsel not registered\n", __func__); |
| 188 | return; |
| 189 | } |
| 190 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 191 | vsel = vdd->pmic_info->uv_to_vsel(uvdc); |
| 192 | |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 193 | vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 194 | vpconfig &= ~(vdd->vp_data->vp_common->vpconfig_initvoltage_mask | |
| 195 | vdd->vp_data->vp_common->vpconfig_initvdd); |
| 196 | vpconfig |= vsel << vdd->vp_data->vp_common->vpconfig_initvoltage_shift; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 197 | |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 198 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 199 | |
| 200 | /* Trigger initVDD value copy to voltage processor */ |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 201 | vdd->write_reg((vpconfig | vdd->vp_data->vp_common->vpconfig_initvdd), |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 202 | vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 203 | |
| 204 | /* Clear initVDD copy trigger bit */ |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 205 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | /* Generic voltage init functions */ |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 209 | static void __init vp_init(struct voltagedomain *voltdm) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 210 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 211 | struct omap_vdd_info *vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 212 | u32 vp_val; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 213 | |
| 214 | if (!vdd->read_reg || !vdd->write_reg) { |
| 215 | pr_err("%s: No read/write API for accessing vdd_%s regs\n", |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 216 | __func__, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 217 | return; |
| 218 | } |
| 219 | |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 220 | vp_val = vdd->vp_rt_data.vpconfig_erroroffset | |
| 221 | (vdd->vp_rt_data.vpconfig_errorgain << |
| 222 | vdd->vp_data->vp_common->vpconfig_errorgain_shift) | |
| 223 | vdd->vp_data->vp_common->vpconfig_timeouten; |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 224 | vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 225 | |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 226 | vp_val = ((vdd->vp_rt_data.vstepmin_smpswaittimemin << |
| 227 | vdd->vp_data->vp_common->vstepmin_smpswaittimemin_shift) | |
| 228 | (vdd->vp_rt_data.vstepmin_stepmin << |
| 229 | vdd->vp_data->vp_common->vstepmin_stepmin_shift)); |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 230 | vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstepmin); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 231 | |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 232 | vp_val = ((vdd->vp_rt_data.vstepmax_smpswaittimemax << |
| 233 | vdd->vp_data->vp_common->vstepmax_smpswaittimemax_shift) | |
| 234 | (vdd->vp_rt_data.vstepmax_stepmax << |
| 235 | vdd->vp_data->vp_common->vstepmax_stepmax_shift)); |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 236 | vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstepmax); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 237 | |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 238 | vp_val = ((vdd->vp_rt_data.vlimitto_vddmax << |
| 239 | vdd->vp_data->vp_common->vlimitto_vddmax_shift) | |
| 240 | (vdd->vp_rt_data.vlimitto_vddmin << |
| 241 | vdd->vp_data->vp_common->vlimitto_vddmin_shift) | |
| 242 | (vdd->vp_rt_data.vlimitto_timeout << |
| 243 | vdd->vp_data->vp_common->vlimitto_timeout_shift)); |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 244 | vdd->write_reg(vp_val, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vlimitto); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 245 | } |
| 246 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 247 | static void __init vdd_debugfs_init(struct voltagedomain *voltdm) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 248 | { |
| 249 | char *name; |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 250 | struct omap_vdd_info *vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 251 | |
| 252 | name = kzalloc(VOLTAGE_DIR_SIZE, GFP_KERNEL); |
| 253 | if (!name) { |
| 254 | pr_warning("%s: Unable to allocate memory for debugfs" |
| 255 | " directory name for vdd_%s", |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 256 | __func__, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 257 | return; |
| 258 | } |
| 259 | strcpy(name, "vdd_"); |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 260 | strcat(name, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 261 | |
| 262 | vdd->debug_dir = debugfs_create_dir(name, voltage_dir); |
Aaro Koskinen | 6227011 | 2011-01-28 18:24:11 +0200 | [diff] [blame] | 263 | kfree(name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 264 | if (IS_ERR(vdd->debug_dir)) { |
| 265 | pr_warning("%s: Unable to create debugfs directory for" |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 266 | " vdd_%s\n", __func__, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 267 | vdd->debug_dir = NULL; |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 268 | return; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 269 | } |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 270 | |
| 271 | (void) debugfs_create_x16("vp_errorgain", S_IRUGO, vdd->debug_dir, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 272 | &(vdd->vp_rt_data.vpconfig_errorgain)); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 273 | (void) debugfs_create_x16("vp_smpswaittimemin", S_IRUGO, |
| 274 | vdd->debug_dir, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 275 | &(vdd->vp_rt_data.vstepmin_smpswaittimemin)); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 276 | (void) debugfs_create_x8("vp_stepmin", S_IRUGO, vdd->debug_dir, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 277 | &(vdd->vp_rt_data.vstepmin_stepmin)); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 278 | (void) debugfs_create_x16("vp_smpswaittimemax", S_IRUGO, |
| 279 | vdd->debug_dir, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 280 | &(vdd->vp_rt_data.vstepmax_smpswaittimemax)); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 281 | (void) debugfs_create_x8("vp_stepmax", S_IRUGO, vdd->debug_dir, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 282 | &(vdd->vp_rt_data.vstepmax_stepmax)); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 283 | (void) debugfs_create_x8("vp_vddmax", S_IRUGO, vdd->debug_dir, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 284 | &(vdd->vp_rt_data.vlimitto_vddmax)); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 285 | (void) debugfs_create_x8("vp_vddmin", S_IRUGO, vdd->debug_dir, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 286 | &(vdd->vp_rt_data.vlimitto_vddmin)); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 287 | (void) debugfs_create_x16("vp_timeout", S_IRUGO, vdd->debug_dir, |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 288 | &(vdd->vp_rt_data.vlimitto_timeout)); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 289 | (void) debugfs_create_file("curr_vp_volt", S_IRUGO, vdd->debug_dir, |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 290 | (void *) voltdm, &vp_volt_debug_fops); |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 291 | (void) debugfs_create_file("curr_nominal_volt", S_IRUGO, |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 292 | vdd->debug_dir, (void *) voltdm, |
Thara Gopinath | 077fcec | 2010-10-27 20:29:37 +0530 | [diff] [blame] | 293 | &nom_volt_debug_fops); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 294 | } |
| 295 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 296 | /* VP force update method of voltage scaling */ |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 297 | static int vp_forceupdate_scale_voltage(struct voltagedomain *voltdm, |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 298 | unsigned long target_volt) |
| 299 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 300 | struct omap_vdd_info *vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 301 | u32 vpconfig; |
Kevin Hilman | c39263c | 2011-03-16 17:20:35 -0700 | [diff] [blame] | 302 | u8 target_vsel, current_vsel; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 303 | int ret, timeout = 0; |
| 304 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame^] | 305 | ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, ¤t_vsel); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 306 | if (ret) |
| 307 | return ret; |
| 308 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 309 | /* |
| 310 | * Clear all pending TransactionDone interrupt/status. Typical latency |
| 311 | * is <3us |
| 312 | */ |
| 313 | while (timeout++ < VP_TRANXDONE_TIMEOUT) { |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 314 | vdd->write_reg(vdd->vp_data->prm_irqst_data->tranxdone_status, |
Kevin Hilman | c39263c | 2011-03-16 17:20:35 -0700 | [diff] [blame] | 315 | vdd->prm_irqst_mod, vdd->prm_irqst_reg); |
| 316 | if (!(vdd->read_reg(vdd->prm_irqst_mod, vdd->prm_irqst_reg) & |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 317 | vdd->vp_data->prm_irqst_data->tranxdone_status)) |
| 318 | break; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 319 | udelay(1); |
| 320 | } |
| 321 | if (timeout >= VP_TRANXDONE_TIMEOUT) { |
| 322 | pr_warning("%s: vdd_%s TRANXDONE timeout exceeded." |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 323 | "Voltage change aborted", __func__, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 324 | return -ETIMEDOUT; |
| 325 | } |
| 326 | |
| 327 | /* Configure for VP-Force Update */ |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 328 | vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 329 | vpconfig &= ~(vdd->vp_data->vp_common->vpconfig_initvdd | |
| 330 | vdd->vp_data->vp_common->vpconfig_forceupdate | |
| 331 | vdd->vp_data->vp_common->vpconfig_initvoltage_mask); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 332 | vpconfig |= ((target_vsel << |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 333 | vdd->vp_data->vp_common->vpconfig_initvoltage_shift)); |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 334 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 335 | |
| 336 | /* Trigger initVDD value copy to voltage processor */ |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 337 | vpconfig |= vdd->vp_data->vp_common->vpconfig_initvdd; |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 338 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 339 | |
| 340 | /* Force update of voltage */ |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 341 | vpconfig |= vdd->vp_data->vp_common->vpconfig_forceupdate; |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 342 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 343 | |
| 344 | /* |
| 345 | * Wait for TransactionDone. Typical latency is <200us. |
| 346 | * Depends on SMPSWAITTIMEMIN/MAX and voltage change |
| 347 | */ |
| 348 | timeout = 0; |
Kevin Hilman | c39263c | 2011-03-16 17:20:35 -0700 | [diff] [blame] | 349 | omap_test_timeout((vdd->read_reg(vdd->prm_irqst_mod, |
| 350 | vdd->prm_irqst_reg) & |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 351 | vdd->vp_data->prm_irqst_data->tranxdone_status), |
| 352 | VP_TRANXDONE_TIMEOUT, timeout); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 353 | if (timeout >= VP_TRANXDONE_TIMEOUT) |
| 354 | pr_err("%s: vdd_%s TRANXDONE timeout exceeded." |
| 355 | "TRANXDONE never got set after the voltage update\n", |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 356 | __func__, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 357 | |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame^] | 358 | omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 359 | |
| 360 | /* |
| 361 | * Disable TransactionDone interrupt , clear all status, clear |
| 362 | * control registers |
| 363 | */ |
| 364 | timeout = 0; |
| 365 | while (timeout++ < VP_TRANXDONE_TIMEOUT) { |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 366 | vdd->write_reg(vdd->vp_data->prm_irqst_data->tranxdone_status, |
Kevin Hilman | c39263c | 2011-03-16 17:20:35 -0700 | [diff] [blame] | 367 | vdd->prm_irqst_mod, vdd->prm_irqst_reg); |
| 368 | if (!(vdd->read_reg(vdd->prm_irqst_mod, vdd->prm_irqst_reg) & |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 369 | vdd->vp_data->prm_irqst_data->tranxdone_status)) |
| 370 | break; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 371 | udelay(1); |
| 372 | } |
| 373 | |
| 374 | if (timeout >= VP_TRANXDONE_TIMEOUT) |
| 375 | pr_warning("%s: vdd_%s TRANXDONE timeout exceeded while trying" |
| 376 | "to clear the TRANXDONE status\n", |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 377 | __func__, voltdm->name); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 378 | |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 379 | vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 380 | /* Clear initVDD copy trigger bit */ |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 381 | vpconfig &= ~vdd->vp_data->vp_common->vpconfig_initvdd; |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 382 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 383 | /* Clear force bit */ |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 384 | vpconfig &= ~vdd->vp_data->vp_common->vpconfig_forceupdate; |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 385 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 386 | |
| 387 | return 0; |
| 388 | } |
| 389 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 390 | static int __init omap_vdd_data_configure(struct voltagedomain *voltdm) |
Thara Gopinath | bd38107 | 2010-12-10 23:15:23 +0530 | [diff] [blame] | 391 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 392 | struct omap_vdd_info *vdd = voltdm->vdd; |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 393 | int ret = -EINVAL; |
Thara Gopinath | bd38107 | 2010-12-10 23:15:23 +0530 | [diff] [blame] | 394 | |
| 395 | if (!vdd->pmic_info) { |
| 396 | pr_err("%s: PMIC info requried to configure vdd_%s not" |
| 397 | "populated.Hence cannot initialize vdd_%s\n", |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 398 | __func__, voltdm->name, voltdm->name); |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 399 | goto ovdc_out; |
Thara Gopinath | bd38107 | 2010-12-10 23:15:23 +0530 | [diff] [blame] | 400 | } |
| 401 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 402 | if (IS_ERR_VALUE(_config_common_vdd_data(voltdm))) |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 403 | goto ovdc_out; |
| 404 | |
| 405 | if (cpu_is_omap34xx()) { |
| 406 | vdd->read_reg = omap3_voltage_read_reg; |
| 407 | vdd->write_reg = omap3_voltage_write_reg; |
| 408 | ret = 0; |
| 409 | } else if (cpu_is_omap44xx()) { |
| 410 | vdd->read_reg = omap4_voltage_read_reg; |
| 411 | vdd->write_reg = omap4_voltage_write_reg; |
| 412 | ret = 0; |
Thara Gopinath | bd38107 | 2010-12-10 23:15:23 +0530 | [diff] [blame] | 413 | } |
| 414 | |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 415 | ovdc_out: |
| 416 | return ret; |
Thara Gopinath | bd38107 | 2010-12-10 23:15:23 +0530 | [diff] [blame] | 417 | } |
| 418 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 419 | /* Public functions */ |
| 420 | /** |
| 421 | * omap_voltage_get_nom_volt() - Gets the current non-auto-compensated voltage |
| 422 | * @voltdm: pointer to the VDD for which current voltage info is needed |
| 423 | * |
| 424 | * API to get the current non-auto-compensated voltage for a VDD. |
| 425 | * Returns 0 in case of error else returns the current voltage for the VDD. |
| 426 | */ |
| 427 | unsigned long omap_voltage_get_nom_volt(struct voltagedomain *voltdm) |
| 428 | { |
| 429 | struct omap_vdd_info *vdd; |
| 430 | |
| 431 | if (!voltdm || IS_ERR(voltdm)) { |
| 432 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 433 | return 0; |
| 434 | } |
| 435 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 436 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 437 | |
| 438 | return vdd->curr_volt; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * omap_vp_get_curr_volt() - API to get the current vp voltage. |
| 443 | * @voltdm: pointer to the VDD. |
| 444 | * |
| 445 | * This API returns the current voltage for the specified voltage processor |
| 446 | */ |
| 447 | unsigned long omap_vp_get_curr_volt(struct voltagedomain *voltdm) |
| 448 | { |
| 449 | struct omap_vdd_info *vdd; |
| 450 | u8 curr_vsel; |
| 451 | |
| 452 | if (!voltdm || IS_ERR(voltdm)) { |
| 453 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 454 | return 0; |
| 455 | } |
| 456 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 457 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 458 | if (!vdd->read_reg) { |
| 459 | pr_err("%s: No read API for reading vdd_%s regs\n", |
| 460 | __func__, voltdm->name); |
| 461 | return 0; |
| 462 | } |
| 463 | |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 464 | curr_vsel = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->voltage); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 465 | |
| 466 | if (!vdd->pmic_info || !vdd->pmic_info->vsel_to_uv) { |
| 467 | pr_warning("%s: PMIC function to convert vsel to voltage" |
| 468 | "in uV not registerd\n", __func__); |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | return vdd->pmic_info->vsel_to_uv(curr_vsel); |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * omap_vp_enable() - API to enable a particular VP |
| 477 | * @voltdm: pointer to the VDD whose VP is to be enabled. |
| 478 | * |
| 479 | * This API enables a particular voltage processor. Needed by the smartreflex |
| 480 | * class drivers. |
| 481 | */ |
| 482 | void omap_vp_enable(struct voltagedomain *voltdm) |
| 483 | { |
| 484 | struct omap_vdd_info *vdd; |
| 485 | u32 vpconfig; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 486 | |
| 487 | if (!voltdm || IS_ERR(voltdm)) { |
| 488 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 489 | return; |
| 490 | } |
| 491 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 492 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 493 | if (!vdd->read_reg || !vdd->write_reg) { |
| 494 | pr_err("%s: No read/write API for accessing vdd_%s regs\n", |
| 495 | __func__, voltdm->name); |
| 496 | return; |
| 497 | } |
| 498 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 499 | /* If VP is already enabled, do nothing. Return */ |
| 500 | if (vdd->vp_enabled) |
| 501 | return; |
| 502 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 503 | vp_latch_vsel(voltdm); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 504 | |
| 505 | /* Enable VP */ |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 506 | vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 507 | vpconfig |= vdd->vp_data->vp_common->vpconfig_vpenable; |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 508 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 509 | vdd->vp_enabled = true; |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * omap_vp_disable() - API to disable a particular VP |
| 514 | * @voltdm: pointer to the VDD whose VP is to be disabled. |
| 515 | * |
| 516 | * This API disables a particular voltage processor. Needed by the smartreflex |
| 517 | * class drivers. |
| 518 | */ |
| 519 | void omap_vp_disable(struct voltagedomain *voltdm) |
| 520 | { |
| 521 | struct omap_vdd_info *vdd; |
| 522 | u32 vpconfig; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 523 | int timeout; |
| 524 | |
| 525 | if (!voltdm || IS_ERR(voltdm)) { |
| 526 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 527 | return; |
| 528 | } |
| 529 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 530 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 531 | if (!vdd->read_reg || !vdd->write_reg) { |
| 532 | pr_err("%s: No read/write API for accessing vdd_%s regs\n", |
| 533 | __func__, voltdm->name); |
| 534 | return; |
| 535 | } |
| 536 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 537 | /* If VP is already disabled, do nothing. Return */ |
| 538 | if (!vdd->vp_enabled) { |
| 539 | pr_warning("%s: Trying to disable VP for vdd_%s when" |
| 540 | "it is already disabled\n", __func__, voltdm->name); |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | /* Disable VP */ |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 545 | vpconfig = vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Paul Walmsley | c0718df | 2011-03-10 22:17:45 -0700 | [diff] [blame] | 546 | vpconfig &= ~vdd->vp_data->vp_common->vpconfig_vpenable; |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 547 | vdd->write_reg(vpconfig, vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vpconfig); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 548 | |
| 549 | /* |
| 550 | * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us |
| 551 | */ |
Kevin Hilman | a7460daf | 2011-03-16 13:35:22 -0700 | [diff] [blame] | 552 | omap_test_timeout((vdd->read_reg(vdd->vp_data->vp_common->prm_mod, vdd->vp_data->vstatus)), |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 553 | VP_IDLE_TIMEOUT, timeout); |
| 554 | |
| 555 | if (timeout >= VP_IDLE_TIMEOUT) |
| 556 | pr_warning("%s: vdd_%s idle timedout\n", |
| 557 | __func__, voltdm->name); |
| 558 | |
| 559 | vdd->vp_enabled = false; |
| 560 | |
| 561 | return; |
| 562 | } |
| 563 | |
| 564 | /** |
| 565 | * omap_voltage_scale_vdd() - API to scale voltage of a particular |
| 566 | * voltage domain. |
| 567 | * @voltdm: pointer to the VDD which is to be scaled. |
| 568 | * @target_volt: The target voltage of the voltage domain |
| 569 | * |
| 570 | * This API should be called by the kernel to do the voltage scaling |
| 571 | * for a particular voltage domain during dvfs or any other situation. |
| 572 | */ |
| 573 | int omap_voltage_scale_vdd(struct voltagedomain *voltdm, |
| 574 | unsigned long target_volt) |
| 575 | { |
| 576 | struct omap_vdd_info *vdd; |
| 577 | |
| 578 | if (!voltdm || IS_ERR(voltdm)) { |
| 579 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 580 | return -EINVAL; |
| 581 | } |
| 582 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 583 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 584 | |
| 585 | if (!vdd->volt_scale) { |
| 586 | pr_err("%s: No voltage scale API registered for vdd_%s\n", |
| 587 | __func__, voltdm->name); |
| 588 | return -ENODATA; |
| 589 | } |
| 590 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 591 | return vdd->volt_scale(voltdm, target_volt); |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /** |
| 595 | * omap_voltage_reset() - Resets the voltage of a particular voltage domain |
| 596 | * to that of the current OPP. |
| 597 | * @voltdm: pointer to the VDD whose voltage is to be reset. |
| 598 | * |
| 599 | * This API finds out the correct voltage the voltage domain is supposed |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 600 | * to be at and resets the voltage to that level. Should be used especially |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 601 | * while disabling any voltage compensation modules. |
| 602 | */ |
| 603 | void omap_voltage_reset(struct voltagedomain *voltdm) |
| 604 | { |
| 605 | unsigned long target_uvdc; |
| 606 | |
| 607 | if (!voltdm || IS_ERR(voltdm)) { |
| 608 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 609 | return; |
| 610 | } |
| 611 | |
| 612 | target_uvdc = omap_voltage_get_nom_volt(voltdm); |
| 613 | if (!target_uvdc) { |
| 614 | pr_err("%s: unable to find current voltage for vdd_%s\n", |
| 615 | __func__, voltdm->name); |
| 616 | return; |
| 617 | } |
| 618 | |
| 619 | omap_voltage_scale_vdd(voltdm, target_uvdc); |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | * omap_voltage_get_volttable() - API to get the voltage table associated with a |
| 624 | * particular voltage domain. |
| 625 | * @voltdm: pointer to the VDD for which the voltage table is required |
| 626 | * @volt_data: the voltage table for the particular vdd which is to be |
| 627 | * populated by this API |
| 628 | * |
| 629 | * This API populates the voltage table associated with a VDD into the |
| 630 | * passed parameter pointer. Returns the count of distinct voltages |
| 631 | * supported by this vdd. |
| 632 | * |
| 633 | */ |
| 634 | void omap_voltage_get_volttable(struct voltagedomain *voltdm, |
| 635 | struct omap_volt_data **volt_data) |
| 636 | { |
| 637 | struct omap_vdd_info *vdd; |
| 638 | |
| 639 | if (!voltdm || IS_ERR(voltdm)) { |
| 640 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 641 | return; |
| 642 | } |
| 643 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 644 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 645 | |
| 646 | *volt_data = vdd->volt_data; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * omap_voltage_get_voltdata() - API to get the voltage table entry for a |
| 651 | * particular voltage |
| 652 | * @voltdm: pointer to the VDD whose voltage table has to be searched |
| 653 | * @volt: the voltage to be searched in the voltage table |
| 654 | * |
| 655 | * This API searches through the voltage table for the required voltage |
| 656 | * domain and tries to find a matching entry for the passed voltage volt. |
| 657 | * If a matching entry is found volt_data is populated with that entry. |
| 658 | * This API searches only through the non-compensated voltages int the |
| 659 | * voltage table. |
| 660 | * Returns pointer to the voltage table entry corresponding to volt on |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 661 | * success. Returns -ENODATA if no voltage table exisits for the passed voltage |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 662 | * domain or if there is no matching entry. |
| 663 | */ |
| 664 | struct omap_volt_data *omap_voltage_get_voltdata(struct voltagedomain *voltdm, |
| 665 | unsigned long volt) |
| 666 | { |
| 667 | struct omap_vdd_info *vdd; |
| 668 | int i; |
| 669 | |
| 670 | if (!voltdm || IS_ERR(voltdm)) { |
| 671 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 672 | return ERR_PTR(-EINVAL); |
| 673 | } |
| 674 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 675 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 676 | |
| 677 | if (!vdd->volt_data) { |
| 678 | pr_warning("%s: voltage table does not exist for vdd_%s\n", |
| 679 | __func__, voltdm->name); |
| 680 | return ERR_PTR(-ENODATA); |
| 681 | } |
| 682 | |
| 683 | for (i = 0; vdd->volt_data[i].volt_nominal != 0; i++) { |
| 684 | if (vdd->volt_data[i].volt_nominal == volt) |
| 685 | return &vdd->volt_data[i]; |
| 686 | } |
| 687 | |
| 688 | pr_notice("%s: Unable to match the current voltage with the voltage" |
| 689 | "table for vdd_%s\n", __func__, voltdm->name); |
| 690 | |
| 691 | return ERR_PTR(-ENODATA); |
| 692 | } |
| 693 | |
| 694 | /** |
| 695 | * omap_voltage_register_pmic() - API to register PMIC specific data |
| 696 | * @voltdm: pointer to the VDD for which the PMIC specific data is |
| 697 | * to be registered |
| 698 | * @pmic_info: the structure containing pmic info |
| 699 | * |
| 700 | * This API is to be called by the SOC/PMIC file to specify the |
| 701 | * pmic specific info as present in omap_volt_pmic_info structure. |
| 702 | */ |
| 703 | int omap_voltage_register_pmic(struct voltagedomain *voltdm, |
| 704 | struct omap_volt_pmic_info *pmic_info) |
| 705 | { |
| 706 | struct omap_vdd_info *vdd; |
| 707 | |
| 708 | if (!voltdm || IS_ERR(voltdm)) { |
| 709 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 710 | return -EINVAL; |
| 711 | } |
| 712 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 713 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 714 | |
| 715 | vdd->pmic_info = pmic_info; |
| 716 | |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | /** |
| 721 | * omap_voltage_get_dbgdir() - API to get pointer to the debugfs directory |
| 722 | * corresponding to a voltage domain. |
| 723 | * |
| 724 | * @voltdm: pointer to the VDD whose debug directory is required. |
| 725 | * |
| 726 | * This API returns pointer to the debugfs directory corresponding |
| 727 | * to the voltage domain. Should be used by drivers requiring to |
| 728 | * add any debug entry for a particular voltage domain. Returns NULL |
| 729 | * in case of error. |
| 730 | */ |
| 731 | struct dentry *omap_voltage_get_dbgdir(struct voltagedomain *voltdm) |
| 732 | { |
| 733 | struct omap_vdd_info *vdd; |
| 734 | |
| 735 | if (!voltdm || IS_ERR(voltdm)) { |
| 736 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 737 | return NULL; |
| 738 | } |
| 739 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 740 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 741 | |
| 742 | return vdd->debug_dir; |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * omap_change_voltscale_method() - API to change the voltage scaling method. |
| 747 | * @voltdm: pointer to the VDD whose voltage scaling method |
| 748 | * has to be changed. |
| 749 | * @voltscale_method: the method to be used for voltage scaling. |
| 750 | * |
| 751 | * This API can be used by the board files to change the method of voltage |
| 752 | * scaling between vpforceupdate and vcbypass. The parameter values are |
| 753 | * defined in voltage.h |
| 754 | */ |
| 755 | void omap_change_voltscale_method(struct voltagedomain *voltdm, |
| 756 | int voltscale_method) |
| 757 | { |
| 758 | struct omap_vdd_info *vdd; |
| 759 | |
| 760 | if (!voltdm || IS_ERR(voltdm)) { |
| 761 | pr_warning("%s: VDD specified does not exist!\n", __func__); |
| 762 | return; |
| 763 | } |
| 764 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 765 | vdd = voltdm->vdd; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 766 | |
| 767 | switch (voltscale_method) { |
| 768 | case VOLTSCALE_VPFORCEUPDATE: |
| 769 | vdd->volt_scale = vp_forceupdate_scale_voltage; |
| 770 | return; |
| 771 | case VOLTSCALE_VCBYPASS: |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame^] | 772 | vdd->volt_scale = omap_vc_bypass_scale_voltage; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 773 | return; |
| 774 | default: |
| 775 | pr_warning("%s: Trying to change the method of voltage scaling" |
| 776 | "to an unsupported one!\n", __func__); |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | /** |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 781 | * omap_voltage_late_init() - Init the various voltage parameters |
| 782 | * |
| 783 | * This API is to be called in the later stages of the |
| 784 | * system boot to init the voltage controller and |
| 785 | * voltage processors. |
| 786 | */ |
| 787 | int __init omap_voltage_late_init(void) |
| 788 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 789 | struct voltagedomain *voltdm; |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 790 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 791 | if (list_empty(&voltdm_list)) { |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 792 | pr_err("%s: Voltage driver support not added\n", |
| 793 | __func__); |
| 794 | return -EINVAL; |
| 795 | } |
| 796 | |
| 797 | voltage_dir = debugfs_create_dir("voltage", NULL); |
| 798 | if (IS_ERR(voltage_dir)) |
| 799 | pr_err("%s: Unable to create voltage debugfs main dir\n", |
| 800 | __func__); |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 801 | list_for_each_entry(voltdm, &voltdm_list, node) { |
Kevin Hilman | 37efca7 | 2011-03-23 17:00:21 -0700 | [diff] [blame] | 802 | if (!voltdm->scalable) |
| 803 | continue; |
| 804 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 805 | if (voltdm->vdd) { |
| 806 | if (omap_vdd_data_configure(voltdm)) |
| 807 | continue; |
Kevin Hilman | ccd5ca7 | 2011-03-21 14:08:55 -0700 | [diff] [blame^] | 808 | omap_vc_init_channel(voltdm); |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 809 | vp_init(voltdm); |
| 810 | vdd_debugfs_init(voltdm); |
| 811 | } |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 817 | static struct voltagedomain *_voltdm_lookup(const char *name) |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 818 | { |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 819 | struct voltagedomain *voltdm, *temp_voltdm; |
| 820 | |
| 821 | voltdm = NULL; |
| 822 | |
| 823 | list_for_each_entry(temp_voltdm, &voltdm_list, node) { |
| 824 | if (!strcmp(name, temp_voltdm->name)) { |
| 825 | voltdm = temp_voltdm; |
| 826 | break; |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | return voltdm; |
| 831 | } |
| 832 | |
Kevin Hilman | e69c22b | 2011-03-16 16:13:15 -0700 | [diff] [blame] | 833 | /** |
| 834 | * voltdm_add_pwrdm - add a powerdomain to a voltagedomain |
| 835 | * @voltdm: struct voltagedomain * to add the powerdomain to |
| 836 | * @pwrdm: struct powerdomain * to associate with a voltagedomain |
| 837 | * |
| 838 | * Associate the powerdomain @pwrdm with a voltagedomain @voltdm. This |
| 839 | * enables the use of voltdm_for_each_pwrdm(). Returns -EINVAL if |
| 840 | * presented with invalid pointers; -ENOMEM if memory could not be allocated; |
| 841 | * or 0 upon success. |
| 842 | */ |
| 843 | int voltdm_add_pwrdm(struct voltagedomain *voltdm, struct powerdomain *pwrdm) |
| 844 | { |
| 845 | if (!voltdm || !pwrdm) |
| 846 | return -EINVAL; |
| 847 | |
| 848 | pr_debug("voltagedomain: associating powerdomain %s with voltagedomain " |
| 849 | "%s\n", pwrdm->name, voltdm->name); |
| 850 | |
| 851 | list_add(&pwrdm->voltdm_node, &voltdm->pwrdm_list); |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | /** |
| 857 | * voltdm_for_each_pwrdm - call function for each pwrdm in a voltdm |
| 858 | * @voltdm: struct voltagedomain * to iterate over |
| 859 | * @fn: callback function * |
| 860 | * |
| 861 | * Call the supplied function @fn for each powerdomain in the |
| 862 | * voltagedomain @voltdm. Returns -EINVAL if presented with invalid |
| 863 | * pointers; or passes along the last return value of the callback |
| 864 | * function, which should be 0 for success or anything else to |
| 865 | * indicate failure. |
| 866 | */ |
| 867 | int voltdm_for_each_pwrdm(struct voltagedomain *voltdm, |
| 868 | int (*fn)(struct voltagedomain *voltdm, |
| 869 | struct powerdomain *pwrdm)) |
| 870 | { |
| 871 | struct powerdomain *pwrdm; |
| 872 | int ret = 0; |
| 873 | |
| 874 | if (!fn) |
| 875 | return -EINVAL; |
| 876 | |
| 877 | list_for_each_entry(pwrdm, &voltdm->pwrdm_list, voltdm_node) |
| 878 | ret = (*fn)(voltdm, pwrdm); |
| 879 | |
| 880 | return ret; |
| 881 | } |
| 882 | |
| 883 | /** |
| 884 | * voltdm_for_each - call function on each registered voltagedomain |
| 885 | * @fn: callback function * |
| 886 | * |
| 887 | * Call the supplied function @fn for each registered voltagedomain. |
| 888 | * The callback function @fn can return anything but 0 to bail out |
| 889 | * early from the iterator. Returns the last return value of the |
| 890 | * callback function, which should be 0 for success or anything else |
| 891 | * to indicate failure; or -EINVAL if the function pointer is null. |
| 892 | */ |
| 893 | int voltdm_for_each(int (*fn)(struct voltagedomain *voltdm, void *user), |
| 894 | void *user) |
| 895 | { |
| 896 | struct voltagedomain *temp_voltdm; |
| 897 | int ret = 0; |
| 898 | |
| 899 | if (!fn) |
| 900 | return -EINVAL; |
| 901 | |
| 902 | list_for_each_entry(temp_voltdm, &voltdm_list, node) { |
| 903 | ret = (*fn)(temp_voltdm, user); |
| 904 | if (ret) |
| 905 | break; |
| 906 | } |
| 907 | |
| 908 | return ret; |
| 909 | } |
| 910 | |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 911 | static int _voltdm_register(struct voltagedomain *voltdm) |
| 912 | { |
| 913 | if (!voltdm || !voltdm->name) |
| 914 | return -EINVAL; |
| 915 | |
Kevin Hilman | e69c22b | 2011-03-16 16:13:15 -0700 | [diff] [blame] | 916 | INIT_LIST_HEAD(&voltdm->pwrdm_list); |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 917 | list_add(&voltdm->node, &voltdm_list); |
| 918 | |
| 919 | pr_debug("voltagedomain: registered %s\n", voltdm->name); |
| 920 | |
Thara Gopinath | 2f34ce8 | 2010-05-29 22:02:21 +0530 | [diff] [blame] | 921 | return 0; |
| 922 | } |
Kevin Hilman | 81a6048 | 2011-03-16 14:25:45 -0700 | [diff] [blame] | 923 | |
| 924 | /** |
| 925 | * voltdm_lookup - look up a voltagedomain by name, return a pointer |
| 926 | * @name: name of voltagedomain |
| 927 | * |
| 928 | * Find a registered voltagedomain by its name @name. Returns a pointer |
| 929 | * to the struct voltagedomain if found, or NULL otherwise. |
| 930 | */ |
| 931 | struct voltagedomain *voltdm_lookup(const char *name) |
| 932 | { |
| 933 | struct voltagedomain *voltdm ; |
| 934 | |
| 935 | if (!name) |
| 936 | return NULL; |
| 937 | |
| 938 | voltdm = _voltdm_lookup(name); |
| 939 | |
| 940 | return voltdm; |
| 941 | } |
| 942 | |
| 943 | /** |
| 944 | * voltdm_init - set up the voltagedomain layer |
| 945 | * @voltdm_list: array of struct voltagedomain pointers to register |
| 946 | * |
| 947 | * Loop through the array of voltagedomains @voltdm_list, registering all |
| 948 | * that are available on the current CPU. If voltdm_list is supplied |
| 949 | * and not null, all of the referenced voltagedomains will be |
| 950 | * registered. No return value. |
| 951 | */ |
| 952 | void voltdm_init(struct voltagedomain **voltdms) |
| 953 | { |
| 954 | struct voltagedomain **v; |
| 955 | |
| 956 | if (voltdms) { |
| 957 | for (v = voltdms; *v; v++) |
| 958 | _voltdm_register(*v); |
| 959 | } |
| 960 | } |