irq-eint.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /* arch/arm/mach-s5p64x0/irq-eint.c
  2. *
  3. * Copyright (c) 2011 Samsung Electronics Co., Ltd
  4. * http://www.samsung.com/
  5. *
  6. * Based on linux/arch/arm/mach-s3c64xx/irq-eint.c
  7. *
  8. * S5P64X0 - Interrupt handling for External Interrupts.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/gpio.h>
  16. #include <linux/irq.h>
  17. #include <linux/io.h>
  18. #include <plat/cpu.h>
  19. #include <plat/regs-irqtype.h>
  20. #include <plat/gpio-cfg.h>
  21. #include <plat/pm.h>
  22. #include <mach/regs-gpio.h>
  23. #include <mach/regs-clock.h>
  24. #define eint_offset(irq) ((irq) - IRQ_EINT(0))
  25. static int s5p64x0_irq_eint_set_type(struct irq_data *data, unsigned int type)
  26. {
  27. int offs = eint_offset(data->irq);
  28. int shift;
  29. u32 ctrl, mask;
  30. u32 newvalue = 0;
  31. if (offs > 15)
  32. return -EINVAL;
  33. switch (type) {
  34. case IRQ_TYPE_NONE:
  35. printk(KERN_WARNING "No edge setting!\n");
  36. break;
  37. case IRQ_TYPE_EDGE_RISING:
  38. newvalue = S3C2410_EXTINT_RISEEDGE;
  39. break;
  40. case IRQ_TYPE_EDGE_FALLING:
  41. newvalue = S3C2410_EXTINT_FALLEDGE;
  42. break;
  43. case IRQ_TYPE_EDGE_BOTH:
  44. newvalue = S3C2410_EXTINT_BOTHEDGE;
  45. break;
  46. case IRQ_TYPE_LEVEL_LOW:
  47. newvalue = S3C2410_EXTINT_LOWLEV;
  48. break;
  49. case IRQ_TYPE_LEVEL_HIGH:
  50. newvalue = S3C2410_EXTINT_HILEV;
  51. break;
  52. default:
  53. printk(KERN_ERR "No such irq type %d", type);
  54. return -EINVAL;
  55. }
  56. shift = (offs / 2) * 4;
  57. mask = 0x7 << shift;
  58. ctrl = __raw_readl(S5P64X0_EINT0CON0) & ~mask;
  59. ctrl |= newvalue << shift;
  60. __raw_writel(ctrl, S5P64X0_EINT0CON0);
  61. /* Configure the GPIO pin for 6450 or 6440 based on CPU ID */
  62. if (soc_is_s5p6450())
  63. s3c_gpio_cfgpin(S5P6450_GPN(offs), S3C_GPIO_SFN(2));
  64. else
  65. s3c_gpio_cfgpin(S5P6440_GPN(offs), S3C_GPIO_SFN(2));
  66. return 0;
  67. }
  68. /*
  69. * s5p64x0_irq_demux_eint
  70. *
  71. * This function demuxes the IRQ from the group0 external interrupts,
  72. * from IRQ_EINT(0) to IRQ_EINT(15). It is designed to be inlined into
  73. * the specific handlers s5p64x0_irq_demux_eintX_Y.
  74. */
  75. static inline void s5p64x0_irq_demux_eint(unsigned int start, unsigned int end)
  76. {
  77. u32 status = __raw_readl(S5P64X0_EINT0PEND);
  78. u32 mask = __raw_readl(S5P64X0_EINT0MASK);
  79. unsigned int irq;
  80. status &= ~mask;
  81. status >>= start;
  82. status &= (1 << (end - start + 1)) - 1;
  83. for (irq = IRQ_EINT(start); irq <= IRQ_EINT(end); irq++) {
  84. if (status & 1)
  85. generic_handle_irq(irq);
  86. status >>= 1;
  87. }
  88. }
  89. static void s5p64x0_irq_demux_eint0_3(unsigned int irq, struct irq_desc *desc)
  90. {
  91. s5p64x0_irq_demux_eint(0, 3);
  92. }
  93. static void s5p64x0_irq_demux_eint4_11(unsigned int irq, struct irq_desc *desc)
  94. {
  95. s5p64x0_irq_demux_eint(4, 11);
  96. }
  97. static void s5p64x0_irq_demux_eint12_15(unsigned int irq,
  98. struct irq_desc *desc)
  99. {
  100. s5p64x0_irq_demux_eint(12, 15);
  101. }
  102. static int s5p64x0_alloc_gc(void)
  103. {
  104. struct irq_chip_generic *gc;
  105. struct irq_chip_type *ct;
  106. gc = irq_alloc_generic_chip("s5p64x0-eint", 1, S5P_IRQ_EINT_BASE,
  107. S5P_VA_GPIO, handle_level_irq);
  108. if (!gc) {
  109. printk(KERN_ERR "%s: irq_alloc_generic_chip for group 0"
  110. "external interrupts failed\n", __func__);
  111. return -EINVAL;
  112. }
  113. ct = gc->chip_types;
  114. ct->chip.irq_ack = irq_gc_ack_set_bit;
  115. ct->chip.irq_mask = irq_gc_mask_set_bit;
  116. ct->chip.irq_unmask = irq_gc_mask_clr_bit;
  117. ct->chip.irq_set_type = s5p64x0_irq_eint_set_type;
  118. ct->chip.irq_set_wake = s3c_irqext_wake;
  119. ct->regs.ack = EINT0PEND_OFFSET;
  120. ct->regs.mask = EINT0MASK_OFFSET;
  121. irq_setup_generic_chip(gc, IRQ_MSK(16), IRQ_GC_INIT_MASK_CACHE,
  122. IRQ_NOREQUEST | IRQ_NOPROBE, 0);
  123. return 0;
  124. }
  125. static int __init s5p64x0_init_irq_eint(void)
  126. {
  127. int ret = s5p64x0_alloc_gc();
  128. irq_set_chained_handler(IRQ_EINT0_3, s5p64x0_irq_demux_eint0_3);
  129. irq_set_chained_handler(IRQ_EINT4_11, s5p64x0_irq_demux_eint4_11);
  130. irq_set_chained_handler(IRQ_EINT12_15, s5p64x0_irq_demux_eint12_15);
  131. return ret;
  132. }
  133. arch_initcall(s5p64x0_init_irq_eint);