ASoC: S3C: I2S: Move set_sysclk to common code
[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_probe(struct platform_device *pdev,
58                              struct snd_soc_dai *dai)
59 {
60         /* configure GPIO for i2s port */
61         switch (dai->id) {
62         case 0:
63                 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
64                 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
65                 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
66                 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
67                 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
68                 break;
69         case 1:
70                 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
71                 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
72                 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
73                 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
74                 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
75         }
76
77         return 0;
78 }
79
80
81 static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops;
82
83 static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
84 {
85         struct s3c_i2sv2_info *i2s;
86         struct snd_soc_dai *dai;
87         int ret;
88
89         if (pdev->id >= MAX_I2SV3) {
90                 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
91                 return -EINVAL;
92         }
93
94         i2s = &s3c64xx_i2s[pdev->id];
95         dai = &s3c64xx_i2s_dai[pdev->id];
96         dai->dev = &pdev->dev;
97         dai->name = "s3c64xx-i2s";
98         dai->id = pdev->id;
99         dai->symmetric_rates = 1;
100         dai->playback.channels_min = 2;
101         dai->playback.channels_max = 2;
102         dai->playback.rates = S3C64XX_I2S_RATES;
103         dai->playback.formats = S3C64XX_I2S_FMTS;
104         dai->capture.channels_min = 2;
105         dai->capture.channels_max = 2;
106         dai->capture.rates = S3C64XX_I2S_RATES;
107         dai->capture.formats = S3C64XX_I2S_FMTS;
108         dai->probe = s3c64xx_i2s_probe;
109         dai->ops = &s3c64xx_i2s_dai_ops;
110
111         i2s->feature |= S3C_FEATURE_CDCLKCON;
112
113         i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
114         i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
115
116         if (pdev->id == 0) {
117                 i2s->dma_capture->channel = DMACH_I2S0_IN;
118                 i2s->dma_capture->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD;
119                 i2s->dma_playback->channel = DMACH_I2S0_OUT;
120                 i2s->dma_playback->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD;
121         } else {
122                 i2s->dma_capture->channel = DMACH_I2S1_IN;
123                 i2s->dma_capture->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD;
124                 i2s->dma_playback->channel = DMACH_I2S1_OUT;
125                 i2s->dma_playback->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD;
126         }
127
128         i2s->dma_capture->client = &s3c64xx_dma_client_in;
129         i2s->dma_capture->dma_size = 4;
130         i2s->dma_playback->client = &s3c64xx_dma_client_out;
131         i2s->dma_playback->dma_size = 4;
132
133         i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
134         if (IS_ERR(i2s->iis_cclk)) {
135                 dev_err(&pdev->dev, "failed to get audio-bus\n");
136                 ret = PTR_ERR(i2s->iis_cclk);
137                 goto err;
138         }
139
140         clk_enable(i2s->iis_cclk);
141
142         ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
143         if (ret)
144                 goto err_clk;
145
146         ret = s3c_i2sv2_register_dai(dai);
147         if (ret != 0)
148                 goto err_i2sv2;
149
150         return 0;
151
152 err_i2sv2:
153         /* Not implemented for I2Sv2 core yet */
154 err_clk:
155         clk_put(i2s->iis_cclk);
156 err:
157         return ret;
158 }
159
160 static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
161 {
162         dev_err(&pdev->dev, "Device removal not yet supported\n");
163         return 0;
164 }
165
166 static struct platform_driver s3c64xx_iis_driver = {
167         .probe  = s3c64xx_iis_dev_probe,
168         .remove = s3c64xx_iis_dev_remove,
169         .driver = {
170                 .name = "s3c64xx-iis",
171                 .owner = THIS_MODULE,
172         },
173 };
174
175 static int __init s3c64xx_i2s_init(void)
176 {
177         return platform_driver_register(&s3c64xx_iis_driver);
178 }
179 module_init(s3c64xx_i2s_init);
180
181 static void __exit s3c64xx_i2s_exit(void)
182 {
183         platform_driver_unregister(&s3c64xx_iis_driver);
184 }
185 module_exit(s3c64xx_i2s_exit);
186
187 /* Module information */
188 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
189 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
190 MODULE_LICENSE("GPL");