spider-pic.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * External Interrupt Controller on Spider South Bridge
  3. *
  4. * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
  5. *
  6. * Author: Arnd Bergmann <arndb@de.ibm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/interrupt.h>
  23. #include <linux/irq.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/prom.h>
  26. #include <asm/io.h>
  27. #include "interrupt.h"
  28. /* register layout taken from Spider spec, table 7.4-4 */
  29. enum {
  30. TIR_DEN = 0x004, /* Detection Enable Register */
  31. TIR_MSK = 0x084, /* Mask Level Register */
  32. TIR_EDC = 0x0c0, /* Edge Detection Clear Register */
  33. TIR_PNDA = 0x100, /* Pending Register A */
  34. TIR_PNDB = 0x104, /* Pending Register B */
  35. TIR_CS = 0x144, /* Current Status Register */
  36. TIR_LCSA = 0x150, /* Level Current Status Register A */
  37. TIR_LCSB = 0x154, /* Level Current Status Register B */
  38. TIR_LCSC = 0x158, /* Level Current Status Register C */
  39. TIR_LCSD = 0x15c, /* Level Current Status Register D */
  40. TIR_CFGA = 0x200, /* Setting Register A0 */
  41. TIR_CFGB = 0x204, /* Setting Register B0 */
  42. /* 0x208 ... 0x3ff Setting Register An/Bn */
  43. TIR_PPNDA = 0x400, /* Packet Pending Register A */
  44. TIR_PPNDB = 0x404, /* Packet Pending Register B */
  45. TIR_PIERA = 0x408, /* Packet Output Error Register A */
  46. TIR_PIERB = 0x40c, /* Packet Output Error Register B */
  47. TIR_PIEN = 0x444, /* Packet Output Enable Register */
  48. TIR_PIPND = 0x454, /* Packet Output Pending Register */
  49. TIRDID = 0x484, /* Spider Device ID Register */
  50. REISTIM = 0x500, /* Reissue Command Timeout Time Setting */
  51. REISTIMEN = 0x504, /* Reissue Command Timeout Setting */
  52. REISWAITEN = 0x508, /* Reissue Wait Control*/
  53. };
  54. static void __iomem *spider_pics[4];
  55. static void __iomem *spider_get_pic(int irq)
  56. {
  57. int node = irq / IIC_NODE_STRIDE;
  58. irq %= IIC_NODE_STRIDE;
  59. if (irq >= IIC_EXT_OFFSET &&
  60. irq < IIC_EXT_OFFSET + IIC_NUM_EXT &&
  61. spider_pics)
  62. return spider_pics[node];
  63. return NULL;
  64. }
  65. static int spider_get_nr(unsigned int irq)
  66. {
  67. return (irq % IIC_NODE_STRIDE) - IIC_EXT_OFFSET;
  68. }
  69. static void __iomem *spider_get_irq_config(int irq)
  70. {
  71. void __iomem *pic;
  72. pic = spider_get_pic(irq);
  73. return pic + TIR_CFGA + 8 * spider_get_nr(irq);
  74. }
  75. static void spider_enable_irq(unsigned int irq)
  76. {
  77. int nodeid = (irq / IIC_NODE_STRIDE) * 0x10;
  78. void __iomem *cfg = spider_get_irq_config(irq);
  79. irq = spider_get_nr(irq);
  80. out_be32(cfg, (in_be32(cfg) & ~0xf0)| 0x3107000eu | nodeid);
  81. out_be32(cfg + 4, in_be32(cfg + 4) | 0x00020000u | irq);
  82. }
  83. static void spider_disable_irq(unsigned int irq)
  84. {
  85. void __iomem *cfg = spider_get_irq_config(irq);
  86. irq = spider_get_nr(irq);
  87. out_be32(cfg, in_be32(cfg) & ~0x30000000u);
  88. }
  89. static unsigned int spider_startup_irq(unsigned int irq)
  90. {
  91. spider_enable_irq(irq);
  92. return 0;
  93. }
  94. static void spider_shutdown_irq(unsigned int irq)
  95. {
  96. spider_disable_irq(irq);
  97. }
  98. static void spider_end_irq(unsigned int irq)
  99. {
  100. spider_enable_irq(irq);
  101. }
  102. static void spider_ack_irq(unsigned int irq)
  103. {
  104. spider_disable_irq(irq);
  105. iic_local_enable();
  106. }
  107. static struct hw_interrupt_type spider_pic = {
  108. .typename = " SPIDER ",
  109. .startup = spider_startup_irq,
  110. .shutdown = spider_shutdown_irq,
  111. .enable = spider_enable_irq,
  112. .disable = spider_disable_irq,
  113. .ack = spider_ack_irq,
  114. .end = spider_end_irq,
  115. };
  116. int spider_get_irq(int node)
  117. {
  118. unsigned long cs;
  119. void __iomem *regs = spider_pics[node];
  120. cs = in_be32(regs + TIR_CS) >> 24;
  121. if (cs == 63)
  122. return -1;
  123. else
  124. return cs;
  125. }
  126. /* hardcoded part to be compatible with older firmware */
  127. void spider_init_IRQ_hardcoded(void)
  128. {
  129. int node;
  130. long spiderpic;
  131. long pics[] = { 0x24000008000, 0x34000008000 };
  132. int n;
  133. pr_debug("%s(%d): Using hardcoded defaults\n", __FUNCTION__, __LINE__);
  134. for (node = 0; node < num_present_cpus()/2; node++) {
  135. spiderpic = pics[node];
  136. printk(KERN_DEBUG "SPIDER addr: %lx\n", spiderpic);
  137. spider_pics[node] = ioremap(spiderpic, 0x800);
  138. for (n = 0; n < IIC_NUM_EXT; n++) {
  139. int irq = n + IIC_EXT_OFFSET + node * IIC_NODE_STRIDE;
  140. get_irq_desc(irq)->handler = &spider_pic;
  141. }
  142. /* do not mask any interrupts because of level */
  143. out_be32(spider_pics[node] + TIR_MSK, 0x0);
  144. /* disable edge detection clear */
  145. /* out_be32(spider_pics[node] + TIR_EDC, 0x0); */
  146. /* enable interrupt packets to be output */
  147. out_be32(spider_pics[node] + TIR_PIEN,
  148. in_be32(spider_pics[node] + TIR_PIEN) | 0x1);
  149. /* Enable the interrupt detection enable bit. Do this last! */
  150. out_be32(spider_pics[node] + TIR_DEN,
  151. in_be32(spider_pics[node] + TIR_DEN) | 0x1);
  152. }
  153. }
  154. void spider_init_IRQ(void)
  155. {
  156. long spider_reg;
  157. struct device_node *dn;
  158. char *compatible;
  159. int n, node = 0;
  160. for (dn = NULL; (dn = of_find_node_by_name(dn, "interrupt-controller"));) {
  161. compatible = (char *)get_property(dn, "compatible", NULL);
  162. if (!compatible)
  163. continue;
  164. if (strstr(compatible, "CBEA,platform-spider-pic"))
  165. spider_reg = *(long *)get_property(dn,"reg", NULL);
  166. else if (strstr(compatible, "sti,platform-spider-pic")) {
  167. spider_init_IRQ_hardcoded();
  168. return;
  169. } else
  170. continue;
  171. if (!spider_reg)
  172. printk("interrupt controller does not have reg property !\n");
  173. n = prom_n_addr_cells(dn);
  174. if ( n != 2)
  175. printk("reg property with invalid number of elements \n");
  176. spider_pics[node] = ioremap(spider_reg, 0x800);
  177. printk("SPIDER addr: %lx with %i addr_cells mapped to %p\n",
  178. spider_reg, n, spider_pics[node]);
  179. for (n = 0; n < IIC_NUM_EXT; n++) {
  180. int irq = n + IIC_EXT_OFFSET + node * IIC_NODE_STRIDE;
  181. get_irq_desc(irq)->handler = &spider_pic;
  182. }
  183. /* do not mask any interrupts because of level */
  184. out_be32(spider_pics[node] + TIR_MSK, 0x0);
  185. /* disable edge detection clear */
  186. /* out_be32(spider_pics[node] + TIR_EDC, 0x0); */
  187. /* enable interrupt packets to be output */
  188. out_be32(spider_pics[node] + TIR_PIEN,
  189. in_be32(spider_pics[node] + TIR_PIEN) | 0x1);
  190. /* Enable the interrupt detection enable bit. Do this last! */
  191. out_be32(spider_pics[node] + TIR_DEN,
  192. in_be32(spider_pics[node] + TIR_DEN) | 0x1);
  193. node++;
  194. }
  195. }