blob: b7e951fe30a6b95b088baedf96c542ed10bae022 [file] [log] [blame]
Ben Dooksf8cf8172009-03-04 00:49:31 +00001/* sound/soc/s3c24xx/s3c64xx-i2s.c
2 *
3 * ALSA SoC Audio Layer - S3C64XX I2S driver
4 *
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
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.
13 */
14
Ben Dooksf8cf8172009-03-04 00:49:31 +000015#include <linux/clk.h>
Ben Dooksf8cf8172009-03-04 00:49:31 +000016#include <linux/gpio.h>
17#include <linux/io.h>
18
Ben Dooksf8cf8172009-03-04 00:49:31 +000019#include <sound/soc.h>
20
Mark Brownfacf9262010-03-01 19:57:59 +000021#include <mach/gpio-bank-d.h>
22#include <mach/gpio-bank-e.h>
Ben Dooksf8cf8172009-03-04 00:49:31 +000023#include <plat/gpio-cfg.h>
Ben Dooksf8cf8172009-03-04 00:49:31 +000024
25#include <mach/map.h>
26#include <mach/dma.h>
27
Jassi Brard3ff5a32009-11-17 16:53:31 +090028#include "s3c-dma.h"
Jassi Brard07e7ce2010-04-27 15:55:21 +090029#include "regs-i2s-v2.h"
Ben Dooksf8cf8172009-03-04 00:49:31 +000030#include "s3c64xx-i2s.h"
31
Jassi Brar0fe69222009-12-09 13:29:25 +090032/* The value should be set to maximum of the total number
33 * of I2Sv3 controllers that any supported SoC has.
34 */
35#define MAX_I2SV3 2
36
Ben Dooksf8cf8172009-03-04 00:49:31 +000037static struct s3c2410_dma_client s3c64xx_dma_client_out = {
38 .name = "I2S PCM Stereo out"
39};
40
41static struct s3c2410_dma_client s3c64xx_dma_client_in = {
42 .name = "I2S PCM Stereo in"
43};
44
Jassi Brar0fe69222009-12-09 13:29:25 +090045static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[MAX_I2SV3];
46static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[MAX_I2SV3];
47static struct s3c_i2sv2_info s3c64xx_i2s[MAX_I2SV3];
Ben Dooksf8cf8172009-03-04 00:49:31 +000048
Jassi Brar0fe69222009-12-09 13:29:25 +090049struct snd_soc_dai s3c64xx_i2s_dai[MAX_I2SV3];
50EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
Ben Dooksf8cf8172009-03-04 00:49:31 +000051
52static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
53{
54 return cpu_dai->private_data;
55}
56
57static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
58 int clk_id, unsigned int freq, int dir)
59{
60 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
61 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
62
63 switch (clk_id) {
64 case S3C64XX_CLKSRC_PCLK:
65 iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
66 break;
67
68 case S3C64XX_CLKSRC_MUX:
69 iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
70 break;
71
Mark Brown8bb01482009-09-16 19:38:53 +010072 case S3C64XX_CLKSRC_CDCLK:
73 switch (dir) {
74 case SND_SOC_CLOCK_IN:
75 iismod |= S3C64XX_IISMOD_CDCLKCON;
76 break;
77 case SND_SOC_CLOCK_OUT:
78 iismod &= ~S3C64XX_IISMOD_CDCLKCON;
79 break;
80 default:
81 return -EINVAL;
82 }
83 break;
84
Ben Dooksf8cf8172009-03-04 00:49:31 +000085 default:
86 return -EINVAL;
87 }
88
89 writel(iismod, i2s->regs + S3C2412_IISMOD);
90
91 return 0;
92}
93
Mark Brown51438442009-04-29 20:30:39 +010094struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
Ben Dooksf8cf8172009-03-04 00:49:31 +000095{
96 struct s3c_i2sv2_info *i2s = to_info(dai);
Jassib1cd6b92009-09-18 15:22:27 +090097 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
Ben Dooksf8cf8172009-03-04 00:49:31 +000098
Jassib1cd6b92009-09-18 15:22:27 +090099 if (iismod & S3C64XX_IISMOD_IMS_SYSMUX)
100 return i2s->iis_cclk;
101 else
102 return i2s->iis_pclk;
Ben Dooksf8cf8172009-03-04 00:49:31 +0000103}
Mark Brown51438442009-04-29 20:30:39 +0100104EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000105
106static int s3c64xx_i2s_probe(struct platform_device *pdev,
107 struct snd_soc_dai *dai)
108{
Ben Dooksf8cf8172009-03-04 00:49:31 +0000109 /* configure GPIO for i2s port */
Mark Brown172fd9e2009-04-24 16:33:10 +0100110 switch (dai->id) {
Ben Dooksf8cf8172009-03-04 00:49:31 +0000111 case 0:
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);
117 break;
118 case 1:
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);
124 }
125
126 return 0;
127}
128
129
Mark Brownf2a5d6a2009-03-16 14:02:07 +0000130static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
131 .set_sysclk = s3c64xx_i2s_set_sysclk,
132};
133
Mark Brown172fd9e2009-04-24 16:33:10 +0100134static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
135{
136 struct s3c_i2sv2_info *i2s;
137 struct snd_soc_dai *dai;
138 int ret;
139
Jassi Brar0fe69222009-12-09 13:29:25 +0900140 if (pdev->id >= MAX_I2SV3) {
Mark Brown172fd9e2009-04-24 16:33:10 +0100141 dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
142 return -EINVAL;
143 }
144
145 i2s = &s3c64xx_i2s[pdev->id];
146 dai = &s3c64xx_i2s_dai[pdev->id];
147 dai->dev = &pdev->dev;
Jassi Brar0fe69222009-12-09 13:29:25 +0900148 dai->name = "s3c64xx-i2s";
149 dai->id = pdev->id;
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;
Mark Brown172fd9e2009-04-24 16:33:10 +0100161
162 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
163 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
164
Jassi Brar0fe69222009-12-09 13:29:25 +0900165 if (pdev->id == 0) {
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;
170 } else {
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;
175 }
176
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;
181
Mark Brown172fd9e2009-04-24 16:33:10 +0100182 i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
183 if (IS_ERR(i2s->iis_cclk)) {
Mark Brown09aa60d2009-04-29 18:51:48 +0100184 dev_err(&pdev->dev, "failed to get audio-bus\n");
Mark Brown172fd9e2009-04-24 16:33:10 +0100185 ret = PTR_ERR(i2s->iis_cclk);
186 goto err;
187 }
188
Jassi Brar6fc786d2009-11-06 18:00:24 +0900189 clk_enable(i2s->iis_cclk);
190
Mark Brown71437552009-04-30 13:42:04 +0100191 ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
Mark Brown172fd9e2009-04-24 16:33:10 +0100192 if (ret)
193 goto err_clk;
194
Mark Browna7be4d92009-04-27 20:24:15 +0100195 ret = s3c_i2sv2_register_dai(dai);
Mark Brown172fd9e2009-04-24 16:33:10 +0100196 if (ret != 0)
197 goto err_i2sv2;
198
199 return 0;
200
201err_i2sv2:
202 /* Not implemented for I2Sv2 core yet */
203err_clk:
204 clk_put(i2s->iis_cclk);
205err:
206 return ret;
207}
208
209static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
210{
211 dev_err(&pdev->dev, "Device removal not yet supported\n");
212 return 0;
213}
214
215static struct platform_driver s3c64xx_iis_driver = {
216 .probe = s3c64xx_iis_dev_probe,
217 .remove = s3c64xx_iis_dev_remove,
218 .driver = {
219 .name = "s3c64xx-iis",
220 .owner = THIS_MODULE,
221 },
222};
223
Ben Dooksf8cf8172009-03-04 00:49:31 +0000224static int __init s3c64xx_i2s_init(void)
225{
Mark Brown172fd9e2009-04-24 16:33:10 +0100226 return platform_driver_register(&s3c64xx_iis_driver);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000227}
228module_init(s3c64xx_i2s_init);
229
230static void __exit s3c64xx_i2s_exit(void)
231{
Mark Brown172fd9e2009-04-24 16:33:10 +0100232 platform_driver_unregister(&s3c64xx_iis_driver);
Ben Dooksf8cf8172009-03-04 00:49:31 +0000233}
234module_exit(s3c64xx_i2s_exit);
235
236/* Module information */
237MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
238MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
239MODULE_LICENSE("GPL");