1 /* linux/arch/arm/mach-s5pc100/dev-audio.c
2  *
3  * Copyright (c) 2010 Samsung Electronics Co. Ltd
4  *	Jaswinder Singh <jassi.brar@samsung.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  */
10 
11 #include <linux/platform_device.h>
12 #include <linux/dma-mapping.h>
13 #include <linux/gpio.h>
14 
15 #include <plat/gpio-cfg.h>
16 #include <plat/audio.h>
17 
18 #include <mach/map.h>
19 #include <mach/dma.h>
20 #include <mach/irqs.h>
21 
s5pc100_cfg_i2s(struct platform_device * pdev)22 static int s5pc100_cfg_i2s(struct platform_device *pdev)
23 {
24 	/* configure GPIO for i2s port */
25 	switch (pdev->id) {
26 	case 0: /* Dedicated pins */
27 		break;
28 	case 1:
29 		s3c_gpio_cfgpin_range(S5PC100_GPC(0), 5, S3C_GPIO_SFN(2));
30 		break;
31 	case 2:
32 		s3c_gpio_cfgpin_range(S5PC100_GPG3(0), 5, S3C_GPIO_SFN(4));
33 		break;
34 	default:
35 		printk(KERN_ERR "Invalid Device %d\n", pdev->id);
36 		return -EINVAL;
37 	}
38 
39 	return 0;
40 }
41 
42 static const char *rclksrc_v5[] = {
43 	[0] = "iis",
44 	[1] = "i2sclkd2",
45 };
46 
47 static struct s3c_audio_pdata i2sv5_pdata = {
48 	.cfg_gpio = s5pc100_cfg_i2s,
49 	.type = {
50 		.i2s = {
51 			.quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI
52 					 | QUIRK_NEED_RSTCLR,
53 			.src_clk = rclksrc_v5,
54 		},
55 	},
56 };
57 
58 static struct resource s5pc100_iis0_resource[] = {
59 	[0] = {
60 		.start = S5PC100_PA_I2S0,
61 		.end   = S5PC100_PA_I2S0 + 0x100 - 1,
62 		.flags = IORESOURCE_MEM,
63 	},
64 	[1] = {
65 		.start = DMACH_I2S0_TX,
66 		.end   = DMACH_I2S0_TX,
67 		.flags = IORESOURCE_DMA,
68 	},
69 	[2] = {
70 		.start = DMACH_I2S0_RX,
71 		.end   = DMACH_I2S0_RX,
72 		.flags = IORESOURCE_DMA,
73 	},
74 	[3] = {
75 		.start = DMACH_I2S0S_TX,
76 		.end = DMACH_I2S0S_TX,
77 		.flags = IORESOURCE_DMA,
78 	},
79 };
80 
81 struct platform_device s5pc100_device_iis0 = {
82 	.name = "samsung-i2s",
83 	.id = 0,
84 	.num_resources	  = ARRAY_SIZE(s5pc100_iis0_resource),
85 	.resource	  = s5pc100_iis0_resource,
86 	.dev = {
87 		.platform_data = &i2sv5_pdata,
88 	},
89 };
90 
91 static const char *rclksrc_v3[] = {
92 	[0] = "iis",
93 	[1] = "sclk_audio",
94 };
95 
96 static struct s3c_audio_pdata i2sv3_pdata = {
97 	.cfg_gpio = s5pc100_cfg_i2s,
98 	.type = {
99 		.i2s = {
100 			.src_clk = rclksrc_v3,
101 		},
102 	},
103 };
104 
105 static struct resource s5pc100_iis1_resource[] = {
106 	[0] = {
107 		.start = S5PC100_PA_I2S1,
108 		.end   = S5PC100_PA_I2S1 + 0x100 - 1,
109 		.flags = IORESOURCE_MEM,
110 	},
111 	[1] = {
112 		.start = DMACH_I2S1_TX,
113 		.end   = DMACH_I2S1_TX,
114 		.flags = IORESOURCE_DMA,
115 	},
116 	[2] = {
117 		.start = DMACH_I2S1_RX,
118 		.end   = DMACH_I2S1_RX,
119 		.flags = IORESOURCE_DMA,
120 	},
121 };
122 
123 struct platform_device s5pc100_device_iis1 = {
124 	.name		  = "samsung-i2s",
125 	.id		  = 1,
126 	.num_resources	  = ARRAY_SIZE(s5pc100_iis1_resource),
127 	.resource	  = s5pc100_iis1_resource,
128 	.dev = {
129 		.platform_data = &i2sv3_pdata,
130 	},
131 };
132 
133 static struct resource s5pc100_iis2_resource[] = {
134 	[0] = {
135 		.start = S5PC100_PA_I2S2,
136 		.end   = S5PC100_PA_I2S2 + 0x100 - 1,
137 		.flags = IORESOURCE_MEM,
138 	},
139 	[1] = {
140 		.start = DMACH_I2S2_TX,
141 		.end   = DMACH_I2S2_TX,
142 		.flags = IORESOURCE_DMA,
143 	},
144 	[2] = {
145 		.start = DMACH_I2S2_RX,
146 		.end   = DMACH_I2S2_RX,
147 		.flags = IORESOURCE_DMA,
148 	},
149 };
150 
151 struct platform_device s5pc100_device_iis2 = {
152 	.name		  = "samsung-i2s",
153 	.id		  = 2,
154 	.num_resources	  = ARRAY_SIZE(s5pc100_iis2_resource),
155 	.resource	  = s5pc100_iis2_resource,
156 	.dev = {
157 		.platform_data = &i2sv3_pdata,
158 	},
159 };
160 
161 /* PCM Controller platform_devices */
162 
s5pc100_pcm_cfg_gpio(struct platform_device * pdev)163 static int s5pc100_pcm_cfg_gpio(struct platform_device *pdev)
164 {
165 	switch (pdev->id) {
166 	case 0:
167 		s3c_gpio_cfgpin_range(S5PC100_GPG3(0), 5, S3C_GPIO_SFN(5));
168 		break;
169 
170 	case 1:
171 		s3c_gpio_cfgpin_range(S5PC100_GPC(0), 5, S3C_GPIO_SFN(3));
172 		break;
173 
174 	default:
175 		printk(KERN_DEBUG "Invalid PCM Controller number!");
176 		return -EINVAL;
177 	}
178 
179 	return 0;
180 }
181 
182 static struct s3c_audio_pdata s3c_pcm_pdata = {
183 	.cfg_gpio = s5pc100_pcm_cfg_gpio,
184 };
185 
186 static struct resource s5pc100_pcm0_resource[] = {
187 	[0] = {
188 		.start = S5PC100_PA_PCM0,
189 		.end   = S5PC100_PA_PCM0 + 0x100 - 1,
190 		.flags = IORESOURCE_MEM,
191 	},
192 	[1] = {
193 		.start = DMACH_PCM0_TX,
194 		.end   = DMACH_PCM0_TX,
195 		.flags = IORESOURCE_DMA,
196 	},
197 	[2] = {
198 		.start = DMACH_PCM0_RX,
199 		.end   = DMACH_PCM0_RX,
200 		.flags = IORESOURCE_DMA,
201 	},
202 };
203 
204 struct platform_device s5pc100_device_pcm0 = {
205 	.name		  = "samsung-pcm",
206 	.id		  = 0,
207 	.num_resources	  = ARRAY_SIZE(s5pc100_pcm0_resource),
208 	.resource	  = s5pc100_pcm0_resource,
209 	.dev = {
210 		.platform_data = &s3c_pcm_pdata,
211 	},
212 };
213 
214 static struct resource s5pc100_pcm1_resource[] = {
215 	[0] = {
216 		.start = S5PC100_PA_PCM1,
217 		.end   = S5PC100_PA_PCM1 + 0x100 - 1,
218 		.flags = IORESOURCE_MEM,
219 	},
220 	[1] = {
221 		.start = DMACH_PCM1_TX,
222 		.end   = DMACH_PCM1_TX,
223 		.flags = IORESOURCE_DMA,
224 	},
225 	[2] = {
226 		.start = DMACH_PCM1_RX,
227 		.end   = DMACH_PCM1_RX,
228 		.flags = IORESOURCE_DMA,
229 	},
230 };
231 
232 struct platform_device s5pc100_device_pcm1 = {
233 	.name		  = "samsung-pcm",
234 	.id		  = 1,
235 	.num_resources	  = ARRAY_SIZE(s5pc100_pcm1_resource),
236 	.resource	  = s5pc100_pcm1_resource,
237 	.dev = {
238 		.platform_data = &s3c_pcm_pdata,
239 	},
240 };
241 
242 /* AC97 Controller platform devices */
243 
s5pc100_ac97_cfg_gpio(struct platform_device * pdev)244 static int s5pc100_ac97_cfg_gpio(struct platform_device *pdev)
245 {
246 	return s3c_gpio_cfgpin_range(S5PC100_GPC(0), 5, S3C_GPIO_SFN(4));
247 }
248 
249 static struct resource s5pc100_ac97_resource[] = {
250 	[0] = {
251 		.start = S5PC100_PA_AC97,
252 		.end   = S5PC100_PA_AC97 + 0x100 - 1,
253 		.flags = IORESOURCE_MEM,
254 	},
255 	[1] = {
256 		.start = DMACH_AC97_PCMOUT,
257 		.end   = DMACH_AC97_PCMOUT,
258 		.flags = IORESOURCE_DMA,
259 	},
260 	[2] = {
261 		.start = DMACH_AC97_PCMIN,
262 		.end   = DMACH_AC97_PCMIN,
263 		.flags = IORESOURCE_DMA,
264 	},
265 	[3] = {
266 		.start = DMACH_AC97_MICIN,
267 		.end   = DMACH_AC97_MICIN,
268 		.flags = IORESOURCE_DMA,
269 	},
270 	[4] = {
271 		.start = IRQ_AC97,
272 		.end   = IRQ_AC97,
273 		.flags = IORESOURCE_IRQ,
274 	},
275 };
276 
277 static struct s3c_audio_pdata s3c_ac97_pdata = {
278 	.cfg_gpio = s5pc100_ac97_cfg_gpio,
279 };
280 
281 static u64 s5pc100_ac97_dmamask = DMA_BIT_MASK(32);
282 
283 struct platform_device s5pc100_device_ac97 = {
284 	.name		  = "samsung-ac97",
285 	.id		  = -1,
286 	.num_resources	  = ARRAY_SIZE(s5pc100_ac97_resource),
287 	.resource	  = s5pc100_ac97_resource,
288 	.dev = {
289 		.platform_data = &s3c_ac97_pdata,
290 		.dma_mask = &s5pc100_ac97_dmamask,
291 		.coherent_dma_mask = DMA_BIT_MASK(32),
292 	},
293 };
294 
295 /* S/PDIF Controller platform_device */
s5pc100_spdif_cfg_gpd(struct platform_device * pdev)296 static int s5pc100_spdif_cfg_gpd(struct platform_device *pdev)
297 {
298 	s3c_gpio_cfgpin_range(S5PC100_GPD(5), 2, S3C_GPIO_SFN(3));
299 
300 	return 0;
301 }
302 
s5pc100_spdif_cfg_gpg3(struct platform_device * pdev)303 static int s5pc100_spdif_cfg_gpg3(struct platform_device *pdev)
304 {
305 	s3c_gpio_cfgpin_range(S5PC100_GPG3(5), 2, S3C_GPIO_SFN(3));
306 
307 	return 0;
308 }
309 
310 static struct resource s5pc100_spdif_resource[] = {
311 	[0] = {
312 		.start	= S5PC100_PA_SPDIF,
313 		.end	= S5PC100_PA_SPDIF + 0x100 - 1,
314 		.flags	= IORESOURCE_MEM,
315 	},
316 	[1] = {
317 		.start	= DMACH_SPDIF,
318 		.end	= DMACH_SPDIF,
319 		.flags	= IORESOURCE_DMA,
320 	},
321 };
322 
323 static struct s3c_audio_pdata s5p_spdif_pdata = {
324 	.cfg_gpio = s5pc100_spdif_cfg_gpd,
325 };
326 
327 static u64 s5pc100_spdif_dmamask = DMA_BIT_MASK(32);
328 
329 struct platform_device s5pc100_device_spdif = {
330 	.name		= "samsung-spdif",
331 	.id		= -1,
332 	.num_resources	= ARRAY_SIZE(s5pc100_spdif_resource),
333 	.resource	= s5pc100_spdif_resource,
334 	.dev = {
335 		.platform_data = &s5p_spdif_pdata,
336 		.dma_mask = &s5pc100_spdif_dmamask,
337 		.coherent_dma_mask = DMA_BIT_MASK(32),
338 	},
339 };
340 
s5pc100_spdif_setup_gpio(int gpio)341 void __init s5pc100_spdif_setup_gpio(int gpio)
342 {
343 	if (gpio == S5PC100_SPDIF_GPD)
344 		s5p_spdif_pdata.cfg_gpio = s5pc100_spdif_cfg_gpd;
345 	else
346 		s5p_spdif_pdata.cfg_gpio = s5pc100_spdif_cfg_gpg3;
347 }
348