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/clk.h>
19 #include <linux/gpio.h>
22 #include <sound/soc.h>
24 #include <plat/regs-s3c2412-iis.h>
25 #include <plat/gpio-bank-d.h>
26 #include <plat/gpio-bank-e.h>
27 #include <plat/gpio-cfg.h>
33 #include "s3c64xx-i2s.h"
35 /* The value should be set to maximum of the total number
36 * of I2Sv3 controllers that any supported SoC has.
40 static struct s3c2410_dma_client s3c64xx_dma_client_out
= {
41 .name
= "I2S PCM Stereo out"
44 static struct s3c2410_dma_client s3c64xx_dma_client_in
= {
45 .name
= "I2S PCM Stereo in"
48 static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out
[MAX_I2SV3
];
49 static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in
[MAX_I2SV3
];
50 static struct s3c_i2sv2_info s3c64xx_i2s
[MAX_I2SV3
];
52 struct snd_soc_dai s3c64xx_i2s_dai
[MAX_I2SV3
];
53 EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai
);
55 static inline struct s3c_i2sv2_info
*to_info(struct snd_soc_dai
*cpu_dai
)
57 return cpu_dai
->private_data
;
60 static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai
*cpu_dai
,
61 int clk_id
, unsigned int freq
, int dir
)
63 struct s3c_i2sv2_info
*i2s
= to_info(cpu_dai
);
64 u32 iismod
= readl(i2s
->regs
+ S3C2412_IISMOD
);
67 case S3C64XX_CLKSRC_PCLK
:
68 iismod
&= ~S3C64XX_IISMOD_IMS_SYSMUX
;
71 case S3C64XX_CLKSRC_MUX
:
72 iismod
|= S3C64XX_IISMOD_IMS_SYSMUX
;
75 case S3C64XX_CLKSRC_CDCLK
:
77 case SND_SOC_CLOCK_IN
:
78 iismod
|= S3C64XX_IISMOD_CDCLKCON
;
80 case SND_SOC_CLOCK_OUT
:
81 iismod
&= ~S3C64XX_IISMOD_CDCLKCON
;
92 writel(iismod
, i2s
->regs
+ S3C2412_IISMOD
);
97 struct clk
*s3c64xx_i2s_get_clock(struct snd_soc_dai
*dai
)
99 struct s3c_i2sv2_info
*i2s
= to_info(dai
);
100 u32 iismod
= readl(i2s
->regs
+ S3C2412_IISMOD
);
102 if (iismod
& S3C64XX_IISMOD_IMS_SYSMUX
)
103 return i2s
->iis_cclk
;
105 return i2s
->iis_pclk
;
107 EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock
);
109 static int s3c64xx_i2s_probe(struct platform_device
*pdev
,
110 struct snd_soc_dai
*dai
)
112 /* configure GPIO for i2s port */
115 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK
);
116 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK
);
117 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK
);
118 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI
);
119 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0
);
122 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK
);
123 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK
);
124 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK
);
125 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI
);
126 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0
);
133 #define S3C64XX_I2S_RATES \
134 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
135 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
136 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
138 #define S3C64XX_I2S_FMTS \
139 (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
140 SNDRV_PCM_FMTBIT_S24_LE)
142 static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops
= {
143 .set_sysclk
= s3c64xx_i2s_set_sysclk
,
146 static __devinit
int s3c64xx_iis_dev_probe(struct platform_device
*pdev
)
148 struct s3c_i2sv2_info
*i2s
;
149 struct snd_soc_dai
*dai
;
152 if (pdev
->id
>= MAX_I2SV3
) {
153 dev_err(&pdev
->dev
, "id %d out of range\n", pdev
->id
);
157 i2s
= &s3c64xx_i2s
[pdev
->id
];
158 dai
= &s3c64xx_i2s_dai
[pdev
->id
];
159 dai
->dev
= &pdev
->dev
;
160 dai
->name
= "s3c64xx-i2s";
162 dai
->symmetric_rates
= 1;
163 dai
->playback
.channels_min
= 2;
164 dai
->playback
.channels_max
= 2;
165 dai
->playback
.rates
= S3C64XX_I2S_RATES
;
166 dai
->playback
.formats
= S3C64XX_I2S_FMTS
;
167 dai
->capture
.channels_min
= 2;
168 dai
->capture
.channels_max
= 2;
169 dai
->capture
.rates
= S3C64XX_I2S_RATES
;
170 dai
->capture
.formats
= S3C64XX_I2S_FMTS
;
171 dai
->probe
= s3c64xx_i2s_probe
;
172 dai
->ops
= &s3c64xx_i2s_dai_ops
;
174 i2s
->dma_capture
= &s3c64xx_i2s_pcm_stereo_in
[pdev
->id
];
175 i2s
->dma_playback
= &s3c64xx_i2s_pcm_stereo_out
[pdev
->id
];
178 i2s
->dma_capture
->channel
= DMACH_I2S0_IN
;
179 i2s
->dma_capture
->dma_addr
= S3C64XX_PA_IIS0
+ S3C2412_IISRXD
;
180 i2s
->dma_playback
->channel
= DMACH_I2S0_OUT
;
181 i2s
->dma_playback
->dma_addr
= S3C64XX_PA_IIS0
+ S3C2412_IISTXD
;
183 i2s
->dma_capture
->channel
= DMACH_I2S1_IN
;
184 i2s
->dma_capture
->dma_addr
= S3C64XX_PA_IIS1
+ S3C2412_IISRXD
;
185 i2s
->dma_playback
->channel
= DMACH_I2S1_OUT
;
186 i2s
->dma_playback
->dma_addr
= S3C64XX_PA_IIS1
+ S3C2412_IISTXD
;
189 i2s
->dma_capture
->client
= &s3c64xx_dma_client_in
;
190 i2s
->dma_capture
->dma_size
= 4;
191 i2s
->dma_playback
->client
= &s3c64xx_dma_client_out
;
192 i2s
->dma_playback
->dma_size
= 4;
194 i2s
->iis_cclk
= clk_get(&pdev
->dev
, "audio-bus");
195 if (IS_ERR(i2s
->iis_cclk
)) {
196 dev_err(&pdev
->dev
, "failed to get audio-bus\n");
197 ret
= PTR_ERR(i2s
->iis_cclk
);
201 clk_enable(i2s
->iis_cclk
);
203 ret
= s3c_i2sv2_probe(pdev
, dai
, i2s
, 0);
207 ret
= s3c_i2sv2_register_dai(dai
);
214 /* Not implemented for I2Sv2 core yet */
216 clk_put(i2s
->iis_cclk
);
221 static __devexit
int s3c64xx_iis_dev_remove(struct platform_device
*pdev
)
223 dev_err(&pdev
->dev
, "Device removal not yet supported\n");
227 static struct platform_driver s3c64xx_iis_driver
= {
228 .probe
= s3c64xx_iis_dev_probe
,
229 .remove
= s3c64xx_iis_dev_remove
,
231 .name
= "s3c64xx-iis",
232 .owner
= THIS_MODULE
,
236 static int __init
s3c64xx_i2s_init(void)
238 return platform_driver_register(&s3c64xx_iis_driver
);
240 module_init(s3c64xx_i2s_init
);
242 static void __exit
s3c64xx_i2s_exit(void)
244 platform_driver_unregister(&s3c64xx_iis_driver
);
246 module_exit(s3c64xx_i2s_exit
);
248 /* Module information */
249 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
250 MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
251 MODULE_LICENSE("GPL");