Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 | */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 12 | #include <sound/soc.h> |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 13 | #include <sound/jack.h> |
Asish Bhattacharya | b1aeae2 | 2012-02-15 08:29:28 +0530 | [diff] [blame] | 14 | #include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | |
| 16 | #define TABLA_NUM_REGISTERS 0x400 |
| 17 | #define TABLA_MAX_REGISTER (TABLA_NUM_REGISTERS-1) |
| 18 | #define TABLA_CACHE_SIZE TABLA_NUM_REGISTERS |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 19 | #define TABLA_1_X_ONLY_REGISTERS 3 |
| 20 | #define TABLA_2_HIGHER_ONLY_REGISTERS 3 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 22 | #define TABLA_REG_VAL(reg, val) {reg, 0, val} |
| 23 | |
Joonwoo Park | 433149a | 2012-01-11 09:53:54 -0800 | [diff] [blame] | 24 | #define DEFAULT_DCE_STA_WAIT 55 |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 25 | #define DEFAULT_DCE_WAIT 60000 |
| 26 | #define DEFAULT_STA_WAIT 5000 |
Joonwoo Park | cf473b4 | 2012-03-29 19:48:16 -0700 | [diff] [blame] | 27 | #define VDDIO_MICBIAS_MV 1800 |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 28 | |
| 29 | #define STA 0 |
| 30 | #define DCE 1 |
| 31 | |
Joonwoo Park | 6b9b03f | 2012-01-23 18:48:54 -0800 | [diff] [blame] | 32 | #define TABLA_JACK_BUTTON_MASK (SND_JACK_BTN_0 | SND_JACK_BTN_1 | \ |
| 33 | SND_JACK_BTN_2 | SND_JACK_BTN_3 | \ |
| 34 | SND_JACK_BTN_4 | SND_JACK_BTN_5 | \ |
| 35 | SND_JACK_BTN_6 | SND_JACK_BTN_7) |
| 36 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 37 | extern const u8 tabla_reg_readable[TABLA_CACHE_SIZE]; |
Joonwoo Park | 6c1ebb6 | 2012-01-16 19:08:43 -0800 | [diff] [blame] | 38 | extern const u32 tabla_1_reg_readable[TABLA_1_X_ONLY_REGISTERS]; |
| 39 | extern const u32 tabla_2_reg_readable[TABLA_2_HIGHER_ONLY_REGISTERS]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 40 | extern const u8 tabla_reg_defaults[TABLA_CACHE_SIZE]; |
| 41 | |
| 42 | enum tabla_micbias_num { |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 43 | TABLA_MICBIAS1 = 0, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | TABLA_MICBIAS2, |
| 45 | TABLA_MICBIAS3, |
| 46 | TABLA_MICBIAS4, |
| 47 | }; |
| 48 | |
| 49 | enum tabla_pid_current { |
| 50 | TABLA_PID_MIC_2P5_UA, |
| 51 | TABLA_PID_MIC_5_UA, |
| 52 | TABLA_PID_MIC_10_UA, |
| 53 | TABLA_PID_MIC_20_UA, |
| 54 | }; |
| 55 | |
Kiran Kandi | 1f6fd72 | 2011-08-11 10:36:11 -0700 | [diff] [blame] | 56 | struct tabla_reg_mask_val { |
| 57 | u16 reg; |
| 58 | u8 mask; |
| 59 | u8 val; |
| 60 | }; |
| 61 | |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 62 | enum tabla_mbhc_clk_freq { |
| 63 | TABLA_MCLK_12P2MHZ = 0, |
| 64 | TABLA_MCLK_9P6MHZ, |
| 65 | TABLA_NUM_CLK_FREQS, |
| 66 | }; |
| 67 | |
| 68 | enum tabla_mbhc_analog_pwr_cfg { |
| 69 | TABLA_ANALOG_PWR_COLLAPSED = 0, |
| 70 | TABLA_ANALOG_PWR_ON, |
| 71 | TABLA_NUM_ANALOG_PWR_CONFIGS, |
| 72 | }; |
| 73 | |
| 74 | enum tabla_mbhc_btn_det_mem { |
| 75 | TABLA_BTN_DET_V_BTN_LOW, |
| 76 | TABLA_BTN_DET_V_BTN_HIGH, |
Joonwoo Park | c067239 | 2012-01-11 11:03:14 -0800 | [diff] [blame] | 77 | TABLA_BTN_DET_N_READY, |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 78 | TABLA_BTN_DET_N_CIC, |
| 79 | TABLA_BTN_DET_GAIN |
| 80 | }; |
| 81 | |
| 82 | struct tabla_mbhc_general_cfg { |
| 83 | u8 t_ldoh; |
| 84 | u8 t_bg_fast_settle; |
| 85 | u8 t_shutdown_plug_rem; |
| 86 | u8 mbhc_nsa; |
| 87 | u8 mbhc_navg; |
| 88 | u8 v_micbias_l; |
| 89 | u8 v_micbias; |
| 90 | u8 mbhc_reserved; |
| 91 | u16 settle_wait; |
| 92 | u16 t_micbias_rampup; |
| 93 | u16 t_micbias_rampdown; |
| 94 | u16 t_supply_bringup; |
| 95 | } __packed; |
| 96 | |
| 97 | struct tabla_mbhc_plug_detect_cfg { |
| 98 | u32 mic_current; |
| 99 | u32 hph_current; |
| 100 | u16 t_mic_pid; |
| 101 | u16 t_ins_complete; |
| 102 | u16 t_ins_retry; |
| 103 | u16 v_removal_delta; |
| 104 | u8 micbias_slow_ramp; |
| 105 | u8 reserved0; |
| 106 | u8 reserved1; |
| 107 | u8 reserved2; |
| 108 | } __packed; |
| 109 | |
| 110 | struct tabla_mbhc_plug_type_cfg { |
| 111 | u8 av_detect; |
| 112 | u8 mono_detect; |
| 113 | u8 num_ins_tries; |
| 114 | u8 reserved0; |
| 115 | s16 v_no_mic; |
| 116 | s16 v_av_min; |
| 117 | s16 v_av_max; |
| 118 | s16 v_hs_min; |
| 119 | s16 v_hs_max; |
| 120 | u16 reserved1; |
| 121 | } __packed; |
| 122 | |
| 123 | |
| 124 | struct tabla_mbhc_btn_detect_cfg { |
| 125 | s8 c[8]; |
| 126 | u8 nc; |
| 127 | u8 n_meas; |
| 128 | u8 mbhc_nsc; |
| 129 | u8 n_btn_meas; |
| 130 | u8 n_btn_con; |
| 131 | u8 num_btn; |
| 132 | u8 reserved0; |
| 133 | u8 reserved1; |
| 134 | u16 t_poll; |
| 135 | u16 t_bounce_wait; |
| 136 | u16 t_rel_timeout; |
| 137 | s16 v_btn_press_delta_sta; |
| 138 | s16 v_btn_press_delta_cic; |
| 139 | u16 t_btn0_timeout; |
| 140 | s16 _v_btn_low[0]; /* v_btn_low[num_btn] */ |
| 141 | s16 _v_btn_high[0]; /* v_btn_high[num_btn] */ |
| 142 | u8 _n_ready[TABLA_NUM_CLK_FREQS]; |
| 143 | u8 _n_cic[TABLA_NUM_CLK_FREQS]; |
| 144 | u8 _gain[TABLA_NUM_CLK_FREQS]; |
| 145 | } __packed; |
| 146 | |
| 147 | struct tabla_mbhc_imped_detect_cfg { |
| 148 | u8 _hs_imped_detect; |
| 149 | u8 _n_rload; |
| 150 | u8 _hph_keep_on; |
| 151 | u8 _repeat_rload_calc; |
| 152 | u16 _t_dac_ramp_time; |
| 153 | u16 _rhph_high; |
| 154 | u16 _rhph_low; |
| 155 | u16 _rload[0]; /* rload[n_rload] */ |
| 156 | u16 _alpha[0]; /* alpha[n_rload] */ |
| 157 | u16 _beta[3]; |
| 158 | } __packed; |
| 159 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 160 | struct tabla_mbhc_config { |
| 161 | struct snd_soc_jack *headset_jack; |
| 162 | struct snd_soc_jack *button_jack; |
| 163 | bool read_fw_bin; |
| 164 | /* void* calibration contains: |
| 165 | * struct tabla_mbhc_general_cfg generic; |
| 166 | * struct tabla_mbhc_plug_detect_cfg plug_det; |
| 167 | * struct tabla_mbhc_plug_type_cfg plug_type; |
| 168 | * struct tabla_mbhc_btn_detect_cfg btn_det; |
| 169 | * struct tabla_mbhc_imped_detect_cfg imped_det; |
| 170 | * Note: various size depends on btn_det->num_btn |
| 171 | */ |
| 172 | void *calibration; |
| 173 | enum tabla_micbias_num micbias; |
| 174 | int (*mclk_cb_fn) (struct snd_soc_codec*, int, bool); |
| 175 | unsigned int mclk_rate; |
| 176 | unsigned int gpio; |
| 177 | unsigned int gpio_irq; |
| 178 | int gpio_level_insert; |
Ravi Kumar Alamanda | 07b6bd6 | 2012-08-15 18:39:47 -0700 | [diff] [blame] | 179 | bool detect_extn_cable; |
Joonwoo Park | 2cc13f0 | 2012-05-09 12:44:25 -0700 | [diff] [blame] | 180 | /* swap_gnd_mic returns true if extern GND/MIC swap switch toggled */ |
| 181 | bool (*swap_gnd_mic) (struct snd_soc_codec *); |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 182 | }; |
| 183 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 184 | extern int tabla_hs_detect(struct snd_soc_codec *codec, |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 185 | const struct tabla_mbhc_config *cfg); |
Bradley Rubin | a7096d0 | 2011-08-03 18:29:02 -0700 | [diff] [blame] | 186 | |
| 187 | struct anc_header { |
| 188 | u32 reserved[3]; |
| 189 | u32 num_anc_slots; |
| 190 | }; |
Kiran Kandi | 6fae8bf | 2011-08-15 10:36:42 -0700 | [diff] [blame] | 191 | |
Joonwoo Park | d7cf2e9 | 2012-03-19 19:38:23 -0700 | [diff] [blame] | 192 | extern int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable, |
| 193 | bool dapm); |
Joonwoo Park | 0976d01 | 2011-12-22 11:48:18 -0800 | [diff] [blame] | 194 | |
| 195 | extern void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg |
| 196 | *btn_det, |
| 197 | const enum tabla_mbhc_btn_det_mem mem); |
| 198 | |
| 199 | #define TABLA_MBHC_CAL_SIZE(buttons, rload) ( \ |
| 200 | sizeof(enum tabla_micbias_num) + \ |
| 201 | sizeof(struct tabla_mbhc_general_cfg) + \ |
| 202 | sizeof(struct tabla_mbhc_plug_detect_cfg) + \ |
| 203 | ((sizeof(s16) + sizeof(s16)) * buttons) + \ |
| 204 | sizeof(struct tabla_mbhc_plug_type_cfg) + \ |
| 205 | sizeof(struct tabla_mbhc_btn_detect_cfg) + \ |
| 206 | sizeof(struct tabla_mbhc_imped_detect_cfg) + \ |
| 207 | ((sizeof(u16) + sizeof(u16)) * rload) \ |
| 208 | ) |
| 209 | |
| 210 | #define TABLA_MBHC_CAL_GENERAL_PTR(cali) ( \ |
| 211 | (struct tabla_mbhc_general_cfg *) cali) |
| 212 | #define TABLA_MBHC_CAL_PLUG_DET_PTR(cali) ( \ |
| 213 | (struct tabla_mbhc_plug_detect_cfg *) \ |
| 214 | &(TABLA_MBHC_CAL_GENERAL_PTR(cali)[1])) |
| 215 | #define TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali) ( \ |
| 216 | (struct tabla_mbhc_plug_type_cfg *) \ |
| 217 | &(TABLA_MBHC_CAL_PLUG_DET_PTR(cali)[1])) |
| 218 | #define TABLA_MBHC_CAL_BTN_DET_PTR(cali) ( \ |
| 219 | (struct tabla_mbhc_btn_detect_cfg *) \ |
| 220 | &(TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali)[1])) |
| 221 | #define TABLA_MBHC_CAL_IMPED_DET_PTR(cali) ( \ |
| 222 | (struct tabla_mbhc_imped_detect_cfg *) \ |
| 223 | (((void *)&TABLA_MBHC_CAL_BTN_DET_PTR(cali)[1]) + \ |
| 224 | (TABLA_MBHC_CAL_BTN_DET_PTR(cali)->num_btn * \ |
| 225 | (sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_low[0]) + \ |
| 226 | sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_high[0])))) \ |
| 227 | ) |
| 228 | |
Patrick Lai | 64b4326 | 2011-12-06 17:29:15 -0800 | [diff] [blame] | 229 | /* minimum size of calibration data assuming there is only one button and |
| 230 | * one rload. |
| 231 | */ |
| 232 | #define TABLA_MBHC_CAL_MIN_SIZE ( \ |
| 233 | sizeof(struct tabla_mbhc_general_cfg) + \ |
| 234 | sizeof(struct tabla_mbhc_plug_detect_cfg) + \ |
| 235 | sizeof(struct tabla_mbhc_plug_type_cfg) + \ |
| 236 | sizeof(struct tabla_mbhc_btn_detect_cfg) + \ |
| 237 | sizeof(struct tabla_mbhc_imped_detect_cfg) + \ |
| 238 | (sizeof(u16) * 2)) |
| 239 | |
| 240 | #define TABLA_MBHC_CAL_BTN_SZ(cfg_ptr) ( \ |
| 241 | sizeof(struct tabla_mbhc_btn_detect_cfg) + \ |
| 242 | (cfg_ptr->num_btn * (sizeof(cfg_ptr->_v_btn_low[0]) + \ |
| 243 | sizeof(cfg_ptr->_v_btn_high[0])))) |
| 244 | |
| 245 | #define TABLA_MBHC_CAL_IMPED_MIN_SZ ( \ |
| 246 | sizeof(struct tabla_mbhc_imped_detect_cfg) + \ |
| 247 | sizeof(u16) * 2) |
| 248 | |
| 249 | #define TABLA_MBHC_CAL_IMPED_SZ(cfg_ptr) ( \ |
| 250 | sizeof(struct tabla_mbhc_imped_detect_cfg) + \ |
| 251 | (cfg_ptr->_n_rload * (sizeof(cfg_ptr->_rload[0]) + \ |
| 252 | sizeof(cfg_ptr->_alpha[0])))) |
| 253 | |
| 254 | |