diva.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /* $Id: diva.c,v 1.33.2.6 2004/02/11 13:21:33 keil Exp $
  2. *
  3. * low level stuff for Eicon.Diehl Diva Family ISDN cards
  4. *
  5. * Author Karsten Keil
  6. * Copyright by Karsten Keil <keil@isdn4linux.de>
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. * For changes and modifications please read
  12. * Documentation/isdn/HiSax.cert
  13. *
  14. * Thanks to Eicon Technology for documents and information
  15. *
  16. */
  17. #include <linux/init.h>
  18. #include <linux/config.h>
  19. #include "hisax.h"
  20. #include "isac.h"
  21. #include "hscx.h"
  22. #include "ipac.h"
  23. #include "ipacx.h"
  24. #include "isdnl1.h"
  25. #include <linux/pci.h>
  26. #include <linux/isapnp.h>
  27. extern const char *CardType[];
  28. static const char *Diva_revision = "$Revision: 1.33.2.6 $";
  29. #define byteout(addr,val) outb(val,addr)
  30. #define bytein(addr) inb(addr)
  31. #define DIVA_HSCX_DATA 0
  32. #define DIVA_HSCX_ADR 4
  33. #define DIVA_ISA_ISAC_DATA 2
  34. #define DIVA_ISA_ISAC_ADR 6
  35. #define DIVA_ISA_CTRL 7
  36. #define DIVA_IPAC_ADR 0
  37. #define DIVA_IPAC_DATA 1
  38. #define DIVA_PCI_ISAC_DATA 8
  39. #define DIVA_PCI_ISAC_ADR 0xc
  40. #define DIVA_PCI_CTRL 0x10
  41. /* SUB Types */
  42. #define DIVA_ISA 1
  43. #define DIVA_PCI 2
  44. #define DIVA_IPAC_ISA 3
  45. #define DIVA_IPAC_PCI 4
  46. #define DIVA_IPACX_PCI 5
  47. /* CTRL (Read) */
  48. #define DIVA_IRQ_STAT 0x01
  49. #define DIVA_EEPROM_SDA 0x02
  50. /* CTRL (Write) */
  51. #define DIVA_IRQ_REQ 0x01
  52. #define DIVA_RESET 0x08
  53. #define DIVA_EEPROM_CLK 0x40
  54. #define DIVA_PCI_LED_A 0x10
  55. #define DIVA_PCI_LED_B 0x20
  56. #define DIVA_ISA_LED_A 0x20
  57. #define DIVA_ISA_LED_B 0x40
  58. #define DIVA_IRQ_CLR 0x80
  59. /* Siemens PITA */
  60. #define PITA_MISC_REG 0x1c
  61. #ifdef __BIG_ENDIAN
  62. #define PITA_PARA_SOFTRESET 0x00000001
  63. #define PITA_SER_SOFTRESET 0x00000002
  64. #define PITA_PARA_MPX_MODE 0x00000004
  65. #define PITA_INT0_ENABLE 0x00000200
  66. #else
  67. #define PITA_PARA_SOFTRESET 0x01000000
  68. #define PITA_SER_SOFTRESET 0x02000000
  69. #define PITA_PARA_MPX_MODE 0x04000000
  70. #define PITA_INT0_ENABLE 0x00020000
  71. #endif
  72. #define PITA_INT0_STATUS 0x02
  73. static inline u_char
  74. readreg(unsigned int ale, unsigned int adr, u_char off)
  75. {
  76. register u_char ret;
  77. byteout(ale, off);
  78. ret = bytein(adr);
  79. return (ret);
  80. }
  81. static inline void
  82. readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
  83. {
  84. byteout(ale, off);
  85. insb(adr, data, size);
  86. }
  87. static inline void
  88. writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
  89. {
  90. byteout(ale, off);
  91. byteout(adr, data);
  92. }
  93. static inline void
  94. writefifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
  95. {
  96. byteout(ale, off);
  97. outsb(adr, data, size);
  98. }
  99. static inline u_char
  100. memreadreg(unsigned long adr, u_char off)
  101. {
  102. return(*((unsigned char *)
  103. (((unsigned int *)adr) + off)));
  104. }
  105. static inline void
  106. memwritereg(unsigned long adr, u_char off, u_char data)
  107. {
  108. register u_char *p;
  109. p = (unsigned char *)(((unsigned int *)adr) + off);
  110. *p = data;
  111. }
  112. /* Interface functions */
  113. static u_char
  114. ReadISAC(struct IsdnCardState *cs, u_char offset)
  115. {
  116. return(readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, offset));
  117. }
  118. static void
  119. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  120. {
  121. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, offset, value);
  122. }
  123. static void
  124. ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  125. {
  126. readfifo(cs->hw.diva.isac_adr, cs->hw.diva.isac, 0, data, size);
  127. }
  128. static void
  129. WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  130. {
  131. writefifo(cs->hw.diva.isac_adr, cs->hw.diva.isac, 0, data, size);
  132. }
  133. static u_char
  134. ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
  135. {
  136. return (readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, offset+0x80));
  137. }
  138. static void
  139. WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
  140. {
  141. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, offset|0x80, value);
  142. }
  143. static void
  144. ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
  145. {
  146. readfifo(cs->hw.diva.isac_adr, cs->hw.diva.isac, 0x80, data, size);
  147. }
  148. static void
  149. WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
  150. {
  151. writefifo(cs->hw.diva.isac_adr, cs->hw.diva.isac, 0x80, data, size);
  152. }
  153. static u_char
  154. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  155. {
  156. return(readreg(cs->hw.diva.hscx_adr,
  157. cs->hw.diva.hscx, offset + (hscx ? 0x40 : 0)));
  158. }
  159. static void
  160. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  161. {
  162. writereg(cs->hw.diva.hscx_adr,
  163. cs->hw.diva.hscx, offset + (hscx ? 0x40 : 0), value);
  164. }
  165. static u_char
  166. MemReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
  167. {
  168. return (memreadreg(cs->hw.diva.cfg_reg, offset+0x80));
  169. }
  170. static void
  171. MemWriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
  172. {
  173. memwritereg(cs->hw.diva.cfg_reg, offset|0x80, value);
  174. }
  175. static void
  176. MemReadISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
  177. {
  178. while(size--)
  179. *data++ = memreadreg(cs->hw.diva.cfg_reg, 0x80);
  180. }
  181. static void
  182. MemWriteISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
  183. {
  184. while(size--)
  185. memwritereg(cs->hw.diva.cfg_reg, 0x80, *data++);
  186. }
  187. static u_char
  188. MemReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  189. {
  190. return(memreadreg(cs->hw.diva.cfg_reg, offset + (hscx ? 0x40 : 0)));
  191. }
  192. static void
  193. MemWriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  194. {
  195. memwritereg(cs->hw.diva.cfg_reg, offset + (hscx ? 0x40 : 0), value);
  196. }
  197. /* IO-Functions for IPACX type cards */
  198. static u_char
  199. MemReadISAC_IPACX(struct IsdnCardState *cs, u_char offset)
  200. {
  201. return (memreadreg(cs->hw.diva.cfg_reg, offset));
  202. }
  203. static void
  204. MemWriteISAC_IPACX(struct IsdnCardState *cs, u_char offset, u_char value)
  205. {
  206. memwritereg(cs->hw.diva.cfg_reg, offset, value);
  207. }
  208. static void
  209. MemReadISACfifo_IPACX(struct IsdnCardState *cs, u_char * data, int size)
  210. {
  211. while(size--)
  212. *data++ = memreadreg(cs->hw.diva.cfg_reg, 0);
  213. }
  214. static void
  215. MemWriteISACfifo_IPACX(struct IsdnCardState *cs, u_char * data, int size)
  216. {
  217. while(size--)
  218. memwritereg(cs->hw.diva.cfg_reg, 0, *data++);
  219. }
  220. static u_char
  221. MemReadHSCX_IPACX(struct IsdnCardState *cs, int hscx, u_char offset)
  222. {
  223. return(memreadreg(cs->hw.diva.cfg_reg, offset +
  224. (hscx ? IPACX_OFF_B2 : IPACX_OFF_B1)));
  225. }
  226. static void
  227. MemWriteHSCX_IPACX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  228. {
  229. memwritereg(cs->hw.diva.cfg_reg, offset +
  230. (hscx ? IPACX_OFF_B2 : IPACX_OFF_B1), value);
  231. }
  232. /*
  233. * fast interrupt HSCX stuff goes here
  234. */
  235. #define READHSCX(cs, nr, reg) readreg(cs->hw.diva.hscx_adr, \
  236. cs->hw.diva.hscx, reg + (nr ? 0x40 : 0))
  237. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.diva.hscx_adr, \
  238. cs->hw.diva.hscx, reg + (nr ? 0x40 : 0), data)
  239. #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.diva.hscx_adr, \
  240. cs->hw.diva.hscx, (nr ? 0x40 : 0), ptr, cnt)
  241. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.diva.hscx_adr, \
  242. cs->hw.diva.hscx, (nr ? 0x40 : 0), ptr, cnt)
  243. #include "hscx_irq.c"
  244. static irqreturn_t
  245. diva_interrupt(int intno, void *dev_id, struct pt_regs *regs)
  246. {
  247. struct IsdnCardState *cs = dev_id;
  248. u_char val, sval;
  249. u_long flags;
  250. int cnt=5;
  251. spin_lock_irqsave(&cs->lock, flags);
  252. while (((sval = bytein(cs->hw.diva.ctrl)) & DIVA_IRQ_REQ) && cnt) {
  253. val = readreg(cs->hw.diva.hscx_adr, cs->hw.diva.hscx, HSCX_ISTA + 0x40);
  254. if (val)
  255. hscx_int_main(cs, val);
  256. val = readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, ISAC_ISTA);
  257. if (val)
  258. isac_interrupt(cs, val);
  259. cnt--;
  260. }
  261. if (!cnt)
  262. printk(KERN_WARNING "Diva: IRQ LOOP\n");
  263. writereg(cs->hw.diva.hscx_adr, cs->hw.diva.hscx, HSCX_MASK, 0xFF);
  264. writereg(cs->hw.diva.hscx_adr, cs->hw.diva.hscx, HSCX_MASK + 0x40, 0xFF);
  265. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, ISAC_MASK, 0xFF);
  266. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, ISAC_MASK, 0x0);
  267. writereg(cs->hw.diva.hscx_adr, cs->hw.diva.hscx, HSCX_MASK, 0x0);
  268. writereg(cs->hw.diva.hscx_adr, cs->hw.diva.hscx, HSCX_MASK + 0x40, 0x0);
  269. spin_unlock_irqrestore(&cs->lock, flags);
  270. return IRQ_HANDLED;
  271. }
  272. static irqreturn_t
  273. diva_irq_ipac_isa(int intno, void *dev_id, struct pt_regs *regs)
  274. {
  275. struct IsdnCardState *cs = dev_id;
  276. u_char ista,val;
  277. u_long flags;
  278. int icnt=5;
  279. spin_lock_irqsave(&cs->lock, flags);
  280. ista = readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_ISTA);
  281. Start_IPACISA:
  282. if (cs->debug & L1_DEB_IPAC)
  283. debugl1(cs, "IPAC ISTA %02X", ista);
  284. if (ista & 0x0f) {
  285. val = readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, HSCX_ISTA + 0x40);
  286. if (ista & 0x01)
  287. val |= 0x01;
  288. if (ista & 0x04)
  289. val |= 0x02;
  290. if (ista & 0x08)
  291. val |= 0x04;
  292. if (val)
  293. hscx_int_main(cs, val);
  294. }
  295. if (ista & 0x20) {
  296. val = 0xfe & readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, ISAC_ISTA + 0x80);
  297. if (val) {
  298. isac_interrupt(cs, val);
  299. }
  300. }
  301. if (ista & 0x10) {
  302. val = 0x01;
  303. isac_interrupt(cs, val);
  304. }
  305. ista = readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_ISTA);
  306. if ((ista & 0x3f) && icnt) {
  307. icnt--;
  308. goto Start_IPACISA;
  309. }
  310. if (!icnt)
  311. printk(KERN_WARNING "DIVA IPAC IRQ LOOP\n");
  312. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_MASK, 0xFF);
  313. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_MASK, 0xC0);
  314. spin_unlock_irqrestore(&cs->lock, flags);
  315. return IRQ_HANDLED;
  316. }
  317. static inline void
  318. MemwaitforCEC(struct IsdnCardState *cs, int hscx)
  319. {
  320. int to = 50;
  321. while ((MemReadHSCX(cs, hscx, HSCX_STAR) & 0x04) && to) {
  322. udelay(1);
  323. to--;
  324. }
  325. if (!to)
  326. printk(KERN_WARNING "HiSax: waitforCEC timeout\n");
  327. }
  328. static inline void
  329. MemwaitforXFW(struct IsdnCardState *cs, int hscx)
  330. {
  331. int to = 50;
  332. while ((!(MemReadHSCX(cs, hscx, HSCX_STAR) & 0x44) == 0x40) && to) {
  333. udelay(1);
  334. to--;
  335. }
  336. if (!to)
  337. printk(KERN_WARNING "HiSax: waitforXFW timeout\n");
  338. }
  339. static inline void
  340. MemWriteHSCXCMDR(struct IsdnCardState *cs, int hscx, u_char data)
  341. {
  342. MemwaitforCEC(cs, hscx);
  343. MemWriteHSCX(cs, hscx, HSCX_CMDR, data);
  344. }
  345. static void
  346. Memhscx_empty_fifo(struct BCState *bcs, int count)
  347. {
  348. u_char *ptr;
  349. struct IsdnCardState *cs = bcs->cs;
  350. int cnt;
  351. if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
  352. debugl1(cs, "hscx_empty_fifo");
  353. if (bcs->hw.hscx.rcvidx + count > HSCX_BUFMAX) {
  354. if (cs->debug & L1_DEB_WARN)
  355. debugl1(cs, "hscx_empty_fifo: incoming packet too large");
  356. MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x80);
  357. bcs->hw.hscx.rcvidx = 0;
  358. return;
  359. }
  360. ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx;
  361. cnt = count;
  362. while (cnt--)
  363. *ptr++ = memreadreg(cs->hw.diva.cfg_reg, bcs->hw.hscx.hscx ? 0x40 : 0);
  364. MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x80);
  365. ptr = bcs->hw.hscx.rcvbuf + bcs->hw.hscx.rcvidx;
  366. bcs->hw.hscx.rcvidx += count;
  367. if (cs->debug & L1_DEB_HSCX_FIFO) {
  368. char *t = bcs->blog;
  369. t += sprintf(t, "hscx_empty_fifo %c cnt %d",
  370. bcs->hw.hscx.hscx ? 'B' : 'A', count);
  371. QuickHex(t, ptr, count);
  372. debugl1(cs, bcs->blog);
  373. }
  374. }
  375. static void
  376. Memhscx_fill_fifo(struct BCState *bcs)
  377. {
  378. struct IsdnCardState *cs = bcs->cs;
  379. int more, count, cnt;
  380. int fifo_size = test_bit(HW_IPAC, &cs->HW_Flags)? 64: 32;
  381. u_char *ptr,*p;
  382. if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
  383. debugl1(cs, "hscx_fill_fifo");
  384. if (!bcs->tx_skb)
  385. return;
  386. if (bcs->tx_skb->len <= 0)
  387. return;
  388. more = (bcs->mode == L1_MODE_TRANS) ? 1 : 0;
  389. if (bcs->tx_skb->len > fifo_size) {
  390. more = !0;
  391. count = fifo_size;
  392. } else
  393. count = bcs->tx_skb->len;
  394. cnt = count;
  395. MemwaitforXFW(cs, bcs->hw.hscx.hscx);
  396. p = ptr = bcs->tx_skb->data;
  397. skb_pull(bcs->tx_skb, count);
  398. bcs->tx_cnt -= count;
  399. bcs->hw.hscx.count += count;
  400. while(cnt--)
  401. memwritereg(cs->hw.diva.cfg_reg, bcs->hw.hscx.hscx ? 0x40 : 0,
  402. *p++);
  403. MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, more ? 0x8 : 0xa);
  404. if (cs->debug & L1_DEB_HSCX_FIFO) {
  405. char *t = bcs->blog;
  406. t += sprintf(t, "hscx_fill_fifo %c cnt %d",
  407. bcs->hw.hscx.hscx ? 'B' : 'A', count);
  408. QuickHex(t, ptr, count);
  409. debugl1(cs, bcs->blog);
  410. }
  411. }
  412. static void
  413. Memhscx_interrupt(struct IsdnCardState *cs, u_char val, u_char hscx)
  414. {
  415. u_char r;
  416. struct BCState *bcs = cs->bcs + hscx;
  417. struct sk_buff *skb;
  418. int fifo_size = test_bit(HW_IPAC, &cs->HW_Flags)? 64: 32;
  419. int count;
  420. if (!test_bit(BC_FLG_INIT, &bcs->Flag))
  421. return;
  422. if (val & 0x80) { /* RME */
  423. r = MemReadHSCX(cs, hscx, HSCX_RSTA);
  424. if ((r & 0xf0) != 0xa0) {
  425. if (!(r & 0x80))
  426. if (cs->debug & L1_DEB_WARN)
  427. debugl1(cs, "HSCX invalid frame");
  428. if ((r & 0x40) && bcs->mode)
  429. if (cs->debug & L1_DEB_WARN)
  430. debugl1(cs, "HSCX RDO mode=%d",
  431. bcs->mode);
  432. if (!(r & 0x20))
  433. if (cs->debug & L1_DEB_WARN)
  434. debugl1(cs, "HSCX CRC error");
  435. MemWriteHSCXCMDR(cs, hscx, 0x80);
  436. } else {
  437. count = MemReadHSCX(cs, hscx, HSCX_RBCL) & (
  438. test_bit(HW_IPAC, &cs->HW_Flags)? 0x3f: 0x1f);
  439. if (count == 0)
  440. count = fifo_size;
  441. Memhscx_empty_fifo(bcs, count);
  442. if ((count = bcs->hw.hscx.rcvidx - 1) > 0) {
  443. if (cs->debug & L1_DEB_HSCX_FIFO)
  444. debugl1(cs, "HX Frame %d", count);
  445. if (!(skb = dev_alloc_skb(count)))
  446. printk(KERN_WARNING "HSCX: receive out of memory\n");
  447. else {
  448. memcpy(skb_put(skb, count), bcs->hw.hscx.rcvbuf, count);
  449. skb_queue_tail(&bcs->rqueue, skb);
  450. }
  451. }
  452. }
  453. bcs->hw.hscx.rcvidx = 0;
  454. schedule_event(bcs, B_RCVBUFREADY);
  455. }
  456. if (val & 0x40) { /* RPF */
  457. Memhscx_empty_fifo(bcs, fifo_size);
  458. if (bcs->mode == L1_MODE_TRANS) {
  459. /* receive audio data */
  460. if (!(skb = dev_alloc_skb(fifo_size)))
  461. printk(KERN_WARNING "HiSax: receive out of memory\n");
  462. else {
  463. memcpy(skb_put(skb, fifo_size), bcs->hw.hscx.rcvbuf, fifo_size);
  464. skb_queue_tail(&bcs->rqueue, skb);
  465. }
  466. bcs->hw.hscx.rcvidx = 0;
  467. schedule_event(bcs, B_RCVBUFREADY);
  468. }
  469. }
  470. if (val & 0x10) { /* XPR */
  471. if (bcs->tx_skb) {
  472. if (bcs->tx_skb->len) {
  473. Memhscx_fill_fifo(bcs);
  474. return;
  475. } else {
  476. if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag) &&
  477. (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
  478. u_long flags;
  479. spin_lock_irqsave(&bcs->aclock, flags);
  480. bcs->ackcnt += bcs->hw.hscx.count;
  481. spin_unlock_irqrestore(&bcs->aclock, flags);
  482. schedule_event(bcs, B_ACKPENDING);
  483. }
  484. dev_kfree_skb_irq(bcs->tx_skb);
  485. bcs->hw.hscx.count = 0;
  486. bcs->tx_skb = NULL;
  487. }
  488. }
  489. if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
  490. bcs->hw.hscx.count = 0;
  491. test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
  492. Memhscx_fill_fifo(bcs);
  493. } else {
  494. test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
  495. schedule_event(bcs, B_XMTBUFREADY);
  496. }
  497. }
  498. }
  499. static inline void
  500. Memhscx_int_main(struct IsdnCardState *cs, u_char val)
  501. {
  502. u_char exval;
  503. struct BCState *bcs;
  504. if (val & 0x01) { // EXB
  505. bcs = cs->bcs + 1;
  506. exval = MemReadHSCX(cs, 1, HSCX_EXIR);
  507. if (exval & 0x40) {
  508. if (bcs->mode == 1)
  509. Memhscx_fill_fifo(bcs);
  510. else {
  511. /* Here we lost an TX interrupt, so
  512. * restart transmitting the whole frame.
  513. */
  514. if (bcs->tx_skb) {
  515. skb_push(bcs->tx_skb, bcs->hw.hscx.count);
  516. bcs->tx_cnt += bcs->hw.hscx.count;
  517. bcs->hw.hscx.count = 0;
  518. }
  519. MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x01);
  520. if (cs->debug & L1_DEB_WARN)
  521. debugl1(cs, "HSCX B EXIR %x Lost TX", exval);
  522. }
  523. } else if (cs->debug & L1_DEB_HSCX)
  524. debugl1(cs, "HSCX B EXIR %x", exval);
  525. }
  526. if (val & 0xf8) {
  527. if (cs->debug & L1_DEB_HSCX)
  528. debugl1(cs, "HSCX B interrupt %x", val);
  529. Memhscx_interrupt(cs, val, 1);
  530. }
  531. if (val & 0x02) { // EXA
  532. bcs = cs->bcs;
  533. exval = MemReadHSCX(cs, 0, HSCX_EXIR);
  534. if (exval & 0x40) {
  535. if (bcs->mode == L1_MODE_TRANS)
  536. Memhscx_fill_fifo(bcs);
  537. else {
  538. /* Here we lost an TX interrupt, so
  539. * restart transmitting the whole frame.
  540. */
  541. if (bcs->tx_skb) {
  542. skb_push(bcs->tx_skb, bcs->hw.hscx.count);
  543. bcs->tx_cnt += bcs->hw.hscx.count;
  544. bcs->hw.hscx.count = 0;
  545. }
  546. MemWriteHSCXCMDR(cs, bcs->hw.hscx.hscx, 0x01);
  547. if (cs->debug & L1_DEB_WARN)
  548. debugl1(cs, "HSCX A EXIR %x Lost TX", exval);
  549. }
  550. } else if (cs->debug & L1_DEB_HSCX)
  551. debugl1(cs, "HSCX A EXIR %x", exval);
  552. }
  553. if (val & 0x04) { // ICA
  554. exval = MemReadHSCX(cs, 0, HSCX_ISTA);
  555. if (cs->debug & L1_DEB_HSCX)
  556. debugl1(cs, "HSCX A interrupt %x", exval);
  557. Memhscx_interrupt(cs, exval, 0);
  558. }
  559. }
  560. static irqreturn_t
  561. diva_irq_ipac_pci(int intno, void *dev_id, struct pt_regs *regs)
  562. {
  563. struct IsdnCardState *cs = dev_id;
  564. u_char ista,val;
  565. int icnt=5;
  566. u_char *cfg;
  567. u_long flags;
  568. spin_lock_irqsave(&cs->lock, flags);
  569. cfg = (u_char *) cs->hw.diva.pci_cfg;
  570. val = *cfg;
  571. if (!(val & PITA_INT0_STATUS)) {
  572. spin_unlock_irqrestore(&cs->lock, flags);
  573. return IRQ_NONE; /* other shared IRQ */
  574. }
  575. *cfg = PITA_INT0_STATUS; /* Reset pending INT0 */
  576. ista = memreadreg(cs->hw.diva.cfg_reg, IPAC_ISTA);
  577. Start_IPACPCI:
  578. if (cs->debug & L1_DEB_IPAC)
  579. debugl1(cs, "IPAC ISTA %02X", ista);
  580. if (ista & 0x0f) {
  581. val = memreadreg(cs->hw.diva.cfg_reg, HSCX_ISTA + 0x40);
  582. if (ista & 0x01)
  583. val |= 0x01;
  584. if (ista & 0x04)
  585. val |= 0x02;
  586. if (ista & 0x08)
  587. val |= 0x04;
  588. if (val)
  589. Memhscx_int_main(cs, val);
  590. }
  591. if (ista & 0x20) {
  592. val = 0xfe & memreadreg(cs->hw.diva.cfg_reg, ISAC_ISTA + 0x80);
  593. if (val) {
  594. isac_interrupt(cs, val);
  595. }
  596. }
  597. if (ista & 0x10) {
  598. val = 0x01;
  599. isac_interrupt(cs, val);
  600. }
  601. ista = memreadreg(cs->hw.diva.cfg_reg, IPAC_ISTA);
  602. if ((ista & 0x3f) && icnt) {
  603. icnt--;
  604. goto Start_IPACPCI;
  605. }
  606. if (!icnt)
  607. printk(KERN_WARNING "DIVA IPAC PCI IRQ LOOP\n");
  608. memwritereg(cs->hw.diva.cfg_reg, IPAC_MASK, 0xFF);
  609. memwritereg(cs->hw.diva.cfg_reg, IPAC_MASK, 0xC0);
  610. spin_unlock_irqrestore(&cs->lock, flags);
  611. return IRQ_HANDLED;
  612. }
  613. static irqreturn_t
  614. diva_irq_ipacx_pci(int intno, void *dev_id, struct pt_regs *regs)
  615. {
  616. struct IsdnCardState *cs = dev_id;
  617. u_char val;
  618. u_char *cfg;
  619. u_long flags;
  620. spin_lock_irqsave(&cs->lock, flags);
  621. cfg = (u_char *) cs->hw.diva.pci_cfg;
  622. val = *cfg;
  623. if (!(val &PITA_INT0_STATUS)) {
  624. spin_unlock_irqrestore(&cs->lock, flags);
  625. return IRQ_NONE; // other shared IRQ
  626. }
  627. interrupt_ipacx(cs); // handler for chip
  628. *cfg = PITA_INT0_STATUS; // Reset PLX interrupt
  629. spin_unlock_irqrestore(&cs->lock, flags);
  630. return IRQ_HANDLED;
  631. }
  632. static void
  633. release_io_diva(struct IsdnCardState *cs)
  634. {
  635. int bytecnt;
  636. if ((cs->subtyp == DIVA_IPAC_PCI) ||
  637. (cs->subtyp == DIVA_IPACX_PCI) ) {
  638. u_int *cfg = (unsigned int *)cs->hw.diva.pci_cfg;
  639. *cfg = 0; /* disable INT0/1 */
  640. *cfg = 2; /* reset pending INT0 */
  641. iounmap((void *)cs->hw.diva.cfg_reg);
  642. iounmap((void *)cs->hw.diva.pci_cfg);
  643. return;
  644. } else if (cs->subtyp != DIVA_IPAC_ISA) {
  645. del_timer(&cs->hw.diva.tl);
  646. if (cs->hw.diva.cfg_reg)
  647. byteout(cs->hw.diva.ctrl, 0); /* LED off, Reset */
  648. }
  649. if ((cs->subtyp == DIVA_ISA) || (cs->subtyp == DIVA_IPAC_ISA))
  650. bytecnt = 8;
  651. else
  652. bytecnt = 32;
  653. if (cs->hw.diva.cfg_reg) {
  654. release_region(cs->hw.diva.cfg_reg, bytecnt);
  655. }
  656. }
  657. static void
  658. reset_diva(struct IsdnCardState *cs)
  659. {
  660. if (cs->subtyp == DIVA_IPAC_ISA) {
  661. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_POTA2, 0x20);
  662. mdelay(10);
  663. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_POTA2, 0x00);
  664. mdelay(10);
  665. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_MASK, 0xc0);
  666. } else if (cs->subtyp == DIVA_IPAC_PCI) {
  667. unsigned int *ireg = (unsigned int *)(cs->hw.diva.pci_cfg +
  668. PITA_MISC_REG);
  669. *ireg = PITA_PARA_SOFTRESET | PITA_PARA_MPX_MODE;
  670. mdelay(10);
  671. *ireg = PITA_PARA_MPX_MODE;
  672. mdelay(10);
  673. memwritereg(cs->hw.diva.cfg_reg, IPAC_MASK, 0xc0);
  674. } else if (cs->subtyp == DIVA_IPACX_PCI) {
  675. unsigned int *ireg = (unsigned int *)(cs->hw.diva.pci_cfg +
  676. PITA_MISC_REG);
  677. *ireg = PITA_PARA_SOFTRESET | PITA_PARA_MPX_MODE;
  678. mdelay(10);
  679. *ireg = PITA_PARA_MPX_MODE | PITA_SER_SOFTRESET;
  680. mdelay(10);
  681. MemWriteISAC_IPACX(cs, IPACX_MASK, 0xff); // Interrupts off
  682. } else { /* DIVA 2.0 */
  683. cs->hw.diva.ctrl_reg = 0; /* Reset On */
  684. byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
  685. mdelay(10);
  686. cs->hw.diva.ctrl_reg |= DIVA_RESET; /* Reset Off */
  687. byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
  688. mdelay(10);
  689. if (cs->subtyp == DIVA_ISA)
  690. cs->hw.diva.ctrl_reg |= DIVA_ISA_LED_A;
  691. else {
  692. /* Workaround PCI9060 */
  693. byteout(cs->hw.diva.pci_cfg + 0x69, 9);
  694. cs->hw.diva.ctrl_reg |= DIVA_PCI_LED_A;
  695. }
  696. byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
  697. }
  698. }
  699. #define DIVA_ASSIGN 1
  700. static void
  701. diva_led_handler(struct IsdnCardState *cs)
  702. {
  703. int blink = 0;
  704. if ((cs->subtyp == DIVA_IPAC_ISA) ||
  705. (cs->subtyp == DIVA_IPAC_PCI) ||
  706. (cs->subtyp == DIVA_IPACX_PCI) )
  707. return;
  708. del_timer(&cs->hw.diva.tl);
  709. if (cs->hw.diva.status & DIVA_ASSIGN)
  710. cs->hw.diva.ctrl_reg |= (DIVA_ISA == cs->subtyp) ?
  711. DIVA_ISA_LED_A : DIVA_PCI_LED_A;
  712. else {
  713. cs->hw.diva.ctrl_reg ^= (DIVA_ISA == cs->subtyp) ?
  714. DIVA_ISA_LED_A : DIVA_PCI_LED_A;
  715. blink = 250;
  716. }
  717. if (cs->hw.diva.status & 0xf000)
  718. cs->hw.diva.ctrl_reg |= (DIVA_ISA == cs->subtyp) ?
  719. DIVA_ISA_LED_B : DIVA_PCI_LED_B;
  720. else if (cs->hw.diva.status & 0x0f00) {
  721. cs->hw.diva.ctrl_reg ^= (DIVA_ISA == cs->subtyp) ?
  722. DIVA_ISA_LED_B : DIVA_PCI_LED_B;
  723. blink = 500;
  724. } else
  725. cs->hw.diva.ctrl_reg &= ~((DIVA_ISA == cs->subtyp) ?
  726. DIVA_ISA_LED_B : DIVA_PCI_LED_B);
  727. byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
  728. if (blink) {
  729. init_timer(&cs->hw.diva.tl);
  730. cs->hw.diva.tl.expires = jiffies + ((blink * HZ) / 1000);
  731. add_timer(&cs->hw.diva.tl);
  732. }
  733. }
  734. static int
  735. Diva_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  736. {
  737. u_int *ireg;
  738. u_long flags;
  739. switch (mt) {
  740. case CARD_RESET:
  741. spin_lock_irqsave(&cs->lock, flags);
  742. reset_diva(cs);
  743. spin_unlock_irqrestore(&cs->lock, flags);
  744. return(0);
  745. case CARD_RELEASE:
  746. release_io_diva(cs);
  747. return(0);
  748. case CARD_INIT:
  749. spin_lock_irqsave(&cs->lock, flags);
  750. reset_diva(cs);
  751. if (cs->subtyp == DIVA_IPACX_PCI) {
  752. ireg = (unsigned int *)cs->hw.diva.pci_cfg;
  753. *ireg = PITA_INT0_ENABLE;
  754. init_ipacx(cs, 3); // init chip and enable interrupts
  755. spin_unlock_irqrestore(&cs->lock, flags);
  756. return (0);
  757. }
  758. if (cs->subtyp == DIVA_IPAC_PCI) {
  759. ireg = (unsigned int *)cs->hw.diva.pci_cfg;
  760. *ireg = PITA_INT0_ENABLE;
  761. }
  762. inithscxisac(cs, 3);
  763. spin_unlock_irqrestore(&cs->lock, flags);
  764. return(0);
  765. case CARD_TEST:
  766. return(0);
  767. case (MDL_REMOVE | REQUEST):
  768. cs->hw.diva.status = 0;
  769. break;
  770. case (MDL_ASSIGN | REQUEST):
  771. cs->hw.diva.status |= DIVA_ASSIGN;
  772. break;
  773. case MDL_INFO_SETUP:
  774. if ((long)arg)
  775. cs->hw.diva.status |= 0x0200;
  776. else
  777. cs->hw.diva.status |= 0x0100;
  778. break;
  779. case MDL_INFO_CONN:
  780. if ((long)arg)
  781. cs->hw.diva.status |= 0x2000;
  782. else
  783. cs->hw.diva.status |= 0x1000;
  784. break;
  785. case MDL_INFO_REL:
  786. if ((long)arg) {
  787. cs->hw.diva.status &= ~0x2000;
  788. cs->hw.diva.status &= ~0x0200;
  789. } else {
  790. cs->hw.diva.status &= ~0x1000;
  791. cs->hw.diva.status &= ~0x0100;
  792. }
  793. break;
  794. }
  795. if ((cs->subtyp != DIVA_IPAC_ISA) &&
  796. (cs->subtyp != DIVA_IPAC_PCI) &&
  797. (cs->subtyp != DIVA_IPACX_PCI)) {
  798. spin_lock_irqsave(&cs->lock, flags);
  799. diva_led_handler(cs);
  800. spin_unlock_irqrestore(&cs->lock, flags);
  801. }
  802. return(0);
  803. }
  804. static struct pci_dev *dev_diva __initdata = NULL;
  805. static struct pci_dev *dev_diva_u __initdata = NULL;
  806. static struct pci_dev *dev_diva201 __initdata = NULL;
  807. static struct pci_dev *dev_diva202 __initdata = NULL;
  808. #ifdef __ISAPNP__
  809. static struct isapnp_device_id diva_ids[] __initdata = {
  810. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
  811. ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
  812. (unsigned long) "Diva picola" },
  813. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
  814. ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0x51),
  815. (unsigned long) "Diva picola" },
  816. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
  817. ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
  818. (unsigned long) "Diva 2.0" },
  819. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
  820. ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0x71),
  821. (unsigned long) "Diva 2.0" },
  822. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
  823. ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
  824. (unsigned long) "Diva 2.01" },
  825. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
  826. ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0xA1),
  827. (unsigned long) "Diva 2.01" },
  828. { 0, }
  829. };
  830. static struct isapnp_device_id *ipid __initdata = &diva_ids[0];
  831. static struct pnp_card *pnp_c __devinitdata = NULL;
  832. #endif
  833. int __init
  834. setup_diva(struct IsdnCard *card)
  835. {
  836. int bytecnt = 8;
  837. u_char val;
  838. struct IsdnCardState *cs = card->cs;
  839. char tmp[64];
  840. strcpy(tmp, Diva_revision);
  841. printk(KERN_INFO "HiSax: Eicon.Diehl Diva driver Rev. %s\n", HiSax_getrev(tmp));
  842. if (cs->typ != ISDN_CTYPE_DIEHLDIVA)
  843. return(0);
  844. cs->hw.diva.status = 0;
  845. if (card->para[1]) {
  846. cs->hw.diva.ctrl_reg = 0;
  847. cs->hw.diva.cfg_reg = card->para[1];
  848. val = readreg(cs->hw.diva.cfg_reg + DIVA_IPAC_ADR,
  849. cs->hw.diva.cfg_reg + DIVA_IPAC_DATA, IPAC_ID);
  850. printk(KERN_INFO "Diva: IPAC version %x\n", val);
  851. if ((val == 1) || (val==2)) {
  852. cs->subtyp = DIVA_IPAC_ISA;
  853. cs->hw.diva.ctrl = 0;
  854. cs->hw.diva.isac = card->para[1] + DIVA_IPAC_DATA;
  855. cs->hw.diva.hscx = card->para[1] + DIVA_IPAC_DATA;
  856. cs->hw.diva.isac_adr = card->para[1] + DIVA_IPAC_ADR;
  857. cs->hw.diva.hscx_adr = card->para[1] + DIVA_IPAC_ADR;
  858. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  859. } else {
  860. cs->subtyp = DIVA_ISA;
  861. cs->hw.diva.ctrl = card->para[1] + DIVA_ISA_CTRL;
  862. cs->hw.diva.isac = card->para[1] + DIVA_ISA_ISAC_DATA;
  863. cs->hw.diva.hscx = card->para[1] + DIVA_HSCX_DATA;
  864. cs->hw.diva.isac_adr = card->para[1] + DIVA_ISA_ISAC_ADR;
  865. cs->hw.diva.hscx_adr = card->para[1] + DIVA_HSCX_ADR;
  866. }
  867. cs->irq = card->para[0];
  868. } else {
  869. #ifdef __ISAPNP__
  870. if (isapnp_present()) {
  871. struct pnp_dev *pnp_d;
  872. while(ipid->card_vendor) {
  873. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  874. ipid->card_device, pnp_c))) {
  875. pnp_d = NULL;
  876. if ((pnp_d = pnp_find_dev(pnp_c,
  877. ipid->vendor, ipid->function, pnp_d))) {
  878. int err;
  879. printk(KERN_INFO "HiSax: %s detected\n",
  880. (char *)ipid->driver_data);
  881. pnp_disable_dev(pnp_d);
  882. err = pnp_activate_dev(pnp_d);
  883. if (err<0) {
  884. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  885. __FUNCTION__, err);
  886. return(0);
  887. }
  888. card->para[1] = pnp_port_start(pnp_d, 0);
  889. card->para[0] = pnp_irq(pnp_d, 0);
  890. if (!card->para[0] || !card->para[1]) {
  891. printk(KERN_ERR "Diva PnP:some resources are missing %ld/%lx\n",
  892. card->para[0], card->para[1]);
  893. pnp_disable_dev(pnp_d);
  894. return(0);
  895. }
  896. cs->hw.diva.cfg_reg = card->para[1];
  897. cs->irq = card->para[0];
  898. if (ipid->function == ISAPNP_FUNCTION(0xA1)) {
  899. cs->subtyp = DIVA_IPAC_ISA;
  900. cs->hw.diva.ctrl = 0;
  901. cs->hw.diva.isac =
  902. card->para[1] + DIVA_IPAC_DATA;
  903. cs->hw.diva.hscx =
  904. card->para[1] + DIVA_IPAC_DATA;
  905. cs->hw.diva.isac_adr =
  906. card->para[1] + DIVA_IPAC_ADR;
  907. cs->hw.diva.hscx_adr =
  908. card->para[1] + DIVA_IPAC_ADR;
  909. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  910. } else {
  911. cs->subtyp = DIVA_ISA;
  912. cs->hw.diva.ctrl =
  913. card->para[1] + DIVA_ISA_CTRL;
  914. cs->hw.diva.isac =
  915. card->para[1] + DIVA_ISA_ISAC_DATA;
  916. cs->hw.diva.hscx =
  917. card->para[1] + DIVA_HSCX_DATA;
  918. cs->hw.diva.isac_adr =
  919. card->para[1] + DIVA_ISA_ISAC_ADR;
  920. cs->hw.diva.hscx_adr =
  921. card->para[1] + DIVA_HSCX_ADR;
  922. }
  923. goto ready;
  924. } else {
  925. printk(KERN_ERR "Diva PnP: PnP error card found, no device\n");
  926. return(0);
  927. }
  928. }
  929. ipid++;
  930. pnp_c=NULL;
  931. }
  932. if (!ipid->card_vendor) {
  933. printk(KERN_INFO "Diva PnP: no ISAPnP card found\n");
  934. }
  935. }
  936. #endif
  937. #ifdef CONFIG_PCI
  938. cs->subtyp = 0;
  939. if ((dev_diva = pci_find_device(PCI_VENDOR_ID_EICON,
  940. PCI_DEVICE_ID_EICON_DIVA20, dev_diva))) {
  941. if (pci_enable_device(dev_diva))
  942. return(0);
  943. cs->subtyp = DIVA_PCI;
  944. cs->irq = dev_diva->irq;
  945. cs->hw.diva.cfg_reg = pci_resource_start(dev_diva, 2);
  946. } else if ((dev_diva_u = pci_find_device(PCI_VENDOR_ID_EICON,
  947. PCI_DEVICE_ID_EICON_DIVA20_U, dev_diva_u))) {
  948. if (pci_enable_device(dev_diva_u))
  949. return(0);
  950. cs->subtyp = DIVA_PCI;
  951. cs->irq = dev_diva_u->irq;
  952. cs->hw.diva.cfg_reg = pci_resource_start(dev_diva_u, 2);
  953. } else if ((dev_diva201 = pci_find_device(PCI_VENDOR_ID_EICON,
  954. PCI_DEVICE_ID_EICON_DIVA201, dev_diva201))) {
  955. if (pci_enable_device(dev_diva201))
  956. return(0);
  957. cs->subtyp = DIVA_IPAC_PCI;
  958. cs->irq = dev_diva201->irq;
  959. cs->hw.diva.pci_cfg =
  960. (ulong) ioremap(pci_resource_start(dev_diva201, 0), 4096);
  961. cs->hw.diva.cfg_reg =
  962. (ulong) ioremap(pci_resource_start(dev_diva201, 1), 4096);
  963. } else if ((dev_diva202 = pci_find_device(PCI_VENDOR_ID_EICON,
  964. PCI_DEVICE_ID_EICON_DIVA202, dev_diva202))) {
  965. if (pci_enable_device(dev_diva202))
  966. return(0);
  967. cs->subtyp = DIVA_IPACX_PCI;
  968. cs->irq = dev_diva202->irq;
  969. cs->hw.diva.pci_cfg =
  970. (ulong) ioremap(pci_resource_start(dev_diva202, 0), 4096);
  971. cs->hw.diva.cfg_reg =
  972. (ulong) ioremap(pci_resource_start(dev_diva202, 1), 4096);
  973. } else {
  974. printk(KERN_WARNING "Diva: No PCI card found\n");
  975. return(0);
  976. }
  977. if (!cs->irq) {
  978. printk(KERN_WARNING "Diva: No IRQ for PCI card found\n");
  979. return(0);
  980. }
  981. if (!cs->hw.diva.cfg_reg) {
  982. printk(KERN_WARNING "Diva: No IO-Adr for PCI card found\n");
  983. return(0);
  984. }
  985. cs->irq_flags |= SA_SHIRQ;
  986. #else
  987. printk(KERN_WARNING "Diva: cfgreg 0 and NO_PCI_BIOS\n");
  988. printk(KERN_WARNING "Diva: unable to config DIVA PCI\n");
  989. return (0);
  990. #endif /* CONFIG_PCI */
  991. if ((cs->subtyp == DIVA_IPAC_PCI) ||
  992. (cs->subtyp == DIVA_IPACX_PCI) ) {
  993. cs->hw.diva.ctrl = 0;
  994. cs->hw.diva.isac = 0;
  995. cs->hw.diva.hscx = 0;
  996. cs->hw.diva.isac_adr = 0;
  997. cs->hw.diva.hscx_adr = 0;
  998. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  999. bytecnt = 0;
  1000. } else {
  1001. cs->hw.diva.ctrl = cs->hw.diva.cfg_reg + DIVA_PCI_CTRL;
  1002. cs->hw.diva.isac = cs->hw.diva.cfg_reg + DIVA_PCI_ISAC_DATA;
  1003. cs->hw.diva.hscx = cs->hw.diva.cfg_reg + DIVA_HSCX_DATA;
  1004. cs->hw.diva.isac_adr = cs->hw.diva.cfg_reg + DIVA_PCI_ISAC_ADR;
  1005. cs->hw.diva.hscx_adr = cs->hw.diva.cfg_reg + DIVA_HSCX_ADR;
  1006. bytecnt = 32;
  1007. }
  1008. }
  1009. ready:
  1010. printk(KERN_INFO
  1011. "Diva: %s card configured at %#lx IRQ %d\n",
  1012. (cs->subtyp == DIVA_PCI) ? "PCI" :
  1013. (cs->subtyp == DIVA_ISA) ? "ISA" :
  1014. (cs->subtyp == DIVA_IPAC_ISA) ? "IPAC ISA" :
  1015. (cs->subtyp == DIVA_IPAC_PCI) ? "IPAC PCI" : "IPACX PCI",
  1016. cs->hw.diva.cfg_reg, cs->irq);
  1017. if ((cs->subtyp == DIVA_IPAC_PCI) ||
  1018. (cs->subtyp == DIVA_IPACX_PCI) ||
  1019. (cs->subtyp == DIVA_PCI) )
  1020. printk(KERN_INFO "Diva: %s space at %#lx\n",
  1021. (cs->subtyp == DIVA_PCI) ? "PCI" :
  1022. (cs->subtyp == DIVA_IPAC_PCI) ? "IPAC PCI" : "IPACX PCI",
  1023. cs->hw.diva.pci_cfg);
  1024. if ((cs->subtyp != DIVA_IPAC_PCI) &&
  1025. (cs->subtyp != DIVA_IPACX_PCI) ) {
  1026. if (!request_region(cs->hw.diva.cfg_reg, bytecnt, "diva isdn")) {
  1027. printk(KERN_WARNING
  1028. "HiSax: %s config port %lx-%lx already in use\n",
  1029. CardType[card->typ],
  1030. cs->hw.diva.cfg_reg,
  1031. cs->hw.diva.cfg_reg + bytecnt);
  1032. return (0);
  1033. }
  1034. }
  1035. cs->BC_Read_Reg = &ReadHSCX;
  1036. cs->BC_Write_Reg = &WriteHSCX;
  1037. cs->BC_Send_Data = &hscx_fill_fifo;
  1038. cs->cardmsg = &Diva_card_msg;
  1039. setup_isac(cs);
  1040. if (cs->subtyp == DIVA_IPAC_ISA) {
  1041. cs->readisac = &ReadISAC_IPAC;
  1042. cs->writeisac = &WriteISAC_IPAC;
  1043. cs->readisacfifo = &ReadISACfifo_IPAC;
  1044. cs->writeisacfifo = &WriteISACfifo_IPAC;
  1045. cs->irq_func = &diva_irq_ipac_isa;
  1046. val = readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_ID);
  1047. printk(KERN_INFO "Diva: IPAC version %x\n", val);
  1048. } else if (cs->subtyp == DIVA_IPAC_PCI) {
  1049. cs->readisac = &MemReadISAC_IPAC;
  1050. cs->writeisac = &MemWriteISAC_IPAC;
  1051. cs->readisacfifo = &MemReadISACfifo_IPAC;
  1052. cs->writeisacfifo = &MemWriteISACfifo_IPAC;
  1053. cs->BC_Read_Reg = &MemReadHSCX;
  1054. cs->BC_Write_Reg = &MemWriteHSCX;
  1055. cs->BC_Send_Data = &Memhscx_fill_fifo;
  1056. cs->irq_func = &diva_irq_ipac_pci;
  1057. val = memreadreg(cs->hw.diva.cfg_reg, IPAC_ID);
  1058. printk(KERN_INFO "Diva: IPAC version %x\n", val);
  1059. } else if (cs->subtyp == DIVA_IPACX_PCI) {
  1060. cs->readisac = &MemReadISAC_IPACX;
  1061. cs->writeisac = &MemWriteISAC_IPACX;
  1062. cs->readisacfifo = &MemReadISACfifo_IPACX;
  1063. cs->writeisacfifo = &MemWriteISACfifo_IPACX;
  1064. cs->BC_Read_Reg = &MemReadHSCX_IPACX;
  1065. cs->BC_Write_Reg = &MemWriteHSCX_IPACX;
  1066. cs->BC_Send_Data = NULL; // function located in ipacx module
  1067. cs->irq_func = &diva_irq_ipacx_pci;
  1068. printk(KERN_INFO "Diva: IPACX Design Id: %x\n",
  1069. MemReadISAC_IPACX(cs, IPACX_ID) &0x3F);
  1070. } else { /* DIVA 2.0 */
  1071. cs->hw.diva.tl.function = (void *) diva_led_handler;
  1072. cs->hw.diva.tl.data = (long) cs;
  1073. init_timer(&cs->hw.diva.tl);
  1074. cs->readisac = &ReadISAC;
  1075. cs->writeisac = &WriteISAC;
  1076. cs->readisacfifo = &ReadISACfifo;
  1077. cs->writeisacfifo = &WriteISACfifo;
  1078. cs->irq_func = &diva_interrupt;
  1079. ISACVersion(cs, "Diva:");
  1080. if (HscxVersion(cs, "Diva:")) {
  1081. printk(KERN_WARNING
  1082. "Diva: wrong HSCX versions check IO address\n");
  1083. release_io_diva(cs);
  1084. return (0);
  1085. }
  1086. }
  1087. return (1);
  1088. }