Linux-ACPI Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] gpio: acpi: add quirk to override GpioInt polarity
@ 2019-08-30  0:00 Peter Cai
  2019-08-30  0:00 ` [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max Peter Cai
  2019-08-30 11:42 ` [PATCH 1/2] gpio: acpi: add quirk to override GpioInt polarity Andy Shevchenko
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Cai @ 2019-08-30  0:00 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: Peter Cai, Mika Westerberg, Andy Shevchenko, Linus Walleij,
	Bartosz Golaszewski, Bastien Nocera, Dmitry Torokhov,
	Rafael J. Wysocki, Len Brown, linux-gpio, linux-acpi,
	linux-kernel, linux-input

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.

Signed-off-by: Peter Cai <peter@typeblog.net>
---
 drivers/gpio/gpiolib-acpi.c | 10 +++++++++-
 include/linux/acpi.h        |  6 ++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c
index 39f2f9035c11..1a07c79ca2de 100644
--- a/drivers/gpio/gpiolib-acpi.c
+++ b/drivers/gpio/gpiolib-acpi.c
@@ -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);
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 9426b9aaed86..6569773ceffd 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -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;
 };
-- 
2.23.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
  2019-08-30  0:00 [PATCH 1/2] gpio: acpi: add quirk to override GpioInt polarity Peter Cai
@ 2019-08-30  0:00 ` Peter Cai
  2019-08-30 11:55   ` Andy Shevchenko
  2019-09-02  6:35   ` kbuild test robot
  2019-08-30 11:42 ` [PATCH 1/2] gpio: acpi: add quirk to override GpioInt polarity Andy Shevchenko
  1 sibling, 2 replies; 7+ messages in thread
From: Peter Cai @ 2019-08-30  0:00 UTC (permalink / raw)
  To: unlisted-recipients:; (no To-header on input)
  Cc: Peter Cai, Mika Westerberg, Andy Shevchenko, Linus Walleij,
	Bartosz Golaszewski, Bastien Nocera, Dmitry Torokhov,
	Rafael J. Wysocki, Len Brown, linux-gpio, linux-acpi,
	linux-kernel, linux-input

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.

Signed-off-by: Peter Cai <peter@typeblog.net>
---
 drivers/input/touchscreen/goodix.c | 37 ++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index 5178ea8b5f30..65b8d04b6dcf 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -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)) {
-- 
2.23.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] gpio: acpi: add quirk to override GpioInt polarity
  2019-08-30  0:00 [PATCH 1/2] gpio: acpi: add quirk to override GpioInt polarity Peter Cai
  2019-08-30  0:00 ` [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max Peter Cai
@ 2019-08-30 11:42 ` Andy Shevchenko
  1 sibling, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2019-08-30 11:42 UTC (permalink / raw)
  To: Peter Cai
  Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski,
	Bastien Nocera, Dmitry Torokhov, Rafael J. Wysocki, Len Brown,
	linux-gpio, linux-acpi, linux-kernel, linux-input

On Fri, Aug 30, 2019 at 08:00:23AM +0800, Peter Cai wrote:
> 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.

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.

>  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.

>  			lookup->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.

> +				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 = ...;
	}

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
  2019-08-30  0:00 ` [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max Peter Cai
@ 2019-08-30 11:55   ` Andy Shevchenko
  2019-08-30 15:32     ` Peter Cai
       [not found]     ` <CA+Zf_0etfu7282TQ4wYE8tOrhh2Je4aV4Dz5tgC_wt7=FMAidA@mail.gmail.com>
  2019-09-02  6:35   ` kbuild test robot
  1 sibling, 2 replies; 7+ messages in thread
From: Andy Shevchenko @ 2019-08-30 11:55 UTC (permalink / raw)
  To: Peter Cai
  Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski,
	Bastien Nocera, Dmitry Torokhov, Rafael J. Wysocki, Len Brown,
	linux-gpio, linux-acpi, linux-kernel, linux-input

On Fri, Aug 30, 2019 at 08:00:24AM +0800, Peter Cai wrote:
> 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.

> +#ifdef CONFIG_ACPI

I guess most of these #ifdef:s makes code less readable for exchange of saving
few bytes in the module footprint.

> +	{ "irq-gpios", &irq_gpios_default, 1,
> +		ACPI_GPIO_QUIRK_OVERRIDE_POLARITY },

One line?

> +		.matches = {
> +			DMI_MATCH(DMI_SYS_VENDOR, "GPD"),
> +			DMI_MATCH(DMI_PRODUCT_NAME, "P2 MAX")

Comma at the end?

> +		},
> +		.driver_data = &gpio_mapping_force_irq_active_high

Ditto.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
  2019-08-30 11:55   ` Andy Shevchenko
@ 2019-08-30 15:32     ` Peter Cai
       [not found]     ` <CA+Zf_0etfu7282TQ4wYE8tOrhh2Je4aV4Dz5tgC_wt7=FMAidA@mail.gmail.com>
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Cai @ 2019-08-30 15:32 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski,
	Bastien Nocera, Dmitry Torokhov, Rafael J. Wysocki, Len Brown,
	linux-gpio, linux-acpi, linux-kernel, linux-input

On August 30, 2019 7:55:05 PM GMT+08:00, Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
>On Fri, Aug 30, 2019 at 08:00:24AM +0800, Peter Cai wrote:
>> 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.
>
>> +#ifdef CONFIG_ACPI
>
>I guess most of these #ifdef:s makes code less readable for exchange of
>saving
>few bytes in the module footprint.
>
>> +	{ "irq-gpios", &irq_gpios_default, 1,
>> +		ACPI_GPIO_QUIRK_OVERRIDE_POLARITY },
>
>One line?
>
>> +		.matches = {
>> +			DMI_MATCH(DMI_SYS_VENDOR, "GPD"),
>> +			DMI_MATCH(DMI_PRODUCT_NAME, "P2 MAX")
>
>Comma at the end?
>
>> +		},
>> +		.driver_data = &gpio_mapping_force_irq_active_high
>
>Ditto.

> 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?

> 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.

-- 
Regards,
Xiyu Cai

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
       [not found]     ` <CA+Zf_0etfu7282TQ4wYE8tOrhh2Je4aV4Dz5tgC_wt7=FMAidA@mail.gmail.com>
@ 2019-08-30 18:16       ` Andy Shevchenko
  0 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2019-08-30 18:16 UTC (permalink / raw)
  To: Peter Cai
  Cc: Mika Westerberg, Linus Walleij, Bartosz Golaszewski,
	Bastien Nocera, Dmitry Torokhov, Rafael J. Wysocki, Len Brown,
	linux-gpio, linux-acpi, linux-kernel, linux-input

On Fri, Aug 30, 2019 at 11:15:27PM +0800, Peter Cai wrote:
> On Fri, Aug 30, 2019, 7:55 PM Andy Shevchenko <
> andriy.shevchenko@linux.intel.com> wrote:

> > 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_gpios does not exist without ACPI defined, thus
> the last guard must exist),

This is not correct.

> 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.

> Should we use __maybe_unused here 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`.

> > 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.

I see. So, this is for Dmitry's preferences.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max
  2019-08-30  0:00 ` [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max Peter Cai
  2019-08-30 11:55   ` Andy Shevchenko
@ 2019-09-02  6:35   ` kbuild test robot
  1 sibling, 0 replies; 7+ messages in thread
From: kbuild test robot @ 2019-09-02  6:35 UTC (permalink / raw)
  To: Peter Cai
  Cc: kbuild-all, Peter Cai, Mika Westerberg, Andy Shevchenko,
	Linus Walleij, Bartosz Golaszewski, Bastien Nocera,
	Dmitry Torokhov, Rafael J. Wysocki, Len Brown, linux-gpio,
	linux-acpi, linux-kernel, linux-input

[-- Attachment #1: Type: text/plain, Size: 1934 bytes --]

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
Reported-by: kbuild test robot <lkp@intel.com>

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

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 50840 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-30  0:00 [PATCH 1/2] gpio: acpi: add quirk to override GpioInt polarity Peter Cai
2019-08-30  0:00 ` [PATCH 2/2] touchscreen: goodix: define GPIO mapping for GPD P2 Max Peter Cai
2019-08-30 11:55   ` Andy Shevchenko
2019-08-30 15:32     ` Peter Cai
     [not found]     ` <CA+Zf_0etfu7282TQ4wYE8tOrhh2Je4aV4Dz5tgC_wt7=FMAidA@mail.gmail.com>
2019-08-30 18:16       ` Andy Shevchenko
2019-09-02  6:35   ` kbuild test robot
2019-08-30 11:42 ` [PATCH 1/2] gpio: acpi: add quirk to override GpioInt polarity Andy Shevchenko

Linux-ACPI Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-acpi/0 linux-acpi/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-acpi linux-acpi/ https://lore.kernel.org/linux-acpi \
		linux-acpi@vger.kernel.org linux-acpi@archiver.kernel.org
	public-inbox-index linux-acpi


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-acpi


AGPL code for this site: git clone https://public-inbox.org/ public-inbox