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