aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/twl4030_charger.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/power/twl4030_charger.c')
-rw-r--r--drivers/power/twl4030_charger.c65
1 files changed, 37 insertions, 28 deletions
diff --git a/drivers/power/twl4030_charger.c b/drivers/power/twl4030_charger.c
index d35b83e635b5..02a522cb7753 100644
--- a/drivers/power/twl4030_charger.c
+++ b/drivers/power/twl4030_charger.c
@@ -87,8 +87,8 @@ MODULE_PARM_DESC(allow_usb, "Allow USB charge drawing default current");
87 87
88struct twl4030_bci { 88struct twl4030_bci {
89 struct device *dev; 89 struct device *dev;
90 struct power_supply ac; 90 struct power_supply *ac;
91 struct power_supply usb; 91 struct power_supply *usb;
92 struct usb_phy *transceiver; 92 struct usb_phy *transceiver;
93 struct notifier_block usb_nb; 93 struct notifier_block usb_nb;
94 struct work_struct work; 94 struct work_struct work;
@@ -318,8 +318,8 @@ static irqreturn_t twl4030_charger_interrupt(int irq, void *arg)
318 struct twl4030_bci *bci = arg; 318 struct twl4030_bci *bci = arg;
319 319
320 dev_dbg(bci->dev, "CHG_PRES irq\n"); 320 dev_dbg(bci->dev, "CHG_PRES irq\n");
321 power_supply_changed(&bci->ac); 321 power_supply_changed(bci->ac);
322 power_supply_changed(&bci->usb); 322 power_supply_changed(bci->usb);
323 323
324 return IRQ_HANDLED; 324 return IRQ_HANDLED;
325} 325}
@@ -347,8 +347,8 @@ static irqreturn_t twl4030_bci_interrupt(int irq, void *arg)
347 347
348 if (irqs1 & (TWL4030_ICHGLOW | TWL4030_ICHGEOC)) { 348 if (irqs1 & (TWL4030_ICHGLOW | TWL4030_ICHGEOC)) {
349 /* charger state change, inform the core */ 349 /* charger state change, inform the core */
350 power_supply_changed(&bci->ac); 350 power_supply_changed(bci->ac);
351 power_supply_changed(&bci->usb); 351 power_supply_changed(bci->usb);
352 } 352 }
353 353
354 /* various monitoring events, for now we just log them here */ 354 /* various monitoring events, for now we just log them here */
@@ -463,7 +463,7 @@ static int twl4030_bci_get_property(struct power_supply *psy,
463 enum power_supply_property psp, 463 enum power_supply_property psp,
464 union power_supply_propval *val) 464 union power_supply_propval *val)
465{ 465{
466 struct twl4030_bci *bci = dev_get_drvdata(psy->dev->parent); 466 struct twl4030_bci *bci = dev_get_drvdata(psy->dev.parent);
467 int is_charging; 467 int is_charging;
468 int state; 468 int state;
469 int ret; 469 int ret;
@@ -472,7 +472,7 @@ static int twl4030_bci_get_property(struct power_supply *psy,
472 if (state < 0) 472 if (state < 0)
473 return state; 473 return state;
474 474
475 if (psy->type == POWER_SUPPLY_TYPE_USB) 475 if (psy->desc->type == POWER_SUPPLY_TYPE_USB)
476 is_charging = state & TWL4030_MSTATEC_USB; 476 is_charging = state & TWL4030_MSTATEC_USB;
477 else 477 else
478 is_charging = state & TWL4030_MSTATEC_AC; 478 is_charging = state & TWL4030_MSTATEC_AC;
@@ -488,7 +488,7 @@ static int twl4030_bci_get_property(struct power_supply *psy,
488 /* charging must be active for meaningful result */ 488 /* charging must be active for meaningful result */
489 if (!is_charging) 489 if (!is_charging)
490 return -ENODATA; 490 return -ENODATA;
491 if (psy->type == POWER_SUPPLY_TYPE_USB) { 491 if (psy->desc->type == POWER_SUPPLY_TYPE_USB) {
492 ret = twl4030bci_read_adc_val(TWL4030_BCIVBUS); 492 ret = twl4030bci_read_adc_val(TWL4030_BCIVBUS);
493 if (ret < 0) 493 if (ret < 0)
494 return ret; 494 return ret;
@@ -558,6 +558,22 @@ twl4030_bci_parse_dt(struct device *dev)
558} 558}
559#endif 559#endif
560 560
561static const struct power_supply_desc twl4030_bci_ac_desc = {
562 .name = "twl4030_ac",
563 .type = POWER_SUPPLY_TYPE_MAINS,
564 .properties = twl4030_charger_props,
565 .num_properties = ARRAY_SIZE(twl4030_charger_props),
566 .get_property = twl4030_bci_get_property,
567};
568
569static const struct power_supply_desc twl4030_bci_usb_desc = {
570 .name = "twl4030_usb",
571 .type = POWER_SUPPLY_TYPE_USB,
572 .properties = twl4030_charger_props,
573 .num_properties = ARRAY_SIZE(twl4030_charger_props),
574 .get_property = twl4030_bci_get_property,
575};
576
561static int __init twl4030_bci_probe(struct platform_device *pdev) 577static int __init twl4030_bci_probe(struct platform_device *pdev)
562{ 578{
563 struct twl4030_bci *bci; 579 struct twl4030_bci *bci;
@@ -584,28 +600,21 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
584 } 600 }
585 601
586 platform_set_drvdata(pdev, bci); 602 platform_set_drvdata(pdev, bci);
587 bci->ac.name = "twl4030_ac";
588 bci->ac.type = POWER_SUPPLY_TYPE_MAINS;
589 bci->ac.properties = twl4030_charger_props;
590 bci->ac.num_properties = ARRAY_SIZE(twl4030_charger_props);
591 bci->ac.get_property = twl4030_bci_get_property;
592 603
593 ret = power_supply_register(&pdev->dev, &bci->ac); 604 bci->ac = power_supply_register(&pdev->dev, &twl4030_bci_ac_desc,
594 if (ret) { 605 NULL);
606 if (IS_ERR(bci->ac)) {
607 ret = PTR_ERR(bci->ac);
595 dev_err(&pdev->dev, "failed to register ac: %d\n", ret); 608 dev_err(&pdev->dev, "failed to register ac: %d\n", ret);
596 goto fail_register_ac; 609 goto fail_register_ac;
597 } 610 }
598 611
599 bci->usb.name = "twl4030_usb";
600 bci->usb.type = POWER_SUPPLY_TYPE_USB;
601 bci->usb.properties = twl4030_charger_props;
602 bci->usb.num_properties = ARRAY_SIZE(twl4030_charger_props);
603 bci->usb.get_property = twl4030_bci_get_property;
604
605 bci->usb_reg = regulator_get(bci->dev, "bci3v1"); 612 bci->usb_reg = regulator_get(bci->dev, "bci3v1");
606 613
607 ret = power_supply_register(&pdev->dev, &bci->usb); 614 bci->usb = power_supply_register(&pdev->dev, &twl4030_bci_usb_desc,
608 if (ret) { 615 NULL);
616 if (IS_ERR(bci->usb)) {
617 ret = PTR_ERR(bci->usb);
609 dev_err(&pdev->dev, "failed to register usb: %d\n", ret); 618 dev_err(&pdev->dev, "failed to register usb: %d\n", ret);
610 goto fail_register_usb; 619 goto fail_register_usb;
611 } 620 }
@@ -670,9 +679,9 @@ fail_unmask_interrupts:
670fail_bci_irq: 679fail_bci_irq:
671 free_irq(bci->irq_chg, bci); 680 free_irq(bci->irq_chg, bci);
672fail_chg_irq: 681fail_chg_irq:
673 power_supply_unregister(&bci->usb); 682 power_supply_unregister(bci->usb);
674fail_register_usb: 683fail_register_usb:
675 power_supply_unregister(&bci->ac); 684 power_supply_unregister(bci->ac);
676fail_register_ac: 685fail_register_ac:
677fail_no_battery: 686fail_no_battery:
678 kfree(bci); 687 kfree(bci);
@@ -700,8 +709,8 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
700 } 709 }
701 free_irq(bci->irq_bci, bci); 710 free_irq(bci->irq_bci, bci);
702 free_irq(bci->irq_chg, bci); 711 free_irq(bci->irq_chg, bci);
703 power_supply_unregister(&bci->usb); 712 power_supply_unregister(bci->usb);
704 power_supply_unregister(&bci->ac); 713 power_supply_unregister(bci->ac);
705 kfree(bci); 714 kfree(bci);
706 715
707 return 0; 716 return 0;