Adam Thomson | 6d817c0 | 2015-09-29 16:44:01 +0100 | [diff] [blame] | 1 | /* |
| 2 | * da7219-aad.h - DA7322 ASoC AAD Driver |
| 3 | * |
| 4 | * Copyright (c) 2015 Dialog Semiconductor Ltd. |
| 5 | * |
| 6 | * Author: Adam Thomson <Adam.Thomson.Opensource@diasemi.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | */ |
| 13 | |
| 14 | #ifndef __DA7219_AAD_H |
| 15 | #define __DA7219_AAD_H |
| 16 | |
| 17 | #include <linux/timer.h> |
| 18 | #include <sound/soc.h> |
| 19 | #include <sound/jack.h> |
| 20 | #include <sound/da7219-aad.h> |
| 21 | |
| 22 | /* |
| 23 | * Registers |
| 24 | */ |
| 25 | |
| 26 | #define DA7219_ACCDET_STATUS_A 0xC0 |
| 27 | #define DA7219_ACCDET_STATUS_B 0xC1 |
| 28 | #define DA7219_ACCDET_IRQ_EVENT_A 0xC2 |
| 29 | #define DA7219_ACCDET_IRQ_EVENT_B 0xC3 |
| 30 | #define DA7219_ACCDET_IRQ_MASK_A 0xC4 |
| 31 | #define DA7219_ACCDET_IRQ_MASK_B 0xC5 |
| 32 | #define DA7219_ACCDET_CONFIG_1 0xC6 |
| 33 | #define DA7219_ACCDET_CONFIG_2 0xC7 |
| 34 | #define DA7219_ACCDET_CONFIG_3 0xC8 |
| 35 | #define DA7219_ACCDET_CONFIG_4 0xC9 |
| 36 | #define DA7219_ACCDET_CONFIG_5 0xCA |
| 37 | #define DA7219_ACCDET_CONFIG_6 0xCB |
| 38 | #define DA7219_ACCDET_CONFIG_7 0xCC |
| 39 | #define DA7219_ACCDET_CONFIG_8 0xCD |
| 40 | |
| 41 | |
| 42 | /* |
| 43 | * Bit Fields |
| 44 | */ |
| 45 | |
| 46 | /* DA7219_ACCDET_STATUS_A = 0xC0 */ |
| 47 | #define DA7219_JACK_INSERTION_STS_SHIFT 0 |
| 48 | #define DA7219_JACK_INSERTION_STS_MASK (0x1 << 0) |
| 49 | #define DA7219_JACK_TYPE_STS_SHIFT 1 |
| 50 | #define DA7219_JACK_TYPE_STS_MASK (0x1 << 1) |
| 51 | #define DA7219_JACK_PIN_ORDER_STS_SHIFT 2 |
| 52 | #define DA7219_JACK_PIN_ORDER_STS_MASK (0x1 << 2) |
| 53 | #define DA7219_MICBIAS_UP_STS_SHIFT 3 |
| 54 | #define DA7219_MICBIAS_UP_STS_MASK (0x1 << 3) |
| 55 | |
| 56 | /* DA7219_ACCDET_STATUS_B = 0xC1 */ |
| 57 | #define DA7219_BUTTON_TYPE_STS_SHIFT 0 |
| 58 | #define DA7219_BUTTON_TYPE_STS_MASK (0xFF << 0) |
| 59 | |
| 60 | /* DA7219_ACCDET_IRQ_EVENT_A = 0xC2 */ |
| 61 | #define DA7219_E_JACK_INSERTED_SHIFT 0 |
| 62 | #define DA7219_E_JACK_INSERTED_MASK (0x1 << 0) |
| 63 | #define DA7219_E_JACK_REMOVED_SHIFT 1 |
| 64 | #define DA7219_E_JACK_REMOVED_MASK (0x1 << 1) |
| 65 | #define DA7219_E_JACK_DETECT_COMPLETE_SHIFT 2 |
| 66 | #define DA7219_E_JACK_DETECT_COMPLETE_MASK (0x1 << 2) |
| 67 | |
| 68 | /* DA7219_ACCDET_IRQ_EVENT_B = 0xC3 */ |
| 69 | #define DA7219_E_BUTTON_A_PRESSED_SHIFT 0 |
| 70 | #define DA7219_E_BUTTON_A_PRESSED_MASK (0x1 << 0) |
| 71 | #define DA7219_E_BUTTON_B_PRESSED_SHIFT 1 |
| 72 | #define DA7219_E_BUTTON_B_PRESSED_MASK (0x1 << 1) |
| 73 | #define DA7219_E_BUTTON_C_PRESSED_SHIFT 2 |
| 74 | #define DA7219_E_BUTTON_C_PRESSED_MASK (0x1 << 2) |
| 75 | #define DA7219_E_BUTTON_D_PRESSED_SHIFT 3 |
| 76 | #define DA7219_E_BUTTON_D_PRESSED_MASK (0x1 << 3) |
| 77 | #define DA7219_E_BUTTON_D_RELEASED_SHIFT 4 |
| 78 | #define DA7219_E_BUTTON_D_RELEASED_MASK (0x1 << 4) |
| 79 | #define DA7219_E_BUTTON_C_RELEASED_SHIFT 5 |
| 80 | #define DA7219_E_BUTTON_C_RELEASED_MASK (0x1 << 5) |
| 81 | #define DA7219_E_BUTTON_B_RELEASED_SHIFT 6 |
| 82 | #define DA7219_E_BUTTON_B_RELEASED_MASK (0x1 << 6) |
| 83 | #define DA7219_E_BUTTON_A_RELEASED_SHIFT 7 |
| 84 | #define DA7219_E_BUTTON_A_RELEASED_MASK (0x1 << 7) |
| 85 | |
| 86 | /* DA7219_ACCDET_IRQ_MASK_A = 0xC4 */ |
| 87 | #define DA7219_M_JACK_INSERTED_SHIFT 0 |
| 88 | #define DA7219_M_JACK_INSERTED_MASK (0x1 << 0) |
| 89 | #define DA7219_M_JACK_REMOVED_SHIFT 1 |
| 90 | #define DA7219_M_JACK_REMOVED_MASK (0x1 << 1) |
| 91 | #define DA7219_M_JACK_DETECT_COMPLETE_SHIFT 2 |
| 92 | #define DA7219_M_JACK_DETECT_COMPLETE_MASK (0x1 << 2) |
| 93 | |
| 94 | /* DA7219_ACCDET_IRQ_MASK_B = 0xC5 */ |
| 95 | #define DA7219_M_BUTTON_A_PRESSED_SHIFT 0 |
| 96 | #define DA7219_M_BUTTON_A_PRESSED_MASK (0x1 << 0) |
| 97 | #define DA7219_M_BUTTON_B_PRESSED_SHIFT 1 |
| 98 | #define DA7219_M_BUTTON_B_PRESSED_MASK (0x1 << 1) |
| 99 | #define DA7219_M_BUTTON_C_PRESSED_SHIFT 2 |
| 100 | #define DA7219_M_BUTTON_C_PRESSED_MASK (0x1 << 2) |
| 101 | #define DA7219_M_BUTTON_D_PRESSED_SHIFT 3 |
| 102 | #define DA7219_M_BUTTON_D_PRESSED_MASK (0x1 << 3) |
| 103 | #define DA7219_M_BUTTON_D_RELEASED_SHIFT 4 |
| 104 | #define DA7219_M_BUTTON_D_RELEASED_MASK (0x1 << 4) |
| 105 | #define DA7219_M_BUTTON_C_RELEASED_SHIFT 5 |
| 106 | #define DA7219_M_BUTTON_C_RELEASED_MASK (0x1 << 5) |
| 107 | #define DA7219_M_BUTTON_B_RELEASED_SHIFT 6 |
| 108 | #define DA7219_M_BUTTON_B_RELEASED_MASK (0x1 << 6) |
| 109 | #define DA7219_M_BUTTON_A_RELEASED_SHIFT 7 |
| 110 | #define DA7219_M_BUTTON_A_RELEASED_MASK (0x1 << 7) |
| 111 | |
| 112 | /* DA7219_ACCDET_CONFIG_1 = 0xC6 */ |
| 113 | #define DA7219_ACCDET_EN_SHIFT 0 |
| 114 | #define DA7219_ACCDET_EN_MASK (0x1 << 0) |
| 115 | #define DA7219_BUTTON_CONFIG_SHIFT 1 |
| 116 | #define DA7219_BUTTON_CONFIG_MASK (0x7 << 1) |
| 117 | #define DA7219_MIC_DET_THRESH_SHIFT 4 |
| 118 | #define DA7219_MIC_DET_THRESH_MASK (0x3 << 4) |
| 119 | #define DA7219_JACK_TYPE_DET_EN_SHIFT 6 |
| 120 | #define DA7219_JACK_TYPE_DET_EN_MASK (0x1 << 6) |
| 121 | #define DA7219_PIN_ORDER_DET_EN_SHIFT 7 |
| 122 | #define DA7219_PIN_ORDER_DET_EN_MASK (0x1 << 7) |
| 123 | |
| 124 | /* DA7219_ACCDET_CONFIG_2 = 0xC7 */ |
| 125 | #define DA7219_ACCDET_PAUSE_SHIFT 0 |
| 126 | #define DA7219_ACCDET_PAUSE_MASK (0x1 << 0) |
| 127 | #define DA7219_JACKDET_DEBOUNCE_SHIFT 1 |
| 128 | #define DA7219_JACKDET_DEBOUNCE_MASK (0x7 << 1) |
| 129 | #define DA7219_JACK_DETECT_RATE_SHIFT 4 |
| 130 | #define DA7219_JACK_DETECT_RATE_MASK (0x3 << 4) |
| 131 | #define DA7219_JACKDET_REM_DEB_SHIFT 6 |
| 132 | #define DA7219_JACKDET_REM_DEB_MASK (0x3 << 6) |
| 133 | |
| 134 | /* DA7219_ACCDET_CONFIG_3 = 0xC8 */ |
| 135 | #define DA7219_A_D_BUTTON_THRESH_SHIFT 0 |
| 136 | #define DA7219_A_D_BUTTON_THRESH_MASK (0xFF << 0) |
| 137 | |
| 138 | /* DA7219_ACCDET_CONFIG_4 = 0xC9 */ |
| 139 | #define DA7219_D_B_BUTTON_THRESH_SHIFT 0 |
| 140 | #define DA7219_D_B_BUTTON_THRESH_MASK (0xFF << 0) |
| 141 | |
| 142 | /* DA7219_ACCDET_CONFIG_5 = 0xCA */ |
| 143 | #define DA7219_B_C_BUTTON_THRESH_SHIFT 0 |
| 144 | #define DA7219_B_C_BUTTON_THRESH_MASK (0xFF << 0) |
| 145 | |
| 146 | /* DA7219_ACCDET_CONFIG_6 = 0xCB */ |
| 147 | #define DA7219_C_MIC_BUTTON_THRESH_SHIFT 0 |
| 148 | #define DA7219_C_MIC_BUTTON_THRESH_MASK (0xFF << 0) |
| 149 | |
| 150 | /* DA7219_ACCDET_CONFIG_7 = 0xCC */ |
| 151 | #define DA7219_BUTTON_AVERAGE_SHIFT 0 |
| 152 | #define DA7219_BUTTON_AVERAGE_MASK (0x3 << 0) |
| 153 | #define DA7219_ADC_1_BIT_REPEAT_SHIFT 2 |
| 154 | #define DA7219_ADC_1_BIT_REPEAT_MASK (0x3 << 2) |
| 155 | #define DA7219_PIN_ORDER_FORCE_SHIFT 4 |
| 156 | #define DA7219_PIN_ORDER_FORCE_MASK (0x1 << 4) |
| 157 | #define DA7219_JACK_TYPE_FORCE_SHIFT 5 |
| 158 | #define DA7219_JACK_TYPE_FORCE_MASK (0x1 << 5) |
| 159 | |
| 160 | /* DA7219_ACCDET_CONFIG_8 = 0xCD */ |
| 161 | #define DA7219_HPTEST_EN_SHIFT 0 |
| 162 | #define DA7219_HPTEST_EN_MASK (0x1 << 0) |
| 163 | #define DA7219_HPTEST_RES_SEL_SHIFT 1 |
| 164 | #define DA7219_HPTEST_RES_SEL_MASK (0x3 << 1) |
| 165 | #define DA7219_HPTEST_RES_SEL_1KOHMS (0x0 << 1) |
| 166 | #define DA7219_HPTEST_COMP_SHIFT 4 |
| 167 | #define DA7219_HPTEST_COMP_MASK (0x1 << 4) |
| 168 | |
| 169 | |
| 170 | #define DA7219_AAD_MAX_BUTTONS 4 |
| 171 | #define DA7219_AAD_REPORT_ALL_MASK (SND_JACK_MECHANICAL | \ |
| 172 | SND_JACK_HEADSET | SND_JACK_LINEOUT | \ |
| 173 | SND_JACK_BTN_0 | SND_JACK_BTN_1 | \ |
| 174 | SND_JACK_BTN_2 | SND_JACK_BTN_3) |
| 175 | |
| 176 | #define DA7219_AAD_MICBIAS_CHK_DELAY 10 |
| 177 | #define DA7219_AAD_MICBIAS_CHK_RETRIES 5 |
| 178 | |
Adam Thomson | 6a0b87c | 2016-09-12 16:46:50 +0100 | [diff] [blame] | 179 | #define DA7219_AAD_HPTEST_RAMP_FREQ 0x28 |
| 180 | #define DA7219_AAD_HPTEST_RAMP_FREQ_INT_OSC 0x4D |
| 181 | #define DA7219_AAD_HPTEST_PERIOD 65 |
| 182 | #define DA7219_AAD_HPTEST_INT_OSC_PATH_DELAY 20 |
Adam Thomson | 6d817c0 | 2015-09-29 16:44:01 +0100 | [diff] [blame] | 183 | |
| 184 | enum da7219_aad_event_regs { |
| 185 | DA7219_AAD_IRQ_REG_A = 0, |
| 186 | DA7219_AAD_IRQ_REG_B, |
| 187 | DA7219_AAD_IRQ_REG_MAX, |
| 188 | }; |
| 189 | |
| 190 | /* Private data */ |
| 191 | struct da7219_aad_priv { |
| 192 | struct snd_soc_codec *codec; |
| 193 | int irq; |
| 194 | |
| 195 | u8 micbias_pulse_lvl; |
| 196 | u32 micbias_pulse_time; |
| 197 | |
| 198 | u8 btn_cfg; |
| 199 | |
| 200 | struct work_struct btn_det_work; |
| 201 | struct work_struct hptest_work; |
| 202 | |
| 203 | struct snd_soc_jack *jack; |
Adam Thomson | bb0c35f | 2016-09-26 14:29:21 +0100 | [diff] [blame] | 204 | bool micbias_resume_enable; |
Adam Thomson | 6d817c0 | 2015-09-29 16:44:01 +0100 | [diff] [blame] | 205 | bool jack_inserted; |
| 206 | }; |
| 207 | |
| 208 | /* AAD control */ |
| 209 | void da7219_aad_jack_det(struct snd_soc_codec *codec, struct snd_soc_jack *jack); |
| 210 | |
Adam Thomson | bb0c35f | 2016-09-26 14:29:21 +0100 | [diff] [blame] | 211 | /* Suspend/Resume */ |
| 212 | void da7219_aad_suspend(struct snd_soc_codec *codec); |
| 213 | void da7219_aad_resume(struct snd_soc_codec *codec); |
| 214 | |
Adam Thomson | 6d817c0 | 2015-09-29 16:44:01 +0100 | [diff] [blame] | 215 | /* Init/Exit */ |
| 216 | int da7219_aad_init(struct snd_soc_codec *codec); |
| 217 | void da7219_aad_exit(struct snd_soc_codec *codec); |
| 218 | |
| 219 | #endif /* __DA7219_AAD_H */ |