Bug 1216806

Summary: [aarch64][LenovoX13s] [power supply] Battery percentage is always 0%
Product: [openSUSE] openSUSE Tumbleweed Reporter: Chester Lin <chester.lin>
Component: KernelAssignee: Guillaume GARDET <guillaume.gardet>
Status: IN_PROGRESS --- QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: afaerber, andrea.porta, deafening_trough502, guillaume.gardet, ivan.ivanov, jlee, mbenes, mbrugger, stanimir.varbanov, tiwai
Version: Current   
Target Milestone: ---   
Hardware: aarch64   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: battery_fail.png
batt_ok.png

Description Chester Lin 2023-11-02 08:19:29 UTC
Created attachment 870581 [details]
battery_fail.png

Tested ISO: openSUSE-Tumbleweed-DVD-aarch64-Snapshot20231029-Media.iso
Link: https://download.opensuse.org/ports/aarch64/tumbleweed/iso/openSUSE-Tumbleweed-DVD-aarch64-Current.iso

Install steps: https://en.opensuse.org/HCL:ThinkpadX13s#ISO_Installation

Symptom:
When booting to the installed tumbleweed, the battery percentage is not able to be measured so it always shows 0% (See attached screenshot). In the meanwhile, the readings dumped by the 'upower' command are all zero.
Comment 1 Chester Lin 2023-11-02 08:35:08 UTC
Created attachment 870584 [details]
batt_ok.png

By tracing the QCOM battery driver [qcom_battmgr.c], I realized that the qcom_battmgr driver needs a notification from the pdr_interface in order to activate the battery measurement, which should be the way originated from the Android systems running on Qualcomm's mobile application processors.

To solve this issue, we will need a net/qrtr[1] lib and a pd-mapper[2][3] program running in userspace in order to trigger the event required by the battery sensor (via QRTR/remoteproc) and its associated battery driver.

I have temporarily packaged these two in my OBS home subject[4], and the result shows that the battery percentage can be fixed after running the pd-mapper. I will submit these two packages to the openSUSE network project.

[1] https://github.com/andersson/qrtr
[2] https://github.com/andersson/pd-mapper
[3] https://groups.google.com/g/linux.debian.devel/c/gZWi4_ca9yw
[4] https://build.opensuse.org/project/show/home:clin:branches:devel:ARM:qcom-qrtr
Comment 2 Chester Lin 2023-11-02 08:37:28 UTC
(In reply to Chester Lin from comment #1)
> Created attachment 870584 [details]
> batt_ok.png
> 
> By tracing the QCOM battery driver [qcom_battmgr.c], I realized that the
> qcom_battmgr driver needs a notification from the pdr_interface in order to
> activate the battery measurement, which should be the way originated from
> the Android systems running on Qualcomm's mobile application processors.
> 
> To solve this issue, we will need a net/qrtr[1] lib and a pd-mapper[2][3]
> program running in userspace in order to trigger the event required by the
> battery sensor (via QRTR/remoteproc) and its associated battery driver.
> 
> I have temporarily packaged these two in my OBS home subject[4], and the
> result shows that the battery percentage can be fixed after running the
> pd-mapper. I will submit these two packages to the openSUSE network project.
> 
> [1] https://github.com/andersson/qrtr
> [2] https://github.com/andersson/pd-mapper
> [3] https://groups.google.com/g/linux.debian.devel/c/gZWi4_ca9yw
> [4]
> https://build.opensuse.org/project/show/home:clin:branches:devel:ARM:qcom-
> qrtr

The same approach can also be seen in other distros, such as Debian and Fedora.
Comment 3 Takashi Iwai 2023-11-02 08:42:56 UTC
Thanks, it looks reasonable to me.

You can add a proper "Supplements" tag to the package, so that it can be automatically installed for the target hardware.
Comment 4 Chester Lin 2023-11-07 02:32:43 UTC
(In reply to Takashi Iwai from comment #3)
> Thanks, it looks reasonable to me.
> 
> You can add a proper "Supplements" tag to the package, so that it can be
> automatically installed for the target hardware.

Thanks for the suggestion. I have submitted packages with a "Supplements" tag in the "pd-mapper.spec". Here are PRs:

libqrtr1: https://build.opensuse.org/request/show/1123703
pd-mapper: https://build.opensuse.org/request/show/1123705
Comment 5 Chester Lin 2023-11-09 14:22:26 UTC
(In reply to Chester Lin from comment #4)
> (In reply to Takashi Iwai from comment #3)
> > Thanks, it looks reasonable to me.
> > 
> > You can add a proper "Supplements" tag to the package, so that it can be
> > automatically installed for the target hardware.
> 
> Thanks for the suggestion. I have submitted packages with a "Supplements"
> tag in the "pd-mapper.spec". Here are PRs:
> 
> libqrtr1: https://build.opensuse.org/request/show/1123703
> pd-mapper: https://build.opensuse.org/request/show/1123705

Accepted by network and now I have submitted to openSUSE:Factory:

libqrtr1: https://build.opensuse.org/request/show/1124452
pd-mapper: https://build.opensuse.org/request/show/1124453
Comment 6 OBSbugzilla Bot 2023-11-13 13:55:03 UTC
This is an autogenerated message for OBS integration:
This bug (1216806) was mentioned in
https://build.opensuse.org/request/show/1125577 Factory / qrtr
https://build.opensuse.org/request/show/1125579 Factory / pd-mapper
Comment 7 Chester Lin 2023-11-17 07:20:39 UTC
(In reply to OBSbugzilla Bot from comment #6)
> This is an autogenerated message for OBS integration:
> This bug (1216806) was mentioned in
> https://build.opensuse.org/request/show/1125577 Factory / qrtr
> https://build.opensuse.org/request/show/1125579 Factory / pd-mapper

I have refreshed the SRs but the qrtr package still needs some improvements based on the reviewer's comment:

qrtr: https://build.opensuse.org/request/show/1125577?notification_id=44316417
pd-mapper: https://build.opensuse.org/request/show/1124453?notification_id=44135231
Comment 8 OBSbugzilla Bot 2023-11-21 09:35:01 UTC
This is an autogenerated message for OBS integration:
This bug (1216806) was mentioned in
https://build.opensuse.org/request/show/1127853 Factory / qrtr
Comment 9 OBSbugzilla Bot 2023-11-21 11:35:01 UTC
This is an autogenerated message for OBS integration:
This bug (1216806) was mentioned in
https://build.opensuse.org/request/show/1127861 Factory / qrtr
Comment 10 Guillaume GARDET 2023-12-01 13:31:06 UTC
Current pd-mapper and qrtr-ns do not work.

qrtr-ns service reports:
  ERROR: qrtr-ns: nameserver already runnin, going dormant: Address already in use

and was started by qrtr-ns.service with:
  /usr/sbin/qrtr-ns -f 1