Skip to contentSkip to conversation

Input: tsc200x: Improve wakeup source handling

PATCH Superseded [email protected] 3 participants 8 messages Mar 9 – Mar 16

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Input: tsc200x: Improve wakeup source handling

From: bui duc phuc <[email protected]>

The tsc200x driver already uses device_init_wakeup() to read the "wakeup-source" property from the Device Tree. However, this property is currently not documented in the DT binding schema.

In addition, the I2C core already handles wakeup initialization and IRQ wake management automatically when the "wakeup-source" property is present. Therefore, the manual wakeup IRQ handling currently done in the driver is redundant for I2C-based devices (TSC2004).

This series makes the following changes:

1. Document the "wakeup-source" property in the DT bindings.

2. Delegate wakeup IRQ management to the I2C core when running on BUS_I2C, while keeping manual management for BUS_SPI (TSC2005) to ensure correct behavior across both interfaces.

Note:
These changes are based on code inspection and the documented behavior of the I2C core. They have not been tested on physical hardware yet.

bui duc phuc (2):
dt-bindings: input: touchscreen: ti,tsc2005: Add wakeup-source
Input: Touchscreen: tsc200x - delegate wakeup IRQ management to I2C
core

 .../bindings/input/touchscreen/ti,tsc2005.yaml |  7 +++++++
 drivers/input/touchscreen/tsc200x-core.c       | 18 +++++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 dt-bindings: input: touchscreen: ti,tsc2005: Add wakeup-source

From: bui duc phuc <[email protected]>

The tsc200x driver uses the "wakeup-source" device tree property to determine whether the device should be configured as a system wakeup source.

In the driver, this property is read with:

    device_init_wakeup(dev,
                       device_property_read_bool(dev, "wakeup-source"));

Document this property in the binding to make it visible to DT schema validation tools and to clarify its usage in device tree descriptions.

---
 .../devicetree/bindings/input/touchscreen/ti,tsc2005.yaml  | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/ti,tsc2005.yaml +7 -0
index 7187c390b2f5..c0aae044d7d4 100644
@@ -55,6 +55,9 @@ properties:
   touchscreen-size-x: true
   touchscreen-size-y: true
 
+  wakeup-source:
+    type: boolean
+
 allOf:
   - $ref: touchscreen.yaml#
   - if:
@@ -97,6 +100,8 @@ examples:
 
             ti,x-plate-ohms = <280>;
             ti,esd-recovery-timeout-ms = <8000>;
+
+            wakeup-source;
         };
     };
   - |
@@ -124,5 +129,7 @@ examples:
 
             ti,x-plate-ohms = <280>;
             ti,esd-recovery-timeout-ms = <8000>;
+
+            wakeup-source;
         };
     };
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH 1/2] dt-bindings: input: touchscreen: ti,tsc2005: Add wakeup-source

Quoted 10 lines · On Mon, Mar 09, 2026 at 06:00:43PM +0700, [email protected] wrote:

From: bui duc phuc <[email protected]>

The tsc200x driver uses the "wakeup-source" device tree property to determine whether the device should be configured as a system wakeup source.

In the driver, this property is read with:

    device_init_wakeup(dev,
                       device_property_read_bool(dev, "wakeup-source"));

Write your commit messages independent of the Linux driver.

Quoted 43 lines

Document this property in the binding to make it visible to DT schema validation tools and to clarify its usage in device tree descriptions.

---
 .../devicetree/bindings/input/touchscreen/ti,tsc2005.yaml  | 7 +++++++
 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/input/touchscreen/ti,tsc2005.yaml +7 -0
index 7187c390b2f5..c0aae044d7d4 100644
@@ -55,6 +55,9 @@ properties:
   touchscreen-size-x: true
   touchscreen-size-y: true
 
+  wakeup-source:
+    type: boolean
+
 allOf:
   - $ref: touchscreen.yaml#
   - if:
@@ -97,6 +100,8 @@ examples:
 
             ti,x-plate-ohms = <280>;
             ti,esd-recovery-timeout-ms = <8000>;
+
+            wakeup-source;
         };
     };
   - |
@@ -124,5 +129,7 @@ examples:
 
             ti,x-plate-ohms = <280>;
             ti,esd-recovery-timeout-ms = <8000>;
+
+            wakeup-source;
         };
     };
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH 1/2] dt-bindings: input: touchscreen: ti,tsc2005: Add

Hi Rob,

Quoted 1 line

Write your commit messages independent of the Linux driver.

Thanks for the feedback.

I will rewrite the commit message to focus on the hardware description and formalizing the binding, and remove references to the Linux driver implementation.

I will send a v2 shortly with this change.

Best regards,
Phuc

#4 lore raw

PATCH 2/2 Input: Touchscreen: tsc200x - delegate wakeup IRQ management to I2C core

In reply to [email protected]

From: bui duc phuc <[email protected]>

The tsc200x driver supports both I2C (tsc2004) and SPI (tsc2005)
interfaces.
Currently, the driver attempts to manually manage the wakeup interrupt by calling enable_irq_wake() and disable_irq_wake() during suspend and resume.

However, for I2C devices, the I2C core already automatically handles the wakeup source initialization and IRQ management if the "wakeup-source" property is present in the device tree. Manually managing it again in the driver is redundant and can lead to unbalanced IRQ wake reference counts.

Clean up the wakeup IRQ handling by checking the bus type:
- For I2C (BUS_I2C): Rely entirely on the I2C core for wakeup management.
- For SPI (BUS_SPI): Explicitly call device_init_wakeup() in probe and manually manage enable/disable_irq_wake() during suspend/resume.

The ts->wake_irq_enabled flag is also updated accordingly to ensure the driver accurately tracks the wakeup state across both buses.

Note: This patch is based on code analysis of the I2C subsystem and has not been verified on actual hardware yet.

---
 drivers/input/touchscreen/tsc200x-core.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/input/touchscreen/tsc200x-core.c +13 -5
index eba53613b005..d14d967845c8 100644
@@ -465,6 +465,7 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
 	ts->idev = input_dev;
 	ts->regmap = regmap;
 	ts->tsc200x_cmd = tsc200x_cmd;
+	ts->bustype = tsc_id->bustype;
 
 	error = device_property_read_u32(dev, "ti,x-plate-ohms", &x_plate_ohm);
 	ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm;
@@ -547,8 +548,9 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
 		return error;
 	}
 
-	device_init_wakeup(dev,
-			   device_property_read_bool(dev, "wakeup-source"));
+	if (ts->bustype == BUS_SPI)
+		device_init_wakeup(dev,
+				 device_property_read_bool(dev, "wakeup-source"));
 
 	return 0;
 }
@@ -565,8 +567,13 @@ static int tsc200x_suspend(struct device *dev)
 
 	ts->suspended = true;
 
-	if (device_may_wakeup(dev))
-		ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0;
+	if (device_may_wakeup(dev)) {
+		if (ts->bustype == BUS_SPI)
+			ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0;
+		else
+			ts->wake_irq_enabled = true;
+	} else
+		ts->wake_irq_enabled = false;
 
 	return 0;
 }
@@ -578,7 +585,8 @@ static int tsc200x_resume(struct device *dev)
 	guard(mutex)(&ts->mutex);
 
 	if (ts->wake_irq_enabled) {
-		disable_irq_wake(ts->irq);
+		if (ts->bustype == BUS_SPI)
+			disable_irq_wake(ts->irq);
 		ts->wake_irq_enabled = false;
 	}
 
Signature · 1 line
2.43.0
maintainer
#5 lore raw

Re: [PATCH 2/2] Input: Touchscreen: tsc200x - delegate wakeup IRQ management to I2C core

Quoted 55 lines · On Mon, Mar 09, 2026 at 06:00:44PM +0700, [email protected] wrote:

From: bui duc phuc <[email protected]>

The tsc200x driver supports both I2C (tsc2004) and SPI (tsc2005)
interfaces.
Currently, the driver attempts to manually manage the wakeup interrupt by calling enable_irq_wake() and disable_irq_wake() during suspend and resume.

However, for I2C devices, the I2C core already automatically handles the wakeup source initialization and IRQ management if the "wakeup-source" property is present in the device tree. Manually managing it again in the driver is redundant and can lead to unbalanced IRQ wake reference counts.

Clean up the wakeup IRQ handling by checking the bus type:
- For I2C (BUS_I2C): Rely entirely on the I2C core for wakeup management.
- For SPI (BUS_SPI): Explicitly call device_init_wakeup() in probe and manually manage enable/disable_irq_wake() during suspend/resume.

The ts->wake_irq_enabled flag is also updated accordingly to ensure the driver accurately tracks the wakeup state across both buses.

Note: This patch is based on code analysis of the I2C subsystem and has not been verified on actual hardware yet.

---
 drivers/input/touchscreen/tsc200x-core.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/input/touchscreen/tsc200x-core.c +4 -2
index eba53613b005..d14d967845c8 100644
@@ -465,6 +465,7 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
 	ts->idev = input_dev;
 	ts->regmap = regmap;
 	ts->tsc200x_cmd = tsc200x_cmd;
+	ts->bustype = tsc_id->bustype;
 
 	error = device_property_read_u32(dev, "ti,x-plate-ohms", &x_plate_ohm);
 	ts->x_plate_ohm = error ? TSC200X_DEF_RESISTOR : x_plate_ohm;
@@ -547,8 +548,9 @@ int tsc200x_probe(struct device *dev, int irq, const struct input_id *tsc_id,
 		return error;
 	}
 
-	device_init_wakeup(dev,
-			   device_property_read_bool(dev, "wakeup-source"));
+	if (ts->bustype == BUS_SPI)
+		device_init_wakeup(dev,
+				 device_property_read_bool(dev, "wakeup-source"));
 
 	return 0;
 }
@@ -565,8 +567,13 @@ static int tsc200x_suspend(struct device *dev)
 
 	ts->suspended = true;

drivers/input/touchscreen/tsc200x-core.c static int tsc200x_suspend(struct device *dev) · line 576

Quoted 10 lines
drivers/input/touchscreen/tsc200x-core.c +7 -2
 
-	if (device_may_wakeup(dev))
-		ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0;
+	if (device_may_wakeup(dev)) {
+		if (ts->bustype == BUS_SPI)
+			ts->wake_irq_enabled = enable_irq_wake(ts->irq) == 0;
+		else
+			ts->wake_irq_enabled = true;
+	} else
+		ts->wake_irq_enabled = false;

Sorry, but this just makes it all worse. There is no downside from letting the driver to control wakeup if it wants to, so I'd rather leave it as it was, at least for now.

Thanks.

Signature · 1 line
Dmitry
#6 lore raw

PATCH 2/2 Input: Touchscreen: tsc200x - delegate wakeup IRQ

Hi Dmitry,

Quoted 3 lines

Sorry, but this just makes it all worse. There is no downside from letting the driver to control wakeup if it wants to, so I'd rather leave it as it was, at least for now.

Thanks you for your reply

I was thinking that the code might be simplified by removing ts->wake_irq_enabled.

In resume(), we could just check device_may_wakeup(dev) before calling disable_irq_wake(ts->irq). From what I can see, wake_irq_enabled is only used there, so it seems redundant.

I don't have the hardware to test this right now, so I didn't try the change myself.

Do you think it would make sense to remove this field?

Best regards,
Phuc

#7 lore raw

In reply to Dmitry Torokhov

Subject: Re: [PATCH 2/2] Input: Touchscreen: tsc200x - delegate wakeup IRQ management to I2C core

Hi Dmitry,

Thanks for the feedback.

I will drop this patch and keep the previous behavior.

I'll send a v2 shortly with only the commit message improvements for the first patch.

Thanks for the review.

Best regards,
Phuc