Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: ab3100: device tree support

This implements device tree support for the AB3100 regulators
driver. The initial settings are moved out of platform data
and into the driver for the device tree case, as it appears
that there is no way to supply this as AUXDATA for an I2C
device. The style and bindings are heavily inspired by
Lee Jones' style for AB8500.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

Linus Walleij and committed by
Mark Brown
8735bc2f 9b318353

+118 -6
+1
drivers/mfd/ab3100-core.c
··· 753 753 }, 754 754 { 755 755 .name = "ab3100-regulators", 756 + .of_compatible = "stericsson,ab3100-regulators", 756 757 .id = -1, 757 758 }, 758 759 {
+117 -6
drivers/regulator/ab3100.c
··· 17 17 #include <linux/regulator/driver.h> 18 18 #include <linux/mfd/ab3100.h> 19 19 #include <linux/mfd/abx500.h> 20 + #include <linux/of.h> 21 + #include <linux/regulator/of_regulator.h> 20 22 21 23 /* LDO registers and some handy masking definitions for AB3100 */ 22 24 #define AB3100_LDO_A 0x40 ··· 347 345 { 348 346 struct ab3100_regulator *abreg = rdev_get_drvdata(reg); 349 347 350 - return abreg->plfdata->external_voltage; 348 + if (abreg->plfdata) 349 + return abreg->plfdata->external_voltage; 350 + else 351 + /* TODO: encode external voltage into device tree */ 352 + return 0; 351 353 } 352 354 353 355 static struct regulator_ops regulator_ops_fixed = { ··· 496 490 497 491 static int ab3100_regulator_register(struct platform_device *pdev, 498 492 struct ab3100_platform_data *plfdata, 493 + struct regulator_init_data *init_data, 494 + struct device_node *np, 499 495 int id) 500 496 { 501 497 struct regulator_desc *desc; ··· 526 518 */ 527 519 reg->dev = &pdev->dev; 528 520 if (plfdata) { 529 - /* This will be replaced by device tree data */ 530 521 reg->plfdata = plfdata; 531 522 config.init_data = &plfdata->reg_constraints[i]; 523 + } else if (np) { 524 + config.of_node = np; 525 + config.init_data = init_data; 532 526 } 533 527 config.dev = &pdev->dev; 534 528 config.driver_data = reg; ··· 550 540 return 0; 551 541 } 552 542 543 + static struct of_regulator_match ab3100_regulator_matches[] = { 544 + { .name = "ab3100_ldo_a", .driver_data = (void *) AB3100_LDO_A, }, 545 + { .name = "ab3100_ldo_c", .driver_data = (void *) AB3100_LDO_C, }, 546 + { .name = "ab3100_ldo_d", .driver_data = (void *) AB3100_LDO_D, }, 547 + { .name = "ab3100_ldo_e", .driver_data = (void *) AB3100_LDO_E, }, 548 + { .name = "ab3100_ldo_f", .driver_data = (void *) AB3100_LDO_F }, 549 + { .name = "ab3100_ldo_g", .driver_data = (void *) AB3100_LDO_G }, 550 + { .name = "ab3100_ldo_h", .driver_data = (void *) AB3100_LDO_H }, 551 + { .name = "ab3100_ldo_k", .driver_data = (void *) AB3100_LDO_K }, 552 + { .name = "ab3100_ext", .driver_data = (void *) AB3100_LDO_EXT }, 553 + { .name = "ab3100_buck", .driver_data = (void *) AB3100_BUCK }, 554 + }; 555 + 553 556 /* 554 - * NOTE: the following functions are regulators pluralis - it is the 555 - * binding to the AB3100 core driver and the parent platform device 556 - * for all the different regulators. 557 + * Initial settings of ab3100 registers. 558 + * Common for below LDO regulator settings are that 559 + * bit 7-5 controls voltage. Bit 4 turns regulator ON(1) or OFF(0). 560 + * Bit 3-2 controls sleep enable and bit 1-0 controls sleep mode. 557 561 */ 562 + /* LDO_A 0x16: 2.75V, ON, SLEEP_A, SLEEP OFF GND */ 563 + #define LDO_A_SETTING 0x16 564 + /* LDO_C 0x10: 2.65V, ON, SLEEP_A or B, SLEEP full power */ 565 + #define LDO_C_SETTING 0x10 566 + /* LDO_D 0x10: 2.65V, ON, sleep mode not used */ 567 + #define LDO_D_SETTING 0x10 568 + /* LDO_E 0x10: 1.8V, ON, SLEEP_A or B, SLEEP full power */ 569 + #define LDO_E_SETTING 0x10 570 + /* LDO_E SLEEP 0x00: 1.8V, not used, SLEEP_A or B, not used */ 571 + #define LDO_E_SLEEP_SETTING 0x00 572 + /* LDO_F 0xD0: 2.5V, ON, SLEEP_A or B, SLEEP full power */ 573 + #define LDO_F_SETTING 0xD0 574 + /* LDO_G 0x00: 2.85V, OFF, SLEEP_A or B, SLEEP full power */ 575 + #define LDO_G_SETTING 0x00 576 + /* LDO_H 0x18: 2.75V, ON, SLEEP_B, SLEEP full power */ 577 + #define LDO_H_SETTING 0x18 578 + /* LDO_K 0x00: 2.75V, OFF, SLEEP_A or B, SLEEP full power */ 579 + #define LDO_K_SETTING 0x00 580 + /* LDO_EXT 0x00: Voltage not set, OFF, not used, not used */ 581 + #define LDO_EXT_SETTING 0x00 582 + /* BUCK 0x7D: 1.2V, ON, SLEEP_A and B, SLEEP low power */ 583 + #define BUCK_SETTING 0x7D 584 + /* BUCK SLEEP 0xAC: 1.05V, Not used, SLEEP_A and B, Not used */ 585 + #define BUCK_SLEEP_SETTING 0xAC 586 + 587 + static const u8 ab3100_reg_initvals[] = { 588 + LDO_A_SETTING, 589 + LDO_C_SETTING, 590 + LDO_E_SETTING, 591 + LDO_E_SLEEP_SETTING, 592 + LDO_F_SETTING, 593 + LDO_G_SETTING, 594 + LDO_H_SETTING, 595 + LDO_K_SETTING, 596 + LDO_EXT_SETTING, 597 + BUCK_SETTING, 598 + BUCK_SLEEP_SETTING, 599 + LDO_D_SETTING, 600 + }; 601 + 602 + static int 603 + ab3100_regulator_of_probe(struct platform_device *pdev, struct device_node *np) 604 + { 605 + int err, i; 606 + 607 + /* 608 + * Set up the regulator registers, as was previously done with 609 + * platform data. 610 + */ 611 + /* Set up regulators */ 612 + for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) { 613 + err = abx500_set_register_interruptible(&pdev->dev, 0, 614 + ab3100_reg_init_order[i], 615 + ab3100_reg_initvals[i]); 616 + if (err) { 617 + dev_err(&pdev->dev, "regulator initialization failed with error %d\n", 618 + err); 619 + return err; 620 + } 621 + } 622 + 623 + for (i = 0; i < ARRAY_SIZE(ab3100_regulator_matches); i++) { 624 + err = ab3100_regulator_register( 625 + pdev, NULL, ab3100_regulator_matches[i].init_data, 626 + ab3100_regulator_matches[i].of_node, 627 + (int) ab3100_regulator_matches[i].driver_data); 628 + if (err) 629 + return err; 630 + } 631 + 632 + return 0; 633 + } 634 + 558 635 559 636 static int ab3100_regulators_probe(struct platform_device *pdev) 560 637 { 561 638 struct ab3100_platform_data *plfdata = pdev->dev.platform_data; 639 + struct device_node *np = pdev->dev.of_node; 562 640 int err = 0; 563 641 u8 data; 564 642 int i; ··· 665 567 dev_notice(&pdev->dev, 666 568 "chip is in inactive mode (Cold start)\n"); 667 569 570 + if (np) { 571 + err = of_regulator_match(&pdev->dev, np, 572 + ab3100_regulator_matches, 573 + ARRAY_SIZE(ab3100_regulator_matches)); 574 + if (err < 0) { 575 + dev_err(&pdev->dev, 576 + "Error parsing regulator init data: %d\n", err); 577 + return err; 578 + } 579 + return ab3100_regulator_of_probe(pdev, np); 580 + } 581 + 668 582 /* Set up regulators */ 669 583 for (i = 0; i < ARRAY_SIZE(ab3100_reg_init_order); i++) { 670 584 err = abx500_set_register_interruptible(&pdev->dev, 0, ··· 693 583 for (i = 0; i < AB3100_NUM_REGULATORS; i++) { 694 584 struct regulator_desc *desc = &ab3100_regulator_desc[i]; 695 585 696 - err = ab3100_regulator_register(pdev, plfdata, desc->id); 586 + err = ab3100_regulator_register(pdev, plfdata, NULL, NULL, 587 + desc->id); 697 588 if (err) 698 589 return err; 699 590 }