ASoC: ad1980: Remove unused header
[deliverable/linux.git] / sound / soc / codecs / ad1980.c
CommitLineData
5f57dc8b
CC
1/*
2 * ad1980.c -- ALSA Soc AD1980 codec support
3 *
4 * Copyright: Analog Device Inc.
5 * Author: Roy Huang <roy.huang@analog.com>
6 * Cliff Cai <cliff.cai@analog.com>
7 *
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.
12 */
13
2e2211a3
SZ
14/*
15 * WARNING:
16 *
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.
20 */
21
5f57dc8b 22#include <linux/init.h>
5a0e3ad6 23#include <linux/slab.h>
5f57dc8b 24#include <linux/module.h>
5f57dc8b
CC
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>
5f57dc8b 32
5f57dc8b
CC
33/*
34 * AD1980 register cache
35 */
36static const u16 ad1980_reg[] = {
37 0x0090, 0x8000, 0x8000, 0x8000, /* 0 - 6 */
38 0x0000, 0x0000, 0x8008, 0x8008, /* 8 - e */
39 0x8808, 0x8808, 0x0000, 0x8808, /* 10 - 16 */
40 0x8808, 0x0000, 0x8000, 0x0000, /* 18 - 1e */
41 0x0000, 0x0000, 0x0000, 0x0000, /* 20 - 26 */
42 0x03c7, 0x0000, 0xbb80, 0xbb80, /* 28 - 2e */
43 0xbb80, 0xbb80, 0x0000, 0x8080, /* 30 - 36 */
44 0x8080, 0x2000, 0x0000, 0x0000, /* 38 - 3e */
45 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
46 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
47 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
48 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
49 0x8080, 0x0000, 0x0000, 0x0000, /* 60 - 66 */
50 0x0000, 0x0000, 0x0000, 0x0000, /* reserved */
51 0x0000, 0x0000, 0x1001, 0x0000, /* 70 - 76 */
52 0x0000, 0x0000, 0x4144, 0x5370 /* 78 - 7e */
53};
54
55static const char *ad1980_rec_sel[] = {"Mic", "CD", "NC", "AUX", "Line",
56 "Stereo Mix", "Mono Mix", "Phone"};
57
901bb6c5
TI
58static SOC_ENUM_DOUBLE_DECL(ad1980_cap_src,
59 AC97_REC_SEL, 8, 0, ad1980_rec_sel);
5f57dc8b
CC
60
61static const struct snd_kcontrol_new ad1980_snd_ac97_controls[] = {
62SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1),
63SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1),
64
65SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
66SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1),
67
68SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1),
69SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1),
70
71SOC_DOUBLE("PCM Capture Volume", AC97_REC_GAIN, 8, 0, 31, 0),
72SOC_SINGLE("PCM Capture Switch", AC97_REC_GAIN, 15, 1, 1),
73
74SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1),
75SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
76
77SOC_SINGLE("Phone Capture Volume", AC97_PHONE, 0, 31, 1),
78SOC_SINGLE("Phone Capture Switch", AC97_PHONE, 15, 1, 1),
79
80SOC_SINGLE("Mic Volume", AC97_MIC, 0, 31, 1),
81SOC_SINGLE("Mic Switch", AC97_MIC, 15, 1, 1),
82
83SOC_SINGLE("Stereo Mic Switch", AC97_AD_MISC, 6, 1, 0),
84SOC_DOUBLE("Line HP Swap Switch", AC97_AD_MISC, 10, 5, 1, 0),
85
86SOC_DOUBLE("Surround Playback Volume", AC97_SURROUND_MASTER, 8, 0, 31, 1),
87SOC_DOUBLE("Surround Playback Switch", AC97_SURROUND_MASTER, 15, 7, 1, 1),
88
9905ed35
CC
89SOC_DOUBLE("Center/LFE Playback Volume", AC97_CENTER_LFE_MASTER, 8, 0, 31, 1),
90SOC_DOUBLE("Center/LFE Playback Switch", AC97_CENTER_LFE_MASTER, 15, 7, 1, 1),
91
5f57dc8b
CC
92SOC_ENUM("Capture Source", ad1980_cap_src),
93
94SOC_SINGLE("Mic Boost Switch", AC97_MIC, 6, 1, 0),
95};
96
9e7e474c
MB
97static const struct snd_soc_dapm_widget ad1980_dapm_widgets[] = {
98SND_SOC_DAPM_INPUT("MIC1"),
99SND_SOC_DAPM_INPUT("MIC2"),
100SND_SOC_DAPM_INPUT("CD_L"),
101SND_SOC_DAPM_INPUT("CD_R"),
102SND_SOC_DAPM_INPUT("AUX_L"),
103SND_SOC_DAPM_INPUT("AUX_R"),
104SND_SOC_DAPM_INPUT("LINE_IN_L"),
105SND_SOC_DAPM_INPUT("LINE_IN_R"),
106
107SND_SOC_DAPM_OUTPUT("LFE_OUT"),
108SND_SOC_DAPM_OUTPUT("CENTER_OUT"),
109SND_SOC_DAPM_OUTPUT("LINE_OUT_L"),
110SND_SOC_DAPM_OUTPUT("LINE_OUT_R"),
111SND_SOC_DAPM_OUTPUT("MONO_OUT"),
112SND_SOC_DAPM_OUTPUT("HP_OUT_L"),
113SND_SOC_DAPM_OUTPUT("HP_OUT_R"),
114};
115
116static const struct snd_soc_dapm_route ad1980_dapm_routes[] = {
117 { "Capture", NULL, "MIC1" },
118 { "Capture", NULL, "MIC2" },
119 { "Capture", NULL, "CD_L" },
120 { "Capture", NULL, "CD_R" },
121 { "Capture", NULL, "AUX_L" },
122 { "Capture", NULL, "AUX_R" },
123 { "Capture", NULL, "LINE_IN_L" },
124 { "Capture", NULL, "LINE_IN_R" },
125
126 { "LFE_OUT", NULL, "Playback" },
127 { "CENTER_OUT", NULL, "Playback" },
128 { "LINE_OUT_L", NULL, "Playback" },
129 { "LINE_OUT_R", NULL, "Playback" },
130 { "MONO_OUT", NULL, "Playback" },
131 { "HP_OUT_L", NULL, "Playback" },
132 { "HP_OUT_R", NULL, "Playback" },
133};
134
5f57dc8b
CC
135static unsigned int ac97_read(struct snd_soc_codec *codec,
136 unsigned int reg)
137{
138 u16 *cache = codec->reg_cache;
139
140 switch (reg) {
141 case AC97_RESET:
142 case AC97_INT_PAGING:
143 case AC97_POWERDOWN:
144 case AC97_EXTENDED_STATUS:
145 case AC97_VENDOR_ID1:
146 case AC97_VENDOR_ID2:
b047e1cc 147 return soc_ac97_ops->read(codec->ac97, reg);
5f57dc8b
CC
148 default:
149 reg = reg >> 1;
150
91432e97 151 if (reg >= ARRAY_SIZE(ad1980_reg))
5f57dc8b
CC
152 return -EINVAL;
153
154 return cache[reg];
155 }
156}
157
158static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
159 unsigned int val)
160{
161 u16 *cache = codec->reg_cache;
162
b047e1cc 163 soc_ac97_ops->write(codec->ac97, reg, val);
5f57dc8b 164 reg = reg >> 1;
91432e97 165 if (reg < ARRAY_SIZE(ad1980_reg))
5f57dc8b
CC
166 cache[reg] = val;
167
168 return 0;
169}
170
de535a5b 171static struct snd_soc_dai_driver ad1980_dai = {
f0fba2ad 172 .name = "ad1980-hifi",
67c91513 173 .ac97_control = 1,
5f57dc8b
CC
174 .playback = {
175 .stream_name = "Playback",
176 .channels_min = 2,
9905ed35 177 .channels_max = 6,
5f57dc8b 178 .rates = SNDRV_PCM_RATE_48000,
33f503c9 179 .formats = SND_SOC_STD_AC97_FMTS, },
5f57dc8b
CC
180 .capture = {
181 .stream_name = "Capture",
182 .channels_min = 2,
183 .channels_max = 2,
184 .rates = SNDRV_PCM_RATE_48000,
33f503c9 185 .formats = SND_SOC_STD_AC97_FMTS, },
5f57dc8b 186};
5f57dc8b
CC
187
188static int ad1980_reset(struct snd_soc_codec *codec, int try_warm)
189{
cf7b71f4
LPC
190 unsigned int retry_cnt = 0;
191
192 do {
193 if (try_warm && soc_ac97_ops->warm_reset) {
194 soc_ac97_ops->warm_reset(codec->ac97);
195 if (ac97_read(codec, AC97_RESET) == 0x0090)
196 return 1;
197 }
198
199 soc_ac97_ops->reset(codec->ac97);
200 /*
201 * Set bit 16slot in register 74h, then every slot will has only
202 * 16 bits. This command is sent out in 20bit mode, in which
203 * case the first nibble of data is eaten by the addr. (Tag is
204 * always 16 bit)
205 */
206 ac97_write(codec, AC97_AD_SERIAL_CFG, 0x9900);
207
208 if (ac97_read(codec, AC97_RESET) == 0x0090)
209 return 0;
210 } while (retry_cnt++ < 10);
5f57dc8b
CC
211
212 printk(KERN_ERR "AD1980 AC97 reset failed\n");
213 return -EIO;
214}
215
f0fba2ad 216static int ad1980_soc_probe(struct snd_soc_codec *codec)
5f57dc8b 217{
f0fba2ad 218 int ret;
5f57dc8b 219 u16 vendor_id2;
9905ed35 220 u16 ext_status;
5f57dc8b
CC
221
222 printk(KERN_INFO "AD1980 SoC Audio Codec\n");
223
b047e1cc 224 ret = snd_soc_new_ac97_codec(codec, soc_ac97_ops, 0);
5f57dc8b
CC
225 if (ret < 0) {
226 printk(KERN_ERR "ad1980: failed to register AC97 codec\n");
f0fba2ad 227 return ret;
5f57dc8b
CC
228 }
229
5f57dc8b
CC
230 ret = ad1980_reset(codec, 0);
231 if (ret < 0) {
39639fab 232 printk(KERN_ERR "Failed to reset AD1980: AC97 link error\n");
5f57dc8b
CC
233 goto reset_err;
234 }
235
236 /* Read out vendor ID to make sure it is ad1980 */
0f73644f
AL
237 if (ac97_read(codec, AC97_VENDOR_ID1) != 0x4144) {
238 ret = -ENODEV;
5f57dc8b 239 goto reset_err;
0f73644f 240 }
5f57dc8b
CC
241
242 vendor_id2 = ac97_read(codec, AC97_VENDOR_ID2);
243
244 if (vendor_id2 != 0x5370) {
0f73644f
AL
245 if (vendor_id2 != 0x5374) {
246 ret = -ENODEV;
5f57dc8b 247 goto reset_err;
0f73644f 248 } else {
5f57dc8b
CC
249 printk(KERN_WARNING "ad1980: "
250 "Found AD1981 - only 2/2 IN/OUT Channels "
251 "supported\n");
0f73644f 252 }
5f57dc8b
CC
253 }
254
9905ed35
CC
255 /* unmute captures and playbacks volume */
256 ac97_write(codec, AC97_MASTER, 0x0000);
257 ac97_write(codec, AC97_PCM, 0x0000);
258 ac97_write(codec, AC97_REC_GAIN, 0x0000);
259 ac97_write(codec, AC97_CENTER_LFE_MASTER, 0x0000);
260 ac97_write(codec, AC97_SURROUND_MASTER, 0x0000);
261
262 /*power on LFE/CENTER/Surround DACs*/
263 ext_status = ac97_read(codec, AC97_EXTENDED_STATUS);
264 ac97_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800);
5f57dc8b 265
022658be 266 snd_soc_add_codec_controls(codec, ad1980_snd_ac97_controls,
3e8e1952 267 ARRAY_SIZE(ad1980_snd_ac97_controls));
5f57dc8b
CC
268
269 return 0;
270
271reset_err:
5f57dc8b 272 snd_soc_free_ac97_codec(codec);
5f57dc8b
CC
273 return ret;
274}
275
f0fba2ad 276static int ad1980_soc_remove(struct snd_soc_codec *codec)
5f57dc8b 277{
5f57dc8b 278 snd_soc_free_ac97_codec(codec);
5f57dc8b
CC
279 return 0;
280}
281
f0fba2ad 282static struct snd_soc_codec_driver soc_codec_dev_ad1980 = {
5f57dc8b
CC
283 .probe = ad1980_soc_probe,
284 .remove = ad1980_soc_remove,
f0fba2ad
LG
285 .reg_cache_size = ARRAY_SIZE(ad1980_reg),
286 .reg_word_size = sizeof(u16),
c7bad06f 287 .reg_cache_default = ad1980_reg,
f0fba2ad
LG
288 .reg_cache_step = 2,
289 .write = ac97_write,
290 .read = ac97_read,
9e7e474c
MB
291
292 .dapm_widgets = ad1980_dapm_widgets,
293 .num_dapm_widgets = ARRAY_SIZE(ad1980_dapm_widgets),
294 .dapm_routes = ad1980_dapm_routes,
295 .num_dapm_routes = ARRAY_SIZE(ad1980_dapm_routes),
5f57dc8b 296};
f0fba2ad 297
7a79e94e 298static int ad1980_probe(struct platform_device *pdev)
f0fba2ad
LG
299{
300 return snd_soc_register_codec(&pdev->dev,
301 &soc_codec_dev_ad1980, &ad1980_dai, 1);
302}
303
7a79e94e 304static int ad1980_remove(struct platform_device *pdev)
f0fba2ad
LG
305{
306 snd_soc_unregister_codec(&pdev->dev);
307 return 0;
308}
309
310static struct platform_driver ad1980_codec_driver = {
311 .driver = {
1afa98b8 312 .name = "ad1980",
f0fba2ad
LG
313 .owner = THIS_MODULE,
314 },
315
316 .probe = ad1980_probe,
7a79e94e 317 .remove = ad1980_remove,
f0fba2ad
LG
318};
319
5bbcc3c0 320module_platform_driver(ad1980_codec_driver);
5f57dc8b 321
2e2211a3 322MODULE_DESCRIPTION("ASoC ad1980 driver (Obsolete)");
5f57dc8b
CC
323MODULE_AUTHOR("Roy Huang, Cliff Cai");
324MODULE_LICENSE("GPL");
This page took 0.249277 seconds and 5 git commands to generate.