diff mbox series

input: goodix: add poll mode for goodix touchscreen

Message ID 20250521025011.887562-1-qijian.guo@nxp.com
State Superseded
Headers show
Series input: goodix: add poll mode for goodix touchscreen | expand

Commit Message

Joseph Guo May 21, 2025, 2:50 a.m. UTC
goodix touchscreen only support interrupt mode by default.
Some panels like waveshare panel which is widely used on raspeberry pi
don't have interrupt pins and only work on i2c poll mode.
The waveshare panel 7inch panel use goodix gt911 touchscreen chip.

Signed-off-by: Joseph Guo <qijian.guo@nxp.com>
Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
---
Change from v1 to v2
- Remove unused variable in goodix_ts_data struct
- Use polling infrastructure
---
 drivers/input/touchscreen/goodix.c | 50 ++++++++++++++++++++++++++----
 1 file changed, 44 insertions(+), 6 deletions(-)

--
2.34.1

Comments

Hans de Goede May 21, 2025, 9:20 a.m. UTC | #1
Hi Joseph,

Thank you for the new version.

For the next version, the subject here should have been "[PATCH v2] input: ...".

You can do this by doing e.g. :

git format-patch -v2 HEAD~
git send-email v2-0001-....patch

On 21-May-25 4:50 AM, Joseph Guo wrote:
> goodix touchscreen only support interrupt mode by default.
> Some panels like waveshare panel which is widely used on raspeberry pi
> don't have interrupt pins and only work on i2c poll mode.
> The waveshare panel 7inch panel use goodix gt911 touchscreen chip.
> 
> Signed-off-by: Joseph Guo <qijian.guo@nxp.com>
> Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
> ---
> Change from v1 to v2
> - Remove unused variable in goodix_ts_data struct
> - Use polling infrastructure
> ---
>  drivers/input/touchscreen/goodix.c | 50 ++++++++++++++++++++++++++----
>  1 file changed, 44 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
> index aaf79ac50004..58e49e5cf148 100644
> --- a/drivers/input/touchscreen/goodix.c
> +++ b/drivers/input/touchscreen/goodix.c
> @@ -47,6 +47,7 @@
>  #define RESOLUTION_LOC		1
>  #define MAX_CONTACTS_LOC	5
>  #define TRIGGER_LOC		6
> +#define GOODIX_POLL_INTERVAL_MS		17	/* 17ms = 60fps */
> 
>  /* Our special handling for GPIO accesses through ACPI is x86 specific */
>  #if defined CONFIG_X86 && defined CONFIG_ACPI
> @@ -497,6 +498,14 @@ static void goodix_process_events(struct goodix_ts_data *ts)
>  	input_sync(ts->input_dev);
>  }
> 
> +static void goodix_ts_work_i2c_poll(struct input_dev *input)
> +{
> +	struct goodix_ts_data *ts = input_get_drvdata(input);
> +
> +	goodix_process_events(ts);
> +	goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0);
> +}
> +
>  /**
>   * goodix_ts_irq_handler - The IRQ handler
>   *
> @@ -523,16 +532,33 @@ static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
>  	return IRQ_HANDLED;
>  }
> 
> +static void goodix_enable_irq(struct goodix_ts_data *ts)
> +{
> +	if (ts->client->irq)
> +		enable_irq(ts->client->irq);
> +}
> +
> +static void goodix_disable_irq(struct goodix_ts_data *ts)
> +{
> +	if (ts->client->irq)
> +		disable_irq(ts->client->irq);
> +}
> +
>  static void goodix_free_irq(struct goodix_ts_data *ts)
>  {
> -	devm_free_irq(&ts->client->dev, ts->client->irq, ts);
> +	if (ts->client->irq)
> +		devm_free_irq(&ts->client->dev, ts->client->irq, ts);
>  }
> 
>  static int goodix_request_irq(struct goodix_ts_data *ts)
>  {
> -	return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
> -					 NULL, goodix_ts_irq_handler,
> -					 ts->irq_flags, ts->client->name, ts);
> +	if (ts->client->irq) {
> +		return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
> +						 NULL, goodix_ts_irq_handler,
> +						 ts->irq_flags, ts->client->name, ts);
> +		}
> +	else
> +		return 0;
>  }

The '}' here is wrongly indented, also if you use {}, which is not strictly
necessary here, please use them in both branches of the if.

Since in this function we're dealing with a multi-line statement I think it
might be better to write this as:

static int goodix_request_irq(struct goodix_ts_data *ts)
{
	if (!ts->client->irq)
		return 0;

	return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
					 NULL, goodix_ts_irq_handler,
					 ts->irq_flags, ts->client->name, ts);
}

This will also make the diff smaller.

Or you can keep what you have and drop the {}.

Regards,

Hans





>  static int goodix_check_cfg_8(struct goodix_ts_data *ts, const u8 *cfg, int len)
> @@ -1229,6 +1255,18 @@ static int goodix_configure_dev(struct goodix_ts_data *ts)
>  		return error;
>  	}
> 
> +	input_set_drvdata(ts->input_dev, ts);
> +
> +	if (!ts->client->irq) {
> +		error = input_setup_polling(ts->input_dev, goodix_ts_work_i2c_poll);
> +		if (error) {
> +			dev_err(&ts->client->dev,
> +				 "could not set up polling mode, %d\n", error);
> +			return error;
> +		}
> +		input_set_poll_interval(ts->input_dev, GOODIX_POLL_INTERVAL_MS);
> +	}
> +
>  	error = input_register_device(ts->input_dev);
>  	if (error) {
>  		dev_err(&ts->client->dev,
> @@ -1435,7 +1473,7 @@ static int goodix_suspend(struct device *dev)
> 
>  	/* We need gpio pins to suspend/resume */
>  	if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
> -		disable_irq(client->irq);
> +		goodix_disable_irq(ts);
>  		return 0;
>  	}
> 
> @@ -1479,7 +1517,7 @@ static int goodix_resume(struct device *dev)
>  	int error;
> 
>  	if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
> -		enable_irq(client->irq);
> +		goodix_enable_irq(ts);
>  		return 0;
>  	}
> 
> --
> 2.34.1
>
Joseph Guo May 22, 2025, 2:05 a.m. UTC | #2
Hi Hans,

Thanks for your great comment. I already made the change in v3.

Best Regards.
Joseph

-----邮件原件-----
发件人: Hans de Goede <hdegoede@redhat.com> 
发送时间: Wednesday, May 21, 2025 5:20 PM
收件人: Joseph Guo <qijian.guo@nxp.com>; Bastien Nocera <hadess@hadess.net>; Dmitry Torokhov <dmitry.torokhov@gmail.com>; open list:GOODIX TOUCHSCREEN <linux-input@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>
抄送: Bough Chen <haibo.chen@nxp.com>; Justin Jiang <justin.jiang@nxp.com>
主题: [EXT] Re: [PATCH] input: goodix: add poll mode for goodix touchscreen

Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button


Hi Joseph,

Thank you for the new version.

For the next version, the subject here should have been "[PATCH v2] input: ...".

You can do this by doing e.g. :

git format-patch -v2 HEAD~
git send-email v2-0001-....patch

On 21-May-25 4:50 AM, Joseph Guo wrote:
> goodix touchscreen only support interrupt mode by default.
> Some panels like waveshare panel which is widely used on raspeberry pi 
> don't have interrupt pins and only work on i2c poll mode.
> The waveshare panel 7inch panel use goodix gt911 touchscreen chip.
>
> Signed-off-by: Joseph Guo <qijian.guo@nxp.com>
> Reviewed-by: Haibo Chen <haibo.chen@nxp.com>
> ---
> Change from v1 to v2
> - Remove unused variable in goodix_ts_data struct
> - Use polling infrastructure
> ---
>  drivers/input/touchscreen/goodix.c | 50 
> ++++++++++++++++++++++++++----
>  1 file changed, 44 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/input/touchscreen/goodix.c 
> b/drivers/input/touchscreen/goodix.c
> index aaf79ac50004..58e49e5cf148 100644
> --- a/drivers/input/touchscreen/goodix.c
> +++ b/drivers/input/touchscreen/goodix.c
> @@ -47,6 +47,7 @@
>  #define RESOLUTION_LOC               1
>  #define MAX_CONTACTS_LOC     5
>  #define TRIGGER_LOC          6
> +#define GOODIX_POLL_INTERVAL_MS              17      /* 17ms = 60fps */
>
>  /* Our special handling for GPIO accesses through ACPI is x86 
> specific */  #if defined CONFIG_X86 && defined CONFIG_ACPI @@ -497,6 
> +498,14 @@ static void goodix_process_events(struct goodix_ts_data *ts)
>       input_sync(ts->input_dev);
>  }
>
> +static void goodix_ts_work_i2c_poll(struct input_dev *input) {
> +     struct goodix_ts_data *ts = input_get_drvdata(input);
> +
> +     goodix_process_events(ts);
> +     goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0); }
> +
>  /**
>   * goodix_ts_irq_handler - The IRQ handler
>   *
> @@ -523,16 +532,33 @@ static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
>       return IRQ_HANDLED;
>  }
>
> +static void goodix_enable_irq(struct goodix_ts_data *ts) {
> +     if (ts->client->irq)
> +             enable_irq(ts->client->irq); }
> +
> +static void goodix_disable_irq(struct goodix_ts_data *ts) {
> +     if (ts->client->irq)
> +             disable_irq(ts->client->irq); }
> +
>  static void goodix_free_irq(struct goodix_ts_data *ts)  {
> -     devm_free_irq(&ts->client->dev, ts->client->irq, ts);
> +     if (ts->client->irq)
> +             devm_free_irq(&ts->client->dev, ts->client->irq, ts);
>  }
>
>  static int goodix_request_irq(struct goodix_ts_data *ts)  {
> -     return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
> -                                      NULL, goodix_ts_irq_handler,
> -                                      ts->irq_flags, ts->client->name, ts);
> +     if (ts->client->irq) {
> +             return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
> +                                              NULL, goodix_ts_irq_handler,
> +                                              ts->irq_flags, ts->client->name, ts);
> +             }
> +     else
> +             return 0;
>  }

The '}' here is wrongly indented, also if you use {}, which is not strictly necessary here, please use them in both branches of the if.

Since in this function we're dealing with a multi-line statement I think it might be better to write this as:

static int goodix_request_irq(struct goodix_ts_data *ts) {
        if (!ts->client->irq)
                return 0;

        return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
                                         NULL, goodix_ts_irq_handler,
                                         ts->irq_flags, ts->client->name, ts); }

This will also make the diff smaller.

Or you can keep what you have and drop the {}.

Regards,

Hans





>  static int goodix_check_cfg_8(struct goodix_ts_data *ts, const u8 
> *cfg, int len) @@ -1229,6 +1255,18 @@ static int goodix_configure_dev(struct goodix_ts_data *ts)
>               return error;
>       }
>
> +     input_set_drvdata(ts->input_dev, ts);
> +
> +     if (!ts->client->irq) {
> +             error = input_setup_polling(ts->input_dev, goodix_ts_work_i2c_poll);
> +             if (error) {
> +                     dev_err(&ts->client->dev,
> +                              "could not set up polling mode, %d\n", error);
> +                     return error;
> +             }
> +             input_set_poll_interval(ts->input_dev, GOODIX_POLL_INTERVAL_MS);
> +     }
> +
>       error = input_register_device(ts->input_dev);
>       if (error) {
>               dev_err(&ts->client->dev, @@ -1435,7 +1473,7 @@ static 
> int goodix_suspend(struct device *dev)
>
>       /* We need gpio pins to suspend/resume */
>       if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
> -             disable_irq(client->irq);
> +             goodix_disable_irq(ts);
>               return 0;
>       }
>
> @@ -1479,7 +1517,7 @@ static int goodix_resume(struct device *dev)
>       int error;
>
>       if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
> -             enable_irq(client->irq);
> +             goodix_enable_irq(ts);
>               return 0;
>       }
>
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index aaf79ac50004..58e49e5cf148 100644
--- a/drivers/input/touchscreen/goodix.c
+++ b/drivers/input/touchscreen/goodix.c
@@ -47,6 +47,7 @@ 
 #define RESOLUTION_LOC		1
 #define MAX_CONTACTS_LOC	5
 #define TRIGGER_LOC		6
+#define GOODIX_POLL_INTERVAL_MS		17	/* 17ms = 60fps */

 /* Our special handling for GPIO accesses through ACPI is x86 specific */
 #if defined CONFIG_X86 && defined CONFIG_ACPI
@@ -497,6 +498,14 @@  static void goodix_process_events(struct goodix_ts_data *ts)
 	input_sync(ts->input_dev);
 }

+static void goodix_ts_work_i2c_poll(struct input_dev *input)
+{
+	struct goodix_ts_data *ts = input_get_drvdata(input);
+
+	goodix_process_events(ts);
+	goodix_i2c_write_u8(ts->client, GOODIX_READ_COOR_ADDR, 0);
+}
+
 /**
  * goodix_ts_irq_handler - The IRQ handler
  *
@@ -523,16 +532,33 @@  static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }

+static void goodix_enable_irq(struct goodix_ts_data *ts)
+{
+	if (ts->client->irq)
+		enable_irq(ts->client->irq);
+}
+
+static void goodix_disable_irq(struct goodix_ts_data *ts)
+{
+	if (ts->client->irq)
+		disable_irq(ts->client->irq);
+}
+
 static void goodix_free_irq(struct goodix_ts_data *ts)
 {
-	devm_free_irq(&ts->client->dev, ts->client->irq, ts);
+	if (ts->client->irq)
+		devm_free_irq(&ts->client->dev, ts->client->irq, ts);
 }

 static int goodix_request_irq(struct goodix_ts_data *ts)
 {
-	return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
-					 NULL, goodix_ts_irq_handler,
-					 ts->irq_flags, ts->client->name, ts);
+	if (ts->client->irq) {
+		return devm_request_threaded_irq(&ts->client->dev, ts->client->irq,
+						 NULL, goodix_ts_irq_handler,
+						 ts->irq_flags, ts->client->name, ts);
+		}
+	else
+		return 0;
 }

 static int goodix_check_cfg_8(struct goodix_ts_data *ts, const u8 *cfg, int len)
@@ -1229,6 +1255,18 @@  static int goodix_configure_dev(struct goodix_ts_data *ts)
 		return error;
 	}

+	input_set_drvdata(ts->input_dev, ts);
+
+	if (!ts->client->irq) {
+		error = input_setup_polling(ts->input_dev, goodix_ts_work_i2c_poll);
+		if (error) {
+			dev_err(&ts->client->dev,
+				 "could not set up polling mode, %d\n", error);
+			return error;
+		}
+		input_set_poll_interval(ts->input_dev, GOODIX_POLL_INTERVAL_MS);
+	}
+
 	error = input_register_device(ts->input_dev);
 	if (error) {
 		dev_err(&ts->client->dev,
@@ -1435,7 +1473,7 @@  static int goodix_suspend(struct device *dev)

 	/* We need gpio pins to suspend/resume */
 	if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
-		disable_irq(client->irq);
+		goodix_disable_irq(ts);
 		return 0;
 	}

@@ -1479,7 +1517,7 @@  static int goodix_resume(struct device *dev)
 	int error;

 	if (ts->irq_pin_access_method == IRQ_PIN_ACCESS_NONE) {
-		enable_irq(client->irq);
+		goodix_enable_irq(ts);
 		return 0;
 	}