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 | |
Axel Lin | ae713d3 | 2012-03-20 09:51:08 +0800 | [diff] [blame] | 237 | static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev, |
| 238 | unsigned selector) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 239 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 240 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 241 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 242 | u8 regval; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 243 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 244 | if (info == NULL) { |
| 245 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 246 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 247 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 248 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 249 | /* set the registers for the request */ |
Axel Lin | ae713d3 | 2012-03-20 09:51:08 +0800 | [diff] [blame] | 250 | regval = (u8)selector; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 251 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 252 | info->voltage_bank, info->voltage_reg, |
| 253 | info->voltage_mask, regval); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 254 | if (ret < 0) |
| 255 | dev_err(rdev_get_dev(rdev), |
| 256 | "couldn't set voltage reg for regulator\n"); |
| 257 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 258 | dev_vdbg(rdev_get_dev(rdev), |
| 259 | "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," |
| 260 | " 0x%x\n", |
| 261 | info->desc.name, info->voltage_bank, info->voltage_reg, |
| 262 | info->voltage_mask, regval); |
| 263 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 264 | return ret; |
| 265 | } |
| 266 | |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 267 | static int ab8500_regulator_enable_time(struct regulator_dev *rdev) |
| 268 | { |
| 269 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 270 | |
| 271 | return info->delay; |
| 272 | } |
| 273 | |
| 274 | static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 275 | unsigned int old_sel, |
| 276 | unsigned int new_sel) |
| 277 | { |
| 278 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 279 | int ret; |
| 280 | |
| 281 | /* If the regulator isn't on, it won't take time here */ |
| 282 | ret = ab8500_regulator_is_enabled(rdev); |
| 283 | if (ret < 0) |
| 284 | return ret; |
| 285 | if (!ret) |
| 286 | return 0; |
| 287 | return info->delay; |
| 288 | } |
| 289 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 290 | static struct regulator_ops ab8500_regulator_ops = { |
| 291 | .enable = ab8500_regulator_enable, |
| 292 | .disable = ab8500_regulator_disable, |
| 293 | .is_enabled = ab8500_regulator_is_enabled, |
Axel Lin | 3bf6e90 | 2012-02-24 17:15:45 +0800 | [diff] [blame] | 294 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, |
Axel Lin | ae713d3 | 2012-03-20 09:51:08 +0800 | [diff] [blame] | 295 | .set_voltage_sel = ab8500_regulator_set_voltage_sel, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 296 | .list_voltage = ab8500_list_voltage, |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 297 | .enable_time = ab8500_regulator_enable_time, |
| 298 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) |
| 302 | { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 303 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 304 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 305 | if (info == NULL) { |
| 306 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 307 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 308 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 309 | |
| 310 | return info->fixed_uV; |
| 311 | } |
| 312 | |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 313 | static struct regulator_ops ab8500_regulator_fixed_ops = { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 314 | .enable = ab8500_regulator_enable, |
| 315 | .disable = ab8500_regulator_disable, |
| 316 | .is_enabled = ab8500_regulator_is_enabled, |
| 317 | .get_voltage = ab8500_fixed_get_voltage, |
| 318 | .list_voltage = ab8500_list_voltage, |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 319 | .enable_time = ab8500_regulator_enable_time, |
| 320 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 321 | }; |
| 322 | |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 323 | static struct ab8500_regulator_info |
| 324 | ab8500_regulator_info[AB8500_NUM_REGULATORS] = { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 325 | /* |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 326 | * Variable Voltage Regulators |
| 327 | * name, min mV, max mV, |
| 328 | * update bank, reg, mask, enable val |
| 329 | * volt bank, reg, mask, table, table length |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 330 | */ |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 331 | [AB8500_LDO_AUX1] = { |
| 332 | .desc = { |
| 333 | .name = "LDO-AUX1", |
| 334 | .ops = &ab8500_regulator_ops, |
| 335 | .type = REGULATOR_VOLTAGE, |
| 336 | .id = AB8500_LDO_AUX1, |
| 337 | .owner = THIS_MODULE, |
| 338 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), |
| 339 | }, |
| 340 | .min_uV = 1100000, |
| 341 | .max_uV = 3300000, |
| 342 | .update_bank = 0x04, |
| 343 | .update_reg = 0x09, |
| 344 | .update_mask = 0x03, |
| 345 | .update_val_enable = 0x01, |
| 346 | .voltage_bank = 0x04, |
| 347 | .voltage_reg = 0x1f, |
| 348 | .voltage_mask = 0x0f, |
| 349 | .voltages = ldo_vauxn_voltages, |
| 350 | .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages), |
| 351 | }, |
| 352 | [AB8500_LDO_AUX2] = { |
| 353 | .desc = { |
| 354 | .name = "LDO-AUX2", |
| 355 | .ops = &ab8500_regulator_ops, |
| 356 | .type = REGULATOR_VOLTAGE, |
| 357 | .id = AB8500_LDO_AUX2, |
| 358 | .owner = THIS_MODULE, |
| 359 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), |
| 360 | }, |
| 361 | .min_uV = 1100000, |
| 362 | .max_uV = 3300000, |
| 363 | .update_bank = 0x04, |
| 364 | .update_reg = 0x09, |
| 365 | .update_mask = 0x0c, |
| 366 | .update_val_enable = 0x04, |
| 367 | .voltage_bank = 0x04, |
| 368 | .voltage_reg = 0x20, |
| 369 | .voltage_mask = 0x0f, |
| 370 | .voltages = ldo_vauxn_voltages, |
| 371 | .voltages_len = ARRAY_SIZE(ldo_vauxn_voltages), |
| 372 | }, |
| 373 | [AB8500_LDO_AUX3] = { |
| 374 | .desc = { |
| 375 | .name = "LDO-AUX3", |
| 376 | .ops = &ab8500_regulator_ops, |
| 377 | .type = REGULATOR_VOLTAGE, |
| 378 | .id = AB8500_LDO_AUX3, |
| 379 | .owner = THIS_MODULE, |
| 380 | .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages), |
| 381 | }, |
| 382 | .min_uV = 1100000, |
| 383 | .max_uV = 3300000, |
| 384 | .update_bank = 0x04, |
| 385 | .update_reg = 0x0a, |
| 386 | .update_mask = 0x03, |
| 387 | .update_val_enable = 0x01, |
| 388 | .voltage_bank = 0x04, |
| 389 | .voltage_reg = 0x21, |
| 390 | .voltage_mask = 0x07, |
| 391 | .voltages = ldo_vaux3_voltages, |
| 392 | .voltages_len = ARRAY_SIZE(ldo_vaux3_voltages), |
| 393 | }, |
| 394 | [AB8500_LDO_INTCORE] = { |
| 395 | .desc = { |
| 396 | .name = "LDO-INTCORE", |
| 397 | .ops = &ab8500_regulator_ops, |
| 398 | .type = REGULATOR_VOLTAGE, |
| 399 | .id = AB8500_LDO_INTCORE, |
| 400 | .owner = THIS_MODULE, |
| 401 | .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages), |
| 402 | }, |
| 403 | .min_uV = 1100000, |
| 404 | .max_uV = 3300000, |
| 405 | .update_bank = 0x03, |
| 406 | .update_reg = 0x80, |
| 407 | .update_mask = 0x44, |
| 408 | .update_val_enable = 0x04, |
| 409 | .voltage_bank = 0x03, |
| 410 | .voltage_reg = 0x80, |
| 411 | .voltage_mask = 0x38, |
| 412 | .voltages = ldo_vintcore_voltages, |
| 413 | .voltages_len = ARRAY_SIZE(ldo_vintcore_voltages), |
| 414 | }, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 415 | |
| 416 | /* |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 417 | * Fixed Voltage Regulators |
| 418 | * name, fixed mV, |
| 419 | * update bank, reg, mask, enable val |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 420 | */ |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 421 | [AB8500_LDO_TVOUT] = { |
| 422 | .desc = { |
| 423 | .name = "LDO-TVOUT", |
| 424 | .ops = &ab8500_regulator_fixed_ops, |
| 425 | .type = REGULATOR_VOLTAGE, |
| 426 | .id = AB8500_LDO_TVOUT, |
| 427 | .owner = THIS_MODULE, |
| 428 | .n_voltages = 1, |
| 429 | }, |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 430 | .delay = 10000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 431 | .fixed_uV = 2000000, |
| 432 | .update_bank = 0x03, |
| 433 | .update_reg = 0x80, |
| 434 | .update_mask = 0x82, |
| 435 | .update_val_enable = 0x02, |
| 436 | }, |
Bengt Jonsson | ea05ef3 | 2011-03-10 14:43:31 +0100 | [diff] [blame] | 437 | [AB8500_LDO_USB] = { |
| 438 | .desc = { |
| 439 | .name = "LDO-USB", |
| 440 | .ops = &ab8500_regulator_fixed_ops, |
| 441 | .type = REGULATOR_VOLTAGE, |
| 442 | .id = AB8500_LDO_USB, |
| 443 | .owner = THIS_MODULE, |
| 444 | .n_voltages = 1, |
| 445 | }, |
| 446 | .fixed_uV = 3300000, |
| 447 | .update_bank = 0x03, |
| 448 | .update_reg = 0x82, |
| 449 | .update_mask = 0x03, |
| 450 | .update_val_enable = 0x01, |
| 451 | }, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 452 | [AB8500_LDO_AUDIO] = { |
| 453 | .desc = { |
| 454 | .name = "LDO-AUDIO", |
| 455 | .ops = &ab8500_regulator_fixed_ops, |
| 456 | .type = REGULATOR_VOLTAGE, |
| 457 | .id = AB8500_LDO_AUDIO, |
| 458 | .owner = THIS_MODULE, |
| 459 | .n_voltages = 1, |
| 460 | }, |
| 461 | .fixed_uV = 2000000, |
| 462 | .update_bank = 0x03, |
| 463 | .update_reg = 0x83, |
| 464 | .update_mask = 0x02, |
| 465 | .update_val_enable = 0x02, |
| 466 | }, |
| 467 | [AB8500_LDO_ANAMIC1] = { |
| 468 | .desc = { |
| 469 | .name = "LDO-ANAMIC1", |
| 470 | .ops = &ab8500_regulator_fixed_ops, |
| 471 | .type = REGULATOR_VOLTAGE, |
| 472 | .id = AB8500_LDO_ANAMIC1, |
| 473 | .owner = THIS_MODULE, |
| 474 | .n_voltages = 1, |
| 475 | }, |
| 476 | .fixed_uV = 2050000, |
| 477 | .update_bank = 0x03, |
| 478 | .update_reg = 0x83, |
| 479 | .update_mask = 0x08, |
| 480 | .update_val_enable = 0x08, |
| 481 | }, |
| 482 | [AB8500_LDO_ANAMIC2] = { |
| 483 | .desc = { |
| 484 | .name = "LDO-ANAMIC2", |
| 485 | .ops = &ab8500_regulator_fixed_ops, |
| 486 | .type = REGULATOR_VOLTAGE, |
| 487 | .id = AB8500_LDO_ANAMIC2, |
| 488 | .owner = THIS_MODULE, |
| 489 | .n_voltages = 1, |
| 490 | }, |
| 491 | .fixed_uV = 2050000, |
| 492 | .update_bank = 0x03, |
| 493 | .update_reg = 0x83, |
| 494 | .update_mask = 0x10, |
| 495 | .update_val_enable = 0x10, |
| 496 | }, |
| 497 | [AB8500_LDO_DMIC] = { |
| 498 | .desc = { |
| 499 | .name = "LDO-DMIC", |
| 500 | .ops = &ab8500_regulator_fixed_ops, |
| 501 | .type = REGULATOR_VOLTAGE, |
| 502 | .id = AB8500_LDO_DMIC, |
| 503 | .owner = THIS_MODULE, |
| 504 | .n_voltages = 1, |
| 505 | }, |
| 506 | .fixed_uV = 1800000, |
| 507 | .update_bank = 0x03, |
| 508 | .update_reg = 0x83, |
| 509 | .update_mask = 0x04, |
| 510 | .update_val_enable = 0x04, |
| 511 | }, |
| 512 | [AB8500_LDO_ANA] = { |
| 513 | .desc = { |
| 514 | .name = "LDO-ANA", |
| 515 | .ops = &ab8500_regulator_fixed_ops, |
| 516 | .type = REGULATOR_VOLTAGE, |
| 517 | .id = AB8500_LDO_ANA, |
| 518 | .owner = THIS_MODULE, |
| 519 | .n_voltages = 1, |
| 520 | }, |
| 521 | .fixed_uV = 1200000, |
| 522 | .update_bank = 0x04, |
| 523 | .update_reg = 0x06, |
| 524 | .update_mask = 0x0c, |
| 525 | .update_val_enable = 0x04, |
| 526 | }, |
| 527 | |
| 528 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 529 | }; |
| 530 | |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 531 | struct ab8500_reg_init { |
| 532 | u8 bank; |
| 533 | u8 addr; |
| 534 | u8 mask; |
| 535 | }; |
| 536 | |
| 537 | #define REG_INIT(_id, _bank, _addr, _mask) \ |
| 538 | [_id] = { \ |
| 539 | .bank = _bank, \ |
| 540 | .addr = _addr, \ |
| 541 | .mask = _mask, \ |
| 542 | } |
| 543 | |
| 544 | static struct ab8500_reg_init ab8500_reg_init[] = { |
| 545 | /* |
| 546 | * 0x30, VanaRequestCtrl |
| 547 | * 0x0C, VpllRequestCtrl |
| 548 | * 0xc0, VextSupply1RequestCtrl |
| 549 | */ |
| 550 | REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xfc), |
| 551 | /* |
| 552 | * 0x03, VextSupply2RequestCtrl |
| 553 | * 0x0c, VextSupply3RequestCtrl |
| 554 | * 0x30, Vaux1RequestCtrl |
| 555 | * 0xc0, Vaux2RequestCtrl |
| 556 | */ |
| 557 | REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff), |
| 558 | /* |
| 559 | * 0x03, Vaux3RequestCtrl |
| 560 | * 0x04, SwHPReq |
| 561 | */ |
| 562 | REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07), |
| 563 | /* |
| 564 | * 0x08, VanaSysClkReq1HPValid |
| 565 | * 0x20, Vaux1SysClkReq1HPValid |
| 566 | * 0x40, Vaux2SysClkReq1HPValid |
| 567 | * 0x80, Vaux3SysClkReq1HPValid |
| 568 | */ |
| 569 | REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xe8), |
| 570 | /* |
| 571 | * 0x10, VextSupply1SysClkReq1HPValid |
| 572 | * 0x20, VextSupply2SysClkReq1HPValid |
| 573 | * 0x40, VextSupply3SysClkReq1HPValid |
| 574 | */ |
| 575 | REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x70), |
| 576 | /* |
| 577 | * 0x08, VanaHwHPReq1Valid |
| 578 | * 0x20, Vaux1HwHPReq1Valid |
| 579 | * 0x40, Vaux2HwHPReq1Valid |
| 580 | * 0x80, Vaux3HwHPReq1Valid |
| 581 | */ |
| 582 | REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xe8), |
| 583 | /* |
| 584 | * 0x01, VextSupply1HwHPReq1Valid |
| 585 | * 0x02, VextSupply2HwHPReq1Valid |
| 586 | * 0x04, VextSupply3HwHPReq1Valid |
| 587 | */ |
| 588 | REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x07), |
| 589 | /* |
| 590 | * 0x08, VanaHwHPReq2Valid |
| 591 | * 0x20, Vaux1HwHPReq2Valid |
| 592 | * 0x40, Vaux2HwHPReq2Valid |
| 593 | * 0x80, Vaux3HwHPReq2Valid |
| 594 | */ |
| 595 | REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xe8), |
| 596 | /* |
| 597 | * 0x01, VextSupply1HwHPReq2Valid |
| 598 | * 0x02, VextSupply2HwHPReq2Valid |
| 599 | * 0x04, VextSupply3HwHPReq2Valid |
| 600 | */ |
| 601 | REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x07), |
| 602 | /* |
| 603 | * 0x20, VanaSwHPReqValid |
| 604 | * 0x80, Vaux1SwHPReqValid |
| 605 | */ |
| 606 | REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xa0), |
| 607 | /* |
| 608 | * 0x01, Vaux2SwHPReqValid |
| 609 | * 0x02, Vaux3SwHPReqValid |
| 610 | * 0x04, VextSupply1SwHPReqValid |
| 611 | * 0x08, VextSupply2SwHPReqValid |
| 612 | * 0x10, VextSupply3SwHPReqValid |
| 613 | */ |
| 614 | REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x1f), |
| 615 | /* |
| 616 | * 0x02, SysClkReq2Valid1 |
| 617 | * ... |
| 618 | * 0x80, SysClkReq8Valid1 |
| 619 | */ |
| 620 | REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe), |
| 621 | /* |
| 622 | * 0x02, SysClkReq2Valid2 |
| 623 | * ... |
| 624 | * 0x80, SysClkReq8Valid2 |
| 625 | */ |
| 626 | REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe), |
| 627 | /* |
| 628 | * 0x02, VTVoutEna |
| 629 | * 0x04, Vintcore12Ena |
| 630 | * 0x38, Vintcore12Sel |
| 631 | * 0x40, Vintcore12LP |
| 632 | * 0x80, VTVoutLP |
| 633 | */ |
| 634 | REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe), |
| 635 | /* |
| 636 | * 0x02, VaudioEna |
| 637 | * 0x04, VdmicEna |
| 638 | * 0x08, Vamic1Ena |
| 639 | * 0x10, Vamic2Ena |
| 640 | */ |
| 641 | REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e), |
| 642 | /* |
| 643 | * 0x01, Vamic1_dzout |
| 644 | * 0x02, Vamic2_dzout |
| 645 | */ |
| 646 | REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03), |
| 647 | /* |
| 648 | * 0x0c, VanaRegu |
| 649 | * 0x03, VpllRegu |
| 650 | */ |
| 651 | REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f), |
| 652 | /* |
| 653 | * 0x01, VrefDDREna |
| 654 | * 0x02, VrefDDRSleepMode |
| 655 | */ |
| 656 | REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03), |
| 657 | /* |
| 658 | * 0x03, VextSupply1Regu |
| 659 | * 0x0c, VextSupply2Regu |
| 660 | * 0x30, VextSupply3Regu |
| 661 | * 0x40, ExtSupply2Bypass |
| 662 | * 0x80, ExtSupply3Bypass |
| 663 | */ |
| 664 | REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff), |
| 665 | /* |
| 666 | * 0x03, Vaux1Regu |
| 667 | * 0x0c, Vaux2Regu |
| 668 | */ |
| 669 | REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f), |
| 670 | /* |
| 671 | * 0x03, Vaux3Regu |
| 672 | */ |
| 673 | REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x03), |
| 674 | /* |
| 675 | * 0x3f, Vsmps1Sel1 |
| 676 | */ |
| 677 | REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f), |
| 678 | /* |
| 679 | * 0x0f, Vaux1Sel |
| 680 | */ |
| 681 | REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f), |
| 682 | /* |
| 683 | * 0x0f, Vaux2Sel |
| 684 | */ |
| 685 | REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f), |
| 686 | /* |
| 687 | * 0x07, Vaux3Sel |
| 688 | */ |
| 689 | REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x07), |
| 690 | /* |
| 691 | * 0x01, VextSupply12LP |
| 692 | */ |
| 693 | REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01), |
| 694 | /* |
| 695 | * 0x04, Vaux1Disch |
| 696 | * 0x08, Vaux2Disch |
| 697 | * 0x10, Vaux3Disch |
| 698 | * 0x20, Vintcore12Disch |
| 699 | * 0x40, VTVoutDisch |
| 700 | * 0x80, VaudioDisch |
| 701 | */ |
| 702 | REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xfc), |
| 703 | /* |
| 704 | * 0x02, VanaDisch |
| 705 | * 0x04, VdmicPullDownEna |
| 706 | * 0x10, VdmicDisch |
| 707 | */ |
| 708 | REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x16), |
| 709 | }; |
| 710 | |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame^] | 711 | static __devinit int |
| 712 | ab8500_regulator_init_registers(struct platform_device *pdev, int id, int value) |
| 713 | { |
| 714 | int err; |
| 715 | |
| 716 | if (value & ~ab8500_reg_init[id].mask) { |
| 717 | dev_err(&pdev->dev, |
| 718 | "Configuration error: value outside mask.\n"); |
| 719 | return -EINVAL; |
| 720 | } |
| 721 | |
| 722 | err = abx500_mask_and_set_register_interruptible( |
| 723 | &pdev->dev, |
| 724 | ab8500_reg_init[id].bank, |
| 725 | ab8500_reg_init[id].addr, |
| 726 | ab8500_reg_init[id].mask, |
| 727 | value); |
| 728 | if (err < 0) { |
| 729 | dev_err(&pdev->dev, |
| 730 | "Failed to initialize 0x%02x, 0x%02x.\n", |
| 731 | ab8500_reg_init[id].bank, |
| 732 | ab8500_reg_init[id].addr); |
| 733 | return err; |
| 734 | } |
| 735 | |
| 736 | dev_vdbg(&pdev->dev, |
| 737 | "init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 738 | ab8500_reg_init[id].bank, |
| 739 | ab8500_reg_init[id].addr, |
| 740 | ab8500_reg_init[id].mask, |
| 741 | value); |
| 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | static __devinit int ab8500_regulator_register(struct platform_device *pdev, |
| 747 | struct regulator_init_data *init_data, |
| 748 | int id, |
| 749 | struct device_node *np) |
| 750 | { |
| 751 | struct ab8500_regulator_info *info = NULL; |
| 752 | struct regulator_config config = { }; |
| 753 | int err; |
| 754 | |
| 755 | /* assign per-regulator data */ |
| 756 | info = &ab8500_regulator_info[id]; |
| 757 | info->dev = &pdev->dev; |
| 758 | |
| 759 | config.dev = &pdev->dev; |
| 760 | config.init_data = init_data; |
| 761 | config.driver_data = info; |
| 762 | config.of_node = np; |
| 763 | |
| 764 | /* fix for hardware before ab8500v2.0 */ |
| 765 | if (abx500_get_chip_id(info->dev) < 0x20) { |
| 766 | if (info->desc.id == AB8500_LDO_AUX3) { |
| 767 | info->desc.n_voltages = |
| 768 | ARRAY_SIZE(ldo_vauxn_voltages); |
| 769 | info->voltages = ldo_vauxn_voltages; |
| 770 | info->voltages_len = |
| 771 | ARRAY_SIZE(ldo_vauxn_voltages); |
| 772 | info->voltage_mask = 0xf; |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | /* register regulator with framework */ |
| 777 | info->regulator = regulator_register(&info->desc, &config); |
| 778 | if (IS_ERR(info->regulator)) { |
| 779 | err = PTR_ERR(info->regulator); |
| 780 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
| 781 | info->desc.name); |
| 782 | /* when we fail, un-register all earlier regulators */ |
| 783 | while (--id >= 0) { |
| 784 | info = &ab8500_regulator_info[id]; |
| 785 | regulator_unregister(info->regulator); |
| 786 | } |
| 787 | return err; |
| 788 | } |
| 789 | |
| 790 | return 0; |
| 791 | } |
| 792 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 793 | static __devinit int ab8500_regulator_probe(struct platform_device *pdev) |
| 794 | { |
| 795 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); |
Dan Carpenter | af54dec | 2010-08-14 11:03:16 +0200 | [diff] [blame] | 796 | struct ab8500_platform_data *pdata; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 797 | int i, err; |
| 798 | |
| 799 | if (!ab8500) { |
| 800 | dev_err(&pdev->dev, "null mfd parent\n"); |
| 801 | return -EINVAL; |
| 802 | } |
Dan Carpenter | af54dec | 2010-08-14 11:03:16 +0200 | [diff] [blame] | 803 | pdata = dev_get_platdata(ab8500->dev); |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 804 | if (!pdata) { |
| 805 | dev_err(&pdev->dev, "null pdata\n"); |
| 806 | return -EINVAL; |
| 807 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 808 | |
Bengt Jonsson | cb189b0 | 2010-12-10 11:08:40 +0100 | [diff] [blame] | 809 | /* make sure the platform data has the correct size */ |
| 810 | if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) { |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 811 | dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); |
Bengt Jonsson | cb189b0 | 2010-12-10 11:08:40 +0100 | [diff] [blame] | 812 | return -EINVAL; |
| 813 | } |
| 814 | |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 815 | /* initialize registers */ |
| 816 | for (i = 0; i < pdata->num_regulator_reg_init; i++) { |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame^] | 817 | int id, value; |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 818 | |
| 819 | id = pdata->regulator_reg_init[i].id; |
| 820 | value = pdata->regulator_reg_init[i].value; |
| 821 | |
| 822 | /* check for configuration errors */ |
| 823 | if (id >= AB8500_NUM_REGULATOR_REGISTERS) { |
| 824 | dev_err(&pdev->dev, |
| 825 | "Configuration error: id outside range.\n"); |
| 826 | return -EINVAL; |
| 827 | } |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 828 | |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame^] | 829 | err = ab8500_regulator_init_registers(pdev, id, value); |
| 830 | if (err < 0) |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 831 | return err; |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 832 | } |
| 833 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 834 | /* register all regulators */ |
| 835 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame^] | 836 | err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL); |
| 837 | if (err < 0) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 838 | return err; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | return 0; |
| 842 | } |
| 843 | |
| 844 | static __devexit int ab8500_regulator_remove(struct platform_device *pdev) |
| 845 | { |
| 846 | int i; |
| 847 | |
| 848 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { |
| 849 | struct ab8500_regulator_info *info = NULL; |
| 850 | info = &ab8500_regulator_info[i]; |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 851 | |
| 852 | dev_vdbg(rdev_get_dev(info->regulator), |
| 853 | "%s-remove\n", info->desc.name); |
| 854 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 855 | regulator_unregister(info->regulator); |
| 856 | } |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | static struct platform_driver ab8500_regulator_driver = { |
| 862 | .probe = ab8500_regulator_probe, |
| 863 | .remove = __devexit_p(ab8500_regulator_remove), |
| 864 | .driver = { |
| 865 | .name = "ab8500-regulator", |
| 866 | .owner = THIS_MODULE, |
| 867 | }, |
| 868 | }; |
| 869 | |
| 870 | static int __init ab8500_regulator_init(void) |
| 871 | { |
| 872 | int ret; |
| 873 | |
| 874 | ret = platform_driver_register(&ab8500_regulator_driver); |
| 875 | if (ret != 0) |
| 876 | pr_err("Failed to register ab8500 regulator: %d\n", ret); |
| 877 | |
| 878 | return ret; |
| 879 | } |
| 880 | subsys_initcall(ab8500_regulator_init); |
| 881 | |
| 882 | static void __exit ab8500_regulator_exit(void) |
| 883 | { |
| 884 | platform_driver_unregister(&ab8500_regulator_driver); |
| 885 | } |
| 886 | module_exit(ab8500_regulator_exit); |
| 887 | |
| 888 | MODULE_LICENSE("GPL v2"); |
| 889 | MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>"); |
| 890 | MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC"); |
| 891 | MODULE_ALIAS("platform:ab8500-regulator"); |