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