Skip to contentSkip to conversation

ti_am335x_tsc: Fix suspend/resume

PATCH Applied Vignesh R 2 participants 8 messages Apr 24, 2018 – May 30, 2018

Subsystems (2)
lore
Share & tools
lore

Vignesh R

author
#0 lore raw

v3 cover ti_am335x_tsc: Fix suspend/resume

This patch series fixes couple of issues wrt suspend/resume with TI AM335x TSC driver. Disable and clear any pending IRQs before suspend, and handle case where TSC wakeup would fail, if there were touch events during suspend.

Grygorii Strashko (2):
Input: ti_am335x_tsc - Ack pending IRQs at probe and before suspend
Input: ti_am335x_tsc - Prevent system suspend when TSC is in use

Vignesh R (1):
Input: ti_am335x_tsc - Mark IRQ as wakeup capable

 drivers/input/touchscreen/ti_am335x_tsc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
Signature · 1 line
2.17.0
author
#1 lore raw

PATCH v3 1/3 Input: ti_am335x_tsc - Mark IRQ as wakeup capable

On AM335x, ti_am335x_tsc can wake up the system from suspend, mark the IRQ as wakeup capable, so that device irq is not disabled during system suspend.

---
v3: Drop unneeded device_may_wakeup() check

 drivers/input/touchscreen/ti_am335x_tsc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +7 -0
index f1043ae71dcc..3908c21862c7 100644
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/sort.h>
+#include <linux/pm_wakeirq.h>
 
 #include <linux/mfd/ti_am335x_tscadc.h>
 
@@ -432,6 +433,10 @@ static int titsc_probe(struct platform_device *pdev)
 		goto err_free_mem;
 	}
 
+	err = dev_pm_set_wake_irq(tscadc_dev->dev, ts_dev->irq);
+	if (err)
+		dev_err(&pdev->dev, "irq wake enable failed.\n");
+
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_EOS);
 	err = titsc_config_wires(ts_dev);
@@ -462,6 +467,7 @@ static int titsc_probe(struct platform_device *pdev)
 	return 0;
 
 err_free_irq:
+	dev_pm_clear_wake_irq(tscadc_dev->dev);
 	free_irq(ts_dev->irq, ts_dev);
 err_free_mem:
 	input_free_device(input_dev);
@@ -474,6 +480,7 @@ static int titsc_remove(struct platform_device *pdev)
 	struct titsc *ts_dev = platform_get_drvdata(pdev);
 	u32 steps;
 
+	dev_pm_clear_wake_irq(ts_dev->mfd_tscadc->dev);
 	free_irq(ts_dev->irq, ts_dev);
 
 	/* total steps followed by the enable mask */
Signature · 1 line
2.17.0
maintainer
#2 lore raw

Re: [PATCH v3 1/3] Input: ti_am335x_tsc - Mark IRQ as wakeup capable

Hi Vignesh,

Quoted 24 lines · Vignesh R

On AM335x, ti_am335x_tsc can wake up the system from suspend, mark the IRQ as wakeup capable, so that device irq is not disabled during system suspend.

---
v3: Drop unneeded device_may_wakeup() check

 drivers/input/touchscreen/ti_am335x_tsc.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +1 -0
index f1043ae71dcc..3908c21862c7 100644
@@ -27,6 +27,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/sort.h>
+#include <linux/pm_wakeirq.h>
 
 #include <linux/mfd/ti_am335x_tscadc.h>
 

drivers/input/touchscreen/ti_am335x_tsc.c static int titsc_probe(struct platform_device *pdev) · line 439

Quoted 7 lines
drivers/input/touchscreen/ti_am335x_tsc.c +4 -0
@@ -432,6 +433,10 @@ static int titsc_probe(struct platform_device *pdev)
 		goto err_free_mem;
 	}
 
+	err = dev_pm_set_wake_irq(tscadc_dev->dev, ts_dev->irq);
+	if (err)
+		dev_err(&pdev->dev, "irq wake enable failed.\n");
+

Looking at this driver some more: why do we have the parent MFD device as wakeup source? It seems we have 2 independent interrupt lines, one in IIO and one in input and we could actually have the touchscreen itself to be one of the wakeup devices? I.e. i'd expect

	err = dev_pm_set_wake_irq(&pdev->dev, ts_dev->irq);

here and we should be checking the touchscreen pdev in suspend/resume when checking whether to program the controller for wakeups.

Quoted 22 lines
drivers/input/touchscreen/ti_am335x_tsc.c +2 -0
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_EOS);
 	err = titsc_config_wires(ts_dev);
@@ -462,6 +467,7 @@ static int titsc_probe(struct platform_device *pdev)
 	return 0;
 
 err_free_irq:
+	dev_pm_clear_wake_irq(tscadc_dev->dev);
 	free_irq(ts_dev->irq, ts_dev);
 err_free_mem:
 	input_free_device(input_dev);
@@ -474,6 +480,7 @@ static int titsc_remove(struct platform_device *pdev)
 	struct titsc *ts_dev = platform_get_drvdata(pdev);
 	u32 steps;
 
+	dev_pm_clear_wake_irq(ts_dev->mfd_tscadc->dev);
 	free_irq(ts_dev->irq, ts_dev);
 
 	/* total steps followed by the enable mask */
Signature · 1 line
2.17.0

Thanks.

Signature · 1 line
Dmitry
author
#3 lore raw

PATCH v3 2/3 Input: ti_am335x_tsc - Ack pending IRQs at probe and before suspend

In reply to Vignesh R

From: Grygorii Strashko <[email protected]>

It is seen that just enabling the TSC module triggers a HW_PEN IRQ without any interaction with touchscreen by user. This results in first suspend/resume sequence to fail as system immediately wakes up from suspend as soon as HW_PEN IRQ is enabled in suspend handler due to the pending IRQ. Therefore clear all IRQs at probe and also in suspend callback for sanity.

---

v3: Clear IRQs related to TSC module only

 drivers/input/touchscreen/ti_am335x_tsc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +4 -0
index 3908c21862c7..a548b0dbe320 100644
@@ -35,6 +35,8 @@
 #define SEQ_SETTLE		275
 #define MAX_12BIT		((1 << 12) - 1)
 
+#define TSC_IRQENB_MASK		(IRQENB_FIFO0THRES | IRQENB_EOS | IRQENB_HW_PEN)
+
 static const int config_pins[] = {
 	STEPCONFIG_XPP,
 	STEPCONFIG_XNN,
@@ -437,6 +439,7 @@ static int titsc_probe(struct platform_device *pdev)
 	if (err)
 		dev_err(&pdev->dev, "irq wake enable failed.\n");
 
+	titsc_writel(ts_dev, REG_IRQSTATUS, TSC_IRQENB_MASK);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_EOS);
 	err = titsc_config_wires(ts_dev);
@@ -502,6 +505,7 @@ static int __maybe_unused titsc_suspend(struct device *dev)
 
 	tscadc_dev = ti_tscadc_dev_get(to_platform_device(dev));
 	if (device_may_wakeup(tscadc_dev->dev)) {
+		titsc_writel(ts_dev, REG_IRQSTATUS, TSC_IRQENB_MASK);
 		idle = titsc_readl(ts_dev, REG_IRQENABLE);
 		titsc_writel(ts_dev, REG_IRQENABLE,
 				(idle | IRQENB_HW_PEN));
Signature · 1 line
2.17.0
maintainer Applied
#4 lore raw

Re: [PATCH v3 2/3] Input: ti_am335x_tsc - Ack pending IRQs at probe and before suspend

Quoted 11 lines · Vignesh R

From: Grygorii Strashko <[email protected]>

It is seen that just enabling the TSC module triggers a HW_PEN IRQ without any interaction with touchscreen by user. This results in first suspend/resume sequence to fail as system immediately wakes up from suspend as soon as HW_PEN IRQ is enabled in suspend handler due to the pending IRQ. Therefore clear all IRQs at probe and also in suspend callback for sanity.

Applied, thank you.

Quoted 39 lines

---

v3: Clear IRQs related to TSC module only

 drivers/input/touchscreen/ti_am335x_tsc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +4 -0
index 3908c21862c7..a548b0dbe320 100644
@@ -35,6 +35,8 @@
 #define SEQ_SETTLE		275
 #define MAX_12BIT		((1 << 12) - 1)
 
+#define TSC_IRQENB_MASK		(IRQENB_FIFO0THRES | IRQENB_EOS | IRQENB_HW_PEN)
+
 static const int config_pins[] = {
 	STEPCONFIG_XPP,
 	STEPCONFIG_XNN,
@@ -437,6 +439,7 @@ static int titsc_probe(struct platform_device *pdev)
 	if (err)
 		dev_err(&pdev->dev, "irq wake enable failed.\n");
 
+	titsc_writel(ts_dev, REG_IRQSTATUS, TSC_IRQENB_MASK);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_EOS);
 	err = titsc_config_wires(ts_dev);
@@ -502,6 +505,7 @@ static int __maybe_unused titsc_suspend(struct device *dev)
 
 	tscadc_dev = ti_tscadc_dev_get(to_platform_device(dev));
 	if (device_may_wakeup(tscadc_dev->dev)) {
+		titsc_writel(ts_dev, REG_IRQSTATUS, TSC_IRQENB_MASK);
 		idle = titsc_readl(ts_dev, REG_IRQENABLE);
 		titsc_writel(ts_dev, REG_IRQENABLE,
 				(idle | IRQENB_HW_PEN));
Signature · 1 line
2.17.0
Signature · 1 line
Dmitry
author
#5 lore raw

PATCH v3 3/3 Input: ti_am335x_tsc - Prevent system suspend when TSC is in use

In reply to Vignesh R

From: Grygorii Strashko <[email protected]>

Prevent system suspend while user has finger on touch screen, because TSC is wakeup source and suspending device while in use will result in failure to disable the module.
This patch uses pm_stay_awake() and pm_relax() APIs to prevent and resume system suspend as required.

---

v3: No change

 drivers/input/touchscreen/ti_am335x_tsc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +3 -0
index a548b0dbe320..ae6fc9099636 100644
@@ -277,6 +277,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
 	if (status & IRQENB_HW_PEN) {
 		ts_dev->pen_down = true;
 		irqclr |= IRQENB_HW_PEN;
+		pm_stay_awake(ts_dev->mfd_tscadc->dev);
 	}
 
 	if (status & IRQENB_PENUP) {
@@ -286,6 +287,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
 			input_report_key(input_dev, BTN_TOUCH, 0);
 			input_report_abs(input_dev, ABS_PRESSURE, 0);
 			input_sync(input_dev);
+			pm_relax(ts_dev->mfd_tscadc->dev);
 		} else {
 			ts_dev->pen_down = true;
 		}
@@ -524,6 +526,7 @@ static int __maybe_unused titsc_resume(struct device *dev)
 		titsc_writel(ts_dev, REG_IRQWAKEUP,
 				0x00);
 		titsc_writel(ts_dev, REG_IRQCLR, IRQENB_HW_PEN);
+		pm_relax(ts_dev->mfd_tscadc->dev);
 	}
 	titsc_step_config(ts_dev);
 	titsc_writel(ts_dev, REG_FIFO0THR,
Signature · 1 line
2.17.0
maintainer Applied
#6 lore raw

Re: [PATCH v3 3/3] Input: ti_am335x_tsc - Prevent system suspend when TSC is in use

Quoted 10 lines · Vignesh R

From: Grygorii Strashko <[email protected]>

Prevent system suspend while user has finger on touch screen, because TSC is wakeup source and suspending device while in use will result in failure to disable the module.
This patch uses pm_stay_awake() and pm_relax() APIs to prevent and resume system suspend as required.

Applied, thank you.

Quoted 38 lines

---

v3: No change

 drivers/input/touchscreen/ti_am335x_tsc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +3 -0
index a548b0dbe320..ae6fc9099636 100644
@@ -277,6 +277,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
 	if (status & IRQENB_HW_PEN) {
 		ts_dev->pen_down = true;
 		irqclr |= IRQENB_HW_PEN;
+		pm_stay_awake(ts_dev->mfd_tscadc->dev);
 	}
 
 	if (status & IRQENB_PENUP) {
@@ -286,6 +287,7 @@ static irqreturn_t titsc_irq(int irq, void *dev)
 			input_report_key(input_dev, BTN_TOUCH, 0);
 			input_report_abs(input_dev, ABS_PRESSURE, 0);
 			input_sync(input_dev);
+			pm_relax(ts_dev->mfd_tscadc->dev);
 		} else {
 			ts_dev->pen_down = true;
 		}
@@ -524,6 +526,7 @@ static int __maybe_unused titsc_resume(struct device *dev)
 		titsc_writel(ts_dev, REG_IRQWAKEUP,
 				0x00);
 		titsc_writel(ts_dev, REG_IRQCLR, IRQENB_HW_PEN);
+		pm_relax(ts_dev->mfd_tscadc->dev);
 	}
 	titsc_step_config(ts_dev);
 	titsc_writel(ts_dev, REG_FIFO0THR,
Signature · 1 line
2.17.0
Signature · 1 line
Dmitry
author
#7 lore raw
In reply to Vignesh R
Quoted 6 lines · Vignesh R

This patch series fixes couple of issues wrt suspend/resume with TI AM335x TSC driver. Disable and clear any pending IRQs before suspend, and handle case where TSC wakeup would fail, if there were touch events during suspend.

Gentle ping on this series... Any comments?

Quoted 10 lines

Grygorii Strashko (2):
Input: ti_am335x_tsc - Ack pending IRQs at probe and before suspend
Input: ti_am335x_tsc - Prevent system suspend when TSC is in use

Vignesh R (1):
Input: ti_am335x_tsc - Mark IRQ as wakeup capable

 drivers/input/touchscreen/ti_am335x_tsc.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)