blob: 4325b93940a981621e7f1703348c8baafef58e69 [file] [log] [blame]
Kukjin Kim95af2142011-12-22 23:28:28 +01001/*
2 * Copyright (c) 2009-2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com
4 *
5 * Common Codes for S5P64X0 machines
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/types.h>
14#include <linux/interrupt.h>
15#include <linux/list.h>
16#include <linux/timer.h>
17#include <linux/init.h>
18#include <linux/clk.h>
19#include <linux/io.h>
Linus Torvalds7affca32012-01-07 12:03:30 -080020#include <linux/device.h>
Kukjin Kim95af2142011-12-22 23:28:28 +010021#include <linux/serial_core.h>
22#include <linux/platform_device.h>
23#include <linux/sched.h>
24#include <linux/dma-mapping.h>
25#include <linux/gpio.h>
26#include <linux/irq.h>
27
28#include <asm/irq.h>
29#include <asm/proc-fns.h>
David Howells9f97da72012-03-28 18:30:01 +010030#include <asm/system_misc.h>
Kukjin Kim95af2142011-12-22 23:28:28 +010031#include <asm/mach/arch.h>
32#include <asm/mach/map.h>
33#include <asm/mach/irq.h>
34
35#include <mach/map.h>
36#include <mach/hardware.h>
37#include <mach/regs-clock.h>
38#include <mach/regs-gpio.h>
39
40#include <plat/cpu.h>
41#include <plat/clock.h>
42#include <plat/devs.h>
43#include <plat/pm.h>
Arnd Bergmann142f2102012-01-09 16:14:07 +000044#include <plat/sdhci.h>
Kukjin Kim95af2142011-12-22 23:28:28 +010045#include <plat/adc-core.h>
46#include <plat/fb-core.h>
47#include <plat/gpio-cfg.h>
48#include <plat/regs-irqtype.h>
49#include <plat/regs-serial.h>
Kukjin Kim73aed8b2011-12-22 23:34:25 +010050#include <plat/watchdog-reset.h>
Kukjin Kim95af2142011-12-22 23:28:28 +010051
52#include "common.h"
53
54static const char name_s5p6440[] = "S5P6440";
55static const char name_s5p6450[] = "S5P6450";
56
57static struct cpu_table cpu_ids[] __initdata = {
58 {
59 .idcode = S5P6440_CPU_ID,
60 .idmask = S5P64XX_CPU_MASK,
61 .map_io = s5p6440_map_io,
62 .init_clocks = s5p6440_init_clocks,
63 .init_uarts = s5p6440_init_uarts,
64 .init = s5p64x0_init,
65 .name = name_s5p6440,
66 }, {
67 .idcode = S5P6450_CPU_ID,
68 .idmask = S5P64XX_CPU_MASK,
69 .map_io = s5p6450_map_io,
70 .init_clocks = s5p6450_init_clocks,
71 .init_uarts = s5p6450_init_uarts,
72 .init = s5p64x0_init,
73 .name = name_s5p6450,
74 },
75};
76
77/* Initial IO mappings */
78
79static struct map_desc s5p64x0_iodesc[] __initdata = {
80 {
81 .virtual = (unsigned long)S5P_VA_CHIPID,
82 .pfn = __phys_to_pfn(S5P64X0_PA_CHIPID),
83 .length = SZ_4K,
84 .type = MT_DEVICE,
85 }, {
86 .virtual = (unsigned long)S3C_VA_SYS,
87 .pfn = __phys_to_pfn(S5P64X0_PA_SYSCON),
88 .length = SZ_64K,
89 .type = MT_DEVICE,
90 }, {
91 .virtual = (unsigned long)S3C_VA_TIMER,
92 .pfn = __phys_to_pfn(S5P64X0_PA_TIMER),
93 .length = SZ_16K,
94 .type = MT_DEVICE,
95 }, {
96 .virtual = (unsigned long)S3C_VA_WATCHDOG,
97 .pfn = __phys_to_pfn(S5P64X0_PA_WDT),
98 .length = SZ_4K,
99 .type = MT_DEVICE,
100 }, {
101 .virtual = (unsigned long)S5P_VA_SROMC,
102 .pfn = __phys_to_pfn(S5P64X0_PA_SROMC),
103 .length = SZ_4K,
104 .type = MT_DEVICE,
105 }, {
106 .virtual = (unsigned long)S5P_VA_GPIO,
107 .pfn = __phys_to_pfn(S5P64X0_PA_GPIO),
108 .length = SZ_4K,
109 .type = MT_DEVICE,
110 }, {
111 .virtual = (unsigned long)VA_VIC0,
112 .pfn = __phys_to_pfn(S5P64X0_PA_VIC0),
113 .length = SZ_16K,
114 .type = MT_DEVICE,
115 }, {
116 .virtual = (unsigned long)VA_VIC1,
117 .pfn = __phys_to_pfn(S5P64X0_PA_VIC1),
118 .length = SZ_16K,
119 .type = MT_DEVICE,
120 },
121};
122
123static struct map_desc s5p6440_iodesc[] __initdata = {
124 {
125 .virtual = (unsigned long)S3C_VA_UART,
126 .pfn = __phys_to_pfn(S5P6440_PA_UART(0)),
127 .length = SZ_4K,
128 .type = MT_DEVICE,
129 },
130};
131
132static struct map_desc s5p6450_iodesc[] __initdata = {
133 {
134 .virtual = (unsigned long)S3C_VA_UART,
135 .pfn = __phys_to_pfn(S5P6450_PA_UART(0)),
136 .length = SZ_512K,
137 .type = MT_DEVICE,
138 }, {
139 .virtual = (unsigned long)S3C_VA_UART + SZ_512K,
140 .pfn = __phys_to_pfn(S5P6450_PA_UART(5)),
141 .length = SZ_4K,
142 .type = MT_DEVICE,
143 },
144};
145
146static void s5p64x0_idle(void)
147{
148 unsigned long val;
149
150 if (!need_resched()) {
151 val = __raw_readl(S5P64X0_PWR_CFG);
152 val &= ~(0x3 << 5);
153 val |= (0x1 << 5);
154 __raw_writel(val, S5P64X0_PWR_CFG);
155
156 cpu_do_idle();
157 }
158 local_irq_enable();
159}
160
161/*
162 * s5p64x0_map_io
163 *
164 * register the standard CPU IO areas
165 */
166
167void __init s5p64x0_init_io(struct map_desc *mach_desc, int size)
168{
169 /* initialize the io descriptors we need for initialization */
170 iotable_init(s5p64x0_iodesc, ARRAY_SIZE(s5p64x0_iodesc));
171 if (mach_desc)
172 iotable_init(mach_desc, size);
173
174 /* detect cpu id and rev. */
175 s5p_init_cpu(S5P64X0_SYS_ID);
176
177 s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids));
178}
179
180void __init s5p6440_map_io(void)
181{
182 /* initialize any device information early */
183 s3c_adc_setname("s3c64xx-adc");
184 s3c_fb_setname("s5p64x0-fb");
185
Arnd Bergmann142f2102012-01-09 16:14:07 +0000186 s5p64x0_default_sdhci0();
187 s5p64x0_default_sdhci1();
188 s5p6440_default_sdhci2();
189
Kukjin Kim95af2142011-12-22 23:28:28 +0100190 iotable_init(s5p6440_iodesc, ARRAY_SIZE(s5p6440_iodesc));
191 init_consistent_dma_size(SZ_8M);
192}
193
194void __init s5p6450_map_io(void)
195{
196 /* initialize any device information early */
197 s3c_adc_setname("s3c64xx-adc");
198 s3c_fb_setname("s5p64x0-fb");
199
Arnd Bergmann142f2102012-01-09 16:14:07 +0000200 s5p64x0_default_sdhci0();
201 s5p64x0_default_sdhci1();
202 s5p6450_default_sdhci2();
203
Kukjin Kim95af2142011-12-22 23:28:28 +0100204 iotable_init(s5p6450_iodesc, ARRAY_SIZE(s5p6450_iodesc));
205 init_consistent_dma_size(SZ_8M);
206}
207
208/*
209 * s5p64x0_init_clocks
210 *
211 * register and setup the CPU clocks
212 */
213
214void __init s5p6440_init_clocks(int xtal)
215{
216 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
217
218 s3c24xx_register_baseclocks(xtal);
219 s5p_register_clocks(xtal);
220 s5p6440_register_clocks();
221 s5p6440_setup_clocks();
222}
223
224void __init s5p6450_init_clocks(int xtal)
225{
226 printk(KERN_DEBUG "%s: initializing clocks\n", __func__);
227
228 s3c24xx_register_baseclocks(xtal);
229 s5p_register_clocks(xtal);
230 s5p6450_register_clocks();
231 s5p6450_setup_clocks();
232}
233
234/*
235 * s5p64x0_init_irq
236 *
237 * register the CPU interrupts
238 */
239
240void __init s5p6440_init_irq(void)
241{
242 /* S5P6440 supports 2 VIC */
243 u32 vic[2];
244
245 /*
246 * VIC0 is missing IRQ_VIC0[3, 4, 8, 10, (12-22)]
247 * VIC1 is missing IRQ VIC1[1, 3, 4, 10, 11, 12, 14, 15, 22]
248 */
249 vic[0] = 0xff800ae7;
250 vic[1] = 0xffbf23e5;
251
252 s5p_init_irq(vic, ARRAY_SIZE(vic));
253}
254
255void __init s5p6450_init_irq(void)
256{
257 /* S5P6450 supports only 2 VIC */
258 u32 vic[2];
259
260 /*
261 * VIC0 is missing IRQ_VIC0[(13-15), (21-22)]
262 * VIC1 is missing IRQ VIC1[12, 14, 23]
263 */
264 vic[0] = 0xff9f1fff;
265 vic[1] = 0xff7fafff;
266
267 s5p_init_irq(vic, ARRAY_SIZE(vic));
268}
269
Linus Torvalds7affca32012-01-07 12:03:30 -0800270struct bus_type s5p64x0_subsys = {
271 .name = "s5p64x0-core",
272 .dev_name = "s5p64x0-core",
Kukjin Kim95af2142011-12-22 23:28:28 +0100273};
274
Linus Torvalds7affca32012-01-07 12:03:30 -0800275static struct device s5p64x0_dev = {
276 .bus = &s5p64x0_subsys,
Kukjin Kim95af2142011-12-22 23:28:28 +0100277};
278
279static int __init s5p64x0_core_init(void)
280{
Linus Torvalds7affca32012-01-07 12:03:30 -0800281 return subsys_system_register(&s5p64x0_subsys, NULL);
Kukjin Kim95af2142011-12-22 23:28:28 +0100282}
283core_initcall(s5p64x0_core_init);
284
285int __init s5p64x0_init(void)
286{
287 printk(KERN_INFO "S5P64X0(S5P6440/S5P6450): Initializing architecture\n");
288
289 /* set idle function */
290 pm_idle = s5p64x0_idle;
291
Linus Torvalds7affca32012-01-07 12:03:30 -0800292 return device_register(&s5p64x0_dev);
Kukjin Kim95af2142011-12-22 23:28:28 +0100293}
294
Kukjin Kim95af2142011-12-22 23:28:28 +0100295/* uart registration process */
Kukjin Kim95af2142011-12-22 23:28:28 +0100296void __init s5p6440_init_uarts(struct s3c2410_uartcfg *cfg, int no)
297{
298 int uart;
299
300 for (uart = 0; uart < no; uart++) {
301 s5p_uart_resources[uart].resources->start = S5P6440_PA_UART(uart);
302 s5p_uart_resources[uart].resources->end = S5P6440_PA_UART(uart) + S5P_SZ_UART;
303 }
304
Kukjin Kim95af2142011-12-22 23:28:28 +0100305 s3c24xx_init_uartdevs("s3c6400-uart", s5p_uart_resources, cfg, no);
306}
307
308void __init s5p6450_init_uarts(struct s3c2410_uartcfg *cfg, int no)
309{
Kukjin Kim95af2142011-12-22 23:28:28 +0100310 s3c24xx_init_uartdevs("s3c6400-uart", s5p_uart_resources, cfg, no);
311}
312
313#define eint_offset(irq) ((irq) - IRQ_EINT(0))
314
315static int s5p64x0_irq_eint_set_type(struct irq_data *data, unsigned int type)
316{
317 int offs = eint_offset(data->irq);
318 int shift;
319 u32 ctrl, mask;
320 u32 newvalue = 0;
321
322 if (offs > 15)
323 return -EINVAL;
324
325 switch (type) {
326 case IRQ_TYPE_NONE:
327 printk(KERN_WARNING "No edge setting!\n");
328 break;
329 case IRQ_TYPE_EDGE_RISING:
330 newvalue = S3C2410_EXTINT_RISEEDGE;
331 break;
332 case IRQ_TYPE_EDGE_FALLING:
333 newvalue = S3C2410_EXTINT_FALLEDGE;
334 break;
335 case IRQ_TYPE_EDGE_BOTH:
336 newvalue = S3C2410_EXTINT_BOTHEDGE;
337 break;
338 case IRQ_TYPE_LEVEL_LOW:
339 newvalue = S3C2410_EXTINT_LOWLEV;
340 break;
341 case IRQ_TYPE_LEVEL_HIGH:
342 newvalue = S3C2410_EXTINT_HILEV;
343 break;
344 default:
345 printk(KERN_ERR "No such irq type %d", type);
346 return -EINVAL;
347 }
348
349 shift = (offs / 2) * 4;
350 mask = 0x7 << shift;
351
352 ctrl = __raw_readl(S5P64X0_EINT0CON0) & ~mask;
353 ctrl |= newvalue << shift;
354 __raw_writel(ctrl, S5P64X0_EINT0CON0);
355
356 /* Configure the GPIO pin for 6450 or 6440 based on CPU ID */
357 if (soc_is_s5p6450())
358 s3c_gpio_cfgpin(S5P6450_GPN(offs), S3C_GPIO_SFN(2));
359 else
360 s3c_gpio_cfgpin(S5P6440_GPN(offs), S3C_GPIO_SFN(2));
361
362 return 0;
363}
364
365/*
366 * s5p64x0_irq_demux_eint
367 *
368 * This function demuxes the IRQ from the group0 external interrupts,
369 * from IRQ_EINT(0) to IRQ_EINT(15). It is designed to be inlined into
370 * the specific handlers s5p64x0_irq_demux_eintX_Y.
371 */
372static inline void s5p64x0_irq_demux_eint(unsigned int start, unsigned int end)
373{
374 u32 status = __raw_readl(S5P64X0_EINT0PEND);
375 u32 mask = __raw_readl(S5P64X0_EINT0MASK);
376 unsigned int irq;
377
378 status &= ~mask;
379 status >>= start;
380 status &= (1 << (end - start + 1)) - 1;
381
382 for (irq = IRQ_EINT(start); irq <= IRQ_EINT(end); irq++) {
383 if (status & 1)
384 generic_handle_irq(irq);
385 status >>= 1;
386 }
387}
388
389static void s5p64x0_irq_demux_eint0_3(unsigned int irq, struct irq_desc *desc)
390{
391 s5p64x0_irq_demux_eint(0, 3);
392}
393
394static void s5p64x0_irq_demux_eint4_11(unsigned int irq, struct irq_desc *desc)
395{
396 s5p64x0_irq_demux_eint(4, 11);
397}
398
399static void s5p64x0_irq_demux_eint12_15(unsigned int irq,
400 struct irq_desc *desc)
401{
402 s5p64x0_irq_demux_eint(12, 15);
403}
404
405static int s5p64x0_alloc_gc(void)
406{
407 struct irq_chip_generic *gc;
408 struct irq_chip_type *ct;
409
410 gc = irq_alloc_generic_chip("s5p64x0-eint", 1, S5P_IRQ_EINT_BASE,
411 S5P_VA_GPIO, handle_level_irq);
412 if (!gc) {
413 printk(KERN_ERR "%s: irq_alloc_generic_chip for group 0"
414 "external interrupts failed\n", __func__);
415 return -EINVAL;
416 }
417
418 ct = gc->chip_types;
419 ct->chip.irq_ack = irq_gc_ack_set_bit;
420 ct->chip.irq_mask = irq_gc_mask_set_bit;
421 ct->chip.irq_unmask = irq_gc_mask_clr_bit;
422 ct->chip.irq_set_type = s5p64x0_irq_eint_set_type;
423 ct->chip.irq_set_wake = s3c_irqext_wake;
424 ct->regs.ack = EINT0PEND_OFFSET;
425 ct->regs.mask = EINT0MASK_OFFSET;
426 irq_setup_generic_chip(gc, IRQ_MSK(16), IRQ_GC_INIT_MASK_CACHE,
427 IRQ_NOREQUEST | IRQ_NOPROBE, 0);
428 return 0;
429}
430
431static int __init s5p64x0_init_irq_eint(void)
432{
433 int ret = s5p64x0_alloc_gc();
434 irq_set_chained_handler(IRQ_EINT0_3, s5p64x0_irq_demux_eint0_3);
435 irq_set_chained_handler(IRQ_EINT4_11, s5p64x0_irq_demux_eint4_11);
436 irq_set_chained_handler(IRQ_EINT12_15, s5p64x0_irq_demux_eint12_15);
437
438 return ret;
439}
440arch_initcall(s5p64x0_init_irq_eint);
Kukjin Kim73aed8b2011-12-22 23:34:25 +0100441
442void s5p64x0_restart(char mode, const char *cmd)
443{
444 if (mode != 's')
445 arch_wdt_reset();
446
447 soft_restart(0);
448}