2 * ac97.c -- ALSA Soc AC97 codec support
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.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.
14 * 17th Oct 2005 Initial version.
16 * Generic AC97 support.
19 #include <linux/init.h>
20 #include <linux/kernel.h>
21 #include <linux/device.h>
22 #include <sound/driver.h>
23 #include <sound/core.h>
24 #include <sound/pcm.h>
25 #include <sound/ac97_codec.h>
26 #include <sound/initval.h>
27 #include <sound/soc.h>
29 #define AC97_VERSION "0.5"
32 (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
35 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
36 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
39 /* may need to expand this */
40 static struct snd_soc_dai_mode soc_ac97[] = {
41 {0, 0, SNDRV_PCM_FMTBIT_S16_LE, AC97_RATES},
42 {0, 0, SNDRV_PCM_FMTBIT_S18_3LE, AC97_RATES},
43 {0, 0, SNDRV_PCM_FMTBIT_S20_3LE, AC97_RATES},
46 static int ac97_prepare(struct snd_pcm_substream *substream)
48 struct snd_pcm_runtime *runtime = substream->runtime;
49 struct snd_soc_pcm_runtime *rtd = substream->private_data;
50 struct snd_soc_device *socdev = rtd->socdev;
51 struct snd_soc_codec *codec = socdev->codec;
53 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
54 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
55 return snd_ac97_set_rate(codec->ac97, reg, runtime->rate);
58 static struct snd_soc_codec_dai ac97_dai = {
61 .stream_name = "AC97 Playback",
65 .stream_name = "AC97 Capture",
69 .prepare = ac97_prepare,},
71 .num_modes = ARRAY_SIZE(soc_ac97),
75 static unsigned int ac97_read(struct snd_soc_codec *codec,
78 return soc_ac97_ops.read(codec->ac97, reg);
81 static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
84 soc_ac97_ops.write(codec->ac97, reg, val);
88 static int ac97_soc_probe(struct platform_device *pdev)
90 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
91 struct snd_soc_codec *codec;
92 struct snd_ac97_bus *ac97_bus;
93 struct snd_ac97_template ac97_template;
96 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
98 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
99 if (socdev->codec == NULL)
101 codec = socdev->codec;
102 mutex_init(&codec->mutex);
104 codec->name = "AC97";
105 codec->owner = THIS_MODULE;
106 codec->dai = &ac97_dai;
108 codec->write = ac97_write;
109 codec->read = ac97_read;
110 INIT_LIST_HEAD(&codec->dapm_widgets);
111 INIT_LIST_HEAD(&codec->dapm_paths);
114 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
118 /* add codec as bus device for standard ac97 */
119 ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus);
123 memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
124 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97);
128 ret = snd_soc_register_card(socdev);
134 snd_soc_free_pcms(socdev);
137 kfree(socdev->codec->reg_cache);
138 kfree(socdev->codec);
139 socdev->codec = NULL;
143 static int ac97_soc_remove(struct platform_device *pdev)
145 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
146 struct snd_soc_codec *codec = socdev->codec;
151 snd_soc_free_pcms(socdev);
152 kfree(socdev->codec->reg_cache);
153 kfree(socdev->codec);
158 struct snd_soc_codec_device soc_codec_dev_ac97= {
159 .probe = ac97_soc_probe,
160 .remove = ac97_soc_remove,
163 EXPORT_SYMBOL_GPL(soc_codec_dev_ac97);
165 MODULE_DESCRIPTION("Soc Generic AC97 driver");
166 MODULE_AUTHOR("Liam Girdwood");
167 MODULE_LICENSE("GPL");