ams-delta-fiq-handler.S 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * linux/arch/arm/mach-omap1/ams-delta-fiq-handler.S
  3. *
  4. * Based on linux/arch/arm/lib/floppydma.S
  5. * Renamed and modified to work with 2.6 kernel by Matt Callow
  6. * Copyright (C) 1995, 1996 Russell King
  7. * Copyright (C) 2004 Pete Trapps
  8. * Copyright (C) 2006 Matt Callow
  9. * Copyright (C) 2010 Janusz Krzysztofik
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License version 2
  13. * as published by the Free Software Foundation.
  14. */
  15. #include <linux/linkage.h>
  16. #include <linux/platform_data/ams-delta-fiq.h>
  17. #include <asm/assembler.h>
  18. #include <mach/board-ams-delta.h>
  19. #include "ams-delta-fiq.h"
  20. #include "iomap.h"
  21. #include "soc.h"
  22. /*
  23. * GPIO related definitions, copied from arch/arm/plat-omap/gpio.c.
  24. * Unfortunately, those were not placed in a separate header file.
  25. */
  26. #define OMAP1510_GPIO_BASE 0xFFFCE000
  27. #define OMAP1510_GPIO_DATA_INPUT 0x00
  28. #define OMAP1510_GPIO_DATA_OUTPUT 0x04
  29. #define OMAP1510_GPIO_DIR_CONTROL 0x08
  30. #define OMAP1510_GPIO_INT_CONTROL 0x0c
  31. #define OMAP1510_GPIO_INT_MASK 0x10
  32. #define OMAP1510_GPIO_INT_STATUS 0x14
  33. #define OMAP1510_GPIO_PIN_CONTROL 0x18
  34. /* GPIO register bitmasks */
  35. #define KEYBRD_DATA_MASK (0x1 << AMS_DELTA_GPIO_PIN_KEYBRD_DATA)
  36. #define KEYBRD_CLK_MASK (0x1 << AMS_DELTA_GPIO_PIN_KEYBRD_CLK)
  37. #define MODEM_IRQ_MASK (0x1 << AMS_DELTA_GPIO_PIN_MODEM_IRQ)
  38. #define HOOK_SWITCH_MASK (0x1 << AMS_DELTA_GPIO_PIN_HOOK_SWITCH)
  39. #define OTHERS_MASK (MODEM_IRQ_MASK | HOOK_SWITCH_MASK)
  40. /* IRQ handler register bitmasks */
  41. #define DEFERRED_FIQ_MASK OMAP_IRQ_BIT(INT_DEFERRED_FIQ)
  42. #define GPIO_BANK1_MASK OMAP_IRQ_BIT(INT_GPIO_BANK1)
  43. /* Driver buffer byte offsets */
  44. #define BUF_MASK (FIQ_MASK * 4)
  45. #define BUF_STATE (FIQ_STATE * 4)
  46. #define BUF_KEYS_CNT (FIQ_KEYS_CNT * 4)
  47. #define BUF_TAIL_OFFSET (FIQ_TAIL_OFFSET * 4)
  48. #define BUF_HEAD_OFFSET (FIQ_HEAD_OFFSET * 4)
  49. #define BUF_BUF_LEN (FIQ_BUF_LEN * 4)
  50. #define BUF_KEY (FIQ_KEY * 4)
  51. #define BUF_MISSED_KEYS (FIQ_MISSED_KEYS * 4)
  52. #define BUF_BUFFER_START (FIQ_BUFFER_START * 4)
  53. #define BUF_GPIO_INT_MASK (FIQ_GPIO_INT_MASK * 4)
  54. #define BUF_KEYS_HICNT (FIQ_KEYS_HICNT * 4)
  55. #define BUF_IRQ_PEND (FIQ_IRQ_PEND * 4)
  56. #define BUF_SIR_CODE_L1 (FIQ_SIR_CODE_L1 * 4)
  57. #define BUF_SIR_CODE_L2 (IRQ_SIR_CODE_L2 * 4)
  58. #define BUF_CNT_INT_00 (FIQ_CNT_INT_00 * 4)
  59. #define BUF_CNT_INT_KEY (FIQ_CNT_INT_KEY * 4)
  60. #define BUF_CNT_INT_MDM (FIQ_CNT_INT_MDM * 4)
  61. #define BUF_CNT_INT_03 (FIQ_CNT_INT_03 * 4)
  62. #define BUF_CNT_INT_HSW (FIQ_CNT_INT_HSW * 4)
  63. #define BUF_CNT_INT_05 (FIQ_CNT_INT_05 * 4)
  64. #define BUF_CNT_INT_06 (FIQ_CNT_INT_06 * 4)
  65. #define BUF_CNT_INT_07 (FIQ_CNT_INT_07 * 4)
  66. #define BUF_CNT_INT_08 (FIQ_CNT_INT_08 * 4)
  67. #define BUF_CNT_INT_09 (FIQ_CNT_INT_09 * 4)
  68. #define BUF_CNT_INT_10 (FIQ_CNT_INT_10 * 4)
  69. #define BUF_CNT_INT_11 (FIQ_CNT_INT_11 * 4)
  70. #define BUF_CNT_INT_12 (FIQ_CNT_INT_12 * 4)
  71. #define BUF_CNT_INT_13 (FIQ_CNT_INT_13 * 4)
  72. #define BUF_CNT_INT_14 (FIQ_CNT_INT_14 * 4)
  73. #define BUF_CNT_INT_15 (FIQ_CNT_INT_15 * 4)
  74. #define BUF_CIRC_BUFF (FIQ_CIRC_BUFF * 4)
  75. /*
  76. * Register usage
  77. * r8 - temporary
  78. * r9 - the driver buffer
  79. * r10 - temporary
  80. * r11 - interrupts mask
  81. * r12 - base pointers
  82. * r13 - interrupts status
  83. */
  84. .text
  85. .global qwerty_fiqin_end
  86. ENTRY(qwerty_fiqin_start)
  87. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  88. @ FIQ intrrupt handler
  89. ldr r12, omap_ih1_base @ set pointer to level1 handler
  90. ldr r11, [r12, #IRQ_MIR_REG_OFFSET] @ fetch interrupts mask
  91. ldr r13, [r12, #IRQ_ITR_REG_OFFSET] @ fetch interrupts status
  92. bics r13, r13, r11 @ clear masked - any left?
  93. beq exit @ none - spurious FIQ? exit
  94. ldr r10, [r12, #IRQ_SIR_FIQ_REG_OFFSET] @ get requested interrupt number
  95. mov r8, #2 @ reset FIQ agreement
  96. str r8, [r12, #IRQ_CONTROL_REG_OFFSET]
  97. cmp r10, #(INT_GPIO_BANK1 - NR_IRQS_LEGACY) @ is it GPIO interrupt?
  98. beq gpio @ yes - process it
  99. mov r8, #1
  100. orr r8, r11, r8, lsl r10 @ mask spurious interrupt
  101. str r8, [r12, #IRQ_MIR_REG_OFFSET]
  102. exit:
  103. subs pc, lr, #4 @ return from FIQ
  104. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  105. @@@@@@@@@@@@@@@@@@@@@@@@@@@
  106. gpio: @ GPIO bank interrupt handler
  107. ldr r12, omap1510_gpio_base @ set base pointer to GPIO bank
  108. ldr r11, [r12, #OMAP1510_GPIO_INT_MASK] @ fetch GPIO interrupts mask
  109. restart:
  110. ldr r13, [r12, #OMAP1510_GPIO_INT_STATUS] @ fetch status bits
  111. bics r13, r13, r11 @ clear masked - any left?
  112. beq exit @ no - spurious interrupt? exit
  113. orr r11, r11, r13 @ mask all requested interrupts
  114. str r11, [r12, #OMAP1510_GPIO_INT_MASK]
  115. str r13, [r12, #OMAP1510_GPIO_INT_STATUS] @ ack all requested interrupts
  116. ands r10, r13, #KEYBRD_CLK_MASK @ extract keyboard status - set?
  117. beq hksw @ no - try next source
  118. @@@@@@@@@@@@@@@@@@@@@@
  119. @ Keyboard clock FIQ mode interrupt handler
  120. @ r10 now contains KEYBRD_CLK_MASK, use it
  121. bic r11, r11, r10 @ unmask it
  122. str r11, [r12, #OMAP1510_GPIO_INT_MASK]
  123. @ Process keyboard data
  124. ldr r8, [r12, #OMAP1510_GPIO_DATA_INPUT] @ fetch GPIO input
  125. ldr r10, [r9, #BUF_STATE] @ fetch kbd interface state
  126. cmp r10, #0 @ are we expecting start bit?
  127. bne data @ no - go to data processing
  128. ands r8, r8, #KEYBRD_DATA_MASK @ check start bit - detected?
  129. beq hksw @ no - try next source
  130. @ r8 contains KEYBRD_DATA_MASK, use it
  131. str r8, [r9, #BUF_STATE] @ enter data processing state
  132. @ r10 already contains 0, reuse it
  133. str r10, [r9, #BUF_KEY] @ clear keycode
  134. mov r10, #2 @ reset input bit mask
  135. str r10, [r9, #BUF_MASK]
  136. @ Mask other GPIO line interrupts till key done
  137. str r11, [r9, #BUF_GPIO_INT_MASK] @ save mask for later restore
  138. mvn r11, #KEYBRD_CLK_MASK @ prepare all except kbd mask
  139. str r11, [r12, #OMAP1510_GPIO_INT_MASK] @ store into the mask register
  140. b restart @ restart
  141. data: ldr r10, [r9, #BUF_MASK] @ fetch current input bit mask
  142. @ r8 still contains GPIO input bits
  143. ands r8, r8, #KEYBRD_DATA_MASK @ is keyboard data line low?
  144. ldreq r8, [r9, #BUF_KEY] @ yes - fetch collected so far,
  145. orreq r8, r8, r10 @ set 1 at current mask position
  146. streq r8, [r9, #BUF_KEY] @ and save back
  147. mov r10, r10, lsl #1 @ shift mask left
  148. bics r10, r10, #0x800 @ have we got all the bits?
  149. strne r10, [r9, #BUF_MASK] @ not yet - store the mask
  150. bne restart @ and restart
  151. @ r10 already contains 0, reuse it
  152. str r10, [r9, #BUF_STATE] @ reset state to start
  153. @ Key done - restore interrupt mask
  154. ldr r10, [r9, #BUF_GPIO_INT_MASK] @ fetch saved mask
  155. and r11, r11, r10 @ unmask all saved as unmasked
  156. str r11, [r12, #OMAP1510_GPIO_INT_MASK] @ restore into the mask register
  157. @ Try appending the keycode to the circular buffer
  158. ldr r10, [r9, #BUF_KEYS_CNT] @ get saved keystrokes count
  159. ldr r8, [r9, #BUF_BUF_LEN] @ get buffer size
  160. cmp r10, r8 @ is buffer full?
  161. beq hksw @ yes - key lost, next source
  162. add r10, r10, #1 @ incremet keystrokes counter
  163. str r10, [r9, #BUF_KEYS_CNT]
  164. ldr r10, [r9, #BUF_TAIL_OFFSET] @ get buffer tail offset
  165. @ r8 already contains buffer size
  166. cmp r10, r8 @ end of buffer?
  167. moveq r10, #0 @ yes - rewind to buffer start
  168. ldr r12, [r9, #BUF_BUFFER_START] @ get buffer start address
  169. add r12, r12, r10, LSL #2 @ calculate buffer tail address
  170. ldr r8, [r9, #BUF_KEY] @ get last keycode
  171. str r8, [r12] @ append it to the buffer tail
  172. add r10, r10, #1 @ increment buffer tail offset
  173. str r10, [r9, #BUF_TAIL_OFFSET]
  174. ldr r10, [r9, #BUF_CNT_INT_KEY] @ increment interrupts counter
  175. add r10, r10, #1
  176. str r10, [r9, #BUF_CNT_INT_KEY]
  177. @@@@@@@@@@@@@@@@@@@@@@@@
  178. hksw: @Is hook switch interrupt requested?
  179. tst r13, #HOOK_SWITCH_MASK @ is hook switch status bit set?
  180. beq mdm @ no - try next source
  181. @@@@@@@@@@@@@@@@@@@@@@@@
  182. @ Hook switch interrupt FIQ mode simple handler
  183. @ Don't toggle active edge, the switch always bounces
  184. @ Increment hook switch interrupt counter
  185. ldr r10, [r9, #BUF_CNT_INT_HSW]
  186. add r10, r10, #1
  187. str r10, [r9, #BUF_CNT_INT_HSW]
  188. @@@@@@@@@@@@@@@@@@@@@@@@
  189. mdm: @Is it a modem interrupt?
  190. tst r13, #MODEM_IRQ_MASK @ is modem status bit set?
  191. beq irq @ no - check for next interrupt
  192. @@@@@@@@@@@@@@@@@@@@@@@@
  193. @ Modem FIQ mode interrupt handler stub
  194. @ Increment modem interrupt counter
  195. ldr r10, [r9, #BUF_CNT_INT_MDM]
  196. add r10, r10, #1
  197. str r10, [r9, #BUF_CNT_INT_MDM]
  198. @@@@@@@@@@@@@@@@@@@@@@@@
  199. irq: @ Place deferred_fiq interrupt request
  200. ldr r12, deferred_fiq_ih_base @ set pointer to IRQ handler
  201. mov r10, #DEFERRED_FIQ_MASK @ set deferred_fiq bit
  202. str r10, [r12, #IRQ_ISR_REG_OFFSET] @ place it in the ISR register
  203. ldr r12, omap1510_gpio_base @ set pointer back to GPIO bank
  204. b restart @ check for next GPIO interrupt
  205. @@@@@@@@@@@@@@@@@@@@@@@@@@@
  206. /*
  207. * Virtual addresses for IO
  208. */
  209. omap_ih1_base:
  210. .word OMAP1_IO_ADDRESS(OMAP_IH1_BASE)
  211. deferred_fiq_ih_base:
  212. .word OMAP1_IO_ADDRESS(DEFERRED_FIQ_IH_BASE)
  213. omap1510_gpio_base:
  214. .word OMAP1_IO_ADDRESS(OMAP1510_GPIO_BASE)
  215. qwerty_fiqin_end:
  216. /*
  217. * Check the size of the FIQ,
  218. * it cannot go beyond 0xffff0200, and is copied to 0xffff001c
  219. */
  220. .if (qwerty_fiqin_end - qwerty_fiqin_start) > (0x200 - 0x1c)
  221. .err
  222. .endif