Commit | Line | Data |
---|---|---|
f8cf8176 BD |
1 | /* 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> | |
f8cf8176 BD |
34 | |
35 | #include <mach/map.h> | |
36 | #include <mach/dma.h> | |
37 | ||
d3ff5a3e | 38 | #include "s3c-dma.h" |
f8cf8176 BD |
39 | #include "s3c64xx-i2s.h" |
40 | ||
41 | static struct s3c2410_dma_client s3c64xx_dma_client_out = { | |
42 | .name = "I2S PCM Stereo out" | |
43 | }; | |
44 | ||
45 | static struct s3c2410_dma_client s3c64xx_dma_client_in = { | |
46 | .name = "I2S PCM Stereo in" | |
47 | }; | |
48 | ||
faa31776 | 49 | static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[2] = { |
f8cf8176 BD |
50 | [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 | ||
faa31776 | 64 | static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[2] = { |
f8cf8176 BD |
65 | [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 | ||
79 | static struct s3c_i2sv2_info s3c64xx_i2s[2]; | |
80 | ||
81 | static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai) | |
82 | { | |
83 | return cpu_dai->private_data; | |
84 | } | |
85 | ||
86 | static 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 | ||
8bb01489 MB |
101 | 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 | ||
f8cf8176 BD |
114 | default: |
115 | return -EINVAL; | |
116 | } | |
117 | ||
118 | writel(iismod, i2s->regs + S3C2412_IISMOD); | |
119 | ||
120 | return 0; | |
121 | } | |
122 | ||
51438449 | 123 | struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai) |
f8cf8176 BD |
124 | { |
125 | struct s3c_i2sv2_info *i2s = to_info(dai); | |
b1cd6b9e | 126 | u32 iismod = readl(i2s->regs + S3C2412_IISMOD); |
f8cf8176 | 127 | |
b1cd6b9e J |
128 | if (iismod & S3C64XX_IISMOD_IMS_SYSMUX) |
129 | return i2s->iis_cclk; | |
130 | else | |
131 | return i2s->iis_pclk; | |
f8cf8176 | 132 | } |
51438449 | 133 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock); |
f8cf8176 BD |
134 | |
135 | static int s3c64xx_i2s_probe(struct platform_device *pdev, | |
136 | struct snd_soc_dai *dai) | |
137 | { | |
f8cf8176 | 138 | /* configure GPIO for i2s port */ |
172fd9e2 | 139 | switch (dai->id) { |
f8cf8176 BD |
140 | 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 \ | |
553b1dd5 MB |
165 | (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ |
166 | SNDRV_PCM_FMTBIT_S24_LE) | |
f8cf8176 | 167 | |
f2a5d6a2 MB |
168 | static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = { |
169 | .set_sysclk = s3c64xx_i2s_set_sysclk, | |
170 | }; | |
171 | ||
172fd9e2 MB |
172 | struct 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, | |
4bc4d899 | 190 | .symmetric_rates = 1, |
f8cf8176 | 191 | }, |
172fd9e2 MB |
192 | { |
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, | |
4bc4d899 | 209 | .symmetric_rates = 1, |
f8cf8176 | 210 | }, |
f8cf8176 BD |
211 | }; |
212 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai); | |
213 | ||
172fd9e2 MB |
214 | static __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)) { | |
09aa60df | 234 | dev_err(&pdev->dev, "failed to get audio-bus\n"); |
172fd9e2 MB |
235 | ret = PTR_ERR(i2s->iis_cclk); |
236 | goto err; | |
237 | } | |
238 | ||
6fc786d5 JB |
239 | clk_enable(i2s->iis_cclk); |
240 | ||
71437552 | 241 | ret = s3c_i2sv2_probe(pdev, dai, i2s, 0); |
172fd9e2 MB |
242 | if (ret) |
243 | goto err_clk; | |
244 | ||
a7be4d92 | 245 | ret = s3c_i2sv2_register_dai(dai); |
172fd9e2 MB |
246 | if (ret != 0) |
247 | goto err_i2sv2; | |
248 | ||
249 | return 0; | |
250 | ||
251 | err_i2sv2: | |
252 | /* Not implemented for I2Sv2 core yet */ | |
253 | err_clk: | |
254 | clk_put(i2s->iis_cclk); | |
255 | err: | |
256 | return ret; | |
257 | } | |
258 | ||
259 | static __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 | ||
265 | static 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 | ||
f8cf8176 BD |
274 | static int __init s3c64xx_i2s_init(void) |
275 | { | |
172fd9e2 | 276 | return platform_driver_register(&s3c64xx_iis_driver); |
f8cf8176 BD |
277 | } |
278 | module_init(s3c64xx_i2s_init); | |
279 | ||
280 | static void __exit s3c64xx_i2s_exit(void) | |
281 | { | |
172fd9e2 | 282 | platform_driver_unregister(&s3c64xx_iis_driver); |
f8cf8176 BD |
283 | } |
284 | module_exit(s3c64xx_i2s_exit); | |
285 | ||
286 | /* Module information */ | |
287 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); | |
288 | MODULE_DESCRIPTION("S3C64XX I2S SoC Interface"); | |
289 | MODULE_LICENSE("GPL"); |