nj_s.c 8.2 KB

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