blob: 719d63c27fdbcb56b94dc40e3a3f3e3cf9338e6c [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>
Ben Dooksf8cf8172009-03-04 00:49:31 +000034
35#include <mach/map.h>
36#include <mach/dma.h>
37
38#include "s3c24xx-pcm.h"
39#include "s3c64xx-i2s.h"
40
41static struct s3c2410_dma_client s3c64xx_dma_client_out = {
42 .name = "I2S PCM Stereo out"
43};
44
45static struct s3c2410_dma_client s3c64xx_dma_client_in = {
46 .name = "I2S PCM Stereo in"
47};
48
Jassi Brarfaa31772009-11-17 16:53:23 +090049static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[2] = {
Ben Dooksf8cf8172009-03-04 00:49:31 +000050 [0] = {
51 .channel = DMACH_I2S0_OUT,
52 .client = &s3c64xx_dma_client_out,
53 .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD,
54 .dma_size = 4,
55 },
56 [1] = {
57 .channel = DMACH_I2S1_OUT,
58 .client = &s3c64xx_dma_client_out,
59 .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD,
60 .dma_size = 4,
61 },
62};
63
Jassi Brarfaa31772009-11-17 16:53:23 +090064static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[2] = {
Ben Dooksf8cf8172009-03-04 00:49:31 +000065 [0] = {
66 .channel = DMACH_I2S0_IN,
67 .client = &s3c64xx_dma_client_in,
68 .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD,
69 .dma_size = 4,
70 },
71 [1] = {
72 .channel = DMACH_I2S1_IN,
73 .client = &s3c64xx_dma_client_in,
74 .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD,
75 .dma_size = 4,
76 },
77};
78
79static struct s3c_i2sv2_info s3c64xx_i2s[2];
80
81static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
82{
83 return cpu_dai->private_data;
84}
85
86static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
87 int clk_id, unsigned int freq, int dir)
88{
89 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
90 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
91
92 switch (clk_id) {
93 case S3C64XX_CLKSRC_PCLK:
94 iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
95 break;
96
97 case S3C64XX_CLKSRC_MUX:
98 iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
99 break;
100
Mark Brown8bb01482009-09-16 19:38:53 +0100101 case S3C64XX_CLKSRC_CDCLK:
102 switch (dir) {
103 case SND_SOC_CLOCK_IN:
104 iismod |= S3C64XX_IISMOD_CDCLKCON;
105 break;
106 case SND_SOC_CLOCK_OUT:
107 iismod &= ~S3C64XX_IISMOD_CDCLKCON;
108 break;
109 default:
110 return -EINVAL;
111 }
112 break;
113
Ben Dooksf8cf8172009-03-04 00:49:31 +0000114 default:
115 return -EINVAL;
116 }
117
118 writel(iismod, i2s->regs + S3C2412_IISMOD);
119
120 return 0;
121}
122
Mark Brown51438442009-04-29 20:30:39 +0100123struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
Ben Dooksf8cf8172009-03-04 00:49:31 +0000124{
125 struct s3c_i2sv2_info *i2s = to_info(dai);
Jassib1cd6b92009-09-18 15:22:27 +0900126 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000127
Jassib1cd6b92009-09-18 15:22:27 +0900128 if (iismod & S3C64XX_IISMOD_IMS_SYSMUX)
129 return i2s->iis_cclk;
130 else
131 return i2s->iis_pclk;
Ben Dooksf8cf8172009-03-04 00:49:31 +0000132}
Mark Brown51438442009-04-29 20:30:39 +0100133EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000134
135static int s3c64xx_i2s_probe(struct platform_device *pdev,
136 struct snd_soc_dai *dai)
137{
Ben Dooksf8cf8172009-03-04 00:49:31 +0000138 /* configure GPIO for i2s port */
Mark Brown172fd9e2009-04-24 16:33:10 +0100139 switch (dai->id) {
Ben Dooksf8cf8172009-03-04 00:49:31 +0000140 case 0:
141 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
142 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
143 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
144 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
145 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
146 break;
147 case 1:
148 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
149 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
150 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
151 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
152 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
153 }
154
155 return 0;
156}
157
158
159#define S3C64XX_I2S_RATES \
160 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
161 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
162 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
163
164#define S3C64XX_I2S_FMTS \
Mark Brown553b1dd2009-04-29 20:29:25 +0100165 (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
166 SNDRV_PCM_FMTBIT_S24_LE)
Ben Dooksf8cf8172009-03-04 00:49:31 +0000167
Mark Brownf2a5d6a2009-03-16 14:02:07 +0000168static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
169 .set_sysclk = s3c64xx_i2s_set_sysclk,
170};
171
Mark Brown172fd9e2009-04-24 16:33:10 +0100172struct snd_soc_dai s3c64xx_i2s_dai[] = {
173 {
174 .name = "s3c64xx-i2s",
175 .id = 0,
176 .probe = s3c64xx_i2s_probe,
177 .playback = {
178 .channels_min = 2,
179 .channels_max = 2,
180 .rates = S3C64XX_I2S_RATES,
181 .formats = S3C64XX_I2S_FMTS,
182 },
183 .capture = {
184 .channels_min = 2,
185 .channels_max = 2,
186 .rates = S3C64XX_I2S_RATES,
187 .formats = S3C64XX_I2S_FMTS,
188 },
189 .ops = &s3c64xx_i2s_dai_ops,
Mark Brown4bc4d892009-04-27 14:28:44 +0100190 .symmetric_rates = 1,
Ben Dooksf8cf8172009-03-04 00:49:31 +0000191 },
Mark Brown172fd9e2009-04-24 16:33:10 +0100192 {
193 .name = "s3c64xx-i2s",
194 .id = 1,
195 .probe = s3c64xx_i2s_probe,
196 .playback = {
197 .channels_min = 2,
198 .channels_max = 2,
199 .rates = S3C64XX_I2S_RATES,
200 .formats = S3C64XX_I2S_FMTS,
201 },
202 .capture = {
203 .channels_min = 2,
204 .channels_max = 2,
205 .rates = S3C64XX_I2S_RATES,
206 .formats = S3C64XX_I2S_FMTS,
207 },
208 .ops = &s3c64xx_i2s_dai_ops,
Mark Brown4bc4d892009-04-27 14:28:44 +0100209 .symmetric_rates = 1,
Ben Dooksf8cf8172009-03-04 00:49:31 +0000210 },
Ben Dooksf8cf8172009-03-04 00:49:31 +0000211};
212EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
213
Mark Brown172fd9e2009-04-24 16:33:10 +0100214static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
215{
216 struct s3c_i2sv2_info *i2s;
217 struct snd_soc_dai *dai;
218 int ret;
219
220 if (pdev->id >= ARRAY_SIZE(s3c64xx_i2s)) {
221 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
222 return -EINVAL;
223 }
224
225 i2s = &s3c64xx_i2s[pdev->id];
226 dai = &s3c64xx_i2s_dai[pdev->id];
227 dai->dev = &pdev->dev;
228
229 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
230 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
231
232 i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
233 if (IS_ERR(i2s->iis_cclk)) {
Mark Brown09aa60d2009-04-29 18:51:48 +0100234 dev_err(&pdev->dev, "failed to get audio-bus\n");
Mark Brown172fd9e2009-04-24 16:33:10 +0100235 ret = PTR_ERR(i2s->iis_cclk);
236 goto err;
237 }
238
Jassi Brar6fc786d2009-11-06 18:00:24 +0900239 clk_enable(i2s->iis_cclk);
240
Mark Brown71437552009-04-30 13:42:04 +0100241 ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
Mark Brown172fd9e2009-04-24 16:33:10 +0100242 if (ret)
243 goto err_clk;
244
Mark Browna7be4d92009-04-27 20:24:15 +0100245 ret = s3c_i2sv2_register_dai(dai);
Mark Brown172fd9e2009-04-24 16:33:10 +0100246 if (ret != 0)
247 goto err_i2sv2;
248
249 return 0;
250
251err_i2sv2:
252 /* Not implemented for I2Sv2 core yet */
253err_clk:
254 clk_put(i2s->iis_cclk);
255err:
256 return ret;
257}
258
259static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
260{
261 dev_err(&pdev->dev, "Device removal not yet supported\n");
262 return 0;
263}
264
265static struct platform_driver s3c64xx_iis_driver = {
266 .probe = s3c64xx_iis_dev_probe,
267 .remove = s3c64xx_iis_dev_remove,
268 .driver = {
269 .name = "s3c64xx-iis",
270 .owner = THIS_MODULE,
271 },
272};
273
Ben Dooksf8cf8172009-03-04 00:49:31 +0000274static int __init s3c64xx_i2s_init(void)
275{
Mark Brown172fd9e2009-04-24 16:33:10 +0100276 return platform_driver_register(&s3c64xx_iis_driver);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000277}
278module_init(s3c64xx_i2s_init);
279
280static void __exit s3c64xx_i2s_exit(void)
281{
Mark Brown172fd9e2009-04-24 16:33:10 +0100282 platform_driver_unregister(&s3c64xx_iis_driver);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000283}
284module_exit(s3c64xx_i2s_exit);
285
286/* Module information */
287MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
288MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
289MODULE_LICENSE("GPL");