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> 22 #include <linux/slab.h> 23 24 #include <linux/mfd/wm831x/core.h> 25 #include <linux/mfd/wm831x/regulator.h> 26 #include <linux/mfd/wm831x/pdata.h> 27 28 #define WM831X_LDO_MAX_NAME 9 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]; 39 char supply_name[WM831X_LDO_MAX_NAME]; 40 struct regulator_desc desc; 41 int base; 42 struct wm831x *wm831x; 43 struct regulator_dev *regulator; 44 }; 45 46 /* 47 * Shared 48 */ 49 50 static irqreturn_t wm831x_ldo_uv_irq(int irq, void *data) 51 { 52 struct wm831x_ldo *ldo = data; 53 54 regulator_notifier_call_chain(ldo->regulator, 55 REGULATOR_EVENT_UNDER_VOLTAGE, 56 NULL); 57 58 return IRQ_HANDLED; 59 } 60 61 /* 62 * General purpose LDOs 63 */ 64 65 static const struct regulator_linear_range wm831x_gp_ldo_ranges[] = { 66 { .min_uV = 900000, .max_uV = 1650000, .min_sel = 0, .max_sel = 14, 67 .uV_step = 50000 }, 68 { .min_uV = 1700000, .max_uV = 3300000, .min_sel = 15, .max_sel = 31, 69 .uV_step = 100000 }, 70 }; 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); 76 struct wm831x *wm831x = ldo->wm831x; 77 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 78 79 sel = regulator_map_voltage_linear_range(rdev, uV, uV); 80 if (sel < 0) 81 return sel; 82 83 return wm831x_set_bits(wm831x, reg, WM831X_LDO1_ON_VSEL_MASK, sel); 84 } 85 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; 92 int ret; 93 94 ret = wm831x_reg_read(wm831x, on_reg); 95 if (ret < 0) 96 return ret; 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) 103 return ret; 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, 131 WM831X_LDO1_LP_MODE, 0); 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; 140 break; 141 142 case REGULATOR_MODE_STANDBY: 143 ret = wm831x_set_bits(wm831x, ctrl_reg, 144 WM831X_LDO1_LP_MODE, 145 WM831X_LDO1_LP_MODE); 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); 179 if (ret < 0) 180 return ret; 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 = { 204 .list_voltage = regulator_list_voltage_linear_range, 205 .map_voltage = regulator_map_voltage_linear_range, 206 .get_voltage_sel = regulator_get_voltage_sel_regmap, 207 .set_voltage_sel = regulator_set_voltage_sel_regmap, 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, 213 .get_bypass = regulator_get_bypass_regmap, 214 .set_bypass = regulator_set_bypass_regmap, 215 216 .is_enabled = regulator_is_enabled_regmap, 217 .enable = regulator_enable_regmap, 218 .disable = regulator_disable_regmap, 219 }; 220 221 static int wm831x_gp_ldo_probe(struct platform_device *pdev) 222 { 223 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 224 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 225 struct regulator_config config = { }; 226 int id; 227 struct wm831x_ldo *ldo; 228 struct resource *res; 229 int ret, irq; 230 231 if (pdata && pdata->wm831x_num) 232 id = (pdata->wm831x_num * 10) + 1; 233 else 234 id = 0; 235 id = pdev->id - id; 236 237 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); 238 239 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); 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 247 res = platform_get_resource(pdev, IORESOURCE_REG, 0); 248 if (res == NULL) { 249 dev_err(&pdev->dev, "No REG resource\n"); 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; 257 258 snprintf(ldo->supply_name, sizeof(ldo->supply_name), 259 "LDO%dVDD", id + 1); 260 ldo->desc.supply_name = ldo->supply_name; 261 262 ldo->desc.id = id; 263 ldo->desc.type = REGULATOR_VOLTAGE; 264 ldo->desc.n_voltages = 32; 265 ldo->desc.ops = &wm831x_gp_ldo_ops; 266 ldo->desc.owner = THIS_MODULE; 267 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; 268 ldo->desc.vsel_mask = WM831X_LDO1_ON_VSEL_MASK; 269 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 270 ldo->desc.enable_mask = 1 << id; 271 ldo->desc.bypass_reg = ldo->base; 272 ldo->desc.bypass_mask = WM831X_LDO1_SWI; 273 ldo->desc.linear_ranges = wm831x_gp_ldo_ranges; 274 ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_gp_ldo_ranges); 275 276 config.dev = pdev->dev.parent; 277 if (pdata) 278 config.init_data = pdata->ldo[id]; 279 config.driver_data = ldo; 280 config.regmap = wm831x->regmap; 281 282 ldo->regulator = regulator_register(&ldo->desc, &config); 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 290 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 291 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, 292 IRQF_TRIGGER_RISING, ldo->name, 293 ldo); 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: 307 return ret; 308 } 309 310 static int wm831x_gp_ldo_remove(struct platform_device *pdev) 311 { 312 struct wm831x_ldo *ldo = platform_get_drvdata(pdev); 313 314 free_irq(wm831x_irq(ldo->wm831x, 315 platform_get_irq_byname(pdev, "UV")), ldo); 316 regulator_unregister(ldo->regulator); 317 318 return 0; 319 } 320 321 static struct platform_driver wm831x_gp_ldo_driver = { 322 .probe = wm831x_gp_ldo_probe, 323 .remove = wm831x_gp_ldo_remove, 324 .driver = { 325 .name = "wm831x-ldo", 326 .owner = THIS_MODULE, 327 }, 328 }; 329 330 /* 331 * Analogue LDOs 332 */ 333 334 static const struct regulator_linear_range wm831x_aldo_ranges[] = { 335 { .min_uV = 1000000, .max_uV = 1650000, .min_sel = 0, .max_sel = 12, 336 .uV_step = 50000 }, 337 { .min_uV = 1700000, .max_uV = 3500000, .min_sel = 13, .max_sel = 31, 338 .uV_step = 100000 }, 339 }; 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); 345 struct wm831x *wm831x = ldo->wm831x; 346 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 347 348 sel = regulator_map_voltage_linear_range(rdev, uV, uV); 349 if (sel < 0) 350 return sel; 351 352 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel); 353 } 354 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; 360 int ret; 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; 377 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; 378 int ret; 379 380 381 switch (mode) { 382 case REGULATOR_MODE_NORMAL: 383 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0); 384 if (ret < 0) 385 return ret; 386 break; 387 388 case REGULATOR_MODE_IDLE: 389 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 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); 418 if (ret < 0) 419 return ret; 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 = { 431 .list_voltage = regulator_list_voltage_linear_range, 432 .map_voltage = regulator_map_voltage_linear_range, 433 .get_voltage_sel = regulator_get_voltage_sel_regmap, 434 .set_voltage_sel = regulator_set_voltage_sel_regmap, 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, 439 .set_bypass = regulator_set_bypass_regmap, 440 .get_bypass = regulator_get_bypass_regmap, 441 442 .is_enabled = regulator_is_enabled_regmap, 443 .enable = regulator_enable_regmap, 444 .disable = regulator_disable_regmap, 445 }; 446 447 static int wm831x_aldo_probe(struct platform_device *pdev) 448 { 449 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 450 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 451 struct regulator_config config = { }; 452 int id; 453 struct wm831x_ldo *ldo; 454 struct resource *res; 455 int ret, irq; 456 457 if (pdata && pdata->wm831x_num) 458 id = (pdata->wm831x_num * 10) + 1; 459 else 460 id = 0; 461 id = pdev->id - id; 462 463 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); 464 465 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); 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 473 res = platform_get_resource(pdev, IORESOURCE_REG, 0); 474 if (res == NULL) { 475 dev_err(&pdev->dev, "No REG resource\n"); 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; 483 484 snprintf(ldo->supply_name, sizeof(ldo->supply_name), 485 "LDO%dVDD", id + 1); 486 ldo->desc.supply_name = ldo->supply_name; 487 488 ldo->desc.id = id; 489 ldo->desc.type = REGULATOR_VOLTAGE; 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); 493 ldo->desc.ops = &wm831x_aldo_ops; 494 ldo->desc.owner = THIS_MODULE; 495 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; 496 ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK; 497 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 498 ldo->desc.enable_mask = 1 << id; 499 ldo->desc.bypass_reg = ldo->base; 500 ldo->desc.bypass_mask = WM831X_LDO7_SWI; 501 502 config.dev = pdev->dev.parent; 503 if (pdata) 504 config.init_data = pdata->ldo[id]; 505 config.driver_data = ldo; 506 config.regmap = wm831x->regmap; 507 508 ldo->regulator = regulator_register(&ldo->desc, &config); 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 516 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 517 ret = request_threaded_irq(irq, NULL, wm831x_ldo_uv_irq, 518 IRQF_TRIGGER_RISING, ldo->name, ldo); 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: 532 return ret; 533 } 534 535 static int wm831x_aldo_remove(struct platform_device *pdev) 536 { 537 struct wm831x_ldo *ldo = platform_get_drvdata(pdev); 538 539 free_irq(wm831x_irq(ldo->wm831x, platform_get_irq_byname(pdev, "UV")), 540 ldo); 541 regulator_unregister(ldo->regulator); 542 543 return 0; 544 } 545 546 static struct platform_driver wm831x_aldo_driver = { 547 .probe = wm831x_aldo_probe, 548 .remove = wm831x_aldo_remove, 549 .driver = { 550 .name = "wm831x-aldo", 551 .owner = THIS_MODULE, 552 }, 553 }; 554 555 /* 556 * Alive LDO 557 */ 558 559 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf 560 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); 565 struct wm831x *wm831x = ldo->wm831x; 566 int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; 567 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); 573 } 574 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 = { 593 .list_voltage = regulator_list_voltage_linear, 594 .map_voltage = regulator_map_voltage_linear, 595 .get_voltage_sel = regulator_get_voltage_sel_regmap, 596 .set_voltage_sel = regulator_set_voltage_sel_regmap, 597 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, 598 .get_status = wm831x_alive_ldo_get_status, 599 600 .is_enabled = regulator_is_enabled_regmap, 601 .enable = regulator_enable_regmap, 602 .disable = regulator_disable_regmap, 603 }; 604 605 static int wm831x_alive_ldo_probe(struct platform_device *pdev) 606 { 607 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 608 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 609 struct regulator_config config = { }; 610 int id; 611 struct wm831x_ldo *ldo; 612 struct resource *res; 613 int ret; 614 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 622 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); 623 624 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); 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 632 res = platform_get_resource(pdev, IORESOURCE_REG, 0); 633 if (res == NULL) { 634 dev_err(&pdev->dev, "No REG resource\n"); 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; 642 643 snprintf(ldo->supply_name, sizeof(ldo->supply_name), 644 "LDO%dVDD", id + 1); 645 ldo->desc.supply_name = ldo->supply_name; 646 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; 652 ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; 653 ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK; 654 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 655 ldo->desc.enable_mask = 1 << id; 656 ldo->desc.min_uV = 800000; 657 ldo->desc.uV_step = 50000; 658 ldo->desc.enable_time = 1000; 659 660 config.dev = pdev->dev.parent; 661 if (pdata) 662 config.init_data = pdata->ldo[id]; 663 config.driver_data = ldo; 664 config.regmap = wm831x->regmap; 665 666 ldo->regulator = regulator_register(&ldo->desc, &config); 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: 679 return ret; 680 } 681 682 static int wm831x_alive_ldo_remove(struct platform_device *pdev) 683 { 684 struct wm831x_ldo *ldo = platform_get_drvdata(pdev); 685 686 regulator_unregister(ldo->regulator); 687 688 return 0; 689 } 690 691 static struct platform_driver wm831x_alive_ldo_driver = { 692 .probe = wm831x_alive_ldo_probe, 693 .remove = wm831x_alive_ldo_remove, 694 .driver = { 695 .name = "wm831x-alive-ldo", 696 .owner = THIS_MODULE, 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"); 736