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