Re: [RESEND PATCH] usb: common: usb-conn-gpio: Register optional charger

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2020-07-27 at 17:02 +0200, Paul Cercueil wrote:
> 
> Le lun. 27 juil. 2020 à 13:42, Chunfeng Yun 
> <chunfeng.yun@xxxxxxxxxxxx> a écrit :
> > On Sun, 2020-07-26 at 12:27 +0200, Paul Cercueil wrote:
> >> 
> >>  Le dim. 26 juil. 2020 à 13:14, Andy Shevchenko
> >>  <andy.shevchenko@xxxxxxxxx> a écrit :
> >>  > On Mon, Jun 22, 2020 at 1:51 AM Paul Cercueil 
> >> <paul@xxxxxxxxxxxxxxx>
> >>  > wrote:
> >>  >>
> >>  >>  Register a power supply charger, if the Kconfig option
> >>  >>  USB_CONN_GPIO_CHARGER is set, whose online state depends on 
> >> whether
> >>  >>  the USB role is set to device or not.
> >>  >>
> >>  >>  This is useful when the USB role is the only way to know if the
> >>  >> device
> >>  >>  is charging from USB. The API is the standard power supply 
> >> charger
> >>  >> API,
> >>  >>  you get a /sys/class/power_supply/xxx/online node which tells 
> >> you
> >>  >> the
> >>  >>  state of the charger.
> >>  >>
> >>  >>  The sole purpose of this is to give userspace applications a 
> >> way to
> >>  >>  know whether or not the charger is plugged.
[...]
> >>  >>  +       switch (psp) {
> >>  >>  +       case POWER_SUPPLY_PROP_ONLINE:
> >>  >>  +               val->intval = info->last_role == 
> >> USB_ROLE_DEVICE;
> > What will happen if you not change info->last_role here?
> > I prefer it's only changed by usb_conn_isr(), if it's changed by other
> > drivers, for example, through power_supply_get_property(), may skip 
> > role
> > switch.
> 
> If you read carefully, info->last_role is not modified here :)
Sorry, my bad

> 
> -Paul
> 
> > 
> >>  >>  +               break;
> >>  >>  +       default:
> >>  >>  +               return -EINVAL;
> >>  >>  +       }
> >>  >>  +
> >>  >>  +       return 0;
> >>  >>  +}
> >>  >>  +
> >>  >>   static int usb_conn_probe(struct platform_device *pdev)
> >>  >>   {
> >>  >>          struct device *dev = &pdev->dev;
> >>  >>  +       struct power_supply_desc *desc;
> >>  >>          struct usb_conn_info *info;
> >>  >>  +       struct power_supply_config cfg = {
> >>  >>  +               .of_node = dev->of_node,
> >>  >>  +       };
> >>  >>          int ret = 0;
> >>  >>
> >>  >>          info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL);
> >>  >>  @@ -203,6 +234,22 @@ static int usb_conn_probe(struct
> >>  >> platform_device *pdev)
> >>  >>                  }
> >>  >>          }
> >>  >>
> >>  >>  +       if (IS_ENABLED(CONFIG_USB_CONN_GPIO_CHARGER)) {
> >>  >>  +               desc = &info->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;
> >>  >>  +               cfg.drv_data = info;
> >>  >>  +
> >>  >>  +               info->charger = devm_power_supply_register(dev,
> >>  >> desc, &cfg);
> >>  >>  +               if (IS_ERR(info->charger)) {
> >>  >>  +                       dev_err(dev, "Unable to register
> >>  >> charger\n");
> >>  >>  +                       return PTR_ERR(info->charger);
> >>  >>  +               }
> >>  >>  +       }
> >>  >>  +
> >>  >>          platform_set_drvdata(pdev, info);
> >>  >>
> >>  >>          /* Perform initial detection */
> >>  >>  --
> >>  >>  2.27.0
> >>  >>
> >>  >
> >>  >
> >>  > --
> >>  > With Best Regards,
> >>  > Andy Shevchenko
> >> 
> >> 
> > 
> 
> 





[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux