blob: 3f987cc3fcf9082f29da72c20742db0decb18e89 [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>
13
Kiran Kandi7a9fd902011-11-14 13:51:45 -080014#define TABLA_VERSION_1_0 0
15#define TABLA_VERSION_1_1 1
16#define TABLA_VERSION_2_0 2
17
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070018#define TABLA_NUM_REGISTERS 0x400
19#define TABLA_MAX_REGISTER (TABLA_NUM_REGISTERS-1)
20#define TABLA_CACHE_SIZE TABLA_NUM_REGISTERS
21
Kiran Kandi1f6fd722011-08-11 10:36:11 -070022#define TABLA_REG_VAL(reg, val) {reg, 0, val}
23
Joonwoo Park0976d012011-12-22 11:48:18 -080024
25#define DEFAULT_DCE_WAIT 60000
26#define DEFAULT_STA_WAIT 5000
27
28#define STA 0
29#define DCE 1
30
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031extern const u8 tabla_reg_readable[TABLA_CACHE_SIZE];
32extern const u8 tabla_reg_defaults[TABLA_CACHE_SIZE];
33
34enum tabla_micbias_num {
35 TABLA_MICBIAS1,
36 TABLA_MICBIAS2,
37 TABLA_MICBIAS3,
38 TABLA_MICBIAS4,
39};
40
41enum tabla_pid_current {
42 TABLA_PID_MIC_2P5_UA,
43 TABLA_PID_MIC_5_UA,
44 TABLA_PID_MIC_10_UA,
45 TABLA_PID_MIC_20_UA,
46};
47
Kiran Kandi1f6fd722011-08-11 10:36:11 -070048struct tabla_reg_mask_val {
49 u16 reg;
50 u8 mask;
51 u8 val;
52};
53
Joonwoo Park0976d012011-12-22 11:48:18 -080054enum tabla_mbhc_clk_freq {
55 TABLA_MCLK_12P2MHZ = 0,
56 TABLA_MCLK_9P6MHZ,
57 TABLA_NUM_CLK_FREQS,
58};
59
60enum tabla_mbhc_analog_pwr_cfg {
61 TABLA_ANALOG_PWR_COLLAPSED = 0,
62 TABLA_ANALOG_PWR_ON,
63 TABLA_NUM_ANALOG_PWR_CONFIGS,
64};
65
66enum tabla_mbhc_btn_det_mem {
67 TABLA_BTN_DET_V_BTN_LOW,
68 TABLA_BTN_DET_V_BTN_HIGH,
69 TABLA_BTN_DET_V_N_READY,
70 TABLA_BTN_DET_N_CIC,
71 TABLA_BTN_DET_GAIN
72};
73
74struct tabla_mbhc_general_cfg {
75 u8 t_ldoh;
76 u8 t_bg_fast_settle;
77 u8 t_shutdown_plug_rem;
78 u8 mbhc_nsa;
79 u8 mbhc_navg;
80 u8 v_micbias_l;
81 u8 v_micbias;
82 u8 mbhc_reserved;
83 u16 settle_wait;
84 u16 t_micbias_rampup;
85 u16 t_micbias_rampdown;
86 u16 t_supply_bringup;
87} __packed;
88
89struct tabla_mbhc_plug_detect_cfg {
90 u32 mic_current;
91 u32 hph_current;
92 u16 t_mic_pid;
93 u16 t_ins_complete;
94 u16 t_ins_retry;
95 u16 v_removal_delta;
96 u8 micbias_slow_ramp;
97 u8 reserved0;
98 u8 reserved1;
99 u8 reserved2;
100} __packed;
101
102struct tabla_mbhc_plug_type_cfg {
103 u8 av_detect;
104 u8 mono_detect;
105 u8 num_ins_tries;
106 u8 reserved0;
107 s16 v_no_mic;
108 s16 v_av_min;
109 s16 v_av_max;
110 s16 v_hs_min;
111 s16 v_hs_max;
112 u16 reserved1;
113} __packed;
114
115
116struct tabla_mbhc_btn_detect_cfg {
117 s8 c[8];
118 u8 nc;
119 u8 n_meas;
120 u8 mbhc_nsc;
121 u8 n_btn_meas;
122 u8 n_btn_con;
123 u8 num_btn;
124 u8 reserved0;
125 u8 reserved1;
126 u16 t_poll;
127 u16 t_bounce_wait;
128 u16 t_rel_timeout;
129 s16 v_btn_press_delta_sta;
130 s16 v_btn_press_delta_cic;
131 u16 t_btn0_timeout;
132 s16 _v_btn_low[0]; /* v_btn_low[num_btn] */
133 s16 _v_btn_high[0]; /* v_btn_high[num_btn] */
134 u8 _n_ready[TABLA_NUM_CLK_FREQS];
135 u8 _n_cic[TABLA_NUM_CLK_FREQS];
136 u8 _gain[TABLA_NUM_CLK_FREQS];
137} __packed;
138
139struct tabla_mbhc_imped_detect_cfg {
140 u8 _hs_imped_detect;
141 u8 _n_rload;
142 u8 _hph_keep_on;
143 u8 _repeat_rload_calc;
144 u16 _t_dac_ramp_time;
145 u16 _rhph_high;
146 u16 _rhph_low;
147 u16 _rload[0]; /* rload[n_rload] */
148 u16 _alpha[0]; /* alpha[n_rload] */
149 u16 _beta[3];
150} __packed;
151
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700152extern int tabla_hs_detect(struct snd_soc_codec *codec,
Joonwoo Park0976d012011-12-22 11:48:18 -0800153 struct snd_soc_jack *headset_jack,
154 struct snd_soc_jack *button_jack,
155 void *calibration, enum tabla_micbias_num micbis,
156 int (*mclk_cb_fn) (struct snd_soc_codec*, int),
157 int read_fw_bin, u32 mclk_rate);
Bradley Rubina7096d02011-08-03 18:29:02 -0700158
159struct anc_header {
160 u32 reserved[3];
161 u32 num_anc_slots;
162};
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700163
164extern int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable);
Joonwoo Park0976d012011-12-22 11:48:18 -0800165
166extern void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg
167 *btn_det,
168 const enum tabla_mbhc_btn_det_mem mem);
169
170#define TABLA_MBHC_CAL_SIZE(buttons, rload) ( \
171 sizeof(enum tabla_micbias_num) + \
172 sizeof(struct tabla_mbhc_general_cfg) + \
173 sizeof(struct tabla_mbhc_plug_detect_cfg) + \
174 ((sizeof(s16) + sizeof(s16)) * buttons) + \
175 sizeof(struct tabla_mbhc_plug_type_cfg) + \
176 sizeof(struct tabla_mbhc_btn_detect_cfg) + \
177 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
178 ((sizeof(u16) + sizeof(u16)) * rload) \
179 )
180
181#define TABLA_MBHC_CAL_GENERAL_PTR(cali) ( \
182 (struct tabla_mbhc_general_cfg *) cali)
183#define TABLA_MBHC_CAL_PLUG_DET_PTR(cali) ( \
184 (struct tabla_mbhc_plug_detect_cfg *) \
185 &(TABLA_MBHC_CAL_GENERAL_PTR(cali)[1]))
186#define TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali) ( \
187 (struct tabla_mbhc_plug_type_cfg *) \
188 &(TABLA_MBHC_CAL_PLUG_DET_PTR(cali)[1]))
189#define TABLA_MBHC_CAL_BTN_DET_PTR(cali) ( \
190 (struct tabla_mbhc_btn_detect_cfg *) \
191 &(TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali)[1]))
192#define TABLA_MBHC_CAL_IMPED_DET_PTR(cali) ( \
193 (struct tabla_mbhc_imped_detect_cfg *) \
194 (((void *)&TABLA_MBHC_CAL_BTN_DET_PTR(cali)[1]) + \
195 (TABLA_MBHC_CAL_BTN_DET_PTR(cali)->num_btn * \
196 (sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_low[0]) + \
197 sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_high[0])))) \
198 )
199
Patrick Lai64b43262011-12-06 17:29:15 -0800200/* minimum size of calibration data assuming there is only one button and
201 * one rload.
202 */
203#define TABLA_MBHC_CAL_MIN_SIZE ( \
204 sizeof(struct tabla_mbhc_general_cfg) + \
205 sizeof(struct tabla_mbhc_plug_detect_cfg) + \
206 sizeof(struct tabla_mbhc_plug_type_cfg) + \
207 sizeof(struct tabla_mbhc_btn_detect_cfg) + \
208 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
209 (sizeof(u16) * 2))
210
211#define TABLA_MBHC_CAL_BTN_SZ(cfg_ptr) ( \
212 sizeof(struct tabla_mbhc_btn_detect_cfg) + \
213 (cfg_ptr->num_btn * (sizeof(cfg_ptr->_v_btn_low[0]) + \
214 sizeof(cfg_ptr->_v_btn_high[0]))))
215
216#define TABLA_MBHC_CAL_IMPED_MIN_SZ ( \
217 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
218 sizeof(u16) * 2)
219
220#define TABLA_MBHC_CAL_IMPED_SZ(cfg_ptr) ( \
221 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
222 (cfg_ptr->_n_rload * (sizeof(cfg_ptr->_rload[0]) + \
223 sizeof(cfg_ptr->_alpha[0]))))
224
225