Skip to contentSkip to conversation

input/imx_keypad: add pm suspend and resume functions

PATCH In review Hui Wang 2 participants 4 messages Oct 13, 2011 – Oct 27, 2011

Subsystems (3)
lore
Share & tools
lore

Hui Wang

author
#0 lore raw

PATCH v2 1/1 input/imx_keypad: add pm suspend and resume functions

The imx_keypad driver is set wake capable in the imx_keypad_probe(), but it doesn't implement suspend and reusme callback interface.

Quoted 1 line

From the i.MX series MCU Reference Manual, the kpp (keypad port) is

a major wake up source which can detect any key press even in low power modes and even when there is no clock.

Now add suspend and resume callback functions for this driver.

---

Sorry for resending this patch, the previous sent patch with [v2] as a prefix, i am afraid that patch was filtered out from mailing list. Now resending this patch with [PATCH v2] as a prefix.

In the V2:
1) add a check for input->users before disable clock.
2) add mutex_lock/unlock to protect input->users checking.
3) use SIMPLE_DEV_PM_OPS.

 drivers/input/keyboard/imx_keypad.c |   46 +++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
drivers/input/keyboard/imx_keypad.c +46 -0
index d92c15c..c43fa97 100644
@@ -567,10 +567,56 @@ static int __devexit imx_keypad_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int imx_kbd_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct imx_keypad *kbd = platform_get_drvdata(pdev);
+	struct input_dev *input_dev = kbd->input_dev;
+
+	/* imx kbd can wake up system even clock is disabled */
+	mutex_lock(&input_dev->mutex);
+
+	if (input_dev->users)
+		clk_disable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		enable_irq_wake(kbd->irq);
+
+	return 0;
+}
+
+static int imx_kbd_resume(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct imx_keypad *kbd = platform_get_drvdata(pdev);
+	struct input_dev *input_dev = kbd->input_dev;
+
+	if (device_may_wakeup(&pdev->dev))
+		disable_irq_wake(kbd->irq);
+
+	mutex_lock(&input_dev->mutex);
+
+	if (input_dev->users)
+		clk_enable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(imx_kbd_pm_ops, imx_kbd_suspend, imx_kbd_resume);
+#endif
+
 static struct platform_driver imx_keypad_driver = {
 	.driver		= {
 		.name	= "imx-keypad",
 		.owner	= THIS_MODULE,
+#ifdef CONFIG_PM
+		.pm	= &imx_kbd_pm_ops,
+#endif
 	},
 	.probe		= imx_keypad_probe,
 	.remove		= __devexit_p(imx_keypad_remove),
Signature · 1 line
1.7.6
maintainer
#1 lore raw
Quoted 39 lines · Hui Wang

The imx_keypad driver is set wake capable in the imx_keypad_probe(), but it doesn't implement suspend and reusme callback interface.

From the i.MX series MCU Reference Manual, the kpp (keypad port) is a major wake up source which can detect any key press even in low power modes and even when there is no clock.

Now add suspend and resume callback functions for this driver.

---

Sorry for resending this patch, the previous sent patch with [v2] as a prefix, i am afraid that patch was filtered out from mailing list. Now resending this patch with [PATCH v2] as a prefix.

In the V2:
1) add a check for input->users before disable clock.
2) add mutex_lock/unlock to protect input->users checking.
3) use SIMPLE_DEV_PM_OPS.

 drivers/input/keyboard/imx_keypad.c |   46 +++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
drivers/input/keyboard/imx_keypad.c +7 -0
index d92c15c..c43fa97 100644
@@ -567,10 +567,56 @@ static int __devexit imx_keypad_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int imx_kbd_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct imx_keypad *kbd = platform_get_drvdata(pdev);
+	struct input_dev *input_dev = kbd->input_dev;
+

drivers/input/keyboard/imx_keypad.c static int __devexit imx_keypad_remove(struct platform_device *pdev) · line 586

Quoted 10 lines
drivers/input/keyboard/imx_keypad.c +10 -0
+	/* imx kbd can wake up system even clock is disabled */
+	mutex_lock(&input_dev->mutex);
+
+	if (input_dev->users)
+		clk_disable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		enable_irq_wake(kbd->irq);

enable_irq_wake can fail. More specifically it *will* fail on all non tzic i.MX boards as this function is not yet implemented for the avic irq controller.
You should check the return value.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author
#2 lore raw
Quoted 49 lines · Sascha Hauer
Quoted 47 lines · Hui Wang

The imx_keypad driver is set wake capable in the imx_keypad_probe(), but it doesn't implement suspend and reusme callback interface.

From the i.MX series MCU Reference Manual, the kpp (keypad port) is a major wake up source which can detect any key press even in low power modes and even when there is no clock.

Now add suspend and resume callback functions for this driver.

---

Sorry for resending this patch, the previous sent patch with [v2] as a prefix, i am afraid that patch was filtered out from mailing list. Now resending this patch with [PATCH v2] as a prefix.

In the V2:
1) add a check for input->users before disable clock.
2) add mutex_lock/unlock to protect input->users checking.
3) use SIMPLE_DEV_PM_OPS.

 drivers/input/keyboard/imx_keypad.c |   46 +++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)
drivers/input/keyboard/imx_keypad.c +15 -0
index d92c15c..c43fa97 100644
@@ -567,10 +567,56 @@ static int __devexit imx_keypad_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_PM
+static int imx_kbd_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct imx_keypad *kbd = platform_get_drvdata(pdev);
+	struct input_dev *input_dev = kbd->input_dev;
+
+	/* imx kbd can wake up system even clock is disabled */
+	mutex_lock(&input_dev->mutex);
+
+	if (input_dev->users)
+		clk_disable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
Quoted 10 lines

drivers/input/keyboard/imx_keypad.c static int __devexit imx_keypad_remove(struct platform_device *pdev)

Quoted 3 lines
drivers/input/keyboard/imx_keypad.c +2 -0
+	if (device_may_wakeup(&pdev->dev))
+		enable_irq_wake(kbd->irq);
 

enable_irq_wake can fail. More specifically it *will* fail on all non tzic i.MX boards as this function is not yet implemented for the avic irq controller.
You should check the return value.

Hi Sascha,

I have sent a patch to change plat-mxc/avic.c to use generic irq chip, in this patch, two lines to handle wakeup_set issues:

gc->wake_enabled = IRQ_MSK(32);
ct->chip.irq_set_wake = irq_gc_set_wake;

These two lines will make enable_irq_wake successful unconditionally.

And i recall you have sent this patch to Arnd through a pull request.

Thanks,
Hui.

Quoted 5 lines

Sascha

maintainer
#3 lore raw
Quoted 61 lines · Hui Wang
Quoted 46 lines · Sascha Hauer
Quoted 45 lines · Hui Wang

The imx_keypad driver is set wake capable in the imx_keypad_probe(), but it doesn't implement suspend and reusme callback interface.

From the i.MX series MCU Reference Manual, the kpp (keypad port) is a major wake up source which can detect any key press even in low power modes and even when there is no clock.

Now add suspend and resume callback functions for this driver.

---

Sorry for resending this patch, the previous sent patch with [v2] as a prefix, i am afraid that patch was filtered out from mailing list. Now resending this patch with [PATCH v2] as a prefix.

In the V2:
1) add a check for input->users before disable clock.
2) add mutex_lock/unlock to protect input->users checking.
3) use SIMPLE_DEV_PM_OPS.

drivers/input/keyboard/imx_keypad.c | 46 +++++++++++++++++++++++++++++++++++

1 files changed, 46 insertions(+), 0 deletions(-)
drivers/input/keyboard/imx_keypad.c +14 -0
index d92c15c..c43fa97 100644
@@ -567,10 +567,56 @@ static int __devexit imx_keypad_remove(struct platform_device *pdev)
 	return 0;
 }
+#ifdef CONFIG_PM
+static int imx_kbd_suspend(struct device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	struct imx_keypad *kbd = platform_get_drvdata(pdev);
+	struct input_dev *input_dev = kbd->input_dev;
+
+	/* imx kbd can wake up system even clock is disabled */
+	mutex_lock(&input_dev->mutex);
+
+	if (input_dev->users)
+		clk_disable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
Quoted 9 lines

drivers/input/keyboard/imx_keypad.c static int __devexit imx_keypad_remove(struct platform_device *pdev) · line 586

Quoted 3 lines
drivers/input/keyboard/imx_keypad.c +3 -0
+
+	if (device_may_wakeup(&pdev->dev))
+		enable_irq_wake(kbd->irq);

enable_irq_wake can fail. More specifically it *will* fail on all non tzic i.MX boards as this function is not yet implemented for the avic irq controller.
You should check the return value.

Hi Sascha,

I have sent a patch to change plat-mxc/avic.c to use generic irq chip, in this patch, two lines to handle wakeup_set issues:

Quoted 6 lines

gc->wake_enabled = IRQ_MSK(32);
ct->chip.irq_set_wake = irq_gc_set_wake;

These two lines will make enable_irq_wake successful unconditionally.

And i recall you have sent this patch to Arnd through a pull request.

Ok, so currently this function can't fail, but this a very bad excuse for not checking error values.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |