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

From: Paul Cercueil
Date: Sat Jul 25 2020 - 13:51:26 EST


Hi Greg,

Le mar. 21 juil. 2020 à 13:41, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> a écrit :
On Mon, Jun 22, 2020 at 12:48:07AM +0200, Paul Cercueil 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.

Signed-off-by: Paul Cercueil <paul@xxxxxxxxxxxxxxx>
---
drivers/usb/common/Kconfig | 11 +++++++
drivers/usb/common/usb-conn-gpio.c | 47 ++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)

diff --git a/drivers/usb/common/Kconfig b/drivers/usb/common/Kconfig
index d611477aae41..5405ae96c68f 100644
--- a/drivers/usb/common/Kconfig
+++ b/drivers/usb/common/Kconfig
@@ -49,3 +49,14 @@ config USB_CONN_GPIO

To compile the driver as a module, choose M here: the module will
be called usb-conn-gpio.ko
+
+if USB_CONN_GPIO
+
+config USB_CONN_GPIO_CHARGER
+ bool "USB charger support"
+ select POWER_SUPPLY
+ help
+ Register a charger with the power supply subsystem. This will allow
+ userspace to know whether or not the device is charging from USB.

Why make this an option at all? Why wouldn't we always want this here?

As this is a charger, exporting that information to userspace should
probably always happen, right?

I wanted to avoid the hardcoded dependency on CONFIG_POWER_SUPPLY.

I can very well make that non-optional.

Cheers,
-Paul

thanks,

greg k-h