[PATCH] input/imx_keypad: add pm suspend and resume functions

Subsystems: input (keyboard, mouse, joystick, touchscreen) drivers, the rest

STALE5450d

7 messages, 3 authors, 2011-10-09 · open the first message on its own page

[PATCH] input/imx_keypad: add pm suspend and resume functions

From: Hui Wang <hidden>
Date: 2011-09-30 07:54:30

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.

Signed-off-by: Hui Wang <redacted>
---
Validated this patch both on i.MX51 PDK and i.MX31 PDK

 drivers/input/keyboard/imx_keypad.c |   42 +++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index d92c15c..9992617 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -567,10 +567,52 @@ 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);
+
+	clk_disable(kbd->clk);
+
+	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;
+
+	mutex_lock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		disable_irq_wake(kbd->irq);
+
+	if (input_dev->users)
+		clk_enable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	return 0;
+}
+
+static const struct dev_pm_ops imx_kbd_pm_ops = {
+	.suspend	= imx_kbd_suspend,
+	.resume		= 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),
-- 
1.7.6

Re: [PATCH] input/imx_keypad: add pm suspend and resume functions

From: Wanlong Gao <hidden>
Date: 2011-09-30 08:43:20

On 09/30/2011 03:54 PM, Hui Wang wrote:
quoted hunk
The imx_keypad driver is set wake capable in the imx_keypad_probe(),
but it doesn't implement suspend and reusme callback interface.
quoted
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.

Signed-off-by: Hui Wang <redacted>
---
Validated this patch both on i.MX51 PDK and i.MX31 PDK

 drivers/input/keyboard/imx_keypad.c |   42 +++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index d92c15c..9992617 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -567,10 +567,52 @@ 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);
+
+	clk_disable(kbd->clk);
+
+	if (device_may_wakeup(&pdev->dev))
+		enable_irq_wake(kbd->irq);
+
+	return 0;
+}
	struct input_dev *input_dev = kbd->input_dev;
	if (device_may_wakeup(dev)) {
		enable_irq_wake(kdb->irq);
	} else {
		mutex_lock(&input_dev->mutex);

		if (input_dev->users)
			clk_disable(kbd->clk);

		mutex_unlock(&input_dev->mutex);
	}

right?
+
+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;
+
+	mutex_lock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		disable_irq_wake(kbd->irq);
+
+	if (input_dev->users)
+		clk_enable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	return 0;
+}
	struct input_dev *input_dev = kbd->input_dev;
	if (device_may_wakeup(dev)) {
		disable_irq_wake(kdb->irq);
	} else {
		mutex_lock(&input_dev->mutex);

		if (input_dev->users)
			clk_enable(kbd->clk);

		mutex_unlock(&input_dev->mutex);
	}
+
+static const struct dev_pm_ops imx_kbd_pm_ops = {

SIMPLE_DEV_PM_OPS?


Thanks
-Wanlong Gao

Re: [PATCH] input/imx_keypad: add pm suspend and resume functions

From: Hui Wang <hidden>
Date: 2011-09-30 09:00:12

Wanlong Gao wrote:
On 09/30/2011 03:54 PM, Hui Wang wrote:

  
quoted
The imx_keypad driver is set wake capable in the imx_keypad_probe(),
but it doesn't implement suspend and reusme callback interface.
quoted
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.

Signed-off-by: Hui Wang <redacted>
---
Validated this patch both on i.MX51 PDK and i.MX31 PDK

 drivers/input/keyboard/imx_keypad.c |   42 +++++++++++++++++++++++++++++++++++
 1 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
index d92c15c..9992617 100644
--- a/drivers/input/keyboard/imx_keypad.c
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -567,10 +567,52 @@ 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);
+
+	clk_disable(kbd->clk);
+
+	if (device_may_wakeup(&pdev->dev))
+		enable_irq_wake(kbd->irq);
+
+	return 0;
+}
    
	struct input_dev *input_dev = kbd->input_dev;
	if (device_may_wakeup(dev)) {
		enable_irq_wake(kdb->irq);
	} else {
		mutex_lock(&input_dev->mutex);

		if (input_dev->users)
			clk_disable(kbd->clk);

		mutex_unlock(&input_dev->mutex);
	}

right?

  
The i.MX series kpp is not like other normal kpps on other platforms, 
the kpp on the i.MX can detect key event and wake up system from low 
power mode even we disable kpp clock. So i choose to unconditionally 
disable its clock. I have explain it the commit header.

"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.
"
quoted
+
+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;
+
+	mutex_lock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		disable_irq_wake(kbd->irq);
+
+	if (input_dev->users)
+		clk_enable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	return 0;
+}
    
	struct input_dev *input_dev = kbd->input_dev;
	if (device_may_wakeup(dev)) {
		disable_irq_wake(kdb->irq);
	} else {
		mutex_lock(&input_dev->mutex);

		if (input_dev->users)
			clk_enable(kbd->clk);

		mutex_unlock(&input_dev->mutex);
	}

  
So, if we unconditionally disable kpp clock in the suspend, we don't 
need above logic as well in the resume.
quoted
+
+static const struct dev_pm_ops imx_kbd_pm_ops = {
    

SIMPLE_DEV_PM_OPS?
  
Correct, i will use SIMPLE_DEV_PM_OPS in V2.
Thanks
-Wanlong Gao

  

Re: [PATCH] input/imx_keypad: add pm suspend and resume functions

From: Wanlong Gao <hidden>
Date: 2011-09-30 09:06:50

On 09/30/2011 04:59 PM, Hui Wang wrote:
Wanlong Gao wrote:
quoted
On 09/30/2011 03:54 PM, Hui Wang wrote:

  
quoted
The imx_keypad driver is set wake capable in the imx_keypad_probe(),
but it doesn't implement suspend and reusme callback interface.
quoted
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.

Signed-off-by: Hui Wang <redacted>
---
quoted
  
The i.MX series kpp is not like other normal kpps on other platforms, 
the kpp on the i.MX can detect key event and wake up system from low 
power mode even we disable kpp clock. So i choose to unconditionally 
disable its clock. I have explain it the commit header.

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

I see.
quoted
quoted
+
+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;
+
+	mutex_lock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		disable_irq_wake(kbd->irq);
+
+	if (input_dev->users)
+		clk_enable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	return 0;
+}

But is it need to hold a mutex lock also when *disable_irq_wake()* here ?

Thanks
-Wanlong Gao

Re: [PATCH] input/imx_keypad: add pm suspend and resume functions

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Date: 2011-09-30 09:12:34

On Fri, Sep 30, 2011 at 04:59:53PM +0800, Hui Wang wrote:
Wanlong Gao wrote:
quoted
On 09/30/2011 03:54 PM, Hui Wang wrote:
quoted
+
+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;
+
+	mutex_lock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		disable_irq_wake(kbd->irq);
+
+	if (input_dev->users)
+		clk_enable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	return 0;
+}
struct input_dev *input_dev = kbd->input_dev;
if (device_may_wakeup(dev)) {
	disable_irq_wake(kdb->irq);
} else {
	mutex_lock(&input_dev->mutex);

	if (input_dev->users)
		clk_enable(kbd->clk);

	mutex_unlock(&input_dev->mutex);
}
So, if we unconditionally disable kpp clock in the suspend, we don't
need above logic as well in the resume.
We should not unconditionally disable clock in suspend, you need to check
if there are any users (or drop check in resume), otherwise you'll get
unbalanced count in clk (suspend - decrement, resume - not enabling clk
if device is not being used).

Also locking is needed in suspend.

Thanks.

-- 
Dmitry

Re: [PATCH] input/imx_keypad: add pm suspend and resume functions

From: Hui Wang <hidden>
Date: 2011-10-09 09:48:15

Wanlong Gao wrote:
On 09/30/2011 04:59 PM, Hui Wang wrote:

  
quoted
Wanlong Gao wrote:
    
quoted
On 09/30/2011 03:54 PM, Hui Wang wrote:

  
      
quoted
The imx_keypad driver is set wake capable in the imx_keypad_probe(),
but it doesn't implement suspend and reusme callback interface.
quoted
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.

Signed-off-by: Hui Wang <redacted>
---
        
  
quoted
quoted
  
      
The i.MX series kpp is not like other normal kpps on other platforms, 
the kpp on the i.MX can detect key event and wake up system from low 
power mode even we disable kpp clock. So i choose to unconditionally 
disable its clock. I have explain it the commit header.

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

    

I see.

  
quoted
quoted
quoted
+
+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;
+
+	mutex_lock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		disable_irq_wake(kbd->irq);
+
+	if (input_dev->users)
+		clk_enable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	return 0;
+}
        

But is it need to hold a mutex lock also when *disable_irq_wake()* here ?
  
Yes, this is a problem, i will address it in the V2.

Thanks,
Hui.
Thanks
-Wanlong Gao

  

Re: [PATCH] input/imx_keypad: add pm suspend and resume functions

From: Hui Wang <hidden>
Date: 2011-10-09 09:50:13

Dmitry Torokhov wrote:
On Fri, Sep 30, 2011 at 04:59:53PM +0800, Hui Wang wrote:
  
quoted
Wanlong Gao wrote:
    
quoted
On 09/30/2011 03:54 PM, Hui Wang wrote:
      
quoted
+
+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;
+
+	mutex_lock(&input_dev->mutex);
+
+	if (device_may_wakeup(&pdev->dev))
+		disable_irq_wake(kbd->irq);
+
+	if (input_dev->users)
+		clk_enable(kbd->clk);
+
+	mutex_unlock(&input_dev->mutex);
+
+	return 0;
+}
        
	struct input_dev *input_dev = kbd->input_dev;
	if (device_may_wakeup(dev)) {
		disable_irq_wake(kdb->irq);
	} else {
		mutex_lock(&input_dev->mutex);

		if (input_dev->users)
			clk_enable(kbd->clk);

		mutex_unlock(&input_dev->mutex);
	}

      
So, if we unconditionally disable kpp clock in the suspend, we don't
need above logic as well in the resume.
    
We should not unconditionally disable clock in suspend, you need to check
if there are any users (or drop check in resume), otherwise you'll get
unbalanced count in clk (suspend - decrement, resume - not enabling clk
if device is not being used).

Also locking is needed in suspend.

  
Got it, will fix them in the V2.

Thanks,
Hui.
Thanks.

  

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help