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