1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for Atmel I2S controller
5 * Copyright (C) 2015 Atmel Corporation
7 * Author: Cyrille Pitchen <cyrille.pitchen@atmel.com>
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/device.h>
13 #include <linux/slab.h>
14 #include <linux/delay.h>
16 #include <linux/clk.h>
17 #include <linux/mfd/syscon.h>
19 #include <sound/core.h>
20 #include <sound/pcm.h>
21 #include <sound/pcm_params.h>
22 #include <sound/initval.h>
23 #include <sound/soc.h>
24 #include <sound/dmaengine_pcm.h>
26 #define ATMEL_I2SC_MAX_TDM_CHANNELS 8
29 * ---- I2S Controller Register map ----
31 #define ATMEL_I2SC_CR 0x0000 /* Control Register */
32 #define ATMEL_I2SC_MR 0x0004 /* Mode Register */
33 #define ATMEL_I2SC_SR 0x0008 /* Status Register */
34 #define ATMEL_I2SC_SCR 0x000c /* Status Clear Register */
35 #define ATMEL_I2SC_SSR 0x0010 /* Status Set Register */
36 #define ATMEL_I2SC_IER 0x0014 /* Interrupt Enable Register */
37 #define ATMEL_I2SC_IDR 0x0018 /* Interrupt Disable Register */
38 #define ATMEL_I2SC_IMR 0x001c /* Interrupt Mask Register */
39 #define ATMEL_I2SC_RHR 0x0020 /* Receiver Holding Register */
40 #define ATMEL_I2SC_THR 0x0024 /* Transmitter Holding Register */
41 #define ATMEL_I2SC_VERSION 0x0028 /* Version Register */
44 * ---- Control Register (Write-only) ----
46 #define ATMEL_I2SC_CR_RXEN BIT(0) /* Receiver Enable */
47 #define ATMEL_I2SC_CR_RXDIS BIT(1) /* Receiver Disable */
48 #define ATMEL_I2SC_CR_CKEN BIT(2) /* Clock Enable */
49 #define ATMEL_I2SC_CR_CKDIS BIT(3) /* Clock Disable */
50 #define ATMEL_I2SC_CR_TXEN BIT(4) /* Transmitter Enable */
51 #define ATMEL_I2SC_CR_TXDIS BIT(5) /* Transmitter Disable */
52 #define ATMEL_I2SC_CR_SWRST BIT(7) /* Software Reset */
55 * ---- Mode Register (Read/Write) ----
57 #define ATMEL_I2SC_MR_MODE_MASK GENMASK(0, 0)
58 #define ATMEL_I2SC_MR_MODE_SLAVE (0 << 0)
59 #define ATMEL_I2SC_MR_MODE_MASTER (1 << 0)
61 #define ATMEL_I2SC_MR_DATALENGTH_MASK GENMASK(4, 2)
62 #define ATMEL_I2SC_MR_DATALENGTH_32_BITS (0 << 2)
63 #define ATMEL_I2SC_MR_DATALENGTH_24_BITS (1 << 2)
64 #define ATMEL_I2SC_MR_DATALENGTH_20_BITS (2 << 2)
65 #define ATMEL_I2SC_MR_DATALENGTH_18_BITS (3 << 2)
66 #define ATMEL_I2SC_MR_DATALENGTH_16_BITS (4 << 2)
67 #define ATMEL_I2SC_MR_DATALENGTH_16_BITS_COMPACT (5 << 2)
68 #define ATMEL_I2SC_MR_DATALENGTH_8_BITS (6 << 2)
69 #define ATMEL_I2SC_MR_DATALENGTH_8_BITS_COMPACT (7 << 2)
71 #define ATMEL_I2SC_MR_FORMAT_MASK GENMASK(7, 6)
72 #define ATMEL_I2SC_MR_FORMAT_I2S (0 << 6)
73 #define ATMEL_I2SC_MR_FORMAT_LJ (1 << 6) /* Left Justified */
74 #define ATMEL_I2SC_MR_FORMAT_TDM (2 << 6)
75 #define ATMEL_I2SC_MR_FORMAT_TDMLJ (3 << 6)
77 /* Left audio samples duplicated to right audio channel */
78 #define ATMEL_I2SC_MR_RXMONO BIT(8)
80 /* Receiver uses one DMA channel ... */
81 #define ATMEL_I2SC_MR_RXDMA_MASK GENMASK(9, 9)
82 #define ATMEL_I2SC_MR_RXDMA_SINGLE (0 << 9) /* for all audio channels */
83 #define ATMEL_I2SC_MR_RXDMA_MULTIPLE (1 << 9) /* per audio channel */
85 /* I2SDO output of I2SC is internally connected to I2SDI input */
86 #define ATMEL_I2SC_MR_RXLOOP BIT(10)
88 /* Left audio samples duplicated to right audio channel */
89 #define ATMEL_I2SC_MR_TXMONO BIT(12)
91 /* Transmitter uses one DMA channel ... */
92 #define ATMEL_I2SC_MR_TXDMA_MASK GENMASK(13, 13)
93 #define ATMEL_I2SC_MR_TXDMA_SINGLE (0 << 13) /* for all audio channels */
94 #define ATMEL_I2SC_MR_TXDME_MULTIPLE (1 << 13) /* per audio channel */
96 /* x sample transmitted when underrun */
97 #define ATMEL_I2SC_MR_TXSAME_MASK GENMASK(14, 14)
98 #define ATMEL_I2SC_MR_TXSAME_ZERO (0 << 14) /* Zero sample */
99 #define ATMEL_I2SC_MR_TXSAME_PREVIOUS (1 << 14) /* Previous sample */
101 /* Audio Clock to I2SC Master Clock ratio */
102 #define ATMEL_I2SC_MR_IMCKDIV_MASK GENMASK(21, 16)
103 #define ATMEL_I2SC_MR_IMCKDIV(div) \
104 (((div) << 16) & ATMEL_I2SC_MR_IMCKDIV_MASK)
106 /* Master Clock to fs ratio */
107 #define ATMEL_I2SC_MR_IMCKFS_MASK GENMASK(29, 24)
108 #define ATMEL_I2SC_MR_IMCKFS(fs) \
109 (((fs) << 24) & ATMEL_I2SC_MR_IMCKFS_MASK)
111 /* Master Clock mode */
112 #define ATMEL_I2SC_MR_IMCKMODE_MASK GENMASK(30, 30)
113 /* 0: No master clock generated (selected clock drives I2SCK pin) */
114 #define ATMEL_I2SC_MR_IMCKMODE_I2SCK (0 << 30)
115 /* 1: master clock generated (internally generated clock drives I2SMCK pin) */
116 #define ATMEL_I2SC_MR_IMCKMODE_I2SMCK (1 << 30)
119 /* 0: slot is 32 bits wide for DATALENGTH = 18/20/24 bits. */
120 /* 1: slot is 24 bits wide for DATALENGTH = 18/20/24 bits. */
121 #define ATMEL_I2SC_MR_IWS BIT(31)
124 * ---- Status Registers ----
126 #define ATMEL_I2SC_SR_RXEN BIT(0) /* Receiver Enabled */
127 #define ATMEL_I2SC_SR_RXRDY BIT(1) /* Receive Ready */
128 #define ATMEL_I2SC_SR_RXOR BIT(2) /* Receive Overrun */
130 #define ATMEL_I2SC_SR_TXEN BIT(4) /* Transmitter Enabled */
131 #define ATMEL_I2SC_SR_TXRDY BIT(5) /* Transmit Ready */
132 #define ATMEL_I2SC_SR_TXUR BIT(6) /* Transmit Underrun */
134 /* Receive Overrun Channel */
135 #define ATMEL_I2SC_SR_RXORCH_MASK GENMASK(15, 8)
136 #define ATMEL_I2SC_SR_RXORCH(ch) (1 << (((ch) & 0x7) + 8))
138 /* Transmit Underrun Channel */
139 #define ATMEL_I2SC_SR_TXURCH_MASK GENMASK(27, 20)
140 #define ATMEL_I2SC_SR_TXURCH(ch) (1 << (((ch) & 0x7) + 20))
143 * ---- Interrupt Enable/Disable/Mask Registers ----
145 #define ATMEL_I2SC_INT_RXRDY ATMEL_I2SC_SR_RXRDY
146 #define ATMEL_I2SC_INT_RXOR ATMEL_I2SC_SR_RXOR
147 #define ATMEL_I2SC_INT_TXRDY ATMEL_I2SC_SR_TXRDY
148 #define ATMEL_I2SC_INT_TXUR ATMEL_I2SC_SR_TXUR
150 static const struct regmap_config atmel_i2s_regmap_config = {
154 .max_register = ATMEL_I2SC_VERSION,
157 struct atmel_i2s_gck_param {
164 #define I2S_MCK_12M288 12288000UL
165 #define I2S_MCK_11M2896 11289600UL
166 #define I2S_MCK_6M144 6144000UL
168 /* mck = (32 * (imckfs+1) / (imckdiv+1)) * fs */
169 static const struct atmel_i2s_gck_param gck_params[] = {
171 { 8000, I2S_MCK_6M144, 1, 47}, /* mck = 768 fs */
173 /* mck = 12.288MHz */
174 { 16000, I2S_MCK_12M288, 1, 47}, /* mck = 768 fs */
175 { 24000, I2S_MCK_12M288, 3, 63}, /* mck = 512 fs */
176 { 32000, I2S_MCK_12M288, 3, 47}, /* mck = 384 fs */
177 { 48000, I2S_MCK_12M288, 7, 63}, /* mck = 256 fs */
178 { 64000, I2S_MCK_12M288, 7, 47}, /* mck = 192 fs */
179 { 96000, I2S_MCK_12M288, 7, 31}, /* mck = 128 fs */
180 {192000, I2S_MCK_12M288, 7, 15}, /* mck = 64 fs */
182 /* mck = 11.2896MHz */
183 { 11025, I2S_MCK_11M2896, 1, 63}, /* mck = 1024 fs */
184 { 22050, I2S_MCK_11M2896, 3, 63}, /* mck = 512 fs */
185 { 44100, I2S_MCK_11M2896, 7, 63}, /* mck = 256 fs */
186 { 88200, I2S_MCK_11M2896, 7, 31}, /* mck = 128 fs */
187 {176400, I2S_MCK_11M2896, 7, 15}, /* mck = 64 fs */
190 struct atmel_i2s_dev;
192 struct atmel_i2s_caps {
193 int (*mck_init)(struct atmel_i2s_dev *, struct device_node *np);
196 struct atmel_i2s_dev {
198 struct regmap *regmap;
201 struct snd_dmaengine_dai_dma_data playback;
202 struct snd_dmaengine_dai_dma_data capture;
204 const struct atmel_i2s_gck_param *gck_param;
205 const struct atmel_i2s_caps *caps;
209 static irqreturn_t atmel_i2s_interrupt(int irq, void *dev_id)
211 struct atmel_i2s_dev *dev = dev_id;
212 unsigned int sr, imr, pending, ch, mask;
213 irqreturn_t ret = IRQ_NONE;
215 regmap_read(dev->regmap, ATMEL_I2SC_SR, &sr);
216 regmap_read(dev->regmap, ATMEL_I2SC_IMR, &imr);
222 if (pending & ATMEL_I2SC_INT_RXOR) {
223 mask = ATMEL_I2SC_SR_RXOR;
225 for (ch = 0; ch < ATMEL_I2SC_MAX_TDM_CHANNELS; ++ch) {
226 if (sr & ATMEL_I2SC_SR_RXORCH(ch)) {
227 mask |= ATMEL_I2SC_SR_RXORCH(ch);
229 "RX overrun on channel %d\n", ch);
232 regmap_write(dev->regmap, ATMEL_I2SC_SCR, mask);
236 if (pending & ATMEL_I2SC_INT_TXUR) {
237 mask = ATMEL_I2SC_SR_TXUR;
239 for (ch = 0; ch < ATMEL_I2SC_MAX_TDM_CHANNELS; ++ch) {
240 if (sr & ATMEL_I2SC_SR_TXURCH(ch)) {
241 mask |= ATMEL_I2SC_SR_TXURCH(ch);
243 "TX underrun on channel %d\n", ch);
246 regmap_write(dev->regmap, ATMEL_I2SC_SCR, mask);
253 #define ATMEL_I2S_RATES SNDRV_PCM_RATE_8000_192000
255 #define ATMEL_I2S_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
256 SNDRV_PCM_FMTBIT_S16_LE | \
257 SNDRV_PCM_FMTBIT_S18_3LE | \
258 SNDRV_PCM_FMTBIT_S20_3LE | \
259 SNDRV_PCM_FMTBIT_S24_3LE | \
260 SNDRV_PCM_FMTBIT_S24_LE | \
261 SNDRV_PCM_FMTBIT_S32_LE)
263 static int atmel_i2s_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
265 struct atmel_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
271 static int atmel_i2s_prepare(struct snd_pcm_substream *substream,
272 struct snd_soc_dai *dai)
274 struct atmel_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
275 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
276 unsigned int rhr, sr = 0;
279 regmap_read(dev->regmap, ATMEL_I2SC_SR, &sr);
280 if (sr & ATMEL_I2SC_SR_RXRDY) {
282 * The RX Ready flag should not be set. However if here,
283 * we flush (read) the Receive Holding Register to start
284 * from a clean state.
286 dev_dbg(dev->dev, "RXRDY is set\n");
287 regmap_read(dev->regmap, ATMEL_I2SC_RHR, &rhr);
294 static int atmel_i2s_get_gck_param(struct atmel_i2s_dev *dev, int fs)
299 dev_err(dev->dev, "cannot generate the I2S Master Clock\n");
304 * Find the best possible settings to generate the I2S Master Clock
305 * from the PLL Audio.
307 dev->gck_param = NULL;
309 for (i = 0; i < ARRAY_SIZE(gck_params); ++i) {
310 const struct atmel_i2s_gck_param *gck_param = &gck_params[i];
311 int val = abs(fs - gck_param->fs);
315 dev->gck_param = gck_param;
322 static int atmel_i2s_hw_params(struct snd_pcm_substream *substream,
323 struct snd_pcm_hw_params *params,
324 struct snd_soc_dai *dai)
326 struct atmel_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
327 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
328 unsigned int mr = 0, mr_mask;
331 mr_mask = ATMEL_I2SC_MR_FORMAT_MASK | ATMEL_I2SC_MR_MODE_MASK |
332 ATMEL_I2SC_MR_DATALENGTH_MASK;
334 mr_mask |= ATMEL_I2SC_MR_TXMONO;
336 mr_mask |= ATMEL_I2SC_MR_RXMONO;
338 switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
339 case SND_SOC_DAIFMT_I2S:
340 mr |= ATMEL_I2SC_MR_FORMAT_I2S;
344 dev_err(dev->dev, "unsupported bus format\n");
348 switch (dev->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
349 case SND_SOC_DAIFMT_BP_FP:
350 /* codec is slave, so cpu is master */
351 mr |= ATMEL_I2SC_MR_MODE_MASTER;
352 ret = atmel_i2s_get_gck_param(dev, params_rate(params));
357 case SND_SOC_DAIFMT_BC_FC:
358 /* codec is master, so cpu is slave */
359 mr |= ATMEL_I2SC_MR_MODE_SLAVE;
360 dev->gck_param = NULL;
364 dev_err(dev->dev, "unsupported master/slave mode\n");
368 switch (params_channels(params)) {
371 mr |= ATMEL_I2SC_MR_TXMONO;
373 mr |= ATMEL_I2SC_MR_RXMONO;
378 dev_err(dev->dev, "unsupported number of audio channels\n");
382 switch (params_format(params)) {
383 case SNDRV_PCM_FORMAT_S8:
384 mr |= ATMEL_I2SC_MR_DATALENGTH_8_BITS;
387 case SNDRV_PCM_FORMAT_S16_LE:
388 mr |= ATMEL_I2SC_MR_DATALENGTH_16_BITS;
391 case SNDRV_PCM_FORMAT_S18_3LE:
392 mr |= ATMEL_I2SC_MR_DATALENGTH_18_BITS | ATMEL_I2SC_MR_IWS;
395 case SNDRV_PCM_FORMAT_S20_3LE:
396 mr |= ATMEL_I2SC_MR_DATALENGTH_20_BITS | ATMEL_I2SC_MR_IWS;
399 case SNDRV_PCM_FORMAT_S24_3LE:
400 mr |= ATMEL_I2SC_MR_DATALENGTH_24_BITS | ATMEL_I2SC_MR_IWS;
403 case SNDRV_PCM_FORMAT_S24_LE:
404 mr |= ATMEL_I2SC_MR_DATALENGTH_24_BITS;
407 case SNDRV_PCM_FORMAT_S32_LE:
408 mr |= ATMEL_I2SC_MR_DATALENGTH_32_BITS;
412 dev_err(dev->dev, "unsupported size/endianness for audio samples\n");
416 return regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, mr);
419 static int atmel_i2s_switch_mck_generator(struct atmel_i2s_dev *dev,
422 unsigned int mr, mr_mask;
423 unsigned long gclk_rate;
427 mr_mask = (ATMEL_I2SC_MR_IMCKDIV_MASK |
428 ATMEL_I2SC_MR_IMCKFS_MASK |
429 ATMEL_I2SC_MR_IMCKMODE_MASK);
432 /* Disable the I2S Master Clock generator. */
433 ret = regmap_write(dev->regmap, ATMEL_I2SC_CR,
434 ATMEL_I2SC_CR_CKDIS);
438 /* Reset the I2S Master Clock generator settings. */
439 ret = regmap_update_bits(dev->regmap, ATMEL_I2SC_MR,
444 /* Disable/unprepare the PMC generated clock. */
445 clk_disable_unprepare(dev->gclk);
453 gclk_rate = dev->gck_param->mck * (dev->gck_param->imckdiv + 1);
455 ret = clk_set_rate(dev->gclk, gclk_rate);
459 ret = clk_prepare_enable(dev->gclk);
463 /* Update the Mode Register to generate the I2S Master Clock. */
464 mr |= ATMEL_I2SC_MR_IMCKDIV(dev->gck_param->imckdiv);
465 mr |= ATMEL_I2SC_MR_IMCKFS(dev->gck_param->imckfs);
466 mr |= ATMEL_I2SC_MR_IMCKMODE_I2SMCK;
467 ret = regmap_update_bits(dev->regmap, ATMEL_I2SC_MR, mr_mask, mr);
471 /* Finally enable the I2S Master Clock generator. */
472 return regmap_write(dev->regmap, ATMEL_I2SC_CR,
476 static int atmel_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
477 struct snd_soc_dai *dai)
479 struct atmel_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
480 bool is_playback = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
481 bool is_master, mck_enabled;
486 case SNDRV_PCM_TRIGGER_START:
487 case SNDRV_PCM_TRIGGER_RESUME:
488 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
489 cr = is_playback ? ATMEL_I2SC_CR_TXEN : ATMEL_I2SC_CR_RXEN;
492 case SNDRV_PCM_TRIGGER_STOP:
493 case SNDRV_PCM_TRIGGER_SUSPEND:
494 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
495 cr = is_playback ? ATMEL_I2SC_CR_TXDIS : ATMEL_I2SC_CR_RXDIS;
502 /* Read the Mode Register to retrieve the master/slave state. */
503 err = regmap_read(dev->regmap, ATMEL_I2SC_MR, &mr);
506 is_master = (mr & ATMEL_I2SC_MR_MODE_MASK) == ATMEL_I2SC_MR_MODE_MASTER;
508 /* If master starts, enable the audio clock. */
509 if (is_master && mck_enabled) {
510 if (!dev->clk_use_no) {
511 err = atmel_i2s_switch_mck_generator(dev, true);
518 err = regmap_write(dev->regmap, ATMEL_I2SC_CR, cr);
522 /* If master stops, disable the audio clock. */
523 if (is_master && !mck_enabled) {
524 if (dev->clk_use_no == 1) {
525 err = atmel_i2s_switch_mck_generator(dev, false);
535 static const struct snd_soc_dai_ops atmel_i2s_dai_ops = {
536 .prepare = atmel_i2s_prepare,
537 .trigger = atmel_i2s_trigger,
538 .hw_params = atmel_i2s_hw_params,
539 .set_fmt = atmel_i2s_set_dai_fmt,
542 static int atmel_i2s_dai_probe(struct snd_soc_dai *dai)
544 struct atmel_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
546 snd_soc_dai_init_dma_data(dai, &dev->playback, &dev->capture);
550 static struct snd_soc_dai_driver atmel_i2s_dai = {
551 .probe = atmel_i2s_dai_probe,
555 .rates = ATMEL_I2S_RATES,
556 .formats = ATMEL_I2S_FORMATS,
561 .rates = ATMEL_I2S_RATES,
562 .formats = ATMEL_I2S_FORMATS,
564 .ops = &atmel_i2s_dai_ops,
566 .symmetric_sample_bits = 1,
569 static const struct snd_soc_component_driver atmel_i2s_component = {
571 .legacy_dai_naming = 1,
574 static int atmel_i2s_sama5d2_mck_init(struct atmel_i2s_dev *dev,
575 struct device_node *np)
583 /* muxclk is optional, so we return error for probe defer only */
584 muxclk = devm_clk_get(dev->dev, "muxclk");
585 if (IS_ERR(muxclk)) {
586 err = PTR_ERR(muxclk);
587 if (err == -EPROBE_DEFER)
588 return -EPROBE_DEFER;
590 "failed to get the I2S clock control: %d\n", err);
594 return clk_set_parent(muxclk, dev->gclk);
597 static const struct atmel_i2s_caps atmel_i2s_sama5d2_caps = {
598 .mck_init = atmel_i2s_sama5d2_mck_init,
601 static const struct of_device_id atmel_i2s_dt_ids[] = {
603 .compatible = "atmel,sama5d2-i2s",
604 .data = (void *)&atmel_i2s_sama5d2_caps,
610 MODULE_DEVICE_TABLE(of, atmel_i2s_dt_ids);
612 static int atmel_i2s_probe(struct platform_device *pdev)
614 struct device_node *np = pdev->dev.of_node;
615 const struct of_device_id *match;
616 struct atmel_i2s_dev *dev;
617 struct resource *mem;
618 struct regmap *regmap;
622 unsigned int pcm_flags = 0;
623 unsigned int version;
625 /* Get memory for driver data. */
626 dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL);
630 /* Get hardware capabilities. */
631 match = of_match_node(atmel_i2s_dt_ids, np);
633 dev->caps = match->data;
635 /* Map I/O registers. */
636 base = devm_platform_get_and_ioremap_resource(pdev, 0, &mem);
638 return PTR_ERR(base);
640 regmap = devm_regmap_init_mmio(&pdev->dev, base,
641 &atmel_i2s_regmap_config);
643 return PTR_ERR(regmap);
646 irq = platform_get_irq(pdev, 0);
650 err = devm_request_irq(&pdev->dev, irq, atmel_i2s_interrupt, 0,
651 dev_name(&pdev->dev), dev);
655 /* Get the peripheral clock. */
656 dev->pclk = devm_clk_get(&pdev->dev, "pclk");
657 if (IS_ERR(dev->pclk)) {
658 err = PTR_ERR(dev->pclk);
660 "failed to get the peripheral clock: %d\n", err);
664 /* Get audio clock to generate the I2S Master Clock (I2S_MCK) */
665 dev->gclk = devm_clk_get(&pdev->dev, "gclk");
666 if (IS_ERR(dev->gclk)) {
667 if (PTR_ERR(dev->gclk) == -EPROBE_DEFER)
668 return -EPROBE_DEFER;
669 /* Master Mode not supported */
672 dev->dev = &pdev->dev;
673 dev->regmap = regmap;
674 platform_set_drvdata(pdev, dev);
676 /* Do hardware specific settings to initialize I2S_MCK generator */
677 if (dev->caps && dev->caps->mck_init) {
678 err = dev->caps->mck_init(dev, np);
683 /* Enable the peripheral clock. */
684 err = clk_prepare_enable(dev->pclk);
688 /* Get IP version. */
689 regmap_read(dev->regmap, ATMEL_I2SC_VERSION, &version);
690 dev_info(&pdev->dev, "hw version: %#x\n", version);
692 /* Enable error interrupts. */
693 regmap_write(dev->regmap, ATMEL_I2SC_IER,
694 ATMEL_I2SC_INT_RXOR | ATMEL_I2SC_INT_TXUR);
696 err = devm_snd_soc_register_component(&pdev->dev,
697 &atmel_i2s_component,
700 dev_err(&pdev->dev, "failed to register DAI: %d\n", err);
701 clk_disable_unprepare(dev->pclk);
705 /* Prepare DMA config. */
706 dev->playback.addr = (dma_addr_t)mem->start + ATMEL_I2SC_THR;
707 dev->playback.maxburst = 1;
708 dev->capture.addr = (dma_addr_t)mem->start + ATMEL_I2SC_RHR;
709 dev->capture.maxburst = 1;
711 if (of_property_match_string(np, "dma-names", "rx-tx") == 0)
712 pcm_flags |= SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX;
713 err = devm_snd_dmaengine_pcm_register(&pdev->dev, NULL, pcm_flags);
715 dev_err(&pdev->dev, "failed to register PCM: %d\n", err);
716 clk_disable_unprepare(dev->pclk);
723 static void atmel_i2s_remove(struct platform_device *pdev)
725 struct atmel_i2s_dev *dev = platform_get_drvdata(pdev);
727 clk_disable_unprepare(dev->pclk);
730 static struct platform_driver atmel_i2s_driver = {
733 .of_match_table = of_match_ptr(atmel_i2s_dt_ids),
735 .probe = atmel_i2s_probe,
736 .remove_new = atmel_i2s_remove,
738 module_platform_driver(atmel_i2s_driver);
740 MODULE_DESCRIPTION("Atmel I2S Controller driver");
741 MODULE_AUTHOR("Cyrille Pitchen <cyrille.pitchen@atmel.com>");
742 MODULE_LICENSE("GPL v2");