diva.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182
  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, struct pt_regs *regs)
  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, struct pt_regs *regs)
  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, struct pt_regs *regs)
  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, struct pt_regs *regs)
  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. iounmap((void *)cs->hw.diva.cfg_reg);
  641. iounmap((void *)cs->hw.diva.pci_cfg);
  642. return;
  643. } else if (cs->subtyp != DIVA_IPAC_ISA) {
  644. del_timer(&cs->hw.diva.tl);
  645. if (cs->hw.diva.cfg_reg)
  646. byteout(cs->hw.diva.ctrl, 0); /* LED off, Reset */
  647. }
  648. if ((cs->subtyp == DIVA_ISA) || (cs->subtyp == DIVA_IPAC_ISA))
  649. bytecnt = 8;
  650. else
  651. bytecnt = 32;
  652. if (cs->hw.diva.cfg_reg) {
  653. release_region(cs->hw.diva.cfg_reg, bytecnt);
  654. }
  655. }
  656. static void
  657. reset_diva(struct IsdnCardState *cs)
  658. {
  659. if (cs->subtyp == DIVA_IPAC_ISA) {
  660. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_POTA2, 0x20);
  661. mdelay(10);
  662. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_POTA2, 0x00);
  663. mdelay(10);
  664. writereg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_MASK, 0xc0);
  665. } else if (cs->subtyp == DIVA_IPAC_PCI) {
  666. unsigned int *ireg = (unsigned int *)(cs->hw.diva.pci_cfg +
  667. PITA_MISC_REG);
  668. *ireg = PITA_PARA_SOFTRESET | PITA_PARA_MPX_MODE;
  669. mdelay(10);
  670. *ireg = PITA_PARA_MPX_MODE;
  671. mdelay(10);
  672. memwritereg(cs->hw.diva.cfg_reg, IPAC_MASK, 0xc0);
  673. } else if (cs->subtyp == DIVA_IPACX_PCI) {
  674. unsigned int *ireg = (unsigned int *)(cs->hw.diva.pci_cfg +
  675. PITA_MISC_REG);
  676. *ireg = PITA_PARA_SOFTRESET | PITA_PARA_MPX_MODE;
  677. mdelay(10);
  678. *ireg = PITA_PARA_MPX_MODE | PITA_SER_SOFTRESET;
  679. mdelay(10);
  680. MemWriteISAC_IPACX(cs, IPACX_MASK, 0xff); // Interrupts off
  681. } else { /* DIVA 2.0 */
  682. cs->hw.diva.ctrl_reg = 0; /* Reset On */
  683. byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
  684. mdelay(10);
  685. cs->hw.diva.ctrl_reg |= DIVA_RESET; /* Reset Off */
  686. byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
  687. mdelay(10);
  688. if (cs->subtyp == DIVA_ISA)
  689. cs->hw.diva.ctrl_reg |= DIVA_ISA_LED_A;
  690. else {
  691. /* Workaround PCI9060 */
  692. byteout(cs->hw.diva.pci_cfg + 0x69, 9);
  693. cs->hw.diva.ctrl_reg |= DIVA_PCI_LED_A;
  694. }
  695. byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
  696. }
  697. }
  698. #define DIVA_ASSIGN 1
  699. static void
  700. diva_led_handler(struct IsdnCardState *cs)
  701. {
  702. int blink = 0;
  703. if ((cs->subtyp == DIVA_IPAC_ISA) ||
  704. (cs->subtyp == DIVA_IPAC_PCI) ||
  705. (cs->subtyp == DIVA_IPACX_PCI) )
  706. return;
  707. del_timer(&cs->hw.diva.tl);
  708. if (cs->hw.diva.status & DIVA_ASSIGN)
  709. cs->hw.diva.ctrl_reg |= (DIVA_ISA == cs->subtyp) ?
  710. DIVA_ISA_LED_A : DIVA_PCI_LED_A;
  711. else {
  712. cs->hw.diva.ctrl_reg ^= (DIVA_ISA == cs->subtyp) ?
  713. DIVA_ISA_LED_A : DIVA_PCI_LED_A;
  714. blink = 250;
  715. }
  716. if (cs->hw.diva.status & 0xf000)
  717. cs->hw.diva.ctrl_reg |= (DIVA_ISA == cs->subtyp) ?
  718. DIVA_ISA_LED_B : DIVA_PCI_LED_B;
  719. else if (cs->hw.diva.status & 0x0f00) {
  720. cs->hw.diva.ctrl_reg ^= (DIVA_ISA == cs->subtyp) ?
  721. DIVA_ISA_LED_B : DIVA_PCI_LED_B;
  722. blink = 500;
  723. } else
  724. cs->hw.diva.ctrl_reg &= ~((DIVA_ISA == cs->subtyp) ?
  725. DIVA_ISA_LED_B : DIVA_PCI_LED_B);
  726. byteout(cs->hw.diva.ctrl, cs->hw.diva.ctrl_reg);
  727. if (blink) {
  728. init_timer(&cs->hw.diva.tl);
  729. cs->hw.diva.tl.expires = jiffies + ((blink * HZ) / 1000);
  730. add_timer(&cs->hw.diva.tl);
  731. }
  732. }
  733. static int
  734. Diva_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  735. {
  736. u_int *ireg;
  737. u_long flags;
  738. switch (mt) {
  739. case CARD_RESET:
  740. spin_lock_irqsave(&cs->lock, flags);
  741. reset_diva(cs);
  742. spin_unlock_irqrestore(&cs->lock, flags);
  743. return(0);
  744. case CARD_RELEASE:
  745. release_io_diva(cs);
  746. return(0);
  747. case CARD_INIT:
  748. spin_lock_irqsave(&cs->lock, flags);
  749. reset_diva(cs);
  750. if (cs->subtyp == DIVA_IPACX_PCI) {
  751. ireg = (unsigned int *)cs->hw.diva.pci_cfg;
  752. *ireg = PITA_INT0_ENABLE;
  753. init_ipacx(cs, 3); // init chip and enable interrupts
  754. spin_unlock_irqrestore(&cs->lock, flags);
  755. return (0);
  756. }
  757. if (cs->subtyp == DIVA_IPAC_PCI) {
  758. ireg = (unsigned int *)cs->hw.diva.pci_cfg;
  759. *ireg = PITA_INT0_ENABLE;
  760. }
  761. inithscxisac(cs, 3);
  762. spin_unlock_irqrestore(&cs->lock, flags);
  763. return(0);
  764. case CARD_TEST:
  765. return(0);
  766. case (MDL_REMOVE | REQUEST):
  767. cs->hw.diva.status = 0;
  768. break;
  769. case (MDL_ASSIGN | REQUEST):
  770. cs->hw.diva.status |= DIVA_ASSIGN;
  771. break;
  772. case MDL_INFO_SETUP:
  773. if ((long)arg)
  774. cs->hw.diva.status |= 0x0200;
  775. else
  776. cs->hw.diva.status |= 0x0100;
  777. break;
  778. case MDL_INFO_CONN:
  779. if ((long)arg)
  780. cs->hw.diva.status |= 0x2000;
  781. else
  782. cs->hw.diva.status |= 0x1000;
  783. break;
  784. case MDL_INFO_REL:
  785. if ((long)arg) {
  786. cs->hw.diva.status &= ~0x2000;
  787. cs->hw.diva.status &= ~0x0200;
  788. } else {
  789. cs->hw.diva.status &= ~0x1000;
  790. cs->hw.diva.status &= ~0x0100;
  791. }
  792. break;
  793. }
  794. if ((cs->subtyp != DIVA_IPAC_ISA) &&
  795. (cs->subtyp != DIVA_IPAC_PCI) &&
  796. (cs->subtyp != DIVA_IPACX_PCI)) {
  797. spin_lock_irqsave(&cs->lock, flags);
  798. diva_led_handler(cs);
  799. spin_unlock_irqrestore(&cs->lock, flags);
  800. }
  801. return(0);
  802. }
  803. static struct pci_dev *dev_diva __devinitdata = NULL;
  804. static struct pci_dev *dev_diva_u __devinitdata = NULL;
  805. static struct pci_dev *dev_diva201 __devinitdata = NULL;
  806. static struct pci_dev *dev_diva202 __devinitdata = NULL;
  807. #ifdef __ISAPNP__
  808. static struct isapnp_device_id diva_ids[] __devinitdata = {
  809. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
  810. ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
  811. (unsigned long) "Diva picola" },
  812. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x51),
  813. ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0x51),
  814. (unsigned long) "Diva picola" },
  815. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
  816. ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
  817. (unsigned long) "Diva 2.0" },
  818. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0x71),
  819. ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0x71),
  820. (unsigned long) "Diva 2.0" },
  821. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
  822. ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
  823. (unsigned long) "Diva 2.01" },
  824. { ISAPNP_VENDOR('G', 'D', 'I'), ISAPNP_FUNCTION(0xA1),
  825. ISAPNP_VENDOR('E', 'I', 'C'), ISAPNP_FUNCTION(0xA1),
  826. (unsigned long) "Diva 2.01" },
  827. { 0, }
  828. };
  829. static struct isapnp_device_id *ipid __devinitdata = &diva_ids[0];
  830. static struct pnp_card *pnp_c __devinitdata = NULL;
  831. #endif
  832. int __devinit
  833. setup_diva(struct IsdnCard *card)
  834. {
  835. int bytecnt = 8;
  836. u_char val;
  837. struct IsdnCardState *cs = card->cs;
  838. char tmp[64];
  839. strcpy(tmp, Diva_revision);
  840. printk(KERN_INFO "HiSax: Eicon.Diehl Diva driver Rev. %s\n", HiSax_getrev(tmp));
  841. if (cs->typ != ISDN_CTYPE_DIEHLDIVA)
  842. return(0);
  843. cs->hw.diva.status = 0;
  844. if (card->para[1]) {
  845. cs->hw.diva.ctrl_reg = 0;
  846. cs->hw.diva.cfg_reg = card->para[1];
  847. val = readreg(cs->hw.diva.cfg_reg + DIVA_IPAC_ADR,
  848. cs->hw.diva.cfg_reg + DIVA_IPAC_DATA, IPAC_ID);
  849. printk(KERN_INFO "Diva: IPAC version %x\n", val);
  850. if ((val == 1) || (val==2)) {
  851. cs->subtyp = DIVA_IPAC_ISA;
  852. cs->hw.diva.ctrl = 0;
  853. cs->hw.diva.isac = card->para[1] + DIVA_IPAC_DATA;
  854. cs->hw.diva.hscx = card->para[1] + DIVA_IPAC_DATA;
  855. cs->hw.diva.isac_adr = card->para[1] + DIVA_IPAC_ADR;
  856. cs->hw.diva.hscx_adr = card->para[1] + DIVA_IPAC_ADR;
  857. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  858. } else {
  859. cs->subtyp = DIVA_ISA;
  860. cs->hw.diva.ctrl = card->para[1] + DIVA_ISA_CTRL;
  861. cs->hw.diva.isac = card->para[1] + DIVA_ISA_ISAC_DATA;
  862. cs->hw.diva.hscx = card->para[1] + DIVA_HSCX_DATA;
  863. cs->hw.diva.isac_adr = card->para[1] + DIVA_ISA_ISAC_ADR;
  864. cs->hw.diva.hscx_adr = card->para[1] + DIVA_HSCX_ADR;
  865. }
  866. cs->irq = card->para[0];
  867. } else {
  868. #ifdef __ISAPNP__
  869. if (isapnp_present()) {
  870. struct pnp_dev *pnp_d;
  871. while(ipid->card_vendor) {
  872. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  873. ipid->card_device, pnp_c))) {
  874. pnp_d = NULL;
  875. if ((pnp_d = pnp_find_dev(pnp_c,
  876. ipid->vendor, ipid->function, pnp_d))) {
  877. int err;
  878. printk(KERN_INFO "HiSax: %s detected\n",
  879. (char *)ipid->driver_data);
  880. pnp_disable_dev(pnp_d);
  881. err = pnp_activate_dev(pnp_d);
  882. if (err<0) {
  883. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  884. __FUNCTION__, err);
  885. return(0);
  886. }
  887. card->para[1] = pnp_port_start(pnp_d, 0);
  888. card->para[0] = pnp_irq(pnp_d, 0);
  889. if (!card->para[0] || !card->para[1]) {
  890. printk(KERN_ERR "Diva PnP:some resources are missing %ld/%lx\n",
  891. card->para[0], card->para[1]);
  892. pnp_disable_dev(pnp_d);
  893. return(0);
  894. }
  895. cs->hw.diva.cfg_reg = card->para[1];
  896. cs->irq = card->para[0];
  897. if (ipid->function == ISAPNP_FUNCTION(0xA1)) {
  898. cs->subtyp = DIVA_IPAC_ISA;
  899. cs->hw.diva.ctrl = 0;
  900. cs->hw.diva.isac =
  901. card->para[1] + DIVA_IPAC_DATA;
  902. cs->hw.diva.hscx =
  903. card->para[1] + DIVA_IPAC_DATA;
  904. cs->hw.diva.isac_adr =
  905. card->para[1] + DIVA_IPAC_ADR;
  906. cs->hw.diva.hscx_adr =
  907. card->para[1] + DIVA_IPAC_ADR;
  908. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  909. } else {
  910. cs->subtyp = DIVA_ISA;
  911. cs->hw.diva.ctrl =
  912. card->para[1] + DIVA_ISA_CTRL;
  913. cs->hw.diva.isac =
  914. card->para[1] + DIVA_ISA_ISAC_DATA;
  915. cs->hw.diva.hscx =
  916. card->para[1] + DIVA_HSCX_DATA;
  917. cs->hw.diva.isac_adr =
  918. card->para[1] + DIVA_ISA_ISAC_ADR;
  919. cs->hw.diva.hscx_adr =
  920. card->para[1] + DIVA_HSCX_ADR;
  921. }
  922. goto ready;
  923. } else {
  924. printk(KERN_ERR "Diva PnP: PnP error card found, no device\n");
  925. return(0);
  926. }
  927. }
  928. ipid++;
  929. pnp_c=NULL;
  930. }
  931. if (!ipid->card_vendor) {
  932. printk(KERN_INFO "Diva PnP: no ISAPnP card found\n");
  933. }
  934. }
  935. #endif
  936. #ifdef CONFIG_PCI
  937. cs->subtyp = 0;
  938. if ((dev_diva = pci_find_device(PCI_VENDOR_ID_EICON,
  939. PCI_DEVICE_ID_EICON_DIVA20, dev_diva))) {
  940. if (pci_enable_device(dev_diva))
  941. return(0);
  942. cs->subtyp = DIVA_PCI;
  943. cs->irq = dev_diva->irq;
  944. cs->hw.diva.cfg_reg = pci_resource_start(dev_diva, 2);
  945. } else if ((dev_diva_u = pci_find_device(PCI_VENDOR_ID_EICON,
  946. PCI_DEVICE_ID_EICON_DIVA20_U, dev_diva_u))) {
  947. if (pci_enable_device(dev_diva_u))
  948. return(0);
  949. cs->subtyp = DIVA_PCI;
  950. cs->irq = dev_diva_u->irq;
  951. cs->hw.diva.cfg_reg = pci_resource_start(dev_diva_u, 2);
  952. } else if ((dev_diva201 = pci_find_device(PCI_VENDOR_ID_EICON,
  953. PCI_DEVICE_ID_EICON_DIVA201, dev_diva201))) {
  954. if (pci_enable_device(dev_diva201))
  955. return(0);
  956. cs->subtyp = DIVA_IPAC_PCI;
  957. cs->irq = dev_diva201->irq;
  958. cs->hw.diva.pci_cfg =
  959. (ulong) ioremap(pci_resource_start(dev_diva201, 0), 4096);
  960. cs->hw.diva.cfg_reg =
  961. (ulong) ioremap(pci_resource_start(dev_diva201, 1), 4096);
  962. } else if ((dev_diva202 = pci_find_device(PCI_VENDOR_ID_EICON,
  963. PCI_DEVICE_ID_EICON_DIVA202, dev_diva202))) {
  964. if (pci_enable_device(dev_diva202))
  965. return(0);
  966. cs->subtyp = DIVA_IPACX_PCI;
  967. cs->irq = dev_diva202->irq;
  968. cs->hw.diva.pci_cfg =
  969. (ulong) ioremap(pci_resource_start(dev_diva202, 0), 4096);
  970. cs->hw.diva.cfg_reg =
  971. (ulong) ioremap(pci_resource_start(dev_diva202, 1), 4096);
  972. } else {
  973. printk(KERN_WARNING "Diva: No PCI card found\n");
  974. return(0);
  975. }
  976. if (!cs->irq) {
  977. printk(KERN_WARNING "Diva: No IRQ for PCI card found\n");
  978. return(0);
  979. }
  980. if (!cs->hw.diva.cfg_reg) {
  981. printk(KERN_WARNING "Diva: No IO-Adr for PCI card found\n");
  982. return(0);
  983. }
  984. cs->irq_flags |= IRQF_SHARED;
  985. #else
  986. printk(KERN_WARNING "Diva: cfgreg 0 and NO_PCI_BIOS\n");
  987. printk(KERN_WARNING "Diva: unable to config DIVA PCI\n");
  988. return (0);
  989. #endif /* CONFIG_PCI */
  990. if ((cs->subtyp == DIVA_IPAC_PCI) ||
  991. (cs->subtyp == DIVA_IPACX_PCI) ) {
  992. cs->hw.diva.ctrl = 0;
  993. cs->hw.diva.isac = 0;
  994. cs->hw.diva.hscx = 0;
  995. cs->hw.diva.isac_adr = 0;
  996. cs->hw.diva.hscx_adr = 0;
  997. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  998. bytecnt = 0;
  999. } else {
  1000. cs->hw.diva.ctrl = cs->hw.diva.cfg_reg + DIVA_PCI_CTRL;
  1001. cs->hw.diva.isac = cs->hw.diva.cfg_reg + DIVA_PCI_ISAC_DATA;
  1002. cs->hw.diva.hscx = cs->hw.diva.cfg_reg + DIVA_HSCX_DATA;
  1003. cs->hw.diva.isac_adr = cs->hw.diva.cfg_reg + DIVA_PCI_ISAC_ADR;
  1004. cs->hw.diva.hscx_adr = cs->hw.diva.cfg_reg + DIVA_HSCX_ADR;
  1005. bytecnt = 32;
  1006. }
  1007. }
  1008. ready:
  1009. printk(KERN_INFO
  1010. "Diva: %s card configured at %#lx IRQ %d\n",
  1011. (cs->subtyp == DIVA_PCI) ? "PCI" :
  1012. (cs->subtyp == DIVA_ISA) ? "ISA" :
  1013. (cs->subtyp == DIVA_IPAC_ISA) ? "IPAC ISA" :
  1014. (cs->subtyp == DIVA_IPAC_PCI) ? "IPAC PCI" : "IPACX PCI",
  1015. cs->hw.diva.cfg_reg, cs->irq);
  1016. if ((cs->subtyp == DIVA_IPAC_PCI) ||
  1017. (cs->subtyp == DIVA_IPACX_PCI) ||
  1018. (cs->subtyp == DIVA_PCI) )
  1019. printk(KERN_INFO "Diva: %s space at %#lx\n",
  1020. (cs->subtyp == DIVA_PCI) ? "PCI" :
  1021. (cs->subtyp == DIVA_IPAC_PCI) ? "IPAC PCI" : "IPACX PCI",
  1022. cs->hw.diva.pci_cfg);
  1023. if ((cs->subtyp != DIVA_IPAC_PCI) &&
  1024. (cs->subtyp != DIVA_IPACX_PCI) ) {
  1025. if (!request_region(cs->hw.diva.cfg_reg, bytecnt, "diva isdn")) {
  1026. printk(KERN_WARNING
  1027. "HiSax: %s config port %lx-%lx already in use\n",
  1028. CardType[card->typ],
  1029. cs->hw.diva.cfg_reg,
  1030. cs->hw.diva.cfg_reg + bytecnt);
  1031. return (0);
  1032. }
  1033. }
  1034. cs->BC_Read_Reg = &ReadHSCX;
  1035. cs->BC_Write_Reg = &WriteHSCX;
  1036. cs->BC_Send_Data = &hscx_fill_fifo;
  1037. cs->cardmsg = &Diva_card_msg;
  1038. setup_isac(cs);
  1039. if (cs->subtyp == DIVA_IPAC_ISA) {
  1040. cs->readisac = &ReadISAC_IPAC;
  1041. cs->writeisac = &WriteISAC_IPAC;
  1042. cs->readisacfifo = &ReadISACfifo_IPAC;
  1043. cs->writeisacfifo = &WriteISACfifo_IPAC;
  1044. cs->irq_func = &diva_irq_ipac_isa;
  1045. val = readreg(cs->hw.diva.isac_adr, cs->hw.diva.isac, IPAC_ID);
  1046. printk(KERN_INFO "Diva: IPAC version %x\n", val);
  1047. } else if (cs->subtyp == DIVA_IPAC_PCI) {
  1048. cs->readisac = &MemReadISAC_IPAC;
  1049. cs->writeisac = &MemWriteISAC_IPAC;
  1050. cs->readisacfifo = &MemReadISACfifo_IPAC;
  1051. cs->writeisacfifo = &MemWriteISACfifo_IPAC;
  1052. cs->BC_Read_Reg = &MemReadHSCX;
  1053. cs->BC_Write_Reg = &MemWriteHSCX;
  1054. cs->BC_Send_Data = &Memhscx_fill_fifo;
  1055. cs->irq_func = &diva_irq_ipac_pci;
  1056. val = memreadreg(cs->hw.diva.cfg_reg, IPAC_ID);
  1057. printk(KERN_INFO "Diva: IPAC version %x\n", val);
  1058. } else if (cs->subtyp == DIVA_IPACX_PCI) {
  1059. cs->readisac = &MemReadISAC_IPACX;
  1060. cs->writeisac = &MemWriteISAC_IPACX;
  1061. cs->readisacfifo = &MemReadISACfifo_IPACX;
  1062. cs->writeisacfifo = &MemWriteISACfifo_IPACX;
  1063. cs->BC_Read_Reg = &MemReadHSCX_IPACX;
  1064. cs->BC_Write_Reg = &MemWriteHSCX_IPACX;
  1065. cs->BC_Send_Data = NULL; // function located in ipacx module
  1066. cs->irq_func = &diva_irq_ipacx_pci;
  1067. printk(KERN_INFO "Diva: IPACX Design Id: %x\n",
  1068. MemReadISAC_IPACX(cs, IPACX_ID) &0x3F);
  1069. } else { /* DIVA 2.0 */
  1070. cs->hw.diva.tl.function = (void *) diva_led_handler;
  1071. cs->hw.diva.tl.data = (long) cs;
  1072. init_timer(&cs->hw.diva.tl);
  1073. cs->readisac = &ReadISAC;
  1074. cs->writeisac = &WriteISAC;
  1075. cs->readisacfifo = &ReadISACfifo;
  1076. cs->writeisacfifo = &WriteISACfifo;
  1077. cs->irq_func = &diva_interrupt;
  1078. ISACVersion(cs, "Diva:");
  1079. if (HscxVersion(cs, "Diva:")) {
  1080. printk(KERN_WARNING
  1081. "Diva: wrong HSCX versions check IO address\n");
  1082. release_io_diva(cs);
  1083. return (0);
  1084. }
  1085. }
  1086. return (1);
  1087. }