intc-525x.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * intc2.c -- support for the 2nd INTC controller of the 525x
  3. *
  4. * (C) Copyright 2012, Steven King <sfking@fdwdc.com>
  5. * (C) Copyright 2009, Greg Ungerer <gerg@snapgear.com>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <linux/io.h>
  17. #include <asm/coldfire.h>
  18. #include <asm/mcfsim.h>
  19. static void intc2_irq_gpio_mask(struct irq_data *d)
  20. {
  21. u32 imr = readl(MCFSIM2_GPIOINTENABLE);
  22. u32 type = irqd_get_trigger_type(d);
  23. int irq = d->irq - MCF_IRQ_GPIO0;
  24. if (type & IRQ_TYPE_EDGE_RISING)
  25. imr &= ~(0x001 << irq);
  26. if (type & IRQ_TYPE_EDGE_FALLING)
  27. imr &= ~(0x100 << irq);
  28. writel(imr, MCFSIM2_GPIOINTENABLE);
  29. }
  30. static void intc2_irq_gpio_unmask(struct irq_data *d)
  31. {
  32. u32 imr = readl(MCFSIM2_GPIOINTENABLE);
  33. u32 type = irqd_get_trigger_type(d);
  34. int irq = d->irq - MCF_IRQ_GPIO0;
  35. if (type & IRQ_TYPE_EDGE_RISING)
  36. imr |= (0x001 << irq);
  37. if (type & IRQ_TYPE_EDGE_FALLING)
  38. imr |= (0x100 << irq);
  39. writel(imr, MCFSIM2_GPIOINTENABLE);
  40. }
  41. static void intc2_irq_gpio_ack(struct irq_data *d)
  42. {
  43. u32 imr = 0;
  44. u32 type = irqd_get_trigger_type(d);
  45. int irq = d->irq - MCF_IRQ_GPIO0;
  46. if (type & IRQ_TYPE_EDGE_RISING)
  47. imr |= (0x001 << irq);
  48. if (type & IRQ_TYPE_EDGE_FALLING)
  49. imr |= (0x100 << irq);
  50. writel(imr, MCFSIM2_GPIOINTCLEAR);
  51. }
  52. static int intc2_irq_gpio_set_type(struct irq_data *d, unsigned int f)
  53. {
  54. if (f & ~IRQ_TYPE_EDGE_BOTH)
  55. return -EINVAL;
  56. return 0;
  57. }
  58. static struct irq_chip intc2_irq_gpio_chip = {
  59. .name = "CF-INTC2",
  60. .irq_mask = intc2_irq_gpio_mask,
  61. .irq_unmask = intc2_irq_gpio_unmask,
  62. .irq_ack = intc2_irq_gpio_ack,
  63. .irq_set_type = intc2_irq_gpio_set_type,
  64. };
  65. static int __init mcf_intc2_init(void)
  66. {
  67. int irq;
  68. /* set the interrupt base for the second interrupt controller */
  69. writel(MCFINTC2_VECBASE, MCFINTC2_INTBASE);
  70. /* GPIO interrupt sources */
  71. for (irq = MCF_IRQ_GPIO0; (irq <= MCF_IRQ_GPIO6); irq++) {
  72. irq_set_chip(irq, &intc2_irq_gpio_chip);
  73. irq_set_handler(irq, handle_edge_irq);
  74. }
  75. return 0;
  76. }
  77. arch_initcall(mcf_intc2_init);