diff options
-rw-r--r-- | firmware/drivers/wm8975.c | 73 | ||||
-rw-r--r-- | firmware/export/wm8975.h | 20 |
2 files changed, 54 insertions, 39 deletions
diff --git a/firmware/drivers/wm8975.c b/firmware/drivers/wm8975.c index a817284406..54e245b61a 100644 --- a/firmware/drivers/wm8975.c +++ b/firmware/drivers/wm8975.c | |||
@@ -45,16 +45,6 @@ void wm8975_reset(void); | |||
45 | 45 | ||
46 | #define IPOD_PCM_LEVEL 0x65 /* -6dB */ | 46 | #define IPOD_PCM_LEVEL 0x65 /* -6dB */ |
47 | 47 | ||
48 | #define RESET (0x0f<<1) | ||
49 | #define PWRMGMT1 (0x19<<1) | ||
50 | #define PWRMGMT2 (0x1a<<1) | ||
51 | #define AINTFCE (0x07<<1) | ||
52 | #define LOUT1VOL (0x02<<1) | ||
53 | #define ROUT1VOL (0x03<<1) | ||
54 | #define LOUT2VOL (0x28<<1) | ||
55 | #define ROUT2VOL (0x29<<1) | ||
56 | |||
57 | |||
58 | /* | 48 | /* |
59 | * Reset the I2S BIT.FORMAT I2S, 16bit, FIFO.FORMAT 32bit | 49 | * Reset the I2S BIT.FORMAT I2S, 16bit, FIFO.FORMAT 32bit |
60 | */ | 50 | */ |
@@ -83,6 +73,11 @@ static void i2s_reset(void) | |||
83 | outl(inl(0x7000280c) | 0x1100, 0x7000280c); | 73 | outl(inl(0x7000280c) | 0x1100, 0x7000280c); |
84 | } | 74 | } |
85 | 75 | ||
76 | void wm8975_write(int reg, int data) | ||
77 | { | ||
78 | ipod_i2c_send(0x1a, (reg<<1) | ((data&0x100)>>8),data&0xff); | ||
79 | } | ||
80 | |||
86 | /* | 81 | /* |
87 | * Initialise the WM8975 for playback via headphone and line out. | 82 | * Initialise the WM8975 for playback via headphone and line out. |
88 | * Note, I'm using the WM8750 datasheet as its apparently close. | 83 | * Note, I'm using the WM8750 datasheet as its apparently close. |
@@ -129,39 +124,39 @@ void wm8975_enable_output(bool enable) | |||
129 | * and Headphone outputs are all OFF (DACMU = 1 Power | 124 | * and Headphone outputs are all OFF (DACMU = 1 Power |
130 | * Management registers 1 and 2 are all zeros). | 125 | * Management registers 1 and 2 are all zeros). |
131 | */ | 126 | */ |
132 | ipod_i2c_send(0x1a, RESET | 1, 0xff); /*Reset*/ | 127 | wm8975_write(RESET, 0x1ff); /*Reset*/ |
133 | ipod_i2c_send(0x1a, RESET, 0x0); | 128 | wm8975_write(RESET, 0x0); |
134 | 129 | ||
135 | /* 2. Enable Vmid and VREF. */ | 130 | /* 2. Enable Vmid and VREF. */ |
136 | ipod_i2c_send(0x1a, PWRMGMT1, 0xc0); /*Pwr Mgmt(1)*/ | 131 | wm8975_write(PWRMGMT1, 0xc0); /*Pwr Mgmt(1)*/ |
137 | 132 | ||
138 | /* 3. Enable DACs as required. */ | 133 | /* 3. Enable DACs as required. */ |
139 | ipod_i2c_send(0x1a, PWRMGMT2 | 0x1, 0x80); /*Pwr Mgmt(2)*/ | 134 | wm8975_write(PWRMGMT2, 0x180); /*Pwr Mgmt(2)*/ |
140 | 135 | ||
141 | /* 4. Enable line and / or headphone output buffers as required. */ | 136 | /* 4. Enable line and / or headphone output buffers as required. */ |
142 | ipod_i2c_send(0x1a, PWRMGMT2 | 0x1, 0xf8); /*Pwr Mgmt(2)*/ | 137 | wm8975_write(PWRMGMT2, 0x1f8); /*Pwr Mgmt(2)*/ |
143 | 138 | ||
144 | /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */ | 139 | /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */ |
145 | /* IWL=00(16 bit) FORMAT=10(I2S format) */ | 140 | /* IWL=00(16 bit) FORMAT=10(I2S format) */ |
146 | ipod_i2c_send(0x1a, AINTFCE, 0x42); | 141 | wm8975_write(AINTFCE, 0x42); |
147 | 142 | ||
148 | /* The iPod can handle multiple frequencies, but fix at 44.1KHz for now */ | 143 | /* The iPod can handle multiple frequencies, but fix at 44.1KHz for now */ |
149 | wm8975_set_sample_rate(WM8975_44100HZ); | 144 | wm8975_set_sample_rate(WM8975_44100HZ); |
150 | 145 | ||
151 | /* set the volume to -6dB */ | 146 | /* set the volume to -6dB */ |
152 | ipod_i2c_send(0x1a, LOUT1VOL, IPOD_PCM_LEVEL); | 147 | wm8975_write(LOUT1VOL, IPOD_PCM_LEVEL); |
153 | ipod_i2c_send(0x1a, ROUT1VOL | 0x1, IPOD_PCM_LEVEL); | 148 | wm8975_write(ROUT1VOL,0x100 | IPOD_PCM_LEVEL); |
154 | ipod_i2c_send(0x1a, LOUT1VOL, IPOD_PCM_LEVEL); | 149 | wm8975_write(LOUT1VOL, IPOD_PCM_LEVEL); |
155 | ipod_i2c_send(0x1a, ROUT1VOL | 0x1, IPOD_PCM_LEVEL); | 150 | wm8975_write(ROUT1VOL,0x100 | IPOD_PCM_LEVEL); |
156 | 151 | ||
157 | ipod_i2c_send(0x1a, 0x45, 0x50); /* Left out Mix(def) */ | 152 | wm8975_write(LOUTMIX1, 0x150); /* Left out Mix(def) */ |
158 | ipod_i2c_send(0x1a, 0x46, 0x50); | 153 | wm8975_write(LOUTMIX2, 0x50); |
159 | 154 | ||
160 | ipod_i2c_send(0x1a, 0x48, 0x50); /* Right out Mix(def) */ | 155 | wm8975_write(ROUTMIX1, 0x50); /* Right out Mix(def) */ |
161 | ipod_i2c_send(0x1a, 0x4b, 0x50); | 156 | wm8975_write(ROUTMIX2, 0x150); |
162 | 157 | ||
163 | ipod_i2c_send(0x1a, 0x4c, 0x0); /* Mono out Mix */ | 158 | wm8975_write(MOUTMIX1, 0x0); /* Mono out Mix */ |
164 | ipod_i2c_send(0x1a, 0x4e, 0x0); | 159 | wm8975_write(MOUTMIX2, 0x0); |
165 | 160 | ||
166 | wm8975_mute(0); | 161 | wm8975_mute(0); |
167 | } else { | 162 | } else { |
@@ -178,12 +173,12 @@ int wm8975_set_master_vol(int vol_l, int vol_r) | |||
178 | /* 0101111 == mute (0x2f) */ | 173 | /* 0101111 == mute (0x2f) */ |
179 | 174 | ||
180 | /* OUT1 */ | 175 | /* OUT1 */ |
181 | ipod_i2c_send(0x1a, LOUT1VOL, vol_l); | 176 | wm8975_write(LOUT1VOL, vol_l); |
182 | ipod_i2c_send(0x1a, ROUT1VOL | 0x1, vol_r); | 177 | wm8975_write(ROUT1VOL, 0x100 | vol_r); |
183 | 178 | ||
184 | /* OUT2 */ | 179 | /* OUT2 */ |
185 | ipod_i2c_send(0x1a, LOUT2VOL, vol_l); | 180 | wm8975_write(LOUT2VOL, vol_l); |
186 | ipod_i2c_send(0x1a, ROUT2VOL | 0x1, vol_r); | 181 | wm8975_write(ROUT2VOL, 0x100 | vol_r); |
187 | 182 | ||
188 | return 0; | 183 | return 0; |
189 | } | 184 | } |
@@ -203,7 +198,7 @@ void wm8975_set_bass(int value) | |||
203 | 198 | ||
204 | if ((value >= -6) && (value <= 9)) { | 199 | if ((value >= -6) && (value <= 9)) { |
205 | /* We use linear bass control with 130Hz cutoff */ | 200 | /* We use linear bass control with 130Hz cutoff */ |
206 | ipod_i2c_send(0x1a, 0x0c << 1, regvalues[value+6]); | 201 | wm8975_write(BASSCTRL, regvalues[value+6]); |
207 | } | 202 | } |
208 | } | 203 | } |
209 | 204 | ||
@@ -213,7 +208,7 @@ void wm8975_set_treble(int value) | |||
213 | 208 | ||
214 | if ((value >= -6) && (value <= 9)) { | 209 | if ((value >= -6) && (value <= 9)) { |
215 | /* We use a 8Khz cutoff */ | 210 | /* We use a 8Khz cutoff */ |
216 | ipod_i2c_send(0x1a, 0x0d << 1, regvalues[value+6]); | 211 | wm8975_write(TREBCTRL, regvalues[value+6]); |
217 | } | 212 | } |
218 | } | 213 | } |
219 | 214 | ||
@@ -222,10 +217,10 @@ int wm8975_mute(int mute) | |||
222 | if (mute) | 217 | if (mute) |
223 | { | 218 | { |
224 | /* Set DACMU = 1 to soft-mute the audio DACs. */ | 219 | /* Set DACMU = 1 to soft-mute the audio DACs. */ |
225 | ipod_i2c_send(0x1a, 0xa, 0x8); | 220 | wm8975_write(DACCTRL, 0x8); |
226 | } else { | 221 | } else { |
227 | /* Set DACMU = 0 to soft-un-mute the audio DACs. */ | 222 | /* Set DACMU = 0 to soft-un-mute the audio DACs. */ |
228 | ipod_i2c_send(0x1a, 0xa, 0x0); | 223 | wm8975_write(DACCTRL, 0x0); |
229 | } | 224 | } |
230 | 225 | ||
231 | return 0; | 226 | return 0; |
@@ -235,13 +230,13 @@ int wm8975_mute(int mute) | |||
235 | void wm8975_close(void) | 230 | void wm8975_close(void) |
236 | { | 231 | { |
237 | /* 1. Set DACMU = 1 to soft-mute the audio DACs. */ | 232 | /* 1. Set DACMU = 1 to soft-mute the audio DACs. */ |
238 | ipod_i2c_send(0x1a, 0xa, 0x8); | 233 | wm8975_write(DACCTRL, 0x8); |
239 | 234 | ||
240 | /* 2. Disable all output buffers. */ | 235 | /* 2. Disable all output buffers. */ |
241 | ipod_i2c_send(0x1a, 0x34, 0x0); /*Pwr Mgmt(2)*/ | 236 | wm8975_write(PWRMGMT2, 0x0); /*Pwr Mgmt(2)*/ |
242 | 237 | ||
243 | /* 3. Switch off the power supplies. */ | 238 | /* 3. Switch off the power supplies. */ |
244 | ipod_i2c_send(0x1a, 0x32, 0x0); /*Pwr Mgmt(1)*/ | 239 | wm8975_write(PWRMGMT1, 0x0); /*Pwr Mgmt(1)*/ |
245 | } | 240 | } |
246 | 241 | ||
247 | /* Change the order of the noise shaper, 5th order is recommended above 32kHz */ | 242 | /* Change the order of the noise shaper, 5th order is recommended above 32kHz */ |
@@ -253,7 +248,7 @@ void wm8975_set_nsorder(int order) | |||
253 | /* Note: Disable output before calling this function */ | 248 | /* Note: Disable output before calling this function */ |
254 | void wm8975_set_sample_rate(int sampling_control) { | 249 | void wm8975_set_sample_rate(int sampling_control) { |
255 | 250 | ||
256 | ipod_i2c_send(0x1a, 0x10, sampling_control); | 251 | wm8975_write(0x08, sampling_control); |
257 | 252 | ||
258 | } | 253 | } |
259 | 254 | ||
diff --git a/firmware/export/wm8975.h b/firmware/export/wm8975.h index c2dcee2a2c..1d63159748 100644 --- a/firmware/export/wm8975.h +++ b/firmware/export/wm8975.h | |||
@@ -37,6 +37,26 @@ extern void wm8975_disable_recording(void); | |||
37 | extern void wm8975_set_recvol(int left, int right, int type); | 37 | extern void wm8975_set_recvol(int left, int right, int type); |
38 | extern void wm8975_set_monitor(int enable); | 38 | extern void wm8975_set_monitor(int enable); |
39 | 39 | ||
40 | /* Register addresses */ | ||
41 | #define LOUT1VOL 0x02 | ||
42 | #define ROUT1VOL 0x03 | ||
43 | #define DACCTRL 0x05 | ||
44 | #define AINTFCE 0x07 | ||
45 | #define BASSCTRL 0x0c | ||
46 | #define TREBCTRL 0x0d | ||
47 | #define RESET 0x0f | ||
48 | #define PWRMGMT1 0x19 | ||
49 | #define PWRMGMT2 0x1a | ||
50 | #define LOUTMIX1 0x22 | ||
51 | #define LOUTMIX2 0x23 | ||
52 | #define ROUTMIX1 0x24 | ||
53 | #define ROUTMIX2 0x25 | ||
54 | #define MOUTMIX1 0x26 | ||
55 | #define MOUTMIX2 0x27 | ||
56 | #define LOUT2VOL 0x28 | ||
57 | #define ROUT2VOL 0x29 | ||
58 | |||
59 | |||
40 | /* Register settings for the supported samplerates: */ | 60 | /* Register settings for the supported samplerates: */ |
41 | #define WM8975_8000HZ 0x4d | 61 | #define WM8975_8000HZ 0x4d |
42 | #define WM8975_12000HZ 0x61 | 62 | #define WM8975_12000HZ 0x61 |