1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // Copyright 2009 Wolfson Microelectronics
4 //      Mark Brown <broonie@opensource.wolfsonmicro.com>
5 
6 #include <linux/kernel.h>
7 #include <linux/string.h>
8 #include <linux/platform_device.h>
9 #include <linux/dma-mapping.h>
10 #include <linux/gpio.h>
11 #include <linux/export.h>
12 
13 #include "irqs.h"
14 #include "map.h"
15 
16 #include "devs.h"
17 #include <linux/platform_data/asoc-s3c.h>
18 #include "gpio-cfg.h"
19 #include "gpio-samsung.h"
20 
21 static int s3c64xx_i2s_cfg_gpio(struct platform_device *pdev)
22 {
23 	unsigned int base;
24 
25 	switch (pdev->id) {
26 	case 0:
27 		base = S3C64XX_GPD(0);
28 		break;
29 	case 1:
30 		base = S3C64XX_GPE(0);
31 		break;
32 	case 2:
33 		s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C_GPIO_SFN(5));
34 		s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C_GPIO_SFN(5));
35 		s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C_GPIO_SFN(5));
36 		s3c_gpio_cfgpin_range(S3C64XX_GPH(6), 4, S3C_GPIO_SFN(5));
37 		return 0;
38 	default:
39 		printk(KERN_DEBUG "Invalid I2S Controller number: %d\n",
40 			pdev->id);
41 		return -EINVAL;
42 	}
43 
44 	s3c_gpio_cfgpin_range(base, 5, S3C_GPIO_SFN(3));
45 
46 	return 0;
47 }
48 
49 static struct resource s3c64xx_iis0_resource[] = {
50 	[0] = DEFINE_RES_MEM(S3C64XX_PA_IIS0, SZ_256),
51 };
52 
53 static struct s3c_audio_pdata i2s0_pdata = {
54 	.cfg_gpio = s3c64xx_i2s_cfg_gpio,
55 };
56 
57 struct platform_device s3c64xx_device_iis0 = {
58 	.name		  = "samsung-i2s",
59 	.id		  = 0,
60 	.num_resources	  = ARRAY_SIZE(s3c64xx_iis0_resource),
61 	.resource	  = s3c64xx_iis0_resource,
62 	.dev = {
63 		.platform_data = &i2s0_pdata,
64 	},
65 };
66 EXPORT_SYMBOL(s3c64xx_device_iis0);
67 
68 static struct resource s3c64xx_iis1_resource[] = {
69 	[0] = DEFINE_RES_MEM(S3C64XX_PA_IIS1, SZ_256),
70 };
71 
72 static struct s3c_audio_pdata i2s1_pdata = {
73 	.cfg_gpio = s3c64xx_i2s_cfg_gpio,
74 };
75 
76 struct platform_device s3c64xx_device_iis1 = {
77 	.name		  = "samsung-i2s",
78 	.id		  = 1,
79 	.num_resources	  = ARRAY_SIZE(s3c64xx_iis1_resource),
80 	.resource	  = s3c64xx_iis1_resource,
81 	.dev = {
82 		.platform_data = &i2s1_pdata,
83 	},
84 };
85 EXPORT_SYMBOL(s3c64xx_device_iis1);
86 
87 static struct resource s3c64xx_iisv4_resource[] = {
88 	[0] = DEFINE_RES_MEM(S3C64XX_PA_IISV4, SZ_256),
89 };
90 
91 static struct s3c_audio_pdata i2sv4_pdata = {
92 	.cfg_gpio = s3c64xx_i2s_cfg_gpio,
93 	.type = {
94 		.quirks = QUIRK_PRI_6CHAN,
95 	},
96 };
97 
98 struct platform_device s3c64xx_device_iisv4 = {
99 	.name = "samsung-i2s",
100 	.id = 2,
101 	.num_resources	  = ARRAY_SIZE(s3c64xx_iisv4_resource),
102 	.resource	  = s3c64xx_iisv4_resource,
103 	.dev = {
104 		.platform_data = &i2sv4_pdata,
105 	},
106 };
107 EXPORT_SYMBOL(s3c64xx_device_iisv4);
108 
109 
110 /* PCM Controller platform_devices */
111 
112 static int s3c64xx_pcm_cfg_gpio(struct platform_device *pdev)
113 {
114 	unsigned int base;
115 
116 	switch (pdev->id) {
117 	case 0:
118 		base = S3C64XX_GPD(0);
119 		break;
120 	case 1:
121 		base = S3C64XX_GPE(0);
122 		break;
123 	default:
124 		printk(KERN_DEBUG "Invalid PCM Controller number: %d\n",
125 			pdev->id);
126 		return -EINVAL;
127 	}
128 
129 	s3c_gpio_cfgpin_range(base, 5, S3C_GPIO_SFN(2));
130 	return 0;
131 }
132 
133 static struct resource s3c64xx_pcm0_resource[] = {
134 	[0] = DEFINE_RES_MEM(S3C64XX_PA_PCM0, SZ_256),
135 };
136 
137 static struct s3c_audio_pdata s3c_pcm0_pdata = {
138 	.cfg_gpio = s3c64xx_pcm_cfg_gpio,
139 };
140 
141 struct platform_device s3c64xx_device_pcm0 = {
142 	.name		  = "samsung-pcm",
143 	.id		  = 0,
144 	.num_resources	  = ARRAY_SIZE(s3c64xx_pcm0_resource),
145 	.resource	  = s3c64xx_pcm0_resource,
146 	.dev = {
147 		.platform_data = &s3c_pcm0_pdata,
148 	},
149 };
150 EXPORT_SYMBOL(s3c64xx_device_pcm0);
151 
152 static struct resource s3c64xx_pcm1_resource[] = {
153 	[0] = DEFINE_RES_MEM(S3C64XX_PA_PCM1, SZ_256),
154 };
155 
156 static struct s3c_audio_pdata s3c_pcm1_pdata = {
157 	.cfg_gpio = s3c64xx_pcm_cfg_gpio,
158 };
159 
160 struct platform_device s3c64xx_device_pcm1 = {
161 	.name		  = "samsung-pcm",
162 	.id		  = 1,
163 	.num_resources	  = ARRAY_SIZE(s3c64xx_pcm1_resource),
164 	.resource	  = s3c64xx_pcm1_resource,
165 	.dev = {
166 		.platform_data = &s3c_pcm1_pdata,
167 	},
168 };
169 EXPORT_SYMBOL(s3c64xx_device_pcm1);
170 
171 /* AC97 Controller platform devices */
172 
173 static int s3c64xx_ac97_cfg_gpd(struct platform_device *pdev)
174 {
175 	return s3c_gpio_cfgpin_range(S3C64XX_GPD(0), 5, S3C_GPIO_SFN(4));
176 }
177 
178 static int s3c64xx_ac97_cfg_gpe(struct platform_device *pdev)
179 {
180 	return s3c_gpio_cfgpin_range(S3C64XX_GPE(0), 5, S3C_GPIO_SFN(4));
181 }
182 
183 static struct resource s3c64xx_ac97_resource[] = {
184 	[0] = DEFINE_RES_MEM(S3C64XX_PA_AC97, SZ_256),
185 	[1] = DEFINE_RES_IRQ(IRQ_AC97),
186 };
187 
188 static struct s3c_audio_pdata s3c_ac97_pdata = {
189 };
190 
191 static u64 s3c64xx_ac97_dmamask = DMA_BIT_MASK(32);
192 
193 struct platform_device s3c64xx_device_ac97 = {
194 	.name		  = "samsung-ac97",
195 	.id		  = -1,
196 	.num_resources	  = ARRAY_SIZE(s3c64xx_ac97_resource),
197 	.resource	  = s3c64xx_ac97_resource,
198 	.dev = {
199 		.platform_data = &s3c_ac97_pdata,
200 		.dma_mask = &s3c64xx_ac97_dmamask,
201 		.coherent_dma_mask = DMA_BIT_MASK(32),
202 	},
203 };
204 EXPORT_SYMBOL(s3c64xx_device_ac97);
205 
206 void __init s3c64xx_ac97_setup_gpio(int num)
207 {
208 	if (num == S3C64XX_AC97_GPD)
209 		s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpd;
210 	else
211 		s3c_ac97_pdata.cfg_gpio = s3c64xx_ac97_cfg_gpe;
212 }
213