enternow_pci.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /* enternow_pci.c,v 0.99 2001/10/02
  2. *
  3. * enternow_pci.c Card-specific routines for
  4. * Formula-n enter:now ISDN PCI ab
  5. * Gerdes AG Power ISDN PCI
  6. * Woerltronic SA 16 PCI
  7. * (based on HiSax driver by Karsten Keil)
  8. *
  9. * Author Christoph Ersfeld <info@formula-n.de>
  10. * Formula-n Europe AG (www.formula-n.com)
  11. * previously Gerdes AG
  12. *
  13. *
  14. * This file is (c) under GNU PUBLIC LICENSE
  15. *
  16. * Notes:
  17. * This driver interfaces to netjet.c which performs B-channel
  18. * processing.
  19. *
  20. * Version 0.99 is the first release of this driver and there are
  21. * certainly a few bugs.
  22. * It isn't testet on linux 2.4 yet, so consider this code to be
  23. * beta.
  24. *
  25. * Please don't report me any malfunction without sending
  26. * (compressed) debug-logs.
  27. * It would be nearly impossible to retrace it.
  28. *
  29. * Log D-channel-processing as follows:
  30. *
  31. * 1. Load hisax with card-specific parameters, this example ist for
  32. * Formula-n enter:now ISDN PCI and compatible
  33. * (f.e. Gerdes Power ISDN PCI)
  34. *
  35. * modprobe hisax type=41 protocol=2 id=gerdes
  36. *
  37. * if you chose an other value for id, you need to modify the
  38. * code below, too.
  39. *
  40. * 2. set debug-level
  41. *
  42. * hisaxctrl gerdes 1 0x3ff
  43. * hisaxctrl gerdes 11 0x4f
  44. * cat /dev/isdnctrl >> ~/log &
  45. *
  46. * Please take also a look into /var/log/messages if there is
  47. * anything importand concerning HISAX.
  48. *
  49. *
  50. * Credits:
  51. * Programming the driver for Formula-n enter:now ISDN PCI and
  52. * necessary the driver for the used Amd 7930 D-channel-controller
  53. * was spnsored by Formula-n Europe AG.
  54. * Thanks to Karsten Keil and Petr Novak, who gave me support in
  55. * Hisax-specific questions.
  56. * I want so say special thanks to Carl-Friedrich Braun, who had to
  57. * answer a lot of questions about generally ISDN and about handling
  58. * of the Amd-Chip.
  59. *
  60. */
  61. #include "hisax.h"
  62. #include "isac.h"
  63. #include "isdnl1.h"
  64. #include "amd7930_fn.h"
  65. #include <linux/interrupt.h>
  66. #include <linux/ppp_defs.h>
  67. #include <linux/pci.h>
  68. #include <linux/init.h>
  69. #include "netjet.h"
  70. static const char *enternow_pci_rev = "$Revision: 1.1.4.5 $";
  71. /* for PowerISDN PCI */
  72. #define TJ_AMD_IRQ 0x20
  73. #define TJ_LED1 0x40
  74. #define TJ_LED2 0x80
  75. /* The window to [the] AMD [chip]...
  76. * From address hw.njet.base + TJ_AMD_PORT onwards, the AMD
  77. * maps [consecutive/multiple] 8 bits into the TigerJet I/O space
  78. * -> 0x01 of the AMD at hw.njet.base + 0C4 */
  79. #define TJ_AMD_PORT 0xC0
  80. /* *************************** I/O-Interface functions ************************************* */
  81. /* cs->readisac, macro rByteAMD */
  82. static unsigned char
  83. ReadByteAmd7930(struct IsdnCardState *cs, unsigned char offset)
  84. {
  85. /* direct register */
  86. if (offset < 8)
  87. return (inb(cs->hw.njet.isac + 4 * offset));
  88. /* indirect register */
  89. else {
  90. outb(offset, cs->hw.njet.isac + 4 * AMD_CR);
  91. return (inb(cs->hw.njet.isac + 4 * AMD_DR));
  92. }
  93. }
  94. /* cs->writeisac, macro wByteAMD */
  95. static void
  96. WriteByteAmd7930(struct IsdnCardState *cs, unsigned char offset, unsigned char value)
  97. {
  98. /* direct register */
  99. if (offset < 8)
  100. outb(value, cs->hw.njet.isac + 4 * offset);
  101. /* indirect register */
  102. else {
  103. outb(offset, cs->hw.njet.isac + 4 * AMD_CR);
  104. outb(value, cs->hw.njet.isac + 4 * AMD_DR);
  105. }
  106. }
  107. static void
  108. enpci_setIrqMask(struct IsdnCardState *cs, unsigned char val) {
  109. if (!val)
  110. outb(0x00, cs->hw.njet.base + NETJET_IRQMASK1);
  111. else
  112. outb(TJ_AMD_IRQ, cs->hw.njet.base + NETJET_IRQMASK1);
  113. }
  114. static unsigned char dummyrr(struct IsdnCardState *cs, int chan, unsigned char off)
  115. {
  116. return (5);
  117. }
  118. static void dummywr(struct IsdnCardState *cs, int chan, unsigned char off, unsigned char value)
  119. {
  120. }
  121. /* ******************************************************************************** */
  122. static void
  123. reset_enpci(struct IsdnCardState *cs)
  124. {
  125. if (cs->debug & L1_DEB_ISAC)
  126. debugl1(cs, "enter:now PCI: reset");
  127. /* Reset on, (also for AMD) */
  128. cs->hw.njet.ctrl_reg = 0x07;
  129. outb(cs->hw.njet.ctrl_reg, cs->hw.njet.base + NETJET_CTRL);
  130. mdelay(20);
  131. /* Reset off */
  132. cs->hw.njet.ctrl_reg = 0x30;
  133. outb(cs->hw.njet.ctrl_reg, cs->hw.njet.base + NETJET_CTRL);
  134. /* 20ms delay */
  135. mdelay(20);
  136. cs->hw.njet.auxd = 0; // LED-status
  137. cs->hw.njet.dmactrl = 0;
  138. outb(~TJ_AMD_IRQ, cs->hw.njet.base + NETJET_AUXCTRL);
  139. outb(TJ_AMD_IRQ, cs->hw.njet.base + NETJET_IRQMASK1);
  140. outb(cs->hw.njet.auxd, cs->hw.njet.auxa); // LED off
  141. }
  142. static int
  143. enpci_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  144. {
  145. u_long flags;
  146. unsigned char *chan;
  147. if (cs->debug & L1_DEB_ISAC)
  148. debugl1(cs, "enter:now PCI: card_msg: 0x%04X", mt);
  149. switch (mt) {
  150. case CARD_RESET:
  151. spin_lock_irqsave(&cs->lock, flags);
  152. reset_enpci(cs);
  153. Amd7930_init(cs);
  154. spin_unlock_irqrestore(&cs->lock, flags);
  155. break;
  156. case CARD_RELEASE:
  157. release_io_netjet(cs);
  158. break;
  159. case CARD_INIT:
  160. reset_enpci(cs);
  161. inittiger(cs);
  162. /* irq must be on here */
  163. Amd7930_init(cs);
  164. break;
  165. case CARD_TEST:
  166. break;
  167. case MDL_ASSIGN:
  168. /* TEI assigned, LED1 on */
  169. cs->hw.njet.auxd = TJ_AMD_IRQ << 1;
  170. outb(cs->hw.njet.auxd, cs->hw.njet.base + NETJET_AUXDATA);
  171. break;
  172. case MDL_REMOVE:
  173. /* TEI removed, LEDs off */
  174. cs->hw.njet.auxd = 0;
  175. outb(0x00, cs->hw.njet.base + NETJET_AUXDATA);
  176. break;
  177. case MDL_BC_ASSIGN:
  178. /* activate B-channel */
  179. chan = (unsigned char *)arg;
  180. if (cs->debug & L1_DEB_ISAC)
  181. debugl1(cs, "enter:now PCI: assign phys. BC %d in AMD LMR1", *chan);
  182. cs->dc.amd7930.ph_command(cs, (cs->dc.amd7930.lmr1 | (*chan + 1)), "MDL_BC_ASSIGN");
  183. /* at least one b-channel in use, LED 2 on */
  184. cs->hw.njet.auxd |= TJ_AMD_IRQ << 2;
  185. outb(cs->hw.njet.auxd, cs->hw.njet.base + NETJET_AUXDATA);
  186. break;
  187. case MDL_BC_RELEASE:
  188. /* deactivate B-channel */
  189. chan = (unsigned char *)arg;
  190. if (cs->debug & L1_DEB_ISAC)
  191. debugl1(cs, "enter:now PCI: release phys. BC %d in Amd LMR1", *chan);
  192. cs->dc.amd7930.ph_command(cs, (cs->dc.amd7930.lmr1 & ~(*chan + 1)), "MDL_BC_RELEASE");
  193. /* no b-channel active -> LED2 off */
  194. if (!(cs->dc.amd7930.lmr1 & 3)) {
  195. cs->hw.njet.auxd &= ~(TJ_AMD_IRQ << 2);
  196. outb(cs->hw.njet.auxd, cs->hw.njet.base + NETJET_AUXDATA);
  197. }
  198. break;
  199. default:
  200. break;
  201. }
  202. return (0);
  203. }
  204. static irqreturn_t
  205. enpci_interrupt(int intno, void *dev_id)
  206. {
  207. struct IsdnCardState *cs = dev_id;
  208. unsigned char s0val, s1val, ir;
  209. u_long flags;
  210. spin_lock_irqsave(&cs->lock, flags);
  211. s1val = inb(cs->hw.njet.base + NETJET_IRQSTAT1);
  212. /* AMD threw an interrupt */
  213. if (!(s1val & TJ_AMD_IRQ)) {
  214. /* read and clear interrupt-register */
  215. ir = ReadByteAmd7930(cs, 0x00);
  216. Amd7930_interrupt(cs, ir);
  217. s1val = 1;
  218. } else
  219. s1val = 0;
  220. s0val = inb(cs->hw.njet.base + NETJET_IRQSTAT0);
  221. if ((s0val | s1val) == 0) { // shared IRQ
  222. spin_unlock_irqrestore(&cs->lock, flags);
  223. return IRQ_NONE;
  224. }
  225. if (s0val)
  226. outb(s0val, cs->hw.njet.base + NETJET_IRQSTAT0);
  227. /* DMA-Interrupt: B-channel-stuff */
  228. /* set bits in sval to indicate which page is free */
  229. if (inl(cs->hw.njet.base + NETJET_DMA_WRITE_ADR) <
  230. inl(cs->hw.njet.base + NETJET_DMA_WRITE_IRQ))
  231. /* the 2nd write page is free */
  232. s0val = 0x08;
  233. else /* the 1st write page is free */
  234. s0val = 0x04;
  235. if (inl(cs->hw.njet.base + NETJET_DMA_READ_ADR) <
  236. inl(cs->hw.njet.base + NETJET_DMA_READ_IRQ))
  237. /* the 2nd read page is free */
  238. s0val = s0val | 0x02;
  239. else /* the 1st read page is free */
  240. s0val = s0val | 0x01;
  241. if (s0val != cs->hw.njet.last_is0) /* we have a DMA interrupt */
  242. {
  243. if (test_and_set_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags)) {
  244. spin_unlock_irqrestore(&cs->lock, flags);
  245. return IRQ_HANDLED;
  246. }
  247. cs->hw.njet.irqstat0 = s0val;
  248. if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_READ) !=
  249. (cs->hw.njet.last_is0 & NETJET_IRQM0_READ))
  250. /* we have a read dma int */
  251. read_tiger(cs);
  252. if ((cs->hw.njet.irqstat0 & NETJET_IRQM0_WRITE) !=
  253. (cs->hw.njet.last_is0 & NETJET_IRQM0_WRITE))
  254. /* we have a write dma int */
  255. write_tiger(cs);
  256. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  257. }
  258. spin_unlock_irqrestore(&cs->lock, flags);
  259. return IRQ_HANDLED;
  260. }
  261. static int en_pci_probe(struct pci_dev *dev_netjet, struct IsdnCardState *cs)
  262. {
  263. if (pci_enable_device(dev_netjet))
  264. return (0);
  265. cs->irq = dev_netjet->irq;
  266. if (!cs->irq) {
  267. printk(KERN_WARNING "enter:now PCI: No IRQ for PCI card found\n");
  268. return (0);
  269. }
  270. cs->hw.njet.base = pci_resource_start(dev_netjet, 0);
  271. if (!cs->hw.njet.base) {
  272. printk(KERN_WARNING "enter:now PCI: No IO-Adr for PCI card found\n");
  273. return (0);
  274. }
  275. /* checks Sub-Vendor ID because system crashes with Traverse-Card */
  276. if ((dev_netjet->subsystem_vendor != 0x55) ||
  277. (dev_netjet->subsystem_device != 0x02)) {
  278. printk(KERN_WARNING "enter:now: You tried to load this driver with an incompatible TigerJet-card\n");
  279. printk(KERN_WARNING "Use type=20 for Traverse NetJet PCI Card.\n");
  280. return (0);
  281. }
  282. return (1);
  283. }
  284. static void en_cs_init(struct IsdnCard *card, struct IsdnCardState *cs)
  285. {
  286. cs->hw.njet.auxa = cs->hw.njet.base + NETJET_AUXDATA;
  287. cs->hw.njet.isac = cs->hw.njet.base + 0xC0; // Fenster zum AMD
  288. /* Reset an */
  289. cs->hw.njet.ctrl_reg = 0x07; // geändert von 0xff
  290. outb(cs->hw.njet.ctrl_reg, cs->hw.njet.base + NETJET_CTRL);
  291. /* 20 ms Pause */
  292. mdelay(20);
  293. cs->hw.njet.ctrl_reg = 0x30; /* Reset Off and status read clear */
  294. outb(cs->hw.njet.ctrl_reg, cs->hw.njet.base + NETJET_CTRL);
  295. mdelay(10);
  296. cs->hw.njet.auxd = 0x00; // war 0xc0
  297. cs->hw.njet.dmactrl = 0;
  298. outb(~TJ_AMD_IRQ, cs->hw.njet.base + NETJET_AUXCTRL);
  299. outb(TJ_AMD_IRQ, cs->hw.njet.base + NETJET_IRQMASK1);
  300. outb(cs->hw.njet.auxd, cs->hw.njet.auxa);
  301. }
  302. static int en_cs_init_rest(struct IsdnCard *card, struct IsdnCardState *cs)
  303. {
  304. const int bytecnt = 256;
  305. printk(KERN_INFO
  306. "enter:now PCI: PCI card configured at 0x%lx IRQ %d\n",
  307. cs->hw.njet.base, cs->irq);
  308. if (!request_region(cs->hw.njet.base, bytecnt, "Fn_ISDN")) {
  309. printk(KERN_WARNING
  310. "HiSax: enter:now config port %lx-%lx already in use\n",
  311. cs->hw.njet.base,
  312. cs->hw.njet.base + bytecnt);
  313. return (0);
  314. }
  315. setup_Amd7930(cs);
  316. cs->hw.njet.last_is0 = 0;
  317. /* macro rByteAMD */
  318. cs->readisac = &ReadByteAmd7930;
  319. /* macro wByteAMD */
  320. cs->writeisac = &WriteByteAmd7930;
  321. cs->dc.amd7930.setIrqMask = &enpci_setIrqMask;
  322. cs->BC_Read_Reg = &dummyrr;
  323. cs->BC_Write_Reg = &dummywr;
  324. cs->BC_Send_Data = &netjet_fill_dma;
  325. cs->cardmsg = &enpci_card_msg;
  326. cs->irq_func = &enpci_interrupt;
  327. cs->irq_flags |= IRQF_SHARED;
  328. return (1);
  329. }
  330. static struct pci_dev *dev_netjet = NULL;
  331. /* called by config.c */
  332. int setup_enternow_pci(struct IsdnCard *card)
  333. {
  334. int ret;
  335. struct IsdnCardState *cs = card->cs;
  336. char tmp[64];
  337. #ifdef __BIG_ENDIAN
  338. #error "not running on big endian machines now"
  339. #endif
  340. strcpy(tmp, enternow_pci_rev);
  341. printk(KERN_INFO "HiSax: Formula-n Europe AG enter:now ISDN PCI driver Rev. %s\n", HiSax_getrev(tmp));
  342. if (cs->typ != ISDN_CTYPE_ENTERNOW)
  343. return (0);
  344. test_and_clear_bit(FLG_LOCK_ATOMIC, &cs->HW_Flags);
  345. for (;;)
  346. {
  347. if ((dev_netjet = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET,
  348. PCI_DEVICE_ID_TIGERJET_300, dev_netjet))) {
  349. ret = en_pci_probe(dev_netjet, cs);
  350. if (!ret)
  351. return (0);
  352. } else {
  353. printk(KERN_WARNING "enter:now PCI: No PCI card found\n");
  354. return (0);
  355. }
  356. en_cs_init(card, cs);
  357. break;
  358. }
  359. return en_cs_init_rest(card, cs);
  360. }