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/clk.h>
16 #include <linux/gpio.h>
19 #include <sound/soc.h>
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>
30 #include "s3c64xx-i2s.h"
32 /* The value should be set to maximum of the total number
33 * of I2Sv3 controllers that any supported SoC has.
37 static struct s3c2410_dma_client s3c64xx_dma_client_out = {
38 .name = "I2S PCM Stereo out"
41 static struct s3c2410_dma_client s3c64xx_dma_client_in = {
42 .name = "I2S PCM Stereo in"
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];
49 struct snd_soc_dai s3c64xx_i2s_dai[MAX_I2SV3];
50 EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
52 static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
54 return cpu_dai->private_data;
57 static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
58 int clk_id, unsigned int freq, int dir)
60 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
61 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
64 case S3C64XX_CLKSRC_PCLK:
65 iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
68 case S3C64XX_CLKSRC_MUX:
69 iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
72 case S3C64XX_CLKSRC_CDCLK:
74 case SND_SOC_CLOCK_IN:
75 iismod |= S3C64XX_IISMOD_CDCLKCON;
77 case SND_SOC_CLOCK_OUT:
78 iismod &= ~S3C64XX_IISMOD_CDCLKCON;
89 writel(iismod, i2s->regs + S3C2412_IISMOD);
94 struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
96 struct s3c_i2sv2_info *i2s = to_info(dai);
97 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
99 if (iismod & S3C64XX_IISMOD_IMS_SYSMUX)
100 return i2s->iis_cclk;
102 return i2s->iis_pclk;
104 EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
106 static int s3c64xx_i2s_probe(struct platform_device *pdev,
107 struct snd_soc_dai *dai)
109 /* configure GPIO for i2s port */
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);
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);
130 static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
131 .set_sysclk = s3c64xx_i2s_set_sysclk,
134 static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
136 struct s3c_i2sv2_info *i2s;
137 struct snd_soc_dai *dai;
140 if (pdev->id >= MAX_I2SV3) {
141 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
145 i2s = &s3c64xx_i2s[pdev->id];
146 dai = &s3c64xx_i2s_dai[pdev->id];
147 dai->dev = &pdev->dev;
148 dai->name = "s3c64xx-i2s";
150 dai->symmetric_rates = 1;
151 dai->playback.channels_min = 2;
152 dai->playback.channels_max = 2;
153 dai->playback.rates = S3C64XX_I2S_RATES;
154 dai->playback.formats = S3C64XX_I2S_FMTS;
155 dai->capture.channels_min = 2;
156 dai->capture.channels_max = 2;
157 dai->capture.rates = S3C64XX_I2S_RATES;
158 dai->capture.formats = S3C64XX_I2S_FMTS;
159 dai->probe = s3c64xx_i2s_probe;
160 dai->ops = &s3c64xx_i2s_dai_ops;
162 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
163 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
166 i2s->dma_capture->channel = DMACH_I2S0_IN;
167 i2s->dma_capture->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD;
168 i2s->dma_playback->channel = DMACH_I2S0_OUT;
169 i2s->dma_playback->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD;
171 i2s->dma_capture->channel = DMACH_I2S1_IN;
172 i2s->dma_capture->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD;
173 i2s->dma_playback->channel = DMACH_I2S1_OUT;
174 i2s->dma_playback->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD;
177 i2s->dma_capture->client = &s3c64xx_dma_client_in;
178 i2s->dma_capture->dma_size = 4;
179 i2s->dma_playback->client = &s3c64xx_dma_client_out;
180 i2s->dma_playback->dma_size = 4;
182 i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
183 if (IS_ERR(i2s->iis_cclk)) {
184 dev_err(&pdev->dev, "failed to get audio-bus\n");
185 ret = PTR_ERR(i2s->iis_cclk);
189 clk_enable(i2s->iis_cclk);
191 ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
195 ret = s3c_i2sv2_register_dai(dai);
202 /* Not implemented for I2Sv2 core yet */
204 clk_put(i2s->iis_cclk);
209 static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
211 dev_err(&pdev->dev, "Device removal not yet supported\n");
215 static struct platform_driver s3c64xx_iis_driver = {
216 .probe = s3c64xx_iis_dev_probe,
217 .remove = s3c64xx_iis_dev_remove,
219 .name = "s3c64xx-iis",
220 .owner = THIS_MODULE,
224 static int __init s3c64xx_i2s_init(void)
226 return platform_driver_register(&s3c64xx_iis_driver);
228 module_init(s3c64xx_i2s_init);
230 static void __exit s3c64xx_i2s_exit(void)
232 platform_driver_unregister(&s3c64xx_iis_driver);
234 module_exit(s3c64xx_i2s_exit);
236 /* Module information */
237 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
238 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
239 MODULE_LICENSE("GPL");