ASoC: Add MODULE_ALIAS to Samsung DAI drivers
[pandora-kernel.git] / sound / soc / s3c24xx / s3c64xx-i2s-v4.c
1 /* sound/soc/s3c24xx/s3c64xx-i2s-v4.c
2  *
3  * ALSA SoC Audio Layer - S3C64XX I2Sv4 driver
4  * Copyright (c) 2010 Samsung Electronics Co. Ltd
5  *      Author: Jaswinder Singh <jassi.brar@samsung.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/clk.h>
13 #include <linux/gpio.h>
14 #include <linux/io.h>
15
16 #include <sound/soc.h>
17 #include <sound/pcm_params.h>
18
19 #include <plat/audio.h>
20
21 #include <mach/map.h>
22 #include <mach/dma.h>
23
24 #include "s3c-dma.h"
25 #include "regs-i2s-v2.h"
26 #include "s3c64xx-i2s.h"
27
28 static struct s3c2410_dma_client s3c64xx_dma_client_out = {
29         .name           = "I2Sv4 PCM Stereo out"
30 };
31
32 static struct s3c2410_dma_client s3c64xx_dma_client_in = {
33         .name           = "I2Sv4 PCM Stereo in"
34 };
35
36 static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_out;
37 static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_in;
38 static struct s3c_i2sv2_info s3c64xx_i2sv4;
39
40 static int s3c64xx_i2sv4_probe(struct snd_soc_dai *dai)
41 {
42         struct s3c_i2sv2_info *i2s = &s3c64xx_i2sv4;
43         int ret = 0;
44
45         snd_soc_dai_set_drvdata(dai, i2s);
46
47         ret = s3c_i2sv2_probe(dai, i2s, i2s->base);
48
49         return ret;
50 }
51
52 static int s3c_i2sv4_hw_params(struct snd_pcm_substream *substream,
53                                  struct snd_pcm_hw_params *params,
54                                  struct snd_soc_dai *cpu_dai)
55 {
56         struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
57         struct s3c_dma_params *dma_data;
58         u32 iismod;
59
60         dev_dbg(cpu_dai->dev, "Entered %s\n", __func__);
61
62         if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
63                 dma_data = i2s->dma_playback;
64         else
65                 dma_data = i2s->dma_capture;
66
67         snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
68
69         iismod = readl(i2s->regs + S3C2412_IISMOD);
70         dev_dbg(cpu_dai->dev, "%s: r: IISMOD: %x\n", __func__, iismod);
71
72         iismod &= ~S3C64XX_IISMOD_BLC_MASK;
73         switch (params_format(params)) {
74         case SNDRV_PCM_FORMAT_S8:
75                 iismod |= S3C64XX_IISMOD_BLC_8BIT;
76                 break;
77         case SNDRV_PCM_FORMAT_S16_LE:
78                 break;
79         case SNDRV_PCM_FORMAT_S24_LE:
80                 iismod |= S3C64XX_IISMOD_BLC_24BIT;
81                 break;
82         }
83
84         writel(iismod, i2s->regs + S3C2412_IISMOD);
85         dev_dbg(cpu_dai->dev, "%s: w: IISMOD: %x\n", __func__, iismod);
86
87         return 0;
88 }
89
90 static struct snd_soc_dai_ops s3c64xx_i2sv4_dai_ops = {
91         .hw_params      = s3c_i2sv4_hw_params,
92 };
93
94 static struct snd_soc_dai_driver s3c64xx_i2s_v4_dai = {
95         .symmetric_rates = 1,
96         .playback = {
97                 .channels_min = 2,
98                 .channels_max = 2,
99                 .rates = S3C64XX_I2S_RATES,
100                 .formats = S3C64XX_I2S_FMTS,
101         },
102         .capture = {
103                 .channels_min = 2,
104                 .channels_max = 2,
105                 .rates = S3C64XX_I2S_RATES,
106                 .formats = S3C64XX_I2S_FMTS,
107         },
108         .probe = s3c64xx_i2sv4_probe,
109         .ops = &s3c64xx_i2sv4_dai_ops,
110 };
111
112 static __devinit int s3c64xx_i2sv4_dev_probe(struct platform_device *pdev)
113 {
114         struct s3c_audio_pdata *i2s_pdata;
115         struct s3c_i2sv2_info *i2s;
116         struct resource *res;
117         int ret;
118
119         i2s = &s3c64xx_i2sv4;
120
121         i2s->feature |= S3C_FEATURE_CDCLKCON;
122
123         i2s->dma_capture = &s3c64xx_i2sv4_pcm_stereo_in;
124         i2s->dma_playback = &s3c64xx_i2sv4_pcm_stereo_out;
125
126         res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
127         if (!res) {
128                 dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
129                 return -ENXIO;
130         }
131         i2s->dma_playback->channel = res->start;
132
133         res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
134         if (!res) {
135                 dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
136                 return -ENXIO;
137         }
138         i2s->dma_capture->channel = res->start;
139
140         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
141         if (!res) {
142                 dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
143                 return -ENXIO;
144         }
145
146         if (!request_mem_region(res->start, resource_size(res),
147                                 "s3c64xx-i2s-v4")) {
148                 dev_err(&pdev->dev, "Unable to request SFR region\n");
149                 return -EBUSY;
150         }
151         i2s->dma_capture->dma_addr = res->start + S3C2412_IISRXD;
152         i2s->dma_playback->dma_addr = res->start + S3C2412_IISTXD;
153
154         i2s->dma_capture->client = &s3c64xx_dma_client_in;
155         i2s->dma_capture->dma_size = 4;
156         i2s->dma_playback->client = &s3c64xx_dma_client_out;
157         i2s->dma_playback->dma_size = 4;
158
159         i2s->base = res->start;
160
161         i2s_pdata = pdev->dev.platform_data;
162         if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
163                 dev_err(&pdev->dev, "Unable to configure gpio\n");
164                 return -EINVAL;
165         }
166
167         i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
168         if (IS_ERR(i2s->iis_cclk)) {
169                 dev_err(&pdev->dev, "failed to get audio-bus\n");
170                 ret = PTR_ERR(i2s->iis_cclk);
171                 goto err;
172         }
173
174         clk_enable(i2s->iis_cclk);
175
176         ret = s3c_i2sv2_register_dai(&pdev->dev, pdev->id, &s3c64xx_i2s_v4_dai);
177         if (ret != 0)
178                 goto err_i2sv2;
179
180         return 0;
181
182 err_i2sv2:
183         clk_put(i2s->iis_cclk);
184 err:
185         return ret;
186 }
187
188 static __devexit int s3c64xx_i2sv4_dev_remove(struct platform_device *pdev)
189 {
190         snd_soc_unregister_dai(&pdev->dev);
191         return 0;
192 }
193
194 static struct platform_driver s3c64xx_i2sv4_driver = {
195         .probe  = s3c64xx_i2sv4_dev_probe,
196         .remove = s3c64xx_i2sv4_dev_remove,
197         .driver = {
198                 .name = "s3c64xx-iis-v4",
199                 .owner = THIS_MODULE,
200         },
201 };
202
203 static int __init s3c64xx_i2sv4_init(void)
204 {
205         return platform_driver_register(&s3c64xx_i2sv4_driver);
206 }
207 module_init(s3c64xx_i2sv4_init);
208
209 static void __exit s3c64xx_i2sv4_exit(void)
210 {
211         platform_driver_unregister(&s3c64xx_i2sv4_driver);
212 }
213 module_exit(s3c64xx_i2sv4_exit);
214
215 /* Module information */
216 MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
217 MODULE_DESCRIPTION("S3C64XX I2Sv4 SoC Interface");
218 MODULE_LICENSE("GPL");
219 MODULE_ALIAS("platform:s3c64xx-iis-v4");