blob: 8fde2c43045bd66e1dce4a92a2ca65d40b500740 [file] [log] [blame]
Duy Truonge833aca2013-02-12 13:35:08 -08001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
Kiran Kandic3b24402012-06-11 00:05:59 -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 */
12#ifndef WCD9320_H
13#define WCD9320_H
14
15#include <sound/soc.h>
16#include <sound/jack.h>
17#include <linux/mfd/wcd9xxx/wcd9xxx-slimslave.h>
18
19#define TAIKO_NUM_REGISTERS 0x400
20#define TAIKO_MAX_REGISTER (TAIKO_NUM_REGISTERS-1)
21#define TAIKO_CACHE_SIZE TAIKO_NUM_REGISTERS
22
23#define TAIKO_REG_VAL(reg, val) {reg, 0, val}
24
25#define DEFAULT_DCE_STA_WAIT 55
26#define DEFAULT_DCE_WAIT 60000
27#define DEFAULT_STA_WAIT 5000
28#define VDDIO_MICBIAS_MV 1800
29
30#define STA 0
31#define DCE 1
32
33#define TAIKO_JACK_BUTTON_MASK (SND_JACK_BTN_0 | SND_JACK_BTN_1 | \
34 SND_JACK_BTN_2 | SND_JACK_BTN_3 | \
35 SND_JACK_BTN_4 | SND_JACK_BTN_5 | \
36 SND_JACK_BTN_6 | SND_JACK_BTN_7)
37
38extern const u8 taiko_reg_readable[TAIKO_CACHE_SIZE];
39extern const u8 taiko_reg_defaults[TAIKO_CACHE_SIZE];
40
41enum taiko_micbias_num {
42 TAIKO_MICBIAS1 = 0,
43 TAIKO_MICBIAS2,
44 TAIKO_MICBIAS3,
45 TAIKO_MICBIAS4,
46};
47
48enum taiko_pid_current {
49 TAIKO_PID_MIC_2P5_UA,
50 TAIKO_PID_MIC_5_UA,
51 TAIKO_PID_MIC_10_UA,
52 TAIKO_PID_MIC_20_UA,
53};
54
55struct taiko_reg_mask_val {
56 u16 reg;
57 u8 mask;
58 u8 val;
59};
60
61enum taiko_mbhc_clk_freq {
62 TAIKO_MCLK_12P2MHZ = 0,
63 TAIKO_MCLK_9P6MHZ,
64 TAIKO_NUM_CLK_FREQS,
65};
66
67enum taiko_mbhc_analog_pwr_cfg {
68 TAIKO_ANALOG_PWR_COLLAPSED = 0,
69 TAIKO_ANALOG_PWR_ON,
70 TAIKO_NUM_ANALOG_PWR_CONFIGS,
71};
72
73enum taiko_mbhc_btn_det_mem {
74 TAIKO_BTN_DET_V_BTN_LOW,
75 TAIKO_BTN_DET_V_BTN_HIGH,
76 TAIKO_BTN_DET_N_READY,
77 TAIKO_BTN_DET_N_CIC,
78 TAIKO_BTN_DET_GAIN
79};
80
81struct taiko_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 taiko_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 taiko_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 taiko_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[TAIKO_NUM_CLK_FREQS];
142 u8 _n_cic[TAIKO_NUM_CLK_FREQS];
143 u8 _gain[TAIKO_NUM_CLK_FREQS];
144} __packed;
145
146struct taiko_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
159struct taiko_mbhc_config {
160 struct snd_soc_jack *headset_jack;
161 struct snd_soc_jack *button_jack;
162 bool read_fw_bin;
163 /* void* calibration contains:
164 * struct taiko_mbhc_general_cfg generic;
165 * struct taiko_mbhc_plug_detect_cfg plug_det;
166 * struct taiko_mbhc_plug_type_cfg plug_type;
167 * struct taiko_mbhc_btn_detect_cfg btn_det;
168 * struct taiko_mbhc_imped_detect_cfg imped_det;
169 * Note: various size depends on btn_det->num_btn
170 */
171 void *calibration;
172 enum taiko_micbias_num micbias;
173 int (*mclk_cb_fn) (struct snd_soc_codec*, int, bool);
174 unsigned int mclk_rate;
175 unsigned int gpio;
176 unsigned int gpio_irq;
177 int gpio_level_insert;
178 /* swap_gnd_mic returns true if extern GND/MIC swap switch toggled */
179 bool (*swap_gnd_mic) (struct snd_soc_codec *);
180};
181
182extern int taiko_hs_detect(struct snd_soc_codec *codec,
183 const struct taiko_mbhc_config *cfg);
184
185struct anc_header {
186 u32 reserved[3];
187 u32 num_anc_slots;
188};
189
190extern int taiko_mclk_enable(struct snd_soc_codec *codec, int mclk_enable,
191 bool dapm);
192
193extern void *taiko_mbhc_cal_btn_det_mp(const struct taiko_mbhc_btn_detect_cfg
194 *btn_det,
195 const enum taiko_mbhc_btn_det_mem mem);
196
197#define TAIKO_MBHC_CAL_SIZE(buttons, rload) ( \
198 sizeof(enum taiko_micbias_num) + \
199 sizeof(struct taiko_mbhc_general_cfg) + \
200 sizeof(struct taiko_mbhc_plug_detect_cfg) + \
201 ((sizeof(s16) + sizeof(s16)) * buttons) + \
202 sizeof(struct taiko_mbhc_plug_type_cfg) + \
203 sizeof(struct taiko_mbhc_btn_detect_cfg) + \
204 sizeof(struct taiko_mbhc_imped_detect_cfg) + \
205 ((sizeof(u16) + sizeof(u16)) * rload) \
206 )
207
208#define TAIKO_MBHC_CAL_GENERAL_PTR(cali) ( \
209 (struct taiko_mbhc_general_cfg *) cali)
210#define TAIKO_MBHC_CAL_PLUG_DET_PTR(cali) ( \
211 (struct taiko_mbhc_plug_detect_cfg *) \
212 &(TAIKO_MBHC_CAL_GENERAL_PTR(cali)[1]))
213#define TAIKO_MBHC_CAL_PLUG_TYPE_PTR(cali) ( \
214 (struct taiko_mbhc_plug_type_cfg *) \
215 &(TAIKO_MBHC_CAL_PLUG_DET_PTR(cali)[1]))
216#define TAIKO_MBHC_CAL_BTN_DET_PTR(cali) ( \
217 (struct taiko_mbhc_btn_detect_cfg *) \
218 &(TAIKO_MBHC_CAL_PLUG_TYPE_PTR(cali)[1]))
219#define TAIKO_MBHC_CAL_IMPED_DET_PTR(cali) ( \
220 (struct taiko_mbhc_imped_detect_cfg *) \
221 (((void *)&TAIKO_MBHC_CAL_BTN_DET_PTR(cali)[1]) + \
222 (TAIKO_MBHC_CAL_BTN_DET_PTR(cali)->num_btn * \
223 (sizeof(TAIKO_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_low[0]) + \
224 sizeof(TAIKO_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_high[0])))) \
225 )
226
227/* minimum size of calibration data assuming there is only one button and
228 * one rload.
229 */
230#define TAIKO_MBHC_CAL_MIN_SIZE ( \
231 sizeof(struct taiko_mbhc_general_cfg) + \
232 sizeof(struct taiko_mbhc_plug_detect_cfg) + \
233 sizeof(struct taiko_mbhc_plug_type_cfg) + \
234 sizeof(struct taiko_mbhc_btn_detect_cfg) + \
235 sizeof(struct taiko_mbhc_imped_detect_cfg) + \
236 (sizeof(u16) * 2))
237
238#define TAIKO_MBHC_CAL_BTN_SZ(cfg_ptr) ( \
239 sizeof(struct taiko_mbhc_btn_detect_cfg) + \
240 (cfg_ptr->num_btn * (sizeof(cfg_ptr->_v_btn_low[0]) + \
241 sizeof(cfg_ptr->_v_btn_high[0]))))
242
243#define TAIKO_MBHC_CAL_IMPED_MIN_SZ ( \
244 sizeof(struct taiko_mbhc_imped_detect_cfg) + \
245 sizeof(u16) * 2)
246
247#define TAIKO_MBHC_CAL_IMPED_SZ(cfg_ptr) ( \
248 sizeof(struct taiko_mbhc_imped_detect_cfg) + \
249 (cfg_ptr->_n_rload * (sizeof(cfg_ptr->_rload[0]) + \
250 sizeof(cfg_ptr->_alpha[0]))))
251
252#endif