common.c 16 KB

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