ams-delta-fiq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Amstrad E3 FIQ handling
  3. *
  4. * Copyright (C) 2009 Janusz Krzysztofik
  5. * Copyright (c) 2006 Matt Callow
  6. * Copyright (c) 2004 Amstrad Plc
  7. * Copyright (C) 2001 RidgeRun, Inc.
  8. *
  9. * Parts of this code are taken from linux/arch/arm/mach-omap/irq.c
  10. * in the MontaVista 2.4 kernel (and the Amstrad changes therein)
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License version 2 as published by
  14. * the Free Software Foundation.
  15. */
  16. #include <linux/gpio.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/irq.h>
  19. #include <linux/module.h>
  20. #include <linux/io.h>
  21. #include <mach/board-ams-delta.h>
  22. #include <asm/fiq.h>
  23. #include <mach/ams-delta-fiq.h>
  24. static struct fiq_handler fh = {
  25. .name = "ams-delta-fiq"
  26. };
  27. /*
  28. * This buffer is shared between FIQ and IRQ contexts.
  29. * The FIQ and IRQ isrs can both read and write it.
  30. * It is structured as a header section several 32bit slots,
  31. * followed by the circular buffer where the FIQ isr stores
  32. * keystrokes received from the qwerty keyboard.
  33. * See ams-delta-fiq.h for details of offsets.
  34. */
  35. unsigned int fiq_buffer[1024];
  36. EXPORT_SYMBOL(fiq_buffer);
  37. static unsigned int irq_counter[16];
  38. static irqreturn_t deferred_fiq(int irq, void *dev_id)
  39. {
  40. int gpio, irq_num, fiq_count;
  41. struct irq_chip *irq_chip;
  42. irq_chip = irq_get_chip(gpio_to_irq(AMS_DELTA_GPIO_PIN_KEYBRD_CLK));
  43. /*
  44. * For each handled GPIO interrupt, keep calling its interrupt handler
  45. * until the IRQ counter catches the FIQ incremented interrupt counter.
  46. */
  47. for (gpio = AMS_DELTA_GPIO_PIN_KEYBRD_CLK;
  48. gpio <= AMS_DELTA_GPIO_PIN_HOOK_SWITCH; gpio++) {
  49. irq_num = gpio_to_irq(gpio);
  50. fiq_count = fiq_buffer[FIQ_CNT_INT_00 + gpio];
  51. while (irq_counter[gpio] < fiq_count) {
  52. if (gpio != AMS_DELTA_GPIO_PIN_KEYBRD_CLK) {
  53. struct irq_data *d = irq_get_irq_data(irq_num);
  54. /*
  55. * It looks like handle_edge_irq() that
  56. * OMAP GPIO edge interrupts default to,
  57. * expects interrupt already unmasked.
  58. */
  59. if (irq_chip && irq_chip->irq_unmask)
  60. irq_chip->irq_unmask(d);
  61. }
  62. generic_handle_irq(irq_num);
  63. irq_counter[gpio]++;
  64. }
  65. }
  66. return IRQ_HANDLED;
  67. }
  68. void __init ams_delta_init_fiq(void)
  69. {
  70. void *fiqhandler_start;
  71. unsigned int fiqhandler_length;
  72. struct pt_regs FIQ_regs;
  73. unsigned long val, offset;
  74. int i, retval;
  75. fiqhandler_start = &qwerty_fiqin_start;
  76. fiqhandler_length = &qwerty_fiqin_end - &qwerty_fiqin_start;
  77. pr_info("Installing fiq handler from %p, length 0x%x\n",
  78. fiqhandler_start, fiqhandler_length);
  79. retval = claim_fiq(&fh);
  80. if (retval) {
  81. pr_err("ams_delta_init_fiq(): couldn't claim FIQ, ret=%d\n",
  82. retval);
  83. return;
  84. }
  85. retval = request_irq(INT_DEFERRED_FIQ, deferred_fiq,
  86. IRQ_TYPE_EDGE_RISING, "deferred_fiq", NULL);
  87. if (retval < 0) {
  88. pr_err("Failed to get deferred_fiq IRQ, ret=%d\n", retval);
  89. release_fiq(&fh);
  90. return;
  91. }
  92. /*
  93. * Since no set_type() method is provided by OMAP irq chip,
  94. * switch to edge triggered interrupt type manually.
  95. */
  96. offset = IRQ_ILR0_REG_OFFSET +
  97. ((INT_DEFERRED_FIQ - NR_IRQS_LEGACY) & 0x1f) * 0x4;
  98. val = omap_readl(DEFERRED_FIQ_IH_BASE + offset) & ~(1 << 1);
  99. omap_writel(val, DEFERRED_FIQ_IH_BASE + offset);
  100. set_fiq_handler(fiqhandler_start, fiqhandler_length);
  101. /*
  102. * Initialise the buffer which is shared
  103. * between FIQ mode and IRQ mode
  104. */
  105. fiq_buffer[FIQ_GPIO_INT_MASK] = 0;
  106. fiq_buffer[FIQ_MASK] = 0;
  107. fiq_buffer[FIQ_STATE] = 0;
  108. fiq_buffer[FIQ_KEY] = 0;
  109. fiq_buffer[FIQ_KEYS_CNT] = 0;
  110. fiq_buffer[FIQ_KEYS_HICNT] = 0;
  111. fiq_buffer[FIQ_TAIL_OFFSET] = 0;
  112. fiq_buffer[FIQ_HEAD_OFFSET] = 0;
  113. fiq_buffer[FIQ_BUF_LEN] = 256;
  114. fiq_buffer[FIQ_MISSED_KEYS] = 0;
  115. fiq_buffer[FIQ_BUFFER_START] =
  116. (unsigned int) &fiq_buffer[FIQ_CIRC_BUFF];
  117. for (i = FIQ_CNT_INT_00; i <= FIQ_CNT_INT_15; i++)
  118. fiq_buffer[i] = 0;
  119. /*
  120. * FIQ mode r9 always points to the fiq_buffer, because the FIQ isr
  121. * will run in an unpredictable context. The fiq_buffer is the FIQ isr's
  122. * only means of communication with the IRQ level and other kernel
  123. * context code.
  124. */
  125. FIQ_regs.ARM_r9 = (unsigned int)fiq_buffer;
  126. set_fiq_regs(&FIQ_regs);
  127. pr_info("request_fiq(): fiq_buffer = %p\n", fiq_buffer);
  128. /*
  129. * Redirect GPIO interrupts to FIQ
  130. */
  131. offset = IRQ_ILR0_REG_OFFSET + (INT_GPIO_BANK1 - NR_IRQS_LEGACY) * 0x4;
  132. val = omap_readl(OMAP_IH1_BASE + offset) | 1;
  133. omap_writel(val, OMAP_IH1_BASE + offset);
  134. }