1 /* sound/soc/s3c24xx/s3c64xx-i2s-v4.c
3 * ALSA SoC Audio Layer - S3C64XX I2Sv4 driver
4 * Copyright (c) 2010 Samsung Electronics Co. Ltd
5 * Author: Jaswinder Singh <jassi.brar@samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/clk.h>
13 #include <linux/gpio.h>
16 #include <sound/soc.h>
17 #include <sound/pcm_params.h>
19 #include <plat/audio.h>
25 #include "regs-i2s-v2.h"
26 #include "s3c64xx-i2s.h"
28 static struct s3c2410_dma_client s3c64xx_dma_client_out = {
29 .name = "I2Sv4 PCM Stereo out"
32 static struct s3c2410_dma_client s3c64xx_dma_client_in = {
33 .name = "I2Sv4 PCM Stereo in"
36 static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_out;
37 static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_in;
38 static struct s3c_i2sv2_info s3c64xx_i2sv4;
40 static int s3c64xx_i2sv4_probe(struct snd_soc_dai *dai)
42 struct s3c_i2sv2_info *i2s = &s3c64xx_i2sv4;
45 snd_soc_dai_set_drvdata(dai, i2s);
47 ret = s3c_i2sv2_probe(dai, i2s, i2s->base);
52 static int s3c_i2sv4_hw_params(struct snd_pcm_substream *substream,
53 struct snd_pcm_hw_params *params,
54 struct snd_soc_dai *cpu_dai)
56 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
57 struct s3c_dma_params *dma_data;
60 dev_dbg(cpu_dai->dev, "Entered %s\n", __func__);
62 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
63 dma_data = i2s->dma_playback;
65 dma_data = i2s->dma_capture;
67 snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
69 iismod = readl(i2s->regs + S3C2412_IISMOD);
70 dev_dbg(cpu_dai->dev, "%s: r: IISMOD: %x\n", __func__, iismod);
72 iismod &= ~S3C64XX_IISMOD_BLC_MASK;
73 switch (params_format(params)) {
74 case SNDRV_PCM_FORMAT_S8:
75 iismod |= S3C64XX_IISMOD_BLC_8BIT;
77 case SNDRV_PCM_FORMAT_S16_LE:
79 case SNDRV_PCM_FORMAT_S24_LE:
80 iismod |= S3C64XX_IISMOD_BLC_24BIT;
84 writel(iismod, i2s->regs + S3C2412_IISMOD);
85 dev_dbg(cpu_dai->dev, "%s: w: IISMOD: %x\n", __func__, iismod);
90 static struct snd_soc_dai_ops s3c64xx_i2sv4_dai_ops = {
91 .hw_params = s3c_i2sv4_hw_params,
94 static struct snd_soc_dai_driver s3c64xx_i2s_v4_dai = {
99 .rates = S3C64XX_I2S_RATES,
100 .formats = S3C64XX_I2S_FMTS,
105 .rates = S3C64XX_I2S_RATES,
106 .formats = S3C64XX_I2S_FMTS,
108 .probe = s3c64xx_i2sv4_probe,
109 .ops = &s3c64xx_i2sv4_dai_ops,
112 static __devinit int s3c64xx_i2sv4_dev_probe(struct platform_device *pdev)
114 struct s3c_audio_pdata *i2s_pdata;
115 struct s3c_i2sv2_info *i2s;
116 struct resource *res;
119 i2s = &s3c64xx_i2sv4;
121 i2s->feature |= S3C_FEATURE_CDCLKCON;
123 i2s->dma_capture = &s3c64xx_i2sv4_pcm_stereo_in;
124 i2s->dma_playback = &s3c64xx_i2sv4_pcm_stereo_out;
126 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
128 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
131 i2s->dma_playback->channel = res->start;
133 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
135 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
138 i2s->dma_capture->channel = res->start;
140 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
142 dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
146 if (!request_mem_region(res->start, resource_size(res),
148 dev_err(&pdev->dev, "Unable to request SFR region\n");
151 i2s->dma_capture->dma_addr = res->start + S3C2412_IISRXD;
152 i2s->dma_playback->dma_addr = res->start + S3C2412_IISTXD;
154 i2s->dma_capture->client = &s3c64xx_dma_client_in;
155 i2s->dma_capture->dma_size = 4;
156 i2s->dma_playback->client = &s3c64xx_dma_client_out;
157 i2s->dma_playback->dma_size = 4;
159 i2s->base = res->start;
161 i2s_pdata = pdev->dev.platform_data;
162 if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
163 dev_err(&pdev->dev, "Unable to configure gpio\n");
167 i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
168 if (IS_ERR(i2s->iis_cclk)) {
169 dev_err(&pdev->dev, "failed to get audio-bus\n");
170 ret = PTR_ERR(i2s->iis_cclk);
174 clk_enable(i2s->iis_cclk);
176 ret = s3c_i2sv2_register_dai(&pdev->dev, pdev->id, &s3c64xx_i2s_v4_dai);
183 clk_put(i2s->iis_cclk);
188 static __devexit int s3c64xx_i2sv4_dev_remove(struct platform_device *pdev)
190 struct s3c_i2sv2_info *i2s = &s3c64xx_i2sv4;
191 struct resource *res;
193 snd_soc_unregister_dai(&pdev->dev);
194 clk_put(i2s->iis_cclk);
196 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
198 release_mem_region(res->start, resource_size(res));
200 dev_warn(&pdev->dev, "Unable to get I2S SFR address\n");
205 static struct platform_driver s3c64xx_i2sv4_driver = {
206 .probe = s3c64xx_i2sv4_dev_probe,
207 .remove = s3c64xx_i2sv4_dev_remove,
209 .name = "s3c64xx-iis-v4",
210 .owner = THIS_MODULE,
214 static int __init s3c64xx_i2sv4_init(void)
216 return platform_driver_register(&s3c64xx_i2sv4_driver);
218 module_init(s3c64xx_i2sv4_init);
220 static void __exit s3c64xx_i2sv4_exit(void)
222 platform_driver_unregister(&s3c64xx_i2sv4_driver);
224 module_exit(s3c64xx_i2sv4_exit);
226 /* Module information */
227 MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
228 MODULE_DESCRIPTION("S3C64XX I2Sv4 SoC Interface");
229 MODULE_LICENSE("GPL");
230 MODULE_ALIAS("platform:s3c64xx-iis-v4");