linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] LF-15225 input: goodix: add poll mode for goodix touchscreen
@ 2025-05-22  2:04 Joseph Guo
  2025-05-22  9:33 ` Hans de Goede
  2025-06-30  1:28 ` Dmitry Torokhov
  0 siblings, 2 replies; 3+ messages in thread
From: Joseph Guo @ 2025-05-22  2:04 UTC (permalink / raw)
  To: Bastien Nocera, Hans de Goede, Dmitry Torokhov,
	open list:GOODIX TOUCHSCREEN, open list
  Cc: qijian.guo, haibo.chen, justin.jiang

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
---
Change from v2 to v3
- Modify goodix_request_irq to make less diff
---
 drivers/input/touchscreen/goodix.c | 43 +++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
index aaf79ac50004..8e72174f486d 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,13 +532,29 @@ 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)
 {
+	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);
@@ -1229,6 +1254,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 +1472,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 +1516,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


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

* Re: [PATCH v3] LF-15225 input: goodix: add poll mode for goodix touchscreen
  2025-05-22  2:04 [PATCH v3] LF-15225 input: goodix: add poll mode for goodix touchscreen Joseph Guo
@ 2025-05-22  9:33 ` Hans de Goede
  2025-06-30  1:28 ` Dmitry Torokhov
  1 sibling, 0 replies; 3+ messages in thread
From: Hans de Goede @ 2025-05-22  9:33 UTC (permalink / raw)
  To: Joseph Guo, Bastien Nocera, Dmitry Torokhov,
	open list:GOODIX TOUCHSCREEN, open list
  Cc: haibo.chen, justin.jiang

Hi,

On 22-May-25 4:04 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
> ---
> Change from v2 to v3
> - Modify goodix_request_irq to make less diff

Thanks, patch looks good to me:

Reviewed-by: Hans de Goede <hdegoede@redhat.com>

Regards,

Hans



> ---
>  drivers/input/touchscreen/goodix.c | 43 +++++++++++++++++++++++++++---
>  1 file changed, 40 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/goodix.c b/drivers/input/touchscreen/goodix.c
> index aaf79ac50004..8e72174f486d 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,13 +532,29 @@ 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)
>  {
> +	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);
> @@ -1229,6 +1254,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 +1472,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 +1516,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;
>  	}
>  


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

* Re: [PATCH v3] LF-15225 input: goodix: add poll mode for goodix touchscreen
  2025-05-22  2:04 [PATCH v3] LF-15225 input: goodix: add poll mode for goodix touchscreen Joseph Guo
  2025-05-22  9:33 ` Hans de Goede
@ 2025-06-30  1:28 ` Dmitry Torokhov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2025-06-30  1:28 UTC (permalink / raw)
  To: Joseph Guo
  Cc: Bastien Nocera, Hans de Goede, open list:GOODIX TOUCHSCREEN,
	open list, haibo.chen, justin.jiang

On Thu, May 22, 2025 at 11:04:18AM +0900, 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>

Applied, thank you.

-- 
Dmitry

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

end of thread, other threads:[~2025-06-30  1:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-22  2:04 [PATCH v3] LF-15225 input: goodix: add poll mode for goodix touchscreen Joseph Guo
2025-05-22  9:33 ` Hans de Goede
2025-06-30  1:28 ` Dmitry Torokhov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).