GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / sound / soc / codecs / ad1980.c
blob70cfaec3be2c0efbcf57c0c753622e747683b67c
1 /*
2 * ad1980.c -- ALSA Soc AD1980 codec support
4 * Copyright: Analog Device Inc.
5 * Author: Roy Huang <roy.huang@analog.com>
6 * Cliff Cai <cliff.cai@analog.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
15 * WARNING:
17 * Because Analog Devices Inc. discontinued the ad1980 sound chip since
18 * Sep. 2009, this ad1980 driver is not maintained, tested and supported
19 * by ADI now.
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/device.h>
27 #include <sound/core.h>
28 #include <sound/pcm.h>
29 #include <sound/ac97_codec.h>
30 #include <sound/initval.h>
31 #include <sound/soc.h>
32 #include <sound/soc-dapm.h>
34 #include "ad1980.h"
36 static unsigned int ac97_read(struct snd_soc_codec *codec,
37 unsigned int reg);
38 static int ac97_write(struct snd_soc_codec *codec,
39 unsigned int reg, unsigned int val);
42 * AD1980 register cache
44 static const u16 ad1980_reg[] = {
45 0x0090, 0x8000, 0x8000, 0x8000, /* 0 - 6 */
46 0x0000, 0x0000, 0x8008, 0x8008, /* 8 - e */
47 0x8808, 0x8808, 0x0000, 0x8808, /* 10 - 16 */
48 0x8808, 0x0000, 0x8000, 0x0000, /* 18 - 1e */
49 0x0000, 0x0000, 0x0000, 0x0000, /* 20 - 26 */
50 0x03c7, 0x0000, 0xbb80, 0xbb80, /* 28 - 2e */
51 0xbb80, 0xbb80, 0x0000, 0x8080, /* 30 - 36 */
52 0x8080, 0x2000, 0x0000, 0x0000, /* 38 - 3e */
53 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
54 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
55 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
56 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
57 0x8080, 0x0000, 0x0000, 0x0000, /* 60 - 66 */
58 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
59 0x0000, 0x0000, 0x1001, 0x0000, /* 70 - 76 */
60 0x0000, 0x0000, 0x4144, 0x5370 /* 78 - 7e */
63 static const char *ad1980_rec_sel[] = {"Mic", "CD", "NC", "AUX", "Line",
64 "Stereo Mix", "Mono Mix", "Phone"};
66 static const struct soc_enum ad1980_cap_src =
67 SOC_ENUM_DOUBLE(AC97_REC_SEL, 8, 0, 7, ad1980_rec_sel);
69 static const struct snd_kcontrol_new ad1980_snd_ac97_controls[] = {
70 SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1),
71 SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1),
73 SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
74 SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1),
76 SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1),
77 SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1),
79 SOC_DOUBLE("PCM Capture Volume", AC97_REC_GAIN, 8, 0, 31, 0),
80 SOC_SINGLE("PCM Capture Switch", AC97_REC_GAIN, 15, 1, 1),
82 SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1),
83 SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
85 SOC_SINGLE("Phone Capture Volume", AC97_PHONE, 0, 31, 1),
86 SOC_SINGLE("Phone Capture Switch", AC97_PHONE, 15, 1, 1),
88 SOC_SINGLE("Mic Volume", AC97_MIC, 0, 31, 1),
89 SOC_SINGLE("Mic Switch", AC97_MIC, 15, 1, 1),
91 SOC_SINGLE("Stereo Mic Switch", AC97_AD_MISC, 6, 1, 0),
92 SOC_DOUBLE("Line HP Swap Switch", AC97_AD_MISC, 10, 5, 1, 0),
94 SOC_DOUBLE("Surround Playback Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
95 SOC_DOUBLE("Surround Playback Switch", AC97_SURROUND_MASTER, 15, 7, 1, 1),
97 SOC_DOUBLE("Center/LFE Playback Volume", AC97_CENTER_LFE_MASTER, 8, 0, 31, 1),
98 SOC_DOUBLE("Center/LFE Playback Switch", AC97_CENTER_LFE_MASTER, 15, 7, 1, 1),
100 SOC_ENUM("Capture Source", ad1980_cap_src),
102 SOC_SINGLE("Mic Boost Switch", AC97_MIC, 6, 1, 0),
105 static unsigned int ac97_read(struct snd_soc_codec *codec,
106 unsigned int reg)
108 u16 *cache = codec->reg_cache;
110 switch (reg) {
111 case AC97_RESET:
112 case AC97_INT_PAGING:
113 case AC97_POWERDOWN:
114 case AC97_EXTENDED_STATUS:
115 case AC97_VENDOR_ID1:
116 case AC97_VENDOR_ID2:
117 return soc_ac97_ops.read(codec->ac97, reg);
118 default:
119 reg = reg >> 1;
121 if (reg >= ARRAY_SIZE(ad1980_reg))
122 return -EINVAL;
124 return cache[reg];
128 static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
129 unsigned int val)
131 u16 *cache = codec->reg_cache;
133 soc_ac97_ops.write(codec->ac97, reg, val);
134 reg = reg >> 1;
135 if (reg < ARRAY_SIZE(ad1980_reg))
136 cache[reg] = val;
138 return 0;
141 struct snd_soc_dai ad1980_dai = {
142 .name = "AC97",
143 .ac97_control = 1,
144 .playback = {
145 .stream_name = "Playback",
146 .channels_min = 2,
147 .channels_max = 6,
148 .rates = SNDRV_PCM_RATE_48000,
149 .formats = SND_SOC_STD_AC97_FMTS, },
150 .capture = {
151 .stream_name = "Capture",
152 .channels_min = 2,
153 .channels_max = 2,
154 .rates = SNDRV_PCM_RATE_48000,
155 .formats = SND_SOC_STD_AC97_FMTS, },
157 EXPORT_SYMBOL_GPL(ad1980_dai);
159 static int ad1980_reset(struct snd_soc_codec *codec, int try_warm)
161 u16 retry_cnt = 0;
163 retry:
164 if (try_warm && soc_ac97_ops.warm_reset) {
165 soc_ac97_ops.warm_reset(codec->ac97);
166 if (ac97_read(codec, AC97_RESET) == 0x0090)
167 return 1;
170 soc_ac97_ops.reset(codec->ac97);
171 /* Set bit 16slot in register 74h, then every slot will has only 16
172 * bits. This command is sent out in 20bit mode, in which case the
173 * first nibble of data is eaten by the addr. (Tag is always 16 bit)*/
174 ac97_write(codec, AC97_AD_SERIAL_CFG, 0x9900);
176 if (ac97_read(codec, AC97_RESET) != 0x0090)
177 goto err;
178 return 0;
180 err:
181 while (retry_cnt++ < 10)
182 goto retry;
184 printk(KERN_ERR "AD1980 AC97 reset failed\n");
185 return -EIO;
188 static int ad1980_soc_probe(struct platform_device *pdev)
190 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
191 struct snd_soc_codec *codec;
192 int ret = 0;
193 u16 vendor_id2;
194 u16 ext_status;
196 printk(KERN_INFO "AD1980 SoC Audio Codec\n");
198 socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
199 if (socdev->card->codec == NULL)
200 return -ENOMEM;
201 codec = socdev->card->codec;
202 mutex_init(&codec->mutex);
204 codec->reg_cache =
205 kzalloc(sizeof(u16) * ARRAY_SIZE(ad1980_reg), GFP_KERNEL);
206 if (codec->reg_cache == NULL) {
207 ret = -ENOMEM;
208 goto cache_err;
210 memcpy(codec->reg_cache, ad1980_reg, sizeof(u16) * \
211 ARRAY_SIZE(ad1980_reg));
212 codec->reg_cache_size = sizeof(u16) * ARRAY_SIZE(ad1980_reg);
213 codec->reg_cache_step = 2;
214 codec->name = "AD1980";
215 codec->owner = THIS_MODULE;
216 codec->dai = &ad1980_dai;
217 codec->num_dai = 1;
218 codec->write = ac97_write;
219 codec->read = ac97_read;
220 INIT_LIST_HEAD(&codec->dapm_widgets);
221 INIT_LIST_HEAD(&codec->dapm_paths);
223 ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0);
224 if (ret < 0) {
225 printk(KERN_ERR "ad1980: failed to register AC97 codec\n");
226 goto codec_err;
229 /* register pcms */
230 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
231 if (ret < 0)
232 goto pcm_err;
235 ret = ad1980_reset(codec, 0);
236 if (ret < 0) {
237 printk(KERN_ERR "Failed to reset AD1980: AC97 link error\n");
238 goto reset_err;
241 /* Read out vendor ID to make sure it is ad1980 */
242 if (ac97_read(codec, AC97_VENDOR_ID1) != 0x4144)
243 goto reset_err;
245 vendor_id2 = ac97_read(codec, AC97_VENDOR_ID2);
247 if (vendor_id2 != 0x5370) {
248 if (vendor_id2 != 0x5374)
249 goto reset_err;
250 else
251 printk(KERN_WARNING "ad1980: "
252 "Found AD1981 - only 2/2 IN/OUT Channels "
253 "supported\n");
256 /* unmute captures and playbacks volume */
257 ac97_write(codec, AC97_MASTER, 0x0000);
258 ac97_write(codec, AC97_PCM, 0x0000);
259 ac97_write(codec, AC97_REC_GAIN, 0x0000);
260 ac97_write(codec, AC97_CENTER_LFE_MASTER, 0x0000);
261 ac97_write(codec, AC97_SURROUND_MASTER, 0x0000);
263 /*power on LFE/CENTER/Surround DACs*/
264 ext_status = ac97_read(codec, AC97_EXTENDED_STATUS);
265 ac97_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800);
267 snd_soc_add_controls(codec, ad1980_snd_ac97_controls,
268 ARRAY_SIZE(ad1980_snd_ac97_controls));
270 return 0;
272 reset_err:
273 snd_soc_free_pcms(socdev);
275 pcm_err:
276 snd_soc_free_ac97_codec(codec);
278 codec_err:
279 kfree(codec->reg_cache);
281 cache_err:
282 kfree(socdev->card->codec);
283 socdev->card->codec = NULL;
284 return ret;
287 static int ad1980_soc_remove(struct platform_device *pdev)
289 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
290 struct snd_soc_codec *codec = socdev->card->codec;
292 if (codec == NULL)
293 return 0;
295 snd_soc_dapm_free(socdev);
296 snd_soc_free_pcms(socdev);
297 snd_soc_free_ac97_codec(codec);
298 kfree(codec->reg_cache);
299 kfree(codec);
300 return 0;
303 struct snd_soc_codec_device soc_codec_dev_ad1980 = {
304 .probe = ad1980_soc_probe,
305 .remove = ad1980_soc_remove,
307 EXPORT_SYMBOL_GPL(soc_codec_dev_ad1980);
309 MODULE_DESCRIPTION("ASoC ad1980 driver (Obsolete)");
310 MODULE_AUTHOR("Roy Huang, Cliff Cai");
311 MODULE_LICENSE("GPL");