Skip to contentSkip to conversation

Input: tegra-kbc - enable key interrupt for wakeup

PATCH In review Rakesh Iyer 2 participants 4 messages Jan 18, 2012 – Jan 24, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: tegra-kbc - enable key interrupt for wakeup

Enable keypress interrupt to support wakeup from low power state.

---
 drivers/input/keyboard/tegra-kbc.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
drivers/input/keyboard/tegra-kbc.c +17 -0
index a136e2e..b307a46 100644
@@ -48,6 +48,7 @@
 #define KBC_FIFO_TH_CNT_SHIFT(cnt)	(cnt << 14)
 #define KBC_DEBOUNCE_CNT_SHIFT(cnt)	(cnt << 4)
 #define KBC_CONTROL_FIFO_CNT_INT_EN	(1 << 3)
+#define KBC_CONTROL_KEYPRESS_INT_EN	(1 << 1)
 #define KBC_CONTROL_KBC_EN		(1 << 0)
 
 /* KBC Interrupt Register */
@@ -356,6 +357,18 @@ static void tegra_kbc_set_fifo_interrupt(struct tegra_kbc *kbc, bool enable)
 	writel(val, kbc->mmio + KBC_CONTROL_0);
 }
 
+static void tegra_kbc_set_keypress_interrupt(struct tegra_kbc *kbc, bool enable)
+{
+	u32 val;
+
+	val = readl(kbc->mmio + KBC_CONTROL_0);
+	if (enable)
+		val |= KBC_CONTROL_KEYPRESS_INT_EN;
+	else
+		val &= ~KBC_CONTROL_KEYPRESS_INT_EN;
+	writel(val, kbc->mmio + KBC_CONTROL_0);
+}
+
 static void tegra_kbc_keypress_timer(unsigned long data)
 {
 	struct tegra_kbc *kbc = (struct tegra_kbc *)data;
@@ -831,6 +844,8 @@ static int tegra_kbc_suspend(struct device *dev)
 		msleep(30);
 
 		kbc->keypress_caused_wake = false;
+		/* Enable keypress interrupt before going into suspend. */
+		tegra_kbc_set_keypress_interrupt(kbc, true);
 		enable_irq(kbc->irq);
 		enable_irq_wake(kbc->irq);
 	} else {
@@ -852,6 +867,8 @@ static int tegra_kbc_resume(struct device *dev)
 	if (device_may_wakeup(&pdev->dev)) {
 		disable_irq_wake(kbc->irq);
 		tegra_kbc_setup_wakekeys(kbc, false);
+		/* We will use fifo interrupts for key detection. */
+		tegra_kbc_set_keypress_interrupt(kbc, false);
 
 		/* Restore the resident time of continuous polling mode. */
 		writel(kbc->cp_to_wkup_dly, kbc->mmio + KBC_TO_CNT_0);
Signature · 1 line
1.7.4.1
#1 lore raw
Quoted 48 lines · Rakesh Iyer

Enable keypress interrupt to support wakeup from low power state.

---
 drivers/input/keyboard/tegra-kbc.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
drivers/input/keyboard/tegra-kbc.c +15 -0
index a136e2e..b307a46 100644
@@ -48,6 +48,7 @@
 #define KBC_FIFO_TH_CNT_SHIFT(cnt)	(cnt << 14)
 #define KBC_DEBOUNCE_CNT_SHIFT(cnt)	(cnt << 4)
 #define KBC_CONTROL_FIFO_CNT_INT_EN	(1 << 3)
+#define KBC_CONTROL_KEYPRESS_INT_EN	(1 << 1)
 #define KBC_CONTROL_KBC_EN		(1 << 0)
 
 /* KBC Interrupt Register */
@@ -356,6 +357,18 @@ static void tegra_kbc_set_fifo_interrupt(struct tegra_kbc *kbc, bool enable)
 	writel(val, kbc->mmio + KBC_CONTROL_0);
 }
 
+static void tegra_kbc_set_keypress_interrupt(struct tegra_kbc *kbc, bool enable)
+{
+	u32 val;
+
+	val = readl(kbc->mmio + KBC_CONTROL_0);
+	if (enable)
+		val |= KBC_CONTROL_KEYPRESS_INT_EN;
+	else
+		val &= ~KBC_CONTROL_KEYPRESS_INT_EN;
+	writel(val, kbc->mmio + KBC_CONTROL_0);
+}
+
 static void tegra_kbc_keypress_timer(unsigned long data)
 {
 	struct tegra_kbc *kbc = (struct tegra_kbc *)data;
@@ -831,6 +844,8 @@ static int tegra_kbc_suspend(struct device *dev)
 		msleep(30);
 
 		kbc->keypress_caused_wake = false;
+		/* Enable keypress interrupt before going into suspend. */
+		tegra_kbc_set_keypress_interrupt(kbc, true);
 		enable_irq(kbc->irq);
 		enable_irq_wake(kbc->irq);
 	} else {

drivers/input/keyboard/tegra-kbc.c static int tegra_kbc_resume(struct device *dev) · line 871

Quoted 5 lines
drivers/input/keyboard/tegra-kbc.c +2 -0
@@ -852,6 +867,8 @@ static int tegra_kbc_resume(struct device *dev)
 	if (device_may_wakeup(&pdev->dev)) {
 		disable_irq_wake(kbc->irq);
 		tegra_kbc_setup_wakekeys(kbc, false);
+		/* We will use fifo interrupts for key detection. */
+		tegra_kbc_set_keypress_interrupt(kbc, false);

Why do yo disable on resume why not have it enabled always?

Quoted 3 lines
drivers/input/keyboard/tegra-kbc.c +0 -0
 		/* Restore the resident time of continuous polling mode. */
 		writel(kbc->cp_to_wkup_dly, kbc->mmio + KBC_TO_CNT_0);
#2 lore raw

drivers/input/keyboard/tegra-kbc.c static int tegra_kbc_resume(struct device *dev) · line 871

Quoted 5 lines
drivers/input/keyboard/tegra-kbc.c +2 -0
 	if (device_may_wakeup(&pdev->dev)) {
 		disable_irq_wake(kbc->irq);
 		tegra_kbc_setup_wakekeys(kbc, false);
+		/* We will use fifo interrupts for key detection. */
+		tegra_kbc_set_keypress_interrupt(kbc, false);

Why do yo disable on resume why not have it enabled always?

drivers/input/keyboard/tegra-kbc.c static int tegra_kbc_resume(struct device *dev) · line 874

Quoted 3 lines
drivers/input/keyboard/tegra-kbc.c +0 -0
 		/* Restore the resident time of continuous polling mode. */
 		writel(kbc->cp_to_wkup_dly, kbc->mmio + KBC_TO_CNT_0);

For the relevant discussion, Tegra KBC provides the following interrupts -
a) The keypress interrupt which is generated as soon as a key is pressed, before matrix scanning begins.
b) FIFO interrupt which is generated when actual keys are decoded from the matrix, and put into the FIFO.

During normal operation the keypress interrupt is not useful as we have to wait for the keys to make it into the FIFO before reporting it to the higher layers.

Since we have turned off scanning(in the following commit) we cannot use the FIFO interrupt during the resume, so we rely on the keypress interrupt and generate the wakeup key.

Commit that turned off scanning

Input: tegra-kbc - fix wakeup from suspend

For wakeup to be reliable, kbc needs to be in interrupt mode before suspend. Created common routine to control the FIFO interrupt.
Added synchronization to ensure orderly suspend.

Regards
Rakesh

#3 lore raw

Hi Rakesh,

Quoted 20 lines · Rakesh Iyer
Quoted 5 lines

      if (device_may_wakeup(&pdev->dev)) { disable_irq_wake(kbc->irq); tegra_kbc_setup_wakekeys(kbc, false);
+             /* We will use fifo interrupts for key detection. */
+             tegra_kbc_set_keypress_interrupt(kbc, false);

Why do yo disable on resume why not have it enabled always?

Quoted 3 lines

              /* Restore the resident time of continuous polling mode. */ writel(kbc->cp_to_wkup_dly, kbc->mmio + KBC_TO_CNT_0);

For the relevant discussion, Tegra KBC provides the following interrupts -
a) The keypress interrupt which is generated as soon as a key is pressed, before matrix scanning begins.
b) FIFO interrupt which is generated when actual keys are decoded from the matrix, and put into the FIFO.

During normal operation the keypress interrupt is not useful as we have to wait for the keys to make it into the FIFO before reporting it to the higher layers.

Quoted 8 lines

Since we have turned off scanning(in the following commit) we cannot use the FIFO interrupt during the resume, so we rely on the keypress interrupt and generate the wakeup key.

Commit that turned off scanning

   Input: tegra-kbc - fix wakeup from suspend

   For wakeup to be reliable, kbc needs to be in interrupt mode before suspend.

Does it need to be disabled at resume?

Quoted 6 lines

   Created common routine to control the FIFO interrupt. Added synchronization to ensure orderly suspend.

Regards
Rakesh

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