summaryrefslogtreecommitdiff
path: root/firmware/drivers/wm8758.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/drivers/wm8758.c')
-rw-r--r--firmware/drivers/wm8758.c128
1 files changed, 33 insertions, 95 deletions
diff --git a/firmware/drivers/wm8758.c b/firmware/drivers/wm8758.c
index 33960af9b4..bdc9c8b450 100644
--- a/firmware/drivers/wm8758.c
+++ b/firmware/drivers/wm8758.c
@@ -37,9 +37,8 @@
37#include "buffer.h" 37#include "buffer.h"
38#include "audio.h" 38#include "audio.h"
39 39
40#include "i2c-pp5020.h" 40#include "wmcodec.h"
41#include "wm8758.h" 41#include "wm8758.h"
42#include "pcf50605.h"
43 42
44void wmcodec_reset(void); 43void wmcodec_reset(void);
45 44
@@ -48,67 +47,6 @@ void wmcodec_reset(void);
48//#define BASSCTRL 0x 47//#define BASSCTRL 0x
49//#define TREBCTRL 0x0b 48//#define TREBCTRL 0x0b
50 49
51/*
52 * Reset the I2S BIT.FORMAT I2S, 16bit, FIFO.FORMAT 32bit
53 */
54static void i2s_reset(void)
55{
56 /* PP502x */
57
58 /* I2S soft reset */
59 outl(inl(0x70002800) | 0x80000000, 0x70002800);
60 outl(inl(0x70002800) & ~0x80000000, 0x70002800);
61
62 /* BIT.FORMAT [11:10] = I2S (default) */
63 outl(inl(0x70002800) & ~0xc00, 0x70002800);
64 /* BIT.SIZE [9:8] = 16bit (default) */
65 outl(inl(0x70002800) & ~0x300, 0x70002800);
66
67 /* FIFO.FORMAT [6:4] = 32 bit LSB */
68 /* since BIT.SIZ < FIFO.FORMAT low 16 bits will be 0 */
69 outl(inl(0x70002800) | 0x30, 0x70002800);
70
71 /* RX_ATN_LVL=1 == when 12 slots full */
72 /* TX_ATN_LVL=1 == when 12 slots empty */
73 outl(inl(0x7000280c) | 0x33, 0x7000280c);
74
75 /* Rx.CLR = 1, TX.CLR = 1 */
76 outl(inl(0x7000280c) | 0x1100, 0x7000280c);
77}
78
79void wm8758_write(int reg, int data)
80{
81 ipod_i2c_send(0x1a, (reg<<1) | ((data&0x100)>>8),data&0xff);
82}
83
84/*
85 * Initialise the WM8758 for playback via headphone and line out.
86 * Note, I'm using the WM8750 datasheet as its apparently close.
87 */
88int wmcodec_init(void) {
89 /* normal outputs for CDI and I2S pin groups */
90 outl(inl(0x70000020) & ~0x300, 0x70000020);
91
92 /*mini2?*/
93 outl(inl(0x70000010) & ~0x3000000, 0x70000010);
94 /*mini2?*/
95
96 /* device reset */
97 outl(inl(0x60006004) | 0x800, 0x60006004);
98 outl(inl(0x60006004) & ~0x800, 0x60006004);
99
100 /* device enable */
101 outl(inl(0x6000600C) | 0x807, 0x6000600C);
102
103 /* enable external dev clock clocks */
104 outl(inl(0x6000600c) | 0x2, 0x6000600c);
105
106 /* external dev clock to 24MHz */
107 outl(inl(0x70000018) & ~0xc, 0x70000018);
108
109 return 0;
110}
111
112/* Silently enable / disable audio output */ 50/* Silently enable / disable audio output */
113void wmcodec_enable_output(bool enable) 51void wmcodec_enable_output(bool enable)
114{ 52{
@@ -119,23 +57,23 @@ void wmcodec_enable_output(bool enable)
119 57
120 /* TODO: Review the power-up sequence to prevent pops */ 58 /* TODO: Review the power-up sequence to prevent pops */
121 59
122 wm8758_write(RESET, 0x1ff); /*Reset*/ 60 wmcodec_write(RESET, 0x1ff); /*Reset*/
123 61
124 wm8758_write(PWRMGMT1, 0x2b); 62 wmcodec_write(PWRMGMT1, 0x2b);
125 wm8758_write(PWRMGMT2, 0x180); 63 wmcodec_write(PWRMGMT2, 0x180);
126 wm8758_write(PWRMGMT3, 0x6f); 64 wmcodec_write(PWRMGMT3, 0x6f);
127 65
128 wm8758_write(AINTFCE, 0x10); 66 wmcodec_write(AINTFCE, 0x10);
129 wm8758_write(CLKCTRL, 0x49); 67 wmcodec_write(CLKCTRL, 0x49);
130 68
131 wm8758_write(OUTCTRL, 1); 69 wmcodec_write(OUTCTRL, 1);
132 70
133 /* The iPod can handle multiple frequencies, but fix at 44.1KHz 71 /* The iPod can handle multiple frequencies, but fix at 44.1KHz
134 for now */ 72 for now */
135 wmcodec_set_sample_rate(WM8758_44100HZ); 73 wmcodec_set_sample_rate(WM8758_44100HZ);
136 74
137 wm8758_write(LOUTMIX,0x1); /* Enable mixer */ 75 wmcodec_write(LOUTMIX,0x1); /* Enable mixer */
138 wm8758_write(ROUTMIX,0x1); /* Enable mixer */ 76 wmcodec_write(ROUTMIX,0x1); /* Enable mixer */
139 wmcodec_mute(0); 77 wmcodec_mute(0);
140 } else { 78 } else {
141 wmcodec_mute(1); 79 wmcodec_mute(1);
@@ -145,8 +83,8 @@ void wmcodec_enable_output(bool enable)
145int wmcodec_set_master_vol(int vol_l, int vol_r) 83int wmcodec_set_master_vol(int vol_l, int vol_r)
146{ 84{
147 /* OUT1 */ 85 /* OUT1 */
148 wm8758_write(LOUT1VOL, 0x080 | vol_l); 86 wmcodec_write(LOUT1VOL, 0x080 | vol_l);
149 wm8758_write(ROUT1VOL, 0x180 | vol_r); 87 wmcodec_write(ROUT1VOL, 0x180 | vol_r);
150 88
151 return 0; 89 return 0;
152} 90}
@@ -154,8 +92,8 @@ int wmcodec_set_master_vol(int vol_l, int vol_r)
154int wmcodec_set_lineout_vol(int vol_l, int vol_r) 92int wmcodec_set_lineout_vol(int vol_l, int vol_r)
155{ 93{
156 /* OUT2 */ 94 /* OUT2 */
157 wm8758_write(LOUT2VOL, vol_l); 95 wmcodec_write(LOUT2VOL, vol_l);
158 wm8758_write(ROUT2VOL, 0x100 | vol_r); 96 wmcodec_write(ROUT2VOL, 0x100 | vol_r);
159 97
160 return 0; 98 return 0;
161} 99}
@@ -178,7 +116,7 @@ void wmcodec_set_bass(int value)
178 116
179 if ((value >= -6) && (value <= 9)) { 117 if ((value >= -6) && (value <= 9)) {
180 /* We use linear bass control with 130Hz cutoff */ 118 /* We use linear bass control with 130Hz cutoff */
181 wm8758_write(BASSCTRL, regvalues[value+6]); 119 wmcodec_write(BASSCTRL, regvalues[value+6]);
182 } 120 }
183#endif 121#endif
184} 122}
@@ -192,7 +130,7 @@ void wmcodec_set_treble(int value)
192 130
193 if ((value >= -6) && (value <= 9)) { 131 if ((value >= -6) && (value <= 9)) {
194 /* We use a 8Khz cutoff */ 132 /* We use a 8Khz cutoff */
195 wm8758_write(TREBCTRL, regvalues[value+6]); 133 wmcodec_write(TREBCTRL, regvalues[value+6]);
196 } 134 }
197#endif 135#endif
198 136
@@ -203,10 +141,10 @@ int wmcodec_mute(int mute)
203 if (mute) 141 if (mute)
204 { 142 {
205 /* Set DACMU = 1 to soft-mute the audio DACs. */ 143 /* Set DACMU = 1 to soft-mute the audio DACs. */
206 wm8758_write(DACCTRL, 0x40); 144 wmcodec_write(DACCTRL, 0x40);
207 } else { 145 } else {
208 /* Set DACMU = 0 to soft-un-mute the audio DACs. */ 146 /* Set DACMU = 0 to soft-un-mute the audio DACs. */
209 wm8758_write(DACCTRL, 0x0); 147 wmcodec_write(DACCTRL, 0x0);
210 } 148 }
211 149
212 return 0; 150 return 0;
@@ -217,11 +155,11 @@ void wmcodec_close(void)
217{ 155{
218 wmcodec_mute(1); 156 wmcodec_mute(1);
219 157
220 wm8758_write(PWRMGMT3, 0x0); 158 wmcodec_write(PWRMGMT3, 0x0);
221 159
222 wm8758_write(PWRMGMT1, 0x0); 160 wmcodec_write(PWRMGMT1, 0x0);
223 161
224 wm8758_write(PWRMGMT2, 0x40); 162 wmcodec_write(PWRMGMT2, 0x40);
225} 163}
226 164
227/* Change the order of the noise shaper, 5th order is recommended above 32kHz */ 165/* Change the order of the noise shaper, 5th order is recommended above 32kHz */
@@ -237,19 +175,19 @@ void wmcodec_set_sample_rate(int sampling_control)
237 (void)sampling_control; 175 (void)sampling_control;
238 176
239 /* set clock div */ 177 /* set clock div */
240 wm8758_write(CLKCTRL, 1 | (0 << 2) | (2 << 5)); 178 wmcodec_write(CLKCTRL, 1 | (0 << 2) | (2 << 5));
241 179
242 /* setup PLL for MHZ=11.2896 */ 180 /* setup PLL for MHZ=11.2896 */
243 wm8758_write(PLLN, (1 << 4) | 0x7); 181 wmcodec_write(PLLN, (1 << 4) | 0x7);
244 wm8758_write(PLLK1, 0x21); 182 wmcodec_write(PLLK1, 0x21);
245 wm8758_write(PLLK2, 0x161); 183 wmcodec_write(PLLK2, 0x161);
246 wm8758_write(PLLK3, 0x26); 184 wmcodec_write(PLLK3, 0x26);
247 185
248 /* set clock div */ 186 /* set clock div */
249 wm8758_write(CLKCTRL, 1 | (1 << 2) | (2 << 5) | (1 << 8)); 187 wmcodec_write(CLKCTRL, 1 | (1 << 2) | (2 << 5) | (1 << 8));
250 188
251 /* set srate */ 189 /* set srate */
252 wm8758_write(SRATECTRL, (0 << 1)); 190 wmcodec_write(SRATECTRL, (0 << 1));
253} 191}
254 192
255void wmcodec_enable_recording(bool source_mic) 193void wmcodec_enable_recording(bool source_mic)
@@ -286,14 +224,14 @@ void wmcodec_set_equalizer_band(int band, int freq, int bw, int gain)
286 eq |= 12 - gain; 224 eq |= 12 - gain;
287 225
288 if (band == 0) { 226 if (band == 0) {
289 wm8758_write(EQ1, eq | 0x100); /* Always apply EQ to the DAC path */ 227 wmcodec_write(EQ1, eq | 0x100); /* Always apply EQ to the DAC path */
290 } else if (band == 1) { 228 } else if (band == 1) {
291 wm8758_write(EQ2, eq); 229 wmcodec_write(EQ2, eq);
292 } else if (band == 2) { 230 } else if (band == 2) {
293 wm8758_write(EQ3, eq); 231 wmcodec_write(EQ3, eq);
294 } else if (band == 3) { 232 } else if (band == 3) {
295 wm8758_write(EQ4, eq); 233 wmcodec_write(EQ4, eq);
296 } else if (band == 4) { 234 } else if (band == 4) {
297 wm8758_write(EQ5, eq); 235 wmcodec_write(EQ5, eq);
298 } 236 }
299} 237}