common.c 17 KB

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