Skip to content

Commit 2a0761a

Browse files
committed
ASoC: Implement WM835x microphone jack detection support
The WM8350 provides microphone presence and short circuit detection. Integrate this with the ASoC jack reporting API. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
1 parent fbc2dae commit 2a0761a

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

‎include/linux/mfd/wm8350/audio.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@
492492
*/
493493
#define WM8350_JACK_L_LVL 0x0800
494494
#define WM8350_JACK_R_LVL 0x0400
495+
#define WM8350_JACK_MICSCD_LVL 0x0200
496+
#define WM8350_JACK_MICSD_LVL 0x0100
495497

496498
/*
497499
* WM8350 Platform setup

‎sound/soc/codecs/wm8350.c‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct wm8350_output {
5454
struct wm8350_jack_data {
5555
struct snd_soc_jack *jack;
5656
int report;
57+
int short_report;
5758
};
5859

5960
struct wm8350_data {
@@ -62,6 +63,7 @@ struct wm8350_data {
6263
struct wm8350_output out2;
6364
struct wm8350_jack_data hpl;
6465
struct wm8350_jack_data hpr;
66+
struct wm8350_jack_data mic;
6567
struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
6668
int fll_freq_out;
6769
int fll_freq_in;
@@ -1430,6 +1432,55 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
14301432
}
14311433
EXPORT_SYMBOL_GPL(wm8350_hp_jack_detect);
14321434

1435+
static irqreturn_t wm8350_mic_handler(int irq, void *data)
1436+
{
1437+
struct wm8350_data *priv = data;
1438+
struct wm8350 *wm8350 = priv->codec.control_data;
1439+
u16 reg;
1440+
int report = 0;
1441+
1442+
reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
1443+
if (reg & WM8350_JACK_MICSCD_LVL)
1444+
report |= priv->mic.short_report;
1445+
if (reg & WM8350_JACK_MICSD_LVL)
1446+
report |= priv->mic.report;
1447+
1448+
snd_soc_jack_report(priv->mic.jack, report,
1449+
priv->mic.report | priv->mic.short_report);
1450+
1451+
return IRQ_HANDLED;
1452+
}
1453+
1454+
/**
1455+
* wm8350_mic_jack_detect - Enable microphone jack detection.
1456+
*
1457+
* @codec: WM8350 codec
1458+
* @jack: jack to report detection events on
1459+
* @detect_report: value to report when presence detected
1460+
* @short_report: value to report when microphone short detected
1461+
*
1462+
* Enables the microphone jack detection of the WM8350.
1463+
*/
1464+
int wm8350_mic_jack_detect(struct snd_soc_codec *codec,
1465+
struct snd_soc_jack *jack,
1466+
int detect_report, int short_report)
1467+
{
1468+
struct wm8350_data *priv = codec->private_data;
1469+
struct wm8350 *wm8350 = codec->control_data;
1470+
1471+
priv->mic.jack = jack;
1472+
priv->mic.report = detect_report;
1473+
priv->mic.short_report = short_report;
1474+
1475+
wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
1476+
wm8350_set_bits(wm8350, WM8350_POWER_MGMT_1, WM8350_MIC_DET_ENA);
1477+
1478+
snd_soc_dapm_force_enable_pin(codec, "Mic Bias");
1479+
1480+
return 0;
1481+
}
1482+
EXPORT_SYMBOL_GPL(wm8350_mic_jack_detect);
1483+
14331484
static struct snd_soc_codec *wm8350_codec;
14341485

14351486
static int wm8350_probe(struct platform_device *pdev)
@@ -1493,6 +1544,10 @@ static int wm8350_probe(struct platform_device *pdev)
14931544
wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R,
14941545
wm8350_hp_jack_handler, 0, "Right jack detect",
14951546
priv);
1547+
wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICSCD,
1548+
wm8350_mic_handler, 0, "Microphone short", priv);
1549+
wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICD,
1550+
wm8350_mic_handler, 0, "Microphone detect", priv);
14961551

14971552
ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
14981553
if (ret < 0) {
@@ -1521,11 +1576,14 @@ static int wm8350_remove(struct platform_device *pdev)
15211576
WM8350_JDL_ENA | WM8350_JDR_ENA);
15221577
wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
15231578

1579+
wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_MICD, priv);
1580+
wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_MICSCD, priv);
15241581
wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L, priv);
15251582
wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R, priv);
15261583

15271584
priv->hpl.jack = NULL;
15281585
priv->hpr.jack = NULL;
1586+
priv->mic.jack = NULL;
15291587

15301588
/* cancel any work waiting to be queued. */
15311589
ret = cancel_delayed_work(&codec->delayed_work);

‎sound/soc/codecs/wm8350.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@ enum wm8350_jack {
2525

2626
int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
2727
struct snd_soc_jack *jack, int report);
28+
int wm8350_mic_jack_detect(struct snd_soc_codec *codec,
29+
struct snd_soc_jack *jack,
30+
int detect_report, int short_report);
2831

2932
#endif

0 commit comments

Comments
 (0)