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 = devm_regulator_register(&pdev->dev, &ldo->desc, 283 &config); 284 if (IS_ERR(ldo->regulator)) { 285 ret = PTR_ERR(ldo->regulator); 286 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 287 id + 1, ret); 288 goto err; 289 } 290 291 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 292 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 293 wm831x_ldo_uv_irq, 294 IRQF_TRIGGER_RISING, ldo->name, 295 ldo); 296 if (ret != 0) { 297 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 298 irq, ret); 299 goto err; 300 } 301 302 platform_set_drvdata(pdev, ldo); 303 304 return 0; 305 306 err: 307 return ret; 308 } 309 310 static struct platform_driver wm831x_gp_ldo_driver = { 311 .probe = wm831x_gp_ldo_probe, 312 .driver = { 313 .name = "wm831x-ldo", 314 .owner = THIS_MODULE, 315 }, 316 }; 317 318 /* 319 * Analogue LDOs 320 */ 321 322 static const struct regulator_linear_range wm831x_aldo_ranges[] = { 323 { .min_uV = 1000000, .max_uV = 1650000, .min_sel = 0, .max_sel = 12, 324 .uV_step = 50000 }, 325 { .min_uV = 1700000, .max_uV = 3500000, .min_sel = 13, .max_sel = 31, 326 .uV_step = 100000 }, 327 }; 328 329 static int wm831x_aldo_set_suspend_voltage(struct regulator_dev *rdev, 330 int uV) 331 { 332 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 333 struct wm831x *wm831x = ldo->wm831x; 334 int sel, reg = ldo->base + WM831X_LDO_SLEEP_CONTROL; 335 336 sel = regulator_map_voltage_linear_range(rdev, uV, uV); 337 if (sel < 0) 338 return sel; 339 340 return wm831x_set_bits(wm831x, reg, WM831X_LDO7_ON_VSEL_MASK, sel); 341 } 342 343 static unsigned int wm831x_aldo_get_mode(struct regulator_dev *rdev) 344 { 345 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 346 struct wm831x *wm831x = ldo->wm831x; 347 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; 348 int ret; 349 350 ret = wm831x_reg_read(wm831x, on_reg); 351 if (ret < 0) 352 return 0; 353 354 if (ret & WM831X_LDO7_ON_MODE) 355 return REGULATOR_MODE_IDLE; 356 else 357 return REGULATOR_MODE_NORMAL; 358 } 359 360 static int wm831x_aldo_set_mode(struct regulator_dev *rdev, 361 unsigned int mode) 362 { 363 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 364 struct wm831x *wm831x = ldo->wm831x; 365 int on_reg = ldo->base + WM831X_LDO_ON_CONTROL; 366 int ret; 367 368 369 switch (mode) { 370 case REGULATOR_MODE_NORMAL: 371 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 0); 372 if (ret < 0) 373 return ret; 374 break; 375 376 case REGULATOR_MODE_IDLE: 377 ret = wm831x_set_bits(wm831x, on_reg, WM831X_LDO7_ON_MODE, 378 WM831X_LDO7_ON_MODE); 379 if (ret < 0) 380 return ret; 381 break; 382 383 default: 384 return -EINVAL; 385 } 386 387 return 0; 388 } 389 390 static int wm831x_aldo_get_status(struct regulator_dev *rdev) 391 { 392 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 393 struct wm831x *wm831x = ldo->wm831x; 394 int mask = 1 << rdev_get_id(rdev); 395 int ret; 396 397 /* Is the regulator on? */ 398 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); 399 if (ret < 0) 400 return ret; 401 if (!(ret & mask)) 402 return REGULATOR_STATUS_OFF; 403 404 /* Is it reporting under voltage? */ 405 ret = wm831x_reg_read(wm831x, WM831X_LDO_UV_STATUS); 406 if (ret < 0) 407 return ret; 408 if (ret & mask) 409 return REGULATOR_STATUS_ERROR; 410 411 ret = wm831x_aldo_get_mode(rdev); 412 if (ret < 0) 413 return ret; 414 else 415 return regulator_mode_to_status(ret); 416 } 417 418 static struct regulator_ops wm831x_aldo_ops = { 419 .list_voltage = regulator_list_voltage_linear_range, 420 .map_voltage = regulator_map_voltage_linear_range, 421 .get_voltage_sel = regulator_get_voltage_sel_regmap, 422 .set_voltage_sel = regulator_set_voltage_sel_regmap, 423 .set_suspend_voltage = wm831x_aldo_set_suspend_voltage, 424 .get_mode = wm831x_aldo_get_mode, 425 .set_mode = wm831x_aldo_set_mode, 426 .get_status = wm831x_aldo_get_status, 427 .set_bypass = regulator_set_bypass_regmap, 428 .get_bypass = regulator_get_bypass_regmap, 429 430 .is_enabled = regulator_is_enabled_regmap, 431 .enable = regulator_enable_regmap, 432 .disable = regulator_disable_regmap, 433 }; 434 435 static int wm831x_aldo_probe(struct platform_device *pdev) 436 { 437 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 438 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 439 struct regulator_config config = { }; 440 int id; 441 struct wm831x_ldo *ldo; 442 struct resource *res; 443 int ret, irq; 444 445 if (pdata && pdata->wm831x_num) 446 id = (pdata->wm831x_num * 10) + 1; 447 else 448 id = 0; 449 id = pdev->id - id; 450 451 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); 452 453 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); 454 if (ldo == NULL) { 455 dev_err(&pdev->dev, "Unable to allocate private data\n"); 456 return -ENOMEM; 457 } 458 459 ldo->wm831x = wm831x; 460 461 res = platform_get_resource(pdev, IORESOURCE_REG, 0); 462 if (res == NULL) { 463 dev_err(&pdev->dev, "No REG resource\n"); 464 ret = -EINVAL; 465 goto err; 466 } 467 ldo->base = res->start; 468 469 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); 470 ldo->desc.name = ldo->name; 471 472 snprintf(ldo->supply_name, sizeof(ldo->supply_name), 473 "LDO%dVDD", id + 1); 474 ldo->desc.supply_name = ldo->supply_name; 475 476 ldo->desc.id = id; 477 ldo->desc.type = REGULATOR_VOLTAGE; 478 ldo->desc.n_voltages = 32; 479 ldo->desc.linear_ranges = wm831x_aldo_ranges; 480 ldo->desc.n_linear_ranges = ARRAY_SIZE(wm831x_aldo_ranges); 481 ldo->desc.ops = &wm831x_aldo_ops; 482 ldo->desc.owner = THIS_MODULE; 483 ldo->desc.vsel_reg = ldo->base + WM831X_LDO_ON_CONTROL; 484 ldo->desc.vsel_mask = WM831X_LDO7_ON_VSEL_MASK; 485 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 486 ldo->desc.enable_mask = 1 << id; 487 ldo->desc.bypass_reg = ldo->base; 488 ldo->desc.bypass_mask = WM831X_LDO7_SWI; 489 490 config.dev = pdev->dev.parent; 491 if (pdata) 492 config.init_data = pdata->ldo[id]; 493 config.driver_data = ldo; 494 config.regmap = wm831x->regmap; 495 496 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc, 497 &config); 498 if (IS_ERR(ldo->regulator)) { 499 ret = PTR_ERR(ldo->regulator); 500 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 501 id + 1, ret); 502 goto err; 503 } 504 505 irq = wm831x_irq(wm831x, platform_get_irq_byname(pdev, "UV")); 506 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 507 wm831x_ldo_uv_irq, 508 IRQF_TRIGGER_RISING, ldo->name, ldo); 509 if (ret != 0) { 510 dev_err(&pdev->dev, "Failed to request UV IRQ %d: %d\n", 511 irq, ret); 512 goto err; 513 } 514 515 platform_set_drvdata(pdev, ldo); 516 517 return 0; 518 519 err: 520 return ret; 521 } 522 523 static struct platform_driver wm831x_aldo_driver = { 524 .probe = wm831x_aldo_probe, 525 .driver = { 526 .name = "wm831x-aldo", 527 .owner = THIS_MODULE, 528 }, 529 }; 530 531 /* 532 * Alive LDO 533 */ 534 535 #define WM831X_ALIVE_LDO_MAX_SELECTOR 0xf 536 537 static int wm831x_alive_ldo_set_suspend_voltage(struct regulator_dev *rdev, 538 int uV) 539 { 540 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 541 struct wm831x *wm831x = ldo->wm831x; 542 int sel, reg = ldo->base + WM831X_ALIVE_LDO_SLEEP_CONTROL; 543 544 sel = regulator_map_voltage_linear(rdev, uV, uV); 545 if (sel < 0) 546 return sel; 547 548 return wm831x_set_bits(wm831x, reg, WM831X_LDO11_ON_VSEL_MASK, sel); 549 } 550 551 static int wm831x_alive_ldo_get_status(struct regulator_dev *rdev) 552 { 553 struct wm831x_ldo *ldo = rdev_get_drvdata(rdev); 554 struct wm831x *wm831x = ldo->wm831x; 555 int mask = 1 << rdev_get_id(rdev); 556 int ret; 557 558 /* Is the regulator on? */ 559 ret = wm831x_reg_read(wm831x, WM831X_LDO_STATUS); 560 if (ret < 0) 561 return ret; 562 if (ret & mask) 563 return REGULATOR_STATUS_ON; 564 else 565 return REGULATOR_STATUS_OFF; 566 } 567 568 static struct regulator_ops wm831x_alive_ldo_ops = { 569 .list_voltage = regulator_list_voltage_linear, 570 .map_voltage = regulator_map_voltage_linear, 571 .get_voltage_sel = regulator_get_voltage_sel_regmap, 572 .set_voltage_sel = regulator_set_voltage_sel_regmap, 573 .set_suspend_voltage = wm831x_alive_ldo_set_suspend_voltage, 574 .get_status = wm831x_alive_ldo_get_status, 575 576 .is_enabled = regulator_is_enabled_regmap, 577 .enable = regulator_enable_regmap, 578 .disable = regulator_disable_regmap, 579 }; 580 581 static int wm831x_alive_ldo_probe(struct platform_device *pdev) 582 { 583 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); 584 struct wm831x_pdata *pdata = dev_get_platdata(wm831x->dev); 585 struct regulator_config config = { }; 586 int id; 587 struct wm831x_ldo *ldo; 588 struct resource *res; 589 int ret; 590 591 if (pdata && pdata->wm831x_num) 592 id = (pdata->wm831x_num * 10) + 1; 593 else 594 id = 0; 595 id = pdev->id - id; 596 597 598 dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); 599 600 ldo = devm_kzalloc(&pdev->dev, sizeof(struct wm831x_ldo), GFP_KERNEL); 601 if (ldo == NULL) { 602 dev_err(&pdev->dev, "Unable to allocate private data\n"); 603 return -ENOMEM; 604 } 605 606 ldo->wm831x = wm831x; 607 608 res = platform_get_resource(pdev, IORESOURCE_REG, 0); 609 if (res == NULL) { 610 dev_err(&pdev->dev, "No REG resource\n"); 611 ret = -EINVAL; 612 goto err; 613 } 614 ldo->base = res->start; 615 616 snprintf(ldo->name, sizeof(ldo->name), "LDO%d", id + 1); 617 ldo->desc.name = ldo->name; 618 619 snprintf(ldo->supply_name, sizeof(ldo->supply_name), 620 "LDO%dVDD", id + 1); 621 ldo->desc.supply_name = ldo->supply_name; 622 623 ldo->desc.id = id; 624 ldo->desc.type = REGULATOR_VOLTAGE; 625 ldo->desc.n_voltages = WM831X_ALIVE_LDO_MAX_SELECTOR + 1; 626 ldo->desc.ops = &wm831x_alive_ldo_ops; 627 ldo->desc.owner = THIS_MODULE; 628 ldo->desc.vsel_reg = ldo->base + WM831X_ALIVE_LDO_ON_CONTROL; 629 ldo->desc.vsel_mask = WM831X_LDO11_ON_VSEL_MASK; 630 ldo->desc.enable_reg = WM831X_LDO_ENABLE; 631 ldo->desc.enable_mask = 1 << id; 632 ldo->desc.min_uV = 800000; 633 ldo->desc.uV_step = 50000; 634 ldo->desc.enable_time = 1000; 635 636 config.dev = pdev->dev.parent; 637 if (pdata) 638 config.init_data = pdata->ldo[id]; 639 config.driver_data = ldo; 640 config.regmap = wm831x->regmap; 641 642 ldo->regulator = devm_regulator_register(&pdev->dev, &ldo->desc, 643 &config); 644 if (IS_ERR(ldo->regulator)) { 645 ret = PTR_ERR(ldo->regulator); 646 dev_err(wm831x->dev, "Failed to register LDO%d: %d\n", 647 id + 1, ret); 648 goto err; 649 } 650 651 platform_set_drvdata(pdev, ldo); 652 653 return 0; 654 655 err: 656 return ret; 657 } 658 659 static struct platform_driver wm831x_alive_ldo_driver = { 660 .probe = wm831x_alive_ldo_probe, 661 .driver = { 662 .name = "wm831x-alive-ldo", 663 .owner = THIS_MODULE, 664 }, 665 }; 666 667 static int __init wm831x_ldo_init(void) 668 { 669 int ret; 670 671 ret = platform_driver_register(&wm831x_gp_ldo_driver); 672 if (ret != 0) 673 pr_err("Failed to register WM831x GP LDO driver: %d\n", ret); 674 675 ret = platform_driver_register(&wm831x_aldo_driver); 676 if (ret != 0) 677 pr_err("Failed to register WM831x ALDO driver: %d\n", ret); 678 679 ret = platform_driver_register(&wm831x_alive_ldo_driver); 680 if (ret != 0) 681 pr_err("Failed to register WM831x alive LDO driver: %d\n", 682 ret); 683 684 return 0; 685 } 686 subsys_initcall(wm831x_ldo_init); 687 688 static void __exit wm831x_ldo_exit(void) 689 { 690 platform_driver_unregister(&wm831x_alive_ldo_driver); 691 platform_driver_unregister(&wm831x_aldo_driver); 692 platform_driver_unregister(&wm831x_gp_ldo_driver); 693 } 694 module_exit(wm831x_ldo_exit); 695 696 /* Module information */ 697 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); 698 MODULE_DESCRIPTION("WM831x LDO driver"); 699 MODULE_LICENSE("GPL"); 700 MODULE_ALIAS("platform:wm831x-ldo"); 701 MODULE_ALIAS("platform:wm831x-aldo"); 702 MODULE_ALIAS("platform:wm831x-aliveldo"); 703