1 /*
2  * Emma Mobile EV2 processor support
3  *
4  * Copyright (C) 2012  Magnus Damm
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 as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
23 #include <linux/platform_device.h>
24 #include <linux/platform_data/gpio-em.h>
25 #include <linux/of_platform.h>
26 #include <linux/delay.h>
27 #include <linux/input.h>
28 #include <linux/io.h>
29 #include <linux/irqchip/arm-gic.h>
30 #include <mach/hardware.h>
31 #include <mach/common.h>
32 #include <mach/emev2.h>
33 #include <mach/irqs.h>
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37 #include <asm/mach/time.h>
38 
39 static struct map_desc emev2_io_desc[] __initdata = {
40 #ifdef CONFIG_SMP
41 	/* 128K entity map for 0xe0100000 (SMU) */
42 	{
43 		.virtual	= 0xe0100000,
44 		.pfn		= __phys_to_pfn(0xe0100000),
45 		.length		= SZ_128K,
46 		.type		= MT_DEVICE
47 	},
48 	/* 2M mapping for SCU + L2 controller */
49 	{
50 		.virtual	= 0xf0000000,
51 		.pfn		= __phys_to_pfn(0x1e000000),
52 		.length		= SZ_2M,
53 		.type		= MT_DEVICE
54 	},
55 #endif
56 };
57 
58 void __init emev2_map_io(void)
59 {
60 	iotable_init(emev2_io_desc, ARRAY_SIZE(emev2_io_desc));
61 }
62 
63 /* UART */
64 static struct resource uart0_resources[] = {
65 	[0]	= {
66 		.start	= 0xe1020000,
67 		.end	= 0xe1020037,
68 		.flags	= IORESOURCE_MEM,
69 	},
70 	[1]	= {
71 		.start	= 40,
72 		.flags	= IORESOURCE_IRQ,
73 	}
74 };
75 
76 static struct platform_device uart0_device = {
77 	.name		= "serial8250-em",
78 	.id		= 0,
79 	.num_resources	= ARRAY_SIZE(uart0_resources),
80 	.resource	= uart0_resources,
81 };
82 
83 static struct resource uart1_resources[] = {
84 	[0]	= {
85 		.start	= 0xe1030000,
86 		.end	= 0xe1030037,
87 		.flags	= IORESOURCE_MEM,
88 	},
89 	[1]	= {
90 		.start	= 41,
91 		.flags	= IORESOURCE_IRQ,
92 	}
93 };
94 
95 static struct platform_device uart1_device = {
96 	.name		= "serial8250-em",
97 	.id		= 1,
98 	.num_resources	= ARRAY_SIZE(uart1_resources),
99 	.resource	= uart1_resources,
100 };
101 
102 static struct resource uart2_resources[] = {
103 	[0]	= {
104 		.start	= 0xe1040000,
105 		.end	= 0xe1040037,
106 		.flags	= IORESOURCE_MEM,
107 	},
108 	[1]	= {
109 		.start	= 42,
110 		.flags	= IORESOURCE_IRQ,
111 	}
112 };
113 
114 static struct platform_device uart2_device = {
115 	.name		= "serial8250-em",
116 	.id		= 2,
117 	.num_resources	= ARRAY_SIZE(uart2_resources),
118 	.resource	= uart2_resources,
119 };
120 
121 static struct resource uart3_resources[] = {
122 	[0]	= {
123 		.start	= 0xe1050000,
124 		.end	= 0xe1050037,
125 		.flags	= IORESOURCE_MEM,
126 	},
127 	[1]	= {
128 		.start	= 43,
129 		.flags	= IORESOURCE_IRQ,
130 	}
131 };
132 
133 static struct platform_device uart3_device = {
134 	.name		= "serial8250-em",
135 	.id		= 3,
136 	.num_resources	= ARRAY_SIZE(uart3_resources),
137 	.resource	= uart3_resources,
138 };
139 
140 /* STI */
141 static struct resource sti_resources[] = {
142 	[0] = {
143 		.name	= "STI",
144 		.start	= 0xe0180000,
145 		.end	= 0xe0180053,
146 		.flags	= IORESOURCE_MEM,
147 	},
148 	[1] = {
149 		.start	= 157,
150 		.flags	= IORESOURCE_IRQ,
151 	},
152 };
153 
154 static struct platform_device sti_device = {
155 	.name		= "em_sti",
156 	.id		= 0,
157 	.resource	= sti_resources,
158 	.num_resources	= ARRAY_SIZE(sti_resources),
159 };
160 
161 
162 /* GIO */
163 static struct gpio_em_config gio0_config = {
164 	.gpio_base = 0,
165 	.irq_base = EMEV2_GPIO_IRQ(0),
166 	.number_of_pins = 32,
167 };
168 
169 static struct resource gio0_resources[] = {
170 	[0] = {
171 		.name	= "GIO_000",
172 		.start	= 0xe0050000,
173 		.end	= 0xe005002b,
174 		.flags	= IORESOURCE_MEM,
175 	},
176 	[1] = {
177 		.name	= "GIO_000",
178 		.start	= 0xe0050040,
179 		.end	= 0xe005005f,
180 		.flags	= IORESOURCE_MEM,
181 	},
182 	[2] = {
183 		.start	= 99,
184 		.flags	= IORESOURCE_IRQ,
185 	},
186 	[3] = {
187 		.start	= 100,
188 		.flags	= IORESOURCE_IRQ,
189 	},
190 };
191 
192 static struct platform_device gio0_device = {
193 	.name		= "em_gio",
194 	.id		= 0,
195 	.resource	= gio0_resources,
196 	.num_resources	= ARRAY_SIZE(gio0_resources),
197 	.dev		= {
198 		.platform_data	= &gio0_config,
199 	},
200 };
201 
202 static struct gpio_em_config gio1_config = {
203 	.gpio_base = 32,
204 	.irq_base = EMEV2_GPIO_IRQ(32),
205 	.number_of_pins = 32,
206 };
207 
208 static struct resource gio1_resources[] = {
209 	[0] = {
210 		.name	= "GIO_032",
211 		.start	= 0xe0050080,
212 		.end	= 0xe00500ab,
213 		.flags	= IORESOURCE_MEM,
214 	},
215 	[1] = {
216 		.name	= "GIO_032",
217 		.start	= 0xe00500c0,
218 		.end	= 0xe00500df,
219 		.flags	= IORESOURCE_MEM,
220 	},
221 	[2] = {
222 		.start	= 101,
223 		.flags	= IORESOURCE_IRQ,
224 	},
225 	[3] = {
226 		.start	= 102,
227 		.flags	= IORESOURCE_IRQ,
228 	},
229 };
230 
231 static struct platform_device gio1_device = {
232 	.name		= "em_gio",
233 	.id		= 1,
234 	.resource	= gio1_resources,
235 	.num_resources	= ARRAY_SIZE(gio1_resources),
236 	.dev		= {
237 		.platform_data	= &gio1_config,
238 	},
239 };
240 
241 static struct gpio_em_config gio2_config = {
242 	.gpio_base = 64,
243 	.irq_base = EMEV2_GPIO_IRQ(64),
244 	.number_of_pins = 32,
245 };
246 
247 static struct resource gio2_resources[] = {
248 	[0] = {
249 		.name	= "GIO_064",
250 		.start	= 0xe0050100,
251 		.end	= 0xe005012b,
252 		.flags	= IORESOURCE_MEM,
253 	},
254 	[1] = {
255 		.name	= "GIO_064",
256 		.start	= 0xe0050140,
257 		.end	= 0xe005015f,
258 		.flags	= IORESOURCE_MEM,
259 	},
260 	[2] = {
261 		.start	= 103,
262 		.flags	= IORESOURCE_IRQ,
263 	},
264 	[3] = {
265 		.start	= 104,
266 		.flags	= IORESOURCE_IRQ,
267 	},
268 };
269 
270 static struct platform_device gio2_device = {
271 	.name		= "em_gio",
272 	.id		= 2,
273 	.resource	= gio2_resources,
274 	.num_resources	= ARRAY_SIZE(gio2_resources),
275 	.dev		= {
276 		.platform_data	= &gio2_config,
277 	},
278 };
279 
280 static struct gpio_em_config gio3_config = {
281 	.gpio_base = 96,
282 	.irq_base = EMEV2_GPIO_IRQ(96),
283 	.number_of_pins = 32,
284 };
285 
286 static struct resource gio3_resources[] = {
287 	[0] = {
288 		.name	= "GIO_096",
289 		.start	= 0xe0050180,
290 		.end	= 0xe00501ab,
291 		.flags	= IORESOURCE_MEM,
292 	},
293 	[1] = {
294 		.name	= "GIO_096",
295 		.start	= 0xe00501c0,
296 		.end	= 0xe00501df,
297 		.flags	= IORESOURCE_MEM,
298 	},
299 	[2] = {
300 		.start	= 105,
301 		.flags	= IORESOURCE_IRQ,
302 	},
303 	[3] = {
304 		.start	= 106,
305 		.flags	= IORESOURCE_IRQ,
306 	},
307 };
308 
309 static struct platform_device gio3_device = {
310 	.name		= "em_gio",
311 	.id		= 3,
312 	.resource	= gio3_resources,
313 	.num_resources	= ARRAY_SIZE(gio3_resources),
314 	.dev		= {
315 		.platform_data	= &gio3_config,
316 	},
317 };
318 
319 static struct gpio_em_config gio4_config = {
320 	.gpio_base = 128,
321 	.irq_base = EMEV2_GPIO_IRQ(128),
322 	.number_of_pins = 31,
323 };
324 
325 static struct resource gio4_resources[] = {
326 	[0] = {
327 		.name	= "GIO_128",
328 		.start	= 0xe0050200,
329 		.end	= 0xe005022b,
330 		.flags	= IORESOURCE_MEM,
331 	},
332 	[1] = {
333 		.name	= "GIO_128",
334 		.start	= 0xe0050240,
335 		.end	= 0xe005025f,
336 		.flags	= IORESOURCE_MEM,
337 	},
338 	[2] = {
339 		.start	= 107,
340 		.flags	= IORESOURCE_IRQ,
341 	},
342 	[3] = {
343 		.start	= 108,
344 		.flags	= IORESOURCE_IRQ,
345 	},
346 };
347 
348 static struct platform_device gio4_device = {
349 	.name		= "em_gio",
350 	.id		= 4,
351 	.resource	= gio4_resources,
352 	.num_resources	= ARRAY_SIZE(gio4_resources),
353 	.dev		= {
354 		.platform_data	= &gio4_config,
355 	},
356 };
357 
358 static struct resource pmu_resources[] = {
359 	[0] = {
360 		.start	= 152,
361 		.end	= 152,
362 		.flags	= IORESOURCE_IRQ,
363 	},
364 	[1] = {
365 		.start	= 153,
366 		.end	= 153,
367 		.flags	= IORESOURCE_IRQ,
368 	},
369 };
370 
371 static struct platform_device pmu_device = {
372 	.name		= "arm-pmu",
373 	.id		= -1,
374 	.num_resources	= ARRAY_SIZE(pmu_resources),
375 	.resource	= pmu_resources,
376 };
377 
378 static struct platform_device *emev2_early_devices[] __initdata = {
379 	&uart0_device,
380 	&uart1_device,
381 	&uart2_device,
382 	&uart3_device,
383 };
384 
385 static struct platform_device *emev2_late_devices[] __initdata = {
386 	&sti_device,
387 	&gio0_device,
388 	&gio1_device,
389 	&gio2_device,
390 	&gio3_device,
391 	&gio4_device,
392 	&pmu_device,
393 };
394 
395 void __init emev2_add_standard_devices(void)
396 {
397 	emev2_clock_init();
398 
399 	platform_add_devices(emev2_early_devices,
400 			     ARRAY_SIZE(emev2_early_devices));
401 
402 	platform_add_devices(emev2_late_devices,
403 			     ARRAY_SIZE(emev2_late_devices));
404 }
405 
406 static void __init emev2_init_delay(void)
407 {
408 	shmobile_setup_delay(533, 1, 3); /* Cortex-A9 @ 533MHz */
409 }
410 
411 void __init emev2_add_early_devices(void)
412 {
413 	emev2_init_delay();
414 
415 	early_platform_add_devices(emev2_early_devices,
416 				   ARRAY_SIZE(emev2_early_devices));
417 
418 	/* setup early console here as well */
419 	shmobile_setup_console();
420 }
421 
422 void __init emev2_init_irq(void)
423 {
424 	void __iomem *gic_dist_base;
425 	void __iomem *gic_cpu_base;
426 
427 	/* Static mappings, never released */
428 	gic_dist_base = ioremap(0xe0028000, PAGE_SIZE);
429 	gic_cpu_base = ioremap(0xe0020000, PAGE_SIZE);
430 	BUG_ON(!gic_dist_base || !gic_cpu_base);
431 
432 	/* Use GIC to handle interrupts */
433 	gic_init(0, 29, gic_dist_base, gic_cpu_base);
434 }
435 
436 #ifdef CONFIG_USE_OF
437 
438 static const char *emev2_boards_compat_dt[] __initdata = {
439 	"renesas,emev2",
440 	NULL,
441 };
442 
443 DT_MACHINE_START(EMEV2_DT, "Generic Emma Mobile EV2 (Flattened Device Tree)")
444 	.smp		= smp_ops(emev2_smp_ops),
445 	.init_early	= emev2_init_delay,
446 	.nr_irqs	= NR_IRQS_LEGACY,
447 	.dt_compat	= emev2_boards_compat_dt,
448 MACHINE_END
449 
450 #endif /* CONFIG_USE_OF */
451