diva.c 33 KB

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