RE: [PATCH v2 3/3] power/supply: Add generic USB charger driver

From: Peter Chen
Date: Mon Dec 16 2019 - 20:33:09 EST



> Le lun., déc. 16, 2019 at 01:24, Peter Chen <peter.chen@xxxxxxx> a écrit :
> >
> >> >> +
> >> >> + desc = &charger->desc;
> >> >> + desc->name = "usb-charger";
> >> >> + desc->properties = usb_charger_properties;
> >> >> + desc->num_properties = ARRAY_SIZE(usb_charger_properties);
> >> >> + desc->get_property = usb_charger_get_property;
> >> >> + desc->type = POWER_SUPPLY_TYPE_USB;
> >> >
> >> > What's your further plan for this generic USB charger?
> >> > To support BC1.2, we need to know charger type, and how we could
> >> get > it?
> >> >
> >> > Peter
> >>
> >> Well I don't really know. The USB role framework does not give any
> >> info about what's plugged.
> >>
> >
> > What's the use case for this patch set? How it be used?
>
> My devicetree:
>
> usb_otg: usb@13440000 {
> compatible = "ingenic,jz4770-musb", "simple-mfd";
> reg = <0x13440000 0x10000>;
> [...]
>
> usb-role-switch;
>
> connector {
> compatible = "gpio-usb-b-connector", "usb-b-connector";
> label = "mini-USB";
> type = "mini";
>
> id-gpios = <&gpf 18 GPIO_ACTIVE_HIGH>;
> vbus-gpios = <&gpb 5 GPIO_ACTIVE_HIGH>;
> [...]
> };
>
> usb_charger: usb-charger {
> compatible = "usb-charger";
> };
> };
>
> The new gpio-usb-connector driver uses the ID/VBUS GPIOs to detect in
> which state (device, host, unconnected) a OTG connector is. However,
> that means I cannot use the standard gpio-charger driver to detect the
> presence of a charger based on the state of the VBUS gpio, since it's
> already requested here. So the point of this patchset is to provide an
> alternative to gpio-charger that works with OTG controllers compatible
> with 'usb-role-switch'.
>

Thanks for explaining it.

What's the user for this USB charger, PMIC or what else? How the user uses
this USB charger interface?

Peter

>
>
> >> >
> >> >> +
> >> >> + charger->charger = devm_power_supply_register(dev, desc,
> >> &cfg);
> >> >> + if (IS_ERR(charger->charger)) {
> >> >> + dev_err(dev, "Unable to register charger");
> >> >> + return PTR_ERR(charger->charger);
> >> >> + }
> >> >> +
> >> >> + err = usb_role_switch_register_notifier(charger->role,
> >> >> &charger->nb);
> >> >> + if (err) {
> >> >> + dev_err(dev, "Unable to register USB role switch notifier");
> >> >> + return err;
> >> >> + }
> >> >> +
> >> >> + return devm_add_action_or_reset(dev, usb_charger_unregister,
> >> >> charger);
> >> >> +}
> >> >> +
> >> >> +static const struct of_device_id usb_charger_of_match[] = {
> >> >> + { .compatible = "usb-charger" },
> >> >> + { /* sentinel */ },
> >> >> +};
> >> >> +MODULE_DEVICE_TABLE(of, usb_charger_of_match); + +static
> >> struct
> >> >> platform_driver usb_charger_driver = {
> >> >> + .driver = {
> >> >> + .name = "usb-charger",
> >> >> + .of_match_table = of_match_ptr(usb_charger_of_match),
> >> >> + },
> >> >> + .probe = usb_charger_probe,
> >> >> +};
> >> >> +module_platform_driver(usb_charger_driver);
> >> >> +
> >> >> +MODULE_DESCRIPTION("Simple USB charger driver");
> >> >> +MODULE_AUTHOR("Paul Cercueil <paul@xxxxxxxxxxxxxxx>");
> >> >> +MODULE_LICENSE("GPL");
> >> >> --
> >> >> 2.24.0
> >> >>
> >> >
> >> > --
> >> >
> >> > Thanks,
> >> > Peter Chen
> >>
> >
>