elsa.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /* $Id: elsa.c,v 2.32.2.4 2004/01/24 20:47:21 keil Exp $
  2. *
  3. * low level stuff for Elsa 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 Elsa GmbH for documents and information
  15. *
  16. * Klaus Lichtenwalder (Klaus.Lichtenwalder@WebForum.DE)
  17. * for ELSA PCMCIA support
  18. *
  19. */
  20. #include <linux/init.h>
  21. #include <linux/slab.h>
  22. #include "hisax.h"
  23. #include "arcofi.h"
  24. #include "isac.h"
  25. #include "ipac.h"
  26. #include "hscx.h"
  27. #include "isdnl1.h"
  28. #include <linux/pci.h>
  29. #include <linux/isapnp.h>
  30. #include <linux/serial.h>
  31. #include <linux/serial_reg.h>
  32. static const char *Elsa_revision = "$Revision: 2.32.2.4 $";
  33. static const char *Elsa_Types[] =
  34. {"None", "PC", "PCC-8", "PCC-16", "PCF", "PCF-Pro",
  35. "PCMCIA", "QS 1000", "QS 3000", "Microlink PCI", "QS 3000 PCI",
  36. "PCMCIA-IPAC" };
  37. static const char *ITACVer[] =
  38. {"?0?", "?1?", "?2?", "?3?", "?4?", "V2.2",
  39. "B1", "A1"};
  40. #define byteout(addr, val) outb(val, addr)
  41. #define bytein(addr) inb(addr)
  42. #define ELSA_ISAC 0
  43. #define ELSA_ISAC_PCM 1
  44. #define ELSA_ITAC 1
  45. #define ELSA_HSCX 2
  46. #define ELSA_ALE 3
  47. #define ELSA_ALE_PCM 4
  48. #define ELSA_CONTROL 4
  49. #define ELSA_CONFIG 5
  50. #define ELSA_START_TIMER 6
  51. #define ELSA_TRIG_IRQ 7
  52. #define ELSA_PC 1
  53. #define ELSA_PCC8 2
  54. #define ELSA_PCC16 3
  55. #define ELSA_PCF 4
  56. #define ELSA_PCFPRO 5
  57. #define ELSA_PCMCIA 6
  58. #define ELSA_QS1000 7
  59. #define ELSA_QS3000 8
  60. #define ELSA_QS1000PCI 9
  61. #define ELSA_QS3000PCI 10
  62. #define ELSA_PCMCIA_IPAC 11
  63. /* PCI stuff */
  64. #define ELSA_PCI_IRQ_MASK 0x04
  65. /* ITAC Registeradressen (only Microlink PC) */
  66. #define ITAC_SYS 0x34
  67. #define ITAC_ISEN 0x48
  68. #define ITAC_RFIE 0x4A
  69. #define ITAC_XFIE 0x4C
  70. #define ITAC_SCIE 0x4E
  71. #define ITAC_STIE 0x46
  72. /*** ***
  73. *** Makros als Befehle fuer die Kartenregister ***
  74. *** (mehrere Befehle werden durch Bit-Oderung kombiniert) ***
  75. *** ***/
  76. /* Config-Register (Read) */
  77. #define ELIRQF_TIMER_RUN 0x02 /* Bit 1 des Config-Reg */
  78. #define ELIRQF_TIMER_RUN_PCC8 0x01 /* Bit 0 des Config-Reg bei PCC */
  79. #define ELSA_IRQ_IDX 0x38 /* Bit 3,4,5 des Config-Reg */
  80. #define ELSA_IRQ_IDX_PCC8 0x30 /* Bit 4,5 des Config-Reg */
  81. #define ELSA_IRQ_IDX_PC 0x0c /* Bit 2,3 des Config-Reg */
  82. /* Control-Register (Write) */
  83. #define ELSA_LINE_LED 0x02 /* Bit 1 Gelbe LED */
  84. #define ELSA_STAT_LED 0x08 /* Bit 3 Gruene LED */
  85. #define ELSA_ISDN_RESET 0x20 /* Bit 5 Reset-Leitung */
  86. #define ELSA_ENA_TIMER_INT 0x80 /* Bit 7 Freigabe Timer Interrupt */
  87. /* ALE-Register (Read) */
  88. #define ELSA_HW_RELEASE 0x07 /* Bit 0-2 Hardwarerkennung */
  89. #define ELSA_S0_POWER_BAD 0x08 /* Bit 3 S0-Bus Spannung fehlt */
  90. /* Status Flags */
  91. #define ELIRQF_TIMER_AKTIV 1
  92. #define ELSA_BAD_PWR 2
  93. #define ELSA_ASSIGN 4
  94. #define RS_ISR_PASS_LIMIT 256
  95. #define FLG_MODEM_ACTIVE 1
  96. /* IPAC AUX */
  97. #define ELSA_IPAC_LINE_LED 0x40 /* Bit 6 Gelbe LED */
  98. #define ELSA_IPAC_STAT_LED 0x80 /* Bit 7 Gruene LED */
  99. #if ARCOFI_USE
  100. static struct arcofi_msg ARCOFI_XOP_F =
  101. {NULL,0,2,{0xa1,0x3f,0,0,0,0,0,0,0,0}}; /* Normal OP */
  102. static struct arcofi_msg ARCOFI_XOP_1 =
  103. {&ARCOFI_XOP_F,0,2,{0xa1,0x31,0,0,0,0,0,0,0,0}}; /* PWR UP */
  104. static struct arcofi_msg ARCOFI_SOP_F =
  105. {&ARCOFI_XOP_1,0,10,{0xa1,0x1f,0x00,0x50,0x10,0x00,0x00,0x80,0x02,0x12}};
  106. static struct arcofi_msg ARCOFI_COP_9 =
  107. {&ARCOFI_SOP_F,0,10,{0xa1,0x29,0x80,0xcb,0xe9,0x88,0x00,0xc8,0xd8,0x80}}; /* RX */
  108. static struct arcofi_msg ARCOFI_COP_8 =
  109. {&ARCOFI_COP_9,0,10,{0xa1,0x28,0x49,0x31,0x8,0x13,0x6e,0x88,0x2a,0x61}}; /* TX */
  110. static struct arcofi_msg ARCOFI_COP_7 =
  111. {&ARCOFI_COP_8,0,4,{0xa1,0x27,0x80,0x80,0,0,0,0,0,0}}; /* GZ */
  112. static struct arcofi_msg ARCOFI_COP_6 =
  113. {&ARCOFI_COP_7,0,6,{0xa1,0x26,0,0,0x82,0x7c,0,0,0,0}}; /* GRL GRH */
  114. static struct arcofi_msg ARCOFI_COP_5 =
  115. {&ARCOFI_COP_6,0,4,{0xa1,0x25,0xbb,0x4a,0,0,0,0,0,0}}; /* GTX */
  116. static struct arcofi_msg ARCOFI_VERSION =
  117. {NULL,1,2,{0xa0,0,0,0,0,0,0,0,0,0}};
  118. static struct arcofi_msg ARCOFI_XOP_0 =
  119. {NULL,0,2,{0xa1,0x30,0,0,0,0,0,0,0,0}}; /* PWR Down */
  120. static void set_arcofi(struct IsdnCardState *cs, int bc);
  121. #include "elsa_ser.c"
  122. #endif /* ARCOFI_USE */
  123. static inline u_char
  124. readreg(unsigned int ale, unsigned int adr, u_char off)
  125. {
  126. register u_char ret;
  127. byteout(ale, off);
  128. ret = bytein(adr);
  129. return (ret);
  130. }
  131. static inline void
  132. readfifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
  133. {
  134. byteout(ale, off);
  135. insb(adr, data, size);
  136. }
  137. static inline void
  138. writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
  139. {
  140. byteout(ale, off);
  141. byteout(adr, data);
  142. }
  143. static inline void
  144. writefifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
  145. {
  146. byteout(ale, off);
  147. outsb(adr, data, size);
  148. }
  149. /* Interface functions */
  150. static u_char
  151. ReadISAC(struct IsdnCardState *cs, u_char offset)
  152. {
  153. return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset));
  154. }
  155. static void
  156. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  157. {
  158. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset, value);
  159. }
  160. static void
  161. ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  162. {
  163. readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
  164. }
  165. static void
  166. WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  167. {
  168. writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0, data, size);
  169. }
  170. static u_char
  171. ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
  172. {
  173. return (readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset + 0x80));
  174. }
  175. static void
  176. WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
  177. {
  178. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, offset | 0x80, value);
  179. }
  180. static void
  181. ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char *data, int size)
  182. {
  183. readfifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
  184. }
  185. static void
  186. WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char *data, int size)
  187. {
  188. writefifo(cs->hw.elsa.ale, cs->hw.elsa.isac, 0x80, data, size);
  189. }
  190. static u_char
  191. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  192. {
  193. return (readreg(cs->hw.elsa.ale,
  194. cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0)));
  195. }
  196. static void
  197. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  198. {
  199. writereg(cs->hw.elsa.ale,
  200. cs->hw.elsa.hscx, offset + (hscx ? 0x40 : 0), value);
  201. }
  202. static inline u_char
  203. readitac(struct IsdnCardState *cs, u_char off)
  204. {
  205. register u_char ret;
  206. byteout(cs->hw.elsa.ale, off);
  207. ret = bytein(cs->hw.elsa.itac);
  208. return (ret);
  209. }
  210. static inline void
  211. writeitac(struct IsdnCardState *cs, u_char off, u_char data)
  212. {
  213. byteout(cs->hw.elsa.ale, off);
  214. byteout(cs->hw.elsa.itac, data);
  215. }
  216. static inline int
  217. TimerRun(struct IsdnCardState *cs)
  218. {
  219. register u_char v;
  220. v = bytein(cs->hw.elsa.cfg);
  221. if ((cs->subtyp == ELSA_QS1000) || (cs->subtyp == ELSA_QS3000))
  222. return (0 == (v & ELIRQF_TIMER_RUN));
  223. else if (cs->subtyp == ELSA_PCC8)
  224. return (v & ELIRQF_TIMER_RUN_PCC8);
  225. return (v & ELIRQF_TIMER_RUN);
  226. }
  227. /*
  228. * fast interrupt HSCX stuff goes here
  229. */
  230. #define READHSCX(cs, nr, reg) readreg(cs->hw.elsa.ale, \
  231. cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0))
  232. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.elsa.ale, \
  233. cs->hw.elsa.hscx, reg + (nr ? 0x40 : 0), data)
  234. #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.elsa.ale, \
  235. cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
  236. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.elsa.ale, \
  237. cs->hw.elsa.hscx, (nr ? 0x40 : 0), ptr, cnt)
  238. #include "hscx_irq.c"
  239. static irqreturn_t
  240. elsa_interrupt(int intno, void *dev_id)
  241. {
  242. struct IsdnCardState *cs = dev_id;
  243. u_long flags;
  244. u_char val;
  245. int icnt = 5;
  246. if ((cs->typ == ISDN_CTYPE_ELSA_PCMCIA) && (*cs->busy_flag == 1)) {
  247. /* The card tends to generate interrupts while being removed
  248. causing us to just crash the kernel. bad. */
  249. printk(KERN_WARNING "Elsa: card not available!\n");
  250. return IRQ_NONE;
  251. }
  252. spin_lock_irqsave(&cs->lock, flags);
  253. #if ARCOFI_USE
  254. if (cs->hw.elsa.MFlag) {
  255. val = serial_inp(cs, UART_IIR);
  256. if (!(val & UART_IIR_NO_INT)) {
  257. debugl1(cs, "IIR %02x", val);
  258. rs_interrupt_elsa(cs);
  259. }
  260. }
  261. #endif
  262. val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
  263. Start_HSCX:
  264. if (val) {
  265. hscx_int_main(cs, val);
  266. }
  267. val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
  268. Start_ISAC:
  269. if (val) {
  270. isac_interrupt(cs, val);
  271. }
  272. val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
  273. if (val && icnt) {
  274. if (cs->debug & L1_DEB_HSCX)
  275. debugl1(cs, "HSCX IntStat after IntRoutine");
  276. icnt--;
  277. goto Start_HSCX;
  278. }
  279. val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA);
  280. if (val && icnt) {
  281. if (cs->debug & L1_DEB_ISAC)
  282. debugl1(cs, "ISAC IntStat after IntRoutine");
  283. icnt--;
  284. goto Start_ISAC;
  285. }
  286. if (!icnt)
  287. printk(KERN_WARNING"ELSA IRQ LOOP\n");
  288. writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0xFF);
  289. writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0xFF);
  290. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0xFF);
  291. if (cs->hw.elsa.status & ELIRQF_TIMER_AKTIV) {
  292. if (!TimerRun(cs)) {
  293. /* Timer Restart */
  294. byteout(cs->hw.elsa.timer, 0);
  295. cs->hw.elsa.counter++;
  296. }
  297. }
  298. #if ARCOFI_USE
  299. if (cs->hw.elsa.MFlag) {
  300. val = serial_inp(cs, UART_MCR);
  301. val ^= 0x8;
  302. serial_outp(cs, UART_MCR, val);
  303. val = serial_inp(cs, UART_MCR);
  304. val ^= 0x8;
  305. serial_outp(cs, UART_MCR, val);
  306. }
  307. #endif
  308. if (cs->hw.elsa.trig)
  309. byteout(cs->hw.elsa.trig, 0x00);
  310. writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK, 0x0);
  311. writereg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_MASK + 0x40, 0x0);
  312. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_MASK, 0x0);
  313. spin_unlock_irqrestore(&cs->lock, flags);
  314. return IRQ_HANDLED;
  315. }
  316. static irqreturn_t
  317. elsa_interrupt_ipac(int intno, void *dev_id)
  318. {
  319. struct IsdnCardState *cs = dev_id;
  320. u_long flags;
  321. u_char ista, val;
  322. int icnt = 5;
  323. spin_lock_irqsave(&cs->lock, flags);
  324. if (cs->subtyp == ELSA_QS1000PCI || cs->subtyp == ELSA_QS3000PCI) {
  325. val = bytein(cs->hw.elsa.cfg + 0x4c); /* PCI IRQ */
  326. if (!(val & ELSA_PCI_IRQ_MASK)) {
  327. spin_unlock_irqrestore(&cs->lock, flags);
  328. return IRQ_NONE;
  329. }
  330. }
  331. #if ARCOFI_USE
  332. if (cs->hw.elsa.MFlag) {
  333. val = serial_inp(cs, UART_IIR);
  334. if (!(val & UART_IIR_NO_INT)) {
  335. debugl1(cs, "IIR %02x", val);
  336. rs_interrupt_elsa(cs);
  337. }
  338. }
  339. #endif
  340. ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
  341. Start_IPAC:
  342. if (cs->debug & L1_DEB_IPAC)
  343. debugl1(cs, "IPAC ISTA %02X", ista);
  344. if (ista & 0x0f) {
  345. val = readreg(cs->hw.elsa.ale, cs->hw.elsa.hscx, HSCX_ISTA + 0x40);
  346. if (ista & 0x01)
  347. val |= 0x01;
  348. if (ista & 0x04)
  349. val |= 0x02;
  350. if (ista & 0x08)
  351. val |= 0x04;
  352. if (val)
  353. hscx_int_main(cs, val);
  354. }
  355. if (ista & 0x20) {
  356. val = 0xfe & readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, ISAC_ISTA + 0x80);
  357. if (val) {
  358. isac_interrupt(cs, val);
  359. }
  360. }
  361. if (ista & 0x10) {
  362. val = 0x01;
  363. isac_interrupt(cs, val);
  364. }
  365. ista = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ISTA);
  366. if ((ista & 0x3f) && icnt) {
  367. icnt--;
  368. goto Start_IPAC;
  369. }
  370. if (!icnt)
  371. printk(KERN_WARNING "ELSA IRQ LOOP\n");
  372. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xFF);
  373. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xC0);
  374. spin_unlock_irqrestore(&cs->lock, flags);
  375. return IRQ_HANDLED;
  376. }
  377. static void
  378. release_io_elsa(struct IsdnCardState *cs)
  379. {
  380. int bytecnt = 8;
  381. del_timer(&cs->hw.elsa.tl);
  382. #if ARCOFI_USE
  383. clear_arcofi(cs);
  384. #endif
  385. if (cs->hw.elsa.ctrl)
  386. byteout(cs->hw.elsa.ctrl, 0); /* LEDs Out */
  387. if (cs->subtyp == ELSA_QS1000PCI) {
  388. byteout(cs->hw.elsa.cfg + 0x4c, 0x01); /* disable IRQ */
  389. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
  390. bytecnt = 2;
  391. release_region(cs->hw.elsa.cfg, 0x80);
  392. }
  393. if (cs->subtyp == ELSA_QS3000PCI) {
  394. byteout(cs->hw.elsa.cfg + 0x4c, 0x03); /* disable ELSA PCI IRQ */
  395. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
  396. release_region(cs->hw.elsa.cfg, 0x80);
  397. }
  398. if (cs->subtyp == ELSA_PCMCIA_IPAC) {
  399. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
  400. }
  401. if ((cs->subtyp == ELSA_PCFPRO) ||
  402. (cs->subtyp == ELSA_QS3000) ||
  403. (cs->subtyp == ELSA_PCF) ||
  404. (cs->subtyp == ELSA_QS3000PCI)) {
  405. bytecnt = 16;
  406. #if ARCOFI_USE
  407. release_modem(cs);
  408. #endif
  409. }
  410. if (cs->hw.elsa.base)
  411. release_region(cs->hw.elsa.base, bytecnt);
  412. }
  413. static void
  414. reset_elsa(struct IsdnCardState *cs)
  415. {
  416. if (cs->hw.elsa.timer) {
  417. /* Wait 1 Timer */
  418. byteout(cs->hw.elsa.timer, 0);
  419. while (TimerRun(cs));
  420. cs->hw.elsa.ctrl_reg |= 0x50;
  421. cs->hw.elsa.ctrl_reg &= ~ELSA_ISDN_RESET; /* Reset On */
  422. byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
  423. /* Wait 1 Timer */
  424. byteout(cs->hw.elsa.timer, 0);
  425. while (TimerRun(cs));
  426. cs->hw.elsa.ctrl_reg |= ELSA_ISDN_RESET; /* Reset Off */
  427. byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
  428. /* Wait 1 Timer */
  429. byteout(cs->hw.elsa.timer, 0);
  430. while (TimerRun(cs));
  431. if (cs->hw.elsa.trig)
  432. byteout(cs->hw.elsa.trig, 0xff);
  433. }
  434. if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
  435. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x20);
  436. mdelay(10);
  437. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_POTA2, 0x00);
  438. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_MASK, 0xc0);
  439. mdelay(10);
  440. if (cs->subtyp != ELSA_PCMCIA_IPAC) {
  441. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x0);
  442. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0x3c);
  443. } else {
  444. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_PCFG, 0x10);
  445. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ACFG, 0x4);
  446. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_AOE, 0xf8);
  447. }
  448. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, 0xff);
  449. if (cs->subtyp == ELSA_QS1000PCI)
  450. byteout(cs->hw.elsa.cfg + 0x4c, 0x41); /* enable ELSA PCI IRQ */
  451. else if (cs->subtyp == ELSA_QS3000PCI)
  452. byteout(cs->hw.elsa.cfg + 0x4c, 0x43); /* enable ELSA PCI IRQ */
  453. }
  454. }
  455. #if ARCOFI_USE
  456. static void
  457. set_arcofi(struct IsdnCardState *cs, int bc) {
  458. cs->dc.isac.arcofi_bc = bc;
  459. arcofi_fsm(cs, ARCOFI_START, &ARCOFI_COP_5);
  460. wait_event_interruptible(cs->dc.isac.arcofi_wait,
  461. cs->dc.isac.arcofi_state == ARCOFI_NOP);
  462. }
  463. static int
  464. check_arcofi(struct IsdnCardState *cs)
  465. {
  466. int arcofi_present = 0;
  467. char tmp[40];
  468. char *t;
  469. u_char *p;
  470. if (!cs->dc.isac.mon_tx)
  471. if (!(cs->dc.isac.mon_tx = kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
  472. if (cs->debug & L1_DEB_WARN)
  473. debugl1(cs, "ISAC MON TX out of buffers!");
  474. return (0);
  475. }
  476. cs->dc.isac.arcofi_bc = 0;
  477. arcofi_fsm(cs, ARCOFI_START, &ARCOFI_VERSION);
  478. wait_event_interruptible(cs->dc.isac.arcofi_wait,
  479. cs->dc.isac.arcofi_state == ARCOFI_NOP);
  480. if (!test_and_clear_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags)) {
  481. debugl1(cs, "Arcofi response received %d bytes", cs->dc.isac.mon_rxp);
  482. p = cs->dc.isac.mon_rx;
  483. t = tmp;
  484. t += sprintf(tmp, "Arcofi data");
  485. QuickHex(t, p, cs->dc.isac.mon_rxp);
  486. debugl1(cs, "%s", tmp);
  487. if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
  488. switch (cs->dc.isac.mon_rx[1]) {
  489. case 0x80:
  490. debugl1(cs, "Arcofi 2160 detected");
  491. arcofi_present = 1;
  492. break;
  493. case 0x82:
  494. debugl1(cs, "Arcofi 2165 detected");
  495. arcofi_present = 2;
  496. break;
  497. case 0x84:
  498. debugl1(cs, "Arcofi 2163 detected");
  499. arcofi_present = 3;
  500. break;
  501. default:
  502. debugl1(cs, "unknown Arcofi response");
  503. break;
  504. }
  505. } else
  506. debugl1(cs, "undefined Monitor response");
  507. cs->dc.isac.mon_rxp = 0;
  508. } else if (cs->dc.isac.mon_tx) {
  509. debugl1(cs, "Arcofi not detected");
  510. }
  511. if (arcofi_present) {
  512. if (cs->subtyp == ELSA_QS1000) {
  513. cs->subtyp = ELSA_QS3000;
  514. printk(KERN_INFO
  515. "Elsa: %s detected modem at 0x%lx\n",
  516. Elsa_Types[cs->subtyp],
  517. cs->hw.elsa.base + 8);
  518. release_region(cs->hw.elsa.base, 8);
  519. if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
  520. printk(KERN_WARNING
  521. "HiSax: %s config port %lx-%lx already in use\n",
  522. Elsa_Types[cs->subtyp],
  523. cs->hw.elsa.base + 8,
  524. cs->hw.elsa.base + 16);
  525. }
  526. } else if (cs->subtyp == ELSA_PCC16) {
  527. cs->subtyp = ELSA_PCF;
  528. printk(KERN_INFO
  529. "Elsa: %s detected modem at 0x%lx\n",
  530. Elsa_Types[cs->subtyp],
  531. cs->hw.elsa.base + 8);
  532. release_region(cs->hw.elsa.base, 8);
  533. if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
  534. printk(KERN_WARNING
  535. "HiSax: %s config port %lx-%lx already in use\n",
  536. Elsa_Types[cs->subtyp],
  537. cs->hw.elsa.base + 8,
  538. cs->hw.elsa.base + 16);
  539. }
  540. } else
  541. printk(KERN_INFO
  542. "Elsa: %s detected modem at 0x%lx\n",
  543. Elsa_Types[cs->subtyp],
  544. cs->hw.elsa.base + 8);
  545. arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
  546. wait_event_interruptible(cs->dc.isac.arcofi_wait,
  547. cs->dc.isac.arcofi_state == ARCOFI_NOP);
  548. return (1);
  549. }
  550. return (0);
  551. }
  552. #endif /* ARCOFI_USE */
  553. static void
  554. elsa_led_handler(struct IsdnCardState *cs)
  555. {
  556. int blink = 0;
  557. if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
  558. return;
  559. del_timer(&cs->hw.elsa.tl);
  560. if (cs->hw.elsa.status & ELSA_ASSIGN)
  561. cs->hw.elsa.ctrl_reg |= ELSA_STAT_LED;
  562. else if (cs->hw.elsa.status & ELSA_BAD_PWR)
  563. cs->hw.elsa.ctrl_reg &= ~ELSA_STAT_LED;
  564. else {
  565. cs->hw.elsa.ctrl_reg ^= ELSA_STAT_LED;
  566. blink = 250;
  567. }
  568. if (cs->hw.elsa.status & 0xf000)
  569. cs->hw.elsa.ctrl_reg |= ELSA_LINE_LED;
  570. else if (cs->hw.elsa.status & 0x0f00) {
  571. cs->hw.elsa.ctrl_reg ^= ELSA_LINE_LED;
  572. blink = 500;
  573. } else
  574. cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;
  575. if ((cs->subtyp == ELSA_QS1000PCI) ||
  576. (cs->subtyp == ELSA_QS3000PCI)) {
  577. u_char led = 0xff;
  578. if (cs->hw.elsa.ctrl_reg & ELSA_LINE_LED)
  579. led ^= ELSA_IPAC_LINE_LED;
  580. if (cs->hw.elsa.ctrl_reg & ELSA_STAT_LED)
  581. led ^= ELSA_IPAC_STAT_LED;
  582. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, led);
  583. } else
  584. byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
  585. if (blink) {
  586. init_timer(&cs->hw.elsa.tl);
  587. cs->hw.elsa.tl.expires = jiffies + ((blink * HZ) / 1000);
  588. add_timer(&cs->hw.elsa.tl);
  589. }
  590. }
  591. static int
  592. Elsa_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  593. {
  594. int ret = 0;
  595. u_long flags;
  596. switch (mt) {
  597. case CARD_RESET:
  598. spin_lock_irqsave(&cs->lock, flags);
  599. reset_elsa(cs);
  600. spin_unlock_irqrestore(&cs->lock, flags);
  601. return (0);
  602. case CARD_RELEASE:
  603. release_io_elsa(cs);
  604. return (0);
  605. case CARD_INIT:
  606. spin_lock_irqsave(&cs->lock, flags);
  607. cs->debug |= L1_DEB_IPAC;
  608. reset_elsa(cs);
  609. inithscxisac(cs, 1);
  610. if ((cs->subtyp == ELSA_QS1000) ||
  611. (cs->subtyp == ELSA_QS3000))
  612. {
  613. byteout(cs->hw.elsa.timer, 0);
  614. }
  615. if (cs->hw.elsa.trig)
  616. byteout(cs->hw.elsa.trig, 0xff);
  617. inithscxisac(cs, 2);
  618. spin_unlock_irqrestore(&cs->lock, flags);
  619. return (0);
  620. case CARD_TEST:
  621. if ((cs->subtyp == ELSA_PCMCIA) ||
  622. (cs->subtyp == ELSA_PCMCIA_IPAC) ||
  623. (cs->subtyp == ELSA_QS1000PCI)) {
  624. return (0);
  625. } else if (cs->subtyp == ELSA_QS3000PCI) {
  626. ret = 0;
  627. } else {
  628. spin_lock_irqsave(&cs->lock, flags);
  629. cs->hw.elsa.counter = 0;
  630. cs->hw.elsa.ctrl_reg |= ELSA_ENA_TIMER_INT;
  631. cs->hw.elsa.status |= ELIRQF_TIMER_AKTIV;
  632. byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
  633. byteout(cs->hw.elsa.timer, 0);
  634. spin_unlock_irqrestore(&cs->lock, flags);
  635. msleep(110);
  636. spin_lock_irqsave(&cs->lock, flags);
  637. cs->hw.elsa.ctrl_reg &= ~ELSA_ENA_TIMER_INT;
  638. byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
  639. cs->hw.elsa.status &= ~ELIRQF_TIMER_AKTIV;
  640. spin_unlock_irqrestore(&cs->lock, flags);
  641. printk(KERN_INFO "Elsa: %d timer tics in 110 msek\n",
  642. cs->hw.elsa.counter);
  643. if ((cs->hw.elsa.counter > 10) &&
  644. (cs->hw.elsa.counter < 16)) {
  645. printk(KERN_INFO "Elsa: timer and irq OK\n");
  646. ret = 0;
  647. } else {
  648. printk(KERN_WARNING
  649. "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
  650. cs->hw.elsa.counter, cs->irq);
  651. ret = 1;
  652. }
  653. }
  654. #if ARCOFI_USE
  655. if (check_arcofi(cs)) {
  656. init_modem(cs);
  657. }
  658. #endif
  659. elsa_led_handler(cs);
  660. return (ret);
  661. case (MDL_REMOVE | REQUEST):
  662. cs->hw.elsa.status &= 0;
  663. break;
  664. case (MDL_ASSIGN | REQUEST):
  665. cs->hw.elsa.status |= ELSA_ASSIGN;
  666. break;
  667. case MDL_INFO_SETUP:
  668. if ((long) arg)
  669. cs->hw.elsa.status |= 0x0200;
  670. else
  671. cs->hw.elsa.status |= 0x0100;
  672. break;
  673. case MDL_INFO_CONN:
  674. if ((long) arg)
  675. cs->hw.elsa.status |= 0x2000;
  676. else
  677. cs->hw.elsa.status |= 0x1000;
  678. break;
  679. case MDL_INFO_REL:
  680. if ((long) arg) {
  681. cs->hw.elsa.status &= ~0x2000;
  682. cs->hw.elsa.status &= ~0x0200;
  683. } else {
  684. cs->hw.elsa.status &= ~0x1000;
  685. cs->hw.elsa.status &= ~0x0100;
  686. }
  687. break;
  688. #if ARCOFI_USE
  689. case CARD_AUX_IND:
  690. if (cs->hw.elsa.MFlag) {
  691. int len;
  692. u_char *msg;
  693. if (!arg)
  694. return (0);
  695. msg = arg;
  696. len = *msg;
  697. msg++;
  698. modem_write_cmd(cs, msg, len);
  699. }
  700. break;
  701. #endif
  702. }
  703. if (cs->typ == ISDN_CTYPE_ELSA) {
  704. int pwr = bytein(cs->hw.elsa.ale);
  705. if (pwr & 0x08)
  706. cs->hw.elsa.status |= ELSA_BAD_PWR;
  707. else
  708. cs->hw.elsa.status &= ~ELSA_BAD_PWR;
  709. }
  710. elsa_led_handler(cs);
  711. return (ret);
  712. }
  713. static unsigned char
  714. probe_elsa_adr(unsigned int adr, int typ)
  715. {
  716. int i, in1, in2, p16_1 = 0, p16_2 = 0, p8_1 = 0, p8_2 = 0, pc_1 = 0,
  717. pc_2 = 0, pfp_1 = 0, pfp_2 = 0;
  718. /* In case of the elsa pcmcia card, this region is in use,
  719. reserved for us by the card manager. So we do not check it
  720. here, it would fail. */
  721. if (typ != ISDN_CTYPE_ELSA_PCMCIA) {
  722. if (request_region(adr, 8, "elsa card")) {
  723. release_region(adr, 8);
  724. } else {
  725. printk(KERN_WARNING
  726. "Elsa: Probing Port 0x%x: already in use\n", adr);
  727. return (0);
  728. }
  729. }
  730. for (i = 0; i < 16; i++) {
  731. in1 = inb(adr + ELSA_CONFIG); /* 'toggelt' bei */
  732. in2 = inb(adr + ELSA_CONFIG); /* jedem Zugriff */
  733. p16_1 += 0x04 & in1;
  734. p16_2 += 0x04 & in2;
  735. p8_1 += 0x02 & in1;
  736. p8_2 += 0x02 & in2;
  737. pc_1 += 0x01 & in1;
  738. pc_2 += 0x01 & in2;
  739. pfp_1 += 0x40 & in1;
  740. pfp_2 += 0x40 & in2;
  741. }
  742. printk(KERN_INFO "Elsa: Probing IO 0x%x", adr);
  743. if (65 == ++p16_1 * ++p16_2) {
  744. printk(" PCC-16/PCF found\n");
  745. return (ELSA_PCC16);
  746. } else if (1025 == ++pfp_1 * ++pfp_2) {
  747. printk(" PCF-Pro found\n");
  748. return (ELSA_PCFPRO);
  749. } else if (33 == ++p8_1 * ++p8_2) {
  750. printk(" PCC8 found\n");
  751. return (ELSA_PCC8);
  752. } else if (17 == ++pc_1 * ++pc_2) {
  753. printk(" PC found\n");
  754. return (ELSA_PC);
  755. } else {
  756. printk(" failed\n");
  757. return (0);
  758. }
  759. }
  760. static unsigned int
  761. probe_elsa(struct IsdnCardState *cs)
  762. {
  763. int i;
  764. unsigned int CARD_portlist[] =
  765. {0x160, 0x170, 0x260, 0x360, 0};
  766. for (i = 0; CARD_portlist[i]; i++) {
  767. if ((cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ)))
  768. break;
  769. }
  770. return (CARD_portlist[i]);
  771. }
  772. static int setup_elsa_isa(struct IsdnCard *card)
  773. {
  774. struct IsdnCardState *cs = card->cs;
  775. u_char val;
  776. cs->hw.elsa.base = card->para[0];
  777. printk(KERN_INFO "Elsa: Microlink IO probing\n");
  778. if (cs->hw.elsa.base) {
  779. if (!(cs->subtyp = probe_elsa_adr(cs->hw.elsa.base,
  780. cs->typ))) {
  781. printk(KERN_WARNING
  782. "Elsa: no Elsa Microlink at %#lx\n",
  783. cs->hw.elsa.base);
  784. return (0);
  785. }
  786. } else
  787. cs->hw.elsa.base = probe_elsa(cs);
  788. if (!cs->hw.elsa.base) {
  789. printk(KERN_WARNING
  790. "No Elsa Microlink found\n");
  791. return (0);
  792. }
  793. cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
  794. cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
  795. cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
  796. cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
  797. cs->hw.elsa.itac = cs->hw.elsa.base + ELSA_ITAC;
  798. cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
  799. cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
  800. cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
  801. val = bytein(cs->hw.elsa.cfg);
  802. if (cs->subtyp == ELSA_PC) {
  803. const u_char CARD_IrqTab[8] =
  804. {7, 3, 5, 9, 0, 0, 0, 0};
  805. cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PC) >> 2];
  806. } else if (cs->subtyp == ELSA_PCC8) {
  807. const u_char CARD_IrqTab[8] =
  808. {7, 3, 5, 9, 0, 0, 0, 0};
  809. cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PCC8) >> 4];
  810. } else {
  811. const u_char CARD_IrqTab[8] =
  812. {15, 10, 15, 3, 11, 5, 11, 9};
  813. cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX) >> 3];
  814. }
  815. val = bytein(cs->hw.elsa.ale) & ELSA_HW_RELEASE;
  816. if (val < 3)
  817. val |= 8;
  818. val += 'A' - 3;
  819. if (val == 'B' || val == 'C')
  820. val ^= 1;
  821. if ((cs->subtyp == ELSA_PCFPRO) && (val == 'G'))
  822. val = 'C';
  823. printk(KERN_INFO
  824. "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
  825. Elsa_Types[cs->subtyp],
  826. cs->hw.elsa.base,
  827. val, cs->irq);
  828. val = bytein(cs->hw.elsa.ale) & ELSA_S0_POWER_BAD;
  829. if (val) {
  830. printk(KERN_WARNING
  831. "Elsa: Microlink S0 bus power bad\n");
  832. cs->hw.elsa.status |= ELSA_BAD_PWR;
  833. }
  834. return (1);
  835. }
  836. #ifdef __ISAPNP__
  837. static struct isapnp_device_id elsa_ids[] = {
  838. { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
  839. ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
  840. (unsigned long) "Elsa QS1000" },
  841. { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
  842. ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
  843. (unsigned long) "Elsa QS3000" },
  844. { 0, }
  845. };
  846. static struct isapnp_device_id *ipid = &elsa_ids[0];
  847. static struct pnp_card *pnp_c = NULL;
  848. #endif /* __ISAPNP__ */
  849. static int setup_elsa_isapnp(struct IsdnCard *card)
  850. {
  851. struct IsdnCardState *cs = card->cs;
  852. #ifdef __ISAPNP__
  853. if (!card->para[1] && isapnp_present()) {
  854. struct pnp_dev *pnp_d;
  855. while (ipid->card_vendor) {
  856. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  857. ipid->card_device, pnp_c))) {
  858. pnp_d = NULL;
  859. if ((pnp_d = pnp_find_dev(pnp_c,
  860. ipid->vendor, ipid->function, pnp_d))) {
  861. int err;
  862. printk(KERN_INFO "HiSax: %s detected\n",
  863. (char *)ipid->driver_data);
  864. pnp_disable_dev(pnp_d);
  865. err = pnp_activate_dev(pnp_d);
  866. if (err < 0) {
  867. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  868. __func__, err);
  869. return (0);
  870. }
  871. card->para[1] = pnp_port_start(pnp_d, 0);
  872. card->para[0] = pnp_irq(pnp_d, 0);
  873. if (!card->para[0] || !card->para[1]) {
  874. printk(KERN_ERR "Elsa PnP:some resources are missing %ld/%lx\n",
  875. card->para[0], card->para[1]);
  876. pnp_disable_dev(pnp_d);
  877. return (0);
  878. }
  879. if (ipid->function == ISAPNP_FUNCTION(0x133))
  880. cs->subtyp = ELSA_QS1000;
  881. else
  882. cs->subtyp = ELSA_QS3000;
  883. break;
  884. } else {
  885. printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
  886. return (0);
  887. }
  888. }
  889. ipid++;
  890. pnp_c = NULL;
  891. }
  892. if (!ipid->card_vendor) {
  893. printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
  894. return (0);
  895. }
  896. }
  897. #endif /* __ISAPNP__ */
  898. if (card->para[1] && card->para[0]) {
  899. cs->hw.elsa.base = card->para[1];
  900. cs->irq = card->para[0];
  901. if (!cs->subtyp)
  902. cs->subtyp = ELSA_QS1000;
  903. } else {
  904. printk(KERN_ERR "Elsa PnP: no parameter\n");
  905. }
  906. cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
  907. cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
  908. cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
  909. cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
  910. cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
  911. cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
  912. cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
  913. printk(KERN_INFO
  914. "Elsa: %s defined at %#lx IRQ %d\n",
  915. Elsa_Types[cs->subtyp],
  916. cs->hw.elsa.base,
  917. cs->irq);
  918. return (1);
  919. }
  920. static void setup_elsa_pcmcia(struct IsdnCard *card)
  921. {
  922. struct IsdnCardState *cs = card->cs;
  923. u_char val;
  924. cs->hw.elsa.base = card->para[1];
  925. cs->irq = card->para[0];
  926. val = readreg(cs->hw.elsa.base + 0, cs->hw.elsa.base + 2, IPAC_ID);
  927. if ((val == 1) || (val == 2)) { /* IPAC version 1.1/1.2 */
  928. cs->subtyp = ELSA_PCMCIA_IPAC;
  929. cs->hw.elsa.ale = cs->hw.elsa.base + 0;
  930. cs->hw.elsa.isac = cs->hw.elsa.base + 2;
  931. cs->hw.elsa.hscx = cs->hw.elsa.base + 2;
  932. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  933. } else {
  934. cs->subtyp = ELSA_PCMCIA;
  935. cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE_PCM;
  936. cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC_PCM;
  937. cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
  938. }
  939. cs->hw.elsa.timer = 0;
  940. cs->hw.elsa.trig = 0;
  941. cs->hw.elsa.ctrl = 0;
  942. cs->irq_flags |= IRQF_SHARED;
  943. printk(KERN_INFO
  944. "Elsa: %s defined at %#lx IRQ %d\n",
  945. Elsa_Types[cs->subtyp],
  946. cs->hw.elsa.base,
  947. cs->irq);
  948. }
  949. #ifdef CONFIG_PCI
  950. static struct pci_dev *dev_qs1000 = NULL;
  951. static struct pci_dev *dev_qs3000 = NULL;
  952. static int setup_elsa_pci(struct IsdnCard *card)
  953. {
  954. struct IsdnCardState *cs = card->cs;
  955. cs->subtyp = 0;
  956. if ((dev_qs1000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA,
  957. PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
  958. if (pci_enable_device(dev_qs1000))
  959. return (0);
  960. cs->subtyp = ELSA_QS1000PCI;
  961. cs->irq = dev_qs1000->irq;
  962. cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1);
  963. cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3);
  964. } else if ((dev_qs3000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA,
  965. PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
  966. if (pci_enable_device(dev_qs3000))
  967. return (0);
  968. cs->subtyp = ELSA_QS3000PCI;
  969. cs->irq = dev_qs3000->irq;
  970. cs->hw.elsa.cfg = pci_resource_start(dev_qs3000, 1);
  971. cs->hw.elsa.base = pci_resource_start(dev_qs3000, 3);
  972. } else {
  973. printk(KERN_WARNING "Elsa: No PCI card found\n");
  974. return (0);
  975. }
  976. if (!cs->irq) {
  977. printk(KERN_WARNING "Elsa: No IRQ for PCI card found\n");
  978. return (0);
  979. }
  980. if (!(cs->hw.elsa.base && cs->hw.elsa.cfg)) {
  981. printk(KERN_WARNING "Elsa: No IO-Adr for PCI card found\n");
  982. return (0);
  983. }
  984. if ((cs->hw.elsa.cfg & 0xff) || (cs->hw.elsa.base & 0xf)) {
  985. printk(KERN_WARNING "Elsa: You may have a wrong PCI bios\n");
  986. printk(KERN_WARNING "Elsa: If your system hangs now, read\n");
  987. printk(KERN_WARNING "Elsa: Documentation/isdn/README.HiSax\n");
  988. }
  989. cs->hw.elsa.ale = cs->hw.elsa.base;
  990. cs->hw.elsa.isac = cs->hw.elsa.base + 1;
  991. cs->hw.elsa.hscx = cs->hw.elsa.base + 1;
  992. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  993. cs->hw.elsa.timer = 0;
  994. cs->hw.elsa.trig = 0;
  995. cs->irq_flags |= IRQF_SHARED;
  996. printk(KERN_INFO
  997. "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
  998. Elsa_Types[cs->subtyp],
  999. cs->hw.elsa.base,
  1000. cs->hw.elsa.cfg,
  1001. cs->irq);
  1002. return (1);
  1003. }
  1004. #else
  1005. static int setup_elsa_pci(struct IsdnCard *card)
  1006. {
  1007. return (1);
  1008. }
  1009. #endif /* CONFIG_PCI */
  1010. static int setup_elsa_common(struct IsdnCard *card)
  1011. {
  1012. struct IsdnCardState *cs = card->cs;
  1013. u_char val;
  1014. int bytecnt;
  1015. switch (cs->subtyp) {
  1016. case ELSA_PC:
  1017. case ELSA_PCC8:
  1018. case ELSA_PCC16:
  1019. case ELSA_QS1000:
  1020. case ELSA_PCMCIA:
  1021. case ELSA_PCMCIA_IPAC:
  1022. bytecnt = 8;
  1023. break;
  1024. case ELSA_PCFPRO:
  1025. case ELSA_PCF:
  1026. case ELSA_QS3000:
  1027. case ELSA_QS3000PCI:
  1028. bytecnt = 16;
  1029. break;
  1030. case ELSA_QS1000PCI:
  1031. bytecnt = 2;
  1032. break;
  1033. default:
  1034. printk(KERN_WARNING
  1035. "Unknown ELSA subtype %d\n", cs->subtyp);
  1036. return (0);
  1037. }
  1038. /* In case of the elsa pcmcia card, this region is in use,
  1039. reserved for us by the card manager. So we do not check it
  1040. here, it would fail. */
  1041. if (cs->typ != ISDN_CTYPE_ELSA_PCMCIA && !request_region(cs->hw.elsa.base, bytecnt, "elsa isdn")) {
  1042. printk(KERN_WARNING
  1043. "HiSax: ELSA config port %#lx-%#lx already in use\n",
  1044. cs->hw.elsa.base,
  1045. cs->hw.elsa.base + bytecnt);
  1046. return (0);
  1047. }
  1048. if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI)) {
  1049. if (!request_region(cs->hw.elsa.cfg, 0x80, "elsa isdn pci")) {
  1050. printk(KERN_WARNING
  1051. "HiSax: ELSA pci port %x-%x already in use\n",
  1052. cs->hw.elsa.cfg,
  1053. cs->hw.elsa.cfg + 0x80);
  1054. release_region(cs->hw.elsa.base, bytecnt);
  1055. return (0);
  1056. }
  1057. }
  1058. #if ARCOFI_USE
  1059. init_arcofi(cs);
  1060. #endif
  1061. setup_isac(cs);
  1062. setup_timer(&cs->hw.elsa.tl, (void *)elsa_led_handler, (long)cs);
  1063. /* Teste Timer */
  1064. if (cs->hw.elsa.timer) {
  1065. byteout(cs->hw.elsa.trig, 0xff);
  1066. byteout(cs->hw.elsa.timer, 0);
  1067. if (!TimerRun(cs)) {
  1068. byteout(cs->hw.elsa.timer, 0); /* 2. Versuch */
  1069. if (!TimerRun(cs)) {
  1070. printk(KERN_WARNING
  1071. "Elsa: timer do not start\n");
  1072. release_io_elsa(cs);
  1073. return (0);
  1074. }
  1075. }
  1076. HZDELAY((HZ / 100) + 1); /* wait >=10 ms */
  1077. if (TimerRun(cs)) {
  1078. printk(KERN_WARNING "Elsa: timer do not run down\n");
  1079. release_io_elsa(cs);
  1080. return (0);
  1081. }
  1082. printk(KERN_INFO "Elsa: timer OK; resetting card\n");
  1083. }
  1084. cs->BC_Read_Reg = &ReadHSCX;
  1085. cs->BC_Write_Reg = &WriteHSCX;
  1086. cs->BC_Send_Data = &hscx_fill_fifo;
  1087. cs->cardmsg = &Elsa_card_msg;
  1088. if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
  1089. cs->readisac = &ReadISAC_IPAC;
  1090. cs->writeisac = &WriteISAC_IPAC;
  1091. cs->readisacfifo = &ReadISACfifo_IPAC;
  1092. cs->writeisacfifo = &WriteISACfifo_IPAC;
  1093. cs->irq_func = &elsa_interrupt_ipac;
  1094. val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ID);
  1095. printk(KERN_INFO "Elsa: IPAC version %x\n", val);
  1096. } else {
  1097. cs->readisac = &ReadISAC;
  1098. cs->writeisac = &WriteISAC;
  1099. cs->readisacfifo = &ReadISACfifo;
  1100. cs->writeisacfifo = &WriteISACfifo;
  1101. cs->irq_func = &elsa_interrupt;
  1102. ISACVersion(cs, "Elsa:");
  1103. if (HscxVersion(cs, "Elsa:")) {
  1104. printk(KERN_WARNING
  1105. "Elsa: wrong HSCX versions check IO address\n");
  1106. release_io_elsa(cs);
  1107. return (0);
  1108. }
  1109. }
  1110. if (cs->subtyp == ELSA_PC) {
  1111. val = readitac(cs, ITAC_SYS);
  1112. printk(KERN_INFO "Elsa: ITAC version %s\n", ITACVer[val & 7]);
  1113. writeitac(cs, ITAC_ISEN, 0);
  1114. writeitac(cs, ITAC_RFIE, 0);
  1115. writeitac(cs, ITAC_XFIE, 0);
  1116. writeitac(cs, ITAC_SCIE, 0);
  1117. writeitac(cs, ITAC_STIE, 0);
  1118. }
  1119. return (1);
  1120. }
  1121. int setup_elsa(struct IsdnCard *card)
  1122. {
  1123. int rc;
  1124. struct IsdnCardState *cs = card->cs;
  1125. char tmp[64];
  1126. strcpy(tmp, Elsa_revision);
  1127. printk(KERN_INFO "HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp));
  1128. cs->hw.elsa.ctrl_reg = 0;
  1129. cs->hw.elsa.status = 0;
  1130. cs->hw.elsa.MFlag = 0;
  1131. cs->subtyp = 0;
  1132. if (cs->typ == ISDN_CTYPE_ELSA) {
  1133. rc = setup_elsa_isa(card);
  1134. if (!rc)
  1135. return (0);
  1136. } else if (cs->typ == ISDN_CTYPE_ELSA_PNP) {
  1137. rc = setup_elsa_isapnp(card);
  1138. if (!rc)
  1139. return (0);
  1140. } else if (cs->typ == ISDN_CTYPE_ELSA_PCMCIA)
  1141. setup_elsa_pcmcia(card);
  1142. else if (cs->typ == ISDN_CTYPE_ELSA_PCI) {
  1143. rc = setup_elsa_pci(card);
  1144. if (!rc)
  1145. return (0);
  1146. } else
  1147. return (0);
  1148. return setup_elsa_common(card);
  1149. }