]>
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 | ||
f8cf8176 | 15 | #include <linux/clk.h> |
f8cf8176 BD |
16 | #include <linux/gpio.h> |
17 | #include <linux/io.h> | |
18 | ||
f8cf8176 BD |
19 | #include <sound/soc.h> |
20 | ||
21 | #include <plat/regs-s3c2412-iis.h> | |
22 | #include <plat/gpio-bank-d.h> | |
23 | #include <plat/gpio-bank-e.h> | |
24 | #include <plat/gpio-cfg.h> | |
f8cf8176 BD |
25 | |
26 | #include <mach/map.h> | |
27 | #include <mach/dma.h> | |
28 | ||
d3ff5a3e | 29 | #include "s3c-dma.h" |
f8cf8176 BD |
30 | #include "s3c64xx-i2s.h" |
31 | ||
0fe69229 JB |
32 | /* The value should be set to maximum of the total number |
33 | * of I2Sv3 controllers that any supported SoC has. | |
34 | */ | |
35 | #define MAX_I2SV3 2 | |
36 | ||
f8cf8176 BD |
37 | static struct s3c2410_dma_client s3c64xx_dma_client_out = { |
38 | .name = "I2S PCM Stereo out" | |
39 | }; | |
40 | ||
41 | static struct s3c2410_dma_client s3c64xx_dma_client_in = { | |
42 | .name = "I2S PCM Stereo in" | |
43 | }; | |
44 | ||
0fe69229 JB |
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]; | |
f8cf8176 | 48 | |
0fe69229 JB |
49 | struct snd_soc_dai s3c64xx_i2s_dai[MAX_I2SV3]; |
50 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai); | |
f8cf8176 BD |
51 | |
52 | static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai) | |
53 | { | |
54 | return cpu_dai->private_data; | |
55 | } | |
56 | ||
57 | static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai, | |
58 | int clk_id, unsigned int freq, int dir) | |
59 | { | |
60 | struct s3c_i2sv2_info *i2s = to_info(cpu_dai); | |
61 | u32 iismod = readl(i2s->regs + S3C2412_IISMOD); | |
62 | ||
63 | switch (clk_id) { | |
64 | case S3C64XX_CLKSRC_PCLK: | |
65 | iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX; | |
66 | break; | |
67 | ||
68 | case S3C64XX_CLKSRC_MUX: | |
69 | iismod |= S3C64XX_IISMOD_IMS_SYSMUX; | |
70 | break; | |
71 | ||
8bb01489 MB |
72 | case S3C64XX_CLKSRC_CDCLK: |
73 | switch (dir) { | |
74 | case SND_SOC_CLOCK_IN: | |
75 | iismod |= S3C64XX_IISMOD_CDCLKCON; | |
76 | break; | |
77 | case SND_SOC_CLOCK_OUT: | |
78 | iismod &= ~S3C64XX_IISMOD_CDCLKCON; | |
79 | break; | |
80 | default: | |
81 | return -EINVAL; | |
82 | } | |
83 | break; | |
84 | ||
f8cf8176 BD |
85 | default: |
86 | return -EINVAL; | |
87 | } | |
88 | ||
89 | writel(iismod, i2s->regs + S3C2412_IISMOD); | |
90 | ||
91 | return 0; | |
92 | } | |
93 | ||
51438449 | 94 | struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai) |
f8cf8176 BD |
95 | { |
96 | struct s3c_i2sv2_info *i2s = to_info(dai); | |
b1cd6b9e | 97 | u32 iismod = readl(i2s->regs + S3C2412_IISMOD); |
f8cf8176 | 98 | |
b1cd6b9e J |
99 | if (iismod & S3C64XX_IISMOD_IMS_SYSMUX) |
100 | return i2s->iis_cclk; | |
101 | else | |
102 | return i2s->iis_pclk; | |
f8cf8176 | 103 | } |
51438449 | 104 | EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock); |
f8cf8176 BD |
105 | |
106 | static int s3c64xx_i2s_probe(struct platform_device *pdev, | |
107 | struct snd_soc_dai *dai) | |
108 | { | |
f8cf8176 | 109 | /* configure GPIO for i2s port */ |
172fd9e2 | 110 | switch (dai->id) { |
f8cf8176 BD |
111 | case 0: |
112 | s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK); | |
113 | s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK); | |
114 | s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK); | |
115 | s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI); | |
116 | s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0); | |
117 | break; | |
118 | case 1: | |
119 | s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK); | |
120 | s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK); | |
121 | s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK); | |
122 | s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI); | |
123 | s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0); | |
124 | } | |
125 | ||
126 | return 0; | |
127 | } | |
128 | ||
129 | ||
130 | #define S3C64XX_I2S_RATES \ | |
131 | (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \ | |
132 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ | |
133 | SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) | |
134 | ||
135 | #define S3C64XX_I2S_FMTS \ | |
553b1dd5 MB |
136 | (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ |
137 | SNDRV_PCM_FMTBIT_S24_LE) | |
f8cf8176 | 138 | |
f2a5d6a2 MB |
139 | static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = { |
140 | .set_sysclk = s3c64xx_i2s_set_sysclk, | |
141 | }; | |
142 | ||
172fd9e2 MB |
143 | static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev) |
144 | { | |
145 | struct s3c_i2sv2_info *i2s; | |
146 | struct snd_soc_dai *dai; | |
147 | int ret; | |
148 | ||
0fe69229 | 149 | if (pdev->id >= MAX_I2SV3) { |
172fd9e2 MB |
150 | dev_err(&pdev->dev, "id %d out of range\n", pdev->id); |
151 | return -EINVAL; | |
152 | } | |
153 | ||
154 | i2s = &s3c64xx_i2s[pdev->id]; | |
155 | dai = &s3c64xx_i2s_dai[pdev->id]; | |
156 | dai->dev = &pdev->dev; | |
0fe69229 JB |
157 | dai->name = "s3c64xx-i2s"; |
158 | dai->id = pdev->id; | |
159 | dai->symmetric_rates = 1; | |
160 | dai->playback.channels_min = 2; | |
161 | dai->playback.channels_max = 2; | |
162 | dai->playback.rates = S3C64XX_I2S_RATES; | |
163 | dai->playback.formats = S3C64XX_I2S_FMTS; | |
164 | dai->capture.channels_min = 2; | |
165 | dai->capture.channels_max = 2; | |
166 | dai->capture.rates = S3C64XX_I2S_RATES; | |
167 | dai->capture.formats = S3C64XX_I2S_FMTS; | |
168 | dai->probe = s3c64xx_i2s_probe; | |
169 | dai->ops = &s3c64xx_i2s_dai_ops; | |
172fd9e2 MB |
170 | |
171 | i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id]; | |
172 | i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id]; | |
173 | ||
0fe69229 JB |
174 | if (pdev->id == 0) { |
175 | i2s->dma_capture->channel = DMACH_I2S0_IN; | |
176 | i2s->dma_capture->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD; | |
177 | i2s->dma_playback->channel = DMACH_I2S0_OUT; | |
178 | i2s->dma_playback->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD; | |
179 | } else { | |
180 | i2s->dma_capture->channel = DMACH_I2S1_IN; | |
181 | i2s->dma_capture->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD; | |
182 | i2s->dma_playback->channel = DMACH_I2S1_OUT; | |
183 | i2s->dma_playback->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD; | |
184 | } | |
185 | ||
186 | i2s->dma_capture->client = &s3c64xx_dma_client_in; | |
187 | i2s->dma_capture->dma_size = 4; | |
188 | i2s->dma_playback->client = &s3c64xx_dma_client_out; | |
189 | i2s->dma_playback->dma_size = 4; | |
190 | ||
172fd9e2 MB |
191 | i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus"); |
192 | if (IS_ERR(i2s->iis_cclk)) { | |
09aa60df | 193 | dev_err(&pdev->dev, "failed to get audio-bus\n"); |
172fd9e2 MB |
194 | ret = PTR_ERR(i2s->iis_cclk); |
195 | goto err; | |
196 | } | |
197 | ||
6fc786d5 JB |
198 | clk_enable(i2s->iis_cclk); |
199 | ||
71437552 | 200 | ret = s3c_i2sv2_probe(pdev, dai, i2s, 0); |
172fd9e2 MB |
201 | if (ret) |
202 | goto err_clk; | |
203 | ||
a7be4d92 | 204 | ret = s3c_i2sv2_register_dai(dai); |
172fd9e2 MB |
205 | if (ret != 0) |
206 | goto err_i2sv2; | |
207 | ||
208 | return 0; | |
209 | ||
210 | err_i2sv2: | |
211 | /* Not implemented for I2Sv2 core yet */ | |
212 | err_clk: | |
213 | clk_put(i2s->iis_cclk); | |
214 | err: | |
215 | return ret; | |
216 | } | |
217 | ||
218 | static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev) | |
219 | { | |
220 | dev_err(&pdev->dev, "Device removal not yet supported\n"); | |
221 | return 0; | |
222 | } | |
223 | ||
224 | static struct platform_driver s3c64xx_iis_driver = { | |
225 | .probe = s3c64xx_iis_dev_probe, | |
226 | .remove = s3c64xx_iis_dev_remove, | |
227 | .driver = { | |
228 | .name = "s3c64xx-iis", | |
229 | .owner = THIS_MODULE, | |
230 | }, | |
231 | }; | |
232 | ||
f8cf8176 BD |
233 | static int __init s3c64xx_i2s_init(void) |
234 | { | |
172fd9e2 | 235 | return platform_driver_register(&s3c64xx_iis_driver); |
f8cf8176 BD |
236 | } |
237 | module_init(s3c64xx_i2s_init); | |
238 | ||
239 | static void __exit s3c64xx_i2s_exit(void) | |
240 | { | |
172fd9e2 | 241 | platform_driver_unregister(&s3c64xx_iis_driver); |
f8cf8176 BD |
242 | } |
243 | module_exit(s3c64xx_i2s_exit); | |
244 | ||
245 | /* Module information */ | |
246 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); | |
247 | MODULE_DESCRIPTION("S3C64XX I2S SoC Interface"); | |
248 | MODULE_LICENSE("GPL"); |