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 [SOUND_MIC_GAIN
] = {"dB", 1, 1, 0, 39, 23},
41 [SOUND_LEFT_GAIN
] = {"dB", 1, 1, 0, 31, 23},
42 [SOUND_RIGHT_GAIN
] = {"dB", 1, 1, 0, 31, 23},
45 /* Shadow registers */
46 static struct as3514_info
48 int vol_r
; /* Cached volume level (R) */
49 int vol_l
; /* Cached volume level (L) */
50 unsigned int regs
[0x1e]; /* last audio register: PLLMODE 0x1d */
58 SOURCE_LINE_IN1_ANALOG
61 static unsigned int source
= SOURCE_DAC
;
64 * little helper method to set register values.
65 * With the help of as3514.regs, we minimize i2c
68 static void as3514_write(unsigned int reg
, unsigned int value
)
70 if (pp_i2c_send(AS3514_I2C_ADDR
, reg
, value
) != 2)
72 DEBUGF("as3514 error reg=0x%02x", reg
);
75 if (reg
< ARRAYLEN(as3514
.regs
))
77 as3514
.regs
[reg
] = value
;
81 DEBUGF("as3514 error reg=0x%02x", reg
);
85 /* Helpers to set/clear bits */
86 static void as3514_write_or(unsigned int reg
, unsigned int bits
)
88 as3514_write(reg
, as3514
.regs
[reg
] | bits
);
91 static void as3514_write_and(unsigned int reg
, unsigned int bits
)
93 as3514_write(reg
, as3514
.regs
[reg
] & bits
);
96 /* convert tenth of dB volume to master volume register value */
97 int tenthdb2master(int db
)
99 /* +6 to -73.5dB in 1.5dB steps == 53 levels */
100 if (db
< VOLUME_MIN
) {
102 } else if (db
>= VOLUME_MAX
) {
105 return((db
-VOLUME_MIN
)/15); /* VOLUME_MIN is negative */
109 int sound_val2phys(int setting
, int value
)
115 case SOUND_LEFT_GAIN
:
116 case SOUND_RIGHT_GAIN
:
118 result
= (value
- 23) * 15;
130 * Initialise the PP I2C and I2S.
132 void audiohw_init(void)
136 /* normal outputs for CDI and I2S pin groups */
140 DEV_INIT1
&=~0x3000000;
147 /* I2S device reset */
151 /* I2S device enable */
154 /* enable external dev clock clocks */
155 DEV_EN
|= DEV_EXTCLOCKS
;
157 /* external dev clock to 24MHz */
158 outl(inl(0x70000018) & ~0xc, 0x70000018);
162 /* Set ADC off, mixer on, DAC on, line out off, line in off, mic off */
164 /* Turn on SUM, DAC */
165 as3514_write(AS3514_AUDIOSET1
, (1 << 6) | (1 << 5));
167 /* Set BIAS on, DITH on, AGC on, IBR_DAC max, LSP_LP on, IBR_LSP min */
168 as3514_write(AS3514_AUDIOSET2
, (1 << 2) | (3 << 0));
170 /* Set HPCM off, ZCU off*/
171 as3514_write(AS3514_AUDIOSET3
, (1 << 2) | (1 << 0));
173 /* Mute and disable speaker */
174 as3514_write(AS3514_LSP_OUT_R
, 0);
175 as3514_write(AS3514_LSP_OUT_L
, (1 << 7));
177 /* set vol and set headphone over-current to 0 */
178 as3514_write(AS3514_HPH_OUT_R
, (0x3 << 6) | 0x16);
179 /* set default vol for headphone */
180 as3514_write(AS3514_HPH_OUT_L
, 0x16);
183 as3514_write(AS3514_PLLMODE
, 0x00);
186 as3514_write_or(AS3514_DAC_L
, (1 << 6));
189 as3514_write_or(AS3514_MIC1_L
, (1 << 7));
191 as3514_write_or(AS3514_MIC2_L
, (1 << 7));
193 /* read all reg values */
194 for (i
= 0; i
< ARRAYLEN(as3514
.regs
); i
++)
196 as3514
.regs
[i
] = i2c_readbyte(AS3514_I2C_ADDR
, i
);
200 void audiohw_postinit(void)
204 /* Silently enable / disable audio output */
205 void audiohw_enable_output(bool enable
)
208 /* reset the I2S controller into known state */
211 as3514_write_or(AS3514_HPH_OUT_L
, (1 << 6)); /* power on */
215 as3514_write_and(AS3514_HPH_OUT_L
, ~(1 << 6)); /* power off */
219 void audiohw_set_master_vol(int vol_l
, int vol_r
)
221 unsigned int hph_r
= as3514
.regs
[AS3514_HPH_OUT_R
] & ~0x1f;
222 unsigned int hph_l
= as3514
.regs
[AS3514_HPH_OUT_L
] & ~0x1f;
223 unsigned int mix_l
, mix_r
;
224 unsigned int mix_reg_r
, mix_reg_l
;
226 /* keep track of current setting */
227 as3514
.vol_l
= vol_l
;
228 as3514
.vol_r
= vol_r
;
230 if (source
== SOURCE_LINE_IN1_ANALOG
) {
231 mix_reg_r
= AS3514_LINE_IN1_R
;
232 mix_reg_l
= AS3514_LINE_IN1_L
;
234 mix_reg_r
= AS3514_DAC_R
;
235 mix_reg_l
= AS3514_DAC_L
;
238 mix_r
= as3514
.regs
[mix_reg_r
] & ~0x1f;
239 mix_l
= as3514
.regs
[mix_reg_l
] & ~0x1f;
241 /* we combine the mixer channel volume range with the headphone volume
248 hph_r
+= vol_r
- 0x16;
256 hph_l
+= vol_l
- 0x16;
259 as3514_write(mix_reg_r
, mix_r
);
260 as3514_write(mix_reg_l
, mix_l
);
261 as3514_write(AS3514_HPH_OUT_R
, hph_r
);
262 as3514_write(AS3514_HPH_OUT_L
, hph_l
);
265 void audiohw_set_lineout_vol(int vol_l
, int vol_r
)
267 as3514_write(AS3514_LINE_OUT_R
, vol_r
);
268 as3514_write(AS3514_LINE_OUT_L
, (1 << 6) | vol_l
);
271 void audiohw_mute(bool mute
)
274 as3514_write_or(AS3514_HPH_OUT_L
, (1 << 7));
276 as3514_write_and(AS3514_HPH_OUT_L
, ~(1 << 7));
280 /* Nice shutdown of WM8758 codec */
281 void audiohw_close(void)
283 /* mute headphones */
286 /* turn off everything */
287 as3514_write(AS3514_AUDIOSET1
, 0x0);
290 void audiohw_set_sample_rate(int sampling_control
)
292 (void)sampling_control
;
295 void audiohw_enable_recording(bool source_mic
)
298 source
= SOURCE_MIC1
;
300 /* Sync mixer volumes before switching inputs */
301 audiohw_set_master_vol(as3514
.vol_l
, as3514
.vol_r
);
303 /* ADCmux = Stereo Microphone */
304 as3514_write_and(AS3514_ADC_R
, ~(0x3 << 6));
305 /* MIC1_on, LIN1_off */
306 as3514_write(AS3514_AUDIOSET1
,
307 (as3514
.regs
[AS3514_AUDIOSET1
] & ~(1 << 2)) | (1 << 0));
309 as3514_write_and(AS3514_MIC1_R
, ~(1 << 7));
311 source
= SOURCE_LINE_IN1
;
313 audiohw_set_master_vol(as3514
.vol_l
, as3514
.vol_r
);
315 /* ADCmux = Line_IN1 */
316 as3514_write(AS3514_ADC_R
,
317 (as3514
.regs
[AS3514_ADC_R
] & ~(0x3 << 6)) | (0x1 << 6));
318 /* MIC1_off, LIN1_on */
319 as3514_write(AS3514_AUDIOSET1
,
320 (as3514
.regs
[AS3514_AUDIOSET1
] & ~(1 << 0)) | (1 << 2));
324 as3514_write_or(AS3514_ADC_L
, (1 << 6));
326 as3514_write_or(AS3514_AUDIOSET1
, (1 << 7));
329 void audiohw_disable_recording(void)
334 as3514_write_and(AS3514_ADC_L
, ~(1 << 6));
336 /* ADC_off, LIN1_off, MIC_off */
337 as3514_write_and(AS3514_AUDIOSET1
, ~((1 << 7) | (1 << 2) | (1 << 0)));
339 audiohw_set_master_vol(as3514
.vol_l
, as3514
.vol_r
);
343 * Set recording volume
345 * Line in : 0 .. 23 .. 31 =>
346 Volume -34.5 .. +00.0 .. +12.0 dB
347 * Mic (left): 0 .. 23 .. 39 =>
348 * Volume -34.5 .. +00.0 .. +24.0 dB
351 void audiohw_set_recvol(int left
, int right
, int type
)
357 /* Combine MIC gains seamlessly with ADC levels */
358 unsigned int mic1_r
= as3514
.regs
[AS3514_MIC1_R
] & ~(0x3 << 5);
361 /* M1_Gain = +40db, ADR_Vol = +7.5dB .. +12.0 dB =>
362 +19.5 dB .. +24.0 dB */
364 mic1_r
|= (0x2 << 5);
365 } else if (left
>= 32) {
366 /* M1_Gain = +34db, ADR_Vol = +7.5dB .. +12.0 dB =>
367 +13.5 dB .. +18.0 dB */
369 mic1_r
|= (0x1 << 5);
371 /* M1_Gain = +28db, ADR_Vol = -34.5dB .. +12.0 dB =>
372 -34.5 dB .. +12.0 dB */
376 as3514_write(AS3514_MIC1_R
, mic1_r
);
379 case AUDIO_GAIN_LINEIN
:
385 as3514_write(AS3514_ADC_R
, (as3514
.regs
[AS3514_ADC_R
] & ~0x1f) | right
);
386 as3514_write(AS3514_ADC_L
, (as3514
.regs
[AS3514_ADC_L
] & ~0x1f) | left
);
390 * Enable line in 1 analog monitoring
393 void audiohw_set_monitor(bool enable
)
395 /* LI1R_Mute_on - default */
396 unsigned int line_in1_r
= as3514
.regs
[AS3514_LINE_IN1_R
] & ~(1 << 5);
397 /* LI1L_Mute_on - default */
398 unsigned int line_in1_l
= as3514
.regs
[AS3514_LINE_IN1_L
] & ~(1 << 5);
399 /* LIN1_off - default */
400 unsigned int audioset1
= as3514
.regs
[AS3514_AUDIOSET1
] & ~(1 << 2);
403 source
= SOURCE_LINE_IN1_ANALOG
;
406 line_in1_r
|= (1 << 5);
408 line_in1_l
|= (1 << 5);
410 audioset1
|= (1 << 2);
413 as3514_write(AS3514_AUDIOSET1
, audioset1
);
414 as3514_write(AS3514_LINE_IN1_R
, line_in1_r
);
415 as3514_write(AS3514_LINE_IN1_L
, line_in1_l
);
417 /* Sync mixer volume */
418 audiohw_set_master_vol(as3514
.vol_l
, as3514
.vol_r
);