blob: 823ef1e71d191e0fd6d33969f39b38188e94ec40 [file] [log] [blame]
apatard@mandriva.comf9b95982010-05-31 13:49:14 +02001/*
2 * kirkwood-i2s.c
3 *
4 * (c) 2010 Arnaud Patard <apatard@mandriva.com>
Arnaud Patard (Rtp)69737892010-09-09 14:10:33 +02005 * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
apatard@mandriva.comf9b95982010-05-31 13:49:14 +02006 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/io.h>
17#include <linux/slab.h>
18#include <linux/mbus.h>
19#include <linux/delay.h>
Andrew Lunne919c712012-03-09 09:56:41 +010020#include <linux/clk.h>
apatard@mandriva.comf9b95982010-05-31 13:49:14 +020021#include <sound/pcm.h>
22#include <sound/pcm_params.h>
23#include <sound/soc.h>
Arnd Bergmannc02cecb2012-08-24 15:21:54 +020024#include <linux/platform_data/asoc-kirkwood.h>
apatard@mandriva.comf9b95982010-05-31 13:49:14 +020025#include "kirkwood.h"
26
27#define DRV_NAME "kirkwood-i2s"
28
29#define KIRKWOOD_I2S_RATES \
30 (SNDRV_PCM_RATE_44100 | \
31 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
32#define KIRKWOOD_I2S_FORMATS \
33 (SNDRV_PCM_FMTBIT_S16_LE | \
34 SNDRV_PCM_FMTBIT_S24_LE | \
35 SNDRV_PCM_FMTBIT_S32_LE)
36
apatard@mandriva.comf9b95982010-05-31 13:49:14 +020037static int kirkwood_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
38 unsigned int fmt)
39{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000040 struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(cpu_dai);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +020041 unsigned long mask;
42 unsigned long value;
43
44 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
45 case SND_SOC_DAIFMT_RIGHT_J:
46 mask = KIRKWOOD_I2S_CTL_RJ;
47 break;
48 case SND_SOC_DAIFMT_LEFT_J:
49 mask = KIRKWOOD_I2S_CTL_LJ;
50 break;
51 case SND_SOC_DAIFMT_I2S:
52 mask = KIRKWOOD_I2S_CTL_I2S;
53 break;
54 default:
55 return -EINVAL;
56 }
57
58 /*
59 * Set same format for playback and record
60 * This avoids some troubles.
61 */
62 value = readl(priv->io+KIRKWOOD_I2S_PLAYCTL);
63 value &= ~KIRKWOOD_I2S_CTL_JUST_MASK;
64 value |= mask;
65 writel(value, priv->io+KIRKWOOD_I2S_PLAYCTL);
66
67 value = readl(priv->io+KIRKWOOD_I2S_RECCTL);
68 value &= ~KIRKWOOD_I2S_CTL_JUST_MASK;
69 value |= mask;
70 writel(value, priv->io+KIRKWOOD_I2S_RECCTL);
71
72 return 0;
73}
74
75static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate)
76{
77 unsigned long value;
78
79 value = KIRKWOOD_DCO_CTL_OFFSET_0;
80 switch (rate) {
81 default:
82 case 44100:
83 value |= KIRKWOOD_DCO_CTL_FREQ_11;
84 break;
85 case 48000:
86 value |= KIRKWOOD_DCO_CTL_FREQ_12;
87 break;
88 case 96000:
89 value |= KIRKWOOD_DCO_CTL_FREQ_24;
90 break;
91 }
92 writel(value, io + KIRKWOOD_DCO_CTL);
93
94 /* wait for dco locked */
95 do {
96 cpu_relax();
97 value = readl(io + KIRKWOOD_DCO_SPCR_STATUS);
Russell King2424d452012-11-20 12:18:32 +000098 value &= KIRKWOOD_DCO_SPCR_STATUS_DCO_LOCK;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +020099 } while (value == 0);
100}
101
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000102static int kirkwood_i2s_startup(struct snd_pcm_substream *substream,
103 struct snd_soc_dai *dai)
104{
105 struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
106
107 snd_soc_dai_set_dma_data(dai, substream, priv);
108 return 0;
109}
110
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200111static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream,
112 struct snd_pcm_hw_params *params,
113 struct snd_soc_dai *dai)
114{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000115 struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
Russell Kingd8d11ba2012-11-20 12:19:53 +0000116 uint32_t ctl_play, ctl_rec;
117 unsigned int i2s_reg;
118 unsigned long i2s_value;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200119
120 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
121 i2s_reg = KIRKWOOD_I2S_PLAYCTL;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200122 } else {
123 i2s_reg = KIRKWOOD_I2S_RECCTL;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200124 }
125
126 /* set dco conf */
127 kirkwood_set_dco(priv->io, params_rate(params));
128
129 i2s_value = readl(priv->io+i2s_reg);
130 i2s_value &= ~KIRKWOOD_I2S_CTL_SIZE_MASK;
131
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200132 /*
133 * Size settings in play/rec i2s control regs and play/rec control
134 * regs must be the same.
135 */
136 switch (params_format(params)) {
137 case SNDRV_PCM_FORMAT_S16_LE:
138 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16;
Russell Kingd8d11ba2012-11-20 12:19:53 +0000139 ctl_play = KIRKWOOD_PLAYCTL_SIZE_16_C |
140 KIRKWOOD_PLAYCTL_I2S_EN;
141 ctl_rec = KIRKWOOD_RECCTL_SIZE_16_C |
142 KIRKWOOD_RECCTL_I2S_EN;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200143 break;
144 /*
145 * doesn't work... S20_3LE != kirkwood 20bit format ?
146 *
147 case SNDRV_PCM_FORMAT_S20_3LE:
148 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_20;
Russell Kingd8d11ba2012-11-20 12:19:53 +0000149 ctl_play = KIRKWOOD_PLAYCTL_SIZE_20 |
150 KIRKWOOD_PLAYCTL_I2S_EN;
151 ctl_rec = KIRKWOOD_RECCTL_SIZE_20 |
152 KIRKWOOD_RECCTL_I2S_EN;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200153 break;
154 */
155 case SNDRV_PCM_FORMAT_S24_LE:
156 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24;
Russell Kingd8d11ba2012-11-20 12:19:53 +0000157 ctl_play = KIRKWOOD_PLAYCTL_SIZE_24 |
158 KIRKWOOD_PLAYCTL_I2S_EN;
159 ctl_rec = KIRKWOOD_RECCTL_SIZE_24 |
160 KIRKWOOD_RECCTL_I2S_EN;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200161 break;
162 case SNDRV_PCM_FORMAT_S32_LE:
163 i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32;
Russell Kingd8d11ba2012-11-20 12:19:53 +0000164 ctl_play = KIRKWOOD_PLAYCTL_SIZE_32 |
165 KIRKWOOD_PLAYCTL_I2S_EN;
166 ctl_rec = KIRKWOOD_RECCTL_SIZE_32 |
167 KIRKWOOD_RECCTL_I2S_EN;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200168 break;
169 default:
170 return -EINVAL;
171 }
arnaud.patard@rtp-net.orgdfe4c932010-07-11 23:28:31 +0200172
173 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
arnaud.patard@rtp-net.orgdfe4c932010-07-11 23:28:31 +0200174 if (params_channels(params) == 1)
Russell Kingd8d11ba2012-11-20 12:19:53 +0000175 ctl_play |= KIRKWOOD_PLAYCTL_MONO_BOTH;
arnaud.patard@rtp-net.orgdfe4c932010-07-11 23:28:31 +0200176 else
Russell Kingd8d11ba2012-11-20 12:19:53 +0000177 ctl_play |= KIRKWOOD_PLAYCTL_MONO_OFF;
178
179 priv->ctl_play &= ~(KIRKWOOD_PLAYCTL_MONO_MASK |
180 KIRKWOOD_PLAYCTL_I2S_EN |
181 KIRKWOOD_PLAYCTL_SPDIF_EN |
182 KIRKWOOD_PLAYCTL_SIZE_MASK);
183 priv->ctl_play |= ctl_play;
184 } else {
185 priv->ctl_rec &= ~KIRKWOOD_RECCTL_SIZE_MASK;
186 priv->ctl_rec |= ctl_rec;
arnaud.patard@rtp-net.orgdfe4c932010-07-11 23:28:31 +0200187 }
188
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200189 writel(i2s_value, priv->io+i2s_reg);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200190
191 return 0;
192}
193
194static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream,
195 int cmd, struct snd_soc_dai *dai)
196{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000197 struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
Russell King982b6042012-11-20 12:18:52 +0000198 uint32_t ctl, value;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200199
Russell King982b6042012-11-20 12:18:52 +0000200 ctl = readl(priv->io + KIRKWOOD_PLAYCTL);
201 if (ctl & KIRKWOOD_PLAYCTL_PAUSE) {
202 unsigned timeout = 5000;
203 /*
204 * The Armada510 spec says that if we enter pause mode, the
205 * busy bit must be read back as clear _twice_. Make sure
206 * we respect that otherwise we get DMA underruns.
207 */
208 do {
209 value = ctl;
210 ctl = readl(priv->io + KIRKWOOD_PLAYCTL);
211 if (!((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY))
212 break;
213 udelay(1);
214 } while (timeout--);
215
216 if ((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY)
217 dev_notice(dai->dev, "timed out waiting for busy to deassert: %08x\n",
218 ctl);
219 }
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200220
221 switch (cmd) {
222 case SNDRV_PCM_TRIGGER_START:
Russell Kingd8d11ba2012-11-20 12:19:53 +0000223 /* configure */
224 ctl = priv->ctl_play;
225 value = ctl & ~(KIRKWOOD_PLAYCTL_I2S_EN |
226 KIRKWOOD_PLAYCTL_SPDIF_EN);
227 writel(value, priv->io + KIRKWOOD_PLAYCTL);
228
229 /* enable interrupts */
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200230 value = readl(priv->io + KIRKWOOD_INT_MASK);
231 value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES;
232 writel(value, priv->io + KIRKWOOD_INT_MASK);
233
Russell Kingd8d11ba2012-11-20 12:19:53 +0000234 /* enable playback */
Russell King982b6042012-11-20 12:18:52 +0000235 writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200236 break;
237
238 case SNDRV_PCM_TRIGGER_STOP:
239 /* stop audio, disable interrupts */
Russell King982b6042012-11-20 12:18:52 +0000240 ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE;
241 writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200242
243 value = readl(priv->io + KIRKWOOD_INT_MASK);
244 value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES;
245 writel(value, priv->io + KIRKWOOD_INT_MASK);
246
247 /* disable all playbacks */
Russell King982b6042012-11-20 12:18:52 +0000248 ctl &= ~(KIRKWOOD_PLAYCTL_I2S_EN | KIRKWOOD_PLAYCTL_SPDIF_EN);
249 writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200250 break;
251
252 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
253 case SNDRV_PCM_TRIGGER_SUSPEND:
Russell King982b6042012-11-20 12:18:52 +0000254 ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE;
255 writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200256 break;
257
258 case SNDRV_PCM_TRIGGER_RESUME:
259 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
Russell King982b6042012-11-20 12:18:52 +0000260 ctl &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE);
261 writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200262 break;
263
264 default:
265 return -EINVAL;
266 }
267
268 return 0;
269}
270
271static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream,
272 int cmd, struct snd_soc_dai *dai)
273{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000274 struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
Russell Kingd8d11ba2012-11-20 12:19:53 +0000275 uint32_t ctl, value;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200276
277 value = readl(priv->io + KIRKWOOD_RECCTL);
278
279 switch (cmd) {
280 case SNDRV_PCM_TRIGGER_START:
Russell Kingd8d11ba2012-11-20 12:19:53 +0000281 /* configure */
282 ctl = priv->ctl_rec;
283 value = ctl & ~KIRKWOOD_RECCTL_I2S_EN;
284 writel(value, priv->io + KIRKWOOD_RECCTL);
285
286 /* enable interrupts */
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200287 value = readl(priv->io + KIRKWOOD_INT_MASK);
288 value |= KIRKWOOD_INT_CAUSE_REC_BYTES;
289 writel(value, priv->io + KIRKWOOD_INT_MASK);
290
Russell Kingd8d11ba2012-11-20 12:19:53 +0000291 /* enable record */
292 writel(ctl, priv->io + KIRKWOOD_RECCTL);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200293 break;
294
295 case SNDRV_PCM_TRIGGER_STOP:
296 /* stop audio, disable interrupts */
297 value = readl(priv->io + KIRKWOOD_RECCTL);
arnaud.patard@rtp-net.orgb424ec92010-07-11 23:28:32 +0200298 value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200299 writel(value, priv->io + KIRKWOOD_RECCTL);
300
301 value = readl(priv->io + KIRKWOOD_INT_MASK);
302 value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES;
303 writel(value, priv->io + KIRKWOOD_INT_MASK);
304
305 /* disable all records */
306 value = readl(priv->io + KIRKWOOD_RECCTL);
307 value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN);
308 writel(value, priv->io + KIRKWOOD_RECCTL);
309 break;
310
311 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
312 case SNDRV_PCM_TRIGGER_SUSPEND:
313 value = readl(priv->io + KIRKWOOD_RECCTL);
arnaud.patard@rtp-net.orgb424ec92010-07-11 23:28:32 +0200314 value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200315 writel(value, priv->io + KIRKWOOD_RECCTL);
316 break;
317
318 case SNDRV_PCM_TRIGGER_RESUME:
319 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
320 value = readl(priv->io + KIRKWOOD_RECCTL);
arnaud.patard@rtp-net.orgb424ec92010-07-11 23:28:32 +0200321 value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200322 writel(value, priv->io + KIRKWOOD_RECCTL);
323 break;
324
325 default:
326 return -EINVAL;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200327 }
328
329 return 0;
330}
331
332static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
333 struct snd_soc_dai *dai)
334{
335 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
336 return kirkwood_i2s_play_trigger(substream, cmd, dai);
337 else
338 return kirkwood_i2s_rec_trigger(substream, cmd, dai);
339
340 return 0;
341}
342
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000343static int kirkwood_i2s_probe(struct snd_soc_dai *dai)
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200344{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000345 struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200346 unsigned long value;
347 unsigned int reg_data;
348
349 /* put system in a "safe" state : */
350 /* disable audio interrupts */
351 writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE);
352 writel(0, priv->io + KIRKWOOD_INT_MASK);
353
354 reg_data = readl(priv->io + 0x1200);
355 reg_data &= (~(0x333FF8));
356 reg_data |= 0x111D18;
357 writel(reg_data, priv->io + 0x1200);
358
359 msleep(500);
360
361 reg_data = readl(priv->io + 0x1200);
362 reg_data &= (~(0x333FF8));
363 reg_data |= 0x111D18;
364 writel(reg_data, priv->io + 0x1200);
365
366 /* disable playback/record */
367 value = readl(priv->io + KIRKWOOD_PLAYCTL);
368 value &= ~(KIRKWOOD_PLAYCTL_I2S_EN|KIRKWOOD_PLAYCTL_SPDIF_EN);
369 writel(value, priv->io + KIRKWOOD_PLAYCTL);
370
371 value = readl(priv->io + KIRKWOOD_RECCTL);
372 value &= ~(KIRKWOOD_RECCTL_I2S_EN | KIRKWOOD_RECCTL_SPDIF_EN);
373 writel(value, priv->io + KIRKWOOD_RECCTL);
374
375 return 0;
376
377}
378
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000379static int kirkwood_i2s_remove(struct snd_soc_dai *dai)
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200380{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000381 return 0;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200382}
383
Lars-Peter Clausen85e76522011-11-23 11:40:40 +0100384static const struct snd_soc_dai_ops kirkwood_i2s_dai_ops = {
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000385 .startup = kirkwood_i2s_startup,
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200386 .trigger = kirkwood_i2s_trigger,
387 .hw_params = kirkwood_i2s_hw_params,
388 .set_fmt = kirkwood_i2s_set_fmt,
389};
390
391
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000392static struct snd_soc_dai_driver kirkwood_i2s_dai = {
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200393 .probe = kirkwood_i2s_probe,
394 .remove = kirkwood_i2s_remove,
395 .playback = {
396 .channels_min = 1,
397 .channels_max = 2,
398 .rates = KIRKWOOD_I2S_RATES,
399 .formats = KIRKWOOD_I2S_FORMATS,},
400 .capture = {
401 .channels_min = 1,
402 .channels_max = 2,
403 .rates = KIRKWOOD_I2S_RATES,
404 .formats = KIRKWOOD_I2S_FORMATS,},
405 .ops = &kirkwood_i2s_dai_ops,
406};
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200407
408static __devinit int kirkwood_i2s_dev_probe(struct platform_device *pdev)
409{
410 struct resource *mem;
411 struct kirkwood_asoc_platform_data *data =
412 pdev->dev.platform_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000413 struct kirkwood_dma_data *priv;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200414 int err;
415
Russell Kingdbc517b2012-11-20 12:19:33 +0000416 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200417 if (!priv) {
418 dev_err(&pdev->dev, "allocation failed\n");
Russell Kingdbc517b2012-11-20 12:19:33 +0000419 return -ENOMEM;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200420 }
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000421 dev_set_drvdata(&pdev->dev, priv);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200422
423 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
424 if (!mem) {
425 dev_err(&pdev->dev, "platform_get_resource failed\n");
Russell Kingdbc517b2012-11-20 12:19:33 +0000426 return -ENXIO;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200427 }
428
Russell Kingdbc517b2012-11-20 12:19:33 +0000429 priv->io = devm_request_and_ioremap(&pdev->dev, mem);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200430 if (!priv->io) {
Russell Kingdbc517b2012-11-20 12:19:33 +0000431 dev_err(&pdev->dev, "devm_request_and_ioremap failed\n");
432 return -ENOMEM;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200433 }
434
435 priv->irq = platform_get_irq(pdev, 0);
436 if (priv->irq <= 0) {
437 dev_err(&pdev->dev, "platform_get_irq failed\n");
Russell Kingdbc517b2012-11-20 12:19:33 +0000438 return -ENXIO;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200439 }
440
Axel Lind4d98202011-12-28 16:05:22 +0800441 if (!data) {
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200442 dev_err(&pdev->dev, "no platform data ?!\n");
Russell Kingdbc517b2012-11-20 12:19:33 +0000443 return -EINVAL;
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200444 }
445
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200446 priv->burst = data->burst;
447
Russell Kingdbc517b2012-11-20 12:19:33 +0000448 priv->clk = devm_clk_get(&pdev->dev, NULL);
Andrew Lunne919c712012-03-09 09:56:41 +0100449 if (IS_ERR(priv->clk)) {
450 dev_err(&pdev->dev, "no clock\n");
Russell Kingdbc517b2012-11-20 12:19:33 +0000451 return PTR_ERR(priv->clk);
Andrew Lunne919c712012-03-09 09:56:41 +0100452 }
Russell Kingdbc517b2012-11-20 12:19:33 +0000453
454 err = clk_prepare_enable(priv->clk);
455 if (err < 0)
456 return err;
Andrew Lunne919c712012-03-09 09:56:41 +0100457
Russell Kingd8d11ba2012-11-20 12:19:53 +0000458 priv->extclk = clk_get(&pdev->dev, "extclk");
459 if (!IS_ERR(priv->extclk)) {
460 if (priv->extclk == priv->clk) {
461 clk_put(priv->extclk);
462 priv->extclk = ERR_PTR(-EINVAL);
463 } else {
464 dev_info(&pdev->dev, "found external clock\n");
465 clk_prepare_enable(priv->extclk);
466 soc_dai = &kirkwood_i2s_dai_extclk;
467 }
468 }
469
470 /* Some sensible defaults - this reflects the powerup values */
471 priv->ctl_play = KIRKWOOD_PLAYCTL_SIZE_24;
472 priv->ctl_rec = KIRKWOOD_RECCTL_SIZE_24;
473
474 /* Select the burst size */
475 if (data->burst == 32) {
476 priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_32;
477 priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_32;
478 } else {
479 priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_128;
480 priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_128;
481 }
482
Simon Baatzbaffab22012-07-19 00:04:09 +0200483 err = snd_soc_register_dai(&pdev->dev, &kirkwood_i2s_dai);
484 if (!err)
485 return 0;
486 dev_err(&pdev->dev, "snd_soc_register_dai failed\n");
487
488 clk_disable_unprepare(priv->clk);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200489
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200490 return err;
491}
492
493static __devexit int kirkwood_i2s_dev_remove(struct platform_device *pdev)
494{
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000495 struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev);
496
497 snd_soc_unregister_dai(&pdev->dev);
Andrew Lunne919c712012-03-09 09:56:41 +0100498
499 clk_disable_unprepare(priv->clk);
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +0000500
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200501 return 0;
502}
503
504static struct platform_driver kirkwood_i2s_driver = {
505 .probe = kirkwood_i2s_dev_probe,
Axel Lin48860e42011-10-02 09:18:17 +0800506 .remove = __devexit_p(kirkwood_i2s_dev_remove),
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200507 .driver = {
508 .name = DRV_NAME,
509 .owner = THIS_MODULE,
510 },
511};
512
Axel Lin41b10222011-11-24 11:43:09 +0800513module_platform_driver(kirkwood_i2s_driver);
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200514
515/* Module information */
Arnaud Patard (Rtp)69737892010-09-09 14:10:33 +0200516MODULE_AUTHOR("Arnaud Patard, <arnaud.patard@rtp-net.org>");
apatard@mandriva.comf9b95982010-05-31 13:49:14 +0200517MODULE_DESCRIPTION("Kirkwood I2S SoC Interface");
518MODULE_LICENSE("GPL");
519MODULE_ALIAS("platform:kirkwood-i2s");