* device type in apple-mfi-fastcharfe
@ 2022-04-07 10:40 Oliver Neukum
2022-04-07 11:05 ` Bastien Nocera
0 siblings, 1 reply; 4+ messages in thread
From: Oliver Neukum @ 2022-04-07 10:40 UTC (permalink / raw)
To: hadess; +Cc: USB list
[-- Attachment #1: Type: text/plain, Size: 424 bytes --]
Hi,
looking at this bug report:
https://bugzilla.kernel.org/show_bug.cgi?id=215799
I had an occasion to look at the way it registers the charger.
In particular:
.type = POWER_SUPPLY_TYPE_BATTERY,
That seems kind of wrong. It does not contain a battery, does it? The
type seems to confound user space. Is there some deeper reason? If not
how about the attached patch? Regards Oliver
[-- Attachment #2: 0001-apple-mfi-fastcharge-correct-type.patch --]
[-- Type: text/x-patch, Size: 1100 bytes --]
From e1e7805585a979f74ba86a407ca8246a51c47a97 Mon Sep 17 00:00:00 2001
From: Oliver Neukum <oneukum@suse.com>
Date: Tue, 5 Apr 2022 11:40:39 +0200
Subject: [PATCH] apple-mfi-fastcharge: correct type
This is a charger, not a battery.
Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
drivers/usb/misc/apple-mfi-fastcharge.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/misc/apple-mfi-fastcharge.c b/drivers/usb/misc/apple-mfi-fastcharge.c
index ac8695195c13..b8b394df622f 100644
--- a/drivers/usb/misc/apple-mfi-fastcharge.c
+++ b/drivers/usb/misc/apple-mfi-fastcharge.c
@@ -157,7 +157,7 @@ static enum power_supply_property apple_mfi_fc_properties[] = {
static const struct power_supply_desc apple_mfi_fc_desc = {
.name = "apple_mfi_fastcharge",
- .type = POWER_SUPPLY_TYPE_BATTERY,
+ .type = POWER_SUPPLY_TYPE_USB,
.properties = apple_mfi_fc_properties,
.num_properties = ARRAY_SIZE(apple_mfi_fc_properties),
.get_property = apple_mfi_fc_get_property,
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: device type in apple-mfi-fastcharfe
2022-04-07 10:40 device type in apple-mfi-fastcharfe Oliver Neukum
@ 2022-04-07 11:05 ` Bastien Nocera
2022-04-07 11:42 ` Benjamin Tissoires
0 siblings, 1 reply; 4+ messages in thread
From: Bastien Nocera @ 2022-04-07 11:05 UTC (permalink / raw)
To: Oliver Neukum, Benjamin Tissoires; +Cc: USB list
On Thu, 2022-04-07 at 12:40 +0200, Oliver Neukum wrote:
> Hi,
>
> looking at this bug report:
>
> https://bugzilla.kernel.org/show_bug.cgi?id=215799
>
> I had an occasion to look at the way it registers the charger.
> In particular:
> .type = POWER_SUPPLY_TYPE_BATTERY,
>
> That seems kind of wrong. It does not contain a battery, does it? The
> type seems to confound user space. Is there some deeper reason? If
> not
> how about the attached patch? Regards Oliver
The "apple-mfi-fastcharge" driver gets registered for a lot of Apple
iOS devices plugged in through USB, and those devices definitely
contain a battery.
I'm going to hazard a guess that the script in question doesn't check
the power_supply "scope" property, which means it thinks any battery
plugged in to the machine is a battery that powers the machine. That's
not the case.
POWER_SUPPLY_TYPE_USB also seems to only be used by USB ports[1] that
are used to charge the machine itself (so a "system" scope), like the
USB port on a phone, not for devices connected through USB (of which
there are a lot).
[1]: Except for drivers/hid/wacom_sys.c, which looks incorrect
Benjamin, so this?
diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
index 066c567dbaa2..620fe74f5676 100644
--- a/drivers/hid/wacom_sys.c
+++ b/drivers/hid/wacom_sys.c
@@ -1777,7 +1777,7 @@ static int __wacom_initialize_battery(struct
wacom *wacom,
bat_desc->get_property = wacom_battery_get_property;
sprintf(battery->bat_name, "wacom_battery_%ld", n);
bat_desc->name = battery->bat_name;
- bat_desc->type = POWER_SUPPLY_TYPE_USB;
+ bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;
bat_desc->use_for_apm = 0;
ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg);
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: device type in apple-mfi-fastcharfe
2022-04-07 11:05 ` Bastien Nocera
@ 2022-04-07 11:42 ` Benjamin Tissoires
2022-04-07 11:54 ` Bastien Nocera
0 siblings, 1 reply; 4+ messages in thread
From: Benjamin Tissoires @ 2022-04-07 11:42 UTC (permalink / raw)
To: Bastien Nocera; +Cc: Oliver Neukum, USB list
On Thu, Apr 7, 2022 at 1:05 PM Bastien Nocera <hadess@hadess.net> wrote:
>
> On Thu, 2022-04-07 at 12:40 +0200, Oliver Neukum wrote:
> > Hi,
> >
> > looking at this bug report:
> >
> > https://bugzilla.kernel.org/show_bug.cgi?id=215799
> >
> > I had an occasion to look at the way it registers the charger.
> > In particular:
> > .type = POWER_SUPPLY_TYPE_BATTERY,
> >
> > That seems kind of wrong. It does not contain a battery, does it? The
> > type seems to confound user space. Is there some deeper reason? If
> > not
> > how about the attached patch? Regards Oliver
>
> The "apple-mfi-fastcharge" driver gets registered for a lot of Apple
> iOS devices plugged in through USB, and those devices definitely
> contain a battery.
>
> I'm going to hazard a guess that the script in question doesn't check
> the power_supply "scope" property, which means it thinks any battery
> plugged in to the machine is a battery that powers the machine. That's
> not the case.
>
> POWER_SUPPLY_TYPE_USB also seems to only be used by USB ports[1] that
> are used to charge the machine itself (so a "system" scope), like the
> USB port on a phone, not for devices connected through USB (of which
> there are a lot).
>
> [1]: Except for drivers/hid/wacom_sys.c, which looks incorrect
> Benjamin, so this?
If the following patch doesn't break existing userspace and is the
"correct" way of reporting battery, sure, why not.
Cheers,
Benjamin
>
> diff --git a/drivers/hid/wacom_sys.c b/drivers/hid/wacom_sys.c
> index 066c567dbaa2..620fe74f5676 100644
> --- a/drivers/hid/wacom_sys.c
> +++ b/drivers/hid/wacom_sys.c
> @@ -1777,7 +1777,7 @@ static int __wacom_initialize_battery(struct
> wacom *wacom,
> bat_desc->get_property = wacom_battery_get_property;
> sprintf(battery->bat_name, "wacom_battery_%ld", n);
> bat_desc->name = battery->bat_name;
> - bat_desc->type = POWER_SUPPLY_TYPE_USB;
> + bat_desc->type = POWER_SUPPLY_TYPE_BATTERY;
> bat_desc->use_for_apm = 0;
>
> ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: device type in apple-mfi-fastcharfe
2022-04-07 11:42 ` Benjamin Tissoires
@ 2022-04-07 11:54 ` Bastien Nocera
0 siblings, 0 replies; 4+ messages in thread
From: Bastien Nocera @ 2022-04-07 11:54 UTC (permalink / raw)
To: Benjamin Tissoires; +Cc: Oliver Neukum, USB list
On Thu, 2022-04-07 at 13:42 +0200, Benjamin Tissoires wrote:
> If the following patch doesn't break existing userspace and is the
> "correct" way of reporting battery, sure, why not.
Sent as a proper patch to linux-input, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-07 11:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 10:40 device type in apple-mfi-fastcharfe Oliver Neukum
2022-04-07 11:05 ` Bastien Nocera
2022-04-07 11:42 ` Benjamin Tissoires
2022-04-07 11:54 ` Bastien Nocera
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).