public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] CBUS: retu-headset updates
@ 2007-10-31 12:04 jarkko.nikula
  2007-10-31 12:04 ` [PATCH 1/3] CBUS: Cleanup retu-headset driver jarkko.nikula
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jarkko.nikula @ 2007-10-31 12:04 UTC (permalink / raw)
  To: linux-omap-open-source

Some updates to retu-headset driver picked from internal tree. That's the only
reason why feature implemented in patch 2 is before fix in patch 3 :-)

Note about bias voltage: external mic doesn't need it while device is in
suspend (hard with sales HW due the watchdogs...) and this can save mA or so
the suspend current. However, button detection is kept active since it can
wake-up the system.

-- 
Jarkko

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

* [PATCH 1/3] CBUS: Cleanup retu-headset driver
  2007-10-31 12:04 [PATCH 0/3] CBUS: retu-headset updates jarkko.nikula
@ 2007-10-31 12:04 ` jarkko.nikula
  2007-10-31 12:04 ` [PATCH 2/3] CBUS: Manage bias voltage in retu-headset suspend/resume code jarkko.nikula
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jarkko.nikula @ 2007-10-31 12:04 UTC (permalink / raw)
  To: linux-omap-open-source

From: Jarkko Nikula <jarkko.nikula@nokia.com>

Few cleanups, coding style fixes and unused stuff removal.

Signed-off-by: Jarkko Nikula <jarkko.nikula@nokia.com>
---
 drivers/cbus/retu-headset.c |   25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/cbus/retu-headset.c b/drivers/cbus/retu-headset.c
index cd55bf2..ac21394 100644
--- a/drivers/cbus/retu-headset.c
+++ b/drivers/cbus/retu-headset.c
@@ -32,18 +32,15 @@
 
 #define RETU_HEADSET_KEY		KEY_PHONE
 
-#define STATE_DISABLE_DET		1
-#define STATE_ENABLE_DET		2
-
 struct retu_headset {
-	struct platform_device *pdev;
-	struct input_dev *idev;
-	unsigned bias_enabled:1;
-
-	unsigned detection_enabled:1, pressed:1;
-	int detection_state;
-	struct timer_list enable_timer, detect_timer;
-	spinlock_t lock;
+	spinlock_t			lock;
+	struct platform_device		*pdev;
+	struct input_dev		*idev;
+	unsigned			bias_enabled:1;
+	unsigned			detection_enabled:1;
+	unsigned			pressed:1;
+	struct timer_list		enable_timer;
+	struct timer_list		detect_timer;
 };
 
 static void retu_headset_set_bias(int enable)
@@ -55,7 +52,7 @@ static void retu_headset_set_bias(int enable)
 		retu_set_clear_reg_bits(RETU_REG_AUDTXR, 1 << 3, 0);
 	} else {
 		retu_set_clear_reg_bits(RETU_REG_AUDTXR, 0,
-				    (1 << 0) | (1 << 1) | (1 << 3));
+					(1 << 0) | (1 << 1) | (1 << 3));
 	}
 }
 
@@ -288,7 +285,8 @@ static int retu_headset_remove(struct platform_device *pdev)
 	return 0;
 }
 
-static int retu_headset_suspend(struct platform_device *pdev, pm_message_t mesg)
+static int retu_headset_suspend(struct platform_device *pdev,
+				pm_message_t mesg)
 {
 	return 0;
 }
@@ -298,7 +296,6 @@ static int retu_headset_resume(struct platform_device *pdev)
 	return 0;
 }
 
-
 static struct platform_driver retu_headset_driver = {
 	.probe		= retu_headset_probe,
 	.remove		= retu_headset_remove,
-- 
1.5.3.4

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

* [PATCH 2/3] CBUS: Manage bias voltage in retu-headset suspend/resume code
  2007-10-31 12:04 [PATCH 0/3] CBUS: retu-headset updates jarkko.nikula
  2007-10-31 12:04 ` [PATCH 1/3] CBUS: Cleanup retu-headset driver jarkko.nikula
@ 2007-10-31 12:04 ` jarkko.nikula
  2007-10-31 12:04 ` [PATCH 3/3] CBUS: Fix reentrant issues in retu-headset driver jarkko.nikula
  2007-11-01  9:04 ` [PATCH 0/3] CBUS: retu-headset updates Tony Lindgren
  3 siblings, 0 replies; 5+ messages in thread
From: jarkko.nikula @ 2007-10-31 12:04 UTC (permalink / raw)
  To: linux-omap-open-source

From: Jarkko Nikula <jarkko.nikula@nokia.com>

Signed-off-by: Jarkko Nikula <jarkko.nikula@nokia.com>
---
 drivers/cbus/retu-headset.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/cbus/retu-headset.c b/drivers/cbus/retu-headset.c
index ac21394..7f3f808 100644
--- a/drivers/cbus/retu-headset.c
+++ b/drivers/cbus/retu-headset.c
@@ -288,11 +288,21 @@ static int retu_headset_remove(struct platform_device *pdev)
 static int retu_headset_suspend(struct platform_device *pdev,
 				pm_message_t mesg)
 {
+	struct retu_headset *hs = platform_get_drvdata(pdev);
+
+	if (hs->bias_enabled)
+		retu_headset_set_bias(0);
+
 	return 0;
 }
 
 static int retu_headset_resume(struct platform_device *pdev)
 {
+	struct retu_headset *hs = platform_get_drvdata(pdev);
+
+	if (hs->bias_enabled)
+		retu_headset_set_bias(1);
+
 	return 0;
 }
 
-- 
1.5.3.4

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

* [PATCH 3/3] CBUS: Fix reentrant issues in retu-headset driver
  2007-10-31 12:04 [PATCH 0/3] CBUS: retu-headset updates jarkko.nikula
  2007-10-31 12:04 ` [PATCH 1/3] CBUS: Cleanup retu-headset driver jarkko.nikula
  2007-10-31 12:04 ` [PATCH 2/3] CBUS: Manage bias voltage in retu-headset suspend/resume code jarkko.nikula
@ 2007-10-31 12:04 ` jarkko.nikula
  2007-11-01  9:04 ` [PATCH 0/3] CBUS: retu-headset updates Tony Lindgren
  3 siblings, 0 replies; 5+ messages in thread
From: jarkko.nikula @ 2007-10-31 12:04 UTC (permalink / raw)
  To: linux-omap-open-source

From: Jarkko Nikula <jarkko.nikula@nokia.com>

- Make headset bias and headset button detection enable/disable functions
  reentrant. Protect also suspend/resume callbacks since they call
  retu_headset_set_bias directly.
- Don't define flag variables as bit fields since bit operations may not be
  atomic and we access one of them from interrupt. Now other flags don't
  need any additional locking since they are not accessed from interrupt
  context.

Signed-off-by: Jarkko Nikula <jarkko.nikula@nokia.com>
---
 drivers/cbus/retu-headset.c |   68 +++++++++++++++++++++++++++----------------
 1 files changed, 43 insertions(+), 25 deletions(-)

diff --git a/drivers/cbus/retu-headset.c b/drivers/cbus/retu-headset.c
index 7f3f808..ed2e59b 100644
--- a/drivers/cbus/retu-headset.c
+++ b/drivers/cbus/retu-headset.c
@@ -34,11 +34,12 @@
 
 struct retu_headset {
 	spinlock_t			lock;
+	struct mutex			mutex;
 	struct platform_device		*pdev;
 	struct input_dev		*idev;
-	unsigned			bias_enabled:1;
-	unsigned			detection_enabled:1;
-	unsigned			pressed:1;
+	unsigned			bias_enabled;
+	unsigned			detection_enabled;
+	unsigned			pressed;
 	struct timer_list		enable_timer;
 	struct timer_list		detect_timer;
 };
@@ -58,40 +59,52 @@ static void retu_headset_set_bias(int enable)
 
 static void retu_headset_enable(struct retu_headset *hs)
 {
-	if (hs->bias_enabled)
-		return;
-	hs->bias_enabled = 1;
-	retu_headset_set_bias(1);
+	mutex_lock(&hs->mutex);
+	if (!hs->bias_enabled) {
+		hs->bias_enabled = 1;
+		retu_headset_set_bias(1);
+	}
+	mutex_unlock(&hs->mutex);
 }
 
 static void retu_headset_disable(struct retu_headset *hs)
 {
-	if (!hs->bias_enabled)
-		return;
-	hs->bias_enabled = 0;
-	retu_headset_set_bias(0);
+	mutex_lock(&hs->mutex);
+	if (hs->bias_enabled) {
+		hs->bias_enabled = 0;
+		retu_headset_set_bias(0);
+	}
+	mutex_unlock(&hs->mutex);
 }
 
 static void retu_headset_det_enable(struct retu_headset *hs)
 {
-	if (hs->detection_enabled)
-		return;
-	hs->detection_enabled = 1;
-	retu_set_clear_reg_bits(RETU_REG_CC1, (1 << 10) | (1 << 8), 0);
-	retu_enable_irq(RETU_INT_HOOK);
+	mutex_lock(&hs->mutex);
+	if (!hs->detection_enabled) {
+		hs->detection_enabled = 1;
+		retu_set_clear_reg_bits(RETU_REG_CC1, (1 << 10) | (1 << 8), 0);
+		retu_enable_irq(RETU_INT_HOOK);
+	}
+	mutex_unlock(&hs->mutex);
 }
 
 static void retu_headset_det_disable(struct retu_headset *hs)
 {
-	if (!hs->detection_enabled)
-		return;
-	hs->detection_enabled = 0;
-	retu_disable_irq(RETU_INT_HOOK);
-	del_timer_sync(&hs->enable_timer);
-	del_timer_sync(&hs->detect_timer);
-	if (hs->pressed)
-		input_report_key(hs->idev, RETU_HEADSET_KEY, 0);
-	retu_set_clear_reg_bits(RETU_REG_CC1, 0, (1 << 10) | (1 << 8));
+	unsigned long flags;
+
+	mutex_lock(&hs->mutex);
+	if (hs->detection_enabled) {
+		hs->detection_enabled = 0;
+		retu_disable_irq(RETU_INT_HOOK);
+		del_timer_sync(&hs->enable_timer);
+		del_timer_sync(&hs->detect_timer);
+		spin_lock_irqsave(&hs->lock, flags);
+		if (hs->pressed)
+			input_report_key(hs->idev, RETU_HEADSET_KEY, 0);
+		spin_unlock_irqrestore(&hs->lock, flags);
+		retu_set_clear_reg_bits(RETU_REG_CC1, 0, (1 << 10) | (1 << 8));
+	}
+	mutex_unlock(&hs->mutex);
 }
 
 static ssize_t retu_headset_hookdet_show(struct device *dev,
@@ -242,6 +255,7 @@ static int __init retu_headset_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, hs);
 
 	spin_lock_init(&hs->lock);
+	mutex_init(&hs->mutex);
 	setup_timer(&hs->enable_timer, retu_headset_enable_timer,
 		    (unsigned long) hs);
 	setup_timer(&hs->detect_timer, retu_headset_detect_timer,
@@ -290,8 +304,10 @@ static int retu_headset_suspend(struct platform_device *pdev,
 {
 	struct retu_headset *hs = platform_get_drvdata(pdev);
 
+	mutex_lock(&hs->mutex);
 	if (hs->bias_enabled)
 		retu_headset_set_bias(0);
+	mutex_unlock(&hs->mutex);
 
 	return 0;
 }
@@ -300,8 +316,10 @@ static int retu_headset_resume(struct platform_device *pdev)
 {
 	struct retu_headset *hs = platform_get_drvdata(pdev);
 
+	mutex_lock(&hs->mutex);
 	if (hs->bias_enabled)
 		retu_headset_set_bias(1);
+	mutex_unlock(&hs->mutex);
 
 	return 0;
 }
-- 
1.5.3.4

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

* Re: [PATCH 0/3] CBUS: retu-headset updates
  2007-10-31 12:04 [PATCH 0/3] CBUS: retu-headset updates jarkko.nikula
                   ` (2 preceding siblings ...)
  2007-10-31 12:04 ` [PATCH 3/3] CBUS: Fix reentrant issues in retu-headset driver jarkko.nikula
@ 2007-11-01  9:04 ` Tony Lindgren
  3 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2007-11-01  9:04 UTC (permalink / raw)
  To: jarkko.nikula; +Cc: linux-omap-open-source

* jarkko.nikula@nokia.com <jarkko.nikula@nokia.com> [071031 05:04]:
> Some updates to retu-headset driver picked from internal tree. That's the only
> reason why feature implemented in patch 2 is before fix in patch 3 :-)
> 
> Note about bias voltage: external mic doesn't need it while device is in
> suspend (hard with sales HW due the watchdogs...) and this can save mA or so
> the suspend current. However, button detection is kept active since it can
> wake-up the system.

Pushing all three today.

Tony

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

end of thread, other threads:[~2007-11-01  9:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-31 12:04 [PATCH 0/3] CBUS: retu-headset updates jarkko.nikula
2007-10-31 12:04 ` [PATCH 1/3] CBUS: Cleanup retu-headset driver jarkko.nikula
2007-10-31 12:04 ` [PATCH 2/3] CBUS: Manage bias voltage in retu-headset suspend/resume code jarkko.nikula
2007-10-31 12:04 ` [PATCH 3/3] CBUS: Fix reentrant issues in retu-headset driver jarkko.nikula
2007-11-01  9:04 ` [PATCH 0/3] CBUS: retu-headset updates Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox