ams-delta-fiq.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <plat/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. struct irq_desc *irq_desc;
  41. struct irq_chip *irq_chip = NULL;
  42. int gpio, irq_num, fiq_count;
  43. irq_desc = irq_to_desc(IH_GPIO_BASE);
  44. if (irq_desc)
  45. irq_chip = irq_desc->chip;
  46. /*
  47. * For each handled GPIO interrupt, keep calling its interrupt handler
  48. * until the IRQ counter catches the FIQ incremented interrupt counter.
  49. */
  50. for (gpio = AMS_DELTA_GPIO_PIN_KEYBRD_CLK;
  51. gpio <= AMS_DELTA_GPIO_PIN_HOOK_SWITCH; gpio++) {
  52. irq_num = gpio_to_irq(gpio);
  53. fiq_count = fiq_buffer[FIQ_CNT_INT_00 + gpio];
  54. while (irq_counter[gpio] < fiq_count) {
  55. if (gpio != AMS_DELTA_GPIO_PIN_KEYBRD_CLK) {
  56. /*
  57. * It looks like handle_edge_irq() that
  58. * OMAP GPIO edge interrupts default to,
  59. * expects interrupt already unmasked.
  60. */
  61. if (irq_chip && irq_chip->unmask)
  62. irq_chip->unmask(irq_num);
  63. }
  64. generic_handle_irq(irq_num);
  65. irq_counter[gpio]++;
  66. }
  67. }
  68. return IRQ_HANDLED;
  69. }
  70. void __init ams_delta_init_fiq(void)
  71. {
  72. void *fiqhandler_start;
  73. unsigned int fiqhandler_length;
  74. struct pt_regs FIQ_regs;
  75. unsigned long val, offset;
  76. int i, retval;
  77. fiqhandler_start = &qwerty_fiqin_start;
  78. fiqhandler_length = &qwerty_fiqin_end - &qwerty_fiqin_start;
  79. pr_info("Installing fiq handler from %p, length 0x%x\n",
  80. fiqhandler_start, fiqhandler_length);
  81. retval = claim_fiq(&fh);
  82. if (retval) {
  83. pr_err("ams_delta_init_fiq(): couldn't claim FIQ, ret=%d\n",
  84. retval);
  85. return;
  86. }
  87. retval = request_irq(INT_DEFERRED_FIQ, deferred_fiq,
  88. IRQ_TYPE_EDGE_RISING, "deferred_fiq", 0);
  89. if (retval < 0) {
  90. pr_err("Failed to get deferred_fiq IRQ, ret=%d\n", retval);
  91. release_fiq(&fh);
  92. return;
  93. }
  94. /*
  95. * Since no set_type() method is provided by OMAP irq chip,
  96. * switch to edge triggered interrupt type manually.
  97. */
  98. offset = IRQ_ILR0_REG_OFFSET + INT_DEFERRED_FIQ * 0x4;
  99. val = omap_readl(DEFERRED_FIQ_IH_BASE + offset) & ~(1 << 1);
  100. omap_writel(val, DEFERRED_FIQ_IH_BASE + offset);
  101. set_fiq_handler(fiqhandler_start, fiqhandler_length);
  102. /*
  103. * Initialise the buffer which is shared
  104. * between FIQ mode and IRQ mode
  105. */
  106. fiq_buffer[FIQ_GPIO_INT_MASK] = 0;
  107. fiq_buffer[FIQ_MASK] = 0;
  108. fiq_buffer[FIQ_STATE] = 0;
  109. fiq_buffer[FIQ_KEY] = 0;
  110. fiq_buffer[FIQ_KEYS_CNT] = 0;
  111. fiq_buffer[FIQ_KEYS_HICNT] = 0;
  112. fiq_buffer[FIQ_TAIL_OFFSET] = 0;
  113. fiq_buffer[FIQ_HEAD_OFFSET] = 0;
  114. fiq_buffer[FIQ_BUF_LEN] = 256;
  115. fiq_buffer[FIQ_MISSED_KEYS] = 0;
  116. fiq_buffer[FIQ_BUFFER_START] =
  117. (unsigned int) &fiq_buffer[FIQ_CIRC_BUFF];
  118. for (i = FIQ_CNT_INT_00; i <= FIQ_CNT_INT_15; i++)
  119. fiq_buffer[i] = 0;
  120. /*
  121. * FIQ mode r9 always points to the fiq_buffer, becauses the FIQ isr
  122. * will run in an unpredictable context. The fiq_buffer is the FIQ isr's
  123. * only means of communication with the IRQ level and other kernel
  124. * context code.
  125. */
  126. FIQ_regs.ARM_r9 = (unsigned int)fiq_buffer;
  127. set_fiq_regs(&FIQ_regs);
  128. pr_info("request_fiq(): fiq_buffer = %p\n", fiq_buffer);
  129. /*
  130. * Redirect GPIO interrupts to FIQ
  131. */
  132. offset = IRQ_ILR0_REG_OFFSET + INT_GPIO_BANK1 * 0x4;
  133. val = omap_readl(OMAP_IH1_BASE + offset) | 1;
  134. omap_writel(val, OMAP_IH1_BASE + offset);
  135. }