MERGE-master-patchset-edits
[linux-2.6/openmoko-kernel.git] / sound / soc / s3c24xx / s3c64xx-i2s.c
blobbf7c3d737394c49c1bad9303e00843472ae585c4
1 /* sound/soc/s3c24xx/s3c64xx-i2s.c
3 * ALSA SoC Audio Layer - S3C64XX I2S driver
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
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.
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>
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>
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>
34 #include <plat/audio.h>
36 #include <mach/map.h>
37 #include <mach/dma.h>
39 #include "s3c24xx-pcm.h"
40 #include "s3c64xx-i2s.h"
42 static struct s3c2410_dma_client s3c64xx_dma_client_out = {
43 .name = "I2S PCM Stereo out"
46 static struct s3c2410_dma_client s3c64xx_dma_client_in = {
47 .name = "I2S PCM Stereo in"
50 static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_out[2] = {
51 [0] = {
52 .client = &s3c64xx_dma_client_out,
53 .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD,
54 .dma_size = 4,
56 [1] = {
57 .client = &s3c64xx_dma_client_out,
58 .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD,
59 .dma_size = 4,
63 static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_in[2] = {
64 [0] = {
65 .client = &s3c64xx_dma_client_in,
66 .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD,
67 .dma_size = 4,
68 },
69 [1] = {
70 .client = &s3c64xx_dma_client_in,
71 .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD,
72 .dma_size = 4,
76 static struct s3c_i2sv2_info s3c64xx_i2s[2];
78 static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
79 int clk_id, unsigned int freq, int dir)
81 /* TODO */
82 return 0;
85 static int s3c64xx_i2s_probe(struct platform_device *pdev,
86 struct snd_soc_dai *dai)
88 struct device *dev = &pdev->dev;
89 struct s3c_i2sv2_info *i2s;
90 int ret;
92 dev_dbg(dev, "%s: probing dai %d\n", __func__, pdev->id);
94 if (pdev->id < 0 || pdev->id > ARRAY_SIZE(s3c64xx_i2s)) {
95 dev_err(dev, "id %d out of range\n", pdev->id);
96 return -EINVAL;
99 i2s = &s3c64xx_i2s[pdev->id];
101 ret = s3c_i2sv2_probe(pdev, dai, i2s,
102 pdev->id ? S3C64XX_PA_IIS1 : S3C64XX_PA_IIS0);
103 if (ret)
104 return ret;
106 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
107 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
109 i2s->iis_cclk = clk_get(dev, "i2sclk");
110 if (i2s->iis_cclk == NULL) {
111 dev_err(dev, "failed to get i2sclk");
112 iounmap(i2s->regs);
113 return -ENODEV;
116 /* configure GPIO for i2s port */
117 switch (pdev->id) {
118 case 0:
119 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
120 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
121 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
122 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
123 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
124 break;
125 case 1:
126 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
127 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
128 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
129 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
130 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
133 return 0;
137 #define S3C64XX_I2S_RATES \
138 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
139 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
140 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
142 #define S3C64XX_I2S_FMTS \
143 (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE)
145 struct snd_soc_dai s3c64xx_i2s_dai = {
146 .name = "s3c64xx-i2s",
147 .id = 0,
148 .probe = s3c64xx_i2s_probe,
149 .playback = {
150 .channels_min = 2,
151 .channels_max = 2,
152 .rates = S3C64XX_I2S_RATES,
153 .formats = S3C64XX_I2S_FMTS,
155 .capture = {
156 .channels_min = 2,
157 .channels_max = 2,
158 .rates = S3C64XX_I2S_RATES,
159 .formats = S3C64XX_I2S_FMTS,
161 .ops = {
162 .set_sysclk = s3c64xx_i2s_set_sysclk,
165 EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
167 static int __init s3c64xx_i2s_init(void)
169 return s3c_i2sv2_register_dai(&s3c64xx_i2s_dai);
171 module_init(s3c64xx_i2s_init);
173 static void __exit s3c64xx_i2s_exit(void)
175 snd_soc_unregister_dai(&s3c64xx_i2s_dai);
177 module_exit(s3c64xx_i2s_exit);
179 /* Module information */
180 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
181 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
182 MODULE_LICENSE("GPL");