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