blob: 5c991e6e1bb9b7e604fb402150cb92193954ec9b [file] [log] [blame]
Simmi Pateriya71d63872012-11-08 01:06:30 +05301/* Copyright (c) 2011-2013, The Linux Foundation. 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
Joonwoo Parkcf473b42012-03-29 19:48:16 -070027#define VDDIO_MICBIAS_MV 1800
Joonwoo Park0976d012011-12-22 11:48:18 -080028
29#define STA 0
30#define DCE 1
31
Joonwoo Park6b9b03f2012-01-23 18:48:54 -080032#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 Huntsman3f2bc4d2011-08-16 17:27:22 -070037extern const u8 tabla_reg_readable[TABLA_CACHE_SIZE];
Joonwoo Park6c1ebb62012-01-16 19:08:43 -080038extern const u32 tabla_1_reg_readable[TABLA_1_X_ONLY_REGISTERS];
39extern const u32 tabla_2_reg_readable[TABLA_2_HIGHER_ONLY_REGISTERS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040extern const u8 tabla_reg_defaults[TABLA_CACHE_SIZE];
41
42enum tabla_micbias_num {
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -070043 TABLA_MICBIAS1 = 0,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044 TABLA_MICBIAS2,
45 TABLA_MICBIAS3,
46 TABLA_MICBIAS4,
Simmi Pateriya71d63872012-11-08 01:06:30 +053047 TABLA_NUM_MICBIAS,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070048};
49
50enum tabla_pid_current {
51 TABLA_PID_MIC_2P5_UA,
52 TABLA_PID_MIC_5_UA,
53 TABLA_PID_MIC_10_UA,
54 TABLA_PID_MIC_20_UA,
55};
56
Kiran Kandi1f6fd722011-08-11 10:36:11 -070057struct tabla_reg_mask_val {
58 u16 reg;
59 u8 mask;
60 u8 val;
61};
62
Joonwoo Park0976d012011-12-22 11:48:18 -080063enum tabla_mbhc_clk_freq {
64 TABLA_MCLK_12P2MHZ = 0,
65 TABLA_MCLK_9P6MHZ,
66 TABLA_NUM_CLK_FREQS,
67};
68
69enum tabla_mbhc_analog_pwr_cfg {
70 TABLA_ANALOG_PWR_COLLAPSED = 0,
71 TABLA_ANALOG_PWR_ON,
72 TABLA_NUM_ANALOG_PWR_CONFIGS,
73};
74
75enum tabla_mbhc_btn_det_mem {
76 TABLA_BTN_DET_V_BTN_LOW,
77 TABLA_BTN_DET_V_BTN_HIGH,
Joonwoo Parkc0672392012-01-11 11:03:14 -080078 TABLA_BTN_DET_N_READY,
Joonwoo Park0976d012011-12-22 11:48:18 -080079 TABLA_BTN_DET_N_CIC,
80 TABLA_BTN_DET_GAIN
81};
82
83struct tabla_mbhc_general_cfg {
84 u8 t_ldoh;
85 u8 t_bg_fast_settle;
86 u8 t_shutdown_plug_rem;
87 u8 mbhc_nsa;
88 u8 mbhc_navg;
89 u8 v_micbias_l;
90 u8 v_micbias;
91 u8 mbhc_reserved;
92 u16 settle_wait;
93 u16 t_micbias_rampup;
94 u16 t_micbias_rampdown;
95 u16 t_supply_bringup;
96} __packed;
97
98struct tabla_mbhc_plug_detect_cfg {
99 u32 mic_current;
100 u32 hph_current;
101 u16 t_mic_pid;
102 u16 t_ins_complete;
103 u16 t_ins_retry;
104 u16 v_removal_delta;
105 u8 micbias_slow_ramp;
106 u8 reserved0;
107 u8 reserved1;
108 u8 reserved2;
109} __packed;
110
111struct tabla_mbhc_plug_type_cfg {
112 u8 av_detect;
113 u8 mono_detect;
114 u8 num_ins_tries;
115 u8 reserved0;
116 s16 v_no_mic;
117 s16 v_av_min;
118 s16 v_av_max;
119 s16 v_hs_min;
120 s16 v_hs_max;
121 u16 reserved1;
122} __packed;
123
124
125struct tabla_mbhc_btn_detect_cfg {
126 s8 c[8];
127 u8 nc;
128 u8 n_meas;
129 u8 mbhc_nsc;
130 u8 n_btn_meas;
131 u8 n_btn_con;
132 u8 num_btn;
133 u8 reserved0;
134 u8 reserved1;
135 u16 t_poll;
136 u16 t_bounce_wait;
137 u16 t_rel_timeout;
138 s16 v_btn_press_delta_sta;
139 s16 v_btn_press_delta_cic;
140 u16 t_btn0_timeout;
141 s16 _v_btn_low[0]; /* v_btn_low[num_btn] */
142 s16 _v_btn_high[0]; /* v_btn_high[num_btn] */
143 u8 _n_ready[TABLA_NUM_CLK_FREQS];
144 u8 _n_cic[TABLA_NUM_CLK_FREQS];
145 u8 _gain[TABLA_NUM_CLK_FREQS];
146} __packed;
147
148struct tabla_mbhc_imped_detect_cfg {
149 u8 _hs_imped_detect;
150 u8 _n_rload;
151 u8 _hph_keep_on;
152 u8 _repeat_rload_calc;
153 u16 _t_dac_ramp_time;
154 u16 _rhph_high;
155 u16 _rhph_low;
156 u16 _rload[0]; /* rload[n_rload] */
157 u16 _alpha[0]; /* alpha[n_rload] */
158 u16 _beta[3];
159} __packed;
160
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700161struct tabla_mbhc_config {
162 struct snd_soc_jack *headset_jack;
163 struct snd_soc_jack *button_jack;
164 bool read_fw_bin;
165 /* void* calibration contains:
166 * struct tabla_mbhc_general_cfg generic;
167 * struct tabla_mbhc_plug_detect_cfg plug_det;
168 * struct tabla_mbhc_plug_type_cfg plug_type;
169 * struct tabla_mbhc_btn_detect_cfg btn_det;
170 * struct tabla_mbhc_imped_detect_cfg imped_det;
171 * Note: various size depends on btn_det->num_btn
172 */
173 void *calibration;
174 enum tabla_micbias_num micbias;
175 int (*mclk_cb_fn) (struct snd_soc_codec*, int, bool);
176 unsigned int mclk_rate;
177 unsigned int gpio;
178 unsigned int gpio_irq;
179 int gpio_level_insert;
Ravi Kumar Alamanda07b6bd62012-08-15 18:39:47 -0700180 bool detect_extn_cable;
Joonwoo Park2cc13f02012-05-09 12:44:25 -0700181 /* swap_gnd_mic returns true if extern GND/MIC swap switch toggled */
182 bool (*swap_gnd_mic) (struct snd_soc_codec *);
Simmi Pateriya71d63872012-11-08 01:06:30 +0530183 bool micbias_always_on;
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700184};
185
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186extern int tabla_hs_detect(struct snd_soc_codec *codec,
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700187 const struct tabla_mbhc_config *cfg);
Bradley Rubina7096d02011-08-03 18:29:02 -0700188
189struct anc_header {
190 u32 reserved[3];
191 u32 num_anc_slots;
192};
Kiran Kandi6fae8bf2011-08-15 10:36:42 -0700193
Joonwoo Parkd7cf2e92012-03-19 19:38:23 -0700194extern int tabla_mclk_enable(struct snd_soc_codec *codec, int mclk_enable,
195 bool dapm);
Joonwoo Park0976d012011-12-22 11:48:18 -0800196
197extern void *tabla_mbhc_cal_btn_det_mp(const struct tabla_mbhc_btn_detect_cfg
198 *btn_det,
199 const enum tabla_mbhc_btn_det_mem mem);
200
201#define TABLA_MBHC_CAL_SIZE(buttons, rload) ( \
202 sizeof(enum tabla_micbias_num) + \
203 sizeof(struct tabla_mbhc_general_cfg) + \
204 sizeof(struct tabla_mbhc_plug_detect_cfg) + \
205 ((sizeof(s16) + sizeof(s16)) * buttons) + \
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) + sizeof(u16)) * rload) \
210 )
211
212#define TABLA_MBHC_CAL_GENERAL_PTR(cali) ( \
213 (struct tabla_mbhc_general_cfg *) cali)
214#define TABLA_MBHC_CAL_PLUG_DET_PTR(cali) ( \
215 (struct tabla_mbhc_plug_detect_cfg *) \
216 &(TABLA_MBHC_CAL_GENERAL_PTR(cali)[1]))
217#define TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali) ( \
218 (struct tabla_mbhc_plug_type_cfg *) \
219 &(TABLA_MBHC_CAL_PLUG_DET_PTR(cali)[1]))
220#define TABLA_MBHC_CAL_BTN_DET_PTR(cali) ( \
221 (struct tabla_mbhc_btn_detect_cfg *) \
222 &(TABLA_MBHC_CAL_PLUG_TYPE_PTR(cali)[1]))
223#define TABLA_MBHC_CAL_IMPED_DET_PTR(cali) ( \
224 (struct tabla_mbhc_imped_detect_cfg *) \
225 (((void *)&TABLA_MBHC_CAL_BTN_DET_PTR(cali)[1]) + \
226 (TABLA_MBHC_CAL_BTN_DET_PTR(cali)->num_btn * \
227 (sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_low[0]) + \
228 sizeof(TABLA_MBHC_CAL_BTN_DET_PTR(cali)->_v_btn_high[0])))) \
229 )
230
Patrick Lai64b43262011-12-06 17:29:15 -0800231/* minimum size of calibration data assuming there is only one button and
232 * one rload.
233 */
234#define TABLA_MBHC_CAL_MIN_SIZE ( \
235 sizeof(struct tabla_mbhc_general_cfg) + \
236 sizeof(struct tabla_mbhc_plug_detect_cfg) + \
237 sizeof(struct tabla_mbhc_plug_type_cfg) + \
238 sizeof(struct tabla_mbhc_btn_detect_cfg) + \
239 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
240 (sizeof(u16) * 2))
241
242#define TABLA_MBHC_CAL_BTN_SZ(cfg_ptr) ( \
243 sizeof(struct tabla_mbhc_btn_detect_cfg) + \
244 (cfg_ptr->num_btn * (sizeof(cfg_ptr->_v_btn_low[0]) + \
245 sizeof(cfg_ptr->_v_btn_high[0]))))
246
247#define TABLA_MBHC_CAL_IMPED_MIN_SZ ( \
248 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
249 sizeof(u16) * 2)
250
251#define TABLA_MBHC_CAL_IMPED_SZ(cfg_ptr) ( \
252 sizeof(struct tabla_mbhc_imped_detect_cfg) + \
253 (cfg_ptr->_n_rload * (sizeof(cfg_ptr->_rload[0]) + \
254 sizeof(cfg_ptr->_alpha[0]))))
255
256
Kuirong Wang906ac472012-07-09 12:54:44 -0700257/* Number of input and output Slimbus port */
258enum {
259 TABLA_RX1 = 0,
260 TABLA_RX2,
261 TABLA_RX3,
262 TABLA_RX4,
263 TABLA_RX5,
264 TABLA_RX6,
265 TABLA_RX7,
266 TABLA_RX_MAX,
267};
268
269enum {
270 TABLA_TX1 = 0,
271 TABLA_TX2,
272 TABLA_TX3,
273 TABLA_TX4,
274 TABLA_TX5,
275 TABLA_TX6,
276 TABLA_TX7,
277 TABLA_TX8,
278 TABLA_TX9,
279 TABLA_TX10,
280 TABLA_TX_MAX,
281};
282