Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2010 |
| 3 | * |
| 4 | * License Terms: GNU General Public License v2 |
| 5 | * |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 6 | * Authors: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson |
| 7 | * Bengt Jonsson <bengt.g.jonsson@stericsson.com> for ST-Ericsson |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 8 | * |
| 9 | * AB8500 peripheral regulators |
| 10 | * |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 11 | * AB8500 supports the following regulators: |
Bengt Jonsson | ea05ef3 | 2011-03-10 14:43:31 +0100 | [diff] [blame] | 12 | * VAUX1/2/3, VINTCORE, VTVOUT, VUSB, VAUDIO, VAMIC1/2, VDMIC, VANA |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 13 | */ |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/kernel.h> |
Paul Gortmaker | 65602c3 | 2011-07-17 16:28:23 -0400 | [diff] [blame] | 16 | #include <linux/module.h> |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 17 | #include <linux/err.h> |
| 18 | #include <linux/platform_device.h> |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 19 | #include <linux/mfd/abx500.h> |
Linus Walleij | ee66e65 | 2011-12-02 14:16:33 +0100 | [diff] [blame] | 20 | #include <linux/mfd/abx500/ab8500.h> |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 21 | #include <linux/regulator/driver.h> |
| 22 | #include <linux/regulator/machine.h> |
| 23 | #include <linux/regulator/ab8500.h> |
| 24 | |
| 25 | /** |
| 26 | * struct ab8500_regulator_info - ab8500 regulator information |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 27 | * @dev: device pointer |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 28 | * @desc: regulator description |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 29 | * @regulator_dev: regulator device |
| 30 | * @max_uV: maximum voltage (for variable voltage supplies) |
| 31 | * @min_uV: minimum voltage (for variable voltage supplies) |
| 32 | * @fixed_uV: typical voltage (for fixed voltage supplies) |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 33 | * @update_bank: bank to control on/off |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 34 | * @update_reg: register to control on/off |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 35 | * @update_mask: mask to enable/disable regulator |
| 36 | * @update_val_enable: bits to enable the regulator in normal (high power) mode |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 37 | * @voltage_bank: bank to control regulator voltage |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 38 | * @voltage_reg: register to control regulator voltage |
| 39 | * @voltage_mask: mask to control regulator voltage |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 40 | * @voltages: supported voltage table |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 41 | * @voltages_len: number of supported voltages for the regulator |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 42 | * @delay: startup/set voltage delay in us |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 43 | */ |
| 44 | struct ab8500_regulator_info { |
| 45 | struct device *dev; |
| 46 | struct regulator_desc desc; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 47 | struct regulator_dev *regulator; |
| 48 | int max_uV; |
| 49 | int min_uV; |
| 50 | int fixed_uV; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 51 | u8 update_bank; |
| 52 | u8 update_reg; |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 53 | u8 update_mask; |
| 54 | u8 update_val_enable; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 55 | u8 voltage_bank; |
| 56 | u8 voltage_reg; |
| 57 | u8 voltage_mask; |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 58 | int const *voltages; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 59 | int voltages_len; |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 60 | unsigned int delay; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /* voltage tables for the vauxn/vintcore supplies */ |
| 64 | static const int ldo_vauxn_voltages[] = { |
| 65 | 1100000, |
| 66 | 1200000, |
| 67 | 1300000, |
| 68 | 1400000, |
| 69 | 1500000, |
| 70 | 1800000, |
| 71 | 1850000, |
| 72 | 1900000, |
| 73 | 2500000, |
| 74 | 2650000, |
| 75 | 2700000, |
| 76 | 2750000, |
| 77 | 2800000, |
| 78 | 2900000, |
| 79 | 3000000, |
| 80 | 3300000, |
| 81 | }; |
| 82 | |
Bengt Jonsson | 2b75151 | 2010-12-10 11:08:43 +0100 | [diff] [blame] | 83 | static const int ldo_vaux3_voltages[] = { |
| 84 | 1200000, |
| 85 | 1500000, |
| 86 | 1800000, |
| 87 | 2100000, |
| 88 | 2500000, |
| 89 | 2750000, |
| 90 | 2790000, |
| 91 | 2910000, |
| 92 | }; |
| 93 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 94 | static const int ldo_vintcore_voltages[] = { |
| 95 | 1200000, |
| 96 | 1225000, |
| 97 | 1250000, |
| 98 | 1275000, |
| 99 | 1300000, |
| 100 | 1325000, |
| 101 | 1350000, |
| 102 | }; |
| 103 | |
| 104 | static int ab8500_regulator_enable(struct regulator_dev *rdev) |
| 105 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 106 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 107 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 108 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 109 | if (info == NULL) { |
| 110 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 111 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 112 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 113 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 114 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 115 | info->update_bank, info->update_reg, |
| 116 | info->update_mask, info->update_val_enable); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 117 | if (ret < 0) |
| 118 | dev_err(rdev_get_dev(rdev), |
| 119 | "couldn't set enable bits for regulator\n"); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 120 | |
| 121 | dev_vdbg(rdev_get_dev(rdev), |
| 122 | "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n", |
| 123 | info->desc.name, info->update_bank, info->update_reg, |
| 124 | info->update_mask, info->update_val_enable); |
| 125 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 126 | return ret; |
| 127 | } |
| 128 | |
| 129 | static int ab8500_regulator_disable(struct regulator_dev *rdev) |
| 130 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 131 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 132 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 133 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 134 | if (info == NULL) { |
| 135 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 136 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 137 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 138 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 139 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 140 | info->update_bank, info->update_reg, |
| 141 | info->update_mask, 0x0); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 142 | if (ret < 0) |
| 143 | dev_err(rdev_get_dev(rdev), |
| 144 | "couldn't set disable bits for regulator\n"); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 145 | |
| 146 | dev_vdbg(rdev_get_dev(rdev), |
| 147 | "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n", |
| 148 | info->desc.name, info->update_bank, info->update_reg, |
| 149 | info->update_mask, 0x0); |
| 150 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 151 | return ret; |
| 152 | } |
| 153 | |
| 154 | static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) |
| 155 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 156 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 157 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 158 | u8 regval; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 159 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 160 | if (info == NULL) { |
| 161 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 162 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 163 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 164 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 165 | ret = abx500_get_register_interruptible(info->dev, |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 166 | info->update_bank, info->update_reg, ®val); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 167 | if (ret < 0) { |
| 168 | dev_err(rdev_get_dev(rdev), |
| 169 | "couldn't read 0x%x register\n", info->update_reg); |
| 170 | return ret; |
| 171 | } |
| 172 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 173 | dev_vdbg(rdev_get_dev(rdev), |
| 174 | "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," |
| 175 | " 0x%x\n", |
| 176 | info->desc.name, info->update_bank, info->update_reg, |
| 177 | info->update_mask, regval); |
| 178 | |
| 179 | if (regval & info->update_mask) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 180 | return true; |
| 181 | else |
| 182 | return false; |
| 183 | } |
| 184 | |
| 185 | static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector) |
| 186 | { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 187 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 188 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 189 | if (info == NULL) { |
| 190 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 191 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 192 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 193 | |
| 194 | /* return the uV for the fixed regulators */ |
| 195 | if (info->fixed_uV) |
| 196 | return info->fixed_uV; |
| 197 | |
Axel Lin | 49990e6 | 2010-09-04 23:06:41 +0800 | [diff] [blame] | 198 | if (selector >= info->voltages_len) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 199 | return -EINVAL; |
| 200 | |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 201 | return info->voltages[selector]; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 202 | } |
| 203 | |
Axel Lin | 3bf6e90 | 2012-02-24 17:15:45 +0800 | [diff] [blame] | 204 | static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 205 | { |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 206 | int ret, val; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 207 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 208 | u8 regval; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 209 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 210 | if (info == NULL) { |
| 211 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 212 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 213 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 214 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 215 | ret = abx500_get_register_interruptible(info->dev, |
| 216 | info->voltage_bank, info->voltage_reg, ®val); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 217 | if (ret < 0) { |
| 218 | dev_err(rdev_get_dev(rdev), |
| 219 | "couldn't read voltage reg for regulator\n"); |
| 220 | return ret; |
| 221 | } |
| 222 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 223 | dev_vdbg(rdev_get_dev(rdev), |
| 224 | "%s-get_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," |
| 225 | " 0x%x\n", |
| 226 | info->desc.name, info->voltage_bank, info->voltage_reg, |
| 227 | info->voltage_mask, regval); |
| 228 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 229 | /* vintcore has a different layout */ |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 230 | val = regval & info->voltage_mask; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 231 | if (info->desc.id == AB8500_LDO_INTCORE) |
Axel Lin | 3bf6e90 | 2012-02-24 17:15:45 +0800 | [diff] [blame] | 232 | return val >> 0x3; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 233 | else |
Axel Lin | 3bf6e90 | 2012-02-24 17:15:45 +0800 | [diff] [blame] | 234 | return val; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static int ab8500_get_best_voltage_index(struct regulator_dev *rdev, |
| 238 | int min_uV, int max_uV) |
| 239 | { |
| 240 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 241 | int i; |
| 242 | |
| 243 | /* check the supported voltage */ |
| 244 | for (i = 0; i < info->voltages_len; i++) { |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 245 | if ((info->voltages[i] >= min_uV) && |
| 246 | (info->voltages[i] <= max_uV)) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 247 | return i; |
| 248 | } |
| 249 | |
| 250 | return -EINVAL; |
| 251 | } |
| 252 | |
| 253 | static int ab8500_regulator_set_voltage(struct regulator_dev *rdev, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 254 | int min_uV, int max_uV, |
| 255 | unsigned *selector) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 256 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 257 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 258 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 259 | u8 regval; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 260 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 261 | if (info == NULL) { |
| 262 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 263 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 264 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 265 | |
| 266 | /* get the appropriate voltages within the range */ |
| 267 | ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV); |
| 268 | if (ret < 0) { |
| 269 | dev_err(rdev_get_dev(rdev), |
| 270 | "couldn't get best voltage for regulator\n"); |
| 271 | return ret; |
| 272 | } |
| 273 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 274 | *selector = ret; |
| 275 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 276 | /* set the registers for the request */ |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 277 | regval = (u8)ret; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 278 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 279 | info->voltage_bank, info->voltage_reg, |
| 280 | info->voltage_mask, regval); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 281 | if (ret < 0) |
| 282 | dev_err(rdev_get_dev(rdev), |
| 283 | "couldn't set voltage reg for regulator\n"); |
| 284 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 285 | dev_vdbg(rdev_get_dev(rdev), |
| 286 | "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," |
| 287 | " 0x%x\n", |
| 288 | info->desc.name, info->voltage_bank, info->voltage_reg, |
| 289 | info->voltage_mask, regval); |
| 290 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 291 | return ret; |
| 292 | } |
| 293 | |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 294 | static int ab8500_regulator_enable_time(struct regulator_dev *rdev) |
| 295 | { |
| 296 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 297 | |
| 298 | return info->delay; |
| 299 | } |
| 300 | |
| 301 | static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 302 | unsigned int old_sel, |
| 303 | unsigned int new_sel) |
| 304 | { |
| 305 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 306 | int ret; |
| 307 | |
| 308 | /* If the regulator isn't on, it won't take time here */ |
| 309 | ret = ab8500_regulator_is_enabled(rdev); |
| 310 | if (ret < 0) |
| 311 | return ret; |
| 312 | if (!ret) |
| 313 | return 0; |
| 314 | return info->delay; |
| 315 | } |
| 316 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 317 | static struct regulator_ops ab8500_regulator_ops = { |
| 318 | .enable = ab8500_regulator_enable, |
| 319 | .disable = ab8500_regulator_disable, |
| 320 | .is_enabled = ab8500_regulator_is_enabled, |
Axel Lin | 3bf6e90 | 2012-02-24 17:15:45 +0800 | [diff] [blame] | 321 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 322 | .set_voltage = ab8500_regulator_set_voltage, |
| 323 | .list_voltage = ab8500_list_voltage, |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 324 | .enable_time = ab8500_regulator_enable_time, |
| 325 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 326 | }; |
| 327 | |
| 328 | static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) |
| 329 | { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 330 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 331 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 332 | if (info == NULL) { |
| 333 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 334 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 335 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 336 | |
| 337 | return info->fixed_uV; |
| 338 | } |
| 339 | |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 340 | static struct regulator_ops ab8500_regulator_fixed_ops = { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 341 | .enable = ab8500_regulator_enable, |
| 342 | .disable = ab8500_regulator_disable, |
| 343 | .is_enabled = ab8500_regulator_is_enabled, |
| 344 | .get_voltage = ab8500_fixed_get_voltage, |
| 345 | .list_voltage = ab8500_list_voltage, |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 346 | .enable_time = ab8500_regulator_enable_time, |
| 347 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 348 | }; |
| 349 | |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 350 | static struct ab8500_regulator_info |
| 351 | ab8500_regulator_info[AB8500_NUM_REGULATORS] = { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 352 | /* |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 353 | * Variable Voltage Regulators |
| 354 | * name, min mV, max mV, |
| 355 | * update bank, reg, mask, enable val |
| 356 | * volt bank, reg, mask, table, table length |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 357 | */ |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 358 | [AB8500_LDO_AUX1] = { |
| 359 | .desc = { |
| 360 | .name = "LDO-AUX1", |
| 361 | .ops = &ab8500_regulator_ops, |
| 362 | .type = REGULATOR_VOLTAGE, |
| 363 | .id = AB8500_LDO_AUX1, |
| 364 | .owner = THIS_MODULE, |
| 365 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), |
| 366 | }, |
| 367 | .min_uV = 1100000, |
| 368 | .max_uV = 3300000, |
| 369 | .update_bank = 0x04, |
| 370 | .update_reg = 0x09, |
| 371 | .update_mask = 0x03, |
| 372 | .update_val_enable = 0x01, |
| 373 | .voltage_bank = 0x04, |
| 374 | .voltage_reg = 0x1f, |
| 375 | .voltage_mask = 0x0f, |
| 376 | .voltages = ldo_vauxn_voltages, |
| 377 | .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages), |
| 378 | }, |
| 379 | [AB8500_LDO_AUX2] = { |
| 380 | .desc = { |
| 381 | .name = "LDO-AUX2", |
| 382 | .ops = &ab8500_regulator_ops, |
| 383 | .type = REGULATOR_VOLTAGE, |
| 384 | .id = AB8500_LDO_AUX2, |
| 385 | .owner = THIS_MODULE, |
| 386 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), |
| 387 | }, |
| 388 | .min_uV = 1100000, |
| 389 | .max_uV = 3300000, |
| 390 | .update_bank = 0x04, |
| 391 | .update_reg = 0x09, |
| 392 | .update_mask = 0x0c, |
| 393 | .update_val_enable = 0x04, |
| 394 | .voltage_bank = 0x04, |
| 395 | .voltage_reg = 0x20, |
| 396 | .voltage_mask = 0x0f, |
| 397 | .voltages = ldo_vauxn_voltages, |
| 398 | .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages), |
| 399 | }, |
| 400 | [AB8500_LDO_AUX3] = { |
| 401 | .desc = { |
| 402 | .name = "LDO-AUX3", |
| 403 | .ops = &ab8500_regulator_ops, |
| 404 | .type = REGULATOR_VOLTAGE, |
| 405 | .id = AB8500_LDO_AUX3, |
| 406 | .owner = THIS_MODULE, |
| 407 | .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages), |
| 408 | }, |
| 409 | .min_uV = 1100000, |
| 410 | .max_uV = 3300000, |
| 411 | .update_bank = 0x04, |
| 412 | .update_reg = 0x0a, |
| 413 | .update_mask = 0x03, |
| 414 | .update_val_enable = 0x01, |
| 415 | .voltage_bank = 0x04, |
| 416 | .voltage_reg = 0x21, |
| 417 | .voltage_mask = 0x07, |
| 418 | .voltages = ldo_vaux3_voltages, |
| 419 | .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages), |
| 420 | }, |
| 421 | [AB8500_LDO_INTCORE] = { |
| 422 | .desc = { |
| 423 | .name = "LDO-INTCORE", |
| 424 | .ops = &ab8500_regulator_ops, |
| 425 | .type = REGULATOR_VOLTAGE, |
| 426 | .id = AB8500_LDO_INTCORE, |
| 427 | .owner = THIS_MODULE, |
| 428 | .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages), |
| 429 | }, |
| 430 | .min_uV = 1100000, |
| 431 | .max_uV = 3300000, |
| 432 | .update_bank = 0x03, |
| 433 | .update_reg = 0x80, |
| 434 | .update_mask = 0x44, |
| 435 | .update_val_enable = 0x04, |
| 436 | .voltage_bank = 0x03, |
| 437 | .voltage_reg = 0x80, |
| 438 | .voltage_mask = 0x38, |
| 439 | .voltages = ldo_vintcore_voltages, |
| 440 | .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages), |
| 441 | }, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 442 | |
| 443 | /* |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 444 | * Fixed Voltage Regulators |
| 445 | * name, fixed mV, |
| 446 | * update bank, reg, mask, enable val |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 447 | */ |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 448 | [AB8500_LDO_TVOUT] = { |
| 449 | .desc = { |
| 450 | .name = "LDO-TVOUT", |
| 451 | .ops = &ab8500_regulator_fixed_ops, |
| 452 | .type = REGULATOR_VOLTAGE, |
| 453 | .id = AB8500_LDO_TVOUT, |
| 454 | .owner = THIS_MODULE, |
| 455 | .n_voltages = 1, |
| 456 | }, |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 457 | .delay = 10000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 458 | .fixed_uV = 2000000, |
| 459 | .update_bank = 0x03, |
| 460 | .update_reg = 0x80, |
| 461 | .update_mask = 0x82, |
| 462 | .update_val_enable = 0x02, |
| 463 | }, |
Bengt Jonsson | ea05ef3 | 2011-03-10 14:43:31 +0100 | [diff] [blame] | 464 | [AB8500_LDO_USB] = { |
| 465 | .desc = { |
| 466 | .name = "LDO-USB", |
| 467 | .ops = &ab8500_regulator_fixed_ops, |
| 468 | .type = REGULATOR_VOLTAGE, |
| 469 | .id = AB8500_LDO_USB, |
| 470 | .owner = THIS_MODULE, |
| 471 | .n_voltages = 1, |
| 472 | }, |
| 473 | .fixed_uV = 3300000, |
| 474 | .update_bank = 0x03, |
| 475 | .update_reg = 0x82, |
| 476 | .update_mask = 0x03, |
| 477 | .update_val_enable = 0x01, |
| 478 | }, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 479 | [AB8500_LDO_AUDIO] = { |
| 480 | .desc = { |
| 481 | .name = "LDO-AUDIO", |
| 482 | .ops = &ab8500_regulator_fixed_ops, |
| 483 | .type = REGULATOR_VOLTAGE, |
| 484 | .id = AB8500_LDO_AUDIO, |
| 485 | .owner = THIS_MODULE, |
| 486 | .n_voltages = 1, |
| 487 | }, |
| 488 | .fixed_uV = 2000000, |
| 489 | .update_bank = 0x03, |
| 490 | .update_reg = 0x83, |
| 491 | .update_mask = 0x02, |
| 492 | .update_val_enable = 0x02, |
| 493 | }, |
| 494 | [AB8500_LDO_ANAMIC1] = { |
| 495 | .desc = { |
| 496 | .name = "LDO-ANAMIC1", |
| 497 | .ops = &ab8500_regulator_fixed_ops, |
| 498 | .type = REGULATOR_VOLTAGE, |
| 499 | .id = AB8500_LDO_ANAMIC1, |
| 500 | .owner = THIS_MODULE, |
| 501 | .n_voltages = 1, |
| 502 | }, |
| 503 | .fixed_uV = 2050000, |
| 504 | .update_bank = 0x03, |
| 505 | .update_reg = 0x83, |
| 506 | .update_mask = 0x08, |
| 507 | .update_val_enable = 0x08, |
| 508 | }, |
| 509 | [AB8500_LDO_ANAMIC2] = { |
| 510 | .desc = { |
| 511 | .name = "LDO-ANAMIC2", |
| 512 | .ops = &ab8500_regulator_fixed_ops, |
| 513 | .type = REGULATOR_VOLTAGE, |
| 514 | .id = AB8500_LDO_ANAMIC2, |
| 515 | .owner = THIS_MODULE, |
| 516 | .n_voltages = 1, |
| 517 | }, |
| 518 | .fixed_uV = 2050000, |
| 519 | .update_bank = 0x03, |
| 520 | .update_reg = 0x83, |
| 521 | .update_mask = 0x10, |
| 522 | .update_val_enable = 0x10, |
| 523 | }, |
| 524 | [AB8500_LDO_DMIC] = { |
| 525 | .desc = { |
| 526 | .name = "LDO-DMIC", |
| 527 | .ops = &ab8500_regulator_fixed_ops, |
| 528 | .type = REGULATOR_VOLTAGE, |
| 529 | .id = AB8500_LDO_DMIC, |
| 530 | .owner = THIS_MODULE, |
| 531 | .n_voltages = 1, |
| 532 | }, |
| 533 | .fixed_uV = 1800000, |
| 534 | .update_bank = 0x03, |
| 535 | .update_reg = 0x83, |
| 536 | .update_mask = 0x04, |
| 537 | .update_val_enable = 0x04, |
| 538 | }, |
| 539 | [AB8500_LDO_ANA] = { |
| 540 | .desc = { |
| 541 | .name = "LDO-ANA", |
| 542 | .ops = &ab8500_regulator_fixed_ops, |
| 543 | .type = REGULATOR_VOLTAGE, |
| 544 | .id = AB8500_LDO_ANA, |
| 545 | .owner = THIS_MODULE, |
| 546 | .n_voltages = 1, |
| 547 | }, |
| 548 | .fixed_uV = 1200000, |
| 549 | .update_bank = 0x04, |
| 550 | .update_reg = 0x06, |
| 551 | .update_mask = 0x0c, |
| 552 | .update_val_enable = 0x04, |
| 553 | }, |
| 554 | |
| 555 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 556 | }; |
| 557 | |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 558 | struct ab8500_reg_init { |
| 559 | u8 bank; |
| 560 | u8 addr; |
| 561 | u8 mask; |
| 562 | }; |
| 563 | |
| 564 | #define REG_INIT(_id, _bank, _addr, _mask) \ |
| 565 | [_id] = { \ |
| 566 | .bank = _bank, \ |
| 567 | .addr = _addr, \ |
| 568 | .mask = _mask, \ |
| 569 | } |
| 570 | |
| 571 | static struct ab8500_reg_init ab8500_reg_init[] = { |
| 572 | /* |
| 573 | * 0x30, VanaRequestCtrl |
| 574 | * 0x0C, VpllRequestCtrl |
| 575 | * 0xc0, VextSupply1RequestCtrl |
| 576 | */ |
| 577 | REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc), |
| 578 | /* |
| 579 | * 0x03, VextSupply2RequestCtrl |
| 580 | * 0x0c, VextSupply3RequestCtrl |
| 581 | * 0x30, Vaux1RequestCtrl |
| 582 | * 0xc0, Vaux2RequestCtrl |
| 583 | */ |
| 584 | REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff), |
| 585 | /* |
| 586 | * 0x03, Vaux3RequestCtrl |
| 587 | * 0x04, SwHPReq |
| 588 | */ |
| 589 | REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07), |
| 590 | /* |
| 591 | * 0x08, VanaSysClkReq1HPValid |
| 592 | * 0x20, Vaux1SysClkReq1HPValid |
| 593 | * 0x40, Vaux2SysClkReq1HPValid |
| 594 | * 0x80, Vaux3SysClkReq1HPValid |
| 595 | */ |
| 596 | REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8), |
| 597 | /* |
| 598 | * 0x10, VextSupply1SysClkReq1HPValid |
| 599 | * 0x20, VextSupply2SysClkReq1HPValid |
| 600 | * 0x40, VextSupply3SysClkReq1HPValid |
| 601 | */ |
| 602 | REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70), |
| 603 | /* |
| 604 | * 0x08, VanaHwHPReq1Valid |
| 605 | * 0x20, Vaux1HwHPReq1Valid |
| 606 | * 0x40, Vaux2HwHPReq1Valid |
| 607 | * 0x80, Vaux3HwHPReq1Valid |
| 608 | */ |
| 609 | REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8), |
| 610 | /* |
| 611 | * 0x01, VextSupply1HwHPReq1Valid |
| 612 | * 0x02, VextSupply2HwHPReq1Valid |
| 613 | * 0x04, VextSupply3HwHPReq1Valid |
| 614 | */ |
| 615 | REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07), |
| 616 | /* |
| 617 | * 0x08, VanaHwHPReq2Valid |
| 618 | * 0x20, Vaux1HwHPReq2Valid |
| 619 | * 0x40, Vaux2HwHPReq2Valid |
| 620 | * 0x80, Vaux3HwHPReq2Valid |
| 621 | */ |
| 622 | REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8), |
| 623 | /* |
| 624 | * 0x01, VextSupply1HwHPReq2Valid |
| 625 | * 0x02, VextSupply2HwHPReq2Valid |
| 626 | * 0x04, VextSupply3HwHPReq2Valid |
| 627 | */ |
| 628 | REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07), |
| 629 | /* |
| 630 | * 0x20, VanaSwHPReqValid |
| 631 | * 0x80, Vaux1SwHPReqValid |
| 632 | */ |
| 633 | REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0), |
| 634 | /* |
| 635 | * 0x01, Vaux2SwHPReqValid |
| 636 | * 0x02, Vaux3SwHPReqValid |
| 637 | * 0x04, VextSupply1SwHPReqValid |
| 638 | * 0x08, VextSupply2SwHPReqValid |
| 639 | * 0x10, VextSupply3SwHPReqValid |
| 640 | */ |
| 641 | REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f), |
| 642 | /* |
| 643 | * 0x02, SysClkReq2Valid1 |
| 644 | * ... |
| 645 | * 0x80, SysClkReq8Valid1 |
| 646 | */ |
| 647 | REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe), |
| 648 | /* |
| 649 | * 0x02, SysClkReq2Valid2 |
| 650 | * ... |
| 651 | * 0x80, SysClkReq8Valid2 |
| 652 | */ |
| 653 | REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe), |
| 654 | /* |
| 655 | * 0x02, VTVoutEna |
| 656 | * 0x04, Vintcore12Ena |
| 657 | * 0x38, Vintcore12Sel |
| 658 | * 0x40, Vintcore12LP |
| 659 | * 0x80, VTVoutLP |
| 660 | */ |
| 661 | REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe), |
| 662 | /* |
| 663 | * 0x02, VaudioEna |
| 664 | * 0x04, VdmicEna |
| 665 | * 0x08, Vamic1Ena |
| 666 | * 0x10, Vamic2Ena |
| 667 | */ |
| 668 | REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e), |
| 669 | /* |
| 670 | * 0x01, Vamic1_dzout |
| 671 | * 0x02, Vamic2_dzout |
| 672 | */ |
| 673 | REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03), |
| 674 | /* |
| 675 | * 0x0c, VanaRegu |
| 676 | * 0x03, VpllRegu |
| 677 | */ |
| 678 | REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f), |
| 679 | /* |
| 680 | * 0x01, VrefDDREna |
| 681 | * 0x02, VrefDDRSleepMode |
| 682 | */ |
| 683 | REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03), |
| 684 | /* |
| 685 | * 0x03, VextSupply1Regu |
| 686 | * 0x0c, VextSupply2Regu |
| 687 | * 0x30, VextSupply3Regu |
| 688 | * 0x40, ExtSupply2Bypass |
| 689 | * 0x80, ExtSupply3Bypass |
| 690 | */ |
| 691 | REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff), |
| 692 | /* |
| 693 | * 0x03, Vaux1Regu |
| 694 | * 0x0c, Vaux2Regu |
| 695 | */ |
| 696 | REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f), |
| 697 | /* |
| 698 | * 0x03, Vaux3Regu |
| 699 | */ |
| 700 | REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03), |
| 701 | /* |
| 702 | * 0x3f, Vsmps1Sel1 |
| 703 | */ |
| 704 | REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f), |
| 705 | /* |
| 706 | * 0x0f, Vaux1Sel |
| 707 | */ |
| 708 | REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f), |
| 709 | /* |
| 710 | * 0x0f, Vaux2Sel |
| 711 | */ |
| 712 | REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f), |
| 713 | /* |
| 714 | * 0x07, Vaux3Sel |
| 715 | */ |
| 716 | REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07), |
| 717 | /* |
| 718 | * 0x01, VextSupply12LP |
| 719 | */ |
| 720 | REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01), |
| 721 | /* |
| 722 | * 0x04, Vaux1Disch |
| 723 | * 0x08, Vaux2Disch |
| 724 | * 0x10, Vaux3Disch |
| 725 | * 0x20, Vintcore12Disch |
| 726 | * 0x40, VTVoutDisch |
| 727 | * 0x80, VaudioDisch |
| 728 | */ |
| 729 | REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc), |
| 730 | /* |
| 731 | * 0x02, VanaDisch |
| 732 | * 0x04, VdmicPullDownEna |
| 733 | * 0x10, VdmicDisch |
| 734 | */ |
| 735 | REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16), |
| 736 | }; |
| 737 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 738 | static __devinit int ab8500_regulator_probe(struct platform_device *pdev) |
| 739 | { |
| 740 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); |
Dan Carpenter | af54dec | 2010-08-14 11:03:16 +0200 | [diff] [blame] | 741 | struct ab8500_platform_data *pdata; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 742 | int i, err; |
| 743 | |
| 744 | if (!ab8500) { |
| 745 | dev_err(&pdev->dev, "null mfd parent\n"); |
| 746 | return -EINVAL; |
| 747 | } |
Dan Carpenter | af54dec | 2010-08-14 11:03:16 +0200 | [diff] [blame] | 748 | pdata = dev_get_platdata(ab8500->dev); |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 749 | if (!pdata) { |
| 750 | dev_err(&pdev->dev, "null pdata\n"); |
| 751 | return -EINVAL; |
| 752 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 753 | |
Bengt Jonsson | cb189b0 | 2010-12-10 11:08:40 +0100 | [diff] [blame] | 754 | /* make sure the platform data has the correct size */ |
| 755 | if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) { |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 756 | dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); |
Bengt Jonsson | cb189b0 | 2010-12-10 11:08:40 +0100 | [diff] [blame] | 757 | return -EINVAL; |
| 758 | } |
| 759 | |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 760 | /* initialize registers */ |
| 761 | for (i = 0; i < pdata->num_regulator_reg_init; i++) { |
| 762 | int id; |
| 763 | u8 value; |
| 764 | |
| 765 | id = pdata->regulator_reg_init[i].id; |
| 766 | value = pdata->regulator_reg_init[i].value; |
| 767 | |
| 768 | /* check for configuration errors */ |
| 769 | if (id >= AB8500_NUM_REGULATOR_REGISTERS) { |
| 770 | dev_err(&pdev->dev, |
| 771 | "Configuration error: id outside range.\n"); |
| 772 | return -EINVAL; |
| 773 | } |
| 774 | if (value & ~ab8500_reg_init[id].mask) { |
| 775 | dev_err(&pdev->dev, |
| 776 | "Configuration error: value outside mask.\n"); |
| 777 | return -EINVAL; |
| 778 | } |
| 779 | |
| 780 | /* initialize register */ |
| 781 | err = abx500_mask_and_set_register_interruptible(&pdev->dev, |
| 782 | ab8500_reg_init[id].bank, |
| 783 | ab8500_reg_init[id].addr, |
| 784 | ab8500_reg_init[id].mask, |
| 785 | value); |
| 786 | if (err < 0) { |
| 787 | dev_err(&pdev->dev, |
| 788 | "Failed to initialize 0x%02x, 0x%02x.\n", |
| 789 | ab8500_reg_init[id].bank, |
| 790 | ab8500_reg_init[id].addr); |
| 791 | return err; |
| 792 | } |
| 793 | dev_vdbg(&pdev->dev, |
| 794 | " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 795 | ab8500_reg_init[id].bank, |
| 796 | ab8500_reg_init[id].addr, |
| 797 | ab8500_reg_init[id].mask, |
| 798 | value); |
| 799 | } |
| 800 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 801 | /* register all regulators */ |
| 802 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { |
| 803 | struct ab8500_regulator_info *info = NULL; |
| 804 | |
| 805 | /* assign per-regulator data */ |
| 806 | info = &ab8500_regulator_info[i]; |
| 807 | info->dev = &pdev->dev; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 808 | |
Bengt Jonsson | 2b75151 | 2010-12-10 11:08:43 +0100 | [diff] [blame] | 809 | /* fix for hardware before ab8500v2.0 */ |
| 810 | if (abx500_get_chip_id(info->dev) < 0x20) { |
| 811 | if (info->desc.id == AB8500_LDO_AUX3) { |
| 812 | info->desc.n_voltages = |
| 813 | ARRAY_SIZE(ldo_vauxn_voltages); |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 814 | info->voltages = ldo_vauxn_voltages; |
Bengt Jonsson | 2b75151 | 2010-12-10 11:08:43 +0100 | [diff] [blame] | 815 | info->voltages_len = |
| 816 | ARRAY_SIZE(ldo_vauxn_voltages); |
| 817 | info->voltage_mask = 0xf; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | /* register regulator with framework */ |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 822 | info->regulator = regulator_register(&info->desc, &pdev->dev, |
Rajendra Nayak | 2c043bc | 2011-11-18 16:47:19 +0530 | [diff] [blame] | 823 | &pdata->regulator[i], info, NULL); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 824 | if (IS_ERR(info->regulator)) { |
| 825 | err = PTR_ERR(info->regulator); |
| 826 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
| 827 | info->desc.name); |
| 828 | /* when we fail, un-register all earlier regulators */ |
Axel Lin | d4876a3 | 2010-08-14 21:44:04 +0800 | [diff] [blame] | 829 | while (--i >= 0) { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 830 | info = &ab8500_regulator_info[i]; |
| 831 | regulator_unregister(info->regulator); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 832 | } |
| 833 | return err; |
| 834 | } |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 835 | |
| 836 | dev_vdbg(rdev_get_dev(info->regulator), |
| 837 | "%s-probed\n", info->desc.name); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static __devexit int ab8500_regulator_remove(struct platform_device *pdev) |
| 844 | { |
| 845 | int i; |
| 846 | |
| 847 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { |
| 848 | struct ab8500_regulator_info *info = NULL; |
| 849 | info = &ab8500_regulator_info[i]; |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 850 | |
| 851 | dev_vdbg(rdev_get_dev(info->regulator), |
| 852 | "%s-remove\n", info->desc.name); |
| 853 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 854 | regulator_unregister(info->regulator); |
| 855 | } |
| 856 | |
| 857 | return 0; |
| 858 | } |
| 859 | |
| 860 | static struct platform_driver ab8500_regulator_driver = { |
| 861 | .probe = ab8500_regulator_probe, |
| 862 | .remove = __devexit_p(ab8500_regulator_remove), |
| 863 | .driver = { |
| 864 | .name = "ab8500-regulator", |
| 865 | .owner = THIS_MODULE, |
| 866 | }, |
| 867 | }; |
| 868 | |
| 869 | static int __init ab8500_regulator_init(void) |
| 870 | { |
| 871 | int ret; |
| 872 | |
| 873 | ret = platform_driver_register(&ab8500_regulator_driver); |
| 874 | if (ret != 0) |
| 875 | pr_err("Failed to register ab8500 regulator: %d\n", ret); |
| 876 | |
| 877 | return ret; |
| 878 | } |
| 879 | subsys_initcall(ab8500_regulator_init); |
| 880 | |
| 881 | static void __exit ab8500_regulator_exit(void) |
| 882 | { |
| 883 | platform_driver_unregister(&ab8500_regulator_driver); |
| 884 | } |
| 885 | module_exit(ab8500_regulator_exit); |
| 886 | |
| 887 | MODULE_LICENSE("GPL v2"); |
| 888 | MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>"); |
| 889 | MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC"); |
| 890 | MODULE_ALIAS("platform:ab8500-regulator"); |