nj_u.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /* $Id: nj_u.c,v 2.14.2.3 2004/01/13 14:31:26 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 "icc.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_U_revision = "$Revision: 2.14.2.3 $";
  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_u_interrupt(int intno, void *dev_id)
  25. {
  26. struct IsdnCardState *cs = dev_id;
  27. u_char val, sval;
  28. u_long flags;
  29. spin_lock_irqsave(&cs->lock, flags);
  30. if (!((sval = bytein(cs->hw.njet.base + NETJET_IRQSTAT1)) &
  31. NETJET_ISACIRQ)) {
  32. val = NETjet_ReadIC(cs, ICC_ISTA);
  33. if (cs->debug & L1_DEB_ISAC)
  34. debugl1(cs, "tiger: i1 %x %x", sval, val);
  35. if (val) {
  36. icc_interrupt(cs, val);
  37. NETjet_WriteIC(cs, ICC_MASK, 0xFF);
  38. NETjet_WriteIC(cs, ICC_MASK, 0x0);
  39. }
  40. }
  41. /* start new code 13/07/00 GE */
  42. /* set bits in sval to indicate which page is free */
  43. if (inl(cs->hw.njet.base + NETJET_DMA_WRITE_ADR) <
  44. inl(cs->hw.njet.base + NETJET_DMA_WRITE_IRQ))
  45. /* the 2nd write page is free */
  46. sval = 0x08;
  47. else /* the 1st write page is free */
  48. sval = 0x04;
  49. if (inl(cs->hw.njet.base + NETJET_DMA_READ_ADR) <
  50. inl(cs->hw.njet.base + NETJET_DMA_READ_IRQ))
  51. /* the 2nd read page is free */
  52. sval = sval | 0x02;
  53. else /* the 1st read page is free */
  54. sval = sval | 0x01;
  55. if (sval != cs->hw.njet.last_is0) /* we have a DMA interrupt */
  56. {
  57. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  58. spin_unlock_irqrestore(&cs->lock, flags);
  59. return IRQ_HANDLED;
  60. }
  61. cs->hw.njet.irqstat0 = sval;
  62. if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_READ) !=
  63. (cs->hw.njet.last_is0 & NETJET_IRQM0_READ))
  64. /* we have a read dma int */
  65. read_tiger(cs);
  66. if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_WRITE) !=
  67. (cs->hw.njet.last_is0 & NETJET_IRQM0_WRITE))
  68. /* we have a write dma int */
  69. write_tiger(cs);
  70. /* end new code 13/07/00 GE */
  71. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  72. }
  73. spin_unlock_irqrestore(&cs->lock, flags);
  74. return IRQ_HANDLED;
  75. }
  76. static void
  77. reset_netjet_u(struct IsdnCardState *cs)
  78. {
  79. cs->hw.njet.ctrl_reg = 0xff; /* Reset On */
  80. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  81. mdelay(10);
  82. cs->hw.njet.ctrl_reg = 0x40; /* Reset Off and status read clear */
  83. /* now edge triggered for TJ320 GE 13/07/00 */
  84. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  85. mdelay(10);
  86. cs->hw.njet.auxd = 0xC0;
  87. cs->hw.njet.dmactrl = 0;
  88. byteout(cs->hw.njet.auxa, 0);
  89. byteout(cs->hw.njet.base + NETJET_AUXCTRL, ~NETJET_ISACIRQ);
  90. byteout(cs->hw.njet.base + NETJET_IRQMASK1, NETJET_ISACIRQ);
  91. byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
  92. }
  93. static int
  94. NETjet_U_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  95. {
  96. u_long flags;
  97. switch (mt) {
  98. case CARD_RESET:
  99. spin_lock_irqsave(&cs->lock, flags);
  100. reset_netjet_u(cs);
  101. spin_unlock_irqrestore(&cs->lock, flags);
  102. return(0);
  103. case CARD_RELEASE:
  104. release_io_netjet(cs);
  105. return(0);
  106. case CARD_INIT:
  107. spin_lock_irqsave(&cs->lock, flags);
  108. inittiger(cs);
  109. reset_netjet_u(cs);
  110. clear_pending_icc_ints(cs);
  111. initicc(cs);
  112. /* Reenable all IRQ */
  113. cs->writeisac(cs, ICC_MASK, 0);
  114. spin_unlock_irqrestore(&cs->lock, flags);
  115. return(0);
  116. case CARD_TEST:
  117. return(0);
  118. }
  119. return(0);
  120. }
  121. static int __devinit nju_pci_probe(struct pci_dev *dev_netjet,
  122. struct IsdnCardState *cs)
  123. {
  124. if (pci_enable_device(dev_netjet))
  125. return(0);
  126. pci_set_master(dev_netjet);
  127. cs->irq = dev_netjet->irq;
  128. if (!cs->irq) {
  129. printk(KERN_WARNING "NETspider-U: No IRQ for PCI card found\n");
  130. return(0);
  131. }
  132. cs->hw.njet.base = pci_resource_start(dev_netjet, 0);
  133. if (!cs->hw.njet.base) {
  134. printk(KERN_WARNING "NETspider-U: No IO-Adr for PCI card found\n");
  135. return(0);
  136. }
  137. return (1);
  138. }
  139. static int __devinit nju_cs_init(struct IsdnCard *card,
  140. struct IsdnCardState *cs)
  141. {
  142. cs->hw.njet.auxa = cs->hw.njet.base + NETJET_AUXDATA;
  143. cs->hw.njet.isac = cs->hw.njet.base | NETJET_ISAC_OFF;
  144. mdelay(10);
  145. cs->hw.njet.ctrl_reg = 0xff; /* Reset On */
  146. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  147. mdelay(10);
  148. cs->hw.njet.ctrl_reg = 0x00; /* Reset Off and status read clear */
  149. byteout(cs->hw.njet.base + NETJET_CTRL, cs->hw.njet.ctrl_reg);
  150. mdelay(10);
  151. cs->hw.njet.auxd = 0xC0;
  152. cs->hw.njet.dmactrl = 0;
  153. byteout(cs->hw.njet.auxa, 0);
  154. byteout(cs->hw.njet.base + NETJET_AUXCTRL, ~NETJET_ISACIRQ);
  155. byteout(cs->hw.njet.base + NETJET_IRQMASK1, NETJET_ISACIRQ);
  156. byteout(cs->hw.njet.auxa, cs->hw.njet.auxd);
  157. switch ( ( ( NETjet_ReadIC( cs, ICC_RBCH ) >> 5 ) & 3 ) )
  158. {
  159. case 3 :
  160. return 1; /* end loop */
  161. case 0 :
  162. printk( KERN_WARNING "NETspider-U: NETjet-S PCI card found\n" );
  163. return -1; /* continue looping */
  164. default :
  165. printk( KERN_WARNING "NETspider-U: No PCI card found\n" );
  166. return 0; /* end loop & function */
  167. }
  168. return 1; /* end loop */
  169. }
  170. static int __devinit nju_cs_init_rest(struct IsdnCard *card,
  171. struct IsdnCardState *cs)
  172. {
  173. const int bytecnt = 256;
  174. printk(KERN_INFO
  175. "NETspider-U: PCI card configured at %#lx IRQ %d\n",
  176. cs->hw.njet.base, cs->irq);
  177. if (!request_region(cs->hw.njet.base, bytecnt, "netspider-u isdn")) {
  178. printk(KERN_WARNING
  179. "HiSax: NETspider-U config port %#lx-%#lx "
  180. "already in use\n",
  181. cs->hw.njet.base,
  182. cs->hw.njet.base + bytecnt);
  183. return (0);
  184. }
  185. setup_icc(cs);
  186. cs->readisac = &NETjet_ReadIC;
  187. cs->writeisac = &NETjet_WriteIC;
  188. cs->readisacfifo = &NETjet_ReadICfifo;
  189. cs->writeisacfifo = &NETjet_WriteICfifo;
  190. cs->BC_Read_Reg = &dummyrr;
  191. cs->BC_Write_Reg = &dummywr;
  192. cs->BC_Send_Data = &netjet_fill_dma;
  193. cs->cardmsg = &NETjet_U_card_msg;
  194. cs->irq_func = &netjet_u_interrupt;
  195. cs->irq_flags |= IRQF_SHARED;
  196. ICCVersion(cs, "NETspider-U:");
  197. return (1);
  198. }
  199. static struct pci_dev *dev_netjet __devinitdata = NULL;
  200. int __devinit
  201. setup_netjet_u(struct IsdnCard *card)
  202. {
  203. int ret;
  204. struct IsdnCardState *cs = card->cs;
  205. char tmp[64];
  206. #ifdef __BIG_ENDIAN
  207. #error "not running on big endian machines now"
  208. #endif
  209. strcpy(tmp, NETjet_U_revision);
  210. printk(KERN_INFO "HiSax: Traverse Tech. NETspider-U driver Rev. %s\n", HiSax_getrev(tmp));
  211. if (cs->typ != ISDN_CTYPE_NETJET_U)
  212. return(0);
  213. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  214. for ( ;; )
  215. {
  216. if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET,
  217. PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
  218. ret = nju_pci_probe(dev_netjet, cs);
  219. if (!ret)
  220. return(0);
  221. } else {
  222. printk(KERN_WARNING "NETspider-U: No PCI card found\n");
  223. return(0);
  224. }
  225. ret = nju_cs_init(card, cs);
  226. if (!ret)
  227. return (0);
  228. if (ret > 0)
  229. break;
  230. /* ret < 0 == continue looping */
  231. }
  232. return nju_cs_init_rest(card, cs);
  233. }