12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 26d817c0eSAdam Thomson /* 36d817c0eSAdam Thomson * da7219-aad.h - DA7322 ASoC AAD Driver 46d817c0eSAdam Thomson * 56d817c0eSAdam Thomson * Copyright (c) 2015 Dialog Semiconductor Ltd. 66d817c0eSAdam Thomson * 76d817c0eSAdam Thomson * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com> 86d817c0eSAdam Thomson */ 96d817c0eSAdam Thomson 106d817c0eSAdam Thomson #ifndef __DA7219_AAD_H 116d817c0eSAdam Thomson #define __DA7219_AAD_H 126d817c0eSAdam Thomson 136d817c0eSAdam Thomson #include <linux/timer.h> 147fde88edSDavid Rau #include <linux/mutex.h> 156d817c0eSAdam Thomson #include <sound/soc.h> 166d817c0eSAdam Thomson #include <sound/jack.h> 176d817c0eSAdam Thomson #include <sound/da7219-aad.h> 186d817c0eSAdam Thomson 196d817c0eSAdam Thomson /* 206d817c0eSAdam Thomson * Registers 216d817c0eSAdam Thomson */ 226d817c0eSAdam Thomson 236d817c0eSAdam Thomson #define DA7219_ACCDET_STATUS_A 0xC0 246d817c0eSAdam Thomson #define DA7219_ACCDET_STATUS_B 0xC1 256d817c0eSAdam Thomson #define DA7219_ACCDET_IRQ_EVENT_A 0xC2 266d817c0eSAdam Thomson #define DA7219_ACCDET_IRQ_EVENT_B 0xC3 276d817c0eSAdam Thomson #define DA7219_ACCDET_IRQ_MASK_A 0xC4 286d817c0eSAdam Thomson #define DA7219_ACCDET_IRQ_MASK_B 0xC5 296d817c0eSAdam Thomson #define DA7219_ACCDET_CONFIG_1 0xC6 306d817c0eSAdam Thomson #define DA7219_ACCDET_CONFIG_2 0xC7 316d817c0eSAdam Thomson #define DA7219_ACCDET_CONFIG_3 0xC8 326d817c0eSAdam Thomson #define DA7219_ACCDET_CONFIG_4 0xC9 336d817c0eSAdam Thomson #define DA7219_ACCDET_CONFIG_5 0xCA 346d817c0eSAdam Thomson #define DA7219_ACCDET_CONFIG_6 0xCB 356d817c0eSAdam Thomson #define DA7219_ACCDET_CONFIG_7 0xCC 366d817c0eSAdam Thomson #define DA7219_ACCDET_CONFIG_8 0xCD 376d817c0eSAdam Thomson 386d817c0eSAdam Thomson 396d817c0eSAdam Thomson /* 406d817c0eSAdam Thomson * Bit Fields 416d817c0eSAdam Thomson */ 426d817c0eSAdam Thomson 436d817c0eSAdam Thomson /* DA7219_ACCDET_STATUS_A = 0xC0 */ 446d817c0eSAdam Thomson #define DA7219_JACK_INSERTION_STS_SHIFT 0 456d817c0eSAdam Thomson #define DA7219_JACK_INSERTION_STS_MASK (0x1 << 0) 466d817c0eSAdam Thomson #define DA7219_JACK_TYPE_STS_SHIFT 1 476d817c0eSAdam Thomson #define DA7219_JACK_TYPE_STS_MASK (0x1 << 1) 486d817c0eSAdam Thomson #define DA7219_JACK_PIN_ORDER_STS_SHIFT 2 496d817c0eSAdam Thomson #define DA7219_JACK_PIN_ORDER_STS_MASK (0x1 << 2) 506d817c0eSAdam Thomson #define DA7219_MICBIAS_UP_STS_SHIFT 3 516d817c0eSAdam Thomson #define DA7219_MICBIAS_UP_STS_MASK (0x1 << 3) 526d817c0eSAdam Thomson 536d817c0eSAdam Thomson /* DA7219_ACCDET_STATUS_B = 0xC1 */ 546d817c0eSAdam Thomson #define DA7219_BUTTON_TYPE_STS_SHIFT 0 556d817c0eSAdam Thomson #define DA7219_BUTTON_TYPE_STS_MASK (0xFF << 0) 566d817c0eSAdam Thomson 576d817c0eSAdam Thomson /* DA7219_ACCDET_IRQ_EVENT_A = 0xC2 */ 586d817c0eSAdam Thomson #define DA7219_E_JACK_INSERTED_SHIFT 0 596d817c0eSAdam Thomson #define DA7219_E_JACK_INSERTED_MASK (0x1 << 0) 606d817c0eSAdam Thomson #define DA7219_E_JACK_REMOVED_SHIFT 1 616d817c0eSAdam Thomson #define DA7219_E_JACK_REMOVED_MASK (0x1 << 1) 626d817c0eSAdam Thomson #define DA7219_E_JACK_DETECT_COMPLETE_SHIFT 2 636d817c0eSAdam Thomson #define DA7219_E_JACK_DETECT_COMPLETE_MASK (0x1 << 2) 646d817c0eSAdam Thomson 656d817c0eSAdam Thomson /* DA7219_ACCDET_IRQ_EVENT_B = 0xC3 */ 666d817c0eSAdam Thomson #define DA7219_E_BUTTON_A_PRESSED_SHIFT 0 676d817c0eSAdam Thomson #define DA7219_E_BUTTON_A_PRESSED_MASK (0x1 << 0) 686d817c0eSAdam Thomson #define DA7219_E_BUTTON_B_PRESSED_SHIFT 1 696d817c0eSAdam Thomson #define DA7219_E_BUTTON_B_PRESSED_MASK (0x1 << 1) 706d817c0eSAdam Thomson #define DA7219_E_BUTTON_C_PRESSED_SHIFT 2 716d817c0eSAdam Thomson #define DA7219_E_BUTTON_C_PRESSED_MASK (0x1 << 2) 726d817c0eSAdam Thomson #define DA7219_E_BUTTON_D_PRESSED_SHIFT 3 736d817c0eSAdam Thomson #define DA7219_E_BUTTON_D_PRESSED_MASK (0x1 << 3) 746d817c0eSAdam Thomson #define DA7219_E_BUTTON_D_RELEASED_SHIFT 4 756d817c0eSAdam Thomson #define DA7219_E_BUTTON_D_RELEASED_MASK (0x1 << 4) 766d817c0eSAdam Thomson #define DA7219_E_BUTTON_C_RELEASED_SHIFT 5 776d817c0eSAdam Thomson #define DA7219_E_BUTTON_C_RELEASED_MASK (0x1 << 5) 786d817c0eSAdam Thomson #define DA7219_E_BUTTON_B_RELEASED_SHIFT 6 796d817c0eSAdam Thomson #define DA7219_E_BUTTON_B_RELEASED_MASK (0x1 << 6) 806d817c0eSAdam Thomson #define DA7219_E_BUTTON_A_RELEASED_SHIFT 7 816d817c0eSAdam Thomson #define DA7219_E_BUTTON_A_RELEASED_MASK (0x1 << 7) 826d817c0eSAdam Thomson 836d817c0eSAdam Thomson /* DA7219_ACCDET_IRQ_MASK_A = 0xC4 */ 846d817c0eSAdam Thomson #define DA7219_M_JACK_INSERTED_SHIFT 0 856d817c0eSAdam Thomson #define DA7219_M_JACK_INSERTED_MASK (0x1 << 0) 866d817c0eSAdam Thomson #define DA7219_M_JACK_REMOVED_SHIFT 1 876d817c0eSAdam Thomson #define DA7219_M_JACK_REMOVED_MASK (0x1 << 1) 886d817c0eSAdam Thomson #define DA7219_M_JACK_DETECT_COMPLETE_SHIFT 2 896d817c0eSAdam Thomson #define DA7219_M_JACK_DETECT_COMPLETE_MASK (0x1 << 2) 906d817c0eSAdam Thomson 916d817c0eSAdam Thomson /* DA7219_ACCDET_IRQ_MASK_B = 0xC5 */ 926d817c0eSAdam Thomson #define DA7219_M_BUTTON_A_PRESSED_SHIFT 0 936d817c0eSAdam Thomson #define DA7219_M_BUTTON_A_PRESSED_MASK (0x1 << 0) 946d817c0eSAdam Thomson #define DA7219_M_BUTTON_B_PRESSED_SHIFT 1 956d817c0eSAdam Thomson #define DA7219_M_BUTTON_B_PRESSED_MASK (0x1 << 1) 966d817c0eSAdam Thomson #define DA7219_M_BUTTON_C_PRESSED_SHIFT 2 976d817c0eSAdam Thomson #define DA7219_M_BUTTON_C_PRESSED_MASK (0x1 << 2) 986d817c0eSAdam Thomson #define DA7219_M_BUTTON_D_PRESSED_SHIFT 3 996d817c0eSAdam Thomson #define DA7219_M_BUTTON_D_PRESSED_MASK (0x1 << 3) 1006d817c0eSAdam Thomson #define DA7219_M_BUTTON_D_RELEASED_SHIFT 4 1016d817c0eSAdam Thomson #define DA7219_M_BUTTON_D_RELEASED_MASK (0x1 << 4) 1026d817c0eSAdam Thomson #define DA7219_M_BUTTON_C_RELEASED_SHIFT 5 1036d817c0eSAdam Thomson #define DA7219_M_BUTTON_C_RELEASED_MASK (0x1 << 5) 1046d817c0eSAdam Thomson #define DA7219_M_BUTTON_B_RELEASED_SHIFT 6 1056d817c0eSAdam Thomson #define DA7219_M_BUTTON_B_RELEASED_MASK (0x1 << 6) 1066d817c0eSAdam Thomson #define DA7219_M_BUTTON_A_RELEASED_SHIFT 7 1076d817c0eSAdam Thomson #define DA7219_M_BUTTON_A_RELEASED_MASK (0x1 << 7) 1086d817c0eSAdam Thomson 1096d817c0eSAdam Thomson /* DA7219_ACCDET_CONFIG_1 = 0xC6 */ 1106d817c0eSAdam Thomson #define DA7219_ACCDET_EN_SHIFT 0 1116d817c0eSAdam Thomson #define DA7219_ACCDET_EN_MASK (0x1 << 0) 1126d817c0eSAdam Thomson #define DA7219_BUTTON_CONFIG_SHIFT 1 1136d817c0eSAdam Thomson #define DA7219_BUTTON_CONFIG_MASK (0x7 << 1) 1146d817c0eSAdam Thomson #define DA7219_MIC_DET_THRESH_SHIFT 4 1156d817c0eSAdam Thomson #define DA7219_MIC_DET_THRESH_MASK (0x3 << 4) 1166d817c0eSAdam Thomson #define DA7219_JACK_TYPE_DET_EN_SHIFT 6 1176d817c0eSAdam Thomson #define DA7219_JACK_TYPE_DET_EN_MASK (0x1 << 6) 1186d817c0eSAdam Thomson #define DA7219_PIN_ORDER_DET_EN_SHIFT 7 1196d817c0eSAdam Thomson #define DA7219_PIN_ORDER_DET_EN_MASK (0x1 << 7) 1206d817c0eSAdam Thomson 1216d817c0eSAdam Thomson /* DA7219_ACCDET_CONFIG_2 = 0xC7 */ 1226d817c0eSAdam Thomson #define DA7219_ACCDET_PAUSE_SHIFT 0 1236d817c0eSAdam Thomson #define DA7219_ACCDET_PAUSE_MASK (0x1 << 0) 1246d817c0eSAdam Thomson #define DA7219_JACKDET_DEBOUNCE_SHIFT 1 1256d817c0eSAdam Thomson #define DA7219_JACKDET_DEBOUNCE_MASK (0x7 << 1) 1266d817c0eSAdam Thomson #define DA7219_JACK_DETECT_RATE_SHIFT 4 1276d817c0eSAdam Thomson #define DA7219_JACK_DETECT_RATE_MASK (0x3 << 4) 1286d817c0eSAdam Thomson #define DA7219_JACKDET_REM_DEB_SHIFT 6 1296d817c0eSAdam Thomson #define DA7219_JACKDET_REM_DEB_MASK (0x3 << 6) 1306d817c0eSAdam Thomson 1316d817c0eSAdam Thomson /* DA7219_ACCDET_CONFIG_3 = 0xC8 */ 1326d817c0eSAdam Thomson #define DA7219_A_D_BUTTON_THRESH_SHIFT 0 1336d817c0eSAdam Thomson #define DA7219_A_D_BUTTON_THRESH_MASK (0xFF << 0) 1346d817c0eSAdam Thomson 1356d817c0eSAdam Thomson /* DA7219_ACCDET_CONFIG_4 = 0xC9 */ 1366d817c0eSAdam Thomson #define DA7219_D_B_BUTTON_THRESH_SHIFT 0 1376d817c0eSAdam Thomson #define DA7219_D_B_BUTTON_THRESH_MASK (0xFF << 0) 1386d817c0eSAdam Thomson 1396d817c0eSAdam Thomson /* DA7219_ACCDET_CONFIG_5 = 0xCA */ 1406d817c0eSAdam Thomson #define DA7219_B_C_BUTTON_THRESH_SHIFT 0 1416d817c0eSAdam Thomson #define DA7219_B_C_BUTTON_THRESH_MASK (0xFF << 0) 1426d817c0eSAdam Thomson 1436d817c0eSAdam Thomson /* DA7219_ACCDET_CONFIG_6 = 0xCB */ 1446d817c0eSAdam Thomson #define DA7219_C_MIC_BUTTON_THRESH_SHIFT 0 1456d817c0eSAdam Thomson #define DA7219_C_MIC_BUTTON_THRESH_MASK (0xFF << 0) 1466d817c0eSAdam Thomson 1476d817c0eSAdam Thomson /* DA7219_ACCDET_CONFIG_7 = 0xCC */ 1486d817c0eSAdam Thomson #define DA7219_BUTTON_AVERAGE_SHIFT 0 1496d817c0eSAdam Thomson #define DA7219_BUTTON_AVERAGE_MASK (0x3 << 0) 1506d817c0eSAdam Thomson #define DA7219_ADC_1_BIT_REPEAT_SHIFT 2 1516d817c0eSAdam Thomson #define DA7219_ADC_1_BIT_REPEAT_MASK (0x3 << 2) 1526d817c0eSAdam Thomson #define DA7219_PIN_ORDER_FORCE_SHIFT 4 1536d817c0eSAdam Thomson #define DA7219_PIN_ORDER_FORCE_MASK (0x1 << 4) 1546d817c0eSAdam Thomson #define DA7219_JACK_TYPE_FORCE_SHIFT 5 1556d817c0eSAdam Thomson #define DA7219_JACK_TYPE_FORCE_MASK (0x1 << 5) 1566d817c0eSAdam Thomson 1576d817c0eSAdam Thomson /* DA7219_ACCDET_CONFIG_8 = 0xCD */ 1586d817c0eSAdam Thomson #define DA7219_HPTEST_EN_SHIFT 0 1596d817c0eSAdam Thomson #define DA7219_HPTEST_EN_MASK (0x1 << 0) 1606d817c0eSAdam Thomson #define DA7219_HPTEST_RES_SEL_SHIFT 1 1616d817c0eSAdam Thomson #define DA7219_HPTEST_RES_SEL_MASK (0x3 << 1) 1626d817c0eSAdam Thomson #define DA7219_HPTEST_RES_SEL_1KOHMS (0x0 << 1) 1636d817c0eSAdam Thomson #define DA7219_HPTEST_COMP_SHIFT 4 1646d817c0eSAdam Thomson #define DA7219_HPTEST_COMP_MASK (0x1 << 4) 1656d817c0eSAdam Thomson 1666d817c0eSAdam Thomson 1676d817c0eSAdam Thomson #define DA7219_AAD_MAX_BUTTONS 4 1686d817c0eSAdam Thomson #define DA7219_AAD_REPORT_ALL_MASK (SND_JACK_MECHANICAL | \ 1696d817c0eSAdam Thomson SND_JACK_HEADSET | SND_JACK_LINEOUT | \ 1706d817c0eSAdam Thomson SND_JACK_BTN_0 | SND_JACK_BTN_1 | \ 1716d817c0eSAdam Thomson SND_JACK_BTN_2 | SND_JACK_BTN_3) 1726d817c0eSAdam Thomson 1736d817c0eSAdam Thomson #define DA7219_AAD_MICBIAS_CHK_DELAY 10 1746d817c0eSAdam Thomson #define DA7219_AAD_MICBIAS_CHK_RETRIES 5 1756d817c0eSAdam Thomson 1766d817c0eSAdam Thomson #define DA7219_AAD_HPTEST_RAMP_FREQ 0x28 1776a0b87c6SAdam Thomson #define DA7219_AAD_HPTEST_RAMP_FREQ_INT_OSC 0x4D 1786d817c0eSAdam Thomson #define DA7219_AAD_HPTEST_PERIOD 65 1796a0b87c6SAdam Thomson #define DA7219_AAD_HPTEST_INT_OSC_PATH_DELAY 20 1806d817c0eSAdam Thomson 1816d817c0eSAdam Thomson enum da7219_aad_event_regs { 1826d817c0eSAdam Thomson DA7219_AAD_IRQ_REG_A = 0, 1836d817c0eSAdam Thomson DA7219_AAD_IRQ_REG_B, 1846d817c0eSAdam Thomson DA7219_AAD_IRQ_REG_MAX, 1856d817c0eSAdam Thomson }; 1866d817c0eSAdam Thomson 1876d817c0eSAdam Thomson /* Private data */ 1886d817c0eSAdam Thomson struct da7219_aad_priv { 18945101122SKuninori Morimoto struct snd_soc_component *component; 1906d817c0eSAdam Thomson int irq; 191969357ecSDavid Rau int gnd_switch_delay; 1926d817c0eSAdam Thomson 1936d817c0eSAdam Thomson u8 micbias_pulse_lvl; 1946d817c0eSAdam Thomson u32 micbias_pulse_time; 1956d817c0eSAdam Thomson 1966d817c0eSAdam Thomson u8 btn_cfg; 1976d817c0eSAdam Thomson 1986d817c0eSAdam Thomson struct work_struct btn_det_work; 1996d817c0eSAdam Thomson struct work_struct hptest_work; 200*2c172778SDavid Rau struct delayed_work jack_det_work; 201*2c172778SDavid Rau struct workqueue_struct *aad_wq; 2026d817c0eSAdam Thomson 2036d817c0eSAdam Thomson struct snd_soc_jack *jack; 204bb0c35fcSAdam Thomson bool micbias_resume_enable; 2056d817c0eSAdam Thomson bool jack_inserted; 2066d817c0eSAdam Thomson }; 2076d817c0eSAdam Thomson 2086d817c0eSAdam Thomson /* AAD control */ 20945101122SKuninori Morimoto void da7219_aad_jack_det(struct snd_soc_component *component, struct snd_soc_jack *jack); 2106d817c0eSAdam Thomson 211bb0c35fcSAdam Thomson /* Suspend/Resume */ 21245101122SKuninori Morimoto void da7219_aad_suspend(struct snd_soc_component *component); 21345101122SKuninori Morimoto void da7219_aad_resume(struct snd_soc_component *component); 214bb0c35fcSAdam Thomson 2156d817c0eSAdam Thomson /* Init/Exit */ 21645101122SKuninori Morimoto int da7219_aad_init(struct snd_soc_component *component); 21745101122SKuninori Morimoto void da7219_aad_exit(struct snd_soc_component *component); 2186d817c0eSAdam Thomson 21921f279f3SAdam Thomson /* I2C Probe */ 22021f279f3SAdam Thomson int da7219_aad_probe(struct i2c_client *i2c); 22121f279f3SAdam Thomson 2226d817c0eSAdam Thomson #endif /* __DA7219_AAD_H */ 223