1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Driver for WM8721 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 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version 2
22 * of the License, or (at your option) any later version.
24 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
25 * KIND, either express or implied.
27 ****************************************************************************/
38 #define IPOD_PCM_LEVEL 0x65 /* -6dB */
40 /* use zero crossing to reduce clicks during volume changes */
41 #define VOLUME_ZC_WAIT (1<<7)
43 const struct sound_settings_info audiohw_settings
[] = {
44 [SOUND_VOLUME
] = {"dB", 0, 1, -74, 6, -25},
45 /* HAVE_SW_TONE_CONTROLS */
46 [SOUND_BASS
] = {"dB", 0, 1, -24, 24, 0},
47 [SOUND_TREBLE
] = {"dB", 0, 1, -24, 24, 0},
48 [SOUND_BALANCE
] = {"%", 0, 1,-100, 100, 0},
49 [SOUND_CHANNELS
] = {"", 0, 1, 0, 5, 0},
50 [SOUND_STEREO_WIDTH
] = {"%", 0, 5, 0, 250, 100},
53 /* convert tenth of dB volume (-730..60) to master volume register value */
54 int tenthdb2master(int db
)
56 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
57 /* 1111111 == +6dB (0x7f) */
58 /* 1111001 == 0dB (0x79) */
59 /* 0110000 == -73dB (0x30 */
60 /* 0101111 == mute (0x2f) */
62 if (db
< VOLUME_MIN
) {
65 return((db
/10)+0x30+73);
69 void audiohw_mute(bool mute
)
73 /* Set DACMU = 1 to soft-mute the audio DACs. */
74 wmcodec_write(DAPCTRL
, 0x8);
76 /* Set DACMU = 0 to soft-un-mute the audio DACs. */
77 wmcodec_write(DAPCTRL
, 0x0);
81 /** From ipodLinux **/
82 static void codec_set_active(int active
)
84 /* set active to 0x0 or 0x1 */
86 wmcodec_write(ACTIVECTRL
, 0x01);
88 wmcodec_write(ACTIVECTRL
, 0x00);
93 /* Silently enable / disable audio output */
94 void audiohw_enable_output(bool enable
)
98 /* reset the I2S controller into known state */
101 wmcodec_write(RESET
, 0x0); /*Reset*/
103 codec_set_active(0x0);
106 wmcodec_write(0x4, 0x10);
108 /* set power register to POWEROFF=0 on OUTPD=0, DACPD=0 */
109 wmcodec_write(PDCTRL
, 0x67);
111 /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */
112 /* IWL=00(16 bit) FORMAT=10(I2S format) */
113 wmcodec_write(AINTFCE
, 0x42);
115 audiohw_set_sample_rate(WM8721_USB24_44100HZ
);
117 /* set the volume to -6dB */
118 wmcodec_write(LOUTVOL
, IPOD_PCM_LEVEL
);
119 wmcodec_write(ROUTVOL
, 0x100 | IPOD_PCM_LEVEL
);
124 /* 5. Set DACMU = 0 to soft-un-mute the audio DACs. */
125 wmcodec_write(DAPCTRL
, 0x0);
133 void audiohw_set_master_vol(int vol_l
, int vol_r
)
135 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
136 /* 1111111 == +6dB */
138 /* 0110000 == -73dB */
139 /* 0101111 == mute (0x2f) */
140 wmcodec_write(LOUTVOL
, VOLUME_ZC_WAIT
| vol_l
);
141 wmcodec_write(ROUTVOL
, VOLUME_ZC_WAIT
| vol_r
);
144 /* Nice shutdown of WM8721 codec */
145 void audiohw_close(void)
147 /* set DACMU=1 DEEMPH=0 */
148 wmcodec_write(DAPCTRL
, 0x8);
151 codec_set_active(0x0);
153 /* set DACSEL=0, MUTEMIC=1 */
154 wmcodec_write(0x4, 0x2);
156 /* set POWEROFF=0 OUTPD=0 DACPD=1 */
157 wmcodec_write(PDCTRL
, 0x6f);
159 /* set POWEROFF=1 OUTPD=1 DACPD=1 */
160 wmcodec_write(PDCTRL
, 0xff);
163 /* Change the order of the noise shaper, 5th order is recommended above 32kHz */
164 void audiohw_set_nsorder(int order
)
169 void audiohw_set_sample_rate(int sampling_control
)
172 switch(sampling_control
)
175 rate
= WM8721_USB24_96000HZ
;
178 rate
= WM8721_USB24_88200HZ
;
181 rate
= WM8721_USB24_48000HZ
;
184 rate
= WM8721_USB24_44100HZ
;
187 rate
= WM8721_USB24_32000HZ
;
190 rate
= WM8721_USB24_8000HZ
;
193 codec_set_active(0x0);
194 wmcodec_write(SAMPCTRL
, rate
);
195 codec_set_active(0x1);