ASoC: max98095: add jack detection
PATCH 1/1 ASoC: max98095: add jack detection
This change adds the logic to support using the jack detect mechanism built in to the codec to detect both when a jack was inserted and what type of jack is present.
This change also supports the use of an external mechanism for headphone detection. If this mechanism exists, when the max98095_jack_detect function is called, the hp_jack is simply passed NULL.
This change supports both simple headphones, powered headphones, microphones and headsets with both headphones and a mic.
--- include/sound/max98095.h | 7 ++ sound/soc/codecs/max98095.c | 166 ++++++++++++++++++++++++++++++++++++++++++- sound/soc/codecs/max98095.h | 22 ++++++ 3 files changed, 194 insertions(+), 1 deletions(-)
include/sound/max98095.h +7 -0
@@ -49,6 +49,13 @@ struct max98095_pdata {*/ unsigned int digmic_left_mode:1; unsigned int digmic_right_mode:1; + +/* Pin5 is the mechanical method of sensing jack insertion +* but it is something that might not be supported. +* 0 = PIN5 not supported +* 1 = PIN5 supported +*/ + int jack_detect_pin5en:1; };#endif
sound/soc/codecs/max98095.c +165 -1
225 lines not on this page · raw message
sound/soc/codecs/max98095.h +22 -0
@@ -175,11 +175,23 @@/* MAX98095 Registers Bit Fields */ +/* M98095_007_JACK_AUTO_STS */ +#define M98095_MIC_IN (1<<3) +#define M98095_LO_IN (1<<5) +#define M98095_HP_IN (1<<6) +#define M98095_DDONE (1<<7) +/* M98095_00F_HOST_CFG */ #define M98095_SEG (1<<0)#define M98095_XTEN (1<<1)#define M98095_MDLLEN (1<<2) +/* M98095_013_JACK_INT_EN */ +#define M98095_IMIC_IN (1<<3) +#define M98095_ILO_IN (1<<5) +#define M98095_IHP_IN (1<<6) +#define M98095_IDDONE (1<<7) +/* M98095_027_DAI1_CLKMODE, M98095_031_DAI2_CLKMODE, M98095_03B_DAI3_CLKMODE */ #define M98095_CLKMODE_MASK 0xFF
@@ -255,6 +267,10 @@#define M98095_EQ2EN (1<<1)#define M98095_EQ1EN (1<<0) +/* M98095_089_JACK_DET_AUTO */ +#define M98095_PIN5EN (1<<2) +#define M98095_JDEN (1<<7) +/* M98095_090_PWR_EN_IN */ #define M98095_INEN (1<<7)#define M98095_MB2EN (1<<3)
@@ -296,4 +312,10 @@#define M98095_174_DAI1_BQ_BASE 0x74#define M98095_17E_DAI2_BQ_BASE 0x7E +/* Default Delay used in Slew Rate Calculation for Jack detection */ +#define M98095_DEFAULT_SLEW_DELAY 0x18 + +extern int max98095_jack_detect (struct snd_soc_codec *codec, +struct snd_soc_jack *hp_jack,struct snd_soc_jack *mic_jack); +#endif
Signature · 1 line
1.7.3.4
Quoted 3 lines · Rhyland Klein
This change adds the logic to support using the jack detect mechanism built in to the codec to detect both when a jack was inserted and what type of jack is present.
You send another identically titled patch of roughly the same size a few minutes ago - what's the difference between the two or is it just a resend?
Quoted 10 lines · Mark Brown
* PGP Signed by an unknown key
Quoted 3 lines · Rhyland Klein
This change adds the logic to support using the jack detect mechanism built in to the codec to detect both when a jack was inserted and what type of jack is present.
You send another identically titled patch of roughly the same size a few minutes ago - what's the difference between the two or is it just a resend?
Sorry, they are the same. I hadn't subscribed to the alsa-devel mailing list and so the first one I sent got as non-subscriber sent email. I canceled the outstanding notice waiting for approval, and resent once I subscribed to the mailing list.
-rhyland
Quoted 3 lines
* Unknown Key
*0x6E30FDDD
Quoted 3 lines · Rhyland Klein
This change adds the logic to support using the jack detect mechanism built in to the codec to detect both when a jack was inserted and what type of jack is present.
This looks mostly good, a few things below.
sound/soc/codecs/max98095.c struct max98095_priv { · line 55
Quoted 5 lines
sound/soc/codecs/max98095.c +1
-0@@ -51,6 +52,9 @@ struct max98095_priv {u8 lin_state;unsigned int mic1pre;unsigned int mic2pre; +int irq;
You can just get the irq from the I2C device.
sound/soc/codecs/max98095.c static void max98095_handle_pdata(struct snd_soc_codec *codec) · line 2207
Quoted 5 lines
sound/soc/codecs/max98095.c +5
-0+if (max98095->headphone_jack == max98095->mic_jack) +snd_soc_jack_report (max98095->headphone_jack, + hp_report | mic_report, +SND_JACK_HEADSET ); +else {
Braces on both sides of the if for clarity.
sound/soc/codecs/max98095.c static void max98095_handle_pdata(struct snd_soc_codec *codec) · line 2226
Quoted 8 lines
sound/soc/codecs/max98095.c +8
-0+static irqreturn_t max98095_jack_handler (int irq,void *data) +{ +struct snd_soc_codec *codec = data; +int ret; + + ret =max98095_report_jack (codec); + +return ret ?IRQ_NONE :IRQ_HANDLED ;
There is no point in having a separate function here, this function has no contents. Just inline it. Please also avoid the use of the ternery operator.
sound/soc/codecs/max98095.c static void max98095_handle_pdata(struct snd_soc_codec *codec) · line 2247
Quoted 9 lines
sound/soc/codecs/max98095.c +9
-0+/* configure jack detection: slew is calculated as 4 * (delay + 1) +* The default is 24 (0x18) to get 100ms delay. +*/ + ret =snd_soc_write (codec,M98095_08E_JACK_DC_SLEW , +M98095_DEFAULT_SLEW_DELAY ); +if (ret <0 ) { +dev_err (codec->dev,"Failed to cfg auto detect %d\n" , ret); +return ret; + }
Platform data?
sound/soc/codecs/max98095.c static int max98095_suspend(struct snd_soc_codec *codec) · line 2324
Quoted 1 line
sound/soc/codecs/max98095.c +1
-0+enable_irq (max98095->irq);
You shouldn't be fiddling around with enable_irq() and disable_irq(). Why are you doing this?
Quoted 10 lines · Mark Brown
* PGP Signed by an unknown key
Quoted 3 lines · Rhyland Klein
This change adds the logic to support using the jack detect mechanism built in to the codec to detect both when a jack was inserted and what type of jack is present.
This looks mostly good, a few things below.
Quoted 7 lines
sound/soc/codecs/max98095.c struct max98095_priv { · line 55
Quoted 5 lines
sound/soc/codecs/max98095.c +1
-0@@ -51,6 +52,9 @@ struct max98095_priv {u8 lin_state;unsigned int mic1pre;unsigned int mic2pre; +int irq;You can just get the irq from the I2C device.
Right, will do.
Quoted 8 lines
sound/soc/codecs/max98095.c static void max98095_handle_pdata(struct snd_soc_codec *codec) · line 2207
Quoted 6 lines
sound/soc/codecs/max98095.c +5
-0+if (max98095->headphone_jack == max98095->mic_jack) +snd_soc_jack_report (max98095->headphone_jack, + hp_report | mic_report, +SND_JACK_HEADSET ); +else {Braces on both sides of the if for clarity.
will do.
Quoted 13 lines
sound/soc/codecs/max98095.c static void max98095_handle_pdata(struct snd_soc_codec *codec) · line 2226
Quoted 9 lines
sound/soc/codecs/max98095.c +8
-0+static irqreturn_t max98095_jack_handler (int irq,void *data) +{ +struct snd_soc_codec *codec = data; +int ret; + + ret =max98095_report_jack (codec); + +return ret ?IRQ_NONE :IRQ_HANDLED ;There is no point in having a separate function here, this function has no contents. Just inline it. Please also avoid the use of the ternery operator.
will do.
Quoted 12 lines
sound/soc/codecs/max98095.c static void max98095_handle_pdata(struct snd_soc_codec *codec) · line 2247
Quoted 10 lines
sound/soc/codecs/max98095.c +9
-0+/* configure jack detection: slew is calculated as 4 * (delay + 1) +* The default is 24 (0x18) to get 100ms delay. +*/ + ret =snd_soc_write (codec,M98095_08E_JACK_DC_SLEW , +M98095_DEFAULT_SLEW_DELAY ); +if (ret <0 ) { +dev_err (codec->dev,"Failed to cfg auto detect %d\n" , ret); +return ret; + }Platform data?
As of now there isn't. But that does make sense to support. Will add.
Quoted 5 lines
sound/soc/codecs/max98095.c static int max98095_suspend(struct snd_soc_codec *codec) · line 2324
Quoted 2 lines
sound/soc/codecs/max98095.c +1
-0+enable_irq (max98095->irq);You shouldn't be fiddling around with
enable_irq()anddisable_irq(). Why are you doing this?
this can be removed.
Quoted 3 lines
* Unknown Key
*0x6E30FDDD
Thanks for quick review,
Rhyland