xref: /OK3568_Linux_fs/kernel/sound/soc/codecs/es7202.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * ALSA SoC ES7202 pdm adc driver
3  *
4  * Author:      David Yang, <yangxiaohua@everest-semi.com>
5  * Copyright:   (C) 2020 Everest Semiconductor Co Ltd.,
6  *
7  * Based on sound/soc/codecs/es7210.c by David Yang
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  *
13  * Notes:
14  *  ES7202 is 2-ch ADC with PDM interface
15  *
16  */
17 #include <linux/clk.h>
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/pm.h>
23 #include <linux/i2c.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/spi/spi.h>
26 #include <linux/platform_device.h>
27 #include <linux/slab.h>
28 #include <linux/of_gpio.h>
29 #include <sound/core.h>
30 #include <sound/pcm.h>
31 #include <sound/pcm_params.h>
32 #include <sound/tlv.h>
33 #include <sound/soc.h>
34 #include <sound/soc-dapm.h>
35 #include <sound/initval.h>
36 #include <linux/proc_fs.h>
37 #include <linux/gpio.h>
38 #include <linux/interrupt.h>
39 #include <linux/irq.h>
40 #include <linux/regmap.h>
41 #include "es7202.h"
42 
43 //static struct snd_soc_codec *es7202_codec;
44 struct i2c_client *i2c_ctl[ADC_DEV_MAXNUM];
45 struct snd_soc_component *tron_component1[ADC_DEV_MAXNUM];
46 static int es7202_adc_num = 0;
47 
48 /* codec private data */
49 struct es7202_priv {
50 	struct regmap *regmap;
51 	struct i2c_client *i2c;
52 
53 	unsigned int pwr_vdd_voltage;
54 	struct regulator *vdd;
55 	int reset_gpio;
56 	bool reset_active_level;
57 };
58 
59 static const struct reg_default es7202_reg_defaults[] = {
60 	{0x00, 0x10}, {0x01, 0x00}, {0x02, 0x04}, {0x03, 0x00},
61 	{0x04, 0x01}, {0x05, 0x18}, {0x06, 0x00}, {0x07, 0x30},
62 	{0x08, 0x02}, {0x10, 0xff}, {0x11, 0x0c}, {0x12, 0x55},
63 	{0x13, 0x55}, {0x14, 0x8c}, {0x15, 0x33}, {0x16, 0x33},
64 	{0x17, 0x33}, {0x18, 0x44}, {0x19, 0x00}, {0x1a, 0x00},
65 	{0x1b, 0x00}, {0x1c, 0xf8}, {0x1d, 0x18}, {0x1e, 0x18},
66 };
67 
es7202_read(u8 reg,u8 * rt_value,struct i2c_client * client)68 static int es7202_read(u8 reg, u8 * rt_value, struct i2c_client *client)
69 {
70 	int ret;
71 	u8 read_cmd[3] = { 0 };
72 	u8 cmd_len = 0;
73 
74 	read_cmd[0] = reg;
75 	cmd_len = 1;
76 
77 	if (!client || !client->adapter)
78 		return -1;
79 
80 	ret = i2c_master_send(client, read_cmd, cmd_len);
81 	if (ret != cmd_len) {
82 		printk("es7202_read error1\n");
83 		return -1;
84 	}
85 
86 	ret = i2c_master_recv(client, rt_value, 1);
87 	if (ret != 1) {
88 		printk("es7202_read error2, ret = %d.\n", ret);
89 		return -1;
90 	}
91 
92 	return 0;
93 }
94 
es7202_write(u8 reg,unsigned char value,struct i2c_client * client)95 static int es7202_write(u8 reg, unsigned char value, struct i2c_client *client)
96 {
97 	int ret = 0;
98 	u8 write_cmd[2] = { 0 };
99 
100 	if (!client || !client->adapter)
101 		return -1;
102 
103 	write_cmd[0] = reg;
104 	write_cmd[1] = value;
105 
106 	ret = i2c_master_send(client, write_cmd, 2);
107 	if (ret != 2) {
108 		printk("es7202_write error->[REG-0x%02x,val-0x%02x]\n",
109 		       reg, value);
110 		return -1;
111 	}
112 
113 	return 0;
114 }
115 
es7202_update_bits(u8 reg,u8 mask,u8 value,struct i2c_client * client)116 static int es7202_update_bits(u8 reg, u8 mask, u8 value,
117 			      struct i2c_client *client)
118 {
119 	u8 val_old = 0, val_new = 0;
120 
121 	es7202_read(reg, &val_old, client);
122 	val_new = (val_old & ~mask) | (value & mask);
123 	if (val_new != val_old) {
124 		es7202_write(reg, val_new, client);
125 	}
126 
127 	return 0;
128 }
129 #if 0
130 static int es7202_multi_chips_write(u8 reg, unsigned char value)
131 {
132 	u8 i;
133 
134 	for (i = 0; i < ADC_DEV_MAXNUM; i++) {
135 		es7202_write(reg, value, i2c_ctl[i]);
136 	}
137 
138 	return 0;
139 }
140 #endif
es7202_multi_chips_update_bits(u8 reg,u8 mask,u8 value)141 static int es7202_multi_chips_update_bits(u8 reg, u8 mask, u8 value)
142 {
143 	u8 i;
144 
145 	for (i = 0; i < ADC_DEV_MAXNUM; i++) {
146 		es7202_update_bits(reg, mask, value, i2c_ctl[i]);
147 	}
148 
149 	return 0;
150 }
151 
152 
153 
154 static const DECLARE_TLV_DB_SCALE(mic_boost_tlv, 0, 300, 0);
155 
156 #if ES7202_CHANNELS_MAX > 0
es7202_micboost1_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)157 static int es7202_micboost1_setting_set(struct snd_kcontrol *kcontrol,
158 			struct snd_ctl_elem_value *ucontrol)
159 {
160 	es7202_update_bits(0x1d, 0x0F,
161 		ucontrol->value.integer.value[0] & 0x0f,
162 		i2c_ctl[0]);
163 	return 0;
164 }
165 
es7202_micboost1_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)166 static int es7202_micboost1_setting_get(struct snd_kcontrol *kcontrol,
167 			struct snd_ctl_elem_value *ucontrol)
168 {
169 	u8 val = 0;
170 	es7202_read(0x1d, &val, i2c_ctl[0]);
171 	ucontrol->value.integer.value[0] = val & 0x0f;
172 	return 0;
173 }
174 
es7202_micboost2_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)175 static int es7202_micboost2_setting_set(struct snd_kcontrol *kcontrol,
176 					struct snd_ctl_elem_value *ucontrol)
177 {
178 	es7202_update_bits(0x1e,
179 			   0x0F,
180 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[0]);
181 	return 0;
182 }
183 
es7202_micboost2_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)184 static int es7202_micboost2_setting_get(struct snd_kcontrol *kcontrol,
185 					struct snd_ctl_elem_value *ucontrol)
186 {
187 	u8 val = 0;
188 	es7202_read(0x1e, &val, i2c_ctl[0]);
189 	ucontrol->value.integer.value[0] = val & 0x0f;
190 	return 0;
191 }
192 #endif
193 #if ES7202_CHANNELS_MAX > 2
es7202_micboost3_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)194 static int es7202_micboost3_setting_set(struct snd_kcontrol *kcontrol,
195 					struct snd_ctl_elem_value *ucontrol)
196 {
197 	es7202_update_bits(0x1d,
198 			   0x0F,
199 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[1]);
200 	return 0;
201 }
202 
es7202_micboost3_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)203 static int es7202_micboost3_setting_get(struct snd_kcontrol *kcontrol,
204 					struct snd_ctl_elem_value *ucontrol)
205 {
206 	u8 val = 0;
207 	es7202_read(0x1d, &val, i2c_ctl[1]);
208 	ucontrol->value.integer.value[0] = val & 0x0f;
209 	return 0;
210 }
211 
es7202_micboost4_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)212 static int es7202_micboost4_setting_set(struct snd_kcontrol *kcontrol,
213 					struct snd_ctl_elem_value *ucontrol)
214 {
215 	es7202_update_bits(0x1e,
216 			   0x0F,
217 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[1]);
218 	return 0;
219 }
220 
es7202_micboost4_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)221 static int es7202_micboost4_setting_get(struct snd_kcontrol *kcontrol,
222 					struct snd_ctl_elem_value *ucontrol)
223 {
224 	u8 val = 0;
225 	es7202_read(0x1e, &val, i2c_ctl[1]);
226 	ucontrol->value.integer.value[0] = val & 0x0f;
227 	return 0;
228 }
229 #endif
230 #if ES7202_CHANNELS_MAX > 4
es7202_micboost5_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)231 static int es7202_micboost5_setting_set(struct snd_kcontrol *kcontrol,
232 					struct snd_ctl_elem_value *ucontrol)
233 {
234 	es7202_update_bits(0x1d,
235 			   0x0F,
236 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[2]);
237 	return 0;
238 }
239 
es7202_micboost5_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)240 static int es7202_micboost5_setting_get(struct snd_kcontrol *kcontrol,
241 					struct snd_ctl_elem_value *ucontrol)
242 {
243 	u8 val;
244 	es7202_read(0x1d, &val, i2c_ctl[2]);
245 	ucontrol->value.integer.value[0] = val & 0x0f;
246 	return 0;
247 }
248 
es7202_micboost6_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)249 static int es7202_micboost6_setting_set(struct snd_kcontrol *kcontrol,
250 					struct snd_ctl_elem_value *ucontrol)
251 {
252 	es7202_update_bits(0x1e,
253 			   0x0F,
254 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[2]);
255 	return 0;
256 }
257 
es7202_micboost6_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)258 static int es7202_micboost6_setting_get(struct snd_kcontrol *kcontrol,
259 					struct snd_ctl_elem_value *ucontrol)
260 {
261 	u8 val;
262 	es7202_read(0x1e, &val, i2c_ctl[2]);
263 	ucontrol->value.integer.value[0] = val & 0x0f;
264 	return 0;
265 }
266 #endif
267 
268 #if ES7202_CHANNELS_MAX > 6
es7202_micboost7_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)269 static int es7202_micboost7_setting_set(struct snd_kcontrol *kcontrol,
270 					struct snd_ctl_elem_value *ucontrol)
271 {
272 	es7202_update_bits(0x1d,
273 			   0x0F,
274 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[3]);
275 	return 0;
276 }
277 
es7202_micboost7_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)278 static int es7202_micboost7_setting_get(struct snd_kcontrol *kcontrol,
279 					struct snd_ctl_elem_value *ucontrol)
280 {
281 	u8 val;
282 	es7202_read(0x1d, &val, i2c_ctl[3]);
283 	ucontrol->value.integer.value[0] = val & 0x0f;
284 	return 0;
285 }
286 
es7202_micboost8_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)287 static int es7202_micboost8_setting_set(struct snd_kcontrol *kcontrol,
288 					struct snd_ctl_elem_value *ucontrol)
289 {
290 	es7202_update_bits(0x1e,
291 			   0x0F,
292 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[3]);
293 	return 0;
294 }
295 
es7202_micboost8_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)296 static int es7202_micboost8_setting_get(struct snd_kcontrol *kcontrol,
297 					struct snd_ctl_elem_value *ucontrol)
298 {
299 	u8 val;
300 	es7202_read(0x1e, &val, i2c_ctl[3]);
301 	ucontrol->value.integer.value[0] = val & 0x0f;
302 	return 0;
303 }
304 #endif
305 
306 #if ES7202_CHANNELS_MAX > 8
es7202_micboost9_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)307 static int es7202_micboost9_setting_set(struct snd_kcontrol *kcontrol,
308 					struct snd_ctl_elem_value *ucontrol)
309 {
310 	es7202_update_bits(0x1d,
311 			   0x0F,
312 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[4]);
313 	return 0;
314 }
315 
es7202_micboost9_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)316 static int es7202_micboost9_setting_get(struct snd_kcontrol *kcontrol,
317 					struct snd_ctl_elem_value *ucontrol)
318 {
319 	u8 val;
320 	es7202_read(0x1d, &val, i2c_ctl[4]);
321 	ucontrol->value.integer.value[0] = val & 0x0f;
322 	return 0;
323 }
324 
es7202_micboost10_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)325 static int es7202_micboost10_setting_set(struct snd_kcontrol *kcontrol,
326 					struct snd_ctl_elem_value *ucontrol)
327 {
328 	es7202_update_bits(0x1e,
329 			   0x0F,
330 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[4]);
331 	return 0;
332 }
333 
es7202_micboost10_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)334 static int es7202_micboost10_setting_get(struct snd_kcontrol *kcontrol,
335 					struct snd_ctl_elem_value *ucontrol)
336 {
337 	u8 val;
338 	es7202_read(0x1e, &val, i2c_ctl[4]);
339 	ucontrol->value.integer.value[0] = val & 0x0f;
340 	return 0;
341 }
342 #endif
343 
344 #if ES7202_CHANNELS_MAX > 10
es7202_micboost11_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)345 static int es7202_micboost11_setting_set(struct snd_kcontrol *kcontrol,
346 					struct snd_ctl_elem_value *ucontrol)
347 {
348 	es7202_update_bits(0x1d,
349 			   0x0F,
350 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[5]);
351 	return 0;
352 }
353 
es7202_micboost11_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)354 static int es7202_micboost11_setting_get(struct snd_kcontrol *kcontrol,
355 					struct snd_ctl_elem_value *ucontrol)
356 {
357 	u8 val;
358 	es7202_read(0x1d, &val, i2c_ctl[5]);
359 	ucontrol->value.integer.value[0] = val & 0x0f;
360 	return 0;
361 }
362 
es7202_micboost12_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)363 static int es7202_micboost12_setting_set(struct snd_kcontrol *kcontrol,
364 					struct snd_ctl_elem_value *ucontrol)
365 {
366 	es7202_update_bits(0x1e,
367 			   0x0F,
368 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[5]);
369 	return 0;
370 }
371 
es7202_micboost12_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)372 static int es7202_micboost12_setting_get(struct snd_kcontrol *kcontrol,
373 					struct snd_ctl_elem_value *ucontrol)
374 {
375 	u8 val;
376 	es7202_read(0x1e, &val, i2c_ctl[5]);
377 	ucontrol->value.integer.value[0] = val & 0x0f;
378 	return 0;
379 }
380 #endif
381 
382 #if ES7202_CHANNELS_MAX > 12
es7202_micboost13_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)383 static int es7202_micboost13_setting_set(struct snd_kcontrol *kcontrol,
384 					struct snd_ctl_elem_value *ucontrol)
385 {
386 	es7202_update_bits(0x1d,
387 			   0x0F,
388 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[6]);
389 	return 0;
390 }
391 
es7202_micboost13_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)392 static int es7202_micboost13_setting_get(struct snd_kcontrol *kcontrol,
393 					struct snd_ctl_elem_value *ucontrol)
394 {
395 	u8 val;
396 	es7202_read(0x1d, &val, i2c_ctl[6]);
397 	ucontrol->value.integer.value[0] = val & 0x0f;
398 	return 0;
399 }
400 
es7202_micboost14_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)401 static int es7202_micboost14_setting_set(struct snd_kcontrol *kcontrol,
402 					struct snd_ctl_elem_value *ucontrol)
403 {
404 	es7202_update_bits(0x1e,
405 			   0x0F,
406 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[6]);
407 	return 0;
408 }
409 
es7202_micboost14_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)410 static int es7202_micboost14_setting_get(struct snd_kcontrol *kcontrol,
411 					struct snd_ctl_elem_value *ucontrol)
412 {
413 	u8 val;
414 	es7202_read(0x1e, &val, i2c_ctl[6]);
415 	ucontrol->value.integer.value[0] = val & 0x0f;
416 	return 0;
417 }
418 #endif
419 
420 #if ES7202_CHANNELS_MAX > 14
es7202_micboost15_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)421 static int es7202_micboost15_setting_set(struct snd_kcontrol *kcontrol,
422 					struct snd_ctl_elem_value *ucontrol)
423 {
424 	es7202_update_bits(0x1d,
425 			   0x0F,
426 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[7]);
427 	return 0;
428 }
429 
es7202_micboost15_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)430 static int es7202_micboost15_setting_get(struct snd_kcontrol *kcontrol,
431 					struct snd_ctl_elem_value *ucontrol)
432 {
433 	u8 val;
434 	es7202_read(0x1d, &val, i2c_ctl[7]);
435 	ucontrol->value.integer.value[0] = val & 0x0f;
436 	return 0;
437 }
438 
es7202_micboost16_setting_set(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)439 static int es7202_micboost16_setting_set(struct snd_kcontrol *kcontrol,
440 					struct snd_ctl_elem_value *ucontrol)
441 {
442 	es7202_update_bits(0x1e,
443 			   0x0F,
444 			   ucontrol->value.integer.value[0] & 0x0f, i2c_ctl[7]);
445 	return 0;
446 }
447 
es7202_micboost16_setting_get(struct snd_kcontrol * kcontrol,struct snd_ctl_elem_value * ucontrol)448 static int es7202_micboost16_setting_get(struct snd_kcontrol *kcontrol,
449 					struct snd_ctl_elem_value *ucontrol)
450 {
451 	u8 val;
452 	es7202_read(0x1e, &val, i2c_ctl[7]);
453 	ucontrol->value.integer.value[0] = val & 0x0f;
454 	return 0;
455 }
456 #endif
457 
458 static const struct snd_kcontrol_new es7202_snd_controls[] = {
459 #if ES7202_CHANNELS_MAX > 0
460 	SOC_SINGLE_EXT_TLV("PGA1_setting", 0x1D, 0, 0x0C, 0,
461 			   es7202_micboost1_setting_get,
462 			   es7202_micboost1_setting_set,
463 			   mic_boost_tlv),
464 	SOC_SINGLE_EXT_TLV("PGA2_setting", 0x1E, 0, 0x0C, 0,
465 			   es7202_micboost2_setting_get,
466 			   es7202_micboost2_setting_set,
467 			   mic_boost_tlv),
468 #endif
469 #if ES7202_CHANNELS_MAX > 2
470 	SOC_SINGLE_EXT_TLV("PGA3_setting", 0x1D, 0, 0x0C, 0,
471 			   es7202_micboost3_setting_get,
472 			   es7202_micboost3_setting_set,
473 			   mic_boost_tlv),
474 	SOC_SINGLE_EXT_TLV("PGA4_setting", 0x1E, 0, 0x0C, 0,
475 			   es7202_micboost4_setting_get,
476 			   es7202_micboost4_setting_set,
477 			   mic_boost_tlv),
478 #endif
479 #if ES7202_CHANNELS_MAX > 4
480 	SOC_SINGLE_EXT_TLV("PGA5_setting", 0x1D, 0, 0x0C, 0,
481 			   es7202_micboost5_setting_get,
482 			   es7202_micboost5_setting_set,
483 			   mic_boost_tlv),
484 	SOC_SINGLE_EXT_TLV("PGA6_setting", 0x1E, 0, 0x0C, 0,
485 			   es7202_micboost6_setting_get,
486 			   es7202_micboost6_setting_set,
487 			   mic_boost_tlv),
488 #endif
489 #if ES7202_CHANNELS_MAX > 6
490 	SOC_SINGLE_EXT_TLV("PGA7_setting", 0x1D, 0, 0x0C, 0,
491 			   es7202_micboost7_setting_get,
492 			   es7202_micboost7_setting_set,
493 			   mic_boost_tlv),
494 	SOC_SINGLE_EXT_TLV("PGA8_setting", 0x1E, 0, 0x0C, 0,
495 			   es7202_micboost8_setting_get,
496 			   es7202_micboost8_setting_set,
497 			   mic_boost_tlv),
498 #endif
499 #if ES7202_CHANNELS_MAX > 8
500 	SOC_SINGLE_EXT_TLV("PGA9_setting", 0x1D, 0, 0x0C, 0,
501 			   es7202_micboost9_setting_get,
502 			   es7202_micboost9_setting_set,
503 			   mic_boost_tlv),
504 	SOC_SINGLE_EXT_TLV("PGA10_setting", 0x1E, 0, 0x0C, 0,
505 			   es7202_micboost10_setting_get,
506 			   es7202_micboost10_setting_set,
507 			   mic_boost_tlv),
508 #endif
509 #if ES7202_CHANNELS_MAX > 10
510 	SOC_SINGLE_EXT_TLV("PGA11_setting", 0x1D, 0, 0x0C, 0,
511 			   es7202_micboost11_setting_get,
512 			   es7202_micboost11_setting_set,
513 			   mic_boost_tlv),
514 	SOC_SINGLE_EXT_TLV("PGA12_setting", 0x1E, 0, 0x0C, 0,
515 			   es7202_micboost12_setting_get,
516 			   es7202_micboost12_setting_set,
517 			   mic_boost_tlv),
518 #endif
519 #if ES7202_CHANNELS_MAX > 12
520 	SOC_SINGLE_EXT_TLV("PGA13_setting", 0x1D, 0, 0x0C, 0,
521 			   es7202_micboost13_setting_get,
522 			   es7202_micboost13_setting_set,
523 			   mic_boost_tlv),
524 	SOC_SINGLE_EXT_TLV("PGA14_setting", 0x1E, 0, 0x0C, 0,
525 			   es7202_micboost14_setting_get,
526 			   es7202_micboost14_setting_set,
527 			   mic_boost_tlv),
528 #endif
529 #if ES7202_CHANNELS_MAX > 14
530 	SOC_SINGLE_EXT_TLV("PGA15_setting", 0x1D, 0, 0x0C, 0,
531 			   es7202_micboost15_setting_get,
532 			   es7202_micboost15_setting_set,
533 			   mic_boost_tlv),
534 	SOC_SINGLE_EXT_TLV("PGA16_setting", 0x1E, 0, 0x0C, 0,
535 			   es7202_micboost16_setting_get,
536 			   es7202_micboost16_setting_set,
537 			   mic_boost_tlv),
538 #endif
539 };
540 
es7202_mute(struct snd_soc_dai * dai,int mute,int stream)541 static int es7202_mute(struct snd_soc_dai *dai, int mute, int stream)
542 {
543 	if (stream == SNDRV_PCM_STREAM_PLAYBACK)
544 		return 0;
545 
546 	if (mute) {
547 		es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x03);
548 	} else {
549 		es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x00);
550 	}
551 
552 	return 0;
553 }
554 
555 #define es7202_RATES SNDRV_PCM_RATE_8000_96000
556 
557 static struct snd_soc_dai_ops es7202_ops = {
558 	.mute_stream = es7202_mute,
559 };
560 #if ES7202_CHANNELS_MAX > 0
561 static struct snd_soc_dai_driver es7202_dai0 = {
562 	.name = "es7202 pdm 0",
563 	.capture = {
564 		.stream_name = "Capture",
565 		.channels_min = 1,
566 		.channels_max = 8,
567 		.rates = es7202_RATES,
568 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
569 	},
570 	.ops = &es7202_ops,
571 	.symmetric_rates = 1,
572 };
573 #endif
574 #if ES7202_CHANNELS_MAX > 2
575 static struct snd_soc_dai_driver es7202_dai1 = {
576 	.name = "es7202 pdm 1",
577 	.capture = {
578 		.stream_name = "Capture",
579 		.channels_min = 1,
580 		.channels_max = 8,
581 		.rates = es7202_RATES,
582 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
583 	},
584 	.ops = &es7202_ops,
585 	.symmetric_rates = 1,
586 };
587 #endif
588 #if ES7202_CHANNELS_MAX > 4
589 static struct snd_soc_dai_driver es7202_dai2 = {
590 	.name = "es7202 pdm 2",
591 	.capture = {
592 		.stream_name = "Capture",
593 		.channels_min = 1,
594 		.channels_max = 8,
595 		.rates = es7202_RATES,
596 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
597 	},
598 	.ops = &es7202_ops,
599 	.symmetric_rates = 1,
600 };
601 #endif
602 #if ES7202_CHANNELS_MAX > 6
603 static struct snd_soc_dai_driver es7202_dai3 = {
604 	.name = "es7202 pdm 3",
605 	.capture = {
606 		.stream_name = "Capture",
607 		.channels_min = 1,
608 		.channels_max = 8,
609 		.rates = es7202_RATES,
610 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
611 	},
612 	.ops = &es7202_ops,
613 	.symmetric_rates = 1,
614 };
615 #endif
616 #if ES7202_CHANNELS_MAX > 8
617 static struct snd_soc_dai_driver es7202_dai4 = {
618 	.name = "es7202 pdm 4",
619 	.capture = {
620 		.stream_name = "Capture",
621 		.channels_min = 1,
622 		.channels_max = 10,
623 		.rates = es7202_RATES,
624 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
625 	},
626 	.ops = &es7202_ops,
627 	.symmetric_rates = 1,
628 };
629 #endif
630 #if ES7202_CHANNELS_MAX > 10
631 static struct snd_soc_dai_driver es7202_dai5 = {
632 	.name = "es7202 pdm 5",
633 	.capture = {
634 		.stream_name = "Capture",
635 		.channels_min = 1,
636 		.channels_max = 12,
637 		.rates = es7202_RATES,
638 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
639 	},
640 	.ops = &es7202_ops,
641 	.symmetric_rates = 1,
642 };
643 #endif
644 #if ES7202_CHANNELS_MAX > 12
645 static struct snd_soc_dai_driver es7202_dai6 = {
646 	.name = "es7202 pdm 6",
647 	.capture = {
648 		.stream_name = "Capture",
649 		.channels_min = 1,
650 		.channels_max = 14,
651 		.rates = es7202_RATES,
652 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
653 	},
654 	.ops = &es7202_ops,
655 	.symmetric_rates = 1,
656 };
657 #endif
658 #if ES7202_CHANNELS_MAX > 14
659 static struct snd_soc_dai_driver es7202_dai7 = {
660 	.name = "es7202 pdm 7",
661 	.capture = {
662 		.stream_name = "Capture",
663 		.channels_min = 1,
664 		.channels_max = 16,
665 		.rates = es7202_RATES,
666 		.formats = SNDRV_PCM_FMTBIT_S16_LE,
667 	},
668 	.ops = &es7202_ops,
669 	.symmetric_rates = 1,
670 };
671 #endif
672 
673 static struct snd_soc_dai_driver *es7202_dai[] = {
674 #if ES7202_CHANNELS_MAX > 0
675         &es7202_dai0,
676 #endif
677 #if ES7202_CHANNELS_MAX > 2
678         &es7202_dai1,
679 #endif
680 #if ES7202_CHANNELS_MAX > 4
681         &es7202_dai2,
682 #endif
683 #if ES7202_CHANNELS_MAX > 6
684         &es7202_dai3,
685 #endif
686 #if ES7202_CHANNELS_MAX > 8
687         &es7202_dai4,
688 #endif
689 #if ES7202_CHANNELS_MAX > 10
690         &es7202_dai5,
691 #endif
692 #if ES7202_CHANNELS_MAX > 12
693         &es7202_dai6,
694 #endif
695 #if ES7202_CHANNELS_MAX > 14
696         &es7202_dai7,
697 #endif
698 };
699 
es7202_suspend(struct snd_soc_component * component)700 static int es7202_suspend(struct snd_soc_component *component)
701 {
702 	es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x03);
703 	msleep(50);
704 	return 0;
705 }
706 
es7202_resume(struct snd_soc_component * component)707 static int es7202_resume(struct snd_soc_component *component)
708 {
709 	msleep(50);
710 	es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x00);
711 	return 0;
712 }
713 
es7202_probe(struct snd_soc_component * component)714 static int es7202_probe(struct snd_soc_component *component)
715 {
716 	struct es7202_priv *es7202 = snd_soc_component_get_drvdata(component);
717 	int cnt;
718 	int ret = 0;
719 	printk("enter into %s()\n", __func__);
720 	tron_component1[es7202_adc_num++] = component;
721 
722 	for (cnt = 0; cnt < ADC_DEV_MAXNUM; cnt++) {
723 		es7202_write(ES7202_SOFT_MODE_REG01, 0x01, i2c_ctl[cnt]);
724 		switch(es7202->pwr_vdd_voltage) {
725 		case VDD_3V3:
726 			es7202_write(ES7202_ANALOG_MISC1_REG1B, 0x50, i2c_ctl[cnt]);
727 			es7202_write(ES7202_PGA1_REG1D, 0x1b, i2c_ctl[cnt]);
728 			es7202_write(ES7202_PGA2_REG1E, 0x1b, i2c_ctl[cnt]);
729 			es7202_write(ES7202_ANALOG_EN_REG10, 0x7F, i2c_ctl[cnt]);
730 			es7202_write(ES7202_BIAS_VMID_REG11, 0x2F, i2c_ctl[cnt]);
731 			es7202_write(ES7202_ANALOG_EN_REG10, 0x0F, i2c_ctl[cnt]);
732 			es7202_write(ES7202_ANALOG_EN_REG10, 0x00, i2c_ctl[cnt]);
733 			break;
734 		default:
735 		case VDD_1V8:
736 			es7202_write(ES7202_ANALOG_MISC1_REG1B, 0x40, i2c_ctl[cnt]);
737 			es7202_write(ES7202_PGA1_REG1D, 0x1b, i2c_ctl[cnt]);
738 			es7202_write(ES7202_PGA2_REG1E, 0x1b, i2c_ctl[cnt]);
739 			es7202_write(ES7202_ANALOG_EN_REG10, 0x7F, i2c_ctl[cnt]);
740 			es7202_write(ES7202_BIAS_VMID_REG11, 0x2F, i2c_ctl[cnt]);
741 			es7202_write(ES7202_ANALOG_EN_REG10, 0x3F, i2c_ctl[cnt]);
742 			es7202_write(ES7202_ANALOG_EN_REG10, 0x00, i2c_ctl[cnt]);
743 			break;
744 		}
745 		es7202_write(ES7202_MOD1_BIAS_REG14, 0x58, i2c_ctl[cnt]);
746 		es7202_write(ES7202_CLK_DIV_REG02, 0x01, i2c_ctl[cnt]);
747 		es7202_write(ES7202_T2_VMID_REG05, 0x01, i2c_ctl[cnt]);
748 		es7202_write(ES7202_MISC_CTL_REG08, 0x02, i2c_ctl[cnt]);
749 		es7202_write(ES7202_RESET_REG00, 0x01, i2c_ctl[cnt]);
750 		es7202_write(ES7202_CLK_EN_REG03, 0x03, i2c_ctl[cnt]);
751 		es7202_write(ES7202_BIAS_VMID_REG11, 0x2E, i2c_ctl[cnt]);
752 
753 		es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03, 0x00);
754 	}
755 	return ret;
756 }
757 
es7202_remove(struct snd_soc_component * component)758 static void es7202_remove(struct snd_soc_component *component)
759 {
760 	es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x03);
761 	msleep(50);
762 }
763 
764 const struct regmap_config es7202_regmap_config = {
765 	.reg_bits	= 8,
766 	.val_bits	= 8,
767 	.max_register	= 0xff,
768 	.cache_type	= REGCACHE_RBTREE,
769 	.reg_defaults = es7202_reg_defaults,
770 	.num_reg_defaults = ARRAY_SIZE(es7202_reg_defaults),
771 };
772 
773 static struct snd_soc_component_driver soc_codec_dev_es7202 = {
774 	.probe =	es7202_probe,
775 	.remove =	es7202_remove,
776 	.suspend =	es7202_suspend,
777 	.resume =	es7202_resume,
778 
779 
780 	.controls = es7202_snd_controls,
781 	.num_controls = ARRAY_SIZE(es7202_snd_controls),
782 	.idle_bias_on = 1,
783 	.use_pmdown_time = 1,
784 	.endianness = 1,
785 	.non_legacy_dai_naming = 1,
786 };
787 
es7202_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)788 static ssize_t es7202_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
789 {
790 	int val=0, flag=0;
791 	u8 i=0, reg, num, value_w, value_r;
792 
793 	struct es7202_priv *es7202 = dev_get_drvdata(dev);
794 	val = simple_strtol(buf, NULL, 16);
795 	flag = (val >> 16) & 0xFF;
796 
797 	if (flag) {
798 		reg = (val >> 8) & 0xFF;
799 		value_w = val & 0xFF;
800 		printk("\nWrite: start REG:0x%02x,val:0x%02x,count:0x%02x\n", reg, value_w, flag);
801 		while(flag--) {
802 			es7202_write(reg, value_w,  es7202->i2c);
803 			printk("Write 0x%02x to REG:0x%02x\n", value_w, reg);
804 			reg++;
805 		}
806 	} else {
807 		reg = (val >> 8) & 0xFF;
808 		num = val & 0xff;
809 		printk("\nRead: start REG:0x%02x,count:0x%02x\n", reg, num);
810 		do {
811 			value_r = 0;
812 			es7202_read(reg, &value_r, es7202->i2c);
813 			printk("REG[0x%02x]: 0x%02x;  ", reg, value_r);
814 			reg++;
815 			i++;
816 			if ((i==num) || (i%4==0))	printk("\n");
817 		} while (i<num);
818 	}
819 
820 	return count;
821 }
822 
es7202_show(struct device * dev,struct device_attribute * attr,char * buf)823 static ssize_t es7202_show(struct device *dev, struct device_attribute *attr, char *buf)
824 {
825 	printk("echo flag|reg|val > es7202\n");
826 	printk("eg read star addres=0x06,count 0x10:echo 0610 >es7202\n");
827 	printk("eg write star addres=0x90,value=0x3c,count=4:echo 4903c >es7202\n");
828 	return 0;
829 }
830 
831 static DEVICE_ATTR(es7202, 0644, es7202_show, es7202_store);
832 
833 static struct attribute *es7202_debug_attrs[] = {
834 	&dev_attr_es7202.attr,
835 	NULL,
836 };
837 
838 static struct attribute_group es7202_debug_attr_group = {
839 	.name   = "es7202_debug",
840 	.attrs  = es7202_debug_attrs,
841 };
842 
es7202_i2c_probe(struct i2c_client * i2c,const struct i2c_device_id * id)843 static int es7202_i2c_probe(struct i2c_client *i2c,
844 			    const struct i2c_device_id *id)
845 {
846 	struct es7202_priv *es7202;
847 	int uV;
848 	int ret = -1;
849 
850 	dev_info(&i2c->dev, "probe\n");
851 	es7202 = devm_kzalloc(&i2c->dev, sizeof(*es7202), GFP_KERNEL);
852 	if (!es7202)
853 		return -ENOMEM;
854 	es7202->i2c = i2c;
855 	es7202->vdd = devm_regulator_get_optional(&i2c->dev, "power");
856 	if (IS_ERR(es7202->vdd)) {
857 		if (PTR_ERR(es7202->vdd) == -EPROBE_DEFER)
858 			return -EPROBE_DEFER;
859 		dev_warn(&i2c->dev, "power-supply get fail, use 3v3 as default\n");
860 		es7202->pwr_vdd_voltage = VDD_3V3;
861 	} else {
862 		uV = regulator_get_voltage(es7202->vdd);
863 		dev_info(&i2c->dev, "probe power-supply %duV\n", uV);
864 		if (uV <= MAX_VOLTAGE_1_8)
865 			es7202->pwr_vdd_voltage = VDD_1V8;
866 		else
867 			es7202->pwr_vdd_voltage = VDD_3V3;
868 	}
869 	dev_set_drvdata(&i2c->dev, es7202);
870 	if (id->driver_data < ADC_DEV_MAXNUM) {
871 		i2c_ctl[id->driver_data] = i2c;
872 		dev_info(&i2c->dev, "probe reigister es7202 dai(%s) component\n",
873 			 es7202_dai[id->driver_data]->name);
874 		ret = devm_snd_soc_register_component(&i2c->dev, &soc_codec_dev_es7202,
875 						      es7202_dai[id->driver_data], 1);
876 		if (ret < 0) {
877 			return ret;
878 		}
879 	}
880 	ret = sysfs_create_group(&i2c->dev.kobj, &es7202_debug_attr_group);
881 	if (ret) {
882 		dev_err(&i2c->dev, "failed to create attr group\n");
883 	}
884 	return ret;
885 }
886 
es7202_i2c_remove(struct i2c_client * client)887 static  int es7202_i2c_remove(struct i2c_client *client)
888 {
889 	sysfs_remove_group(&client->dev.kobj, &es7202_debug_attr_group);
890 
891 	return 0;
892 }
893 
es7202_i2c_shutdown(struct i2c_client * client)894 static void es7202_i2c_shutdown(struct i2c_client *client)
895 {
896 	es7202_multi_chips_update_bits(ES7202_PDM_INF_CTL_REG07, 0x03,0x03);
897 	msleep(50);
898 }
899 
900 #if !ES7202_MATCH_DTS_EN
es7202_i2c_detect(struct i2c_client * client,struct i2c_board_info * info)901 static int es7202_i2c_detect(struct i2c_client *client,
902 			     struct i2c_board_info *info)
903 {
904 	struct i2c_adapter *adapter = client->adapter;
905 
906 	if (adapter->nr == ES7202_I2C_BUS_NUM) {
907 		if (client->addr == 0x30) {
908 			strlcpy(info->type, "ES7202_PDM_ADC_1", I2C_NAME_SIZE);
909 			return 0;
910 		} else if (client->addr == 0x31) {
911 			strlcpy(info->type, "ES7202_PDM_ADC_2", I2C_NAME_SIZE);
912 			return 0;
913 		} else if (client->addr == 0x32) {
914 			strlcpy(info->type, "ES7202_PDM_ADC_3", I2C_NAME_SIZE);
915 			return 0;
916 		} else if (client->addr == 0x33) {
917 			strlcpy(info->type, "ES7202_PDM_ADC_4", I2C_NAME_SIZE);
918 			return 0;
919 		}else if (client->addr == 0x34) {
920 			strlcpy(info->type, "ES7202_PDM_ADC_5", I2C_NAME_SIZE);
921 			return 0;
922 		}else if (client->addr == 0x35) {
923 			strlcpy(info->type, "ES7202_PDM_ADC_6", I2C_NAME_SIZE);
924 			return 0;
925 		}else if (client->addr == 0x36) {
926 			strlcpy(info->type, "ES7202_PDM_ADC_7", I2C_NAME_SIZE);
927 			return 0;
928 		}else if (client->addr == 0x37) {
929 			strlcpy(info->type, "ES7202_PDM_ADC_8", I2C_NAME_SIZE);
930 			return 0;
931 		}
932 	}
933 
934 	return -ENODEV;
935 }
936 
937 static const unsigned short es7202_i2c_addr[] = {
938 #if ES7202_CHANNELS_MAX > 0
939 	0x30,
940 #endif
941 
942 #if ES7202_CHANNELS_MAX > 2
943 	0x31,
944 #endif
945 
946 #if ES7202_CHANNELS_MAX > 4
947 	0x32,
948 #endif
949 
950 #if ES7202_CHANNELS_MAX > 6
951 	0x33,
952 #endif
953 
954 #if ES7202_CHANNELS_MAX > 8
955 	0x34,
956 #endif
957 
958 #if ES7202_CHANNELS_MAX > 10
959 	0x35,
960 #endif
961 
962 #if ES7202_CHANNELS_MAX > 12
963 	0x36,
964 #endif
965 
966 #if ES7202_CHANNELS_MAX > 14
967 	0x37,
968 #endif
969 	I2C_CLIENT_END,
970 };
971 #endif
972 
973 #if ES7202_MATCH_DTS_EN
974 /*
975 * device tree source or i2c_board_info both use to
976 * transfer hardware information to linux kernel,
977 * use one of them wil be OK
978 */
979 #if 0
980 static struct i2c_board_info es7202_i2c_board_info[] = {
981 #if ES7202_CHANNELS_MAX > 0
982 	{I2C_BOARD_INFO("ES7202_PDM_ADC_1", 0x30),},
983 #endif
984 
985 #if ES7202_CHANNELS_MAX > 2
986 	{I2C_BOARD_INFO("ES7202_PDM_ADC_2", 0x31),},
987 #endif
988 
989 #if ES7202_CHANNELS_MAX > 4
990 	{I2C_BOARD_INFO("ES7202_PDM_ADC_3", 0x32),},
991 #endif
992 
993 #if ES7202_CHANNELS_MAX > 6
994 	{I2C_BOARD_INFO("ES7202_PDM_ADC_4", 0x33),},
995 #endif
996 
997 #if ES7202_CHANNELS_MAX > 8
998 	{I2C_BOARD_INFO("ES7202_PDM_ADC_5", 0x34),},
999 #endif
1000 
1001 #if ES7202_CHANNELS_MAX > 10
1002 	{I2C_BOARD_INFO("ES7202_PDM_ADC_6", 0x35),},
1003 #endif
1004 
1005 #if ES7202_CHANNELS_MAX > 12
1006 	{I2C_BOARD_INFO("ES7202_PDM_ADC_7", 0x36),},
1007 #endif
1008 
1009 #if ES7202_CHANNELS_MAX > 14
1010 	{I2C_BOARD_INFO("ES7202_PDM_ADC_8", 0x37),},
1011 #endif
1012 };
1013 #endif
1014 static const struct of_device_id es7202_dt_ids[] = {
1015 #if ES7202_CHANNELS_MAX > 0
1016 	{.compatible = "ES7202_PDM_ADC_1",},
1017 #endif
1018 
1019 #if ES7202_CHANNELS_MAX > 2
1020 	{.compatible = "ES7202_PDM_ADC_2",},
1021 #endif
1022 
1023 #if ES7202_CHANNELS_MAX > 4
1024 	{.compatible = "ES7202_PDM_ADC_3",},
1025 #endif
1026 
1027 #if ES7202_CHANNELS_MAX > 6
1028 	{.compatible = "ES7202_PDM_ADC_4",},
1029 #endif
1030 
1031 #if ES7202_CHANNELS_MAX > 8
1032 	{.compatible = "ES7202_PDM_ADC_5",},
1033 #endif
1034 
1035 #if ES7202_CHANNELS_MAX > 10
1036 	{.compatible = "ES7202_PDM_ADC_6",},
1037 #endif
1038 
1039 #if ES7202_CHANNELS_MAX > 12
1040 	{.compatible = "ES7202_PDM_ADC_7",},
1041 #endif
1042 
1043 #if ES7202_CHANNELS_MAX > 14
1044 	{.compatible = "ES7202_PDM_ADC_8",},
1045 #endif
1046 	{}
1047 };
1048 #endif
1049 
1050 static const struct i2c_device_id es7202_i2c_id[] = {
1051 #if ES7202_CHANNELS_MAX > 0
1052 	{"ES7202_PDM_ADC_1", 0},
1053 #endif
1054 
1055 #if ES7202_CHANNELS_MAX > 2
1056 	{"ES7202_PDM_ADC_2", 1},
1057 #endif
1058 
1059 #if ES7202_CHANNELS_MAX > 4
1060 	{"ES7202_PDM_ADC_3", 2},
1061 #endif
1062 
1063 #if ES7202_CHANNELS_MAX > 6
1064 	{"ES7202_PDM_ADC_4", 3},
1065 #endif
1066 
1067 #if ES7202_CHANNELS_MAX > 8
1068 	{"ES7202_PDM_ADC_5", 4},
1069 #endif
1070 
1071 #if ES7202_CHANNELS_MAX > 10
1072 	{"ES7202_PDM_ADC_6", 5},
1073 #endif
1074 
1075 #if ES7202_CHANNELS_MAX > 12
1076 	{"ES7202_PDM_ADC_7", 6},
1077 #endif
1078 
1079 #if ES7202_CHANNELS_MAX > 14
1080 	{"ES7202_PDM_ADC_8", 7},
1081 #endif
1082 	{}
1083 };
1084 
1085 static struct i2c_driver es7202_i2c_driver = {
1086 	.driver = {
1087 		.name		= "es7202",
1088 #if ES7202_MATCH_DTS_EN
1089 		   .of_match_table = es7202_dt_ids,
1090 #endif
1091 	},
1092 	.probe    = es7202_i2c_probe,
1093 	.remove   = es7202_i2c_remove,
1094 	.shutdown = es7202_i2c_shutdown,
1095 	.class = I2C_CLASS_HWMON,
1096 	.id_table = es7202_i2c_id,
1097 #if !ES7202_MATCH_DTS_EN
1098 	.address_list = es7202_i2c_addr,
1099 	.detect = es7202_i2c_detect,
1100 #endif
1101 };
1102 
es7202_modinit(void)1103 static int __init es7202_modinit(void)
1104 {
1105 	int ret;
1106 //#if ES7202_MATCH_DTS_EN
1107 #if 0
1108 	int i;
1109 	struct i2c_adapter *adapter;
1110 	struct i2c_client *client;
1111 #endif
1112 
1113 //#if ES7202_MATCH_DTS_EN
1114 #if 0
1115 /*
1116 * Notes:
1117 * if the device has been declared in DTS tree,
1118 * here don't need to create new i2c device with i2c_board_info.
1119 */
1120 	adapter = i2c_get_adapter(ES7202_I2C_BUS_NUM);
1121 	if (!adapter) {
1122 		printk("i2c_get_adapter() fail!\n");
1123 		return -ENODEV;
1124 	}
1125 	printk("%s() begin0000", __func__);
1126 
1127 	for (i = 0; i < ADC_DEV_MAXNUM; i++) {
1128 		client = i2c_new_device(adapter, &es7202_i2c_board_info[i]);
1129 		printk("%s() i2c_new_device\n", __func__);
1130 		if (!client)
1131 			return -ENODEV;
1132 	}
1133 	i2c_put_adapter(adapter);
1134 #endif
1135 	ret = i2c_add_driver(&es7202_i2c_driver);
1136 	if (ret != 0)
1137 		printk("Failed to register es7202 i2c driver : %d \n", ret);
1138 	return ret;
1139 }
1140 
1141 late_initcall(es7202_modinit);
1142 //module_init(es7202_modinit);
es7202_exit(void)1143 static void __exit es7202_exit(void)
1144 {
1145 	i2c_del_driver(&es7202_i2c_driver);
1146 }
1147 
1148 module_exit(es7202_exit);
1149 
1150 MODULE_DESCRIPTION("ASoC es7202 pdm adc driver");
1151 MODULE_AUTHOR(" David Yang, <yangxiaohua@everest-semi.com>>");
1152 MODULE_LICENSE("GPL v2");
1153