From: ChenJQ Date: Fri, 10 Sep 2010 07:54:38 +0000 (-0700) Subject: Add set volume for call in codec wm8994 X-Git-Tag: firefly_0821_release~11161^2~2 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=92439d4338f6de2b2756e80bed22465cfa8a91dc;p=firefly-linux-kernel-4.4.55.git Add set volume for call in codec wm8994 --- diff --git a/drivers/headset_observe/rk2818_headset.c b/drivers/headset_observe/rk2818_headset.c index 65d56512d848..84f6b2e4b34c 100644 --- a/drivers/headset_observe/rk2818_headset.c +++ b/drivers/headset_observe/rk2818_headset.c @@ -39,9 +39,9 @@ /* Debug */ #if 0 -#define DBG printk +#define DBG(x...) printk(KERN_INFO x) #else -#define DBG +#define DBG(x...) do { } while (0) #endif /* ¶ú»ú״̬ */ diff --git a/include/sound/asound.h b/include/sound/asound.h index 1f57bb92eb5a..2e9027d2399f 100644 --- a/include/sound/asound.h +++ b/include/sound/asound.h @@ -480,6 +480,7 @@ enum { #define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern) #define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int) #define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61) +#define SNDRV_PCM_IOCTL_VOL _IOW('A', 0x62, int) /***************************************************************************** * * diff --git a/include/sound/pcm.h b/include/sound/pcm.h old mode 100644 new mode 100755 index de6d981de5d6..5685b7de99c9 --- a/include/sound/pcm.h +++ b/include/sound/pcm.h @@ -106,6 +106,8 @@ struct snd_pcm_ops { #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE 4 #define SNDRV_PCM_TRIGGER_SUSPEND 5 #define SNDRV_PCM_TRIGGER_RESUME 6 +//add by qiuen for volume +#define SNDRV_PCM_TRIGGER_VOLUME 7 #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1) diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h old mode 100644 new mode 100755 index 97ca9af414dc..ff690e178fcf --- a/include/sound/soc-dai.h +++ b/include/sound/soc-dai.h @@ -172,6 +172,9 @@ struct snd_soc_dai_ops { struct snd_soc_dai *); int (*trigger)(struct snd_pcm_substream *, int, struct snd_soc_dai *); + + /* set volume,add by qiuen*/ +void (*set_volume)(unsigned char mode,unsigned char volume); }; /* diff --git a/include/sound/soc.h b/include/sound/soc.h old mode 100644 new mode 100755 index 475cb7ed6bec..855a9ce5af19 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -363,6 +363,8 @@ struct snd_soc_ops { int (*hw_free)(struct snd_pcm_substream *); int (*prepare)(struct snd_pcm_substream *); int (*trigger)(struct snd_pcm_substream *, int); + /* set volume,add by qiuen*/ + void (*set_volume)(unsigned char mode,unsigned char volume); }; /* SoC Audio Codec */ diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c old mode 100644 new mode 100755 index ab73edf2c89a..9a127a033536 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1025,6 +1025,17 @@ static int snd_pcm_pause(struct snd_pcm_substream *substream, int push) return snd_pcm_action(&snd_pcm_action_pause, substream, push); } +/* + * set volume. + * add by qiuen + */ +static int snd_pcm_vol(struct snd_pcm_substream *substream, int push) +{ + substream->number = push; + + return substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_VOLUME); +} + #ifdef CONFIG_PM /* suspend */ @@ -2532,6 +2543,11 @@ static int snd_pcm_common_ioctl1(struct file *file, return snd_pcm_drain(substream, file); case SNDRV_PCM_IOCTL_DROP: return snd_pcm_drop(substream); + /*add by qiuen for volume*/ + case SNDRV_PCM_IOCTL_VOL: + snd_pcm_vol(substream, (int)(unsigned long)arg); + return 0; + /**********end***********/ case SNDRV_PCM_IOCTL_PAUSE: { int res; diff --git a/sound/soc/codecs/wm8994.c b/sound/soc/codecs/wm8994.c index 024813feed83..ff26e8ac6a78 100755 --- a/sound/soc/codecs/wm8994.c +++ b/sound/soc/codecs/wm8994.c @@ -168,7 +168,6 @@ static int wm8994_read(unsigned short reg,unsigned short *value) if (reg_recv_data(wm8994_client,®s,&values,400000) > 0) { *value=((values>>8)& 0x00FF)|((values<<8)&0xFF00); - printk("wm8994_read reg = 0x%x value = 0x%x \n",reg,*value); return 0; } @@ -435,7 +434,6 @@ void recorder_and_AP_to_speakers(void) wm8994_write(0x26, 0x017F); //Speaker Left Output Volume wm8994_write(0x27, 0x017F); //Speaker Right Output Volume wm8994_write(0x420, 0x0000); - #ifdef CONFIG_SND_CODEC_SOC_MASTER wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64 @@ -639,6 +637,7 @@ void handsetMIC_to_baseband_to_headset(void) wm8994_write(0x22, 0x0000); wm8994_write(0x23, 0x0100); wm8994_write(0x28, 0x0030); //IN1LN_TO_IN1L IN1LP_TO_IN1L + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); wm8994_write(0x02, 0x6240); wm8994_write(0x2B, 0x0005); //VRX_MIXINL_VOL @@ -663,9 +662,6 @@ void handsetMIC_to_baseband_to_headset(void) wm8994_write(0x610, 0x01A0); //DAC1 Left Volume bit0~7 wm8994_write(0x611, 0x01A0); //DAC1 Right Volume bit0~7 - wm8994_write(0x1C, 0x01FF); //HPOUT1L Volume - wm8994_write(0x1D, 0x01FF); //HPOUT1R Volume - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); #ifdef CONFIG_SND_CODEC_SOC_MASTER wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64 @@ -689,8 +685,7 @@ void handsetMIC_to_baseband_to_headset_and_record(void) wm8994_write(0x04, 0x0303); wm8994_write(0x18, 0x014B); //volume wm8994_write(0x19, 0x014B); //volume - wm8994_write(0x1C, 0x01FF); //LEFT OUTPUT VOLUME - wm8994_write(0x1D, 0x01F9); //RIGHT OUTPUT VOLUME + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); wm8994_write(0x1E, 0x0006); wm8994_write(0x28, 0x00B0); //IN2LP_TO_IN2L wm8994_write(0x29, 0x0120); @@ -710,12 +705,7 @@ void handsetMIC_to_baseband_to_headset_and_record(void) wm8994_write(0x606, 0x0002); wm8994_write(0x607, 0x0002); - wm8994_write(0x620, 0x0000); - - wm8994_write(0x1C, 0x01F9); - wm8994_write(0x1D, 0x01F9); - - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); + wm8994_write(0x620, 0x0000); } void mainMIC_to_baseband_to_earpiece(void) @@ -756,6 +746,7 @@ void mainMIC_to_baseband_to_earpiece(void) wm8994_write(0x2B, 0x0005); //VRX_MIXINL_VOL wm8994_write(0x2D, 0x0041); //DAC1L_TO_MIXOUTL=1 wm8994_write(0x2E, 0x0001); //DAC1R_TO_MIXOUTR=1 + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); wm8994_write(0x33, 0x0010); wm8994_write(0x34, 0x0004); //MIXOUTR_TO_SPKMIXR =1 un-mute 0x0002 @@ -766,7 +757,7 @@ void mainMIC_to_baseband_to_earpiece(void) wm8994_write(0x611, 0x01C0); //DAC1_VU=1, DAC1R_VOL=1100_0000 wm8994_write(0x420, 0x0000); - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); + #ifdef CONFIG_SND_CODEC_SOC_MASTER wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64 @@ -806,6 +797,7 @@ void mainMIC_to_baseband_to_earpiece_I2S(void) wm8994_write(0x1F, 0x0000); wm8994_write(0x28, 0x0030); wm8994_write(0x29, 0x0020); //IN1L_TO_MIXINL=1, IN1L_MIXINL_VOL=0, MIXOUTL_MIXINL_VOL=000 + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); wm8994_write(0x200, 0x0011); // sysclk = fll (bit4 =1) 0x0011 //cjq @@ -836,8 +828,6 @@ void mainMIC_to_baseband_to_earpiece_I2S(void) wm8994_write(0x420, 0x0000); - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); - #ifdef CONFIG_SND_CODEC_SOC_MASTER wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64 @@ -872,6 +862,7 @@ void mainMIC_to_baseband_to_earpiece_and_record(void) wm8994_write(0x200 ,0x0001); wm8994_write(0x208 ,0x000A); wm8994_write(0x300 ,0xC050); + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); #ifdef CONFIG_SND_CODEC_SOC_MASTER wm8994_write(0x302, 0x4000); // master = 0x4000 // slave= 0x0000 @@ -881,8 +872,6 @@ void mainMIC_to_baseband_to_earpiece_and_record(void) wm8994_write(0x606 ,0x0002); wm8994_write(0x607 ,0x0002); wm8994_write(0x620 ,0x0000); - - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); } void mainMIC_to_baseband_to_speakers(void) @@ -918,8 +907,7 @@ void mainMIC_to_baseband_to_speakers(void) wm8994_write(0x1E, 0x0006); wm8994_write(0x22, 0x0000); wm8994_write(0x23, 0x0100); - wm8994_write(0x26, 0x017F); //Speaker Volume Left bit 0~5 - wm8994_write(0x27, 0x017F); //Speaker Volume Right bit 0~5 + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); wm8994_write(0x28, 0x0003); //IN1RP_TO_IN1R IN1RN_TO_IN1R wm8994_write(0x2B, 0x0005); //VRX_MIXINL_VOL wm8994_write(0x2D, 0x0041); //bit 1 IN2LP_TO_MIXOUTL //0x0003 for info @@ -938,7 +926,6 @@ void mainMIC_to_baseband_to_speakers(void) wm8994_write(0x610, 0x01c0); //DAC1 Left Volume bit0~7 wm8994_write(0x611, 0x01c0); //DAC1 Right Volume bit0~7 - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); #ifdef CONFIG_SND_CODEC_SOC_MASTER wm8994_write(0x303, 0x0040); // AIF1 BCLK DIV--------AIF1CLK/4 wm8994_write(0x304, 0x0040); // AIF1 ADCLRCK DIV-----BCLK/64 @@ -974,6 +961,7 @@ void mainMIC_to_baseband_to_speakers_and_record(void) wm8994_write(0x200, 0x0001); wm8994_write(0x208, 0x000A); wm8994_write(0x300, 0xC050); + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); #ifdef CONFIG_SND_CODEC_SOC_MASTER wm8994_write(0x302, 0x4000); // master = 0x4000 // slave= 0x0000 @@ -983,8 +971,6 @@ void mainMIC_to_baseband_to_speakers_and_record(void) wm8994_write(0x606, 0x0002); wm8994_write(0x607, 0x0002); wm8994_write(0x620, 0x0000); - - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); } void BT_baseband(void) @@ -1002,8 +988,7 @@ void BT_baseband(void) wm8994_write(0x04, 0x3303); wm8994_write(0x05, 0x3002); wm8994_write(0x06, 0x000A); - wm8994_write(0x19, 0x014B); - wm8994_write(0x1B, 0x014B); + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); wm8994_write(0x1E, 0x0006); wm8994_write(0x28, 0x00CC); wm8994_write(0x29, 0x0100); @@ -1059,7 +1044,7 @@ void BT_baseband(void) wm8994_write(0x708, 0x2100); wm8994_write(0x709, 0x2100); wm8994_write(0x70A, 0x2100); - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); + #ifdef CONFIG_SND_CODEC_SOC_MASTER wm8994_write(0x303, 0x0090); wm8994_write(0x313, 0x0020); // SMbus_16inx_16dat Write 0x34 * AIF2 BCLK DIV--------AIF1CLK/2 @@ -1085,8 +1070,7 @@ void BT_baseband_and_record(void) wm8994_write(0x04, 0x3303); wm8994_write(0x05, 0x3002); wm8994_write(0x06, 0x000A); - wm8994_write(0x19, 0x014B); - wm8994_write(0x1B, 0x014B); + wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); wm8994_write(0x1E, 0x0006); wm8994_write(0x28, 0x00CC); wm8994_write(0x29, 0x0100); @@ -1148,8 +1132,6 @@ void BT_baseband_and_record(void) wm8994_write(0x708, 0x2100); wm8994_write(0x709, 0x2100); wm8994_write(0x70A, 0x2100); - - wm8994_set_volume(wm8994_current_mode,call_vol,call_maxvol); } #else //PCM_BB @@ -2111,30 +2093,26 @@ static const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0); static const struct snd_kcontrol_new wm8994_snd_controls[] = { -/* 鍠囧彮 */ SOC_DOUBLE_SWITCH_WM8994CODEC("Speaker incall Switch", SPEAKER_INCALL), SOC_DOUBLE_SWITCH_WM8994CODEC("Speaker normal Switch", SPEAKER_NORMAL), -/* 鍚瓛 */ + SOC_DOUBLE_SWITCH_WM8994CODEC("Earpiece incall Switch", EARPIECE_INCALL), SOC_DOUBLE_SWITCH_WM8994CODEC("Earpiece normal Switch", EARPIECE_NORMAL), -/* 鑰虫満 */ + SOC_DOUBLE_SWITCH_WM8994CODEC("Headset incall Switch", HEADSET_INCALL), SOC_DOUBLE_SWITCH_WM8994CODEC("Headset normal Switch", HEADSET_NORMAL), -/* 钃濈墮SCO */ + SOC_DOUBLE_SWITCH_WM8994CODEC("Bluetooth incall Switch", BLUETOOTH_SCO_INCALL), SOC_DOUBLE_SWITCH_WM8994CODEC("Bluetooth normal Switch", BLUETOOTH_SCO_NORMAL), -/* 钃濈墮A2DP */ + SOC_DOUBLE_SWITCH_WM8994CODEC("Bluetooth-A2DP incall Switch", BLUETOOTH_A2DP_INCALL), SOC_DOUBLE_SWITCH_WM8994CODEC("Bluetooth-A2DP normal Switch", BLUETOOTH_A2DP_NORMAL), -/* 鑰抽害 */ + SOC_DOUBLE_SWITCH_WM8994CODEC("Capture Switch", MIC_CAPTURE), SOC_DOUBLE_SWITCH_WM8994CODEC("Earpiece ringtone Switch",EARPIECE_RINGTONE), - SOC_DOUBLE_SWITCH_WM8994CODEC("Speaker ringtone Switch",SPEAKER_RINGTONE), - SOC_DOUBLE_SWITCH_WM8994CODEC("Headset ringtone Switch",HEADSET_RINGTONE), - }; /* @@ -2556,6 +2534,8 @@ static struct snd_soc_dai_ops wm8994_ops = { .set_fmt = wm8994_set_dai_fmt, .set_sysclk = wm8994_set_dai_sysclk, .digital_mute = wm8994_mute, + /*add by qiuen for volume*/ + .set_volume = wm8994_codec_set_volume, }; struct snd_soc_dai wm8994_dai = { diff --git a/sound/soc/rk2818/rk2818_pcm.c b/sound/soc/rk2818/rk2818_pcm.c old mode 100644 new mode 100755 index b5b9afdaee66..bbfe586268bb --- a/sound/soc/rk2818/rk2818_pcm.c +++ b/sound/soc/rk2818/rk2818_pcm.c @@ -365,9 +365,21 @@ static int rockchip_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct rockchip_runtime_data *prtd = substream->runtime->private_data; int ret = 0; - - DBG("Enter::%s----%d---%d\n",__FUNCTION__,__LINE__,cmd); - + /**************add by qiuen for volume*****/ + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *pCodec_dai = rtd->dai->codec_dai; + int vol = 0; + int streamType = 0; + + DBG("Enter::%s----%d\n",__FUNCTION__,__LINE__); + + if(cmd==SNDRV_PCM_TRIGGER_VOLUME){ + vol = substream->number % 100; + streamType = (substream->number / 100) % 100; + DBG("enter:vol=%d,streamType=%d\n",vol,streamType); + pCodec_dai->ops->set_volume(streamType, vol); + } + /****************************************************/ spin_lock(&prtd->lock); switch (cmd) {