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