1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Driver for WM8731L audio codec
12 * Based on code from the ipodlinux project - http://ipodlinux.org/
13 * Adapted for Rockbox in January 2006
15 * Original file: linux/arch/armnommu/mach-ipod/audio.c
17 * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
19 * All files in this archive are subject to the GNU General Public License.
20 * See the file COPYING in the source tree root for full license agreement.
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
25 ****************************************************************************/
44 #define IPOD_PCM_LEVEL 0x65 /* -6dB */
46 /* use zero crossing to reduce clicks during volume changes */
47 #define VOLUME_ZC_WAIT (1<<7)
49 /* convert tenth of dB volume (-730..60) to master volume register value */
50 int tenthdb2master(int db
)
52 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
53 /* 1111111 == +6dB (0x7f) */
54 /* 1111001 == 0dB (0x79) */
55 /* 0110000 == -73dB (0x30 */
56 /* 0101111 == mute (0x2f) */
58 if (db
< VOLUME_MIN
) {
61 return((db
/10)+0x30+73);
65 /* convert tenth of dB volume (-780..0) to mixer volume register value */
66 int tenthdb2mixer(int db
)
68 if (db
< -660) /* 1.5 dB steps */
69 return (2640 - db
) / 15;
70 else if (db
< -600) /* 0.75 dB steps */
71 return (990 - db
) * 2 / 15;
72 else if (db
< -460) /* 0.5 dB steps */
73 return (460 - db
) / 5;
74 else /* 0.25 dB steps */
78 int audiohw_mute(int mute
)
82 /* Set DACMU = 1 to soft-mute the audio DACs. */
83 wmcodec_write(DACCTRL
, 0x8);
85 /* Set DACMU = 0 to soft-un-mute the audio DACs. */
86 wmcodec_write(DACCTRL
, 0x0);
92 /** From ipodLinux **/
93 static void codec_set_active(int active
)
95 /* set active to 0x0 or 0x1 */
97 wmcodec_write(ACTIVECTRL
, 0x01);
99 wmcodec_write(ACTIVECTRL
, 0x00);
104 /* Silently enable / disable audio output */
105 void audiohw_enable_output(bool enable
)
109 /* reset the I2S controller into known state */
112 wmcodec_write(RESET
, 0x0); /*Reset*/
114 codec_set_active(0x0);
118 wmcodec_write(0x4, 0x10);
119 #elif defined HAVE_WM8731
120 /* DACSEL=1, BYPASS=1 */
121 wmcodec_write(0x4, 0x18);
124 /* set power register to POWEROFF=0 on OUTPD=0, DACPD=0 */
125 wmcodec_write(PWRMGMT
, 0x67);
127 /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */
128 /* IWL=00(16 bit) FORMAT=10(I2S format) */
129 wmcodec_write(AINTFCE
, 0x42);
131 audiohw_set_sample_rate(WM8731L_44100HZ
);
133 /* set the volume to -6dB */
134 wmcodec_write(LOUTVOL
, IPOD_PCM_LEVEL
);
135 wmcodec_write(ROUTVOL
, 0x100 | IPOD_PCM_LEVEL
);
140 /* 5. Set DACMU = 0 to soft-un-mute the audio DACs. */
141 wmcodec_write(DACCTRL
, 0x0);
143 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
144 /* We need to enable bit 4 of GPIOL for output for sound on H10 */
145 GPIOL_OUTPUT_VAL
|= 0x10;
149 #if defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
150 /* We need to disable bit 4 of GPIOL to disable sound on H10 */
151 GPIOL_OUTPUT_VAL
&= ~0x10;
157 int audiohw_set_master_vol(int vol_l
, int vol_r
)
159 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
160 /* 1111111 == +6dB */
162 /* 0110000 == -73dB */
163 /* 0101111 == mute (0x2f) */
165 wmcodec_write(LOUTVOL
, VOLUME_ZC_WAIT
| vol_l
);
166 wmcodec_write(ROUTVOL
, VOLUME_ZC_WAIT
| vol_r
);
171 int audiohw_set_mixer_vol(int channel1
, int channel2
)
179 void audiohw_set_bass(int value
)
184 void audiohw_set_treble(int value
)
189 /* Nice shutdown of WM8731 codec */
190 void audiohw_close(void)
192 /* set DACMU=1 DEEMPH=0 */
193 wmcodec_write(DACCTRL
, 0x8);
196 codec_set_active(0x0);
198 /* line in mute left & right*/
199 wmcodec_write(LINVOL
, 0x100 | 0x80);
201 /* set DACSEL=0, MUTEMIC=1 */
202 wmcodec_write(0x4, 0x2);
204 /* set POWEROFF=0 OUTPD=0 DACPD=1 */
205 wmcodec_write(PWRMGMT
, 0x6f);
207 /* set POWEROFF=1 OUTPD=1 DACPD=1 */
208 wmcodec_write(PWRMGMT
, 0xff);
211 /* Change the order of the noise shaper, 5th order is recommended above 32kHz */
212 void audiohw_set_nsorder(int order
)
217 void audiohw_set_sample_rate(int sampling_control
)
219 codec_set_active(0x0);
220 wmcodec_write(SAMPCTRL
, sampling_control
);
221 codec_set_active(0x1);
224 void audiohw_enable_recording(bool source_mic
)
226 static int line_level
= 0x17;
227 static int mic_boost
= true;
228 codec_set_active(0x0);
230 /* set BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0
231 * LRP=0 IWL=00(16 bit) FORMAT=10(I2S format) */
232 wmcodec_write(AINTFCE
, 0x42);
234 wmcodec_write(LOUTVOL
, 0x0); /* headphone mute left */
235 wmcodec_write(ROUTVOL
, 0x0); /* headphone mute right */
239 wmcodec_write(LINVOL
, 0x80); /* line in mute left */
240 wmcodec_write(RINVOL
, 0x80); /* line in mute right */
244 wmcodec_write(AAPCTRL
, 0x5); /* INSEL=mic, MIC_BOOST=enable */
246 wmcodec_write(AAPCTRL
, 0x4); /* INSEL=mic */
249 if (line_level
== 0) {
250 wmcodec_write(LINVOL
, 0x80);
251 wmcodec_write(RINVOL
, 0x80);
253 wmcodec_write(LINVOL
, line_level
);
254 wmcodec_write(RINVOL
, line_level
);
256 wmcodec_write(AAPCTRL
, 0xa); /* BY PASS, mute mic, INSEL=line in */
259 /* disable ADC high pass filter, mute dac */
260 wmcodec_write(DACCTRL
, 0x9);
262 /* power on (PWR_OFF=0) */
264 /* CLKOUTPD OSCPD OUTPD DACPD LINEINPD */
265 wmcodec_write(PWRMGMT
, 0x79);
267 wmcodec_write(PWRMGMT
, 0x7a); /* MICPD */
270 codec_set_active(0x1);
273 void audiohw_disable_recording(void)
275 /* set DACMU=1 DEEMPH=0 */
276 wmcodec_write(DACCTRL
, 0x8);
279 codec_set_active(0x0);
281 /* line in mute left & right*/
282 wmcodec_write(LINVOL
, 0x80);
283 wmcodec_write(RINVOL
, 0x80);
285 /* set DACSEL=0, MUTEMIC=1 */
286 wmcodec_write(AAPCTRL
, 0x2);
288 /* set POWEROFF=0 OUTPD=0 DACPD=1 */
289 wmcodec_write(PWRMGMT
, 0x6f);
291 /* set POWEROFF=1 OUTPD=1 DACPD=1 */
292 wmcodec_write(PWRMGMT
, 0xff);
295 void audiohw_set_recvol(int left
, int right
, int type
)
302 void audiohw_set_monitor(int enable
)