elsa.c 34 KB

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