aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2013-10-31 02:05:50 -0400
committerAnton Vorontsov <anton@enomsg.org>2013-11-13 01:35:45 -0500
commitec0b380245d7b7d4d8e4201facca780a14352cda (patch)
tree3257053e219e8818f2ef2f0d5df89aec8fa49934 /drivers/power
parent588bd5918baca940a52802045f3b388358dc6917 (diff)
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>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/twl4030_charger.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index d98abe911e37..f14108844e1a 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -495,10 +495,38 @@ static enum power_supply_property twl4030_charger_props[] = {
495 POWER_SUPPLY_PROP_CURRENT_NOW, 495 POWER_SUPPLY_PROP_CURRENT_NOW,
496}; 496};
497 497
498#ifdef CONFIG_OF
499static const struct twl4030_bci_platform_data *
500twl4030_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
519static inline const struct twl4030_bci_platform_data *
520twl4030_bci_parse_dt(struct device *dev)
521{
522 return NULL;
523}
524#endif
525
498static int __init twl4030_bci_probe(struct platform_device *pdev) 526static int __init twl4030_bci_probe(struct platform_device *pdev)
499{ 527{
500 struct twl4030_bci *bci; 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 int ret; 530 int ret;
503 u32 reg; 531 u32 reg;
504 532
@@ -506,6 +534,9 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
506 if (bci == NULL) 534 if (bci == NULL)
507 return -ENOMEM; 535 return -ENOMEM;
508 536
537 if (!pdata)
538 pdata = twl4030_bci_parse_dt(&pdev->dev);
539
509 bci->dev = &pdev->dev; 540 bci->dev = &pdev->dev;
510 bci->irq_chg = platform_get_irq(pdev, 0); 541 bci->irq_chg = platform_get_irq(pdev, 0);
511 bci->irq_bci = platform_get_irq(pdev, 1); 542 bci->irq_bci = platform_get_irq(pdev, 1);
@@ -581,8 +612,11 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
581 612
582 twl4030_charger_enable_ac(true); 613 twl4030_charger_enable_ac(true);
583 twl4030_charger_enable_usb(bci, true); 614 twl4030_charger_enable_usb(bci, true);
584 twl4030_charger_enable_backup(pdata->bb_uvolt, 615 if (pdata)
585 pdata->bb_uamp); 616 twl4030_charger_enable_backup(pdata->bb_uvolt,
617 pdata->bb_uamp);
618 else
619 twl4030_charger_enable_backup(0, 0);
586 620
587 return 0; 621 return 0;
588 622
@@ -631,10 +665,17 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
631 return 0; 665 return 0;
632} 666}
633 667
668static const struct of_device_id twl_bci_of_match[] = {
669 {.compatible = "ti,twl4030-bci", },
670 { }
671};
672MODULE_DEVICE_TABLE(of, twl_bci_of_match);
673
634static struct platform_driver twl4030_bci_driver = { 674static struct platform_driver twl4030_bci_driver = {
635 .driver = { 675 .driver = {
636 .name = "twl4030_bci", 676 .name = "twl4030_bci",
637 .owner = THIS_MODULE, 677 .owner = THIS_MODULE,
678 .of_match_table = of_match_ptr(twl_bci_of_match),
638 }, 679 },
639 .remove = __exit_p(twl4030_bci_remove), 680 .remove = __exit_p(twl4030_bci_remove),
640}; 681};