1 /* sound/soc/s3c24xx/s3c64xx-i2s.c
3 * ALSA SoC Audio Layer - S3C64XX I2S driver
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
15 #include <linux/module.h>
16 #include <linux/clk.h>
17 #include <linux/gpio.h>
19 #include <linux/slab.h>
21 #include <sound/soc.h>
23 #include <plat/audio.h>
29 #include "regs-i2s-v2.h"
30 #include "s3c64xx-i2s.h"
32 /* The value should be set to maximum of the total number
33 * of I2Sv3 controllers that any supported SoC has.
37 static struct s3c2410_dma_client s3c64xx_dma_client_out = {
38 .name = "I2S PCM Stereo out"
41 static struct s3c2410_dma_client s3c64xx_dma_client_in = {
42 .name = "I2S PCM Stereo in"
45 static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[MAX_I2SV3];
46 static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[MAX_I2SV3];
47 static struct s3c_i2sv2_info s3c64xx_i2s[MAX_I2SV3];
49 struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
51 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(dai);
52 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
54 if (iismod & S3C2412_IISMOD_IMS_SYSMUX)
59 EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
61 static int s3c64xx_i2s_probe(struct snd_soc_dai *dai)
63 struct s3c_i2sv2_info *i2s;
66 if (dai->id >= MAX_I2SV3) {
67 dev_err(dai->dev, "id %d out of range\n", dai->id);
71 i2s = &s3c64xx_i2s[dai->id];
72 snd_soc_dai_set_drvdata(dai, i2s);
74 i2s->iis_cclk = clk_get(dai->dev, "audio-bus");
75 if (IS_ERR(i2s->iis_cclk)) {
76 dev_err(dai->dev, "failed to get audio-bus\n");
77 ret = PTR_ERR(i2s->iis_cclk);
81 clk_enable(i2s->iis_cclk);
83 ret = s3c_i2sv2_probe(dai, i2s, i2s->base);
90 clk_disable(i2s->iis_cclk);
91 clk_put(i2s->iis_cclk);
97 static int s3c64xx_i2s_remove(struct snd_soc_dai *dai)
99 struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(dai);
101 clk_disable(i2s->iis_cclk);
102 clk_put(i2s->iis_cclk);
107 static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops;
109 static struct snd_soc_dai_driver s3c64xx_i2s_dai[MAX_I2SV3] = {
111 .name = "s3c64xx-i2s-0",
112 .probe = s3c64xx_i2s_probe,
113 .remove = s3c64xx_i2s_remove,
117 .rates = S3C64XX_I2S_RATES,
118 .formats = S3C64XX_I2S_FMTS,},
122 .rates = S3C64XX_I2S_RATES,
123 .formats = S3C64XX_I2S_FMTS,},
124 .ops = &s3c64xx_i2s_dai_ops,
125 .symmetric_rates = 1,
127 .name = "s3c64xx-i2s-1",
128 .probe = s3c64xx_i2s_probe,
129 .remove = s3c64xx_i2s_remove,
133 .rates = S3C64XX_I2S_RATES,
134 .formats = S3C64XX_I2S_FMTS,},
138 .rates = S3C64XX_I2S_RATES,
139 .formats = S3C64XX_I2S_FMTS,},
140 .ops = &s3c64xx_i2s_dai_ops,
141 .symmetric_rates = 1,
144 static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
146 struct s3c_audio_pdata *i2s_pdata;
147 struct s3c_i2sv2_info *i2s;
148 struct resource *res;
151 if (pdev->id >= MAX_I2SV3) {
152 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
156 i2s = &s3c64xx_i2s[pdev->id];
158 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
159 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
161 res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
163 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
166 i2s->dma_playback->channel = res->start;
168 res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
170 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
173 i2s->dma_capture->channel = res->start;
175 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
177 dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
181 if (!request_mem_region(res->start, resource_size(res),
183 dev_err(&pdev->dev, "Unable to request SFR region\n");
186 i2s->base = res->start;
188 i2s_pdata = pdev->dev.platform_data;
189 if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
190 dev_err(&pdev->dev, "Unable to configure gpio\n");
193 i2s->dma_capture->dma_addr = res->start + S3C2412_IISRXD;
194 i2s->dma_playback->dma_addr = res->start + S3C2412_IISTXD;
196 i2s->dma_capture->client = &s3c64xx_dma_client_in;
197 i2s->dma_capture->dma_size = 4;
198 i2s->dma_playback->client = &s3c64xx_dma_client_out;
199 i2s->dma_playback->dma_size = 4;
201 for (i = 0; i < ARRAY_SIZE(s3c64xx_i2s_dai); i++) {
202 ret = s3c_i2sv2_register_dai(&pdev->dev, i,
203 &s3c64xx_i2s_dai[i]);
211 static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
213 snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(s3c64xx_i2s_dai));
217 static struct platform_driver s3c64xx_iis_driver = {
218 .probe = s3c64xx_iis_dev_probe,
219 .remove = s3c64xx_iis_dev_remove,
221 .name = "s3c64xx-iis",
222 .owner = THIS_MODULE,
226 static int __init s3c64xx_i2s_init(void)
228 return platform_driver_register(&s3c64xx_iis_driver);
230 module_init(s3c64xx_i2s_init);
232 static void __exit s3c64xx_i2s_exit(void)
234 platform_driver_unregister(&s3c64xx_iis_driver);
236 module_exit(s3c64xx_i2s_exit);
238 /* Module information */
239 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
240 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
241 MODULE_LICENSE("GPL");