common.c 17 KB

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