Remove pcm_mute() which has been unused since r19308
[kugel-rb.git] / firmware / drivers / audio / ak4537.c
blobc3ce02a3aff3b634126f49b8446818bd6239d2e4
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "config.h"
22 #include "system.h"
23 #include "string.h"
25 /*#define LOGF_ENABLE*/
26 #include "logf.h"
28 #include "pcm_sampr.h"
29 #include "audio.h"
30 #include "akcodec.h"
31 #include "audiohw.h"
32 #include "sound.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},
46 #endif
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)
54 return;
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));
75 #if 0
76 static void codec_set_active(int active)
78 (void)active;
80 #endif
82 /* convert tenth of dB volume (-1270..0) to master volume register value */
83 int tenthdb2master(int db)
85 if (db < VOLUME_MIN)
86 return 0xff; /* mute */
87 else if (db >= VOLUME_MAX)
88 return 0x00;
89 else
90 return ((-db)/5);
93 int sound_val2phys(int setting, int value)
95 int result;
97 switch(setting)
99 #ifdef HAVE_RECORDING
100 case SOUND_LEFT_GAIN:
101 case SOUND_RIGHT_GAIN:
102 result = (value - 23) * 15; /* fix */
103 break;
104 case SOUND_MIC_GAIN:
105 result = value * 200; /* fix */
106 break;
107 #endif
108 default:
109 result = value;
110 break;
113 return result;
116 /*static void audiohw_mute(bool mute)
118 if (mute)
120 akc_set(AK4537_DAC, SMUTE);
121 udelay(200000);
123 else
125 udelay(200000);
126 akc_clear(AK4537_DAC, SMUTE);
130 void audiohw_preinit(void)
132 int i;
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 */
140 /* power up VCOM */
141 akc_set(AK4537_PM1, PMVCM);
142 udelay(100000);
144 /* setup AK4537_SIGSEL1 */
145 akc_set(AK4537_SIGSEL1, ALCS | MOUT2);
146 udelay(100000);
148 /* setup AK4537_SIGSEL2 */
149 akc_write_masked(AK4537_SIGSEL2, DAHS, (DAHS | HPL | HPR));
150 udelay(100000);
152 /* setup AK4537_MODE1 */
153 akc_write_masked(AK4537_MODE1, DIF_I2S | BICK_32FS | MCKI_PLL_12000KHZ,
154 (DIF_MASK | BICK_MASK | MCKI_MASK));
155 udelay(100000);
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));
161 udelay(100000);
163 /* power-up the PLL */
164 akc_set(AK4537_PM2, PMPLL);
165 udelay(100000);
167 /* enable MCKO output and setup MCKO output freq */
168 akc_set(AK4537_MODE1, MCKO_EN);
169 udelay(100000);
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);
185 udelay(100000);
187 /* power up the headphone amp */
188 akc_clear(AK4537_SIGSEL2, HPL | HPR);
189 udelay(100000);
191 /* power up the common voltage of headphone amp */
192 akc_set(AK4537_PM2, PMHPL | PMHPR);
193 udelay(100000);
196 void audiohw_postinit(void)
198 /* nothing */
201 void audiohw_close(void)
203 /* POWER DOWN SEQUENCE (from the datasheet) */
205 /* mute */
206 akc_write(AK4537_ATTL, 0xff);
207 akc_write(AK4537_ATTR, 0xff);
208 akc_set(AK4537_DAC, SMUTE);
209 udelay(100000);
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);
220 /* disable MCKO */
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);
228 udelay(100000);
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)
262 (void)source_mic;
265 void audiohw_disable_recording(void)
269 void audiohw_set_recvol(int left, int right, int type)
271 (void)left;
272 (void)right;
273 (void)type;
276 void audiohw_set_monitor(bool enable)
278 (void)enable;
280 #endif /* HAVE_RECORDING */