• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  *  Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
4  */
5 
6 #include <linux/init.h>
7 #include <linux/io.h>
8 #include <linux/of.h>
9 #include <linux/of_device.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/platform_device.h>
13 #include <linux/slab.h>
14 
15 #include <linux/clk.h>
16 #include <linux/delay.h>
17 
18 #include <linux/dma-mapping.h>
19 
20 #include <sound/core.h>
21 #include <sound/pcm.h>
22 #include <sound/pcm_params.h>
23 #include <sound/soc.h>
24 #include <sound/initval.h>
25 #include <sound/dmaengine_pcm.h>
26 
27 #include "jz4740-i2s.h"
28 
29 #define JZ4740_DMA_TYPE_AIC_TRANSMIT 24
30 #define JZ4740_DMA_TYPE_AIC_RECEIVE 25
31 
32 #define JZ_REG_AIC_CONF		0x00
33 #define JZ_REG_AIC_CTRL		0x04
34 #define JZ_REG_AIC_I2S_FMT	0x10
35 #define JZ_REG_AIC_FIFO_STATUS	0x14
36 #define JZ_REG_AIC_I2S_STATUS	0x1c
37 #define JZ_REG_AIC_CLK_DIV	0x30
38 #define JZ_REG_AIC_FIFO		0x34
39 
40 #define JZ_AIC_CONF_FIFO_RX_THRESHOLD_MASK (0xf << 12)
41 #define JZ_AIC_CONF_FIFO_TX_THRESHOLD_MASK (0xf <<  8)
42 #define JZ_AIC_CONF_OVERFLOW_PLAY_LAST BIT(6)
43 #define JZ_AIC_CONF_INTERNAL_CODEC BIT(5)
44 #define JZ_AIC_CONF_I2S BIT(4)
45 #define JZ_AIC_CONF_RESET BIT(3)
46 #define JZ_AIC_CONF_BIT_CLK_MASTER BIT(2)
47 #define JZ_AIC_CONF_SYNC_CLK_MASTER BIT(1)
48 #define JZ_AIC_CONF_ENABLE BIT(0)
49 
50 #define JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 12
51 #define JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 8
52 #define JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET 24
53 #define JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET 16
54 #define JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_MASK \
55 			(0xf << JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET)
56 #define JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_MASK \
57 			(0x1f <<  JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET)
58 
59 #define JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_MASK (0x7 << 19)
60 #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK (0x7 << 16)
61 #define JZ_AIC_CTRL_ENABLE_RX_DMA BIT(15)
62 #define JZ_AIC_CTRL_ENABLE_TX_DMA BIT(14)
63 #define JZ_AIC_CTRL_MONO_TO_STEREO BIT(11)
64 #define JZ_AIC_CTRL_SWITCH_ENDIANNESS BIT(10)
65 #define JZ_AIC_CTRL_SIGNED_TO_UNSIGNED BIT(9)
66 #define JZ_AIC_CTRL_FLUSH		BIT(8)
67 #define JZ_AIC_CTRL_ENABLE_ROR_INT BIT(6)
68 #define JZ_AIC_CTRL_ENABLE_TUR_INT BIT(5)
69 #define JZ_AIC_CTRL_ENABLE_RFS_INT BIT(4)
70 #define JZ_AIC_CTRL_ENABLE_TFS_INT BIT(3)
71 #define JZ_AIC_CTRL_ENABLE_LOOPBACK BIT(2)
72 #define JZ_AIC_CTRL_ENABLE_PLAYBACK BIT(1)
73 #define JZ_AIC_CTRL_ENABLE_CAPTURE BIT(0)
74 
75 #define JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_OFFSET 19
76 #define JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET  16
77 
78 #define JZ_AIC_I2S_FMT_DISABLE_BIT_CLK BIT(12)
79 #define JZ_AIC_I2S_FMT_DISABLE_BIT_ICLK BIT(13)
80 #define JZ_AIC_I2S_FMT_ENABLE_SYS_CLK BIT(4)
81 #define JZ_AIC_I2S_FMT_MSB BIT(0)
82 
83 #define JZ_AIC_I2S_STATUS_BUSY BIT(2)
84 
85 #define JZ_AIC_CLK_DIV_MASK 0xf
86 #define I2SDIV_DV_SHIFT 0
87 #define I2SDIV_DV_MASK (0xf << I2SDIV_DV_SHIFT)
88 #define I2SDIV_IDV_SHIFT 8
89 #define I2SDIV_IDV_MASK (0xf << I2SDIV_IDV_SHIFT)
90 
91 enum jz47xx_i2s_version {
92 	JZ_I2S_JZ4740,
93 	JZ_I2S_JZ4780,
94 };
95 
96 struct jz4740_i2s {
97 	struct resource *mem;
98 	void __iomem *base;
99 	dma_addr_t phys_base;
100 
101 	struct clk *clk_aic;
102 	struct clk *clk_i2s;
103 
104 	struct snd_dmaengine_dai_dma_data playback_dma_data;
105 	struct snd_dmaengine_dai_dma_data capture_dma_data;
106 
107 	enum jz47xx_i2s_version version;
108 };
109 
jz4740_i2s_read(const struct jz4740_i2s * i2s,unsigned int reg)110 static inline uint32_t jz4740_i2s_read(const struct jz4740_i2s *i2s,
111 	unsigned int reg)
112 {
113 	return readl(i2s->base + reg);
114 }
115 
jz4740_i2s_write(const struct jz4740_i2s * i2s,unsigned int reg,uint32_t value)116 static inline void jz4740_i2s_write(const struct jz4740_i2s *i2s,
117 	unsigned int reg, uint32_t value)
118 {
119 	writel(value, i2s->base + reg);
120 }
121 
jz4740_i2s_startup(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)122 static int jz4740_i2s_startup(struct snd_pcm_substream *substream,
123 	struct snd_soc_dai *dai)
124 {
125 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
126 	uint32_t conf, ctrl;
127 	int ret;
128 
129 	if (dai->active)
130 		return 0;
131 
132 	ctrl = jz4740_i2s_read(i2s, JZ_REG_AIC_CTRL);
133 	ctrl |= JZ_AIC_CTRL_FLUSH;
134 	jz4740_i2s_write(i2s, JZ_REG_AIC_CTRL, ctrl);
135 
136 	ret = clk_prepare_enable(i2s->clk_i2s);
137 	if (ret)
138 		return ret;
139 
140 	conf = jz4740_i2s_read(i2s, JZ_REG_AIC_CONF);
141 	conf |= JZ_AIC_CONF_ENABLE;
142 	jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf);
143 
144 	return 0;
145 }
146 
jz4740_i2s_shutdown(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)147 static void jz4740_i2s_shutdown(struct snd_pcm_substream *substream,
148 	struct snd_soc_dai *dai)
149 {
150 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
151 	uint32_t conf;
152 
153 	if (dai->active)
154 		return;
155 
156 	conf = jz4740_i2s_read(i2s, JZ_REG_AIC_CONF);
157 	conf &= ~JZ_AIC_CONF_ENABLE;
158 	jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf);
159 
160 	clk_disable_unprepare(i2s->clk_i2s);
161 }
162 
jz4740_i2s_trigger(struct snd_pcm_substream * substream,int cmd,struct snd_soc_dai * dai)163 static int jz4740_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
164 	struct snd_soc_dai *dai)
165 {
166 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
167 
168 	uint32_t ctrl;
169 	uint32_t mask;
170 
171 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
172 		mask = JZ_AIC_CTRL_ENABLE_PLAYBACK | JZ_AIC_CTRL_ENABLE_TX_DMA;
173 	else
174 		mask = JZ_AIC_CTRL_ENABLE_CAPTURE | JZ_AIC_CTRL_ENABLE_RX_DMA;
175 
176 	ctrl = jz4740_i2s_read(i2s, JZ_REG_AIC_CTRL);
177 
178 	switch (cmd) {
179 	case SNDRV_PCM_TRIGGER_START:
180 	case SNDRV_PCM_TRIGGER_RESUME:
181 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
182 		ctrl |= mask;
183 		break;
184 	case SNDRV_PCM_TRIGGER_STOP:
185 	case SNDRV_PCM_TRIGGER_SUSPEND:
186 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
187 		ctrl &= ~mask;
188 		break;
189 	default:
190 		return -EINVAL;
191 	}
192 
193 	jz4740_i2s_write(i2s, JZ_REG_AIC_CTRL, ctrl);
194 
195 	return 0;
196 }
197 
jz4740_i2s_set_fmt(struct snd_soc_dai * dai,unsigned int fmt)198 static int jz4740_i2s_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
199 {
200 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
201 
202 	uint32_t format = 0;
203 	uint32_t conf;
204 
205 	conf = jz4740_i2s_read(i2s, JZ_REG_AIC_CONF);
206 
207 	conf &= ~(JZ_AIC_CONF_BIT_CLK_MASTER | JZ_AIC_CONF_SYNC_CLK_MASTER);
208 
209 	switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
210 	case SND_SOC_DAIFMT_CBS_CFS:
211 		conf |= JZ_AIC_CONF_BIT_CLK_MASTER | JZ_AIC_CONF_SYNC_CLK_MASTER;
212 		format |= JZ_AIC_I2S_FMT_ENABLE_SYS_CLK;
213 		break;
214 	case SND_SOC_DAIFMT_CBM_CFS:
215 		conf |= JZ_AIC_CONF_SYNC_CLK_MASTER;
216 		break;
217 	case SND_SOC_DAIFMT_CBS_CFM:
218 		conf |= JZ_AIC_CONF_BIT_CLK_MASTER;
219 		break;
220 	case SND_SOC_DAIFMT_CBM_CFM:
221 		break;
222 	default:
223 		return -EINVAL;
224 	}
225 
226 	switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
227 	case SND_SOC_DAIFMT_MSB:
228 		format |= JZ_AIC_I2S_FMT_MSB;
229 		break;
230 	case SND_SOC_DAIFMT_I2S:
231 		break;
232 	default:
233 		return -EINVAL;
234 	}
235 
236 	switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
237 	case SND_SOC_DAIFMT_NB_NF:
238 		break;
239 	default:
240 		return -EINVAL;
241 	}
242 
243 	jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf);
244 	jz4740_i2s_write(i2s, JZ_REG_AIC_I2S_FMT, format);
245 
246 	return 0;
247 }
248 
jz4740_i2s_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params,struct snd_soc_dai * dai)249 static int jz4740_i2s_hw_params(struct snd_pcm_substream *substream,
250 	struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
251 {
252 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
253 	unsigned int sample_size;
254 	uint32_t ctrl, div_reg;
255 	int div;
256 
257 	ctrl = jz4740_i2s_read(i2s, JZ_REG_AIC_CTRL);
258 
259 	div_reg = jz4740_i2s_read(i2s, JZ_REG_AIC_CLK_DIV);
260 	div = clk_get_rate(i2s->clk_i2s) / (64 * params_rate(params));
261 
262 	switch (params_format(params)) {
263 	case SNDRV_PCM_FORMAT_S8:
264 		sample_size = 0;
265 		break;
266 	case SNDRV_PCM_FORMAT_S16:
267 		sample_size = 1;
268 		break;
269 	default:
270 		return -EINVAL;
271 	}
272 
273 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
274 		ctrl &= ~JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_MASK;
275 		ctrl |= sample_size << JZ_AIC_CTRL_OUTPUT_SAMPLE_SIZE_OFFSET;
276 		if (params_channels(params) == 1)
277 			ctrl |= JZ_AIC_CTRL_MONO_TO_STEREO;
278 		else
279 			ctrl &= ~JZ_AIC_CTRL_MONO_TO_STEREO;
280 
281 		div_reg &= ~I2SDIV_DV_MASK;
282 		div_reg |= (div - 1) << I2SDIV_DV_SHIFT;
283 	} else {
284 		ctrl &= ~JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK;
285 		ctrl |= sample_size << JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET;
286 
287 		if (i2s->version >= JZ_I2S_JZ4780) {
288 			div_reg &= ~I2SDIV_IDV_MASK;
289 			div_reg |= (div - 1) << I2SDIV_IDV_SHIFT;
290 		} else {
291 			div_reg &= ~I2SDIV_DV_MASK;
292 			div_reg |= (div - 1) << I2SDIV_DV_SHIFT;
293 		}
294 	}
295 
296 	jz4740_i2s_write(i2s, JZ_REG_AIC_CTRL, ctrl);
297 	jz4740_i2s_write(i2s, JZ_REG_AIC_CLK_DIV, div_reg);
298 
299 	return 0;
300 }
301 
jz4740_i2s_set_sysclk(struct snd_soc_dai * dai,int clk_id,unsigned int freq,int dir)302 static int jz4740_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
303 	unsigned int freq, int dir)
304 {
305 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
306 	struct clk *parent;
307 	int ret = 0;
308 
309 	switch (clk_id) {
310 	case JZ4740_I2S_CLKSRC_EXT:
311 		parent = clk_get(NULL, "ext");
312 		if (IS_ERR(parent))
313 			return PTR_ERR(parent);
314 		clk_set_parent(i2s->clk_i2s, parent);
315 		break;
316 	case JZ4740_I2S_CLKSRC_PLL:
317 		parent = clk_get(NULL, "pll half");
318 		if (IS_ERR(parent))
319 			return PTR_ERR(parent);
320 		clk_set_parent(i2s->clk_i2s, parent);
321 		ret = clk_set_rate(i2s->clk_i2s, freq);
322 		break;
323 	default:
324 		return -EINVAL;
325 	}
326 	clk_put(parent);
327 
328 	return ret;
329 }
330 
jz4740_i2s_suspend(struct snd_soc_dai * dai)331 static int jz4740_i2s_suspend(struct snd_soc_dai *dai)
332 {
333 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
334 	uint32_t conf;
335 
336 	if (dai->active) {
337 		conf = jz4740_i2s_read(i2s, JZ_REG_AIC_CONF);
338 		conf &= ~JZ_AIC_CONF_ENABLE;
339 		jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf);
340 
341 		clk_disable_unprepare(i2s->clk_i2s);
342 	}
343 
344 	clk_disable_unprepare(i2s->clk_aic);
345 
346 	return 0;
347 }
348 
jz4740_i2s_resume(struct snd_soc_dai * dai)349 static int jz4740_i2s_resume(struct snd_soc_dai *dai)
350 {
351 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
352 	uint32_t conf;
353 	int ret;
354 
355 	ret = clk_prepare_enable(i2s->clk_aic);
356 	if (ret)
357 		return ret;
358 
359 	if (dai->active) {
360 		ret = clk_prepare_enable(i2s->clk_i2s);
361 		if (ret) {
362 			clk_disable_unprepare(i2s->clk_aic);
363 			return ret;
364 		}
365 
366 		conf = jz4740_i2s_read(i2s, JZ_REG_AIC_CONF);
367 		conf |= JZ_AIC_CONF_ENABLE;
368 		jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf);
369 	}
370 
371 	return 0;
372 }
373 
jz4740_i2c_init_pcm_config(struct jz4740_i2s * i2s)374 static void jz4740_i2c_init_pcm_config(struct jz4740_i2s *i2s)
375 {
376 	struct snd_dmaengine_dai_dma_data *dma_data;
377 
378 	/* Playback */
379 	dma_data = &i2s->playback_dma_data;
380 	dma_data->maxburst = 16;
381 	dma_data->slave_id = JZ4740_DMA_TYPE_AIC_TRANSMIT;
382 	dma_data->addr = i2s->phys_base + JZ_REG_AIC_FIFO;
383 
384 	/* Capture */
385 	dma_data = &i2s->capture_dma_data;
386 	dma_data->maxburst = 16;
387 	dma_data->slave_id = JZ4740_DMA_TYPE_AIC_RECEIVE;
388 	dma_data->addr = i2s->phys_base + JZ_REG_AIC_FIFO;
389 }
390 
jz4740_i2s_dai_probe(struct snd_soc_dai * dai)391 static int jz4740_i2s_dai_probe(struct snd_soc_dai *dai)
392 {
393 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
394 	uint32_t conf;
395 	int ret;
396 
397 	ret = clk_prepare_enable(i2s->clk_aic);
398 	if (ret)
399 		return ret;
400 
401 	jz4740_i2c_init_pcm_config(i2s);
402 	snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data,
403 		&i2s->capture_dma_data);
404 
405 	if (i2s->version >= JZ_I2S_JZ4780) {
406 		conf = (7 << JZ4780_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) |
407 			(8 << JZ4780_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) |
408 			JZ_AIC_CONF_OVERFLOW_PLAY_LAST |
409 			JZ_AIC_CONF_I2S |
410 			JZ_AIC_CONF_INTERNAL_CODEC;
411 	} else {
412 		conf = (7 << JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) |
413 			(8 << JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) |
414 			JZ_AIC_CONF_OVERFLOW_PLAY_LAST |
415 			JZ_AIC_CONF_I2S |
416 			JZ_AIC_CONF_INTERNAL_CODEC;
417 	}
418 
419 	jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, JZ_AIC_CONF_RESET);
420 	jz4740_i2s_write(i2s, JZ_REG_AIC_CONF, conf);
421 
422 	return 0;
423 }
424 
jz4740_i2s_dai_remove(struct snd_soc_dai * dai)425 static int jz4740_i2s_dai_remove(struct snd_soc_dai *dai)
426 {
427 	struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
428 
429 	clk_disable_unprepare(i2s->clk_aic);
430 	return 0;
431 }
432 
433 static const struct snd_soc_dai_ops jz4740_i2s_dai_ops = {
434 	.startup = jz4740_i2s_startup,
435 	.shutdown = jz4740_i2s_shutdown,
436 	.trigger = jz4740_i2s_trigger,
437 	.hw_params = jz4740_i2s_hw_params,
438 	.set_fmt = jz4740_i2s_set_fmt,
439 	.set_sysclk = jz4740_i2s_set_sysclk,
440 };
441 
442 #define JZ4740_I2S_FMTS (SNDRV_PCM_FMTBIT_S8 | \
443 		SNDRV_PCM_FMTBIT_S16_LE)
444 
445 static struct snd_soc_dai_driver jz4740_i2s_dai = {
446 	.probe = jz4740_i2s_dai_probe,
447 	.remove = jz4740_i2s_dai_remove,
448 	.playback = {
449 		.channels_min = 1,
450 		.channels_max = 2,
451 		.rates = SNDRV_PCM_RATE_8000_48000,
452 		.formats = JZ4740_I2S_FMTS,
453 	},
454 	.capture = {
455 		.channels_min = 2,
456 		.channels_max = 2,
457 		.rates = SNDRV_PCM_RATE_8000_48000,
458 		.formats = JZ4740_I2S_FMTS,
459 	},
460 	.symmetric_rates = 1,
461 	.ops = &jz4740_i2s_dai_ops,
462 	.suspend = jz4740_i2s_suspend,
463 	.resume = jz4740_i2s_resume,
464 };
465 
466 static struct snd_soc_dai_driver jz4780_i2s_dai = {
467 	.probe = jz4740_i2s_dai_probe,
468 	.remove = jz4740_i2s_dai_remove,
469 	.playback = {
470 		.channels_min = 1,
471 		.channels_max = 2,
472 		.rates = SNDRV_PCM_RATE_8000_48000,
473 		.formats = JZ4740_I2S_FMTS,
474 	},
475 	.capture = {
476 		.channels_min = 2,
477 		.channels_max = 2,
478 		.rates = SNDRV_PCM_RATE_8000_48000,
479 		.formats = JZ4740_I2S_FMTS,
480 	},
481 	.ops = &jz4740_i2s_dai_ops,
482 	.suspend = jz4740_i2s_suspend,
483 	.resume = jz4740_i2s_resume,
484 };
485 
486 static const struct snd_soc_component_driver jz4740_i2s_component = {
487 	.name		= "jz4740-i2s",
488 };
489 
490 #ifdef CONFIG_OF
491 static const struct of_device_id jz4740_of_matches[] = {
492 	{ .compatible = "ingenic,jz4740-i2s", .data = (void *)JZ_I2S_JZ4740 },
493 	{ .compatible = "ingenic,jz4780-i2s", .data = (void *)JZ_I2S_JZ4780 },
494 	{ /* sentinel */ }
495 };
496 MODULE_DEVICE_TABLE(of, jz4740_of_matches);
497 #endif
498 
jz4740_i2s_dev_probe(struct platform_device * pdev)499 static int jz4740_i2s_dev_probe(struct platform_device *pdev)
500 {
501 	struct jz4740_i2s *i2s;
502 	struct resource *mem;
503 	int ret;
504 	const struct of_device_id *match;
505 
506 	i2s = devm_kzalloc(&pdev->dev, sizeof(*i2s), GFP_KERNEL);
507 	if (!i2s)
508 		return -ENOMEM;
509 
510 	match = of_match_device(jz4740_of_matches, &pdev->dev);
511 	if (match)
512 		i2s->version = (enum jz47xx_i2s_version)match->data;
513 
514 	mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
515 	i2s->base = devm_ioremap_resource(&pdev->dev, mem);
516 	if (IS_ERR(i2s->base))
517 		return PTR_ERR(i2s->base);
518 
519 	i2s->phys_base = mem->start;
520 
521 	i2s->clk_aic = devm_clk_get(&pdev->dev, "aic");
522 	if (IS_ERR(i2s->clk_aic))
523 		return PTR_ERR(i2s->clk_aic);
524 
525 	i2s->clk_i2s = devm_clk_get(&pdev->dev, "i2s");
526 	if (IS_ERR(i2s->clk_i2s))
527 		return PTR_ERR(i2s->clk_i2s);
528 
529 	platform_set_drvdata(pdev, i2s);
530 
531 	if (i2s->version == JZ_I2S_JZ4780)
532 		ret = devm_snd_soc_register_component(&pdev->dev,
533 			&jz4740_i2s_component, &jz4780_i2s_dai, 1);
534 	else
535 		ret = devm_snd_soc_register_component(&pdev->dev,
536 			&jz4740_i2s_component, &jz4740_i2s_dai, 1);
537 
538 	if (ret)
539 		return ret;
540 
541 	return devm_snd_dmaengine_pcm_register(&pdev->dev, NULL,
542 		SND_DMAENGINE_PCM_FLAG_COMPAT);
543 }
544 
545 static struct platform_driver jz4740_i2s_driver = {
546 	.probe = jz4740_i2s_dev_probe,
547 	.driver = {
548 		.name = "jz4740-i2s",
549 		.of_match_table = of_match_ptr(jz4740_of_matches)
550 	},
551 };
552 
553 module_platform_driver(jz4740_i2s_driver);
554 
555 MODULE_AUTHOR("Lars-Peter Clausen, <lars@metafoo.de>");
556 MODULE_DESCRIPTION("Ingenic JZ4740 SoC I2S driver");
557 MODULE_LICENSE("GPL");
558 MODULE_ALIAS("platform:jz4740-i2s");
559