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