summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorAndree Buschmann <AndreeBuschmann@t-online.de>2010-05-30 18:29:04 +0000
committerAndree Buschmann <AndreeBuschmann@t-online.de>2010-05-30 18:29:04 +0000
commitf0e1cf038f6265fe71d5c3658e553b08c0eec163 (patch)
treee3fc9064ed3172851880c65fb81c7b89d6378fb5 /firmware
parent17889d4ec451fe3325ca4a450d74d923bab5d6e4 (diff)
downloadrockbox-f0e1cf038f6265fe71d5c3658e553b08c0eec163.tar.gz
rockbox-f0e1cf038f6265fe71d5c3658e553b08c0eec163.zip
Submit FS#11240 by Raphael Jakse. Allows to reduce volume on WM8985 to -89 dB (e.g. used for Cowon D2). Below -57 dB the line out is affected. The manual is updated accordingly.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26413 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/drivers/audio/wm8985.c75
-rw-r--r--firmware/export/wm8985.h2
2 files changed, 59 insertions, 18 deletions
diff --git a/firmware/drivers/audio/wm8985.c b/firmware/drivers/audio/wm8985.c
index da08b44402..a76e20e57b 100644
--- a/firmware/drivers/audio/wm8985.c
+++ b/firmware/drivers/audio/wm8985.c
@@ -42,6 +42,7 @@
42#define ADCCTL 0x0e 42#define ADCCTL 0x0e
43#define LADCVOL 0x0f 43#define LADCVOL 0x0f
44#define RADCVOL 0x10 44#define RADCVOL 0x10
45#define RDACVOL_DACVU 0x100
45 46
46#define EQ1 0x12 47#define EQ1 0x12
47#define EQ2 0x13 48#define EQ2 0x13
@@ -88,7 +89,7 @@
88#define BIASCTL 0x3d 89#define BIASCTL 0x3d
89 90
90const struct sound_settings_info audiohw_settings[] = { 91const struct sound_settings_info audiohw_settings[] = {
91 [SOUND_VOLUME] = {"dB", 0, 1, -58, 6, -25}, 92 [SOUND_VOLUME] = {"dB", 0, 1, -90, 6, -25},
92 [SOUND_BASS] = {"dB", 0, 1, -12, 12, 0}, 93 [SOUND_BASS] = {"dB", 0, 1, -12, 12, 0},
93 [SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 0}, 94 [SOUND_TREBLE] = {"dB", 0, 1, -12, 12, 0},
94 [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0}, 95 [SOUND_BALANCE] = {"%", 0, 1,-100, 100, 0},
@@ -111,21 +112,48 @@ const struct sound_settings_info audiohw_settings[] = {
111unsigned int eq1_reg; 112unsigned int eq1_reg;
112unsigned int eq5_reg; 113unsigned int eq5_reg;
113 114
114/* convert tenth of dB volume (-57..6) to master volume register value */ 115/* convert tenth of dB volume (-89..6) to master volume register value */
115int tenthdb2master(int db) 116int tenthdb2master(int db)
116{ 117{
117 /* +6 to -57dB in 1dB steps == 64 levels = 6 bits */ 118 /* Might have no sense, taken from wm8758.c :
118 /* 0111111 == +6dB (0x3f) = 63) */ 119 att DAC AMP result
119 /* 0111001 == 0dB (0x39) = 57) */ 120 +6dB 0 +6 96
120 /* 0000001 == -56dB (0x01) = */ 121 0dB 0 0 90
121 /* 0000000 == -57dB (0x00) */ 122 -57dB 0 -57 33
122 123 -58dB -1 -57 32
123 /* 1000000 == Mute (0x40) */ 124 -89dB -32 -57 1
125 -90dB -oo -oo 0 */
124 126
125 if (db < VOLUME_MIN) { 127 if (db < VOLUME_MIN) {
126 return 0x40; 128 return 0;
127 } else { 129 } else {
128 return((db/10)+57); 130 return (db-VOLUME_MIN)/10 + 1;
131 }
132}
133
134 /* helper function coming from wm8758.c that calculates the register setting for amplifier and
135 DAC volume out of the input from tenthdb2master() */
136static void get_volume_params(int db, int *dac, int *amp)
137{
138 /* should never happen, set max volume for amp and dac */
139 if (db > 96) {
140 *dac = 255;
141 *amp = 63;
142 }
143 /* set dac to max and set volume for amp (better snr) */
144 else if (db > 32) {
145 *dac = 255;
146 *amp = (db-90)+57;
147 }
148 /* set amp to min and reduce dac output */
149 else if (db > 0) {
150 *dac = (db-33)*2 + 255;
151 *amp = 0;
152 }
153 /* mute all */
154 else {
155 *dac = 0x00;
156 *amp = 0x40;
129 } 157 }
130} 158}
131 159
@@ -190,16 +218,29 @@ void audiohw_postinit(void)
190 218
191void audiohw_set_headphone_vol(int vol_l, int vol_r) 219void audiohw_set_headphone_vol(int vol_l, int vol_r)
192{ 220{
193 /* OUT1 */ 221 int dac_l, amp_l, dac_r, amp_r;
194 wmcodec_write(LOUT1VOL, 0x080 | vol_l); 222 get_volume_params(vol_l, &dac_l, &amp_l);
195 wmcodec_write(ROUT1VOL, 0x180 | vol_r); 223 get_volume_params(vol_r, &dac_r, &amp_r);
224
225 /* set DAC
226 Important: DAC is global and will also affect lineout */
227 wmcodec_write(LDACVOL, dac_l);
228 wmcodec_write(RDACVOL, dac_r | RDACVOL_DACVU);
229
230 /* set headphone amp OUT1 */
231 wmcodec_write(LOUT1VOL, amp_l | 0x080);
232 wmcodec_write(ROUT1VOL, amp_r | 0x180);
196} 233}
197 234
198void audiohw_set_lineout_vol(int vol_l, int vol_r) 235void audiohw_set_lineout_vol(int vol_l, int vol_r)
199{ 236{
200 /* OUT2 */ 237 int dac_l, amp_l, dac_r, amp_r;
201 wmcodec_write(LOUT2VOL, vol_l); 238 get_volume_params(vol_l, &dac_l, &amp_l);
202 wmcodec_write(ROUT2VOL, 0x100 | vol_r); 239 get_volume_params(vol_r, &dac_r, &amp_r);
240
241 /* set lineout amp OUT2 */
242 wmcodec_write(LOUT2VOL, amp_l);
243 wmcodec_write(ROUT2VOL, amp_r | 0x100);
203} 244}
204 245
205void audiohw_set_aux_vol(int vol_l, int vol_r) 246void audiohw_set_aux_vol(int vol_l, int vol_r)
diff --git a/firmware/export/wm8985.h b/firmware/export/wm8985.h
index c6b8e3825f..4538b5edc5 100644
--- a/firmware/export/wm8985.h
+++ b/firmware/export/wm8985.h
@@ -23,7 +23,7 @@
23#define _WM8985_H 23#define _WM8985_H
24 24
25/* volume/balance/treble/bass interdependency */ 25/* volume/balance/treble/bass interdependency */
26#define VOLUME_MIN -570 26#define VOLUME_MIN -890
27#define VOLUME_MAX 60 27#define VOLUME_MAX 60
28 28
29#ifdef COWON_D2 29#ifdef COWON_D2