[PATCH v2 3/3] input: touchscreen: st1232: add system wakeup support

phucduc.bui@gmail.com posted 3 patches 1 month ago
There is a newer version of this series
[PATCH v2 3/3] input: touchscreen: st1232: add system wakeup support
Posted by phucduc.bui@gmail.com 1 month ago
From: bui duc phuc <phucduc.bui@gmail.com>

The ST1232 touchscreen controller can generate an interrupt when the
panel is touched, which may be used as a wakeup source for the system.

Add support for system wakeup by initializing the device wakeup
capability in probe() based on the "wakeup-source" device property.
When wakeup is enabled, the driver enables IRQ wake during suspend
so that touch events can wake the system.

Additionally, report wakeup events from the interrupt handler when
the device is allowed to wake the system. This allows the PM core to
track touch-generated wakeup events and helps avoid potential races
with system suspend.

If wakeup is not enabled, the driver retains the existing behavior of
disabling the IRQ and powering down the controller during suspend.

Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
---
 drivers/input/touchscreen/st1232.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
index 9b3901eec0a5..2bab06cf099b 100644
--- a/drivers/input/touchscreen/st1232.c
+++ b/drivers/input/touchscreen/st1232.c
@@ -183,6 +183,9 @@ static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id)
 	int count;
 	int error;
 
+	if (device_may_wakeup(&ts->client->dev))
+		pm_wakeup_event(&ts->client->dev, 0);
+
 	error = st1232_ts_read_data(ts, REG_XY_COORDINATES, ts->read_buf_len);
 	if (error)
 		goto out;
@@ -356,6 +359,9 @@ static int st1232_ts_probe(struct i2c_client *client)
 
 	i2c_set_clientdata(client, ts);
 
+	device_init_wakeup(&client->dev,
+			device_property_read_bool(&client->dev, "wakeup-source"));
+
 	return 0;
 }
 
@@ -363,11 +369,20 @@ static int st1232_ts_suspend(struct device *dev)
 {
 	struct i2c_client *client = to_i2c_client(dev);
 	struct st1232_ts_data *ts = i2c_get_clientdata(client);
+	int ret;
 
-	disable_irq(client->irq);
+	dev_info(dev, "st1232: suspend called\n");
+	dev_info(dev, "st1232: irq=%d wakeup=%d\n", client->irq, device_may_wakeup(dev));
 
-	if (!device_may_wakeup(&client->dev))
+	if (device_may_wakeup(dev)) {
+		ret = enable_irq_wake(client->irq);
+		dev_info(dev, "st1232: Supend use wakeup\n");
+		dev_info(dev, "enable_irq_wake ret=%d\n", ret);
+	} else {
+		dev_info(dev, "st1232: Suspend Don't use wakeup\n");
+		disable_irq(client->irq);
 		st1232_ts_power(ts, false);
+	}
 
 	return 0;
 }
@@ -377,10 +392,12 @@ static int st1232_ts_resume(struct device *dev)
 	struct i2c_client *client = to_i2c_client(dev);
 	struct st1232_ts_data *ts = i2c_get_clientdata(client);
 
-	if (!device_may_wakeup(&client->dev))
+	if (device_may_wakeup(dev)) {
+		disable_irq_wake(client->irq);
+	} else {
 		st1232_ts_power(ts, true);
-
-	enable_irq(client->irq);
+		enable_irq(client->irq);
+	}
 
 	return 0;
 }
-- 
2.43.0
Re: [PATCH v2 3/3] input: touchscreen: st1232: add system wakeup support
Posted by Krzysztof Kozlowski 1 month ago
On 06/03/2026 11:40, phucduc.bui@gmail.com wrote:
> From: bui duc phuc <phucduc.bui@gmail.com>
> 
> The ST1232 touchscreen controller can generate an interrupt when the
> panel is touched, which may be used as a wakeup source for the system.
> 
> Add support for system wakeup by initializing the device wakeup
> capability in probe() based on the "wakeup-source" device property.
> When wakeup is enabled, the driver enables IRQ wake during suspend
> so that touch events can wake the system.
> 
> Additionally, report wakeup events from the interrupt handler when
> the device is allowed to wake the system. This allows the PM core to
> track touch-generated wakeup events and helps avoid potential races
> with system suspend.
> 
> If wakeup is not enabled, the driver retains the existing behavior of
> disabling the IRQ and powering down the controller during suspend.
> 
> Signed-off-by: bui duc phuc <phucduc.bui@gmail.com>
> ---
>  drivers/input/touchscreen/st1232.c | 27 ++++++++++++++++++++++-----
>  1 file changed, 22 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/st1232.c b/drivers/input/touchscreen/st1232.c
> index 9b3901eec0a5..2bab06cf099b 100644
> --- a/drivers/input/touchscreen/st1232.c
> +++ b/drivers/input/touchscreen/st1232.c
> @@ -183,6 +183,9 @@ static irqreturn_t st1232_ts_irq_handler(int irq, void *dev_id)
>  	int count;
>  	int error;
>  
> +	if (device_may_wakeup(&ts->client->dev))
> +		pm_wakeup_event(&ts->client->dev, 0);
> +
>  	error = st1232_ts_read_data(ts, REG_XY_COORDINATES, ts->read_buf_len);
>  	if (error)
>  		goto out;
> @@ -356,6 +359,9 @@ static int st1232_ts_probe(struct i2c_client *client)
>  
>  	i2c_set_clientdata(client, ts);
>  
> +	device_init_wakeup(&client->dev,
> +			device_property_read_bool(&client->dev, "wakeup-source"));
> +
>  	return 0;
>  }
>  
> @@ -363,11 +369,20 @@ static int st1232_ts_suspend(struct device *dev)
>  {
>  	struct i2c_client *client = to_i2c_client(dev);
>  	struct st1232_ts_data *ts = i2c_get_clientdata(client);
> +	int ret;
>  
> -	disable_irq(client->irq);
> +	dev_info(dev, "st1232: suspend called\n");
> +	dev_info(dev, "st1232: irq=%d wakeup=%d\n", client->irq, device_may_wakeup(dev));

No, there is no need to add success messages.

>  
> -	if (!device_may_wakeup(&client->dev))
> +	if (device_may_wakeup(dev)) {
> +		ret = enable_irq_wake(client->irq);
> +		dev_info(dev, "st1232: Supend use wakeup\n");
> +		dev_info(dev, "enable_irq_wake ret=%d\n", ret);

Drop both


> +	} else {
> +		dev_info(dev, "st1232: Suspend Don't use wakeup\n");

Drop



Best regards,
Krzysztof
Re: [PATCH v2 3/3] input: touchscreen: st1232: add system wakeup support
Posted by phucduc.bui@gmail.com 1 month ago
Hi Krzysztof,

> > +	dev_info(dev, "st1232: suspend called\n");
> > +	dev_info(dev, "st1232: irq=%d wakeup=%d\n", client->irq, 
> device_may_wakeup(dev));
> 
> No, there is no need to add success messages.
> 
> >  
> > -	if (!device_may_wakeup(&client->dev))
> > +	if (device_may_wakeup(dev)) {
> > +		ret = enable_irq_wake(client->irq);
> > +		dev_info(dev, "st1232: Supend use wakeup\n");
> > +		dev_info(dev, "enable_irq_wake ret=%d\n", ret);
> 
> Drop both
>  
> 
> > +	} else {
> > +		dev_info(dev, "st1232: Suspend Don't use wakeup\n");
> 
> Drop

My apologies. You are absolutely right. I realized these debug messages 
were unnecessary and already removed them in the v3 I sent (though I 
unfortunately messed up the threading for that version). 
I will ensure they stay removed in v4, which will be sent as a fresh 
thread.

Best regards,
Phuc