blob: cb11f7831474e5378d774bfa3d35ab1a170fa7d7 [file] [log] [blame]
Ben Dooksf8cf8172009-03-04 00:49:31 +00001/* sound/soc/s3c24xx/s3c64xx-i2s.c
2 *
3 * ALSA SoC Audio Layer - S3C64XX I2S driver
4 *
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
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.
13 */
14
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>
23
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>
29
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>
35
36#include <mach/map.h>
37#include <mach/dma.h>
38
39#include "s3c24xx-pcm.h"
40#include "s3c64xx-i2s.h"
41
42static struct s3c2410_dma_client s3c64xx_dma_client_out = {
43 .name = "I2S PCM Stereo out"
44};
45
46static struct s3c2410_dma_client s3c64xx_dma_client_in = {
47 .name = "I2S PCM Stereo in"
48};
49
50static 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,
56 },
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,
62 },
63};
64
65static 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,
71 },
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,
77 },
78};
79
80static struct s3c_i2sv2_info s3c64xx_i2s[2];
81
82static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
83{
84 return cpu_dai->private_data;
85}
86
87static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
88 int clk_id, unsigned int freq, int dir)
89{
90 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
91 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
92
93 switch (clk_id) {
94 case S3C64XX_CLKSRC_PCLK:
95 iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
96 break;
97
98 case S3C64XX_CLKSRC_MUX:
99 iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
100 break;
101
102 default:
103 return -EINVAL;
104 }
105
106 writel(iismod, i2s->regs + S3C2412_IISMOD);
107
108 return 0;
109}
110
Mark Brown51438442009-04-29 20:30:39 +0100111struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
Ben Dooksf8cf8172009-03-04 00:49:31 +0000112{
113 struct s3c_i2sv2_info *i2s = to_info(dai);
114
Mark Brown51438442009-04-29 20:30:39 +0100115 return i2s->iis_cclk;
Ben Dooksf8cf8172009-03-04 00:49:31 +0000116}
Mark Brown51438442009-04-29 20:30:39 +0100117EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000118
119static int s3c64xx_i2s_probe(struct platform_device *pdev,
120 struct snd_soc_dai *dai)
121{
Ben Dooksf8cf8172009-03-04 00:49:31 +0000122 /* configure GPIO for i2s port */
Mark Brown172fd9e2009-04-24 16:33:10 +0100123 switch (dai->id) {
Ben Dooksf8cf8172009-03-04 00:49:31 +0000124 case 0:
125 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
126 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
127 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
128 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
129 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
130 break;
131 case 1:
132 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
133 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
134 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
135 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
136 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
137 }
138
139 return 0;
140}
141
142
143#define S3C64XX_I2S_RATES \
144 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
145 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
146 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
147
148#define S3C64XX_I2S_FMTS \
149 (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE)
150
Mark Brownf2a5d6a2009-03-16 14:02:07 +0000151static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
152 .set_sysclk = s3c64xx_i2s_set_sysclk,
153};
154
Mark Brown172fd9e2009-04-24 16:33:10 +0100155struct snd_soc_dai s3c64xx_i2s_dai[] = {
156 {
157 .name = "s3c64xx-i2s",
158 .id = 0,
159 .probe = s3c64xx_i2s_probe,
160 .playback = {
161 .channels_min = 2,
162 .channels_max = 2,
163 .rates = S3C64XX_I2S_RATES,
164 .formats = S3C64XX_I2S_FMTS,
165 },
166 .capture = {
167 .channels_min = 2,
168 .channels_max = 2,
169 .rates = S3C64XX_I2S_RATES,
170 .formats = S3C64XX_I2S_FMTS,
171 },
172 .ops = &s3c64xx_i2s_dai_ops,
Mark Brown4bc4d892009-04-27 14:28:44 +0100173 .symmetric_rates = 1,
Ben Dooksf8cf8172009-03-04 00:49:31 +0000174 },
Mark Brown172fd9e2009-04-24 16:33:10 +0100175 {
176 .name = "s3c64xx-i2s",
177 .id = 1,
178 .probe = s3c64xx_i2s_probe,
179 .playback = {
180 .channels_min = 2,
181 .channels_max = 2,
182 .rates = S3C64XX_I2S_RATES,
183 .formats = S3C64XX_I2S_FMTS,
184 },
185 .capture = {
186 .channels_min = 2,
187 .channels_max = 2,
188 .rates = S3C64XX_I2S_RATES,
189 .formats = S3C64XX_I2S_FMTS,
190 },
191 .ops = &s3c64xx_i2s_dai_ops,
Mark Brown4bc4d892009-04-27 14:28:44 +0100192 .symmetric_rates = 1,
Ben Dooksf8cf8172009-03-04 00:49:31 +0000193 },
Ben Dooksf8cf8172009-03-04 00:49:31 +0000194};
195EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
196
Mark Brown172fd9e2009-04-24 16:33:10 +0100197static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
198{
199 struct s3c_i2sv2_info *i2s;
200 struct snd_soc_dai *dai;
201 int ret;
202
203 if (pdev->id >= ARRAY_SIZE(s3c64xx_i2s)) {
204 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
205 return -EINVAL;
206 }
207
208 i2s = &s3c64xx_i2s[pdev->id];
209 dai = &s3c64xx_i2s_dai[pdev->id];
210 dai->dev = &pdev->dev;
211
212 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
213 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
214
215 i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
216 if (IS_ERR(i2s->iis_cclk)) {
Mark Brown09aa60d2009-04-29 18:51:48 +0100217 dev_err(&pdev->dev, "failed to get audio-bus\n");
Mark Brown172fd9e2009-04-24 16:33:10 +0100218 ret = PTR_ERR(i2s->iis_cclk);
219 goto err;
220 }
221
222 ret = s3c_i2sv2_probe(pdev, dai, i2s,
223 dai->id ? S3C64XX_PA_IIS1 : S3C64XX_PA_IIS0);
224 if (ret)
225 goto err_clk;
226
Mark Browna7be4d92009-04-27 20:24:15 +0100227 ret = s3c_i2sv2_register_dai(dai);
Mark Brown172fd9e2009-04-24 16:33:10 +0100228 if (ret != 0)
229 goto err_i2sv2;
230
231 return 0;
232
233err_i2sv2:
234 /* Not implemented for I2Sv2 core yet */
235err_clk:
236 clk_put(i2s->iis_cclk);
237err:
238 return ret;
239}
240
241static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
242{
243 dev_err(&pdev->dev, "Device removal not yet supported\n");
244 return 0;
245}
246
247static struct platform_driver s3c64xx_iis_driver = {
248 .probe = s3c64xx_iis_dev_probe,
249 .remove = s3c64xx_iis_dev_remove,
250 .driver = {
251 .name = "s3c64xx-iis",
252 .owner = THIS_MODULE,
253 },
254};
255
Ben Dooksf8cf8172009-03-04 00:49:31 +0000256static int __init s3c64xx_i2s_init(void)
257{
Mark Brown172fd9e2009-04-24 16:33:10 +0100258 return platform_driver_register(&s3c64xx_iis_driver);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000259}
260module_init(s3c64xx_i2s_init);
261
262static void __exit s3c64xx_i2s_exit(void)
263{
Mark Brown172fd9e2009-04-24 16:33:10 +0100264 platform_driver_unregister(&s3c64xx_iis_driver);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000265}
266module_exit(s3c64xx_i2s_exit);
267
268/* Module information */
269MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
270MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
271MODULE_LICENSE("GPL");