aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@rpsys.net>2006-10-06 12:38:03 -0400
committerJaroslav Kysela <perex@suse.cz>2007-02-09 03:00:24 -0500
commitdbc6b6ad767c86907db373e85139b0e975ba7599 (patch)
tree0be48efd7ac629cfb51e16aa15185fd0a477a587 /sound/soc/codecs
parent10c5cf30446fe91b7173436b75c4f00dfb4cd9f8 (diff)
[ALSA] ASoC codecs: generic AC97 support
This patch allows the std Alsa AC97 codec driver to use any AsoC AC97 controller driver. Currently, only HiFi playback and Capture are supported atm. Signed-off-by: Richard Purdie <rpurdie@rpsys.net> Signed-off-by: Liam Girdwood <liam.girdwood@wolfsonmicro.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/ac97.c167
-rw-r--r--sound/soc/codecs/ac97.h18
2 files changed, 185 insertions, 0 deletions
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
new file mode 100644
index 000000000000..dd1a9f579a6b
--- /dev/null
+++ b/sound/soc/codecs/ac97.c
@@ -0,0 +1,167 @@
1/*
2 * ac97.c -- ALSA Soc AC97 codec support
3 *
4 * Copyright 2005 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.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 * Revision history
14 * 17th Oct 2005 Initial version.
15 *
16 * Generic AC97 support.
17 */
18
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>
28
29#define AC97_VERSION "0.5"
30
31#define AC97_DIR \
32 (SND_SOC_DAIDIR_PLAYBACK | SND_SOC_DAIDIR_CAPTURE)
33
34#define AC97_RATES \
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 | \
37 SNDRV_PCM_RATE_48000)
38
39/* may need to expand this */
40static 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},
44};
45
46static int ac97_prepare(struct snd_pcm_substream *substream)
47{
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;
52
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);
56}
57
58static struct snd_soc_codec_dai ac97_dai = {
59 .name = "AC97 HiFi",
60 .playback = {
61 .stream_name = "AC97 Playback",
62 .channels_min = 1,
63 .channels_max = 2,},
64 .capture = {
65 .stream_name = "AC97 Capture",
66 .channels_min = 1,
67 .channels_max = 2,},
68 .ops = {
69 .prepare = ac97_prepare,},
70 .caps = {
71 .num_modes = ARRAY_SIZE(soc_ac97),
72 .mode = soc_ac97,},
73};
74
75static unsigned int ac97_read(struct snd_soc_codec *codec,
76 unsigned int reg)
77{
78 return soc_ac97_ops.read(codec->ac97, reg);
79}
80
81static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
82 unsigned int val)
83{
84 soc_ac97_ops.write(codec->ac97, reg, val);
85 return 0;
86}
87
88static int ac97_soc_probe(struct platform_device *pdev)
89{
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;
94 int ret = 0;
95
96 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
97
98 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
99 if (socdev->codec == NULL)
100 return -ENOMEM;
101 codec = socdev->codec;
102 mutex_init(&codec->mutex);
103
104 codec->name = "AC97";
105 codec->owner = THIS_MODULE;
106 codec->dai = &ac97_dai;
107 codec->num_dai = 1;
108 codec->write = ac97_write;
109 codec->read = ac97_read;
110 INIT_LIST_HEAD(&codec->dapm_widgets);
111 INIT_LIST_HEAD(&codec->dapm_paths);
112
113 /* register pcms */
114 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
115 if(ret < 0)
116 goto err;
117
118 /* add codec as bus device for standard ac97 */
119 ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus);
120 if(ret < 0)
121 goto bus_err;
122
123 memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
124 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97);
125 if(ret < 0)
126 goto bus_err;
127
128 ret = snd_soc_register_card(socdev);
129 if (ret < 0)
130 goto bus_err;
131 return 0;
132
133bus_err:
134 snd_soc_free_pcms(socdev);
135
136err:
137 kfree(socdev->codec->reg_cache);
138 kfree(socdev->codec);
139 socdev->codec = NULL;
140 return ret;
141}
142
143static int ac97_soc_remove(struct platform_device *pdev)
144{
145 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
146 struct snd_soc_codec *codec = socdev->codec;
147
148 if(codec == NULL)
149 return 0;
150
151 snd_soc_free_pcms(socdev);
152 kfree(socdev->codec->reg_cache);
153 kfree(socdev->codec);
154
155 return 0;
156}
157
158struct snd_soc_codec_device soc_codec_dev_ac97= {
159 .probe = ac97_soc_probe,
160 .remove = ac97_soc_remove,
161};
162
163EXPORT_SYMBOL_GPL(soc_codec_dev_ac97);
164
165MODULE_DESCRIPTION("Soc Generic AC97 driver");
166MODULE_AUTHOR("Liam Girdwood");
167MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/ac97.h b/sound/soc/codecs/ac97.h
new file mode 100644
index 000000000000..930ddfc2321a
--- /dev/null
+++ b/sound/soc/codecs/ac97.h
@@ -0,0 +1,18 @@
1/*
2 * linux/sound/codecs/ac97.h -- ALSA SoC Layer
3 *
4 * Author: Liam Girdwood
5 * Created: Dec 1st 2005
6 * Copyright: Wolfson Microelectronics. PLC.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#ifndef __LINUX_SND_SOC_AC97_H
14#define __LINUX_SND_SOC_AC97_H
15
16extern struct snd_soc_codec_device soc_codec_dev_ac97;
17
18#endif