gpio: acpi: add quirk to override GpioInt polarity
Subsystems (5)
PATCH 1/2 gpio: acpi: add quirk to override GpioInt polarity
On GPD P2 Max, the firmware could not reset the touch panel correctly. The kernel needs to take on the job instead, but the GpioInt definition in DSDT specifies ActiveHigh while the GPIO pin should actually be ActiveLow.
We need to override the polarity defined by DSDT. The GPIO driver already allows defining polarity in acpi_gpio_params, but the option is not applied to GpioInt.
This patch adds a new quirk that enables the polarity specified in acpi_gpio_params to also be applied to GpioInt.
--- drivers/gpio/gpiolib-acpi.c | 10 +++++++++- include/linux/acpi.h | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib-acpi.c +9 -1
@@ -583,13 +583,21 @@ static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data)/* * Polarity and triggering are only specified for GpioInt * resource. +* Polarity specified by GpioInt may be ignored if +* ACPI_GPIO_QUIRK_OVERRIDE_POLARITY is set. * Note: we expect here: * - ACPI_ACTIVE_LOW == GPIO_ACTIVE_LOW * - ACPI_ACTIVE_HIGH == GPIO_ACTIVE_HIGH */ if (lookup->info.gpioint) { lookup->info.flags =GPIOD_IN ; - lookup->info.polarity = agpio->polarity; +if (lookup->info.quirks & +ACPI_GPIO_QUIRK_OVERRIDE_POLARITY ) { +dev_warn (&lookup->info.adev->dev,FW_BUG "Incorrect polarity specified by GpioInt, overriding.\n" ); + lookup->info.polarity = lookup->active_low; + }else { + lookup->info.polarity = agpio->polarity; + } lookup->info.triggering = agpio->triggering; }else { lookup->info.flags =acpi_gpio_to_gpiod_flags (agpio);
include/linux/acpi.h +6 -0
@@ -1014,6 +1014,12 @@ struct acpi_gpio_mapping {* get GpioIo type explicitly, this quirk may be used. */ #define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1) +/* +* Use the GPIO polarity (ActiveHigh / ActiveLow) from acpi_gpio_params +* for GpioInt as well. The default behavior is to use the one specified +* by GpioInt, which can be incorrect on some devices. +*/ +#define ACPI_GPIO_QUIRK_OVERRIDE_POLARITY BIT(2)unsigned int quirks; };
Signature · 1 line
2.23.0
PATCH 2/2 touchscreen: goodix: define GPIO mapping for GPD P2 Max
The firmware of GPD P2 Max could not handle panel resets although code is present in DSDT. The kernel needs to take on this job instead, but the DSDT does not provide _DSD, rendering kernel helpless when trying to find the respective GPIO pins.
Fortunately, this time GPD has proper DMI vendor / product strings that we could match against. We simply apply an acpi_gpio_mapping table when GPD P2 Max is matched.
Additionally, the DSDT definition of the irq pin specifies a wrong polarity. The new quirk introduced in the previous patch (ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) is applied to correct this.
--- drivers/input/touchscreen/goodix.c | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
drivers/input/touchscreen/goodix.c +37 -0
@@ -144,6 +144,34 @@ static const struct dmi_system_id rotated_screen[] = { {} }; +#ifdef CONFIG_ACPI +static const struct acpi_gpio_params irq_gpios_default = {0 ,0 , false }; +static const struct acpi_gpio_params reset_gpios_default = {1 ,0 , false }; +static const struct acpi_gpio_mapping gpio_mapping_force_irq_active_high[] = { + {"irq-gpios" , &irq_gpios_default,1 , +ACPI_GPIO_QUIRK_OVERRIDE_POLARITY }, + {"reset-gpios" , &reset_gpios_default,1 }, + {} +}; + +/* +* Devices that need acpi_gpio_mapping to function correctly +*/ +static const struct dmi_system_id need_gpio_mapping[] = { +#if defined(CONFIG_DMI) && defined(CONFIG_X86) + { + .ident ="GPD P2 Max" , + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"GPD" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"P2 MAX" ) + }, + .driver_data = &gpio_mapping_force_irq_active_high + }, +#endif + {} +}; +#endif +/** * goodix_i2c_read - read data from a register of the i2c slave device. *
@@ -796,6 +824,15 @@ static int goodix_ts_probe(struct i2c_client *client,struct goodix_ts_data *ts;int error; +#ifdef CONFIG_ACPI +struct dmi_system_id *dmi_match; + + dmi_match =dmi_first_match (need_gpio_mapping); +if (dmi_match) +devm_acpi_dev_add_driver_gpios (&client->dev, + dmi_match->driver_data); +#endif +dev_dbg (&client->dev,"I2C Address: 0x%02x\n" , client->addr);if (!i2c_check_functionality (client->adapter,I2C_FUNC_I2C )) {
Signature · 1 line
2.23.0
Re: [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
Quoted 9 lines · Peter Cai
The firmware of GPD P2 Max could not handle panel resets although code is present in DSDT. The kernel needs to take on this job instead, but the DSDT does not provide
_DSD, rendering kernel helpless when trying to find the respective GPIO pins.Fortunately, this time GPD has proper DMI vendor / product strings that we could match against. We simply apply an
acpi_gpio_mappingtable when GPD P2 Max is matched.
Quoted 5 lines
Additionally, the DSDT definition of the irq pin specifies a wrong polarity. The new quirk introduced in the previous patch (
ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) is applied to correct this.+#ifdef
CONFIG_ACPI
I guess most of these #ifdef:s makes code less readable for exchange of saving few bytes in the module footprint.
drivers/input/touchscreen/goodix.c static const struct dmi_system_id rotated_screen[] = { · line 152
Quoted 2 lines
drivers/input/touchscreen/goodix.c +2
-0+ {"irq-gpios" , &irq_gpios_default,1 , + ACPI_GPIO_QUIRK_OVERRIDE_POLARITY },
One line?
drivers/input/touchscreen/goodix.c static const struct dmi_system_id rotated_screen[] = { · line 166
Quoted 3 lines
drivers/input/touchscreen/goodix.c +3
-0+ .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"GPD" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"P2 MAX" )
Comma at the end?
drivers/input/touchscreen/goodix.c static const struct dmi_system_id rotated_screen[] = { · line 168
Quoted 2 lines
drivers/input/touchscreen/goodix.c +2
-0+ }, + .driver_data = &gpio_mapping_force_irq_active_high
Ditto.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
Quoted 35 lines · Andy Shevchenko
Quoted 1 line · Peter Cai
The firmware of GPD P2 Max could not handle panel resets although
code
Quoted 2 lines
is present in DSDT. The kernel needs to take on this job instead, but the DSDT does not provide
_DSD, rendering kernel helpless when tryingto
Quoted 3 lines
find the respective GPIO pins.
Fortunately, this time GPD has proper DMI vendor / product strings
that
Quoted 1 line
we could match against. We simply apply an
acpi_gpio_mappingtablewhen
Quoted 7 lines
GPD P2 Max is matched.
Additionally, the DSDT definition of the irq pin specifies a wrong polarity. The new quirk introduced in the previous patch (
ACPI_GPIO_QUIRK_OVERRIDE_POLARITY) is applied to correct this.+#ifdef
CONFIG_ACPII guess most of these #ifdef:s makes code less readable for exchange of saving
few bytes in the module footprint.drivers/input/touchscreen/goodix.c static const struct dmi_system_id rotated_screen[] = { · line 152
Quoted 2 lines
drivers/input/touchscreen/goodix.c +2
-0+ {"irq-gpios" , &irq_gpios_default,1 , + ACPI_GPIO_QUIRK_OVERRIDE_POLARITY },One line?
drivers/input/touchscreen/goodix.c static const struct dmi_system_id rotated_screen[] = { · line 166
Quoted 3 lines
drivers/input/touchscreen/goodix.c +3
-0+ .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"GPD" ), +DMI_MATCH (DMI_PRODUCT_NAME ,"P2 MAX" )Comma at the end?
Quoted 6 lines
drivers/input/touchscreen/goodix.c static const struct dmi_system_id rotated_screen[] = { · line 168
Quoted 2 lines
drivers/input/touchscreen/goodix.c +2
-0+ }, + .driver_data = &gpio_mapping_force_irq_active_highDitto.
I guess most of these #ifdef:s makes code less readable for exchange of saving
few bytes in the module footprint.
Since they can only be used when ACPI is supported (devm_acpi_dev_add_driver_gpios does not exist without ACPI defined, thus the last guard must exist), if they were not guarded then we would be left with a bunch of unused variables warnings when building without ACPI which doesn't seem good.
Should we use __maybe_unused here instead of #ifdef guards?
Quoted 1 line
Comma at the end?
I was trying to follow the style of this driver but it doesn't seem to be really consistent within itself. Another dmi_system_id definition in the same file mixed both styles so I was kind of confused.
Signature · 2 lines
Regards, Xiyu Cai
A message that is not in the archive (sent off-list or not yet received): CA+Zf_0etfu7282TQ4wYE8tOrhh2Je4aV4Dz5tgC_wt7=FMAidA@mail.gmail.com
Re: [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
Quoted 11 lines · Peter Cai
Quoted 1 line · Andy Shevchenko
I guess most of these #ifdef:s makes code less readable for exchange of
saving
few bytes in the module footprint.Well since they can only be used when ACPI is supported
(
devm_acpi_dev_add_driver_gpiosdoes not exist without ACPI defined, thus the last guard must exist),
This is not correct.
Quoted 3 lines
if they were not guarded then we would be left
with a bunch of unused variables warnings when building without ACPI which doesn't seem good.
Good / no-good is only matter of few dozens of bytes here and there to be saved.
Quoted 1 line
Should we use
__maybe_unusedhere instead of #ifdef guards?
No, it won't make sense, because the structures will be part of _add_driver_gpio() call, due to which compiler likely can't recognize unused structures. However, you may try with warnings enabled make W=1.
Quoted 5 lines
Quoted 1 line
Comma at the end?
I was trying to follow the style of this driver but it doesn't seem to be really consistent within itself. Another
dmi_system_iddefinition in the same file mixed both styles so I was kind of confused.
I see. So, this is for Dmitry's preferences.
Signature · 2 lines
With Best Regards, Andy Shevchenko
kbuild test robot
build botRe: [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
In reply to Peter CaiThank you for the patch! Perhaps something to improve:
Hi Peter,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[cannot apply to v5.3-rc6 next-20190830]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Peter-Cai/gpio-acpi-add-quirk-to-override-GpioInt-polarity/20190902-004801
config: x86_64-fedora-25 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-11) 7.4.0 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 If you fix the issue, kindly add following tag
All warnings (new ones prefixed by >>):
>> drivers/input/touchscreen/goodix.c:168:18: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-array-qualifiers]
.driver_data = &gpio_mapping_force_irq_active_high
^
drivers/input/touchscreen/goodix.c: In function 'goodix_ts_probe':
>> drivers/input/touchscreen/goodix.c:830:12: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
dmi_match = dmi_first_match(need_gpio_mapping);
^vim +/const +168 drivers/input/touchscreen/goodix.c
156
157 /*
158 * Devices that need acpi_gpio_mapping to function correctly
159 */
160 static const struct dmi_system_id need_gpio_mapping[] = {
161 #if defined(CONFIG_DMI) && defined(CONFIG_X86)
162 {
163 .ident = "GPD P2 Max",
164 .matches = {
165 DMI_MATCH(DMI_SYS_VENDOR, "GPD"),
166 DMI_MATCH(DMI_PRODUCT_NAME, "P2 MAX")
167 },
> 168 .driver_data = &gpio_mapping_force_irq_active_high
169 },
170 #endif
171 {}
172 };
173 #endif
174
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 11 lines · Peter Cai
On GPD P2 Max, the firmware could not reset the touch panel correctly. The kernel needs to take on the job instead, but the GpioInt definition in DSDT specifies ActiveHigh while the GPIO pin should actually be ActiveLow.
We need to override the polarity defined by DSDT. The GPIO driver already allows defining polarity in
acpi_gpio_params, but the option is not applied to GpioInt.This patch adds a new quirk that enables the polarity specified in
acpi_gpio_paramsto also be applied to GpioInt.
In general if it's really the case, I'm not objecting to have another quirk. So, I would wait for the comments on the second patch to see how it's going.
Quoted 1 line
include/linux/acpi.h | 6 ++++++
The GPIO part of the header had been moved to the drivers/gpio/gpiolib-acpi.h. Please, base your series on top of the gpio/for-next.
drivers/gpio/gpiolib-acpi.c static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data) · line 595
Quoted 5 lines
drivers/gpio/gpiolib-acpi.c +2
-1lookup->info.flags =GPIOD_IN ; - lookup->info.polarity = agpio->polarity; +if (lookup->info.quirks & +ACPI_GPIO_QUIRK_OVERRIDE_POLARITY ) {
Disregard checkpatch I would leave this on one line.
drivers/gpio/gpiolib-acpi.c static int acpi_populate_gpio_lookup(struct acpi_resource *ares, void *data) · line 601
Quoted 6 lines
drivers/gpio/gpiolib-acpi.c +5
-0+dev_warn (&lookup->info.adev->dev,FW_BUG "Incorrect polarity specified by GpioInt, overriding.\n" ); + lookup->info.polarity = lookup->active_low; + }else { + lookup->info.polarity = agpio->polarity; + } lookup->info.triggering = agpio->triggering;
Since the quirk makes sense only for GpioInt and basically no-op for GpioIo, I would move the check out of if (gpioint) {} else {} conditional:
if (gpioint) {
...
} else {
...
}
if (quirk) {
dev_warn();
polarity = ...;
}Signature · 2 lines
With Best Regards, Andy Shevchenko