platform/x86: x86-android-tablets: New driver for x86 Android tablets
PATCH 1/1 platform/x86: x86-android-tablets: New driver for x86 Android tablets
x86 tablets which ship with Android as (part of) the factory image typically have various problems with their DSDTs. The factory kernels shipped on these devices typically have device addresses and GPIOs hardcoded in the kernel, rather then specified in their DSDT.
With the DSDT containing a random collection of devices which may or may not actually be present as well as missing devices which are actually present.
This driver, which loads only on affected models based on DMI matching, adds DMI based instantiating of kernel devices for devices which are missing from the DSDT, fixing e.g. battery monitoring, touchpads and/or accelerometers not working.
Note the Kconfig help text also refers to "various fixes" ATM there are no such fixes, but there are also known cases where entries are present in the DSDT but they contain bugs, such as missing/wrong GPIOs. The plan is to also add fixes for things like this here in the future.
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 | 17 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/x86-android-tablets.c | 315 +++++++++++++++++++++ 3 files changed, 333 insertions(+) create mode 100644 drivers/platform/x86/x86-android-tablets.c
drivers/platform/x86/Kconfig +17 -0
@@ -1006,6 +1006,23 @@ config TOUCHSCREEN_DMI the OS-image for the device. This option supplies the missing info. Enable this for x86 tablets with Silead or Chipone touchscreens. +config X86_ANDROID_TABLETS + tristate "X86 Android tablet support" + depends on I2C && ACPI + help + X86 tablets which ship with Android as (part of) the factory image + typically have various problems with their DSDTs. The factory kernels + shipped on these devices typically have device addresses and GPIOs + hardcoded in the kernel, rather then specified in their DSDT. + + With the DSDT containing a random collection of devices which may or + may not actually be present. This driver contains various fixes for + such tablets, including instantiating kernel devices for devices which + are missing from the DSDT. + + If you have a x86 Android tablet say Y or M here, for a generic x86 + distro config say M here. + config FW_ATTR_CLASS tristate
drivers/platform/x86/Makefile +1 -0
@@ -113,6 +113,7 @@ obj-$(CONFIG_I2C_MULTI_INSTANTIATE) += i2c-multi-instantiate.o obj-$(CONFIG_MLX_PLATFORM) += mlx-platform.o obj-$(CONFIG_TOUCHSCREEN_DMI) += touchscreen_dmi.o obj-$(CONFIG_WIRELESS_HOTKEY) += wireless-hotkey.o +obj-$(CONFIG_X86_ANDROID_TABLETS) += x86-android-tablets.o # Intel uncore drivers obj-$(CONFIG_INTEL_IPS) += intel_ips.o
drivers/platform/x86/x86-android-tablets.c new file +315 -0
315 lines not on this page · raw message
Signature · 1 line
2.33.1
Quoted 15 lines · Hans de Goede
x86 tablets which ship with Android as (part of) the factory image typically have various problems with their DSDTs. The factory kernels shipped on these devices typically have device addresses and GPIOs hardcoded in the kernel, rather then specified in their DSDT.
With the DSDT containing a random collection of devices which may or may not actually be present as well as missing devices which are actually present.
This driver, which loads only on affected models based on DMI matching, adds DMI based instantiating of kernel devices for devices which are missing from the DSDT, fixing e.g. battery monitoring, touchpads and/or accelerometers not working.
Quoted 8 lines
Note the
Kconfighelp text also refers to "various fixes" ATM there are no such fixes, but there are also known cases where entries are present in the DSDT but they contain bugs, such as missing/wrong GPIOs. The plan is to also add fixes for things like this here in the future.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.
The idea is not bad.
...
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI
Quoted 4 lines
drivers/platform/x86/Kconfig +3
-0+config X86_ANDROID_TABLETS + tristate "X86 Android tablet support" + depends on I2C && ACPI
Why I²C dependency? Are you expecting all problematic DSDTs to be related to I²C?
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1016
Quoted 5 lines
drivers/platform/x86/Kconfig +5
-0+ help + X86 tablets which ship with Android as (part of) the factory image + typically have various problems with their DSDTs. The factory kernels + shipped on these devices typically have device addresses and GPIOs + hardcoded in the kernel, rather then specified in their DSDT.
than
Quoted 7 lines
drivers/platform/x86/Kconfig +7
-0+ With the DSDT containing a random collection of devices which may or + may not actually be present. This driver contains various fixes for + such tablets, including instantiating kernel devices for devices which + are missing from the DSDT. + + If you have a x86 Android tablet say Y or M here, for a generic x86 + distro config say M here.
...
Quoted 1 line
+#define
pr_fmt(fmt)"x86-android-tablet: " fmt
Can we use a predefined module name instead?
...
drivers/platform/x86/x86-android-tablets.c line 24
Quoted 3 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+#define IRQ_TYPE_NONE 0 +#define IRQ_TYPE_APIC 1 +#define IRQ_TYPE_GPIOINT 2
Is this same / similar to what we have in I²C multi-instantiate driver? Perhaps something in include/linux/platform_data/x86?
...
drivers/platform/x86/x86-android-tablets.c line 32
Quoted 8 lines
drivers/platform/x86/x86-android-tablets.c new file +7
-0+struct x86_i2c_client_info { +struct i2c_board_info board_info; +char *adapter_path; +int irq_type; +int irq_index; +int irq_trigger; +int irq_polarity;
Wondering if these fields are already defined in some structure by IRQ core or alike. In such case I would rather use more memory and predefined structure (it it has proper naming, of course).
Quoted 1 line
+};
...
drivers/platform/x86/x86-android-tablets.c line 115
Quoted 5 lines
drivers/platform/x86/x86-android-tablets.c new file +5
-0+static const struct x86_dev_info chuwi_hi8_info__initconst = { + .i2c_client_info = chuwi_hi8_i2c_clients, + .i2c_client_count =ARRAY_SIZE (chuwi_hi8_i2c_clients), + .gpiod_lookup_table = &chuwi_hi8_gpios, +};
Okay, looking into the below, I think of better granularity of this one, by splitting on per device module or so. Does it make sense? (I'm expecting this one to grow too big to be suitable for everybody)
...
Quoted 3 lines
+/*
+ * On the Xiaomi Mi Pad 2 X86 tablet a bunch of devices are hidden when
+ * the EFI if the tablet does thinks the OS it is booting is Windows
in Windows
Quoted 11 lines
+ * (OSID in the DSDT is set to 1); and the EFI code thinks this as soon
+ * as the EFI bootloader is not Xiaomi's own signed Android loader :|
+ *
+ * This takes care of instantiating the hidden devices manually.
+ */drivers/platform/x86/x86-android-tablets.c new file +6
-0+static const char *const bq27520_suppliers[] = {"bq25890-charger" }; + +static const struct property_entry bq27520_props[] = { +PROPERTY_ENTRY_STRING_ARRAY ("supplied-from" , bq27520_suppliers), + { } +};
...
drivers/platform/x86/x86-android-tablets.c line 212
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+if (ret <0 ) { +pr_err ("Error getting APIC IRQ %d: %d\n" , + client_info->irq_index, ret);
One line?
Quoted 2 lines
(quoted diff) +2
-0+ goto out; + }
...
drivers/platform/x86/x86-android-tablets.c line 250
Quoted 6 lines
drivers/platform/x86/x86-android-tablets.c new file +6
-0+ ret =0 ; + i2c_clients[idx] =i2c_new_client_device (adap, &board_info); +if (IS_ERR (i2c_clients[idx])) { + ret =PTR_ERR (i2c_clients[idx]); +pr_err ("Error creating I2C-client %d: %d\n" , idx, ret); + }
Ah, can we actually use i2c-multi-instantiate as a driver here?
...
Quoted 1 line
+ if (
dev_info->gpiod_lookup_table)
Perhaps it makes sense to move this to the GPIO library? AFAIR I saw a few more cases like this.
Quoted 1 line
+
gpiod_add_lookup_table(dev_info->gpiod_lookup_table);
...
Quoted 1 line
+ if (
dev_info->gpiod_lookup_table)
This is not needed. (Yes, now I checked it carefully)
Quoted 1 line
+
gpiod_remove_lookup_table(dev_info->gpiod_lookup_table);
...
drivers/platform/x86/x86-android-tablets.c line 311
Quoted 3 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+ +module_init (x86_android_tablet_init); +module_exit (x86_android_tablet_cleanup);
I would prefer to see them attached to the methods and without an additional blank line (but it's minor thingy).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 29 lines · Andy Shevchenko
Quoted 15 lines · Hans de Goede
x86 tablets which ship with Android as (part of) the factory image typically have various problems with their DSDTs. The factory kernels shipped on these devices typically have device addresses and GPIOs hardcoded in the kernel, rather then specified in their DSDT.
With the DSDT containing a random collection of devices which may or may not actually be present as well as missing devices which are actually present.
This driver, which loads only on affected models based on DMI matching, adds DMI based instantiating of kernel devices for devices which are missing from the DSDT, fixing e.g. battery monitoring, touchpads and/or accelerometers not working.
Quoted 8 lines
Note the
Kconfighelp text also refers to "various fixes" ATM there are no such fixes, but there are also known cases where entries are present in the DSDT but they contain bugs, such as missing/wrong GPIOs. The plan is to also add fixes for things like this here in the future.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.
The idea is not bad.
...
Quoted 7 lines
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI
Quoted 4 lines
drivers/platform/x86/Kconfig +3
-0+config X86_ANDROID_TABLETS + tristate "X86 Android tablet support" + depends on I2C && ACPIWhy I²C dependency? Are you expecting all problematic DSDTs to be related to I²C?
I2C at a minimum is a big part if it. So far all this "driver" dies is instantiate I2C devices, so building it in a kernel which has I2C disabled does not make any sense.
Quoted 8 lines
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1016
Quoted 6 lines
drivers/platform/x86/Kconfig +5
-0+ help + X86 tablets which ship with Android as (part of) the factory image + typically have various problems with their DSDTs. The factory kernels + shipped on these devices typically have device addresses and GPIOs + hardcoded in the kernel, rather then specified in their DSDT.than
Ack, will fix.
Quoted 9 lines
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1024
Quoted 8 lines
drivers/platform/x86/Kconfig +7
-0+ With the DSDT containing a random collection of devices which may or + may not actually be present. This driver contains various fixes for + such tablets, including instantiating kernel devices for devices which + are missing from the DSDT. + + If you have a x86 Android tablet say Y or M here, for a generic x86 + distro config say M here.
Quoted 5 lines
...
Quoted 1 line
+#define
pr_fmt(fmt)"x86-android-tablet: " fmtCan we use a predefined module name instead?
Ack, will fix.
Quoted 9 lines
...
drivers/platform/x86/x86-android-tablets.c line 24
Quoted 3 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+#define IRQ_TYPE_NONE 0 +#define IRQ_TYPE_APIC 1 +#define IRQ_TYPE_GPIOINT 2Is this same / similar to what we have in I²C multi-instantiate driver? Perhaps something in
include/linux/platform_data/x86?
Yes and no, it looks similar, but there the "enum" is used to select which ACPI resource to lookup. Where as here we are manually looking up the interrupt number ourselves since there are no ACPI resources.
So the similarity is superficial only the actual code is quite different.
Quoted 7 lines
...
Quoted 3 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+struct x86_i2c_client_info { +struct i2c_board_info board_info; +char *adapter_path;
Quoted 8 lines
drivers/platform/x86/x86-android-tablets.c line 32
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +4
-0+int irq_type; +int irq_index; +int irq_trigger; +int irq_polarity;Wondering if these fields are already defined in some structure by IRQ core or alike. In such case I would rather use more memory and predefined structure (it it has proper naming, of course).
irq_type is set to our own unique defines from above, so I'm afraid there is no pre-defined structure matching this.
Quoted 5 lines
Quoted 2 lines
+};
...
Quoted 9 lines
drivers/platform/x86/x86-android-tablets.c line 115
Quoted 5 lines
drivers/platform/x86/x86-android-tablets.c new file +5
-0+static const struct x86_dev_info chuwi_hi8_info__initconst = { + .i2c_client_info = chuwi_hi8_i2c_clients, + .i2c_client_count =ARRAY_SIZE (chuwi_hi8_i2c_clients), + .gpiod_lookup_table = &chuwi_hi8_gpios, +};Okay, looking into the below, I think of better granularity of this one, by splitting on per device module or so. Does it make sense? (I'm expecting this one to grow too big to be suitable for everybody)
I actually started with a 1 special driver per model as concept, but having a lot of tiny modules has a price too, figuring out Kconfig options takes quite some time for distro kernel maintainers.
And each module adds overhead to, in disk use, but also in depmod info.
So I deliberately decided to go for one file. I'm actually not expecting this to grow that much at all. Most tablets are dual-boot and the dual-boot ones typically have a DSDT which is fine.
The only troublesome models which I'm aware of and which I plan to eventually add are:
1. Asus MeMO Pad 7ME176C (7" BYT Android only tablet)
2. Asus Transformer TF103C (10" BYT Android only tablet)
3. No-name (sometimes branded as Glavey) TM800A550L (8" BYT Android only tablet)
Which puts the total at 5 devices, at least for now. So I believe that keeping this in 1 file is fine. We can always split it later if it becomes too big.
Quoted 7 lines
...
Quoted 3 lines
+/*
+ * On the Xiaomi Mi Pad 2 X86 tablet a bunch of devices are hidden when
+ * the EFI if the tablet does thinks the OS it is booting is Windowsin Windows
Ack, will fix.
Quoted 15 lines
Quoted 12 lines
+ * (OSID in the DSDT is set to 1); and the EFI code thinks this as soon
+ * as the EFI bootloader is not Xiaomi's own signed Android loader :|
+ *
+ * This takes care of instantiating the hidden devices manually.
+ */drivers/platform/x86/x86-android-tablets.c new file +6
-0+static const char *const bq27520_suppliers[] = {"bq25890-charger" }; + +static const struct property_entry bq27520_props[] = { +PROPERTY_ENTRY_STRING_ARRAY ("supplied-from" , bq27520_suppliers), + { } +};...
Quoted 6 lines
drivers/platform/x86/x86-android-tablets.c line 212
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+if (ret <0 ) { +pr_err ("Error getting APIC IRQ %d: %d\n" , + client_info->irq_index, ret);One line?
Ack, will fix.
Quoted 6 lines
Quoted 3 lines
(quoted diff) +2
-0+ goto out; + }...
Quoted 8 lines
drivers/platform/x86/x86-android-tablets.c line 250
Quoted 6 lines
drivers/platform/x86/x86-android-tablets.c new file +6
-0+ ret =0 ; + i2c_clients[idx] =i2c_new_client_device (adap, &board_info); +if (IS_ERR (i2c_clients[idx])) { + ret =PTR_ERR (i2c_clients[idx]); +pr_err ("Error creating I2C-client %d: %d\n" , idx, ret); + }Ah, can we actually use i2c-multi-instantiate as a driver here?
That expects ACPI resources, both for the I2C adapter / client address pair (an I2cSerialBusV2 resource) as well as for the IRQs.
Quoted 7 lines
...
Quoted 1 line
+ if (
dev_info->gpiod_lookup_table)Perhaps it makes sense to move this to the GPIO library? AFAIR I saw a few more cases like this.
Maybe something for a separate cleanup series, I don't know adding NULL checks to register/add functions is not really standard practice in the kernel.
Quoted 10 lines
Quoted 2 lines
+
gpiod_add_lookup_table(dev_info->gpiod_lookup_table);...
Quoted 1 line
+ if (
dev_info->gpiod_lookup_table)This is not needed. (Yes, now I checked it carefully)
Quoted 1 line
+
gpiod_remove_lookup_table(dev_info->gpiod_lookup_table);
Ack, will fix.
Quoted 11 lines
...
drivers/platform/x86/x86-android-tablets.c line 311
Quoted 3 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+ +module_init (x86_android_tablet_init); +module_exit (x86_android_tablet_cleanup);I would prefer to see them attached to the methods and without an additional blank line (but it's minor thingy).
Regards,
Hans