summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/wm8731l.c
diff options
context:
space:
mode:
authorMarcoen Hirschberg <marcoen@gmail.com>2007-04-19 10:46:50 +0000
committerMarcoen Hirschberg <marcoen@gmail.com>2007-04-19 10:46:50 +0000
commit15dfe87f9606a191707d5c7b3b33b21963510f53 (patch)
tree5c31520b84dc60aff6997eac6a7e8b4b3ec1127e /firmware/drivers/audio/wm8731l.c
parentf725ef12565a65d46ff2f9bd34eb3e19da7b763e (diff)
downloadrockbox-15dfe87f9606a191707d5c7b3b33b21963510f53.tar.gz
rockbox-15dfe87f9606a191707d5c7b3b33b21963510f53.zip
move audio drivers together into a subdir
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13209 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/audio/wm8731l.c')
-rw-r--r--firmware/drivers/audio/wm8731l.c305
1 files changed, 305 insertions, 0 deletions
diff --git a/firmware/drivers/audio/wm8731l.c b/firmware/drivers/audio/wm8731l.c
new file mode 100644
index 0000000000..62b1b6a81e
--- /dev/null
+++ b/firmware/drivers/audio/wm8731l.c
@@ -0,0 +1,305 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Driver for WM8731L audio codec
11 *
12 * Based on code from the ipodlinux project - http://ipodlinux.org/
13 * Adapted for Rockbox in January 2006
14 *
15 * Original file: linux/arch/armnommu/mach-ipod/audio.c
16 *
17 * Copyright (c) 2003-2005 Bernard Leach (leachbj@bouncycastle.org)
18 *
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.
21 *
22 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23 * KIND, either express or implied.
24 *
25 ****************************************************************************/
26#include "lcd.h"
27#include "cpu.h"
28#include "kernel.h"
29#include "thread.h"
30#include "power.h"
31#include "debug.h"
32#include "system.h"
33#include "sprintf.h"
34#include "button.h"
35#include "string.h"
36#include "file.h"
37#include "buffer.h"
38#include "audio.h"
39
40#include "wmcodec.h"
41#include "wm8731l.h"
42#include "i2s.h"
43
44#define IPOD_PCM_LEVEL 0x65 /* -6dB */
45
46/* use zero crossing to reduce clicks during volume changes */
47#define VOLUME_ZC_WAIT (1<<7)
48
49/* convert tenth of dB volume (-730..60) to master volume register value */
50int tenthdb2master(int db)
51{
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) */
57
58 if (db < VOLUME_MIN) {
59 return 0x2f;
60 } else {
61 return((db/10)+0x30+73);
62 }
63}
64
65/* convert tenth of dB volume (-780..0) to mixer volume register value */
66int tenthdb2mixer(int db)
67{
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 */
75 return -db * 2 / 5;
76}
77
78int audiohw_mute(int mute)
79{
80 if (mute)
81 {
82 /* Set DACMU = 1 to soft-mute the audio DACs. */
83 wmcodec_write(DACCTRL, 0x8);
84 } else {
85 /* Set DACMU = 0 to soft-un-mute the audio DACs. */
86 wmcodec_write(DACCTRL, 0x0);
87 }
88
89 return 0;
90}
91
92/** From ipodLinux **/
93static void codec_set_active(int active)
94{
95 /* set active to 0x0 or 0x1 */
96 if (active) {
97 wmcodec_write(ACTIVECTRL, 0x01);
98 } else {
99 wmcodec_write(ACTIVECTRL, 0x00);
100 }
101}
102
103
104/* Silently enable / disable audio output */
105void audiohw_enable_output(bool enable)
106{
107 if (enable)
108 {
109 /* reset the I2S controller into known state */
110 i2s_reset();
111
112 wmcodec_write(RESET, 0x0); /*Reset*/
113
114 codec_set_active(0x0);
115
116#ifdef HAVE_WM8721
117 /* DACSEL=1 */
118 wmcodec_write(0x4, 0x10);
119#elif defined HAVE_WM8731
120 /* DACSEL=1, BYPASS=1 */
121 wmcodec_write(0x4, 0x18);
122#endif
123
124 /* set power register to POWEROFF=0 on OUTPD=0, DACPD=0 */
125 wmcodec_write(PWRMGMT, 0x67);
126
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);
130
131 audiohw_set_sample_rate(WM8731L_44100HZ);
132
133 /* set the volume to -6dB */
134 wmcodec_write(LOUTVOL, IPOD_PCM_LEVEL);
135 wmcodec_write(ROUTVOL, 0x100 | IPOD_PCM_LEVEL);
136
137 /* ACTIVE=1 */
138 codec_set_active(1);
139
140 /* 5. Set DACMU = 0 to soft-un-mute the audio DACs. */
141 wmcodec_write(DACCTRL, 0x0);
142
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;
146#endif
147 audiohw_mute(0);
148 } else {
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;
152#endif
153 audiohw_mute(1);
154 }
155}
156
157int audiohw_set_master_vol(int vol_l, int vol_r)
158{
159 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
160 /* 1111111 == +6dB */
161 /* 1111001 == 0dB */
162 /* 0110000 == -73dB */
163 /* 0101111 == mute (0x2f) */
164
165 wmcodec_write(LOUTVOL, VOLUME_ZC_WAIT | vol_l);
166 wmcodec_write(ROUTVOL, VOLUME_ZC_WAIT | vol_r);
167
168 return 0;
169}
170
171int audiohw_set_mixer_vol(int channel1, int channel2)
172{
173 (void)channel1;
174 (void)channel2;
175
176 return 0;
177}
178
179void audiohw_set_bass(int value)
180{
181 (void)value;
182}
183
184void audiohw_set_treble(int value)
185{
186 (void)value;
187}
188
189/* Nice shutdown of WM8731 codec */
190void audiohw_close(void)
191{
192 /* set DACMU=1 DEEMPH=0 */
193 wmcodec_write(DACCTRL, 0x8);
194
195 /* ACTIVE=0 */
196 codec_set_active(0x0);
197
198 /* line in mute left & right*/
199 wmcodec_write(LINVOL, 0x100 | 0x80);
200
201 /* set DACSEL=0, MUTEMIC=1 */
202 wmcodec_write(0x4, 0x2);
203
204 /* set POWEROFF=0 OUTPD=0 DACPD=1 */
205 wmcodec_write(PWRMGMT, 0x6f);
206
207 /* set POWEROFF=1 OUTPD=1 DACPD=1 */
208 wmcodec_write(PWRMGMT, 0xff);
209}
210
211/* Change the order of the noise shaper, 5th order is recommended above 32kHz */
212void audiohw_set_nsorder(int order)
213{
214 (void)order;
215}
216
217void audiohw_set_sample_rate(int sampling_control)
218{
219 codec_set_active(0x0);
220 wmcodec_write(SAMPCTRL, sampling_control);
221 codec_set_active(0x1);
222}
223
224void audiohw_enable_recording(bool source_mic)
225{
226 static int line_level = 0x17;
227 static int mic_boost = true;
228 codec_set_active(0x0);
229
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);
233
234 wmcodec_write(LOUTVOL, 0x0); /* headphone mute left */
235 wmcodec_write(ROUTVOL, 0x0); /* headphone mute right */
236
237
238 if(source_mic){
239 wmcodec_write(LINVOL, 0x80); /* line in mute left */
240 wmcodec_write(RINVOL, 0x80); /* line in mute right */
241
242
243 if (mic_boost) {
244 wmcodec_write(AAPCTRL, 0x5); /* INSEL=mic, MIC_BOOST=enable */
245 } else {
246 wmcodec_write(AAPCTRL, 0x4); /* INSEL=mic */
247 }
248 } else {
249 if (line_level == 0) {
250 wmcodec_write(LINVOL, 0x80);
251 wmcodec_write(RINVOL, 0x80);
252 } else {
253 wmcodec_write(LINVOL, line_level);
254 wmcodec_write(RINVOL, line_level);
255 }
256 wmcodec_write(AAPCTRL, 0xa); /* BY PASS, mute mic, INSEL=line in */
257 }
258
259 /* disable ADC high pass filter, mute dac */
260 wmcodec_write(DACCTRL, 0x9);
261
262 /* power on (PWR_OFF=0) */
263 if(source_mic){
264 /* CLKOUTPD OSCPD OUTPD DACPD LINEINPD */
265 wmcodec_write(PWRMGMT, 0x79);
266 } else {
267 wmcodec_write(PWRMGMT, 0x7a); /* MICPD */
268 }
269
270 codec_set_active(0x1);
271}
272
273void audiohw_disable_recording(void)
274{
275 /* set DACMU=1 DEEMPH=0 */
276 wmcodec_write(DACCTRL, 0x8);
277
278 /* ACTIVE=0 */
279 codec_set_active(0x0);
280
281 /* line in mute left & right*/
282 wmcodec_write(LINVOL, 0x80);
283 wmcodec_write(RINVOL, 0x80);
284
285 /* set DACSEL=0, MUTEMIC=1 */
286 wmcodec_write(AAPCTRL, 0x2);
287
288 /* set POWEROFF=0 OUTPD=0 DACPD=1 */
289 wmcodec_write(PWRMGMT, 0x6f);
290
291 /* set POWEROFF=1 OUTPD=1 DACPD=1 */
292 wmcodec_write(PWRMGMT, 0xff);
293}
294
295void audiohw_set_recvol(int left, int right, int type)
296{
297 (void)left;
298 (void)right;
299 (void)type;
300}
301
302void audiohw_set_monitor(int enable)
303{
304 (void)enable;
305}