1 /*
2  * DB1200/DB1300/DB1550 ASoC audio fabric support code.
3  *
4  * (c) 2008-2011 Manuel Lauss <manuel.lauss@googlemail.com>
5  *
6  */
7 
8 #include <linux/module.h>
9 #include <linux/moduleparam.h>
10 #include <linux/timer.h>
11 #include <linux/interrupt.h>
12 #include <linux/platform_device.h>
13 #include <sound/core.h>
14 #include <sound/pcm.h>
15 #include <sound/soc.h>
16 #include <asm/mach-au1x00/au1000.h>
17 #include <asm/mach-au1x00/au1xxx_psc.h>
18 #include <asm/mach-au1x00/au1xxx_dbdma.h>
19 #include <asm/mach-db1x00/bcsr.h>
20 
21 #include "../codecs/wm8731.h"
22 #include "psc.h"
23 
24 static struct platform_device_id db1200_pids[] = {
25 	{
26 		.name		= "db1200-ac97",
27 		.driver_data	= 0,
28 	}, {
29 		.name		= "db1200-i2s",
30 		.driver_data	= 1,
31 	}, {
32 		.name		= "db1300-ac97",
33 		.driver_data	= 2,
34 	}, {
35 		.name		= "db1300-i2s",
36 		.driver_data	= 3,
37 	}, {
38 		.name		= "db1550-ac97",
39 		.driver_data	= 4,
40 	}, {
41 		.name		= "db1550-i2s",
42 		.driver_data	= 5,
43 	},
44 	{},
45 };
46 
47 /*-------------------------  AC97 PART  ---------------------------*/
48 
49 static struct snd_soc_dai_link db1200_ac97_dai = {
50 	.name		= "AC97",
51 	.stream_name	= "AC97 HiFi",
52 	.codec_dai_name	= "ac97-hifi",
53 	.cpu_dai_name	= "au1xpsc_ac97.1",
54 	.platform_name	= "au1xpsc-pcm.1",
55 	.codec_name	= "ac97-codec.1",
56 };
57 
58 static struct snd_soc_card db1200_ac97_machine = {
59 	.name		= "DB1200_AC97",
60 	.owner		= THIS_MODULE,
61 	.dai_link	= &db1200_ac97_dai,
62 	.num_links	= 1,
63 };
64 
65 static struct snd_soc_dai_link db1300_ac97_dai = {
66 	.name		= "AC97",
67 	.stream_name	= "AC97 HiFi",
68 	.codec_dai_name	= "wm9712-hifi",
69 	.cpu_dai_name	= "au1xpsc_ac97.1",
70 	.platform_name	= "au1xpsc-pcm.1",
71 	.codec_name	= "wm9712-codec.1",
72 };
73 
74 static struct snd_soc_card db1300_ac97_machine = {
75 	.name		= "DB1300_AC97",
76 	.dai_link	= &db1300_ac97_dai,
77 	.num_links	= 1,
78 };
79 
80 static struct snd_soc_card db1550_ac97_machine = {
81 	.name		= "DB1550_AC97",
82 	.dai_link	= &db1200_ac97_dai,
83 	.num_links	= 1,
84 };
85 
86 /*-------------------------  I2S PART  ---------------------------*/
87 
db1200_i2s_startup(struct snd_pcm_substream * substream)88 static int db1200_i2s_startup(struct snd_pcm_substream *substream)
89 {
90 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
91 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
92 	struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
93 	int ret;
94 
95 	/* WM8731 has its own 12MHz crystal */
96 	snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL,
97 				12000000, SND_SOC_CLOCK_IN);
98 
99 	/* codec is bitclock and lrclk master */
100 	ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_LEFT_J |
101 			SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
102 	if (ret < 0)
103 		goto out;
104 
105 	ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_LEFT_J |
106 			SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
107 	if (ret < 0)
108 		goto out;
109 
110 	ret = 0;
111 out:
112 	return ret;
113 }
114 
115 static struct snd_soc_ops db1200_i2s_wm8731_ops = {
116 	.startup	= db1200_i2s_startup,
117 };
118 
119 static struct snd_soc_dai_link db1200_i2s_dai = {
120 	.name		= "WM8731",
121 	.stream_name	= "WM8731 PCM",
122 	.codec_dai_name	= "wm8731-hifi",
123 	.cpu_dai_name	= "au1xpsc_i2s.1",
124 	.platform_name	= "au1xpsc-pcm.1",
125 	.codec_name	= "wm8731.0-001b",
126 	.ops		= &db1200_i2s_wm8731_ops,
127 };
128 
129 static struct snd_soc_card db1200_i2s_machine = {
130 	.name		= "DB1200_I2S",
131 	.owner		= THIS_MODULE,
132 	.dai_link	= &db1200_i2s_dai,
133 	.num_links	= 1,
134 };
135 
136 static struct snd_soc_dai_link db1300_i2s_dai = {
137 	.name		= "WM8731",
138 	.stream_name	= "WM8731 PCM",
139 	.codec_dai_name	= "wm8731-hifi",
140 	.cpu_dai_name	= "au1xpsc_i2s.2",
141 	.platform_name	= "au1xpsc-pcm.2",
142 	.codec_name	= "wm8731.0-001b",
143 	.ops		= &db1200_i2s_wm8731_ops,
144 };
145 
146 static struct snd_soc_card db1300_i2s_machine = {
147 	.name		= "DB1300_I2S",
148 	.dai_link	= &db1300_i2s_dai,
149 	.num_links	= 1,
150 };
151 
152 static struct snd_soc_dai_link db1550_i2s_dai = {
153 	.name		= "WM8731",
154 	.stream_name	= "WM8731 PCM",
155 	.codec_dai_name	= "wm8731-hifi",
156 	.cpu_dai_name	= "au1xpsc_i2s.3",
157 	.platform_name	= "au1xpsc-pcm.3",
158 	.codec_name	= "wm8731.0-001b",
159 	.ops		= &db1200_i2s_wm8731_ops,
160 };
161 
162 static struct snd_soc_card db1550_i2s_machine = {
163 	.name		= "DB1550_I2S",
164 	.dai_link	= &db1550_i2s_dai,
165 	.num_links	= 1,
166 };
167 
168 /*-------------------------  COMMON PART  ---------------------------*/
169 
170 static struct snd_soc_card *db1200_cards[] __devinitdata = {
171 	&db1200_ac97_machine,
172 	&db1200_i2s_machine,
173 	&db1300_ac97_machine,
174 	&db1300_i2s_machine,
175 	&db1550_ac97_machine,
176 	&db1550_i2s_machine,
177 };
178 
db1200_audio_probe(struct platform_device * pdev)179 static int __devinit db1200_audio_probe(struct platform_device *pdev)
180 {
181 	const struct platform_device_id *pid = platform_get_device_id(pdev);
182 	struct snd_soc_card *card;
183 
184 	card = db1200_cards[pid->driver_data];
185 	card->dev = &pdev->dev;
186 	return snd_soc_register_card(card);
187 }
188 
db1200_audio_remove(struct platform_device * pdev)189 static int __devexit db1200_audio_remove(struct platform_device *pdev)
190 {
191 	struct snd_soc_card *card = platform_get_drvdata(pdev);
192 	snd_soc_unregister_card(card);
193 	return 0;
194 }
195 
196 static struct platform_driver db1200_audio_driver = {
197 	.driver	= {
198 		.name	= "db1200-ac97",
199 		.owner	= THIS_MODULE,
200 		.pm	= &snd_soc_pm_ops,
201 	},
202 	.id_table	= db1200_pids,
203 	.probe		= db1200_audio_probe,
204 	.remove		= __devexit_p(db1200_audio_remove),
205 };
206 
207 module_platform_driver(db1200_audio_driver);
208 
209 MODULE_LICENSE("GPL");
210 MODULE_DESCRIPTION("DB1200/DB1300/DB1550 ASoC audio support");
211 MODULE_AUTHOR("Manuel Lauss");
212