Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm831x-ldo.c -- LDO driver for the WM831x series |
| 3 | * |
| 4 | * Copyright 2009 Wolfson Microelectronics PLC. |
| 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/moduleparam.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/bitops.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/i2c.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/regulator/driver.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 23 | |
| 24 | #include <linux/mfd/wm831x/core.h> |
| 25 | #include <linux/mfd/wm831x/regulator.h> |
| 26 | #include <linux/mfd/wm831x/pdata.h> |
| 27 | |
| 28 | #define WM831X_LDO_MAX_NAME 6 |
| 29 | |
| 30 | #define WM831X_LDO_CONTROL 0 |
| 31 | #define WM831X_LDO_ON_CONTROL 1 |
| 32 | #define WM831X_LDO_SLEEP_CONTROL 2 |
| 33 | |
| 34 | #define WM831X_ALIVE_LDO_ON_CONTROL 0 |
| 35 | #define WM831X_ALIVE_LDO_SLEEP_CONTROL 1 |
| 36 | |
| 37 | struct wm831x_ldo { |
| 38 | char name[WM831X_LDO_MAX_NAME]; |
| 39 | struct regulator_desc desc; |
| 40 | int base; |
| 41 | struct wm831x *wm831x; |
| 42 | struct regulator_dev *regulator; |
| 43 | }; |
| 44 | |
| 45 | /* |
| 46 | * Shared |
| 47 | */ |
| 48 | |
| 49 | static int wm831x_ldo_is_enabled(struct regulator_dev *rdev) |
| 50 | { |
| 51 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 52 | struct wm831x *wm831x = ldo->wm831x; |
| 53 | int mask = 1 << rdev_get_id(rdev); |
| 54 | int reg; |
| 55 | |
| 56 | reg = wm831x_reg_read(wm831x, WM831X_LDO_ENABLE); |
| 57 | if (reg < 0) |
| 58 | return reg; |
| 59 | |
| 60 | if (reg & mask) |
| 61 | return 1; |
| 62 | else |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static int wm831x_ldo_enable(struct regulator_dev *rdev) |
| 67 | { |
| 68 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 69 | struct wm831x *wm831x = ldo->wm831x; |
| 70 | int mask = 1 << rdev_get_id(rdev); |
| 71 | |
| 72 | return wm831x_set_bits(wm831x, WM831X_LDO_ENABLE, mask, mask); |
| 73 | } |
| 74 | |
| 75 | static int wm831x_ldo_disable(struct regulator_dev *rdev) |
| 76 | { |
| 77 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 78 | struct wm831x *wm831x = ldo->wm831x; |
| 79 | int mask = 1 << rdev_get_id(rdev); |
| 80 | |
| 81 | return wm831x_set_bits(wm831x, WM831X_LDO_ENABLE, mask, 0); |
| 82 | } |
| 83 | |
| 84 | static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) |
| 85 | { |
| 86 | struct wm831x_ldo *ldo = data; |
| 87 | |
| 88 | regulator_notifier_call_chain(ldo->regulator, |
| 89 | REGULATOR_EVENT_UNDER_VOLTAGE, |
| 90 | NULL); |
| 91 | |
| 92 | return IRQ_HANDLED; |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * General purpose LDOs |
| 97 | */ |
| 98 | |
| 99 | #define WM831X_GP_LDO_SELECTOR_LOW 0xe |
| 100 | #define WM831X_GP_LDO_MAX_SELECTOR 0x1f |
| 101 | |
| 102 | static int wm831x_gp_ldo_list_voltage(struct regulator_dev *rdev, |
| 103 | unsigned int selector) |
| 104 | { |
| 105 | /* 0.9-1.6V in 50mV steps */ |
| 106 | if (selector <= WM831X_GP_LDO_SELECTOR_LOW) |
| 107 | return 900000 + (selector * 50000); |
Axel Lin | 6085d4d | 2012-03-29 15:04:22 +0800 | [diff] [blame] | 108 | /* 1.7-3.3V in 100mV steps */ |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 109 | if (selector <= WM831X_GP_LDO_MAX_SELECTOR) |
| 110 | return 1600000 + ((selector - WM831X_GP_LDO_SELECTOR_LOW) |
| 111 | * 100000); |
| 112 | return -EINVAL; |
| 113 | } |
| 114 | |
| 115 | static int wm831x_gp_ldo_set_voltage_int(struct regulator_dev *rdev, int reg, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 116 | int min_uV, int max_uV, |
| 117 | unsigned *selector) |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 118 | { |
| 119 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 120 | struct wm831x *wm831x = ldo->wm831x; |
| 121 | int vsel, ret; |
| 122 | |
| 123 | if (min_uV < 900000) |
| 124 | vsel = 0; |
| 125 | else if (min_uV < 1700000) |
| 126 | vsel = ((min_uV - 900000) / 50000); |
| 127 | else |
| 128 | vsel = ((min_uV - 1700000) / 100000) |
| 129 | + WM831X_GP_LDO_SELECTOR_LOW + 1; |
| 130 | |
| 131 | ret = wm831x_gp_ldo_list_voltage(rdev, vsel); |
| 132 | if (ret < 0) |
| 133 | return ret; |
| 134 | if (ret < min_uV || ret > max_uV) |
| 135 | return -EINVAL; |
| 136 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 137 | *selector = vsel; |
| 138 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 139 | return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, vsel); |
| 140 | } |
| 141 | |
| 142 | static int wm831x_gp_ldo_set_voltage(struct regulator_dev *rdev, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 143 | int min_uV, int max_uV, |
| 144 | unsigned *selector) |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 145 | { |
| 146 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 147 | int reg = ldo->base + WM831X_LDO_ON_CONTROL; |
| 148 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 149 | return wm831x_gp_ldo_set_voltage_int(rdev, reg, min_uV, max_uV, |
| 150 | selector); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static int wm831x_gp_ldo_set_suspend_voltage(struct regulator_dev *rdev, |
| 154 | int uV) |
| 155 | { |
| 156 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 157 | int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 158 | unsigned int selector; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 159 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 160 | return wm831x_gp_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 163 | static unsigned int wm831x_gp_ldo_get_mode(struct regulator_dev *rdev) |
| 164 | { |
| 165 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 166 | struct wm831x *wm831x = ldo->wm831x; |
| 167 | int ctrl_reg = ldo->base + WM831X_LDO_CONTROL; |
| 168 | int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; |
Roel Kluin | 9a767d4 | 2009-10-16 14:16:15 +0200 | [diff] [blame] | 169 | int ret; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 170 | |
| 171 | ret = wm831x_reg_read(wm831x, on_reg); |
| 172 | if (ret < 0) |
Roel Kluin | 9a767d4 | 2009-10-16 14:16:15 +0200 | [diff] [blame] | 173 | return ret; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 174 | |
| 175 | if (!(ret & WM831X_LDO1_ON_MODE)) |
| 176 | return REGULATOR_MODE_NORMAL; |
| 177 | |
| 178 | ret = wm831x_reg_read(wm831x, ctrl_reg); |
| 179 | if (ret < 0) |
Roel Kluin | 9a767d4 | 2009-10-16 14:16:15 +0200 | [diff] [blame] | 180 | return ret; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 181 | |
| 182 | if (ret & WM831X_LDO1_LP_MODE) |
| 183 | return REGULATOR_MODE_STANDBY; |
| 184 | else |
| 185 | return REGULATOR_MODE_IDLE; |
| 186 | } |
| 187 | |
| 188 | static int wm831x_gp_ldo_set_mode(struct regulator_dev *rdev, |
| 189 | unsigned int mode) |
| 190 | { |
| 191 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 192 | struct wm831x *wm831x = ldo->wm831x; |
| 193 | int ctrl_reg = ldo->base + WM831X_LDO_CONTROL; |
| 194 | int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; |
| 195 | int ret; |
| 196 | |
| 197 | |
| 198 | switch (mode) { |
| 199 | case REGULATOR_MODE_NORMAL: |
| 200 | ret = wm831x_set_bits(wm831x, on_reg, |
| 201 | WM831X_LDO1_ON_MODE, 0); |
| 202 | if (ret < 0) |
| 203 | return ret; |
| 204 | break; |
| 205 | |
| 206 | case REGULATOR_MODE_IDLE: |
| 207 | ret = wm831x_set_bits(wm831x, ctrl_reg, |
Axel Lin | e260999 | 2010-09-06 16:48:13 +0800 | [diff] [blame] | 208 | WM831X_LDO1_LP_MODE, 0); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 209 | if (ret < 0) |
| 210 | return ret; |
| 211 | |
| 212 | ret = wm831x_set_bits(wm831x, on_reg, |
| 213 | WM831X_LDO1_ON_MODE, |
| 214 | WM831X_LDO1_ON_MODE); |
| 215 | if (ret < 0) |
| 216 | return ret; |
Axel Lin | e260999 | 2010-09-06 16:48:13 +0800 | [diff] [blame] | 217 | break; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 218 | |
| 219 | case REGULATOR_MODE_STANDBY: |
| 220 | ret = wm831x_set_bits(wm831x, ctrl_reg, |
Axel Lin | e260999 | 2010-09-06 16:48:13 +0800 | [diff] [blame] | 221 | WM831X_LDO1_LP_MODE, |
| 222 | WM831X_LDO1_LP_MODE); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 223 | if (ret < 0) |
| 224 | return ret; |
| 225 | |
| 226 | ret = wm831x_set_bits(wm831x, on_reg, |
| 227 | WM831X_LDO1_ON_MODE, |
| 228 | WM831X_LDO1_ON_MODE); |
| 229 | if (ret < 0) |
| 230 | return ret; |
| 231 | break; |
| 232 | |
| 233 | default: |
| 234 | return -EINVAL; |
| 235 | } |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | static int wm831x_gp_ldo_get_status(struct regulator_dev *rdev) |
| 241 | { |
| 242 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 243 | struct wm831x *wm831x = ldo->wm831x; |
| 244 | int mask = 1 << rdev_get_id(rdev); |
| 245 | int ret; |
| 246 | |
| 247 | /* Is the regulator on? */ |
| 248 | ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); |
| 249 | if (ret < 0) |
| 250 | return ret; |
| 251 | if (!(ret & mask)) |
| 252 | return REGULATOR_STATUS_OFF; |
| 253 | |
| 254 | /* Is it reporting under voltage? */ |
| 255 | ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); |
| 256 | if (ret & mask) |
| 257 | return REGULATOR_STATUS_ERROR; |
| 258 | |
| 259 | ret = wm831x_gp_ldo_get_mode(rdev); |
| 260 | if (ret < 0) |
| 261 | return ret; |
| 262 | else |
| 263 | return regulator_mode_to_status(ret); |
| 264 | } |
| 265 | |
| 266 | static unsigned int wm831x_gp_ldo_get_optimum_mode(struct regulator_dev *rdev, |
| 267 | int input_uV, |
| 268 | int output_uV, int load_uA) |
| 269 | { |
| 270 | if (load_uA < 20000) |
| 271 | return REGULATOR_MODE_STANDBY; |
| 272 | if (load_uA < 50000) |
| 273 | return REGULATOR_MODE_IDLE; |
| 274 | return REGULATOR_MODE_NORMAL; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | static struct regulator_ops wm831x_gp_ldo_ops = { |
| 279 | .list_voltage = wm831x_gp_ldo_list_voltage, |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 280 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 281 | .set_voltage = wm831x_gp_ldo_set_voltage, |
| 282 | .set_suspend_voltage = wm831x_gp_ldo_set_suspend_voltage, |
| 283 | .get_mode = wm831x_gp_ldo_get_mode, |
| 284 | .set_mode = wm831x_gp_ldo_set_mode, |
| 285 | .get_status = wm831x_gp_ldo_get_status, |
| 286 | .get_optimum_mode = wm831x_gp_ldo_get_optimum_mode, |
| 287 | |
| 288 | .is_enabled = wm831x_ldo_is_enabled, |
| 289 | .enable = wm831x_ldo_enable, |
| 290 | .disable = wm831x_ldo_disable, |
| 291 | }; |
| 292 | |
| 293 | static __devinit int wm831x_gp_ldo_probe(struct platform_device *pdev) |
| 294 | { |
| 295 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
| 296 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 297 | struct regulator_config config = { }; |
Mark Brown | 137a635 | 2011-07-25 22:20:29 +0100 | [diff] [blame] | 298 | int id; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 299 | struct wm831x_ldo *ldo; |
| 300 | struct resource *res; |
| 301 | int ret, irq; |
| 302 | |
Mark Brown | 137a635 | 2011-07-25 22:20:29 +0100 | [diff] [blame] | 303 | if (pdata && pdata->wm831x_num) |
| 304 | id = (pdata->wm831x_num * 10) + 1; |
| 305 | else |
| 306 | id = 0; |
| 307 | id = pdev->id - id; |
| 308 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 309 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); |
| 310 | |
| 311 | if (pdata == NULL || pdata->ldo[id] == NULL) |
| 312 | return -ENODEV; |
| 313 | |
Mark Brown | fded2f4 | 2011-12-15 02:11:14 +0800 | [diff] [blame] | 314 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 315 | if (ldo == NULL) { |
| 316 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
| 317 | return -ENOMEM; |
| 318 | } |
| 319 | |
| 320 | ldo->wm831x = wm831x; |
| 321 | |
| 322 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 323 | if (res == NULL) { |
| 324 | dev_err(&pdev->dev, "No I/O resource\n"); |
| 325 | ret = -EINVAL; |
| 326 | goto err; |
| 327 | } |
| 328 | ldo->base = res->start; |
| 329 | |
| 330 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); |
| 331 | ldo->desc.name = ldo->name; |
| 332 | ldo->desc.id = id; |
| 333 | ldo->desc.type = REGULATOR_VOLTAGE; |
| 334 | ldo->desc.n_voltages = WM831X_GP_LDO_MAX_SELECTOR + 1; |
| 335 | ldo->desc.ops = &wm831x_gp_ldo_ops; |
| 336 | ldo->desc.owner = THIS_MODULE; |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 337 | ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; |
| 338 | ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 339 | |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 340 | config.dev = pdev->dev.parent; |
| 341 | config.init_data = pdata->ldo[id]; |
| 342 | config.driver_data = ldo; |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 343 | config.regmap = wm831x->regmap; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 344 | |
| 345 | ldo->regulator = regulator_register(&ldo->desc, &config); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 346 | if (IS_ERR(ldo->regulator)) { |
| 347 | ret = PTR_ERR(ldo->regulator); |
| 348 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", |
| 349 | id + 1, ret); |
| 350 | goto err; |
| 351 | } |
| 352 | |
| 353 | irq = platform_get_irq_byname(pdev, "UV"); |
Mark Brown | dfda9c2 | 2011-03-01 16:50:43 +0000 | [diff] [blame] | 354 | ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, |
| 355 | IRQF_TRIGGER_RISING, ldo->name, |
| 356 | ldo); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 357 | if (ret != 0) { |
| 358 | dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", |
| 359 | irq, ret); |
| 360 | goto err_regulator; |
| 361 | } |
| 362 | |
| 363 | platform_set_drvdata(pdev, ldo); |
| 364 | |
| 365 | return 0; |
| 366 | |
| 367 | err_regulator: |
| 368 | regulator_unregister(ldo->regulator); |
| 369 | err: |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 370 | return ret; |
| 371 | } |
| 372 | |
| 373 | static __devexit int wm831x_gp_ldo_remove(struct platform_device *pdev) |
| 374 | { |
| 375 | struct wm831x_ldo *ldo = platform_get_drvdata(pdev); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 376 | |
Dmitry Torokhov | eb66d56 | 2010-02-23 23:38:39 -0800 | [diff] [blame] | 377 | platform_set_drvdata(pdev, NULL); |
| 378 | |
Mark Brown | dfda9c2 | 2011-03-01 16:50:43 +0000 | [diff] [blame] | 379 | free_irq(platform_get_irq_byname(pdev, "UV"), ldo); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 380 | regulator_unregister(ldo->regulator); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | static struct platform_driver wm831x_gp_ldo_driver = { |
| 386 | .probe = wm831x_gp_ldo_probe, |
| 387 | .remove = __devexit_p(wm831x_gp_ldo_remove), |
| 388 | .driver = { |
| 389 | .name = "wm831x-ldo", |
Dmitry Torokhov | eb66d56 | 2010-02-23 23:38:39 -0800 | [diff] [blame] | 390 | .owner = THIS_MODULE, |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 391 | }, |
| 392 | }; |
| 393 | |
| 394 | /* |
| 395 | * Analogue LDOs |
| 396 | */ |
| 397 | |
| 398 | |
| 399 | #define WM831X_ALDO_SELECTOR_LOW 0xc |
| 400 | #define WM831X_ALDO_MAX_SELECTOR 0x1f |
| 401 | |
| 402 | static int wm831x_aldo_list_voltage(struct regulator_dev *rdev, |
| 403 | unsigned int selector) |
| 404 | { |
| 405 | /* 1-1.6V in 50mV steps */ |
| 406 | if (selector <= WM831X_ALDO_SELECTOR_LOW) |
| 407 | return 1000000 + (selector * 50000); |
Axel Lin | 6085d4d | 2012-03-29 15:04:22 +0800 | [diff] [blame] | 408 | /* 1.7-3.5V in 100mV steps */ |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 409 | if (selector <= WM831X_ALDO_MAX_SELECTOR) |
| 410 | return 1600000 + ((selector - WM831X_ALDO_SELECTOR_LOW) |
| 411 | * 100000); |
| 412 | return -EINVAL; |
| 413 | } |
| 414 | |
| 415 | static int wm831x_aldo_set_voltage_int(struct regulator_dev *rdev, int reg, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 416 | int min_uV, int max_uV, |
| 417 | unsigned *selector) |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 418 | { |
| 419 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 420 | struct wm831x *wm831x = ldo->wm831x; |
| 421 | int vsel, ret; |
| 422 | |
| 423 | if (min_uV < 1000000) |
| 424 | vsel = 0; |
| 425 | else if (min_uV < 1700000) |
| 426 | vsel = ((min_uV - 1000000) / 50000); |
| 427 | else |
| 428 | vsel = ((min_uV - 1700000) / 100000) |
| 429 | + WM831X_ALDO_SELECTOR_LOW + 1; |
| 430 | |
| 431 | ret = wm831x_aldo_list_voltage(rdev, vsel); |
| 432 | if (ret < 0) |
| 433 | return ret; |
| 434 | if (ret < min_uV || ret > max_uV) |
| 435 | return -EINVAL; |
| 436 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 437 | *selector = vsel; |
| 438 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 439 | return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, vsel); |
| 440 | } |
| 441 | |
| 442 | static int wm831x_aldo_set_voltage(struct regulator_dev *rdev, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 443 | int min_uV, int max_uV, unsigned *selector) |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 444 | { |
| 445 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 446 | int reg = ldo->base + WM831X_LDO_ON_CONTROL; |
| 447 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 448 | return wm831x_aldo_set_voltage_int(rdev, reg, min_uV, max_uV, |
| 449 | selector); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, |
| 453 | int uV) |
| 454 | { |
| 455 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 456 | int reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 457 | unsigned int selector; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 458 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 459 | return wm831x_aldo_set_voltage_int(rdev, reg, uV, uV, &selector); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 462 | static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) |
| 463 | { |
| 464 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 465 | struct wm831x *wm831x = ldo->wm831x; |
| 466 | int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; |
Roel Kluin | 6f17c65 | 2009-12-15 20:07:31 +0100 | [diff] [blame] | 467 | int ret; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 468 | |
| 469 | ret = wm831x_reg_read(wm831x, on_reg); |
| 470 | if (ret < 0) |
| 471 | return 0; |
| 472 | |
| 473 | if (ret & WM831X_LDO7_ON_MODE) |
| 474 | return REGULATOR_MODE_IDLE; |
| 475 | else |
| 476 | return REGULATOR_MODE_NORMAL; |
| 477 | } |
| 478 | |
| 479 | static int wm831x_aldo_set_mode(struct regulator_dev *rdev, |
| 480 | unsigned int mode) |
| 481 | { |
| 482 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 483 | struct wm831x *wm831x = ldo->wm831x; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 484 | int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; |
| 485 | int ret; |
| 486 | |
| 487 | |
| 488 | switch (mode) { |
| 489 | case REGULATOR_MODE_NORMAL: |
Axel Lin | e841a36 | 2012-03-29 15:02:55 +0800 | [diff] [blame] | 490 | ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 491 | if (ret < 0) |
| 492 | return ret; |
| 493 | break; |
| 494 | |
| 495 | case REGULATOR_MODE_IDLE: |
Axel Lin | e841a36 | 2012-03-29 15:02:55 +0800 | [diff] [blame] | 496 | ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 497 | WM831X_LDO7_ON_MODE); |
| 498 | if (ret < 0) |
| 499 | return ret; |
| 500 | break; |
| 501 | |
| 502 | default: |
| 503 | return -EINVAL; |
| 504 | } |
| 505 | |
| 506 | return 0; |
| 507 | } |
| 508 | |
| 509 | static int wm831x_aldo_get_status(struct regulator_dev *rdev) |
| 510 | { |
| 511 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 512 | struct wm831x *wm831x = ldo->wm831x; |
| 513 | int mask = 1 << rdev_get_id(rdev); |
| 514 | int ret; |
| 515 | |
| 516 | /* Is the regulator on? */ |
| 517 | ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); |
| 518 | if (ret < 0) |
| 519 | return ret; |
| 520 | if (!(ret & mask)) |
| 521 | return REGULATOR_STATUS_OFF; |
| 522 | |
| 523 | /* Is it reporting under voltage? */ |
| 524 | ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); |
| 525 | if (ret & mask) |
| 526 | return REGULATOR_STATUS_ERROR; |
| 527 | |
| 528 | ret = wm831x_aldo_get_mode(rdev); |
| 529 | if (ret < 0) |
| 530 | return ret; |
| 531 | else |
| 532 | return regulator_mode_to_status(ret); |
| 533 | } |
| 534 | |
| 535 | static struct regulator_ops wm831x_aldo_ops = { |
| 536 | .list_voltage = wm831x_aldo_list_voltage, |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 537 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 538 | .set_voltage = wm831x_aldo_set_voltage, |
| 539 | .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, |
| 540 | .get_mode = wm831x_aldo_get_mode, |
| 541 | .set_mode = wm831x_aldo_set_mode, |
| 542 | .get_status = wm831x_aldo_get_status, |
| 543 | |
| 544 | .is_enabled = wm831x_ldo_is_enabled, |
| 545 | .enable = wm831x_ldo_enable, |
| 546 | .disable = wm831x_ldo_disable, |
| 547 | }; |
| 548 | |
| 549 | static __devinit int wm831x_aldo_probe(struct platform_device *pdev) |
| 550 | { |
| 551 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
| 552 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 553 | struct regulator_config config = { }; |
Mark Brown | 137a635 | 2011-07-25 22:20:29 +0100 | [diff] [blame] | 554 | int id; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 555 | struct wm831x_ldo *ldo; |
| 556 | struct resource *res; |
| 557 | int ret, irq; |
| 558 | |
Mark Brown | 137a635 | 2011-07-25 22:20:29 +0100 | [diff] [blame] | 559 | if (pdata && pdata->wm831x_num) |
| 560 | id = (pdata->wm831x_num * 10) + 1; |
| 561 | else |
| 562 | id = 0; |
| 563 | id = pdev->id - id; |
| 564 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 565 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); |
| 566 | |
| 567 | if (pdata == NULL || pdata->ldo[id] == NULL) |
| 568 | return -ENODEV; |
| 569 | |
Mark Brown | fded2f4 | 2011-12-15 02:11:14 +0800 | [diff] [blame] | 570 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 571 | if (ldo == NULL) { |
| 572 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
| 573 | return -ENOMEM; |
| 574 | } |
| 575 | |
| 576 | ldo->wm831x = wm831x; |
| 577 | |
| 578 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 579 | if (res == NULL) { |
| 580 | dev_err(&pdev->dev, "No I/O resource\n"); |
| 581 | ret = -EINVAL; |
| 582 | goto err; |
| 583 | } |
| 584 | ldo->base = res->start; |
| 585 | |
| 586 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); |
| 587 | ldo->desc.name = ldo->name; |
| 588 | ldo->desc.id = id; |
| 589 | ldo->desc.type = REGULATOR_VOLTAGE; |
| 590 | ldo->desc.n_voltages = WM831X_ALDO_MAX_SELECTOR + 1; |
| 591 | ldo->desc.ops = &wm831x_aldo_ops; |
| 592 | ldo->desc.owner = THIS_MODULE; |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 593 | ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; |
| 594 | ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 595 | |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 596 | config.dev = pdev->dev.parent; |
| 597 | config.init_data = pdata->ldo[id]; |
| 598 | config.driver_data = ldo; |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 599 | config.regmap = wm831x->regmap; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 600 | |
| 601 | ldo->regulator = regulator_register(&ldo->desc, &config); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 602 | if (IS_ERR(ldo->regulator)) { |
| 603 | ret = PTR_ERR(ldo->regulator); |
| 604 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", |
| 605 | id + 1, ret); |
| 606 | goto err; |
| 607 | } |
| 608 | |
| 609 | irq = platform_get_irq_byname(pdev, "UV"); |
Mark Brown | dfda9c2 | 2011-03-01 16:50:43 +0000 | [diff] [blame] | 610 | ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, |
| 611 | IRQF_TRIGGER_RISING, ldo->name, ldo); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 612 | if (ret != 0) { |
| 613 | dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", |
| 614 | irq, ret); |
| 615 | goto err_regulator; |
| 616 | } |
| 617 | |
| 618 | platform_set_drvdata(pdev, ldo); |
| 619 | |
| 620 | return 0; |
| 621 | |
| 622 | err_regulator: |
| 623 | regulator_unregister(ldo->regulator); |
| 624 | err: |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 625 | return ret; |
| 626 | } |
| 627 | |
| 628 | static __devexit int wm831x_aldo_remove(struct platform_device *pdev) |
| 629 | { |
| 630 | struct wm831x_ldo *ldo = platform_get_drvdata(pdev); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 631 | |
Mark Brown | dfda9c2 | 2011-03-01 16:50:43 +0000 | [diff] [blame] | 632 | free_irq(platform_get_irq_byname(pdev, "UV"), ldo); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 633 | regulator_unregister(ldo->regulator); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | static struct platform_driver wm831x_aldo_driver = { |
| 639 | .probe = wm831x_aldo_probe, |
| 640 | .remove = __devexit_p(wm831x_aldo_remove), |
| 641 | .driver = { |
| 642 | .name = "wm831x-aldo", |
Dmitry Torokhov | eb66d56 | 2010-02-23 23:38:39 -0800 | [diff] [blame] | 643 | .owner = THIS_MODULE, |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 644 | }, |
| 645 | }; |
| 646 | |
| 647 | /* |
| 648 | * Alive LDO |
| 649 | */ |
| 650 | |
| 651 | #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf |
| 652 | |
| 653 | static int wm831x_alive_ldo_list_voltage(struct regulator_dev *rdev, |
| 654 | unsigned int selector) |
| 655 | { |
| 656 | /* 0.8-1.55V in 50mV steps */ |
| 657 | if (selector <= WM831X_ALIVE_LDO_MAX_SELECTOR) |
| 658 | return 800000 + (selector * 50000); |
| 659 | return -EINVAL; |
| 660 | } |
| 661 | |
| 662 | static int wm831x_alive_ldo_set_voltage_int(struct regulator_dev *rdev, |
| 663 | int reg, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 664 | int min_uV, int max_uV, |
| 665 | unsigned *selector) |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 666 | { |
| 667 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 668 | struct wm831x *wm831x = ldo->wm831x; |
| 669 | int vsel, ret; |
| 670 | |
| 671 | vsel = (min_uV - 800000) / 50000; |
| 672 | |
| 673 | ret = wm831x_alive_ldo_list_voltage(rdev, vsel); |
| 674 | if (ret < 0) |
| 675 | return ret; |
| 676 | if (ret < min_uV || ret > max_uV) |
| 677 | return -EINVAL; |
| 678 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 679 | *selector = vsel; |
| 680 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 681 | return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, vsel); |
| 682 | } |
| 683 | |
| 684 | static int wm831x_alive_ldo_set_voltage(struct regulator_dev *rdev, |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 685 | int min_uV, int max_uV, |
| 686 | unsigned *selector) |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 687 | { |
| 688 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 689 | int reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; |
| 690 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 691 | return wm831x_alive_ldo_set_voltage_int(rdev, reg, min_uV, max_uV, |
| 692 | selector); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, |
| 696 | int uV) |
| 697 | { |
| 698 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 699 | int reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 700 | unsigned selector; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 701 | |
Mark Brown | 3a93f2a | 2010-11-10 14:38:29 +0000 | [diff] [blame] | 702 | return wm831x_alive_ldo_set_voltage_int(rdev, reg, uV, uV, &selector); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 703 | } |
| 704 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 705 | static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) |
| 706 | { |
| 707 | struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); |
| 708 | struct wm831x *wm831x = ldo->wm831x; |
| 709 | int mask = 1 << rdev_get_id(rdev); |
| 710 | int ret; |
| 711 | |
| 712 | /* Is the regulator on? */ |
| 713 | ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); |
| 714 | if (ret < 0) |
| 715 | return ret; |
| 716 | if (ret & mask) |
| 717 | return REGULATOR_STATUS_ON; |
| 718 | else |
| 719 | return REGULATOR_STATUS_OFF; |
| 720 | } |
| 721 | |
| 722 | static struct regulator_ops wm831x_alive_ldo_ops = { |
| 723 | .list_voltage = wm831x_alive_ldo_list_voltage, |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 724 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 725 | .set_voltage = wm831x_alive_ldo_set_voltage, |
| 726 | .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, |
| 727 | .get_status = wm831x_alive_ldo_get_status, |
| 728 | |
| 729 | .is_enabled = wm831x_ldo_is_enabled, |
| 730 | .enable = wm831x_ldo_enable, |
| 731 | .disable = wm831x_ldo_disable, |
| 732 | }; |
| 733 | |
| 734 | static __devinit int wm831x_alive_ldo_probe(struct platform_device *pdev) |
| 735 | { |
| 736 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); |
| 737 | struct wm831x_pdata *pdata = wm831x->dev->platform_data; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 738 | struct regulator_config config = { }; |
Mark Brown | 137a635 | 2011-07-25 22:20:29 +0100 | [diff] [blame] | 739 | int id; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 740 | struct wm831x_ldo *ldo; |
| 741 | struct resource *res; |
| 742 | int ret; |
| 743 | |
Mark Brown | 137a635 | 2011-07-25 22:20:29 +0100 | [diff] [blame] | 744 | if (pdata && pdata->wm831x_num) |
| 745 | id = (pdata->wm831x_num * 10) + 1; |
| 746 | else |
| 747 | id = 0; |
| 748 | id = pdev->id - id; |
| 749 | |
| 750 | |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 751 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); |
| 752 | |
| 753 | if (pdata == NULL || pdata->ldo[id] == NULL) |
| 754 | return -ENODEV; |
| 755 | |
Mark Brown | fded2f4 | 2011-12-15 02:11:14 +0800 | [diff] [blame] | 756 | ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 757 | if (ldo == NULL) { |
| 758 | dev_err(&pdev->dev, "Unable to allocate private data\n"); |
| 759 | return -ENOMEM; |
| 760 | } |
| 761 | |
| 762 | ldo->wm831x = wm831x; |
| 763 | |
| 764 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 765 | if (res == NULL) { |
| 766 | dev_err(&pdev->dev, "No I/O resource\n"); |
| 767 | ret = -EINVAL; |
| 768 | goto err; |
| 769 | } |
| 770 | ldo->base = res->start; |
| 771 | |
| 772 | snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); |
| 773 | ldo->desc.name = ldo->name; |
| 774 | ldo->desc.id = id; |
| 775 | ldo->desc.type = REGULATOR_VOLTAGE; |
| 776 | ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1; |
| 777 | ldo->desc.ops = &wm831x_alive_ldo_ops; |
| 778 | ldo->desc.owner = THIS_MODULE; |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 779 | ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; |
| 780 | ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK; |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 781 | |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 782 | config.dev = pdev->dev.parent; |
| 783 | config.init_data = pdata->ldo[id]; |
| 784 | config.driver_data = ldo; |
Mark Brown | ac663b4 | 2012-04-15 11:55:55 +0100 | [diff] [blame^] | 785 | config.regmap = wm831x->regmap; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 786 | |
| 787 | ldo->regulator = regulator_register(&ldo->desc, &config); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 788 | if (IS_ERR(ldo->regulator)) { |
| 789 | ret = PTR_ERR(ldo->regulator); |
| 790 | dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", |
| 791 | id + 1, ret); |
| 792 | goto err; |
| 793 | } |
| 794 | |
| 795 | platform_set_drvdata(pdev, ldo); |
| 796 | |
| 797 | return 0; |
| 798 | |
| 799 | err: |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 800 | return ret; |
| 801 | } |
| 802 | |
| 803 | static __devexit int wm831x_alive_ldo_remove(struct platform_device *pdev) |
| 804 | { |
| 805 | struct wm831x_ldo *ldo = platform_get_drvdata(pdev); |
| 806 | |
| 807 | regulator_unregister(ldo->regulator); |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 808 | |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | static struct platform_driver wm831x_alive_ldo_driver = { |
| 813 | .probe = wm831x_alive_ldo_probe, |
| 814 | .remove = __devexit_p(wm831x_alive_ldo_remove), |
| 815 | .driver = { |
| 816 | .name = "wm831x-alive-ldo", |
Dmitry Torokhov | eb66d56 | 2010-02-23 23:38:39 -0800 | [diff] [blame] | 817 | .owner = THIS_MODULE, |
Mark Brown | d1c6b4f | 2009-07-28 15:22:02 +0100 | [diff] [blame] | 818 | }, |
| 819 | }; |
| 820 | |
| 821 | static int __init wm831x_ldo_init(void) |
| 822 | { |
| 823 | int ret; |
| 824 | |
| 825 | ret = platform_driver_register(&wm831x_gp_ldo_driver); |
| 826 | if (ret != 0) |
| 827 | pr_err("Failed to register WM831x GP LDO driver: %d\n", ret); |
| 828 | |
| 829 | ret = platform_driver_register(&wm831x_aldo_driver); |
| 830 | if (ret != 0) |
| 831 | pr_err("Failed to register WM831x ALDO driver: %d\n", ret); |
| 832 | |
| 833 | ret = platform_driver_register(&wm831x_alive_ldo_driver); |
| 834 | if (ret != 0) |
| 835 | pr_err("Failed to register WM831x alive LDO driver: %d\n", |
| 836 | ret); |
| 837 | |
| 838 | return 0; |
| 839 | } |
| 840 | subsys_initcall(wm831x_ldo_init); |
| 841 | |
| 842 | static void __exit wm831x_ldo_exit(void) |
| 843 | { |
| 844 | platform_driver_unregister(&wm831x_alive_ldo_driver); |
| 845 | platform_driver_unregister(&wm831x_aldo_driver); |
| 846 | platform_driver_unregister(&wm831x_gp_ldo_driver); |
| 847 | } |
| 848 | module_exit(wm831x_ldo_exit); |
| 849 | |
| 850 | /* Module information */ |
| 851 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); |
| 852 | MODULE_DESCRIPTION("WM831x LDO driver"); |
| 853 | MODULE_LICENSE("GPL"); |
| 854 | MODULE_ALIAS("platform:wm831x-ldo"); |
| 855 | MODULE_ALIAS("platform:wm831x-aldo"); |
| 856 | MODULE_ALIAS("platform:wm831x-aliveldo"); |