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