Skip to contentSkip to conversation

AM335x: tsc: Fix suspended while touchscreen in use

PATCH In review Vignesh R 3 participants 8 messages May 16, 2016 – May 17, 2016

Subsystems (3)
lore
Share & tools
lore

Vignesh R

author
#0 lore raw

cover AM335x: tsc: Fix suspended while touchscreen in use

On am335x-evm, its observed that touchscreen fails to wake system from suspend if user had finger on touch screen while entering system. This series addresses the above issue.

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

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

 drivers/input/touchscreen/ti_am335x_tsc.c | 14 ++++++++++++++
 include/linux/mfd/ti_am335x_tscadc.h      |  1 +
 2 files changed, 15 insertions(+)
Signature · 1 line
2.8.2
author
#1 lore raw

PATCH 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.

---
 drivers/input/touchscreen/ti_am335x_tsc.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +9 -0
index 8b3f15ca7725..f9fefbe337b9 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,12 @@ static int titsc_probe(struct platform_device *pdev)
 		goto err_free_mem;
 	}
 
+	if (device_may_wakeup(tscadc_dev->dev)) {
+		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 +469,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 +482,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.8.2
maintainer
#2 lore raw

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

Quoted 3 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.

I would love for platform core to do this for us, like I2C core does.

Quoted 50 lines
---
 drivers/input/touchscreen/ti_am335x_tsc.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +9 -0
index 8b3f15ca7725..f9fefbe337b9 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,12 @@ static int titsc_probe(struct platform_device *pdev)
 		goto err_free_mem;
 	}
 
+	if (device_may_wakeup(tscadc_dev->dev)) {
+		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 +469,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 +482,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.8.2
Signature · 1 line
Dmitry
author
#3 lore raw

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

Quoted 6 lines · Dmitry Torokhov
Quoted 3 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.

I would love for platform core to do this for us, like I2C core does.

Ok, I will replicate the same in input_register_device() for input core.

Signature · 2 lines
Regards
Vignesh
author
#4 lore raw

PATCH 2/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.

---
 drivers/input/touchscreen/ti_am335x_tsc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +3 -0
index f9fefbe337b9..4683ed18b9f8 100644
@@ -275,6 +275,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) {
@@ -284,6 +285,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;
 		}
@@ -522,6 +524,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.8.2
author
#5 lore raw

PATCH 3/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.

---
 drivers/input/touchscreen/ti_am335x_tsc.c | 2 ++
 include/linux/mfd/ti_am335x_tscadc.h      | 1 +
 2 files changed, 3 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +2 -0
index 4683ed18b9f8..d2c55b5730e6 100644
@@ -441,6 +441,7 @@ static int titsc_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev, "irq wake enable failed.\n");
 	}
 
+	titsc_writel(ts_dev, REG_IRQSTATUS, IRQENB_MASK);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_EOS);
 	err = titsc_config_wires(ts_dev);
@@ -506,6 +507,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, IRQENB_MASK);
 		idle = titsc_readl(ts_dev, REG_IRQENABLE);
 		titsc_writel(ts_dev, REG_IRQENABLE,
 				(idle | IRQENB_HW_PEN));
include/linux/mfd/ti_am335x_tscadc.h +1 -0
index 1fd50dcfe47c..a7ca0f908ba8 100644
@@ -60,6 +60,7 @@
 #define IRQENB_FIFO1OVRRUN	BIT(6)
 #define IRQENB_FIFO1UNDRFLW	BIT(7)
 #define IRQENB_PENUP		BIT(9)
+#define IRQENB_MASK		(0x7FF)
 
 /* Step Configuration */
 #define STEPCONFIG_MODE_MASK	(3 << 0)
Signature · 1 line
2.8.2
maintainer
#6 lore raw

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

Quoted 8 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.

What if user touches the screen while device's suspend routine is executing?

Quoted 43 lines
---
 drivers/input/touchscreen/ti_am335x_tsc.c | 2 ++
 include/linux/mfd/ti_am335x_tscadc.h      | 1 +
 2 files changed, 3 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +2 -0
index 4683ed18b9f8..d2c55b5730e6 100644
@@ -441,6 +441,7 @@ static int titsc_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev, "irq wake enable failed.\n");
 	}
 
+	titsc_writel(ts_dev, REG_IRQSTATUS, IRQENB_MASK);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_EOS);
 	err = titsc_config_wires(ts_dev);
@@ -506,6 +507,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, IRQENB_MASK);
 		idle = titsc_readl(ts_dev, REG_IRQENABLE);
 		titsc_writel(ts_dev, REG_IRQENABLE,
 				(idle | IRQENB_HW_PEN));
include/linux/mfd/ti_am335x_tscadc.h +1 -0
index 1fd50dcfe47c..a7ca0f908ba8 100644
@@ -60,6 +60,7 @@
 #define IRQENB_FIFO1OVRRUN	BIT(6)
 #define IRQENB_FIFO1UNDRFLW	BIT(7)
 #define IRQENB_PENUP		BIT(9)
+#define IRQENB_MASK		(0x7FF)
 
 /* Step Configuration */
 #define STEPCONFIG_MODE_MASK	(3 << 0)
Signature · 1 line
2.8.2
Signature · 1 line
Dmitry
Acked-by on v1 3/3
#7 lore raw

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

In reply to Vignesh R
Quoted 9 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.

Quoted 5 lines
---
 drivers/input/touchscreen/ti_am335x_tsc.c | 2 ++
 include/linux/mfd/ti_am335x_tscadc.h      | 1 +

For the MFD change:

Quoted 34 lines
 2 files changed, 3 insertions(+)
drivers/input/touchscreen/ti_am335x_tsc.c +2 -0
index 4683ed18b9f8..d2c55b5730e6 100644
@@ -441,6 +441,7 @@ static int titsc_probe(struct platform_device *pdev)
 			dev_err(&pdev->dev, "irq wake enable failed.\n");
 	}
 
+	titsc_writel(ts_dev, REG_IRQSTATUS, IRQENB_MASK);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_FIFO0THRES);
 	titsc_writel(ts_dev, REG_IRQENABLE, IRQENB_EOS);
 	err = titsc_config_wires(ts_dev);
@@ -506,6 +507,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, IRQENB_MASK);
 		idle = titsc_readl(ts_dev, REG_IRQENABLE);
 		titsc_writel(ts_dev, REG_IRQENABLE,
 				(idle | IRQENB_HW_PEN));
include/linux/mfd/ti_am335x_tscadc.h +1 -0
index 1fd50dcfe47c..a7ca0f908ba8 100644
@@ -60,6 +60,7 @@
 #define IRQENB_FIFO1OVRRUN	BIT(6)
 #define IRQENB_FIFO1UNDRFLW	BIT(7)
 #define IRQENB_PENUP		BIT(9)
+#define IRQENB_MASK		(0x7FF)
 
 /* Step Configuration */
 #define STEPCONFIG_MODE_MASK	(3 << 0)
Signature · 8 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html