2 * wm8994.c -- WM8994 ALSA SoC audio driver
4 * Copyright 2009 Wolfson Microelectronics plc
5 * Copyright 2005 Openedhand Ltd.
7 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
19 #include <linux/i2c.h>
20 #include <linux/spi/spi.h>
21 #include <linux/platform_device.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/tlv.h>
26 #include <sound/soc.h>
27 #include <sound/soc-dapm.h>
28 #include <sound/initval.h>
30 #include <mach/iomux.h>
31 #include <mach/gpio.h>
34 #include <linux/miscdevice.h>
35 #include <linux/circ_buf.h>
36 //#include <mach/spi_fpga.h>
40 #include <linux/proc_fs.h>
41 #include <linux/seq_file.h>
42 #include <linux/vmalloc.h>
45 #define CONFIG_SND_BB_NORMAL_INPUT
46 #define CONFIG_SND_INSIDE_EARPIECE
47 /* If digital BB is used,open this define. */
50 /* Define what kind of digital BB is used. */
55 //#define THINKWILL_M800_MODE
59 #define DBG(x...) printk(KERN_INFO x)
61 #define DBG(x...) do { } while (0)
64 #define wm8994_mic_VCC 0x0010
65 #define WM8994_DELAY 50
67 struct i2c_client *wm8994_client;
68 bool first_incall = false, isWM8994SetChannel = true, isSetChannelErr = false;
69 struct workqueue_struct *wm8994_workqueue;
70 struct work_struct wm8994_work;
71 struct timer_list wm8994_timer;
72 int reg_send_data(struct i2c_client *client, unsigned short *reg, unsigned short *data, u32 scl_rate);
73 int reg_recv_data(struct i2c_client *client, unsigned short *reg, unsigned short *buf, u32 scl_rate);
74 void wm8994_set_volume(unsigned char wm8994_mode,unsigned char volume,unsigned char max_volume);
75 void wm8994_set_channel_vol(void);
76 //extern bool isHSKey_MIC(void);
78 enum wm8994_codec_mode
81 wm8994_AP_to_speakers,
82 wm8994_AP_to_speakers_and_headset,
83 wm8994_recorder_and_AP_to_headset,
84 wm8994_recorder_and_AP_to_speakers,
86 wm8994_FM_to_headset_and_record,
87 wm8994_FM_to_speakers,
88 wm8994_FM_to_speakers_and_record,
89 wm8994_handsetMIC_to_baseband_to_headset,
90 wm8994_mainMIC_to_baseband_to_headset,
91 wm8994_handsetMIC_to_baseband_to_headset_and_record,
92 wm8994_mainMIC_to_baseband_to_earpiece,
93 wm8994_mainMIC_to_baseband_to_earpiece_and_record,
94 wm8994_mainMIC_to_baseband_to_speakers,
95 wm8994_mainMIC_to_baseband_to_speakers_and_record,
97 wm8994_BT_baseband_and_record,
101 /* wm8994_current_mode:save current wm8994 mode */
102 unsigned char wm8994_current_mode=null;
104 enum stream_type_wm8994
110 /* For voice device route set, add by phc */
111 enum VoiceDeviceSwitch
122 BLUETOOTH_SCO_INCALL,
123 BLUETOOTH_SCO_NORMAL,
125 BLUETOOTH_A2DP_INCALL,
126 BLUETOOTH_A2DP_NORMAL,
139 char wm8994_current_route = SPEAKER_NORMAL;
140 char debug_write_read = 0;
143 #define WM_EN_PIN RK29_PIN5_PA1
144 #define call_maxvol 5
145 #define BT_call_maxvol 15
147 /* call_vol: save all kinds of system volume value. */
148 unsigned char call_vol = 5, BT_call_vol = 15;
150 unsigned short headset_vol_table[6] ={0x012D,0x0133,0x0136,0x0139,0x013B,0x013D};
151 unsigned short speakers_vol_table[6] ={0x012D,0x0133,0x0136,0x0139,0x013B,0x013D};
152 #ifdef CONFIG_RAHO_CTA
153 unsigned short earpiece_vol_table[6] ={0x0127,0x012D,0x0130,0x0135,0x0137,0x0135};//for cta
155 unsigned short earpiece_vol_table[6] ={0x0127,0x012D,0x0130,0x0135,0x0139,0x013D};//normal
157 unsigned short BT_vol_table[16] ={0x01DB,0x01DC,0x01DD,0x01DE,0x01DF,0x01E0,
158 0x01E1,0x01E2,0x01E3,0x01E4,0x01E5,0x01E6,
159 0x01E7,0x01E8,0x01E9,0x01EA};
161 int speaker_incall_vol = 0,//CONFIG_WM8994_SPEAKER_INCALL_VOL
162 speaker_incall_mic_vol = -9,//CONFIG_WM8994_SPEAKER_INCALL_MIC_VOL
163 speaker_normal_vol = 6,//CONFIG_WM8994_SPEAKER_NORMAL_VOL,
164 earpiece_incall_vol = 0,//CONFIG_WM8994_EARPIECE_INCALL_VOL
165 headset_incall_vol = 6,//CONFIG_WM8994_HEADSET_INCALL_VOL
166 headset_incall_mic_vol = -6,//CONFIG_WM8994_HEADSET_INCALL_MIC_VOL
167 headset_normal_vol = 6,//CONFIG_WM8994_HEADSET_NORMAL_VOL,
168 BT_incall_vol = 0,//CONFIG_WM8994_BT_INCALL_VOL,
169 BT_incall_mic_vol = 0,//CONFIG_WM8994_BT_INCALL_MIC_VOL,
170 recorder_vol = 50,//CONFIG_WM8994_RECORDER_VOL,
171 bank_vol[6] = {0,0,-3,3,-6,3};
174 * wm8994 register cache
175 * We can't read the WM8994 register space when we
176 * are using 2 wire for device control, so we cache them instead.
178 static const u16 wm8994_reg[] = {
179 0x0097, 0x0097, 0x0079, 0x0079, /* 0 */
180 0x0000, 0x0008, 0x0000, 0x000a, /* 4 */
181 0x0000, 0x0000, 0x00ff, 0x00ff, /* 8 */
182 0x000f, 0x000f, 0x0000, 0x0000, /* 12 */
183 0x0000, 0x007b, 0x0000, 0x0032, /* 16 */
184 0x0000, 0x00c3, 0x00c3, 0x00c0, /* 20 */
185 0x0000, 0x0000, 0x0000, 0x0000, /* 24 */
186 0x0000, 0x0000, 0x0000, 0x0000, /* 28 */
187 0x0000, 0x0000, 0x0050, 0x0050, /* 32 */
188 0x0050, 0x0050, 0x0050, 0x0050, /* 36 */
189 0x0079, 0x0079, 0x0079, /* 40 */
192 /* codec private data */
195 struct snd_soc_codec codec;
196 struct snd_pcm_hw_constraint_list *sysclk_constraints;
197 u16 reg_cache[WM8994_NUM_REG];
200 bool wm8994_set_status(void)
202 return isWM8994SetChannel;
205 EXPORT_SYMBOL_GPL(wm8994_set_status);
207 static int wm8994_read(unsigned short reg,unsigned short *value)
209 unsigned short regs=((reg>>8)&0x00FF)|((reg<<8)&0xFF00),values;
212 if(isSetChannelErr)return -EIO;
217 if (reg_recv_data(wm8994_client,®s,&values,400000) > 0)
219 *value=((values>>8)& 0x00FF)|((values<<8)&0xFF00);
221 if(debug_write_read != 0)
222 DBG("%s:0x%04x = 0x%04x",__FUNCTION__,reg,*value);
227 isSetChannelErr = true;
229 printk("%s---line->%d:Codec read error! reg = 0x%x , value = 0x%x\n",__FUNCTION__,__LINE__,reg,*value);
234 static int wm8994_write(unsigned short reg,unsigned short value)
236 unsigned short regs=((reg>>8)&0x00FF)|((reg<<8)&0xFF00),values=((value>>8)&0x00FF)|((value<<8)&0xFF00);
239 if(isSetChannelErr)return -EIO;
241 if(debug_write_read != 0)
242 DBG("%s:0x%04x = 0x%04x\n",__FUNCTION__,reg,value);
247 if (reg_send_data(wm8994_client,®s,&values,400000) > 0)
251 wm8994_read(0x406, &values);
252 wm8994_write(0x406, values);
253 wm8994_read(reg, &values);
255 DBG("read 0x302 = 0x%x write 0x302 = 0x%x \n", values, value);
258 isSetChannelErr = true;
263 isSetChannelErr = true;
265 printk("%s---line->%d:Codec write error! reg = 0x%x , value = 0x%x\n",__FUNCTION__,__LINE__,reg,value);
270 void wm8994_work_handler(struct work_struct *work)
272 DBG("Enter::wm8994 work handler\n");
273 if(wm8994_current_mode==wm8994_BT_baseband){
274 wm8994_write(0x602, 0x0001);
276 wm8994_write(0x601, 0x0001);
277 wm8994_write(0x602, 0x0001);
281 static void wm8994_codec_timer(unsigned long data)
283 DBG("Enter::wm8994 timer\n");
285 DBG("first_incall set 0x601 0x602\n");
286 queue_work(wm8994_workqueue, &wm8994_work);
287 first_incall = false;
291 static void wm8994_codec_first_incall(void)
293 if(wm8994_current_mode==wm8994_AP_to_speakers_and_headset||
294 wm8994_current_mode==wm8994_recorder_and_AP_to_headset||
295 wm8994_current_mode==wm8994_recorder_and_AP_to_speakers){
297 wm8994_timer.expires = jiffies + msecs_to_jiffies(1500);//1s
298 add_timer(&wm8994_timer);
302 static void wm8994_set_all_mute(void)
309 for (i = call_vol; i >= 0; i--)
310 wm8994_set_volume(null,i,call_maxvol);
314 static void wm8994_set_level_volume(void)
318 for (i = 0; i <= call_vol; i++)
319 wm8994_set_volume(wm8994_current_mode,i,call_maxvol);
323 #define wm8994_reset() wm8994_set_all_mute();\
324 wm8994_write(WM8994_RESET, 0)
327 void AP_to_headset(void)
329 DBG("%s::%d\n",__FUNCTION__,__LINE__);
331 if(wm8994_current_mode==wm8994_AP_to_headset)return;
332 wm8994_current_mode=wm8994_AP_to_headset;
334 msleep(WM8994_DELAY);
336 wm8994_write(0x700, 0xA101);
337 wm8994_write(0x01, 0x0023);
338 wm8994_write(0x200, 0x0000);
339 mdelay(WM8994_DELAY);
341 wm8994_write(0x220, 0x0000);
342 wm8994_write(0x221, 0x0700);
343 wm8994_write(0x222, 0x3126);
344 wm8994_write(0x223, 0x0100);
346 wm8994_write(0x220, 0x0004);
348 wm8994_write(0x220, 0x0005);
351 wm8994_write(0x200, 0x0010);
352 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
353 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
354 wm8994_write(0x210, 0x0083); // SR=48KHz
355 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
356 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
357 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
358 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
359 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
360 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
361 wm8994_write(0x300, 0x4010); // i2s 16 bits
363 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
365 wm8994_write(0x04, 0x0303); // AIF1ADC1L_ENA=1, AIF1ADC1R_ENA=1, ADCL_ENA=1, ADCR_ENA=1/ q
366 wm8994_write(0x05, 0x0303);
367 wm8994_write(0x2D, 0x0100);
368 wm8994_write(0x2E, 0x0100);
370 wm8994_write(0x4C, 0x9F25);
372 wm8994_write(0x01, 0x0323);
374 wm8994_write(0x60, 0x0022);
375 wm8994_write(0x60, 0x00FF);
377 wm8994_write(0x420, 0x0000);
378 wm8994_write(0x601, 0x0001);
379 wm8994_write(0x602, 0x0001);
381 wm8994_write(0x610, 0x01A0); //DAC1 Left Volume bit0~7
382 wm8994_write(0x611, 0x01A0); //DAC1 Right Volume bit0~7
383 wm8994_write(0x03, 0x3030);
384 wm8994_write(0x22, 0x0000);
385 wm8994_write(0x23, 0x0100);
386 wm8994_write(0x36, 0x0003);
387 wm8994_write(0x1C, 0x017F); //HPOUT1L Volume
388 wm8994_write(0x1D, 0x017F); //HPOUT1R Volume
391 void AP_to_speakers(void)
393 DBG("%s::%d\n",__FUNCTION__,__LINE__);
395 if(wm8994_current_mode==wm8994_AP_to_speakers)return;
396 wm8994_current_mode=wm8994_AP_to_speakers;
399 msleep(WM8994_DELAY);
401 // wm8994_write(0x700, 0xA101);
402 // wm8994_write(0x39, 0x006C);
403 wm8994_write(0x01, 0x0023);
404 wm8994_write(0x200, 0x0000);
405 mdelay(WM8994_DELAY);
407 wm8994_write(0x220, 0x0000);
408 wm8994_write(0x221, 0x0700);
409 wm8994_write(0x222, 0x3126);
410 wm8994_write(0x223, 0x0100);
412 wm8994_write(0x220, 0x0004);
414 wm8994_write(0x220, 0x0005);
417 wm8994_write(0x200, 0x0010);
418 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
419 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
420 wm8994_write(0x210, 0x0083); // SR=48KHz
421 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
422 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
423 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
424 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
425 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
426 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
427 wm8994_write(0x300, 0xC010); // i2s 16 bits
429 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
431 wm8994_write(0x01, 0x3023);
432 wm8994_write(0x03, 0x0330);
433 wm8994_write(0x05, 0x0303);
434 wm8994_write(0x22, 0x0000);
435 wm8994_write(0x23, 0x0100);
436 wm8994_write(0x2D, 0x0001);
437 wm8994_write(0x2E, 0x0000);
438 wm8994_write(0x36, 0x000C);
439 wm8994_write(0x4C, 0x9F25);
440 wm8994_write(0x60, 0x00EE);
441 wm8994_write(0x420, 0x0000);
443 wm8994_write(0x601, 0x0001);
444 wm8994_write(0x602, 0x0001);
446 wm8994_write(0x610, 0x01c0); //DAC1 Left Volume bit0~7
447 wm8994_write(0x611, 0x01c0); //DAC1 Right Volume bit0~7
449 wm8994_write(0x26, 0x017F); //Speaker Left Output Volume
450 wm8994_write(0x27, 0x017F); //Speaker Right Output Volume
453 void AP_to_speakers_and_headset(void)
455 DBG("%s::%d\n",__FUNCTION__,__LINE__);
456 if(wm8994_current_mode==wm8994_AP_to_speakers_and_headset)return;
457 wm8994_current_mode=wm8994_AP_to_speakers_and_headset;
459 mdelay(WM8994_DELAY);
461 wm8994_write(0x700, 0xA101);
462 wm8994_write(0x39, 0x006C);
463 wm8994_write(0x01, 0x0023);
464 wm8994_write(0x200, 0x0000);
465 mdelay(WM8994_DELAY);
467 wm8994_write(0x220, 0x0000);
468 wm8994_write(0x221, 0x0700);
469 wm8994_write(0x222, 0x3126);
470 wm8994_write(0x223, 0x0100);
472 wm8994_write(0x220, 0x0004);
474 wm8994_write(0x220, 0x0005);
477 wm8994_write(0x200, 0x0010);
478 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
479 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
480 wm8994_write(0x210, 0x0083); // SR=48KHz
481 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
482 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
483 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
484 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
485 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
486 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
487 wm8994_write(0x300, 0xC010); // i2s 16 bits
489 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
491 wm8994_write(0x610, 0x0100); //DAC1 Left Volume bit0~7
492 wm8994_write(0x611, 0x0100); //DAC1 Right Volume bit0~7
494 // wm8994_write(0x24, 0x0011);
495 wm8994_set_channel_vol();
496 //wm8994_write(0x25, 0x003F);
498 wm8994_write(0x04, 0x0303); // AIF1ADC1L_ENA=1, AIF1ADC1R_ENA=1, ADCL_ENA=1, ADCR_ENA=1
499 wm8994_write(0x05, 0x0303);
500 wm8994_write(0x2D, 0x0100);
501 wm8994_write(0x2E, 0x0100);
503 wm8994_write(0x4C, 0x9F25);
505 wm8994_write(0x01, 0x3303);
507 wm8994_write(0x60, 0x0022);
508 wm8994_write(0x60, 0x00EE);
510 wm8994_write(0x420, 0x0000);
512 wm8994_write(0x601, 0x0001);
513 wm8994_write(0x602, 0x0001);
515 wm8994_write(0x03, 0x3330);
516 wm8994_write(0x22, 0x0000);
517 wm8994_write(0x23, 0x0100);
518 wm8994_write(0x36, 0x0003);
519 wm8994_write(0x01, 0x3323);
521 wm8994_write(0x610, 0x01C0); //DAC1 Left Volume bit0~7
522 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
525 void recorder_and_AP_to_headset(void)
527 DBG("%s::%d\n",__FUNCTION__,__LINE__);
529 if(wm8994_current_mode==wm8994_recorder_and_AP_to_headset)return;
530 wm8994_current_mode=wm8994_recorder_and_AP_to_headset;
532 msleep(WM8994_DELAY);
534 wm8994_write(0x700, 0xA101);
535 wm8994_write(0x01, 0x0023);
536 wm8994_write(0x200, 0x0000);
537 mdelay(WM8994_DELAY);
539 wm8994_write(0x220, 0x0000);
540 wm8994_write(0x221, 0x0700);
541 wm8994_write(0x222, 0x3126);
542 wm8994_write(0x223, 0x0100);
544 wm8994_write(0x220, 0x0004);
546 wm8994_write(0x220, 0x0005);
549 wm8994_write(0x200, 0x0010);
550 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
551 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
552 wm8994_write(0x210, 0x0083); // SR=48KHz
553 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
554 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
555 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
556 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
557 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
558 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
559 wm8994_write(0x300, 0xC050); // i2s 16 bits
561 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
563 wm8994_write(0x610, 0x0100); // DAC1_VU=1, DAC1L_VOL=1100_0000
564 wm8994_write(0x611, 0x0100); // DAC1_VU=1, DAC1R_VOL=1100_0000
566 wm8994_set_channel_vol();
567 //wm8994_write(0x25, 0x003F);
568 wm8994_write(0x28, 0x0003); // IN1RP_TO_IN1R=1, IN1RN_TO_IN1R=1
569 wm8994_write(0x606, 0x0002); // ADC1L_TO_AIF1ADC1L=1
570 wm8994_write(0x607, 0x0002); // ADC1R_TO_AIF1ADC1R=1
571 wm8994_write(0x620, 0x0000);
573 wm8994_write(0x402, 0x01FF); // AIF1ADC1L_VOL [7:0]
574 wm8994_write(0x403, 0x01FF); // AIF1ADC1R_VOL [7:0]
575 wm8994_write(0x440, 0x01BF);
576 wm8994_write(0x450, 0x01BF);
577 wm8994_write(0x2D, 0x0100); // DAC1L_TO_HPOUT1L=1
578 wm8994_write(0x2E, 0x0100); // DAC1R_TO_HPOUT1R=1
580 wm8994_write(0x4C, 0x9F25);
582 wm8994_write(0x01, 0x3303);
584 wm8994_write(0x60, 0x0022);
585 wm8994_write(0x60, 0x00FF);
587 wm8994_write(0x02, 0x6110); // TSHUT_ENA=1, TSHUT_OPDIS=1, MIXINR_ENA=1,IN1R_ENA=1
588 wm8994_write(0x03, 0x3030);
589 wm8994_write(0x04, 0x0303); // AIF1ADC1L_ENA=1, AIF1ADC1R_ENA=1, ADCL_ENA=1, ADCR_ENA=1
590 wm8994_write(0x05, 0x0303); // AIF1DAC1L_ENA=1, AIF1DAC1R_ENA=1, DAC1L_ENA=1, DAC1R_ENA=1
591 wm8994_write(0x420, 0x0000);
593 wm8994_write(0x01, 0x0333);
595 wm8994_write(0x601, 0x0001); // AIF1DAC1L_TO_DAC1L=1
596 wm8994_write(0x602, 0x0001); // AIF1DAC1R_TO_DAC1R=1
597 wm8994_write(0x610, 0x01A0); // DAC1_VU=1, DAC1L_VOL=1100_0000
598 wm8994_write(0x611, 0x01A0); // DAC1_VU=1, DAC1R_VOL=1100_0000
601 void recorder_and_AP_to_speakers(void)
603 DBG("%s::%d\n",__FUNCTION__,__LINE__);
605 if(wm8994_current_mode==wm8994_recorder_and_AP_to_speakers)return;
606 wm8994_current_mode=wm8994_recorder_and_AP_to_speakers;
608 msleep(WM8994_DELAY);
610 wm8994_write(0x700, 0xA101);
611 wm8994_write(0x39, 0x006C);
612 wm8994_write(0x01, 0x0023);
613 wm8994_write(0x200, 0x0000);
614 mdelay(WM8994_DELAY);
616 wm8994_write(0x220, 0x0000);
617 wm8994_write(0x221, 0x0700);
618 wm8994_write(0x222, 0x3126);
619 wm8994_write(0x223, 0x0100);
621 wm8994_write(0x220, 0x0004);
623 wm8994_write(0x220, 0x0005);
626 wm8994_write(0x200, 0x0010);
627 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
628 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
629 wm8994_write(0x210, 0x0083); // SR=48KHz
630 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
631 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
632 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
633 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
634 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
635 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
636 wm8994_write(0x300, 0xC050); // i2s 16 bits
638 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
640 wm8994_write(0x610, 0x0100); // DAC1_VU=1, DAC1L_VOL=1100_0000
641 wm8994_write(0x611, 0x0100); // DAC1_VU=1, DAC1R_VOL=1100_0000
642 wm8994_set_channel_vol();
643 // wm8994_write(0x24, 0x001f);
644 //wm8994_write(0x25, 0x003F);
646 wm8994_write(0x02, 0x6110); // TSHUT_ENA=1, TSHUT_OPDIS=1, MIXINR_ENA=1,IN1R_ENA=1
647 wm8994_write(0x04, 0x0303); // AIF1ADC1L_ENA=1, AIF1ADC1R_ENA=1, ADCL_ENA=1, ADCR_ENA=1
648 wm8994_write(0x28, 0x0003); // IN1RP_TO_IN1R=1, IN1RN_TO_IN1R=1
650 wm8994_write(0x606, 0x0002); // ADC1L_TO_AIF1ADC1L=1
651 wm8994_write(0x607, 0x0002); // ADC1R_TO_AIF1ADC1R=1
652 wm8994_write(0x620, 0x0000);
654 wm8994_write(0x402, 0x01FF); // AIF1ADC1L_VOL [7:0]
655 wm8994_write(0x403, 0x01FF); // AIF1ADC1R_VOL [7:0]
657 wm8994_write(0x03, 0x0330); // SPKRVOL_ENA=1, SPKLVOL_ENA=1, MIXOUTL_ENA=1, MIXOUTR_ENA=1
658 wm8994_write(0x05, 0x0303); // AIF1DAC1L_ENA=1, AIF1DAC1R_ENA=1, DAC1L_ENA=1, DAC1R_ENA=1
659 wm8994_write(0x22, 0x0000);
660 wm8994_write(0x23, 0x0100); // SPKOUT_CLASSAB=1
662 wm8994_write(0x2D, 0x0001); // DAC1L_TO_MIXOUTL=1
663 wm8994_write(0x2E, 0x0001); // DAC1R_TO_MIXOUTR=1
664 wm8994_write(0x4C, 0x9F25);
665 wm8994_write(0x60, 0x00EE);
666 wm8994_write(0x36, 0x000C); // MIXOUTL_TO_SPKMIXL=1, MIXOUTR_TO_SPKMIXR=1
667 wm8994_write(0x440, 0x01BF);
668 wm8994_write(0x450, 0x01BF);
669 wm8994_write(0x610, 0x01C0); // DAC1_VU=1, DAC1L_VOL=1100_0000
670 wm8994_write(0x611, 0x01C0); // DAC1_VU=1, DAC1R_VOL=1100_0000
671 wm8994_write(0x601, 0x0001); // AIF1DAC1L_TO_DAC1L=1
672 wm8994_write(0x602, 0x0001); // AIF1DAC1R_TO_DAC1R=1
673 wm8994_write(0x420, 0x0000);
674 wm8994_write(0x01, 0x3003);
676 wm8994_write(0x01, 0x3033);
679 void FM_to_headset(void)
681 DBG("%s::%d\n",__FUNCTION__,__LINE__);
683 if(wm8994_current_mode == wm8994_FM_to_headset)return;
684 wm8994_current_mode = wm8994_FM_to_headset;
686 msleep(WM8994_DELAY);
688 wm8994_write(0x01, 0x0303);
689 wm8994_write(0x02, 0x03A0);
690 wm8994_write(0x03, 0x0030);
691 wm8994_write(0x19, 0x010B); //LEFT LINE INPUT 3&4 VOLUME
692 wm8994_write(0x1B, 0x010B); //RIGHT LINE INPUT 3&4 VOLUME
694 wm8994_write(0x28, 0x0044);
695 wm8994_write(0x29, 0x0100);
696 wm8994_write(0x2A, 0x0100);
697 wm8994_write(0x2D, 0x0040);
698 wm8994_write(0x2E, 0x0040);
699 wm8994_write(0x4C, 0x9F25);
700 wm8994_write(0x60, 0x00EE);
701 wm8994_write(0x220, 0x0003);
702 wm8994_write(0x221, 0x0700);
703 wm8994_write(0x224, 0x0CC0);
704 wm8994_write(0x200, 0x0011);
705 wm8994_write(0x1C, 0x01F9); //LEFT OUTPUT VOLUME
706 wm8994_write(0x1D, 0x01F9); //RIGHT OUTPUT VOLUME
709 void FM_to_headset_and_record(void)
711 DBG("%s::%d\n",__FUNCTION__,__LINE__);
713 if(wm8994_current_mode == wm8994_FM_to_headset_and_record)return;
714 wm8994_current_mode = wm8994_FM_to_headset_and_record;
716 msleep(WM8994_DELAY);
718 wm8994_write(0x01, 0x0003);
719 msleep(WM8994_DELAY);
720 wm8994_write(0x221, 0x1900); //8~13BIT div
722 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
723 wm8994_write(0x302, 0x4000); // master = 0x4000 // slave= 0x0000
724 wm8994_write(0x303, 0x0040); // master 0x0050 lrck 7.94kHz bclk 510KHz
727 wm8994_write(0x220, 0x0004);
728 msleep(WM8994_DELAY);
729 wm8994_write(0x220, 0x0005);
731 wm8994_write(0x01, 0x0323);
732 wm8994_write(0x02, 0x03A0);
733 wm8994_write(0x03, 0x0030);
734 wm8994_write(0x19, 0x010B); //LEFT LINE INPUT 3&4 VOLUME
735 wm8994_write(0x1B, 0x010B); //RIGHT LINE INPUT 3&4 VOLUME
737 wm8994_write(0x28, 0x0044);
738 wm8994_write(0x29, 0x0100);
739 wm8994_write(0x2A, 0x0100);
740 wm8994_write(0x2D, 0x0040);
741 wm8994_write(0x2E, 0x0040);
742 wm8994_write(0x4C, 0x9F25);
743 wm8994_write(0x60, 0x00EE);
744 wm8994_write(0x200, 0x0011);
745 wm8994_write(0x1C, 0x01F9); //LEFT OUTPUT VOLUME
746 wm8994_write(0x1D, 0x01F9); //RIGHT OUTPUT VOLUME
747 wm8994_write(0x04, 0x0303);
748 wm8994_write(0x208, 0x000A);
749 wm8994_write(0x300, 0x4050);
750 wm8994_write(0x606, 0x0002);
751 wm8994_write(0x607, 0x0002);
752 wm8994_write(0x620, 0x0000);
755 void FM_to_speakers(void)
757 DBG("%s::%d\n",__FUNCTION__,__LINE__);
759 if(wm8994_current_mode == wm8994_FM_to_speakers)return;
760 wm8994_current_mode = wm8994_FM_to_speakers;
762 msleep(WM8994_DELAY);
764 wm8994_write(0x01, 0x3003);
765 wm8994_write(0x02, 0x03A0);
766 wm8994_write(0x03, 0x0330);
767 wm8994_write(0x19, 0x010B); //LEFT LINE INPUT 3&4 VOLUME
768 wm8994_write(0x1B, 0x010B); //RIGHT LINE INPUT 3&4 VOLUME
770 wm8994_write(0x22, 0x0000);
771 wm8994_write(0x23, 0x0000);
772 wm8994_write(0x36, 0x000C);
774 wm8994_write(0x28, 0x0044);
775 wm8994_write(0x29, 0x0100);
776 wm8994_write(0x2A, 0x0100);
777 wm8994_write(0x2D, 0x0040);
778 wm8994_write(0x2E, 0x0040);
780 wm8994_write(0x220, 0x0003);
781 wm8994_write(0x221, 0x0700);
782 wm8994_write(0x224, 0x0CC0);
784 wm8994_write(0x200, 0x0011);
785 wm8994_write(0x20, 0x01F9);
786 wm8994_write(0x21, 0x01F9);
789 void FM_to_speakers_and_record(void)
791 DBG("%s::%d\n",__FUNCTION__,__LINE__);
793 if(wm8994_current_mode == wm8994_FM_to_speakers_and_record)return;
794 wm8994_current_mode = wm8994_FM_to_speakers_and_record;
796 msleep(WM8994_DELAY);
798 wm8994_write(0x01, 0x0003);
799 msleep(WM8994_DELAY);
801 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
802 wm8994_write(0x302, 0x4000); // master = 0x4000 // slave= 0x0000
803 wm8994_write(0x303, 0x0090); //
806 wm8994_write(0x220, 0x0006);
807 msleep(WM8994_DELAY);
809 wm8994_write(0x01, 0x3023);
810 wm8994_write(0x02, 0x03A0);
811 wm8994_write(0x03, 0x0330);
812 wm8994_write(0x19, 0x010B); //LEFT LINE INPUT 3&4 VOLUME
813 wm8994_write(0x1B, 0x010B); //RIGHT LINE INPUT 3&4 VOLUME
815 wm8994_write(0x22, 0x0000);
816 wm8994_write(0x23, 0x0000);
817 wm8994_write(0x36, 0x000C);
819 wm8994_write(0x28, 0x0044);
820 wm8994_write(0x29, 0x0100);
821 wm8994_write(0x2A, 0x0100);
822 wm8994_write(0x2D, 0x0040);
823 wm8994_write(0x2E, 0x0040);
825 wm8994_write(0x220, 0x0003);
826 wm8994_write(0x221, 0x0700);
827 wm8994_write(0x224, 0x0CC0);
829 wm8994_write(0x200, 0x0011);
830 wm8994_write(0x20, 0x01F9);
831 wm8994_write(0x21, 0x01F9);
832 wm8994_write(0x04, 0x0303);
833 wm8994_write(0x208, 0x000A);
834 wm8994_write(0x300, 0x4050);
835 wm8994_write(0x606, 0x0002);
836 wm8994_write(0x607, 0x0002);
837 wm8994_write(0x620, 0x0000);
840 void handsetMIC_to_baseband_to_headset(void)
842 DBG("%s::%d\n",__FUNCTION__,__LINE__);
844 if(wm8994_current_mode == wm8994_handsetMIC_to_baseband_to_headset)return;
846 wm8994_codec_first_incall();
847 wm8994_current_mode = wm8994_handsetMIC_to_baseband_to_headset;
849 msleep(WM8994_DELAY);
851 wm8994_set_volume(wm8994_current_mode,0,call_maxvol);
853 wm8994_write(0x700, 0xA101);
854 wm8994_write(0x01, 0x0023);
855 wm8994_write(0x200, 0x0000);
856 mdelay(WM8994_DELAY);
858 wm8994_write(0x220, 0x0000);
859 wm8994_write(0x221, 0x0700);
860 wm8994_write(0x222, 0x3126);
861 wm8994_write(0x223, 0x0100);
863 wm8994_write(0x220, 0x0004);
865 wm8994_write(0x220, 0x0005);
868 wm8994_write(0x200, 0x0010);
869 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
870 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
871 wm8994_write(0x210, 0x0083); // SR=48KHz
872 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
873 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
874 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
875 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
876 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
877 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
878 wm8994_write(0x300, 0xC010); // i2s 16 bits
880 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
882 wm8994_write(0x01, 0x0023);
883 mdelay(WM8994_DELAY);
884 wm8994_write(0xFF, 0x0000);
886 wm8994_write(0x4C, 0x9F25);
888 wm8994_write(0x01, 0x0323);
889 wm8994_write(0x60, 0x0022);
890 wm8994_write(0x60, 0x00EE);
892 wm8994_write(0x54, 0x0033);
894 wm8994_write(0x610, 0x0100); //DAC1 Left Volume bit0~7
895 wm8994_write(0x611, 0x0100); //DAC1 Right Volume bit0~7
897 wm8994_set_channel_vol();
899 wm8994_write(0x22, 0x0000);
900 wm8994_write(0x23, 0x0100);
902 wm8994_write(0x02, 0x6240);
903 wm8994_write(0x28, 0x0030); //IN1LN_TO_IN1L IN1LP_TO_IN1L
904 #ifdef CONFIG_SND_BB_DIFFERENTIAL_INPUT
905 wm8994_write(0x2D, 0x0041); //bit 1 MIXINL_TO_MIXOUTL bit 12 DAC1L_TO_HPOUT1L 0x0102
906 wm8994_write(0x2E, 0x0081); //bit 1 MIXINL_TO_MIXOUTR bit 12 DAC1R_TO_HPOUT1R 0x0102
908 #ifdef CONFIG_SND_BB_NORMAL_INPUT
909 wm8994_write(0x2D, 0x0003); //bit 1 IN2LP_TO_MIXOUTL bit 12 DAC1L_TO_HPOUT1L 0x0102
910 wm8994_write(0x2E, 0x0003); //bit 1 IN2RP_TO_MIXOUTR bit 12 DAC1R_TO_HPOUT1R 0x0102
912 wm8994_write(0x34, 0x0002); //IN1L_TO_LINEOUT1P
913 wm8994_write(0x36, 0x0003);
915 wm8994_write(0x4C, 0x9F25);
917 wm8994_write(0x01, 0x0303);
919 wm8994_write(0x60, 0x0022);
920 wm8994_write(0x60, 0x00EE);
922 wm8994_write(0x03, 0x3030);
923 wm8994_write(0x04, 0x0300); // AIF1ADC1L_ENA=1, AIF1ADC1R_ENA=1
924 wm8994_write(0x05, 0x0303);
925 wm8994_write(0x420, 0x0000);
927 wm8994_write(0x01, 0x0323);
929 wm8994_write(0x601, 0x0001);
930 wm8994_write(0x602, 0x0001);
932 wm8994_write(0x610, 0x01A0); //DAC1 Left Volume bit0~7
933 wm8994_write(0x611, 0x01A0); //DAC1 Right Volume bit0~7
935 wm8994_set_level_volume();
938 void mainMIC_to_baseband_to_headset(void)
940 DBG("%s::%d\n",__FUNCTION__,__LINE__);
942 if(wm8994_current_mode == wm8994_mainMIC_to_baseband_to_headset)return;
943 wm8994_codec_first_incall();
944 wm8994_current_mode = wm8994_mainMIC_to_baseband_to_headset;
946 msleep(WM8994_DELAY);
948 wm8994_write(0x700, 0xA101);
949 wm8994_write(0x01, 0x0023);
950 wm8994_write(0x200, 0x0000);
951 mdelay(WM8994_DELAY);
953 wm8994_write(0x220, 0x0000);
954 wm8994_write(0x221, 0x0700);
955 wm8994_write(0x222, 0x3126);
956 wm8994_write(0x223, 0x0100);
958 wm8994_write(0x220, 0x0004);
960 wm8994_write(0x220, 0x0005);
963 wm8994_write(0x200, 0x0010);
964 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
965 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
966 wm8994_write(0x210, 0x0083); // SR=48KHz
967 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
968 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
969 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
970 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
971 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
972 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
973 wm8994_write(0x300, 0xC010); // i2s 16 bits
975 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
977 wm8994_write(0x39, 0x006C);
978 wm8994_write(0x01, 0x0023);
979 mdelay(WM8994_DELAY);
980 wm8994_write(0xFF, 0x0000);
982 wm8994_write(0x4C, 0x9F25);
984 wm8994_write(0x01, 0x0323);
985 wm8994_write(0x60, 0x0022);
986 wm8994_write(0x60, 0x00EE);
988 wm8994_write(0x54, 0x0033);
990 wm8994_write(0x610, 0x0100); //DAC1 Left Volume bit0~7
991 wm8994_write(0x611, 0x0100); //DAC1 Right Volume bit0~7
993 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
994 wm8994_set_channel_vol();
996 wm8994_write(0x22, 0x0000);
997 wm8994_write(0x23, 0x0100);
999 wm8994_write(0x02, 0x6210);
1000 wm8994_write(0x28, 0x0003); //IN1LN_TO_IN1L IN1LP_TO_IN1L
1001 #ifdef CONFIG_SND_BB_DIFFERENTIAL_INPUT
1002 wm8994_write(0x2D, 0x0041); //bit 1 MIXINL_TO_MIXOUTL bit 12 DAC1L_TO_HPOUT1L 0x0102
1003 wm8994_write(0x2E, 0x0081); //bit 1 MIXINL_TO_MIXOUTR bit 12 DAC1R_TO_HPOUT1R 0x0102
1005 #ifdef CONFIG_SND_BB_NORMAL_INPUT
1006 wm8994_write(0x2D, 0x0003); //bit 1 IN2LP_TO_MIXOUTL bit 12 DAC1L_TO_HPOUT1L 0x0102
1007 wm8994_write(0x2E, 0x0003); //bit 1 IN2RP_TO_MIXOUTR bit 12 DAC1R_TO_HPOUT1R 0x0102
1009 wm8994_write(0x34, 0x0004); //IN1L_TO_LINEOUT1P
1010 wm8994_write(0x36, 0x0003);
1012 wm8994_write(0x4C, 0x9F25);
1014 wm8994_write(0x01, 0x0303);
1016 wm8994_write(0x60, 0x0022);
1017 wm8994_write(0x60, 0x00EE);
1019 wm8994_write(0x03, 0x3030);
1020 wm8994_write(0x04, 0x0300); // AIF1ADC1L_ENA=1, AIF1ADC1R_ENA=1
1021 wm8994_write(0x05, 0x0303);
1022 wm8994_write(0x420, 0x0000);
1024 wm8994_write(0x01, 0x0333);
1026 wm8994_write(0x601, 0x0001);
1027 wm8994_write(0x602, 0x0001);
1029 wm8994_write(0x610, 0x01A0); //DAC1 Left Volume bit0~7
1030 wm8994_write(0x611, 0x01A0); //DAC1 Right Volume bit0~7
1033 void handsetMIC_to_baseband_to_headset_and_record(void)
1035 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1037 if(wm8994_current_mode == wm8994_handsetMIC_to_baseband_to_headset_and_record)return;
1038 wm8994_current_mode = wm8994_handsetMIC_to_baseband_to_headset_and_record;
1040 msleep(WM8994_DELAY);
1042 wm8994_write(0x01, 0x0303);
1043 wm8994_write(0x02, 0x62C0);
1044 wm8994_write(0x03, 0x3030);
1045 wm8994_write(0x04, 0x0303);
1046 wm8994_write(0x18, 0x014B); //volume
1047 wm8994_write(0x19, 0x014B); //volume
1048 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1049 wm8994_write(0x1E, 0x0006);
1050 wm8994_write(0x28, 0x00B0); //IN2LP_TO_IN2L
1051 wm8994_write(0x29, 0x0120);
1052 wm8994_write(0x2D, 0x0002); //bit 1 IN2LP_TO_MIXOUTL
1053 wm8994_write(0x2E, 0x0002); //bit 1 IN2RP_TO_MIXOUTR
1054 wm8994_write(0x34, 0x0002);
1055 wm8994_write(0x4C, 0x9F25);
1056 wm8994_write(0x60, 0x00EE);
1057 wm8994_write(0x200, 0x0001);
1058 wm8994_write(0x208, 0x000A);
1059 wm8994_write(0x300, 0x0050);
1061 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
1062 wm8994_write(0x302, 0x4000); // master = 0x4000 // slave= 0x0000
1063 wm8994_write(0x303, 0x0090); // master lrck 16k
1066 wm8994_write(0x606, 0x0002);
1067 wm8994_write(0x607, 0x0002);
1068 wm8994_write(0x620, 0x0000);
1071 void mainMIC_to_baseband_to_earpiece(void)
1073 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1075 if(wm8994_current_mode == wm8994_mainMIC_to_baseband_to_earpiece)return;
1077 wm8994_codec_first_incall();
1078 wm8994_current_mode = wm8994_mainMIC_to_baseband_to_earpiece;
1080 msleep(WM8994_DELAY);
1082 wm8994_write(0x700, 0xA101);
1083 wm8994_write(0x01, 0x0023);
1084 wm8994_write(0x200, 0x0000);
1085 mdelay(WM8994_DELAY);
1087 wm8994_write(0x220, 0x0000);
1088 wm8994_write(0x221, 0x0700);
1089 wm8994_write(0x222, 0x3126);
1090 wm8994_write(0x223, 0x0100);
1092 wm8994_write(0x220, 0x0004);
1094 wm8994_write(0x220, 0x0005);
1097 wm8994_write(0x200, 0x0010);
1098 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
1099 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
1100 wm8994_write(0x210, 0x0083); // SR=48KHz
1101 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
1102 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
1103 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
1104 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
1105 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
1106 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
1107 wm8994_write(0x300, 0x4010); // i2s 16 bits
1109 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
1111 wm8994_write(0x01, 0x0833); //HPOUT2_ENA=1, VMID_SEL=01, BIAS_ENA=1
1112 wm8994_write(0x4C, 0x9F25);
1114 wm8994_write(0x02, 0x6250); //bit4 IN1R_ENV bit6 IN1L_ENV
1115 wm8994_write(0x03, 0x30F0);
1116 wm8994_write(0x04, 0x0303); // AIF1ADC1L_ENA=1, AIF1ADC1R_ENA=1, ADCL_ENA=1, ADCR_ENA=1
1117 wm8994_write(0x05, 0x0303);
1118 wm8994_write(0x1F, 0x0000);
1120 #if defined(CONFIG_SND_INSIDE_EARPIECE)||defined(CONFIG_SND_OUTSIDE_EARPIECE)
1121 wm8994_set_channel_vol();
1122 #ifdef CONFIG_SND_INSIDE_EARPIECE
1123 wm8994_write(0x28, 0x0003); //IN1RP_TO_IN1R IN1RN_TO_IN1R
1124 wm8994_write(0x34, 0x0004); //IN1R_TO_LINEOUT1P
1126 #ifdef CONFIG_SND_OUTSIDE_EARPIECE
1127 wm8994_write(0x28, 0x0030); //IN1LP_TO_IN1L IN1LN_TO_IN1L
1128 wm8994_write(0x34, 0x0002); //IN1L_TO_LINEOUT1P
1131 #ifdef CONFIG_SND_BB_NORMAL_INPUT
1132 wm8994_write(0x2D, 0x0003); //bit 1 IN2LP_TO_MIXOUTL bit 12 DAC1L_TO_HPOUT1L 0x0102
1133 wm8994_write(0x2E, 0x0003); //bit 1 IN2RP_TO_MIXOUTR bit 12 DAC1R_TO_HPOUT1R 0x0102
1135 #ifdef CONFIG_SND_BB_DIFFERENTIAL_INPUT
1136 wm8994_write(0x2B, 0x0007); //VRX_MIXINL_VOL
1137 wm8994_write(0x2D, 0x0041); //bit 1 MIXINL_TO_MIXOUTL bit 12 DAC1L_TO_HPOUT1L 0x0102
1138 wm8994_write(0x2E, 0x0081); //bit 1 MIXINL_TO_MIXOUTR bit 12 DAC1R_TO_HPOUT1R 0x0102
1142 wm8994_write(0x601, 0x0001); //AIF1DAC1L_TO_DAC1L=1
1143 wm8994_write(0x602, 0x0001); //AIF1DAC1R_TO_DAC1R=1
1145 wm8994_write(0x610, 0x01C0); //DAC1_VU=1, DAC1L_VOL=1100_0000
1146 wm8994_write(0x611, 0x01C0); //DAC1_VU=1, DAC1R_VOL=1100_0000
1148 wm8994_write(0x420, 0x0000);
1150 wm8994_set_level_volume();
1153 void mainMIC_to_baseband_to_earpiece_and_record(void)
1155 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1157 if(wm8994_current_mode==wm8994_mainMIC_to_baseband_to_earpiece_and_record)return;
1158 wm8994_current_mode=wm8994_mainMIC_to_baseband_to_earpiece_and_record;
1160 msleep(WM8994_DELAY);
1162 wm8994_write(0x01 ,0x0803|wm8994_mic_VCC);
1163 wm8994_write(0x02 ,0x6310);
1164 wm8994_write(0x03 ,0x30A0);
1165 wm8994_write(0x04 ,0x0303);
1166 wm8994_write(0x1A ,0x014F);
1167 wm8994_write(0x1E ,0x0006);
1168 wm8994_write(0x1F ,0x0000);
1169 wm8994_write(0x28 ,0x0003); //MAINMIC_TO_IN1R
1170 wm8994_write(0x2A ,0x0020); //IN1R_TO_MIXINR
1171 wm8994_write(0x2B ,0x0005); //VRX_MIXINL_VOL bit 0~2
1172 wm8994_write(0x2C ,0x0005); //VRX_MIXINR_VOL
1173 wm8994_write(0x2D ,0x0040); //MIXINL_TO_MIXOUTL
1174 wm8994_write(0x33 ,0x0010); //MIXOUTLVOL_TO_HPOUT2
1175 wm8994_write(0x34 ,0x0004); //IN1R_TO_LINEOUT1
1176 wm8994_write(0x200 ,0x0001);
1177 wm8994_write(0x208 ,0x000A);
1178 wm8994_write(0x300 ,0xC050);
1179 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1181 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
1182 wm8994_write(0x302, 0x4000); // master = 0x4000 // slave= 0x0000
1183 wm8994_write(0x303, 0x0090); // master lrck 16k
1186 wm8994_write(0x606 ,0x0002);
1187 wm8994_write(0x607 ,0x0002);
1188 wm8994_write(0x620 ,0x0000);
1191 void mainMIC_to_baseband_to_speakers(void)
1193 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1195 if(wm8994_current_mode==wm8994_mainMIC_to_baseband_to_speakers)return;
1197 wm8994_codec_first_incall();
1198 wm8994_current_mode=wm8994_mainMIC_to_baseband_to_speakers;
1200 msleep(WM8994_DELAY);
1201 wm8994_set_volume(wm8994_current_mode,0,call_maxvol);
1203 wm8994_write(0x700, 0xA101);
1204 wm8994_write(0x39, 0x006C);
1205 wm8994_write(0x01, 0x0023);
1206 wm8994_write(0x200, 0x0000);
1207 mdelay(WM8994_DELAY);
1209 wm8994_write(0x220, 0x0000);
1210 wm8994_write(0x221, 0x0700);
1211 wm8994_write(0x222, 0x3126);
1212 wm8994_write(0x223, 0x0100);
1214 wm8994_write(0x220, 0x0004);
1216 wm8994_write(0x220, 0x0005);
1219 wm8994_write(0x200, 0x0010);
1220 wm8994_write(0x208, 0x0008); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
1221 wm8994_write(0x208, 0x000A); //DSP_FS1CLK_ENA=1, DSP_FSINTCLK_ENA=1
1222 wm8994_write(0x210, 0x0083); // SR=48KHz
1223 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
1224 wm8994_write(0x302, 0x3000); // AIF1_MSTR=1
1225 wm8994_write(0x302, 0x7000); // AIF1_MSTR=1
1226 wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4
1227 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64
1228 wm8994_write(0x305, 0x0040); // AIF1 DACLRCK DIV-----BCLK/64
1229 wm8994_write(0x300, 0xC010); // i2s 16 bits
1231 wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011
1233 wm8994_write(0x610, 0x0100);
1234 wm8994_write(0x611, 0x0100);
1236 // wm8994_write(0x24, 0x0011);
1237 wm8994_set_channel_vol();
1239 wm8994_write(0x02, 0x6210);
1240 wm8994_write(0x03, 0x1330);
1241 wm8994_write(0x04, 0x0303); // AIF1ADC1L_ENA=1, AIF1ADC1R_ENA=1, ADCL_ENA=1, ADCR_ENA=1
1242 wm8994_write(0x05, 0x0303);
1243 wm8994_write(0x22, 0x0000);
1244 wm8994_write(0x23, 0x0100);
1245 wm8994_write(0x28, 0x0003); //IN1LN_TO_IN1L IN1LP_TO_IN1L
1246 wm8994_write(0x29, 0x0030);
1247 #ifdef CONFIG_SND_BB_NORMAL_INPUT
1248 wm8994_write(0x2D, 0x0003); //bit 1 IN2LP_TO_MIXOUTL bit 12 DAC1L_TO_HPOUT1L 0x0102
1249 wm8994_write(0x2E, 0x0003); //bit 1 IN2RP_TO_MIXOUTR bit 12 DAC1R_TO_HPOUT1R 0x0102
1251 #ifdef CONFIG_SND_BB_DIFFERENTIAL_INPUT
1252 wm8994_write(0x2B, 0x0005); //VRX_MIXINL_VOL
1253 wm8994_write(0x2D, 0x0041); //bit 1 MIXINL_TO_MIXOUTL bit 12 DAC1L_TO_HPOUT1L 0x0102
1254 wm8994_write(0x2E, 0x0081); //bit 1 MIXINL_TO_MIXOUTR bit 12 DAC1R_TO_HPOUT1R 0x0102
1256 wm8994_write(0x34, 0x000C); //IN1L_TO_LINEOUT1P
1258 wm8994_write(0x4C, 0x9F25);
1260 wm8994_write(0x01, 0x3003);
1262 wm8994_write(0x60, 0x0022);
1263 wm8994_write(0x36, 0x000C);
1264 wm8994_write(0x60, 0x00EE);
1265 wm8994_write(0x420, 0x0000);
1267 wm8994_write(0x601, 0x0001);
1268 wm8994_write(0x602, 0x0001);
1270 wm8994_write(0x01, 0x3033);
1271 wm8994_write(0x610, 0x01C0); //DAC1 Left Volume bit0~7
1272 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
1274 wm8994_set_level_volume();
1277 void mainMIC_to_baseband_to_speakers_and_record(void)
1279 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1281 if(wm8994_current_mode==wm8994_mainMIC_to_baseband_to_speakers_and_record)return;
1282 wm8994_current_mode=wm8994_mainMIC_to_baseband_to_speakers_and_record;
1284 msleep(WM8994_DELAY);
1286 wm8994_write(0x01, 0x3023|wm8994_mic_VCC);
1287 wm8994_write(0x02, 0x6330);
1288 wm8994_write(0x03, 0x3330);
1289 wm8994_write(0x04, 0x0303);
1290 wm8994_write(0x1A, 0x014B);
1291 wm8994_write(0x1B, 0x014B);
1292 wm8994_write(0x1E, 0x0006);
1293 wm8994_write(0x22, 0x0000);
1294 wm8994_write(0x23, 0x0100);
1295 wm8994_write(0x28, 0x0007);
1296 wm8994_write(0x2A, 0x0120);
1297 wm8994_write(0x2D, 0x0002); //bit 1 IN2LP_TO_MIXOUTL
1298 wm8994_write(0x2E, 0x0002); //bit 1 IN2RP_TO_MIXOUTR
1299 wm8994_write(0x34, 0x0004);
1300 wm8994_write(0x36, 0x000C);
1301 wm8994_write(0x200, 0x0001);
1302 wm8994_write(0x208, 0x000A);
1303 wm8994_write(0x300, 0xC050);
1304 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1306 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
1307 wm8994_write(0x302, 0x4000); // master = 0x4000 // slave= 0x0000
1308 wm8994_write(0x303, 0x0090); // master lrck 16k
1311 wm8994_write(0x606, 0x0002);
1312 wm8994_write(0x607, 0x0002);
1313 wm8994_write(0x620, 0x0000);
1316 void BT_baseband(void)
1318 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1320 if(wm8994_current_mode==wm8994_BT_baseband)return;
1321 wm8994_codec_first_incall();
1322 wm8994_current_mode=wm8994_BT_baseband;
1324 msleep(WM8994_DELAY);
1326 wm8994_write(0x700, 0xA101);
1327 wm8994_write(0x705, 0xA101);
1328 wm8994_write(0x01, 0x0023);
1329 wm8994_write(0x200, 0x0000);
1330 msleep(WM8994_DELAY);
1332 //roger_chen@20100524
1333 //8KHz, BCLK=8KHz*128=1024KHz, Fout=2.048MHz
1334 wm8994_write(0x220, 0x0000); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=0, FLL1_OSC_ENA=0, FLL1_ENA=0
1335 wm8994_write(0x221, 0x0700); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (2)(221H): 0700 FLL1_OUTDIV=2Fh, FLL1_CTRL_RATE=000, FLL1_FRATIO=000
1336 wm8994_write(0x222, 0x3126); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (3)(222H): 8FD5 FLL1_K=3126h
1337 wm8994_write(0x223, 0x0100); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (4)(223H): 00E0 FLL1_N=8h, FLL1_GAIN=0000
1339 wm8994_write(0x220, 0x0004); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=1, FLL1_OSC_ENA=0, FLL1_ENA=0
1341 wm8994_write(0x220, 0x0005); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=1, FLL1_OSC_ENA=0, FLL1_ENA=1
1344 wm8994_write(0x200, 0x0010);
1345 wm8994_write(0x208, 0x0008);
1346 wm8994_write(0x208, 0x000A);
1348 wm8994_write(0x210, 0x0083); // SMbus_16inx_16dat Write 0x34 * SR=48KHz
1349 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
1350 wm8994_write(0x302, 0x3000);
1352 wm8994_write(0x302, 0x7000);
1353 wm8994_write(0x303, 0x0040);
1354 wm8994_write(0x304, 0x0040);
1355 wm8994_write(0x305, 0x0040);
1356 wm8994_write(0x300, 0xC050); //DSP/PCM; 16bits; ADC L channel = R channel;MODE A
1358 wm8994_write(0x200, 0x0011);
1360 wm8994_write(0x204, 0x0000);
1361 msleep(WM8994_DELAY);
1362 wm8994_write(0x240, 0x0000);
1363 wm8994_write(0x241, 0x2F00);
1364 wm8994_write(0x242, 0x3126);
1365 wm8994_write(0x243, 0x0100);
1367 wm8994_write(0x240, 0x0004);
1369 wm8994_write(0x240, 0x0005);
1372 wm8994_write(0x204, 0x0018); // SMbus_16inx_16dat Write 0x34 * AIF2 Clocking (1)(204H): 0011 AIF2CLK_SRC=10, AIF2CLK_INV=0, AIF2CLK_DIV=0, AIF2CLK_ENA=1
1373 wm8994_write(0x208, 0x000E);
1374 wm8994_write(0x211, 0x0003);
1375 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
1376 wm8994_write(0x312, 0x3000); // SMbus_16inx_16dat Write 0x34 * AIF2 Master/Slave(312H): 7000 AIF2_TRI=0, AIF2_MSTR=1, AIF2_CLK_FRC=0, AIF2_LRCLK_FRC=0
1378 wm8994_write(0x312, 0x7000);
1379 wm8994_write(0x313, 0x0020); // SMbus_16inx_16dat Write 0x34 * AIF2 BCLK DIV--------AIF1CLK/2
1380 wm8994_write(0x314, 0x0080); // SMbus_16inx_16dat Write 0x34 * AIF2 ADCLRCK DIV-----BCLK/128
1381 wm8994_write(0x315, 0x0080);
1382 wm8994_write(0x310, 0x0118); //DSP/PCM; 16bits; ADC L channel = R channel;MODE A
1384 wm8994_write(0x204, 0x0019); // SMbus_16inx_16dat Write 0x34 * AIF2 Clocking (1)(204H): 0011 AIF2CLK_SRC=10, AIF2CLK_INV=0, AIF2CLK_DIV=0, AIF2CLK_ENA=1
1386 //roger_chen@20100519
1387 //enable AIF2 BCLK,LRCK
1388 //Rev.B and Rev.D is different
1389 wm8994_write(0x702, 0x2100);
1390 wm8994_write(0x703, 0x2100);
1392 wm8994_write(0x704, 0xA100);
1393 wm8994_write(0x707, 0xA100);
1394 wm8994_write(0x708, 0x2100);
1395 wm8994_write(0x709, 0x2100);
1396 wm8994_write(0x70A, 0x2100);
1398 wm8994_write(0x01, 0x3003);
1399 wm8994_write(0x02, 0x63A0);
1400 wm8994_write(0x03, 0x33F0);
1401 wm8994_write(0x04, 0x3303);
1402 wm8994_write(0x05, 0x3303);
1403 wm8994_write(0x06, 0x000A);
1404 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1405 wm8994_write(0x1E, 0x0006);
1406 wm8994_write(0x29, 0x0100);
1407 wm8994_write(0x2A, 0x0100);
1409 wm8994_set_channel_vol();
1411 #ifdef CONFIG_SND_BB_NORMAL_INPUT
1412 wm8994_write(0x28, 0x00C0);
1414 #ifdef CONFIG_SND_BB_DIFFERENTIAL_INPUT
1415 /*vol = BT_incall_vol;
1418 wm8994_write(0x2B, (vol+12)/3 + 1);*/
1419 wm8994_write(0x28, 0x00CC);
1421 wm8994_write(0x22, 0x0000);
1422 wm8994_write(0x23, 0x0100);
1423 wm8994_write(0x24, 0x0009);
1424 wm8994_write(0x29, 0x0130);
1425 wm8994_write(0x2A, 0x0130);
1426 wm8994_write(0x2D, 0x0001);
1427 wm8994_write(0x2E, 0x0001);
1428 wm8994_write(0x34, 0x0001);
1429 wm8994_write(0x36, 0x0004);
1430 wm8994_write(0x4C, 0x9F25);
1431 wm8994_write(0x60, 0x00EE);
1432 wm8994_write(0x01, 0x3023);
1434 wm8994_write(0x440, 0x0018);
1435 wm8994_write(0x450, 0x0018);
1436 wm8994_write(0x540, 0x01BF); //open nosie gate
1437 wm8994_write(0x550, 0x01BF); //open nosie gate
1438 wm8994_write(0x480, 0x0000);
1439 wm8994_write(0x481, 0x0000);
1440 wm8994_write(0x4A0, 0x0000);
1441 wm8994_write(0x4A1, 0x0000);
1442 wm8994_write(0x520, 0x0000);
1443 wm8994_write(0x540, 0x0018);
1444 wm8994_write(0x580, 0x0000);
1445 wm8994_write(0x581, 0x0000);
1446 wm8994_write(0x601, 0x0004);
1448 wm8994_write(0x602, 0x0001);
1450 wm8994_write(0x603, 0x000C);
1451 wm8994_write(0x604, 0x0010);
1452 wm8994_write(0x605, 0x0010);
1453 wm8994_write(0x610, 0x01C0);
1454 wm8994_write(0x611, 0x01C0);
1455 wm8994_write(0x612, 0x01C0);
1456 wm8994_write(0x613, 0x01C0);
1457 wm8994_write(0x620, 0x0000);
1458 wm8994_write(0x420, 0x0000);
1461 void BT_baseband_old(void)
1463 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1465 if(wm8994_current_mode==wm8994_BT_baseband)return;
1466 wm8994_codec_first_incall();
1467 wm8994_current_mode=wm8994_BT_baseband;
1469 msleep(WM8994_DELAY);
1471 wm8994_write(0x01, 0x3003);
1472 wm8994_write(0x02, 0x63A0);
1473 wm8994_write(0x03, 0x33F0);
1474 wm8994_write(0x04, 0x3303);
1475 wm8994_write(0x05, 0x3303);
1476 wm8994_write(0x06, 0x000A);
1477 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1478 wm8994_write(0x1E, 0x0006);
1479 wm8994_write(0x29, 0x0100);
1480 wm8994_write(0x2A, 0x0100);
1482 wm8994_set_channel_vol();
1484 #ifdef CONFIG_SND_BB_NORMAL_INPUT
1485 wm8994_write(0x28, 0x00C0);
1487 #ifdef CONFIG_SND_BB_DIFFERENTIAL_INPUT
1488 /*vol = BT_incall_vol;
1491 wm8994_write(0x2B, (vol+12)/3 + 1);*/
1492 wm8994_write(0x28, 0x00CC);
1494 wm8994_write(0x22, 0x0000);
1495 wm8994_write(0x23, 0x0100);
1496 wm8994_write(0x24, 0x0009);
1497 wm8994_write(0x29, 0x0130);
1498 wm8994_write(0x2A, 0x0130);
1499 wm8994_write(0x2D, 0x0001);
1500 wm8994_write(0x2E, 0x0001);
1501 wm8994_write(0x34, 0x0001);
1502 wm8994_write(0x36, 0x0004);
1503 wm8994_write(0x4C, 0x9F25);
1504 wm8994_write(0x60, 0x00EE);
1505 wm8994_write(0x01, 0x3023);
1506 //roger_chen@20100524
1507 //8KHz, BCLK=8KHz*128=1024KHz, Fout=2.048MHz
1508 wm8994_write(0x200, 0x0001);
1509 wm8994_write(0x204, 0x0001); // SMbus_16inx_16dat Write 0x34 * AIF2 Clocking (1)(204H): 0011 AIF2CLK_SRC=00, AIF2CLK_INV=0, AIF2CLK_DIV=0, AIF2CLK_ENA=1
1510 wm8994_write(0x208, 0x000E);
1511 wm8994_write(0x220, 0x0000); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=0, FLL1_OSC_ENA=0, FLL1_ENA=0
1512 wm8994_write(0x221, 0x0700); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (2)(221H): 0700 FLL1_OUTDIV=2Fh, FLL1_CTRL_RATE=000, FLL1_FRATIO=000
1513 wm8994_write(0x222, 0x3126); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (3)(222H): 8FD5 FLL1_K=3126h
1514 wm8994_write(0x223, 0x0100); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (4)(223H): 00E0 FLL1_N=8h, FLL1_GAIN=0000
1516 wm8994_write(0x303, 0x0040);
1517 wm8994_write(0x304, 0x0040);
1518 wm8994_write(0x305, 0x0040);
1519 wm8994_write(0x300, 0xC050); //DSP/PCM; 16bits; ADC L channel = R channel;MODE A
1521 wm8994_write(0x210, 0x0083); // SMbus_16inx_16dat Write 0x34 * SR=48KHz
1522 wm8994_write(0x220, 0x0004); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=1, FLL1_OSC_ENA=0, FLL1_ENA=0
1524 wm8994_write(0x220, 0x0005); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=1, FLL1_OSC_ENA=0, FLL1_ENA=1
1526 wm8994_write(0x240, 0x0000);
1527 wm8994_write(0x241, 0x2F00);
1528 wm8994_write(0x242, 0x3126);
1529 wm8994_write(0x243, 0x0100);
1531 wm8994_write(0x313, 0x0020); // SMbus_16inx_16dat Write 0x34 * AIF2 BCLK DIV--------AIF1CLK/2
1532 wm8994_write(0x314, 0x0080); // SMbus_16inx_16dat Write 0x34 * AIF2 ADCLRCK DIV-----BCLK/128
1533 wm8994_write(0x315, 0x0080);
1534 wm8994_write(0x310, 0x0118); //DSP/PCM; 16bits; ADC L channel = R channel;MODE A
1536 wm8994_write(0x211, 0x0003); // SMbus_16inx_16dat Write 0x34 * SR=8KHz
1537 wm8994_write(0x240, 0x0004);
1539 wm8994_write(0x240, 0x0005);
1541 wm8994_write(0x200, 0x0011);
1542 wm8994_write(0x204, 0x0019); // SMbus_16inx_16dat Write 0x34 * AIF2 Clocking (1)(204H): 0011 AIF2CLK_SRC=10, AIF2CLK_INV=0, AIF2CLK_DIV=0, AIF2CLK_ENA=1
1543 wm8994_write(0x440, 0x0018);
1544 wm8994_write(0x450, 0x0018);
1545 wm8994_write(0x540, 0x01BF); //open nosie gate
1546 wm8994_write(0x550, 0x01BF); //open nosie gate
1547 wm8994_write(0x480, 0x0000);
1548 wm8994_write(0x481, 0x0000);
1549 wm8994_write(0x4A0, 0x0000);
1550 wm8994_write(0x4A1, 0x0000);
1551 wm8994_write(0x520, 0x0000);
1552 wm8994_write(0x540, 0x0018);
1553 wm8994_write(0x580, 0x0000);
1554 wm8994_write(0x581, 0x0000);
1555 wm8994_write(0x601, 0x0004);
1557 wm8994_write(0x602, 0x0001);
1559 wm8994_write(0x603, 0x000C);
1560 wm8994_write(0x604, 0x0010);
1561 wm8994_write(0x605, 0x0010);
1562 wm8994_write(0x610, 0x01C0);
1563 wm8994_write(0x611, 0x01C0);
1564 wm8994_write(0x612, 0x01C0);
1565 wm8994_write(0x613, 0x01C0);
1566 wm8994_write(0x620, 0x0000);
1567 wm8994_write(0x420, 0x0000);
1569 //roger_chen@20100519
1570 //enable AIF2 BCLK,LRCK
1571 //Rev.B and Rev.D is different
1572 wm8994_write(0x702, 0x2100);
1573 wm8994_write(0x703, 0x2100);
1575 wm8994_write(0x704, 0xA100);
1576 wm8994_write(0x707, 0xA100);
1577 wm8994_write(0x708, 0x2100);
1578 wm8994_write(0x709, 0x2100);
1579 wm8994_write(0x70A, 0x2100);
1580 #ifdef CONFIG_SND_RK29_CODEC_SOC_MASTER
1581 wm8994_write(0x700, 0xA101);
1582 wm8994_write(0x705, 0xA101);
1583 wm8994_write(0x302, 0x3000);
1585 wm8994_write(0x302, 0x7000);
1587 wm8994_write(0x312, 0x3000); // SMbus_16inx_16dat Write 0x34 * AIF2 Master/Slave(312H): 7000 AIF2_TRI=0, AIF2_MSTR=1, AIF2_CLK_FRC=0, AIF2_LRCLK_FRC=0
1589 wm8994_write(0x312, 0x7000);
1593 void BT_baseband_and_record(void)
1595 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1597 if(wm8994_current_mode==wm8994_BT_baseband_and_record)return;
1598 wm8994_current_mode=wm8994_BT_baseband_and_record;
1600 msleep(WM8994_DELAY);
1602 wm8994_write(0x01, 0x0023);
1603 wm8994_write(0x02, 0x63A0);
1604 wm8994_write(0x03, 0x30A0);
1605 wm8994_write(0x04, 0x3303);
1606 wm8994_write(0x05, 0x3002);
1607 wm8994_write(0x06, 0x000A);
1608 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1609 wm8994_write(0x1E, 0x0006);
1610 wm8994_write(0x28, 0x00CC);
1611 wm8994_write(0x29, 0x0100);
1612 wm8994_write(0x2A, 0x0100);
1613 wm8994_write(0x2D, 0x0001);
1614 wm8994_write(0x34, 0x0001);
1615 wm8994_write(0x200, 0x0001);
1617 //roger_chen@20100524
1618 //8KHz, BCLK=8KHz*128=1024KHz, Fout=2.048MHz
1619 wm8994_write(0x204, 0x0001); // SMbus_16inx_16dat Write 0x34 * AIF2 Clocking (1)(204H): 0011 AIF2CLK_SRC=00, AIF2CLK_INV=0, AIF2CLK_DIV=0, AIF2CLK_ENA=1
1620 wm8994_write(0x208, 0x000F);
1621 wm8994_write(0x220, 0x0000); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=0, FLL1_OSC_ENA=0, FLL1_ENA=0
1622 wm8994_write(0x221, 0x2F00); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (2)(221H): 0700 FLL1_OUTDIV=2Fh, FLL1_CTRL_RATE=000, FLL1_FRATIO=000
1623 wm8994_write(0x222, 0x3126); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (3)(222H): 8FD5 FLL1_K=3126h
1624 wm8994_write(0x223, 0x0100); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (4)(223H): 00E0 FLL1_N=8h, FLL1_GAIN=0000
1625 wm8994_write(0x302, 0x4000);
1626 wm8994_write(0x303, 0x0090);
1627 wm8994_write(0x310, 0xC118); //DSP/PCM; 16bits; ADC L channel = R channel;MODE A
1628 wm8994_write(0x312, 0x4000); // SMbus_16inx_16dat Write 0x34 * AIF2 Master/Slave(312H): 7000 AIF2_TRI=0, AIF2_MSTR=1, AIF2_CLK_FRC=0, AIF2_LRCLK_FRC=0
1629 wm8994_write(0x313, 0x0020); // SMbus_16inx_16dat Write 0x34 * AIF2 BCLK DIV--------AIF1CLK/2
1630 wm8994_write(0x314, 0x0080); // SMbus_16inx_16dat Write 0x34 * AIF2 ADCLRCK DIV-----BCLK/128
1631 wm8994_write(0x315, 0x0080); // SMbus_16inx_16dat Write 0x34 * AIF2 DACLRCK DIV-----BCLK/128
1632 wm8994_write(0x210, 0x0003); // SMbus_16inx_16dat Write 0x34 * SR=8KHz
1633 wm8994_write(0x220, 0x0004); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=1, FLL1_OSC_ENA=0, FLL1_ENA=0
1634 msleep(WM8994_DELAY);
1635 wm8994_write(0x220, 0x0005); // SMbus_16inx_16dat Write 0x34 * FLL1 Control (1)(220H): 0005 FLL1_FRACN_ENA=1, FLL1_OSC_ENA=0, FLL1_ENA=1
1636 wm8994_write(0x204, 0x0011); // SMbus_16inx_16dat Write 0x34 * AIF2 Clocking (1)(204H): 0011 AIF2CLK_SRC=10, AIF2CLK_INV=0, AIF2CLK_DIV=0, AIF2CLK_ENA=1
1638 wm8994_write(0x440, 0x0018);
1639 wm8994_write(0x450, 0x0018);
1640 wm8994_write(0x480, 0x0000);
1641 wm8994_write(0x481, 0x0000);
1642 wm8994_write(0x4A0, 0x0000);
1643 wm8994_write(0x4A1, 0x0000);
1644 wm8994_write(0x520, 0x0000);
1645 wm8994_write(0x540, 0x0018);
1646 wm8994_write(0x580, 0x0000);
1647 wm8994_write(0x581, 0x0000);
1648 wm8994_write(0x601, 0x0004);
1649 wm8994_write(0x603, 0x000C);
1650 wm8994_write(0x604, 0x0010);
1651 wm8994_write(0x605, 0x0010);
1652 wm8994_write(0x606, 0x0003);
1653 wm8994_write(0x607, 0x0003);
1654 wm8994_write(0x610, 0x01C0);
1655 wm8994_write(0x612, 0x01C0);
1656 wm8994_write(0x613, 0x01C0);
1657 wm8994_write(0x620, 0x0000);
1659 //roger_chen@20100519
1660 //enable AIF2 BCLK,LRCK
1661 //Rev.B and Rev.D is different
1662 wm8994_write(0x702, 0xA100);
1663 wm8994_write(0x703, 0xA100);
1665 wm8994_write(0x704, 0xA100);
1666 wm8994_write(0x707, 0xA100);
1667 wm8994_write(0x708, 0x2100);
1668 wm8994_write(0x709, 0x2100);
1669 wm8994_write(0x70A, 0x2100);
1674 /******************PCM BB BEGIN*****************/
1676 void handsetMIC_to_baseband_to_headset(void) //pcmbaseband
1678 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1680 if(wm8994_current_mode==wm8994_handsetMIC_to_baseband_to_headset)return;
1681 wm8994_current_mode=wm8994_handsetMIC_to_baseband_to_headset;
1685 wm8994_write(0x01, 0x0003|wm8994_mic_VCC);
1687 wm8994_write(0x221, 0x0700);
1688 wm8994_write(0x222, 0x3127);
1689 wm8994_write(0x223, 0x0100);
1690 wm8994_write(0x220, 0x0004);
1692 wm8994_write(0x220, 0x0005);
1694 wm8994_write(0x01, 0x0303|wm8994_mic_VCC); ///0x0303); // sysclk = fll (bit4 =1) 0x0011
1695 wm8994_write(0x02, 0x0240);
1696 wm8994_write(0x03, 0x0030);
1697 wm8994_write(0x04, 0x3003);
1698 wm8994_write(0x05, 0x3003); // i2s 16 bits
1699 wm8994_write(0x18, 0x010B);
1700 wm8994_write(0x28, 0x0030);
1701 wm8994_write(0x29, 0x0020);
1702 wm8994_write(0x2D, 0x0100); //0x0100);DAC1L_TO_HPOUT1L ;;;bit 8
1703 wm8994_write(0x2E, 0x0100); //0x0100);DAC1R_TO_HPOUT1R ;;;bit 8
1704 wm8994_write(0x4C, 0x9F25);
1705 wm8994_write(0x60, 0x00EE);
1706 wm8994_write(0x200, 0x0001);
1707 wm8994_write(0x204, 0x0001);
1708 wm8994_write(0x208, 0x0007);
1709 wm8994_write(0x520, 0x0000);
1710 wm8994_write(0x601, 0x0004); //AIF2DACL_TO_DAC1L
1711 wm8994_write(0x602, 0x0004); //AIF2DACR_TO_DAC1R
1713 wm8994_write(0x610, 0x01C0); //DAC1 Left Volume bit0~7
1714 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
1715 wm8994_write(0x612, 0x01C0); //DAC2 Left Volume bit0~7
1716 wm8994_write(0x613, 0x01C0); //DAC2 Right Volume bit0~7
1718 wm8994_write(0x702, 0xC100);
1719 wm8994_write(0x703, 0xC100);
1720 wm8994_write(0x704, 0xC100);
1721 wm8994_write(0x706, 0x4100);
1722 wm8994_write(0x204, 0x0011);
1723 wm8994_write(0x211, 0x0009);
1725 wm8994_write(0x310, 0x4108); ///0x4118); ///interface dsp mode 16bit
1728 wm8994_write(0x310, 0x4118); ///0x4118); ///interface dsp mode 16bit
1731 wm8994_write(0x310, 0x4118); ///0x4118); ///interface dsp mode 16bit
1732 wm8994_write(0x241, 0x2f04);
1733 wm8994_write(0x242, 0x0000);
1734 wm8994_write(0x243, 0x0300);
1735 wm8994_write(0x240, 0x0004);
1737 wm8994_write(0x240, 0x0005);
1738 wm8994_write(0x204, 0x0019);
1739 wm8994_write(0x211, 0x0003);
1740 wm8994_write(0x244, 0x0c83);
1741 wm8994_write(0x620, 0x0000);
1743 #ifdef THINKWILL_M800_MODE
1744 wm8994_write(0x310, 0x4118); ///0x4118); ///interface dsp mode 16bit
1746 wm8994_write(0x313, 0x00F0);
1747 wm8994_write(0x314, 0x0020);
1748 wm8994_write(0x315, 0x0020);
1749 wm8994_write(0x603, 0x018c); ///0x000C); //Rev.D ADCL SideTone
1750 wm8994_write(0x604, 0x0010); //XX
1751 wm8994_write(0x605, 0x0010); //XX
1752 wm8994_write(0x621, 0x0000); //0x0001); ///0x0000);
1753 wm8994_write(0x317, 0x0003);
1754 wm8994_write(0x312, 0x0000); /// as slave ///0x4000); //AIF2 SET AS MASTER
1756 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1759 void handsetMIC_to_baseband_to_headset_and_record(void) //pcmbaseband
1761 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1763 if(wm8994_current_mode==wm8994_handsetMIC_to_baseband_to_headset_and_record)return;
1764 wm8994_current_mode=wm8994_handsetMIC_to_baseband_to_headset_and_record;
1768 wm8994_write(0x01, 0x0003|wm8994_mic_VCC);
1770 wm8994_write(0x221, 0x0700); //MCLK=12MHz
1771 wm8994_write(0x222, 0x3127);
1772 wm8994_write(0x223, 0x0100);
1773 wm8994_write(0x220, 0x0004);
1775 wm8994_write(0x220, 0x0005);
1777 wm8994_write(0x01, 0x0303|wm8994_mic_VCC);
1778 wm8994_write(0x02, 0x0240);
1779 wm8994_write(0x03, 0x0030);
1780 wm8994_write(0x04, 0x3003);
1781 wm8994_write(0x05, 0x3003);
1782 wm8994_write(0x18, 0x010B); // 0x011F=+30dB for MIC
1783 wm8994_write(0x28, 0x0030);
1784 wm8994_write(0x29, 0x0020);
1785 wm8994_write(0x2D, 0x0100);
1786 wm8994_write(0x2E, 0x0100);
1787 wm8994_write(0x4C, 0x9F25);
1788 wm8994_write(0x60, 0x00EE);
1789 wm8994_write(0x200, 0x0001);
1790 wm8994_write(0x204, 0x0001);
1791 wm8994_write(0x208, 0x0007);
1792 wm8994_write(0x520, 0x0000);
1793 wm8994_write(0x601, 0x0004);
1794 wm8994_write(0x602, 0x0004);
1796 wm8994_write(0x610, 0x01C0); //DAC1 Left Volume bit0~7
1797 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
1798 wm8994_write(0x612, 0x01C0); //DAC2 Left Volume bit0~7
1799 wm8994_write(0x613, 0x01C0); //DAC2 Right Volume bit0~7
1801 wm8994_write(0x700, 0x8141); //SYNC issue, AIF1 ADCLRC1 from LRCK1
1802 wm8994_write(0x702, 0xC100);
1803 wm8994_write(0x703, 0xC100);
1804 wm8994_write(0x704, 0xC100);
1805 wm8994_write(0x706, 0x4100);
1806 wm8994_write(0x204, 0x0011); //AIF2 MCLK=FLL1
1807 wm8994_write(0x211, 0x0009); //LRCK=8KHz, Rate=MCLK/1536
1808 wm8994_write(0x310, 0x4118); //DSP/PCM 16bits
1809 wm8994_write(0x313, 0x00F0);
1810 wm8994_write(0x314, 0x0020);
1811 wm8994_write(0x315, 0x0020);
1813 wm8994_write(0x603, 0x018c); ///0x000C); //Rev.D ADCL SideTone
1814 wm8994_write(0x604, 0x0010);
1815 wm8994_write(0x605, 0x0010);
1816 wm8994_write(0x621, 0x0000);
1817 //wm8994_write(0x317, 0x0003);
1818 //wm8994_write(0x312, 0x4000); //AIF2 SET AS MASTER
1820 wm8994_write(0x04, 0x3303);
1821 wm8994_write(0x200, 0x0001);
1822 wm8994_write(0x208, 0x000F);
1823 wm8994_write(0x210, 0x0009); //LRCK=8KHz, Rate=MCLK/1536
1824 wm8994_write(0x300, 0x0118); //DSP/PCM 16bits, R ADC = L ADC
1825 wm8994_write(0x606, 0x0003);
1826 wm8994_write(0x607, 0x0003);
1828 ////AIF1 Master Clock(SR=8KHz)
1829 wm8994_write(0x200, 0x0011);
1830 wm8994_write(0x302, 0x4000);
1831 wm8994_write(0x303, 0x00F0);
1832 wm8994_write(0x304, 0x0020);
1833 wm8994_write(0x305, 0x0020);
1836 wm8994_write(0x05, 0x3303);
1837 wm8994_write(0x420, 0x0000);
1838 wm8994_write(0x601, 0x0001);
1839 wm8994_write(0x602, 0x0001);
1840 wm8994_write(0x700, 0x8140);//SYNC issue, AIF1 ADCLRC1 from FLL after AIF1 MASTER!!!
1842 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1845 void mainMIC_to_baseband_to_earpiece(void) //pcmbaseband
1847 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1849 if(wm8994_current_mode==wm8994_mainMIC_to_baseband_to_earpiece)return;
1850 wm8994_current_mode=wm8994_mainMIC_to_baseband_to_earpiece;
1854 wm8994_write(0x01, 0x0003|wm8994_mic_VCC);
1856 wm8994_write(0x221, 0x0700); //MCLK=12MHz
1857 wm8994_write(0x222, 0x3127);
1858 wm8994_write(0x223, 0x0100);
1859 wm8994_write(0x220, 0x0004);
1861 wm8994_write(0x220, 0x0005);
1863 wm8994_write(0x01, 0x0803|wm8994_mic_VCC); ///0x0813);
1864 wm8994_write(0x02, 0x0240); ///0x0110);
1865 wm8994_write(0x03, 0x00F0);
1866 wm8994_write(0x04, 0x3003);
1867 wm8994_write(0x05, 0x3003);
1868 wm8994_write(0x18, 0x011F);
1869 wm8994_write(0x1F, 0x0000);
1870 wm8994_write(0x28, 0x0030); ///0x0003);
1871 wm8994_write(0x29, 0x0020);
1872 wm8994_write(0x2D, 0x0001);
1873 wm8994_write(0x2E, 0x0001);
1874 wm8994_write(0x33, 0x0018);
1875 wm8994_write(0x200, 0x0001);
1876 wm8994_write(0x204, 0x0001);
1877 wm8994_write(0x208, 0x0007);
1878 wm8994_write(0x520, 0x0000);
1879 wm8994_write(0x601, 0x0004);
1880 wm8994_write(0x602, 0x0004);
1882 wm8994_write(0x610, 0x01C0); //DAC1 Left Volume bit0~7
1883 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
1884 wm8994_write(0x612, 0x01C0); //DAC2 Left Volume bit0~7
1885 wm8994_write(0x613, 0x01C0); //DAC2 Right Volume bit0~7
1887 wm8994_write(0x702, 0xC100);
1888 wm8994_write(0x703, 0xC100);
1889 wm8994_write(0x704, 0xC100);
1890 wm8994_write(0x706, 0x4100);
1891 wm8994_write(0x204, 0x0011); //AIF2 MCLK=FLL1
1892 wm8994_write(0x211, 0x0009); //LRCK=8KHz, Rate=MCLK/1536
1894 wm8994_write(0x310, 0x4108); ///0x4118); ///interface dsp mode 16bit
1897 wm8994_write(0x310, 0x4118); ///0x4118); ///interface dsp mode 16bit
1900 wm8994_write(0x310, 0x4118); ///0x4118); ///interface dsp mode 16bit
1901 wm8994_write(0x241, 0x2f04);
1902 wm8994_write(0x242, 0x0000);
1903 wm8994_write(0x243, 0x0300);
1904 wm8994_write(0x240, 0x0004);
1906 wm8994_write(0x240, 0x0005);
1907 wm8994_write(0x204, 0x0019);
1908 wm8994_write(0x211, 0x0003);
1909 wm8994_write(0x244, 0x0c83);
1910 wm8994_write(0x620, 0x0000);
1912 #ifdef THINKWILL_M800_MODE
1913 wm8994_write(0x310, 0x4118); ///0x4118); ///interface dsp mode 16bit
1915 wm8994_write(0x313, 0x00F0);
1916 wm8994_write(0x314, 0x0020);
1917 wm8994_write(0x315, 0x0020);
1919 wm8994_write(0x603, 0x018C); //Rev.D ADCL SideTone
1920 wm8994_write(0x604, 0x0010);
1921 wm8994_write(0x605, 0x0010);
1922 wm8994_write(0x621, 0x0000); ///0x0001);
1923 wm8994_write(0x317, 0x0003);
1924 wm8994_write(0x312, 0x0000); //AIF2 SET AS MASTER
1926 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
1929 void mainMIC_to_baseband_to_earpiece_and_record(void) //pcmbaseband
1931 DBG("%s::%d\n",__FUNCTION__,__LINE__);
1933 if(wm8994_current_mode==wm8994_mainMIC_to_baseband_to_earpiece_and_record)return;
1934 wm8994_current_mode=wm8994_mainMIC_to_baseband_to_earpiece_and_record;
1938 wm8994_write(0x01, 0x0003|wm8994_mic_VCC);
1940 wm8994_write(0x221, 0x0700); //MCLK=12MHz
1941 wm8994_write(0x222, 0x3127);
1942 wm8994_write(0x223, 0x0100);
1943 wm8994_write(0x220, 0x0004);
1945 wm8994_write(0x220, 0x0005);
1947 wm8994_write(0x01, 0x0803|wm8994_mic_VCC);
1948 wm8994_write(0x02, 0x0110);
1949 wm8994_write(0x03, 0x00F0);
1950 wm8994_write(0x04, 0x3003);
1951 wm8994_write(0x05, 0x3003);
1952 wm8994_write(0x1A, 0x010B);
1953 wm8994_write(0x1F, 0x0000);
1954 wm8994_write(0x28, 0x0003);
1955 wm8994_write(0x2A, 0x0020);
1956 wm8994_write(0x2D, 0x0001);
1957 wm8994_write(0x2E, 0x0001);
1958 wm8994_write(0x33, 0x0018);
1959 wm8994_write(0x200, 0x0001);
1960 wm8994_write(0x204, 0x0001);
1961 wm8994_write(0x208, 0x0007);
1962 wm8994_write(0x520, 0x0000);
1963 wm8994_write(0x601, 0x0004);
1964 wm8994_write(0x602, 0x0004);
1966 wm8994_write(0x610, 0x01C0); //DAC1 Left Volume bit0~7
1967 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
1968 wm8994_write(0x612, 0x01C0); //DAC2 Left Volume bit0~7
1969 wm8994_write(0x613, 0x01C0); //DAC2 Right Volume bit0~7
1971 wm8994_write(0x702, 0xC100);
1972 wm8994_write(0x703, 0xC100);
1973 wm8994_write(0x704, 0xC100);
1974 wm8994_write(0x706, 0x4100);
1975 wm8994_write(0x204, 0x0011); //AIF2 MCLK=FLL1
1976 wm8994_write(0x211, 0x0009); //LRCK=8KHz, Rate=MCLK/1536
1977 wm8994_write(0x310, 0x4118); //DSP/PCM 16bits
1978 wm8994_write(0x313, 0x00F0);
1979 wm8994_write(0x314, 0x0020);
1980 wm8994_write(0x315, 0x0020);
1982 wm8994_write(0x603, 0x018C); //Rev.D ADCL SideTone
1983 wm8994_write(0x604, 0x0010);
1984 wm8994_write(0x605, 0x0010);
1985 wm8994_write(0x621, 0x0001);
1988 wm8994_write(0x04, 0x3303);
1989 wm8994_write(0x200, 0x0001);
1990 wm8994_write(0x208, 0x000F);
1991 wm8994_write(0x210, 0x0009); //LRCK=8KHz, Rate=MCLK/1536
1992 wm8994_write(0x300, 0xC118); //DSP/PCM 16bits, R ADC = L ADC
1993 wm8994_write(0x606, 0x0003);
1994 wm8994_write(0x607, 0x0003);
1996 ////AIF1 Master Clock(SR=8KHz)
1997 wm8994_write(0x200, 0x0011);
1998 wm8994_write(0x302, 0x4000);
1999 wm8994_write(0x303, 0x00F0);
2000 wm8994_write(0x304, 0x0020);
2001 wm8994_write(0x305, 0x0020);
2004 wm8994_write(0x05, 0x3303);
2005 wm8994_write(0x420, 0x0000);
2006 wm8994_write(0x601, 0x0001);
2007 wm8994_write(0x602, 0x0001);
2008 wm8994_write(0x700, 0x8140);//SYNC issue, AIF1 ADCLRC1 from FLL after AIF1 MASTER!!!
2010 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
2013 void mainMIC_to_baseband_to_speakers(void) //pcmbaseband
2015 DBG("%s::%d\n",__FUNCTION__,__LINE__);
2017 if(wm8994_current_mode==wm8994_mainMIC_to_baseband_to_speakers)return;
2018 wm8994_current_mode=wm8994_mainMIC_to_baseband_to_speakers;
2022 wm8994_write(0x01, 0x0003|wm8994_mic_VCC); //0x0013);
2024 wm8994_write(0x221, 0x0700); //MCLK=12MHz //FLL1 CONTRLO(2)
2025 wm8994_write(0x222, 0x3127); //FLL1 CONTRLO(3)
2026 wm8994_write(0x223, 0x0100); //FLL1 CONTRLO(4)
2027 wm8994_write(0x220, 0x0004); //FLL1 CONTRLO(1)
2029 wm8994_write(0x220, 0x0005); //FLL1 CONTRLO(1)
2031 wm8994_write(0x01, 0x3003|wm8994_mic_VCC);
2032 wm8994_write(0x02, 0x0110);
2033 wm8994_write(0x03, 0x0030); ///0x0330);
2034 wm8994_write(0x04, 0x3003);
2035 wm8994_write(0x05, 0x3003);
2036 wm8994_write(0x1A, 0x011F);
2037 wm8994_write(0x22, 0x0000);
2038 wm8994_write(0x23, 0x0100); ///0x0000);
2039 //wm8994_write(0x25, 0x0152);
2040 wm8994_write(0x28, 0x0003);
2041 wm8994_write(0x2A, 0x0020);
2042 wm8994_write(0x2D, 0x0001);
2043 wm8994_write(0x2E, 0x0001);
2044 wm8994_write(0x36, 0x000C); //MIXOUTL_TO_SPKMIXL MIXOUTR_TO_SPKMIXR
2045 wm8994_write(0x200, 0x0001); //AIF1 CLOCKING(1)
2046 wm8994_write(0x204, 0x0001); //AIF2 CLOCKING(1)
2047 wm8994_write(0x208, 0x0007); //CLOCKING(1)
2048 wm8994_write(0x520, 0x0000); //AIF2 DAC FILTERS(1)
2049 wm8994_write(0x601, 0x0004); //AIF2DACL_DAC1L
2050 wm8994_write(0x602, 0x0004); //AIF2DACR_DAC1R
2052 wm8994_write(0x610, 0x01C0); //DAC1 Left Volume bit0~7
2053 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
2054 wm8994_write(0x612, 0x01C0); //DAC2 Left Volume bit0~7
2055 wm8994_write(0x613, 0x01C0); //DAC2 Right Volume bit0~7
2057 wm8994_write(0x702, 0xC100); //GPIO3
2058 wm8994_write(0x703, 0xC100); //GPIO4
2059 wm8994_write(0x704, 0xC100); //GPIO5
2060 wm8994_write(0x706, 0x4100); //GPIO7
2061 wm8994_write(0x204, 0x0011); //AIF2 MCLK=FLL1
2062 wm8994_write(0x211, 0x0009); //LRCK=8KHz, Rate=MCLK/1536
2064 wm8994_write(0x310, 0xc108); ///0x4118); ///interface dsp mode 16bit
2067 wm8994_write(0x310, 0xc018); ///0x4118); ///interface dsp mode 16bit
2070 wm8994_write(0x310, 0xc118); ///0x4118); ///interface dsp mode 16bit
2071 wm8994_write(0x241, 0x2f04);
2072 wm8994_write(0x242, 0x0000);
2073 wm8994_write(0x243, 0x0300);
2074 wm8994_write(0x240, 0x0004);
2076 wm8994_write(0x240, 0x0005);
2077 wm8994_write(0x204, 0x0019);
2078 wm8994_write(0x211, 0x0003);
2079 wm8994_write(0x244, 0x0c83);
2080 wm8994_write(0x620, 0x0000);
2082 #ifdef THINKWILL_M800_MODE
2083 wm8994_write(0x310, 0xc118); ///0x4118); ///interface dsp mode 16bit
2085 wm8994_write(0x313, 0x00F0); //AIF2BCLK
2086 wm8994_write(0x314, 0x0020); //AIF2ADCLRCK
2087 wm8994_write(0x315, 0x0020); //AIF2DACLRCLK
2089 wm8994_write(0x603, 0x018C); //Rev.D ADCL SideTone
2090 wm8994_write(0x604, 0x0020); ///0x0010); //ADC2_TO_DAC2L
2091 wm8994_write(0x605, 0x0020); //0x0010); //ADC2_TO_DAC2R
2092 wm8994_write(0x621, 0x0000); ///0x0001);
2093 wm8994_write(0x317, 0x0003);
2094 wm8994_write(0x312, 0x0000); //AIF2 SET AS MASTER
2096 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
2099 void mainMIC_to_baseband_to_speakers_and_record(void) //pcmbaseband
2101 DBG("%s::%d\n",__FUNCTION__,__LINE__);
2103 if(wm8994_current_mode==wm8994_mainMIC_to_baseband_to_speakers_and_record)return;
2104 wm8994_current_mode=wm8994_mainMIC_to_baseband_to_speakers_and_record;
2108 wm8994_write(0x01, 0x0003|wm8994_mic_VCC);
2110 wm8994_write(0x221, 0x0700); //MCLK=12MHz
2111 wm8994_write(0x222, 0x3127);
2112 wm8994_write(0x223, 0x0100);
2113 wm8994_write(0x220, 0x0004);
2115 wm8994_write(0x220, 0x0005);
2117 wm8994_write(0x02, 0x0110);
2118 wm8994_write(0x03, 0x0330);
2119 wm8994_write(0x04, 0x3003);
2120 wm8994_write(0x05, 0x3003);
2121 wm8994_write(0x1A, 0x010B);
2122 wm8994_write(0x22, 0x0000);
2123 wm8994_write(0x23, 0x0000);
2124 wm8994_write(0x28, 0x0003);
2125 wm8994_write(0x2A, 0x0020);
2126 wm8994_write(0x2D, 0x0001);
2127 wm8994_write(0x2E, 0x0001);
2128 wm8994_write(0x36, 0x000C);
2129 wm8994_write(0x200, 0x0001);
2130 wm8994_write(0x204, 0x0001);
2131 wm8994_write(0x208, 0x0007);
2132 wm8994_write(0x520, 0x0000);
2133 wm8994_write(0x601, 0x0004);
2134 wm8994_write(0x602, 0x0004);
2136 wm8994_write(0x610, 0x01C0); //DAC1 Left Volume bit0~7
2137 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
2138 wm8994_write(0x612, 0x01C0); //DAC2 Left Volume bit0~7
2139 wm8994_write(0x613, 0x01C0); //DAC2 Right Volume bit0~7
2141 wm8994_write(0x700, 0x8141);
2142 wm8994_write(0x702, 0xC100);
2143 wm8994_write(0x703, 0xC100);
2144 wm8994_write(0x704, 0xC100);
2145 wm8994_write(0x706, 0x4100);
2146 wm8994_write(0x204, 0x0011); //AIF2 MCLK=FLL1
2147 wm8994_write(0x211, 0x0009); //LRCK=8KHz, Rate=MCLK/1536
2148 wm8994_write(0x310, 0x4118); //DSP/PCM 16bits
2149 wm8994_write(0x313, 0x00F0);
2150 wm8994_write(0x314, 0x0020);
2151 wm8994_write(0x315, 0x0020);
2153 wm8994_write(0x603, 0x018C); //Rev.D ADCL SideTone
2154 wm8994_write(0x604, 0x0010);
2155 wm8994_write(0x605, 0x0010);
2156 wm8994_write(0x621, 0x0001);
2159 wm8994_write(0x04, 0x3303);
2160 wm8994_write(0x200, 0x0001);
2161 wm8994_write(0x208, 0x000F);
2162 wm8994_write(0x210, 0x0009); //LRCK=8KHz, Rate=MCLK/1536
2163 wm8994_write(0x300, 0xC118); //DSP/PCM 16bits, R ADC = L ADC
2164 wm8994_write(0x606, 0x0003);
2165 wm8994_write(0x607, 0x0003);
2167 ////AIF1 Master Clock(SR=8KHz)
2168 wm8994_write(0x200, 0x0011);
2169 wm8994_write(0x302, 0x4000);
2170 wm8994_write(0x303, 0x00F0);
2171 wm8994_write(0x304, 0x0020);
2172 wm8994_write(0x305, 0x0020);
2175 wm8994_write(0x05, 0x3303);
2176 wm8994_write(0x420, 0x0000);
2177 wm8994_write(0x601, 0x0001);
2178 wm8994_write(0x602, 0x0001);
2179 wm8994_write(0x700, 0x8140);//SYNC issue, AIF1 ADCLRC1 from FLL after AIF1 MASTER!!!
2181 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
2184 void BT_baseband(void) //pcmbaseband
2186 DBG("%s::%d\n",__FUNCTION__,__LINE__);
2188 if(wm8994_current_mode==wm8994_BT_baseband)return;
2189 wm8994_current_mode=wm8994_BT_baseband;
2193 wm8994_write(0x01 ,0x0003);
2196 wm8994_write(0x200 ,0x0001);
2197 wm8994_write(0x221 ,0x0700);//MCLK=12MHz
2198 wm8994_write(0x222 ,0x3127);
2199 wm8994_write(0x223 ,0x0100);
2200 wm8994_write(0x220 ,0x0004);
2202 wm8994_write(0x220 ,0x0005);
2204 wm8994_write(0x02 ,0x0000);
2205 wm8994_write(0x200 ,0x0011);// AIF1 MCLK=FLL1
2206 wm8994_write(0x210 ,0x0009);// LRCK=8KHz, Rate=MCLK/1536
2207 wm8994_write(0x300 ,0x4018);// DSP/PCM 16bits
2209 wm8994_write(0x204 ,0x0011);// AIF2 MCLK=FLL1
2210 wm8994_write(0x211 ,0x0009);// LRCK=8KHz, Rate=MCLK/1536
2211 wm8994_write(0x310 ,0x4118);// DSP/PCM 16bits
2212 wm8994_write(0x208 ,0x000F);
2215 wm8994_write(0x700 ,0x8101);
2217 wm8994_write(0x702 ,0xC100);
2218 wm8994_write(0x703 ,0xC100);
2219 wm8994_write(0x704 ,0xC100);
2220 wm8994_write(0x706 ,0x4100);
2222 wm8994_write(0x707 ,0xA100);
2223 wm8994_write(0x708 ,0xA100);
2224 wm8994_write(0x709 ,0xA100);
2225 wm8994_write(0x70A ,0xA100);
2227 wm8994_write(0x06 ,0x0001);
2229 wm8994_write(0x02 ,0x0300);
2230 wm8994_write(0x03 ,0x0030);
2231 wm8994_write(0x04 ,0x3301);//ADCL off
2232 wm8994_write(0x05 ,0x3301);//DACL off
2234 wm8994_write(0x2A ,0x0005);
2236 wm8994_write(0x313 ,0x00F0);
2237 wm8994_write(0x314 ,0x0020);
2238 wm8994_write(0x315 ,0x0020);
2240 wm8994_write(0x2E ,0x0001);
2241 wm8994_write(0x420 ,0x0000);
2242 wm8994_write(0x520 ,0x0000);
2243 wm8994_write(0x601 ,0x0001);
2244 wm8994_write(0x602 ,0x0001);
2245 wm8994_write(0x604 ,0x0001);
2246 wm8994_write(0x605 ,0x0001);
2247 wm8994_write(0x607 ,0x0002);
2248 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
2249 wm8994_write(0x612, 0x01C0); //DAC2 Left Volume bit0~7
2250 wm8994_write(0x613, 0x01C0); //DAC2 Right Volume bit0~7
2253 wm8994_write(0x312 ,0x4000);
2255 wm8994_write(0x606 ,0x0001);
2256 wm8994_write(0x607 ,0x0003);//R channel for data mix/CPU record data
2259 ////////////HP output test
2260 wm8994_write(0x01 ,0x0303);
2261 wm8994_write(0x4C ,0x9F25);
2262 wm8994_write(0x60 ,0x00EE);
2263 ///////////end HP test
2265 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
2268 void BT_baseband_and_record(void) //pcmbaseband
2270 DBG("%s::%d\n",__FUNCTION__,__LINE__);
2272 if(wm8994_current_mode==wm8994_BT_baseband_and_record)return;
2273 wm8994_current_mode=wm8994_BT_baseband_and_record;
2277 wm8994_write(0x01 ,0x0003);
2280 wm8994_write(0x200 ,0x0001);
2281 wm8994_write(0x221 ,0x0700);//MCLK=12MHz
2282 wm8994_write(0x222 ,0x3127);
2283 wm8994_write(0x223 ,0x0100);
2284 wm8994_write(0x220 ,0x0004);
2286 wm8994_write(0x220 ,0x0005);
2288 wm8994_write(0x02 ,0x0000);
2289 wm8994_write(0x200 ,0x0011);// AIF1 MCLK=FLL1
2290 wm8994_write(0x210 ,0x0009);// LRCK=8KHz, Rate=MCLK/1536
2291 wm8994_write(0x300 ,0x4018);// DSP/PCM 16bits
2293 wm8994_write(0x204 ,0x0011);// AIF2 MCLK=FLL1
2294 wm8994_write(0x211 ,0x0009);// LRCK=8KHz, Rate=MCLK/1536
2295 wm8994_write(0x310 ,0x4118);// DSP/PCM 16bits
2296 wm8994_write(0x208 ,0x000F);
2299 wm8994_write(0x700 ,0x8101);
2301 wm8994_write(0x702 ,0xC100);
2302 wm8994_write(0x703 ,0xC100);
2303 wm8994_write(0x704 ,0xC100);
2304 wm8994_write(0x706 ,0x4100);
2306 wm8994_write(0x707 ,0xA100);
2307 wm8994_write(0x708 ,0xA100);
2308 wm8994_write(0x709 ,0xA100);
2309 wm8994_write(0x70A ,0xA100);
2311 wm8994_write(0x06 ,0x0001);
2312 wm8994_write(0x02 ,0x0300);
2313 wm8994_write(0x03 ,0x0030);
2314 wm8994_write(0x04 ,0x3301);//ADCL off
2315 wm8994_write(0x05 ,0x3301);//DACL off
2316 wm8994_write(0x2A ,0x0005);
2318 wm8994_write(0x313 ,0x00F0);
2319 wm8994_write(0x314 ,0x0020);
2320 wm8994_write(0x315 ,0x0020);
2322 wm8994_write(0x2E ,0x0001);
2323 wm8994_write(0x420 ,0x0000);
2324 wm8994_write(0x520 ,0x0000);
2325 wm8994_write(0x602 ,0x0001);
2326 wm8994_write(0x604 ,0x0001);
2327 wm8994_write(0x605 ,0x0001);
2328 wm8994_write(0x607 ,0x0002);
2329 wm8994_write(0x611, 0x01C0); //DAC1 Right Volume bit0~7
2330 wm8994_write(0x612, 0x01C0); //DAC2 Left Volume bit0~7
2331 wm8994_write(0x613, 0x01C0); //DAC2 Right Volume bit0~7
2333 wm8994_write(0x312 ,0x4000);
2335 wm8994_write(0x606 ,0x0001);
2336 wm8994_write(0x607 ,0x0003);//R channel for data mix/CPU record data
2337 ////////////HP output test
2338 wm8994_write(0x01 ,0x0303);
2339 wm8994_write(0x4C ,0x9F25);
2340 wm8994_write(0x60 ,0x00EE);
2341 ///////////end HP test
2343 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
2348 typedef void (wm8994_codec_fnc_t) (void);
2350 wm8994_codec_fnc_t *wm8994_codec_sequence[] = {
2353 AP_to_speakers_and_headset,
2354 recorder_and_AP_to_headset,
2355 recorder_and_AP_to_speakers,
2357 FM_to_headset_and_record,
2359 FM_to_speakers_and_record,
2360 handsetMIC_to_baseband_to_headset,
2361 mainMIC_to_baseband_to_headset,
2362 handsetMIC_to_baseband_to_headset_and_record,
2363 mainMIC_to_baseband_to_earpiece,
2364 mainMIC_to_baseband_to_earpiece_and_record,
2365 mainMIC_to_baseband_to_speakers,
2366 mainMIC_to_baseband_to_speakers_and_record,
2368 BT_baseband_and_record,
2371 void wm8994_set_AIF1DAC_EQ(void){
2373 wm8994_write(0x0480, 0x0001|((bank_vol[1]+12)<<11)|
2374 ((bank_vol[2]+12)<<6)|((bank_vol[3]+12)<<1));
2375 wm8994_write(0x0481, 0x0000|((bank_vol[4]+12)<<11)|
2376 ((bank_vol[5]+12)<<6));
2379 void wm8994_set_channel_vol(void)
2381 switch(wm8994_current_mode){
2382 case wm8994_AP_to_speakers_and_headset:
2383 if(speaker_normal_vol > 6)
2384 speaker_normal_vol = 6;
2385 else if(speaker_normal_vol < -57)
2386 speaker_normal_vol = -57;
2387 if(headset_normal_vol > 6)
2388 headset_normal_vol = 6;
2389 else if(headset_normal_vol < -57)
2390 headset_normal_vol = -57;
2392 DBG("headset_normal_vol = %ddB \n",headset_normal_vol);
2393 DBG("speaker_normal_vol = %ddB \n",speaker_normal_vol);
2395 vol = speaker_normal_vol;
2397 wm8994_write(0x26, 320+vol+57); //-57dB~6dB
2398 wm8994_write(0x27, 320+vol+57); //-57dB~6dB
2400 // wm8994_write(0x25, 0x003F); //0~12dB
2401 wm8994_write(0x26, 320+vol+45); //-57dB~6dB
2402 wm8994_write(0x27, 320+vol+45); //-57dB~6dB
2404 vol = headset_normal_vol-4;
2406 //for turn down headset volume when ringtone
2412 wm8994_write(0x1C, 320+vol+57); //-57dB~6dB
2413 wm8994_write(0x1D, 320+vol+57); //-57dB~6dB
2415 wm8994_set_AIF1DAC_EQ();
2418 case wm8994_recorder_and_AP_to_headset:
2419 if(headset_normal_vol > 6)
2420 headset_normal_vol = 6;
2421 else if(headset_normal_vol < -57)
2422 headset_normal_vol = -57;
2423 if(recorder_vol > 60)
2425 else if(recorder_vol < -16)
2428 DBG("recorder_vol = %ddB \n",recorder_vol);
2429 DBG("headset_normal_vol = %ddB \n",headset_normal_vol);
2433 wm8994_write(0x1A, 320+(vol+16)*10/15); //mic vol
2435 wm8994_write(0x2A, 0x0030);
2436 wm8994_write(0x1A, 320+(vol-14)*10/15); //mic vol
2438 vol = headset_normal_vol;
2439 wm8994_write(0x1C, 320+vol+57); //-57dB~6dB
2440 wm8994_write(0x1D, 320+vol+57); //-57dB~6dB
2443 case wm8994_recorder_and_AP_to_speakers:
2444 if(recorder_vol > 60)
2446 else if(recorder_vol < -16)
2448 if(speaker_normal_vol > 6)
2449 speaker_normal_vol = 6;
2450 else if(speaker_normal_vol < -57)
2451 speaker_normal_vol = -57;
2453 DBG("speaker_normal_vol = %ddB \n",speaker_normal_vol);
2454 DBG("recorder_vol = %ddB \n",recorder_vol);
2458 wm8994_write(0x1A, 320+(vol+16)*10/15); //mic vol
2460 wm8994_write(0x2A, 0x0030);
2461 wm8994_write(0x1A, 320+(vol-14)*10/15); //mic vol
2464 vol = speaker_normal_vol;
2465 wm8994_write(0x26, 320+vol+57); //-57dB~6dB
2466 wm8994_write(0x27, 320+vol+57); //-57dB~6dB
2468 wm8994_set_AIF1DAC_EQ();
2471 case wm8994_handsetMIC_to_baseband_to_headset:
2472 if(headset_incall_vol > 6)
2473 headset_incall_vol = 6;
2474 else if(headset_incall_vol < -12)
2475 headset_incall_vol = -12;
2476 if(headset_incall_mic_vol > 30)
2477 headset_incall_mic_vol = 30;
2478 else if(headset_incall_mic_vol < -22)
2479 headset_incall_mic_vol = -22;
2481 DBG("headset_incall_mic_vol = %ddB \n",headset_incall_mic_vol);
2482 DBG("headset_incall_vol = %ddB \n",headset_incall_vol);
2484 vol = headset_incall_mic_vol;
2486 wm8994_write(0x1E, 0x0016); //mic vol
2487 wm8994_write(0x18, 320+(vol+22)*10/15); //mic vol
2489 wm8994_write(0x1E, 0x0006); //mic vol
2490 wm8994_write(0x18, 320+(vol+16)*10/15); //mic vol
2492 #ifdef CONFIG_SND_BB_DIFFERENTIAL_INPUT
2493 vol = headset_incall_vol;
2494 wm8994_write(0x2B, (vol+12)/3+1); //-12~6dB
2498 case wm8994_mainMIC_to_baseband_to_headset:
2499 if(headset_incall_vol > 6)
2500 headset_incall_vol = 6;
2501 else if(headset_incall_vol < -12)
2502 headset_incall_vol = -12;
2503 if(speaker_incall_mic_vol > 30)
2504 speaker_incall_mic_vol = 30;
2505 else if(speaker_incall_mic_vol < -22)
2506 speaker_incall_mic_vol = -22;
2508 DBG("speaker_incall_mic_vol = %ddB \n",speaker_incall_mic_vol);
2509 DBG("headset_incall_vol = %ddB \n",headset_incall_vol);
2511 vol=speaker_incall_mic_vol;
2513 wm8994_write(0x1E, 0x0016); //mic vol
2514 wm8994_write(0x1A, 320+(vol+22)*10/15); //mic vol
2516 wm8994_write(0x1E, 0x0006); //mic vol
2517 wm8994_write(0x1A, 320+(vol+16)*10/15); //mic vol
2519 #ifdef CONFIG_SND_BB_DIFFERENTIAL_INPUT
2520 vol = headset_incall_vol;
2521 wm8994_write(0x2B, (vol+12)/3+1); //-12~6dB
2525 case wm8994_mainMIC_to_baseband_to_earpiece:
2526 if(speaker_incall_mic_vol > 30)
2527 speaker_incall_mic_vol = 30;
2528 else if(speaker_incall_mic_vol < -22)
2529 speaker_incall_mic_vol = -22;
2530 if(earpiece_incall_vol>6)
2531 earpiece_incall_vol = 6;
2532 else if(earpiece_incall_vol<-21)
2533 earpiece_incall_vol = -21;
2535 DBG("earpiece_incall_vol = %ddB \n",earpiece_incall_vol);
2536 DBG("speaker_incall_mic_vol = %ddB \n",speaker_incall_mic_vol);
2538 vol = earpiece_incall_vol;
2540 wm8994_write(0x33, 0x0018); //6dB
2541 wm8994_write(0x31, (((6-vol)/3)<<3)+(6-vol)/3); //-21dB
2543 wm8994_write(0x33, 0x0010);
2544 wm8994_write(0x31, (((-vol)/3)<<3)+(-vol)/3); //-21dB
2546 #ifdef CONFIG_SND_INSIDE_EARPIECE
2547 vol = speaker_incall_mic_vol;
2549 wm8994_write(0x1E, 0x0016);
2550 wm8994_write(0x1A, 320+(vol+22)*10/15);
2552 wm8994_write(0x1E, 0x0006);
2553 wm8994_write(0x1A, 320+(vol+16)*10/15);
2556 #ifdef CONFIG_SND_OUTSIDE_EARPIECE
2557 vol = headset_incall_mic_vol;
2559 wm8994_write(0x1E, 0x0016); //mic vol
2560 wm8994_write(0x18, 320+(vol+22)*10/15); //mic vol
2562 wm8994_write(0x1E, 0x0006); //mic vol
2563 wm8994_write(0x18, 320+(vol+16)*10/15); //mic vol
2568 case wm8994_mainMIC_to_baseband_to_speakers:
2569 if(speaker_incall_mic_vol > 30)
2570 speaker_incall_mic_vol = 30;
2571 else if(speaker_incall_mic_vol < -22)
2572 speaker_incall_mic_vol = -22;
2573 if(speaker_incall_vol > 12)
2574 speaker_incall_vol = 12;
2575 else if(speaker_incall_vol < -21)
2576 speaker_incall_vol = -21;
2578 DBG("speaker_incall_vol = %ddB \n",speaker_incall_vol);
2579 DBG("speaker_incall_mic_vol = %ddB \n",speaker_incall_mic_vol);
2581 vol = speaker_incall_mic_vol;
2583 wm8994_write(0x1E, 0x0016);
2584 wm8994_write(0x1A, 320+(vol+22)*10/15);
2586 wm8994_write(0x1E, 0x0006);
2587 wm8994_write(0x1A, 320+(vol+16)*10/15);
2589 vol = speaker_incall_vol;
2591 wm8994_write(0x31, (((-vol)/3)<<3)+(-vol)/3);
2593 // wm8994_write(0x25, ((vol*10/15)<<3)+vol*10/15);
2595 // wm8994_write(0x25, 0x003F);
2599 case wm8994_BT_baseband:
2600 if(BT_incall_vol > 30)
2602 else if(BT_incall_vol < -16)
2603 BT_incall_vol = -16;
2604 if(BT_incall_mic_vol > 6)
2605 BT_incall_mic_vol = 6;
2606 else if(BT_incall_mic_vol < -57)
2607 BT_incall_mic_vol = -57;
2609 DBG("BT_incall_mic_vol = %ddB \n",BT_incall_mic_vol);
2610 DBG("BT_incall_vol = %ddB \n",BT_incall_vol);
2612 vol = BT_incall_mic_vol;
2613 wm8994_write(0x20, 320+vol+57);
2615 vol = BT_incall_vol;
2616 wm8994_write(0x19, 0x0500+(vol+16)*10/15);
2619 printk("route error !\n");
2624 void wm8994_codec_set_volume(unsigned char system_type,unsigned char volume)
2626 DBG("%s:: system_type = %d volume = %d \n",__FUNCTION__,system_type,volume);
2628 if(system_type == VOICE_CALL)
2630 if(volume <= call_maxvol)
2633 printk("%s----%d::max value is 7\n",__FUNCTION__,__LINE__);
2634 call_vol=call_maxvol;
2636 if(wm8994_current_mode<=wm8994_mainMIC_to_baseband_to_speakers_and_record&&
2637 wm8994_current_mode>=wm8994_handsetMIC_to_baseband_to_headset)
2638 wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol);
2639 }else if(system_type == BLUETOOTH_SCO){
2640 if(volume <= BT_call_maxvol)
2641 BT_call_vol = volume;
2643 printk("%s----%d::max value is 15\n",__FUNCTION__,__LINE__);
2644 BT_call_vol = BT_call_maxvol;
2646 if(wm8994_current_mode<null&&
2647 wm8994_current_mode>=wm8994_BT_baseband)
2648 wm8994_set_volume(wm8994_current_mode,BT_call_vol,BT_call_maxvol);
2651 printk("%s----%d::system type error!\n",__FUNCTION__,__LINE__);
2655 void wm8994_set_volume(unsigned char wm8994_mode,unsigned char volume,unsigned char max_volume)
2657 unsigned short lvol=0,rvol=0;
2659 // DBG("%s::volume = %d \n",__FUNCTION__,volume);
2661 if(volume>max_volume)volume=max_volume;
2663 if(wm8994_mode == wm8994_handsetMIC_to_baseband_to_headset_and_record||
2664 wm8994_mode == wm8994_handsetMIC_to_baseband_to_headset||
2665 wm8994_mode == wm8994_mainMIC_to_baseband_to_headset)
2667 wm8994_read(0x001C, &lvol);
2668 wm8994_read(0x001D, &rvol);
2669 //HPOUT1L_VOL bit 0~5 /-57dB to +6dB in 1dB steps
2670 wm8994_write(0x001C, (lvol&~0x003f)|headset_vol_table[volume]);
2671 //HPOUT1R_VOL bit 0~5 /-57dB to +6dB in 1dB steps
2672 wm8994_write(0x001D, (rvol&~0x003f)|headset_vol_table[volume]);
2674 else if(wm8994_mode == wm8994_mainMIC_to_baseband_to_speakers_and_record||
2675 wm8994_mode == wm8994_mainMIC_to_baseband_to_speakers)
2677 wm8994_read(0x0026, &lvol);
2678 wm8994_read(0x0027, &rvol);
2679 //SPKOUTL_VOL bit 0~5 /-57dB to +6dB in 1dB steps
2680 wm8994_write(0x0026, (lvol&~0x003f)|speakers_vol_table[volume]);
2681 //SPKOUTR_VOL bit 0~5 /-57dB to +6dB in 1dB steps
2682 wm8994_write(0x0027, (rvol&~0x003f)|speakers_vol_table[volume]);
2684 else if(wm8994_mode == wm8994_mainMIC_to_baseband_to_earpiece||
2685 wm8994_mode == wm8994_mainMIC_to_baseband_to_earpiece_and_record)
2687 wm8994_read(0x0020, &lvol);
2688 wm8994_read(0x0021, &rvol);
2690 //MIXOUTL_VOL bit 0~5 /-57dB to +6dB in 1dB steps
2691 wm8994_write(0x0020, (lvol&~0x003f)|earpiece_vol_table[volume]);
2692 //MIXOUTR_VOL bit 0~5 /-57dB to +6dB in 1dB steps
2693 wm8994_write(0x0021, (rvol&~0x003f)|earpiece_vol_table[volume]);
2695 else if(wm8994_mode == wm8994_BT_baseband||wm8994_mode==wm8994_BT_baseband_and_record)
2697 //bit 0~4 /-16.5dB to +30dB in 1.5dB steps
2698 DBG("BT_vol_table[volume] = 0x%x\n",BT_vol_table[volume]);
2699 wm8994_write(0x0500, BT_vol_table[volume]);
2700 wm8994_write(0x0501, 0x0100);
2702 else if(wm8994_mode == null)
2704 wm8994_read(0x001C, &lvol);
2705 wm8994_read(0x001D, &rvol);
2706 wm8994_write(0x001C, (lvol&~0x003f)|headset_vol_table[volume]);
2707 wm8994_write(0x001D, (rvol&~0x003f)|headset_vol_table[volume]);
2708 wm8994_read(0x0026, &lvol);
2709 wm8994_read(0x0027, &rvol);
2710 wm8994_write(0x0026, (lvol&~0x003f)|speakers_vol_table[volume]);
2711 wm8994_write(0x0027, (rvol&~0x003f)|speakers_vol_table[volume]);
2712 wm8994_read(0x0020, &lvol);
2713 wm8994_read(0x0021, &rvol);
2714 wm8994_write(0x0020, (lvol&~0x003f)|earpiece_vol_table[volume]);
2715 wm8994_write(0x0021, (rvol&~0x003f)|earpiece_vol_table[volume]);
2719 void wm8994_check_channel(void)
2721 wm8994_codec_fnc_t **wm8994_fnc_ptr = wm8994_codec_sequence;
2722 unsigned char wm8994_mode = wm8994_current_mode;
2724 DBG("%s--%d::Enter\n",__FUNCTION__,__LINE__);
2726 isWM8994SetChannel = true;
2728 if(wm8994_mode < wm8994_AP_to_headset ||
2729 wm8994_mode > wm8994_BT_baseband_and_record)
2731 wm8994_mode = wm8994_recorder_and_AP_to_speakers;
2732 printk("%s--%d--: Wm8994 set channel with null mode\n",__FUNCTION__,__LINE__);
2735 wm8994_fnc_ptr += wm8994_mode;
2737 while(isSetChannelErr){
2738 gpio_request(WM_EN_PIN, NULL);
2739 gpio_direction_output(WM_EN_PIN,GPIO_LOW);
2740 gpio_free(WM_EN_PIN);
2744 gpio_request(WM_EN_PIN, NULL);
2745 gpio_direction_output(WM_EN_PIN,GPIO_HIGH);
2746 gpio_free(WM_EN_PIN);
2750 wm8994_current_mode = null;
2751 isSetChannelErr = false;
2753 (*wm8994_fnc_ptr)() ;
2756 isWM8994SetChannel = false;
2758 DBG("%s--%d::Exit\n",__FUNCTION__,__LINE__);
2761 #define SOC_DOUBLE_SWITCH_WM8994CODEC(xname, route) \
2762 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
2763 .info = snd_soc_info_route, \
2764 .get = snd_soc_get_route, .put = snd_soc_put_route, \
2765 .private_value = route }
2767 int snd_soc_info_route(struct snd_kcontrol *kcontrol,
2768 struct snd_ctl_elem_info *uinfo)
2770 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2773 uinfo->value.integer.min = 0;
2774 uinfo->value.integer.max = 0;
2778 int snd_soc_get_route(struct snd_kcontrol *kcontrol,
2779 struct snd_ctl_elem_value *ucontrol)
2784 int snd_soc_put_route(struct snd_kcontrol *kcontrol,
2785 struct snd_ctl_elem_value *ucontrol)
2787 char route = kcontrol->private_value & 0xff;
2790 wm8994_current_route = route;
2792 isWM8994SetChannel = true;
2796 case SPEAKER_NORMAL: //AP-> 8994Codec -> Speaker
2797 recorder_and_AP_to_speakers();
2800 case SPEAKER_INCALL: //BB-> 8994Codec -> Speaker
2801 mainMIC_to_baseband_to_speakers();
2805 case HEADSET_NORMAL: //AP-> 8994Codec -> Headset
2806 recorder_and_AP_to_headset();
2808 case HEADSET_INCALL: //AP-> 8994Codec -> Headset
2809 // if(isHSKey_MIC())
2810 handsetMIC_to_baseband_to_headset();
2812 // mainMIC_to_baseband_to_headset();
2817 case EARPIECE_INCALL: //:BB-> 8994Codec -> EARPIECE
2818 //#ifdef CONFIG_SND_NO_EARPIECE
2819 // mainMIC_to_baseband_to_speakers();
2821 mainMIC_to_baseband_to_earpiece();
2825 case EARPIECE_NORMAL: //:BB-> 8994Codec -> EARPIECE
2826 if(wm8994_current_mode==wm8994_handsetMIC_to_baseband_to_headset||
2827 wm8994_mainMIC_to_baseband_to_headset)
2828 recorder_and_AP_to_headset();
2829 else if(wm8994_current_mode==wm8994_mainMIC_to_baseband_to_speakers||
2830 wm8994_current_mode==wm8994_mainMIC_to_baseband_to_earpiece)
2831 recorder_and_AP_to_speakers();
2832 else if(wm8994_current_mode==wm8994_recorder_and_AP_to_speakers||
2833 wm8994_current_mode==wm8994_recorder_and_AP_to_speakers)
2836 recorder_and_AP_to_speakers();
2837 printk("%s--%d--: wm8994 with null mode\n",__FUNCTION__,__LINE__);
2843 case BLUETOOTH_SCO_INCALL: //BB-> 8994Codec -> BLUETOOTH_SCO
2848 case BLUETOOTH_A2DP_NORMAL: //AP-> 8994Codec -> BLUETOOTH_A2DP
2852 if(wm8994_current_mode==wm8994_AP_to_headset)
2853 recorder_and_AP_to_headset();
2854 else if(wm8994_current_mode==wm8994_AP_to_speakers)
2855 recorder_and_AP_to_speakers();
2856 else if(wm8994_current_mode==wm8994_recorder_and_AP_to_speakers||
2857 wm8994_current_mode==wm8994_recorder_and_AP_to_headset)
2860 recorder_and_AP_to_speakers();
2861 printk("%s--%d--: wm8994 with null mode\n",__FUNCTION__,__LINE__);
2865 case EARPIECE_RINGTONE:
2866 recorder_and_AP_to_speakers();
2869 case HEADSET_RINGTONE:
2870 AP_to_speakers_and_headset();
2873 case SPEAKER_RINGTONE:
2874 recorder_and_AP_to_speakers();
2878 //codec_daout_route();
2881 wm8994_check_channel();
2883 isWM8994SetChannel = false;
2891 static const char *bass_boost_txt[] = {"Linear Control", "Adaptive Boost"};
2892 static const struct soc_enum bass_boost =
2893 SOC_ENUM_SINGLE(WM8994_BASS, 7, 2, bass_boost_txt);
2895 static const char *bass_filter_txt[] = { "130Hz @ 48kHz", "200Hz @ 48kHz" };
2896 static const struct soc_enum bass_filter =
2897 SOC_ENUM_SINGLE(WM8994_BASS, 6, 2, bass_filter_txt);
2899 static const char *treble_txt[] = {"8kHz", "4kHz"};
2900 static const struct soc_enum treble =
2901 SOC_ENUM_SINGLE(WM8994_TREBLE, 6, 2, treble_txt);
2903 static const char *stereo_3d_lc_txt[] = {"200Hz", "500Hz"};
2904 static const struct soc_enum stereo_3d_lc =
2905 SOC_ENUM_SINGLE(WM8994_3D, 5, 2, stereo_3d_lc_txt);
2907 static const char *stereo_3d_uc_txt[] = {"2.2kHz", "1.5kHz"};
2908 static const struct soc_enum stereo_3d_uc =
2909 SOC_ENUM_SINGLE(WM8994_3D, 6, 2, stereo_3d_uc_txt);
2911 static const char *stereo_3d_func_txt[] = {"Capture", "Playback"};
2912 static const struct soc_enum stereo_3d_func =
2913 SOC_ENUM_SINGLE(WM8994_3D, 7, 2, stereo_3d_func_txt);
2915 static const char *alc_func_txt[] = {"Off", "Right", "Left", "Stereo"};
2916 static const struct soc_enum alc_func =
2917 SOC_ENUM_SINGLE(WM8994_ALC1, 7, 4, alc_func_txt);
2919 static const char *ng_type_txt[] = {"Constant PGA Gain",
2921 static const struct soc_enum ng_type =
2922 SOC_ENUM_SINGLE(WM8994_NGATE, 1, 2, ng_type_txt);
2924 static const char *deemph_txt[] = {"None", "32Khz", "44.1Khz", "48Khz"};
2925 static const struct soc_enum deemph =
2926 SOC_ENUM_SINGLE(WM8994_ADCDAC, 1, 4, deemph_txt);
2928 static const char *adcpol_txt[] = {"Normal", "L Invert", "R Invert",
2930 static const struct soc_enum adcpol =
2931 SOC_ENUM_SINGLE(WM8994_ADCDAC, 5, 4, adcpol_txt);
2933 static const DECLARE_TLV_DB_SCALE(pga_tlv, -1725, 75, 0);
2934 static const DECLARE_TLV_DB_SCALE(adc_tlv, -9750, 50, 1);
2935 static const DECLARE_TLV_DB_SCALE(dac_tlv, -12750, 50, 1);
2936 static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
2937 static const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0);
2939 static const struct snd_kcontrol_new wm8994_snd_controls[] = {
2941 SOC_DOUBLE_SWITCH_WM8994CODEC("Speaker incall Switch", SPEAKER_INCALL),
2942 SOC_DOUBLE_SWITCH_WM8994CODEC("Speaker normal Switch", SPEAKER_NORMAL),
2944 SOC_DOUBLE_SWITCH_WM8994CODEC("Earpiece incall Switch", EARPIECE_INCALL),
2945 SOC_DOUBLE_SWITCH_WM8994CODEC("Earpiece normal Switch", EARPIECE_NORMAL),
2947 SOC_DOUBLE_SWITCH_WM8994CODEC("Headset incall Switch", HEADSET_INCALL),
2948 SOC_DOUBLE_SWITCH_WM8994CODEC("Headset normal Switch", HEADSET_NORMAL),
2950 SOC_DOUBLE_SWITCH_WM8994CODEC("Bluetooth incall Switch", BLUETOOTH_SCO_INCALL),
2951 SOC_DOUBLE_SWITCH_WM8994CODEC("Bluetooth normal Switch", BLUETOOTH_SCO_NORMAL),
2953 SOC_DOUBLE_SWITCH_WM8994CODEC("Bluetooth-A2DP incall Switch", BLUETOOTH_A2DP_INCALL),
2954 SOC_DOUBLE_SWITCH_WM8994CODEC("Bluetooth-A2DP normal Switch", BLUETOOTH_A2DP_NORMAL),
2956 SOC_DOUBLE_SWITCH_WM8994CODEC("Capture Switch", MIC_CAPTURE),
2958 SOC_DOUBLE_SWITCH_WM8994CODEC("Earpiece ringtone Switch",EARPIECE_RINGTONE),
2959 SOC_DOUBLE_SWITCH_WM8994CODEC("Speaker ringtone Switch",SPEAKER_RINGTONE),
2960 SOC_DOUBLE_SWITCH_WM8994CODEC("Headset ringtone Switch",HEADSET_RINGTONE),
2967 static int wm8994_lrc_control(struct snd_soc_dapm_widget *w,
2968 struct snd_kcontrol *kcontrol, int event)
2973 static const char *wm8994_line_texts[] = {
2974 "Line 1", "Line 2", "PGA", "Differential"};
2976 static const unsigned int wm8994_line_values[] = {
2979 static const struct soc_enum wm8994_lline_enum =
2980 SOC_VALUE_ENUM_SINGLE(WM8994_LOUTM1, 0, 7,
2981 ARRAY_SIZE(wm8994_line_texts),
2983 wm8994_line_values);
2984 static const struct snd_kcontrol_new wm8994_left_line_controls =
2985 SOC_DAPM_VALUE_ENUM("Route", wm8994_lline_enum);
2987 static const struct soc_enum wm8994_rline_enum =
2988 SOC_VALUE_ENUM_SINGLE(WM8994_ROUTM1, 0, 7,
2989 ARRAY_SIZE(wm8994_line_texts),
2991 wm8994_line_values);
2992 static const struct snd_kcontrol_new wm8994_right_line_controls =
2993 SOC_DAPM_VALUE_ENUM("Route", wm8994_lline_enum);
2996 static const struct snd_kcontrol_new wm8994_left_mixer_controls[] = {
2997 SOC_DAPM_SINGLE("Playback Switch", WM8994_LOUTM1, 8, 1, 0),
2998 SOC_DAPM_SINGLE("Left Bypass Switch", WM8994_LOUTM1, 7, 1, 0),
2999 SOC_DAPM_SINGLE("Right Playback Switch", WM8994_LOUTM2, 8, 1, 0),
3000 SOC_DAPM_SINGLE("Right Bypass Switch", WM8994_LOUTM2, 7, 1, 0),
3004 static const struct snd_kcontrol_new wm8994_right_mixer_controls[] = {
3005 SOC_DAPM_SINGLE("Left Playback Switch", WM8994_ROUTM1, 8, 1, 0),
3006 SOC_DAPM_SINGLE("Left Bypass Switch", WM8994_ROUTM1, 7, 1, 0),
3007 SOC_DAPM_SINGLE("Playback Switch", WM8994_ROUTM2, 8, 1, 0),
3008 SOC_DAPM_SINGLE("Right Bypass Switch", WM8994_ROUTM2, 7, 1, 0),
3011 static const char *wm8994_pga_sel[] = {"Line 1", "Line 2", "Differential"};
3012 static const unsigned int wm8994_pga_val[] = { 0, 1, 3 };
3015 static const struct soc_enum wm8994_lpga_enum =
3016 SOC_VALUE_ENUM_SINGLE(WM8994_LADCIN, 6, 3,
3017 ARRAY_SIZE(wm8994_pga_sel),
3020 static const struct snd_kcontrol_new wm8994_left_pga_controls =
3021 SOC_DAPM_VALUE_ENUM("Route", wm8994_lpga_enum);
3024 static const struct soc_enum wm8994_rpga_enum =
3025 SOC_VALUE_ENUM_SINGLE(WM8994_RADCIN, 6, 3,
3026 ARRAY_SIZE(wm8994_pga_sel),
3029 static const struct snd_kcontrol_new wm8994_right_pga_controls =
3030 SOC_DAPM_VALUE_ENUM("Route", wm8994_rpga_enum);
3032 /* Differential Mux */
3033 static const char *wm8994_diff_sel[] = {"Line 1", "Line 2"};
3034 static const struct soc_enum diffmux =
3035 SOC_ENUM_SINGLE(WM8994_ADCIN, 8, 2, wm8994_diff_sel);
3036 static const struct snd_kcontrol_new wm8994_diffmux_controls =
3037 SOC_DAPM_ENUM("Route", diffmux);
3040 static const char *wm8994_mono_mux[] = {"Stereo", "Mono (Left)",
3041 "Mono (Right)", "Digital Mono"};
3042 static const struct soc_enum monomux =
3043 SOC_ENUM_SINGLE(WM8994_ADCIN, 6, 4, wm8994_mono_mux);
3044 static const struct snd_kcontrol_new wm8994_monomux_controls =
3045 SOC_DAPM_ENUM("Route", monomux);
3047 static const struct snd_soc_dapm_widget wm8994_dapm_widgets[] = {
3048 SND_SOC_DAPM_MICBIAS("Mic Bias", WM8994_PWR1, 1, 0),
3050 SND_SOC_DAPM_MUX("Differential Mux", SND_SOC_NOPM, 0, 0,
3051 &wm8994_diffmux_controls),
3052 SND_SOC_DAPM_MUX("Left ADC Mux", SND_SOC_NOPM, 0, 0,
3053 &wm8994_monomux_controls),
3054 SND_SOC_DAPM_MUX("Right ADC Mux", SND_SOC_NOPM, 0, 0,
3055 &wm8994_monomux_controls),
3057 SND_SOC_DAPM_MUX("Left PGA Mux", WM8994_PWR1, 5, 0,
3058 &wm8994_left_pga_controls),
3059 SND_SOC_DAPM_MUX("Right PGA Mux", WM8994_PWR1, 4, 0,
3060 &wm8994_right_pga_controls),
3062 SND_SOC_DAPM_MUX("Left Line Mux", SND_SOC_NOPM, 0, 0,
3063 &wm8994_left_line_controls),
3064 SND_SOC_DAPM_MUX("Right Line Mux", SND_SOC_NOPM, 0, 0,
3065 &wm8994_right_line_controls),
3067 SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8994_PWR1, 2, 0),
3068 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8994_PWR1, 3, 0),
3070 SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8994_PWR2, 7, 0),
3071 SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8994_PWR2, 8, 0),
3073 SND_SOC_DAPM_MIXER("Left Mixer", SND_SOC_NOPM, 0, 0,
3074 &wm8994_left_mixer_controls[0],
3075 ARRAY_SIZE(wm8994_left_mixer_controls)),
3076 SND_SOC_DAPM_MIXER("Right Mixer", SND_SOC_NOPM, 0, 0,
3077 &wm8994_right_mixer_controls[0],
3078 ARRAY_SIZE(wm8994_right_mixer_controls)),
3080 SND_SOC_DAPM_PGA("Right Out 2", WM8994_PWR2, 3, 0, NULL, 0),
3081 SND_SOC_DAPM_PGA("Left Out 2", WM8994_PWR2, 4, 0, NULL, 0),
3082 SND_SOC_DAPM_PGA("Right Out 1", WM8994_PWR2, 5, 0, NULL, 0),
3083 SND_SOC_DAPM_PGA("Left Out 1", WM8994_PWR2, 6, 0, NULL, 0),
3085 SND_SOC_DAPM_POST("LRC control", wm8994_lrc_control),
3087 SND_SOC_DAPM_OUTPUT("LOUT1"),
3088 SND_SOC_DAPM_OUTPUT("ROUT1"),
3089 SND_SOC_DAPM_OUTPUT("LOUT2"),
3090 SND_SOC_DAPM_OUTPUT("ROUT2"),
3091 SND_SOC_DAPM_OUTPUT("VREF"),
3093 SND_SOC_DAPM_INPUT("LINPUT1"),
3094 SND_SOC_DAPM_INPUT("LINPUT2"),
3095 SND_SOC_DAPM_INPUT("RINPUT1"),
3096 SND_SOC_DAPM_INPUT("RINPUT2"),
3099 static const struct snd_soc_dapm_route audio_map[] = {
3101 { "Left Line Mux", "Line 1", "LINPUT1" },
3102 { "Left Line Mux", "Line 2", "LINPUT2" },
3103 { "Left Line Mux", "PGA", "Left PGA Mux" },
3104 { "Left Line Mux", "Differential", "Differential Mux" },
3106 { "Right Line Mux", "Line 1", "RINPUT1" },
3107 { "Right Line Mux", "Line 2", "RINPUT2" },
3108 { "Right Line Mux", "PGA", "Right PGA Mux" },
3109 { "Right Line Mux", "Differential", "Differential Mux" },
3111 { "Left PGA Mux", "Line 1", "LINPUT1" },
3112 { "Left PGA Mux", "Line 2", "LINPUT2" },
3113 { "Left PGA Mux", "Differential", "Differential Mux" },
3115 { "Right PGA Mux", "Line 1", "RINPUT1" },
3116 { "Right PGA Mux", "Line 2", "RINPUT2" },
3117 { "Right PGA Mux", "Differential", "Differential Mux" },
3119 { "Differential Mux", "Line 1", "LINPUT1" },
3120 { "Differential Mux", "Line 1", "RINPUT1" },
3121 { "Differential Mux", "Line 2", "LINPUT2" },
3122 { "Differential Mux", "Line 2", "RINPUT2" },
3124 { "Left ADC Mux", "Stereo", "Left PGA Mux" },
3125 { "Left ADC Mux", "Mono (Left)", "Left PGA Mux" },
3126 { "Left ADC Mux", "Digital Mono", "Left PGA Mux" },
3128 { "Right ADC Mux", "Stereo", "Right PGA Mux" },
3129 { "Right ADC Mux", "Mono (Right)", "Right PGA Mux" },
3130 { "Right ADC Mux", "Digital Mono", "Right PGA Mux" },
3132 { "Left ADC", NULL, "Left ADC Mux" },
3133 { "Right ADC", NULL, "Right ADC Mux" },
3135 { "Left Line Mux", "Line 1", "LINPUT1" },
3136 { "Left Line Mux", "Line 2", "LINPUT2" },
3137 { "Left Line Mux", "PGA", "Left PGA Mux" },
3138 { "Left Line Mux", "Differential", "Differential Mux" },
3140 { "Right Line Mux", "Line 1", "RINPUT1" },
3141 { "Right Line Mux", "Line 2", "RINPUT2" },
3142 { "Right Line Mux", "PGA", "Right PGA Mux" },
3143 { "Right Line Mux", "Differential", "Differential Mux" },
3145 { "Left Mixer", "Playback Switch", "Left DAC" },
3146 { "Left Mixer", "Left Bypass Switch", "Left Line Mux" },
3147 { "Left Mixer", "Right Playback Switch", "Right DAC" },
3148 { "Left Mixer", "Right Bypass Switch", "Right Line Mux" },
3150 { "Right Mixer", "Left Playback Switch", "Left DAC" },
3151 { "Right Mixer", "Left Bypass Switch", "Left Line Mux" },
3152 { "Right Mixer", "Playback Switch", "Right DAC" },
3153 { "Right Mixer", "Right Bypass Switch", "Right Line Mux" },
3155 { "Left Out 1", NULL, "Left Mixer" },
3156 { "LOUT1", NULL, "Left Out 1" },
3157 { "Right Out 1", NULL, "Right Mixer" },
3158 { "ROUT1", NULL, "Right Out 1" },
3160 { "Left Out 2", NULL, "Left Mixer" },
3161 { "LOUT2", NULL, "Left Out 2" },
3162 { "Right Out 2", NULL, "Right Mixer" },
3163 { "ROUT2", NULL, "Right Out 2" },
3174 /* codec hifi mclk clock divider coefficients */
3175 static const struct _coeff_div coeff_div[] = {
3177 {12288000, 8000, 1536, 0x6, 0x0},
3178 {11289600, 8000, 1408, 0x16, 0x0},
3179 {18432000, 8000, 2304, 0x7, 0x0},
3180 {16934400, 8000, 2112, 0x17, 0x0},
3181 {12000000, 8000, 1500, 0x6, 0x1},
3184 {11289600, 11025, 1024, 0x18, 0x0},
3185 {16934400, 11025, 1536, 0x19, 0x0},
3186 {12000000, 11025, 1088, 0x19, 0x1},
3189 {12288000, 16000, 768, 0xa, 0x0},
3190 {18432000, 16000, 1152, 0xb, 0x0},
3191 {12000000, 16000, 750, 0xa, 0x1},
3194 {11289600, 22050, 512, 0x1a, 0x0},
3195 {16934400, 22050, 768, 0x1b, 0x0},
3196 {12000000, 22050, 544, 0x1b, 0x1},
3199 {12288000, 32000, 384, 0xc, 0x0},
3200 {18432000, 32000, 576, 0xd, 0x0},
3201 {12000000, 32000, 375, 0xa, 0x1},
3204 {11289600, 44100, 256, 0x10, 0x0},
3205 {16934400, 44100, 384, 0x11, 0x0},
3206 {12000000, 44100, 272, 0x11, 0x1},
3209 {12288000, 48000, 256, 0x0, 0x0},
3210 {18432000, 48000, 384, 0x1, 0x0},
3211 {12000000, 48000, 250, 0x0, 0x1},
3214 {11289600, 88200, 128, 0x1e, 0x0},
3215 {16934400, 88200, 192, 0x1f, 0x0},
3216 {12000000, 88200, 136, 0x1f, 0x1},
3219 {12288000, 96000, 128, 0xe, 0x0},
3220 {18432000, 96000, 192, 0xf, 0x0},
3221 {12000000, 96000, 125, 0xe, 0x1},
3225 static inline int get_coeff(int mclk, int rate)
3229 for (i = 0; i < ARRAY_SIZE(coeff_div); i++) {
3230 if (coeff_div[i].rate == rate && coeff_div[i].mclk == mclk)
3237 /* The set of rates we can generate from the above for each SYSCLK */
3239 static unsigned int rates_12288[] = {
3240 8000, 12000, 16000, 24000, 24000, 32000, 48000, 96000,
3243 static struct snd_pcm_hw_constraint_list constraints_12288 = {
3244 .count = ARRAY_SIZE(rates_12288),
3245 .list = rates_12288,
3248 static unsigned int rates_112896[] = {
3249 8000, 11025, 22050, 44100,
3252 static struct snd_pcm_hw_constraint_list constraints_112896 = {
3253 .count = ARRAY_SIZE(rates_112896),
3254 .list = rates_112896,
3257 static unsigned int rates_12[] = {
3258 8000, 11025, 12000, 16000, 22050, 2400, 32000, 41100, 48000,
3259 48000, 88235, 96000,
3262 static struct snd_pcm_hw_constraint_list constraints_12 = {
3263 .count = ARRAY_SIZE(rates_12),
3268 * Note that this should be called from init rather than from hw_params.
3270 static int wm8994_set_dai_sysclk(struct snd_soc_dai *codec_dai,
3271 int clk_id, unsigned int freq, int dir)
3273 struct snd_soc_codec *codec = codec_dai->codec;
3274 struct wm8994_priv *wm8994 = codec->private_data;
3276 DBG("%s----%d\n",__FUNCTION__,__LINE__);
3283 wm8994->sysclk_constraints = &constraints_112896;
3284 wm8994->sysclk = freq;
3291 wm8994->sysclk_constraints = &constraints_12288;
3292 wm8994->sysclk = freq;
3297 wm8994->sysclk_constraints = &constraints_12;
3298 wm8994->sysclk = freq;
3304 static int wm8994_set_dai_fmt(struct snd_soc_dai *codec_dai,
3310 static int wm8994_pcm_startup(struct snd_pcm_substream *substream,
3311 struct snd_soc_dai *dai)
3313 struct snd_soc_codec *codec = dai->codec;
3314 struct wm8994_priv *wm8994 = codec->private_data;
3316 /* The set of sample rates that can be supported depends on the
3317 * MCLK supplied to the CODEC - enforce this.
3320 if (!wm8994->sysclk) {
3322 "No MCLK configured, call set_sysclk() on init\n");
3326 snd_pcm_hw_constraint_list(substream->runtime, 0,
3327 SNDRV_PCM_HW_PARAM_RATE,
3328 wm8994->sysclk_constraints);
3333 static int wm8994_pcm_hw_params(struct snd_pcm_substream *substream,
3334 struct snd_pcm_hw_params *params,
3335 struct snd_soc_dai *dai)
3337 struct snd_soc_pcm_runtime *rtd = substream->private_data;
3338 struct snd_soc_device *socdev = rtd->socdev;
3339 struct snd_soc_codec *codec = socdev->card->codec;
3340 struct wm8994_priv *wm8994 = codec->private_data;
3343 coeff = get_coeff(wm8994->sysclk, params_rate(params));
3345 coeff = get_coeff(wm8994->sysclk / 2, params_rate(params));
3349 "Unable to configure sample rate %dHz with %dHz MCLK\n",
3350 params_rate(params), wm8994->sysclk);
3353 params_format(params);
3358 static int wm8994_mute(struct snd_soc_dai *dai, int mute)
3363 static int wm8994_set_bias_level(struct snd_soc_codec *codec,
3364 enum snd_soc_bias_level level)
3367 codec->bias_level = level;
3371 #define WM8994_RATES SNDRV_PCM_RATE_48000
3373 #define WM8994_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
3374 SNDRV_PCM_FMTBIT_S24_LE)
3376 static struct snd_soc_dai_ops wm8994_ops = {
3377 .startup = wm8994_pcm_startup,
3378 .hw_params = wm8994_pcm_hw_params,
3379 .set_fmt = wm8994_set_dai_fmt,
3380 .set_sysclk = wm8994_set_dai_sysclk,
3381 .digital_mute = wm8994_mute,
3382 /*add by qiuen for volume*/
3383 .set_volume = wm8994_codec_set_volume,
3386 struct snd_soc_dai wm8994_dai = {
3389 .stream_name = "Playback",
3392 .rates = WM8994_RATES,
3393 .formats = WM8994_FORMATS,
3396 .stream_name = "Capture",
3399 .rates = WM8994_RATES,
3400 .formats = WM8994_FORMATS,
3403 .symmetric_rates = 1,
3405 EXPORT_SYMBOL_GPL(wm8994_dai);
3407 static int wm8994_suspend(struct platform_device *pdev, pm_message_t state)
3409 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
3410 struct snd_soc_codec *codec = socdev->card->codec;
3412 isWM8994SetChannel = true;
3413 wm8994_set_bias_level(codec,SND_SOC_BIAS_OFF);
3414 wm8994_write(0x00, 0x00);
3417 gpio_request(WM_EN_PIN, NULL);
3418 gpio_direction_output(WM_EN_PIN,GPIO_LOW);
3419 gpio_free(WM_EN_PIN);
3426 static int wm8994_resume(struct platform_device *pdev)
3428 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
3429 struct snd_soc_codec *codec = socdev->card->codec;
3430 wm8994_codec_fnc_t **wm8994_fnc_ptr = wm8994_codec_sequence;
3431 unsigned char wm8994_resume_mode = wm8994_current_mode;
3432 wm8994_current_mode = null;
3434 gpio_request(WM_EN_PIN, NULL);
3435 gpio_direction_output(WM_EN_PIN,GPIO_HIGH);
3436 gpio_free(WM_EN_PIN);
3440 wm8994_set_bias_level(codec,SND_SOC_BIAS_STANDBY);
3441 if(wm8994_resume_mode == wm8994_recorder_and_AP_to_speakers ||
3442 wm8994_resume_mode == wm8994_recorder_and_AP_to_headset)
3444 DBG("wm8994 resume\n");
3446 else if(wm8994_resume_mode > wm8994_BT_baseband_and_record)
3448 wm8994_resume_mode = wm8994_recorder_and_AP_to_speakers;
3449 printk("%s--%d--: Wm8994 resume with null mode\n",__FUNCTION__,__LINE__);
3452 printk("%s--%d--: Wm8994 resume with error mode\n",__FUNCTION__,__LINE__);
3454 wm8994_fnc_ptr += wm8994_resume_mode;
3455 (*wm8994_fnc_ptr)() ;
3457 wm8994_check_channel();
3459 isWM8994SetChannel = false;
3463 static struct snd_soc_codec *wm8994_codec;
3466 static ssize_t wm8994_proc_write(struct file *file, const char __user *buffer,
3467 unsigned long len, void *data)
3475 unsigned short eqvol;
3476 unsigned char wm8994_proc_mode;
3477 wm8994_codec_fnc_t **wm8994_fnc_ptr = wm8994_codec_sequence;
3479 cookie_pot = (char *)vmalloc( len );
3486 if (copy_from_user( cookie_pot, buffer, len ))
3490 switch(cookie_pot[0])
3494 if(*(cookie_pot+1)=='+'){
3496 }else if(*(cookie_pot+1)=='-'){
3499 printk("Please press '+' or '-' follow 'n'!\n");
3502 switch(wm8994_current_route){
3503 case HEADSET_NORMAL:
3505 headset_normal_vol += 3;
3507 headset_normal_vol -= 3;
3509 if(headset_normal_vol > 6)
3510 headset_normal_vol = 6;
3511 else if(headset_normal_vol < -57)
3512 headset_normal_vol = -57;
3514 printk("headset_normal_vol = %ddB \n",headset_normal_vol);
3517 case SPEAKER_NORMAL:
3518 case EARPIECE_NORMAL:
3519 case SPEAKER_RINGTONE:
3520 case EARPIECE_RINGTONE:
3521 case BLUETOOTH_SCO_INCALL:
3523 speaker_normal_vol += 3;
3525 speaker_normal_vol -= 3;
3527 if(speaker_normal_vol > 6)
3528 speaker_normal_vol = 6;
3529 else if(speaker_normal_vol < -57)
3530 speaker_normal_vol = -57;
3532 printk("speaker_normal_vol = %ddB \n",speaker_normal_vol);
3535 case HEADSET_RINGTONE:
3537 headset_normal_vol += 3;
3538 speaker_normal_vol += 3;
3540 headset_normal_vol -= 3;
3541 speaker_normal_vol -= 3;
3544 if(speaker_normal_vol > 6)
3545 speaker_normal_vol = 6;
3546 else if(speaker_normal_vol < -57)
3547 speaker_normal_vol = -57;
3548 if(headset_normal_vol > 6)
3549 headset_normal_vol = 6;
3550 else if(headset_normal_vol < -57)
3551 headset_normal_vol = -57;
3553 printk("headset_normal_vol = %ddB \n",headset_normal_vol);
3554 printk("speaker_normal_vol = %ddB \n",speaker_normal_vol);
3558 printk("Current channel does not match to normal mode!\n");
3564 if(*(cookie_pot+1)=='+'){
3566 }else if(*(cookie_pot+1)=='-'){
3569 printk("Please press '+' or '-' follow 'i'!\n");
3573 switch(wm8994_current_route){
3574 case HEADSET_INCALL:
3576 headset_incall_vol += 3;
3578 headset_incall_vol -= 3;
3580 if(headset_incall_vol > 6)
3581 headset_incall_vol = 6;
3582 else if(headset_incall_vol < -12)
3583 headset_incall_vol = -12;
3585 printk("headset_incall_vol = %ddB \n",headset_incall_vol);
3588 case EARPIECE_INCALL:
3590 earpiece_incall_vol += 3;
3592 earpiece_incall_vol -= 3;
3594 if(earpiece_incall_vol>6)
3595 earpiece_incall_vol = 6;
3596 else if(earpiece_incall_vol<-21)
3597 earpiece_incall_vol = -21;
3599 printk("earpiece_incall_vol = %ddB \n",earpiece_incall_vol);
3602 case SPEAKER_INCALL:
3604 speaker_incall_vol += 3;
3606 speaker_incall_vol -= 3;
3608 if(speaker_incall_vol > 12)
3609 speaker_incall_vol = 12;
3610 else if(speaker_incall_vol < -21)
3611 speaker_incall_vol = -21;
3613 printk("speaker_incall_vol = %ddB \n",speaker_incall_vol);
3616 case BLUETOOTH_SCO_INCALL:
3622 if(BT_incall_vol > 30)
3624 else if(BT_incall_vol < -16)
3625 BT_incall_vol = -16;
3627 printk("BT_incall_vol = %ddB \n",BT_incall_vol);
3631 printk("Current channel does not match to incall mode!\n");
3637 if(*(cookie_pot+1)=='+'){
3639 }else if(*(cookie_pot+1)=='-'){
3642 printk("Please press '+' or '-' follow 'm'!\n");
3645 switch(wm8994_current_route){
3646 case HEADSET_INCALL:
3648 headset_incall_mic_vol += 3;
3650 headset_incall_mic_vol -= 3;
3652 if(speaker_incall_mic_vol > 30)
3653 speaker_incall_mic_vol = 30;
3654 else if(speaker_incall_mic_vol < -22)
3655 speaker_incall_mic_vol = -22;
3657 printk("speaker_incall_mic_vol = %ddB \n",speaker_incall_mic_vol);
3660 case EARPIECE_INCALL:
3662 speaker_incall_mic_vol += 3;
3664 speaker_incall_mic_vol -= 3;
3666 if(speaker_incall_mic_vol > 30)
3667 speaker_incall_mic_vol = 30;
3668 else if(speaker_incall_mic_vol < -22)
3669 speaker_incall_mic_vol = -22;
3671 printk("speaker_incall_mic_vol = %ddB \n",speaker_incall_mic_vol);
3674 case SPEAKER_INCALL:
3676 speaker_incall_mic_vol += 3;
3678 speaker_incall_mic_vol -= 3;
3680 if(speaker_incall_mic_vol > 30)
3681 speaker_incall_mic_vol = 30;
3682 else if(speaker_incall_mic_vol < -22)
3683 speaker_incall_mic_vol = -22;
3685 printk("speaker_incall_mic_vol = %ddB \n",speaker_incall_mic_vol);
3688 case BLUETOOTH_SCO_INCALL:
3690 BT_incall_mic_vol += 3;
3692 BT_incall_mic_vol -= 3;
3694 if(BT_incall_mic_vol > 6)
3695 BT_incall_mic_vol = 6;
3696 else if(BT_incall_mic_vol < -57)
3697 BT_incall_mic_vol = -57;
3699 printk("BT_incall_mic_vol = %ddB \n",BT_incall_mic_vol);
3708 if(recorder_vol > 60)
3710 else if(recorder_vol < -16)
3713 printk("recorder_vol = %ddB \n",recorder_vol);
3717 printk("Current channel does not match to mic mode!\n");
3724 printk("headset_normal_vol = %ddB \n",headset_normal_vol);
3725 printk("speaker_normal_vol = %ddB \n",speaker_normal_vol);
3726 printk("headset_incall_vol = %ddB \n",headset_incall_vol);
3727 printk("earpiece_incall_vol = %ddB \n",earpiece_incall_vol);
3728 printk("speaker_incall_vol = %ddB \n",speaker_incall_vol);
3729 printk("BT_incall_vol = %ddB \n",BT_incall_vol);
3730 printk("headset_incall_mic_vol = %ddB \n",headset_incall_mic_vol);
3731 printk("speaker_incall_mic_vol = %ddB \n",speaker_incall_mic_vol);
3732 printk("BT_incall_mic_vol = %ddB \n",BT_incall_mic_vol);
3733 printk("recorder_vol = %ddB \n",recorder_vol);
3734 printk("bank_vol[1] = %ddB \n",bank_vol[1]);
3735 printk("bank_vol[2] = %ddB \n",bank_vol[2]);
3736 printk("bank_vol[3] = %ddB \n",bank_vol[3]);
3737 printk("bank_vol[4] = %ddB \n",bank_vol[4]);
3738 printk("bank_vol[5] = %ddB \n",bank_vol[5]);
3744 if(((*(cookie_pot+1) == 't') || (*(cookie_pot+1) == 'T')) &&
3745 ((*(cookie_pot+2) == 'a') || (*(cookie_pot+2) == 'A'))){
3746 if(earpiece_vol_table[5] == 0x013D){
3747 earpiece_vol_table[0] = 0x0127;//for cta
3748 earpiece_vol_table[1] = 0x012D;
3749 earpiece_vol_table[2] = 0x0130;
3750 earpiece_vol_table[3] = 0x0135;
3751 earpiece_vol_table[4] = 0x0137;
3752 earpiece_vol_table[5] = 0x0135;
3753 printk("CTA on,earpiece table value is:0x0127,0x012D,0x0130,0x0135,0x0137,0x0135\n");
3758 isWM8994SetChannel = true;
3759 if(*(cookie_pot+1) == '+'){
3760 wm8994_proc_mode = wm8994_current_mode+1;
3762 if(wm8994_proc_mode > wm8994_BT_baseband)
3763 wm8994_proc_mode = wm8994_AP_to_headset;
3764 }else if(*(cookie_pot+1) == '-'){
3765 wm8994_proc_mode = wm8994_current_mode-1;
3767 if(wm8994_proc_mode == null || wm8994_proc_mode > wm8994_BT_baseband)
3768 wm8994_proc_mode = wm8994_BT_baseband;
3770 wm8994_proc_mode = wm8994_current_mode;
3771 wm8994_current_mode = null;
3774 wm8994_fnc_ptr += wm8994_proc_mode;
3775 (*wm8994_fnc_ptr)();
3776 isWM8994SetChannel = false;
3781 if(*(cookie_pot+1)=='+'){
3783 }else if(*(cookie_pot+1)=='-'){
3785 }else if(*(cookie_pot+1)=='c'){
3786 wm8994_write(0x0480, 0x0000);
3788 }else if(*(cookie_pot+1)=='o'){
3789 wm8994_write(0x0480, 0x0001|((bank_vol[1]+12)<<11)|
3790 ((bank_vol[2]+12)<<6)|((bank_vol[3]+12)<<1));
3791 wm8994_write(0x0481, 0x0000|((bank_vol[4]+12)<<11)|
3792 ((bank_vol[5]+12)<<6));
3795 printk("Please press '+' '-' 'o' 'c' follow 'e'!\n");
3799 switch(*(cookie_pot+2)){
3806 if(bank_vol[1] > 12)bank_vol[1] = 12;
3807 if(bank_vol[1] < -12)bank_vol[1] = -12;
3809 wm8994_read(0x0480, &eqvol);
3810 wm8994_write(0x0480, (eqvol&0x07FF)|((bank_vol[1]+12)<<11));
3812 printk("bank_vol[1] = %ddB \n",bank_vol[1]);
3821 if(bank_vol[2] > 12)bank_vol[2] = 12;
3822 if(bank_vol[2] < -12)bank_vol[2] = -12;
3824 wm8994_read(0x0480, &eqvol);
3825 wm8994_write(0x0480, (eqvol&0xF83F)|((bank_vol[2]+12)<<6));
3827 printk("bank_vol[2] = %ddB \n",bank_vol[2]);
3836 if(bank_vol[3] > 12)bank_vol[3] = 12;
3837 if(bank_vol[3] < -12)bank_vol[3] = -12;
3839 wm8994_read(0x0480, &eqvol);
3840 wm8994_write(0x0480, (eqvol&0xFFC1)|((bank_vol[3]+12)<<1));
3842 printk("bank_vol[3] = %ddB \n",bank_vol[3]);
3851 if(bank_vol[4] > 12)bank_vol[4] = 12;
3852 if(bank_vol[4] < -12)bank_vol[4] = -12;
3854 wm8994_read(0x0481, &eqvol);
3855 wm8994_write(0x0481, (eqvol&0x07FF)|((bank_vol[4]+12)<<11));
3857 printk("bank_vol[4] = %ddB \n",bank_vol[4]);
3866 if(bank_vol[5] > 12)bank_vol[5] = 12;
3867 if(bank_vol[5] < -12)bank_vol[5] = -12;
3869 wm8994_read(0x0481, &eqvol);
3870 wm8994_write(0x0481, (eqvol&0xF83F)|((bank_vol[5]+12)<<6));
3872 printk("bank_vol[5] = %ddB \n",bank_vol[5]);
3876 printk("Please press bank '1' to '5' follow 'e+' or 'e-'!\n");
3881 //------------------------------------------------------------------------------
3882 //------------------------------------------------------------------------------
3883 //------------------------------------------------------------------------------
3886 debug_write_read ++;
3887 debug_write_read %= 2;
3888 if(debug_write_read != 0)
3889 DBG("Debug read and write reg on\n");
3891 DBG("Debug read and write reg off\n");
3895 DBG("Read reg debug\n");
3896 if(cookie_pot[1] ==':')
3898 debug_write_read = 1;
3899 strsep(&cookie_pot,":");
3900 while((p=strsep(&cookie_pot,",")))
3902 wm8994_read(simple_strtol(p,NULL,16),(unsigned short *)&value);
3904 debug_write_read = 0;;
3909 DBG("Error Read reg debug.\n");
3910 DBG("For example: echo 'r:22,23,24,25'>wm8994_ts\n");
3915 DBG("Write reg debug\n");
3916 if(cookie_pot[1] ==':')
3918 debug_write_read = 1;
3919 strsep(&cookie_pot,":");
3920 while((p=strsep(&cookie_pot,"=")))
3922 reg = simple_strtol(p,NULL,16);
3923 p=strsep(&cookie_pot,",");
3924 value = simple_strtol(p,NULL,16);
3925 wm8994_write(reg,value);
3927 debug_write_read = 0;;
3932 DBG("Error Write reg debug.\n");
3933 DBG("For example: w:22=0,23=0,24=0,25=0\n");
3940 recorder_and_AP_to_headset();
3943 DBG("Help for wm8994_ts .\n-->The Cmd list: \n");
3944 DBG("-->'d&&D' Open or Off the debug\n");
3945 DBG("-->'r&&R' Read reg debug,Example: echo 'r:22,23,24,25'>wm8994_ts\n");
3946 DBG("-->'w&&W' Write reg debug,Example: echo 'w:22=0,23=0,24=0,25=0'>wm8994_ts\n");
3950 wm8994_set_channel_vol();
3954 static const struct file_operations wm8994_proc_fops = {
3955 .owner = THIS_MODULE,
3956 //.open = snd_mem_proc_open,
3959 .write = wm8994_proc_write,
3961 //.llseek = seq_lseek,
3962 //.release = single_release,
3965 static int wm8994_proc_init(void){
3967 struct proc_dir_entry *wm8994_proc_entry;
3969 wm8994_proc_entry = create_proc_entry("driver/wm8994_ts", 0777, NULL);
3971 if(wm8994_proc_entry != NULL){
3973 wm8994_proc_entry->write_proc = wm8994_proc_write;
3977 printk("create proc error !\n");
3985 static int wm8994_probe(struct platform_device *pdev)
3987 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
3988 struct snd_soc_codec *codec;
3989 unsigned long wm8994_port = 0;
3997 if (wm8994_codec == NULL) {
3998 dev_err(&pdev->dev, "Codec device not registered\n");
4002 socdev->card->codec = wm8994_codec;
4003 codec = wm8994_codec;
4005 // recorder_and_AP_to_speakers();
4007 setup_timer(&wm8994_timer, wm8994_codec_timer, wm8994_port);
4008 wm8994_timer.expires = jiffies+500;//=500ms
4009 add_timer(&wm8994_timer);
4011 sprintf(b, "wm8994_workqueue");
4012 wm8994_workqueue = create_freezeable_workqueue(b);
4013 if (!wm8994_workqueue)
4014 printk("cannot create wm8994 workqueue\n");
4016 INIT_WORK(&wm8994_work, wm8994_work_handler);
4018 if (wm8994_codec == NULL) {
4019 dev_err(&pdev->dev, "Codec device not registered\n");
4025 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
4027 dev_err(codec->dev, "failed to create pcms: %d\n", ret);
4031 snd_soc_add_controls(codec,wm8994_snd_controls,
4032 ARRAY_SIZE(wm8994_snd_controls));
4033 snd_soc_dapm_new_controls(codec,wm8994_dapm_widgets,
4034 ARRAY_SIZE(wm8994_dapm_widgets));
4035 snd_soc_dapm_add_routes(codec,audio_map, ARRAY_SIZE(audio_map));
4036 snd_soc_dapm_new_widgets(codec);
4038 ret = snd_soc_init_card(socdev);
4040 dev_err(codec->dev, "failed to register card: %d\n", ret);
4047 snd_soc_free_pcms(socdev);
4048 snd_soc_dapm_free(socdev);
4053 static int wm8994_remove(struct platform_device *pdev)
4055 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
4057 snd_soc_free_pcms(socdev);
4058 snd_soc_dapm_free(socdev);
4063 struct snd_soc_codec_device soc_codec_dev_wm8994 = {
4064 .probe = wm8994_probe,
4065 .remove = wm8994_remove,
4066 .suspend = wm8994_suspend,
4067 .resume = wm8994_resume,
4069 EXPORT_SYMBOL_GPL(soc_codec_dev_wm8994);
4071 static int wm8994_register(struct wm8994_priv *wm8994,
4072 enum snd_soc_control_type control)
4074 struct snd_soc_codec *codec = &wm8994->codec;
4078 dev_err(codec->dev, "Another WM8994 is registered\n");
4083 mutex_init(&codec->mutex);
4084 INIT_LIST_HEAD(&codec->dapm_widgets);
4085 INIT_LIST_HEAD(&codec->dapm_paths);
4087 codec->private_data = wm8994;
4088 codec->name = "WM8994";
4089 codec->owner = THIS_MODULE;
4090 codec->dai = &wm8994_dai;
4092 codec->reg_cache_size = ARRAY_SIZE(wm8994->reg_cache);
4093 codec->reg_cache = &wm8994->reg_cache;
4094 codec->bias_level = SND_SOC_BIAS_OFF;
4095 codec->set_bias_level = wm8994_set_bias_level;
4097 memcpy(codec->reg_cache, wm8994_reg,
4098 sizeof(wm8994_reg));
4100 ret = snd_soc_codec_set_cache_io(codec,7, 9, control);
4102 dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
4108 dev_err(codec->dev, "Failed to issue reset\n");
4112 wm8994_set_bias_level(&wm8994->codec, SND_SOC_BIAS_STANDBY);
4114 wm8994_dai.dev = codec->dev;
4116 wm8994_codec = codec;
4118 ret = snd_soc_register_codec(codec);
4120 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
4124 ret = snd_soc_register_dai(&wm8994_dai);
4126 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
4127 snd_soc_unregister_codec(codec);
4133 snd_soc_unregister_codec(codec);
4139 static void wm8994_unregister(struct wm8994_priv *wm8994)
4141 wm8994_set_bias_level(&wm8994->codec, SND_SOC_BIAS_OFF);
4142 snd_soc_unregister_dai(&wm8994_dai);
4143 snd_soc_unregister_codec(&wm8994->codec);
4145 wm8994_codec = NULL;
4148 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
4149 static int wm8994_i2c_probe(struct i2c_client *i2c,
4150 const struct i2c_device_id *id)
4152 struct wm8994_priv *wm8994;
4153 struct snd_soc_codec *codec;
4156 wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL);
4160 codec = &wm8994->codec;
4162 i2c_set_clientdata(i2c, wm8994);
4163 codec->control_data = i2c;
4165 codec->dev = &i2c->dev;
4167 return wm8994_register(wm8994, SND_SOC_I2C);
4170 static int wm8994_i2c_remove(struct i2c_client *client)
4172 struct wm8994_priv *wm8994 = i2c_get_clientdata(client);
4173 wm8994_unregister(wm8994);
4178 static int wm8994_i2c_suspend(struct i2c_client *client, pm_message_t msg)
4180 return snd_soc_suspend_device(&client->dev);
4183 static int wm8994_i2c_resume(struct i2c_client *client)
4185 return snd_soc_resume_device(&client->dev);
4188 #define wm8994_i2c_suspend NULL
4189 #define wm8994_i2c_resume NULL
4192 static const struct i2c_device_id wm8994_i2c_id[] = {
4196 MODULE_DEVICE_TABLE(i2c, wm8994_i2c_id);
4198 static struct i2c_driver wm8994_i2c_driver = {
4201 .owner = THIS_MODULE,
4203 .probe = wm8994_i2c_probe,
4204 .remove = wm8994_i2c_remove,
4205 .suspend = wm8994_i2c_suspend,
4206 .resume = wm8994_i2c_resume,
4207 .id_table = wm8994_i2c_id,
4210 int reg_send_data(struct i2c_client *client, unsigned short *reg, unsigned short *data, u32 scl_rate)
4213 struct i2c_adapter *adap = client->adapter;
4217 memcpy(tx_buf, reg, 2);
4218 memcpy(tx_buf+2, data, 2);
4219 msg.addr = client->addr;
4222 msg.flags = client->flags;
4223 msg.scl_rate = scl_rate;
4225 ret = i2c_transfer(adap, &msg, 1);
4230 int reg_recv_data(struct i2c_client *client, unsigned short *reg, unsigned short *buf, u32 scl_rate)
4233 struct i2c_adapter *adap = client->adapter;
4234 struct i2c_msg msgs[2];
4236 msgs[0].addr = client->addr;
4237 msgs[0].buf = (char *)reg;
4238 msgs[0].flags = client->flags;
4240 msgs[0].scl_rate = scl_rate;
4241 msgs[0].read_type = 2;
4243 msgs[1].addr = client->addr;
4244 msgs[1].buf = (char *)buf;
4245 msgs[1].flags = client->flags | I2C_M_RD;
4247 msgs[1].scl_rate = scl_rate;
4248 msgs[1].read_type = 2;
4250 ret = i2c_transfer(adap, msgs, 2);
4257 #if defined(CONFIG_SPI_MASTER)
4258 static int __devinit wm8994_spi_probe(struct spi_device *spi)
4260 struct wm8994_priv *wm8994;
4261 struct snd_soc_codec *codec;
4263 wm8994 = kzalloc(sizeof(struct wm8994_priv), GFP_KERNEL);
4267 codec = &wm8994->codec;
4268 codec->control_data = spi;
4269 codec->dev = &spi->dev;
4271 dev_set_drvdata(&spi->dev, wm8994);
4273 return wm8994_register(wm8994, SND_SOC_SPI);
4276 static int __devexit wm8994_spi_remove(struct spi_device *spi)
4278 struct wm8994_priv *wm8994 = dev_get_drvdata(&spi->dev);
4280 wm8994_unregister(wm8994);
4286 static int wm8994_spi_suspend(struct spi_device *spi, pm_message_t msg)
4288 return snd_soc_suspend_device(&spi->dev);
4291 static int wm8994_spi_resume(struct spi_device *spi)
4293 return snd_soc_resume_device(&spi->dev);
4296 #define wm8994_spi_suspend NULL
4297 #define wm8994_spi_resume NULL
4300 static struct spi_driver wm8994_spi_driver = {
4303 .bus = &spi_bus_type,
4304 .owner = THIS_MODULE,
4306 .probe = wm8994_spi_probe,
4307 .remove = __devexit_p(wm8994_spi_remove),
4308 .suspend = wm8994_spi_suspend,
4309 .resume = wm8994_spi_resume,
4313 static int __init wm8994_modinit(void)
4317 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
4318 ret = i2c_add_driver(&wm8994_i2c_driver);
4320 pr_err("WM8994: Unable to register I2C driver: %d\n", ret);
4322 #if defined(CONFIG_SPI_MASTER)
4323 ret = spi_register_driver(&wm8994_spi_driver);
4325 pr_err("WM8994: Unable to register SPI driver: %d\n", ret);
4329 module_init(wm8994_modinit);
4331 static void __exit wm8994_exit(void)
4333 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
4334 i2c_del_driver(&wm8994_i2c_driver);
4336 #if defined(CONFIG_SPI_MASTER)
4337 spi_unregister_driver(&wm8994_spi_driver);
4340 module_exit(wm8994_exit);
4343 MODULE_DESCRIPTION("ASoC WM8994 driver");
4344 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
4345 MODULE_LICENSE("GPL");