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
916932static 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
14941527static 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 )
0 commit comments