ams-delta-fiq.c 4.3 KB

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