gsc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Interrupt management for most GSC and related devices.
  3. *
  4. * (c) Copyright 1999 Alex deVries for The Puffin Group
  5. * (c) Copyright 1999 Grant Grundler for Hewlett-Packard
  6. * (c) Copyright 1999 Matthew Wilcox
  7. * (c) Copyright 2000 Helge Deller
  8. * (c) Copyright 2001 Matthew Wilcox for Hewlett-Packard
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. */
  15. #include <linux/bitops.h>
  16. #include <linux/errno.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ioport.h>
  20. #include <linux/module.h>
  21. #include <linux/types.h>
  22. #include <asm/hardware.h>
  23. #include <asm/io.h>
  24. #include "gsc.h"
  25. #undef DEBUG
  26. #ifdef DEBUG
  27. #define DEBPRINTK printk
  28. #else
  29. #define DEBPRINTK(x,...)
  30. #endif
  31. int gsc_alloc_irq(struct gsc_irq *i)
  32. {
  33. int irq = txn_alloc_irq(GSC_EIM_WIDTH);
  34. if (irq < 0) {
  35. printk("cannot get irq\n");
  36. return irq;
  37. }
  38. i->txn_addr = txn_alloc_addr(irq);
  39. i->txn_data = txn_alloc_data(irq);
  40. i->irq = irq;
  41. return irq;
  42. }
  43. int gsc_claim_irq(struct gsc_irq *i, int irq)
  44. {
  45. int c = irq;
  46. irq += CPU_IRQ_BASE; /* virtualize the IRQ first */
  47. irq = txn_claim_irq(irq);
  48. if (irq < 0) {
  49. printk("cannot claim irq %d\n", c);
  50. return irq;
  51. }
  52. i->txn_addr = txn_alloc_addr(irq);
  53. i->txn_data = txn_alloc_data(irq);
  54. i->irq = irq;
  55. return irq;
  56. }
  57. EXPORT_SYMBOL(gsc_alloc_irq);
  58. EXPORT_SYMBOL(gsc_claim_irq);
  59. /* Common interrupt demultiplexer used by Asp, Lasi & Wax. */
  60. irqreturn_t gsc_asic_intr(int gsc_asic_irq, void *dev)
  61. {
  62. unsigned long irr;
  63. struct gsc_asic *gsc_asic = dev;
  64. irr = gsc_readl(gsc_asic->hpa + OFFSET_IRR);
  65. if (irr == 0)
  66. return IRQ_NONE;
  67. DEBPRINTK("%s intr, mask=0x%x\n", gsc_asic->name, irr);
  68. do {
  69. int local_irq = __ffs(irr);
  70. unsigned int irq = gsc_asic->global_irq[local_irq];
  71. __do_IRQ(irq);
  72. irr &= ~(1 << local_irq);
  73. } while (irr);
  74. return IRQ_HANDLED;
  75. }
  76. int gsc_find_local_irq(unsigned int irq, int *global_irqs, int limit)
  77. {
  78. int local_irq;
  79. for (local_irq = 0; local_irq < limit; local_irq++) {
  80. if (global_irqs[local_irq] == irq)
  81. return local_irq;
  82. }
  83. return NO_IRQ;
  84. }
  85. static void gsc_asic_disable_irq(unsigned int irq)
  86. {
  87. struct irq_desc *desc = irq_to_desc(irq);
  88. struct gsc_asic *irq_dev = desc->chip_data;
  89. int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
  90. u32 imr;
  91. DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
  92. irq_dev->name, imr);
  93. /* Disable the IRQ line by clearing the bit in the IMR */
  94. imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
  95. imr &= ~(1 << local_irq);
  96. gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
  97. }
  98. static void gsc_asic_enable_irq(unsigned int irq)
  99. {
  100. struct irq_desc *desc = irq_to_desc(irq);
  101. struct gsc_asic *irq_dev = desc->chip_data;
  102. int local_irq = gsc_find_local_irq(irq, irq_dev->global_irq, 32);
  103. u32 imr;
  104. DEBPRINTK(KERN_DEBUG "%s(%d) %s: IMR 0x%x\n", __func__, irq,
  105. irq_dev->name, imr);
  106. /* Enable the IRQ line by setting the bit in the IMR */
  107. imr = gsc_readl(irq_dev->hpa + OFFSET_IMR);
  108. imr |= 1 << local_irq;
  109. gsc_writel(imr, irq_dev->hpa + OFFSET_IMR);
  110. /*
  111. * FIXME: read IPR to make sure the IRQ isn't already pending.
  112. * If so, we need to read IRR and manually call do_irq().
  113. */
  114. }
  115. static unsigned int gsc_asic_startup_irq(unsigned int irq)
  116. {
  117. gsc_asic_enable_irq(irq);
  118. return 0;
  119. }
  120. static struct irq_chip gsc_asic_interrupt_type = {
  121. .name = "GSC-ASIC",
  122. .startup = gsc_asic_startup_irq,
  123. .shutdown = gsc_asic_disable_irq,
  124. .enable = gsc_asic_enable_irq,
  125. .disable = gsc_asic_disable_irq,
  126. .ack = no_ack_irq,
  127. .end = no_end_irq,
  128. };
  129. int gsc_assign_irq(struct irq_chip *type, void *data)
  130. {
  131. static int irq = GSC_IRQ_BASE;
  132. struct irq_desc *desc;
  133. if (irq > GSC_IRQ_MAX)
  134. return NO_IRQ;
  135. desc = irq_to_desc(irq);
  136. desc->chip = type;
  137. desc->chip_data = data;
  138. return irq++;
  139. }
  140. void gsc_asic_assign_irq(struct gsc_asic *asic, int local_irq, int *irqp)
  141. {
  142. int irq = asic->global_irq[local_irq];
  143. if (irq <= 0) {
  144. irq = gsc_assign_irq(&gsc_asic_interrupt_type, asic);
  145. if (irq == NO_IRQ)
  146. return;
  147. asic->global_irq[local_irq] = irq;
  148. }
  149. *irqp = irq;
  150. }
  151. struct gsc_fixup_struct {
  152. void (*choose_irq)(struct parisc_device *, void *);
  153. void *ctrl;
  154. };
  155. static int gsc_fixup_irqs_callback(struct device *dev, void *data)
  156. {
  157. struct parisc_device *padev = to_parisc_device(dev);
  158. struct gsc_fixup_struct *gf = data;
  159. /* work-around for 715/64 and others which have parent
  160. at path [5] and children at path [5/0/x] */
  161. if (padev->id.hw_type == HPHW_FAULTY)
  162. gsc_fixup_irqs(padev, gf->ctrl, gf->choose_irq);
  163. gf->choose_irq(padev, gf->ctrl);
  164. return 0;
  165. }
  166. void gsc_fixup_irqs(struct parisc_device *parent, void *ctrl,
  167. void (*choose_irq)(struct parisc_device *, void *))
  168. {
  169. struct gsc_fixup_struct data = {
  170. .choose_irq = choose_irq,
  171. .ctrl = ctrl,
  172. };
  173. device_for_each_child(&parent->dev, &data, gsc_fixup_irqs_callback);
  174. }
  175. int gsc_common_setup(struct parisc_device *parent, struct gsc_asic *gsc_asic)
  176. {
  177. struct resource *res;
  178. int i;
  179. gsc_asic->gsc = parent;
  180. /* Initialise local irq -> global irq mapping */
  181. for (i = 0; i < 32; i++) {
  182. gsc_asic->global_irq[i] = NO_IRQ;
  183. }
  184. /* allocate resource region */
  185. res = request_mem_region(gsc_asic->hpa, 0x100000, gsc_asic->name);
  186. if (res) {
  187. res->flags = IORESOURCE_MEM; /* do not mark it busy ! */
  188. }
  189. #if 0
  190. printk(KERN_WARNING "%s IRQ %d EIM 0x%x", gsc_asic->name,
  191. parent->irq, gsc_asic->eim);
  192. if (gsc_readl(gsc_asic->hpa + OFFSET_IMR))
  193. printk(" IMR is non-zero! (0x%x)",
  194. gsc_readl(gsc_asic->hpa + OFFSET_IMR));
  195. printk("\n");
  196. #endif
  197. return 0;
  198. }
  199. extern struct parisc_driver lasi_driver;
  200. extern struct parisc_driver asp_driver;
  201. extern struct parisc_driver wax_driver;
  202. void __init gsc_init(void)
  203. {
  204. #ifdef CONFIG_GSC_LASI
  205. register_parisc_driver(&lasi_driver);
  206. register_parisc_driver(&asp_driver);
  207. #endif
  208. #ifdef CONFIG_GSC_WAX
  209. register_parisc_driver(&wax_driver);
  210. #endif
  211. }