nj_s.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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 njs_pci_probe(struct pci_dev *dev_netjet, struct IsdnCardState *cs)
  142. {
  143. u32 cfg;
  144. if (pci_enable_device(dev_netjet))
  145. return (0);
  146. pci_set_master(dev_netjet);
  147. cs->irq = dev_netjet->irq;
  148. if (!cs->irq) {
  149. printk(KERN_WARNING "NETjet-S: No IRQ for PCI card found\n");
  150. return (0);
  151. }
  152. cs->hw.njet.base = pci_resource_start(dev_netjet, 0);
  153. if (!cs->hw.njet.base) {
  154. printk(KERN_WARNING "NETjet-S: No IO-Adr for PCI card found\n");
  155. return (0);
  156. }
  157. /* the TJ300 and TJ320 must be detected, the IRQ handling is different
  158. * unfortunately the chips use the same device ID, but the TJ320 has
  159. * the bit20 in status PCI cfg register set
  160. */
  161. pci_read_config_dword(dev_netjet, 0x04, &cfg);
  162. if (cfg & 0x00100000)
  163. cs->subtyp = 1; /* TJ320 */
  164. else
  165. cs->subtyp = 0; /* TJ300 */
  166. /* 2001/10/04 Christoph Ersfeld, Formula-n Europe AG www.formula-n.com */
  167. if ((dev_netjet->subsystem_vendor == 0x55) &&
  168. (dev_netjet->subsystem_device == 0x02)) {
  169. printk(KERN_WARNING "Netjet: You tried to load this driver with an incompatible TigerJet-card\n");
  170. printk(KERN_WARNING "Use type=41 for Formula-n enter:now ISDN PCI and compatible\n");
  171. return (0);
  172. }
  173. /* end new code */
  174. return (1);
  175. }
  176. static int njs_cs_init(struct IsdnCard *card, struct IsdnCardState *cs)
  177. {
  178. cs->hw.njet.auxa = cs->hw.njet.base + NETJET_AUXDATA;
  179. cs->hw.njet.isac = cs->hw.njet.base | NETJET_ISAC_OFF;
  180. cs->hw.njet.ctrl_reg = 0xff; /* Reset On */
  181. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  182. mdelay(10);
  183. cs->hw.njet.ctrl_reg = 0x00; /* Reset Off and status read clear */
  184. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  185. mdelay(10);
  186. cs->hw.njet.auxd = 0xC0;
  187. cs->hw.njet.dmactrl = 0;
  188. byteout(cs->hw.njet.base + NETJET_AUXCTRL, ~NETJET_ISACIRQ);
  189. byteout(cs->hw.njet.base + NETJET_IRQMASK1, NETJET_ISACIRQ);
  190. byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
  191. switch (((NETjet_ReadIC(cs, ISAC_RBCH) >> 5) & 3))
  192. {
  193. case 0:
  194. return 1; /* end loop */
  195. case 3:
  196. printk(KERN_WARNING "NETjet-S: NETspider-U PCI card found\n");
  197. return -1; /* continue looping */
  198. default:
  199. printk(KERN_WARNING "NETjet-S: No PCI card found\n");
  200. return 0; /* end loop & function */
  201. }
  202. return 1; /* end loop */
  203. }
  204. static int njs_cs_init_rest(struct IsdnCard *card, struct IsdnCardState *cs)
  205. {
  206. const int bytecnt = 256;
  207. printk(KERN_INFO
  208. "NETjet-S: %s card configured at %#lx IRQ %d\n",
  209. cs->subtyp ? "TJ320" : "TJ300", cs->hw.njet.base, cs->irq);
  210. if (!request_region(cs->hw.njet.base, bytecnt, "netjet-s isdn")) {
  211. printk(KERN_WARNING
  212. "HiSax: NETjet-S config port %#lx-%#lx already in use\n",
  213. cs->hw.njet.base,
  214. cs->hw.njet.base + bytecnt);
  215. return (0);
  216. }
  217. cs->readisac = &NETjet_ReadIC;
  218. cs->writeisac = &NETjet_WriteIC;
  219. cs->readisacfifo = &NETjet_ReadICfifo;
  220. cs->writeisacfifo = &NETjet_WriteICfifo;
  221. cs->BC_Read_Reg = &dummyrr;
  222. cs->BC_Write_Reg = &dummywr;
  223. cs->BC_Send_Data = &netjet_fill_dma;
  224. setup_isac(cs);
  225. cs->cardmsg = &NETjet_S_card_msg;
  226. cs->irq_func = &netjet_s_interrupt;
  227. cs->irq_flags |= IRQF_SHARED;
  228. ISACVersion(cs, "NETjet-S:");
  229. return (1);
  230. }
  231. static struct pci_dev *dev_netjet = NULL;
  232. int setup_netjet_s(struct IsdnCard *card)
  233. {
  234. int ret;
  235. struct IsdnCardState *cs = card->cs;
  236. char tmp[64];
  237. #ifdef __BIG_ENDIAN
  238. #error "not running on big endian machines now"
  239. #endif
  240. strcpy(tmp, NETjet_S_revision);
  241. printk(KERN_INFO "HiSax: Traverse Tech. NETjet-S driver Rev. %s\n", HiSax_getrev(tmp));
  242. if (cs->typ != ISDN_CTYPE_NETJET_S)
  243. return (0);
  244. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  245. for (;;)
  246. {
  247. if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET,
  248. PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
  249. ret = njs_pci_probe(dev_netjet, cs);
  250. if (!ret)
  251. return (0);
  252. } else {
  253. printk(KERN_WARNING "NETjet-S: No PCI card found\n");
  254. return (0);
  255. }
  256. ret = njs_cs_init(card, cs);
  257. if (!ret)
  258. return (0);
  259. if (ret > 0)
  260. break;
  261. /* otherwise, ret < 0, continue looping */
  262. }
  263. return njs_cs_init_rest(card, cs);
  264. }