1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Driver for AS3514 audio codec
12 * Copyright (c) 2007 Daniel Ankers
13 * Copyright (c) 2007 Christian Gmeiner
15 * All files in this archive are subject to the GNU General Public License.
16 * See the file COPYING in the source tree root for full license agreement.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ****************************************************************************/
32 const struct sound_settings_info audiohw_settings
[] = {
33 [SOUND_VOLUME
] = {"dB", 0, 1, -74, 6, -25},
34 /* HAVE_SW_TONE_CONTROLS */
35 [SOUND_BASS
] = {"dB", 0, 1, -24, 24, 0},
36 [SOUND_TREBLE
] = {"dB", 0, 1, -24, 24, 0},
37 [SOUND_BALANCE
] = {"%", 0, 1,-100, 100, 0},
38 [SOUND_CHANNELS
] = {"", 0, 1, 0, 5, 0},
39 [SOUND_STEREO_WIDTH
] = {"%", 0, 5, 0, 250, 100},
40 #if defined(HAVE_RECORDING)
41 [SOUND_MIC_GAIN
] = {"dB", 1, 1, 0, 39, 23},
42 [SOUND_LEFT_GAIN
] = {"dB", 1, 1, 0, 31, 23},
43 [SOUND_RIGHT_GAIN
] = {"dB", 1, 1, 0, 31, 23},
47 /* Shadow registers */
48 static struct as3514_info
50 int vol_r
; /* Cached volume level (R) */
51 int vol_l
; /* Cached volume level (L) */
52 unsigned int regs
[0x1e]; /* last audio register: PLLMODE 0x1d */
60 SOURCE_LINE_IN1_ANALOG
63 static unsigned int source
= SOURCE_DAC
;
66 * little helper method to set register values.
67 * With the help of as3514.regs, we minimize i2c
70 static void as3514_write(unsigned int reg
, unsigned int value
)
72 if (pp_i2c_send(AS3514_I2C_ADDR
, reg
, value
) != 2)
74 DEBUGF("as3514 error reg=0x%02x", reg
);
77 if (reg
< ARRAYLEN(as3514
.regs
))
79 as3514
.regs
[reg
] = value
;
83 DEBUGF("as3514 error reg=0x%02x", reg
);
87 /* Helpers to set/clear bits */
88 static void as3514_write_or(unsigned int reg
, unsigned int bits
)
90 as3514_write(reg
, as3514
.regs
[reg
] | bits
);
93 static void as3514_write_and(unsigned int reg
, unsigned int bits
)
95 as3514_write(reg
, as3514
.regs
[reg
] & bits
);
98 /* convert tenth of dB volume to master volume register value */
99 int tenthdb2master(int db
)
101 /* +6 to -73.5dB in 1.5dB steps == 53 levels */
102 if (db
< VOLUME_MIN
) {
104 } else if (db
>= VOLUME_MAX
) {
107 return((db
-VOLUME_MIN
)/15); /* VOLUME_MIN is negative */
111 int sound_val2phys(int setting
, int value
)
117 #if defined(HAVE_RECORDING)
118 case SOUND_LEFT_GAIN
:
119 case SOUND_RIGHT_GAIN
:
121 result
= (value
- 23) * 15;
134 * Initialise the PP I2C and I2S.
136 void audiohw_init(void)
140 /* normal outputs for CDI and I2S pin groups */
144 DEV_INIT1
&=~0x3000000;
151 /* I2S device reset */
155 /* I2S device enable */
158 /* enable external dev clock clocks */
159 DEV_EN
|= DEV_EXTCLOCKS
;
161 /* external dev clock to 24MHz */
162 outl(inl(0x70000018) & ~0xc, 0x70000018);
166 /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */
168 /* Turn on SUM, DAC */
169 as3514_write(AS3514_AUDIOSET1
, (1 << 6) | (1 << 5));
171 /* Set BIAS on, DITH on, AGC on, IBR_DAC max, LSP_LP on, IBR_LSP min */
172 as3514_write(AS3514_AUDIOSET2
, (1 << 2) | (3 << 0));
174 /* Set HPCM off, ZCU off*/
175 as3514_write(AS3514_AUDIOSET3
, (1 << 2) | (1 << 0));
177 /* Mute and disable speaker */
178 as3514_write(AS3514_LSP_OUT_R
, 0);
179 as3514_write(AS3514_LSP_OUT_L
, (1 << 7));
181 /* set vol and set headphone over-current to 0 */
182 as3514_write(AS3514_HPH_OUT_R
, (0x3 << 6) | 0x16);
183 /* set default vol for headphone */
184 as3514_write(AS3514_HPH_OUT_L
, 0x16);
187 as3514_write(AS3514_PLLMODE
, 0x00);
190 as3514_write_or(AS3514_DAC_L
, (1 << 6));
193 as3514_write_or(AS3514_MIC1_L
, (1 << 7));
195 as3514_write_or(AS3514_MIC2_L
, (1 << 7));
197 /* read all reg values */
198 for (i
= 0; i
< ARRAYLEN(as3514
.regs
); i
++)
200 as3514
.regs
[i
] = i2c_readbyte(AS3514_I2C_ADDR
, i
);
204 void audiohw_postinit(void)
208 /* Silently enable / disable audio output */
209 void audiohw_enable_output(bool enable
)
212 /* reset the I2S controller into known state */
215 as3514_write_or(AS3514_HPH_OUT_L
, (1 << 6)); /* power on */
219 as3514_write_and(AS3514_HPH_OUT_L
, ~(1 << 6)); /* power off */
223 void audiohw_set_master_vol(int vol_l
, int vol_r
)
225 unsigned int hph_r
= as3514
.regs
[AS3514_HPH_OUT_R
] & ~0x1f;
226 unsigned int hph_l
= as3514
.regs
[AS3514_HPH_OUT_L
] & ~0x1f;
227 unsigned int mix_l
, mix_r
;
228 unsigned int mix_reg_r
, mix_reg_l
;
230 /* keep track of current setting */
231 as3514
.vol_l
= vol_l
;
232 as3514
.vol_r
= vol_r
;
234 if (source
== SOURCE_LINE_IN1_ANALOG
) {
235 mix_reg_r
= AS3514_LINE_IN1_R
;
236 mix_reg_l
= AS3514_LINE_IN1_L
;
238 mix_reg_r
= AS3514_DAC_R
;
239 mix_reg_l
= AS3514_DAC_L
;
242 mix_r
= as3514
.regs
[mix_reg_r
] & ~0x1f;
243 mix_l
= as3514
.regs
[mix_reg_l
] & ~0x1f;
245 /* we combine the mixer channel volume range with the headphone volume
252 hph_r
+= vol_r
- 0x16;
260 hph_l
+= vol_l
- 0x16;
263 as3514_write(mix_reg_r
, mix_r
);
264 as3514_write(mix_reg_l
, mix_l
);
265 as3514_write(AS3514_HPH_OUT_R
, hph_r
);
266 as3514_write(AS3514_HPH_OUT_L
, hph_l
);
269 void audiohw_set_lineout_vol(int vol_l
, int vol_r
)
271 as3514_write(AS3514_LINE_OUT_R
, vol_r
);
272 as3514_write(AS3514_LINE_OUT_L
, (1 << 6) | vol_l
);
275 void audiohw_mute(bool mute
)
278 as3514_write_or(AS3514_HPH_OUT_L
, (1 << 7));
280 as3514_write_and(AS3514_HPH_OUT_L
, ~(1 << 7));
284 /* Nice shutdown of AS3514 audio codec */
285 void audiohw_close(void)
287 /* mute headphones */
290 /* turn off everything */
291 as3514_write(AS3514_AUDIOSET1
, 0x0);
294 void audiohw_set_sample_rate(int sampling_control
)
296 (void)sampling_control
;
299 #if defined(HAVE_RECORDING)
300 void audiohw_enable_recording(bool source_mic
)
303 source
= SOURCE_MIC1
;
305 /* Sync mixer volumes before switching inputs */
306 audiohw_set_master_vol(as3514
.vol_l
, as3514
.vol_r
);
308 /* ADCmux = Stereo Microphone */
309 as3514_write_and(AS3514_ADC_R
, ~(0x3 << 6));
310 /* MIC1_on, LIN1_off */
311 as3514_write(AS3514_AUDIOSET1
,
312 (as3514
.regs
[AS3514_AUDIOSET1
] & ~(1 << 2)) | (1 << 0));
314 as3514_write_and(AS3514_MIC1_R
, ~(1 << 7));
316 source
= SOURCE_LINE_IN1
;
318 audiohw_set_master_vol(as3514
.vol_l
, as3514
.vol_r
);
320 /* ADCmux = Line_IN1 */
321 as3514_write(AS3514_ADC_R
,
322 (as3514
.regs
[AS3514_ADC_R
] & ~(0x3 << 6)) | (0x1 << 6));
323 /* MIC1_off, LIN1_on */
324 as3514_write(AS3514_AUDIOSET1
,
325 (as3514
.regs
[AS3514_AUDIOSET1
] & ~(1 << 0)) | (1 << 2));
329 as3514_write_or(AS3514_ADC_L
, (1 << 6));
331 as3514_write_or(AS3514_AUDIOSET1
, (1 << 7));
334 void audiohw_disable_recording(void)
339 as3514_write_and(AS3514_ADC_L
, ~(1 << 6));
341 /* ADC_off, LIN1_off, MIC_off */
342 as3514_write_and(AS3514_AUDIOSET1
, ~((1 << 7) | (1 << 2) | (1 << 0)));
344 audiohw_set_master_vol(as3514
.vol_l
, as3514
.vol_r
);
348 * Set recording volume
350 * Line in : 0 .. 23 .. 31 =>
351 Volume -34.5 .. +00.0 .. +12.0 dB
352 * Mic (left): 0 .. 23 .. 39 =>
353 * Volume -34.5 .. +00.0 .. +24.0 dB
356 void audiohw_set_recvol(int left
, int right
, int type
)
362 /* Combine MIC gains seamlessly with ADC levels */
363 unsigned int mic1_r
= as3514
.regs
[AS3514_MIC1_R
] & ~(0x3 << 5);
366 /* M1_Gain = +40db, ADR_Vol = +7.5dB .. +12.0 dB =>
367 +19.5 dB .. +24.0 dB */
369 mic1_r
|= (0x2 << 5);
370 } else if (left
>= 32) {
371 /* M1_Gain = +34db, ADR_Vol = +7.5dB .. +12.0 dB =>
372 +13.5 dB .. +18.0 dB */
374 mic1_r
|= (0x1 << 5);
376 /* M1_Gain = +28db, ADR_Vol = -34.5dB .. +12.0 dB =>
377 -34.5 dB .. +12.0 dB */
381 as3514_write(AS3514_MIC1_R
, mic1_r
);
384 case AUDIO_GAIN_LINEIN
:
390 as3514_write(AS3514_ADC_R
, (as3514
.regs
[AS3514_ADC_R
] & ~0x1f) | right
);
391 as3514_write(AS3514_ADC_L
, (as3514
.regs
[AS3514_ADC_L
] & ~0x1f) | left
);
395 * Enable line in 1 analog monitoring
398 void audiohw_set_monitor(bool enable
)
400 /* LI1R_Mute_on - default */
401 unsigned int line_in1_r
= as3514
.regs
[AS3514_LINE_IN1_R
] & ~(1 << 5);
402 /* LI1L_Mute_on - default */
403 unsigned int line_in1_l
= as3514
.regs
[AS3514_LINE_IN1_L
] & ~(1 << 5);
404 /* LIN1_off - default */
405 unsigned int audioset1
= as3514
.regs
[AS3514_AUDIOSET1
] & ~(1 << 2);
408 source
= SOURCE_LINE_IN1_ANALOG
;
411 line_in1_r
|= (1 << 5);
413 line_in1_l
|= (1 << 5);
415 audioset1
|= (1 << 2);
418 as3514_write(AS3514_AUDIOSET1
, audioset1
);
419 as3514_write(AS3514_LINE_IN1_R
, line_in1_r
);
420 as3514_write(AS3514_LINE_IN1_L
, line_in1_l
);
422 /* Sync mixer volume */
423 audiohw_set_master_vol(as3514
.vol_l
, as3514
.vol_r
);
425 #endif /* HAVE_RECORDING */