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 <mach/gpio-bank-d.h>
22 #include <mach/gpio-bank-e.h>
23 #include <plat/gpio-cfg.h>
29 #include "regs-i2s-v2.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 &= ~S3C2412_IISMOD_IMS_SYSMUX;
68 case S3C64XX_CLKSRC_MUX:
69 iismod |= S3C2412_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 static int s3c64xx_i2s_probe(struct platform_device *pdev,
95 struct snd_soc_dai *dai)
97 /* configure GPIO for i2s port */
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);
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);
118 static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
119 .set_sysclk = s3c64xx_i2s_set_sysclk,
122 static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
124 struct s3c_i2sv2_info *i2s;
125 struct snd_soc_dai *dai;
128 if (pdev->id >= MAX_I2SV3) {
129 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
133 i2s = &s3c64xx_i2s[pdev->id];
134 dai = &s3c64xx_i2s_dai[pdev->id];
135 dai->dev = &pdev->dev;
136 dai->name = "s3c64xx-i2s";
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;
150 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
151 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
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;
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;
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;
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);
177 clk_enable(i2s->iis_cclk);
179 ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
183 ret = s3c_i2sv2_register_dai(dai);
190 /* Not implemented for I2Sv2 core yet */
192 clk_put(i2s->iis_cclk);
197 static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
199 dev_err(&pdev->dev, "Device removal not yet supported\n");
203 static struct platform_driver s3c64xx_iis_driver = {
204 .probe = s3c64xx_iis_dev_probe,
205 .remove = s3c64xx_iis_dev_remove,
207 .name = "s3c64xx-iis",
208 .owner = THIS_MODULE,
212 static int __init s3c64xx_i2s_init(void)
214 return platform_driver_register(&s3c64xx_iis_driver);
216 module_init(s3c64xx_i2s_init);
218 static void __exit s3c64xx_i2s_exit(void)
220 platform_driver_unregister(&s3c64xx_iis_driver);
222 module_exit(s3c64xx_i2s_exit);
224 /* Module information */
225 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
226 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
227 MODULE_LICENSE("GPL");