1 // SPDX-License-Identifier: GPL-2.0+
3 // ALSA Soc Audio Layer - S3C2412 I2S driver
5 // Copyright (c) 2006 Wolfson Microelectronics PLC.
6 // Graeme Gregory graeme.gregory@wolfsonmicro.com
7 // linux@wolfsonmicro.com
9 // Copyright (c) 2007, 2004-2005 Simtec Electronics
10 // http://armlinux.simtec.co.uk/
11 // Ben Dooks <ben@simtec.co.uk>
13 #include <linux/delay.h>
14 #include <linux/gpio.h>
15 #include <linux/clk.h>
17 #include <linux/module.h>
19 #include <sound/soc.h>
20 #include <sound/pcm_params.h>
23 #include "regs-i2s-v2.h"
24 #include "s3c2412-i2s.h"
26 #include <linux/platform_data/asoc-s3c.h>
28 static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_out = {
33 static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_in = {
38 static struct s3c_i2sv2_info s3c2412_i2s;
40 static int s3c2412_i2s_probe(struct snd_soc_dai *dai)
44 pr_debug("Entered %s\n", __func__);
46 snd_soc_dai_init_dma_data(dai, &s3c2412_i2s_pcm_stereo_out,
47 &s3c2412_i2s_pcm_stereo_in);
49 ret = s3c_i2sv2_probe(dai, &s3c2412_i2s);
53 s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
54 s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
56 s3c2412_i2s.iis_cclk = devm_clk_get(dai->dev, "i2sclk");
57 if (IS_ERR(s3c2412_i2s.iis_cclk)) {
58 pr_err("failed to get i2sclk clock\n");
59 ret = PTR_ERR(s3c2412_i2s.iis_cclk);
63 /* Set MPLL as the source for IIS CLK */
65 clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
66 ret = clk_prepare_enable(s3c2412_i2s.iis_cclk);
73 s3c_i2sv2_cleanup(dai, &s3c2412_i2s);
78 static int s3c2412_i2s_remove(struct snd_soc_dai *dai)
80 clk_disable_unprepare(s3c2412_i2s.iis_cclk);
81 s3c_i2sv2_cleanup(dai, &s3c2412_i2s);
86 static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
87 struct snd_pcm_hw_params *params,
88 struct snd_soc_dai *cpu_dai)
90 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
93 pr_debug("Entered %s\n", __func__);
95 iismod = readl(i2s->regs + S3C2412_IISMOD);
96 pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
98 switch (params_width(params)) {
100 iismod |= S3C2412_IISMOD_8BIT;
103 iismod &= ~S3C2412_IISMOD_8BIT;
107 writel(iismod, i2s->regs + S3C2412_IISMOD);
108 pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
114 static int s3c2412_i2s_suspend(struct snd_soc_component *component)
116 struct s3c_i2sv2_info *i2s = snd_soc_component_get_drvdata(component);
119 if (component->active) {
120 i2s->suspend_iismod = readl(i2s->regs + S3C2412_IISMOD);
121 i2s->suspend_iiscon = readl(i2s->regs + S3C2412_IISCON);
122 i2s->suspend_iispsr = readl(i2s->regs + S3C2412_IISPSR);
124 /* some basic suspend checks */
126 iismod = readl(i2s->regs + S3C2412_IISMOD);
128 if (iismod & S3C2412_IISCON_RXDMA_ACTIVE)
129 pr_warn("%s: RXDMA active?\n", __func__);
131 if (iismod & S3C2412_IISCON_TXDMA_ACTIVE)
132 pr_warn("%s: TXDMA active?\n", __func__);
134 if (iismod & S3C2412_IISCON_IIS_ACTIVE)
135 pr_warn("%s: IIS active\n", __func__);
141 static int s3c2412_i2s_resume(struct snd_soc_component *component)
143 struct s3c_i2sv2_info *i2s = snd_soc_component_get_drvdata(component);
145 pr_info("component_active %d, IISMOD %08x, IISCON %08x\n",
146 component->active, i2s->suspend_iismod, i2s->suspend_iiscon);
148 if (component->active) {
149 writel(i2s->suspend_iiscon, i2s->regs + S3C2412_IISCON);
150 writel(i2s->suspend_iismod, i2s->regs + S3C2412_IISMOD);
151 writel(i2s->suspend_iispsr, i2s->regs + S3C2412_IISPSR);
153 writel(S3C2412_IISFIC_RXFLUSH | S3C2412_IISFIC_TXFLUSH,
154 i2s->regs + S3C2412_IISFIC);
157 writel(0x0, i2s->regs + S3C2412_IISFIC);
163 #define s3c2412_i2s_suspend NULL
164 #define s3c2412_i2s_resume NULL
167 #define S3C2412_I2S_RATES \
168 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
169 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
170 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
172 static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
173 .hw_params = s3c2412_i2s_hw_params,
176 static struct snd_soc_dai_driver s3c2412_i2s_dai = {
177 .probe = s3c2412_i2s_probe,
178 .remove = s3c2412_i2s_remove,
182 .rates = S3C2412_I2S_RATES,
183 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
188 .rates = S3C2412_I2S_RATES,
189 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
191 .ops = &s3c2412_i2s_dai_ops,
194 static const struct snd_soc_component_driver s3c2412_i2s_component = {
195 .name = "s3c2412-i2s",
196 .suspend = s3c2412_i2s_suspend,
197 .resume = s3c2412_i2s_resume,
200 static int s3c2412_iis_dev_probe(struct platform_device *pdev)
203 struct resource *res;
204 struct s3c_audio_pdata *pdata = dev_get_platdata(&pdev->dev);
207 dev_err(&pdev->dev, "missing platform data");
211 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
212 s3c2412_i2s.regs = devm_ioremap_resource(&pdev->dev, res);
213 if (IS_ERR(s3c2412_i2s.regs))
214 return PTR_ERR(s3c2412_i2s.regs);
216 s3c2412_i2s_pcm_stereo_out.addr = res->start + S3C2412_IISTXD;
217 s3c2412_i2s_pcm_stereo_out.filter_data = pdata->dma_playback;
218 s3c2412_i2s_pcm_stereo_in.addr = res->start + S3C2412_IISRXD;
219 s3c2412_i2s_pcm_stereo_in.filter_data = pdata->dma_capture;
221 ret = samsung_asoc_dma_platform_register(&pdev->dev,
225 pr_err("failed to register the DMA: %d\n", ret);
229 ret = s3c_i2sv2_register_component(&pdev->dev, -1,
230 &s3c2412_i2s_component,
233 pr_err("failed to register the dai\n");
238 static struct platform_driver s3c2412_iis_driver = {
239 .probe = s3c2412_iis_dev_probe,
241 .name = "s3c2412-iis",
245 module_platform_driver(s3c2412_iis_driver);
247 /* Module information */
248 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
249 MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
250 MODULE_LICENSE("GPL");
251 MODULE_ALIAS("platform:s3c2412-iis");