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.
17 * Because Analog Devices Inc. discontinued the ad1980 sound chip since
18 * Sep. 2009, this ad1980 driver is not maintained, tested and supported
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 <linux/regmap.h>
28 #include <sound/core.h>
29 #include <sound/pcm.h>
30 #include <sound/ac97_codec.h>
31 #include <sound/initval.h>
32 #include <sound/soc.h>
34 static const struct reg_default ad1980_reg_defaults
[] = {
62 static bool ad1980_readable_reg(struct device
*dev
, unsigned int reg
)
65 case AC97_RESET
... AC97_MASTER_MONO
:
66 case AC97_PHONE
... AC97_CD
:
67 case AC97_AUX
... AC97_GENERAL_PURPOSE
:
68 case AC97_POWERDOWN
... AC97_PCM_LR_ADC_RATE
:
70 case AC97_CODEC_CLASS_REV
:
72 case AC97_AD_CODEC_CFG
:
73 case AC97_AD_JACK_SPDIF
:
74 case AC97_AD_SERIAL_CFG
:
83 static bool ad1980_writeable_reg(struct device
*dev
, unsigned int reg
)
90 return ad1980_readable_reg(dev
, reg
);
94 static const struct regmap_config ad1980_regmap_config
= {
99 .cache_type
= REGCACHE_RBTREE
,
101 .volatile_reg
= regmap_ac97_default_volatile
,
102 .readable_reg
= ad1980_readable_reg
,
103 .writeable_reg
= ad1980_writeable_reg
,
105 .reg_defaults
= ad1980_reg_defaults
,
106 .num_reg_defaults
= ARRAY_SIZE(ad1980_reg_defaults
),
109 static const char *ad1980_rec_sel
[] = {"Mic", "CD", "NC", "AUX", "Line",
110 "Stereo Mix", "Mono Mix", "Phone"};
112 static SOC_ENUM_DOUBLE_DECL(ad1980_cap_src
,
113 AC97_REC_SEL
, 8, 0, ad1980_rec_sel
);
115 static const struct snd_kcontrol_new ad1980_snd_ac97_controls
[] = {
116 SOC_DOUBLE("Master Playback Volume", AC97_MASTER
, 8, 0, 31, 1),
117 SOC_SINGLE("Master Playback Switch", AC97_MASTER
, 15, 1, 1),
119 SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE
, 8, 0, 31, 1),
120 SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE
, 15, 1, 1),
122 SOC_DOUBLE("PCM Playback Volume", AC97_PCM
, 8, 0, 31, 1),
123 SOC_SINGLE("PCM Playback Switch", AC97_PCM
, 15, 1, 1),
125 SOC_DOUBLE("PCM Capture Volume", AC97_REC_GAIN
, 8, 0, 31, 0),
126 SOC_SINGLE("PCM Capture Switch", AC97_REC_GAIN
, 15, 1, 1),
128 SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO
, 0, 31, 1),
129 SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO
, 15, 1, 1),
131 SOC_SINGLE("Phone Capture Volume", AC97_PHONE
, 0, 31, 1),
132 SOC_SINGLE("Phone Capture Switch", AC97_PHONE
, 15, 1, 1),
134 SOC_SINGLE("Mic Volume", AC97_MIC
, 0, 31, 1),
135 SOC_SINGLE("Mic Switch", AC97_MIC
, 15, 1, 1),
137 SOC_SINGLE("Stereo Mic Switch", AC97_AD_MISC
, 6, 1, 0),
138 SOC_DOUBLE("Line HP Swap Switch", AC97_AD_MISC
, 10, 5, 1, 0),
140 SOC_DOUBLE("Surround Playback Volume", AC97_SURROUND_MASTER
, 8, 0, 31, 1),
141 SOC_DOUBLE("Surround Playback Switch", AC97_SURROUND_MASTER
, 15, 7, 1, 1),
143 SOC_DOUBLE("Center/LFE Playback Volume", AC97_CENTER_LFE_MASTER
, 8, 0, 31, 1),
144 SOC_DOUBLE("Center/LFE Playback Switch", AC97_CENTER_LFE_MASTER
, 15, 7, 1, 1),
146 SOC_ENUM("Capture Source", ad1980_cap_src
),
148 SOC_SINGLE("Mic Boost Switch", AC97_MIC
, 6, 1, 0),
151 static const struct snd_soc_dapm_widget ad1980_dapm_widgets
[] = {
152 SND_SOC_DAPM_INPUT("MIC1"),
153 SND_SOC_DAPM_INPUT("MIC2"),
154 SND_SOC_DAPM_INPUT("CD_L"),
155 SND_SOC_DAPM_INPUT("CD_R"),
156 SND_SOC_DAPM_INPUT("AUX_L"),
157 SND_SOC_DAPM_INPUT("AUX_R"),
158 SND_SOC_DAPM_INPUT("LINE_IN_L"),
159 SND_SOC_DAPM_INPUT("LINE_IN_R"),
161 SND_SOC_DAPM_OUTPUT("LFE_OUT"),
162 SND_SOC_DAPM_OUTPUT("CENTER_OUT"),
163 SND_SOC_DAPM_OUTPUT("LINE_OUT_L"),
164 SND_SOC_DAPM_OUTPUT("LINE_OUT_R"),
165 SND_SOC_DAPM_OUTPUT("MONO_OUT"),
166 SND_SOC_DAPM_OUTPUT("HP_OUT_L"),
167 SND_SOC_DAPM_OUTPUT("HP_OUT_R"),
170 static const struct snd_soc_dapm_route ad1980_dapm_routes
[] = {
171 { "Capture", NULL
, "MIC1" },
172 { "Capture", NULL
, "MIC2" },
173 { "Capture", NULL
, "CD_L" },
174 { "Capture", NULL
, "CD_R" },
175 { "Capture", NULL
, "AUX_L" },
176 { "Capture", NULL
, "AUX_R" },
177 { "Capture", NULL
, "LINE_IN_L" },
178 { "Capture", NULL
, "LINE_IN_R" },
180 { "LFE_OUT", NULL
, "Playback" },
181 { "CENTER_OUT", NULL
, "Playback" },
182 { "LINE_OUT_L", NULL
, "Playback" },
183 { "LINE_OUT_R", NULL
, "Playback" },
184 { "MONO_OUT", NULL
, "Playback" },
185 { "HP_OUT_L", NULL
, "Playback" },
186 { "HP_OUT_R", NULL
, "Playback" },
189 static struct snd_soc_dai_driver ad1980_dai
= {
190 .name
= "ad1980-hifi",
192 .stream_name
= "Playback",
195 .rates
= SNDRV_PCM_RATE_48000
,
196 .formats
= SND_SOC_STD_AC97_FMTS
, },
198 .stream_name
= "Capture",
201 .rates
= SNDRV_PCM_RATE_48000
,
202 .formats
= SND_SOC_STD_AC97_FMTS
, },
205 #define AD1980_VENDOR_ID 0x41445300
206 #define AD1980_VENDOR_MASK 0xffffff00
208 static int ad1980_reset(struct snd_soc_codec
*codec
, int try_warm
)
210 struct snd_ac97
*ac97
= snd_soc_codec_get_drvdata(codec
);
211 unsigned int retry_cnt
= 0;
215 ret
= snd_ac97_reset(ac97
, true, AD1980_VENDOR_ID
,
221 * Set bit 16slot in register 74h, then every slot will has only
222 * 16 bits. This command is sent out in 20bit mode, in which
223 * case the first nibble of data is eaten by the addr. (Tag is
226 snd_soc_write(codec
, AC97_AD_SERIAL_CFG
, 0x9900);
228 } while (retry_cnt
++ < 10);
230 dev_err(codec
->dev
, "Failed to reset: AC97 link error\n");
235 static int ad1980_soc_probe(struct snd_soc_codec
*codec
)
237 struct snd_ac97
*ac97
;
238 struct regmap
*regmap
;
243 ac97
= snd_soc_new_ac97_codec(codec
, 0, 0);
246 dev_err(codec
->dev
, "Failed to register AC97 codec: %d\n", ret
);
250 regmap
= regmap_init_ac97(ac97
, &ad1980_regmap_config
);
251 if (IS_ERR(regmap
)) {
252 ret
= PTR_ERR(regmap
);
256 snd_soc_codec_init_regmap(codec
, regmap
);
257 snd_soc_codec_set_drvdata(codec
, ac97
);
259 ret
= ad1980_reset(codec
, 0);
263 vendor_id2
= snd_soc_read(codec
, AC97_VENDOR_ID2
);
264 if (vendor_id2
== 0x5374) {
266 "Found AD1981 - only 2/2 IN/OUT Channels supported\n");
269 /* unmute captures and playbacks volume */
270 snd_soc_write(codec
, AC97_MASTER
, 0x0000);
271 snd_soc_write(codec
, AC97_PCM
, 0x0000);
272 snd_soc_write(codec
, AC97_REC_GAIN
, 0x0000);
273 snd_soc_write(codec
, AC97_CENTER_LFE_MASTER
, 0x0000);
274 snd_soc_write(codec
, AC97_SURROUND_MASTER
, 0x0000);
276 /*power on LFE/CENTER/Surround DACs*/
277 ext_status
= snd_soc_read(codec
, AC97_EXTENDED_STATUS
);
278 snd_soc_write(codec
, AC97_EXTENDED_STATUS
, ext_status
&~0x3800);
283 snd_soc_codec_exit_regmap(codec
);
285 snd_soc_free_ac97_codec(ac97
);
289 static int ad1980_soc_remove(struct snd_soc_codec
*codec
)
291 struct snd_ac97
*ac97
= snd_soc_codec_get_drvdata(codec
);
293 snd_soc_codec_exit_regmap(codec
);
294 snd_soc_free_ac97_codec(ac97
);
298 static struct snd_soc_codec_driver soc_codec_dev_ad1980
= {
299 .probe
= ad1980_soc_probe
,
300 .remove
= ad1980_soc_remove
,
302 .component_driver
= {
303 .controls
= ad1980_snd_ac97_controls
,
304 .num_controls
= ARRAY_SIZE(ad1980_snd_ac97_controls
),
305 .dapm_widgets
= ad1980_dapm_widgets
,
306 .num_dapm_widgets
= ARRAY_SIZE(ad1980_dapm_widgets
),
307 .dapm_routes
= ad1980_dapm_routes
,
308 .num_dapm_routes
= ARRAY_SIZE(ad1980_dapm_routes
),
312 static int ad1980_probe(struct platform_device
*pdev
)
314 return snd_soc_register_codec(&pdev
->dev
,
315 &soc_codec_dev_ad1980
, &ad1980_dai
, 1);
318 static int ad1980_remove(struct platform_device
*pdev
)
320 snd_soc_unregister_codec(&pdev
->dev
);
324 static struct platform_driver ad1980_codec_driver
= {
329 .probe
= ad1980_probe
,
330 .remove
= ad1980_remove
,
333 module_platform_driver(ad1980_codec_driver
);
335 MODULE_DESCRIPTION("ASoC ad1980 driver (Obsolete)");
336 MODULE_AUTHOR("Roy Huang, Cliff Cai");
337 MODULE_LICENSE("GPL");