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