Skip to contentSkip to conversation

CBUS: retu-headset updates

PATCH In review [email protected] 2 participants 5 messages Oct 31, 2007 – Nov 1, 2007

lore
Share & tools
lore
#0 lore raw

cover CBUS: retu-headset updates

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.

Signature · 1 line
Jarkko
#1 lore raw

PATCH 1/3 CBUS: Cleanup retu-headset driver

From: Jarkko Nikula <[email protected]>

Few cleanups, coding style fixes and unused stuff removal.

---
 drivers/cbus/retu-headset.c |   25 +++++++++++--------------
 1 files changed, 11 insertions(+), 14 deletions(-)
drivers/cbus/retu-headset.c +11 -14
index cd55bf2..ac21394 100644
@@ -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,
Signature · 1 line
1.5.3.4
#2 lore raw

PATCH 2/3 CBUS: Manage bias voltage in retu-headset suspend/resume code

In reply to [email protected]

From: Jarkko Nikula <[email protected]>

---
 drivers/cbus/retu-headset.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
drivers/cbus/retu-headset.c +10 -0
index ac21394..7f3f808 100644
@@ -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;
 }
 
Signature · 1 line
1.5.3.4
#3 lore raw

PATCH 3/3 CBUS: Fix reentrant issues in retu-headset driver

In reply to [email protected]

From: Jarkko Nikula <[email protected]>

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

---
 drivers/cbus/retu-headset.c |   68 +++++++++++++++++++++++++++----------------
 1 files changed, 43 insertions(+), 25 deletions(-)
drivers/cbus/retu-headset.c +43 -25
index 7f3f808..ed2e59b 100644
@@ -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;
 }
Signature · 1 line
1.5.3.4
#4 lore raw
In reply to [email protected]
Quoted 7 lines · * [email protected] <[email protected]> [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