1 /* linux/arch/arm/mach-s5pv210/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 
22 static const char *rclksrc[] = {
23 	[0] = "busclk",
24 	[1] = "i2sclk",
25 };
26 
s5pv210_cfg_i2s(struct platform_device * pdev)27 static int s5pv210_cfg_i2s(struct platform_device *pdev)
28 {
29 	/* configure GPIO for i2s port */
30 	switch (pdev->id) {
31 	case 0:
32 		s3c_gpio_cfgpin_range(S5PV210_GPI(0), 7, S3C_GPIO_SFN(2));
33 		break;
34 	case 1:
35 		s3c_gpio_cfgpin_range(S5PV210_GPC0(0), 5, S3C_GPIO_SFN(2));
36 		break;
37 	case 2:
38 		s3c_gpio_cfgpin_range(S5PV210_GPC1(0), 5, S3C_GPIO_SFN(4));
39 		break;
40 	default:
41 		printk(KERN_ERR "Invalid Device %d\n", pdev->id);
42 		return -EINVAL;
43 	}
44 
45 	return 0;
46 }
47 
48 static struct s3c_audio_pdata i2sv5_pdata = {
49 	.cfg_gpio = s5pv210_cfg_i2s,
50 	.type = {
51 		.i2s = {
52 			.quirks = QUIRK_PRI_6CHAN | QUIRK_SEC_DAI
53 					 | QUIRK_NEED_RSTCLR,
54 			.src_clk = rclksrc,
55 		},
56 	},
57 };
58 
59 static struct resource s5pv210_iis0_resource[] = {
60 	[0] = {
61 		.start = S5PV210_PA_IIS0,
62 		.end   = S5PV210_PA_IIS0 + 0x100 - 1,
63 		.flags = IORESOURCE_MEM,
64 	},
65 	[1] = {
66 		.start = DMACH_I2S0_TX,
67 		.end   = DMACH_I2S0_TX,
68 		.flags = IORESOURCE_DMA,
69 	},
70 	[2] = {
71 		.start = DMACH_I2S0_RX,
72 		.end   = DMACH_I2S0_RX,
73 		.flags = IORESOURCE_DMA,
74 	},
75 	[3] = {
76 		.start = DMACH_I2S0S_TX,
77 		.end = DMACH_I2S0S_TX,
78 		.flags = IORESOURCE_DMA,
79 	},
80 };
81 
82 struct platform_device s5pv210_device_iis0 = {
83 	.name = "samsung-i2s",
84 	.id = 0,
85 	.num_resources	  = ARRAY_SIZE(s5pv210_iis0_resource),
86 	.resource	  = s5pv210_iis0_resource,
87 	.dev = {
88 		.platform_data = &i2sv5_pdata,
89 	},
90 };
91 
92 static const char *rclksrc_v3[] = {
93 	[0] = "iis",
94 	[1] = "audio-bus",
95 };
96 
97 static struct s3c_audio_pdata i2sv3_pdata = {
98 	.cfg_gpio = s5pv210_cfg_i2s,
99 	.type = {
100 		.i2s = {
101 			.src_clk = rclksrc_v3,
102 		},
103 	},
104 };
105 
106 static struct resource s5pv210_iis1_resource[] = {
107 	[0] = {
108 		.start = S5PV210_PA_IIS1,
109 		.end   = S5PV210_PA_IIS1 + 0x100 - 1,
110 		.flags = IORESOURCE_MEM,
111 	},
112 	[1] = {
113 		.start = DMACH_I2S1_TX,
114 		.end   = DMACH_I2S1_TX,
115 		.flags = IORESOURCE_DMA,
116 	},
117 	[2] = {
118 		.start = DMACH_I2S1_RX,
119 		.end   = DMACH_I2S1_RX,
120 		.flags = IORESOURCE_DMA,
121 	},
122 };
123 
124 struct platform_device s5pv210_device_iis1 = {
125 	.name		  = "samsung-i2s",
126 	.id		  = 1,
127 	.num_resources	  = ARRAY_SIZE(s5pv210_iis1_resource),
128 	.resource	  = s5pv210_iis1_resource,
129 	.dev = {
130 		.platform_data = &i2sv3_pdata,
131 	},
132 };
133 
134 static struct resource s5pv210_iis2_resource[] = {
135 	[0] = {
136 		.start = S5PV210_PA_IIS2,
137 		.end   = S5PV210_PA_IIS2 + 0x100 - 1,
138 		.flags = IORESOURCE_MEM,
139 	},
140 	[1] = {
141 		.start = DMACH_I2S2_TX,
142 		.end   = DMACH_I2S2_TX,
143 		.flags = IORESOURCE_DMA,
144 	},
145 	[2] = {
146 		.start = DMACH_I2S2_RX,
147 		.end   = DMACH_I2S2_RX,
148 		.flags = IORESOURCE_DMA,
149 	},
150 };
151 
152 struct platform_device s5pv210_device_iis2 = {
153 	.name		  = "samsung-i2s",
154 	.id		  = 2,
155 	.num_resources	  = ARRAY_SIZE(s5pv210_iis2_resource),
156 	.resource	  = s5pv210_iis2_resource,
157 	.dev = {
158 		.platform_data = &i2sv3_pdata,
159 	},
160 };
161 
162 /* PCM Controller platform_devices */
163 
s5pv210_pcm_cfg_gpio(struct platform_device * pdev)164 static int s5pv210_pcm_cfg_gpio(struct platform_device *pdev)
165 {
166 	switch (pdev->id) {
167 	case 0:
168 		s3c_gpio_cfgpin_range(S5PV210_GPI(0), 5, S3C_GPIO_SFN(3));
169 		break;
170 	case 1:
171 		s3c_gpio_cfgpin_range(S5PV210_GPC0(0), 5, S3C_GPIO_SFN(3));
172 		break;
173 	case 2:
174 		s3c_gpio_cfgpin_range(S5PV210_GPC1(0), 5, S3C_GPIO_SFN(2));
175 		break;
176 	default:
177 		printk(KERN_DEBUG "Invalid PCM Controller number!");
178 		return -EINVAL;
179 	}
180 
181 	return 0;
182 }
183 
184 static struct s3c_audio_pdata s3c_pcm_pdata = {
185 	.cfg_gpio = s5pv210_pcm_cfg_gpio,
186 };
187 
188 static struct resource s5pv210_pcm0_resource[] = {
189 	[0] = {
190 		.start = S5PV210_PA_PCM0,
191 		.end   = S5PV210_PA_PCM0 + 0x100 - 1,
192 		.flags = IORESOURCE_MEM,
193 	},
194 	[1] = {
195 		.start = DMACH_PCM0_TX,
196 		.end   = DMACH_PCM0_TX,
197 		.flags = IORESOURCE_DMA,
198 	},
199 	[2] = {
200 		.start = DMACH_PCM0_RX,
201 		.end   = DMACH_PCM0_RX,
202 		.flags = IORESOURCE_DMA,
203 	},
204 };
205 
206 struct platform_device s5pv210_device_pcm0 = {
207 	.name		  = "samsung-pcm",
208 	.id		  = 0,
209 	.num_resources	  = ARRAY_SIZE(s5pv210_pcm0_resource),
210 	.resource	  = s5pv210_pcm0_resource,
211 	.dev = {
212 		.platform_data = &s3c_pcm_pdata,
213 	},
214 };
215 
216 static struct resource s5pv210_pcm1_resource[] = {
217 	[0] = {
218 		.start = S5PV210_PA_PCM1,
219 		.end   = S5PV210_PA_PCM1 + 0x100 - 1,
220 		.flags = IORESOURCE_MEM,
221 	},
222 	[1] = {
223 		.start = DMACH_PCM1_TX,
224 		.end   = DMACH_PCM1_TX,
225 		.flags = IORESOURCE_DMA,
226 	},
227 	[2] = {
228 		.start = DMACH_PCM1_RX,
229 		.end   = DMACH_PCM1_RX,
230 		.flags = IORESOURCE_DMA,
231 	},
232 };
233 
234 struct platform_device s5pv210_device_pcm1 = {
235 	.name		  = "samsung-pcm",
236 	.id		  = 1,
237 	.num_resources	  = ARRAY_SIZE(s5pv210_pcm1_resource),
238 	.resource	  = s5pv210_pcm1_resource,
239 	.dev = {
240 		.platform_data = &s3c_pcm_pdata,
241 	},
242 };
243 
244 static struct resource s5pv210_pcm2_resource[] = {
245 	[0] = {
246 		.start = S5PV210_PA_PCM2,
247 		.end   = S5PV210_PA_PCM2 + 0x100 - 1,
248 		.flags = IORESOURCE_MEM,
249 	},
250 	[1] = {
251 		.start = DMACH_PCM2_TX,
252 		.end   = DMACH_PCM2_TX,
253 		.flags = IORESOURCE_DMA,
254 	},
255 	[2] = {
256 		.start = DMACH_PCM2_RX,
257 		.end   = DMACH_PCM2_RX,
258 		.flags = IORESOURCE_DMA,
259 	},
260 };
261 
262 struct platform_device s5pv210_device_pcm2 = {
263 	.name		  = "samsung-pcm",
264 	.id		  = 2,
265 	.num_resources	  = ARRAY_SIZE(s5pv210_pcm2_resource),
266 	.resource	  = s5pv210_pcm2_resource,
267 	.dev = {
268 		.platform_data = &s3c_pcm_pdata,
269 	},
270 };
271 
272 /* AC97 Controller platform devices */
273 
s5pv210_ac97_cfg_gpio(struct platform_device * pdev)274 static int s5pv210_ac97_cfg_gpio(struct platform_device *pdev)
275 {
276 	return s3c_gpio_cfgpin_range(S5PV210_GPC0(0), 5, S3C_GPIO_SFN(4));
277 }
278 
279 static struct resource s5pv210_ac97_resource[] = {
280 	[0] = {
281 		.start = S5PV210_PA_AC97,
282 		.end   = S5PV210_PA_AC97 + 0x100 - 1,
283 		.flags = IORESOURCE_MEM,
284 	},
285 	[1] = {
286 		.start = DMACH_AC97_PCMOUT,
287 		.end   = DMACH_AC97_PCMOUT,
288 		.flags = IORESOURCE_DMA,
289 	},
290 	[2] = {
291 		.start = DMACH_AC97_PCMIN,
292 		.end   = DMACH_AC97_PCMIN,
293 		.flags = IORESOURCE_DMA,
294 	},
295 	[3] = {
296 		.start = DMACH_AC97_MICIN,
297 		.end   = DMACH_AC97_MICIN,
298 		.flags = IORESOURCE_DMA,
299 	},
300 	[4] = {
301 		.start = IRQ_AC97,
302 		.end   = IRQ_AC97,
303 		.flags = IORESOURCE_IRQ,
304 	},
305 };
306 
307 static struct s3c_audio_pdata s3c_ac97_pdata = {
308 	.cfg_gpio = s5pv210_ac97_cfg_gpio,
309 };
310 
311 static u64 s5pv210_ac97_dmamask = DMA_BIT_MASK(32);
312 
313 struct platform_device s5pv210_device_ac97 = {
314 	.name		  = "samsung-ac97",
315 	.id		  = -1,
316 	.num_resources	  = ARRAY_SIZE(s5pv210_ac97_resource),
317 	.resource	  = s5pv210_ac97_resource,
318 	.dev = {
319 		.platform_data = &s3c_ac97_pdata,
320 		.dma_mask = &s5pv210_ac97_dmamask,
321 		.coherent_dma_mask = DMA_BIT_MASK(32),
322 	},
323 };
324 
325 /* S/PDIF Controller platform_device */
326 
s5pv210_spdif_cfg_gpio(struct platform_device * pdev)327 static int s5pv210_spdif_cfg_gpio(struct platform_device *pdev)
328 {
329 	s3c_gpio_cfgpin_range(S5PV210_GPC1(0), 2, S3C_GPIO_SFN(3));
330 
331 	return 0;
332 }
333 
334 static struct resource s5pv210_spdif_resource[] = {
335 	[0] = {
336 		.start	= S5PV210_PA_SPDIF,
337 		.end	= S5PV210_PA_SPDIF + 0x100 - 1,
338 		.flags	= IORESOURCE_MEM,
339 	},
340 	[1] = {
341 		.start	= DMACH_SPDIF,
342 		.end	= DMACH_SPDIF,
343 		.flags	= IORESOURCE_DMA,
344 	},
345 };
346 
347 static struct s3c_audio_pdata samsung_spdif_pdata = {
348 	.cfg_gpio = s5pv210_spdif_cfg_gpio,
349 };
350 
351 static u64 s5pv210_spdif_dmamask = DMA_BIT_MASK(32);
352 
353 struct platform_device s5pv210_device_spdif = {
354 	.name		= "samsung-spdif",
355 	.id		= -1,
356 	.num_resources	= ARRAY_SIZE(s5pv210_spdif_resource),
357 	.resource	= s5pv210_spdif_resource,
358 	.dev = {
359 		.platform_data = &samsung_spdif_pdata,
360 		.dma_mask = &s5pv210_spdif_dmamask,
361 		.coherent_dma_mask = DMA_BIT_MASK(32),
362 	},
363 };
364