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