mm-only debug patch...
[mmotm.git] / sound / soc / s3c24xx / s3c64xx-i2s.c
blob43fb253a3429a3b10d8eaebf001940196b025667
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/init.h>
16 #include <linux/module.h>
17 #include <linux/device.h>
18 #include <linux/delay.h>
19 #include <linux/clk.h>
20 #include <linux/kernel.h>
21 #include <linux/gpio.h>
22 #include <linux/io.h>
24 #include <sound/core.h>
25 #include <sound/pcm.h>
26 #include <sound/pcm_params.h>
27 #include <sound/initval.h>
28 #include <sound/soc.h>
30 #include <plat/regs-s3c2412-iis.h>
31 #include <plat/gpio-bank-d.h>
32 #include <plat/gpio-bank-e.h>
33 #include <plat/gpio-cfg.h>
34 #include <plat/audio.h>
36 #include <mach/map.h>
37 #include <mach/dma.h>
39 #include "s3c24xx-pcm.h"
40 #include "s3c64xx-i2s.h"
42 static struct s3c2410_dma_client s3c64xx_dma_client_out = {
43 .name = "I2S PCM Stereo out"
46 static struct s3c2410_dma_client s3c64xx_dma_client_in = {
47 .name = "I2S PCM Stereo in"
50 static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_out[2] = {
51 [0] = {
52 .channel = DMACH_I2S0_OUT,
53 .client = &s3c64xx_dma_client_out,
54 .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD,
55 .dma_size = 4,
57 [1] = {
58 .channel = DMACH_I2S1_OUT,
59 .client = &s3c64xx_dma_client_out,
60 .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD,
61 .dma_size = 4,
65 static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_in[2] = {
66 [0] = {
67 .channel = DMACH_I2S0_IN,
68 .client = &s3c64xx_dma_client_in,
69 .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD,
70 .dma_size = 4,
72 [1] = {
73 .channel = DMACH_I2S1_IN,
74 .client = &s3c64xx_dma_client_in,
75 .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD,
76 .dma_size = 4,
80 static struct s3c_i2sv2_info s3c64xx_i2s[2];
82 static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
84 return cpu_dai->private_data;
87 static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
88 int clk_id, unsigned int freq, int dir)
90 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
91 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
93 switch (clk_id) {
94 case S3C64XX_CLKSRC_PCLK:
95 iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
96 break;
98 case S3C64XX_CLKSRC_MUX:
99 iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
100 break;
102 case S3C64XX_CLKSRC_CDCLK:
103 switch (dir) {
104 case SND_SOC_CLOCK_IN:
105 iismod |= S3C64XX_IISMOD_CDCLKCON;
106 break;
107 case SND_SOC_CLOCK_OUT:
108 iismod &= ~S3C64XX_IISMOD_CDCLKCON;
109 break;
110 default:
111 return -EINVAL;
113 break;
115 default:
116 return -EINVAL;
119 writel(iismod, i2s->regs + S3C2412_IISMOD);
121 return 0;
124 struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
126 struct s3c_i2sv2_info *i2s = to_info(dai);
127 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
129 if (iismod & S3C64XX_IISMOD_IMS_SYSMUX)
130 return i2s->iis_cclk;
131 else
132 return i2s->iis_pclk;
134 EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
136 static int s3c64xx_i2s_probe(struct platform_device *pdev,
137 struct snd_soc_dai *dai)
139 /* configure GPIO for i2s port */
140 switch (dai->id) {
141 case 0:
142 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
143 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
144 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
145 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
146 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
147 break;
148 case 1:
149 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
150 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
151 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
152 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
153 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
156 return 0;
160 #define S3C64XX_I2S_RATES \
161 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
162 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
163 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
165 #define S3C64XX_I2S_FMTS \
166 (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
167 SNDRV_PCM_FMTBIT_S24_LE)
169 static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
170 .set_sysclk = s3c64xx_i2s_set_sysclk,
173 struct snd_soc_dai s3c64xx_i2s_dai[] = {
175 .name = "s3c64xx-i2s",
176 .id = 0,
177 .probe = s3c64xx_i2s_probe,
178 .playback = {
179 .channels_min = 2,
180 .channels_max = 2,
181 .rates = S3C64XX_I2S_RATES,
182 .formats = S3C64XX_I2S_FMTS,
184 .capture = {
185 .channels_min = 2,
186 .channels_max = 2,
187 .rates = S3C64XX_I2S_RATES,
188 .formats = S3C64XX_I2S_FMTS,
190 .ops = &s3c64xx_i2s_dai_ops,
191 .symmetric_rates = 1,
194 .name = "s3c64xx-i2s",
195 .id = 1,
196 .probe = s3c64xx_i2s_probe,
197 .playback = {
198 .channels_min = 2,
199 .channels_max = 2,
200 .rates = S3C64XX_I2S_RATES,
201 .formats = S3C64XX_I2S_FMTS,
203 .capture = {
204 .channels_min = 2,
205 .channels_max = 2,
206 .rates = S3C64XX_I2S_RATES,
207 .formats = S3C64XX_I2S_FMTS,
209 .ops = &s3c64xx_i2s_dai_ops,
210 .symmetric_rates = 1,
213 EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
215 static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
217 struct s3c_i2sv2_info *i2s;
218 struct snd_soc_dai *dai;
219 int ret;
221 if (pdev->id >= ARRAY_SIZE(s3c64xx_i2s)) {
222 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
223 return -EINVAL;
226 i2s = &s3c64xx_i2s[pdev->id];
227 dai = &s3c64xx_i2s_dai[pdev->id];
228 dai->dev = &pdev->dev;
230 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
231 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
233 i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
234 if (IS_ERR(i2s->iis_cclk)) {
235 dev_err(&pdev->dev, "failed to get audio-bus\n");
236 ret = PTR_ERR(i2s->iis_cclk);
237 goto err;
240 ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
241 if (ret)
242 goto err_clk;
244 ret = s3c_i2sv2_register_dai(dai);
245 if (ret != 0)
246 goto err_i2sv2;
248 return 0;
250 err_i2sv2:
251 /* Not implemented for I2Sv2 core yet */
252 err_clk:
253 clk_put(i2s->iis_cclk);
254 err:
255 return ret;
258 static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
260 dev_err(&pdev->dev, "Device removal not yet supported\n");
261 return 0;
264 static struct platform_driver s3c64xx_iis_driver = {
265 .probe = s3c64xx_iis_dev_probe,
266 .remove = s3c64xx_iis_dev_remove,
267 .driver = {
268 .name = "s3c64xx-iis",
269 .owner = THIS_MODULE,
273 static int __init s3c64xx_i2s_init(void)
275 return platform_driver_register(&s3c64xx_iis_driver);
277 module_init(s3c64xx_i2s_init);
279 static void __exit s3c64xx_i2s_exit(void)
281 platform_driver_unregister(&s3c64xx_iis_driver);
283 module_exit(s3c64xx_i2s_exit);
285 /* Module information */
286 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
287 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
288 MODULE_LICENSE("GPL");