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