platform/x86: Add x86-acpi-irq-helpers.h
PATCH v2 1/2 platform/x86: Add x86-acpi-irq-helpers.h
Add helper code to get Linux IRQ numbers given a description of the IRQ source (either IOAPIC index, or GPIO chip name + pin-number).
This is intended to be used to lookup Linux IRQ numbers in cases where the ACPI description for a device somehow lacks this info. This is only meant for use on x86 ACPI platforms.
This code is big/complex enough to warrant sharing, but too small to live in its own module, therefor x86_acpi_irq_helper_get() is defined as a static inline helper function.
---
Changes in v2:
- New patch in v2 of this patch-set
--- drivers/platform/x86/x86-acpi-irq-helpers.h | 82 +++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 drivers/platform/x86/x86-acpi-irq-helpers.h
drivers/platform/x86/x86-acpi-irq-helpers.h new file +82 -0
@@ -0,0 +1,82 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Helper code to get Linux IRQ numbers given a description of the IRQ source +* (either IOAPIC index, or GPIO chip name + pin-number). +* +* This is intended to be used to lookup Linux IRQ numbers in cases where the +* ACPI description for a device somehow lacks this info. This is only meant +* for use on x86 ACPI platforms. +*/ + +#include <linux/acpi.h> +#include <linux/irq.h> +#include <linux/string.h> +#include <linux/gpio/consumer.h> +#include <linux/gpio/driver.h> + +/* For gpio_get_desc which is EXPORT_SYMBOL_GPL() */ +#include "../../gpio/gpiolib.h" + +enum x86_acpi_irq_type { +X86_ACPI_IRQ_TYPE_NONE , +X86_ACPI_IRQ_TYPE_APIC , +X86_ACPI_IRQ_TYPE_GPIOINT , +}; + +struct x86_acpi_irq_data { +char *gpio_chip;/* GPIO chip label for X86_ACPI_IRQ_TYPE_GPIOINT */ +enum x86_acpi_irq_type type; +int index; +int trigger;/* ACPI_EDGE_SENSITIVE / ACPI_LEVEL_SENSITIVE */ +int polarity;/* ACPI_ACTIVE_HIGH / ACPI_ACTIVE_LOW / ACPI_ACTIVE_BOTH */ +}; + +static int x86_acpi_irq_helper_gpiochip_find (struct gpio_chip *gc,void *data) +{ +return gc->label && !strcmp (gc->label, data); +} + +static inline int x86_acpi_irq_helper_get (const struct x86_acpi_irq_data *data) +{ +struct gpio_desc *gpiod; +struct gpio_chip *chip; +unsigned int irq_type; +int irq, ret; + +switch (data->type) { +case X86_ACPI_IRQ_TYPE_APIC : + irq =acpi_register_gsi (NULL , data->index, data->trigger, data->polarity); +if (irq <0 ) +pr_err ("error %d getting APIC IRQ %d\n" , irq, data->index); + +return irq; +case X86_ACPI_IRQ_TYPE_GPIOINT : +/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */ + chip =gpiochip_find (data->gpio_chip, x86_acpi_irq_helper_gpiochip_find); +if (!chip) +return -EPROBE_DEFER ; + + gpiod =gpiochip_get_desc (chip, data->index); +if (IS_ERR (gpiod)) { + ret =PTR_ERR (gpiod); +pr_err ("error %d getting GPIO %s %d\n" , ret, + data->gpio_chip, data->index); +return ret; + } + + irq =gpiod_to_irq (gpiod); +if (irq <0 ) { +pr_err ("error %d getting IRQ %s %d\n" , irq, + data->gpio_chip, data->index); +return irq; + } + + irq_type =acpi_dev_get_irq_type (data->trigger, data->polarity); +if (irq_type !=IRQ_TYPE_NONE && irq_type !=irq_get_trigger_type (irq)) +irq_set_irq_type (irq, irq_type); + +return irq; +default : +return 0 ; + } +}
Signature · 1 line
2.33.1
PATCH v2 2/2 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.
---
Changes in v2:
- Use the new x86_acpi_irq_helper_get() helper
- Fixup / improve a couple of comments
--- MAINTAINERS | 8 + drivers/platform/x86/Kconfig | 17 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/x86-android-tablets.c | 253 +++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 drivers/platform/x86/x86-android-tablets.c
MAINTAINERS +8 -0
@@ -20732,6 +20732,14 @@ S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86/mm F: arch/x86/mm/ +X86 PLATFORM ANDROID TABLETS DSDT FIXUP DRIVER +M: Hans de Goede <[email protected]> +L: [email protected] +S: Maintained +T: git git://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git +F: drivers/platform/x86/x86-acpi-irq-helpers.h +F: drivers/platform/x86/x86-android-tablets.c + X86 PLATFORM DRIVERS M: Hans de Goede <[email protected]> M: Mark Gross <[email protected]>
drivers/platform/x86/Kconfig +17 -0
@@ -1024,6 +1024,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
@@ -114,6 +114,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 +253 -0
253 lines not on this page · raw message
Signature · 1 line
2.33.1
Re: [PATCH v2 2/2] platform/x86: x86-android-tablets: New driver for x86 Android tablets
Quoted 23 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.
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.
...
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1034
Quoted 8 lines
drivers/platform/x86/Kconfig +8
-0+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.
than
Quoted 5 lines
drivers/platform/x86/Kconfig +5
-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.
...
drivers/platform/x86/x86-android-tablets.c line 59
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +4
-0+static const char *const chuwi_hi8_mount_matrix[] = { +"1" ,"0" ,"0" , +"0" ,"-1" ,"0" , +"0" ,"0" ,"1"
+ comma?
Quoted 1 line
+};
...
drivers/platform/x86/x86-android-tablets.c line 197
Quoted 7 lines
drivers/platform/x86/x86-android-tablets.c new file +6
-0+int ret =0 ; + board_info.irq =x86_acpi_irq_helper_get (&client_info->irq_data); +if (board_info.irq <0 ) { + ret = board_info.irq; + goto out; + }
Can we rather use
ret = ...
if (ret < 0)
goto
.irq = ret;
?
...
drivers/platform/x86/x86-android-tablets.c line 202
Quoted 5 lines
drivers/platform/x86/x86-android-tablets.c new file +4
-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);
dev_err_probe()? (device of the adapter)
Quoted 1 line
+ }
...
Quoted 1 line
+out:
out_put_device: ?
Quoted 2 lines
(quoted diff) +2
-0+ put_device(&adap->dev); + return ret;
...
Quoted 1 line
+ int i, ret = 0;
Do you need this assignment? See below.
...
drivers/platform/x86/x86-android-tablets.c line 241
Quoted 6 lines
drivers/platform/x86/x86-android-tablets.c new file +5
-0+for (i =0 ; i < dev_info->i2c_client_count; i++) { + ret =x86_instantiate_i2c_client (dev_info, i); +if (ret <0 ) { +x86_android_tablet_cleanup (); +break ;
return ret; ?
drivers/platform/x86/x86-android-tablets.c line 206
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+ } + } +return ret;
return 0; ?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/2] platform/x86: x86-android-tablets: New driver for x86 Android tablets
Hi,
Quoted 36 lines · Andy Shevchenko
Quoted 23 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.
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.
...
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1034
Quoted 8 lines
drivers/platform/x86/Kconfig +8
-0+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.
Quoted 1 line
than
Fixed.
Quoted 7 lines
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1039
Quoted 6 lines
drivers/platform/x86/Kconfig +5
-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.
Quoted 8 lines
...
drivers/platform/x86/x86-android-tablets.c line 59
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +4
-0+static const char *const chuwi_hi8_mount_matrix[] = { +"1" ,"0" ,"0" , +"0" ,"-1" ,"0" , +"0" ,"0" ,"1" + comma?
This is a 3x3 matrix, there are never going to be extra entries added, so no I don't think so.
Quoted 13 lines
Quoted 2 lines
+};
...
drivers/platform/x86/x86-android-tablets.c line 197
Quoted 7 lines
drivers/platform/x86/x86-android-tablets.c new file +6
-0+int ret =0 ; + board_info.irq =x86_acpi_irq_helper_get (&client_info->irq_data); +if (board_info.irq <0 ) { + ret = board_info.irq; + goto out; + }
Quoted 7 lines
Can we rather use
ret = ...
if (ret < 0)
goto
.irq = ret;?
Ack, fixed.
Quoted 10 lines
...
drivers/platform/x86/x86-android-tablets.c line 202
Quoted 5 lines
drivers/platform/x86/x86-android-tablets.c new file +4
-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);
dev_err_probe()? (device of the adapter)
Ack, fixed.
Quoted 8 lines
Quoted 2 lines
+ }
...
Quoted 1 line
+out:
out_put_device: ?
I've gone with out_put_adap instead.
Regards,
Hans
Quoted 28 lines
Quoted 3 lines
(quoted diff) +2
-0+ put_device(&adap->dev); + return ret;...
Quoted 1 line
+ int i, ret = 0;
Do you need this assignment? See below.
...
drivers/platform/x86/x86-android-tablets.c line 241
Quoted 6 lines
drivers/platform/x86/x86-android-tablets.c new file +5
-0+for (i =0 ; i < dev_info->i2c_client_count; i++) { + ret =x86_instantiate_i2c_client (dev_info, i); +if (ret <0 ) { +x86_android_tablet_cleanup (); +break ;return ret; ?
drivers/platform/x86/x86-android-tablets.c line 206
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+ } + } +return ret;return 0; ?
Re: [PATCH v2 2/2] platform/x86: x86-android-tablets: New driver for x86 Android tablets
Hi,
Quoted 81 lines · Hans de Goede
Hi,
Quoted 36 lines · Andy Shevchenko
Quoted 23 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.
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.
...
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1034
Quoted 8 lines
drivers/platform/x86/Kconfig +8
-0+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.Quoted 1 line
than
Fixed.
Quoted 7 lines
drivers/platform/x86/Kconfig config TOUCHSCREEN_DMI · line 1039
Quoted 6 lines
drivers/platform/x86/Kconfig +5
-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.Quoted 8 lines
...
drivers/platform/x86/x86-android-tablets.c line 59
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +4
-0+static const char *const chuwi_hi8_mount_matrix[] = { +"1" ,"0" ,"0" , +"0" ,"-1" ,"0" , +"0" ,"0" ,"1" + comma?
This is a 3x3 matrix, there are never going to be extra entries added, so no I don't think so.
Quoted 19 lines
Quoted 2 lines
+};
...
drivers/platform/x86/x86-android-tablets.c line 197
Quoted 7 lines
drivers/platform/x86/x86-android-tablets.c new file +6
-0+int ret =0 ; + board_info.irq =x86_acpi_irq_helper_get (&client_info->irq_data); +if (board_info.irq <0 ) { + ret = board_info.irq; + goto out; + }Can we rather use
ret = ...
if (ret < 0)
goto
.irq = ret;
Quoted 3 lines
Quoted 1 line
?
Ack, fixed.
Scrap that, this way the function will now return the Linux IRQ number on success instead of 0.
Instead I've ended up refactoring things so that I don't need a ret variable; nor a goto at all anymore (by getting the irq first).
Regards,
Hans
Quoted 59 lines
Quoted 11 lines
...
drivers/platform/x86/x86-android-tablets.c line 202
Quoted 5 lines
drivers/platform/x86/x86-android-tablets.c new file +4
-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);
dev_err_probe()? (device of the adapter)Ack, fixed.
Quoted 8 lines
Quoted 2 lines
+ }
...
Quoted 1 line
+out:
out_put_device: ?I've gone with
out_put_adapinstead.Regards,
Hans
Quoted 28 lines
Quoted 3 lines
(quoted diff) +2
-0+ put_device(&adap->dev); + return ret;...
Quoted 1 line
+ int i, ret = 0;
Do you need this assignment? See below.
...
drivers/platform/x86/x86-android-tablets.c line 241
Quoted 6 lines
drivers/platform/x86/x86-android-tablets.c new file +5
-0+for (i =0 ; i < dev_info->i2c_client_count; i++) { + ret =x86_instantiate_i2c_client (dev_info, i); +if (ret <0 ) { +x86_android_tablet_cleanup (); +break ;return ret; ?
drivers/platform/x86/x86-android-tablets.c line 206
Quoted 4 lines
drivers/platform/x86/x86-android-tablets.c new file +3
-0+ } + } +return ret;return 0; ?
Quoted 11 lines · Hans de Goede
Add helper code to get Linux IRQ numbers given a description of the IRQ source (either IOAPIC index, or GPIO chip name + pin-number).
This is intended to be used to lookup Linux IRQ numbers in cases where the ACPI description for a device somehow lacks this info. This is only meant for use on x86 ACPI platforms.
This code is big/complex enough to warrant sharing, but too small to live in its own module, therefor
x86_acpi_irq_helper_get()is defined as a static inline helper function.
...
Quoted 1 line
+/* For
gpio_get_descwhich isEXPORT_SYMBOL_GPL()*/
gpio_get_desc() and honestly I don't like this kind of includes (yes, I know sometimes it's the best compromise).
Quoted 1 line
+#include "
../../gpio/gpiolib.h"
...
Quoted 15 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +15
-0+/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */ + chip =gpiochip_find (data->gpio_chip, x86_acpi_irq_helper_gpiochip_find); +if (!chip) +return -EPROBE_DEFER ; + + gpiod =gpiochip_get_desc (chip, data->index); +if (IS_ERR (gpiod)) { + ret =PTR_ERR (gpiod); +pr_err ("error %d getting GPIO %s %d\n" , ret, + data->gpio_chip, data->index); +return ret; + } + + irq =gpiod_to_irq (gpiod); +if (irq <0 ) {
drivers/platform/x86/x86-acpi-irq-helpers.h line 78
Quoted 10 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +10
-0+pr_err ("error %d getting IRQ %s %d\n" , irq, + data->gpio_chip, data->index); +return irq; + } + + irq_type =acpi_dev_get_irq_type (data->trigger, data->polarity); +if (irq_type !=IRQ_TYPE_NONE && irq_type !=irq_get_trigger_type (irq)) +irq_set_irq_type (irq, irq_type); + +return irq;
I'm wondering why it can't be a part of the GPIO ACPI library?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Hans de Goede
Add helper code to get Linux IRQ numbers given a description of the IRQ source (either IOAPIC index, or GPIO chip name + pin-number).
This is intended to be used to lookup Linux IRQ numbers in cases where the ACPI description for a device somehow lacks this info. This is only meant for use on x86 ACPI platforms.
This code is big/complex enough to warrant sharing, but too small to live in its own module, therefor
x86_acpi_irq_helper_get()is defined as a static inline helper function.
Quoted 5 lines
...
Quoted 1 line
+/* For
gpio_get_descwhich isEXPORT_SYMBOL_GPL()*/
gpio_get_desc()
Fixed in my local version.
Quoted 26 lines
and honestly I don't like this kind of includes (yes, I know sometimes it's the best compromise).
Quoted 1 line
+#include "
../../gpio/gpiolib.h"...
Quoted 19 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +19
-0+/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */ + chip =gpiochip_find (data->gpio_chip, x86_acpi_irq_helper_gpiochip_find); +if (!chip) +return -EPROBE_DEFER ; + + gpiod =gpiochip_get_desc (chip, data->index); +if (IS_ERR (gpiod)) { + ret =PTR_ERR (gpiod); +pr_err ("error %d getting GPIO %s %d\n" , ret, + data->gpio_chip, data->index); +return ret; + } + + irq =gpiod_to_irq (gpiod); +if (irq <0 ) { +pr_err ("error %d getting IRQ %s %d\n" , irq, + data->gpio_chip, data->index); +return irq; + }
Quoted 8 lines
drivers/platform/x86/x86-acpi-irq-helpers.h line 78
Quoted 6 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +6
-0+ + irq_type =acpi_dev_get_irq_type (data->trigger, data->polarity); +if (irq_type !=IRQ_TYPE_NONE && irq_type !=irq_get_trigger_type (irq)) +irq_set_irq_type (irq, irq_type); + +return irq;I'm wondering why it can't be a part of the GPIO ACPI library?
Interesting suggestion, but this really is only intended for the special case when the DSDT is missing this info. I'm a bit worried that having this available as a generic helper may lead to it getting used too much. But I guess we can just put a comment on it explaining that normally its use should be avoided.
I've added Mika to the Cc, Mika, what do you think about adding this as a new helper to the GPIO ACPI library ?
Regards,
Hans
Hi,
Quoted 59 lines · Hans de Goede
Hi,
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Hans de Goede
Add helper code to get Linux IRQ numbers given a description of the IRQ source (either IOAPIC index, or GPIO chip name + pin-number).
This is intended to be used to lookup Linux IRQ numbers in cases where the ACPI description for a device somehow lacks this info. This is only meant for use on x86 ACPI platforms.
This code is big/complex enough to warrant sharing, but too small to live in its own module, therefor
x86_acpi_irq_helper_get()is defined as a static inline helper function.Quoted 5 lines
...
Quoted 1 line
+/* For
gpio_get_descwhich isEXPORT_SYMBOL_GPL()*/
gpio_get_desc()Fixed in my local version.
Quoted 26 lines
and honestly I don't like this kind of includes (yes, I know sometimes it's the best compromise).
Quoted 1 line
+#include "
../../gpio/gpiolib.h"...
Quoted 19 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +19
-0+/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */ + chip =gpiochip_find (data->gpio_chip, x86_acpi_irq_helper_gpiochip_find); +if (!chip) +return -EPROBE_DEFER ; + + gpiod =gpiochip_get_desc (chip, data->index); +if (IS_ERR (gpiod)) { + ret =PTR_ERR (gpiod); +pr_err ("error %d getting GPIO %s %d\n" , ret, + data->gpio_chip, data->index); +return ret; + } + + irq =gpiod_to_irq (gpiod); +if (irq <0 ) { +pr_err ("error %d getting IRQ %s %d\n" , irq, + data->gpio_chip, data->index); +return irq; + }Quoted 8 lines
drivers/platform/x86/x86-acpi-irq-helpers.h line 78
Quoted 6 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +6
-0+ + irq_type =acpi_dev_get_irq_type (data->trigger, data->polarity); +if (irq_type !=IRQ_TYPE_NONE && irq_type !=irq_get_trigger_type (irq)) +irq_set_irq_type (irq, irq_type); + +return irq;I'm wondering why it can't be a part of the GPIO ACPI library?
Quoted 8 lines
Interesting suggestion, but this really is only intended for the special case when the DSDT is missing this info. I'm a bit worried that having this available as a generic helper may lead to it getting used too much. But I guess we can just put a comment on it explaining that normally its use should be avoided.
I've added Mika to the Cc, Mika, what do you think about adding this as a new helper to the GPIO ACPI library ?
Preferably no :-) Reason is that even if we add comment to the function you don't remember it after two weeks so the next patch adding another user will not be noticed by reviewers (unless tha name of the function clearly says it is a quirk/workaround).
Quoted 64 lines · Mika Westerberg
Quoted 63 lines · Hans de Goede
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Hans de Goede
Add helper code to get Linux IRQ numbers given a description of the IRQ source (either IOAPIC index, or GPIO chip name + pin-number).
This is intended to be used to lookup Linux IRQ numbers in cases where the ACPI description for a device somehow lacks this info. This is only meant for use on x86 ACPI platforms.
This code is big/complex enough to warrant sharing, but too small to live in its own module, therefor
x86_acpi_irq_helper_get()is defined as a static inline helper function.Quoted 5 lines
...
Quoted 1 line
+/* For
gpio_get_descwhich isEXPORT_SYMBOL_GPL()*/
gpio_get_desc()Fixed in my local version.
Quoted 26 lines
and honestly I don't like this kind of includes (yes, I know sometimes it's the best compromise).
Quoted 1 line
+#include "
../../gpio/gpiolib.h"...
Quoted 19 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +19
-0+/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */ + chip =gpiochip_find (data->gpio_chip, x86_acpi_irq_helper_gpiochip_find); +if (!chip) +return -EPROBE_DEFER ; + + gpiod =gpiochip_get_desc (chip, data->index); +if (IS_ERR (gpiod)) { + ret =PTR_ERR (gpiod); +pr_err ("error %d getting GPIO %s %d\n" , ret, + data->gpio_chip, data->index); +return ret; + } + + irq =gpiod_to_irq (gpiod); +if (irq <0 ) { +pr_err ("error %d getting IRQ %s %d\n" , irq, + data->gpio_chip, data->index); +return irq; + }Quoted 8 lines
drivers/platform/x86/x86-acpi-irq-helpers.h line 78
Quoted 6 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +6
-0+ + irq_type =acpi_dev_get_irq_type (data->trigger, data->polarity); +if (irq_type !=IRQ_TYPE_NONE && irq_type !=irq_get_trigger_type (irq)) +irq_set_irq_type (irq, irq_type); + +return irq;I'm wondering why it can't be a part of the GPIO ACPI library?
Interesting suggestion, but this really is only intended for the special case when the DSDT is missing this info. I'm a bit worried that having this available as a generic helper may lead to it getting used too much. But I guess we can just put a comment on it explaining that normally its use should be avoided.
Quoted 7 lines
Quoted 2 lines
I've added Mika to the Cc, Mika, what do you think about adding this as a new helper to the GPIO ACPI library ?
Preferably no :-) Reason is that even if we add comment to the function you don't remember it after two weeks so the next patch adding another user will not be noticed by reviewers (unless tha name of the function clearly says it is a quirk/workaround).
Oh, we have a solution for this already, it's called an export namespace. We may export symbols in its own namespace and any user must to import it. It will show immediately who is trying to do "bad things". Code duplication makes kernel bigger and harder to maintain. Imagine if there is an issue or refactoring happening in one copy of the code and missed in the other. How long would it take to discover that and fix it?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Hi,
Quoted 68 lines · Mika Westerberg
Hi,
Quoted 65 lines · Hans de Goede
Hi,
Quoted 13 lines · Andy Shevchenko
Quoted 11 lines · Hans de Goede
Add helper code to get Linux IRQ numbers given a description of the IRQ source (either IOAPIC index, or GPIO chip name + pin-number).
This is intended to be used to lookup Linux IRQ numbers in cases where the ACPI description for a device somehow lacks this info. This is only meant for use on x86 ACPI platforms.
This code is big/complex enough to warrant sharing, but too small to live in its own module, therefor
x86_acpi_irq_helper_get()is defined as a static inline helper function.Quoted 5 lines
...
Quoted 1 line
+/* For
gpio_get_descwhich isEXPORT_SYMBOL_GPL()*/
gpio_get_desc()Fixed in my local version.
Quoted 26 lines
and honestly I don't like this kind of includes (yes, I know sometimes it's the best compromise).
Quoted 1 line
+#include "
../../gpio/gpiolib.h"...
Quoted 19 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +19
-0+/* Like acpi_dev_gpio_irq_get(), but without parsing ACPI resources */ + chip =gpiochip_find (data->gpio_chip, x86_acpi_irq_helper_gpiochip_find); +if (!chip) +return -EPROBE_DEFER ; + + gpiod =gpiochip_get_desc (chip, data->index); +if (IS_ERR (gpiod)) { + ret =PTR_ERR (gpiod); +pr_err ("error %d getting GPIO %s %d\n" , ret, + data->gpio_chip, data->index); +return ret; + } + + irq =gpiod_to_irq (gpiod); +if (irq <0 ) { +pr_err ("error %d getting IRQ %s %d\n" , irq, + data->gpio_chip, data->index); +return irq; + }Quoted 8 lines
drivers/platform/x86/x86-acpi-irq-helpers.h line 78
Quoted 6 lines
drivers/platform/x86/x86-acpi-irq-helpers.h new file +6
-0+ + irq_type =acpi_dev_get_irq_type (data->trigger, data->polarity); +if (irq_type !=IRQ_TYPE_NONE && irq_type !=irq_get_trigger_type (irq)) +irq_set_irq_type (irq, irq_type); + +return irq;I'm wondering why it can't be a part of the GPIO ACPI library?
Interesting suggestion, but this really is only intended for the special case when the DSDT is missing this info. I'm a bit worried that having this available as a generic helper may lead to it getting used too much. But I guess we can just put a comment on it explaining that normally its use should be avoided.
Quoted 7 lines
Quoted 2 lines
I've added Mika to the Cc, Mika, what do you think about adding this as a new helper to the GPIO ACPI library ?
Preferably no :-) Reason is that even if we add comment to the function you don't remember it after two weeks so the next patch adding another user will not be noticed by reviewers (unless tha name of the function clearly says it is a quirk/workaround).
Right, I also just found another, better way of dealing with the second use-case for these helpers, which leaves only the upcoming x86-android-tablets kernel module as user. So for version 3 of that module I'm just going to fold these back into that module, since now that will be the only user of this kludge.
Turning this into a separate helper did result in a nice cleanup, so I'm going to keep things as is but just put them back into x86-android-tablets.c keeping them as is will also make it easier to factor them out again if that ever becomes necessary.
Regards,
Hans