Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1565758 > unrolled thread

[PATCH] extcon: arizona: Wait for any running HPDETs to complete on jack removal

Started byCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
First post2017-01-24 11:20 +0100
Last post2017-01-25 10:20 +0100
Articles 3 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] extcon: arizona: Wait for any running HPDETs to complete on jack removal Charles Keepax <ckeepax@opensource.wolfsonmicro.com> - 2017-01-24 11:20 +0100
    Re: [PATCH] extcon: arizona: Wait for any running HPDETs to complete  on jack removal Chanwoo Choi <cw00.choi@samsung.com> - 2017-01-25 02:10 +0100
      Re: [PATCH] extcon: arizona: Wait for any running HPDETs to complete  on jack removal Charles Keepax <ckeepax@opensource.wolfsonmicro.com> - 2017-01-25 10:20 +0100

#1565758 — [PATCH] extcon: arizona: Wait for any running HPDETs to complete on jack removal

FromCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Date2017-01-24 11:20 +0100
Subject[PATCH] extcon: arizona: Wait for any running HPDETs to complete on jack removal
Message-ID<t36mK-30U-13@gated-at.bofh.it>
As the HPDET can't be aborted mid way through we should not allow any new
insertion to be processed until the previous HPDET has finished. It is very
unlikely but with low enough debounce settings you could start a new HPDET
before the old one has completed, which results in an erroneous reading.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
---
 drivers/extcon/extcon-arizona.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index ed78b7c..218e378 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -1049,6 +1049,39 @@ static void arizona_hpdet_work(struct work_struct *work)
 	mutex_unlock(&info->lock);
 }
 
+static int arizona_hpdet_wait(struct arizona_extcon_info *info)
+{
+	struct arizona *arizona = info->arizona;
+	unsigned int val;
+	int i, ret;
+
+	for (i = 0; i < 15; i++) {
+		ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2,
+				  &val);
+		if (ret) {
+			dev_err(arizona->dev,
+				"Failed to read HPDET state: %d\n", ret);
+			return ret;
+		}
+
+		switch (info->hpdet_ip_version) {
+		case 0:
+			if (val & ARIZONA_HP_DONE)
+				return 0;
+			break;
+		default:
+			if (val & ARIZONA_HP_DONE_B)
+				return 0;
+			break;
+		}
+
+		msleep(20);
+	}
+
+	dev_err(arizona->dev, "HPDET did not appear to complete\n");
+	return -ETIMEDOUT;
+}
+
 static irqreturn_t arizona_jackdet(int irq, void *data)
 {
 	struct arizona_extcon_info *info = data;
@@ -1155,6 +1188,8 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
 					"Removal report failed: %d\n", ret);
 		}
 
+		arizona_hpdet_wait(info);
+
 		regmap_update_bits(arizona->regmap,
 				   ARIZONA_JACK_DETECT_DEBOUNCE,
 				   ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
-- 
2.1.4

[toc] | [next] | [standalone]


#1566256 — Re: [PATCH] extcon: arizona: Wait for any running HPDETs to complete on jack removal

FromChanwoo Choi <cw00.choi@samsung.com>
Date2017-01-25 02:10 +0100
SubjectRe: [PATCH] extcon: arizona: Wait for any running HPDETs to complete on jack removal
Message-ID<t3kg2-3qv-9@gated-at.bofh.it>
In reply to#1565758
Hi Charles,

On 2017년 01월 24일 19:17, Charles Keepax wrote:
> As the HPDET can't be aborted mid way through we should not allow any new
> insertion to be processed until the previous HPDET has finished. It is very
> unlikely but with low enough debounce settings you could start a new HPDET
> before the old one has completed, which results in an erroneous reading.
> 
> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> ---
>  drivers/extcon/extcon-arizona.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
> 
> diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
> index ed78b7c..218e378 100644
> --- a/drivers/extcon/extcon-arizona.c
> +++ b/drivers/extcon/extcon-arizona.c
> @@ -1049,6 +1049,39 @@ static void arizona_hpdet_work(struct work_struct *work)
>  	mutex_unlock(&info->lock);
>  }
>  
> +static int arizona_hpdet_wait(struct arizona_extcon_info *info)
> +{
> +	struct arizona *arizona = info->arizona;
> +	unsigned int val;
> +	int i, ret;
> +
> +	for (i = 0; i < 15; i++) {

I recommend that you define the separate constant definition
instead of using interger value (15) directly as following:
	
	#define HPDET_WAIT_COUNT	15

> +		ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2,
> +				  &val);
> +		if (ret) {
> +			dev_err(arizona->dev,
> +				"Failed to read HPDET state: %d\n", ret);
> +			return ret;
> +		}
> +
> +		switch (info->hpdet_ip_version) {
> +		case 0:
> +			if (val & ARIZONA_HP_DONE)
> +				return 0;
> +			break;
> +		default:
> +			if (val & ARIZONA_HP_DONE_B)
> +				return 0;
> +			break;
> +		}
> +
> +		msleep(20);

ditto.

	#define HPDET_WAIT_DELAY_MS	20

> +	}
> +
> +	dev_err(arizona->dev, "HPDET did not appear to complete\n");
> +	return -ETIMEDOUT;
> +}
> +
>  static irqreturn_t arizona_jackdet(int irq, void *data)
>  {
>  	struct arizona_extcon_info *info = data;
> @@ -1155,6 +1188,8 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
>  					"Removal report failed: %d\n", ret);
>  		}
>  

Sometimes I met this similiar case on specific h/w.
I agree to add some delay according to the h/w.
So, you better to add the detailed comment before
calling the arizona_hpdet_wait() to make it easy
to understand why it is necessary.

> +		arizona_hpdet_wait(info);

Is not necessary to check the return value of this call?
When arizona_hpdet_wait() return the -ETIMEDOUT,
Does not this error affect the next some code?

> +

>  		regmap_update_bits(arizona->regmap,
>  				   ARIZONA_JACK_DETECT_DEBOUNCE,
>  				   ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
> 
-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

[toc] | [prev] | [next] | [standalone]


#1566402 — Re: [PATCH] extcon: arizona: Wait for any running HPDETs to complete on jack removal

FromCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Date2017-01-25 10:20 +0100
SubjectRe: [PATCH] extcon: arizona: Wait for any running HPDETs to complete on jack removal
Message-ID<t3rUe-8k5-33@gated-at.bofh.it>
In reply to#1566256
On Wed, Jan 25, 2017 at 10:00:40AM +0900, Chanwoo Choi wrote:
> Hi Charles,
> 
> On 2017년 01월 24일 19:17, Charles Keepax wrote:
> > As the HPDET can't be aborted mid way through we should not allow any new
> > insertion to be processed until the previous HPDET has finished. It is very
> > unlikely but with low enough debounce settings you could start a new HPDET
> > before the old one has completed, which results in an erroneous reading.
> > 
> > Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> > ---
> >  drivers/extcon/extcon-arizona.c | 35 +++++++++++++++++++++++++++++++++++
> >  1 file changed, 35 insertions(+)
> > 
> > diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
> > index ed78b7c..218e378 100644
> > --- a/drivers/extcon/extcon-arizona.c
> > +++ b/drivers/extcon/extcon-arizona.c
> > @@ -1049,6 +1049,39 @@ static void arizona_hpdet_work(struct work_struct *work)
> >  	mutex_unlock(&info->lock);
> >  }
> >  
> > +static int arizona_hpdet_wait(struct arizona_extcon_info *info)
> > +{
> > +	struct arizona *arizona = info->arizona;
> > +	unsigned int val;
> > +	int i, ret;
> > +
> > +	for (i = 0; i < 15; i++) {
> 
> I recommend that you define the separate constant definition
> instead of using interger value (15) directly as following:
> 	
> 	#define HPDET_WAIT_COUNT	15
> 
> > +		ret = regmap_read(arizona->regmap, ARIZONA_HEADPHONE_DETECT_2,
> > +				  &val);
> > +		if (ret) {
> > +			dev_err(arizona->dev,
> > +				"Failed to read HPDET state: %d\n", ret);
> > +			return ret;
> > +		}
> > +
> > +		switch (info->hpdet_ip_version) {
> > +		case 0:
> > +			if (val & ARIZONA_HP_DONE)
> > +				return 0;
> > +			break;
> > +		default:
> > +			if (val & ARIZONA_HP_DONE_B)
> > +				return 0;
> > +			break;
> > +		}
> > +
> > +		msleep(20);
> 
> ditto.
> 
> 	#define HPDET_WAIT_DELAY_MS	20
> 

Yeah can do.

> > +	}
> > +
> > +	dev_err(arizona->dev, "HPDET did not appear to complete\n");
> > +	return -ETIMEDOUT;
> > +}
> > +
> >  static irqreturn_t arizona_jackdet(int irq, void *data)
> >  {
> >  	struct arizona_extcon_info *info = data;
> > @@ -1155,6 +1188,8 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
> >  					"Removal report failed: %d\n", ret);
> >  		}
> >  
> 
> Sometimes I met this similiar case on specific h/w.
> I agree to add some delay according to the h/w.
> So, you better to add the detailed comment before
> calling the arizona_hpdet_wait() to make it easy
> to understand why it is necessary.
> 
> > +		arizona_hpdet_wait(info);
> 

No problem to add a comment.

> Is not necessary to check the return value of this call?
> When arizona_hpdet_wait() return the -ETIMEDOUT,
> Does not this error affect the next some code?
> 

I included a return value for completeness sake and incase the
function gets reused in other places in the future. But at that
point I don't think there is really any action we can take if
that call fails, that part of the code relates to the jack being
removed so we still need to take all those actions. We can only
really log that the failure happened in the kernel log which it
already does.

Thanks,
Charles

> > +
> 
> >  		regmap_update_bits(arizona->regmap,
> >  				   ARIZONA_JACK_DETECT_DEBOUNCE,
> >  				   ARIZONA_MICD_CLAMP_DB | ARIZONA_JD1_DB,
> > 
> -- 
> Best Regards,
> Chanwoo Choi
> Samsung Electronics

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web