Commit | Line | Data |
---|---|---|
f9b95980 | 1 | /* |
2 | * kirkwood-i2s.c | |
3 | * | |
4 | * (c) 2010 Arnaud Patard <apatard@mandriva.com> | |
69737897 | 5 | * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org> |
f9b95980 | 6 | * |
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> | |
e919c716 | 20 | #include <linux/clk.h> |
f9b95980 | 21 | #include <sound/pcm.h> |
22 | #include <sound/pcm_params.h> | |
23 | #include <sound/soc.h> | |
c02cecb9 | 24 | #include <linux/platform_data/asoc-kirkwood.h> |
eb632318 JFM |
25 | #include <linux/of.h> |
26 | ||
f9b95980 | 27 | #include "kirkwood.h" |
28 | ||
64ddf1f8 | 29 | #define DRV_NAME "mvebu-audio" |
f9b95980 | 30 | |
f9b95980 | 31 | #define KIRKWOOD_I2S_FORMATS \ |
32 | (SNDRV_PCM_FMTBIT_S16_LE | \ | |
33 | SNDRV_PCM_FMTBIT_S24_LE | \ | |
34 | SNDRV_PCM_FMTBIT_S32_LE) | |
35 | ||
1c195ddb JFM |
36 | #define KIRKWOOD_SPDIF_FORMATS \ |
37 | (SNDRV_PCM_FMTBIT_S16_LE | \ | |
38 | SNDRV_PCM_FMTBIT_S24_LE) | |
39 | ||
f9b95980 | 40 | static int kirkwood_i2s_set_fmt(struct snd_soc_dai *cpu_dai, |
41 | unsigned int fmt) | |
42 | { | |
f0fba2ad | 43 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(cpu_dai); |
f9b95980 | 44 | unsigned long mask; |
45 | unsigned long value; | |
46 | ||
47 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { | |
48 | case SND_SOC_DAIFMT_RIGHT_J: | |
49 | mask = KIRKWOOD_I2S_CTL_RJ; | |
50 | break; | |
51 | case SND_SOC_DAIFMT_LEFT_J: | |
52 | mask = KIRKWOOD_I2S_CTL_LJ; | |
53 | break; | |
54 | case SND_SOC_DAIFMT_I2S: | |
55 | mask = KIRKWOOD_I2S_CTL_I2S; | |
56 | break; | |
57 | default: | |
58 | return -EINVAL; | |
59 | } | |
60 | ||
61 | /* | |
62 | * Set same format for playback and record | |
63 | * This avoids some troubles. | |
64 | */ | |
65 | value = readl(priv->io+KIRKWOOD_I2S_PLAYCTL); | |
66 | value &= ~KIRKWOOD_I2S_CTL_JUST_MASK; | |
67 | value |= mask; | |
68 | writel(value, priv->io+KIRKWOOD_I2S_PLAYCTL); | |
69 | ||
70 | value = readl(priv->io+KIRKWOOD_I2S_RECCTL); | |
71 | value &= ~KIRKWOOD_I2S_CTL_JUST_MASK; | |
72 | value |= mask; | |
73 | writel(value, priv->io+KIRKWOOD_I2S_RECCTL); | |
74 | ||
75 | return 0; | |
76 | } | |
77 | ||
78 | static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate) | |
79 | { | |
80 | unsigned long value; | |
81 | ||
82 | value = KIRKWOOD_DCO_CTL_OFFSET_0; | |
83 | switch (rate) { | |
84 | default: | |
85 | case 44100: | |
86 | value |= KIRKWOOD_DCO_CTL_FREQ_11; | |
87 | break; | |
88 | case 48000: | |
89 | value |= KIRKWOOD_DCO_CTL_FREQ_12; | |
90 | break; | |
91 | case 96000: | |
92 | value |= KIRKWOOD_DCO_CTL_FREQ_24; | |
93 | break; | |
94 | } | |
95 | writel(value, io + KIRKWOOD_DCO_CTL); | |
96 | ||
97 | /* wait for dco locked */ | |
98 | do { | |
99 | cpu_relax(); | |
100 | value = readl(io + KIRKWOOD_DCO_SPCR_STATUS); | |
2424d458 | 101 | value &= KIRKWOOD_DCO_SPCR_STATUS_DCO_LOCK; |
f9b95980 | 102 | } while (value == 0); |
103 | } | |
104 | ||
363589bf RK |
105 | static void kirkwood_set_rate(struct snd_soc_dai *dai, |
106 | struct kirkwood_dma_data *priv, unsigned long rate) | |
107 | { | |
108 | uint32_t clks_ctrl; | |
109 | ||
1f1b6579 | 110 | if (IS_ERR(priv->extclk)) { |
8a537f85 JFM |
111 | /* use internal dco for the supported rates |
112 | * defined in kirkwood_i2s_dai */ | |
363589bf RK |
113 | dev_dbg(dai->dev, "%s: dco set rate = %lu\n", |
114 | __func__, rate); | |
115 | kirkwood_set_dco(priv->io, rate); | |
116 | ||
117 | clks_ctrl = KIRKWOOD_MCLK_SOURCE_DCO; | |
8a537f85 JFM |
118 | } else { |
119 | /* use the external clock for the other rates | |
120 | * defined in kirkwood_i2s_dai_extclk */ | |
363589bf RK |
121 | dev_dbg(dai->dev, "%s: extclk set rate = %lu -> %lu\n", |
122 | __func__, rate, 256 * rate); | |
123 | clk_set_rate(priv->extclk, 256 * rate); | |
124 | ||
125 | clks_ctrl = KIRKWOOD_MCLK_SOURCE_EXTCLK; | |
126 | } | |
127 | writel(clks_ctrl, priv->io + KIRKWOOD_CLOCKS_CTRL); | |
128 | } | |
129 | ||
f0fba2ad LG |
130 | static int kirkwood_i2s_startup(struct snd_pcm_substream *substream, |
131 | struct snd_soc_dai *dai) | |
132 | { | |
133 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); | |
134 | ||
135 | snd_soc_dai_set_dma_data(dai, substream, priv); | |
136 | return 0; | |
137 | } | |
138 | ||
f9b95980 | 139 | static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream, |
140 | struct snd_pcm_hw_params *params, | |
141 | struct snd_soc_dai *dai) | |
142 | { | |
f0fba2ad | 143 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
d8d11ba5 RK |
144 | uint32_t ctl_play, ctl_rec; |
145 | unsigned int i2s_reg; | |
146 | unsigned long i2s_value; | |
f9b95980 | 147 | |
148 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | |
149 | i2s_reg = KIRKWOOD_I2S_PLAYCTL; | |
f9b95980 | 150 | } else { |
151 | i2s_reg = KIRKWOOD_I2S_RECCTL; | |
f9b95980 | 152 | } |
153 | ||
363589bf | 154 | kirkwood_set_rate(dai, priv, params_rate(params)); |
f9b95980 | 155 | |
156 | i2s_value = readl(priv->io+i2s_reg); | |
157 | i2s_value &= ~KIRKWOOD_I2S_CTL_SIZE_MASK; | |
158 | ||
f9b95980 | 159 | /* |
160 | * Size settings in play/rec i2s control regs and play/rec control | |
161 | * regs must be the same. | |
162 | */ | |
163 | switch (params_format(params)) { | |
164 | case SNDRV_PCM_FORMAT_S16_LE: | |
165 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16; | |
d8d11ba5 | 166 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_16_C | |
75b9b65e JFM |
167 | KIRKWOOD_PLAYCTL_I2S_EN | |
168 | KIRKWOOD_PLAYCTL_SPDIF_EN; | |
d8d11ba5 | 169 | ctl_rec = KIRKWOOD_RECCTL_SIZE_16_C | |
75b9b65e JFM |
170 | KIRKWOOD_RECCTL_I2S_EN | |
171 | KIRKWOOD_RECCTL_SPDIF_EN; | |
f9b95980 | 172 | break; |
173 | /* | |
174 | * doesn't work... S20_3LE != kirkwood 20bit format ? | |
175 | * | |
176 | case SNDRV_PCM_FORMAT_S20_3LE: | |
177 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_20; | |
d8d11ba5 RK |
178 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_20 | |
179 | KIRKWOOD_PLAYCTL_I2S_EN; | |
180 | ctl_rec = KIRKWOOD_RECCTL_SIZE_20 | | |
181 | KIRKWOOD_RECCTL_I2S_EN; | |
f9b95980 | 182 | break; |
183 | */ | |
184 | case SNDRV_PCM_FORMAT_S24_LE: | |
185 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24; | |
d8d11ba5 | 186 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_24 | |
75b9b65e JFM |
187 | KIRKWOOD_PLAYCTL_I2S_EN | |
188 | KIRKWOOD_PLAYCTL_SPDIF_EN; | |
d8d11ba5 | 189 | ctl_rec = KIRKWOOD_RECCTL_SIZE_24 | |
75b9b65e JFM |
190 | KIRKWOOD_RECCTL_I2S_EN | |
191 | KIRKWOOD_RECCTL_SPDIF_EN; | |
f9b95980 | 192 | break; |
193 | case SNDRV_PCM_FORMAT_S32_LE: | |
194 | i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32; | |
d8d11ba5 RK |
195 | ctl_play = KIRKWOOD_PLAYCTL_SIZE_32 | |
196 | KIRKWOOD_PLAYCTL_I2S_EN; | |
197 | ctl_rec = KIRKWOOD_RECCTL_SIZE_32 | | |
198 | KIRKWOOD_RECCTL_I2S_EN; | |
f9b95980 | 199 | break; |
200 | default: | |
201 | return -EINVAL; | |
202 | } | |
dfe4c936 | 203 | |
204 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | |
dfe4c936 | 205 | if (params_channels(params) == 1) |
d8d11ba5 | 206 | ctl_play |= KIRKWOOD_PLAYCTL_MONO_BOTH; |
dfe4c936 | 207 | else |
d8d11ba5 RK |
208 | ctl_play |= KIRKWOOD_PLAYCTL_MONO_OFF; |
209 | ||
210 | priv->ctl_play &= ~(KIRKWOOD_PLAYCTL_MONO_MASK | | |
db43b16f | 211 | KIRKWOOD_PLAYCTL_ENABLE_MASK | |
d8d11ba5 RK |
212 | KIRKWOOD_PLAYCTL_SIZE_MASK); |
213 | priv->ctl_play |= ctl_play; | |
214 | } else { | |
67721906 RK |
215 | priv->ctl_rec &= ~(KIRKWOOD_RECCTL_ENABLE_MASK | |
216 | KIRKWOOD_RECCTL_SIZE_MASK); | |
d8d11ba5 | 217 | priv->ctl_rec |= ctl_rec; |
dfe4c936 | 218 | } |
219 | ||
f9b95980 | 220 | writel(i2s_value, priv->io+i2s_reg); |
f9b95980 | 221 | |
222 | return 0; | |
223 | } | |
224 | ||
2fbc3821 RK |
225 | static unsigned kirkwood_i2s_play_mute(unsigned ctl) |
226 | { | |
227 | if (!(ctl & KIRKWOOD_PLAYCTL_I2S_EN)) | |
228 | ctl |= KIRKWOOD_PLAYCTL_I2S_MUTE; | |
229 | if (!(ctl & KIRKWOOD_PLAYCTL_SPDIF_EN)) | |
230 | ctl |= KIRKWOOD_PLAYCTL_SPDIF_MUTE; | |
231 | return ctl; | |
232 | } | |
233 | ||
f9b95980 | 234 | static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream, |
235 | int cmd, struct snd_soc_dai *dai) | |
236 | { | |
920ec4e5 | 237 | struct snd_pcm_runtime *runtime = substream->runtime; |
f0fba2ad | 238 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
982b604b RK |
239 | uint32_t ctl, value; |
240 | ||
241 | ctl = readl(priv->io + KIRKWOOD_PLAYCTL); | |
4d2097e5 | 242 | if ((ctl & KIRKWOOD_PLAYCTL_ENABLE_MASK) == 0) { |
982b604b RK |
243 | unsigned timeout = 5000; |
244 | /* | |
245 | * The Armada510 spec says that if we enter pause mode, the | |
246 | * busy bit must be read back as clear _twice_. Make sure | |
247 | * we respect that otherwise we get DMA underruns. | |
248 | */ | |
249 | do { | |
250 | value = ctl; | |
251 | ctl = readl(priv->io + KIRKWOOD_PLAYCTL); | |
252 | if (!((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY)) | |
253 | break; | |
254 | udelay(1); | |
255 | } while (timeout--); | |
256 | ||
257 | if ((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY) | |
258 | dev_notice(dai->dev, "timed out waiting for busy to deassert: %08x\n", | |
259 | ctl); | |
260 | } | |
f9b95980 | 261 | |
262 | switch (cmd) { | |
263 | case SNDRV_PCM_TRIGGER_START: | |
d8d11ba5 RK |
264 | /* configure */ |
265 | ctl = priv->ctl_play; | |
4f6f1478 JFM |
266 | if (dai->id == 0) |
267 | ctl &= ~KIRKWOOD_PLAYCTL_SPDIF_EN; /* i2s */ | |
268 | else | |
269 | ctl &= ~KIRKWOOD_PLAYCTL_I2S_EN; /* spdif */ | |
2fbc3821 | 270 | ctl = kirkwood_i2s_play_mute(ctl); |
db43b16f | 271 | value = ctl & ~KIRKWOOD_PLAYCTL_ENABLE_MASK; |
d8d11ba5 RK |
272 | writel(value, priv->io + KIRKWOOD_PLAYCTL); |
273 | ||
274 | /* enable interrupts */ | |
920ec4e5 RK |
275 | if (!runtime->no_period_wakeup) { |
276 | value = readl(priv->io + KIRKWOOD_INT_MASK); | |
277 | value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES; | |
278 | writel(value, priv->io + KIRKWOOD_INT_MASK); | |
279 | } | |
f9b95980 | 280 | |
d8d11ba5 | 281 | /* enable playback */ |
982b604b | 282 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
f9b95980 | 283 | break; |
284 | ||
285 | case SNDRV_PCM_TRIGGER_STOP: | |
286 | /* stop audio, disable interrupts */ | |
75b9b65e JFM |
287 | ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE | |
288 | KIRKWOOD_PLAYCTL_SPDIF_MUTE; | |
982b604b | 289 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
f9b95980 | 290 | |
291 | value = readl(priv->io + KIRKWOOD_INT_MASK); | |
292 | value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES; | |
293 | writel(value, priv->io + KIRKWOOD_INT_MASK); | |
294 | ||
295 | /* disable all playbacks */ | |
db43b16f | 296 | ctl &= ~KIRKWOOD_PLAYCTL_ENABLE_MASK; |
982b604b | 297 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
f9b95980 | 298 | break; |
299 | ||
300 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | |
301 | case SNDRV_PCM_TRIGGER_SUSPEND: | |
75b9b65e JFM |
302 | ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE | |
303 | KIRKWOOD_PLAYCTL_SPDIF_MUTE; | |
982b604b | 304 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
f9b95980 | 305 | break; |
306 | ||
307 | case SNDRV_PCM_TRIGGER_RESUME: | |
308 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | |
75b9b65e JFM |
309 | ctl &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE | |
310 | KIRKWOOD_PLAYCTL_SPDIF_MUTE); | |
2fbc3821 | 311 | ctl = kirkwood_i2s_play_mute(ctl); |
982b604b | 312 | writel(ctl, priv->io + KIRKWOOD_PLAYCTL); |
f9b95980 | 313 | break; |
314 | ||
315 | default: | |
316 | return -EINVAL; | |
317 | } | |
318 | ||
319 | return 0; | |
320 | } | |
321 | ||
322 | static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream, | |
323 | int cmd, struct snd_soc_dai *dai) | |
324 | { | |
f0fba2ad | 325 | struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai); |
d8d11ba5 | 326 | uint32_t ctl, value; |
f9b95980 | 327 | |
328 | value = readl(priv->io + KIRKWOOD_RECCTL); | |
329 | ||
330 | switch (cmd) { | |
331 | case SNDRV_PCM_TRIGGER_START: | |
d8d11ba5 RK |
332 | /* configure */ |
333 | ctl = priv->ctl_rec; | |
75b9b65e JFM |
334 | if (dai->id == 0) |
335 | ctl &= ~KIRKWOOD_RECCTL_SPDIF_EN; /* i2s */ | |
336 | else | |
337 | ctl &= ~KIRKWOOD_RECCTL_I2S_EN; /* spdif */ | |
338 | ||
52b896cf | 339 | value = ctl & ~KIRKWOOD_RECCTL_ENABLE_MASK; |
d8d11ba5 RK |
340 | writel(value, priv->io + KIRKWOOD_RECCTL); |
341 | ||
342 | /* enable interrupts */ | |
f9b95980 | 343 | value = readl(priv->io + KIRKWOOD_INT_MASK); |
344 | value |= KIRKWOOD_INT_CAUSE_REC_BYTES; | |
345 | writel(value, priv->io + KIRKWOOD_INT_MASK); | |
346 | ||
d8d11ba5 RK |
347 | /* enable record */ |
348 | writel(ctl, priv->io + KIRKWOOD_RECCTL); | |
f9b95980 | 349 | break; |
350 | ||
351 | case SNDRV_PCM_TRIGGER_STOP: | |
352 | /* stop audio, disable interrupts */ | |
353 | value = readl(priv->io + KIRKWOOD_RECCTL); | |
b424ec95 | 354 | value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; |
f9b95980 | 355 | writel(value, priv->io + KIRKWOOD_RECCTL); |
356 | ||
357 | value = readl(priv->io + KIRKWOOD_INT_MASK); | |
358 | value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES; | |
359 | writel(value, priv->io + KIRKWOOD_INT_MASK); | |
360 | ||
361 | /* disable all records */ | |
362 | value = readl(priv->io + KIRKWOOD_RECCTL); | |
52b896cf | 363 | value &= ~KIRKWOOD_RECCTL_ENABLE_MASK; |
f9b95980 | 364 | writel(value, priv->io + KIRKWOOD_RECCTL); |
365 | break; | |
366 | ||
367 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: | |
368 | case SNDRV_PCM_TRIGGER_SUSPEND: | |
369 | value = readl(priv->io + KIRKWOOD_RECCTL); | |
b424ec95 | 370 | value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE; |
f9b95980 | 371 | writel(value, priv->io + KIRKWOOD_RECCTL); |
372 | break; | |
373 | ||
374 | case SNDRV_PCM_TRIGGER_RESUME: | |
375 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: | |
376 | value = readl(priv->io + KIRKWOOD_RECCTL); | |
b424ec95 | 377 | value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE); |
f9b95980 | 378 | writel(value, priv->io + KIRKWOOD_RECCTL); |
379 | break; | |
380 | ||
381 | default: | |
382 | return -EINVAL; | |
f9b95980 | 383 | } |
384 | ||
385 | return 0; | |
386 | } | |
387 | ||
388 | static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd, | |
389 | struct snd_soc_dai *dai) | |
390 | { | |
391 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | |
392 | return kirkwood_i2s_play_trigger(substream, cmd, dai); | |
393 | else | |
394 | return kirkwood_i2s_rec_trigger(substream, cmd, dai); | |
395 | ||
396 | return 0; | |
397 | } | |
398 | ||
75b9b65e | 399 | static int kirkwood_i2s_init(struct kirkwood_dma_data *priv) |
f9b95980 | 400 | { |
401 | unsigned long value; | |
402 | unsigned int reg_data; | |
403 | ||
404 | /* put system in a "safe" state : */ | |
405 | /* disable audio interrupts */ | |
406 | writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE); | |
407 | writel(0, priv->io + KIRKWOOD_INT_MASK); | |
408 | ||
409 | reg_data = readl(priv->io + 0x1200); | |
410 | reg_data &= (~(0x333FF8)); | |
411 | reg_data |= 0x111D18; | |
412 | writel(reg_data, priv->io + 0x1200); | |
413 | ||
414 | msleep(500); | |
415 | ||
416 | reg_data = readl(priv->io + 0x1200); | |
417 | reg_data &= (~(0x333FF8)); | |
418 | reg_data |= 0x111D18; | |
419 | writel(reg_data, priv->io + 0x1200); | |
420 | ||
421 | /* disable playback/record */ | |
422 | value = readl(priv->io + KIRKWOOD_PLAYCTL); | |
db43b16f | 423 | value &= ~KIRKWOOD_PLAYCTL_ENABLE_MASK; |
f9b95980 | 424 | writel(value, priv->io + KIRKWOOD_PLAYCTL); |
425 | ||
426 | value = readl(priv->io + KIRKWOOD_RECCTL); | |
52b896cf | 427 | value &= ~KIRKWOOD_RECCTL_ENABLE_MASK; |
f9b95980 | 428 | writel(value, priv->io + KIRKWOOD_RECCTL); |
429 | ||
430 | return 0; | |
431 | ||
432 | } | |
433 | ||
85e7652d | 434 | static const struct snd_soc_dai_ops kirkwood_i2s_dai_ops = { |
f0fba2ad | 435 | .startup = kirkwood_i2s_startup, |
f9b95980 | 436 | .trigger = kirkwood_i2s_trigger, |
437 | .hw_params = kirkwood_i2s_hw_params, | |
438 | .set_fmt = kirkwood_i2s_set_fmt, | |
439 | }; | |
440 | ||
75b9b65e JFM |
441 | static struct snd_soc_dai_driver kirkwood_i2s_dai[2] = { |
442 | { | |
443 | .name = "i2s", | |
444 | .id = 0, | |
445 | .playback = { | |
446 | .channels_min = 1, | |
447 | .channels_max = 2, | |
448 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | | |
449 | SNDRV_PCM_RATE_96000, | |
450 | .formats = KIRKWOOD_I2S_FORMATS, | |
451 | }, | |
452 | .capture = { | |
453 | .channels_min = 1, | |
454 | .channels_max = 2, | |
455 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | | |
456 | SNDRV_PCM_RATE_96000, | |
457 | .formats = KIRKWOOD_I2S_FORMATS, | |
458 | }, | |
459 | .ops = &kirkwood_i2s_dai_ops, | |
460 | }, | |
461 | { | |
462 | .name = "spdif", | |
463 | .id = 1, | |
f9b95980 | 464 | .playback = { |
465 | .channels_min = 1, | |
466 | .channels_max = 2, | |
9e12cbd9 MB |
467 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
468 | SNDRV_PCM_RATE_96000, | |
1c195ddb | 469 | .formats = KIRKWOOD_SPDIF_FORMATS, |
363589bf | 470 | }, |
f9b95980 | 471 | .capture = { |
472 | .channels_min = 1, | |
473 | .channels_max = 2, | |
9e12cbd9 MB |
474 | .rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
475 | SNDRV_PCM_RATE_96000, | |
1c195ddb | 476 | .formats = KIRKWOOD_SPDIF_FORMATS, |
363589bf RK |
477 | }, |
478 | .ops = &kirkwood_i2s_dai_ops, | |
75b9b65e | 479 | }, |
363589bf RK |
480 | }; |
481 | ||
75b9b65e JFM |
482 | static struct snd_soc_dai_driver kirkwood_i2s_dai_extclk[2] = { |
483 | { | |
484 | .name = "i2s", | |
485 | .id = 0, | |
486 | .playback = { | |
487 | .channels_min = 1, | |
488 | .channels_max = 2, | |
02fc17c1 JFM |
489 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
490 | .rate_min = 5512, | |
491 | .rate_max = 192000, | |
75b9b65e JFM |
492 | .formats = KIRKWOOD_I2S_FORMATS, |
493 | }, | |
494 | .capture = { | |
495 | .channels_min = 1, | |
496 | .channels_max = 2, | |
02fc17c1 JFM |
497 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
498 | .rate_min = 5512, | |
499 | .rate_max = 192000, | |
75b9b65e JFM |
500 | .formats = KIRKWOOD_I2S_FORMATS, |
501 | }, | |
502 | .ops = &kirkwood_i2s_dai_ops, | |
503 | }, | |
504 | { | |
505 | .name = "spdif", | |
506 | .id = 1, | |
363589bf RK |
507 | .playback = { |
508 | .channels_min = 1, | |
509 | .channels_max = 2, | |
02fc17c1 JFM |
510 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
511 | .rate_min = 5512, | |
512 | .rate_max = 192000, | |
1c195ddb | 513 | .formats = KIRKWOOD_SPDIF_FORMATS, |
363589bf RK |
514 | }, |
515 | .capture = { | |
516 | .channels_min = 1, | |
517 | .channels_max = 2, | |
02fc17c1 JFM |
518 | .rates = SNDRV_PCM_RATE_CONTINUOUS, |
519 | .rate_min = 5512, | |
520 | .rate_max = 192000, | |
1c195ddb | 521 | .formats = KIRKWOOD_SPDIF_FORMATS, |
363589bf | 522 | }, |
f9b95980 | 523 | .ops = &kirkwood_i2s_dai_ops, |
75b9b65e | 524 | }, |
f9b95980 | 525 | }; |
f9b95980 | 526 | |
83d85f53 KM |
527 | static const struct snd_soc_component_driver kirkwood_i2s_component = { |
528 | .name = DRV_NAME, | |
529 | }; | |
530 | ||
34e15fbd | 531 | static int kirkwood_i2s_dev_probe(struct platform_device *pdev) |
f9b95980 | 532 | { |
363589bf | 533 | struct kirkwood_asoc_platform_data *data = pdev->dev.platform_data; |
75b9b65e | 534 | struct snd_soc_dai_driver *soc_dai = kirkwood_i2s_dai; |
f0fba2ad | 535 | struct kirkwood_dma_data *priv; |
363589bf | 536 | struct resource *mem; |
eb632318 | 537 | struct device_node *np = pdev->dev.of_node; |
f9b95980 | 538 | int err; |
539 | ||
dbc517bf | 540 | priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); |
c7591edc | 541 | if (!priv) |
dbc517bf | 542 | return -ENOMEM; |
c7591edc | 543 | |
f0fba2ad | 544 | dev_set_drvdata(&pdev->dev, priv); |
f9b95980 | 545 | |
546 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); | |
b25b5aa0 TR |
547 | priv->io = devm_ioremap_resource(&pdev->dev, mem); |
548 | if (IS_ERR(priv->io)) | |
549 | return PTR_ERR(priv->io); | |
f9b95980 | 550 | |
551 | priv->irq = platform_get_irq(pdev, 0); | |
e7b2e30a GS |
552 | if (priv->irq < 0) { |
553 | dev_err(&pdev->dev, "platform_get_irq failed: %d\n", priv->irq); | |
554 | return priv->irq; | |
f9b95980 | 555 | } |
556 | ||
eb632318 JFM |
557 | if (np) { |
558 | priv->burst = 128; /* might be 32 or 128 */ | |
559 | } else if (data) { | |
560 | priv->burst = data->burst; | |
561 | } else { | |
562 | dev_err(&pdev->dev, "no DT nor platform data ?!\n"); | |
dbc517bf | 563 | return -EINVAL; |
f9b95980 | 564 | } |
565 | ||
eb632318 | 566 | priv->clk = devm_clk_get(&pdev->dev, np ? "internal" : NULL); |
e919c716 AL |
567 | if (IS_ERR(priv->clk)) { |
568 | dev_err(&pdev->dev, "no clock\n"); | |
dbc517bf | 569 | return PTR_ERR(priv->clk); |
e919c716 | 570 | } |
dbc517bf RK |
571 | |
572 | err = clk_prepare_enable(priv->clk); | |
573 | if (err < 0) | |
574 | return err; | |
e919c716 | 575 | |
4734dc96 | 576 | priv->extclk = devm_clk_get(&pdev->dev, "extclk"); |
84aac6c7 JFM |
577 | if (IS_ERR(priv->extclk)) { |
578 | if (PTR_ERR(priv->extclk) == -EPROBE_DEFER) | |
579 | return -EPROBE_DEFER; | |
580 | } else { | |
aaa6d062 | 581 | if (clk_is_match(priv->extclk, priv->clk)) { |
af64d734 | 582 | devm_clk_put(&pdev->dev, priv->extclk); |
d8d11ba5 RK |
583 | priv->extclk = ERR_PTR(-EINVAL); |
584 | } else { | |
585 | dev_info(&pdev->dev, "found external clock\n"); | |
586 | clk_prepare_enable(priv->extclk); | |
99d8d3ba | 587 | soc_dai = kirkwood_i2s_dai_extclk; |
d8d11ba5 RK |
588 | } |
589 | } | |
590 | ||
591 | /* Some sensible defaults - this reflects the powerup values */ | |
592 | priv->ctl_play = KIRKWOOD_PLAYCTL_SIZE_24; | |
593 | priv->ctl_rec = KIRKWOOD_RECCTL_SIZE_24; | |
594 | ||
595 | /* Select the burst size */ | |
eb632318 | 596 | if (priv->burst == 32) { |
d8d11ba5 RK |
597 | priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_32; |
598 | priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_32; | |
599 | } else { | |
600 | priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_128; | |
601 | priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_128; | |
602 | } | |
603 | ||
83d85f53 | 604 | err = snd_soc_register_component(&pdev->dev, &kirkwood_i2s_component, |
75b9b65e | 605 | soc_dai, 2); |
64ddf1f8 RK |
606 | if (err) { |
607 | dev_err(&pdev->dev, "snd_soc_register_component failed\n"); | |
608 | goto err_component; | |
609 | } | |
baffab28 | 610 | |
64ddf1f8 RK |
611 | err = snd_soc_register_platform(&pdev->dev, &kirkwood_soc_platform); |
612 | if (err) { | |
613 | dev_err(&pdev->dev, "snd_soc_register_platform failed\n"); | |
614 | goto err_platform; | |
615 | } | |
75b9b65e JFM |
616 | |
617 | kirkwood_i2s_init(priv); | |
618 | ||
64ddf1f8 RK |
619 | return 0; |
620 | err_platform: | |
621 | snd_soc_unregister_component(&pdev->dev); | |
622 | err_component: | |
4734dc96 | 623 | if (!IS_ERR(priv->extclk)) |
363589bf | 624 | clk_disable_unprepare(priv->extclk); |
baffab28 | 625 | clk_disable_unprepare(priv->clk); |
dbc517bf | 626 | |
f9b95980 | 627 | return err; |
628 | } | |
629 | ||
34e15fbd | 630 | static int kirkwood_i2s_dev_remove(struct platform_device *pdev) |
f9b95980 | 631 | { |
f0fba2ad LG |
632 | struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev); |
633 | ||
64ddf1f8 | 634 | snd_soc_unregister_platform(&pdev->dev); |
83d85f53 | 635 | snd_soc_unregister_component(&pdev->dev); |
e919c716 | 636 | |
4734dc96 | 637 | if (!IS_ERR(priv->extclk)) |
363589bf | 638 | clk_disable_unprepare(priv->extclk); |
e919c716 | 639 | clk_disable_unprepare(priv->clk); |
f0fba2ad | 640 | |
f9b95980 | 641 | return 0; |
642 | } | |
643 | ||
eb632318 | 644 | #ifdef CONFIG_OF |
7f2c52af | 645 | static const struct of_device_id mvebu_audio_of_match[] = { |
d098b2f0 TP |
646 | { .compatible = "marvell,kirkwood-audio" }, |
647 | { .compatible = "marvell,dove-audio" }, | |
9a0d5113 | 648 | { .compatible = "marvell,armada370-audio" }, |
eb632318 JFM |
649 | { } |
650 | }; | |
651 | MODULE_DEVICE_TABLE(of, mvebu_audio_of_match); | |
652 | #endif | |
653 | ||
f9b95980 | 654 | static struct platform_driver kirkwood_i2s_driver = { |
655 | .probe = kirkwood_i2s_dev_probe, | |
34e15fbd | 656 | .remove = kirkwood_i2s_dev_remove, |
f9b95980 | 657 | .driver = { |
658 | .name = DRV_NAME, | |
eb632318 | 659 | .of_match_table = of_match_ptr(mvebu_audio_of_match), |
f9b95980 | 660 | }, |
661 | }; | |
662 | ||
41b10225 | 663 | module_platform_driver(kirkwood_i2s_driver); |
f9b95980 | 664 | |
665 | /* Module information */ | |
69737897 | 666 | MODULE_AUTHOR("Arnaud Patard, <arnaud.patard@rtp-net.org>"); |
f9b95980 | 667 | MODULE_DESCRIPTION("Kirkwood I2S SoC Interface"); |
668 | MODULE_LICENSE("GPL"); | |
64ddf1f8 | 669 | MODULE_ALIAS("platform:mvebu-audio"); |