Banajit Goswami | de8271c | 2017-01-18 00:28:59 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #ifndef WCD9XXX_CODEC_COMMON |
| 14 | |
| 15 | #define WCD9XXX_CODEC_COMMON |
| 16 | |
| 17 | #include "wcd9xxx-resmgr.h" |
| 18 | |
| 19 | #define WCD9XXX_CLSH_REQ_ENABLE true |
| 20 | #define WCD9XXX_CLSH_REQ_DISABLE false |
| 21 | |
| 22 | #define WCD9XXX_CLSH_EVENT_PRE_DAC 0x01 |
| 23 | #define WCD9XXX_CLSH_EVENT_POST_PA 0x02 |
| 24 | |
| 25 | /* Basic states for Class H state machine. |
| 26 | * represented as a bit mask within a u8 data type |
| 27 | * bit 0: EAR mode |
| 28 | * bit 1: HPH Left mode |
| 29 | * bit 2: HPH Right mode |
| 30 | * bit 3: Lineout mode |
| 31 | * bit 4: Ultrasound mode |
| 32 | */ |
| 33 | #define WCD9XXX_CLSH_STATE_IDLE 0x00 |
| 34 | #define WCD9XXX_CLSH_STATE_EAR (0x01 << 0) |
| 35 | #define WCD9XXX_CLSH_STATE_HPHL (0x01 << 1) |
| 36 | #define WCD9XXX_CLSH_STATE_HPHR (0x01 << 2) |
| 37 | #define WCD9XXX_CLSH_STATE_LO (0x01 << 3) |
| 38 | #define NUM_CLSH_STATES (0x01 << 4) |
| 39 | |
| 40 | #define WCD9XXX_CLSAB_STATE_IDLE 0x00 |
| 41 | #define WCD9XXX_CLSAB_STATE_HPHL (0x01 << 1) |
| 42 | #define WCD9XXX_CLSAB_STATE_HPHR (0x01 << 2) |
| 43 | |
| 44 | #define WCD9XXX_CLSAB_REQ_ENABLE true |
| 45 | #define WCD9XXX_CLSAB_REQ_DISABLE false |
| 46 | |
| 47 | #define WCD9XXX_NON_UHQA_MODE 0 |
| 48 | |
| 49 | #define WCD9XXX_DMIC_SAMPLE_RATE_DIV_2 0x0 |
| 50 | #define WCD9XXX_DMIC_SAMPLE_RATE_DIV_3 0x1 |
| 51 | #define WCD9XXX_DMIC_SAMPLE_RATE_DIV_4 0x2 |
| 52 | |
| 53 | #define WCD9XXX_DMIC_B1_CTL_DIV_2 0x00 |
| 54 | #define WCD9XXX_DMIC_B1_CTL_DIV_3 0x22 |
| 55 | #define WCD9XXX_DMIC_B1_CTL_DIV_4 0x44 |
| 56 | |
| 57 | #define WCD9XXX_DMIC_B2_CTL_DIV_2 0x00 |
| 58 | #define WCD9XXX_DMIC_B2_CTL_DIV_3 0x02 |
| 59 | #define WCD9XXX_DMIC_B2_CTL_DIV_4 0x04 |
| 60 | |
| 61 | #define WCD9XXX_ANC_DMIC_X2_ON 0x1 |
| 62 | #define WCD9XXX_ANC_DMIC_X2_OFF 0x0 |
| 63 | |
| 64 | /* Derived State: Bits 1 and 2 should be set for Headphone stereo */ |
| 65 | #define WCD9XXX_CLSH_STATE_HPH_ST (WCD9XXX_CLSH_STATE_HPHL | \ |
| 66 | WCD9XXX_CLSH_STATE_HPHR) |
| 67 | |
| 68 | #define WCD9XXX_CLSH_STATE_HPHL_EAR (WCD9XXX_CLSH_STATE_HPHL | \ |
| 69 | WCD9XXX_CLSH_STATE_EAR) |
| 70 | #define WCD9XXX_CLSH_STATE_HPHR_EAR (WCD9XXX_CLSH_STATE_HPHR | \ |
| 71 | WCD9XXX_CLSH_STATE_EAR) |
| 72 | |
| 73 | #define WCD9XXX_CLSH_STATE_HPH_ST_EAR (WCD9XXX_CLSH_STATE_HPH_ST | \ |
| 74 | WCD9XXX_CLSH_STATE_EAR) |
| 75 | |
| 76 | #define WCD9XXX_CLSH_STATE_HPHL_LO (WCD9XXX_CLSH_STATE_HPHL | \ |
| 77 | WCD9XXX_CLSH_STATE_LO) |
| 78 | #define WCD9XXX_CLSH_STATE_HPHR_LO (WCD9XXX_CLSH_STATE_HPHR | \ |
| 79 | WCD9XXX_CLSH_STATE_LO) |
| 80 | |
| 81 | #define WCD9XXX_CLSH_STATE_HPH_ST_LO (WCD9XXX_CLSH_STATE_HPH_ST | \ |
| 82 | WCD9XXX_CLSH_STATE_LO) |
| 83 | |
| 84 | #define WCD9XXX_CLSH_STATE_EAR_LO (WCD9XXX_CLSH_STATE_EAR | \ |
| 85 | WCD9XXX_CLSH_STATE_LO) |
| 86 | |
| 87 | #define WCD9XXX_CLSH_STATE_HPHL_EAR_LO (WCD9XXX_CLSH_STATE_HPHL | \ |
| 88 | WCD9XXX_CLSH_STATE_EAR | \ |
| 89 | WCD9XXX_CLSH_STATE_LO) |
| 90 | #define WCD9XXX_CLSH_STATE_HPHR_EAR_LO (WCD9XXX_CLSH_STATE_HPHR | \ |
| 91 | WCD9XXX_CLSH_STATE_EAR | \ |
| 92 | WCD9XXX_CLSH_STATE_LO) |
| 93 | #define WCD9XXX_CLSH_STATE_HPH_ST_EAR_LO (WCD9XXX_CLSH_STATE_HPH_ST | \ |
| 94 | WCD9XXX_CLSH_STATE_EAR | \ |
| 95 | WCD9XXX_CLSH_STATE_LO) |
| 96 | |
| 97 | struct wcd9xxx_reg_mask_val { |
| 98 | u16 reg; |
| 99 | u8 mask; |
| 100 | u8 val; |
| 101 | }; |
| 102 | |
| 103 | enum ncp_fclk_level { |
| 104 | NCP_FCLK_LEVEL_8, |
| 105 | NCP_FCLK_LEVEL_5, |
| 106 | NCP_FCLK_LEVEL_MAX, |
| 107 | }; |
| 108 | |
| 109 | /* Class H data that the codec driver will maintain */ |
| 110 | struct wcd9xxx_clsh_cdc_data { |
| 111 | u8 state; |
| 112 | int buck_mv; |
| 113 | bool is_dynamic_vdd_cp; |
| 114 | int clsh_users; |
| 115 | int buck_users; |
| 116 | int ncp_users[NCP_FCLK_LEVEL_MAX]; |
| 117 | struct wcd9xxx_resmgr *resmgr; |
| 118 | }; |
| 119 | |
| 120 | struct wcd9xxx_anc_header { |
| 121 | u32 reserved[3]; |
| 122 | u32 num_anc_slots; |
| 123 | }; |
| 124 | |
| 125 | enum wcd9xxx_buck_volt { |
| 126 | WCD9XXX_CDC_BUCK_UNSUPPORTED = 0, |
| 127 | WCD9XXX_CDC_BUCK_MV_1P8 = 1800000, |
| 128 | WCD9XXX_CDC_BUCK_MV_2P15 = 2150000, |
| 129 | }; |
| 130 | |
| 131 | struct mad_audio_header { |
| 132 | u32 reserved[3]; |
| 133 | u32 num_reg_cfg; |
| 134 | }; |
| 135 | |
| 136 | struct mad_microphone_info { |
| 137 | uint8_t input_microphone; |
| 138 | uint8_t cycle_time; |
| 139 | uint8_t settle_time; |
| 140 | uint8_t padding; |
| 141 | } __packed; |
| 142 | |
| 143 | struct mad_micbias_info { |
| 144 | uint8_t micbias; |
| 145 | uint8_t k_factor; |
| 146 | uint8_t external_bypass_capacitor; |
| 147 | uint8_t internal_biasing; |
| 148 | uint8_t cfilter; |
| 149 | uint8_t padding[3]; |
| 150 | } __packed; |
| 151 | |
| 152 | struct mad_rms_audio_beacon_info { |
| 153 | uint8_t rms_omit_samples; |
| 154 | uint8_t rms_comp_time; |
| 155 | uint8_t detection_mechanism; |
| 156 | uint8_t rms_diff_threshold; |
| 157 | uint8_t rms_threshold_lsb; |
| 158 | uint8_t rms_threshold_msb; |
| 159 | uint8_t padding[2]; |
| 160 | uint8_t iir_coefficients[36]; |
| 161 | } __packed; |
| 162 | |
| 163 | struct mad_rms_ultrasound_info { |
| 164 | uint8_t rms_comp_time; |
| 165 | uint8_t detection_mechanism; |
| 166 | uint8_t rms_diff_threshold; |
| 167 | uint8_t rms_threshold_lsb; |
| 168 | uint8_t rms_threshold_msb; |
| 169 | uint8_t padding[3]; |
| 170 | uint8_t iir_coefficients[36]; |
| 171 | } __packed; |
| 172 | |
| 173 | struct mad_audio_cal { |
| 174 | uint32_t version; |
| 175 | struct mad_microphone_info microphone_info; |
| 176 | struct mad_micbias_info micbias_info; |
| 177 | struct mad_rms_audio_beacon_info audio_info; |
| 178 | struct mad_rms_audio_beacon_info beacon_info; |
| 179 | struct mad_rms_ultrasound_info ultrasound_info; |
| 180 | } __packed; |
| 181 | |
| 182 | extern void wcd9xxx_clsh_fsm(struct snd_soc_codec *codec, |
| 183 | struct wcd9xxx_clsh_cdc_data *cdc_clsh_d, |
| 184 | u8 req_state, bool req_type, u8 clsh_event); |
| 185 | |
| 186 | extern void wcd9xxx_enable_high_perf_mode(struct snd_soc_codec *codec, |
| 187 | struct wcd9xxx_clsh_cdc_data *clsh_d, |
| 188 | u8 uhqa_mode, u8 req_state, bool req_type); |
| 189 | |
| 190 | extern void wcd9xxx_clsh_init(struct wcd9xxx_clsh_cdc_data *clsh, |
| 191 | struct wcd9xxx_resmgr *resmgr); |
| 192 | |
| 193 | extern void wcd9xxx_clsh_imped_config(struct snd_soc_codec *codec, |
| 194 | int imped); |
| 195 | |
| 196 | enum wcd9xxx_codec_event { |
| 197 | WCD9XXX_CODEC_EVENT_CODEC_UP = 0, |
| 198 | }; |
| 199 | |
| 200 | struct wcd9xxx_register_save_node { |
| 201 | struct list_head lh; |
| 202 | u16 reg; |
| 203 | u16 value; |
| 204 | }; |
| 205 | |
| 206 | extern int wcd9xxx_soc_update_bits_push(struct snd_soc_codec *codec, |
| 207 | struct list_head *lh, |
| 208 | uint16_t reg, uint8_t mask, |
| 209 | uint8_t value, int delay); |
| 210 | extern void wcd9xxx_restore_registers(struct snd_soc_codec *codec, |
| 211 | struct list_head *lh); |
| 212 | enum { |
| 213 | RESERVED = 0, |
| 214 | AANC_LPF_FF_FB = 1, |
| 215 | AANC_LPF_COEFF_MSB, |
| 216 | AANC_LPF_COEFF_LSB, |
| 217 | HW_MAD_AUDIO_ENABLE, |
| 218 | HW_MAD_ULTR_ENABLE, |
| 219 | HW_MAD_BEACON_ENABLE, |
| 220 | HW_MAD_AUDIO_SLEEP_TIME, |
| 221 | HW_MAD_ULTR_SLEEP_TIME, |
| 222 | HW_MAD_BEACON_SLEEP_TIME, |
| 223 | HW_MAD_TX_AUDIO_SWITCH_OFF, |
| 224 | HW_MAD_TX_ULTR_SWITCH_OFF, |
| 225 | HW_MAD_TX_BEACON_SWITCH_OFF, |
| 226 | MAD_AUDIO_INT_DEST_SELECT_REG, |
| 227 | MAD_ULT_INT_DEST_SELECT_REG, |
| 228 | MAD_BEACON_INT_DEST_SELECT_REG, |
| 229 | MAD_CLIP_INT_DEST_SELECT_REG, |
| 230 | MAD_VBAT_INT_DEST_SELECT_REG, |
| 231 | MAD_AUDIO_INT_MASK_REG, |
| 232 | MAD_ULT_INT_MASK_REG, |
| 233 | MAD_BEACON_INT_MASK_REG, |
| 234 | MAD_CLIP_INT_MASK_REG, |
| 235 | MAD_VBAT_INT_MASK_REG, |
| 236 | MAD_AUDIO_INT_STATUS_REG, |
| 237 | MAD_ULT_INT_STATUS_REG, |
| 238 | MAD_BEACON_INT_STATUS_REG, |
| 239 | MAD_CLIP_INT_STATUS_REG, |
| 240 | MAD_VBAT_INT_STATUS_REG, |
| 241 | MAD_AUDIO_INT_CLEAR_REG, |
| 242 | MAD_ULT_INT_CLEAR_REG, |
| 243 | MAD_BEACON_INT_CLEAR_REG, |
| 244 | MAD_CLIP_INT_CLEAR_REG, |
| 245 | MAD_VBAT_INT_CLEAR_REG, |
| 246 | SB_PGD_PORT_TX_WATERMARK_N, |
| 247 | SB_PGD_PORT_TX_ENABLE_N, |
| 248 | SB_PGD_PORT_RX_WATERMARK_N, |
| 249 | SB_PGD_PORT_RX_ENABLE_N, |
| 250 | SB_PGD_TX_PORTn_MULTI_CHNL_0, |
| 251 | SB_PGD_TX_PORTn_MULTI_CHNL_1, |
| 252 | SB_PGD_RX_PORTn_MULTI_CHNL_0, |
| 253 | SB_PGD_RX_PORTn_MULTI_CHNL_1, |
| 254 | AANC_FF_GAIN_ADAPTIVE, |
| 255 | AANC_FFGAIN_ADAPTIVE_EN, |
| 256 | AANC_GAIN_CONTROL, |
| 257 | SPKR_CLIP_PIPE_BANK_SEL, |
| 258 | SPKR_CLIPDET_VAL0, |
| 259 | SPKR_CLIPDET_VAL1, |
| 260 | SPKR_CLIPDET_VAL2, |
| 261 | SPKR_CLIPDET_VAL3, |
| 262 | SPKR_CLIPDET_VAL4, |
| 263 | SPKR_CLIPDET_VAL5, |
| 264 | SPKR_CLIPDET_VAL6, |
| 265 | SPKR_CLIPDET_VAL7, |
| 266 | VBAT_RELEASE_INT_DEST_SELECT_REG, |
| 267 | VBAT_RELEASE_INT_MASK_REG, |
| 268 | VBAT_RELEASE_INT_STATUS_REG, |
| 269 | VBAT_RELEASE_INT_CLEAR_REG, |
| 270 | MAD2_CLIP_INT_DEST_SELECT_REG, |
| 271 | MAD2_CLIP_INT_MASK_REG, |
| 272 | MAD2_CLIP_INT_STATUS_REG, |
| 273 | MAD2_CLIP_INT_CLEAR_REG, |
| 274 | SPKR2_CLIP_PIPE_BANK_SEL, |
| 275 | SPKR2_CLIPDET_VAL0, |
| 276 | SPKR2_CLIPDET_VAL1, |
| 277 | SPKR2_CLIPDET_VAL2, |
| 278 | SPKR2_CLIPDET_VAL3, |
| 279 | SPKR2_CLIPDET_VAL4, |
| 280 | SPKR2_CLIPDET_VAL5, |
| 281 | SPKR2_CLIPDET_VAL6, |
| 282 | SPKR2_CLIPDET_VAL7, |
| 283 | MAX_CFG_REGISTERS, |
| 284 | }; |
| 285 | |
| 286 | #endif |