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> |
Lee Jones | 3a8334b | 2012-05-17 14:45:16 +0100 | [diff] [blame] | 21 | #include <linux/of.h> |
| 22 | #include <linux/regulator/of_regulator.h> |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 23 | #include <linux/regulator/driver.h> |
| 24 | #include <linux/regulator/machine.h> |
| 25 | #include <linux/regulator/ab8500.h> |
Lee Jones | 3a8334b | 2012-05-17 14:45:16 +0100 | [diff] [blame] | 26 | #include <linux/slab.h> |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * struct ab8500_regulator_info - ab8500 regulator information |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 30 | * @dev: device pointer |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 31 | * @desc: regulator description |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 32 | * @regulator_dev: regulator device |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 33 | * @is_enabled: status of regulator (on/off) |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 34 | * @load_lp_uA: maximum load in idle (low power) mode |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 35 | * @update_bank: bank to control on/off |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 36 | * @update_reg: register to control on/off |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 37 | * @update_mask: mask to enable/disable and set mode of regulator |
| 38 | * @update_val: bits holding the regulator current mode |
| 39 | * @update_val_idle: bits to enable the regulator in idle (low power) mode |
| 40 | * @update_val_normal: bits to enable the regulator in normal (high power) mode |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 41 | * @voltage_bank: bank to control regulator voltage |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 42 | * @voltage_reg: register to control regulator voltage |
| 43 | * @voltage_mask: mask to control regulator voltage |
Linus Walleij | a0a7014 | 2012-08-20 18:41:35 +0200 | [diff] [blame] | 44 | * @voltage_shift: shift to control regulator voltage |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 45 | * @delay: startup/set voltage delay in us |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 46 | */ |
| 47 | struct ab8500_regulator_info { |
| 48 | struct device *dev; |
| 49 | struct regulator_desc desc; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 50 | struct regulator_dev *regulator; |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 51 | bool is_enabled; |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 52 | int load_lp_uA; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 53 | u8 update_bank; |
| 54 | u8 update_reg; |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 55 | u8 update_mask; |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 56 | u8 update_val; |
| 57 | u8 update_val_idle; |
| 58 | u8 update_val_normal; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 59 | u8 voltage_bank; |
| 60 | u8 voltage_reg; |
| 61 | u8 voltage_mask; |
Linus Walleij | a0a7014 | 2012-08-20 18:41:35 +0200 | [diff] [blame] | 62 | u8 voltage_shift; |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 63 | unsigned int delay; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /* voltage tables for the vauxn/vintcore supplies */ |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 67 | static const unsigned int ldo_vauxn_voltages[] = { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 68 | 1100000, |
| 69 | 1200000, |
| 70 | 1300000, |
| 71 | 1400000, |
| 72 | 1500000, |
| 73 | 1800000, |
| 74 | 1850000, |
| 75 | 1900000, |
| 76 | 2500000, |
| 77 | 2650000, |
| 78 | 2700000, |
| 79 | 2750000, |
| 80 | 2800000, |
| 81 | 2900000, |
| 82 | 3000000, |
| 83 | 3300000, |
| 84 | }; |
| 85 | |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 86 | static const unsigned int ldo_vaux3_voltages[] = { |
Bengt Jonsson | 2b75151 | 2010-12-10 11:08:43 +0100 | [diff] [blame] | 87 | 1200000, |
| 88 | 1500000, |
| 89 | 1800000, |
| 90 | 2100000, |
| 91 | 2500000, |
| 92 | 2750000, |
| 93 | 2790000, |
| 94 | 2910000, |
| 95 | }; |
| 96 | |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 97 | static const unsigned int ldo_vintcore_voltages[] = { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 98 | 1200000, |
| 99 | 1225000, |
| 100 | 1250000, |
| 101 | 1275000, |
| 102 | 1300000, |
| 103 | 1325000, |
| 104 | 1350000, |
| 105 | }; |
| 106 | |
| 107 | static int ab8500_regulator_enable(struct regulator_dev *rdev) |
| 108 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 109 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 110 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 111 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 112 | if (info == NULL) { |
| 113 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 114 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 115 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 116 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 117 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 118 | info->update_bank, info->update_reg, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 119 | info->update_mask, info->update_val); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 120 | if (ret < 0) |
| 121 | dev_err(rdev_get_dev(rdev), |
| 122 | "couldn't set enable bits for regulator\n"); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 123 | |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 124 | info->is_enabled = true; |
| 125 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 126 | dev_vdbg(rdev_get_dev(rdev), |
| 127 | "%s-enable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n", |
| 128 | info->desc.name, info->update_bank, info->update_reg, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 129 | info->update_mask, info->update_val); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 130 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | static int ab8500_regulator_disable(struct regulator_dev *rdev) |
| 135 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 136 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 137 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 138 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 139 | if (info == NULL) { |
| 140 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 141 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 142 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 143 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 144 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 145 | info->update_bank, info->update_reg, |
| 146 | info->update_mask, 0x0); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 147 | if (ret < 0) |
| 148 | dev_err(rdev_get_dev(rdev), |
| 149 | "couldn't set disable bits for regulator\n"); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 150 | |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 151 | info->is_enabled = false; |
| 152 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 153 | dev_vdbg(rdev_get_dev(rdev), |
| 154 | "%s-disable (bank, reg, mask, value): 0x%x, 0x%x, 0x%x, 0x%x\n", |
| 155 | info->desc.name, info->update_bank, info->update_reg, |
| 156 | info->update_mask, 0x0); |
| 157 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 158 | return ret; |
| 159 | } |
| 160 | |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 161 | static unsigned int ab8500_regulator_get_optimum_mode( |
| 162 | struct regulator_dev *rdev, int input_uV, |
| 163 | int output_uV, int load_uA) |
| 164 | { |
| 165 | unsigned int mode; |
| 166 | |
| 167 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 168 | |
| 169 | if (info == NULL) { |
| 170 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 171 | return -EINVAL; |
| 172 | } |
| 173 | |
| 174 | if (load_uA <= info->load_lp_uA) |
| 175 | mode = REGULATOR_MODE_IDLE; |
| 176 | else |
| 177 | mode = REGULATOR_MODE_NORMAL; |
| 178 | |
| 179 | return mode; |
| 180 | } |
| 181 | |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 182 | static int ab8500_regulator_set_mode(struct regulator_dev *rdev, |
| 183 | unsigned int mode) |
| 184 | { |
| 185 | int ret = 0; |
| 186 | |
| 187 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 188 | |
| 189 | if (info == NULL) { |
| 190 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | switch (mode) { |
| 195 | case REGULATOR_MODE_NORMAL: |
| 196 | info->update_val = info->update_val_normal; |
| 197 | break; |
| 198 | case REGULATOR_MODE_IDLE: |
| 199 | info->update_val = info->update_val_idle; |
| 200 | break; |
| 201 | default: |
| 202 | return -EINVAL; |
| 203 | } |
| 204 | |
| 205 | if (info->is_enabled) { |
| 206 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
| 207 | info->update_bank, info->update_reg, |
| 208 | info->update_mask, info->update_val); |
| 209 | if (ret < 0) |
| 210 | dev_err(rdev_get_dev(rdev), |
| 211 | "couldn't set regulator mode\n"); |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 212 | |
| 213 | dev_vdbg(rdev_get_dev(rdev), |
| 214 | "%s-set_mode (bank, reg, mask, value): " |
| 215 | "0x%x, 0x%x, 0x%x, 0x%x\n", |
| 216 | info->desc.name, info->update_bank, info->update_reg, |
| 217 | info->update_mask, info->update_val); |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | return ret; |
| 221 | } |
| 222 | |
| 223 | static unsigned int ab8500_regulator_get_mode(struct regulator_dev *rdev) |
| 224 | { |
| 225 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
| 226 | int ret; |
| 227 | |
| 228 | if (info == NULL) { |
| 229 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 230 | return -EINVAL; |
| 231 | } |
| 232 | |
| 233 | if (info->update_val == info->update_val_normal) |
| 234 | ret = REGULATOR_MODE_NORMAL; |
| 235 | else if (info->update_val == info->update_val_idle) |
| 236 | ret = REGULATOR_MODE_IDLE; |
| 237 | else |
| 238 | ret = -EINVAL; |
| 239 | |
| 240 | return ret; |
| 241 | } |
| 242 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 243 | static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) |
| 244 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 245 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 246 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 247 | u8 regval; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 248 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 249 | if (info == NULL) { |
| 250 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 251 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 252 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 253 | |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 254 | ret = abx500_get_register_interruptible(info->dev, |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 255 | info->update_bank, info->update_reg, ®val); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 256 | if (ret < 0) { |
| 257 | dev_err(rdev_get_dev(rdev), |
| 258 | "couldn't read 0x%x register\n", info->update_reg); |
| 259 | return ret; |
| 260 | } |
| 261 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 262 | dev_vdbg(rdev_get_dev(rdev), |
| 263 | "%s-is_enabled (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," |
| 264 | " 0x%x\n", |
| 265 | info->desc.name, info->update_bank, info->update_reg, |
| 266 | info->update_mask, regval); |
| 267 | |
| 268 | if (regval & info->update_mask) |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 269 | info->is_enabled = true; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 270 | else |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 271 | info->is_enabled = false; |
| 272 | |
| 273 | return info->is_enabled; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 274 | } |
| 275 | |
Axel Lin | 3bf6e90 | 2012-02-24 17:15:45 +0800 | [diff] [blame] | 276 | static int ab8500_regulator_get_voltage_sel(struct regulator_dev *rdev) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 277 | { |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 278 | int ret, val; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 279 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 280 | u8 regval; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 281 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 282 | if (info == NULL) { |
| 283 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 284 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 285 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 286 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 287 | ret = abx500_get_register_interruptible(info->dev, |
| 288 | info->voltage_bank, info->voltage_reg, ®val); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 289 | if (ret < 0) { |
| 290 | dev_err(rdev_get_dev(rdev), |
| 291 | "couldn't read voltage reg for regulator\n"); |
| 292 | return ret; |
| 293 | } |
| 294 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 295 | dev_vdbg(rdev_get_dev(rdev), |
Linus Walleij | a0a7014 | 2012-08-20 18:41:35 +0200 | [diff] [blame] | 296 | "%s-get_voltage (bank, reg, mask, shift, value): " |
| 297 | "0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", |
| 298 | info->desc.name, info->voltage_bank, |
| 299 | info->voltage_reg, info->voltage_mask, |
| 300 | info->voltage_shift, regval); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 301 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 302 | val = regval & info->voltage_mask; |
Linus Walleij | a0a7014 | 2012-08-20 18:41:35 +0200 | [diff] [blame] | 303 | return val >> info->voltage_shift; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 304 | } |
| 305 | |
Axel Lin | ae713d3 | 2012-03-20 09:51:08 +0800 | [diff] [blame] | 306 | static int ab8500_regulator_set_voltage_sel(struct regulator_dev *rdev, |
| 307 | unsigned selector) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 308 | { |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 309 | int ret; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 310 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 311 | u8 regval; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 312 | |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 313 | if (info == NULL) { |
| 314 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 315 | return -EINVAL; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 316 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 317 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 318 | /* set the registers for the request */ |
Linus Walleij | a0a7014 | 2012-08-20 18:41:35 +0200 | [diff] [blame] | 319 | regval = (u8)selector << info->voltage_shift; |
Mattias Wallin | 47c1697 | 2010-09-10 17:47:56 +0200 | [diff] [blame] | 320 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 321 | info->voltage_bank, info->voltage_reg, |
| 322 | info->voltage_mask, regval); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 323 | if (ret < 0) |
| 324 | dev_err(rdev_get_dev(rdev), |
| 325 | "couldn't set voltage reg for regulator\n"); |
| 326 | |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 327 | dev_vdbg(rdev_get_dev(rdev), |
| 328 | "%s-set_voltage (bank, reg, mask, value): 0x%x, 0x%x, 0x%x," |
| 329 | " 0x%x\n", |
| 330 | info->desc.name, info->voltage_bank, info->voltage_reg, |
| 331 | info->voltage_mask, regval); |
| 332 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 333 | return ret; |
| 334 | } |
| 335 | |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 336 | static int ab8500_regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 337 | unsigned int old_sel, |
| 338 | unsigned int new_sel) |
| 339 | { |
| 340 | struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 341 | |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 342 | return info->delay; |
| 343 | } |
| 344 | |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 345 | static struct regulator_ops ab8500_regulator_volt_mode_ops = { |
| 346 | .enable = ab8500_regulator_enable, |
| 347 | .disable = ab8500_regulator_disable, |
| 348 | .is_enabled = ab8500_regulator_is_enabled, |
| 349 | .get_optimum_mode = ab8500_regulator_get_optimum_mode, |
| 350 | .set_mode = ab8500_regulator_set_mode, |
| 351 | .get_mode = ab8500_regulator_get_mode, |
| 352 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, |
| 353 | .set_voltage_sel = ab8500_regulator_set_voltage_sel, |
| 354 | .list_voltage = regulator_list_voltage_table, |
| 355 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 356 | }; |
| 357 | |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 358 | static struct regulator_ops ab8500_regulator_mode_ops = { |
| 359 | .enable = ab8500_regulator_enable, |
| 360 | .disable = ab8500_regulator_disable, |
| 361 | .is_enabled = ab8500_regulator_is_enabled, |
| 362 | .get_optimum_mode = ab8500_regulator_get_optimum_mode, |
| 363 | .set_mode = ab8500_regulator_set_mode, |
| 364 | .get_mode = ab8500_regulator_get_mode, |
| 365 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, |
| 366 | .list_voltage = regulator_list_voltage_table, |
| 367 | .set_voltage_time_sel = ab8500_regulator_set_voltage_time_sel, |
| 368 | }; |
| 369 | |
| 370 | static struct regulator_ops ab8500_regulator_ops = { |
| 371 | .enable = ab8500_regulator_enable, |
| 372 | .disable = ab8500_regulator_disable, |
| 373 | .is_enabled = ab8500_regulator_is_enabled, |
| 374 | .get_voltage_sel = ab8500_regulator_get_voltage_sel, |
| 375 | .list_voltage = regulator_list_voltage_table, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 376 | }; |
| 377 | |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 378 | static struct ab8500_regulator_info |
| 379 | ab8500_regulator_info[AB8500_NUM_REGULATORS] = { |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 380 | /* |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 381 | * Variable Voltage Regulators |
| 382 | * name, min mV, max mV, |
| 383 | * update bank, reg, mask, enable val |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 384 | * volt bank, reg, mask |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 385 | */ |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 386 | [AB8500_LDO_AUX1] = { |
| 387 | .desc = { |
| 388 | .name = "LDO-AUX1", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 389 | .ops = &ab8500_regulator_volt_mode_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 390 | .type = REGULATOR_VOLTAGE, |
| 391 | .id = AB8500_LDO_AUX1, |
| 392 | .owner = THIS_MODULE, |
| 393 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 394 | .volt_table = ldo_vauxn_voltages, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 395 | }, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 396 | .load_lp_uA = 5000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 397 | .update_bank = 0x04, |
| 398 | .update_reg = 0x09, |
| 399 | .update_mask = 0x03, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 400 | .update_val = 0x01, |
| 401 | .update_val_idle = 0x03, |
| 402 | .update_val_normal = 0x01, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 403 | .voltage_bank = 0x04, |
| 404 | .voltage_reg = 0x1f, |
| 405 | .voltage_mask = 0x0f, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 406 | }, |
| 407 | [AB8500_LDO_AUX2] = { |
| 408 | .desc = { |
| 409 | .name = "LDO-AUX2", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 410 | .ops = &ab8500_regulator_volt_mode_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 411 | .type = REGULATOR_VOLTAGE, |
| 412 | .id = AB8500_LDO_AUX2, |
| 413 | .owner = THIS_MODULE, |
| 414 | .n_voltages = ARRAY_SIZE(ldo_vauxn_voltages), |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 415 | .volt_table = ldo_vauxn_voltages, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 416 | }, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 417 | .load_lp_uA = 5000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 418 | .update_bank = 0x04, |
| 419 | .update_reg = 0x09, |
| 420 | .update_mask = 0x0c, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 421 | .update_val = 0x04, |
| 422 | .update_val_idle = 0x0c, |
| 423 | .update_val_normal = 0x04, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 424 | .voltage_bank = 0x04, |
| 425 | .voltage_reg = 0x20, |
| 426 | .voltage_mask = 0x0f, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 427 | }, |
| 428 | [AB8500_LDO_AUX3] = { |
| 429 | .desc = { |
| 430 | .name = "LDO-AUX3", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 431 | .ops = &ab8500_regulator_volt_mode_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 432 | .type = REGULATOR_VOLTAGE, |
| 433 | .id = AB8500_LDO_AUX3, |
| 434 | .owner = THIS_MODULE, |
| 435 | .n_voltages = ARRAY_SIZE(ldo_vaux3_voltages), |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 436 | .volt_table = ldo_vaux3_voltages, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 437 | }, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 438 | .load_lp_uA = 5000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 439 | .update_bank = 0x04, |
| 440 | .update_reg = 0x0a, |
| 441 | .update_mask = 0x03, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 442 | .update_val = 0x01, |
| 443 | .update_val_idle = 0x03, |
| 444 | .update_val_normal = 0x01, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 445 | .voltage_bank = 0x04, |
| 446 | .voltage_reg = 0x21, |
| 447 | .voltage_mask = 0x07, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 448 | }, |
| 449 | [AB8500_LDO_INTCORE] = { |
| 450 | .desc = { |
| 451 | .name = "LDO-INTCORE", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 452 | .ops = &ab8500_regulator_volt_mode_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 453 | .type = REGULATOR_VOLTAGE, |
| 454 | .id = AB8500_LDO_INTCORE, |
| 455 | .owner = THIS_MODULE, |
| 456 | .n_voltages = ARRAY_SIZE(ldo_vintcore_voltages), |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 457 | .volt_table = ldo_vintcore_voltages, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 458 | }, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 459 | .load_lp_uA = 5000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 460 | .update_bank = 0x03, |
| 461 | .update_reg = 0x80, |
| 462 | .update_mask = 0x44, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 463 | .update_val = 0x04, |
| 464 | .update_val_idle = 0x44, |
| 465 | .update_val_normal = 0x04, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 466 | .voltage_bank = 0x03, |
| 467 | .voltage_reg = 0x80, |
| 468 | .voltage_mask = 0x38, |
Linus Walleij | a0a7014 | 2012-08-20 18:41:35 +0200 | [diff] [blame] | 469 | .voltage_shift = 3, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 470 | }, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 471 | |
| 472 | /* |
Bengt Jonsson | e1159e6 | 2010-12-10 11:08:44 +0100 | [diff] [blame] | 473 | * Fixed Voltage Regulators |
| 474 | * name, fixed mV, |
| 475 | * update bank, reg, mask, enable val |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 476 | */ |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 477 | [AB8500_LDO_TVOUT] = { |
| 478 | .desc = { |
| 479 | .name = "LDO-TVOUT", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 480 | .ops = &ab8500_regulator_mode_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 481 | .type = REGULATOR_VOLTAGE, |
| 482 | .id = AB8500_LDO_TVOUT, |
| 483 | .owner = THIS_MODULE, |
| 484 | .n_voltages = 1, |
Axel Lin | 7142e21 | 2012-06-08 10:27:49 +0800 | [diff] [blame] | 485 | .min_uV = 2000000, |
Axel Lin | 7fee2af | 2012-08-07 22:21:23 +0800 | [diff] [blame] | 486 | .enable_time = 10000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 487 | }, |
Linus Walleij | 42ab616 | 2011-03-17 13:25:02 +0100 | [diff] [blame] | 488 | .delay = 10000, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 489 | .load_lp_uA = 1000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 490 | .update_bank = 0x03, |
| 491 | .update_reg = 0x80, |
| 492 | .update_mask = 0x82, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 493 | .update_val = 0x02, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 494 | .update_val_idle = 0x82, |
| 495 | .update_val_normal = 0x02, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 496 | }, |
Bengt Jonsson | ea05ef3 | 2011-03-10 14:43:31 +0100 | [diff] [blame] | 497 | [AB8500_LDO_USB] = { |
| 498 | .desc = { |
| 499 | .name = "LDO-USB", |
| 500 | .ops = &ab8500_regulator_fixed_ops, |
| 501 | .type = REGULATOR_VOLTAGE, |
| 502 | .id = AB8500_LDO_USB, |
| 503 | .owner = THIS_MODULE, |
| 504 | .n_voltages = 1, |
Axel Lin | 7142e21 | 2012-06-08 10:27:49 +0800 | [diff] [blame] | 505 | .min_uV = 3300000, |
Bengt Jonsson | ea05ef3 | 2011-03-10 14:43:31 +0100 | [diff] [blame] | 506 | }, |
Bengt Jonsson | ea05ef3 | 2011-03-10 14:43:31 +0100 | [diff] [blame] | 507 | .update_bank = 0x03, |
| 508 | .update_reg = 0x82, |
| 509 | .update_mask = 0x03, |
Bengt Jonsson | ea05ef3 | 2011-03-10 14:43:31 +0100 | [diff] [blame] | 510 | }, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 511 | |
| 512 | /* |
| 513 | * Regulators with fixed voltage and normal mode |
| 514 | */ |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 515 | [AB8500_LDO_AUDIO] = { |
| 516 | .desc = { |
| 517 | .name = "LDO-AUDIO", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 518 | .ops = &ab8500_regulator_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 519 | .type = REGULATOR_VOLTAGE, |
| 520 | .id = AB8500_LDO_AUDIO, |
| 521 | .owner = THIS_MODULE, |
| 522 | .n_voltages = 1, |
Axel Lin | 7142e21 | 2012-06-08 10:27:49 +0800 | [diff] [blame] | 523 | .min_uV = 2000000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 524 | }, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 525 | .update_bank = 0x03, |
| 526 | .update_reg = 0x83, |
| 527 | .update_mask = 0x02, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 528 | .update_val = 0x02, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 529 | }, |
| 530 | [AB8500_LDO_ANAMIC1] = { |
| 531 | .desc = { |
| 532 | .name = "LDO-ANAMIC1", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 533 | .ops = &ab8500_regulator_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 534 | .type = REGULATOR_VOLTAGE, |
| 535 | .id = AB8500_LDO_ANAMIC1, |
| 536 | .owner = THIS_MODULE, |
| 537 | .n_voltages = 1, |
Axel Lin | 7142e21 | 2012-06-08 10:27:49 +0800 | [diff] [blame] | 538 | .min_uV = 2050000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 539 | }, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 540 | .update_bank = 0x03, |
| 541 | .update_reg = 0x83, |
| 542 | .update_mask = 0x08, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 543 | .update_val = 0x08, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 544 | }, |
| 545 | [AB8500_LDO_ANAMIC2] = { |
| 546 | .desc = { |
| 547 | .name = "LDO-ANAMIC2", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 548 | .ops = &ab8500_regulator_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 549 | .type = REGULATOR_VOLTAGE, |
| 550 | .id = AB8500_LDO_ANAMIC2, |
| 551 | .owner = THIS_MODULE, |
| 552 | .n_voltages = 1, |
Axel Lin | 7142e21 | 2012-06-08 10:27:49 +0800 | [diff] [blame] | 553 | .min_uV = 2050000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 554 | }, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 555 | .update_bank = 0x03, |
| 556 | .update_reg = 0x83, |
| 557 | .update_mask = 0x10, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 558 | .update_val = 0x10, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 559 | }, |
| 560 | [AB8500_LDO_DMIC] = { |
| 561 | .desc = { |
| 562 | .name = "LDO-DMIC", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 563 | .ops = &ab8500_regulator_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 564 | .type = REGULATOR_VOLTAGE, |
| 565 | .id = AB8500_LDO_DMIC, |
| 566 | .owner = THIS_MODULE, |
| 567 | .n_voltages = 1, |
Axel Lin | 7142e21 | 2012-06-08 10:27:49 +0800 | [diff] [blame] | 568 | .min_uV = 1800000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 569 | }, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 570 | .update_bank = 0x03, |
| 571 | .update_reg = 0x83, |
| 572 | .update_mask = 0x04, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 573 | .update_val = 0x04, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 574 | }, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 575 | |
| 576 | /* |
| 577 | * Regulators with fixed voltage and normal/idle modes |
| 578 | */ |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 579 | [AB8500_LDO_ANA] = { |
| 580 | .desc = { |
| 581 | .name = "LDO-ANA", |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 582 | .ops = &ab8500_regulator_mode_ops, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 583 | .type = REGULATOR_VOLTAGE, |
| 584 | .id = AB8500_LDO_ANA, |
| 585 | .owner = THIS_MODULE, |
| 586 | .n_voltages = 1, |
Axel Lin | 7142e21 | 2012-06-08 10:27:49 +0800 | [diff] [blame] | 587 | .min_uV = 1200000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 588 | }, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 589 | .load_lp_uA = 1000, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 590 | .update_bank = 0x04, |
| 591 | .update_reg = 0x06, |
| 592 | .update_mask = 0x0c, |
Emeric Vigier | bd28a15 | 2013-03-21 15:58:59 +0000 | [diff] [blame] | 593 | .update_val = 0x04, |
Bengt Jonsson | 7ce4669 | 2013-03-21 15:59:00 +0000 | [diff] [blame] | 594 | .update_val_idle = 0x0c, |
| 595 | .update_val_normal = 0x04, |
Bengt Jonsson | 6909b45 | 2010-12-10 11:08:47 +0100 | [diff] [blame] | 596 | }, |
| 597 | |
| 598 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 599 | }; |
| 600 | |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 601 | struct ab8500_reg_init { |
| 602 | u8 bank; |
| 603 | u8 addr; |
| 604 | u8 mask; |
| 605 | }; |
| 606 | |
| 607 | #define REG_INIT(_id, _bank, _addr, _mask) \ |
| 608 | [_id] = { \ |
| 609 | .bank = _bank, \ |
| 610 | .addr = _addr, \ |
| 611 | .mask = _mask, \ |
| 612 | } |
| 613 | |
| 614 | static struct ab8500_reg_init ab8500_reg_init[] = { |
| 615 | /* |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 616 | * 0x03, VarmRequestCtrl |
| 617 | * 0x0c, VapeRequestCtrl |
| 618 | * 0x30, Vsmps1RequestCtrl |
| 619 | * 0xc0, Vsmps2RequestCtrl |
| 620 | */ |
| 621 | REG_INIT(AB8500_REGUREQUESTCTRL1, 0x03, 0x03, 0xff), |
| 622 | /* |
| 623 | * 0x03, Vsmps3RequestCtrl |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 624 | * 0x0c, VpllRequestCtrl |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 625 | * 0x30, VanaRequestCtrl |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 626 | * 0xc0, VextSupply1RequestCtrl |
| 627 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 628 | REG_INIT(AB8500_REGUREQUESTCTRL2, 0x03, 0x04, 0xff), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 629 | /* |
| 630 | * 0x03, VextSupply2RequestCtrl |
| 631 | * 0x0c, VextSupply3RequestCtrl |
| 632 | * 0x30, Vaux1RequestCtrl |
| 633 | * 0xc0, Vaux2RequestCtrl |
| 634 | */ |
| 635 | REG_INIT(AB8500_REGUREQUESTCTRL3, 0x03, 0x05, 0xff), |
| 636 | /* |
| 637 | * 0x03, Vaux3RequestCtrl |
| 638 | * 0x04, SwHPReq |
| 639 | */ |
| 640 | REG_INIT(AB8500_REGUREQUESTCTRL4, 0x03, 0x06, 0x07), |
| 641 | /* |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 642 | * 0x01, Vsmps1SysClkReq1HPValid |
| 643 | * 0x02, Vsmps2SysClkReq1HPValid |
| 644 | * 0x04, Vsmps3SysClkReq1HPValid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 645 | * 0x08, VanaSysClkReq1HPValid |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 646 | * 0x10, VpllSysClkReq1HPValid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 647 | * 0x20, Vaux1SysClkReq1HPValid |
| 648 | * 0x40, Vaux2SysClkReq1HPValid |
| 649 | * 0x80, Vaux3SysClkReq1HPValid |
| 650 | */ |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 651 | REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID1, 0x03, 0x07, 0xff), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 652 | /* |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 653 | * 0x01, VapeSysClkReq1HPValid |
| 654 | * 0x02, VarmSysClkReq1HPValid |
| 655 | * 0x04, VbbSysClkReq1HPValid |
| 656 | * 0x08, VmodSysClkReq1HPValid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 657 | * 0x10, VextSupply1SysClkReq1HPValid |
| 658 | * 0x20, VextSupply2SysClkReq1HPValid |
| 659 | * 0x40, VextSupply3SysClkReq1HPValid |
| 660 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 661 | REG_INIT(AB8500_REGUSYSCLKREQ1HPVALID2, 0x03, 0x08, 0x7f), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 662 | /* |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 663 | * 0x01, Vsmps1HwHPReq1Valid |
| 664 | * 0x02, Vsmps2HwHPReq1Valid |
| 665 | * 0x04, Vsmps3HwHPReq1Valid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 666 | * 0x08, VanaHwHPReq1Valid |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 667 | * 0x10, VpllHwHPReq1Valid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 668 | * 0x20, Vaux1HwHPReq1Valid |
| 669 | * 0x40, Vaux2HwHPReq1Valid |
| 670 | * 0x80, Vaux3HwHPReq1Valid |
| 671 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 672 | REG_INIT(AB8500_REGUHWHPREQ1VALID1, 0x03, 0x09, 0xff), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 673 | /* |
| 674 | * 0x01, VextSupply1HwHPReq1Valid |
| 675 | * 0x02, VextSupply2HwHPReq1Valid |
| 676 | * 0x04, VextSupply3HwHPReq1Valid |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 677 | * 0x08, VmodHwHPReq1Valid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 678 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 679 | REG_INIT(AB8500_REGUHWHPREQ1VALID2, 0x03, 0x0a, 0x0f), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 680 | /* |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 681 | * 0x01, Vsmps1HwHPReq2Valid |
| 682 | * 0x02, Vsmps2HwHPReq2Valid |
| 683 | * 0x03, Vsmps3HwHPReq2Valid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 684 | * 0x08, VanaHwHPReq2Valid |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 685 | * 0x10, VpllHwHPReq2Valid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 686 | * 0x20, Vaux1HwHPReq2Valid |
| 687 | * 0x40, Vaux2HwHPReq2Valid |
| 688 | * 0x80, Vaux3HwHPReq2Valid |
| 689 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 690 | REG_INIT(AB8500_REGUHWHPREQ2VALID1, 0x03, 0x0b, 0xff), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 691 | /* |
| 692 | * 0x01, VextSupply1HwHPReq2Valid |
| 693 | * 0x02, VextSupply2HwHPReq2Valid |
| 694 | * 0x04, VextSupply3HwHPReq2Valid |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 695 | * 0x08, VmodHwHPReq2Valid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 696 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 697 | REG_INIT(AB8500_REGUHWHPREQ2VALID2, 0x03, 0x0c, 0x0f), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 698 | /* |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 699 | * 0x01, VapeSwHPReqValid |
| 700 | * 0x02, VarmSwHPReqValid |
| 701 | * 0x04, Vsmps1SwHPReqValid |
| 702 | * 0x08, Vsmps2SwHPReqValid |
| 703 | * 0x10, Vsmps3SwHPReqValid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 704 | * 0x20, VanaSwHPReqValid |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 705 | * 0x40, VpllSwHPReqValid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 706 | * 0x80, Vaux1SwHPReqValid |
| 707 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 708 | REG_INIT(AB8500_REGUSWHPREQVALID1, 0x03, 0x0d, 0xff), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 709 | /* |
| 710 | * 0x01, Vaux2SwHPReqValid |
| 711 | * 0x02, Vaux3SwHPReqValid |
| 712 | * 0x04, VextSupply1SwHPReqValid |
| 713 | * 0x08, VextSupply2SwHPReqValid |
| 714 | * 0x10, VextSupply3SwHPReqValid |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 715 | * 0x20, VmodSwHPReqValid |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 716 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 717 | REG_INIT(AB8500_REGUSWHPREQVALID2, 0x03, 0x0e, 0x3f), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 718 | /* |
| 719 | * 0x02, SysClkReq2Valid1 |
| 720 | * ... |
| 721 | * 0x80, SysClkReq8Valid1 |
| 722 | */ |
| 723 | REG_INIT(AB8500_REGUSYSCLKREQVALID1, 0x03, 0x0f, 0xfe), |
| 724 | /* |
| 725 | * 0x02, SysClkReq2Valid2 |
| 726 | * ... |
| 727 | * 0x80, SysClkReq8Valid2 |
| 728 | */ |
| 729 | REG_INIT(AB8500_REGUSYSCLKREQVALID2, 0x03, 0x10, 0xfe), |
| 730 | /* |
| 731 | * 0x02, VTVoutEna |
| 732 | * 0x04, Vintcore12Ena |
| 733 | * 0x38, Vintcore12Sel |
| 734 | * 0x40, Vintcore12LP |
| 735 | * 0x80, VTVoutLP |
| 736 | */ |
| 737 | REG_INIT(AB8500_REGUMISC1, 0x03, 0x80, 0xfe), |
| 738 | /* |
| 739 | * 0x02, VaudioEna |
| 740 | * 0x04, VdmicEna |
| 741 | * 0x08, Vamic1Ena |
| 742 | * 0x10, Vamic2Ena |
| 743 | */ |
| 744 | REG_INIT(AB8500_VAUDIOSUPPLY, 0x03, 0x83, 0x1e), |
| 745 | /* |
| 746 | * 0x01, Vamic1_dzout |
| 747 | * 0x02, Vamic2_dzout |
| 748 | */ |
| 749 | REG_INIT(AB8500_REGUCTRL1VAMIC, 0x03, 0x84, 0x03), |
| 750 | /* |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 751 | * 0x03, Vsmps1Regu |
| 752 | * 0x0c, Vsmps1SelCtrl |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 753 | * 0x10, Vsmps1AutoMode |
| 754 | * 0x20, Vsmps1PWMMode |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 755 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 756 | REG_INIT(AB8500_VSMPS1REGU, 0x04, 0x03, 0x3f), |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 757 | /* |
| 758 | * 0x03, Vsmps2Regu |
| 759 | * 0x0c, Vsmps2SelCtrl |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 760 | * 0x10, Vsmps2AutoMode |
| 761 | * 0x20, Vsmps2PWMMode |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 762 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 763 | REG_INIT(AB8500_VSMPS2REGU, 0x04, 0x04, 0x3f), |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 764 | /* |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 765 | * 0x03, VpllRegu |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 766 | * 0x0c, VanaRegu |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 767 | */ |
| 768 | REG_INIT(AB8500_VPLLVANAREGU, 0x04, 0x06, 0x0f), |
| 769 | /* |
| 770 | * 0x01, VrefDDREna |
| 771 | * 0x02, VrefDDRSleepMode |
| 772 | */ |
| 773 | REG_INIT(AB8500_VREFDDR, 0x04, 0x07, 0x03), |
| 774 | /* |
| 775 | * 0x03, VextSupply1Regu |
| 776 | * 0x0c, VextSupply2Regu |
| 777 | * 0x30, VextSupply3Regu |
| 778 | * 0x40, ExtSupply2Bypass |
| 779 | * 0x80, ExtSupply3Bypass |
| 780 | */ |
| 781 | REG_INIT(AB8500_EXTSUPPLYREGU, 0x04, 0x08, 0xff), |
| 782 | /* |
| 783 | * 0x03, Vaux1Regu |
| 784 | * 0x0c, Vaux2Regu |
| 785 | */ |
| 786 | REG_INIT(AB8500_VAUX12REGU, 0x04, 0x09, 0x0f), |
| 787 | /* |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 788 | * 0x0c, Vrf1Regu |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 789 | * 0x03, Vaux3Regu |
| 790 | */ |
Lee Jones | d79df32 | 2013-03-21 15:58:58 +0000 | [diff] [blame] | 791 | REG_INIT(AB8500_VRF1VAUX3REGU, 0x04, 0x0a, 0x0f), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 792 | /* |
| 793 | * 0x3f, Vsmps1Sel1 |
| 794 | */ |
| 795 | REG_INIT(AB8500_VSMPS1SEL1, 0x04, 0x13, 0x3f), |
| 796 | /* |
| 797 | * 0x0f, Vaux1Sel |
| 798 | */ |
| 799 | REG_INIT(AB8500_VAUX1SEL, 0x04, 0x1f, 0x0f), |
| 800 | /* |
| 801 | * 0x0f, Vaux2Sel |
| 802 | */ |
| 803 | REG_INIT(AB8500_VAUX2SEL, 0x04, 0x20, 0x0f), |
| 804 | /* |
| 805 | * 0x07, Vaux3Sel |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 806 | * 0x30, Vrf1Sel |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 807 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 808 | REG_INIT(AB8500_VRF1VAUX3SEL, 0x04, 0x21, 0x37), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 809 | /* |
| 810 | * 0x01, VextSupply12LP |
| 811 | */ |
| 812 | REG_INIT(AB8500_REGUCTRL2SPARE, 0x04, 0x22, 0x01), |
| 813 | /* |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 814 | * 0x01, VpllDisch |
| 815 | * 0x02, Vrf1Disch |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 816 | * 0x04, Vaux1Disch |
| 817 | * 0x08, Vaux2Disch |
| 818 | * 0x10, Vaux3Disch |
| 819 | * 0x20, Vintcore12Disch |
| 820 | * 0x40, VTVoutDisch |
| 821 | * 0x80, VaudioDisch |
| 822 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 823 | REG_INIT(AB8500_REGUCTRLDISCH, 0x04, 0x43, 0xff), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 824 | /* |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 825 | * 0x01, VsimDisch |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 826 | * 0x02, VanaDisch |
| 827 | * 0x04, VdmicPullDownEna |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 828 | * 0x08, VpllPullDownEna |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 829 | * 0x10, VdmicDisch |
| 830 | */ |
Lee Jones | 33bc8f4 | 2013-03-21 15:59:02 +0000 | [diff] [blame] | 831 | REG_INIT(AB8500_REGUCTRLDISCH2, 0x04, 0x44, 0x1f), |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 832 | }; |
| 833 | |
Lee Jones | 3c1b843 | 2013-03-21 15:59:01 +0000 | [diff] [blame] | 834 | static int ab8500_regulator_init_registers(struct platform_device *pdev, |
| 835 | int id, int mask, int value) |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 836 | { |
| 837 | int err; |
| 838 | |
Lee Jones | 3c1b843 | 2013-03-21 15:59:01 +0000 | [diff] [blame] | 839 | BUG_ON(value & ~mask); |
| 840 | BUG_ON(mask & ~ab8500_reg_init[id].mask); |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 841 | |
Lee Jones | 3c1b843 | 2013-03-21 15:59:01 +0000 | [diff] [blame] | 842 | /* initialize register */ |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 843 | err = abx500_mask_and_set_register_interruptible( |
| 844 | &pdev->dev, |
| 845 | ab8500_reg_init[id].bank, |
| 846 | ab8500_reg_init[id].addr, |
Lee Jones | 3c1b843 | 2013-03-21 15:59:01 +0000 | [diff] [blame] | 847 | mask, value); |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 848 | if (err < 0) { |
| 849 | dev_err(&pdev->dev, |
| 850 | "Failed to initialize 0x%02x, 0x%02x.\n", |
| 851 | ab8500_reg_init[id].bank, |
| 852 | ab8500_reg_init[id].addr); |
| 853 | return err; |
| 854 | } |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 855 | dev_vdbg(&pdev->dev, |
Lee Jones | 3c1b843 | 2013-03-21 15:59:01 +0000 | [diff] [blame] | 856 | " init: 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 857 | ab8500_reg_init[id].bank, |
| 858 | ab8500_reg_init[id].addr, |
| 859 | mask, value); |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 860 | |
| 861 | return 0; |
| 862 | } |
| 863 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 864 | static int ab8500_regulator_register(struct platform_device *pdev, |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 865 | struct regulator_init_data *init_data, |
| 866 | int id, |
| 867 | struct device_node *np) |
| 868 | { |
| 869 | struct ab8500_regulator_info *info = NULL; |
| 870 | struct regulator_config config = { }; |
| 871 | int err; |
| 872 | |
| 873 | /* assign per-regulator data */ |
| 874 | info = &ab8500_regulator_info[id]; |
| 875 | info->dev = &pdev->dev; |
| 876 | |
| 877 | config.dev = &pdev->dev; |
| 878 | config.init_data = init_data; |
| 879 | config.driver_data = info; |
| 880 | config.of_node = np; |
| 881 | |
| 882 | /* fix for hardware before ab8500v2.0 */ |
| 883 | if (abx500_get_chip_id(info->dev) < 0x20) { |
| 884 | if (info->desc.id == AB8500_LDO_AUX3) { |
| 885 | info->desc.n_voltages = |
| 886 | ARRAY_SIZE(ldo_vauxn_voltages); |
Axel Lin | ec1cc4d | 2012-05-20 10:33:35 +0800 | [diff] [blame] | 887 | info->desc.volt_table = ldo_vauxn_voltages; |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 888 | info->voltage_mask = 0xf; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | /* register regulator with framework */ |
| 893 | info->regulator = regulator_register(&info->desc, &config); |
| 894 | if (IS_ERR(info->regulator)) { |
| 895 | err = PTR_ERR(info->regulator); |
| 896 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
| 897 | info->desc.name); |
| 898 | /* when we fail, un-register all earlier regulators */ |
| 899 | while (--id >= 0) { |
| 900 | info = &ab8500_regulator_info[id]; |
| 901 | regulator_unregister(info->regulator); |
| 902 | } |
| 903 | return err; |
| 904 | } |
| 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
Lee Jones | 3a8334b | 2012-05-17 14:45:16 +0100 | [diff] [blame] | 909 | static struct of_regulator_match ab8500_regulator_matches[] = { |
Lee Jones | 7e715b9 | 2012-05-30 12:47:26 +0800 | [diff] [blame] | 910 | { .name = "ab8500_ldo_aux1", .driver_data = (void *) AB8500_LDO_AUX1, }, |
| 911 | { .name = "ab8500_ldo_aux2", .driver_data = (void *) AB8500_LDO_AUX2, }, |
| 912 | { .name = "ab8500_ldo_aux3", .driver_data = (void *) AB8500_LDO_AUX3, }, |
| 913 | { .name = "ab8500_ldo_intcore", .driver_data = (void *) AB8500_LDO_INTCORE, }, |
| 914 | { .name = "ab8500_ldo_tvout", .driver_data = (void *) AB8500_LDO_TVOUT, }, |
| 915 | { .name = "ab8500_ldo_usb", .driver_data = (void *) AB8500_LDO_USB, }, |
| 916 | { .name = "ab8500_ldo_audio", .driver_data = (void *) AB8500_LDO_AUDIO, }, |
| 917 | { .name = "ab8500_ldo_anamic1", .driver_data = (void *) AB8500_LDO_ANAMIC1, }, |
| 918 | { .name = "ab8500_ldo_amamic2", .driver_data = (void *) AB8500_LDO_ANAMIC2, }, |
| 919 | { .name = "ab8500_ldo_dmic", .driver_data = (void *) AB8500_LDO_DMIC, }, |
| 920 | { .name = "ab8500_ldo_ana", .driver_data = (void *) AB8500_LDO_ANA, }, |
Lee Jones | 3a8334b | 2012-05-17 14:45:16 +0100 | [diff] [blame] | 921 | }; |
| 922 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 923 | static int |
Lee Jones | 3a8334b | 2012-05-17 14:45:16 +0100 | [diff] [blame] | 924 | ab8500_regulator_of_probe(struct platform_device *pdev, struct device_node *np) |
| 925 | { |
| 926 | int err, i; |
| 927 | |
| 928 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { |
| 929 | err = ab8500_regulator_register( |
| 930 | pdev, ab8500_regulator_matches[i].init_data, |
| 931 | i, ab8500_regulator_matches[i].of_node); |
| 932 | if (err) |
| 933 | return err; |
| 934 | } |
| 935 | |
| 936 | return 0; |
| 937 | } |
| 938 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 939 | static int ab8500_regulator_probe(struct platform_device *pdev) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 940 | { |
| 941 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); |
Lee Jones | 3a8334b | 2012-05-17 14:45:16 +0100 | [diff] [blame] | 942 | struct device_node *np = pdev->dev.of_node; |
Bengt Jonsson | 732805a | 2013-03-21 15:59:03 +0000 | [diff] [blame^] | 943 | struct ab8500_platform_data *ppdata; |
| 944 | struct ab8500_regulator_platform_data *pdata; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 945 | int i, err; |
| 946 | |
Lee Jones | 3a8334b | 2012-05-17 14:45:16 +0100 | [diff] [blame] | 947 | if (np) { |
| 948 | err = of_regulator_match(&pdev->dev, np, |
| 949 | ab8500_regulator_matches, |
| 950 | ARRAY_SIZE(ab8500_regulator_matches)); |
| 951 | if (err < 0) { |
| 952 | dev_err(&pdev->dev, |
| 953 | "Error parsing regulator init data: %d\n", err); |
| 954 | return err; |
| 955 | } |
| 956 | |
| 957 | err = ab8500_regulator_of_probe(pdev, np); |
| 958 | return err; |
| 959 | } |
| 960 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 961 | if (!ab8500) { |
| 962 | dev_err(&pdev->dev, "null mfd parent\n"); |
| 963 | return -EINVAL; |
| 964 | } |
Bengt Jonsson | 732805a | 2013-03-21 15:59:03 +0000 | [diff] [blame^] | 965 | |
| 966 | ppdata = dev_get_platdata(ab8500->dev); |
| 967 | if (!ppdata) { |
| 968 | dev_err(&pdev->dev, "null parent pdata\n"); |
| 969 | return -EINVAL; |
| 970 | } |
| 971 | |
| 972 | pdata = ppdata->regulator; |
Bengt Jonsson | fc24b42 | 2010-12-10 11:08:45 +0100 | [diff] [blame] | 973 | if (!pdata) { |
| 974 | dev_err(&pdev->dev, "null pdata\n"); |
| 975 | return -EINVAL; |
| 976 | } |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 977 | |
Bengt Jonsson | cb189b0 | 2010-12-10 11:08:40 +0100 | [diff] [blame] | 978 | /* make sure the platform data has the correct size */ |
| 979 | if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) { |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 980 | dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); |
Bengt Jonsson | cb189b0 | 2010-12-10 11:08:40 +0100 | [diff] [blame] | 981 | return -EINVAL; |
| 982 | } |
| 983 | |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 984 | /* initialize registers */ |
Bengt Jonsson | 732805a | 2013-03-21 15:59:03 +0000 | [diff] [blame^] | 985 | for (i = 0; i < pdata->num_reg_init; i++) { |
Lee Jones | 3c1b843 | 2013-03-21 15:59:01 +0000 | [diff] [blame] | 986 | int id, mask, value; |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 987 | |
Bengt Jonsson | 732805a | 2013-03-21 15:59:03 +0000 | [diff] [blame^] | 988 | id = pdata->reg_init[i].id; |
| 989 | mask = pdata->reg_init[i].mask; |
| 990 | value = pdata->reg_init[i].value; |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 991 | |
| 992 | /* check for configuration errors */ |
Lee Jones | 3c1b843 | 2013-03-21 15:59:01 +0000 | [diff] [blame] | 993 | BUG_ON(id >= AB8500_NUM_REGULATOR_REGISTERS); |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 994 | |
Lee Jones | 3c1b843 | 2013-03-21 15:59:01 +0000 | [diff] [blame] | 995 | err = ab8500_regulator_init_registers(pdev, id, mask, value); |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 996 | if (err < 0) |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 997 | return err; |
Bengt Jonsson | 79568b94 | 2011-03-11 11:54:46 +0100 | [diff] [blame] | 998 | } |
| 999 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1000 | /* register all regulators */ |
| 1001 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { |
Lee Jones | a7ac1d9 | 2012-05-17 14:45:14 +0100 | [diff] [blame] | 1002 | err = ab8500_regulator_register(pdev, &pdata->regulator[i], i, NULL); |
| 1003 | if (err < 0) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1004 | return err; |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
Bill Pemberton | 8dc995f | 2012-11-19 13:26:10 -0500 | [diff] [blame] | 1010 | static int ab8500_regulator_remove(struct platform_device *pdev) |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1011 | { |
| 1012 | int i; |
| 1013 | |
| 1014 | for (i = 0; i < ARRAY_SIZE(ab8500_regulator_info); i++) { |
| 1015 | struct ab8500_regulator_info *info = NULL; |
| 1016 | info = &ab8500_regulator_info[i]; |
Bengt Jonsson | 09aefa1 | 2010-12-10 11:08:46 +0100 | [diff] [blame] | 1017 | |
| 1018 | dev_vdbg(rdev_get_dev(info->regulator), |
| 1019 | "%s-remove\n", info->desc.name); |
| 1020 | |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1021 | regulator_unregister(info->regulator); |
| 1022 | } |
| 1023 | |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
| 1027 | static struct platform_driver ab8500_regulator_driver = { |
| 1028 | .probe = ab8500_regulator_probe, |
Bill Pemberton | 5eb9f2b | 2012-11-19 13:20:42 -0500 | [diff] [blame] | 1029 | .remove = ab8500_regulator_remove, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1030 | .driver = { |
| 1031 | .name = "ab8500-regulator", |
| 1032 | .owner = THIS_MODULE, |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1033 | }, |
| 1034 | }; |
| 1035 | |
| 1036 | static int __init ab8500_regulator_init(void) |
| 1037 | { |
| 1038 | int ret; |
| 1039 | |
| 1040 | ret = platform_driver_register(&ab8500_regulator_driver); |
| 1041 | if (ret != 0) |
| 1042 | pr_err("Failed to register ab8500 regulator: %d\n", ret); |
| 1043 | |
| 1044 | return ret; |
| 1045 | } |
| 1046 | subsys_initcall(ab8500_regulator_init); |
| 1047 | |
| 1048 | static void __exit ab8500_regulator_exit(void) |
| 1049 | { |
| 1050 | platform_driver_unregister(&ab8500_regulator_driver); |
| 1051 | } |
| 1052 | module_exit(ab8500_regulator_exit); |
| 1053 | |
| 1054 | MODULE_LICENSE("GPL v2"); |
| 1055 | MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>"); |
Bengt Jonsson | 732805a | 2013-03-21 15:59:03 +0000 | [diff] [blame^] | 1056 | MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>"); |
Sundar R IYER | c789ca2 | 2010-07-13 21:48:56 +0530 | [diff] [blame] | 1057 | MODULE_DESCRIPTION("Regulator Driver for ST-Ericsson AB8500 Mixed-Sig PMIC"); |
| 1058 | MODULE_ALIAS("platform:ab8500-regulator"); |