Commit | Line | Data |
---|---|---|
b024043b KK |
1 | /* |
2 | * Copyright (c) 2011 Samsung Electronics Co., Ltd. | |
3 | * http://www.samsung.com | |
80789e79 BD |
4 | * |
5 | * Copyright 2008 Openmoko, Inc. | |
6 | * Copyright 2008 Simtec Electronics | |
b024043b KK |
7 | * Ben Dooks <ben@simtec.co.uk> |
8 | * http://armlinux.simtec.co.uk/ | |
80789e79 | 9 | * |
b024043b | 10 | * Common Codes for S3C64XX machines |
80789e79 BD |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License version 2 as | |
14 | * published by the Free Software Foundation. | |
15 | */ | |
16 | ||
17 | #include <linux/kernel.h> | |
b024043b KK |
18 | #include <linux/init.h> |
19 | #include <linux/module.h> | |
80789e79 | 20 | #include <linux/interrupt.h> |
b024043b | 21 | #include <linux/ioport.h> |
b024043b KK |
22 | #include <linux/serial_core.h> |
23 | #include <linux/platform_device.h> | |
80789e79 | 24 | #include <linux/io.h> |
b024043b KK |
25 | #include <linux/dma-mapping.h> |
26 | #include <linux/irq.h> | |
27 | #include <linux/gpio.h> | |
9e47b8bf | 28 | #include <linux/irqchip/arm-vic.h> |
80789e79 | 29 | |
b024043b KK |
30 | #include <asm/mach/arch.h> |
31 | #include <asm/mach/map.h> | |
9f97da78 | 32 | #include <asm/system_misc.h> |
80789e79 | 33 | |
b024043b KK |
34 | #include <mach/map.h> |
35 | #include <mach/hardware.h> | |
3501c9ae | 36 | #include <mach/regs-gpio.h> |
80789e79 | 37 | |
80789e79 | 38 | #include <plat/cpu.h> |
b024043b KK |
39 | #include <plat/clock.h> |
40 | #include <plat/devs.h> | |
bd117bd1 | 41 | #include <plat/pm.h> |
b024043b KK |
42 | #include <plat/gpio-cfg.h> |
43 | #include <plat/irq-uart.h> | |
44 | #include <plat/irq-vic-timer.h> | |
45 | #include <plat/regs-irqtype.h> | |
46 | #include <plat/regs-serial.h> | |
ff84ded2 | 47 | #include <plat/watchdog-reset.h> |
b024043b KK |
48 | |
49 | #include "common.h" | |
50 | ||
51 | /* uart registration process */ | |
52 | ||
b7c9705c | 53 | static void __init s3c64xx_init_uarts(struct s3c2410_uartcfg *cfg, int no) |
b024043b KK |
54 | { |
55 | s3c24xx_init_uartdevs("s3c6400-uart", s3c64xx_uart_resources, cfg, no); | |
56 | } | |
57 | ||
58 | /* table of supported CPUs */ | |
59 | ||
60 | static const char name_s3c6400[] = "S3C6400"; | |
61 | static const char name_s3c6410[] = "S3C6410"; | |
62 | ||
63 | static struct cpu_table cpu_ids[] __initdata = { | |
64 | { | |
65 | .idcode = S3C6400_CPU_ID, | |
66 | .idmask = S3C64XX_CPU_MASK, | |
67 | .map_io = s3c6400_map_io, | |
68 | .init_clocks = s3c6400_init_clocks, | |
69 | .init_uarts = s3c64xx_init_uarts, | |
70 | .init = s3c6400_init, | |
71 | .name = name_s3c6400, | |
72 | }, { | |
73 | .idcode = S3C6410_CPU_ID, | |
74 | .idmask = S3C64XX_CPU_MASK, | |
75 | .map_io = s3c6410_map_io, | |
76 | .init_clocks = s3c6410_init_clocks, | |
77 | .init_uarts = s3c64xx_init_uarts, | |
78 | .init = s3c6410_init, | |
79 | .name = name_s3c6410, | |
80 | }, | |
81 | }; | |
82 | ||
83 | /* minimal IO mapping */ | |
84 | ||
85 | /* see notes on uart map in arch/arm/mach-s3c64xx/include/mach/debug-macro.S */ | |
86 | #define UART_OFFS (S3C_PA_UART & 0xfffff) | |
87 | ||
88 | static struct map_desc s3c_iodesc[] __initdata = { | |
89 | { | |
90 | .virtual = (unsigned long)S3C_VA_SYS, | |
91 | .pfn = __phys_to_pfn(S3C64XX_PA_SYSCON), | |
92 | .length = SZ_4K, | |
93 | .type = MT_DEVICE, | |
94 | }, { | |
95 | .virtual = (unsigned long)S3C_VA_MEM, | |
96 | .pfn = __phys_to_pfn(S3C64XX_PA_SROM), | |
97 | .length = SZ_4K, | |
98 | .type = MT_DEVICE, | |
99 | }, { | |
100 | .virtual = (unsigned long)(S3C_VA_UART + UART_OFFS), | |
101 | .pfn = __phys_to_pfn(S3C_PA_UART), | |
102 | .length = SZ_4K, | |
103 | .type = MT_DEVICE, | |
104 | }, { | |
105 | .virtual = (unsigned long)VA_VIC0, | |
106 | .pfn = __phys_to_pfn(S3C64XX_PA_VIC0), | |
107 | .length = SZ_16K, | |
108 | .type = MT_DEVICE, | |
109 | }, { | |
110 | .virtual = (unsigned long)VA_VIC1, | |
111 | .pfn = __phys_to_pfn(S3C64XX_PA_VIC1), | |
112 | .length = SZ_16K, | |
113 | .type = MT_DEVICE, | |
114 | }, { | |
115 | .virtual = (unsigned long)S3C_VA_TIMER, | |
116 | .pfn = __phys_to_pfn(S3C_PA_TIMER), | |
117 | .length = SZ_16K, | |
118 | .type = MT_DEVICE, | |
119 | }, { | |
120 | .virtual = (unsigned long)S3C64XX_VA_GPIO, | |
121 | .pfn = __phys_to_pfn(S3C64XX_PA_GPIO), | |
122 | .length = SZ_4K, | |
123 | .type = MT_DEVICE, | |
124 | }, { | |
125 | .virtual = (unsigned long)S3C64XX_VA_MODEM, | |
126 | .pfn = __phys_to_pfn(S3C64XX_PA_MODEM), | |
127 | .length = SZ_4K, | |
128 | .type = MT_DEVICE, | |
129 | }, { | |
130 | .virtual = (unsigned long)S3C_VA_WATCHDOG, | |
131 | .pfn = __phys_to_pfn(S3C64XX_PA_WATCHDOG), | |
132 | .length = SZ_4K, | |
133 | .type = MT_DEVICE, | |
134 | }, { | |
135 | .virtual = (unsigned long)S3C_VA_USB_HSPHY, | |
136 | .pfn = __phys_to_pfn(S3C64XX_PA_USB_HSPHY), | |
137 | .length = SZ_1K, | |
138 | .type = MT_DEVICE, | |
139 | }, | |
140 | }; | |
141 | ||
7affca35 LT |
142 | static struct bus_type s3c64xx_subsys = { |
143 | .name = "s3c64xx-core", | |
144 | .dev_name = "s3c64xx-core", | |
b024043b KK |
145 | }; |
146 | ||
7affca35 LT |
147 | static struct device s3c64xx_dev = { |
148 | .bus = &s3c64xx_subsys, | |
b024043b KK |
149 | }; |
150 | ||
151 | /* read cpu identification code */ | |
152 | ||
153 | void __init s3c64xx_init_io(struct map_desc *mach_desc, int size) | |
154 | { | |
155 | /* initialise the io descriptors we need for initialisation */ | |
156 | iotable_init(s3c_iodesc, ARRAY_SIZE(s3c_iodesc)); | |
157 | iotable_init(mach_desc, size); | |
b024043b KK |
158 | |
159 | /* detect cpu id */ | |
160 | s3c64xx_init_cpu(); | |
161 | ||
162 | s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids)); | |
163 | } | |
164 | ||
7affca35 | 165 | static __init int s3c64xx_dev_init(void) |
b024043b | 166 | { |
7affca35 LT |
167 | subsys_system_register(&s3c64xx_subsys, NULL); |
168 | return device_register(&s3c64xx_dev); | |
b024043b | 169 | } |
7affca35 | 170 | core_initcall(s3c64xx_dev_init); |
b024043b KK |
171 | |
172 | /* | |
173 | * setup the sources the vic should advertise resume | |
174 | * for, even though it is not doing the wake | |
175 | * (set_irq_wake needs to be valid) | |
176 | */ | |
177 | #define IRQ_VIC0_RESUME (1 << (IRQ_RTC_TIC - IRQ_VIC0_BASE)) | |
178 | #define IRQ_VIC1_RESUME (1 << (IRQ_RTC_ALARM - IRQ_VIC1_BASE) | \ | |
179 | 1 << (IRQ_PENDN - IRQ_VIC1_BASE) | \ | |
180 | 1 << (IRQ_HSMMC0 - IRQ_VIC1_BASE) | \ | |
181 | 1 << (IRQ_HSMMC1 - IRQ_VIC1_BASE) | \ | |
182 | 1 << (IRQ_HSMMC2 - IRQ_VIC1_BASE)) | |
183 | ||
184 | void __init s3c64xx_init_irq(u32 vic0_valid, u32 vic1_valid) | |
185 | { | |
88f59738 TF |
186 | /* |
187 | * FIXME: there is no better place to put this at the moment | |
188 | * (samsung_wdt_reset_init needs clocks) | |
189 | */ | |
190 | samsung_wdt_reset_init(S3C_VA_WATCHDOG); | |
191 | ||
b024043b KK |
192 | printk(KERN_DEBUG "%s: initialising interrupts\n", __func__); |
193 | ||
194 | /* initialise the pair of VICs */ | |
195 | vic_init(VA_VIC0, IRQ_VIC0_BASE, vic0_valid, IRQ_VIC0_RESUME); | |
196 | vic_init(VA_VIC1, IRQ_VIC1_BASE, vic1_valid, IRQ_VIC1_RESUME); | |
197 | ||
198 | /* add the timer sub-irqs */ | |
199 | s3c_init_vic_timer_irq(5, IRQ_TIMER0); | |
200 | } | |
80789e79 | 201 | |
80789e79 | 202 | #define eint_offset(irq) ((irq) - IRQ_EINT(0)) |
3c916975 | 203 | #define eint_irq_to_bit(irq) ((u32)(1 << eint_offset(irq))) |
80789e79 | 204 | |
c35cd6ec | 205 | static inline void s3c_irq_eint_mask(struct irq_data *data) |
80789e79 BD |
206 | { |
207 | u32 mask; | |
208 | ||
209 | mask = __raw_readl(S3C64XX_EINT0MASK); | |
3c916975 | 210 | mask |= (u32)data->chip_data; |
80789e79 BD |
211 | __raw_writel(mask, S3C64XX_EINT0MASK); |
212 | } | |
213 | ||
c35cd6ec | 214 | static void s3c_irq_eint_unmask(struct irq_data *data) |
80789e79 BD |
215 | { |
216 | u32 mask; | |
217 | ||
218 | mask = __raw_readl(S3C64XX_EINT0MASK); | |
3c916975 | 219 | mask &= ~((u32)data->chip_data); |
80789e79 BD |
220 | __raw_writel(mask, S3C64XX_EINT0MASK); |
221 | } | |
222 | ||
c35cd6ec | 223 | static inline void s3c_irq_eint_ack(struct irq_data *data) |
80789e79 | 224 | { |
3c916975 | 225 | __raw_writel((u32)data->chip_data, S3C64XX_EINT0PEND); |
80789e79 BD |
226 | } |
227 | ||
c35cd6ec | 228 | static void s3c_irq_eint_maskack(struct irq_data *data) |
80789e79 BD |
229 | { |
230 | /* compiler should in-line these */ | |
c35cd6ec MB |
231 | s3c_irq_eint_mask(data); |
232 | s3c_irq_eint_ack(data); | |
80789e79 BD |
233 | } |
234 | ||
c35cd6ec | 235 | static int s3c_irq_eint_set_type(struct irq_data *data, unsigned int type) |
80789e79 | 236 | { |
c35cd6ec | 237 | int offs = eint_offset(data->irq); |
6a88e983 | 238 | int pin, pin_val; |
80789e79 BD |
239 | int shift; |
240 | u32 ctrl, mask; | |
241 | u32 newvalue = 0; | |
242 | void __iomem *reg; | |
243 | ||
244 | if (offs > 27) | |
245 | return -EINVAL; | |
246 | ||
a9c5d23a | 247 | if (offs <= 15) |
80789e79 BD |
248 | reg = S3C64XX_EINT0CON0; |
249 | else | |
250 | reg = S3C64XX_EINT0CON1; | |
251 | ||
252 | switch (type) { | |
253 | case IRQ_TYPE_NONE: | |
254 | printk(KERN_WARNING "No edge setting!\n"); | |
255 | break; | |
256 | ||
257 | case IRQ_TYPE_EDGE_RISING: | |
258 | newvalue = S3C2410_EXTINT_RISEEDGE; | |
259 | break; | |
260 | ||
261 | case IRQ_TYPE_EDGE_FALLING: | |
262 | newvalue = S3C2410_EXTINT_FALLEDGE; | |
263 | break; | |
264 | ||
265 | case IRQ_TYPE_EDGE_BOTH: | |
266 | newvalue = S3C2410_EXTINT_BOTHEDGE; | |
267 | break; | |
268 | ||
269 | case IRQ_TYPE_LEVEL_LOW: | |
270 | newvalue = S3C2410_EXTINT_LOWLEV; | |
271 | break; | |
272 | ||
273 | case IRQ_TYPE_LEVEL_HIGH: | |
274 | newvalue = S3C2410_EXTINT_HILEV; | |
275 | break; | |
276 | ||
277 | default: | |
278 | printk(KERN_ERR "No such irq type %d", type); | |
279 | return -1; | |
280 | } | |
281 | ||
6a88e983 MC |
282 | if (offs <= 15) |
283 | shift = (offs / 2) * 4; | |
284 | else | |
285 | shift = ((offs - 16) / 2) * 4; | |
80789e79 BD |
286 | mask = 0x7 << shift; |
287 | ||
288 | ctrl = __raw_readl(reg); | |
289 | ctrl &= ~mask; | |
290 | ctrl |= newvalue << shift; | |
291 | __raw_writel(ctrl, reg); | |
292 | ||
28fd2d39 BD |
293 | /* set the GPIO pin appropriately */ |
294 | ||
6a88e983 | 295 | if (offs < 16) { |
28fd2d39 | 296 | pin = S3C64XX_GPN(offs); |
6a88e983 MC |
297 | pin_val = S3C_GPIO_SFN(2); |
298 | } else if (offs < 23) { | |
299 | pin = S3C64XX_GPL(offs + 8 - 16); | |
300 | pin_val = S3C_GPIO_SFN(3); | |
301 | } else { | |
28fd2d39 | 302 | pin = S3C64XX_GPM(offs - 23); |
6a88e983 MC |
303 | pin_val = S3C_GPIO_SFN(3); |
304 | } | |
28fd2d39 | 305 | |
6a88e983 | 306 | s3c_gpio_cfgpin(pin, pin_val); |
28fd2d39 | 307 | |
80789e79 BD |
308 | return 0; |
309 | } | |
310 | ||
311 | static struct irq_chip s3c_irq_eint = { | |
312 | .name = "s3c-eint", | |
c35cd6ec MB |
313 | .irq_mask = s3c_irq_eint_mask, |
314 | .irq_unmask = s3c_irq_eint_unmask, | |
315 | .irq_mask_ack = s3c_irq_eint_maskack, | |
316 | .irq_ack = s3c_irq_eint_ack, | |
317 | .irq_set_type = s3c_irq_eint_set_type, | |
f5aeffb7 | 318 | .irq_set_wake = s3c_irqext_wake, |
80789e79 BD |
319 | }; |
320 | ||
321 | /* s3c_irq_demux_eint | |
322 | * | |
323 | * This function demuxes the IRQ from the group0 external interrupts, | |
324 | * from IRQ_EINT(0) to IRQ_EINT(27). It is designed to be inlined into | |
325 | * the specific handlers s3c_irq_demux_eintX_Y. | |
326 | */ | |
327 | static inline void s3c_irq_demux_eint(unsigned int start, unsigned int end) | |
328 | { | |
329 | u32 status = __raw_readl(S3C64XX_EINT0PEND); | |
330 | u32 mask = __raw_readl(S3C64XX_EINT0MASK); | |
331 | unsigned int irq; | |
332 | ||
333 | status &= ~mask; | |
334 | status >>= start; | |
335 | status &= (1 << (end - start + 1)) - 1; | |
336 | ||
337 | for (irq = IRQ_EINT(start); irq <= IRQ_EINT(end); irq++) { | |
338 | if (status & 1) | |
339 | generic_handle_irq(irq); | |
340 | ||
341 | status >>= 1; | |
342 | } | |
343 | } | |
344 | ||
345 | static void s3c_irq_demux_eint0_3(unsigned int irq, struct irq_desc *desc) | |
346 | { | |
347 | s3c_irq_demux_eint(0, 3); | |
348 | } | |
349 | ||
350 | static void s3c_irq_demux_eint4_11(unsigned int irq, struct irq_desc *desc) | |
351 | { | |
352 | s3c_irq_demux_eint(4, 11); | |
353 | } | |
354 | ||
355 | static void s3c_irq_demux_eint12_19(unsigned int irq, struct irq_desc *desc) | |
356 | { | |
357 | s3c_irq_demux_eint(12, 19); | |
358 | } | |
359 | ||
360 | static void s3c_irq_demux_eint20_27(unsigned int irq, struct irq_desc *desc) | |
361 | { | |
362 | s3c_irq_demux_eint(20, 27); | |
363 | } | |
364 | ||
8bd8dbdf | 365 | static int __init s3c64xx_init_irq_eint(void) |
80789e79 BD |
366 | { |
367 | int irq; | |
368 | ||
369 | for (irq = IRQ_EINT(0); irq <= IRQ_EINT(27); irq++) { | |
f38c02f3 | 370 | irq_set_chip_and_handler(irq, &s3c_irq_eint, handle_level_irq); |
9323f261 | 371 | irq_set_chip_data(irq, (void *)eint_irq_to_bit(irq)); |
80789e79 BD |
372 | set_irq_flags(irq, IRQF_VALID); |
373 | } | |
374 | ||
6845664a TG |
375 | irq_set_chained_handler(IRQ_EINT0_3, s3c_irq_demux_eint0_3); |
376 | irq_set_chained_handler(IRQ_EINT4_11, s3c_irq_demux_eint4_11); | |
377 | irq_set_chained_handler(IRQ_EINT12_19, s3c_irq_demux_eint12_19); | |
378 | irq_set_chained_handler(IRQ_EINT20_27, s3c_irq_demux_eint20_27); | |
80789e79 BD |
379 | |
380 | return 0; | |
381 | } | |
80789e79 | 382 | arch_initcall(s3c64xx_init_irq_eint); |
ff84ded2 KK |
383 | |
384 | void s3c64xx_restart(char mode, const char *cmd) | |
385 | { | |
386 | if (mode != 's') | |
88f59738 | 387 | samsung_wdt_reset(); |
ff84ded2 KK |
388 | |
389 | /* if all else fails, or mode was for soft, jump to 0 */ | |
390 | soft_restart(0); | |
391 | } | |
cc8f252b SG |
392 | |
393 | void __init s3c64xx_init_late(void) | |
394 | { | |
395 | s3c64xx_pm_late_initcall(); | |
396 | } |