Bug 201121

Summary: Full battery reported as 1%
Product: Drivers Reporter: Trent Gamblin (trentfromcanmore)
Component: Input DevicesAssignee: drivers_input-devices
Status: NEW ---    
Severity: normal CC: developer, luya, trent
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 4.15 Subsystem:
Regression: No Bisected commit-id:
Attachments: lsusb -vd output
Patch to ignore battery on this device

Description Trent Gamblin 2018-09-14 01:02:29 UTC
Created attachment 278523 [details]
lsusb -vd output

With an ELAN touchscreen and active stylus, the stylus reports 1% battery at all times. I've used several batteries including 2 brand new ones. I noticed in the USB HID driver the possibility of ignoring the battery on devices by adding IDs to the source, perhaps it's a good idea with this device. To double check it I ordered a second stylus and they both do the same thing.

When I use the stylus it pops up a notification saying the battery is low. On Windows, I don't get any notification nor does there seem to be any way to check the battery level, so I think it might not be a valid value at all. The troubleshooting manual from Dell for the stylus simply says if the stylus isn't working anymore, replace the battery. I'm using a Dell Inspiron 5379 laptop.

lsusb -vd output is attached.
Comment 1 Luya Tshimbalanga 2018-11-24 09:09:19 UTC
Given by the name, it looks like the information for each device is incomplete

Device:           ELAN0732:00 04F3:264C
Kernel:           /dev/input/event5
Group:            7
Seat:             seat0, default
Size:             332x188mm
Capabilities:     touch 
Tap-to-click:     n/a
Tap-and-drag:     n/a
Tap drag lock:    n/a
Left-handed:      n/a
Nat.scrolling:    n/a
Middle emulation: n/a
Calibration:      identity matrix
Scroll methods:   none
Click methods:    none
Disable-w-typing: n/a
Accel profiles:   n/a
Rotation:         n/a

Device:           ELAN0732:00 04F3:264C Pen
Kernel:           /dev/input/event6
Group:            7
Seat:             seat0, default
Size:             346x193mm
Capabilities:     tablet 
Tap-to-click:     n/a
Tap-and-drag:     n/a
Tap drag lock:    n/a
Left-handed:      n/a
Nat.scrolling:    n/a
Middle emulation: n/a
Calibration:      n/a
Scroll methods:   none
Click methods:    none
Disable-w-typing: n/a
Accel profiles:   none
Rotation:         n/a

Causing desktop environment like Gnome Shell complaining 

Nov 23 08:05:01 gnome-shell[1760]: Could not get tablet information for 'ELAN0732:00 04F3:264C Pen': (null)

Elantech will need to provide the missing detailed information for both stylus and touchscreen.
Comment 2 Trent Gamblin 2018-11-26 01:05:53 UTC
I wrote a patch which ignores the battery on this device, stopping the error message. Is this useful? Otherwise I can try to contact Elantech but I'm unsure if that will help.
Comment 3 Trent Gamblin 2018-11-26 03:45:17 UTC
Created attachment 279653 [details]
Patch to ignore battery on this device

Here is the patch, I have tested it on 4.19 but not 4.20 but I could do so if it's useful.
Comment 4 Luya Tshimbalanga 2018-11-27 08:15:01 UTC
(In reply to Trent Gamblin from comment #2)
> I wrote a patch which ignores the battery on this device, stopping the error
> message. Is this useful? Otherwise I can try to contact Elantech but I'm
> unsure if that will help.

That patch just removes the error message but also the battery status of the active stylus within the desktop environment. Essentially, we are still missing the detailed information like human readable name of the device i.e. HP Pen (or Elan Pen) from the config-table inside the kernel rather than LAN0732:00 04F3:264C Pen in this example.

Looking at the comment from https://bugzilla.kernel.org/show_bug.cgi?id=198715#c93 , the suggestion will be to assign the product to ACPI and the component to Config-Table from this report.
Comment 5 Luya Tshimbalanga 2018-11-27 08:28:35 UTC
P.S: if possible, add the info of the device for linuxwacom (https://github.com/linuxwacom/libwacom/) using their template on https://github.com/linuxwacom/libwacom/blob/master/data/wacom.example
Comment 6 Trent Gamblin 2018-11-27 08:59:02 UTC
I've been over this bug with the linuxwacom guys and they determined that the stylus reports the battery status incorrectly, which is why I wrote this patch. Having the correct stylus name would be nice but I'm not sure it will solve anything.

Here is the thread with linuxwacom: https://github.com/linuxwacom/input-wacom/issues/37
Comment 7 Luya Tshimbalanga 2018-11-27 10:00:39 UTC
Thanks for the thread.
From details, the bug is specific to the Elan active stylus itself not the Dell as suggested by the patch because it also impacts HP touchscreen which I own. 

As suggested on #4, let's switch the Product to ACPI and the Component to Config-Table. I think there is a link with that dmesg extract from boot on my HP Envy laptop:

[...snip...]
[    5.710951] ACPI Error: Field [D128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20180810/dsopcode-201)
[    5.710966] ACPI Error: Method parse/execution failed \HWMC, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.710981] ACPI Error: Method parse/execution failed \_SB.WMID.WMAA, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.711040] ACPI Error: Field [D128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20180810/dsopcode-201)
[    5.711044] ACPI Error: Method parse/execution failed \HWMC, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.711051] ACPI Error: Method parse/execution failed \_SB.WMID.WMAA, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.711109] ACPI Error: Field [D128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20180810/dsopcode-201)
[    5.711114] ACPI Error: Method parse/execution failed \HWMC, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.711121] ACPI Error: Method parse/execution failed \_SB.WMID.WMAA, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.713899] ACPI Error: Field [D128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20180810/dsopcode-201)
[    5.713909] ACPI Error: Method parse/execution failed \HWMC, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.713919] ACPI Error: Method parse/execution failed \_SB.WMID.WMAA, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.713979] ACPI Error: Field [D128] at bit offset/length 128/1024 exceeds size of target Buffer (160 bits) (20180810/dsopcode-201)
[    5.713984] ACPI Error: Method parse/execution failed \HWMC, AE_AML_BUFFER_LIMIT (20180810/psparse-516)
[    5.713991] ACPI Error: Method parse/execution failed \_SB.WMID.WMAA, AE_AML_BUFFER_LIMIT (20180810/psparse-516)


If you have similar dmesg from above on your Dell from boot, then the issue is possibly the ACPI that needs a fix.
Comment 8 Trent Gamblin 2018-11-27 10:18:35 UTC
I have no ACPI errors in my dmesg, might be unrelated.
Comment 9 Luya Tshimbalanga 2018-11-27 16:31:32 UTC
OK, that ACPI eror is out of the equation.

Run the upower -m to monitor the battery activity in order to find the device.
Then run upower -i  /org/freedesktop/UPower/devices/keyboard_hid_0018o04F3o264Cx0001_battery as an example and post the result.

 upower -i /org/freedesktop/UPower/devices/keyboard_hid_0018o04F3o264Cx0001_battery
  native-path:          hid-0018:04F3:264C.0001-battery
  model:                ELAN0732:00 04F3:264C
  power supply:         no
  updated:              Tue 27 Nov 2018 08:13:45 AM PST (16 seconds ago)
  has history:          yes
  has statistics:       yes
  keyboard
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       critical
    percentage:          1%
    icon-name:          'battery-caution-symbolic'

Just that information revealed upower detected the pen as keyboard_hid displaying the identical percentage of the stylus. It shows we are missing the acpi config-table to identity ELAN0732:00 04F3:xxxx Pen (where xxxx is the hexadecimal suffix name of the device, in my case 264C).

Based on that, we need to find the config-table listing the device.
Comment 10 Luya Tshimbalanga 2018-11-27 16:36:24 UTC
I suggest changing the title like "Elan active stylus mistakenly reported 1% battery". What we want is the Elan style to correctly report the battery status, not hide it.
Comment 11 Addie Morrison 2018-11-27 19:20:58 UTC
It's worth officially noting that this does affect some other (possibly all?) Elan devices such as ELAN0732:00 04F3:2538 seen in some HP Envy x360s
Comment 12 Luya Tshimbalanga 2018-11-28 05:56:29 UTC
Right. The title should be like "ELAN0732:00 04F3:xxxx data displays wrong battery information for Elan active pen".

After some investigations, the battery information is located on /sys/class/power_supply/

In my case, /sys/class/power_supply/hid-0018:04F3:264C.0001-battery/ containing the following:

ls -l /sys/class/power_supply/hid-0018\:04F3\:264C.0001-battery/
total 0
-r--r--r--. 1 root root 4096 Nov 27 21:11 capacity
lrwxrwxrwx. 1 root root    0 Nov 27 21:40 device -> ../../../0018:04F3:264C.0001
-r--r--r--. 1 root root 4096 Nov 27 21:11 model_name
-r--r--r--. 1 root root 4096 Nov 27 21:40 online
drwxr-xr-x. 2 root root    0 Nov 27 21:40 power
lrwxrwxrwx. 1 root root    0 Nov 27 21:40 powers -> ../../../0018:04F3:264C.0001
-r--r--r--. 1 root root 4096 Nov 27 21:40 present
-r--r--r--. 1 root root 4096 Nov 27 21:11 scope
-r--r--r--. 1 root root 4096 Nov 27 21:11 status
lrwxrwxrwx. 1 root root    0 Nov 27 21:11 subsystem -> ../../../../../../../../class/power_supply
-r--r--r--. 1 root root 4096 Nov 27 21:11 type
-rw-r--r--. 1 root root 4096 Nov 27 13:11 uevent

cat /sys/class/power_supply/hid-0018\:04F3\:264C.0001-battery/uevent 
POWER_SUPPLY_NAME=hid-0018:04F3:264C.0001-battery
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_CAPACITY=1
POWER_SUPPLY_MODEL_NAME=ELAN0732:00 04F3:264C
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device

Further details show the pen located on
/sys/class/power_supply/hid-0018\:04F3\:264C.0001-battery/device/input/input15/

and the name
cat /sys/class/power_supply/hid-0018\:04F3\:264C.0001-battery/device/input/input15/name 
ELAN0732:00 04F3:264C Pen

So if I understand, the kernel recognized the Pen has a power supply but does not know how to properly get its battery status.

Hopefully one of ACPI kernel developers can further investigate the issue.
Comment 13 Luya Tshimbalanga 2018-12-28 20:26:07 UTC
With no other available alternative, it looks like hiding the false 1% report is a safe option. I tested Windows 10 showing no battery status for the pen.
Comment 14 Trent Gamblin 2018-12-28 20:48:52 UTC
Since Comment 11 indicates this affects other device ids as well, I’m not sure what the correct approach is. They could both be added to the patch but if there are several devices it could be a mess.