1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (c) 2009 Mark Arigo
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 /*#define LOGF_ENABLE*/
28 #include "pcm_sampr.h"
34 const struct sound_settings_info audiohw_settings
[] = {
35 [SOUND_VOLUME
] = {"dB", 0, 1,-127, 0, -25},
36 /* HAVE_SW_TONE_CONTROLS */
37 [SOUND_BASS
] = {"dB", 0, 1, -24, 24, 0},
38 [SOUND_TREBLE
] = {"dB", 0, 1, -24, 24, 0},
39 [SOUND_BALANCE
] = {"%", 0, 1,-100, 100, 0},
40 [SOUND_CHANNELS
] = {"", 0, 1, 0, 5, 0},
41 [SOUND_STEREO_WIDTH
] = {"%", 0, 5, 0, 250, 100},
42 #if defined(HAVE_RECORDING)
43 [SOUND_LEFT_GAIN
] = {"dB", 1, 1, 0, 31, 23},
44 [SOUND_RIGHT_GAIN
] = {"dB", 1, 1, 0, 31, 23},
45 [SOUND_MIC_GAIN
] = {"dB", 1, 1, 0, 1, 0},
49 static unsigned char akc_regs
[AKC_NUM_REGS
];
51 static void akc_write(int reg
, unsigned val
)
53 if ((unsigned)reg
>= AKC_NUM_REGS
)
56 akc_regs
[reg
] = (unsigned char)val
;
57 akcodec_write(reg
, val
);
60 static void akc_set(int reg
, unsigned bits
)
62 akc_write(reg
, akc_regs
[reg
] | bits
);
65 static void akc_clear(int reg
, unsigned bits
)
67 akc_write(reg
, akc_regs
[reg
] & ~bits
);
70 static void akc_write_masked(int reg
, unsigned bits
, unsigned mask
)
72 akc_write(reg
, (akc_regs
[reg
] & ~mask
) | (bits
& mask
));
76 static void codec_set_active(int active
)
82 /* convert tenth of dB volume (-1270..0) to master volume register value */
83 int tenthdb2master(int db
)
86 return 0xff; /* mute */
87 else if (db
>= VOLUME_MAX
)
93 int sound_val2phys(int setting
, int value
)
100 case SOUND_LEFT_GAIN
:
101 case SOUND_RIGHT_GAIN
:
102 result
= (value
- 23) * 15; /* fix */
105 result
= value
* 200; /* fix */
116 /*static void audiohw_mute(bool mute)
120 akc_set(AK4537_DAC, SMUTE);
126 akc_clear(AK4537_DAC, SMUTE);
130 void audiohw_preinit(void)
133 for (i
= 0; i
< AKC_NUM_REGS
; i
++)
134 akc_regs
[i
] = akcodec_read(i
);
136 /* POWER UP SEQUENCE (from the datasheet) */
137 /* Note: the delay length is what the OF uses, although the datasheet
138 suggests they can be shorter */
141 akc_set(AK4537_PM1
, PMVCM
);
144 /* setup AK4537_SIGSEL1 */
145 akc_set(AK4537_SIGSEL1
, ALCS
| MOUT2
);
148 /* setup AK4537_SIGSEL2 */
149 akc_write_masked(AK4537_SIGSEL2
, DAHS
, (DAHS
| HPL
| HPR
));
152 /* setup AK4537_MODE1 */
153 akc_write_masked(AK4537_MODE1
, DIF_I2S
| BICK_32FS
| MCKI_PLL_12000KHZ
,
154 (DIF_MASK
| BICK_MASK
| MCKI_MASK
));
157 /* CLOCK SETUP - X'tal used in PLL mode (master mode) */
159 /* release the pull-down of the XTI pin and power-up the X'tal osc */
160 akc_write_masked(AK4537_PM2
, PMXTL
, (MCLKPD
| PMXTL
));
163 /* power-up the PLL */
164 akc_set(AK4537_PM2
, PMPLL
);
167 /* enable MCKO output and setup MCKO output freq */
168 akc_set(AK4537_MODE1
, MCKO_EN
);
171 /* ENABLE HEADPHONE AMP OUTPUT */
173 /* setup the sampling freq if PLL mode is used */
174 akc_write_masked(AK4537_MODE2
, AKC_PLL_44100HZ
, FS_MASK
);
176 /* setup the low freq boost level */
177 akc_write_masked(AK4537_DAC
, BST_OFF
, BST_MASK
);
179 /* setup the digital volume */
180 akc_write(AK4537_ATTL
, 0x10);
181 akc_write(AK4537_ATTR
, 0x10);
183 /* power up the DAC */
184 akc_set(AK4537_PM2
, PMDAC
);
187 /* power up the headphone amp */
188 akc_clear(AK4537_SIGSEL2
, HPL
| HPR
);
191 /* power up the common voltage of headphone amp */
192 akc_set(AK4537_PM2
, PMHPL
| PMHPR
);
196 void audiohw_postinit(void)
201 void audiohw_close(void)
203 /* POWER DOWN SEQUENCE (from the datasheet) */
206 akc_write(AK4537_ATTL
, 0xff);
207 akc_write(AK4537_ATTR
, 0xff);
208 akc_set(AK4537_DAC
, SMUTE
);
211 /* power down the common voltage of headphone amp */
212 akc_clear(AK4537_PM2
, PMHPL
| PMHPR
);
214 /* power down the DAC */
215 akc_clear(AK4537_PM2
, PMDAC
);
217 /* power down the headphone amp */
218 akc_set(AK4537_SIGSEL2
, HPL
| HPR
);
221 akc_clear(AK4537_MODE1
, MCKO_EN
);
223 /* power down X'tal and PLL, pull down the XTI pin */
224 akc_write_masked(AK4537_PM2
, MCLKPD
, (MCLKPD
| PMXTL
| PMPLL
));
226 /* power down VCOM */
227 akc_clear(AK4537_PM1
, PMVCM
);
230 akcodec_close(); /* target-specific */
233 void audiohw_set_master_vol(int vol_l
, int vol_r
)
235 akc_write(AK4537_ATTL
, vol_l
& 0xff);
236 akc_write(AK4537_ATTR
, vol_r
& 0xff);
239 void audiohw_set_frequency(int fsel
)
241 static const unsigned char srctrl_table
[HW_NUM_FREQ
] =
243 HW_HAVE_8_([HW_FREQ_8
] = AKC_PLL_8000HZ
, )
244 HW_HAVE_11_([HW_FREQ_11
] = AKC_PLL_11025HZ
,)
245 HW_HAVE_16_([HW_FREQ_16
] = AKC_PLL_16000HZ
,)
246 HW_HAVE_22_([HW_FREQ_22
] = AKC_PLL_22050HZ
,)
247 HW_HAVE_24_([HW_FREQ_24
] = AKC_PLL_24000HZ
,)
248 HW_HAVE_32_([HW_FREQ_32
] = AKC_PLL_32000HZ
,)
249 HW_HAVE_44_([HW_FREQ_44
] = AKC_PLL_44100HZ
,)
250 HW_HAVE_48_([HW_FREQ_48
] = AKC_PLL_48000HZ
,)
253 if ((unsigned)fsel
>= HW_NUM_FREQ
)
254 fsel
= HW_FREQ_DEFAULT
;
256 akc_write_masked(AK4537_MODE2
, srctrl_table
[fsel
], FS_MASK
);
259 #if defined(HAVE_RECORDING)
260 void audiohw_enable_recording(bool source_mic
)
265 void audiohw_disable_recording(void)
269 void audiohw_set_recvol(int left
, int right
, int type
)
276 void audiohw_set_monitor(bool enable
)
280 #endif /* HAVE_RECORDING */