All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
@ 2014-02-14  3:20 ` Barry Song
  0 siblings, 0 replies; 14+ messages in thread
From: Barry Song @ 2014-02-14  3:20 UTC (permalink / raw)
  To: dmitry.torokhov, linux-input
  Cc: linux-arm-kernel, workgroup.linux, Xianglong Du, Rongjun Ying,
	Barry Song

From: Xianglong Du <Xianglong.Du@csr.com>

this patch adds a delayed_work to detect the untouch of onkey since HW will
not generate interrupt for it.

at the same time, we move the KEY event to POWER instead of SUSPEND, which
will be suitable for both Android and Linux. Userspace PowerManager Daemon
will decide to suspend or shutdown based on how long we have touched onkey

Signed-off-by: Xianglong Du <Xianglong.Du@csr.com>
Signed-off-by: Rongjun Ying <Rongjun.Ying@csr.com>
Signed-off-by: Barry Song <Baohua.Song@csr.com>
---
 -v3: move to use custom devres action

 drivers/input/misc/sirfsoc-onkey.c |   60 +++++++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
index e8897c3..b354da8 100644
--- a/drivers/input/misc/sirfsoc-onkey.c
+++ b/drivers/input/misc/sirfsoc-onkey.c
@@ -13,16 +13,44 @@
 #include <linux/input.h>
 #include <linux/rtc/sirfsoc_rtciobrg.h>
 #include <linux/of.h>
+#include <linux/workqueue.h>
 
 struct sirfsoc_pwrc_drvdata {
 	u32			pwrc_base;
 	struct input_dev	*input;
+	struct delayed_work	work;
 };
 
 #define PWRC_ON_KEY_BIT			(1 << 0)
 
 #define PWRC_INT_STATUS			0xc
 #define PWRC_INT_MASK			0x10
+#define PWRC_PIN_STATUS			0x14
+#define PWRC_KEY_DETECT_UP_TIME		20	/* ms*/
+
+static inline int sirfsoc_pwrc_is_on_key_down(
+		struct sirfsoc_pwrc_drvdata *pwrcdrv)
+{
+	int state = sirfsoc_rtc_iobrg_readl(
+				pwrcdrv->pwrc_base + PWRC_PIN_STATUS)
+				& PWRC_ON_KEY_BIT;
+	return !state; /* ON_KEY is active low */
+}
+
+static void sirfsoc_pwrc_report_event(struct work_struct *work)
+{
+	struct sirfsoc_pwrc_drvdata *pwrcdrv =
+				container_of((struct delayed_work *)work,
+				struct sirfsoc_pwrc_drvdata, work);
+
+	if (!sirfsoc_pwrc_is_on_key_down(pwrcdrv)) {
+		input_event(pwrcdrv->input, EV_KEY, KEY_POWER, 0);
+		input_sync(pwrcdrv->input);
+	} else {
+		schedule_delayed_work(&pwrcdrv->work,
+			msecs_to_jiffies(PWRC_KEY_DETECT_UP_TIME));
+	}
+}
 
 static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
 {
@@ -34,21 +62,22 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
 	sirfsoc_rtc_iobrg_writel(int_status & ~PWRC_ON_KEY_BIT,
 				 pwrcdrv->pwrc_base + PWRC_INT_STATUS);
 
-	/*
-	 * For a typical Linux system, we report KEY_SUSPEND to trigger apm-power.c
-	 * to queue a SUSPEND APM event
-	 */
-	input_event(pwrcdrv->input, EV_PWR, KEY_SUSPEND, 1);
-	input_sync(pwrcdrv->input);
 
-	/*
-	 * Todo: report KEY_POWER event for Android platforms, Android PowerManager
-	 * will handle the suspend and powerdown/hibernation
-	 */
+	input_event(pwrcdrv->input, EV_KEY, KEY_POWER, 1);
+	input_sync(pwrcdrv->input);
+	schedule_delayed_work(&pwrcdrv->work,
+		msecs_to_jiffies(PWRC_KEY_DETECT_UP_TIME));
 
 	return IRQ_HANDLED;
 }
 
+static void sirfsoc_pwrc_stop_updetect(void *data)
+{
+	struct sirfsoc_pwrc_drvdata *pwrcdrv = data;
+
+	cancel_delayed_work_sync(&pwrcdrv->work);
+}
+
 static const struct of_device_id sirfsoc_pwrc_of_match[] = {
 	{ .compatible = "sirf,prima2-pwrc" },
 	{},
@@ -86,7 +115,9 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 
 	pwrcdrv->input->name = "sirfsoc pwrckey";
 	pwrcdrv->input->phys = "pwrc/input0";
-	pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
+	pwrcdrv->input->evbit[0] = BIT_MASK(EV_KEY);
+
+	INIT_DELAYED_WORK(&pwrcdrv->work, sirfsoc_pwrc_report_event);
 
 	irq = platform_get_irq(pdev, 0);
 	error = devm_request_irq(&pdev->dev, irq,
@@ -98,6 +129,13 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 		return error;
 	}
 
+	error = devm_add_action(&pdev->dev, sirfsoc_pwrc_stop_updetect, pwrcdrv);
+	if (error) {
+		dev_err(&pdev->dev, "failed to add stop untouch detection action, %d\n",
+			error);
+		return error;
+	}
+
 	sirfsoc_rtc_iobrg_writel(
 		sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
 			PWRC_ON_KEY_BIT,
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
@ 2014-02-14  3:20 ` Barry Song
  0 siblings, 0 replies; 14+ messages in thread
From: Barry Song @ 2014-02-14  3:20 UTC (permalink / raw)
  To: linux-arm-kernel

From: Xianglong Du <Xianglong.Du@csr.com>

this patch adds a delayed_work to detect the untouch of onkey since HW will
not generate interrupt for it.

at the same time, we move the KEY event to POWER instead of SUSPEND, which
will be suitable for both Android and Linux. Userspace PowerManager Daemon
will decide to suspend or shutdown based on how long we have touched onkey

Signed-off-by: Xianglong Du <Xianglong.Du@csr.com>
Signed-off-by: Rongjun Ying <Rongjun.Ying@csr.com>
Signed-off-by: Barry Song <Baohua.Song@csr.com>
---
 -v3: move to use custom devres action

 drivers/input/misc/sirfsoc-onkey.c |   60 +++++++++++++++++++++++++++++------
 1 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
index e8897c3..b354da8 100644
--- a/drivers/input/misc/sirfsoc-onkey.c
+++ b/drivers/input/misc/sirfsoc-onkey.c
@@ -13,16 +13,44 @@
 #include <linux/input.h>
 #include <linux/rtc/sirfsoc_rtciobrg.h>
 #include <linux/of.h>
+#include <linux/workqueue.h>
 
 struct sirfsoc_pwrc_drvdata {
 	u32			pwrc_base;
 	struct input_dev	*input;
+	struct delayed_work	work;
 };
 
 #define PWRC_ON_KEY_BIT			(1 << 0)
 
 #define PWRC_INT_STATUS			0xc
 #define PWRC_INT_MASK			0x10
+#define PWRC_PIN_STATUS			0x14
+#define PWRC_KEY_DETECT_UP_TIME		20	/* ms*/
+
+static inline int sirfsoc_pwrc_is_on_key_down(
+		struct sirfsoc_pwrc_drvdata *pwrcdrv)
+{
+	int state = sirfsoc_rtc_iobrg_readl(
+				pwrcdrv->pwrc_base + PWRC_PIN_STATUS)
+				& PWRC_ON_KEY_BIT;
+	return !state; /* ON_KEY is active low */
+}
+
+static void sirfsoc_pwrc_report_event(struct work_struct *work)
+{
+	struct sirfsoc_pwrc_drvdata *pwrcdrv =
+				container_of((struct delayed_work *)work,
+				struct sirfsoc_pwrc_drvdata, work);
+
+	if (!sirfsoc_pwrc_is_on_key_down(pwrcdrv)) {
+		input_event(pwrcdrv->input, EV_KEY, KEY_POWER, 0);
+		input_sync(pwrcdrv->input);
+	} else {
+		schedule_delayed_work(&pwrcdrv->work,
+			msecs_to_jiffies(PWRC_KEY_DETECT_UP_TIME));
+	}
+}
 
 static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
 {
@@ -34,21 +62,22 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
 	sirfsoc_rtc_iobrg_writel(int_status & ~PWRC_ON_KEY_BIT,
 				 pwrcdrv->pwrc_base + PWRC_INT_STATUS);
 
-	/*
-	 * For a typical Linux system, we report KEY_SUSPEND to trigger apm-power.c
-	 * to queue a SUSPEND APM event
-	 */
-	input_event(pwrcdrv->input, EV_PWR, KEY_SUSPEND, 1);
-	input_sync(pwrcdrv->input);
 
-	/*
-	 * Todo: report KEY_POWER event for Android platforms, Android PowerManager
-	 * will handle the suspend and powerdown/hibernation
-	 */
+	input_event(pwrcdrv->input, EV_KEY, KEY_POWER, 1);
+	input_sync(pwrcdrv->input);
+	schedule_delayed_work(&pwrcdrv->work,
+		msecs_to_jiffies(PWRC_KEY_DETECT_UP_TIME));
 
 	return IRQ_HANDLED;
 }
 
+static void sirfsoc_pwrc_stop_updetect(void *data)
+{
+	struct sirfsoc_pwrc_drvdata *pwrcdrv = data;
+
+	cancel_delayed_work_sync(&pwrcdrv->work);
+}
+
 static const struct of_device_id sirfsoc_pwrc_of_match[] = {
 	{ .compatible = "sirf,prima2-pwrc" },
 	{},
@@ -86,7 +115,9 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 
 	pwrcdrv->input->name = "sirfsoc pwrckey";
 	pwrcdrv->input->phys = "pwrc/input0";
-	pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
+	pwrcdrv->input->evbit[0] = BIT_MASK(EV_KEY);
+
+	INIT_DELAYED_WORK(&pwrcdrv->work, sirfsoc_pwrc_report_event);
 
 	irq = platform_get_irq(pdev, 0);
 	error = devm_request_irq(&pdev->dev, irq,
@@ -98,6 +129,13 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 		return error;
 	}
 
+	error = devm_add_action(&pdev->dev, sirfsoc_pwrc_stop_updetect, pwrcdrv);
+	if (error) {
+		dev_err(&pdev->dev, "failed to add stop untouch detection action, %d\n",
+			error);
+		return error;
+	}
+
 	sirfsoc_rtc_iobrg_writel(
 		sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
 			PWRC_ON_KEY_BIT,
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
  2014-02-14  3:20 ` Barry Song
@ 2014-02-14  7:57   ` Dmitry Torokhov
  -1 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2014-02-14  7:57 UTC (permalink / raw)
  To: Barry Song
  Cc: linux-input, linux-arm-kernel, workgroup.linux, Xianglong Du,
	Rongjun Ying, Barry Song

Hi Barry,

On Fri, Feb 14, 2014 at 11:20:01AM +0800, Barry Song wrote:
> From: Xianglong Du <Xianglong.Du@csr.com>
> 
> this patch adds a delayed_work to detect the untouch of onkey since HW will
> not generate interrupt for it.
> 
> at the same time, we move the KEY event to POWER instead of SUSPEND, which
> will be suitable for both Android and Linux. Userspace PowerManager Daemon
> will decide to suspend or shutdown based on how long we have touched onkey
> 
> Signed-off-by: Xianglong Du <Xianglong.Du@csr.com>
> Signed-off-by: Rongjun Ying <Rongjun.Ying@csr.com>
> Signed-off-by: Barry Song <Baohua.Song@csr.com>
> ---
>  -v3: move to use custom devres action

Thank you for making the changes, however it seems that we can control
whether the device generates interrupts or not and so we can implement
open and close methods. If patch below works then your
cancel_delayed_work() call should go into sirfosc_pwrc_close() and we do
not need to use devm_free_irq() not custom action.

Thanks.

-- 
Dmitry


Input: sirfsoc-onkey - implement open and close methods

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>

We can control whetehr device generates interrupts or not so let's
implement open and close methods of input device so that we do not do any
processing until there are users.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/misc/sirfsoc-onkey.c |   50 +++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
index e8897c3..dc7db65 100644
--- a/drivers/input/misc/sirfsoc-onkey.c
+++ b/drivers/input/misc/sirfsoc-onkey.c
@@ -49,6 +49,35 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static void sirfsoc_pwrc_toggle_interrupts(struct sirfsoc_pwrc_drvdata *pwrcdrv,
+					   bool enable)
+{
+	u32 int_mask;
+
+	int_mask = sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK);
+	if (enable)
+		int_mask |= PWRC_ON_KEY_BIT;
+	else
+		int_mask &= ~PWRC_ON_KEY_BIT;
+	sirfsoc_rtc_iobrg_writel(int_mask, pwrcdrv->pwrc_base + PWRC_INT_MASK);
+}
+
+static int sirfsoc_pwrc_open(struct input_dev *input)
+{
+	struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
+
+	sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
+
+	return 0;
+}
+
+static void sirfsoc_pwrc_close(struct input_dev *input)
+{
+	struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
+
+	sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false);
+}
+
 static const struct of_device_id sirfsoc_pwrc_of_match[] = {
 	{ .compatible = "sirf,prima2-pwrc" },
 	{},
@@ -70,7 +99,7 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 	}
 
 	/*
-	 * we can't use of_iomap because pwrc is not mapped in memory,
+	 * We can't use of_iomap because pwrc is not mapped in memory,
 	 * the so-called base address is only offset in rtciobrg
 	 */
 	error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base);
@@ -88,6 +117,11 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 	pwrcdrv->input->phys = "pwrc/input0";
 	pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
 
+	pwrcdrv->input->open = sirfsoc_pwrc_open;
+	pwrcdrv->input->close = sirfsoc_pwrc_close;
+
+	input_set_drvdata(pwrcdrv->input, pwrcdrv);
+
 	irq = platform_get_irq(pdev, 0);
 	error = devm_request_irq(&pdev->dev, irq,
 				 sirfsoc_pwrc_isr, IRQF_SHARED,
@@ -98,11 +132,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 		return error;
 	}
 
-	sirfsoc_rtc_iobrg_writel(
-		sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
-			PWRC_ON_KEY_BIT,
-		pwrcdrv->pwrc_base + PWRC_INT_MASK);
-
 	error = input_register_device(pwrcdrv->input);
 	if (error) {
 		dev_err(&pdev->dev,
@@ -129,15 +158,16 @@ static int pwrc_resume(struct device *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct sirfsoc_pwrc_drvdata *pwrcdrv = platform_get_drvdata(pdev);
+	struct input_dev *input = pwrcdrv->input;
 
 	/*
 	 * Do not mask pwrc interrupt as we want pwrc work as a wakeup source
 	 * if users touch X_ONKEY_B, see arch/arm/mach-prima2/pm.c
 	 */
-	sirfsoc_rtc_iobrg_writel(
-		sirfsoc_rtc_iobrg_readl(
-		pwrcdrv->pwrc_base + PWRC_INT_MASK) | PWRC_ON_KEY_BIT,
-		pwrcdrv->pwrc_base + PWRC_INT_MASK);
+	mutex_lock(&input->mutex);
+	if (input->users)
+		sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
+	mutex_unlock(&input->mutex);
 
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
@ 2014-02-14  7:57   ` Dmitry Torokhov
  0 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2014-02-14  7:57 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Barry,

On Fri, Feb 14, 2014 at 11:20:01AM +0800, Barry Song wrote:
> From: Xianglong Du <Xianglong.Du@csr.com>
> 
> this patch adds a delayed_work to detect the untouch of onkey since HW will
> not generate interrupt for it.
> 
> at the same time, we move the KEY event to POWER instead of SUSPEND, which
> will be suitable for both Android and Linux. Userspace PowerManager Daemon
> will decide to suspend or shutdown based on how long we have touched onkey
> 
> Signed-off-by: Xianglong Du <Xianglong.Du@csr.com>
> Signed-off-by: Rongjun Ying <Rongjun.Ying@csr.com>
> Signed-off-by: Barry Song <Baohua.Song@csr.com>
> ---
>  -v3: move to use custom devres action

Thank you for making the changes, however it seems that we can control
whether the device generates interrupts or not and so we can implement
open and close methods. If patch below works then your
cancel_delayed_work() call should go into sirfosc_pwrc_close() and we do
not need to use devm_free_irq() not custom action.

Thanks.

-- 
Dmitry


Input: sirfsoc-onkey - implement open and close methods

From: Dmitry Torokhov <dmitry.torokhov@gmail.com>

We can control whetehr device generates interrupts or not so let's
implement open and close methods of input device so that we do not do any
processing until there are users.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/input/misc/sirfsoc-onkey.c |   50 +++++++++++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 10 deletions(-)

diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
index e8897c3..dc7db65 100644
--- a/drivers/input/misc/sirfsoc-onkey.c
+++ b/drivers/input/misc/sirfsoc-onkey.c
@@ -49,6 +49,35 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static void sirfsoc_pwrc_toggle_interrupts(struct sirfsoc_pwrc_drvdata *pwrcdrv,
+					   bool enable)
+{
+	u32 int_mask;
+
+	int_mask = sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK);
+	if (enable)
+		int_mask |= PWRC_ON_KEY_BIT;
+	else
+		int_mask &= ~PWRC_ON_KEY_BIT;
+	sirfsoc_rtc_iobrg_writel(int_mask, pwrcdrv->pwrc_base + PWRC_INT_MASK);
+}
+
+static int sirfsoc_pwrc_open(struct input_dev *input)
+{
+	struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
+
+	sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
+
+	return 0;
+}
+
+static void sirfsoc_pwrc_close(struct input_dev *input)
+{
+	struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
+
+	sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false);
+}
+
 static const struct of_device_id sirfsoc_pwrc_of_match[] = {
 	{ .compatible = "sirf,prima2-pwrc" },
 	{},
@@ -70,7 +99,7 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 	}
 
 	/*
-	 * we can't use of_iomap because pwrc is not mapped in memory,
+	 * We can't use of_iomap because pwrc is not mapped in memory,
 	 * the so-called base address is only offset in rtciobrg
 	 */
 	error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base);
@@ -88,6 +117,11 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 	pwrcdrv->input->phys = "pwrc/input0";
 	pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
 
+	pwrcdrv->input->open = sirfsoc_pwrc_open;
+	pwrcdrv->input->close = sirfsoc_pwrc_close;
+
+	input_set_drvdata(pwrcdrv->input, pwrcdrv);
+
 	irq = platform_get_irq(pdev, 0);
 	error = devm_request_irq(&pdev->dev, irq,
 				 sirfsoc_pwrc_isr, IRQF_SHARED,
@@ -98,11 +132,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
 		return error;
 	}
 
-	sirfsoc_rtc_iobrg_writel(
-		sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
-			PWRC_ON_KEY_BIT,
-		pwrcdrv->pwrc_base + PWRC_INT_MASK);
-
 	error = input_register_device(pwrcdrv->input);
 	if (error) {
 		dev_err(&pdev->dev,
@@ -129,15 +158,16 @@ static int pwrc_resume(struct device *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev);
 	struct sirfsoc_pwrc_drvdata *pwrcdrv = platform_get_drvdata(pdev);
+	struct input_dev *input = pwrcdrv->input;
 
 	/*
 	 * Do not mask pwrc interrupt as we want pwrc work as a wakeup source
 	 * if users touch X_ONKEY_B, see arch/arm/mach-prima2/pm.c
 	 */
-	sirfsoc_rtc_iobrg_writel(
-		sirfsoc_rtc_iobrg_readl(
-		pwrcdrv->pwrc_base + PWRC_INT_MASK) | PWRC_ON_KEY_BIT,
-		pwrcdrv->pwrc_base + PWRC_INT_MASK);
+	mutex_lock(&input->mutex);
+	if (input->users)
+		sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
+	mutex_unlock(&input->mutex);
 
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
  2014-02-14  7:57   ` Dmitry Torokhov
@ 2014-02-14  8:49     ` Barry Song
  -1 siblings, 0 replies; 14+ messages in thread
From: Barry Song @ 2014-02-14  8:49 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-arm-kernel, DL-SHA-WorkGroupLinux,
	Xianglong Du, Rongjun Ying, Barry Song

2014-02-14 15:57 GMT+08:00 Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> Hi Barry,
>
> On Fri, Feb 14, 2014 at 11:20:01AM +0800, Barry Song wrote:
>> From: Xianglong Du <Xianglong.Du@csr.com>
>>
>> this patch adds a delayed_work to detect the untouch of onkey since HW will
>> not generate interrupt for it.
>>
>> at the same time, we move the KEY event to POWER instead of SUSPEND, which
>> will be suitable for both Android and Linux. Userspace PowerManager Daemon
>> will decide to suspend or shutdown based on how long we have touched onkey
>>
>> Signed-off-by: Xianglong Du <Xianglong.Du@csr.com>
>> Signed-off-by: Rongjun Ying <Rongjun.Ying@csr.com>
>> Signed-off-by: Barry Song <Baohua.Song@csr.com>
>> ---
>>  -v3: move to use custom devres action
>
> Thank you for making the changes, however it seems that we can control
> whether the device generates interrupts or not and so we can implement
> open and close methods. If patch below works then your
> cancel_delayed_work() call should go into sirfosc_pwrc_close() and we do
> not need to use devm_free_irq() not custom action.

this one looks making lots of senses. it makes sure HW will not
trigger any SW behaviour before probe() finishes, and also makes sure
HW will not trigger any SW behaviour in remove(). i'd like xianglong
to give a quick test on it.

>
> Thanks.
>
> --
> Dmitry
>
>
> Input: sirfsoc-onkey - implement open and close methods
>
> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> We can control whetehr device generates interrupts or not so let's
> implement open and close methods of input device so that we do not do any
> processing until there are users.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/misc/sirfsoc-onkey.c |   50 +++++++++++++++++++++++++++++-------
>  1 file changed, 40 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
> index e8897c3..dc7db65 100644
> --- a/drivers/input/misc/sirfsoc-onkey.c
> +++ b/drivers/input/misc/sirfsoc-onkey.c
> @@ -49,6 +49,35 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
>         return IRQ_HANDLED;
>  }
>
> +static void sirfsoc_pwrc_toggle_interrupts(struct sirfsoc_pwrc_drvdata *pwrcdrv,
> +                                          bool enable)
> +{
> +       u32 int_mask;
> +
> +       int_mask = sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +       if (enable)
> +               int_mask |= PWRC_ON_KEY_BIT;
> +       else
> +               int_mask &= ~PWRC_ON_KEY_BIT;
> +       sirfsoc_rtc_iobrg_writel(int_mask, pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +}
> +
> +static int sirfsoc_pwrc_open(struct input_dev *input)
> +{
> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
> +
> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
> +
> +       return 0;
> +}
> +
> +static void sirfsoc_pwrc_close(struct input_dev *input)
> +{
> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
> +
> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false);
> +}
> +
>  static const struct of_device_id sirfsoc_pwrc_of_match[] = {
>         { .compatible = "sirf,prima2-pwrc" },
>         {},
> @@ -70,7 +99,7 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>         }
>
>         /*
> -        * we can't use of_iomap because pwrc is not mapped in memory,
> +        * We can't use of_iomap because pwrc is not mapped in memory,
>          * the so-called base address is only offset in rtciobrg
>          */
>         error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base);
> @@ -88,6 +117,11 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>         pwrcdrv->input->phys = "pwrc/input0";
>         pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
>
> +       pwrcdrv->input->open = sirfsoc_pwrc_open;
> +       pwrcdrv->input->close = sirfsoc_pwrc_close;
> +
> +       input_set_drvdata(pwrcdrv->input, pwrcdrv);
> +
>         irq = platform_get_irq(pdev, 0);
>         error = devm_request_irq(&pdev->dev, irq,
>                                  sirfsoc_pwrc_isr, IRQF_SHARED,
> @@ -98,11 +132,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>                 return error;
>         }
>
> -       sirfsoc_rtc_iobrg_writel(
> -               sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
> -                       PWRC_ON_KEY_BIT,
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
> -
>         error = input_register_device(pwrcdrv->input);
>         if (error) {
>                 dev_err(&pdev->dev,
> @@ -129,15 +158,16 @@ static int pwrc_resume(struct device *dev)
>  {
>         struct platform_device *pdev = to_platform_device(dev);
>         struct sirfsoc_pwrc_drvdata *pwrcdrv = platform_get_drvdata(pdev);
> +       struct input_dev *input = pwrcdrv->input;
>
>         /*
>          * Do not mask pwrc interrupt as we want pwrc work as a wakeup source
>          * if users touch X_ONKEY_B, see arch/arm/mach-prima2/pm.c
>          */
> -       sirfsoc_rtc_iobrg_writel(
> -               sirfsoc_rtc_iobrg_readl(
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK) | PWRC_ON_KEY_BIT,
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +       mutex_lock(&input->mutex);
> +       if (input->users)
> +               sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
> +       mutex_unlock(&input->mutex);
>
>         return 0;
>  }

-barry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
@ 2014-02-14  8:49     ` Barry Song
  0 siblings, 0 replies; 14+ messages in thread
From: Barry Song @ 2014-02-14  8:49 UTC (permalink / raw)
  To: linux-arm-kernel

2014-02-14 15:57 GMT+08:00 Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> Hi Barry,
>
> On Fri, Feb 14, 2014 at 11:20:01AM +0800, Barry Song wrote:
>> From: Xianglong Du <Xianglong.Du@csr.com>
>>
>> this patch adds a delayed_work to detect the untouch of onkey since HW will
>> not generate interrupt for it.
>>
>> at the same time, we move the KEY event to POWER instead of SUSPEND, which
>> will be suitable for both Android and Linux. Userspace PowerManager Daemon
>> will decide to suspend or shutdown based on how long we have touched onkey
>>
>> Signed-off-by: Xianglong Du <Xianglong.Du@csr.com>
>> Signed-off-by: Rongjun Ying <Rongjun.Ying@csr.com>
>> Signed-off-by: Barry Song <Baohua.Song@csr.com>
>> ---
>>  -v3: move to use custom devres action
>
> Thank you for making the changes, however it seems that we can control
> whether the device generates interrupts or not and so we can implement
> open and close methods. If patch below works then your
> cancel_delayed_work() call should go into sirfosc_pwrc_close() and we do
> not need to use devm_free_irq() not custom action.

this one looks making lots of senses. it makes sure HW will not
trigger any SW behaviour before probe() finishes, and also makes sure
HW will not trigger any SW behaviour in remove(). i'd like xianglong
to give a quick test on it.

>
> Thanks.
>
> --
> Dmitry
>
>
> Input: sirfsoc-onkey - implement open and close methods
>
> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> We can control whetehr device generates interrupts or not so let's
> implement open and close methods of input device so that we do not do any
> processing until there are users.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/misc/sirfsoc-onkey.c |   50 +++++++++++++++++++++++++++++-------
>  1 file changed, 40 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
> index e8897c3..dc7db65 100644
> --- a/drivers/input/misc/sirfsoc-onkey.c
> +++ b/drivers/input/misc/sirfsoc-onkey.c
> @@ -49,6 +49,35 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
>         return IRQ_HANDLED;
>  }
>
> +static void sirfsoc_pwrc_toggle_interrupts(struct sirfsoc_pwrc_drvdata *pwrcdrv,
> +                                          bool enable)
> +{
> +       u32 int_mask;
> +
> +       int_mask = sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +       if (enable)
> +               int_mask |= PWRC_ON_KEY_BIT;
> +       else
> +               int_mask &= ~PWRC_ON_KEY_BIT;
> +       sirfsoc_rtc_iobrg_writel(int_mask, pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +}
> +
> +static int sirfsoc_pwrc_open(struct input_dev *input)
> +{
> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
> +
> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
> +
> +       return 0;
> +}
> +
> +static void sirfsoc_pwrc_close(struct input_dev *input)
> +{
> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
> +
> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false);
> +}
> +
>  static const struct of_device_id sirfsoc_pwrc_of_match[] = {
>         { .compatible = "sirf,prima2-pwrc" },
>         {},
> @@ -70,7 +99,7 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>         }
>
>         /*
> -        * we can't use of_iomap because pwrc is not mapped in memory,
> +        * We can't use of_iomap because pwrc is not mapped in memory,
>          * the so-called base address is only offset in rtciobrg
>          */
>         error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base);
> @@ -88,6 +117,11 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>         pwrcdrv->input->phys = "pwrc/input0";
>         pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
>
> +       pwrcdrv->input->open = sirfsoc_pwrc_open;
> +       pwrcdrv->input->close = sirfsoc_pwrc_close;
> +
> +       input_set_drvdata(pwrcdrv->input, pwrcdrv);
> +
>         irq = platform_get_irq(pdev, 0);
>         error = devm_request_irq(&pdev->dev, irq,
>                                  sirfsoc_pwrc_isr, IRQF_SHARED,
> @@ -98,11 +132,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>                 return error;
>         }
>
> -       sirfsoc_rtc_iobrg_writel(
> -               sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
> -                       PWRC_ON_KEY_BIT,
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
> -
>         error = input_register_device(pwrcdrv->input);
>         if (error) {
>                 dev_err(&pdev->dev,
> @@ -129,15 +158,16 @@ static int pwrc_resume(struct device *dev)
>  {
>         struct platform_device *pdev = to_platform_device(dev);
>         struct sirfsoc_pwrc_drvdata *pwrcdrv = platform_get_drvdata(pdev);
> +       struct input_dev *input = pwrcdrv->input;
>
>         /*
>          * Do not mask pwrc interrupt as we want pwrc work as a wakeup source
>          * if users touch X_ONKEY_B, see arch/arm/mach-prima2/pm.c
>          */
> -       sirfsoc_rtc_iobrg_writel(
> -               sirfsoc_rtc_iobrg_readl(
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK) | PWRC_ON_KEY_BIT,
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +       mutex_lock(&input->mutex);
> +       if (input->users)
> +               sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
> +       mutex_unlock(&input->mutex);
>
>         return 0;
>  }

-barry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
  2014-02-14  8:49     ` Barry Song
@ 2014-02-14 10:32       ` Xianglong Du
  -1 siblings, 0 replies; 14+ messages in thread
From: Xianglong Du @ 2014-02-14 10:32 UTC (permalink / raw)
  To: Barry Song, Dmitry Torokhov
  Cc: Rongjun Ying, DL-SHA-WorkGroupLinux, Barry Song,
	linux-arm-kernel, linux-input

Tested-by: Xianglong Du <Xianglong.Du@csr.com>

________________________________________
From: Barry Song [21cnbao@gmail.com]
Sent: Friday, February 14, 2014 16:49
To: Dmitry Torokhov
Cc: linux-input@vger.kernel.org; linux-arm-kernel@lists.infradead.org; DL-SHA-WorkGroupLinux; Xianglong Du; Rongjun Ying; Barry Song
Subject: Re: [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status

2014-02-14 15:57 GMT+08:00 Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> Hi Barry,
>
> On Fri, Feb 14, 2014 at 11:20:01AM +0800, Barry Song wrote:
>> From: Xianglong Du <Xianglong.Du@csr.com>
>>
>> this patch adds a delayed_work to detect the untouch of onkey since HW will
>> not generate interrupt for it.
>>
>> at the same time, we move the KEY event to POWER instead of SUSPEND, which
>> will be suitable for both Android and Linux. Userspace PowerManager Daemon
>> will decide to suspend or shutdown based on how long we have touched onkey
>>
>> Signed-off-by: Xianglong Du <Xianglong.Du@csr.com>
>> Signed-off-by: Rongjun Ying <Rongjun.Ying@csr.com>
>> Signed-off-by: Barry Song <Baohua.Song@csr.com>
>> ---
>>  -v3: move to use custom devres action
>
> Thank you for making the changes, however it seems that we can control
> whether the device generates interrupts or not and so we can implement
> open and close methods. If patch below works then your
> cancel_delayed_work() call should go into sirfosc_pwrc_close() and we do
> not need to use devm_free_irq() not custom action.

this one looks making lots of senses. it makes sure HW will not
trigger any SW behaviour before probe() finishes, and also makes sure
HW will not trigger any SW behaviour in remove(). i'd like xianglong
to give a quick test on it.

>
> Thanks.
>
> --
> Dmitry
>
>
> Input: sirfsoc-onkey - implement open and close methods
>
> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> We can control whetehr device generates interrupts or not so let's
> implement open and close methods of input device so that we do not do any
> processing until there are users.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/misc/sirfsoc-onkey.c |   50 +++++++++++++++++++++++++++++-------
>  1 file changed, 40 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
> index e8897c3..dc7db65 100644
> --- a/drivers/input/misc/sirfsoc-onkey.c
> +++ b/drivers/input/misc/sirfsoc-onkey.c
> @@ -49,6 +49,35 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
>         return IRQ_HANDLED;
>  }
>
> +static void sirfsoc_pwrc_toggle_interrupts(struct sirfsoc_pwrc_drvdata *pwrcdrv,
> +                                          bool enable)
> +{
> +       u32 int_mask;
> +
> +       int_mask = sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +       if (enable)
> +               int_mask |= PWRC_ON_KEY_BIT;
> +       else
> +               int_mask &= ~PWRC_ON_KEY_BIT;
> +       sirfsoc_rtc_iobrg_writel(int_mask, pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +}
> +
> +static int sirfsoc_pwrc_open(struct input_dev *input)
> +{
> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
> +
> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
> +
> +       return 0;
> +}
> +
> +static void sirfsoc_pwrc_close(struct input_dev *input)
> +{
> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
> +
> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false);
> +}
> +
>  static const struct of_device_id sirfsoc_pwrc_of_match[] = {
>         { .compatible = "sirf,prima2-pwrc" },
>         {},
> @@ -70,7 +99,7 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>         }
>
>         /*
> -        * we can't use of_iomap because pwrc is not mapped in memory,
> +        * We can't use of_iomap because pwrc is not mapped in memory,
>          * the so-called base address is only offset in rtciobrg
>          */
>         error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base);
> @@ -88,6 +117,11 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>         pwrcdrv->input->phys = "pwrc/input0";
>         pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
>
> +       pwrcdrv->input->open = sirfsoc_pwrc_open;
> +       pwrcdrv->input->close = sirfsoc_pwrc_close;
> +
> +       input_set_drvdata(pwrcdrv->input, pwrcdrv);
> +
>         irq = platform_get_irq(pdev, 0);
>         error = devm_request_irq(&pdev->dev, irq,
>                                  sirfsoc_pwrc_isr, IRQF_SHARED,
> @@ -98,11 +132,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>                 return error;
>         }
>
> -       sirfsoc_rtc_iobrg_writel(
> -               sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
> -                       PWRC_ON_KEY_BIT,
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
> -
>         error = input_register_device(pwrcdrv->input);
>         if (error) {
>                 dev_err(&pdev->dev,
> @@ -129,15 +158,16 @@ static int pwrc_resume(struct device *dev)
>  {
>         struct platform_device *pdev = to_platform_device(dev);
>         struct sirfsoc_pwrc_drvdata *pwrcdrv = platform_get_drvdata(pdev);
> +       struct input_dev *input = pwrcdrv->input;
>
>         /*
>          * Do not mask pwrc interrupt as we want pwrc work as a wakeup source
>          * if users touch X_ONKEY_B, see arch/arm/mach-prima2/pm.c
>          */
> -       sirfsoc_rtc_iobrg_writel(
> -               sirfsoc_rtc_iobrg_readl(
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK) | PWRC_ON_KEY_BIT,
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +       mutex_lock(&input->mutex);
> +       if (input->users)
> +               sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
> +       mutex_unlock(&input->mutex);
>
>         return 0;
>  }

-barry


 To report this email as spam click https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ== .


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc.
New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
@ 2014-02-14 10:32       ` Xianglong Du
  0 siblings, 0 replies; 14+ messages in thread
From: Xianglong Du @ 2014-02-14 10:32 UTC (permalink / raw)
  To: linux-arm-kernel

Tested-by: Xianglong Du <Xianglong.Du@csr.com>

________________________________________
From: Barry Song [21cnbao at gmail.com]
Sent: Friday, February 14, 2014 16:49
To: Dmitry Torokhov
Cc: linux-input at vger.kernel.org; linux-arm-kernel at lists.infradead.org; DL-SHA-WorkGroupLinux; Xianglong Du; Rongjun Ying; Barry Song
Subject: Re: [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status

2014-02-14 15:57 GMT+08:00 Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> Hi Barry,
>
> On Fri, Feb 14, 2014 at 11:20:01AM +0800, Barry Song wrote:
>> From: Xianglong Du <Xianglong.Du@csr.com>
>>
>> this patch adds a delayed_work to detect the untouch of onkey since HW will
>> not generate interrupt for it.
>>
>> at the same time, we move the KEY event to POWER instead of SUSPEND, which
>> will be suitable for both Android and Linux. Userspace PowerManager Daemon
>> will decide to suspend or shutdown based on how long we have touched onkey
>>
>> Signed-off-by: Xianglong Du <Xianglong.Du@csr.com>
>> Signed-off-by: Rongjun Ying <Rongjun.Ying@csr.com>
>> Signed-off-by: Barry Song <Baohua.Song@csr.com>
>> ---
>>  -v3: move to use custom devres action
>
> Thank you for making the changes, however it seems that we can control
> whether the device generates interrupts or not and so we can implement
> open and close methods. If patch below works then your
> cancel_delayed_work() call should go into sirfosc_pwrc_close() and we do
> not need to use devm_free_irq() not custom action.

this one looks making lots of senses. it makes sure HW will not
trigger any SW behaviour before probe() finishes, and also makes sure
HW will not trigger any SW behaviour in remove(). i'd like xianglong
to give a quick test on it.

>
> Thanks.
>
> --
> Dmitry
>
>
> Input: sirfsoc-onkey - implement open and close methods
>
> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>
> We can control whetehr device generates interrupts or not so let's
> implement open and close methods of input device so that we do not do any
> processing until there are users.
>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/input/misc/sirfsoc-onkey.c |   50 +++++++++++++++++++++++++++++-------
>  1 file changed, 40 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
> index e8897c3..dc7db65 100644
> --- a/drivers/input/misc/sirfsoc-onkey.c
> +++ b/drivers/input/misc/sirfsoc-onkey.c
> @@ -49,6 +49,35 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
>         return IRQ_HANDLED;
>  }
>
> +static void sirfsoc_pwrc_toggle_interrupts(struct sirfsoc_pwrc_drvdata *pwrcdrv,
> +                                          bool enable)
> +{
> +       u32 int_mask;
> +
> +       int_mask = sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +       if (enable)
> +               int_mask |= PWRC_ON_KEY_BIT;
> +       else
> +               int_mask &= ~PWRC_ON_KEY_BIT;
> +       sirfsoc_rtc_iobrg_writel(int_mask, pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +}
> +
> +static int sirfsoc_pwrc_open(struct input_dev *input)
> +{
> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
> +
> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
> +
> +       return 0;
> +}
> +
> +static void sirfsoc_pwrc_close(struct input_dev *input)
> +{
> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
> +
> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false);
> +}
> +
>  static const struct of_device_id sirfsoc_pwrc_of_match[] = {
>         { .compatible = "sirf,prima2-pwrc" },
>         {},
> @@ -70,7 +99,7 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>         }
>
>         /*
> -        * we can't use of_iomap because pwrc is not mapped in memory,
> +        * We can't use of_iomap because pwrc is not mapped in memory,
>          * the so-called base address is only offset in rtciobrg
>          */
>         error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base);
> @@ -88,6 +117,11 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>         pwrcdrv->input->phys = "pwrc/input0";
>         pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
>
> +       pwrcdrv->input->open = sirfsoc_pwrc_open;
> +       pwrcdrv->input->close = sirfsoc_pwrc_close;
> +
> +       input_set_drvdata(pwrcdrv->input, pwrcdrv);
> +
>         irq = platform_get_irq(pdev, 0);
>         error = devm_request_irq(&pdev->dev, irq,
>                                  sirfsoc_pwrc_isr, IRQF_SHARED,
> @@ -98,11 +132,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>                 return error;
>         }
>
> -       sirfsoc_rtc_iobrg_writel(
> -               sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
> -                       PWRC_ON_KEY_BIT,
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
> -
>         error = input_register_device(pwrcdrv->input);
>         if (error) {
>                 dev_err(&pdev->dev,
> @@ -129,15 +158,16 @@ static int pwrc_resume(struct device *dev)
>  {
>         struct platform_device *pdev = to_platform_device(dev);
>         struct sirfsoc_pwrc_drvdata *pwrcdrv = platform_get_drvdata(pdev);
> +       struct input_dev *input = pwrcdrv->input;
>
>         /*
>          * Do not mask pwrc interrupt as we want pwrc work as a wakeup source
>          * if users touch X_ONKEY_B, see arch/arm/mach-prima2/pm.c
>          */
> -       sirfsoc_rtc_iobrg_writel(
> -               sirfsoc_rtc_iobrg_readl(
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK) | PWRC_ON_KEY_BIT,
> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
> +       mutex_lock(&input->mutex);
> +       if (input->users)
> +               sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
> +       mutex_unlock(&input->mutex);
>
>         return 0;
>  }

-barry


 To report this email as spam click https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ== .


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc.
New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
  2014-02-14 10:32       ` Xianglong Du
@ 2014-02-14 13:41         ` Barry Song
  -1 siblings, 0 replies; 14+ messages in thread
From: Barry Song @ 2014-02-14 13:41 UTC (permalink / raw)
  To: Xianglong Du
  Cc: Dmitry Torokhov, linux-input, linux-arm-kernel,
	DL-SHA-WorkGroupLinux, Rongjun Ying, Barry Song

>> Input: sirfsoc-onkey - implement open and close methods
>>
>> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>>
>> We can control whetehr device generates interrupts or not so let's
>> implement open and close methods of input device so that we do not do any
>> processing until there are users.
>>
>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Tested-by: Xianglong Du <Xianglong.Du@csr.com>

Dmitry, will you push this one to your tree so that i can rebase others?

>> ---
>>  drivers/input/misc/sirfsoc-onkey.c |   50 +++++++++++++++++++++++++++++-------
>>  1 file changed, 40 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
>> index e8897c3..dc7db65 100644
>> --- a/drivers/input/misc/sirfsoc-onkey.c
>> +++ b/drivers/input/misc/sirfsoc-onkey.c
>> @@ -49,6 +49,35 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
>>         return IRQ_HANDLED;
>>  }
>>
>> +static void sirfsoc_pwrc_toggle_interrupts(struct sirfsoc_pwrc_drvdata *pwrcdrv,
>> +                                          bool enable)
>> +{
>> +       u32 int_mask;
>> +
>> +       int_mask = sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK);
>> +       if (enable)
>> +               int_mask |= PWRC_ON_KEY_BIT;
>> +       else
>> +               int_mask &= ~PWRC_ON_KEY_BIT;
>> +       sirfsoc_rtc_iobrg_writel(int_mask, pwrcdrv->pwrc_base + PWRC_INT_MASK);
>> +}
>> +
>> +static int sirfsoc_pwrc_open(struct input_dev *input)
>> +{
>> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
>> +
>> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
>> +
>> +       return 0;
>> +}
>> +
>> +static void sirfsoc_pwrc_close(struct input_dev *input)
>> +{
>> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
>> +
>> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false);
>> +}
>> +
>>  static const struct of_device_id sirfsoc_pwrc_of_match[] = {
>>         { .compatible = "sirf,prima2-pwrc" },
>>         {},
>> @@ -70,7 +99,7 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>>         }
>>
>>         /*
>> -        * we can't use of_iomap because pwrc is not mapped in memory,
>> +        * We can't use of_iomap because pwrc is not mapped in memory,
>>          * the so-called base address is only offset in rtciobrg
>>          */
>>         error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base);
>> @@ -88,6 +117,11 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>>         pwrcdrv->input->phys = "pwrc/input0";
>>         pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
>>
>> +       pwrcdrv->input->open = sirfsoc_pwrc_open;
>> +       pwrcdrv->input->close = sirfsoc_pwrc_close;
>> +
>> +       input_set_drvdata(pwrcdrv->input, pwrcdrv);
>> +
>>         irq = platform_get_irq(pdev, 0);
>>         error = devm_request_irq(&pdev->dev, irq,
>>                                  sirfsoc_pwrc_isr, IRQF_SHARED,
>> @@ -98,11 +132,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>>                 return error;
>>         }
>>
>> -       sirfsoc_rtc_iobrg_writel(
>> -               sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
>> -                       PWRC_ON_KEY_BIT,
>> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
>> -
>>         error = input_register_device(pwrcdrv->input);
>>         if (error) {
>>                 dev_err(&pdev->dev,
>> @@ -129,15 +158,16 @@ static int pwrc_resume(struct device *dev)
>>  {
>>         struct platform_device *pdev = to_platform_device(dev);
>>         struct sirfsoc_pwrc_drvdata *pwrcdrv = platform_get_drvdata(pdev);
>> +       struct input_dev *input = pwrcdrv->input;
>>
>>         /*
>>          * Do not mask pwrc interrupt as we want pwrc work as a wakeup source
>>          * if users touch X_ONKEY_B, see arch/arm/mach-prima2/pm.c
>>          */
>> -       sirfsoc_rtc_iobrg_writel(
>> -               sirfsoc_rtc_iobrg_readl(
>> -               pwrcdrv->pwrc_base + PWRC_INT_MASK) | PWRC_ON_KEY_BIT,
>> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
>> +       mutex_lock(&input->mutex);
>> +       if (input->users)
>> +               sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
>> +       mutex_unlock(&input->mutex);
>>
>>         return 0;
>>  }
>
> -barry

-barry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
@ 2014-02-14 13:41         ` Barry Song
  0 siblings, 0 replies; 14+ messages in thread
From: Barry Song @ 2014-02-14 13:41 UTC (permalink / raw)
  To: linux-arm-kernel

>> Input: sirfsoc-onkey - implement open and close methods
>>
>> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>>
>> We can control whetehr device generates interrupts or not so let's
>> implement open and close methods of input device so that we do not do any
>> processing until there are users.
>>
>> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Tested-by: Xianglong Du <Xianglong.Du@csr.com>

Dmitry, will you push this one to your tree so that i can rebase others?

>> ---
>>  drivers/input/misc/sirfsoc-onkey.c |   50 +++++++++++++++++++++++++++++-------
>>  1 file changed, 40 insertions(+), 10 deletions(-)
>>
>> diff --git a/drivers/input/misc/sirfsoc-onkey.c b/drivers/input/misc/sirfsoc-onkey.c
>> index e8897c3..dc7db65 100644
>> --- a/drivers/input/misc/sirfsoc-onkey.c
>> +++ b/drivers/input/misc/sirfsoc-onkey.c
>> @@ -49,6 +49,35 @@ static irqreturn_t sirfsoc_pwrc_isr(int irq, void *dev_id)
>>         return IRQ_HANDLED;
>>  }
>>
>> +static void sirfsoc_pwrc_toggle_interrupts(struct sirfsoc_pwrc_drvdata *pwrcdrv,
>> +                                          bool enable)
>> +{
>> +       u32 int_mask;
>> +
>> +       int_mask = sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK);
>> +       if (enable)
>> +               int_mask |= PWRC_ON_KEY_BIT;
>> +       else
>> +               int_mask &= ~PWRC_ON_KEY_BIT;
>> +       sirfsoc_rtc_iobrg_writel(int_mask, pwrcdrv->pwrc_base + PWRC_INT_MASK);
>> +}
>> +
>> +static int sirfsoc_pwrc_open(struct input_dev *input)
>> +{
>> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
>> +
>> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
>> +
>> +       return 0;
>> +}
>> +
>> +static void sirfsoc_pwrc_close(struct input_dev *input)
>> +{
>> +       struct sirfsoc_pwrc_drvdata *pwrcdrv = input_get_drvdata(input);
>> +
>> +       sirfsoc_pwrc_toggle_interrupts(pwrcdrv, false);
>> +}
>> +
>>  static const struct of_device_id sirfsoc_pwrc_of_match[] = {
>>         { .compatible = "sirf,prima2-pwrc" },
>>         {},
>> @@ -70,7 +99,7 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>>         }
>>
>>         /*
>> -        * we can't use of_iomap because pwrc is not mapped in memory,
>> +        * We can't use of_iomap because pwrc is not mapped in memory,
>>          * the so-called base address is only offset in rtciobrg
>>          */
>>         error = of_property_read_u32(np, "reg", &pwrcdrv->pwrc_base);
>> @@ -88,6 +117,11 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>>         pwrcdrv->input->phys = "pwrc/input0";
>>         pwrcdrv->input->evbit[0] = BIT_MASK(EV_PWR);
>>
>> +       pwrcdrv->input->open = sirfsoc_pwrc_open;
>> +       pwrcdrv->input->close = sirfsoc_pwrc_close;
>> +
>> +       input_set_drvdata(pwrcdrv->input, pwrcdrv);
>> +
>>         irq = platform_get_irq(pdev, 0);
>>         error = devm_request_irq(&pdev->dev, irq,
>>                                  sirfsoc_pwrc_isr, IRQF_SHARED,
>> @@ -98,11 +132,6 @@ static int sirfsoc_pwrc_probe(struct platform_device *pdev)
>>                 return error;
>>         }
>>
>> -       sirfsoc_rtc_iobrg_writel(
>> -               sirfsoc_rtc_iobrg_readl(pwrcdrv->pwrc_base + PWRC_INT_MASK) |
>> -                       PWRC_ON_KEY_BIT,
>> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
>> -
>>         error = input_register_device(pwrcdrv->input);
>>         if (error) {
>>                 dev_err(&pdev->dev,
>> @@ -129,15 +158,16 @@ static int pwrc_resume(struct device *dev)
>>  {
>>         struct platform_device *pdev = to_platform_device(dev);
>>         struct sirfsoc_pwrc_drvdata *pwrcdrv = platform_get_drvdata(pdev);
>> +       struct input_dev *input = pwrcdrv->input;
>>
>>         /*
>>          * Do not mask pwrc interrupt as we want pwrc work as a wakeup source
>>          * if users touch X_ONKEY_B, see arch/arm/mach-prima2/pm.c
>>          */
>> -       sirfsoc_rtc_iobrg_writel(
>> -               sirfsoc_rtc_iobrg_readl(
>> -               pwrcdrv->pwrc_base + PWRC_INT_MASK) | PWRC_ON_KEY_BIT,
>> -               pwrcdrv->pwrc_base + PWRC_INT_MASK);
>> +       mutex_lock(&input->mutex);
>> +       if (input->users)
>> +               sirfsoc_pwrc_toggle_interrupts(pwrcdrv, true);
>> +       mutex_unlock(&input->mutex);
>>
>>         return 0;
>>  }
>
> -barry

-barry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
  2014-02-14 13:41         ` Barry Song
@ 2014-02-17 19:16           ` Dmitry Torokhov
  -1 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2014-02-17 19:16 UTC (permalink / raw)
  To: Barry Song
  Cc: Xianglong Du, linux-input, linux-arm-kernel,
	DL-SHA-WorkGroupLinux, Rongjun Ying, Barry Song

On Fri, Feb 14, 2014 at 09:41:06PM +0800, Barry Song wrote:
> >> Input: sirfsoc-onkey - implement open and close methods
> >>
> >> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> >>
> >> We can control whetehr device generates interrupts or not so let's
> >> implement open and close methods of input device so that we do not do any
> >> processing until there are users.
> >>
> >> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> Tested-by: Xianglong Du <Xianglong.Du@csr.com>
> 
> Dmitry, will you push this one to your tree so that i can rebase others?

I rebased and pushed everything out, please take a look to make sure it
all looks good.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
@ 2014-02-17 19:16           ` Dmitry Torokhov
  0 siblings, 0 replies; 14+ messages in thread
From: Dmitry Torokhov @ 2014-02-17 19:16 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, Feb 14, 2014 at 09:41:06PM +0800, Barry Song wrote:
> >> Input: sirfsoc-onkey - implement open and close methods
> >>
> >> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> >>
> >> We can control whetehr device generates interrupts or not so let's
> >> implement open and close methods of input device so that we do not do any
> >> processing until there are users.
> >>
> >> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> 
> Tested-by: Xianglong Du <Xianglong.Du@csr.com>
> 
> Dmitry, will you push this one to your tree so that i can rebase others?

I rebased and pushed everything out, please take a look to make sure it
all looks good.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
  2014-02-17 19:16           ` Dmitry Torokhov
@ 2014-02-18  6:11             ` Barry Song
  -1 siblings, 0 replies; 14+ messages in thread
From: Barry Song @ 2014-02-18  6:11 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Xianglong Du, linux-input, linux-arm-kernel, Rongjun Ying,
	Barry Song, DL-SHA-WorkGroupLinux

2014-02-18 3:16 GMT+08:00 Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> On Fri, Feb 14, 2014 at 09:41:06PM +0800, Barry Song wrote:
>> >> Input: sirfsoc-onkey - implement open and close methods
>> >>
>> >> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>> >>
>> >> We can control whetehr device generates interrupts or not so let's
>> >> implement open and close methods of input device so that we do not do any
>> >> processing until there are users.
>> >>
>> >> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>>
>> Tested-by: Xianglong Du <Xianglong.Du@csr.com>
>>
>> Dmitry, will you push this one to your tree so that i can rebase others?
>
> I rebased and pushed everything out, please take a look to make sure it
> all looks good.

thanks, we have done a update to CSR local tree.

>
> Thanks.
>
> --
> Dmitry

-barry

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status
@ 2014-02-18  6:11             ` Barry Song
  0 siblings, 0 replies; 14+ messages in thread
From: Barry Song @ 2014-02-18  6:11 UTC (permalink / raw)
  To: linux-arm-kernel

2014-02-18 3:16 GMT+08:00 Dmitry Torokhov <dmitry.torokhov@gmail.com>:
> On Fri, Feb 14, 2014 at 09:41:06PM +0800, Barry Song wrote:
>> >> Input: sirfsoc-onkey - implement open and close methods
>> >>
>> >> From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>> >>
>> >> We can control whetehr device generates interrupts or not so let's
>> >> implement open and close methods of input device so that we do not do any
>> >> processing until there are users.
>> >>
>> >> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
>>
>> Tested-by: Xianglong Du <Xianglong.Du@csr.com>
>>
>> Dmitry, will you push this one to your tree so that i can rebase others?
>
> I rebased and pushed everything out, please take a look to make sure it
> all looks good.

thanks, we have done a update to CSR local tree.

>
> Thanks.
>
> --
> Dmitry

-barry

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-02-18  6:12 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-14  3:20 [PATCH v3] input: sirfsoc-onkey - report onkey untouch event by detecting pin status Barry Song
2014-02-14  3:20 ` Barry Song
2014-02-14  7:57 ` Dmitry Torokhov
2014-02-14  7:57   ` Dmitry Torokhov
2014-02-14  8:49   ` Barry Song
2014-02-14  8:49     ` Barry Song
2014-02-14 10:32     ` Xianglong Du
2014-02-14 10:32       ` Xianglong Du
2014-02-14 13:41       ` Barry Song
2014-02-14 13:41         ` Barry Song
2014-02-17 19:16         ` Dmitry Torokhov
2014-02-17 19:16           ` Dmitry Torokhov
2014-02-18  6:11           ` Barry Song
2014-02-18  6:11             ` Barry Song

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.