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