summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/wm8731l.c65
-rw-r--r--firmware/drivers/wm8758.c72
-rw-r--r--firmware/drivers/wm8975.c73
3 files changed, 184 insertions, 26 deletions
diff --git a/firmware/drivers/wm8731l.c b/firmware/drivers/wm8731l.c
index a690aade48..4f0f249149 100644
--- a/firmware/drivers/wm8731l.c
+++ b/firmware/drivers/wm8731l.c
@@ -220,12 +220,73 @@ void audiohw_set_sample_rate(int sampling_control)
220 220
221void audiohw_enable_recording(bool source_mic) 221void audiohw_enable_recording(bool source_mic)
222{ 222{
223 (void)source_mic; 223 static int line_level = 0x17;
224 static int mic_boost = true;
225 codec_set_active(0x0);
226
227 /* set BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0
228 * LRP=0 IWL=00(16 bit) FORMAT=10(I2S format) */
229 wmcodec_write(AINTFCE, 0x42);
230
231 wmcodec_write(LOUTVOL, 0x0); /* headphone mute left */
232 wmcodec_write(ROUTVOL, 0x0); /* headphone mute right */
233
234
235 if(source_mic){
236 wmcodec_write(LINVOL, 0x80); /* line in mute left */
237 wmcodec_write(RINVOL, 0x80); /* line in mute right */
238
239
240 if (mic_boost) {
241 wmcodec_write(AAPCTRL, 0x5); /* INSEL=mic, MIC_BOOST=enable */
242 } else {
243 wmcodec_write(AAPCTRL, 0x4); /* INSEL=mic */
244 }
245 } else {
246 if (line_level == 0) {
247 wmcodec_write(LINVOL, 0x80);
248 wmcodec_write(RINVOL, 0x80);
249 } else {
250 wmcodec_write(LINVOL, line_level);
251 wmcodec_write(RINVOL, line_level);
252 }
253 wmcodec_write(AAPCTRL, 0xa); /* BY PASS, mute mic, INSEL=line in */
254 }
255
256 /* disable ADC high pass filter, mute dac */
257 wmcodec_write(DACCTRL, 0x9);
258
259 /* power on (PWR_OFF=0) */
260 if(source_mic){
261 /* CLKOUTPD OSCPD OUTPD DACPD LINEINPD */
262 wmcodec_write(PWRMGMT, 0x79);
263 } else {
264 wmcodec_write(PWRMGMT, 0x7a); /* MICPD */
265 }
266
267 codec_set_active(0x1);
224} 268}
225 269
226void audiohw_disable_recording(void) 270void audiohw_disable_recording(void)
227{ 271{
228 272 /* set DACMU=1 DEEMPH=0 */
273 wmcodec_write(DACCTRL, 0x8);
274
275 /* ACTIVE=0 */
276 codec_set_active(0x0);
277
278 /* line in mute left & right*/
279 wmcodec_write(LINVOL, 0x80);
280 wmcodec_write(RINVOL, 0x80);
281
282 /* set DACSEL=0, MUTEMIC=1 */
283 wmcodec_write(AAPCTRL, 0x2);
284
285 /* set POWEROFF=0 OUTPD=0 DACPD=1 */
286 wmcodec_write(PWRMGMT, 0x6f);
287
288 /* set POWEROFF=1 OUTPD=1 DACPD=1 */
289 wmcodec_write(PWRMGMT, 0xff);
229} 290}
230 291
231void audiohw_set_recvol(int left, int right, int type) 292void audiohw_set_recvol(int left, int right, int type)
diff --git a/firmware/drivers/wm8758.c b/firmware/drivers/wm8758.c
index 22bef73e45..9732d4f776 100644
--- a/firmware/drivers/wm8758.c
+++ b/firmware/drivers/wm8758.c
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Driver for WM8758 audio codec 10 * Driver for WM8758 audio codec - based on datasheet for WM8983
11 * 11 *
12 * Based on code from the ipodlinux project - http://ipodlinux.org/ 12 * Based on code from the ipodlinux project - http://ipodlinux.org/
13 * Adapted for Rockbox in December 2005 13 * Adapted for Rockbox in December 2005
@@ -142,30 +142,11 @@ int audiohw_set_mixer_vol(int channel1, int channel2)
142void audiohw_set_bass(int value) 142void audiohw_set_bass(int value)
143{ 143{
144 (void)value; 144 (void)value;
145#if 0
146 /* Not yet implemented - this is the wm8975 code*/
147 int regvalues[]={11, 10, 10, 9, 8, 8, 0xf , 6, 6, 5, 4, 4, 3, 2, 1, 0};
148
149 if ((value >= -6) && (value <= 9)) {
150 /* We use linear bass control with 130Hz cutoff */
151 wmcodec_write(BASSCTRL, regvalues[value+6]);
152 }
153#endif
154} 145}
155 146
156void audiohw_set_treble(int value) 147void audiohw_set_treble(int value)
157{ 148{
158 (void)value; 149 (void)value;
159#if 0
160 /* Not yet implemented - this is the wm8975 code*/
161 int regvalues[]={11, 10, 10, 9, 8, 8, 0xf , 6, 6, 5, 4, 4, 3, 2, 1, 0};
162
163 if ((value >= -6) && (value <= 9)) {
164 /* We use a 8Khz cutoff */
165 wmcodec_write(TREBCTRL, regvalues[value+6]);
166 }
167#endif
168
169} 150}
170 151
171int audiohw_mute(int mute) 152int audiohw_mute(int mute)
@@ -224,11 +205,60 @@ void audiohw_set_sample_rate(int sampling_control)
224 205
225void audiohw_enable_recording(bool source_mic) 206void audiohw_enable_recording(bool source_mic)
226{ 207{
227 (void)source_mic; 208 (void)source_mic; /* We only have a line-in (I think) */
209
210 /* reset the I2S controller into known state */
211 i2s_reset();
212
213 wmcodec_write(RESET, 0x1ff); /*Reset*/
214
215 wmcodec_write(PWRMGMT1, 0x2b);
216 wmcodec_write(PWRMGMT2, 0x18f); /* Enable ADC - 0x0c enables left/right PGA input, and 0x03 turns on power to the ADCs */
217 wmcodec_write(PWRMGMT3, 0x6f);
218
219 wmcodec_write(AINTFCE, 0x10);
220 wmcodec_write(CLKCTRL, 0x49);
221
222 wmcodec_write(OUTCTRL, 1);
223
224 /* The iPod can handle multiple frequencies, but fix at 44.1KHz
225 for now */
226 wmcodec_set_sample_rate(WM8758_44100HZ);
227
228 wmcodec_write(INCTRL,0x44); /* Connect L2 and R2 inputs */
229
230 /* Set L2/R2_2BOOSTVOL to 0db (bits 4-6) */
231 /* 000 = disabled
232 001 = -12dB
233 010 = -9dB
234 011 = -6dB
235 100 = -3dB
236 101 = 0dB
237 110 = 3dB
238 111 = 6dB
239 */
240 wmcodec_write(LADCBOOST,0x50);
241 wmcodec_write(RADCBOOST,0x50);
242
243 /* Set L/R input PGA Volume to 0db */
244 // wm8758_write(LINPGAVOL,0x3f);
245 // wm8758_write(RINPGAVOL,0x13f);
246
247 /* Enable monitoring */
248 wmcodec_write(LOUTMIX,0x17); /* Enable output mixer - BYPL2LMIX @ 0db*/
249 wmcodec_write(ROUTMIX,0x17); /* Enable output mixer - BYPR2RMIX @ 0db*/
250
251 wmcodec_mute(0);
228} 252}
229 253
230void audiohw_disable_recording(void) { 254void audiohw_disable_recording(void) {
255 wmcodec_mute(1);
256
257 wmcodec_write(PWRMGMT3, 0x0);
231 258
259 wmcodec_write(PWRMGMT1, 0x0);
260
261 wmcodec_write(PWRMGMT2, 0x40);
232} 262}
233 263
234void audiohw_set_recvol(int left, int right, int type) { 264void audiohw_set_recvol(int left, int right, int type) {
diff --git a/firmware/drivers/wm8975.c b/firmware/drivers/wm8975.c
index d2b1fa64b2..011d771a13 100644
--- a/firmware/drivers/wm8975.c
+++ b/firmware/drivers/wm8975.c
@@ -224,13 +224,80 @@ void audiohw_set_sample_rate(int sampling_control) {
224 224
225} 225}
226 226
227void audiohw_enable_recording(bool source_mic) { 227void audiohw_enable_recording(bool source_mic)
228{
229 (void)source_mic;
228 230
229 (void)source_mic; 231 /* reset the I2S controller into known state */
230} 232 i2s_reset();
233
234 /*
235 * 1. Switch on power supplies.
236 * By default the WM8750L is in Standby Mode, the DAC is
237 * digitally muted and the Audio Interface, Line outputs
238 * and Headphone outputs are all OFF (DACMU = 1 Power
239 * Management registers 1 and 2 are all zeros).
240 */
241 wmcodec_write(0x0f, 0x1ff);
242 wmcodec_write(0x0f, 0x000);
243
244 /* 2. Enable Vmid and VREF. */
245 wmcodec_write(0x19, 0xc0); /*Pwr Mgmt(1)*/
246
247 /* 3. Enable ADCs as required. */
248 wmcodec_write(0x19, 0xcc); /*Pwr Mgmt(1)*/
249 wmcodec_write(0x1a, 0x180); /*Pwr Mgmt(2)*/
250
251 /* 4. Enable line and / or headphone output buffers as required. */
252 wmcodec_write(0x19, 0xfc); /*Pwr Mgmt(1)*/
253
254 /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */
255 /* IWL=00(16 bit) FORMAT=10(I2S format) */
256 wmcodec_write(0x07, 0x42);
257
258 /* The iPod can handle multiple frequencies, but fix at 44.1KHz for now */
259 wmcodec_set_sample_rate(WM8975_44100HZ);
260
261 /* unmute inputs */
262 wmcodec_write(0x00, 0x17); /* LINVOL (def 0dB) */
263 wmcodec_write(0x01, 0x117); /* RINVOL (def 0dB) */
264
265 wmcodec_write(0x15, 0x1d7); /* LADCVOL max vol x was ff */
266 wmcodec_write(0x16, 0x1d7); /* RADCVOL max vol x was ff */
267
268 if (source_mic) {
269 /* VSEL=10(def) DATSEL=10 (use right ADC only) */
270 wmcodec_write(0x17, 0xc8); /* Additional control(1) */
231 271
272 /* VROI=1 (sets output resistance to 40kohms) */
273 wmcodec_write(0x1b, 0x40); /* Additional control(3) */
274
275 /* LINSEL=1 (LINPUT2) LMICBOOST=10 (20dB boost) */
276 wmcodec_write(0x20, 0x60); /* ADCL signal path */
277 wmcodec_write(0x21, 0x60); /* ADCR signal path */
278 } else {
279 /* VSEL=10(def) DATSEL=00 (left->left, right->right) */
280 wmcodec_write(0x17, 0xc0); /* Additional control(1) */
281
282 /* VROI=1 (sets output resistance to 40kohms) */
283 wmcodec_write(0x1b, 0x40); /* Additional control(3) */
284
285 /* LINSEL=0 (LINPUT1) LMICBOOST=00 (bypass boost) */
286 wmcodec_write(0x20, 0x00); /* ADCL signal path */
287 /* RINSEL=0 (RINPUT1) RMICBOOST=00 (bypass boost) */
288 wmcodec_write(0x21, 0x00); /* ADCR signal path */
289 }
290}
291
232void audiohw_disable_recording(void) { 292void audiohw_disable_recording(void) {
293 /* 1. Set DACMU = 1 to soft-mute the audio DACs. */
294 wmcodec_write(0x05, 0x8);
233 295
296 /* 2. Disable all output buffers. */
297 wmcodec_write(0x1a, 0x0); /*Pwr Mgmt(2)*/
298
299 /* 3. Switch off the power supplies. */
300 wmcodec_write(0x19, 0x0); /*Pwr Mgmt(1)*/
234} 301}
235 302
236void audiohw_set_recvol(int left, int right, int type) { 303void audiohw_set_recvol(int left, int right, int type) {