Skip to content

Commit f5e4edb

Browse files
neilbrownFelipe Balbi
authored andcommitted
power: twl4030_charger: find associated phy by more reliable means.
twl4030_charger currently finds the associated phy using usb_get_phy() which will return the first USB2 phy. If your platform has multiple such phys (as mine does), this is not reliable (and reliably fails on the GTA04). Change to use devm_usb_get_phy_by_node(), having found the node by looking for an appropriately named sibling in device-tree. This makes usb-charging dependent on correct device-tree configuration. Acked-By: Sebastian Reichel <sre@kernel.org> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Felipe Balbi <balbi@ti.com>
1 parent e842b84 commit f5e4edb

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

Documentation/devicetree/bindings/power/twl-charger.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
TWL BCI (Battery Charger Interface)
22

3+
The battery charger needs to interact with the USB phy in order
4+
to know when charging is permissible, and when there is a connection
5+
or disconnection.
6+
7+
The choice of phy cannot be configured at a hardware level, so there
8+
is no value in explicit configuration in device-tree. Rather
9+
if there is a sibling of the BCI node which is compatible with
10+
"ti,twl4030-usb", then that is used to determine when and how
11+
use USB power for charging.
12+
313
Required properties:
414
- compatible:
515
- "ti,twl4030-bci"

Documentation/devicetree/bindings/usb/twlxxxx-usb.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ TWL4030 USB PHY AND COMPARATOR
3030
- usb_mode : The mode used by the phy to connect to the controller. "1"
3131
specifies "ULPI" mode and "2" specifies "CEA2011_3PIN" mode.
3232

33+
If a sibling node is compatible "ti,twl4030-bci", then it will find
34+
this device and query it for USB power status.
35+
3336
twl4030-usb {
3437
compatible = "ti,twl4030-usb";
3538
interrupts = < 10 4 >;

drivers/power/twl4030_charger.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,15 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
638638

639639
INIT_WORK(&bci->work, twl4030_bci_usb_work);
640640

641-
bci->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
642-
if (!IS_ERR_OR_NULL(bci->transceiver)) {
643-
bci->usb_nb.notifier_call = twl4030_bci_usb_ncb;
644-
usb_register_notifier(bci->transceiver, &bci->usb_nb);
641+
bci->usb_nb.notifier_call = twl4030_bci_usb_ncb;
642+
if (bci->dev->of_node) {
643+
struct device_node *phynode;
644+
645+
phynode = of_find_compatible_node(bci->dev->of_node->parent,
646+
NULL, "ti,twl4030-usb");
647+
if (phynode)
648+
bci->transceiver = devm_usb_get_phy_by_node(
649+
bci->dev, phynode, &bci->usb_nb);
645650
}
646651

647652
/* Enable interrupts now. */
@@ -671,10 +676,6 @@ static int __init twl4030_bci_probe(struct platform_device *pdev)
671676
return 0;
672677

673678
fail_unmask_interrupts:
674-
if (!IS_ERR_OR_NULL(bci->transceiver)) {
675-
usb_unregister_notifier(bci->transceiver, &bci->usb_nb);
676-
usb_put_phy(bci->transceiver);
677-
}
678679
free_irq(bci->irq_bci, bci);
679680
fail_bci_irq:
680681
free_irq(bci->irq_chg, bci);
@@ -703,10 +704,6 @@ static int __exit twl4030_bci_remove(struct platform_device *pdev)
703704
twl_i2c_write_u8(TWL4030_MODULE_INTERRUPTS, 0xff,
704705
TWL4030_INTERRUPTS_BCIIMR2A);
705706

706-
if (!IS_ERR_OR_NULL(bci->transceiver)) {
707-
usb_unregister_notifier(bci->transceiver, &bci->usb_nb);
708-
usb_put_phy(bci->transceiver);
709-
}
710707
free_irq(bci->irq_bci, bci);
711708
free_irq(bci->irq_chg, bci);
712709
power_supply_unregister(bci->usb);

0 commit comments

Comments
 (0)