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

twl4030_charger: Add devicetree support

This allows the charger to be enabled with devicetree, and allows the
parameters for charging the backup battery to be set.

Signed-off-by: NeilBrown <neilb@suse.de>
Acked-by: Kumar Gala <galak@codeaurora.org>
Acked-by: Grant Likely <grant.likely@linaro.org>
Signed-off-by: Anton Vorontsov <anton@enomsg.org>

authored by

NeilBrown and committed by
Anton Vorontsov
ec0b3802 588bd591

+70 -3
+20
Documentation/devicetree/bindings/power/twl-charger.txt
··· 1 + TWL BCI (Battery Charger Interface) 2 + 3 + Required properties: 4 + - compatible: 5 + - "ti,twl4030-bci" 6 + - interrupts: two interrupt lines from the TWL SIH (secondary 7 + interrupt handler) - interrupts 9 and 2. 8 + 9 + Optional properties: 10 + - ti,bb-uvolt: microvolts for charging the backup battery. 11 + - ti,bb-uamp: microamps for charging the backup battery. 12 + 13 + Examples: 14 + 15 + bci { 16 + compatible = "ti,twl4030-bci"; 17 + interrupts = <9>, <2>; 18 + ti,bb-uvolt = <3200000>; 19 + ti,bb-uamp = <150>; 20 + };
+6
arch/arm/boot/dts/twl4030.dtsi
··· 19 19 interrupts = <11>; 20 20 }; 21 21 22 + charger: bci { 23 + compatible = "ti,twl4030-bci"; 24 + interrupts = <9>, <2>; 25 + bci3v1-supply = <&vusb3v1>; 26 + }; 27 + 22 28 watchdog { 23 29 compatible = "ti,twl4030-wdt"; 24 30 };
+44 -3
drivers/power/twl4030_charger.c
··· 495 495 POWER_SUPPLY_PROP_CURRENT_NOW, 496 496 }; 497 497 498 + #ifdef CONFIG_OF 499 + static const struct twl4030_bci_platform_data * 500 + twl4030_bci_parse_dt(struct device *dev) 501 + { 502 + struct device_node *np = dev->of_node; 503 + struct twl4030_bci_platform_data *pdata; 504 + u32 num; 505 + 506 + if (!np) 507 + return NULL; 508 + pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 509 + if (!pdata) 510 + return pdata; 511 + 512 + if (of_property_read_u32(np, "ti,bb-uvolt", &num) == 0) 513 + pdata->bb_uvolt = num; 514 + if (of_property_read_u32(np, "ti,bb-uamp", &num) == 0) 515 + pdata->bb_uamp = num; 516 + return pdata; 517 + } 518 + #else 519 + static inline const struct twl4030_bci_platform_data * 520 + twl4030_bci_parse_dt(struct device *dev) 521 + { 522 + return NULL; 523 + } 524 + #endif 525 + 498 526 static int __init twl4030_bci_probe(struct platform_device *pdev) 499 527 { 500 528 struct twl4030_bci *bci; 501 - struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data; 529 + const struct twl4030_bci_platform_data *pdata = pdev->dev.platform_data; 502 530 int ret; 503 531 u32 reg; 504 532 505 533 bci = kzalloc(sizeof(*bci), GFP_KERNEL); 506 534 if (bci == NULL) 507 535 return -ENOMEM; 536 + 537 + if (!pdata) 538 + pdata = twl4030_bci_parse_dt(&pdev->dev); 508 539 509 540 bci->dev = &pdev->dev; 510 541 bci->irq_chg = platform_get_irq(pdev, 0); ··· 612 581 613 582 twl4030_charger_enable_ac(true); 614 583 twl4030_charger_enable_usb(bci, true); 615 - twl4030_charger_enable_backup(pdata->bb_uvolt, 616 - pdata->bb_uamp); 584 + if (pdata) 585 + twl4030_charger_enable_backup(pdata->bb_uvolt, 586 + pdata->bb_uamp); 587 + else 588 + twl4030_charger_enable_backup(0, 0); 617 589 618 590 return 0; 619 591 ··· 665 631 return 0; 666 632 } 667 633 634 + static const struct of_device_id twl_bci_of_match[] = { 635 + {.compatible = "ti,twl4030-bci", }, 636 + { } 637 + }; 638 + MODULE_DEVICE_TABLE(of, twl_bci_of_match); 639 + 668 640 static struct platform_driver twl4030_bci_driver = { 669 641 .driver = { 670 642 .name = "twl4030_bci", 671 643 .owner = THIS_MODULE, 644 + .of_match_table = of_match_ptr(twl_bci_of_match), 672 645 }, 673 646 .remove = __exit_p(twl4030_bci_remove), 674 647 };