summaryrefslogtreecommitdiff
path: root/firmware/drivers/audio/wm8978.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-04-12 23:35:47 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-04-15 12:02:05 -0400
commit0c7b7873984e04941c9f21fa272638018fdb9a16 (patch)
treefb6afca45d2bef0a2c91732a39ffc0b965f5c557 /firmware/drivers/audio/wm8978.c
parentfd9e2568908f91b5bcf7378dc28f6ec070d6027a (diff)
downloadrockbox-0c7b7873984e04941c9f21fa272638018fdb9a16.tar.gz
rockbox-0c7b7873984e04941c9f21fa272638018fdb9a16.zip
Straighten out the mad twisted state of sound.c and related areas.
This is going right in since it's long overdue. If anything is goofed, drop me a line or just tweak it yourself if you know what's wrong. :-) Make HW/SW codec interface more uniform when emulating HW functionality on SWCODEC for functions such as "audiohw_set_pitch". The firmware-to- DSP plumbing is in firmware/drivers/audiohw-swcodec.c. "sound_XXX" APIs are all in sound.c with none in DSP code any longer. Reduce number of settings definitions needed by each codec by providing defaults for common ones like balance, channels and SW tone controls. Remove need for separate SIM code and tables and add virtual codec header for hosted targets. Change-Id: I3f23702bca054fc9bda40f49824ce681bb7f777b
Diffstat (limited to 'firmware/drivers/audio/wm8978.c')
-rw-r--r--firmware/drivers/audio/wm8978.c77
1 files changed, 7 insertions, 70 deletions
diff --git a/firmware/drivers/audio/wm8978.c b/firmware/drivers/audio/wm8978.c
index 3602bf9cb3..3a86ef204e 100644
--- a/firmware/drivers/audio/wm8978.c
+++ b/firmware/drivers/audio/wm8978.c
@@ -36,39 +36,6 @@
36 * file it may break things. */ 36 * file it may break things. */
37extern void audiohw_enable_headphone_jack(bool enable); 37extern void audiohw_enable_headphone_jack(bool enable);
38 38
39const struct sound_settings_info audiohw_settings[] =
40{
41 [SOUND_VOLUME] = {"dB", 0, 1, -90, 6, -25},
42 [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
43 [SOUND_CHANNELS] = {"", 0, 1, 0, 5, 0},
44 [SOUND_STEREO_WIDTH] = {"%", 0, 5, 0, 250, 100},
45 [SOUND_EQ_BAND1_GAIN] = {"dB", 0, 1, -12, 12, 0},
46 [SOUND_EQ_BAND2_GAIN] = {"dB", 0, 1, -12, 12, 0},
47 [SOUND_EQ_BAND3_GAIN] = {"dB", 0, 1, -12, 12, 0},
48 [SOUND_EQ_BAND4_GAIN] = {"dB", 0, 1, -12, 12, 0},
49 [SOUND_EQ_BAND5_GAIN] = {"dB", 0, 1, -12, 12, 0},
50 [SOUND_EQ_BAND1_FREQUENCY] = {"", 0, 1, 0, 3, 0},
51 [SOUND_EQ_BAND2_FREQUENCY] = {"", 0, 1, 0, 3, 0},
52 [SOUND_EQ_BAND3_FREQUENCY] = {"", 0, 1, 0, 3, 0},
53 [SOUND_EQ_BAND4_FREQUENCY] = {"", 0, 1, 0, 3, 0},
54 [SOUND_EQ_BAND5_FREQUENCY] = {"", 0, 1, 0, 3, 0},
55 [SOUND_EQ_BAND2_WIDTH] = {"", 0, 1, 0, 1, 0},
56 [SOUND_EQ_BAND3_WIDTH] = {"", 0, 1, 0, 1, 0},
57 [SOUND_EQ_BAND4_WIDTH] = {"", 0, 1, 0, 1, 0},
58 [SOUND_DEPTH_3D] = {"%", 0, 1, 0, 15, 0},
59#ifdef HAVE_RECORDING
60 /* Digital: -119.0dB to +8.0dB in 0.5dB increments
61 * Analog: Relegated to volume control
62 * Circumstances unfortunately do not allow a great deal of positive
63 * gain. */
64 [SOUND_LEFT_GAIN] = {"dB", 1, 1,-238, 16, 0},
65 [SOUND_RIGHT_GAIN] = {"dB", 1, 1,-238, 16, 0},
66#if 0
67 [SOUND_MIC_GAIN] = {"dB", 1, 1,-238, 16, 0},
68#endif
69#endif
70};
71
72static uint16_t wmc_regs[WMC_NUM_REGISTERS] = 39static uint16_t wmc_regs[WMC_NUM_REGISTERS] =
73{ 40{
74 /* Initialized with post-reset default values - the 2-wire interface 41 /* Initialized with post-reset default values - the 2-wire interface
@@ -184,9 +151,9 @@ static void wmc_write_masked(unsigned int reg, unsigned int bits,
184 wmc_write(reg, (wmc_regs[reg] & ~mask) | (bits & mask)); 151 wmc_write(reg, (wmc_regs[reg] & ~mask) | (bits & mask));
185} 152}
186 153
187/* convert tenth of dB volume (-890..60) to master volume register value 154/* convert tenth of dB volume (-890..60) to volume register value
188 * (000000...111111) */ 155 * (000000...111111) */
189int tenthdb2master(int db) 156static int vol_tenthdb2hw(int db)
190{ 157{
191 /* -90dB to +6dB 1dB steps (96 levels) 7bits */ 158 /* -90dB to +6dB 1dB steps (96 levels) 7bits */
192 /* 1100000 == +6dB (0x60,96) */ 159 /* 1100000 == +6dB (0x60,96) */
@@ -194,7 +161,7 @@ int tenthdb2master(int db)
194 /* 1000001 == -57dB (0x21,33,DAC) */ 161 /* 1000001 == -57dB (0x21,33,DAC) */
195 /* 0000001 == -89dB (0x01,01) */ 162 /* 0000001 == -89dB (0x01,01) */
196 /* 0000000 == -90dB (0x00,00,Mute) */ 163 /* 0000000 == -90dB (0x00,00,Mute) */
197 if (db <= VOLUME_MIN) 164 if (db < VOLUME_MIN)
198 { 165 {
199 return 0x0; 166 return 0x0;
200 } 167 }
@@ -204,39 +171,6 @@ int tenthdb2master(int db)
204 } 171 }
205} 172}
206 173
207int sound_val2phys(int setting, int value)
208{
209 int result;
210
211 switch (setting)
212 {
213#ifdef HAVE_RECORDING
214 case SOUND_LEFT_GAIN:
215 case SOUND_RIGHT_GAIN:
216 case SOUND_MIC_GAIN:
217 result = value * 5;
218 break;
219#endif
220
221 case SOUND_EQ_BAND1_GAIN+0x10000:
222 case SOUND_EQ_BAND2_GAIN+0x10000:
223 case SOUND_EQ_BAND3_GAIN+0x10000:
224 case SOUND_EQ_BAND4_GAIN+0x10000:
225 case SOUND_EQ_BAND5_GAIN+0x10000:
226 result = value * 10;
227 break;
228
229 case SOUND_DEPTH_3D:
230 result = (100 * value + 8) / 15;
231 break;
232
233 default:
234 result = value;
235 }
236
237 return result;
238}
239
240void audiohw_preinit(void) 174void audiohw_preinit(void)
241{ 175{
242 /* 1. Turn on external power supplies. Wait for supply voltage to settle. */ 176 /* 1. Turn on external power supplies. Wait for supply voltage to settle. */
@@ -350,13 +284,16 @@ static void sync_prescaler(void)
350 WMC_DVOL); 284 WMC_DVOL);
351} 285}
352 286
353void audiohw_set_headphone_vol(int vol_l, int vol_r) 287void audiohw_set_volume(int vol_l, int vol_r)
354{ 288{
355 int prev_l = wmc_vol.vol_l; 289 int prev_l = wmc_vol.vol_l;
356 int prev_r = wmc_vol.vol_r; 290 int prev_r = wmc_vol.vol_r;
357 int dac_l, dac_r, hp_l, hp_r; 291 int dac_l, dac_r, hp_l, hp_r;
358 int mix_l, mix_r, boost_l, boost_r; 292 int mix_l, mix_r, boost_l, boost_r;
359 293
294 vol_l = vol_tenthdb2hw(vol_l);
295 vol_r = vol_tenthdb2hw(vol_r);
296
360 wmc_vol.vol_l = vol_l; 297 wmc_vol.vol_l = vol_l;
361 wmc_vol.vol_r = vol_r; 298 wmc_vol.vol_r = vol_r;
362 299