irq.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. /*
  2. * Copyright 2001, 2007-2008 MontaVista Software Inc.
  3. * Author: MontaVista Software, Inc. <source@mvista.com>
  4. *
  5. * Copyright (C) 2007 Ralf Baechle (ralf@linux-mips.org)
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  13. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  15. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  18. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  19. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #include <linux/export.h>
  28. #include <linux/init.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/slab.h>
  31. #include <linux/syscore_ops.h>
  32. #include <asm/irq_cpu.h>
  33. #include <asm/mach-au1x00/au1000.h>
  34. #include <asm/mach-au1x00/gpio-au1300.h>
  35. /* Interrupt Controller register offsets */
  36. #define IC_CFG0RD 0x40
  37. #define IC_CFG0SET 0x40
  38. #define IC_CFG0CLR 0x44
  39. #define IC_CFG1RD 0x48
  40. #define IC_CFG1SET 0x48
  41. #define IC_CFG1CLR 0x4C
  42. #define IC_CFG2RD 0x50
  43. #define IC_CFG2SET 0x50
  44. #define IC_CFG2CLR 0x54
  45. #define IC_REQ0INT 0x54
  46. #define IC_SRCRD 0x58
  47. #define IC_SRCSET 0x58
  48. #define IC_SRCCLR 0x5C
  49. #define IC_REQ1INT 0x5C
  50. #define IC_ASSIGNRD 0x60
  51. #define IC_ASSIGNSET 0x60
  52. #define IC_ASSIGNCLR 0x64
  53. #define IC_WAKERD 0x68
  54. #define IC_WAKESET 0x68
  55. #define IC_WAKECLR 0x6C
  56. #define IC_MASKRD 0x70
  57. #define IC_MASKSET 0x70
  58. #define IC_MASKCLR 0x74
  59. #define IC_RISINGRD 0x78
  60. #define IC_RISINGCLR 0x78
  61. #define IC_FALLINGRD 0x7C
  62. #define IC_FALLINGCLR 0x7C
  63. #define IC_TESTBIT 0x80
  64. /* per-processor fixed function irqs */
  65. struct alchemy_irqmap {
  66. int irq; /* linux IRQ number */
  67. int type; /* IRQ_TYPE_ */
  68. int prio; /* irq priority, 0 highest, 3 lowest */
  69. int internal; /* GPIC: internal source (no ext. pin)? */
  70. };
  71. static int au1x_ic_settype(struct irq_data *d, unsigned int type);
  72. static int au1300_gpic_settype(struct irq_data *d, unsigned int type);
  73. /* NOTE on interrupt priorities: The original writers of this code said:
  74. *
  75. * Because of the tight timing of SETUP token to reply transactions,
  76. * the USB devices-side packet complete interrupt (USB_DEV_REQ_INT)
  77. * needs the highest priority.
  78. */
  79. struct alchemy_irqmap au1000_irqmap[] __initdata = {
  80. { AU1000_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  81. { AU1000_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  82. { AU1000_UART2_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  83. { AU1000_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  84. { AU1000_SSI0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  85. { AU1000_SSI1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  86. { AU1000_DMA_INT_BASE, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  87. { AU1000_DMA_INT_BASE+1, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  88. { AU1000_DMA_INT_BASE+2, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  89. { AU1000_DMA_INT_BASE+3, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  90. { AU1000_DMA_INT_BASE+4, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  91. { AU1000_DMA_INT_BASE+5, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  92. { AU1000_DMA_INT_BASE+6, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  93. { AU1000_DMA_INT_BASE+7, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  94. { AU1000_TOY_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  95. { AU1000_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  96. { AU1000_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  97. { AU1000_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  98. { AU1000_RTC_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  99. { AU1000_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  100. { AU1000_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  101. { AU1000_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0, 0 },
  102. { AU1000_IRDA_TX_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  103. { AU1000_IRDA_RX_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  104. { AU1000_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH, 0, 0 },
  105. { AU1000_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  106. { AU1000_USB_HOST_INT, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  107. { AU1000_ACSYNC_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  108. { AU1000_MAC0_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  109. { AU1000_MAC1_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  110. { AU1000_AC97C_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  111. { -1, },
  112. };
  113. struct alchemy_irqmap au1500_irqmap[] __initdata = {
  114. { AU1500_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  115. { AU1500_PCI_INTA, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  116. { AU1500_PCI_INTB, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  117. { AU1500_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  118. { AU1500_PCI_INTC, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  119. { AU1500_PCI_INTD, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  120. { AU1500_DMA_INT_BASE, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  121. { AU1500_DMA_INT_BASE+1, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  122. { AU1500_DMA_INT_BASE+2, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  123. { AU1500_DMA_INT_BASE+3, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  124. { AU1500_DMA_INT_BASE+4, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  125. { AU1500_DMA_INT_BASE+5, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  126. { AU1500_DMA_INT_BASE+6, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  127. { AU1500_DMA_INT_BASE+7, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  128. { AU1500_TOY_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  129. { AU1500_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  130. { AU1500_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  131. { AU1500_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  132. { AU1500_RTC_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  133. { AU1500_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  134. { AU1500_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  135. { AU1500_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0, 0 },
  136. { AU1500_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH, 0, 0 },
  137. { AU1500_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  138. { AU1500_USB_HOST_INT, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  139. { AU1500_ACSYNC_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  140. { AU1500_MAC0_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  141. { AU1500_MAC1_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  142. { AU1500_AC97C_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  143. { -1, },
  144. };
  145. struct alchemy_irqmap au1100_irqmap[] __initdata = {
  146. { AU1100_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  147. { AU1100_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  148. { AU1100_SD_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  149. { AU1100_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  150. { AU1100_SSI0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  151. { AU1100_SSI1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  152. { AU1100_DMA_INT_BASE, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  153. { AU1100_DMA_INT_BASE+1, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  154. { AU1100_DMA_INT_BASE+2, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  155. { AU1100_DMA_INT_BASE+3, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  156. { AU1100_DMA_INT_BASE+4, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  157. { AU1100_DMA_INT_BASE+5, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  158. { AU1100_DMA_INT_BASE+6, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  159. { AU1100_DMA_INT_BASE+7, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  160. { AU1100_TOY_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  161. { AU1100_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  162. { AU1100_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  163. { AU1100_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  164. { AU1100_RTC_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  165. { AU1100_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  166. { AU1100_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  167. { AU1100_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0, 0 },
  168. { AU1100_IRDA_TX_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  169. { AU1100_IRDA_RX_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  170. { AU1100_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH, 0, 0 },
  171. { AU1100_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  172. { AU1100_USB_HOST_INT, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  173. { AU1100_ACSYNC_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  174. { AU1100_MAC0_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  175. { AU1100_LCD_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  176. { AU1100_AC97C_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  177. { -1, },
  178. };
  179. struct alchemy_irqmap au1550_irqmap[] __initdata = {
  180. { AU1550_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  181. { AU1550_PCI_INTA, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  182. { AU1550_PCI_INTB, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  183. { AU1550_DDMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  184. { AU1550_CRYPTO_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  185. { AU1550_PCI_INTC, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  186. { AU1550_PCI_INTD, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  187. { AU1550_PCI_RST_INT, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  188. { AU1550_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  189. { AU1550_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  190. { AU1550_PSC0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  191. { AU1550_PSC1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  192. { AU1550_PSC2_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  193. { AU1550_PSC3_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  194. { AU1550_TOY_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  195. { AU1550_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  196. { AU1550_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  197. { AU1550_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  198. { AU1550_RTC_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  199. { AU1550_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  200. { AU1550_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  201. { AU1550_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0, 0 },
  202. { AU1550_NAND_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  203. { AU1550_USB_DEV_REQ_INT, IRQ_TYPE_LEVEL_HIGH, 0, 0 },
  204. { AU1550_USB_DEV_SUS_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  205. { AU1550_USB_HOST_INT, IRQ_TYPE_LEVEL_LOW, 1, 0 },
  206. { AU1550_MAC0_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  207. { AU1550_MAC1_DMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  208. { -1, },
  209. };
  210. struct alchemy_irqmap au1200_irqmap[] __initdata = {
  211. { AU1200_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  212. { AU1200_SWT_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  213. { AU1200_SD_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  214. { AU1200_DDMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  215. { AU1200_MAE_BE_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  216. { AU1200_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  217. { AU1200_MAE_FE_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  218. { AU1200_PSC0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  219. { AU1200_PSC1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  220. { AU1200_AES_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  221. { AU1200_CAMERA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  222. { AU1200_TOY_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  223. { AU1200_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  224. { AU1200_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  225. { AU1200_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  226. { AU1200_RTC_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  227. { AU1200_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  228. { AU1200_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  229. { AU1200_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0, 0 },
  230. { AU1200_NAND_INT, IRQ_TYPE_EDGE_RISING, 1, 0 },
  231. { AU1200_USB_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  232. { AU1200_LCD_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  233. { AU1200_MAE_BOTH_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0 },
  234. { -1, },
  235. };
  236. static struct alchemy_irqmap au1300_irqmap[] __initdata = {
  237. /* multifunction: gpio pin or device */
  238. { AU1300_UART1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  239. { AU1300_UART2_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  240. { AU1300_UART3_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  241. { AU1300_SD1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  242. { AU1300_SD2_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  243. { AU1300_PSC0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  244. { AU1300_PSC1_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  245. { AU1300_PSC2_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  246. { AU1300_PSC3_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  247. { AU1300_NAND_INT, IRQ_TYPE_LEVEL_HIGH, 1, 0, },
  248. /* au1300 internal */
  249. { AU1300_DDMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  250. { AU1300_MMU_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  251. { AU1300_MPU_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  252. { AU1300_GPU_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  253. { AU1300_UDMA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  254. { AU1300_TOY_INT, IRQ_TYPE_EDGE_RISING, 1, 1, },
  255. { AU1300_TOY_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 1, },
  256. { AU1300_TOY_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 1, },
  257. { AU1300_TOY_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 1, 1, },
  258. { AU1300_RTC_INT, IRQ_TYPE_EDGE_RISING, 1, 1, },
  259. { AU1300_RTC_MATCH0_INT, IRQ_TYPE_EDGE_RISING, 1, 1, },
  260. { AU1300_RTC_MATCH1_INT, IRQ_TYPE_EDGE_RISING, 1, 1, },
  261. { AU1300_RTC_MATCH2_INT, IRQ_TYPE_EDGE_RISING, 0, 1, },
  262. { AU1300_UART0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  263. { AU1300_SD0_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  264. { AU1300_USB_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  265. { AU1300_LCD_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  266. { AU1300_BSA_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  267. { AU1300_MPE_INT, IRQ_TYPE_EDGE_RISING, 1, 1, },
  268. { AU1300_ITE_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  269. { AU1300_AES_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  270. { AU1300_CIM_INT, IRQ_TYPE_LEVEL_HIGH, 1, 1, },
  271. { -1, }, /* terminator */
  272. };
  273. /******************************************************************************/
  274. static void au1x_ic0_unmask(struct irq_data *d)
  275. {
  276. unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
  277. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
  278. __raw_writel(1 << bit, base + IC_MASKSET);
  279. __raw_writel(1 << bit, base + IC_WAKESET);
  280. wmb();
  281. }
  282. static void au1x_ic1_unmask(struct irq_data *d)
  283. {
  284. unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
  285. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
  286. __raw_writel(1 << bit, base + IC_MASKSET);
  287. __raw_writel(1 << bit, base + IC_WAKESET);
  288. wmb();
  289. }
  290. static void au1x_ic0_mask(struct irq_data *d)
  291. {
  292. unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
  293. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
  294. __raw_writel(1 << bit, base + IC_MASKCLR);
  295. __raw_writel(1 << bit, base + IC_WAKECLR);
  296. wmb();
  297. }
  298. static void au1x_ic1_mask(struct irq_data *d)
  299. {
  300. unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
  301. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
  302. __raw_writel(1 << bit, base + IC_MASKCLR);
  303. __raw_writel(1 << bit, base + IC_WAKECLR);
  304. wmb();
  305. }
  306. static void au1x_ic0_ack(struct irq_data *d)
  307. {
  308. unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
  309. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
  310. /*
  311. * This may assume that we don't get interrupts from
  312. * both edges at once, or if we do, that we don't care.
  313. */
  314. __raw_writel(1 << bit, base + IC_FALLINGCLR);
  315. __raw_writel(1 << bit, base + IC_RISINGCLR);
  316. wmb();
  317. }
  318. static void au1x_ic1_ack(struct irq_data *d)
  319. {
  320. unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
  321. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
  322. /*
  323. * This may assume that we don't get interrupts from
  324. * both edges at once, or if we do, that we don't care.
  325. */
  326. __raw_writel(1 << bit, base + IC_FALLINGCLR);
  327. __raw_writel(1 << bit, base + IC_RISINGCLR);
  328. wmb();
  329. }
  330. static void au1x_ic0_maskack(struct irq_data *d)
  331. {
  332. unsigned int bit = d->irq - AU1000_INTC0_INT_BASE;
  333. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
  334. __raw_writel(1 << bit, base + IC_WAKECLR);
  335. __raw_writel(1 << bit, base + IC_MASKCLR);
  336. __raw_writel(1 << bit, base + IC_RISINGCLR);
  337. __raw_writel(1 << bit, base + IC_FALLINGCLR);
  338. wmb();
  339. }
  340. static void au1x_ic1_maskack(struct irq_data *d)
  341. {
  342. unsigned int bit = d->irq - AU1000_INTC1_INT_BASE;
  343. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
  344. __raw_writel(1 << bit, base + IC_WAKECLR);
  345. __raw_writel(1 << bit, base + IC_MASKCLR);
  346. __raw_writel(1 << bit, base + IC_RISINGCLR);
  347. __raw_writel(1 << bit, base + IC_FALLINGCLR);
  348. wmb();
  349. }
  350. static int au1x_ic1_setwake(struct irq_data *d, unsigned int on)
  351. {
  352. int bit = d->irq - AU1000_INTC1_INT_BASE;
  353. unsigned long wakemsk, flags;
  354. /* only GPIO 0-7 can act as wakeup source. Fortunately these
  355. * are wired up identically on all supported variants.
  356. */
  357. if ((bit < 0) || (bit > 7))
  358. return -EINVAL;
  359. local_irq_save(flags);
  360. wakemsk = alchemy_rdsys(AU1000_SYS_WAKEMSK);
  361. if (on)
  362. wakemsk |= 1 << bit;
  363. else
  364. wakemsk &= ~(1 << bit);
  365. alchemy_wrsys(wakemsk, AU1000_SYS_WAKEMSK);
  366. local_irq_restore(flags);
  367. return 0;
  368. }
  369. /*
  370. * irq_chips for both ICs; this way the mask handlers can be
  371. * as short as possible.
  372. */
  373. static struct irq_chip au1x_ic0_chip = {
  374. .name = "Alchemy-IC0",
  375. .irq_ack = au1x_ic0_ack,
  376. .irq_mask = au1x_ic0_mask,
  377. .irq_mask_ack = au1x_ic0_maskack,
  378. .irq_unmask = au1x_ic0_unmask,
  379. .irq_set_type = au1x_ic_settype,
  380. };
  381. static struct irq_chip au1x_ic1_chip = {
  382. .name = "Alchemy-IC1",
  383. .irq_ack = au1x_ic1_ack,
  384. .irq_mask = au1x_ic1_mask,
  385. .irq_mask_ack = au1x_ic1_maskack,
  386. .irq_unmask = au1x_ic1_unmask,
  387. .irq_set_type = au1x_ic_settype,
  388. .irq_set_wake = au1x_ic1_setwake,
  389. };
  390. static int au1x_ic_settype(struct irq_data *d, unsigned int flow_type)
  391. {
  392. struct irq_chip *chip;
  393. unsigned int bit, irq = d->irq;
  394. irq_flow_handler_t handler = NULL;
  395. unsigned char *name = NULL;
  396. void __iomem *base;
  397. int ret;
  398. if (irq >= AU1000_INTC1_INT_BASE) {
  399. bit = irq - AU1000_INTC1_INT_BASE;
  400. chip = &au1x_ic1_chip;
  401. base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
  402. } else {
  403. bit = irq - AU1000_INTC0_INT_BASE;
  404. chip = &au1x_ic0_chip;
  405. base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
  406. }
  407. if (bit > 31)
  408. return -EINVAL;
  409. ret = 0;
  410. switch (flow_type) { /* cfgregs 2:1:0 */
  411. case IRQ_TYPE_EDGE_RISING: /* 0:0:1 */
  412. __raw_writel(1 << bit, base + IC_CFG2CLR);
  413. __raw_writel(1 << bit, base + IC_CFG1CLR);
  414. __raw_writel(1 << bit, base + IC_CFG0SET);
  415. handler = handle_edge_irq;
  416. name = "riseedge";
  417. break;
  418. case IRQ_TYPE_EDGE_FALLING: /* 0:1:0 */
  419. __raw_writel(1 << bit, base + IC_CFG2CLR);
  420. __raw_writel(1 << bit, base + IC_CFG1SET);
  421. __raw_writel(1 << bit, base + IC_CFG0CLR);
  422. handler = handle_edge_irq;
  423. name = "falledge";
  424. break;
  425. case IRQ_TYPE_EDGE_BOTH: /* 0:1:1 */
  426. __raw_writel(1 << bit, base + IC_CFG2CLR);
  427. __raw_writel(1 << bit, base + IC_CFG1SET);
  428. __raw_writel(1 << bit, base + IC_CFG0SET);
  429. handler = handle_edge_irq;
  430. name = "bothedge";
  431. break;
  432. case IRQ_TYPE_LEVEL_HIGH: /* 1:0:1 */
  433. __raw_writel(1 << bit, base + IC_CFG2SET);
  434. __raw_writel(1 << bit, base + IC_CFG1CLR);
  435. __raw_writel(1 << bit, base + IC_CFG0SET);
  436. handler = handle_level_irq;
  437. name = "hilevel";
  438. break;
  439. case IRQ_TYPE_LEVEL_LOW: /* 1:1:0 */
  440. __raw_writel(1 << bit, base + IC_CFG2SET);
  441. __raw_writel(1 << bit, base + IC_CFG1SET);
  442. __raw_writel(1 << bit, base + IC_CFG0CLR);
  443. handler = handle_level_irq;
  444. name = "lowlevel";
  445. break;
  446. case IRQ_TYPE_NONE: /* 0:0:0 */
  447. __raw_writel(1 << bit, base + IC_CFG2CLR);
  448. __raw_writel(1 << bit, base + IC_CFG1CLR);
  449. __raw_writel(1 << bit, base + IC_CFG0CLR);
  450. break;
  451. default:
  452. ret = -EINVAL;
  453. }
  454. irq_set_chip_handler_name_locked(d, chip, handler, name);
  455. wmb();
  456. return ret;
  457. }
  458. /******************************************************************************/
  459. /*
  460. * au1300_gpic_chgcfg - change PIN configuration.
  461. * @gpio: pin to change (0-based GPIO number from datasheet).
  462. * @clr: clear all bits set in 'clr'.
  463. * @set: set these bits.
  464. *
  465. * modifies a pins' configuration register, bits set in @clr will
  466. * be cleared in the register, bits in @set will be set.
  467. */
  468. static inline void au1300_gpic_chgcfg(unsigned int gpio,
  469. unsigned long clr,
  470. unsigned long set)
  471. {
  472. void __iomem *r = AU1300_GPIC_ADDR;
  473. unsigned long l;
  474. r += gpio * 4; /* offset into pin config array */
  475. l = __raw_readl(r + AU1300_GPIC_PINCFG);
  476. l &= ~clr;
  477. l |= set;
  478. __raw_writel(l, r + AU1300_GPIC_PINCFG);
  479. wmb();
  480. }
  481. /*
  482. * au1300_pinfunc_to_gpio - assign a pin as GPIO input (GPIO ctrl).
  483. * @pin: pin (0-based GPIO number from datasheet).
  484. *
  485. * Assigns a GPIO pin to the GPIO controller, so its level can either
  486. * be read or set through the generic GPIO functions.
  487. * If you need a GPOUT, use au1300_gpio_set_value(pin, 0/1).
  488. * REVISIT: is this function really necessary?
  489. */
  490. void au1300_pinfunc_to_gpio(enum au1300_multifunc_pins gpio)
  491. {
  492. au1300_gpio_direction_input(gpio + AU1300_GPIO_BASE);
  493. }
  494. EXPORT_SYMBOL_GPL(au1300_pinfunc_to_gpio);
  495. /*
  496. * au1300_pinfunc_to_dev - assign a pin to the device function.
  497. * @pin: pin (0-based GPIO number from datasheet).
  498. *
  499. * Assigns a GPIO pin to its associated device function; the pin will be
  500. * driven by the device and not through GPIO functions.
  501. */
  502. void au1300_pinfunc_to_dev(enum au1300_multifunc_pins gpio)
  503. {
  504. void __iomem *r = AU1300_GPIC_ADDR;
  505. unsigned long bit;
  506. r += GPIC_GPIO_BANKOFF(gpio);
  507. bit = GPIC_GPIO_TO_BIT(gpio);
  508. __raw_writel(bit, r + AU1300_GPIC_DEVSEL);
  509. wmb();
  510. }
  511. EXPORT_SYMBOL_GPL(au1300_pinfunc_to_dev);
  512. /*
  513. * au1300_set_irq_priority - set internal priority of IRQ.
  514. * @irq: irq to set priority (linux irq number).
  515. * @p: priority (0 = highest, 3 = lowest).
  516. */
  517. void au1300_set_irq_priority(unsigned int irq, int p)
  518. {
  519. irq -= ALCHEMY_GPIC_INT_BASE;
  520. au1300_gpic_chgcfg(irq, GPIC_CFG_IL_MASK, GPIC_CFG_IL_SET(p));
  521. }
  522. EXPORT_SYMBOL_GPL(au1300_set_irq_priority);
  523. /*
  524. * au1300_set_dbdma_gpio - assign a gpio to one of the DBDMA triggers.
  525. * @dchan: dbdma trigger select (0, 1).
  526. * @gpio: pin to assign as trigger.
  527. *
  528. * DBDMA controller has 2 external trigger sources; this function
  529. * assigns a GPIO to the selected trigger.
  530. */
  531. void au1300_set_dbdma_gpio(int dchan, unsigned int gpio)
  532. {
  533. unsigned long r;
  534. if ((dchan >= 0) && (dchan <= 1)) {
  535. r = __raw_readl(AU1300_GPIC_ADDR + AU1300_GPIC_DMASEL);
  536. r &= ~(0xff << (8 * dchan));
  537. r |= (gpio & 0x7f) << (8 * dchan);
  538. __raw_writel(r, AU1300_GPIC_ADDR + AU1300_GPIC_DMASEL);
  539. wmb();
  540. }
  541. }
  542. static inline void gpic_pin_set_idlewake(unsigned int gpio, int allow)
  543. {
  544. au1300_gpic_chgcfg(gpio, GPIC_CFG_IDLEWAKE,
  545. allow ? GPIC_CFG_IDLEWAKE : 0);
  546. }
  547. static void au1300_gpic_mask(struct irq_data *d)
  548. {
  549. void __iomem *r = AU1300_GPIC_ADDR;
  550. unsigned long bit, irq = d->irq;
  551. irq -= ALCHEMY_GPIC_INT_BASE;
  552. r += GPIC_GPIO_BANKOFF(irq);
  553. bit = GPIC_GPIO_TO_BIT(irq);
  554. __raw_writel(bit, r + AU1300_GPIC_IDIS);
  555. wmb();
  556. gpic_pin_set_idlewake(irq, 0);
  557. }
  558. static void au1300_gpic_unmask(struct irq_data *d)
  559. {
  560. void __iomem *r = AU1300_GPIC_ADDR;
  561. unsigned long bit, irq = d->irq;
  562. irq -= ALCHEMY_GPIC_INT_BASE;
  563. gpic_pin_set_idlewake(irq, 1);
  564. r += GPIC_GPIO_BANKOFF(irq);
  565. bit = GPIC_GPIO_TO_BIT(irq);
  566. __raw_writel(bit, r + AU1300_GPIC_IEN);
  567. wmb();
  568. }
  569. static void au1300_gpic_maskack(struct irq_data *d)
  570. {
  571. void __iomem *r = AU1300_GPIC_ADDR;
  572. unsigned long bit, irq = d->irq;
  573. irq -= ALCHEMY_GPIC_INT_BASE;
  574. r += GPIC_GPIO_BANKOFF(irq);
  575. bit = GPIC_GPIO_TO_BIT(irq);
  576. __raw_writel(bit, r + AU1300_GPIC_IPEND); /* ack */
  577. __raw_writel(bit, r + AU1300_GPIC_IDIS); /* mask */
  578. wmb();
  579. gpic_pin_set_idlewake(irq, 0);
  580. }
  581. static void au1300_gpic_ack(struct irq_data *d)
  582. {
  583. void __iomem *r = AU1300_GPIC_ADDR;
  584. unsigned long bit, irq = d->irq;
  585. irq -= ALCHEMY_GPIC_INT_BASE;
  586. r += GPIC_GPIO_BANKOFF(irq);
  587. bit = GPIC_GPIO_TO_BIT(irq);
  588. __raw_writel(bit, r + AU1300_GPIC_IPEND); /* ack */
  589. wmb();
  590. }
  591. static struct irq_chip au1300_gpic = {
  592. .name = "GPIOINT",
  593. .irq_ack = au1300_gpic_ack,
  594. .irq_mask = au1300_gpic_mask,
  595. .irq_mask_ack = au1300_gpic_maskack,
  596. .irq_unmask = au1300_gpic_unmask,
  597. .irq_set_type = au1300_gpic_settype,
  598. };
  599. static int au1300_gpic_settype(struct irq_data *d, unsigned int type)
  600. {
  601. unsigned long s;
  602. unsigned char *name = NULL;
  603. irq_flow_handler_t hdl = NULL;
  604. switch (type) {
  605. case IRQ_TYPE_LEVEL_HIGH:
  606. s = GPIC_CFG_IC_LEVEL_HIGH;
  607. name = "high";
  608. hdl = handle_level_irq;
  609. break;
  610. case IRQ_TYPE_LEVEL_LOW:
  611. s = GPIC_CFG_IC_LEVEL_LOW;
  612. name = "low";
  613. hdl = handle_level_irq;
  614. break;
  615. case IRQ_TYPE_EDGE_RISING:
  616. s = GPIC_CFG_IC_EDGE_RISE;
  617. name = "posedge";
  618. hdl = handle_edge_irq;
  619. break;
  620. case IRQ_TYPE_EDGE_FALLING:
  621. s = GPIC_CFG_IC_EDGE_FALL;
  622. name = "negedge";
  623. hdl = handle_edge_irq;
  624. break;
  625. case IRQ_TYPE_EDGE_BOTH:
  626. s = GPIC_CFG_IC_EDGE_BOTH;
  627. name = "bothedge";
  628. hdl = handle_edge_irq;
  629. break;
  630. case IRQ_TYPE_NONE:
  631. s = GPIC_CFG_IC_OFF;
  632. name = "disabled";
  633. hdl = handle_level_irq;
  634. break;
  635. default:
  636. return -EINVAL;
  637. }
  638. irq_set_chip_handler_name_locked(d, &au1300_gpic, hdl, name);
  639. au1300_gpic_chgcfg(d->irq - ALCHEMY_GPIC_INT_BASE, GPIC_CFG_IC_MASK, s);
  640. return 0;
  641. }
  642. /******************************************************************************/
  643. static inline void ic_init(void __iomem *base)
  644. {
  645. /* initialize interrupt controller to a safe state */
  646. __raw_writel(0xffffffff, base + IC_CFG0CLR);
  647. __raw_writel(0xffffffff, base + IC_CFG1CLR);
  648. __raw_writel(0xffffffff, base + IC_CFG2CLR);
  649. __raw_writel(0xffffffff, base + IC_MASKCLR);
  650. __raw_writel(0xffffffff, base + IC_ASSIGNCLR);
  651. __raw_writel(0xffffffff, base + IC_WAKECLR);
  652. __raw_writel(0xffffffff, base + IC_SRCSET);
  653. __raw_writel(0xffffffff, base + IC_FALLINGCLR);
  654. __raw_writel(0xffffffff, base + IC_RISINGCLR);
  655. __raw_writel(0x00000000, base + IC_TESTBIT);
  656. wmb();
  657. }
  658. static unsigned long alchemy_gpic_pmdata[ALCHEMY_GPIC_INT_NUM + 6];
  659. static inline void alchemy_ic_suspend_one(void __iomem *base, unsigned long *d)
  660. {
  661. d[0] = __raw_readl(base + IC_CFG0RD);
  662. d[1] = __raw_readl(base + IC_CFG1RD);
  663. d[2] = __raw_readl(base + IC_CFG2RD);
  664. d[3] = __raw_readl(base + IC_SRCRD);
  665. d[4] = __raw_readl(base + IC_ASSIGNRD);
  666. d[5] = __raw_readl(base + IC_WAKERD);
  667. d[6] = __raw_readl(base + IC_MASKRD);
  668. ic_init(base); /* shut it up too while at it */
  669. }
  670. static inline void alchemy_ic_resume_one(void __iomem *base, unsigned long *d)
  671. {
  672. ic_init(base);
  673. __raw_writel(d[0], base + IC_CFG0SET);
  674. __raw_writel(d[1], base + IC_CFG1SET);
  675. __raw_writel(d[2], base + IC_CFG2SET);
  676. __raw_writel(d[3], base + IC_SRCSET);
  677. __raw_writel(d[4], base + IC_ASSIGNSET);
  678. __raw_writel(d[5], base + IC_WAKESET);
  679. wmb();
  680. __raw_writel(d[6], base + IC_MASKSET);
  681. wmb();
  682. }
  683. static int alchemy_ic_suspend(void)
  684. {
  685. alchemy_ic_suspend_one((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR),
  686. alchemy_gpic_pmdata);
  687. alchemy_ic_suspend_one((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR),
  688. &alchemy_gpic_pmdata[7]);
  689. return 0;
  690. }
  691. static void alchemy_ic_resume(void)
  692. {
  693. alchemy_ic_resume_one((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR),
  694. &alchemy_gpic_pmdata[7]);
  695. alchemy_ic_resume_one((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR),
  696. alchemy_gpic_pmdata);
  697. }
  698. static int alchemy_gpic_suspend(void)
  699. {
  700. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
  701. int i;
  702. /* save 4 interrupt mask status registers */
  703. alchemy_gpic_pmdata[0] = __raw_readl(base + AU1300_GPIC_IEN + 0x0);
  704. alchemy_gpic_pmdata[1] = __raw_readl(base + AU1300_GPIC_IEN + 0x4);
  705. alchemy_gpic_pmdata[2] = __raw_readl(base + AU1300_GPIC_IEN + 0x8);
  706. alchemy_gpic_pmdata[3] = __raw_readl(base + AU1300_GPIC_IEN + 0xc);
  707. /* save misc register(s) */
  708. alchemy_gpic_pmdata[4] = __raw_readl(base + AU1300_GPIC_DMASEL);
  709. /* molto silenzioso */
  710. __raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x0);
  711. __raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x4);
  712. __raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x8);
  713. __raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0xc);
  714. wmb();
  715. /* save pin/int-type configuration */
  716. base += AU1300_GPIC_PINCFG;
  717. for (i = 0; i < ALCHEMY_GPIC_INT_NUM; i++)
  718. alchemy_gpic_pmdata[i + 5] = __raw_readl(base + (i << 2));
  719. wmb();
  720. return 0;
  721. }
  722. static void alchemy_gpic_resume(void)
  723. {
  724. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
  725. int i;
  726. /* disable all first */
  727. __raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x0);
  728. __raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x4);
  729. __raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0x8);
  730. __raw_writel(~0UL, base + AU1300_GPIC_IDIS + 0xc);
  731. wmb();
  732. /* restore pin/int-type configurations */
  733. base += AU1300_GPIC_PINCFG;
  734. for (i = 0; i < ALCHEMY_GPIC_INT_NUM; i++)
  735. __raw_writel(alchemy_gpic_pmdata[i + 5], base + (i << 2));
  736. wmb();
  737. /* restore misc register(s) */
  738. base = (void __iomem *)KSEG1ADDR(AU1300_GPIC_PHYS_ADDR);
  739. __raw_writel(alchemy_gpic_pmdata[4], base + AU1300_GPIC_DMASEL);
  740. wmb();
  741. /* finally restore masks */
  742. __raw_writel(alchemy_gpic_pmdata[0], base + AU1300_GPIC_IEN + 0x0);
  743. __raw_writel(alchemy_gpic_pmdata[1], base + AU1300_GPIC_IEN + 0x4);
  744. __raw_writel(alchemy_gpic_pmdata[2], base + AU1300_GPIC_IEN + 0x8);
  745. __raw_writel(alchemy_gpic_pmdata[3], base + AU1300_GPIC_IEN + 0xc);
  746. wmb();
  747. }
  748. static struct syscore_ops alchemy_ic_pmops = {
  749. .suspend = alchemy_ic_suspend,
  750. .resume = alchemy_ic_resume,
  751. };
  752. static struct syscore_ops alchemy_gpic_pmops = {
  753. .suspend = alchemy_gpic_suspend,
  754. .resume = alchemy_gpic_resume,
  755. };
  756. /******************************************************************************/
  757. /* create chained handlers for the 4 IC requests to the MIPS IRQ ctrl */
  758. #define DISP(name, base, addr) \
  759. static void au1000_##name##_dispatch(struct irq_desc *d) \
  760. { \
  761. unsigned long r = __raw_readl((void __iomem *)KSEG1ADDR(addr)); \
  762. if (likely(r)) \
  763. generic_handle_irq(base + __ffs(r)); \
  764. else \
  765. spurious_interrupt(); \
  766. }
  767. DISP(ic0r0, AU1000_INTC0_INT_BASE, AU1000_IC0_PHYS_ADDR + IC_REQ0INT)
  768. DISP(ic0r1, AU1000_INTC0_INT_BASE, AU1000_IC0_PHYS_ADDR + IC_REQ1INT)
  769. DISP(ic1r0, AU1000_INTC1_INT_BASE, AU1000_IC1_PHYS_ADDR + IC_REQ0INT)
  770. DISP(ic1r1, AU1000_INTC1_INT_BASE, AU1000_IC1_PHYS_ADDR + IC_REQ1INT)
  771. static void alchemy_gpic_dispatch(struct irq_desc *d)
  772. {
  773. int i = __raw_readl(AU1300_GPIC_ADDR + AU1300_GPIC_PRIENC);
  774. generic_handle_irq(ALCHEMY_GPIC_INT_BASE + i);
  775. }
  776. /******************************************************************************/
  777. static void __init au1000_init_irq(struct alchemy_irqmap *map)
  778. {
  779. unsigned int bit, irq_nr;
  780. void __iomem *base;
  781. ic_init((void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR));
  782. ic_init((void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR));
  783. register_syscore_ops(&alchemy_ic_pmops);
  784. mips_cpu_irq_init();
  785. /* register all 64 possible IC0+IC1 irq sources as type "none".
  786. * Use set_irq_type() to set edge/level behaviour at runtime.
  787. */
  788. for (irq_nr = AU1000_INTC0_INT_BASE;
  789. (irq_nr < AU1000_INTC0_INT_BASE + 32); irq_nr++)
  790. au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE);
  791. for (irq_nr = AU1000_INTC1_INT_BASE;
  792. (irq_nr < AU1000_INTC1_INT_BASE + 32); irq_nr++)
  793. au1x_ic_settype(irq_get_irq_data(irq_nr), IRQ_TYPE_NONE);
  794. /*
  795. * Initialize IC0, which is fixed per processor.
  796. */
  797. while (map->irq != -1) {
  798. irq_nr = map->irq;
  799. if (irq_nr >= AU1000_INTC1_INT_BASE) {
  800. bit = irq_nr - AU1000_INTC1_INT_BASE;
  801. base = (void __iomem *)KSEG1ADDR(AU1000_IC1_PHYS_ADDR);
  802. } else {
  803. bit = irq_nr - AU1000_INTC0_INT_BASE;
  804. base = (void __iomem *)KSEG1ADDR(AU1000_IC0_PHYS_ADDR);
  805. }
  806. if (map->prio == 0)
  807. __raw_writel(1 << bit, base + IC_ASSIGNSET);
  808. au1x_ic_settype(irq_get_irq_data(irq_nr), map->type);
  809. ++map;
  810. }
  811. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 2, au1000_ic0r0_dispatch);
  812. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 3, au1000_ic0r1_dispatch);
  813. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 4, au1000_ic1r0_dispatch);
  814. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 5, au1000_ic1r1_dispatch);
  815. }
  816. static void __init alchemy_gpic_init_irq(const struct alchemy_irqmap *dints)
  817. {
  818. int i;
  819. void __iomem *bank_base;
  820. register_syscore_ops(&alchemy_gpic_pmops);
  821. mips_cpu_irq_init();
  822. /* disable & ack all possible interrupt sources */
  823. for (i = 0; i < 4; i++) {
  824. bank_base = AU1300_GPIC_ADDR + (i * 4);
  825. __raw_writel(~0UL, bank_base + AU1300_GPIC_IDIS);
  826. wmb();
  827. __raw_writel(~0UL, bank_base + AU1300_GPIC_IPEND);
  828. wmb();
  829. }
  830. /* register an irq_chip for them, with 2nd highest priority */
  831. for (i = ALCHEMY_GPIC_INT_BASE; i <= ALCHEMY_GPIC_INT_LAST; i++) {
  832. au1300_set_irq_priority(i, 1);
  833. au1300_gpic_settype(irq_get_irq_data(i), IRQ_TYPE_NONE);
  834. }
  835. /* setup known on-chip sources */
  836. while ((i = dints->irq) != -1) {
  837. au1300_gpic_settype(irq_get_irq_data(i), dints->type);
  838. au1300_set_irq_priority(i, dints->prio);
  839. if (dints->internal)
  840. au1300_pinfunc_to_dev(i - ALCHEMY_GPIC_INT_BASE);
  841. dints++;
  842. }
  843. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 2, alchemy_gpic_dispatch);
  844. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 3, alchemy_gpic_dispatch);
  845. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 4, alchemy_gpic_dispatch);
  846. irq_set_chained_handler(MIPS_CPU_IRQ_BASE + 5, alchemy_gpic_dispatch);
  847. }
  848. /******************************************************************************/
  849. void __init arch_init_irq(void)
  850. {
  851. switch (alchemy_get_cputype()) {
  852. case ALCHEMY_CPU_AU1000:
  853. au1000_init_irq(au1000_irqmap);
  854. break;
  855. case ALCHEMY_CPU_AU1500:
  856. au1000_init_irq(au1500_irqmap);
  857. break;
  858. case ALCHEMY_CPU_AU1100:
  859. au1000_init_irq(au1100_irqmap);
  860. break;
  861. case ALCHEMY_CPU_AU1550:
  862. au1000_init_irq(au1550_irqmap);
  863. break;
  864. case ALCHEMY_CPU_AU1200:
  865. au1000_init_irq(au1200_irqmap);
  866. break;
  867. case ALCHEMY_CPU_AU1300:
  868. alchemy_gpic_init_irq(au1300_irqmap);
  869. break;
  870. default:
  871. pr_err("unknown Alchemy IRQ core\n");
  872. break;
  873. }
  874. }
  875. asmlinkage void plat_irq_dispatch(void)
  876. {
  877. unsigned long r = (read_c0_status() & read_c0_cause()) >> 8;
  878. do_IRQ(MIPS_CPU_IRQ_BASE + __ffs(r & 0xff));
  879. }