All of lore.kernel.org
 help / color / mirror / Atom feed
* Power supply detection issue caused by ucsi_psy?
@ 2020-11-09 10:48 Vladimir Yerilov
  2020-11-09 11:20 ` Heikki Krogerus
  0 siblings, 1 reply; 8+ messages in thread
From: Vladimir Yerilov @ 2020-11-09 10:48 UTC (permalink / raw)
  To: linux-usb, Heikki Krogerus, Greg KH

[-- Attachment #1: Type: text/plain, Size: 1389 bytes --]

Good day everyone,

Since linux 5.8 I'm experiencing a problem related to power source
detection on my laptop. My machine is equipped with 2 typec ports, one
of them has power delivery and is used for charging, another one has
only data transfer capability. The issue is, when I unplug the power
cable, the OS is reporting something like "Battery at 100%, plugged in
but still discharging" (KDE Plasma notification) - whether another
port is used or not. I checked with upower, you can see the output for
kernel 5.4 and 5.10 attached. In brief, on 5.8 onwards I have some
"line_power_ucsi_source_psy_USBC000o001" device which is considered a
power supply and that prevents OS to switch to "battery mode" when
unplugging the cable, instead it thinks there's a power source but not
powerful enough to charge the battery, upower says this: "on-battery:
    no", but actually no ac power source is connected.
I did some research with git bisect up to the merge commit
`e611c0fe318c6d6827ee2bba660fbc23cf73f7dc` ("Merge tag 'usb-5.8-rc1'
of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb"), and
looked through its content. My wild guess based on upower output is
that a new driver introduced there, /drivers/usb/typec/ucsi/psy.c, is
responsible for this wrong behavior.

Could you please look into that based on info I'm providing?
Thank you!

-- 
----
Best regards,
Vladimir Yerilov

[-- Attachment #2: upower_5.10.txt --]
[-- Type: text/plain, Size: 2381 bytes --]

Device: /org/freedesktop/UPower/devices/line_power_ADP0
  native-path:          ADP0
  power supply:         yes
  updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              yes
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               SUNWODA
  model:                R15B01W
  serial:               ACFA
  power supply:         yes
  updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              46.198 Wh
    energy-empty:        0 Wh
    energy-full:         46.664 Wh
    energy-full-design:  60.04 Wh
    energy-rate:         2.059 W
    voltage:             8.672 V
    time to full:        13.6 minutes
    percentage:          99%
    capacity:            77.7215%
    technology:          lithium-ion
    icon-name:          'battery-full-charging-symbolic'
  History (charge):
    1604813259	0.000	unknown
  History (rate):
    1604813259	0.000	unknown

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
  native-path:          ucsi-source-psy-USBC000:001
  power supply:         yes
  updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              yes
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               charging
    warning-level:       none
    energy:              46.198 Wh
    energy-full:         46.664 Wh
    energy-rate:         2.059 W
    time to full:        13.6 minutes
    percentage:          99%
    icon-name:          'battery-full-charging-symbolic'

Daemon:
  daemon-version:  0.99.11
  on-battery:      no
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: HybridSleep

[-- Attachment #3: upower_5.10_bat.txt --]
[-- Type: text/plain, Size: 2368 bytes --]

Device: /org/freedesktop/UPower/devices/line_power_ADP0
  native-path:          ADP0
  power supply:         yes
  updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               SUNWODA
  model:                R15B01W
  serial:               ACFA
  power supply:         yes
  updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              46.198 Wh
    energy-empty:        0 Wh
    energy-full:         46.664 Wh
    energy-full-design:  60.04 Wh
    energy-rate:         1.998 W
    voltage:             8.44 V
    time to empty:       23.1 hours
    percentage:          99%
    capacity:            77.7215%
    technology:          lithium-ion
    icon-name:          'battery-full-symbolic'
  History (charge):
    1604813365	99.000	charging
  History (rate):
    1604813365	1.998	charging

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
  native-path:          ucsi-source-psy-USBC000:001
  power supply:         yes
  updated:              Sun 08 Nov 2020 15:27:39 +10 (124 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              yes
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              46.198 Wh
    energy-full:         46.664 Wh
    energy-rate:         1.998 W
    time to empty:       23.1 hours
    percentage:          99%
    icon-name:          'battery-full-symbolic'

Daemon:
  daemon-version:  0.99.11
  on-battery:      no
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: HybridSleep


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Power supply detection issue caused by ucsi_psy?
  2020-11-09 10:48 Power supply detection issue caused by ucsi_psy? Vladimir Yerilov
@ 2020-11-09 11:20 ` Heikki Krogerus
  2020-11-09 11:36   ` Benjamin Berg
  0 siblings, 1 reply; 8+ messages in thread
From: Heikki Krogerus @ 2020-11-09 11:20 UTC (permalink / raw)
  To: Vladimir Yerilov; +Cc: linux-usb, Greg KH, Benjamin Berg

On Mon, Nov 09, 2020 at 08:48:06PM +1000, Vladimir Yerilov wrote:
> Good day everyone,
> 
> Since linux 5.8 I'm experiencing a problem related to power source
> detection on my laptop. My machine is equipped with 2 typec ports, one
> of them has power delivery and is used for charging, another one has
> only data transfer capability. The issue is, when I unplug the power
> cable, the OS is reporting something like "Battery at 100%, plugged in
> but still discharging" (KDE Plasma notification) - whether another
> port is used or not. I checked with upower, you can see the output for
> kernel 5.4 and 5.10 attached. In brief, on 5.8 onwards I have some
> "line_power_ucsi_source_psy_USBC000o001" device which is considered a
> power supply and that prevents OS to switch to "battery mode" when
> unplugging the cable, instead it thinks there's a power source but not
> powerful enough to charge the battery, upower says this: "on-battery:
>     no", but actually no ac power source is connected.
> I did some research with git bisect up to the merge commit
> `e611c0fe318c6d6827ee2bba660fbc23cf73f7dc` ("Merge tag 'usb-5.8-rc1'
> of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb"), and
> looked through its content. My wild guess based on upower output is
> that a new driver introduced there, /drivers/usb/typec/ucsi/psy.c, is
> responsible for this wrong behavior.
> 
> Could you please look into that based on info I'm providing?
> Thank you!

This sounds a bit like the issue that was reported and fixed here:
https://lore.kernel.org/lkml/20201009144047.505957-1-benjamin@sipsolutions.net/

Can you try the two patches from that series?

+Bejamin, who prepared those patches.

> Device: /org/freedesktop/UPower/devices/line_power_ADP0
>   native-path:          ADP0
>   power supply:         yes
>   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds ago)
>   has history:          no
>   has statistics:       no
>   line-power
>     warning-level:       none
>     online:              yes
>     icon-name:          'ac-adapter-symbolic'
> 
> Device: /org/freedesktop/UPower/devices/battery_BAT0
>   native-path:          BAT0
>   vendor:               SUNWODA
>   model:                R15B01W
>   serial:               ACFA
>   power supply:         yes
>   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds ago)
>   has history:          yes
>   has statistics:       yes
>   battery
>     present:             yes
>     rechargeable:        yes
>     state:               charging
>     warning-level:       none
>     energy:              46.198 Wh
>     energy-empty:        0 Wh
>     energy-full:         46.664 Wh
>     energy-full-design:  60.04 Wh
>     energy-rate:         2.059 W
>     voltage:             8.672 V
>     time to full:        13.6 minutes
>     percentage:          99%
>     capacity:            77.7215%
>     technology:          lithium-ion
>     icon-name:          'battery-full-charging-symbolic'
>   History (charge):
>     1604813259	0.000	unknown
>   History (rate):
>     1604813259	0.000	unknown
> 
> Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
>   native-path:          ucsi-source-psy-USBC000:001
>   power supply:         yes
>   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds ago)
>   has history:          no
>   has statistics:       no
>   line-power
>     warning-level:       none
>     online:              yes
>     icon-name:          'ac-adapter-symbolic'
> 
> Device: /org/freedesktop/UPower/devices/DisplayDevice
>   power supply:         yes
>   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds ago)
>   has history:          no
>   has statistics:       no
>   battery
>     present:             yes
>     state:               charging
>     warning-level:       none
>     energy:              46.198 Wh
>     energy-full:         46.664 Wh
>     energy-rate:         2.059 W
>     time to full:        13.6 minutes
>     percentage:          99%
>     icon-name:          'battery-full-charging-symbolic'
> 
> Daemon:
>   daemon-version:  0.99.11
>   on-battery:      no
>   lid-is-closed:   no
>   lid-is-present:  yes
>   critical-action: HybridSleep

> Device: /org/freedesktop/UPower/devices/line_power_ADP0
>   native-path:          ADP0
>   power supply:         yes
>   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds ago)
>   has history:          no
>   has statistics:       no
>   line-power
>     warning-level:       none
>     online:              no
>     icon-name:          'ac-adapter-symbolic'
> 
> Device: /org/freedesktop/UPower/devices/battery_BAT0
>   native-path:          BAT0
>   vendor:               SUNWODA
>   model:                R15B01W
>   serial:               ACFA
>   power supply:         yes
>   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds ago)
>   has history:          yes
>   has statistics:       yes
>   battery
>     present:             yes
>     rechargeable:        yes
>     state:               discharging
>     warning-level:       none
>     energy:              46.198 Wh
>     energy-empty:        0 Wh
>     energy-full:         46.664 Wh
>     energy-full-design:  60.04 Wh
>     energy-rate:         1.998 W
>     voltage:             8.44 V
>     time to empty:       23.1 hours
>     percentage:          99%
>     capacity:            77.7215%
>     technology:          lithium-ion
>     icon-name:          'battery-full-symbolic'
>   History (charge):
>     1604813365	99.000	charging
>   History (rate):
>     1604813365	1.998	charging
> 
> Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
>   native-path:          ucsi-source-psy-USBC000:001
>   power supply:         yes
>   updated:              Sun 08 Nov 2020 15:27:39 +10 (124 seconds ago)
>   has history:          no
>   has statistics:       no
>   line-power
>     warning-level:       none
>     online:              yes
>     icon-name:          'ac-adapter-symbolic'
> 
> Device: /org/freedesktop/UPower/devices/DisplayDevice
>   power supply:         yes
>   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds ago)
>   has history:          no
>   has statistics:       no
>   battery
>     present:             yes
>     state:               discharging
>     warning-level:       none
>     energy:              46.198 Wh
>     energy-full:         46.664 Wh
>     energy-rate:         1.998 W
>     time to empty:       23.1 hours
>     percentage:          99%
>     icon-name:          'battery-full-symbolic'
> 
> Daemon:
>   daemon-version:  0.99.11
>   on-battery:      no
>   lid-is-closed:   no
>   lid-is-present:  yes
>   critical-action: HybridSleep
> 

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Power supply detection issue caused by ucsi_psy?
  2020-11-09 11:20 ` Heikki Krogerus
@ 2020-11-09 11:36   ` Benjamin Berg
  2020-11-09 12:55     ` Vladimir Yerilov
       [not found]     ` <CAB31r6XWQqM-kLYm4vb8H=45grhuwsHDYT94y5QJZVtP8w_sXg@mail.gmail.com>
  0 siblings, 2 replies; 8+ messages in thread
From: Benjamin Berg @ 2020-11-09 11:36 UTC (permalink / raw)
  To: Heikki Krogerus, Vladimir Yerilov; +Cc: linux-usb, Greg KH

[-- Attachment #1: Type: text/plain, Size: 7852 bytes --]

Hi,

On Mon, 2020-11-09 at 13:20 +0200, Heikki Krogerus wrote:
> On Mon, Nov 09, 2020 at 08:48:06PM +1000, Vladimir Yerilov wrote:
> > Since linux 5.8 I'm experiencing a problem related to power source
> > detection on my laptop. My machine is equipped with 2 typec ports, one
> > of them has power delivery and is used for charging, another one has
> > only data transfer capability. The issue is, when I unplug the power
> > cable, the OS is reporting something like "Battery at 100%, plugged in
> > but still discharging" (KDE Plasma notification) - whether another
> > port is used or not. I checked with upower, you can see the output for
> > kernel 5.4 and 5.10 attached. In brief, on 5.8 onwards I have some
> > "line_power_ucsi_source_psy_USBC000o001" device which is considered a
> > power supply and that prevents OS to switch to "battery mode" when
> > unplugging the cable, instead it thinks there's a power source but not
> > powerful enough to charge the battery, upower says this: "on-battery:
> >     no", but actually no ac power source is connected.
> > I did some research with git bisect up to the merge commit
> > `e611c0fe318c6d6827ee2bba660fbc23cf73f7dc` ("Merge tag 'usb-5.8-rc1'
> > of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb"), and
> > looked through its content. My wild guess based on upower output is
> > that a new driver introduced there, /drivers/usb/typec/ucsi/psy.c, is
> > responsible for this wrong behavior.
> > 
> > Could you please look into that based on info I'm providing?
> > Thank you!
> 
> This sounds a bit like the issue that was reported and fixed here:
> https://lore.kernel.org/lkml/20201009144047.505957-1-benjamin@sipsolutions.net/

I agree, sounds very much like the issue I was seeing.

What machine/model are you seeing this on? The PPM is implemented in
Firmware, so the behaviour will depend on the Vendor or even model. I
observed it on a Lenovo laptop, but would be curious to know if similar
issues happen elsewhere.

I only observed an issue when using a thunderbolt dock and not with a
plain USB-C charger.

> Can you try the two patches from that series?

Yeah, that would be a good data point.

Benjamin

> +Bejamin, who prepared those patches.
> 
> > Device: /org/freedesktop/UPower/devices/line_power_ADP0
> >   native-path:          ADP0
> >   power supply:         yes
> >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > ago)
> >   has history:          no
> >   has statistics:       no
> >   line-power
> >     warning-level:       none
> >     online:              yes
> >     icon-name:          'ac-adapter-symbolic'
> > 
> > Device: /org/freedesktop/UPower/devices/battery_BAT0
> >   native-path:          BAT0
> >   vendor:               SUNWODA
> >   model:                R15B01W
> >   serial:               ACFA
> >   power supply:         yes
> >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > ago)
> >   has history:          yes
> >   has statistics:       yes
> >   battery
> >     present:             yes
> >     rechargeable:        yes
> >     state:               charging
> >     warning-level:       none
> >     energy:              46.198 Wh
> >     energy-empty:        0 Wh
> >     energy-full:         46.664 Wh
> >     energy-full-design:  60.04 Wh
> >     energy-rate:         2.059 W
> >     voltage:             8.672 V
> >     time to full:        13.6 minutes
> >     percentage:          99%
> >     capacity:            77.7215%
> >     technology:          lithium-ion
> >     icon-name:          'battery-full-charging-symbolic'
> >   History (charge):
> >     1604813259	0.000	unknown
> >   History (rate):
> >     1604813259	0.000	unknown
> > 
> > Device:
> > /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o
> > 001
> >   native-path:          ucsi-source-psy-USBC000:001
> >   power supply:         yes
> >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > ago)
> >   has history:          no
> >   has statistics:       no
> >   line-power
> >     warning-level:       none
> >     online:              yes
> >     icon-name:          'ac-adapter-symbolic'
> > 
> > Device: /org/freedesktop/UPower/devices/DisplayDevice
> >   power supply:         yes
> >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > ago)
> >   has history:          no
> >   has statistics:       no
> >   battery
> >     present:             yes
> >     state:               charging
> >     warning-level:       none
> >     energy:              46.198 Wh
> >     energy-full:         46.664 Wh
> >     energy-rate:         2.059 W
> >     time to full:        13.6 minutes
> >     percentage:          99%
> >     icon-name:          'battery-full-charging-symbolic'
> > 
> > Daemon:
> >   daemon-version:  0.99.11
> >   on-battery:      no
> >   lid-is-closed:   no
> >   lid-is-present:  yes
> >   critical-action: HybridSleep
> > Device: /org/freedesktop/UPower/devices/line_power_ADP0
> >   native-path:          ADP0
> >   power supply:         yes
> >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > ago)
> >   has history:          no
> >   has statistics:       no
> >   line-power
> >     warning-level:       none
> >     online:              no
> >     icon-name:          'ac-adapter-symbolic'
> > 
> > Device: /org/freedesktop/UPower/devices/battery_BAT0
> >   native-path:          BAT0
> >   vendor:               SUNWODA
> >   model:                R15B01W
> >   serial:               ACFA
> >   power supply:         yes
> >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > ago)
> >   has history:          yes
> >   has statistics:       yes
> >   battery
> >     present:             yes
> >     rechargeable:        yes
> >     state:               discharging
> >     warning-level:       none
> >     energy:              46.198 Wh
> >     energy-empty:        0 Wh
> >     energy-full:         46.664 Wh
> >     energy-full-design:  60.04 Wh
> >     energy-rate:         1.998 W
> >     voltage:             8.44 V
> >     time to empty:       23.1 hours
> >     percentage:          99%
> >     capacity:            77.7215%
> >     technology:          lithium-ion
> >     icon-name:          'battery-full-symbolic'
> >   History (charge):
> >     1604813365	99.000	charging
> >   History (rate):
> >     1604813365	1.998	charging
> > 
> > Device:
> > /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o
> > 001
> >   native-path:          ucsi-source-psy-USBC000:001
> >   power supply:         yes
> >   updated:              Sun 08 Nov 2020 15:27:39 +10 (124 seconds
> > ago)
> >   has history:          no
> >   has statistics:       no
> >   line-power
> >     warning-level:       none
> >     online:              yes
> >     icon-name:          'ac-adapter-symbolic'
> > 
> > Device: /org/freedesktop/UPower/devices/DisplayDevice
> >   power supply:         yes
> >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > ago)
> >   has history:          no
> >   has statistics:       no
> >   battery
> >     present:             yes
> >     state:               discharging
> >     warning-level:       none
> >     energy:              46.198 Wh
> >     energy-full:         46.664 Wh
> >     energy-rate:         1.998 W
> >     time to empty:       23.1 hours
> >     percentage:          99%
> >     icon-name:          'battery-full-symbolic'
> > 
> > Daemon:
> >   daemon-version:  0.99.11
> >   on-battery:      no
> >   lid-is-closed:   no
> >   lid-is-present:  yes
> >   critical-action: HybridSleep
> > 
> 
> thanks,
> 

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Power supply detection issue caused by ucsi_psy?
  2020-11-09 11:36   ` Benjamin Berg
@ 2020-11-09 12:55     ` Vladimir Yerilov
       [not found]     ` <CAB31r6XWQqM-kLYm4vb8H=45grhuwsHDYT94y5QJZVtP8w_sXg@mail.gmail.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Vladimir Yerilov @ 2020-11-09 12:55 UTC (permalink / raw)
  To: Benjamin Berg; +Cc: Heikki Krogerus, linux-usb, Greg KH

Thanks!
Will test as soon as I can.

The machine is Xiaomi laptop, made by Timi Computing, model is TM1701,
firmware is made by Insyde company.

пн, 9 нояб. 2020 г. в 21:36, Benjamin Berg <bberg@redhat.com>:
>
> Hi,
>
> On Mon, 2020-11-09 at 13:20 +0200, Heikki Krogerus wrote:
> > On Mon, Nov 09, 2020 at 08:48:06PM +1000, Vladimir Yerilov wrote:
> > > Since linux 5.8 I'm experiencing a problem related to power source
> > > detection on my laptop. My machine is equipped with 2 typec ports, one
> > > of them has power delivery and is used for charging, another one has
> > > only data transfer capability. The issue is, when I unplug the power
> > > cable, the OS is reporting something like "Battery at 100%, plugged in
> > > but still discharging" (KDE Plasma notification) - whether another
> > > port is used or not. I checked with upower, you can see the output for
> > > kernel 5.4 and 5.10 attached. In brief, on 5.8 onwards I have some
> > > "line_power_ucsi_source_psy_USBC000o001" device which is considered a
> > > power supply and that prevents OS to switch to "battery mode" when
> > > unplugging the cable, instead it thinks there's a power source but not
> > > powerful enough to charge the battery, upower says this: "on-battery:
> > >     no", but actually no ac power source is connected.
> > > I did some research with git bisect up to the merge commit
> > > `e611c0fe318c6d6827ee2bba660fbc23cf73f7dc` ("Merge tag 'usb-5.8-rc1'
> > > of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb"), and
> > > looked through its content. My wild guess based on upower output is
> > > that a new driver introduced there, /drivers/usb/typec/ucsi/psy.c, is
> > > responsible for this wrong behavior.
> > >
> > > Could you please look into that based on info I'm providing?
> > > Thank you!
> >
> > This sounds a bit like the issue that was reported and fixed here:
> > https://lore.kernel.org/lkml/20201009144047.505957-1-benjamin@sipsolutions.net/
>
> I agree, sounds very much like the issue I was seeing.
>
> What machine/model are you seeing this on? The PPM is implemented in
> Firmware, so the behaviour will depend on the Vendor or even model. I
> observed it on a Lenovo laptop, but would be curious to know if similar
> issues happen elsewhere.
>
> I only observed an issue when using a thunderbolt dock and not with a
> plain USB-C charger.
>
> > Can you try the two patches from that series?
>
> Yeah, that would be a good data point.
>
> Benjamin
>
> > +Bejamin, who prepared those patches.
> >
> > > Device: /org/freedesktop/UPower/devices/line_power_ADP0
> > >   native-path:          ADP0
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   line-power
> > >     warning-level:       none
> > >     online:              yes
> > >     icon-name:          'ac-adapter-symbolic'
> > >
> > > Device: /org/freedesktop/UPower/devices/battery_BAT0
> > >   native-path:          BAT0
> > >   vendor:               SUNWODA
> > >   model:                R15B01W
> > >   serial:               ACFA
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > > ago)
> > >   has history:          yes
> > >   has statistics:       yes
> > >   battery
> > >     present:             yes
> > >     rechargeable:        yes
> > >     state:               charging
> > >     warning-level:       none
> > >     energy:              46.198 Wh
> > >     energy-empty:        0 Wh
> > >     energy-full:         46.664 Wh
> > >     energy-full-design:  60.04 Wh
> > >     energy-rate:         2.059 W
> > >     voltage:             8.672 V
> > >     time to full:        13.6 minutes
> > >     percentage:          99%
> > >     capacity:            77.7215%
> > >     technology:          lithium-ion
> > >     icon-name:          'battery-full-charging-symbolic'
> > >   History (charge):
> > >     1604813259      0.000   unknown
> > >   History (rate):
> > >     1604813259      0.000   unknown
> > >
> > > Device:
> > > /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o
> > > 001
> > >   native-path:          ucsi-source-psy-USBC000:001
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   line-power
> > >     warning-level:       none
> > >     online:              yes
> > >     icon-name:          'ac-adapter-symbolic'
> > >
> > > Device: /org/freedesktop/UPower/devices/DisplayDevice
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   battery
> > >     present:             yes
> > >     state:               charging
> > >     warning-level:       none
> > >     energy:              46.198 Wh
> > >     energy-full:         46.664 Wh
> > >     energy-rate:         2.059 W
> > >     time to full:        13.6 minutes
> > >     percentage:          99%
> > >     icon-name:          'battery-full-charging-symbolic'
> > >
> > > Daemon:
> > >   daemon-version:  0.99.11
> > >   on-battery:      no
> > >   lid-is-closed:   no
> > >   lid-is-present:  yes
> > >   critical-action: HybridSleep
> > > Device: /org/freedesktop/UPower/devices/line_power_ADP0
> > >   native-path:          ADP0
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   line-power
> > >     warning-level:       none
> > >     online:              no
> > >     icon-name:          'ac-adapter-symbolic'
> > >
> > > Device: /org/freedesktop/UPower/devices/battery_BAT0
> > >   native-path:          BAT0
> > >   vendor:               SUNWODA
> > >   model:                R15B01W
> > >   serial:               ACFA
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > > ago)
> > >   has history:          yes
> > >   has statistics:       yes
> > >   battery
> > >     present:             yes
> > >     rechargeable:        yes
> > >     state:               discharging
> > >     warning-level:       none
> > >     energy:              46.198 Wh
> > >     energy-empty:        0 Wh
> > >     energy-full:         46.664 Wh
> > >     energy-full-design:  60.04 Wh
> > >     energy-rate:         1.998 W
> > >     voltage:             8.44 V
> > >     time to empty:       23.1 hours
> > >     percentage:          99%
> > >     capacity:            77.7215%
> > >     technology:          lithium-ion
> > >     icon-name:          'battery-full-symbolic'
> > >   History (charge):
> > >     1604813365      99.000  charging
> > >   History (rate):
> > >     1604813365      1.998   charging
> > >
> > > Device:
> > > /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o
> > > 001
> > >   native-path:          ucsi-source-psy-USBC000:001
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (124 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   line-power
> > >     warning-level:       none
> > >     online:              yes
> > >     icon-name:          'ac-adapter-symbolic'
> > >
> > > Device: /org/freedesktop/UPower/devices/DisplayDevice
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   battery
> > >     present:             yes
> > >     state:               discharging
> > >     warning-level:       none
> > >     energy:              46.198 Wh
> > >     energy-full:         46.664 Wh
> > >     energy-rate:         1.998 W
> > >     time to empty:       23.1 hours
> > >     percentage:          99%
> > >     icon-name:          'battery-full-symbolic'
> > >
> > > Daemon:
> > >   daemon-version:  0.99.11
> > >   on-battery:      no
> > >   lid-is-closed:   no
> > >   lid-is-present:  yes
> > >   critical-action: HybridSleep
> > >
> >
> > thanks,
> >



-- 
----
Best regards,
Vladimir Yerilov

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Fwd: Power supply detection issue caused by ucsi_psy?
       [not found]     ` <CAB31r6XWQqM-kLYm4vb8H=45grhuwsHDYT94y5QJZVtP8w_sXg@mail.gmail.com>
@ 2020-11-09 17:02       ` Vladimir Yerilov
  2020-11-10  8:31         ` Heikki Krogerus
  0 siblings, 1 reply; 8+ messages in thread
From: Vladimir Yerilov @ 2020-11-09 17:02 UTC (permalink / raw)
  To: Heikki Krogerus, Greg KH, linux-usb

[-- Attachment #1: Type: text/plain, Size: 9466 bytes --]

Forwarding to y'all.

Just some extra info:
`cat /sys/class/power_supply/ucsi-source-psy-USBC000:001/online` shows
zero when the cable is unplugged, same for
`/sys/class/power_supply/ADP0/online` status, but that means nothing
for upower and all system services considering that there a power
source available and not setting display brightness and other
parameters due to that.
Checked in Ubuntu as well, same situation with their kernel 5.8.


---------- Forwarded message ---------
От: Vladimir Yerilov <openmindead@gmail.com>
Date: вт, 10 нояб. 2020 г. в 01:23
Subject: Re: Power supply detection issue caused by ucsi_psy?
To: Benjamin Berg <bberg@redhat.com>


Hi Benjamin and all,

Unfortunately, these patches had no effect on my side. The OS still
thinks there's some power source called
"/org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001"
when there's actually no cables attached.
I used 5.10-rc3 as base with your patches applied on top of it.

пн, 9 нояб. 2020 г. в 21:36, Benjamin Berg <bberg@redhat.com>:
>
> Hi,
>
> On Mon, 2020-11-09 at 13:20 +0200, Heikki Krogerus wrote:
> > On Mon, Nov 09, 2020 at 08:48:06PM +1000, Vladimir Yerilov wrote:
> > > Since linux 5.8 I'm experiencing a problem related to power source
> > > detection on my laptop. My machine is equipped with 2 typec ports, one
> > > of them has power delivery and is used for charging, another one has
> > > only data transfer capability. The issue is, when I unplug the power
> > > cable, the OS is reporting something like "Battery at 100%, plugged in
> > > but still discharging" (KDE Plasma notification) - whether another
> > > port is used or not. I checked with upower, you can see the output for
> > > kernel 5.4 and 5.10 attached. In brief, on 5.8 onwards I have some
> > > "line_power_ucsi_source_psy_USBC000o001" device which is considered a
> > > power supply and that prevents OS to switch to "battery mode" when
> > > unplugging the cable, instead it thinks there's a power source but not
> > > powerful enough to charge the battery, upower says this: "on-battery:
> > >     no", but actually no ac power source is connected.
> > > I did some research with git bisect up to the merge commit
> > > `e611c0fe318c6d6827ee2bba660fbc23cf73f7dc` ("Merge tag 'usb-5.8-rc1'
> > > of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb"), and
> > > looked through its content. My wild guess based on upower output is
> > > that a new driver introduced there, /drivers/usb/typec/ucsi/psy.c, is
> > > responsible for this wrong behavior.
> > >
> > > Could you please look into that based on info I'm providing?
> > > Thank you!
> >
> > This sounds a bit like the issue that was reported and fixed here:
> > https://lore.kernel.org/lkml/20201009144047.505957-1-benjamin@sipsolutions.net/
>
> I agree, sounds very much like the issue I was seeing.
>
> What machine/model are you seeing this on? The PPM is implemented in
> Firmware, so the behaviour will depend on the Vendor or even model. I
> observed it on a Lenovo laptop, but would be curious to know if similar
> issues happen elsewhere.
>
> I only observed an issue when using a thunderbolt dock and not with a
> plain USB-C charger.
>
> > Can you try the two patches from that series?
>
> Yeah, that would be a good data point.
>
> Benjamin
>
> > +Bejamin, who prepared those patches.
> >
> > > Device: /org/freedesktop/UPower/devices/line_power_ADP0
> > >   native-path:          ADP0
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   line-power
> > >     warning-level:       none
> > >     online:              yes
> > >     icon-name:          'ac-adapter-symbolic'
> > >
> > > Device: /org/freedesktop/UPower/devices/battery_BAT0
> > >   native-path:          BAT0
> > >   vendor:               SUNWODA
> > >   model:                R15B01W
> > >   serial:               ACFA
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > > ago)
> > >   has history:          yes
> > >   has statistics:       yes
> > >   battery
> > >     present:             yes
> > >     rechargeable:        yes
> > >     state:               charging
> > >     warning-level:       none
> > >     energy:              46.198 Wh
> > >     energy-empty:        0 Wh
> > >     energy-full:         46.664 Wh
> > >     energy-full-design:  60.04 Wh
> > >     energy-rate:         2.059 W
> > >     voltage:             8.672 V
> > >     time to full:        13.6 minutes
> > >     percentage:          99%
> > >     capacity:            77.7215%
> > >     technology:          lithium-ion
> > >     icon-name:          'battery-full-charging-symbolic'
> > >   History (charge):
> > >     1604813259      0.000   unknown
> > >   History (rate):
> > >     1604813259      0.000   unknown
> > >
> > > Device:
> > > /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o
> > > 001
> > >   native-path:          ucsi-source-psy-USBC000:001
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   line-power
> > >     warning-level:       none
> > >     online:              yes
> > >     icon-name:          'ac-adapter-symbolic'
> > >
> > > Device: /org/freedesktop/UPower/devices/DisplayDevice
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (97 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   battery
> > >     present:             yes
> > >     state:               charging
> > >     warning-level:       none
> > >     energy:              46.198 Wh
> > >     energy-full:         46.664 Wh
> > >     energy-rate:         2.059 W
> > >     time to full:        13.6 minutes
> > >     percentage:          99%
> > >     icon-name:          'battery-full-charging-symbolic'
> > >
> > > Daemon:
> > >   daemon-version:  0.99.11
> > >   on-battery:      no
> > >   lid-is-closed:   no
> > >   lid-is-present:  yes
> > >   critical-action: HybridSleep
> > > Device: /org/freedesktop/UPower/devices/line_power_ADP0
> > >   native-path:          ADP0
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   line-power
> > >     warning-level:       none
> > >     online:              no
> > >     icon-name:          'ac-adapter-symbolic'
> > >
> > > Device: /org/freedesktop/UPower/devices/battery_BAT0
> > >   native-path:          BAT0
> > >   vendor:               SUNWODA
> > >   model:                R15B01W
> > >   serial:               ACFA
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > > ago)
> > >   has history:          yes
> > >   has statistics:       yes
> > >   battery
> > >     present:             yes
> > >     rechargeable:        yes
> > >     state:               discharging
> > >     warning-level:       none
> > >     energy:              46.198 Wh
> > >     energy-empty:        0 Wh
> > >     energy-full:         46.664 Wh
> > >     energy-full-design:  60.04 Wh
> > >     energy-rate:         1.998 W
> > >     voltage:             8.44 V
> > >     time to empty:       23.1 hours
> > >     percentage:          99%
> > >     capacity:            77.7215%
> > >     technology:          lithium-ion
> > >     icon-name:          'battery-full-symbolic'
> > >   History (charge):
> > >     1604813365      99.000  charging
> > >   History (rate):
> > >     1604813365      1.998   charging
> > >
> > > Device:
> > > /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o
> > > 001
> > >   native-path:          ucsi-source-psy-USBC000:001
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:27:39 +10 (124 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   line-power
> > >     warning-level:       none
> > >     online:              yes
> > >     icon-name:          'ac-adapter-symbolic'
> > >
> > > Device: /org/freedesktop/UPower/devices/DisplayDevice
> > >   power supply:         yes
> > >   updated:              Sun 08 Nov 2020 15:29:25 +10 (18 seconds
> > > ago)
> > >   has history:          no
> > >   has statistics:       no
> > >   battery
> > >     present:             yes
> > >     state:               discharging
> > >     warning-level:       none
> > >     energy:              46.198 Wh
> > >     energy-full:         46.664 Wh
> > >     energy-rate:         1.998 W
> > >     time to empty:       23.1 hours
> > >     percentage:          99%
> > >     icon-name:          'battery-full-symbolic'
> > >
> > > Daemon:
> > >   daemon-version:  0.99.11
> > >   on-battery:      no
> > >   lid-is-closed:   no
> > >   lid-is-present:  yes
> > >   critical-action: HybridSleep
> > >
> >
> > thanks,
> >



--
----
Best regards,
Vladimir Yerilov


-- 
----
Best regards,
Vladimir Yerilov

[-- Attachment #2: upower_5.10_bat.txt --]
[-- Type: text/plain, Size: 2373 bytes --]

Device: /org/freedesktop/UPower/devices/line_power_ADP0
  native-path:          ADP0
  power supply:         yes
  updated:              Tue 10 Nov 2020 01:20:58 +10 (40 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              no
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               SUNWODA
  model:                R15B01W
  serial:               ACFA
  power supply:         yes
  updated:              Tue 10 Nov 2020 01:20:58 +10 (40 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    energy:              46.198 Wh
    energy-empty:        0 Wh
    energy-full:         46.664 Wh
    energy-full-design:  60.04 Wh
    energy-rate:         2.5 W
    voltage:             8.36 V
    time to empty:       18.5 hours
    percentage:          99%
    capacity:            77.7215%
    technology:          lithium-ion
    icon-name:          'battery-full-symbolic'
  History (charge):
    1604935258	99.000	fully-charged
  History (rate):
    1604935258	2.500	fully-charged

Device: /org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
  native-path:          ucsi-source-psy-USBC000:001
  power supply:         yes
  updated:              Tue 10 Nov 2020 01:15:13 +10 (385 seconds ago)
  has history:          no
  has statistics:       no
  line-power
    warning-level:       none
    online:              yes
    icon-name:          'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         yes
  updated:              Tue 10 Nov 2020 01:20:58 +10 (40 seconds ago)
  has history:          no
  has statistics:       no
  battery
    present:             yes
    state:               discharging
    warning-level:       none
    energy:              46.198 Wh
    energy-full:         46.664 Wh
    energy-rate:         2.5 W
    time to empty:       18.5 hours
    percentage:          99%
    icon-name:          'battery-full-symbolic'

Daemon:
  daemon-version:  0.99.11
  on-battery:      no
  lid-is-closed:   no
  lid-is-present:  yes
  critical-action: HybridSleep

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fwd: Power supply detection issue caused by ucsi_psy?
  2020-11-09 17:02       ` Fwd: " Vladimir Yerilov
@ 2020-11-10  8:31         ` Heikki Krogerus
  2020-11-10 10:15           ` Heikki Krogerus
       [not found]           ` <CAB31r6Wq5c7n=Ywdq1KAgRZFemH6Wx2b-9tq46k=ipZrqarmdA@mail.gmail.com>
  0 siblings, 2 replies; 8+ messages in thread
From: Heikki Krogerus @ 2020-11-10  8:31 UTC (permalink / raw)
  To: Vladimir Yerilov; +Cc: Greg KH, linux-usb

[-- Attachment #1: Type: text/plain, Size: 755 bytes --]

Hi Vladimir,

On Tue, Nov 10, 2020 at 03:02:40AM +1000, Vladimir Yerilov wrote:
> Forwarding to y'all.
> 
> Just some extra info:
> `cat /sys/class/power_supply/ucsi-source-psy-USBC000:001/online` shows
> zero when the cable is unplugged, same for
> `/sys/class/power_supply/ADP0/online` status, but that means nothing
> for upower and all system services considering that there a power
> source available and not setting display brightness and other
> parameters due to that.
> Checked in Ubuntu as well, same situation with their kernel 5.8.

Please try to avoid top-posting.

It seems that the ucsi psy does not report any changes. That is one
obvious bug that I can see.

I'm attaching a patch to fix that. Can you give it a try?

thanks,

-- 
heikki

[-- Attachment #2: 0001-usb-typec-ucsi-Send-power-supply-change-notification.patch --]
[-- Type: text/plain, Size: 3186 bytes --]

From 3017dd8d8f9b8bca58d5ac80fff00d7af80e87bd Mon Sep 17 00:00:00 2001
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Date: Tue, 10 Nov 2020 11:25:42 +0300
Subject: [PATCH] usb: typec: ucsi: Send power supply change notifications

When the ucsi power supply goes online/offline, and when the
power levels change, the power supply class needs to be
notified so it can inform the user space.

Fixes: 992a60ed0d5e ("usb: typec: ucsi: register with power_supply class")
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/ucsi/psy.c  | 9 +++++++++
 drivers/usb/typec/ucsi/ucsi.c | 7 ++++++-
 drivers/usb/typec/ucsi/ucsi.h | 2 ++
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
index 26ed0b520749a..571a51e162346 100644
--- a/drivers/usb/typec/ucsi/psy.c
+++ b/drivers/usb/typec/ucsi/psy.c
@@ -238,4 +238,13 @@ void ucsi_unregister_port_psy(struct ucsi_connector *con)
 		return;
 
 	power_supply_unregister(con->psy);
+	con->psy = NULL;
+}
+
+void ucsi_port_psy_changed(struct ucsi_connector *con)
+{
+	if (IS_ERR_OR_NULL(con->psy))
+		return;
+
+	power_supply_changed(con->psy);
 }
diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 758b988ac518a..51a570d40a42e 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -643,8 +643,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
 	role = !!(con->status.flags & UCSI_CONSTAT_PWR_DIR);
 
 	if (con->status.change & UCSI_CONSTAT_POWER_OPMODE_CHANGE ||
-	    con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE)
+	    con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE) {
 		ucsi_pwr_opmode_change(con);
+		ucsi_port_psy_changed(con);
+	}
 
 	if (con->status.change & UCSI_CONSTAT_POWER_DIR_CHANGE) {
 		typec_set_pwr_role(con->port, role);
@@ -674,6 +676,8 @@ static void ucsi_handle_connector_change(struct work_struct *work)
 			ucsi_register_partner(con);
 		else
 			ucsi_unregister_partner(con);
+
+		ucsi_port_psy_changed(con);
 	}
 
 	if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) {
@@ -994,6 +998,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)
 				  !!(con->status.flags & UCSI_CONSTAT_PWR_DIR));
 		ucsi_pwr_opmode_change(con);
 		ucsi_register_partner(con);
+		ucsi_port_psy_changed(con);
 	}
 
 	if (con->partner) {
diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
index cba6f77bea61b..b7a92f2460507 100644
--- a/drivers/usb/typec/ucsi/ucsi.h
+++ b/drivers/usb/typec/ucsi/ucsi.h
@@ -340,9 +340,11 @@ int ucsi_resume(struct ucsi *ucsi);
 #if IS_ENABLED(CONFIG_POWER_SUPPLY)
 int ucsi_register_port_psy(struct ucsi_connector *con);
 void ucsi_unregister_port_psy(struct ucsi_connector *con);
+void ucsi_port_psy_changed(struct ucsi_connector *con);
 #else
 static inline int ucsi_register_port_psy(struct ucsi_connector *con) { return 0; }
 static inline void ucsi_unregister_port_psy(struct ucsi_connector *con) { }
+static inline void ucsi_port_psy_changed(struct ucsi_connector *con) { }
 #endif /* CONFIG_POWER_SUPPLY */
 
 #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: Fwd: Power supply detection issue caused by ucsi_psy?
  2020-11-10  8:31         ` Heikki Krogerus
@ 2020-11-10 10:15           ` Heikki Krogerus
       [not found]           ` <CAB31r6Wq5c7n=Ywdq1KAgRZFemH6Wx2b-9tq46k=ipZrqarmdA@mail.gmail.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2020-11-10 10:15 UTC (permalink / raw)
  To: Vladimir Yerilov, Benjamin Berg; +Cc: Greg KH, linux-usb

+Benjamin

On Tue, Nov 10, 2020 at 10:31:36AM +0200, Heikki Krogerus wrote:
> Hi Vladimir,
> 
> On Tue, Nov 10, 2020 at 03:02:40AM +1000, Vladimir Yerilov wrote:
> > Forwarding to y'all.
> > 
> > Just some extra info:
> > `cat /sys/class/power_supply/ucsi-source-psy-USBC000:001/online` shows
> > zero when the cable is unplugged, same for
> > `/sys/class/power_supply/ADP0/online` status, but that means nothing
> > for upower and all system services considering that there a power
> > source available and not setting display brightness and other
> > parameters due to that.
> > Checked in Ubuntu as well, same situation with their kernel 5.8.
> 
> Please try to avoid top-posting.
> 
> It seems that the ucsi psy does not report any changes. That is one
> obvious bug that I can see.
> 
> I'm attaching a patch to fix that. Can you give it a try?
> 
> thanks,
> 
> -- 
> heikki

> From 3017dd8d8f9b8bca58d5ac80fff00d7af80e87bd Mon Sep 17 00:00:00 2001
> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Date: Tue, 10 Nov 2020 11:25:42 +0300
> Subject: [PATCH] usb: typec: ucsi: Send power supply change notifications
> 
> When the ucsi power supply goes online/offline, and when the
> power levels change, the power supply class needs to be
> notified so it can inform the user space.
> 
> Fixes: 992a60ed0d5e ("usb: typec: ucsi: register with power_supply class")
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  drivers/usb/typec/ucsi/psy.c  | 9 +++++++++
>  drivers/usb/typec/ucsi/ucsi.c | 7 ++++++-
>  drivers/usb/typec/ucsi/ucsi.h | 2 ++
>  3 files changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/ucsi/psy.c b/drivers/usb/typec/ucsi/psy.c
> index 26ed0b520749a..571a51e162346 100644
> --- a/drivers/usb/typec/ucsi/psy.c
> +++ b/drivers/usb/typec/ucsi/psy.c
> @@ -238,4 +238,13 @@ void ucsi_unregister_port_psy(struct ucsi_connector *con)
>  		return;
>  
>  	power_supply_unregister(con->psy);
> +	con->psy = NULL;
> +}
> +
> +void ucsi_port_psy_changed(struct ucsi_connector *con)
> +{
> +	if (IS_ERR_OR_NULL(con->psy))
> +		return;
> +
> +	power_supply_changed(con->psy);
>  }
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 758b988ac518a..51a570d40a42e 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -643,8 +643,10 @@ static void ucsi_handle_connector_change(struct work_struct *work)
>  	role = !!(con->status.flags & UCSI_CONSTAT_PWR_DIR);
>  
>  	if (con->status.change & UCSI_CONSTAT_POWER_OPMODE_CHANGE ||
> -	    con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE)
> +	    con->status.change & UCSI_CONSTAT_POWER_LEVEL_CHANGE) {
>  		ucsi_pwr_opmode_change(con);
> +		ucsi_port_psy_changed(con);
> +	}
>  
>  	if (con->status.change & UCSI_CONSTAT_POWER_DIR_CHANGE) {
>  		typec_set_pwr_role(con->port, role);
> @@ -674,6 +676,8 @@ static void ucsi_handle_connector_change(struct work_struct *work)
>  			ucsi_register_partner(con);
>  		else
>  			ucsi_unregister_partner(con);
> +
> +		ucsi_port_psy_changed(con);
>  	}
>  
>  	if (con->status.change & UCSI_CONSTAT_CAM_CHANGE) {
> @@ -994,6 +998,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)
>  				  !!(con->status.flags & UCSI_CONSTAT_PWR_DIR));
>  		ucsi_pwr_opmode_change(con);
>  		ucsi_register_partner(con);
> +		ucsi_port_psy_changed(con);
>  	}
>  
>  	if (con->partner) {
> diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
> index cba6f77bea61b..b7a92f2460507 100644
> --- a/drivers/usb/typec/ucsi/ucsi.h
> +++ b/drivers/usb/typec/ucsi/ucsi.h
> @@ -340,9 +340,11 @@ int ucsi_resume(struct ucsi *ucsi);
>  #if IS_ENABLED(CONFIG_POWER_SUPPLY)
>  int ucsi_register_port_psy(struct ucsi_connector *con);
>  void ucsi_unregister_port_psy(struct ucsi_connector *con);
> +void ucsi_port_psy_changed(struct ucsi_connector *con);
>  #else
>  static inline int ucsi_register_port_psy(struct ucsi_connector *con) { return 0; }
>  static inline void ucsi_unregister_port_psy(struct ucsi_connector *con) { }
> +static inline void ucsi_port_psy_changed(struct ucsi_connector *con) { }
>  #endif /* CONFIG_POWER_SUPPLY */
>  
>  #if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE)
> -- 
> 2.28.0
> 


-- 
heikki

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Fwd: Power supply detection issue caused by ucsi_psy?
       [not found]           ` <CAB31r6Wq5c7n=Ywdq1KAgRZFemH6Wx2b-9tq46k=ipZrqarmdA@mail.gmail.com>
@ 2020-11-10 10:30             ` Heikki Krogerus
  0 siblings, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2020-11-10 10:30 UTC (permalink / raw)
  To: Vladimir Yerilov; +Cc: Greg KH, Benjamin Berg, linux-usb

On Tue, Nov 10, 2020 at 08:22:31PM +1000, Vladimir Yerilov wrote:
> It worked! You're a wizard sir, thank you!
> :D

Excellent!

+Greg, Benjamin and the list.

> вт, 10 нояб. 2020 г. в 18:31, Heikki Krogerus <heikki.krogerus@linux.intel.com>:
> >
> > Hi Vladimir,
> >
> > On Tue, Nov 10, 2020 at 03:02:40AM +1000, Vladimir Yerilov wrote:
> > > Forwarding to y'all.
> > >
> > > Just some extra info:
> > > `cat /sys/class/power_supply/ucsi-source-psy-USBC000:001/online` shows
> > > zero when the cable is unplugged, same for
> > > `/sys/class/power_supply/ADP0/online` status, but that means nothing
> > > for upower and all system services considering that there a power
> > > source available and not setting display brightness and other
> > > parameters due to that.
> > > Checked in Ubuntu as well, same situation with their kernel 5.8.
> >
> > Please try to avoid top-posting.
> >
> > It seems that the ucsi psy does not report any changes. That is one
> > obvious bug that I can see.
> >
> > I'm attaching a patch to fix that. Can you give it a try?

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-11-10 10:30 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09 10:48 Power supply detection issue caused by ucsi_psy? Vladimir Yerilov
2020-11-09 11:20 ` Heikki Krogerus
2020-11-09 11:36   ` Benjamin Berg
2020-11-09 12:55     ` Vladimir Yerilov
     [not found]     ` <CAB31r6XWQqM-kLYm4vb8H=45grhuwsHDYT94y5QJZVtP8w_sXg@mail.gmail.com>
2020-11-09 17:02       ` Fwd: " Vladimir Yerilov
2020-11-10  8:31         ` Heikki Krogerus
2020-11-10 10:15           ` Heikki Krogerus
     [not found]           ` <CAB31r6Wq5c7n=Ywdq1KAgRZFemH6Wx2b-9tq46k=ipZrqarmdA@mail.gmail.com>
2020-11-10 10:30             ` Heikki Krogerus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.