6d49bd93717b94071040da6aedd8c054ce1b6e1f
[safe/jmp/linux-2.6] / sound / soc / s3c24xx / s3c64xx-i2s.c
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/clk.h>
16 #include <linux/gpio.h>
17 #include <linux/io.h>
18
19 #include <sound/soc.h>
20
21 #include <mach/gpio-bank-d.h>
22 #include <mach/gpio-bank-e.h>
23 #include <plat/gpio-cfg.h>
24
25 #include <mach/map.h>
26 #include <mach/dma.h>
27
28 #include "s3c-dma.h"
29 #include "regs-i2s-v2.h"
30 #include "s3c64xx-i2s.h"
31
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
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
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];
48
49 struct snd_soc_dai s3c64xx_i2s_dai[MAX_I2SV3];
50 EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
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 &= ~S3C2412_IISMOD_IMS_SYSMUX;
66                 break;
67
68         case S3C64XX_CLKSRC_MUX:
69                 iismod |= S3C2412_IISMOD_IMS_SYSMUX;
70                 break;
71
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
85         default:
86                 return -EINVAL;
87         }
88
89         writel(iismod, i2s->regs + S3C2412_IISMOD);
90
91         return 0;
92 }
93
94 static int s3c64xx_i2s_probe(struct platform_device *pdev,
95                              struct snd_soc_dai *dai)
96 {
97         /* configure GPIO for i2s port */
98         switch (dai->id) {
99         case 0:
100                 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
101                 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
102                 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
103                 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
104                 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
105                 break;
106         case 1:
107                 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
108                 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
109                 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
110                 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
111                 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
112         }
113
114         return 0;
115 }
116
117
118 static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
119         .set_sysclk     = s3c64xx_i2s_set_sysclk,       
120 };
121
122 static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
123 {
124         struct s3c_i2sv2_info *i2s;
125         struct snd_soc_dai *dai;
126         int ret;
127
128         if (pdev->id >= MAX_I2SV3) {
129                 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
130                 return -EINVAL;
131         }
132
133         i2s = &s3c64xx_i2s[pdev->id];
134         dai = &s3c64xx_i2s_dai[pdev->id];
135         dai->dev = &pdev->dev;
136         dai->name = "s3c64xx-i2s";
137         dai->id = pdev->id;
138         dai->symmetric_rates = 1;
139         dai->playback.channels_min = 2;
140         dai->playback.channels_max = 2;
141         dai->playback.rates = S3C64XX_I2S_RATES;
142         dai->playback.formats = S3C64XX_I2S_FMTS;
143         dai->capture.channels_min = 2;
144         dai->capture.channels_max = 2;
145         dai->capture.rates = S3C64XX_I2S_RATES;
146         dai->capture.formats = S3C64XX_I2S_FMTS;
147         dai->probe = s3c64xx_i2s_probe;
148         dai->ops = &s3c64xx_i2s_dai_ops;
149
150         i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
151         i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
152
153         if (pdev->id == 0) {
154                 i2s->dma_capture->channel = DMACH_I2S0_IN;
155                 i2s->dma_capture->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD;
156                 i2s->dma_playback->channel = DMACH_I2S0_OUT;
157                 i2s->dma_playback->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD;
158         } else {
159                 i2s->dma_capture->channel = DMACH_I2S1_IN;
160                 i2s->dma_capture->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD;
161                 i2s->dma_playback->channel = DMACH_I2S1_OUT;
162                 i2s->dma_playback->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD;
163         }
164
165         i2s->dma_capture->client = &s3c64xx_dma_client_in;
166         i2s->dma_capture->dma_size = 4;
167         i2s->dma_playback->client = &s3c64xx_dma_client_out;
168         i2s->dma_playback->dma_size = 4;
169
170         i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
171         if (IS_ERR(i2s->iis_cclk)) {
172                 dev_err(&pdev->dev, "failed to get audio-bus\n");
173                 ret = PTR_ERR(i2s->iis_cclk);
174                 goto err;
175         }
176
177         clk_enable(i2s->iis_cclk);
178
179         ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
180         if (ret)
181                 goto err_clk;
182
183         ret = s3c_i2sv2_register_dai(dai);
184         if (ret != 0)
185                 goto err_i2sv2;
186
187         return 0;
188
189 err_i2sv2:
190         /* Not implemented for I2Sv2 core yet */
191 err_clk:
192         clk_put(i2s->iis_cclk);
193 err:
194         return ret;
195 }
196
197 static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
198 {
199         dev_err(&pdev->dev, "Device removal not yet supported\n");
200         return 0;
201 }
202
203 static struct platform_driver s3c64xx_iis_driver = {
204         .probe  = s3c64xx_iis_dev_probe,
205         .remove = s3c64xx_iis_dev_remove,
206         .driver = {
207                 .name = "s3c64xx-iis",
208                 .owner = THIS_MODULE,
209         },
210 };
211
212 static int __init s3c64xx_i2s_init(void)
213 {
214         return platform_driver_register(&s3c64xx_iis_driver);
215 }
216 module_init(s3c64xx_i2s_init);
217
218 static void __exit s3c64xx_i2s_exit(void)
219 {
220         platform_driver_unregister(&s3c64xx_iis_driver);
221 }
222 module_exit(s3c64xx_i2s_exit);
223
224 /* Module information */
225 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
226 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
227 MODULE_LICENSE("GPL");