xref: /linux/sound/soc/kirkwood/kirkwood-i2s.c (revision 7f2c52afc02554f18db27242b62d4047bbd8df4c)
1f9b95980Sapatard@mandriva.com /*
2f9b95980Sapatard@mandriva.com  * kirkwood-i2s.c
3f9b95980Sapatard@mandriva.com  *
4f9b95980Sapatard@mandriva.com  * (c) 2010 Arnaud Patard <apatard@mandriva.com>
569737897SArnaud Patard (Rtp)  * (c) 2010 Arnaud Patard <arnaud.patard@rtp-net.org>
6f9b95980Sapatard@mandriva.com  *
7f9b95980Sapatard@mandriva.com  *  This program is free software; you can redistribute  it and/or modify it
8f9b95980Sapatard@mandriva.com  *  under  the terms of  the GNU General  Public License as published by the
9f9b95980Sapatard@mandriva.com  *  Free Software Foundation;  either version 2 of the  License, or (at your
10f9b95980Sapatard@mandriva.com  *  option) any later version.
11f9b95980Sapatard@mandriva.com  */
12f9b95980Sapatard@mandriva.com 
13f9b95980Sapatard@mandriva.com #include <linux/init.h>
14f9b95980Sapatard@mandriva.com #include <linux/module.h>
15f9b95980Sapatard@mandriva.com #include <linux/platform_device.h>
16f9b95980Sapatard@mandriva.com #include <linux/io.h>
17f9b95980Sapatard@mandriva.com #include <linux/slab.h>
18f9b95980Sapatard@mandriva.com #include <linux/mbus.h>
19f9b95980Sapatard@mandriva.com #include <linux/delay.h>
20e919c716SAndrew Lunn #include <linux/clk.h>
21f9b95980Sapatard@mandriva.com #include <sound/pcm.h>
22f9b95980Sapatard@mandriva.com #include <sound/pcm_params.h>
23f9b95980Sapatard@mandriva.com #include <sound/soc.h>
24c02cecb9SArnd Bergmann #include <linux/platform_data/asoc-kirkwood.h>
25eb632318SJean-Francois Moine #include <linux/of.h>
26eb632318SJean-Francois Moine 
27f9b95980Sapatard@mandriva.com #include "kirkwood.h"
28f9b95980Sapatard@mandriva.com 
2964ddf1f8SRussell King #define DRV_NAME	"mvebu-audio"
30f9b95980Sapatard@mandriva.com 
31f9b95980Sapatard@mandriva.com #define KIRKWOOD_I2S_FORMATS \
32f9b95980Sapatard@mandriva.com 	(SNDRV_PCM_FMTBIT_S16_LE | \
33f9b95980Sapatard@mandriva.com 	 SNDRV_PCM_FMTBIT_S24_LE | \
34f9b95980Sapatard@mandriva.com 	 SNDRV_PCM_FMTBIT_S32_LE)
35f9b95980Sapatard@mandriva.com 
361c195ddbSJean-Francois Moine #define KIRKWOOD_SPDIF_FORMATS \
371c195ddbSJean-Francois Moine 	(SNDRV_PCM_FMTBIT_S16_LE | \
381c195ddbSJean-Francois Moine 	 SNDRV_PCM_FMTBIT_S24_LE)
391c195ddbSJean-Francois Moine 
40f9b95980Sapatard@mandriva.com static int kirkwood_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
41f9b95980Sapatard@mandriva.com 		unsigned int fmt)
42f9b95980Sapatard@mandriva.com {
43f0fba2adSLiam Girdwood 	struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(cpu_dai);
44f9b95980Sapatard@mandriva.com 	unsigned long mask;
45f9b95980Sapatard@mandriva.com 	unsigned long value;
46f9b95980Sapatard@mandriva.com 
47f9b95980Sapatard@mandriva.com 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
48f9b95980Sapatard@mandriva.com 	case SND_SOC_DAIFMT_RIGHT_J:
49f9b95980Sapatard@mandriva.com 		mask = KIRKWOOD_I2S_CTL_RJ;
50f9b95980Sapatard@mandriva.com 		break;
51f9b95980Sapatard@mandriva.com 	case SND_SOC_DAIFMT_LEFT_J:
52f9b95980Sapatard@mandriva.com 		mask = KIRKWOOD_I2S_CTL_LJ;
53f9b95980Sapatard@mandriva.com 		break;
54f9b95980Sapatard@mandriva.com 	case SND_SOC_DAIFMT_I2S:
55f9b95980Sapatard@mandriva.com 		mask = KIRKWOOD_I2S_CTL_I2S;
56f9b95980Sapatard@mandriva.com 		break;
57f9b95980Sapatard@mandriva.com 	default:
58f9b95980Sapatard@mandriva.com 		return -EINVAL;
59f9b95980Sapatard@mandriva.com 	}
60f9b95980Sapatard@mandriva.com 
61f9b95980Sapatard@mandriva.com 	/*
62f9b95980Sapatard@mandriva.com 	 * Set same format for playback and record
63f9b95980Sapatard@mandriva.com 	 * This avoids some troubles.
64f9b95980Sapatard@mandriva.com 	 */
65f9b95980Sapatard@mandriva.com 	value = readl(priv->io+KIRKWOOD_I2S_PLAYCTL);
66f9b95980Sapatard@mandriva.com 	value &= ~KIRKWOOD_I2S_CTL_JUST_MASK;
67f9b95980Sapatard@mandriva.com 	value |= mask;
68f9b95980Sapatard@mandriva.com 	writel(value, priv->io+KIRKWOOD_I2S_PLAYCTL);
69f9b95980Sapatard@mandriva.com 
70f9b95980Sapatard@mandriva.com 	value = readl(priv->io+KIRKWOOD_I2S_RECCTL);
71f9b95980Sapatard@mandriva.com 	value &= ~KIRKWOOD_I2S_CTL_JUST_MASK;
72f9b95980Sapatard@mandriva.com 	value |= mask;
73f9b95980Sapatard@mandriva.com 	writel(value, priv->io+KIRKWOOD_I2S_RECCTL);
74f9b95980Sapatard@mandriva.com 
75f9b95980Sapatard@mandriva.com 	return 0;
76f9b95980Sapatard@mandriva.com }
77f9b95980Sapatard@mandriva.com 
78f9b95980Sapatard@mandriva.com static inline void kirkwood_set_dco(void __iomem *io, unsigned long rate)
79f9b95980Sapatard@mandriva.com {
80f9b95980Sapatard@mandriva.com 	unsigned long value;
81f9b95980Sapatard@mandriva.com 
82f9b95980Sapatard@mandriva.com 	value = KIRKWOOD_DCO_CTL_OFFSET_0;
83f9b95980Sapatard@mandriva.com 	switch (rate) {
84f9b95980Sapatard@mandriva.com 	default:
85f9b95980Sapatard@mandriva.com 	case 44100:
86f9b95980Sapatard@mandriva.com 		value |= KIRKWOOD_DCO_CTL_FREQ_11;
87f9b95980Sapatard@mandriva.com 		break;
88f9b95980Sapatard@mandriva.com 	case 48000:
89f9b95980Sapatard@mandriva.com 		value |= KIRKWOOD_DCO_CTL_FREQ_12;
90f9b95980Sapatard@mandriva.com 		break;
91f9b95980Sapatard@mandriva.com 	case 96000:
92f9b95980Sapatard@mandriva.com 		value |= KIRKWOOD_DCO_CTL_FREQ_24;
93f9b95980Sapatard@mandriva.com 		break;
94f9b95980Sapatard@mandriva.com 	}
95f9b95980Sapatard@mandriva.com 	writel(value, io + KIRKWOOD_DCO_CTL);
96f9b95980Sapatard@mandriva.com 
97f9b95980Sapatard@mandriva.com 	/* wait for dco locked */
98f9b95980Sapatard@mandriva.com 	do {
99f9b95980Sapatard@mandriva.com 		cpu_relax();
100f9b95980Sapatard@mandriva.com 		value = readl(io + KIRKWOOD_DCO_SPCR_STATUS);
1012424d458SRussell King 		value &= KIRKWOOD_DCO_SPCR_STATUS_DCO_LOCK;
102f9b95980Sapatard@mandriva.com 	} while (value == 0);
103f9b95980Sapatard@mandriva.com }
104f9b95980Sapatard@mandriva.com 
105363589bfSRussell King static void kirkwood_set_rate(struct snd_soc_dai *dai,
106363589bfSRussell King 	struct kirkwood_dma_data *priv, unsigned long rate)
107363589bfSRussell King {
108363589bfSRussell King 	uint32_t clks_ctrl;
109363589bfSRussell King 
1101f1b6579SJean-Francois Moine 	if (IS_ERR(priv->extclk)) {
1118a537f85SJean-Francois Moine 		/* use internal dco for the supported rates
1128a537f85SJean-Francois Moine 		 * defined in kirkwood_i2s_dai */
113363589bfSRussell King 		dev_dbg(dai->dev, "%s: dco set rate = %lu\n",
114363589bfSRussell King 			__func__, rate);
115363589bfSRussell King 		kirkwood_set_dco(priv->io, rate);
116363589bfSRussell King 
117363589bfSRussell King 		clks_ctrl = KIRKWOOD_MCLK_SOURCE_DCO;
1188a537f85SJean-Francois Moine 	} else {
1198a537f85SJean-Francois Moine 		/* use the external clock for the other rates
1208a537f85SJean-Francois Moine 		 * defined in kirkwood_i2s_dai_extclk */
121363589bfSRussell King 		dev_dbg(dai->dev, "%s: extclk set rate = %lu -> %lu\n",
122363589bfSRussell King 			__func__, rate, 256 * rate);
123363589bfSRussell King 		clk_set_rate(priv->extclk, 256 * rate);
124363589bfSRussell King 
125363589bfSRussell King 		clks_ctrl = KIRKWOOD_MCLK_SOURCE_EXTCLK;
126363589bfSRussell King 	}
127363589bfSRussell King 	writel(clks_ctrl, priv->io + KIRKWOOD_CLOCKS_CTRL);
128363589bfSRussell King }
129363589bfSRussell King 
130f0fba2adSLiam Girdwood static int kirkwood_i2s_startup(struct snd_pcm_substream *substream,
131f0fba2adSLiam Girdwood 		struct snd_soc_dai *dai)
132f0fba2adSLiam Girdwood {
133f0fba2adSLiam Girdwood 	struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
134f0fba2adSLiam Girdwood 
135f0fba2adSLiam Girdwood 	snd_soc_dai_set_dma_data(dai, substream, priv);
136f0fba2adSLiam Girdwood 	return 0;
137f0fba2adSLiam Girdwood }
138f0fba2adSLiam Girdwood 
139f9b95980Sapatard@mandriva.com static int kirkwood_i2s_hw_params(struct snd_pcm_substream *substream,
140f9b95980Sapatard@mandriva.com 				 struct snd_pcm_hw_params *params,
141f9b95980Sapatard@mandriva.com 				 struct snd_soc_dai *dai)
142f9b95980Sapatard@mandriva.com {
143f0fba2adSLiam Girdwood 	struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
144d8d11ba5SRussell King 	uint32_t ctl_play, ctl_rec;
145d8d11ba5SRussell King 	unsigned int i2s_reg;
146d8d11ba5SRussell King 	unsigned long i2s_value;
147f9b95980Sapatard@mandriva.com 
148f9b95980Sapatard@mandriva.com 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
149f9b95980Sapatard@mandriva.com 		i2s_reg = KIRKWOOD_I2S_PLAYCTL;
150f9b95980Sapatard@mandriva.com 	} else {
151f9b95980Sapatard@mandriva.com 		i2s_reg = KIRKWOOD_I2S_RECCTL;
152f9b95980Sapatard@mandriva.com 	}
153f9b95980Sapatard@mandriva.com 
154363589bfSRussell King 	kirkwood_set_rate(dai, priv, params_rate(params));
155f9b95980Sapatard@mandriva.com 
156f9b95980Sapatard@mandriva.com 	i2s_value = readl(priv->io+i2s_reg);
157f9b95980Sapatard@mandriva.com 	i2s_value &= ~KIRKWOOD_I2S_CTL_SIZE_MASK;
158f9b95980Sapatard@mandriva.com 
159f9b95980Sapatard@mandriva.com 	/*
160f9b95980Sapatard@mandriva.com 	 * Size settings in play/rec i2s control regs and play/rec control
161f9b95980Sapatard@mandriva.com 	 * regs must be the same.
162f9b95980Sapatard@mandriva.com 	 */
163f9b95980Sapatard@mandriva.com 	switch (params_format(params)) {
164f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_FORMAT_S16_LE:
165f9b95980Sapatard@mandriva.com 		i2s_value |= KIRKWOOD_I2S_CTL_SIZE_16;
166d8d11ba5SRussell King 		ctl_play = KIRKWOOD_PLAYCTL_SIZE_16_C |
16775b9b65eSJean-Francois Moine 			   KIRKWOOD_PLAYCTL_I2S_EN |
16875b9b65eSJean-Francois Moine 			   KIRKWOOD_PLAYCTL_SPDIF_EN;
169d8d11ba5SRussell King 		ctl_rec = KIRKWOOD_RECCTL_SIZE_16_C |
17075b9b65eSJean-Francois Moine 			  KIRKWOOD_RECCTL_I2S_EN |
17175b9b65eSJean-Francois Moine 			  KIRKWOOD_RECCTL_SPDIF_EN;
172f9b95980Sapatard@mandriva.com 		break;
173f9b95980Sapatard@mandriva.com 	/*
174f9b95980Sapatard@mandriva.com 	 * doesn't work... S20_3LE != kirkwood 20bit format ?
175f9b95980Sapatard@mandriva.com 	 *
176f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_FORMAT_S20_3LE:
177f9b95980Sapatard@mandriva.com 		i2s_value |= KIRKWOOD_I2S_CTL_SIZE_20;
178d8d11ba5SRussell King 		ctl_play = KIRKWOOD_PLAYCTL_SIZE_20 |
179d8d11ba5SRussell King 			   KIRKWOOD_PLAYCTL_I2S_EN;
180d8d11ba5SRussell King 		ctl_rec = KIRKWOOD_RECCTL_SIZE_20 |
181d8d11ba5SRussell King 			  KIRKWOOD_RECCTL_I2S_EN;
182f9b95980Sapatard@mandriva.com 		break;
183f9b95980Sapatard@mandriva.com 	*/
184f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_FORMAT_S24_LE:
185f9b95980Sapatard@mandriva.com 		i2s_value |= KIRKWOOD_I2S_CTL_SIZE_24;
186d8d11ba5SRussell King 		ctl_play = KIRKWOOD_PLAYCTL_SIZE_24 |
18775b9b65eSJean-Francois Moine 			   KIRKWOOD_PLAYCTL_I2S_EN |
18875b9b65eSJean-Francois Moine 			   KIRKWOOD_PLAYCTL_SPDIF_EN;
189d8d11ba5SRussell King 		ctl_rec = KIRKWOOD_RECCTL_SIZE_24 |
19075b9b65eSJean-Francois Moine 			  KIRKWOOD_RECCTL_I2S_EN |
19175b9b65eSJean-Francois Moine 			  KIRKWOOD_RECCTL_SPDIF_EN;
192f9b95980Sapatard@mandriva.com 		break;
193f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_FORMAT_S32_LE:
194f9b95980Sapatard@mandriva.com 		i2s_value |= KIRKWOOD_I2S_CTL_SIZE_32;
195d8d11ba5SRussell King 		ctl_play = KIRKWOOD_PLAYCTL_SIZE_32 |
196d8d11ba5SRussell King 			   KIRKWOOD_PLAYCTL_I2S_EN;
197d8d11ba5SRussell King 		ctl_rec = KIRKWOOD_RECCTL_SIZE_32 |
198d8d11ba5SRussell King 			  KIRKWOOD_RECCTL_I2S_EN;
199f9b95980Sapatard@mandriva.com 		break;
200f9b95980Sapatard@mandriva.com 	default:
201f9b95980Sapatard@mandriva.com 		return -EINVAL;
202f9b95980Sapatard@mandriva.com 	}
203dfe4c936Sarnaud.patard@rtp-net.org 
204dfe4c936Sarnaud.patard@rtp-net.org 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
205dfe4c936Sarnaud.patard@rtp-net.org 		if (params_channels(params) == 1)
206d8d11ba5SRussell King 			ctl_play |= KIRKWOOD_PLAYCTL_MONO_BOTH;
207dfe4c936Sarnaud.patard@rtp-net.org 		else
208d8d11ba5SRussell King 			ctl_play |= KIRKWOOD_PLAYCTL_MONO_OFF;
209d8d11ba5SRussell King 
210d8d11ba5SRussell King 		priv->ctl_play &= ~(KIRKWOOD_PLAYCTL_MONO_MASK |
211db43b16fSRussell King 				    KIRKWOOD_PLAYCTL_ENABLE_MASK |
212d8d11ba5SRussell King 				    KIRKWOOD_PLAYCTL_SIZE_MASK);
213d8d11ba5SRussell King 		priv->ctl_play |= ctl_play;
214d8d11ba5SRussell King 	} else {
21567721906SRussell King 		priv->ctl_rec &= ~(KIRKWOOD_RECCTL_ENABLE_MASK |
21667721906SRussell King 				   KIRKWOOD_RECCTL_SIZE_MASK);
217d8d11ba5SRussell King 		priv->ctl_rec |= ctl_rec;
218dfe4c936Sarnaud.patard@rtp-net.org 	}
219dfe4c936Sarnaud.patard@rtp-net.org 
220f9b95980Sapatard@mandriva.com 	writel(i2s_value, priv->io+i2s_reg);
221f9b95980Sapatard@mandriva.com 
222f9b95980Sapatard@mandriva.com 	return 0;
223f9b95980Sapatard@mandriva.com }
224f9b95980Sapatard@mandriva.com 
2252fbc3821SRussell King static unsigned kirkwood_i2s_play_mute(unsigned ctl)
2262fbc3821SRussell King {
2272fbc3821SRussell King 	if (!(ctl & KIRKWOOD_PLAYCTL_I2S_EN))
2282fbc3821SRussell King 		ctl |= KIRKWOOD_PLAYCTL_I2S_MUTE;
2292fbc3821SRussell King 	if (!(ctl & KIRKWOOD_PLAYCTL_SPDIF_EN))
2302fbc3821SRussell King 		ctl |= KIRKWOOD_PLAYCTL_SPDIF_MUTE;
2312fbc3821SRussell King 	return ctl;
2322fbc3821SRussell King }
2332fbc3821SRussell King 
234f9b95980Sapatard@mandriva.com static int kirkwood_i2s_play_trigger(struct snd_pcm_substream *substream,
235f9b95980Sapatard@mandriva.com 				int cmd, struct snd_soc_dai *dai)
236f9b95980Sapatard@mandriva.com {
237920ec4e5SRussell King 	struct snd_pcm_runtime *runtime = substream->runtime;
238f0fba2adSLiam Girdwood 	struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
239982b604bSRussell King 	uint32_t ctl, value;
240f9b95980Sapatard@mandriva.com 
241982b604bSRussell King 	ctl = readl(priv->io + KIRKWOOD_PLAYCTL);
2424d2097e5SRussell King 	if ((ctl & KIRKWOOD_PLAYCTL_ENABLE_MASK) == 0) {
243982b604bSRussell King 		unsigned timeout = 5000;
244f9b95980Sapatard@mandriva.com 		/*
245982b604bSRussell King 		 * The Armada510 spec says that if we enter pause mode, the
246982b604bSRussell King 		 * busy bit must be read back as clear _twice_.  Make sure
247982b604bSRussell King 		 * we respect that otherwise we get DMA underruns.
248f9b95980Sapatard@mandriva.com 		 */
249982b604bSRussell King 		do {
250982b604bSRussell King 			value = ctl;
251982b604bSRussell King 			ctl = readl(priv->io + KIRKWOOD_PLAYCTL);
252982b604bSRussell King 			if (!((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY))
253982b604bSRussell King 				break;
254982b604bSRussell King 			udelay(1);
255982b604bSRussell King 		} while (timeout--);
256982b604bSRussell King 
257982b604bSRussell King 		if ((ctl | value) & KIRKWOOD_PLAYCTL_PLAY_BUSY)
258982b604bSRussell King 			dev_notice(dai->dev, "timed out waiting for busy to deassert: %08x\n",
259982b604bSRussell King 				   ctl);
260982b604bSRussell King 	}
261f9b95980Sapatard@mandriva.com 
2624f6f1478SJean-Francois Moine 	switch (cmd) {
2634f6f1478SJean-Francois Moine 	case SNDRV_PCM_TRIGGER_START:
2644f6f1478SJean-Francois Moine 		/* configure */
2654f6f1478SJean-Francois Moine 		ctl = priv->ctl_play;
26675b9b65eSJean-Francois Moine 		if (dai->id == 0)
26775b9b65eSJean-Francois Moine 			ctl &= ~KIRKWOOD_PLAYCTL_SPDIF_EN;	/* i2s */
26875b9b65eSJean-Francois Moine 		else
26975b9b65eSJean-Francois Moine 			ctl &= ~KIRKWOOD_PLAYCTL_I2S_EN;	/* spdif */
2702fbc3821SRussell King 		ctl = kirkwood_i2s_play_mute(ctl);
271db43b16fSRussell King 		value = ctl & ~KIRKWOOD_PLAYCTL_ENABLE_MASK;
272d8d11ba5SRussell King 		writel(value, priv->io + KIRKWOOD_PLAYCTL);
273d8d11ba5SRussell King 
274d8d11ba5SRussell King 		/* enable interrupts */
275920ec4e5SRussell King 		if (!runtime->no_period_wakeup) {
276f9b95980Sapatard@mandriva.com 			value = readl(priv->io + KIRKWOOD_INT_MASK);
277f9b95980Sapatard@mandriva.com 			value |= KIRKWOOD_INT_CAUSE_PLAY_BYTES;
278f9b95980Sapatard@mandriva.com 			writel(value, priv->io + KIRKWOOD_INT_MASK);
279920ec4e5SRussell King 		}
280f9b95980Sapatard@mandriva.com 
281d8d11ba5SRussell King 		/* enable playback */
282982b604bSRussell King 		writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
283f9b95980Sapatard@mandriva.com 		break;
284f9b95980Sapatard@mandriva.com 
285f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_STOP:
286f9b95980Sapatard@mandriva.com 		/* stop audio, disable interrupts */
28775b9b65eSJean-Francois Moine 		ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
28875b9b65eSJean-Francois Moine 				KIRKWOOD_PLAYCTL_SPDIF_MUTE;
289982b604bSRussell King 		writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
290f9b95980Sapatard@mandriva.com 
291f9b95980Sapatard@mandriva.com 		value = readl(priv->io + KIRKWOOD_INT_MASK);
292f9b95980Sapatard@mandriva.com 		value &= ~KIRKWOOD_INT_CAUSE_PLAY_BYTES;
293f9b95980Sapatard@mandriva.com 		writel(value, priv->io + KIRKWOOD_INT_MASK);
294f9b95980Sapatard@mandriva.com 
295f9b95980Sapatard@mandriva.com 		/* disable all playbacks */
296db43b16fSRussell King 		ctl &= ~KIRKWOOD_PLAYCTL_ENABLE_MASK;
297982b604bSRussell King 		writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
298f9b95980Sapatard@mandriva.com 		break;
299f9b95980Sapatard@mandriva.com 
300f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
301f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_SUSPEND:
30275b9b65eSJean-Francois Moine 		ctl |= KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
30375b9b65eSJean-Francois Moine 				KIRKWOOD_PLAYCTL_SPDIF_MUTE;
304982b604bSRussell King 		writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
305f9b95980Sapatard@mandriva.com 		break;
306f9b95980Sapatard@mandriva.com 
307f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_RESUME:
308f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
30975b9b65eSJean-Francois Moine 		ctl &= ~(KIRKWOOD_PLAYCTL_PAUSE | KIRKWOOD_PLAYCTL_I2S_MUTE |
31075b9b65eSJean-Francois Moine 				KIRKWOOD_PLAYCTL_SPDIF_MUTE);
3112fbc3821SRussell King 		ctl = kirkwood_i2s_play_mute(ctl);
312982b604bSRussell King 		writel(ctl, priv->io + KIRKWOOD_PLAYCTL);
313f9b95980Sapatard@mandriva.com 		break;
314f9b95980Sapatard@mandriva.com 
315f9b95980Sapatard@mandriva.com 	default:
316f9b95980Sapatard@mandriva.com 		return -EINVAL;
317f9b95980Sapatard@mandriva.com 	}
318f9b95980Sapatard@mandriva.com 
319f9b95980Sapatard@mandriva.com 	return 0;
320f9b95980Sapatard@mandriva.com }
321f9b95980Sapatard@mandriva.com 
322f9b95980Sapatard@mandriva.com static int kirkwood_i2s_rec_trigger(struct snd_pcm_substream *substream,
323f9b95980Sapatard@mandriva.com 				int cmd, struct snd_soc_dai *dai)
324f9b95980Sapatard@mandriva.com {
325f0fba2adSLiam Girdwood 	struct kirkwood_dma_data *priv = snd_soc_dai_get_drvdata(dai);
326d8d11ba5SRussell King 	uint32_t ctl, value;
327f9b95980Sapatard@mandriva.com 
328f9b95980Sapatard@mandriva.com 	value = readl(priv->io + KIRKWOOD_RECCTL);
329f9b95980Sapatard@mandriva.com 
330f9b95980Sapatard@mandriva.com 	switch (cmd) {
331f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_START:
332d8d11ba5SRussell King 		/* configure */
333d8d11ba5SRussell King 		ctl = priv->ctl_rec;
33475b9b65eSJean-Francois Moine 		if (dai->id == 0)
33575b9b65eSJean-Francois Moine 			ctl &= ~KIRKWOOD_RECCTL_SPDIF_EN;	/* i2s */
33675b9b65eSJean-Francois Moine 		else
33775b9b65eSJean-Francois Moine 			ctl &= ~KIRKWOOD_RECCTL_I2S_EN;		/* spdif */
33875b9b65eSJean-Francois Moine 
33952b896cfSRussell King 		value = ctl & ~KIRKWOOD_RECCTL_ENABLE_MASK;
340d8d11ba5SRussell King 		writel(value, priv->io + KIRKWOOD_RECCTL);
341d8d11ba5SRussell King 
342d8d11ba5SRussell King 		/* enable interrupts */
343f9b95980Sapatard@mandriva.com 		value = readl(priv->io + KIRKWOOD_INT_MASK);
344f9b95980Sapatard@mandriva.com 		value |= KIRKWOOD_INT_CAUSE_REC_BYTES;
345f9b95980Sapatard@mandriva.com 		writel(value, priv->io + KIRKWOOD_INT_MASK);
346f9b95980Sapatard@mandriva.com 
347d8d11ba5SRussell King 		/* enable record */
348d8d11ba5SRussell King 		writel(ctl, priv->io + KIRKWOOD_RECCTL);
349f9b95980Sapatard@mandriva.com 		break;
350f9b95980Sapatard@mandriva.com 
351f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_STOP:
352f9b95980Sapatard@mandriva.com 		/* stop audio, disable interrupts */
353f9b95980Sapatard@mandriva.com 		value = readl(priv->io + KIRKWOOD_RECCTL);
354b424ec95Sarnaud.patard@rtp-net.org 		value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE;
355f9b95980Sapatard@mandriva.com 		writel(value, priv->io + KIRKWOOD_RECCTL);
356f9b95980Sapatard@mandriva.com 
357f9b95980Sapatard@mandriva.com 		value = readl(priv->io + KIRKWOOD_INT_MASK);
358f9b95980Sapatard@mandriva.com 		value &= ~KIRKWOOD_INT_CAUSE_REC_BYTES;
359f9b95980Sapatard@mandriva.com 		writel(value, priv->io + KIRKWOOD_INT_MASK);
360f9b95980Sapatard@mandriva.com 
361f9b95980Sapatard@mandriva.com 		/* disable all records */
362f9b95980Sapatard@mandriva.com 		value = readl(priv->io + KIRKWOOD_RECCTL);
36352b896cfSRussell King 		value &= ~KIRKWOOD_RECCTL_ENABLE_MASK;
364f9b95980Sapatard@mandriva.com 		writel(value, priv->io + KIRKWOOD_RECCTL);
365f9b95980Sapatard@mandriva.com 		break;
366f9b95980Sapatard@mandriva.com 
367f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
368f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_SUSPEND:
369f9b95980Sapatard@mandriva.com 		value = readl(priv->io + KIRKWOOD_RECCTL);
370b424ec95Sarnaud.patard@rtp-net.org 		value |= KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE;
371f9b95980Sapatard@mandriva.com 		writel(value, priv->io + KIRKWOOD_RECCTL);
372f9b95980Sapatard@mandriva.com 		break;
373f9b95980Sapatard@mandriva.com 
374f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_RESUME:
375f9b95980Sapatard@mandriva.com 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
376f9b95980Sapatard@mandriva.com 		value = readl(priv->io + KIRKWOOD_RECCTL);
377b424ec95Sarnaud.patard@rtp-net.org 		value &= ~(KIRKWOOD_RECCTL_PAUSE | KIRKWOOD_RECCTL_MUTE);
378f9b95980Sapatard@mandriva.com 		writel(value, priv->io + KIRKWOOD_RECCTL);
379f9b95980Sapatard@mandriva.com 		break;
380f9b95980Sapatard@mandriva.com 
381f9b95980Sapatard@mandriva.com 	default:
382f9b95980Sapatard@mandriva.com 		return -EINVAL;
383f9b95980Sapatard@mandriva.com 	}
384f9b95980Sapatard@mandriva.com 
385f9b95980Sapatard@mandriva.com 	return 0;
386f9b95980Sapatard@mandriva.com }
387f9b95980Sapatard@mandriva.com 
388f9b95980Sapatard@mandriva.com static int kirkwood_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
389f9b95980Sapatard@mandriva.com 			       struct snd_soc_dai *dai)
390f9b95980Sapatard@mandriva.com {
391f9b95980Sapatard@mandriva.com 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
392f9b95980Sapatard@mandriva.com 		return kirkwood_i2s_play_trigger(substream, cmd, dai);
393f9b95980Sapatard@mandriva.com 	else
394f9b95980Sapatard@mandriva.com 		return kirkwood_i2s_rec_trigger(substream, cmd, dai);
395f9b95980Sapatard@mandriva.com 
396f9b95980Sapatard@mandriva.com 	return 0;
397f9b95980Sapatard@mandriva.com }
398f9b95980Sapatard@mandriva.com 
39975b9b65eSJean-Francois Moine static int kirkwood_i2s_init(struct kirkwood_dma_data *priv)
400f9b95980Sapatard@mandriva.com {
401f9b95980Sapatard@mandriva.com 	unsigned long value;
402f9b95980Sapatard@mandriva.com 	unsigned int reg_data;
403f9b95980Sapatard@mandriva.com 
404f9b95980Sapatard@mandriva.com 	/* put system in a "safe" state : */
405f9b95980Sapatard@mandriva.com 	/* disable audio interrupts */
406f9b95980Sapatard@mandriva.com 	writel(0xffffffff, priv->io + KIRKWOOD_INT_CAUSE);
407f9b95980Sapatard@mandriva.com 	writel(0, priv->io + KIRKWOOD_INT_MASK);
408f9b95980Sapatard@mandriva.com 
409f9b95980Sapatard@mandriva.com 	reg_data = readl(priv->io + 0x1200);
410f9b95980Sapatard@mandriva.com 	reg_data &= (~(0x333FF8));
411f9b95980Sapatard@mandriva.com 	reg_data |= 0x111D18;
412f9b95980Sapatard@mandriva.com 	writel(reg_data, priv->io + 0x1200);
413f9b95980Sapatard@mandriva.com 
414f9b95980Sapatard@mandriva.com 	msleep(500);
415f9b95980Sapatard@mandriva.com 
416f9b95980Sapatard@mandriva.com 	reg_data = readl(priv->io + 0x1200);
417f9b95980Sapatard@mandriva.com 	reg_data &= (~(0x333FF8));
418f9b95980Sapatard@mandriva.com 	reg_data |= 0x111D18;
419f9b95980Sapatard@mandriva.com 	writel(reg_data, priv->io + 0x1200);
420f9b95980Sapatard@mandriva.com 
421f9b95980Sapatard@mandriva.com 	/* disable playback/record */
422f9b95980Sapatard@mandriva.com 	value = readl(priv->io + KIRKWOOD_PLAYCTL);
423db43b16fSRussell King 	value &= ~KIRKWOOD_PLAYCTL_ENABLE_MASK;
424f9b95980Sapatard@mandriva.com 	writel(value, priv->io + KIRKWOOD_PLAYCTL);
425f9b95980Sapatard@mandriva.com 
426f9b95980Sapatard@mandriva.com 	value = readl(priv->io + KIRKWOOD_RECCTL);
42752b896cfSRussell King 	value &= ~KIRKWOOD_RECCTL_ENABLE_MASK;
428f9b95980Sapatard@mandriva.com 	writel(value, priv->io + KIRKWOOD_RECCTL);
429f9b95980Sapatard@mandriva.com 
430f9b95980Sapatard@mandriva.com 	return 0;
431f9b95980Sapatard@mandriva.com 
432f9b95980Sapatard@mandriva.com }
433f9b95980Sapatard@mandriva.com 
43485e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops kirkwood_i2s_dai_ops = {
435f0fba2adSLiam Girdwood 	.startup	= kirkwood_i2s_startup,
436f9b95980Sapatard@mandriva.com 	.trigger	= kirkwood_i2s_trigger,
437f9b95980Sapatard@mandriva.com 	.hw_params      = kirkwood_i2s_hw_params,
438f9b95980Sapatard@mandriva.com 	.set_fmt        = kirkwood_i2s_set_fmt,
439f9b95980Sapatard@mandriva.com };
440f9b95980Sapatard@mandriva.com 
44175b9b65eSJean-Francois Moine static struct snd_soc_dai_driver kirkwood_i2s_dai[2] = {
44275b9b65eSJean-Francois Moine     {
44375b9b65eSJean-Francois Moine 	.name = "i2s",
44475b9b65eSJean-Francois Moine 	.id = 0,
445f9b95980Sapatard@mandriva.com 	.playback = {
446f9b95980Sapatard@mandriva.com 		.channels_min = 1,
447f9b95980Sapatard@mandriva.com 		.channels_max = 2,
4489e12cbd9SMark Brown 		.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
4499e12cbd9SMark Brown 				SNDRV_PCM_RATE_96000,
450363589bfSRussell King 		.formats = KIRKWOOD_I2S_FORMATS,
451363589bfSRussell King 	},
452f9b95980Sapatard@mandriva.com 	.capture = {
453f9b95980Sapatard@mandriva.com 		.channels_min = 1,
454f9b95980Sapatard@mandriva.com 		.channels_max = 2,
4559e12cbd9SMark Brown 		.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
4569e12cbd9SMark Brown 				SNDRV_PCM_RATE_96000,
457363589bfSRussell King 		.formats = KIRKWOOD_I2S_FORMATS,
458363589bfSRussell King 	},
459363589bfSRussell King 	.ops = &kirkwood_i2s_dai_ops,
46075b9b65eSJean-Francois Moine     },
46175b9b65eSJean-Francois Moine     {
46275b9b65eSJean-Francois Moine 	.name = "spdif",
46375b9b65eSJean-Francois Moine 	.id = 1,
46475b9b65eSJean-Francois Moine 	.playback = {
46575b9b65eSJean-Francois Moine 		.channels_min = 1,
46675b9b65eSJean-Francois Moine 		.channels_max = 2,
46775b9b65eSJean-Francois Moine 		.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
46875b9b65eSJean-Francois Moine 				SNDRV_PCM_RATE_96000,
4691c195ddbSJean-Francois Moine 		.formats = KIRKWOOD_SPDIF_FORMATS,
47075b9b65eSJean-Francois Moine 	},
47175b9b65eSJean-Francois Moine 	.capture = {
47275b9b65eSJean-Francois Moine 		.channels_min = 1,
47375b9b65eSJean-Francois Moine 		.channels_max = 2,
47475b9b65eSJean-Francois Moine 		.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
47575b9b65eSJean-Francois Moine 				SNDRV_PCM_RATE_96000,
4761c195ddbSJean-Francois Moine 		.formats = KIRKWOOD_SPDIF_FORMATS,
47775b9b65eSJean-Francois Moine 	},
47875b9b65eSJean-Francois Moine 	.ops = &kirkwood_i2s_dai_ops,
47975b9b65eSJean-Francois Moine     },
480363589bfSRussell King };
481363589bfSRussell King 
48275b9b65eSJean-Francois Moine static struct snd_soc_dai_driver kirkwood_i2s_dai_extclk[2] = {
48375b9b65eSJean-Francois Moine     {
48475b9b65eSJean-Francois Moine 	.name = "i2s",
48575b9b65eSJean-Francois Moine 	.id = 0,
486363589bfSRussell King 	.playback = {
487363589bfSRussell King 		.channels_min = 1,
488363589bfSRussell King 		.channels_max = 2,
48902fc17c1SJean-Francois Moine 		.rates = SNDRV_PCM_RATE_CONTINUOUS,
49002fc17c1SJean-Francois Moine 		.rate_min = 5512,
49102fc17c1SJean-Francois Moine 		.rate_max = 192000,
492363589bfSRussell King 		.formats = KIRKWOOD_I2S_FORMATS,
493363589bfSRussell King 	},
494363589bfSRussell King 	.capture = {
495363589bfSRussell King 		.channels_min = 1,
496363589bfSRussell King 		.channels_max = 2,
49702fc17c1SJean-Francois Moine 		.rates = SNDRV_PCM_RATE_CONTINUOUS,
49802fc17c1SJean-Francois Moine 		.rate_min = 5512,
49902fc17c1SJean-Francois Moine 		.rate_max = 192000,
500363589bfSRussell King 		.formats = KIRKWOOD_I2S_FORMATS,
501363589bfSRussell King 	},
502f9b95980Sapatard@mandriva.com 	.ops = &kirkwood_i2s_dai_ops,
50375b9b65eSJean-Francois Moine     },
50475b9b65eSJean-Francois Moine     {
50575b9b65eSJean-Francois Moine 	.name = "spdif",
50675b9b65eSJean-Francois Moine 	.id = 1,
50775b9b65eSJean-Francois Moine 	.playback = {
50875b9b65eSJean-Francois Moine 		.channels_min = 1,
50975b9b65eSJean-Francois Moine 		.channels_max = 2,
51002fc17c1SJean-Francois Moine 		.rates = SNDRV_PCM_RATE_CONTINUOUS,
51102fc17c1SJean-Francois Moine 		.rate_min = 5512,
51202fc17c1SJean-Francois Moine 		.rate_max = 192000,
5131c195ddbSJean-Francois Moine 		.formats = KIRKWOOD_SPDIF_FORMATS,
51475b9b65eSJean-Francois Moine 	},
51575b9b65eSJean-Francois Moine 	.capture = {
51675b9b65eSJean-Francois Moine 		.channels_min = 1,
51775b9b65eSJean-Francois Moine 		.channels_max = 2,
51802fc17c1SJean-Francois Moine 		.rates = SNDRV_PCM_RATE_CONTINUOUS,
51902fc17c1SJean-Francois Moine 		.rate_min = 5512,
52002fc17c1SJean-Francois Moine 		.rate_max = 192000,
5211c195ddbSJean-Francois Moine 		.formats = KIRKWOOD_SPDIF_FORMATS,
52275b9b65eSJean-Francois Moine 	},
52375b9b65eSJean-Francois Moine 	.ops = &kirkwood_i2s_dai_ops,
52475b9b65eSJean-Francois Moine     },
525f9b95980Sapatard@mandriva.com };
526f9b95980Sapatard@mandriva.com 
52783d85f53SKuninori Morimoto static const struct snd_soc_component_driver kirkwood_i2s_component = {
52883d85f53SKuninori Morimoto 	.name		= DRV_NAME,
52983d85f53SKuninori Morimoto };
53083d85f53SKuninori Morimoto 
53134e15fbdSBill Pemberton static int kirkwood_i2s_dev_probe(struct platform_device *pdev)
532f9b95980Sapatard@mandriva.com {
533363589bfSRussell King 	struct kirkwood_asoc_platform_data *data = pdev->dev.platform_data;
53475b9b65eSJean-Francois Moine 	struct snd_soc_dai_driver *soc_dai = kirkwood_i2s_dai;
535f0fba2adSLiam Girdwood 	struct kirkwood_dma_data *priv;
536363589bfSRussell King 	struct resource *mem;
537eb632318SJean-Francois Moine 	struct device_node *np = pdev->dev.of_node;
538f9b95980Sapatard@mandriva.com 	int err;
539f9b95980Sapatard@mandriva.com 
540dbc517bfSRussell King 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
541f9b95980Sapatard@mandriva.com 	if (!priv) {
542f9b95980Sapatard@mandriva.com 		dev_err(&pdev->dev, "allocation failed\n");
543dbc517bfSRussell King 		return -ENOMEM;
544f9b95980Sapatard@mandriva.com 	}
545f0fba2adSLiam Girdwood 	dev_set_drvdata(&pdev->dev, priv);
546f9b95980Sapatard@mandriva.com 
547f9b95980Sapatard@mandriva.com 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
548b25b5aa0SThierry Reding 	priv->io = devm_ioremap_resource(&pdev->dev, mem);
549b25b5aa0SThierry Reding 	if (IS_ERR(priv->io))
550b25b5aa0SThierry Reding 		return PTR_ERR(priv->io);
551f9b95980Sapatard@mandriva.com 
552f9b95980Sapatard@mandriva.com 	priv->irq = platform_get_irq(pdev, 0);
553f9b95980Sapatard@mandriva.com 	if (priv->irq <= 0) {
554f9b95980Sapatard@mandriva.com 		dev_err(&pdev->dev, "platform_get_irq failed\n");
555dbc517bfSRussell King 		return -ENXIO;
556f9b95980Sapatard@mandriva.com 	}
557f9b95980Sapatard@mandriva.com 
558eb632318SJean-Francois Moine 	if (np) {
559eb632318SJean-Francois Moine 		priv->burst = 128;		/* might be 32 or 128 */
560eb632318SJean-Francois Moine 	} else if (data) {
561eb632318SJean-Francois Moine 		priv->burst = data->burst;
562eb632318SJean-Francois Moine 	} else {
563eb632318SJean-Francois Moine 		dev_err(&pdev->dev, "no DT nor platform data ?!\n");
564dbc517bfSRussell King 		return -EINVAL;
565f9b95980Sapatard@mandriva.com 	}
566f9b95980Sapatard@mandriva.com 
567eb632318SJean-Francois Moine 	priv->clk = devm_clk_get(&pdev->dev, np ? "internal" : NULL);
568e919c716SAndrew Lunn 	if (IS_ERR(priv->clk)) {
569e919c716SAndrew Lunn 		dev_err(&pdev->dev, "no clock\n");
570dbc517bfSRussell King 		return PTR_ERR(priv->clk);
571e919c716SAndrew Lunn 	}
572dbc517bfSRussell King 
573dbc517bfSRussell King 	err = clk_prepare_enable(priv->clk);
574dbc517bfSRussell King 	if (err < 0)
575dbc517bfSRussell King 		return err;
576e919c716SAndrew Lunn 
5774734dc96SMark Brown 	priv->extclk = devm_clk_get(&pdev->dev, "extclk");
57884aac6c7SJean-Francois Moine 	if (IS_ERR(priv->extclk)) {
57984aac6c7SJean-Francois Moine 		if (PTR_ERR(priv->extclk) == -EPROBE_DEFER)
58084aac6c7SJean-Francois Moine 			return -EPROBE_DEFER;
58184aac6c7SJean-Francois Moine 	} else {
582d8d11ba5SRussell King 		if (priv->extclk == priv->clk) {
583af64d734SRussell King 			devm_clk_put(&pdev->dev, priv->extclk);
584d8d11ba5SRussell King 			priv->extclk = ERR_PTR(-EINVAL);
585d8d11ba5SRussell King 		} else {
586d8d11ba5SRussell King 			dev_info(&pdev->dev, "found external clock\n");
587d8d11ba5SRussell King 			clk_prepare_enable(priv->extclk);
58899d8d3baSJean-Francois Moine 			soc_dai = kirkwood_i2s_dai_extclk;
589d8d11ba5SRussell King 		}
590d8d11ba5SRussell King 	}
591d8d11ba5SRussell King 
592d8d11ba5SRussell King 	/* Some sensible defaults - this reflects the powerup values */
593d8d11ba5SRussell King 	priv->ctl_play = KIRKWOOD_PLAYCTL_SIZE_24;
594d8d11ba5SRussell King 	priv->ctl_rec = KIRKWOOD_RECCTL_SIZE_24;
595d8d11ba5SRussell King 
596d8d11ba5SRussell King 	/* Select the burst size */
597eb632318SJean-Francois Moine 	if (priv->burst == 32) {
598d8d11ba5SRussell King 		priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_32;
599d8d11ba5SRussell King 		priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_32;
600d8d11ba5SRussell King 	} else {
601d8d11ba5SRussell King 		priv->ctl_play |= KIRKWOOD_PLAYCTL_BURST_128;
602d8d11ba5SRussell King 		priv->ctl_rec |= KIRKWOOD_RECCTL_BURST_128;
603d8d11ba5SRussell King 	}
604d8d11ba5SRussell King 
60583d85f53SKuninori Morimoto 	err = snd_soc_register_component(&pdev->dev, &kirkwood_i2s_component,
60675b9b65eSJean-Francois Moine 					 soc_dai, 2);
60764ddf1f8SRussell King 	if (err) {
60883d85f53SKuninori Morimoto 		dev_err(&pdev->dev, "snd_soc_register_component failed\n");
60964ddf1f8SRussell King 		goto err_component;
61064ddf1f8SRussell King 	}
611baffab28SSimon Baatz 
61264ddf1f8SRussell King 	err = snd_soc_register_platform(&pdev->dev, &kirkwood_soc_platform);
61364ddf1f8SRussell King 	if (err) {
61464ddf1f8SRussell King 		dev_err(&pdev->dev, "snd_soc_register_platform failed\n");
61564ddf1f8SRussell King 		goto err_platform;
61664ddf1f8SRussell King 	}
61775b9b65eSJean-Francois Moine 
61875b9b65eSJean-Francois Moine 	kirkwood_i2s_init(priv);
61975b9b65eSJean-Francois Moine 
62064ddf1f8SRussell King 	return 0;
62164ddf1f8SRussell King  err_platform:
62264ddf1f8SRussell King 	snd_soc_unregister_component(&pdev->dev);
62364ddf1f8SRussell King  err_component:
6244734dc96SMark Brown 	if (!IS_ERR(priv->extclk))
625363589bfSRussell King 		clk_disable_unprepare(priv->extclk);
626baffab28SSimon Baatz 	clk_disable_unprepare(priv->clk);
627f9b95980Sapatard@mandriva.com 
628f9b95980Sapatard@mandriva.com 	return err;
629f9b95980Sapatard@mandriva.com }
630f9b95980Sapatard@mandriva.com 
63134e15fbdSBill Pemberton static int kirkwood_i2s_dev_remove(struct platform_device *pdev)
632f9b95980Sapatard@mandriva.com {
633f0fba2adSLiam Girdwood 	struct kirkwood_dma_data *priv = dev_get_drvdata(&pdev->dev);
634f0fba2adSLiam Girdwood 
63564ddf1f8SRussell King 	snd_soc_unregister_platform(&pdev->dev);
63683d85f53SKuninori Morimoto 	snd_soc_unregister_component(&pdev->dev);
637e919c716SAndrew Lunn 
6384734dc96SMark Brown 	if (!IS_ERR(priv->extclk))
639363589bfSRussell King 		clk_disable_unprepare(priv->extclk);
640e919c716SAndrew Lunn 	clk_disable_unprepare(priv->clk);
641f0fba2adSLiam Girdwood 
642f9b95980Sapatard@mandriva.com 	return 0;
643f9b95980Sapatard@mandriva.com }
644f9b95980Sapatard@mandriva.com 
645eb632318SJean-Francois Moine #ifdef CONFIG_OF
646*7f2c52afSFabian Frederick static const struct of_device_id mvebu_audio_of_match[] = {
647d098b2f0SThomas Petazzoni 	{ .compatible = "marvell,kirkwood-audio" },
648d098b2f0SThomas Petazzoni 	{ .compatible = "marvell,dove-audio" },
6499a0d5113SThomas Petazzoni 	{ .compatible = "marvell,armada370-audio" },
650eb632318SJean-Francois Moine 	{ }
651eb632318SJean-Francois Moine };
652eb632318SJean-Francois Moine MODULE_DEVICE_TABLE(of, mvebu_audio_of_match);
653eb632318SJean-Francois Moine #endif
654eb632318SJean-Francois Moine 
655f9b95980Sapatard@mandriva.com static struct platform_driver kirkwood_i2s_driver = {
656f9b95980Sapatard@mandriva.com 	.probe  = kirkwood_i2s_dev_probe,
65734e15fbdSBill Pemberton 	.remove = kirkwood_i2s_dev_remove,
658f9b95980Sapatard@mandriva.com 	.driver = {
659f9b95980Sapatard@mandriva.com 		.name = DRV_NAME,
660eb632318SJean-Francois Moine 		.of_match_table = of_match_ptr(mvebu_audio_of_match),
661f9b95980Sapatard@mandriva.com 	},
662f9b95980Sapatard@mandriva.com };
663f9b95980Sapatard@mandriva.com 
66441b10225SAxel Lin module_platform_driver(kirkwood_i2s_driver);
665f9b95980Sapatard@mandriva.com 
666f9b95980Sapatard@mandriva.com /* Module information */
66769737897SArnaud Patard (Rtp) MODULE_AUTHOR("Arnaud Patard, <arnaud.patard@rtp-net.org>");
668f9b95980Sapatard@mandriva.com MODULE_DESCRIPTION("Kirkwood I2S SoC Interface");
669f9b95980Sapatard@mandriva.com MODULE_LICENSE("GPL");
67064ddf1f8SRussell King MODULE_ALIAS("platform:mvebu-audio");
671