diva.c 34 KB

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