1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * All files in this archive are subject to the GNU General Public License.
11 * See the file COPYING in the source tree root for full license agreement.
13 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
14 * KIND, either express or implied.
16 ****************************************************************************/
26 /* Register addresses as per datasheet Rev.4.4 */
34 #define SRATECTRL 0x07
36 #define JACKDETECT0 0x09
40 #define JACKDETECT1 0x0d
50 #define EQ_GAIN_MASK 0x001f
51 #define EQ_CUTOFF_MASK 0x0060
52 #define EQ_GAIN_VALUE(x) (((-x) + 12) & 0x1f)
53 #define EQ_CUTOFF_VALUE(x) ((((x) - 1) & 0x03) << 5)
55 #define CLASSDCTL 0x17
56 #define DACLIMIT1 0x18
57 #define DACLIMIT2 0x19
65 #define NOISEGATE 0x23
70 #define THREEDCTL 0x29
74 #define LINPGAGAIN 0x2d
75 #define RINPGAGAIN 0x2e
76 #define LADCBOOST 0x2f
77 #define RADCBOOST 0x30
89 /* Register settings for the supported samplerates: */
90 #define WM8985_8000HZ 0x4d
91 #define WM8985_12000HZ 0x61
92 #define WM8985_16000HZ 0x55
93 #define WM8985_22050HZ 0x77
94 #define WM8985_24000HZ 0x79
95 #define WM8985_32000HZ 0x59
96 #define WM8985_44100HZ 0x63
97 #define WM8985_48000HZ 0x41
98 #define WM8985_88200HZ 0x7f
99 #define WM8985_96000HZ 0x5d
101 const struct sound_settings_info audiohw_settings
[] = {
102 [SOUND_VOLUME
] = {"dB", 0, 1, -58, 6, -25},
103 [SOUND_BASS
] = {"dB", 0, 1, -12, 12, 0},
104 [SOUND_TREBLE
] = {"dB", 0, 1, -12, 12, 0},
105 [SOUND_BALANCE
] = {"%", 0, 1,-100, 100, 0},
106 [SOUND_CHANNELS
] = {"", 0, 1, 0, 5, 0},
107 [SOUND_STEREO_WIDTH
] = {"%", 0, 5, 0, 250, 100},
108 [SOUND_LEFT_GAIN
] = {"dB", 1, 1,-128, 96, 0},
109 [SOUND_RIGHT_GAIN
] = {"dB", 1, 1,-128, 96, 0},
110 [SOUND_MIC_GAIN
] = {"dB", 1, 1,-128, 108, 16},
111 [SOUND_BASS_CUTOFF
] = {"", 0, 1, 1, 4, 1},
112 [SOUND_TREBLE_CUTOFF
] = {"", 0, 1, 1, 4, 1},
115 /* shadow registers */
116 unsigned int eq1_reg
;
117 unsigned int eq5_reg
;
119 /* convert tenth of dB volume (-57..6) to master volume register value */
120 int tenthdb2master(int db
)
122 /* +6 to -57dB in 1dB steps == 64 levels = 6 bits */
123 /* 0111111 == +6dB (0x3f) = 63) */
124 /* 0111001 == 0dB (0x39) = 57) */
125 /* 0000001 == -56dB (0x01) = */
126 /* 0000000 == -57dB (0x00) */
128 /* 1000000 == Mute (0x40) */
130 if (db
< VOLUME_MIN
) {
137 /* convert tenth of dB volume (-780..0) to mixer volume register value */
138 int tenthdb2mixer(int db
)
140 if (db
< -660) /* 1.5 dB steps */
141 return (2640 - db
) / 15;
142 else if (db
< -600) /* 0.75 dB steps */
143 return (990 - db
) * 2 / 15;
144 else if (db
< -460) /* 0.5 dB steps */
145 return (460 - db
) / 5;
146 else /* 0.25 dB steps */
150 /* Silently enable / disable audio output */
151 void audiohw_enable_output(bool enable
)
155 /* TODO: reset the I2S controller into known state */
158 /* TODO: Review the power-up sequence to prevent pops (see datasheet) */
160 wmcodec_write(RESET
, 0x1ff); /*Reset*/
162 wmcodec_write(PWRMGMT1
, 0x2b);
163 wmcodec_write(PWRMGMT2
, 0x180);
164 wmcodec_write(PWRMGMT3
, 0x6f);
166 wmcodec_write(AINTFCE
, 0x10);
167 wmcodec_write(CLKCTRL
, 0x49);
169 wmcodec_write(OUTCTRL
, 1);
171 /* The iPod can handle multiple frequencies, but fix at 44.1KHz
173 audiohw_set_sample_rate(WM8985_44100HZ
);
175 wmcodec_write(LOUTMIX
,0x1); /* Enable mixer */
176 wmcodec_write(ROUTMIX
,0x1); /* Enable mixer */
183 void audiohw_set_master_vol(int vol_l
, int vol_r
)
186 wmcodec_write(LOUT1VOL
, 0x080 | vol_l
);
187 wmcodec_write(ROUT1VOL
, 0x180 | vol_r
);
190 void audiohw_set_lineout_vol(int vol_l
, int vol_r
)
193 wmcodec_write(LOUT2VOL
, vol_l
);
194 wmcodec_write(ROUT2VOL
, 0x100 | vol_r
);
197 void audiohw_set_mixer_vol(int channel1
, int channel2
)
203 void audiohw_set_bass(int value
)
205 eq1_reg
= (eq1_reg
& ~EQ_GAIN_MASK
) | EQ_GAIN_VALUE(value
);
206 wmcodec_write(EQ1
, 0x100 | eq1_reg
);
209 void audiohw_set_bass_cutoff(int value
)
211 eq1_reg
= (eq1_reg
& ~EQ_CUTOFF_MASK
) | EQ_CUTOFF_VALUE(value
);
212 wmcodec_write(EQ1
, 0x100 | eq1_reg
);
215 void audiohw_set_treble(int value
)
217 eq5_reg
= (eq5_reg
& ~EQ_GAIN_MASK
) | EQ_GAIN_VALUE(value
);
218 wmcodec_write(EQ5
, eq5_reg
);
221 void audiohw_set_treble_cutoff(int value
)
223 eq5_reg
= (eq5_reg
& ~EQ_CUTOFF_MASK
) | EQ_CUTOFF_VALUE(value
);
224 wmcodec_write(EQ5
, eq5_reg
);
227 void audiohw_mute(bool mute
)
231 /* Set DACMU = 1 to soft-mute the audio DACs. */
232 wmcodec_write(DACCTRL
, 0x40);
234 /* Set DACMU = 0 to soft-un-mute the audio DACs. */
235 wmcodec_write(DACCTRL
, 0x0);
239 /* Nice shutdown of WM8758 codec */
240 void audiohw_close(void)
244 wmcodec_write(PWRMGMT3
, 0x0);
246 wmcodec_write(PWRMGMT1
, 0x0);
248 wmcodec_write(PWRMGMT2
, 0x40);
251 /* Change the order of the noise shaper, 5th order is recommended above 32kHz */
252 void audiohw_set_nsorder(int order
)
257 /* Note: Disable output before calling this function */
258 void audiohw_set_sample_rate(int sampling_control
)
260 /**** We force 44.1KHz for now. ****/
261 (void)sampling_control
;
264 wmcodec_write(CLKCTRL
, 1 | (0 << 2) | (2 << 5));
266 /* setup PLL for MHZ=11.2896 */
267 wmcodec_write(PLLN
, (1 << 4) | 0x7);
268 wmcodec_write(PLLK1
, 0x21);
269 wmcodec_write(PLLK2
, 0x161);
270 wmcodec_write(PLLK3
, 0x26);
273 wmcodec_write(CLKCTRL
, 1 | (1 << 2) | (2 << 5) | (1 << 8));
276 wmcodec_write(SRATECTRL
, (0 << 1));
279 #ifdef HAVE_RECORDING
280 void audiohw_enable_recording(bool source_mic
)
282 (void)source_mic
; /* We only have a line-in (I think) */
284 /* TODO: reset the I2S controller into known state */
287 wmcodec_write(RESET
, 0x1ff); /*Reset*/
289 wmcodec_write(PWRMGMT1
, 0x2b);
290 wmcodec_write(PWRMGMT2
, 0x18f); /* Enable ADC - 0x0c enables left/right PGA input, and 0x03 turns on power to the ADCs */
291 wmcodec_write(PWRMGMT3
, 0x6f);
293 wmcodec_write(AINTFCE
, 0x10);
294 wmcodec_write(CLKCTRL
, 0x49);
296 wmcodec_write(OUTCTRL
, 1);
298 /* The iPod can handle multiple frequencies, but fix at 44.1KHz
300 audiohw_set_sample_rate(WM8985_44100HZ
);
302 wmcodec_write(INCTRL
,0x44); /* Connect L2 and R2 inputs */
304 /* Set L2/R2_2BOOSTVOL to 0db (bits 4-6) */
314 wmcodec_write(LADCBOOST
,0x50);
315 wmcodec_write(RADCBOOST
,0x50);
317 /* Set L/R input PGA Volume to 0db */
318 // wm8758_write(LINPGAVOL,0x3f);
319 // wm8758_write(RINPGAVOL,0x13f);
321 /* Enable monitoring */
322 wmcodec_write(LOUTMIX
,0x17); /* Enable output mixer - BYPL2LMIX @ 0db*/
323 wmcodec_write(ROUTMIX
,0x17); /* Enable output mixer - BYPR2RMIX @ 0db*/
328 void audiohw_disable_recording(void) {
331 wmcodec_write(PWRMGMT3
, 0x0);
333 wmcodec_write(PWRMGMT1
, 0x0);
335 wmcodec_write(PWRMGMT2
, 0x40);
338 void audiohw_set_recvol(int left
, int right
, int type
) {
345 void audiohw_set_monitor(bool enable
) {
349 #endif /* HAVE_RECORDING */