summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-05-03 16:10:46 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-05-03 16:10:46 +0000
commit8f0a1b3e6cd466b8016e79ee49fc342986a787ad (patch)
tree8b99f65380c447c93407ada021041ba8799c6ab5
parent28df6bf869353d9a288f7a11cb7341177cc6b386 (diff)
downloadrockbox-8f0a1b3e6cd466b8016e79ee49fc342986a787ad.tar.gz
rockbox-8f0a1b3e6cd466b8016e79ee49fc342986a787ad.zip
It's better not to use fixed constants since the lower volume limit may not be constant.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17329 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/audio/wm8978.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/firmware/drivers/audio/wm8978.c b/firmware/drivers/audio/wm8978.c
index f94f1db87f..9ebfeca820 100644
--- a/firmware/drivers/audio/wm8978.c
+++ b/firmware/drivers/audio/wm8978.c
@@ -26,9 +26,15 @@
26//#define LOGF_ENABLE 26//#define LOGF_ENABLE
27#include "logf.h" 27#include "logf.h"
28 28
29#define HW_VOL_MIN 0 29/* #define to help adjust lower volume limit */
30#define HW_VOL_MUTE 0 30#define HW_VOL_MIN 0
31#define HW_VOL_MAX 96 31#define HW_VOL_MUTE 0
32#define HW_VOL_MAX 96
33#define HW_VOL_ANA_MIN 0
34#define HW_VOL_ANA_MAX 63
35#define HW_VOL_DIG_MAX 255
36#define HW_VOL_DIG_THRESHOLD (HW_VOL_MAX - HW_VOL_ANA_MAX)
37#define HW_VOL_DIG_MIN (HW_VOL_DIG_MAX - 2*HW_VOL_DIG_THRESHOLD)
32 38
33/* TODO: Define/refine an API for special hardware steps outside the 39/* TODO: Define/refine an API for special hardware steps outside the
34 * main codec driver such as special GPIO handling. */ 40 * main codec driver such as special GPIO handling. */
@@ -119,7 +125,7 @@ struct
119 bool ahw_mute; 125 bool ahw_mute;
120} wmc_vol = 126} wmc_vol =
121{ 127{
122 0, 0, false 128 HW_VOL_MUTE, HW_VOL_MUTE, false
123}; 129};
124 130
125static void wmc_write(unsigned int reg, unsigned int val) 131static void wmc_write(unsigned int reg, unsigned int val)
@@ -222,10 +228,10 @@ void audiohw_postinit(void)
222 wmc_write(WMC_ADDITIONAL_CTRL, WMC_SR_48KHZ); /* 44.1 */ 228 wmc_write(WMC_ADDITIONAL_CTRL, WMC_SR_48KHZ); /* 44.1 */
223 229
224 /* Initialize to minimum volume */ 230 /* Initialize to minimum volume */
225 wmc_write_masked(WMC_LEFT_DAC_DIGITAL_VOL, 189, WMC_DVOL); 231 wmc_write_masked(WMC_LEFT_DAC_DIGITAL_VOL, HW_VOL_DIG_MIN, WMC_DVOL);
226 wmc_write_masked(WMC_LOUT1_HP_VOLUME_CTRL, 0, WMC_AVOL); 232 wmc_write_masked(WMC_LOUT1_HP_VOLUME_CTRL, HW_VOL_ANA_MIN, WMC_AVOL);
227 wmc_write_masked(WMC_RIGHT_DAC_DIGITAL_VOL, 189, WMC_DVOL); 233 wmc_write_masked(WMC_RIGHT_DAC_DIGITAL_VOL, HW_VOL_DIG_MIN, WMC_DVOL);
228 wmc_write_masked(WMC_ROUT1_HP_VOLUME_CTRL, 0, WMC_AVOL); 234 wmc_write_masked(WMC_ROUT1_HP_VOLUME_CTRL, HW_VOL_ANA_MIN, WMC_AVOL);
229 235
230 /* ADC silenced */ 236 /* ADC silenced */
231 wmc_write_masked(WMC_LEFT_ADC_DIGITAL_VOL, 0x00, WMC_DVOL); 237 wmc_write_masked(WMC_LEFT_ADC_DIGITAL_VOL, 0x00, WMC_DVOL);
@@ -245,38 +251,38 @@ void audiohw_set_headphone_vol(int vol_l, int vol_r)
245 251
246 /* When analogue volume falls below -57dB (0x00) start attenuating the 252 /* When analogue volume falls below -57dB (0x00) start attenuating the
247 * DAC volume */ 253 * DAC volume */
248 if (vol_l >= 33) 254 if (vol_l >= HW_VOL_DIG_THRESHOLD)
249 { 255 {
250 if (vol_l > HW_VOL_MAX) 256 if (vol_l > HW_VOL_MAX)
251 vol_l = HW_VOL_MAX; 257 vol_l = HW_VOL_MAX;
252 258
253 dac_l = 255; 259 dac_l = HW_VOL_DIG_MAX;
254 vol_l -= 33; 260 vol_l -= HW_VOL_DIG_THRESHOLD;
255 } 261 }
256 else 262 else
257 { 263 {
258 if (vol_l < HW_VOL_MIN) 264 if (vol_l < HW_VOL_MIN)
259 vol_l = HW_VOL_MIN; 265 vol_l = HW_VOL_MIN;
260 266
261 dac_l = 2*vol_l + 189; 267 dac_l = 2*vol_l + HW_VOL_DIG_MIN;
262 vol_l = 0; 268 vol_l = HW_VOL_ANA_MIN;
263 } 269 }
264 270
265 if (vol_r >= 33) 271 if (vol_r >= HW_VOL_DIG_THRESHOLD)
266 { 272 {
267 if (vol_r > HW_VOL_MAX) 273 if (vol_r > HW_VOL_MAX)
268 vol_r = HW_VOL_MAX; 274 vol_r = HW_VOL_MAX;
269 275
270 dac_r = 255; 276 dac_r = HW_VOL_DIG_MAX;
271 vol_r -= 33; 277 vol_r -= HW_VOL_DIG_THRESHOLD;
272 } 278 }
273 else 279 else
274 { 280 {
275 if (vol_r < HW_VOL_MIN) 281 if (vol_r < HW_VOL_MIN)
276 vol_r = HW_VOL_MIN; 282 vol_r = HW_VOL_MIN;
277 283
278 dac_r = 2*vol_r + 189; 284 dac_r = 2*vol_r + HW_VOL_DIG_MIN;
279 vol_r = 0; 285 vol_r = HW_VOL_ANA_MIN;
280 } 286 }
281 287
282 /* Have to write both channels always to have the latching work */ 288 /* Have to write both channels always to have the latching work */