@@ -46,6 +46,8 @@ struct wm8731_priv {
4646 u16 reg_cache [WM8731_CACHEREGNUM ];
4747 unsigned int sysclk ;
4848 int sysclk_type ;
49+ int playback_fs ;
50+ bool deemph ;
4951};
5052
5153
@@ -65,14 +67,73 @@ static const u16 wm8731_reg[WM8731_CACHEREGNUM] = {
6567
6668static const char * wm8731_input_select [] = {"Line In" , "Mic" };
6769
68- static const char * wm8731_deemph [] = {"None" , "32Khz" , "44.1Khz" , "48Khz" };
69-
7070static const struct soc_enum wm8731_insel_enum =
7171 SOC_ENUM_SINGLE (WM8731_APANA , 2 , 2 , wm8731_input_select );
7272
73- static const struct soc_enum wm8731_deemph_enum =
74- SOC_ENUM_SINGLE (WM8731_APDIGI , 1 , 4 , wm8731_deemph );
73+ static int wm8731_deemph [] = { 0 , 32000 , 44100 , 48000 };
74+
75+ static int wm8731_set_deemph (struct snd_soc_codec * codec )
76+ {
77+ struct wm8731_priv * wm8731 = snd_soc_codec_get_drvdata (codec );
78+ int val , i , best ;
79+
80+ /* If we're using deemphasis select the nearest available sample
81+ * rate.
82+ */
83+ if (wm8731 -> deemph ) {
84+ best = 1 ;
85+ for (i = 2 ; i < ARRAY_SIZE (wm8731_deemph ); i ++ ) {
86+ if (abs (wm8731_deemph [i ] - wm8731 -> playback_fs ) <
87+ abs (wm8731_deemph [best ] - wm8731 -> playback_fs ))
88+ best = i ;
89+ }
90+
91+ val = best << 1 ;
92+ } else {
93+ best = 0 ;
94+ val = 0 ;
95+ }
96+
97+ dev_dbg (codec -> dev , "Set deemphasis %d (%dHz)\n" ,
98+ best , wm8731_deemph [best ]);
7599
100+ return snd_soc_update_bits (codec , WM8731_APDIGI , 0x6 , val );
101+ }
102+
103+ static int wm8731_get_deemph (struct snd_kcontrol * kcontrol ,
104+ struct snd_ctl_elem_value * ucontrol )
105+ {
106+ struct snd_soc_codec * codec = snd_kcontrol_chip (kcontrol );
107+ struct wm8731_priv * wm8731 = snd_soc_codec_get_drvdata (codec );
108+
109+ ucontrol -> value .enumerated .item [0 ] = wm8731 -> deemph ;
110+
111+ return 0 ;
112+ }
113+
114+ static int wm8731_put_deemph (struct snd_kcontrol * kcontrol ,
115+ struct snd_ctl_elem_value * ucontrol )
116+ {
117+ struct snd_soc_codec * codec = snd_kcontrol_chip (kcontrol );
118+ struct wm8731_priv * wm8731 = snd_soc_codec_get_drvdata (codec );
119+ int deemph = ucontrol -> value .enumerated .item [0 ];
120+ int ret = 0 ;
121+
122+ if (deemph > 1 )
123+ return - EINVAL ;
124+
125+ mutex_lock (& codec -> mutex );
126+ if (wm8731 -> deemph != deemph ) {
127+ wm8731 -> deemph = deemph ;
128+
129+ wm8731_set_deemph (codec );
130+
131+ ret = 1 ;
132+ }
133+ mutex_unlock (& codec -> mutex );
134+
135+ return ret ;
136+ }
76137
77138static const DECLARE_TLV_DB_SCALE (in_tlv , -3450 , 150 , 0 ) ;
78139static const DECLARE_TLV_DB_SCALE (sidetone_tlv , -1500 , 300 , 0 ) ;
@@ -99,7 +160,8 @@ SOC_SINGLE_TLV("Sidetone Playback Volume", WM8731_APANA, 6, 3, 1,
99160SOC_SINGLE ("ADC High Pass Filter Switch" , WM8731_APDIGI , 0 , 1 , 1 ),
100161SOC_SINGLE ("Store DC Offset Switch" , WM8731_APDIGI , 4 , 1 , 0 ),
101162
102- SOC_ENUM ("Playback De-emphasis" , wm8731_deemph_enum ),
163+ SOC_SINGLE_BOOL_EXT ("Playback Deemphasis Switch" , 0 ,
164+ wm8731_get_deemph , wm8731_put_deemph ),
103165};
104166
105167/* Output Mixer */
@@ -243,6 +305,8 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream,
243305 u16 srate = (coeff_div [i ].sr << 2 ) |
244306 (coeff_div [i ].bosr << 1 ) | coeff_div [i ].usb ;
245307
308+ wm8731 -> playback_fs = params_rate (params );
309+
246310 snd_soc_write (codec , WM8731_SRATE , srate );
247311
248312 /* bit size */
@@ -257,6 +321,8 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream,
257321 break ;
258322 }
259323
324+ wm8731_set_deemph (codec );
325+
260326 snd_soc_write (codec , WM8731_IFACE , iface );
261327 return 0 ;
262328}
0 commit comments