ACPI/power-suppy add fuel-gauge support on cht-wc PMIC without USB-PD support devs
Subsystems (2)
v2 cover ACPI/power-suppy add fuel-gauge support on cht-wc PMIC without USB-PD support devs
Hi All,
Here is a new RFC to add battery monitoring support on the Xiaomi Mi Pad 2 this implements option 2 of the different options which I gave in v1:
https://lore.kernel.org/platform-driver-x86/[email protected]/
To solve the challenges of getting this to work on this device, as you can see compared to option 1, the first patch has gone from adding 3 separate quirks to adding only one; and the 2 gpiolib-acpi and 2 bq27xxx_battery driver patches are now no longer necessary.
These are now all 4 replaced by a new special xiaomi-mipad2 module under drivers/platform/x86 which uses a DMI modalias to autoload and thus will only be auto-loaded on the actual Mi Pad 2.
I like this option much better then the previous option, but this still a RFC for now, since I would like to also see what is necessary to get everything PMIC / micro-USB connector related to work on the Yoga Book YB1-X91L which is on its way to me.
Regards,
Hans
p.s.
While working on this I realized that there also is a 4th option, which is basically option 1 from the v1 RFC minus the 2 gpiolib-acpi patches.
With the 2nd option (as implemented by this RFC) we leave the _AEI handler in place and run the fuel-gauge without interrupt, we can do the same when marking the fuel-gauge as always present by treating IRQs on ACPI devices the same way as in the max17042_battery code, which has already solved the IRQ problem without disabling the _AEI handler:
/* * On ACPI systems the IRQ may be handled by ACPI-event code, * so we need to share (if the ACPI code is willing to share). */ if (acpi_id) flags |= IRQF_SHARED | IRQF_PROBE_SHARED;
This is a pretty decent option too, it requires:
1. 2 more always_present quirks in the ACPI scan code which is part of the main kernel image.
2. Patches to the bq27xxx_battery code to support ACPI enumeration.
Hans de Goede (2):
ACPI / x86: Add PWM2 on the Xiaomi Mi Pad 2 to the always_present list platform/x86: xiaomi-mipad2: New driver for Xiaomi Mi Pad 2 tablets
drivers/acpi/x86/utils.c | 5 ++ drivers/platform/x86/Kconfig | 13 +++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/xiaomi-mipad2.c | 126 +++++++++++++++++++++++++++ 4 files changed, 145 insertions(+) create mode 100644 drivers/platform/x86/xiaomi-mipad2.c
Signature · 1 line
2.31.1
RFC v2 1/2 ACPI / x86: Add PWM2 on the Xiaomi Mi Pad 2 to the always_present list
The Xiaomi Mi Pad 2 has backlit LEDs behind the capacitive menu, home and back buttons below the screen which are controlled by the PWM2 controller of the CHT SoC. This PWM2 controller gets hidden by the firmware, add it to the always_present_ids table so that we can use the PWM controller to control the backlighting of the buttons.
--- drivers/acpi/x86/utils.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/acpi/x86/utils.c +5 -0
@@ -58,6 +58,11 @@ static const struct always_present_id always_present_ids[] = { ENTRY("80862289", "2", X86_MATCH(ATOM_AIRMONT), { DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"), }), + /* The Xiaomi Mi Pad 2 uses PWM2 for touchkeys backlight control */ + ENTRY("80862289", "2", X86_MATCH(ATOM_AIRMONT), { + DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), + }), /* * The INT0002 device is necessary to clear wakeup interrupt sources * on Cherry Trail devices, without it we get nobody cared IRQ msgs.
Signature · 1 line
2.31.1
Re: [RFC v2 1/2] ACPI / x86: Add PWM2 on the Xiaomi Mi Pad 2 to the always_present list
Quoted 8 lines · Hans de Goede
The Xiaomi Mi Pad 2 has backlit LEDs behind the capacitive menu, home and back buttons below the screen which are controlled by the PWM2 controller of the CHT SoC. This PWM2 controller gets hidden by the firmware, add it to the
always_present_idstable so that we can use the PWM controller to control the backlighting of the buttons.Signed-off-by Hans de Goede <[email protected]>
Quoted 23 lines
--- drivers/acpi/x86/utils.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/acpi/x86/utils.c +5
-1@@ -58,6 +58,11 @@ static const struct always_present_id always_present_ids[] = { ENTRY("80862289", "2", X86_MATCH(ATOM_AIRMONT), { DMI_MATCH(DMI_PRODUCT_NAME, "Lenovo YB1-X9"), }), + /* The Xiaomi Mi Pad 2 uses PWM2 for touchkeys backlight control */ + ENTRY("80862289", "2", X86_MATCH(ATOM_AIRMONT), { + DMI_MATCH(DMI_SYS_VENDOR, "Xiaomi Inc"), + DMI_MATCH(DMI_PRODUCT_NAME, "Mipad2"), + }), /* * The INT0002 device is necessary to clear wakeup interrupt sources * on Cherry Trail devices, without it we get nobody cared IRQ msgs. -- 2.31.1
RFC v2 2/2 platform/x86: xiaomi-mipad2: New driver for Xiaomi Mi Pad 2 tablets
In reply to Hans de GoedeThe ACPI tables on the Xiaomi Mi Pad 2 hide a number of devices from Linux, such as the fuel-gauge IC used for battery monitoring.
This adds a xiaomi-mipad2 "board-file" which manually instantiates device-objects for the missing devices.
When build as a module this will only ever get auto-loaded on Xiaomi Mi Pad 2 tablets, allowing us to support these tablets in generic X86 kernels at the cost of just a small amount of diskspace for the module.
As discussed previously this is the least ugly option to get these devices to fully work and to do so without adding any extra code to the main kernel image (vmlinuz) when built as a module.
--- drivers/platform/x86/Kconfig | 13 +++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/xiaomi-mipad2.c | 126 +++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 drivers/platform/x86/xiaomi-mipad2.c
drivers/platform/x86/Kconfig +13 -0
@@ -958,6 +958,19 @@ config TOPSTAR_LAPTOP If you have a Topstar laptop, say Y or M here. +config XIAOMI_MIPAD2 + tristate "Xiaomi Mi Pad 2 support" + depends on I2C && ACPI + help + The ACPI tables on the Xiaomi Mi Pad 2 hide a number of devices + from Linux, such as the fuel-gauge IC used for battery monitoring. + + Say Y or M here to enable building a xiaomi-mipad2 board-file which + manually instantiates device-objects for the missing devices. + + If you have a Xiaomi Mi Pad 2 say Y or M here, for a generic X86 + distro config say M here. + config I2C_MULTI_INSTANTIATE tristate "I2C multi instantiate pseudo device driver" depends on I2C && ACPI
drivers/platform/x86/Makefile +1 -0
@@ -105,6 +105,7 @@ obj-$(CONFIG_PANASONIC_LAPTOP) += panasonic-laptop.o obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o obj-$(CONFIG_SYSTEM76_ACPI) += system76_acpi.o obj-$(CONFIG_TOPSTAR_LAPTOP) += topstar-laptop.o +obj-$(CONFIG_XIAOMI_MIPAD2) += xiaomi-mipad2.o # Platform drivers obj-$(CONFIG_DMI_DEVICE_PROPERTIES) += dmi_device_properties.o
drivers/platform/x86/xiaomi-mipad2.c new file +126 -0
126 lines not on this page · raw message
Signature · 1 line
2.31.1
On Wed, Nov 3, 2021 at 12:40 AM Hans de Goede <[email protected]> wrote:
...
Quoted 11 lines
While working on this I realized that there also is a 4th option, which is basically option 1 from the v1 RFC minus the 2 gpiolib-acpi patches.
With the 2nd option (as implemented by this RFC) we leave the
_AEIhandler in place and run the fuel-gauge without interrupt, we can do the same when marking the fuel-gauge as always present by treating IRQs on ACPI devices the same way as in themax17042_batterycode, which has already solved the IRQ problem without disabling the_AEIhandler:
Quoted 6 lines
/*
* On ACPI systems the IRQ may be handled by ACPI-event code,
* so we need to share (if the ACPI code is willing to share). */if (
acpi_id)
(Side remark: wouldn't it be better to have has_acpi_companion() and use device_get_match_data()?)
Quoted 8 lines
flags |= IRQF_SHARED | IRQF_PROBE_SHARED;This is a pretty decent option too, it requires:
1. 2 more
always_presentquirks in the ACPI scan code which is part of the main kernel image.2. Patches to the
bq27xxx_batterycode to support ACPI enumeration.
If it works, why not try it?
I like the common base for the FG drivers that can be used as a pattern then.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 23 lines · Andy Shevchenko
On Wed, Nov 3, 2021 at 12:40 AM Hans de Goede <[email protected]> wrote:
...
Quoted 19 lines
While working on this I realized that there also is a 4th option, which is basically option 1 from the v1 RFC minus the 2 gpiolib-acpi patches.
With the 2nd option (as implemented by this RFC) we leave the
_AEIhandler in place and run the fuel-gauge without interrupt, we can do the same when marking the fuel-gauge as always present by treating IRQs on ACPI devices the same way as in themax17042_batterycode, which has already solved the IRQ problem without disabling the_AEIhandler:/* * On ACPI systems the IRQ may be handled by ACPI-event code, * so we need to share (if the ACPI code is willing to share). */ if (acpi_id) flags |= IRQF_SHARED | IRQF_PROBE_SHARED;
Quoted 8 lines
Quoted 6 lines
This is a pretty decent option too, it requires:
1. 2 more
always_presentquirks in the ACPI scan code which is part of the main kernel image.2. Patches to the
bq27xxx_batterycode to support ACPI enumeration.If it works, why not try it?
I'm 99.9% sure it will work, so I see no reason to actually try it unless we decide that this is a better option.
This option would basically be patches 1 + 4-5 from option 1 / the v1 RFC:
https://lore.kernel.org/platform-driver-x86/[email protected]/
plus extra changes to the bq27xxx_battery code IRQ handling like above.
So this would mean 2 extra quirks in drivers/apci/x86/utils.c vs this RFC v2 patches + various changes to the bq27xxx_battery code, where as this (option 2/RFC v2) approach requires no changes to the bq27xxx_battery code at all (1).
So at the cost of a board_file (patch 2/2 of this RFC v2 series) we save 2 quirks which would be in the main vmlinuz image for everyone, as well as not having to add any special code to the bq27xxx_battery code just for this one board; and as mentioned the board-file .ko will only ever auto-load on the actual board, so it just costs diskspace when enabled in generic distro kernels, where as e.g. the 2 quirks take op memory for everyone.
So all in all I still believe that the approach in this v2 RFC is the best.
Also note that we already have an i2c-client being instantiated for a bq27xxx_battery fuel-gauge (rather then forcing an ACPI-device as always- present) here:
drivers/platform/x86/intel/int33fe/intel_cht_int33fe_microb.c
and for the max17042 fg here:
drivers/platform/x86/intel/int33fe/intel_cht_int33fe_typec.c
So doing the manual instantiation already is somewhat of a pattern and IMHO is the best (least bad) option to deal with this.
Quoted 1 line
I like the common base for the FG drivers that can be used as a pattern then.
I don't believe this is a pattern which we want to introduce, with the exception of one buggy BIOS version (2) fuel-gauges on ACPI devices are never directly instantiated through an ACPI-device / fwnode.
The whole business of using native fuel-gauge drivers on X86/ACPI is a special case just for BYT/CHT devices to begin with (because of broken or outright missing ACPI battery class support) and on all but the broken BIOS version the platform_dev or i2c-client for the fuel-gauge is instantiated by specific kernel-code, rather then directly from ACPI tables. So having ACPI enumeration support in fuel-gauge drivers is something which we do not need and should not want.
(Arguably we also need an always_hidden option for the ACPI quirks and then use that to hide the anomaly of the MAX17042 ACPI device not being hidden on the one troublesome BIOS version, this would allow removing a nice amount of code in a bunch of places.)
Regards,
Hans
1) Well I notices some issues there which need fixes but those issues impact all users of the bq27xxx_battery code and are not related to the discussed enumeration issues
2) BIOS version, not board, other BIOS versions for the same board are fine