Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) ST-Ericsson SA 2010 |
| 3 | * |
| 4 | * License Terms: GNU General Public License v2 |
| 5 | * |
| 6 | * Authors: Bengt Jonsson <bengt.g.jonsson@stericsson.com> |
| 7 | * |
| 8 | * This file is based on drivers/regulator/ab8500.c |
| 9 | * |
| 10 | * AB8500 external regulators |
| 11 | * |
| 12 | * ab8500-ext supports the following regulators: |
| 13 | * - VextSupply3 |
| 14 | */ |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/module.h> |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 19 | #include <linux/of.h> |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/regulator/driver.h> |
| 22 | #include <linux/regulator/machine.h> |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 23 | #include <linux/regulator/of_regulator.h> |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 24 | #include <linux/mfd/abx500.h> |
| 25 | #include <linux/mfd/abx500/ab8500.h> |
| 26 | #include <linux/regulator/ab8500.h> |
| 27 | |
| 28 | /** |
| 29 | * struct ab8500_ext_regulator_info - ab8500 regulator information |
| 30 | * @dev: device pointer |
| 31 | * @desc: regulator description |
| 32 | * @rdev: regulator device |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 33 | * @cfg: regulator configuration (extension of regulator FW configuration) |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 34 | * @update_bank: bank to control on/off |
| 35 | * @update_reg: register to control on/off |
| 36 | * @update_mask: mask to enable/disable and set mode of regulator |
| 37 | * @update_val: bits holding the regulator current mode |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 38 | * @update_val_hp: bits to set EN pin active (LPn pin deactive) |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 39 | * normally this means high power mode |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 40 | * @update_val_lp: bits to set EN pin active and LPn pin active |
| 41 | * normally this means low power mode |
| 42 | * @update_val_hw: bits to set regulator pins in HW control |
| 43 | * SysClkReq pins and logic will choose mode |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 44 | */ |
| 45 | struct ab8500_ext_regulator_info { |
| 46 | struct device *dev; |
| 47 | struct regulator_desc desc; |
| 48 | struct regulator_dev *rdev; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 49 | struct ab8500_ext_regulator_cfg *cfg; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 50 | u8 update_bank; |
| 51 | u8 update_reg; |
| 52 | u8 update_mask; |
| 53 | u8 update_val; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 54 | u8 update_val_hp; |
| 55 | u8 update_val_lp; |
| 56 | u8 update_val_hw; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 59 | static int ab8500_ext_regulator_enable(struct regulator_dev *rdev) |
| 60 | { |
| 61 | int ret; |
| 62 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
| 63 | u8 regval; |
| 64 | |
| 65 | if (info == NULL) { |
| 66 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 67 | return -EINVAL; |
| 68 | } |
| 69 | |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 70 | /* |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 71 | * To satisfy both HW high power request and SW request, the regulator |
| 72 | * must be on in high power. |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 73 | */ |
| 74 | if (info->cfg && info->cfg->hwreq) |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 75 | regval = info->update_val_hp; |
| 76 | else |
| 77 | regval = info->update_val; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 78 | |
| 79 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
| 80 | info->update_bank, info->update_reg, |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 81 | info->update_mask, regval); |
Axel Lin | 37daa8a | 2013-04-02 20:56:16 +0800 | [diff] [blame] | 82 | if (ret < 0) { |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 83 | dev_err(rdev_get_dev(info->rdev), |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 84 | "couldn't set enable bits for regulator\n"); |
Axel Lin | 37daa8a | 2013-04-02 20:56:16 +0800 | [diff] [blame] | 85 | return ret; |
| 86 | } |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 87 | |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 88 | dev_dbg(rdev_get_dev(rdev), |
| 89 | "%s-enable (bank, reg, mask, value): 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 90 | info->desc.name, info->update_bank, info->update_reg, |
| 91 | info->update_mask, regval); |
| 92 | |
| 93 | return 0; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static int ab8500_ext_regulator_disable(struct regulator_dev *rdev) |
| 97 | { |
| 98 | int ret; |
| 99 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 100 | u8 regval; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 101 | |
| 102 | if (info == NULL) { |
| 103 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 107 | /* |
| 108 | * Set the regulator in HW request mode if configured |
| 109 | */ |
| 110 | if (info->cfg && info->cfg->hwreq) |
| 111 | regval = info->update_val_hw; |
| 112 | else |
| 113 | regval = 0; |
| 114 | |
| 115 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
| 116 | info->update_bank, info->update_reg, |
| 117 | info->update_mask, regval); |
| 118 | if (ret < 0) { |
| 119 | dev_err(rdev_get_dev(info->rdev), |
| 120 | "couldn't set disable bits for regulator\n"); |
| 121 | return ret; |
| 122 | } |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 123 | |
| 124 | dev_dbg(rdev_get_dev(rdev), "%s-disable (bank, reg, mask, value):" |
| 125 | " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 126 | info->desc.name, info->update_bank, info->update_reg, |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 127 | info->update_mask, regval); |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 128 | |
Axel Lin | 7384744 | 2013-04-16 23:33:00 +0800 | [diff] [blame] | 129 | return 0; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static int ab8500_ext_regulator_is_enabled(struct regulator_dev *rdev) |
| 133 | { |
| 134 | int ret; |
| 135 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
| 136 | u8 regval; |
| 137 | |
| 138 | if (info == NULL) { |
| 139 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 140 | return -EINVAL; |
| 141 | } |
| 142 | |
| 143 | ret = abx500_get_register_interruptible(info->dev, |
| 144 | info->update_bank, info->update_reg, ®val); |
| 145 | if (ret < 0) { |
| 146 | dev_err(rdev_get_dev(rdev), |
| 147 | "couldn't read 0x%x register\n", info->update_reg); |
| 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | dev_dbg(rdev_get_dev(rdev), "%s-is_enabled (bank, reg, mask, value):" |
| 152 | " 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", |
| 153 | info->desc.name, info->update_bank, info->update_reg, |
| 154 | info->update_mask, regval); |
| 155 | |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 156 | if (((regval & info->update_mask) == info->update_val_lp) || |
| 157 | ((regval & info->update_mask) == info->update_val_hp)) |
Axel Lin | 9ab51a0 | 2013-04-07 23:13:39 +0800 | [diff] [blame] | 158 | return 1; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 159 | else |
Axel Lin | 9ab51a0 | 2013-04-07 23:13:39 +0800 | [diff] [blame] | 160 | return 0; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static int ab8500_ext_regulator_set_mode(struct regulator_dev *rdev, |
| 164 | unsigned int mode) |
| 165 | { |
| 166 | int ret = 0; |
| 167 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 168 | u8 regval; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 169 | |
| 170 | if (info == NULL) { |
| 171 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 172 | return -EINVAL; |
| 173 | } |
| 174 | |
| 175 | switch (mode) { |
| 176 | case REGULATOR_MODE_NORMAL: |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 177 | regval = info->update_val_hp; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 178 | break; |
| 179 | case REGULATOR_MODE_IDLE: |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 180 | regval = info->update_val_lp; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 181 | break; |
| 182 | |
| 183 | default: |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 187 | /* If regulator is enabled and info->cfg->hwreq is set, the regulator |
| 188 | must be on in high power, so we don't need to write the register with |
| 189 | the same value. |
| 190 | */ |
| 191 | if (ab8500_ext_regulator_is_enabled(rdev) && |
| 192 | !(info->cfg && info->cfg->hwreq)) { |
| 193 | ret = abx500_mask_and_set_register_interruptible(info->dev, |
| 194 | info->update_bank, info->update_reg, |
| 195 | info->update_mask, regval); |
| 196 | if (ret < 0) { |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 197 | dev_err(rdev_get_dev(rdev), |
| 198 | "Could not set regulator mode.\n"); |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 199 | return ret; |
| 200 | } |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 201 | |
| 202 | dev_dbg(rdev_get_dev(rdev), |
| 203 | "%s-set_mode (bank, reg, mask, value): " |
| 204 | "0x%x, 0x%x, 0x%x, 0x%x\n", |
| 205 | info->desc.name, info->update_bank, info->update_reg, |
| 206 | info->update_mask, regval); |
| 207 | } |
| 208 | |
Axel Lin | 66511fa | 2013-04-16 23:29:12 +0800 | [diff] [blame] | 209 | info->update_val = regval; |
| 210 | |
| 211 | return 0; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static unsigned int ab8500_ext_regulator_get_mode(struct regulator_dev *rdev) |
| 215 | { |
| 216 | struct ab8500_ext_regulator_info *info = rdev_get_drvdata(rdev); |
| 217 | int ret; |
| 218 | |
| 219 | if (info == NULL) { |
| 220 | dev_err(rdev_get_dev(rdev), "regulator info null pointer\n"); |
| 221 | return -EINVAL; |
| 222 | } |
| 223 | |
| 224 | if (info->update_val == info->update_val_hp) |
| 225 | ret = REGULATOR_MODE_NORMAL; |
| 226 | else if (info->update_val == info->update_val_lp) |
| 227 | ret = REGULATOR_MODE_IDLE; |
| 228 | else |
| 229 | ret = -EINVAL; |
| 230 | |
| 231 | return ret; |
| 232 | } |
| 233 | |
Lee Jones | 33fb880 | 2013-06-07 17:11:25 +0100 | [diff] [blame] | 234 | static int ab8500_ext_set_voltage(struct regulator_dev *rdev, int min_uV, |
| 235 | int max_uV, unsigned *selector) |
| 236 | { |
| 237 | struct regulation_constraints *regu_constraints = rdev->constraints; |
| 238 | |
| 239 | if (!regu_constraints) { |
| 240 | dev_err(rdev_get_dev(rdev), "No regulator constraints\n"); |
| 241 | return -EINVAL; |
| 242 | } |
| 243 | |
| 244 | if (regu_constraints->min_uV == min_uV && |
| 245 | regu_constraints->max_uV == max_uV) |
| 246 | return 0; |
| 247 | |
| 248 | dev_err(rdev_get_dev(rdev), |
| 249 | "Requested min %duV max %duV != constrained min %duV max %duV\n", |
| 250 | min_uV, max_uV, |
| 251 | regu_constraints->min_uV, regu_constraints->max_uV); |
| 252 | |
| 253 | return -EINVAL; |
| 254 | } |
| 255 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 256 | static int ab8500_ext_list_voltage(struct regulator_dev *rdev, |
| 257 | unsigned selector) |
| 258 | { |
| 259 | struct regulation_constraints *regu_constraints = rdev->constraints; |
| 260 | |
| 261 | if (regu_constraints == NULL) { |
| 262 | dev_err(rdev_get_dev(rdev), "regulator constraints null pointer\n"); |
| 263 | return -EINVAL; |
| 264 | } |
| 265 | /* return the uV for the fixed regulators */ |
| 266 | if (regu_constraints->min_uV && regu_constraints->max_uV) { |
| 267 | if (regu_constraints->min_uV == regu_constraints->max_uV) |
| 268 | return regu_constraints->min_uV; |
| 269 | } |
| 270 | return -EINVAL; |
| 271 | } |
| 272 | |
| 273 | static struct regulator_ops ab8500_ext_regulator_ops = { |
| 274 | .enable = ab8500_ext_regulator_enable, |
| 275 | .disable = ab8500_ext_regulator_disable, |
| 276 | .is_enabled = ab8500_ext_regulator_is_enabled, |
| 277 | .set_mode = ab8500_ext_regulator_set_mode, |
| 278 | .get_mode = ab8500_ext_regulator_get_mode, |
Lee Jones | 33fb880 | 2013-06-07 17:11:25 +0100 | [diff] [blame] | 279 | .set_voltage = ab8500_ext_set_voltage, |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 280 | .list_voltage = ab8500_ext_list_voltage, |
| 281 | }; |
| 282 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 283 | static struct ab8500_ext_regulator_info |
| 284 | ab8500_ext_regulator_info[AB8500_NUM_EXT_REGULATORS] = { |
| 285 | [AB8500_EXT_SUPPLY1] = { |
| 286 | .desc = { |
| 287 | .name = "VEXTSUPPLY1", |
| 288 | .ops = &ab8500_ext_regulator_ops, |
| 289 | .type = REGULATOR_VOLTAGE, |
| 290 | .id = AB8500_EXT_SUPPLY1, |
| 291 | .owner = THIS_MODULE, |
| 292 | .n_voltages = 1, |
| 293 | }, |
| 294 | .update_bank = 0x04, |
| 295 | .update_reg = 0x08, |
| 296 | .update_mask = 0x03, |
| 297 | .update_val = 0x01, |
| 298 | .update_val_hp = 0x01, |
| 299 | .update_val_lp = 0x03, |
| 300 | .update_val_hw = 0x02, |
| 301 | }, |
| 302 | [AB8500_EXT_SUPPLY2] = { |
| 303 | .desc = { |
| 304 | .name = "VEXTSUPPLY2", |
| 305 | .ops = &ab8500_ext_regulator_ops, |
| 306 | .type = REGULATOR_VOLTAGE, |
| 307 | .id = AB8500_EXT_SUPPLY2, |
| 308 | .owner = THIS_MODULE, |
| 309 | .n_voltages = 1, |
| 310 | }, |
| 311 | .update_bank = 0x04, |
| 312 | .update_reg = 0x08, |
| 313 | .update_mask = 0x0c, |
| 314 | .update_val = 0x04, |
| 315 | .update_val_hp = 0x04, |
| 316 | .update_val_lp = 0x0c, |
| 317 | .update_val_hw = 0x08, |
| 318 | }, |
| 319 | [AB8500_EXT_SUPPLY3] = { |
| 320 | .desc = { |
| 321 | .name = "VEXTSUPPLY3", |
| 322 | .ops = &ab8500_ext_regulator_ops, |
| 323 | .type = REGULATOR_VOLTAGE, |
| 324 | .id = AB8500_EXT_SUPPLY3, |
| 325 | .owner = THIS_MODULE, |
| 326 | .n_voltages = 1, |
| 327 | }, |
| 328 | .update_bank = 0x04, |
| 329 | .update_reg = 0x08, |
| 330 | .update_mask = 0x30, |
| 331 | .update_val = 0x10, |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 332 | .update_val_hp = 0x10, |
| 333 | .update_val_lp = 0x30, |
| 334 | .update_val_hw = 0x20, |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 335 | }, |
| 336 | }; |
| 337 | |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 338 | static struct of_regulator_match ab8500_ext_regulator_match[] = { |
| 339 | { .name = "ab8500_ext1", .driver_data = (void *) AB8500_EXT_SUPPLY1, }, |
| 340 | { .name = "ab8500_ext2", .driver_data = (void *) AB8500_EXT_SUPPLY2, }, |
| 341 | { .name = "ab8500_ext3", .driver_data = (void *) AB8500_EXT_SUPPLY3, }, |
| 342 | }; |
| 343 | |
Sachin Kamat | 08d49f4 | 2013-06-26 10:13:37 +0530 | [diff] [blame] | 344 | static int ab8500_ext_regulator_probe(struct platform_device *pdev) |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 345 | { |
| 346 | struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent); |
| 347 | struct ab8500_platform_data *ppdata; |
| 348 | struct ab8500_regulator_platform_data *pdata; |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 349 | struct device_node *np = pdev->dev.of_node; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 350 | struct regulator_config config = { }; |
| 351 | int i, err; |
| 352 | |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 353 | if (np) { |
| 354 | err = of_regulator_match(&pdev->dev, np, |
| 355 | ab8500_ext_regulator_match, |
| 356 | ARRAY_SIZE(ab8500_ext_regulator_match)); |
| 357 | if (err < 0) { |
| 358 | dev_err(&pdev->dev, |
| 359 | "Error parsing regulator init data: %d\n", err); |
| 360 | return err; |
| 361 | } |
| 362 | } |
| 363 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 364 | if (!ab8500) { |
| 365 | dev_err(&pdev->dev, "null mfd parent\n"); |
| 366 | return -EINVAL; |
| 367 | } |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 368 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 369 | ppdata = dev_get_platdata(ab8500->dev); |
| 370 | if (!ppdata) { |
| 371 | dev_err(&pdev->dev, "null parent pdata\n"); |
| 372 | return -EINVAL; |
| 373 | } |
| 374 | |
| 375 | pdata = ppdata->regulator; |
| 376 | if (!pdata) { |
| 377 | dev_err(&pdev->dev, "null pdata\n"); |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | |
| 381 | /* make sure the platform data has the correct size */ |
| 382 | if (pdata->num_ext_regulator != ARRAY_SIZE(ab8500_ext_regulator_info)) { |
| 383 | dev_err(&pdev->dev, "Configuration error: size mismatch.\n"); |
| 384 | return -EINVAL; |
| 385 | } |
| 386 | |
| 387 | /* check for AB8500 2.x */ |
Bengt Jonsson | a632470 | 2013-03-28 16:11:13 +0000 | [diff] [blame] | 388 | if (is_ab8500_2p0_or_earlier(ab8500)) { |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 389 | struct ab8500_ext_regulator_info *info; |
| 390 | |
| 391 | /* VextSupply3LPn is inverted on AB8500 2.x */ |
| 392 | info = &ab8500_ext_regulator_info[AB8500_EXT_SUPPLY3]; |
| 393 | info->update_val = 0x30; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 394 | info->update_val_hp = 0x30; |
| 395 | info->update_val_lp = 0x10; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* register all regulators */ |
| 399 | for (i = 0; i < ARRAY_SIZE(ab8500_ext_regulator_info); i++) { |
| 400 | struct ab8500_ext_regulator_info *info = NULL; |
| 401 | |
| 402 | /* assign per-regulator data */ |
| 403 | info = &ab8500_ext_regulator_info[i]; |
| 404 | info->dev = &pdev->dev; |
Bengt Jonsson | 18bc2b3 | 2013-03-28 16:11:06 +0000 | [diff] [blame] | 405 | info->cfg = (struct ab8500_ext_regulator_cfg *) |
| 406 | pdata->ext_regulator[i].driver_data; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 407 | |
| 408 | config.dev = &pdev->dev; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 409 | config.driver_data = info; |
Lee Jones | 30aa4b2 | 2013-06-07 17:11:27 +0100 | [diff] [blame] | 410 | config.of_node = ab8500_ext_regulator_match[i].of_node; |
| 411 | config.init_data = (np) ? |
| 412 | ab8500_ext_regulator_match[i].init_data : |
| 413 | &pdata->ext_regulator[i]; |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 414 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 415 | /* register regulator with framework */ |
Jingoo Han | a4a6b9d | 2013-09-30 09:52:37 +0900 | [diff] [blame] | 416 | info->rdev = devm_regulator_register(&pdev->dev, &info->desc, |
| 417 | &config); |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 418 | if (IS_ERR(info->rdev)) { |
| 419 | err = PTR_ERR(info->rdev); |
| 420 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
| 421 | info->desc.name); |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 422 | return err; |
| 423 | } |
| 424 | |
| 425 | dev_dbg(rdev_get_dev(info->rdev), |
| 426 | "%s-probed\n", info->desc.name); |
| 427 | } |
| 428 | |
| 429 | return 0; |
| 430 | } |
| 431 | |
Lee Jones | 5a49b4a | 2013-06-07 17:11:26 +0100 | [diff] [blame] | 432 | static struct platform_driver ab8500_ext_regulator_driver = { |
| 433 | .probe = ab8500_ext_regulator_probe, |
Lee Jones | 5a49b4a | 2013-06-07 17:11:26 +0100 | [diff] [blame] | 434 | .driver = { |
| 435 | .name = "ab8500-ext-regulator", |
Lee Jones | 5a49b4a | 2013-06-07 17:11:26 +0100 | [diff] [blame] | 436 | }, |
| 437 | }; |
| 438 | |
| 439 | static int __init ab8500_ext_regulator_init(void) |
| 440 | { |
| 441 | int ret; |
| 442 | |
| 443 | ret = platform_driver_register(&ab8500_ext_regulator_driver); |
| 444 | if (ret) |
| 445 | pr_err("Failed to register ab8500 ext regulator: %d\n", ret); |
| 446 | |
| 447 | return ret; |
| 448 | } |
| 449 | subsys_initcall(ab8500_ext_regulator_init); |
| 450 | |
| 451 | static void __exit ab8500_ext_regulator_exit(void) |
| 452 | { |
| 453 | platform_driver_unregister(&ab8500_ext_regulator_driver); |
| 454 | } |
| 455 | module_exit(ab8500_ext_regulator_exit); |
| 456 | |
Lee Jones | d1a8200 | 2013-03-28 16:11:01 +0000 | [diff] [blame] | 457 | MODULE_LICENSE("GPL v2"); |
| 458 | MODULE_AUTHOR("Bengt Jonsson <bengt.g.jonsson@stericsson.com>"); |
| 459 | MODULE_DESCRIPTION("AB8500 external regulator driver"); |
| 460 | MODULE_ALIAS("platform:ab8500-ext-regulator"); |