Skip to content

Commit 2633f73

Browse files
committed
ASoC: wm5100: Handle failures to determine accessory polarity
If we get an indeterminate impedance with both headset polarities then give up and report the accessory as a headphone rather than continually retrying. Signed-off-by: Mark Brown <[email protected]>
1 parent 24e0c57 commit 2633f73

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

sound/soc/codecs/wm5100.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct wm5100_priv {
7272
bool jack_detecting;
7373
bool jack_mic;
7474
int jack_mode;
75+
int jack_flips;
7576

7677
struct wm5100_fll fll[2];
7778

@@ -1996,6 +1997,19 @@ static void wm5100_set_detect_mode(struct wm5100_priv *wm5100, int the_mode)
19961997
wm5100->jack_mode);
19971998
}
19981999

2000+
static void wm5100_report_headphone(struct wm5100_priv *wm5100)
2001+
{
2002+
dev_dbg(wm5100->dev, "Headphone detected\n");
2003+
wm5100->jack_detecting = false;
2004+
snd_soc_jack_report(wm5100->jack, SND_JACK_HEADPHONE,
2005+
SND_JACK_HEADPHONE);
2006+
2007+
/* Increase the detection rate a bit for responsiveness. */
2008+
regmap_update_bits(wm5100->regmap, WM5100_MIC_DETECT_1,
2009+
WM5100_ACCDET_RATE_MASK,
2010+
7 << WM5100_ACCDET_RATE_SHIFT);
2011+
}
2012+
19992013
static void wm5100_micd_irq(struct wm5100_priv *wm5100)
20002014
{
20012015
unsigned int val;
@@ -2020,6 +2034,7 @@ static void wm5100_micd_irq(struct wm5100_priv *wm5100)
20202034
dev_dbg(wm5100->dev, "Jack removal detected\n");
20212035
wm5100->jack_mic = false;
20222036
wm5100->jack_detecting = true;
2037+
wm5100->jack_flips = 0;
20232038
snd_soc_jack_report(wm5100->jack, 0,
20242039
SND_JACK_LINEOUT | SND_JACK_HEADSET |
20252040
SND_JACK_BTN_0);
@@ -2058,10 +2073,16 @@ static void wm5100_micd_irq(struct wm5100_priv *wm5100)
20582073
/* If we detected a lower impedence during initial startup
20592074
* then we probably have the wrong polarity, flip it. Don't
20602075
* do this for the lowest impedences to speed up detection of
2061-
* plain headphones.
2076+
* plain headphones and give up if neither polarity looks
2077+
* sensible.
20622078
*/
20632079
if (wm5100->jack_detecting && (val & 0x3f8)) {
2064-
wm5100_set_detect_mode(wm5100, !wm5100->jack_mode);
2080+
wm5100->jack_flips++;
2081+
2082+
if (wm5100->jack_flips > 1)
2083+
wm5100_report_headphone(wm5100);
2084+
else
2085+
wm5100_set_detect_mode(wm5100, !wm5100->jack_mode);
20652086

20662087
return;
20672088
}
@@ -2075,16 +2096,7 @@ static void wm5100_micd_irq(struct wm5100_priv *wm5100)
20752096
snd_soc_jack_report(wm5100->jack, SND_JACK_BTN_0,
20762097
SND_JACK_BTN_0);
20772098
} else if (wm5100->jack_detecting) {
2078-
dev_dbg(wm5100->dev, "Headphone detected\n");
2079-
snd_soc_jack_report(wm5100->jack, SND_JACK_HEADPHONE,
2080-
SND_JACK_HEADPHONE);
2081-
2082-
/* Increase the detection rate a bit for
2083-
* responsiveness.
2084-
*/
2085-
regmap_update_bits(wm5100->regmap, WM5100_MIC_DETECT_1,
2086-
WM5100_ACCDET_RATE_MASK,
2087-
7 << WM5100_ACCDET_RATE_SHIFT);
2099+
wm5100_report_headphone(wm5100);
20882100
}
20892101
}
20902102
}
@@ -2096,6 +2108,7 @@ int wm5100_detect(struct snd_soc_codec *codec, struct snd_soc_jack *jack)
20962108
if (jack) {
20972109
wm5100->jack = jack;
20982110
wm5100->jack_detecting = true;
2111+
wm5100->jack_flips = 0;
20992112

21002113
wm5100_set_detect_mode(wm5100, 0);
21012114

0 commit comments

Comments
 (0)