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>
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>
39 #include "s3c64xx-i2s.h"
41 static struct s3c2410_dma_client s3c64xx_dma_client_out
= {
42 .name
= "I2S PCM Stereo out"
45 static struct s3c2410_dma_client s3c64xx_dma_client_in
= {
46 .name
= "I2S PCM Stereo in"
49 static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out
[2] = {
51 .channel
= DMACH_I2S0_OUT
,
52 .client
= &s3c64xx_dma_client_out
,
53 .dma_addr
= S3C64XX_PA_IIS0
+ S3C2412_IISTXD
,
57 .channel
= DMACH_I2S1_OUT
,
58 .client
= &s3c64xx_dma_client_out
,
59 .dma_addr
= S3C64XX_PA_IIS1
+ S3C2412_IISTXD
,
64 static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in
[2] = {
66 .channel
= DMACH_I2S0_IN
,
67 .client
= &s3c64xx_dma_client_in
,
68 .dma_addr
= S3C64XX_PA_IIS0
+ S3C2412_IISRXD
,
72 .channel
= DMACH_I2S1_IN
,
73 .client
= &s3c64xx_dma_client_in
,
74 .dma_addr
= S3C64XX_PA_IIS1
+ S3C2412_IISRXD
,
79 static struct s3c_i2sv2_info s3c64xx_i2s
[2];
81 static inline struct s3c_i2sv2_info
*to_info(struct snd_soc_dai
*cpu_dai
)
83 return cpu_dai
->private_data
;
86 static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai
*cpu_dai
,
87 int clk_id
, unsigned int freq
, int dir
)
89 struct s3c_i2sv2_info
*i2s
= to_info(cpu_dai
);
90 u32 iismod
= readl(i2s
->regs
+ S3C2412_IISMOD
);
93 case S3C64XX_CLKSRC_PCLK
:
94 iismod
&= ~S3C64XX_IISMOD_IMS_SYSMUX
;
97 case S3C64XX_CLKSRC_MUX
:
98 iismod
|= S3C64XX_IISMOD_IMS_SYSMUX
;
101 case S3C64XX_CLKSRC_CDCLK
:
103 case SND_SOC_CLOCK_IN
:
104 iismod
|= S3C64XX_IISMOD_CDCLKCON
;
106 case SND_SOC_CLOCK_OUT
:
107 iismod
&= ~S3C64XX_IISMOD_CDCLKCON
;
118 writel(iismod
, i2s
->regs
+ S3C2412_IISMOD
);
123 struct clk
*s3c64xx_i2s_get_clock(struct snd_soc_dai
*dai
)
125 struct s3c_i2sv2_info
*i2s
= to_info(dai
);
126 u32 iismod
= readl(i2s
->regs
+ S3C2412_IISMOD
);
128 if (iismod
& S3C64XX_IISMOD_IMS_SYSMUX
)
129 return i2s
->iis_cclk
;
131 return i2s
->iis_pclk
;
133 EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock
);
135 static int s3c64xx_i2s_probe(struct platform_device
*pdev
,
136 struct snd_soc_dai
*dai
)
138 /* configure GPIO for i2s port */
141 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK
);
142 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK
);
143 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK
);
144 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI
);
145 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0
);
148 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK
);
149 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK
);
150 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK
);
151 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI
);
152 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0
);
159 #define S3C64XX_I2S_RATES \
160 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
161 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
162 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
164 #define S3C64XX_I2S_FMTS \
165 (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
166 SNDRV_PCM_FMTBIT_S24_LE)
168 static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops
= {
169 .set_sysclk
= s3c64xx_i2s_set_sysclk
,
172 struct snd_soc_dai s3c64xx_i2s_dai
[] = {
174 .name
= "s3c64xx-i2s",
176 .probe
= s3c64xx_i2s_probe
,
180 .rates
= S3C64XX_I2S_RATES
,
181 .formats
= S3C64XX_I2S_FMTS
,
186 .rates
= S3C64XX_I2S_RATES
,
187 .formats
= S3C64XX_I2S_FMTS
,
189 .ops
= &s3c64xx_i2s_dai_ops
,
190 .symmetric_rates
= 1,
193 .name
= "s3c64xx-i2s",
195 .probe
= s3c64xx_i2s_probe
,
199 .rates
= S3C64XX_I2S_RATES
,
200 .formats
= S3C64XX_I2S_FMTS
,
205 .rates
= S3C64XX_I2S_RATES
,
206 .formats
= S3C64XX_I2S_FMTS
,
208 .ops
= &s3c64xx_i2s_dai_ops
,
209 .symmetric_rates
= 1,
212 EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai
);
214 static __devinit
int s3c64xx_iis_dev_probe(struct platform_device
*pdev
)
216 struct s3c_i2sv2_info
*i2s
;
217 struct snd_soc_dai
*dai
;
220 if (pdev
->id
>= ARRAY_SIZE(s3c64xx_i2s
)) {
221 dev_err(&pdev
->dev
, "id %d out of range\n", pdev
->id
);
225 i2s
= &s3c64xx_i2s
[pdev
->id
];
226 dai
= &s3c64xx_i2s_dai
[pdev
->id
];
227 dai
->dev
= &pdev
->dev
;
229 i2s
->dma_capture
= &s3c64xx_i2s_pcm_stereo_in
[pdev
->id
];
230 i2s
->dma_playback
= &s3c64xx_i2s_pcm_stereo_out
[pdev
->id
];
232 i2s
->iis_cclk
= clk_get(&pdev
->dev
, "audio-bus");
233 if (IS_ERR(i2s
->iis_cclk
)) {
234 dev_err(&pdev
->dev
, "failed to get audio-bus\n");
235 ret
= PTR_ERR(i2s
->iis_cclk
);
239 clk_enable(i2s
->iis_cclk
);
241 ret
= s3c_i2sv2_probe(pdev
, dai
, i2s
, 0);
245 ret
= s3c_i2sv2_register_dai(dai
);
252 /* Not implemented for I2Sv2 core yet */
254 clk_put(i2s
->iis_cclk
);
259 static __devexit
int s3c64xx_iis_dev_remove(struct platform_device
*pdev
)
261 dev_err(&pdev
->dev
, "Device removal not yet supported\n");
265 static struct platform_driver s3c64xx_iis_driver
= {
266 .probe
= s3c64xx_iis_dev_probe
,
267 .remove
= s3c64xx_iis_dev_remove
,
269 .name
= "s3c64xx-iis",
270 .owner
= THIS_MODULE
,
274 static int __init
s3c64xx_i2s_init(void)
276 return platform_driver_register(&s3c64xx_iis_driver
);
278 module_init(s3c64xx_i2s_init
);
280 static void __exit
s3c64xx_i2s_exit(void)
282 platform_driver_unregister(&s3c64xx_iis_driver
);
284 module_exit(s3c64xx_i2s_exit
);
286 /* Module information */
287 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
288 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
289 MODULE_LICENSE("GPL");