nj_s.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /* $Id: nj_s.c,v 2.13.2.4 2004/01/16 01:53:48 keil Exp $
  2. *
  3. * This software may be used and distributed according to the terms
  4. * of the GNU General Public License, incorporated herein by reference.
  5. *
  6. */
  7. #include <linux/config.h>
  8. #include <linux/init.h>
  9. #include "hisax.h"
  10. #include "isac.h"
  11. #include "isdnl1.h"
  12. #include <linux/pci.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/ppp_defs.h>
  15. #include "netjet.h"
  16. static const char *NETjet_S_revision = "$Revision: 2.13.2.4 $";
  17. static u_char dummyrr(struct IsdnCardState *cs, int chan, u_char off)
  18. {
  19. return(5);
  20. }
  21. static void dummywr(struct IsdnCardState *cs, int chan, u_char off, u_char value)
  22. {
  23. }
  24. static irqreturn_t
  25. netjet_s_interrupt(int intno, void *dev_id, struct pt_regs *regs)
  26. {
  27. struct IsdnCardState *cs = dev_id;
  28. u_char val, s1val, s0val;
  29. u_long flags;
  30. spin_lock_irqsave(&cs->lock, flags);
  31. s1val = bytein(cs->hw.njet.base + NETJET_IRQSTAT1);
  32. if (!(s1val & NETJET_ISACIRQ)) {
  33. val = NETjet_ReadIC(cs, ISAC_ISTA);
  34. if (cs->debug & L1_DEB_ISAC)
  35. debugl1(cs, "tiger: i1 %x %x", s1val, val);
  36. if (val) {
  37. isac_interrupt(cs, val);
  38. NETjet_WriteIC(cs, ISAC_MASK, 0xFF);
  39. NETjet_WriteIC(cs, ISAC_MASK, 0x0);
  40. }
  41. s1val = 1;
  42. } else
  43. s1val = 0;
  44. /*
  45. * read/write stat0 is better, because lower IRQ rate
  46. * Note the IRQ is on for 125 us if a condition match
  47. * thats long on modern CPU and so the IRQ is reentered
  48. * all the time.
  49. */
  50. s0val = bytein(cs->hw.njet.base + NETJET_IRQSTAT0);
  51. if ((s0val | s1val)==0) { // shared IRQ
  52. spin_unlock_irqrestore(&cs->lock, flags);
  53. return IRQ_NONE;
  54. }
  55. if (s0val)
  56. byteout(cs->hw.njet.base + NETJET_IRQSTAT0, s0val);
  57. /* start new code 13/07/00 GE */
  58. /* set bits in sval to indicate which page is free */
  59. if (inl(cs->hw.njet.base + NETJET_DMA_WRITE_ADR) <
  60. inl(cs->hw.njet.base + NETJET_DMA_WRITE_IRQ))
  61. /* the 2nd write page is free */
  62. s0val = 0x08;
  63. else /* the 1st write page is free */
  64. s0val = 0x04;
  65. if (inl(cs->hw.njet.base + NETJET_DMA_READ_ADR) <
  66. inl(cs->hw.njet.base + NETJET_DMA_READ_IRQ))
  67. /* the 2nd read page is free */
  68. s0val |= 0x02;
  69. else /* the 1st read page is free */
  70. s0val |= 0x01;
  71. if (s0val != cs->hw.njet.last_is0) /* we have a DMA interrupt */
  72. {
  73. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  74. printk(KERN_WARNING "nj LOCK_ATOMIC s0val %x->%x\n",
  75. cs->hw.njet.last_is0, s0val);
  76. spin_unlock_irqrestore(&cs->lock, flags);
  77. return IRQ_HANDLED;
  78. }
  79. cs->hw.njet.irqstat0 = s0val;
  80. if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_READ) !=
  81. (cs->hw.njet.last_is0 & NETJET_IRQM0_READ))
  82. /* we have a read dma int */
  83. read_tiger(cs);
  84. if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_WRITE) !=
  85. (cs->hw.njet.last_is0 & NETJET_IRQM0_WRITE))
  86. /* we have a write dma int */
  87. write_tiger(cs);
  88. /* end new code 13/07/00 GE */
  89. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  90. }
  91. spin_unlock_irqrestore(&cs->lock, flags);
  92. return IRQ_HANDLED;
  93. }
  94. static void
  95. reset_netjet_s(struct IsdnCardState *cs)
  96. {
  97. cs->hw.njet.ctrl_reg = 0xff; /* Reset On */
  98. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  99. mdelay(10);
  100. /* now edge triggered for TJ320 GE 13/07/00 */
  101. /* see comment in IRQ function */
  102. if (cs->subtyp) /* TJ320 */
  103. cs->hw.njet.ctrl_reg = 0x40; /* Reset Off and status read clear */
  104. else
  105. cs->hw.njet.ctrl_reg = 0x00; /* Reset Off and status read clear */
  106. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  107. mdelay(10);
  108. cs->hw.njet.auxd = 0;
  109. cs->hw.njet.dmactrl = 0;
  110. byteout(cs->hw.njet.base + NETJET_AUXCTRL, ~NETJET_ISACIRQ);
  111. byteout(cs->hw.njet.base + NETJET_IRQMASK1, NETJET_ISACIRQ);
  112. byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
  113. }
  114. static int
  115. NETjet_S_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  116. {
  117. u_long flags;
  118. switch (mt) {
  119. case CARD_RESET:
  120. spin_lock_irqsave(&cs->lock, flags);
  121. reset_netjet_s(cs);
  122. spin_unlock_irqrestore(&cs->lock, flags);
  123. return(0);
  124. case CARD_RELEASE:
  125. release_io_netjet(cs);
  126. return(0);
  127. case CARD_INIT:
  128. reset_netjet_s(cs);
  129. inittiger(cs);
  130. spin_lock_irqsave(&cs->lock, flags);
  131. clear_pending_isac_ints(cs);
  132. initisac(cs);
  133. /* Reenable all IRQ */
  134. cs->writeisac(cs, ISAC_MASK, 0);
  135. spin_unlock_irqrestore(&cs->lock, flags);
  136. return(0);
  137. case CARD_TEST:
  138. return(0);
  139. }
  140. return(0);
  141. }
  142. static struct pci_dev *dev_netjet __initdata = NULL;
  143. int __init
  144. setup_netjet_s(struct IsdnCard *card)
  145. {
  146. int bytecnt,cfg;
  147. struct IsdnCardState *cs = card->cs;
  148. char tmp[64];
  149. #ifdef __BIG_ENDIAN
  150. #error "not running on big endian machines now"
  151. #endif
  152. strcpy(tmp, NETjet_S_revision);
  153. printk(KERN_INFO "HiSax: Traverse Tech. NETjet-S driver Rev. %s\n", HiSax_getrev(tmp));
  154. if (cs->typ != ISDN_CTYPE_NETJET_S)
  155. return(0);
  156. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  157. #ifdef CONFIG_PCI
  158. for ( ;; )
  159. {
  160. if ((dev_netjet = pci_find_device(PCI_VENDOR_ID_TIGERJET,
  161. PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
  162. if (pci_enable_device(dev_netjet))
  163. return(0);
  164. pci_set_master(dev_netjet);
  165. cs->irq = dev_netjet->irq;
  166. if (!cs->irq) {
  167. printk(KERN_WARNING "NETjet-S: No IRQ for PCI card found\n");
  168. return(0);
  169. }
  170. cs->hw.njet.base = pci_resource_start(dev_netjet, 0);
  171. if (!cs->hw.njet.base) {
  172. printk(KERN_WARNING "NETjet-S: No IO-Adr for PCI card found\n");
  173. return(0);
  174. }
  175. /* the TJ300 and TJ320 must be detected, the IRQ handling is different
  176. * unfortunatly the chips use the same device ID, but the TJ320 has
  177. * the bit20 in status PCI cfg register set
  178. */
  179. pci_read_config_dword(dev_netjet, 0x04, &cfg);
  180. if (cfg & 0x00100000)
  181. cs->subtyp = 1; /* TJ320 */
  182. else
  183. cs->subtyp = 0; /* TJ300 */
  184. /* 2001/10/04 Christoph Ersfeld, Formula-n Europe AG www.formula-n.com */
  185. if ((dev_netjet->subsystem_vendor == 0x55) &&
  186. (dev_netjet->subsystem_device == 0x02)) {
  187. printk(KERN_WARNING "Netjet: You tried to load this driver with an incompatible TigerJet-card\n");
  188. printk(KERN_WARNING "Use type=41 for Formula-n enter:now ISDN PCI and compatible\n");
  189. return(0);
  190. }
  191. /* end new code */
  192. } else {
  193. printk(KERN_WARNING "NETjet-S: No PCI card found\n");
  194. return(0);
  195. }
  196. cs->hw.njet.auxa = cs->hw.njet.base + NETJET_AUXDATA;
  197. cs->hw.njet.isac = cs->hw.njet.base | NETJET_ISAC_OFF;
  198. cs->hw.njet.ctrl_reg = 0xff; /* Reset On */
  199. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  200. mdelay(10);
  201. cs->hw.njet.ctrl_reg = 0x00; /* Reset Off and status read clear */
  202. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  203. mdelay(10);
  204. cs->hw.njet.auxd = 0xC0;
  205. cs->hw.njet.dmactrl = 0;
  206. byteout(cs->hw.njet.base + NETJET_AUXCTRL, ~NETJET_ISACIRQ);
  207. byteout(cs->hw.njet.base + NETJET_IRQMASK1, NETJET_ISACIRQ);
  208. byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
  209. switch ( ( ( NETjet_ReadIC( cs, ISAC_RBCH ) >> 5 ) & 3 ) )
  210. {
  211. case 0 :
  212. break;
  213. case 3 :
  214. printk( KERN_WARNING "NETjet-S: NETspider-U PCI card found\n" );
  215. continue;
  216. default :
  217. printk( KERN_WARNING "NETjet-S: No PCI card found\n" );
  218. return 0;
  219. }
  220. break;
  221. }
  222. #else
  223. printk(KERN_WARNING "NETjet-S: NO_PCI_BIOS\n");
  224. printk(KERN_WARNING "NETjet-S: unable to config NETJET-S PCI\n");
  225. return (0);
  226. #endif /* CONFIG_PCI */
  227. bytecnt = 256;
  228. printk(KERN_INFO
  229. "NETjet-S: %s card configured at %#lx IRQ %d\n",
  230. cs->subtyp ? "TJ320" : "TJ300", cs->hw.njet.base, cs->irq);
  231. if (!request_region(cs->hw.njet.base, bytecnt, "netjet-s isdn")) {
  232. printk(KERN_WARNING
  233. "HiSax: %s config port %#lx-%#lx already in use\n",
  234. CardType[card->typ],
  235. cs->hw.njet.base,
  236. cs->hw.njet.base + bytecnt);
  237. return (0);
  238. }
  239. cs->readisac = &NETjet_ReadIC;
  240. cs->writeisac = &NETjet_WriteIC;
  241. cs->readisacfifo = &NETjet_ReadICfifo;
  242. cs->writeisacfifo = &NETjet_WriteICfifo;
  243. cs->BC_Read_Reg = &dummyrr;
  244. cs->BC_Write_Reg = &dummywr;
  245. cs->BC_Send_Data = &netjet_fill_dma;
  246. setup_isac(cs);
  247. cs->cardmsg = &NETjet_S_card_msg;
  248. cs->irq_func = &netjet_s_interrupt;
  249. cs->irq_flags |= SA_SHIRQ;
  250. ISACVersion(cs, "NETjet-S:");
  251. return (1);
  252. }