common.c 17 KB

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