Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. |
| 3 | * http://www.samsung.com |
| 4 | * |
| 5 | * Common Codes for EXYNOS |
| 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/interrupt.h> |
| 14 | #include <linux/irq.h> |
| 15 | #include <linux/io.h> |
Linus Torvalds | 7affca3 | 2012-01-07 12:03:30 -0800 | [diff] [blame] | 16 | #include <linux/device.h> |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 17 | #include <linux/gpio.h> |
| 18 | #include <linux/sched.h> |
| 19 | #include <linux/serial_core.h> |
Arnd Bergmann | 237c78b | 2012-01-07 12:30:20 +0000 | [diff] [blame] | 20 | #include <linux/of.h> |
| 21 | #include <linux/of_irq.h> |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 22 | |
| 23 | #include <asm/proc-fns.h> |
Arnd Bergmann | 40ba95f | 2012-01-07 11:51:28 +0000 | [diff] [blame] | 24 | #include <asm/exception.h> |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 25 | #include <asm/hardware/cache-l2x0.h> |
| 26 | #include <asm/hardware/gic.h> |
| 27 | #include <asm/mach/map.h> |
| 28 | #include <asm/mach/irq.h> |
| 29 | |
| 30 | #include <mach/regs-irq.h> |
| 31 | #include <mach/regs-pmu.h> |
| 32 | #include <mach/regs-gpio.h> |
| 33 | |
| 34 | #include <plat/cpu.h> |
| 35 | #include <plat/clock.h> |
| 36 | #include <plat/devs.h> |
| 37 | #include <plat/pm.h> |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 38 | #include <plat/sdhci.h> |
| 39 | #include <plat/gpio-cfg.h> |
| 40 | #include <plat/adc-core.h> |
| 41 | #include <plat/fb-core.h> |
| 42 | #include <plat/fimc-core.h> |
| 43 | #include <plat/iic-core.h> |
| 44 | #include <plat/tv-core.h> |
| 45 | #include <plat/regs-serial.h> |
| 46 | |
| 47 | #include "common.h" |
| 48 | |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 49 | static const char name_exynos4210[] = "EXYNOS4210"; |
| 50 | static const char name_exynos4212[] = "EXYNOS4212"; |
| 51 | static const char name_exynos4412[] = "EXYNOS4412"; |
| 52 | |
Kukjin Kim | 906c789 | 2012-02-11 21:27:08 +0900 | [diff] [blame] | 53 | static void exynos4_map_io(void); |
| 54 | static void exynos4_init_clocks(int xtal); |
Kukjin Kim | 920f488 | 2012-01-24 20:52:52 +0900 | [diff] [blame] | 55 | static void exynos_init_uarts(struct s3c2410_uartcfg *cfg, int no); |
Kukjin Kim | 906c789 | 2012-02-11 21:27:08 +0900 | [diff] [blame] | 56 | static int exynos_init(void); |
| 57 | |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 58 | static struct cpu_table cpu_ids[] __initdata = { |
| 59 | { |
| 60 | .idcode = EXYNOS4210_CPU_ID, |
| 61 | .idmask = EXYNOS4_CPU_MASK, |
| 62 | .map_io = exynos4_map_io, |
| 63 | .init_clocks = exynos4_init_clocks, |
Kukjin Kim | 920f488 | 2012-01-24 20:52:52 +0900 | [diff] [blame] | 64 | .init_uarts = exynos_init_uarts, |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 65 | .init = exynos_init, |
| 66 | .name = name_exynos4210, |
| 67 | }, { |
| 68 | .idcode = EXYNOS4212_CPU_ID, |
| 69 | .idmask = EXYNOS4_CPU_MASK, |
| 70 | .map_io = exynos4_map_io, |
| 71 | .init_clocks = exynos4_init_clocks, |
Kukjin Kim | 920f488 | 2012-01-24 20:52:52 +0900 | [diff] [blame] | 72 | .init_uarts = exynos_init_uarts, |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 73 | .init = exynos_init, |
| 74 | .name = name_exynos4212, |
| 75 | }, { |
| 76 | .idcode = EXYNOS4412_CPU_ID, |
| 77 | .idmask = EXYNOS4_CPU_MASK, |
| 78 | .map_io = exynos4_map_io, |
| 79 | .init_clocks = exynos4_init_clocks, |
Kukjin Kim | 920f488 | 2012-01-24 20:52:52 +0900 | [diff] [blame] | 80 | .init_uarts = exynos_init_uarts, |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 81 | .init = exynos_init, |
| 82 | .name = name_exynos4412, |
| 83 | }, |
| 84 | }; |
| 85 | |
| 86 | /* Initial IO mappings */ |
| 87 | |
| 88 | static struct map_desc exynos_iodesc[] __initdata = { |
| 89 | { |
| 90 | .virtual = (unsigned long)S5P_VA_CHIPID, |
| 91 | .pfn = __phys_to_pfn(EXYNOS4_PA_CHIPID), |
| 92 | .length = SZ_4K, |
| 93 | .type = MT_DEVICE, |
| 94 | }, { |
| 95 | .virtual = (unsigned long)S3C_VA_SYS, |
| 96 | .pfn = __phys_to_pfn(EXYNOS4_PA_SYSCON), |
| 97 | .length = SZ_64K, |
| 98 | .type = MT_DEVICE, |
| 99 | }, { |
| 100 | .virtual = (unsigned long)S3C_VA_TIMER, |
| 101 | .pfn = __phys_to_pfn(EXYNOS4_PA_TIMER), |
| 102 | .length = SZ_16K, |
| 103 | .type = MT_DEVICE, |
| 104 | }, { |
| 105 | .virtual = (unsigned long)S3C_VA_WATCHDOG, |
| 106 | .pfn = __phys_to_pfn(EXYNOS4_PA_WATCHDOG), |
| 107 | .length = SZ_4K, |
| 108 | .type = MT_DEVICE, |
| 109 | }, { |
| 110 | .virtual = (unsigned long)S5P_VA_SROMC, |
| 111 | .pfn = __phys_to_pfn(EXYNOS4_PA_SROMC), |
| 112 | .length = SZ_4K, |
| 113 | .type = MT_DEVICE, |
| 114 | }, { |
| 115 | .virtual = (unsigned long)S5P_VA_SYSTIMER, |
| 116 | .pfn = __phys_to_pfn(EXYNOS4_PA_SYSTIMER), |
| 117 | .length = SZ_4K, |
| 118 | .type = MT_DEVICE, |
| 119 | }, { |
| 120 | .virtual = (unsigned long)S5P_VA_PMU, |
| 121 | .pfn = __phys_to_pfn(EXYNOS4_PA_PMU), |
| 122 | .length = SZ_64K, |
| 123 | .type = MT_DEVICE, |
| 124 | }, { |
| 125 | .virtual = (unsigned long)S5P_VA_COMBINER_BASE, |
| 126 | .pfn = __phys_to_pfn(EXYNOS4_PA_COMBINER), |
| 127 | .length = SZ_4K, |
| 128 | .type = MT_DEVICE, |
| 129 | }, { |
| 130 | .virtual = (unsigned long)S5P_VA_GIC_CPU, |
| 131 | .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_CPU), |
| 132 | .length = SZ_64K, |
| 133 | .type = MT_DEVICE, |
| 134 | }, { |
| 135 | .virtual = (unsigned long)S5P_VA_GIC_DIST, |
| 136 | .pfn = __phys_to_pfn(EXYNOS4_PA_GIC_DIST), |
| 137 | .length = SZ_64K, |
| 138 | .type = MT_DEVICE, |
| 139 | }, { |
| 140 | .virtual = (unsigned long)S3C_VA_UART, |
| 141 | .pfn = __phys_to_pfn(EXYNOS4_PA_UART), |
| 142 | .length = SZ_512K, |
| 143 | .type = MT_DEVICE, |
| 144 | }, |
| 145 | }; |
| 146 | |
| 147 | static struct map_desc exynos4_iodesc[] __initdata = { |
| 148 | { |
| 149 | .virtual = (unsigned long)S5P_VA_CMU, |
| 150 | .pfn = __phys_to_pfn(EXYNOS4_PA_CMU), |
| 151 | .length = SZ_128K, |
| 152 | .type = MT_DEVICE, |
| 153 | }, { |
| 154 | .virtual = (unsigned long)S5P_VA_COREPERI_BASE, |
| 155 | .pfn = __phys_to_pfn(EXYNOS4_PA_COREPERI), |
| 156 | .length = SZ_8K, |
| 157 | .type = MT_DEVICE, |
| 158 | }, { |
| 159 | .virtual = (unsigned long)S5P_VA_L2CC, |
| 160 | .pfn = __phys_to_pfn(EXYNOS4_PA_L2CC), |
| 161 | .length = SZ_4K, |
| 162 | .type = MT_DEVICE, |
| 163 | }, { |
| 164 | .virtual = (unsigned long)S5P_VA_GPIO1, |
| 165 | .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO1), |
| 166 | .length = SZ_4K, |
| 167 | .type = MT_DEVICE, |
| 168 | }, { |
| 169 | .virtual = (unsigned long)S5P_VA_GPIO2, |
| 170 | .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO2), |
| 171 | .length = SZ_4K, |
| 172 | .type = MT_DEVICE, |
| 173 | }, { |
| 174 | .virtual = (unsigned long)S5P_VA_GPIO3, |
| 175 | .pfn = __phys_to_pfn(EXYNOS4_PA_GPIO3), |
| 176 | .length = SZ_256, |
| 177 | .type = MT_DEVICE, |
| 178 | }, { |
| 179 | .virtual = (unsigned long)S5P_VA_DMC0, |
| 180 | .pfn = __phys_to_pfn(EXYNOS4_PA_DMC0), |
| 181 | .length = SZ_4K, |
| 182 | .type = MT_DEVICE, |
| 183 | }, { |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 184 | .virtual = (unsigned long)S3C_VA_USB_HSPHY, |
| 185 | .pfn = __phys_to_pfn(EXYNOS4_PA_HSPHY), |
| 186 | .length = SZ_4K, |
| 187 | .type = MT_DEVICE, |
| 188 | }, |
| 189 | }; |
| 190 | |
| 191 | static struct map_desc exynos4_iodesc0[] __initdata = { |
| 192 | { |
| 193 | .virtual = (unsigned long)S5P_VA_SYSRAM, |
| 194 | .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM0), |
| 195 | .length = SZ_4K, |
| 196 | .type = MT_DEVICE, |
| 197 | }, |
| 198 | }; |
| 199 | |
| 200 | static struct map_desc exynos4_iodesc1[] __initdata = { |
| 201 | { |
| 202 | .virtual = (unsigned long)S5P_VA_SYSRAM, |
| 203 | .pfn = __phys_to_pfn(EXYNOS4_PA_SYSRAM1), |
| 204 | .length = SZ_4K, |
| 205 | .type = MT_DEVICE, |
| 206 | }, |
| 207 | }; |
| 208 | |
Russell King | 9eb4859 | 2012-01-03 11:56:53 +0100 | [diff] [blame] | 209 | void exynos4_restart(char mode, const char *cmd) |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 210 | { |
| 211 | __raw_writel(0x1, S5P_SWRESET); |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * exynos_map_io |
| 216 | * |
| 217 | * register the standard cpu IO areas |
| 218 | */ |
| 219 | |
| 220 | void __init exynos_init_io(struct map_desc *mach_desc, int size) |
| 221 | { |
| 222 | /* initialize the io descriptors we need for initialization */ |
| 223 | iotable_init(exynos_iodesc, ARRAY_SIZE(exynos_iodesc)); |
| 224 | if (mach_desc) |
| 225 | iotable_init(mach_desc, size); |
| 226 | |
| 227 | /* detect cpu id and rev. */ |
| 228 | s5p_init_cpu(S5P_VA_CHIPID); |
| 229 | |
| 230 | s3c_init_cpu(samsung_cpu_id, cpu_ids, ARRAY_SIZE(cpu_ids)); |
| 231 | } |
| 232 | |
Kukjin Kim | 906c789 | 2012-02-11 21:27:08 +0900 | [diff] [blame] | 233 | static void __init exynos4_map_io(void) |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 234 | { |
| 235 | iotable_init(exynos4_iodesc, ARRAY_SIZE(exynos4_iodesc)); |
| 236 | |
| 237 | if (soc_is_exynos4210() && samsung_rev() == EXYNOS4210_REV_0) |
| 238 | iotable_init(exynos4_iodesc0, ARRAY_SIZE(exynos4_iodesc0)); |
| 239 | else |
| 240 | iotable_init(exynos4_iodesc1, ARRAY_SIZE(exynos4_iodesc1)); |
| 241 | |
| 242 | /* initialize device information early */ |
| 243 | exynos4_default_sdhci0(); |
| 244 | exynos4_default_sdhci1(); |
| 245 | exynos4_default_sdhci2(); |
| 246 | exynos4_default_sdhci3(); |
| 247 | |
| 248 | s3c_adc_setname("samsung-adc-v3"); |
| 249 | |
| 250 | s3c_fimc_setname(0, "exynos4-fimc"); |
| 251 | s3c_fimc_setname(1, "exynos4-fimc"); |
| 252 | s3c_fimc_setname(2, "exynos4-fimc"); |
| 253 | s3c_fimc_setname(3, "exynos4-fimc"); |
| 254 | |
| 255 | /* The I2C bus controllers are directly compatible with s3c2440 */ |
| 256 | s3c_i2c0_setname("s3c2440-i2c"); |
| 257 | s3c_i2c1_setname("s3c2440-i2c"); |
| 258 | s3c_i2c2_setname("s3c2440-i2c"); |
| 259 | |
| 260 | s5p_fb_setname(0, "exynos4-fb"); |
| 261 | s5p_hdmi_setname("exynos4-hdmi"); |
| 262 | } |
| 263 | |
Kukjin Kim | 906c789 | 2012-02-11 21:27:08 +0900 | [diff] [blame] | 264 | static void __init exynos4_init_clocks(int xtal) |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 265 | { |
| 266 | printk(KERN_DEBUG "%s: initializing clocks\n", __func__); |
| 267 | |
| 268 | s3c24xx_register_baseclocks(xtal); |
| 269 | s5p_register_clocks(xtal); |
| 270 | |
| 271 | if (soc_is_exynos4210()) |
| 272 | exynos4210_register_clocks(); |
| 273 | else if (soc_is_exynos4212() || soc_is_exynos4412()) |
| 274 | exynos4212_register_clocks(); |
| 275 | |
| 276 | exynos4_register_clocks(); |
| 277 | exynos4_setup_clocks(); |
| 278 | } |
| 279 | |
| 280 | #define COMBINER_ENABLE_SET 0x0 |
| 281 | #define COMBINER_ENABLE_CLEAR 0x4 |
| 282 | #define COMBINER_INT_STATUS 0xC |
| 283 | |
| 284 | static DEFINE_SPINLOCK(irq_controller_lock); |
| 285 | |
| 286 | struct combiner_chip_data { |
| 287 | unsigned int irq_offset; |
| 288 | unsigned int irq_mask; |
| 289 | void __iomem *base; |
| 290 | }; |
| 291 | |
| 292 | static struct combiner_chip_data combiner_data[MAX_COMBINER_NR]; |
| 293 | |
| 294 | static inline void __iomem *combiner_base(struct irq_data *data) |
| 295 | { |
| 296 | struct combiner_chip_data *combiner_data = |
| 297 | irq_data_get_irq_chip_data(data); |
| 298 | |
| 299 | return combiner_data->base; |
| 300 | } |
| 301 | |
| 302 | static void combiner_mask_irq(struct irq_data *data) |
| 303 | { |
| 304 | u32 mask = 1 << (data->irq % 32); |
| 305 | |
| 306 | __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_CLEAR); |
| 307 | } |
| 308 | |
| 309 | static void combiner_unmask_irq(struct irq_data *data) |
| 310 | { |
| 311 | u32 mask = 1 << (data->irq % 32); |
| 312 | |
| 313 | __raw_writel(mask, combiner_base(data) + COMBINER_ENABLE_SET); |
| 314 | } |
| 315 | |
| 316 | static void combiner_handle_cascade_irq(unsigned int irq, struct irq_desc *desc) |
| 317 | { |
| 318 | struct combiner_chip_data *chip_data = irq_get_handler_data(irq); |
| 319 | struct irq_chip *chip = irq_get_chip(irq); |
| 320 | unsigned int cascade_irq, combiner_irq; |
| 321 | unsigned long status; |
| 322 | |
| 323 | chained_irq_enter(chip, desc); |
| 324 | |
| 325 | spin_lock(&irq_controller_lock); |
| 326 | status = __raw_readl(chip_data->base + COMBINER_INT_STATUS); |
| 327 | spin_unlock(&irq_controller_lock); |
| 328 | status &= chip_data->irq_mask; |
| 329 | |
| 330 | if (status == 0) |
| 331 | goto out; |
| 332 | |
| 333 | combiner_irq = __ffs(status); |
| 334 | |
| 335 | cascade_irq = combiner_irq + (chip_data->irq_offset & ~31); |
| 336 | if (unlikely(cascade_irq >= NR_IRQS)) |
| 337 | do_bad_IRQ(cascade_irq, desc); |
| 338 | else |
| 339 | generic_handle_irq(cascade_irq); |
| 340 | |
| 341 | out: |
| 342 | chained_irq_exit(chip, desc); |
| 343 | } |
| 344 | |
| 345 | static struct irq_chip combiner_chip = { |
| 346 | .name = "COMBINER", |
| 347 | .irq_mask = combiner_mask_irq, |
| 348 | .irq_unmask = combiner_unmask_irq, |
| 349 | }; |
| 350 | |
| 351 | static void __init combiner_cascade_irq(unsigned int combiner_nr, unsigned int irq) |
| 352 | { |
| 353 | if (combiner_nr >= MAX_COMBINER_NR) |
| 354 | BUG(); |
| 355 | if (irq_set_handler_data(irq, &combiner_data[combiner_nr]) != 0) |
| 356 | BUG(); |
| 357 | irq_set_chained_handler(irq, combiner_handle_cascade_irq); |
| 358 | } |
| 359 | |
| 360 | static void __init combiner_init(unsigned int combiner_nr, void __iomem *base, |
| 361 | unsigned int irq_start) |
| 362 | { |
| 363 | unsigned int i; |
| 364 | |
| 365 | if (combiner_nr >= MAX_COMBINER_NR) |
| 366 | BUG(); |
| 367 | |
| 368 | combiner_data[combiner_nr].base = base; |
| 369 | combiner_data[combiner_nr].irq_offset = irq_start; |
| 370 | combiner_data[combiner_nr].irq_mask = 0xff << ((combiner_nr % 4) << 3); |
| 371 | |
| 372 | /* Disable all interrupts */ |
| 373 | |
| 374 | __raw_writel(combiner_data[combiner_nr].irq_mask, |
| 375 | base + COMBINER_ENABLE_CLEAR); |
| 376 | |
| 377 | /* Setup the Linux IRQ subsystem */ |
| 378 | |
| 379 | for (i = irq_start; i < combiner_data[combiner_nr].irq_offset |
| 380 | + MAX_IRQ_IN_COMBINER; i++) { |
| 381 | irq_set_chip_and_handler(i, &combiner_chip, handle_level_irq); |
| 382 | irq_set_chip_data(i, &combiner_data[combiner_nr]); |
| 383 | set_irq_flags(i, IRQF_VALID | IRQF_PROBE); |
| 384 | } |
| 385 | } |
| 386 | |
Arnd Bergmann | 237c78b | 2012-01-07 12:30:20 +0000 | [diff] [blame] | 387 | #ifdef CONFIG_OF |
| 388 | static const struct of_device_id exynos4_dt_irq_match[] = { |
| 389 | { .compatible = "arm,cortex-a9-gic", .data = gic_of_init, }, |
| 390 | {}, |
| 391 | }; |
| 392 | #endif |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 393 | |
| 394 | void __init exynos4_init_irq(void) |
| 395 | { |
| 396 | int irq; |
Arnd Bergmann | 40ba95f | 2012-01-07 11:51:28 +0000 | [diff] [blame] | 397 | unsigned int gic_bank_offset; |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 398 | |
| 399 | gic_bank_offset = soc_is_exynos4412() ? 0x4000 : 0x8000; |
| 400 | |
Arnd Bergmann | 237c78b | 2012-01-07 12:30:20 +0000 | [diff] [blame] | 401 | if (!of_have_populated_dt()) |
| 402 | gic_init_bases(0, IRQ_PPI(0), S5P_VA_GIC_DIST, S5P_VA_GIC_CPU, gic_bank_offset); |
| 403 | #ifdef CONFIG_OF |
| 404 | else |
| 405 | of_irq_init(exynos4_dt_irq_match); |
| 406 | #endif |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 407 | |
| 408 | for (irq = 0; irq < MAX_COMBINER_NR; irq++) { |
| 409 | |
| 410 | combiner_init(irq, (void __iomem *)S5P_VA_COMBINER(irq), |
| 411 | COMBINER_IRQ(irq, 0)); |
| 412 | combiner_cascade_irq(irq, IRQ_SPI(irq)); |
| 413 | } |
| 414 | |
| 415 | /* |
| 416 | * The parameters of s5p_init_irq() are for VIC init. |
| 417 | * Theses parameters should be NULL and 0 because EXYNOS4 |
| 418 | * uses GIC instead of VIC. |
| 419 | */ |
| 420 | s5p_init_irq(NULL, 0); |
| 421 | } |
| 422 | |
Linus Torvalds | 7affca3 | 2012-01-07 12:03:30 -0800 | [diff] [blame] | 423 | struct bus_type exynos4_subsys = { |
| 424 | .name = "exynos4-core", |
| 425 | .dev_name = "exynos4-core", |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 426 | }; |
| 427 | |
Linus Torvalds | 7affca3 | 2012-01-07 12:03:30 -0800 | [diff] [blame] | 428 | static struct device exynos4_dev = { |
| 429 | .bus = &exynos4_subsys, |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | static int __init exynos4_core_init(void) |
| 433 | { |
Linus Torvalds | 7affca3 | 2012-01-07 12:03:30 -0800 | [diff] [blame] | 434 | return subsys_system_register(&exynos4_subsys, NULL); |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 435 | } |
| 436 | core_initcall(exynos4_core_init); |
| 437 | |
| 438 | #ifdef CONFIG_CACHE_L2X0 |
| 439 | static int __init exynos4_l2x0_cache_init(void) |
| 440 | { |
| 441 | /* TAG, Data Latency Control: 2cycle */ |
| 442 | __raw_writel(0x110, S5P_VA_L2CC + L2X0_TAG_LATENCY_CTRL); |
| 443 | |
| 444 | if (soc_is_exynos4210()) |
| 445 | __raw_writel(0x110, S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL); |
| 446 | else if (soc_is_exynos4212() || soc_is_exynos4412()) |
| 447 | __raw_writel(0x120, S5P_VA_L2CC + L2X0_DATA_LATENCY_CTRL); |
| 448 | |
| 449 | /* L2X0 Prefetch Control */ |
| 450 | __raw_writel(0x30000007, S5P_VA_L2CC + L2X0_PREFETCH_CTRL); |
| 451 | |
| 452 | /* L2X0 Power Control */ |
| 453 | __raw_writel(L2X0_DYNAMIC_CLK_GATING_EN | L2X0_STNDBY_MODE_EN, |
| 454 | S5P_VA_L2CC + L2X0_POWER_CTRL); |
| 455 | |
| 456 | l2x0_init(S5P_VA_L2CC, 0x7C470001, 0xC200ffff); |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | early_initcall(exynos4_l2x0_cache_init); |
| 462 | #endif |
| 463 | |
Kukjin Kim | 906c789 | 2012-02-11 21:27:08 +0900 | [diff] [blame] | 464 | static int __init exynos_init(void) |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 465 | { |
| 466 | printk(KERN_INFO "EXYNOS: Initializing architecture\n"); |
Linus Torvalds | 7affca3 | 2012-01-07 12:03:30 -0800 | [diff] [blame] | 467 | return device_register(&exynos4_dev); |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 468 | } |
| 469 | |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 470 | /* uart registration process */ |
| 471 | |
Kukjin Kim | 920f488 | 2012-01-24 20:52:52 +0900 | [diff] [blame] | 472 | static void __init exynos_init_uarts(struct s3c2410_uartcfg *cfg, int no) |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 473 | { |
| 474 | struct s3c2410_uartcfg *tcfg = cfg; |
| 475 | u32 ucnt; |
| 476 | |
Arnd Bergmann | 237c78b | 2012-01-07 12:30:20 +0000 | [diff] [blame] | 477 | for (ucnt = 0; ucnt < no; ucnt++, tcfg++) |
| 478 | tcfg->has_fracval = 1; |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 479 | |
Kukjin Kim | 171c067 | 2012-02-10 11:57:53 +0900 | [diff] [blame^] | 480 | if (soc_is_exynos5250()) |
| 481 | s3c24xx_init_uartdevs("exynos4210-uart", exynos5_uart_resources, cfg, no); |
| 482 | else |
| 483 | s3c24xx_init_uartdevs("exynos4210-uart", exynos4_uart_resources, cfg, no); |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static DEFINE_SPINLOCK(eint_lock); |
| 487 | |
| 488 | static unsigned int eint0_15_data[16]; |
| 489 | |
| 490 | static unsigned int exynos4_get_irq_nr(unsigned int number) |
| 491 | { |
| 492 | u32 ret = 0; |
| 493 | |
| 494 | switch (number) { |
| 495 | case 0 ... 3: |
| 496 | ret = (number + IRQ_EINT0); |
| 497 | break; |
| 498 | case 4 ... 7: |
| 499 | ret = (number + (IRQ_EINT4 - 4)); |
| 500 | break; |
| 501 | case 8 ... 15: |
| 502 | ret = (number + (IRQ_EINT8 - 8)); |
| 503 | break; |
| 504 | default: |
| 505 | printk(KERN_ERR "number available : %d\n", number); |
| 506 | } |
| 507 | |
| 508 | return ret; |
| 509 | } |
| 510 | |
| 511 | static inline void exynos4_irq_eint_mask(struct irq_data *data) |
| 512 | { |
| 513 | u32 mask; |
| 514 | |
| 515 | spin_lock(&eint_lock); |
| 516 | mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq))); |
| 517 | mask |= eint_irq_to_bit(data->irq); |
| 518 | __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq))); |
| 519 | spin_unlock(&eint_lock); |
| 520 | } |
| 521 | |
| 522 | static void exynos4_irq_eint_unmask(struct irq_data *data) |
| 523 | { |
| 524 | u32 mask; |
| 525 | |
| 526 | spin_lock(&eint_lock); |
| 527 | mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(data->irq))); |
| 528 | mask &= ~(eint_irq_to_bit(data->irq)); |
| 529 | __raw_writel(mask, S5P_EINT_MASK(EINT_REG_NR(data->irq))); |
| 530 | spin_unlock(&eint_lock); |
| 531 | } |
| 532 | |
| 533 | static inline void exynos4_irq_eint_ack(struct irq_data *data) |
| 534 | { |
| 535 | __raw_writel(eint_irq_to_bit(data->irq), |
| 536 | S5P_EINT_PEND(EINT_REG_NR(data->irq))); |
| 537 | } |
| 538 | |
| 539 | static void exynos4_irq_eint_maskack(struct irq_data *data) |
| 540 | { |
| 541 | exynos4_irq_eint_mask(data); |
| 542 | exynos4_irq_eint_ack(data); |
| 543 | } |
| 544 | |
| 545 | static int exynos4_irq_eint_set_type(struct irq_data *data, unsigned int type) |
| 546 | { |
| 547 | int offs = EINT_OFFSET(data->irq); |
| 548 | int shift; |
| 549 | u32 ctrl, mask; |
| 550 | u32 newvalue = 0; |
| 551 | |
| 552 | switch (type) { |
| 553 | case IRQ_TYPE_EDGE_RISING: |
| 554 | newvalue = S5P_IRQ_TYPE_EDGE_RISING; |
| 555 | break; |
| 556 | |
| 557 | case IRQ_TYPE_EDGE_FALLING: |
| 558 | newvalue = S5P_IRQ_TYPE_EDGE_FALLING; |
| 559 | break; |
| 560 | |
| 561 | case IRQ_TYPE_EDGE_BOTH: |
| 562 | newvalue = S5P_IRQ_TYPE_EDGE_BOTH; |
| 563 | break; |
| 564 | |
| 565 | case IRQ_TYPE_LEVEL_LOW: |
| 566 | newvalue = S5P_IRQ_TYPE_LEVEL_LOW; |
| 567 | break; |
| 568 | |
| 569 | case IRQ_TYPE_LEVEL_HIGH: |
| 570 | newvalue = S5P_IRQ_TYPE_LEVEL_HIGH; |
| 571 | break; |
| 572 | |
| 573 | default: |
| 574 | printk(KERN_ERR "No such irq type %d", type); |
| 575 | return -EINVAL; |
| 576 | } |
| 577 | |
| 578 | shift = (offs & 0x7) * 4; |
| 579 | mask = 0x7 << shift; |
| 580 | |
| 581 | spin_lock(&eint_lock); |
| 582 | ctrl = __raw_readl(S5P_EINT_CON(EINT_REG_NR(data->irq))); |
| 583 | ctrl &= ~mask; |
| 584 | ctrl |= newvalue << shift; |
| 585 | __raw_writel(ctrl, S5P_EINT_CON(EINT_REG_NR(data->irq))); |
| 586 | spin_unlock(&eint_lock); |
| 587 | |
| 588 | switch (offs) { |
| 589 | case 0 ... 7: |
| 590 | s3c_gpio_cfgpin(EINT_GPIO_0(offs & 0x7), EINT_MODE); |
| 591 | break; |
| 592 | case 8 ... 15: |
| 593 | s3c_gpio_cfgpin(EINT_GPIO_1(offs & 0x7), EINT_MODE); |
| 594 | break; |
| 595 | case 16 ... 23: |
| 596 | s3c_gpio_cfgpin(EINT_GPIO_2(offs & 0x7), EINT_MODE); |
| 597 | break; |
| 598 | case 24 ... 31: |
| 599 | s3c_gpio_cfgpin(EINT_GPIO_3(offs & 0x7), EINT_MODE); |
| 600 | break; |
| 601 | default: |
| 602 | printk(KERN_ERR "No such irq number %d", offs); |
| 603 | } |
| 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | static struct irq_chip exynos4_irq_eint = { |
| 609 | .name = "exynos4-eint", |
| 610 | .irq_mask = exynos4_irq_eint_mask, |
| 611 | .irq_unmask = exynos4_irq_eint_unmask, |
| 612 | .irq_mask_ack = exynos4_irq_eint_maskack, |
| 613 | .irq_ack = exynos4_irq_eint_ack, |
| 614 | .irq_set_type = exynos4_irq_eint_set_type, |
| 615 | #ifdef CONFIG_PM |
| 616 | .irq_set_wake = s3c_irqext_wake, |
| 617 | #endif |
| 618 | }; |
| 619 | |
| 620 | /* |
| 621 | * exynos4_irq_demux_eint |
| 622 | * |
| 623 | * This function demuxes the IRQ from from EINTs 16 to 31. |
| 624 | * It is designed to be inlined into the specific handler |
| 625 | * s5p_irq_demux_eintX_Y. |
| 626 | * |
| 627 | * Each EINT pend/mask registers handle eight of them. |
| 628 | */ |
| 629 | static inline void exynos4_irq_demux_eint(unsigned int start) |
| 630 | { |
| 631 | unsigned int irq; |
| 632 | |
| 633 | u32 status = __raw_readl(S5P_EINT_PEND(EINT_REG_NR(start))); |
| 634 | u32 mask = __raw_readl(S5P_EINT_MASK(EINT_REG_NR(start))); |
| 635 | |
| 636 | status &= ~mask; |
| 637 | status &= 0xff; |
| 638 | |
| 639 | while (status) { |
| 640 | irq = fls(status) - 1; |
| 641 | generic_handle_irq(irq + start); |
| 642 | status &= ~(1 << irq); |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | static void exynos4_irq_demux_eint16_31(unsigned int irq, struct irq_desc *desc) |
| 647 | { |
| 648 | struct irq_chip *chip = irq_get_chip(irq); |
| 649 | chained_irq_enter(chip, desc); |
| 650 | exynos4_irq_demux_eint(IRQ_EINT(16)); |
| 651 | exynos4_irq_demux_eint(IRQ_EINT(24)); |
| 652 | chained_irq_exit(chip, desc); |
| 653 | } |
| 654 | |
| 655 | static void exynos4_irq_eint0_15(unsigned int irq, struct irq_desc *desc) |
| 656 | { |
| 657 | u32 *irq_data = irq_get_handler_data(irq); |
| 658 | struct irq_chip *chip = irq_get_chip(irq); |
| 659 | |
| 660 | chained_irq_enter(chip, desc); |
| 661 | chip->irq_mask(&desc->irq_data); |
| 662 | |
| 663 | if (chip->irq_ack) |
| 664 | chip->irq_ack(&desc->irq_data); |
| 665 | |
| 666 | generic_handle_irq(*irq_data); |
| 667 | |
| 668 | chip->irq_unmask(&desc->irq_data); |
| 669 | chained_irq_exit(chip, desc); |
| 670 | } |
| 671 | |
Kukjin Kim | e745e06 | 2012-01-21 10:47:14 +0900 | [diff] [blame] | 672 | static int __init exynos4_init_irq_eint(void) |
Kukjin Kim | cc511b8 | 2011-12-27 08:18:36 +0100 | [diff] [blame] | 673 | { |
| 674 | int irq; |
| 675 | |
| 676 | for (irq = 0 ; irq <= 31 ; irq++) { |
| 677 | irq_set_chip_and_handler(IRQ_EINT(irq), &exynos4_irq_eint, |
| 678 | handle_level_irq); |
| 679 | set_irq_flags(IRQ_EINT(irq), IRQF_VALID); |
| 680 | } |
| 681 | |
| 682 | irq_set_chained_handler(IRQ_EINT16_31, exynos4_irq_demux_eint16_31); |
| 683 | |
| 684 | for (irq = 0 ; irq <= 15 ; irq++) { |
| 685 | eint0_15_data[irq] = IRQ_EINT(irq); |
| 686 | |
| 687 | irq_set_handler_data(exynos4_get_irq_nr(irq), |
| 688 | &eint0_15_data[irq]); |
| 689 | irq_set_chained_handler(exynos4_get_irq_nr(irq), |
| 690 | exynos4_irq_eint0_15); |
| 691 | } |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | arch_initcall(exynos4_init_irq_eint); |