blob: d1d0c17afb02e30ba3816fc426c573bcc671c3fc [file] [log] [blame]
Joonwoo Park0976d012011-12-22 11:48:18 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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 Huntsman3f2bc4d2011-08-16 17:27:22 -070012#include <sound/soc.h>
Joonwoo Park6b9b03f2012-01-23 18:48:54 -080013#include <sound/jack.h>
Asish Bhattacharyab1aeae22012-02-15 08:29:28 +053014#include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070015
16#define TABLA_NUM_REGISTERS 0x400
17#define TABLA_MAX_REGISTER (TABLA_NUM_REGISTERS-1)
18#define TABLA_CACHE_SIZE TABLA_NUM_REGISTERS
Joonwoo Park6c1ebb62012-01-16 19:08:43 -080019#define TABLA_1_X_ONLY_REGISTERS 3
20#define TABLA_2_HIGHER_ONLY_REGISTERS 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021
Kiran Kandi1f6fd722011-08-11 10:36:11 -070022#define TABLA_REG_VAL(reg, val) {reg, 0, val}
23
Joonwoo Park433149a2012-01-11 09:53:54 -080024#define DEFAULT_DCE_STA_WAIT 55
Joonwoo Park0976d012011-12-22 11:48:18 -080025#define DEFAULT_DCE_WAIT 60000
26#define DEFAULT_STA_WAIT 5000
27
28#define STA 0
29#define DCE 1
30
Joonwoo Park6b9b03f2012-01-23 18:48:54 -080031#define TABLA_JACK_BUTTON_MASK (SND_JACK_BTN_0 | SND_JACK_BTN_1 | \
32 SND_JACK_BTN_2 | SND_JACK_BTN_3 | \
33 SND_JACK_BTN_4 | SND_JACK_BTN_5 | \
34 SND_JACK_BTN_6 | SND_JACK_BTN_7)
35
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036extern const u8 tabla_reg_readable[TABLA_CACHE_SIZE];
Joonwoo Park6c1ebb62012-01-16 19:08:43 -080037extern const u32 tabla_1_reg_readable[TABLA_1_X_ONLY_REGISTERS];
38extern const u32 tabla_2_reg_readable[TABLA_2_HIGHER_ONLY_REGISTERS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039extern const u8 tabla_reg_defaults[TABLA_CACHE_SIZE];
40
41enum tabla_micbias_num {
42 TABLA_MICBIAS1,
43 TABLA_MICBIAS2,
44 TABLA_MICBIAS3,
45 TABLA_MICBIAS4,
46};
47
48enum tabla_pid_current {
49 TABLA_PID_MIC_2P5_UA,
50 TABLA_PID_MIC_5_UA,
51 TABLA_PID_MIC_10_UA,
52 TABLA_PID_MIC_20_UA,
53};
54
Kiran Kandi1f6fd722011-08-11 10:36:11 -070055struct tabla_reg_mask_val {
56 u16 reg;
57 u8 mask;
58 u8 val;
59};
60
Joonwoo Park0976d012011-12-22 11:48:18 -080061enum tabla_mbhc_clk_freq {
62 TABLA_MCLK_12P2MHZ = 0,
63 TABLA_MCLK_9P6MHZ,
64 TABLA_NUM_CLK_FREQS,
65};
66
67enum tabla_mbhc_analog_pwr_cfg {
68 TABLA_ANALOG_PWR_COLLAPSED = 0,
69 TABLA_ANALOG_PWR_ON,
70 TABLA_NUM_ANALOG_PWR_CONFIGS,
71};
72
73enum tabla_mbhc_btn_det_mem {
74 TABLA_BTN_DET_V_BTN_LOW,
75 TABLA_BTN_DET_V_BTN_HIGH,
Joonwoo Parkc0672392012-01-11 11:03:14 -080076 TABLA_BTN_DET_N_READY,
Joonwoo Park0976d012011-12-22 11:48:18 -080077 TABLA_BTN_DET_N_CIC,
78 TABLA_BTN_DET_GAIN
79};
80
81struct tabla_mbhc_general_cfg {
82 u8 t_ldoh;
83 u8 t_bg_fast_settle;
84 u8 t_shutdown_plug_rem;
85 u8 mbhc_nsa;
86 u8 mbhc_navg;
87 u8 v_micbias_l;
88 u8 v_micbias;
89 u8 mbhc_reserved;
90 u16 settle_wait;
91 u16 t_micbias_rampup;
92 u16 t_micbias_rampdown;
93 u16 t_supply_bringup;
94} __packed;
95
96struct tabla_mbhc_plug_detect_cfg {
97 u32 mic_current;
98 u32 hph_current;
99 u16 t_mic_pid;
100 u16 t_ins_complete;
101 u16 t_ins_retry;
102 u16 v_removal_delta;
103 u8 micbias_slow_ramp;
104 u8 reserved0;
105 u8 reserved1;
106 u8 reserved2;
107} __packed;
108
109struct tabla_mbhc_plug_type_cfg {
110 u8 av_detect;
111 u8 mono_detect;
112 u8 num_ins_tries;
113 u8 reserved0;
114 s16 v_no_mic;
115 s16 v_av_min;
116 s16 v_av_max;
117 s16 v_hs_min;
118 s16 v_hs_max;
119 u16 reserved1;
120} __packed;
121
122
123struct tabla_mbhc_btn_detect_cfg {
124 s8 c[8];
125 u8 nc;
126 u8 n_meas;
127 u8 mbhc_nsc;
128 u8 n_btn_meas;
129 u8 n_btn_con;
130 u8 num_btn;
131 u8 reserved0;
132 u8 reserved1;
133 u16 t_poll;
134 u16 t_bounce_wait;
135 u16 t_rel_timeout;
136 s16 v_btn_press_delta_sta;
137 s16 v_btn_press_delta_cic;
138 u16 t_btn0_timeout;
139 s16 _v_btn_low[0]; /* v_btn_low[num_btn] */
140 s16 _v_btn_high[0]; /* v_btn_high[num_btn] */
141 u8 _n_ready[TABLA_NUM_CLK_FREQS];
142 u8 _n_cic[TABLA_NUM_CLK_FREQS];
143 u8 _gain[TABLA_NUM_CLK_FREQS];
144} __packed;
145
146struct tabla_mbhc_imped_detect_cfg {
147 u8 _hs_imped_detect;
148 u8 _n_rload;
149 u8 _hph_keep_on;
150 u8 _repeat_rload_calc;
151 u16 _t_dac_ramp_time;
152 u16 _rhph_high;
153 u16 _rhph_low;
154 u16 _rload[0]; /* rload[n_rload] */
155 u16 _alpha[0]; /* alpha[n_rload] */
156 u16 _beta[3];
157} __packed;
158
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159extern int tabla_hs_detect(struct snd_soc_codec *codec,
Joonwoo Park0976d012011-12-22 11:48:18 -0800160 struct snd_soc_jack *headset_jack,
161 struct snd_soc_jack *button_jack,
162 void *calibration, enum tabla_micbias_num micbis,
163 int (*mclk_cb_fn) (struct snd_soc_codec*, int),
164 int read_fw_bin, u32 mclk_rate);
Bradley Rubina7096d02011-08-03 18:29:02 -0700165
166struct anc_header {
167 u32 reserved[3];
168 u32 num_anc_slots;
169};
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700170
171extern int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable);
Joonwoo Park0976d012011-12-22 11:48:18 -0800172
173extern void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg
174 *btn_det,
175 const enum tabla_mbhc_btn_det_mem mem);
176
177#define TABLA_MBHC_CAL_SIZE(buttons, rload) ( \
178 sizeof(enum tabla_micbias_num) + \
179 sizeof(struct tabla_mbhc_general_cfg) + \
180 sizeof(struct tabla_mbhc_plug_detect_cfg) + \
181 ((sizeof(s16) + sizeof(s16)) * buttons) + \
182 sizeof(struct tabla_mbhc_plug_type_cfg) + \
183 sizeof(struct tabla_mbhc_btn_detect_cfg) + \
184 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
185 ((sizeof(u16) + sizeof(u16)) * rload) \
186 )
187
188#define TABLA_MBHC_CAL_GENERAL_PTR(cali) ( \
189 (struct tabla_mbhc_general_cfg *) cali)
190#define TABLA_MBHC_CAL_PLUG_DET_PTR(cali) ( \
191 (struct tabla_mbhc_plug_detect_cfg *) \
192 &(TABLA_MBHC_CAL_GENERAL_PTR(cali)[1]))
193#define TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali) ( \
194 (struct tabla_mbhc_plug_type_cfg *) \
195 &(TABLA_MBHC_CAL_PLUG_DET_PTR(cali)[1]))
196#define TABLA_MBHC_CAL_BTN_DET_PTR(cali) ( \
197 (struct tabla_mbhc_btn_detect_cfg *) \
198 &(TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali)[1]))
199#define TABLA_MBHC_CAL_IMPED_DET_PTR(cali) ( \
200 (struct tabla_mbhc_imped_detect_cfg *) \
201 (((void *)&TABLA_MBHC_CAL_BTN_DET_PTR(cali)[1]) + \
202 (TABLA_MBHC_CAL_BTN_DET_PTR(cali)->num_btn * \
203 (sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_low[0]) + \
204 sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_high[0])))) \
205 )
206
Patrick Lai64b43262011-12-06 17:29:15 -0800207/* minimum size of calibration data assuming there is only one button and
208 * one rload.
209 */
210#define TABLA_MBHC_CAL_MIN_SIZE ( \
211 sizeof(struct tabla_mbhc_general_cfg) + \
212 sizeof(struct tabla_mbhc_plug_detect_cfg) + \
213 sizeof(struct tabla_mbhc_plug_type_cfg) + \
214 sizeof(struct tabla_mbhc_btn_detect_cfg) + \
215 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
216 (sizeof(u16) * 2))
217
218#define TABLA_MBHC_CAL_BTN_SZ(cfg_ptr) ( \
219 sizeof(struct tabla_mbhc_btn_detect_cfg) + \
220 (cfg_ptr->num_btn * (sizeof(cfg_ptr->_v_btn_low[0]) + \
221 sizeof(cfg_ptr->_v_btn_high[0]))))
222
223#define TABLA_MBHC_CAL_IMPED_MIN_SZ ( \
224 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
225 sizeof(u16) * 2)
226
227#define TABLA_MBHC_CAL_IMPED_SZ(cfg_ptr) ( \
228 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
229 (cfg_ptr->_n_rload * (sizeof(cfg_ptr->_rload[0]) + \
230 sizeof(cfg_ptr->_alpha[0]))))
231
232