summaryrefslogtreecommitdiff
path: root/firmware/drivers/wm8731l.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/wm8731l.c')
-rw-r--r--firmware/drivers/wm8731l.c106
1 files changed, 54 insertions, 52 deletions
diff --git a/firmware/drivers/wm8731l.c b/firmware/drivers/wm8731l.c
index d49e8f4476..990ad0ebbc 100644
--- a/firmware/drivers/wm8731l.c
+++ b/firmware/drivers/wm8731l.c
@@ -41,40 +41,46 @@
41#include "wm8731l.h" 41#include "wm8731l.h"
42#include "pcf50605.h" 42#include "pcf50605.h"
43 43
44void wm8731l_reset(void);
45
46#define IPOD_PCM_LEVEL 0x65 /* -6dB */ 44#define IPOD_PCM_LEVEL 0x65 /* -6dB */
47 45
48#define RESET (0x0f<<1) 46#define LINVOL 0x00
49#define PWRMGMT1 (0x19<<1) 47#define RINVOL 0x01
50#define PWRMGMT2 (0x1a<<1) 48#define LOUTVOL 0x02
51#define AINTFCE (0x07<<1) 49#define ROUTVOL 0x03
52#define LOUT1VOL (0x02<<1) 50#define DACCTRL 0x05
53#define ROUT1VOL (0x03<<1) 51#define PWRMGMT 0x06
54#define LOUT2VOL (0x28<<1) 52#define AINTFCE 0x07
55#define ROUT2VOL (0x29<<1) 53#define SAMPCTRL 0x08
54#define ACTIVECTRL 0x09
55#define RESET 0x0f
56
57void wm8731_write(int reg, int data)
58{
59 ipod_i2c_send(0x1a, (reg<<1) | ((data&0x100)>>8),data&0xff);
60}
56 61
57int wm8731l_mute(int mute) 62int wmcodec_mute(int mute)
58{ 63{
59 if (mute) 64 if (mute)
60 { 65 {
61 /* Set DACMU = 1 to soft-mute the audio DACs. */ 66 /* Set DACMU = 1 to soft-mute the audio DACs. */
62 ipod_i2c_send(0x1a, 0xa, 0x8); 67 wm8731_write(DACCTRL, 0x8);
63 } else { 68 } else {
64 /* Set DACMU = 0 to soft-un-mute the audio DACs. */ 69 /* Set DACMU = 0 to soft-un-mute the audio DACs. */
65 ipod_i2c_send(0x1a, 0xa, 0x0); 70 wm8731_write(DACCTRL, 0x0);
66 } 71 }
67 72
68 return 0; 73 return 0;
69} 74}
75
70/** From ipodLinux **/ 76/** From ipodLinux **/
71static void codec_set_active(int active) 77static void codec_set_active(int active)
72{ 78{
73 /* set active to 0x0 or 0x1 */ 79 /* set active to 0x0 or 0x1 */
74 if (active) { 80 if (active) {
75 ipod_i2c_send(0x1a, 0x12, 0x01); 81 wm8731_write(ACTIVECTRL, 0x01);
76 } else { 82 } else {
77 ipod_i2c_send(0x1a, 0x12, 0x00); 83 wm8731_write(ACTIVECTRL, 0x00);
78 } 84 }
79} 85}
80 86
@@ -102,7 +108,7 @@ static void i2s_reset(void)
102 * Initialise the WM8975 for playback via headphone and line out. 108 * Initialise the WM8975 for playback via headphone and line out.
103 * Note, I'm using the WM8750 datasheet as its apparently close. 109 * Note, I'm using the WM8750 datasheet as its apparently close.
104 */ 110 */
105int wm8731l_init(void) { 111int wmcodec_init(void) {
106 /* reset I2C */ 112 /* reset I2C */
107 i2c_init(); 113 i2c_init();
108 114
@@ -134,64 +140,61 @@ int wm8731l_init(void) {
134} 140}
135 141
136/* Silently enable / disable audio output */ 142/* Silently enable / disable audio output */
137void wm8731l_enable_output(bool enable) 143void wmcodec_enable_output(bool enable)
138{ 144{
139 if (enable) 145 if (enable)
140 { 146 {
141 /* reset the I2S controller into known state */ 147 /* reset the I2S controller into known state */
142 i2s_reset(); 148 i2s_reset();
143 149
144 ipod_i2c_send(0x1a, 0x1e, 0x0); /*Reset*/ 150 wm8731_write(RESET, 0x0); /*Reset*/
145 151
146 codec_set_active(0x0); 152 codec_set_active(0x0);
147 153
148 /* DACSEL=1 */ 154 /* DACSEL=1 */
149 /* BYPASS=1 */ 155 /* BYPASS=1 */
150 ipod_i2c_send(0x1a, 0x8, 0x18); 156 wm8731_write(0x4, 0x18);
151 157
152 /* set power register to POWEROFF=0 on OUTPD=0, DACPD=0 */ 158 /* set power register to POWEROFF=0 on OUTPD=0, DACPD=0 */
153 ipod_i2c_send(0x1a, 0xc, 0x67); 159 wm8731_write(PWRMGMT, 0x67);
154 160
155 /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */ 161 /* BCLKINV=0(Dont invert BCLK) MS=1(Enable Master) LRSWAP=0 LRP=0 */
156 /* IWL=00(16 bit) FORMAT=10(I2S format) */ 162 /* IWL=00(16 bit) FORMAT=10(I2S format) */
157 ipod_i2c_send(0x1a, 0xe, 0x42); 163 wm8731_write(AINTFCE, 0x42);
158 164
159 wm8731l_set_sample_rate(WM8731L_44100HZ); 165 wmcodec_set_sample_rate(WM8731L_44100HZ);
160 166
161 /* set the volume to -6dB */ 167 /* set the volume to -6dB */
162 ipod_i2c_send(0x1a, 0x4, IPOD_PCM_LEVEL); 168 wm8731_write(LOUTVOL, IPOD_PCM_LEVEL);
163 ipod_i2c_send(0x1a, 0x6 | 0x1, IPOD_PCM_LEVEL); 169 wm8731_write(ROUTVOL, 0x100 | IPOD_PCM_LEVEL);
164 170
165 /* ACTIVE=1 */ 171 /* ACTIVE=1 */
166 codec_set_active(1); 172 codec_set_active(1);
167 173
168 /* 5. Set DACMU = 0 to soft-un-mute the audio DACs. */ 174 /* 5. Set DACMU = 0 to soft-un-mute the audio DACs. */
169 ipod_i2c_send(0x1a, 0xa, 0x0); 175 wm8731_write(DACCTRL, 0x0);
170 176
171 wm8731l_mute(0); 177 wmcodec_mute(0);
172 } else { 178 } else {
173 wm8731l_mute(1); 179 wmcodec_mute(1);
174 } 180 }
175} 181}
176 182
177int wm8731l_set_master_vol(int vol_l, int vol_r) 183int wmcodec_set_master_vol(int vol_l, int vol_r)
178{ 184{
179 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */ 185 /* +6 to -73dB 1dB steps (plus mute == 80levels) 7bits */
180 /* 1111111 == +6dB */ 186 /* 1111111 == +6dB */
181 /* 1111001 == 0dB */ 187 /* 1111001 == 0dB */
182 /* 0110000 == -73dB */ 188 /* 0110000 == -73dB */
183 /* 0101111 == mute (0x2f) */ 189 /* 0101111 == mute (0x2f) */
184 if (vol_l == vol_r) { 190
185 ipod_i2c_send(0x1a, 0x4 | 0x1, vol_l); 191 wm8731_write(LOUTVOL, vol_l);
186 } else { 192 wm8731_write(ROUTVOL, vol_r);
187 ipod_i2c_send(0x1a, 0x4, vol_l);
188 ipod_i2c_send(0x1a, 0x6, vol_r);
189 }
190 193
191 return 0; 194 return 0;
192} 195}
193 196
194int wm8975_set_mixer_vol(int channel1, int channel2) 197int wmcodec_set_mixer_vol(int channel1, int channel2)
195{ 198{
196 (void)channel1; 199 (void)channel1;
197 (void)channel2; 200 (void)channel2;
@@ -199,70 +202,69 @@ int wm8975_set_mixer_vol(int channel1, int channel2)
199 return 0; 202 return 0;
200} 203}
201 204
202void wm8731l_set_bass(int value) 205void wmcodec_set_bass(int value)
203{ 206{
204 (void)value; 207 (void)value;
205} 208}
206 209
207void wm8731l_set_treble(int value) 210void wmcodec_set_treble(int value)
208{ 211{
209 (void)value; 212 (void)value;
210} 213}
211 214
212/* Nice shutdown of WM8975 codec */ 215/* Nice shutdown of WM8731 codec */
213void wm8731l_close(void) 216void wmcodec_close(void)
214{ 217{
215 /* set DACMU=1 DEEMPH=0 */ 218 /* set DACMU=1 DEEMPH=0 */
216 ipod_i2c_send(0x1a, 0xa, 0x8); 219 wm8731_write(DACCTRL, 0x8);
217 220
218 /* ACTIVE=0 */ 221 /* ACTIVE=0 */
219 codec_set_active(0x0); 222 codec_set_active(0x0);
220 223
221 /* line in mute left & right*/ 224 /* line in mute left & right*/
222 ipod_i2c_send(0x1a, 0x0 | 0x1, 0x80); 225 wm8731_write(LINVOL, 0x100 | 0x80);
223 226
224 /* set DACSEL=0, MUTEMIC=1 */ 227 /* set DACSEL=0, MUTEMIC=1 */
225 ipod_i2c_send(0x1a, 0x8, 0x2); 228 wm8731_write(0x4, 0x2);
226 229
227 /* set POWEROFF=0 OUTPD=0 DACPD=1 */ 230 /* set POWEROFF=0 OUTPD=0 DACPD=1 */
228 ipod_i2c_send(0x1a, 0xc, 0x6f); 231 wm8731_write(PWRMGMT, 0x6f);
229 232
230 /* set POWEROFF=1 OUTPD=1 DACPD=1 */ 233 /* set POWEROFF=1 OUTPD=1 DACPD=1 */
231 ipod_i2c_send(0x1a, 0xc, 0xff); 234 wm8731_write(PWRMGMT, 0xff);
232} 235}
233 236
234/* Change the order of the noise shaper, 5th order is recommended above 32kHz */ 237/* Change the order of the noise shaper, 5th order is recommended above 32kHz */
235void wm8731l_set_nsorder(int order) 238void wmcodec_set_nsorder(int order)
236{ 239{
237 (void)order; 240 (void)order;
238} 241}
239 242
240/* */ 243void wmcodec_set_sample_rate(int sampling_control)
241void wm8731l_set_sample_rate(int sampling_control)
242{ 244{
243 codec_set_active(0x0); 245 codec_set_active(0x0);
244 ipod_i2c_send(0x1a, 0x10, sampling_control); 246 wm8731_write(SAMPCTRL, sampling_control);
245 codec_set_active(0x1); 247 codec_set_active(0x1);
246} 248}
247 249
248void wm8731l_enable_recording(bool source_mic) 250void wmcodec_enable_recording(bool source_mic)
249{ 251{
250 (void)source_mic; 252 (void)source_mic;
251} 253}
252 254
253void wm8731l_disable_recording(void) 255void wmcodec_disable_recording(void)
254{ 256{
255 257
256} 258}
257 259
258void wm8731l_set_recvol(int left, int right, int type) 260void wmcodec_set_recvol(int left, int right, int type)
259{ 261{
260 (void)left; 262 (void)left;
261 (void)right; 263 (void)right;
262 (void)type; 264 (void)type;
263} 265}
264 266
265void wm8731l_set_monitor(int enable) 267void wmcodec_set_monitor(int enable)
266{ 268{
267 (void)enable; 269 (void)enable;
268} 270}