elsa.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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. interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
  461. }
  462. static int
  463. check_arcofi(struct IsdnCardState *cs)
  464. {
  465. int arcofi_present = 0;
  466. char tmp[40];
  467. char *t;
  468. u_char *p;
  469. if (!cs->dc.isac.mon_tx)
  470. if (!(cs->dc.isac.mon_tx=kmalloc(MAX_MON_FRAME, GFP_ATOMIC))) {
  471. if (cs->debug & L1_DEB_WARN)
  472. debugl1(cs, "ISAC MON TX out of buffers!");
  473. return(0);
  474. }
  475. cs->dc.isac.arcofi_bc = 0;
  476. arcofi_fsm(cs, ARCOFI_START, &ARCOFI_VERSION);
  477. interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
  478. if (!test_and_clear_bit(FLG_ARCOFI_ERROR, &cs->HW_Flags)) {
  479. debugl1(cs, "Arcofi response received %d bytes", cs->dc.isac.mon_rxp);
  480. p = cs->dc.isac.mon_rx;
  481. t = tmp;
  482. t += sprintf(tmp, "Arcofi data");
  483. QuickHex(t, p, cs->dc.isac.mon_rxp);
  484. debugl1(cs, tmp);
  485. if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
  486. switch(cs->dc.isac.mon_rx[1]) {
  487. case 0x80:
  488. debugl1(cs, "Arcofi 2160 detected");
  489. arcofi_present = 1;
  490. break;
  491. case 0x82:
  492. debugl1(cs, "Arcofi 2165 detected");
  493. arcofi_present = 2;
  494. break;
  495. case 0x84:
  496. debugl1(cs, "Arcofi 2163 detected");
  497. arcofi_present = 3;
  498. break;
  499. default:
  500. debugl1(cs, "unknown Arcofi response");
  501. break;
  502. }
  503. } else
  504. debugl1(cs, "undefined Monitor response");
  505. cs->dc.isac.mon_rxp = 0;
  506. } else if (cs->dc.isac.mon_tx) {
  507. debugl1(cs, "Arcofi not detected");
  508. }
  509. if (arcofi_present) {
  510. if (cs->subtyp==ELSA_QS1000) {
  511. cs->subtyp = ELSA_QS3000;
  512. printk(KERN_INFO
  513. "Elsa: %s detected modem at 0x%lx\n",
  514. Elsa_Types[cs->subtyp],
  515. cs->hw.elsa.base+8);
  516. release_region(cs->hw.elsa.base, 8);
  517. if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
  518. printk(KERN_WARNING
  519. "HiSax: %s config port %lx-%lx already in use\n",
  520. Elsa_Types[cs->subtyp],
  521. cs->hw.elsa.base + 8,
  522. cs->hw.elsa.base + 16);
  523. }
  524. } else if (cs->subtyp==ELSA_PCC16) {
  525. cs->subtyp = ELSA_PCF;
  526. printk(KERN_INFO
  527. "Elsa: %s detected modem at 0x%lx\n",
  528. Elsa_Types[cs->subtyp],
  529. cs->hw.elsa.base+8);
  530. release_region(cs->hw.elsa.base, 8);
  531. if (!request_region(cs->hw.elsa.base, 16, "elsa isdn modem")) {
  532. printk(KERN_WARNING
  533. "HiSax: %s config port %lx-%lx already in use\n",
  534. Elsa_Types[cs->subtyp],
  535. cs->hw.elsa.base + 8,
  536. cs->hw.elsa.base + 16);
  537. }
  538. } else
  539. printk(KERN_INFO
  540. "Elsa: %s detected modem at 0x%lx\n",
  541. Elsa_Types[cs->subtyp],
  542. cs->hw.elsa.base+8);
  543. arcofi_fsm(cs, ARCOFI_START, &ARCOFI_XOP_0);
  544. interruptible_sleep_on(&cs->dc.isac.arcofi_wait);
  545. return(1);
  546. }
  547. return(0);
  548. }
  549. #endif /* ARCOFI_USE */
  550. static void
  551. elsa_led_handler(struct IsdnCardState *cs)
  552. {
  553. int blink = 0;
  554. if (cs->subtyp == ELSA_PCMCIA || cs->subtyp == ELSA_PCMCIA_IPAC)
  555. return;
  556. del_timer(&cs->hw.elsa.tl);
  557. if (cs->hw.elsa.status & ELSA_ASSIGN)
  558. cs->hw.elsa.ctrl_reg |= ELSA_STAT_LED;
  559. else if (cs->hw.elsa.status & ELSA_BAD_PWR)
  560. cs->hw.elsa.ctrl_reg &= ~ELSA_STAT_LED;
  561. else {
  562. cs->hw.elsa.ctrl_reg ^= ELSA_STAT_LED;
  563. blink = 250;
  564. }
  565. if (cs->hw.elsa.status & 0xf000)
  566. cs->hw.elsa.ctrl_reg |= ELSA_LINE_LED;
  567. else if (cs->hw.elsa.status & 0x0f00) {
  568. cs->hw.elsa.ctrl_reg ^= ELSA_LINE_LED;
  569. blink = 500;
  570. } else
  571. cs->hw.elsa.ctrl_reg &= ~ELSA_LINE_LED;
  572. if ((cs->subtyp == ELSA_QS1000PCI) ||
  573. (cs->subtyp == ELSA_QS3000PCI)) {
  574. u_char led = 0xff;
  575. if (cs->hw.elsa.ctrl_reg & ELSA_LINE_LED)
  576. led ^= ELSA_IPAC_LINE_LED;
  577. if (cs->hw.elsa.ctrl_reg & ELSA_STAT_LED)
  578. led ^= ELSA_IPAC_STAT_LED;
  579. writereg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ATX, led);
  580. } else
  581. byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
  582. if (blink) {
  583. init_timer(&cs->hw.elsa.tl);
  584. cs->hw.elsa.tl.expires = jiffies + ((blink * HZ) / 1000);
  585. add_timer(&cs->hw.elsa.tl);
  586. }
  587. }
  588. static int
  589. Elsa_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  590. {
  591. int ret = 0;
  592. u_long flags;
  593. switch (mt) {
  594. case CARD_RESET:
  595. spin_lock_irqsave(&cs->lock, flags);
  596. reset_elsa(cs);
  597. spin_unlock_irqrestore(&cs->lock, flags);
  598. return(0);
  599. case CARD_RELEASE:
  600. release_io_elsa(cs);
  601. return(0);
  602. case CARD_INIT:
  603. spin_lock_irqsave(&cs->lock, flags);
  604. cs->debug |= L1_DEB_IPAC;
  605. reset_elsa(cs);
  606. inithscxisac(cs, 1);
  607. if ((cs->subtyp == ELSA_QS1000) ||
  608. (cs->subtyp == ELSA_QS3000))
  609. {
  610. byteout(cs->hw.elsa.timer, 0);
  611. }
  612. if (cs->hw.elsa.trig)
  613. byteout(cs->hw.elsa.trig, 0xff);
  614. inithscxisac(cs, 2);
  615. spin_unlock_irqrestore(&cs->lock, flags);
  616. return(0);
  617. case CARD_TEST:
  618. if ((cs->subtyp == ELSA_PCMCIA) ||
  619. (cs->subtyp == ELSA_PCMCIA_IPAC) ||
  620. (cs->subtyp == ELSA_QS1000PCI)) {
  621. return(0);
  622. } else if (cs->subtyp == ELSA_QS3000PCI) {
  623. ret = 0;
  624. } else {
  625. spin_lock_irqsave(&cs->lock, flags);
  626. cs->hw.elsa.counter = 0;
  627. cs->hw.elsa.ctrl_reg |= ELSA_ENA_TIMER_INT;
  628. cs->hw.elsa.status |= ELIRQF_TIMER_AKTIV;
  629. byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
  630. byteout(cs->hw.elsa.timer, 0);
  631. spin_unlock_irqrestore(&cs->lock, flags);
  632. msleep(110);
  633. spin_lock_irqsave(&cs->lock, flags);
  634. cs->hw.elsa.ctrl_reg &= ~ELSA_ENA_TIMER_INT;
  635. byteout(cs->hw.elsa.ctrl, cs->hw.elsa.ctrl_reg);
  636. cs->hw.elsa.status &= ~ELIRQF_TIMER_AKTIV;
  637. spin_unlock_irqrestore(&cs->lock, flags);
  638. printk(KERN_INFO "Elsa: %d timer tics in 110 msek\n",
  639. cs->hw.elsa.counter);
  640. if ((cs->hw.elsa.counter > 10) &&
  641. (cs->hw.elsa.counter < 16)) {
  642. printk(KERN_INFO "Elsa: timer and irq OK\n");
  643. ret = 0;
  644. } else {
  645. printk(KERN_WARNING
  646. "Elsa: timer tic problem (%d/12) maybe an IRQ(%d) conflict\n",
  647. cs->hw.elsa.counter, cs->irq);
  648. ret = 1;
  649. }
  650. }
  651. #if ARCOFI_USE
  652. if (check_arcofi(cs)) {
  653. init_modem(cs);
  654. }
  655. #endif
  656. elsa_led_handler(cs);
  657. return(ret);
  658. case (MDL_REMOVE | REQUEST):
  659. cs->hw.elsa.status &= 0;
  660. break;
  661. case (MDL_ASSIGN | REQUEST):
  662. cs->hw.elsa.status |= ELSA_ASSIGN;
  663. break;
  664. case MDL_INFO_SETUP:
  665. if ((long) arg)
  666. cs->hw.elsa.status |= 0x0200;
  667. else
  668. cs->hw.elsa.status |= 0x0100;
  669. break;
  670. case MDL_INFO_CONN:
  671. if ((long) arg)
  672. cs->hw.elsa.status |= 0x2000;
  673. else
  674. cs->hw.elsa.status |= 0x1000;
  675. break;
  676. case MDL_INFO_REL:
  677. if ((long) arg) {
  678. cs->hw.elsa.status &= ~0x2000;
  679. cs->hw.elsa.status &= ~0x0200;
  680. } else {
  681. cs->hw.elsa.status &= ~0x1000;
  682. cs->hw.elsa.status &= ~0x0100;
  683. }
  684. break;
  685. #if ARCOFI_USE
  686. case CARD_AUX_IND:
  687. if (cs->hw.elsa.MFlag) {
  688. int len;
  689. u_char *msg;
  690. if (!arg)
  691. return(0);
  692. msg = arg;
  693. len = *msg;
  694. msg++;
  695. modem_write_cmd(cs, msg, len);
  696. }
  697. break;
  698. #endif
  699. }
  700. if (cs->typ == ISDN_CTYPE_ELSA) {
  701. int pwr = bytein(cs->hw.elsa.ale);
  702. if (pwr & 0x08)
  703. cs->hw.elsa.status |= ELSA_BAD_PWR;
  704. else
  705. cs->hw.elsa.status &= ~ELSA_BAD_PWR;
  706. }
  707. elsa_led_handler(cs);
  708. return(ret);
  709. }
  710. static unsigned char
  711. probe_elsa_adr(unsigned int adr, int typ)
  712. {
  713. int i, in1, in2, p16_1 = 0, p16_2 = 0, p8_1 = 0, p8_2 = 0, pc_1 = 0,
  714. pc_2 = 0, pfp_1 = 0, pfp_2 = 0;
  715. /* In case of the elsa pcmcia card, this region is in use,
  716. reserved for us by the card manager. So we do not check it
  717. here, it would fail. */
  718. if (typ != ISDN_CTYPE_ELSA_PCMCIA) {
  719. if (request_region(adr, 8, "elsa card")) {
  720. release_region(adr, 8);
  721. } else {
  722. printk(KERN_WARNING
  723. "Elsa: Probing Port 0x%x: already in use\n", adr);
  724. return (0);
  725. }
  726. }
  727. for (i = 0; i < 16; i++) {
  728. in1 = inb(adr + ELSA_CONFIG); /* 'toggelt' bei */
  729. in2 = inb(adr + ELSA_CONFIG); /* jedem Zugriff */
  730. p16_1 += 0x04 & in1;
  731. p16_2 += 0x04 & in2;
  732. p8_1 += 0x02 & in1;
  733. p8_2 += 0x02 & in2;
  734. pc_1 += 0x01 & in1;
  735. pc_2 += 0x01 & in2;
  736. pfp_1 += 0x40 & in1;
  737. pfp_2 += 0x40 & in2;
  738. }
  739. printk(KERN_INFO "Elsa: Probing IO 0x%x", adr);
  740. if (65 == ++p16_1 * ++p16_2) {
  741. printk(" PCC-16/PCF found\n");
  742. return (ELSA_PCC16);
  743. } else if (1025 == ++pfp_1 * ++pfp_2) {
  744. printk(" PCF-Pro found\n");
  745. return (ELSA_PCFPRO);
  746. } else if (33 == ++p8_1 * ++p8_2) {
  747. printk(" PCC8 found\n");
  748. return (ELSA_PCC8);
  749. } else if (17 == ++pc_1 * ++pc_2) {
  750. printk(" PC found\n");
  751. return (ELSA_PC);
  752. } else {
  753. printk(" failed\n");
  754. return (0);
  755. }
  756. }
  757. static unsigned int
  758. probe_elsa(struct IsdnCardState *cs)
  759. {
  760. int i;
  761. unsigned int CARD_portlist[] =
  762. {0x160, 0x170, 0x260, 0x360, 0};
  763. for (i = 0; CARD_portlist[i]; i++) {
  764. if ((cs->subtyp = probe_elsa_adr(CARD_portlist[i], cs->typ)))
  765. break;
  766. }
  767. return (CARD_portlist[i]);
  768. }
  769. static int __devinit
  770. setup_elsa_isa(struct IsdnCard *card)
  771. {
  772. struct IsdnCardState *cs = card->cs;
  773. u_char val;
  774. cs->hw.elsa.base = card->para[0];
  775. printk(KERN_INFO "Elsa: Microlink IO probing\n");
  776. if (cs->hw.elsa.base) {
  777. if (!(cs->subtyp = probe_elsa_adr(cs->hw.elsa.base,
  778. cs->typ))) {
  779. printk(KERN_WARNING
  780. "Elsa: no Elsa Microlink at %#lx\n",
  781. cs->hw.elsa.base);
  782. return (0);
  783. }
  784. } else
  785. cs->hw.elsa.base = probe_elsa(cs);
  786. if (!cs->hw.elsa.base) {
  787. printk(KERN_WARNING
  788. "No Elsa Microlink found\n");
  789. return (0);
  790. }
  791. cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
  792. cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
  793. cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
  794. cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
  795. cs->hw.elsa.itac = cs->hw.elsa.base + ELSA_ITAC;
  796. cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
  797. cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
  798. cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
  799. val = bytein(cs->hw.elsa.cfg);
  800. if (cs->subtyp == ELSA_PC) {
  801. const u_char CARD_IrqTab[8] =
  802. {7, 3, 5, 9, 0, 0, 0, 0};
  803. cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PC) >> 2];
  804. } else if (cs->subtyp == ELSA_PCC8) {
  805. const u_char CARD_IrqTab[8] =
  806. {7, 3, 5, 9, 0, 0, 0, 0};
  807. cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX_PCC8) >> 4];
  808. } else {
  809. const u_char CARD_IrqTab[8] =
  810. {15, 10, 15, 3, 11, 5, 11, 9};
  811. cs->irq = CARD_IrqTab[(val & ELSA_IRQ_IDX) >> 3];
  812. }
  813. val = bytein(cs->hw.elsa.ale) & ELSA_HW_RELEASE;
  814. if (val < 3)
  815. val |= 8;
  816. val += 'A' - 3;
  817. if (val == 'B' || val == 'C')
  818. val ^= 1;
  819. if ((cs->subtyp == ELSA_PCFPRO) && (val == 'G'))
  820. val = 'C';
  821. printk(KERN_INFO
  822. "Elsa: %s found at %#lx Rev.:%c IRQ %d\n",
  823. Elsa_Types[cs->subtyp],
  824. cs->hw.elsa.base,
  825. val, cs->irq);
  826. val = bytein(cs->hw.elsa.ale) & ELSA_S0_POWER_BAD;
  827. if (val) {
  828. printk(KERN_WARNING
  829. "Elsa: Microlink S0 bus power bad\n");
  830. cs->hw.elsa.status |= ELSA_BAD_PWR;
  831. }
  832. return (1);
  833. }
  834. #ifdef __ISAPNP__
  835. static struct isapnp_device_id elsa_ids[] __devinitdata = {
  836. { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
  837. ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0133),
  838. (unsigned long) "Elsa QS1000" },
  839. { ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
  840. ISAPNP_VENDOR('E', 'L', 'S'), ISAPNP_FUNCTION(0x0134),
  841. (unsigned long) "Elsa QS3000" },
  842. { 0, }
  843. };
  844. static struct isapnp_device_id *ipid __devinitdata = &elsa_ids[0];
  845. static struct pnp_card *pnp_c __devinitdata = NULL;
  846. #endif /* __ISAPNP__ */
  847. static int __devinit
  848. setup_elsa_isapnp(struct IsdnCard *card)
  849. {
  850. struct IsdnCardState *cs = card->cs;
  851. #ifdef __ISAPNP__
  852. if (!card->para[1] && isapnp_present()) {
  853. struct pnp_dev *pnp_d;
  854. while(ipid->card_vendor) {
  855. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  856. ipid->card_device, pnp_c))) {
  857. pnp_d = NULL;
  858. if ((pnp_d = pnp_find_dev(pnp_c,
  859. ipid->vendor, ipid->function, pnp_d))) {
  860. int err;
  861. printk(KERN_INFO "HiSax: %s detected\n",
  862. (char *)ipid->driver_data);
  863. pnp_disable_dev(pnp_d);
  864. err = pnp_activate_dev(pnp_d);
  865. if (err<0) {
  866. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  867. __func__, err);
  868. return(0);
  869. }
  870. card->para[1] = pnp_port_start(pnp_d, 0);
  871. card->para[0] = pnp_irq(pnp_d, 0);
  872. if (!card->para[0] || !card->para[1]) {
  873. printk(KERN_ERR "Elsa PnP:some resources are missing %ld/%lx\n",
  874. card->para[0], card->para[1]);
  875. pnp_disable_dev(pnp_d);
  876. return(0);
  877. }
  878. if (ipid->function == ISAPNP_FUNCTION(0x133))
  879. cs->subtyp = ELSA_QS1000;
  880. else
  881. cs->subtyp = ELSA_QS3000;
  882. break;
  883. } else {
  884. printk(KERN_ERR "Elsa PnP: PnP error card found, no device\n");
  885. return(0);
  886. }
  887. }
  888. ipid++;
  889. pnp_c=NULL;
  890. }
  891. if (!ipid->card_vendor) {
  892. printk(KERN_INFO "Elsa PnP: no ISAPnP card found\n");
  893. return(0);
  894. }
  895. }
  896. #endif /* __ISAPNP__ */
  897. if (card->para[1] && card->para[0]) {
  898. cs->hw.elsa.base = card->para[1];
  899. cs->irq = card->para[0];
  900. if (!cs->subtyp)
  901. cs->subtyp = ELSA_QS1000;
  902. } else {
  903. printk(KERN_ERR "Elsa PnP: no parameter\n");
  904. }
  905. cs->hw.elsa.cfg = cs->hw.elsa.base + ELSA_CONFIG;
  906. cs->hw.elsa.ale = cs->hw.elsa.base + ELSA_ALE;
  907. cs->hw.elsa.isac = cs->hw.elsa.base + ELSA_ISAC;
  908. cs->hw.elsa.hscx = cs->hw.elsa.base + ELSA_HSCX;
  909. cs->hw.elsa.trig = cs->hw.elsa.base + ELSA_TRIG_IRQ;
  910. cs->hw.elsa.timer = cs->hw.elsa.base + ELSA_START_TIMER;
  911. cs->hw.elsa.ctrl = cs->hw.elsa.base + ELSA_CONTROL;
  912. printk(KERN_INFO
  913. "Elsa: %s defined at %#lx IRQ %d\n",
  914. Elsa_Types[cs->subtyp],
  915. cs->hw.elsa.base,
  916. cs->irq);
  917. return (1);
  918. }
  919. static void __devinit
  920. 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 __devinitdata = NULL;
  951. static struct pci_dev *dev_qs3000 __devinitdata = NULL;
  952. static int __devinit
  953. setup_elsa_pci(struct IsdnCard *card)
  954. {
  955. struct IsdnCardState *cs = card->cs;
  956. cs->subtyp = 0;
  957. if ((dev_qs1000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA,
  958. PCI_DEVICE_ID_ELSA_MICROLINK, dev_qs1000))) {
  959. if (pci_enable_device(dev_qs1000))
  960. return(0);
  961. cs->subtyp = ELSA_QS1000PCI;
  962. cs->irq = dev_qs1000->irq;
  963. cs->hw.elsa.cfg = pci_resource_start(dev_qs1000, 1);
  964. cs->hw.elsa.base = pci_resource_start(dev_qs1000, 3);
  965. } else if ((dev_qs3000 = hisax_find_pci_device(PCI_VENDOR_ID_ELSA,
  966. PCI_DEVICE_ID_ELSA_QS3000, dev_qs3000))) {
  967. if (pci_enable_device(dev_qs3000))
  968. return(0);
  969. cs->subtyp = ELSA_QS3000PCI;
  970. cs->irq = dev_qs3000->irq;
  971. cs->hw.elsa.cfg = pci_resource_start(dev_qs3000, 1);
  972. cs->hw.elsa.base = pci_resource_start(dev_qs3000, 3);
  973. } else {
  974. printk(KERN_WARNING "Elsa: No PCI card found\n");
  975. return(0);
  976. }
  977. if (!cs->irq) {
  978. printk(KERN_WARNING "Elsa: No IRQ for PCI card found\n");
  979. return(0);
  980. }
  981. if (!(cs->hw.elsa.base && cs->hw.elsa.cfg)) {
  982. printk(KERN_WARNING "Elsa: No IO-Adr for PCI card found\n");
  983. return(0);
  984. }
  985. if ((cs->hw.elsa.cfg & 0xff) || (cs->hw.elsa.base & 0xf)) {
  986. printk(KERN_WARNING "Elsa: You may have a wrong PCI bios\n");
  987. printk(KERN_WARNING "Elsa: If your system hangs now, read\n");
  988. printk(KERN_WARNING "Elsa: Documentation/isdn/README.HiSax\n");
  989. }
  990. cs->hw.elsa.ale = cs->hw.elsa.base;
  991. cs->hw.elsa.isac = cs->hw.elsa.base +1;
  992. cs->hw.elsa.hscx = cs->hw.elsa.base +1;
  993. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  994. cs->hw.elsa.timer = 0;
  995. cs->hw.elsa.trig = 0;
  996. cs->irq_flags |= IRQF_SHARED;
  997. printk(KERN_INFO
  998. "Elsa: %s defined at %#lx/0x%x IRQ %d\n",
  999. Elsa_Types[cs->subtyp],
  1000. cs->hw.elsa.base,
  1001. cs->hw.elsa.cfg,
  1002. cs->irq);
  1003. return (1);
  1004. }
  1005. #else
  1006. static int __devinit
  1007. setup_elsa_pci(struct IsdnCard *card)
  1008. {
  1009. return (1);
  1010. }
  1011. #endif /* CONFIG_PCI */
  1012. static int __devinit
  1013. setup_elsa_common(struct IsdnCard *card)
  1014. {
  1015. struct IsdnCardState *cs = card->cs;
  1016. u_char val;
  1017. int bytecnt;
  1018. switch (cs->subtyp) {
  1019. case ELSA_PC:
  1020. case ELSA_PCC8:
  1021. case ELSA_PCC16:
  1022. case ELSA_QS1000:
  1023. case ELSA_PCMCIA:
  1024. case ELSA_PCMCIA_IPAC:
  1025. bytecnt = 8;
  1026. break;
  1027. case ELSA_PCFPRO:
  1028. case ELSA_PCF:
  1029. case ELSA_QS3000:
  1030. case ELSA_QS3000PCI:
  1031. bytecnt = 16;
  1032. break;
  1033. case ELSA_QS1000PCI:
  1034. bytecnt = 2;
  1035. break;
  1036. default:
  1037. printk(KERN_WARNING
  1038. "Unknown ELSA subtype %d\n", cs->subtyp);
  1039. return (0);
  1040. }
  1041. /* In case of the elsa pcmcia card, this region is in use,
  1042. reserved for us by the card manager. So we do not check it
  1043. here, it would fail. */
  1044. if (cs->typ != ISDN_CTYPE_ELSA_PCMCIA && !request_region(cs->hw.elsa.base, bytecnt, "elsa isdn")) {
  1045. printk(KERN_WARNING
  1046. "HiSax: ELSA config port %#lx-%#lx already in use\n",
  1047. cs->hw.elsa.base,
  1048. cs->hw.elsa.base + bytecnt);
  1049. return (0);
  1050. }
  1051. if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI)) {
  1052. if (!request_region(cs->hw.elsa.cfg, 0x80, "elsa isdn pci")) {
  1053. printk(KERN_WARNING
  1054. "HiSax: ELSA pci port %x-%x already in use\n",
  1055. cs->hw.elsa.cfg,
  1056. cs->hw.elsa.cfg + 0x80);
  1057. release_region(cs->hw.elsa.base, bytecnt);
  1058. return (0);
  1059. }
  1060. }
  1061. #if ARCOFI_USE
  1062. init_arcofi(cs);
  1063. #endif
  1064. setup_isac(cs);
  1065. cs->hw.elsa.tl.function = (void *) elsa_led_handler;
  1066. cs->hw.elsa.tl.data = (long) cs;
  1067. init_timer(&cs->hw.elsa.tl);
  1068. /* Teste Timer */
  1069. if (cs->hw.elsa.timer) {
  1070. byteout(cs->hw.elsa.trig, 0xff);
  1071. byteout(cs->hw.elsa.timer, 0);
  1072. if (!TimerRun(cs)) {
  1073. byteout(cs->hw.elsa.timer, 0); /* 2. Versuch */
  1074. if (!TimerRun(cs)) {
  1075. printk(KERN_WARNING
  1076. "Elsa: timer do not start\n");
  1077. release_io_elsa(cs);
  1078. return (0);
  1079. }
  1080. }
  1081. HZDELAY((HZ/100) + 1); /* wait >=10 ms */
  1082. if (TimerRun(cs)) {
  1083. printk(KERN_WARNING "Elsa: timer do not run down\n");
  1084. release_io_elsa(cs);
  1085. return (0);
  1086. }
  1087. printk(KERN_INFO "Elsa: timer OK; resetting card\n");
  1088. }
  1089. cs->BC_Read_Reg = &ReadHSCX;
  1090. cs->BC_Write_Reg = &WriteHSCX;
  1091. cs->BC_Send_Data = &hscx_fill_fifo;
  1092. cs->cardmsg = &Elsa_card_msg;
  1093. if ((cs->subtyp == ELSA_QS1000PCI) || (cs->subtyp == ELSA_QS3000PCI) || (cs->subtyp == ELSA_PCMCIA_IPAC)) {
  1094. cs->readisac = &ReadISAC_IPAC;
  1095. cs->writeisac = &WriteISAC_IPAC;
  1096. cs->readisacfifo = &ReadISACfifo_IPAC;
  1097. cs->writeisacfifo = &WriteISACfifo_IPAC;
  1098. cs->irq_func = &elsa_interrupt_ipac;
  1099. val = readreg(cs->hw.elsa.ale, cs->hw.elsa.isac, IPAC_ID);
  1100. printk(KERN_INFO "Elsa: IPAC version %x\n", val);
  1101. } else {
  1102. cs->readisac = &ReadISAC;
  1103. cs->writeisac = &WriteISAC;
  1104. cs->readisacfifo = &ReadISACfifo;
  1105. cs->writeisacfifo = &WriteISACfifo;
  1106. cs->irq_func = &elsa_interrupt;
  1107. ISACVersion(cs, "Elsa:");
  1108. if (HscxVersion(cs, "Elsa:")) {
  1109. printk(KERN_WARNING
  1110. "Elsa: wrong HSCX versions check IO address\n");
  1111. release_io_elsa(cs);
  1112. return (0);
  1113. }
  1114. }
  1115. if (cs->subtyp == ELSA_PC) {
  1116. val = readitac(cs, ITAC_SYS);
  1117. printk(KERN_INFO "Elsa: ITAC version %s\n", ITACVer[val & 7]);
  1118. writeitac(cs, ITAC_ISEN, 0);
  1119. writeitac(cs, ITAC_RFIE, 0);
  1120. writeitac(cs, ITAC_XFIE, 0);
  1121. writeitac(cs, ITAC_SCIE, 0);
  1122. writeitac(cs, ITAC_STIE, 0);
  1123. }
  1124. return (1);
  1125. }
  1126. int __devinit
  1127. setup_elsa(struct IsdnCard *card)
  1128. {
  1129. int rc;
  1130. struct IsdnCardState *cs = card->cs;
  1131. char tmp[64];
  1132. strcpy(tmp, Elsa_revision);
  1133. printk(KERN_INFO "HiSax: Elsa driver Rev. %s\n", HiSax_getrev(tmp));
  1134. cs->hw.elsa.ctrl_reg = 0;
  1135. cs->hw.elsa.status = 0;
  1136. cs->hw.elsa.MFlag = 0;
  1137. cs->subtyp = 0;
  1138. if (cs->typ == ISDN_CTYPE_ELSA) {
  1139. rc = setup_elsa_isa(card);
  1140. if (!rc)
  1141. return (0);
  1142. } else if (cs->typ == ISDN_CTYPE_ELSA_PNP) {
  1143. rc = setup_elsa_isapnp(card);
  1144. if (!rc)
  1145. return (0);
  1146. } else if (cs->typ == ISDN_CTYPE_ELSA_PCMCIA)
  1147. setup_elsa_pcmcia(card);
  1148. else if (cs->typ == ISDN_CTYPE_ELSA_PCI) {
  1149. rc = setup_elsa_pci(card);
  1150. if (!rc)
  1151. return (0);
  1152. } else
  1153. return (0);
  1154. return setup_elsa_common(card);
  1155. }