Skip to content

Commit 2551b6e

Browse files
LeeWeiTse-sevenbroonie
authored andcommitted
ASoC: nau8821: Add headset button detection
This patch adds the function of headphone button detection, Button detection will be enabled if the device tree has a key_enable property. Signed-off-by: Seven Lee <wtli@nuvoton.com> Link: https://lore.kernel.org/r/20220627032959.3442064-1-wtli@nuvoton.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 8e26c51 commit 2551b6e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

Documentation/devicetree/bindings/sound/nau8821.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Optional properties:
3434
- nuvoton,jack-eject-debounce: number from 0 to 7 that sets debounce time to 2^(n+2) ms
3535

3636
- nuvoton,dmic-clk-threshold: the ADC threshold of DMIC clock.
37-
37+
- nuvoton,key_enable: Headset button detection switch.
3838

3939
Example:
4040

sound/soc/codecs/nau8821.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#define NAU_FVCO_MAX 100000000
3030
#define NAU_FVCO_MIN 90000000
3131

32+
#define NAU8821_BUTTON SND_JACK_BTN_0
33+
3234
/* the maximum frequency of CLK_ADC and CLK_DAC */
3335
#define CLK_DA_AD_MAX 6144000
3436

@@ -911,6 +913,20 @@ static void nau8821_eject_jack(struct nau8821 *nau8821)
911913
/* Recover to normal channel input */
912914
regmap_update_bits(regmap, NAU8821_R2B_ADC_RATE,
913915
NAU8821_ADC_R_SRC_EN, 0);
916+
if (nau8821->key_enable) {
917+
regmap_update_bits(regmap, NAU8821_R0F_INTERRUPT_MASK,
918+
NAU8821_IRQ_KEY_RELEASE_EN |
919+
NAU8821_IRQ_KEY_PRESS_EN,
920+
NAU8821_IRQ_KEY_RELEASE_EN |
921+
NAU8821_IRQ_KEY_PRESS_EN);
922+
regmap_update_bits(regmap,
923+
NAU8821_R12_INTERRUPT_DIS_CTRL,
924+
NAU8821_IRQ_KEY_RELEASE_DIS |
925+
NAU8821_IRQ_KEY_PRESS_DIS,
926+
NAU8821_IRQ_KEY_RELEASE_DIS |
927+
NAU8821_IRQ_KEY_PRESS_DIS);
928+
}
929+
914930
}
915931

916932
static void nau8821_jdet_work(struct work_struct *work)
@@ -940,6 +956,15 @@ static void nau8821_jdet_work(struct work_struct *work)
940956
*/
941957
regmap_update_bits(regmap, NAU8821_R2B_ADC_RATE,
942958
NAU8821_ADC_R_SRC_EN, NAU8821_ADC_R_SRC_EN);
959+
if (nau8821->key_enable) {
960+
regmap_update_bits(regmap, NAU8821_R0F_INTERRUPT_MASK,
961+
NAU8821_IRQ_KEY_RELEASE_EN |
962+
NAU8821_IRQ_KEY_PRESS_EN, 0);
963+
regmap_update_bits(regmap,
964+
NAU8821_R12_INTERRUPT_DIS_CTRL,
965+
NAU8821_IRQ_KEY_RELEASE_DIS |
966+
NAU8821_IRQ_KEY_PRESS_DIS, 0);
967+
}
943968
} else {
944969
dev_dbg(nau8821->dev, "Headphone connected\n");
945970
event |= SND_JACK_HEADPHONE;
@@ -999,6 +1024,13 @@ static irqreturn_t nau8821_interrupt(int irq, void *data)
9991024
nau8821_eject_jack(nau8821);
10001025
event_mask |= SND_JACK_HEADSET;
10011026
clear_irq = NAU8821_JACK_EJECT_IRQ_MASK;
1027+
} else if (active_irq & NAU8821_KEY_SHORT_PRESS_IRQ) {
1028+
event |= NAU8821_BUTTON;
1029+
event_mask |= NAU8821_BUTTON;
1030+
clear_irq = NAU8821_KEY_SHORT_PRESS_IRQ;
1031+
} else if (active_irq & NAU8821_KEY_RELEASE_IRQ) {
1032+
event_mask = NAU8821_BUTTON;
1033+
clear_irq = NAU8821_KEY_RELEASE_IRQ;
10021034
} else if ((active_irq & NAU8821_JACK_INSERT_IRQ_MASK) ==
10031035
NAU8821_JACK_INSERT_DETECTED) {
10041036
regmap_update_bits(regmap, NAU8821_R71_ANALOG_ADC_1,
@@ -1489,6 +1521,7 @@ static void nau8821_print_device_properties(struct nau8821 *nau8821)
14891521
nau8821->jack_eject_debounce);
14901522
dev_dbg(dev, "dmic-clk-threshold: %d\n",
14911523
nau8821->dmic_clk_threshold);
1524+
dev_dbg(dev, "key_enable: %d\n", nau8821->key_enable);
14921525
}
14931526

14941527
static int nau8821_read_device_properties(struct device *dev,
@@ -1502,6 +1535,8 @@ static int nau8821_read_device_properties(struct device *dev,
15021535
"nuvoton,jkdet-pull-enable");
15031536
nau8821->jkdet_pull_up = device_property_read_bool(dev,
15041537
"nuvoton,jkdet-pull-up");
1538+
nau8821->key_enable = device_property_read_bool(dev,
1539+
"nuvoton,key-enable");
15051540
ret = device_property_read_u32(dev, "nuvoton,jkdet-polarity",
15061541
&nau8821->jkdet_polarity);
15071542
if (ret)

sound/soc/codecs/nau8821.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ struct nau8821 {
525525
int jack_eject_debounce;
526526
int fs;
527527
int dmic_clk_threshold;
528+
int key_enable;
528529
};
529530

530531
int nau8821_enable_jack_detect(struct snd_soc_component *component,

0 commit comments

Comments
 (0)