sedlbauer.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. /* $Id: sedlbauer.c,v 1.34.2.6 2004/01/24 20:47:24 keil Exp $
  2. *
  3. * low level stuff for Sedlbauer cards
  4. * includes support for the Sedlbauer speed star (speed star II),
  5. * support for the Sedlbauer speed fax+,
  6. * support for the Sedlbauer ISDN-Controller PC/104 and
  7. * support for the Sedlbauer speed pci
  8. * derived from the original file asuscom.c from Karsten Keil
  9. *
  10. * Author Marcus Niemann
  11. * Copyright by Marcus Niemann <niemann@www-bib.fh-bielefeld.de>
  12. *
  13. * This software may be used and distributed according to the terms
  14. * of the GNU General Public License, incorporated herein by reference.
  15. *
  16. * Thanks to Karsten Keil
  17. * Sedlbauer AG for informations
  18. * Edgar Toernig
  19. *
  20. */
  21. /* Supported cards:
  22. * Card: Chip: Configuration: Comment:
  23. * ---------------------------------------------------------------------
  24. * Speed Card ISAC_HSCX DIP-SWITCH
  25. * Speed Win ISAC_HSCX ISAPNP
  26. * Speed Fax+ ISAC_ISAR ISAPNP Full analog support
  27. * Speed Star ISAC_HSCX CARDMGR
  28. * Speed Win2 IPAC ISAPNP
  29. * ISDN PC/104 IPAC DIP-SWITCH
  30. * Speed Star2 IPAC CARDMGR
  31. * Speed PCI IPAC PCI PNP
  32. * Speed Fax+ ISAC_ISAR PCI PNP Full analog support
  33. *
  34. * Important:
  35. * For the sedlbauer speed fax+ to work properly you have to download
  36. * the firmware onto the card.
  37. * For example: hisaxctrl <DriverID> 9 ISAR.BIN
  38. */
  39. #include <linux/init.h>
  40. #include "hisax.h"
  41. #include "isac.h"
  42. #include "ipac.h"
  43. #include "hscx.h"
  44. #include "isar.h"
  45. #include "isdnl1.h"
  46. #include <linux/pci.h>
  47. #include <linux/isapnp.h>
  48. static const char *Sedlbauer_revision = "$Revision: 1.34.2.6 $";
  49. static const char *Sedlbauer_Types[] =
  50. {"None", "speed card/win", "speed star", "speed fax+",
  51. "speed win II / ISDN PC/104", "speed star II", "speed pci",
  52. "speed fax+ pyramid", "speed fax+ pci", "HST Saphir III"};
  53. #define PCI_SUBVENDOR_SPEEDFAX_PYRAMID 0x51
  54. #define PCI_SUBVENDOR_HST_SAPHIR3 0x52
  55. #define PCI_SUBVENDOR_SEDLBAUER_PCI 0x53
  56. #define PCI_SUBVENDOR_SPEEDFAX_PCI 0x54
  57. #define PCI_SUB_ID_SEDLBAUER 0x01
  58. #define SEDL_SPEED_CARD_WIN 1
  59. #define SEDL_SPEED_STAR 2
  60. #define SEDL_SPEED_FAX 3
  61. #define SEDL_SPEED_WIN2_PC104 4
  62. #define SEDL_SPEED_STAR2 5
  63. #define SEDL_SPEED_PCI 6
  64. #define SEDL_SPEEDFAX_PYRAMID 7
  65. #define SEDL_SPEEDFAX_PCI 8
  66. #define HST_SAPHIR3 9
  67. #define SEDL_CHIP_TEST 0
  68. #define SEDL_CHIP_ISAC_HSCX 1
  69. #define SEDL_CHIP_ISAC_ISAR 2
  70. #define SEDL_CHIP_IPAC 3
  71. #define SEDL_BUS_ISA 1
  72. #define SEDL_BUS_PCI 2
  73. #define SEDL_BUS_PCMCIA 3
  74. #define byteout(addr, val) outb(val, addr)
  75. #define bytein(addr) inb(addr)
  76. #define SEDL_HSCX_ISA_RESET_ON 0
  77. #define SEDL_HSCX_ISA_RESET_OFF 1
  78. #define SEDL_HSCX_ISA_ISAC 2
  79. #define SEDL_HSCX_ISA_HSCX 3
  80. #define SEDL_HSCX_ISA_ADR 4
  81. #define SEDL_HSCX_PCMCIA_RESET 0
  82. #define SEDL_HSCX_PCMCIA_ISAC 1
  83. #define SEDL_HSCX_PCMCIA_HSCX 2
  84. #define SEDL_HSCX_PCMCIA_ADR 4
  85. #define SEDL_ISAR_ISA_ISAC 4
  86. #define SEDL_ISAR_ISA_ISAR 6
  87. #define SEDL_ISAR_ISA_ADR 8
  88. #define SEDL_ISAR_ISA_ISAR_RESET_ON 10
  89. #define SEDL_ISAR_ISA_ISAR_RESET_OFF 12
  90. #define SEDL_IPAC_ANY_ADR 0
  91. #define SEDL_IPAC_ANY_IPAC 2
  92. #define SEDL_IPAC_PCI_BASE 0
  93. #define SEDL_IPAC_PCI_ADR 0xc0
  94. #define SEDL_IPAC_PCI_IPAC 0xc8
  95. #define SEDL_ISAR_PCI_ADR 0xc8
  96. #define SEDL_ISAR_PCI_ISAC 0xd0
  97. #define SEDL_ISAR_PCI_ISAR 0xe0
  98. #define SEDL_ISAR_PCI_ISAR_RESET_ON 0x01
  99. #define SEDL_ISAR_PCI_ISAR_RESET_OFF 0x18
  100. #define SEDL_ISAR_PCI_LED1 0x08
  101. #define SEDL_ISAR_PCI_LED2 0x10
  102. #define SEDL_RESET 0x3 /* same as DOS driver */
  103. static inline u_char
  104. readreg(unsigned int ale, unsigned int adr, u_char off)
  105. {
  106. register u_char ret;
  107. byteout(ale, off);
  108. ret = bytein(adr);
  109. return (ret);
  110. }
  111. static inline void
  112. readfifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
  113. {
  114. byteout(ale, off);
  115. insb(adr, data, size);
  116. }
  117. static inline void
  118. writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
  119. {
  120. byteout(ale, off);
  121. byteout(adr, data);
  122. }
  123. static inline void
  124. writefifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
  125. {
  126. byteout(ale, off);
  127. outsb(adr, data, size);
  128. }
  129. /* Interface functions */
  130. static u_char
  131. ReadISAC(struct IsdnCardState *cs, u_char offset)
  132. {
  133. return (readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, offset));
  134. }
  135. static void
  136. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  137. {
  138. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, offset, value);
  139. }
  140. static void
  141. ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  142. {
  143. readfifo(cs->hw.sedl.adr, cs->hw.sedl.isac, 0, data, size);
  144. }
  145. static void
  146. WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  147. {
  148. writefifo(cs->hw.sedl.adr, cs->hw.sedl.isac, 0, data, size);
  149. }
  150. static u_char
  151. ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
  152. {
  153. return (readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, offset | 0x80));
  154. }
  155. static void
  156. WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
  157. {
  158. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, offset | 0x80, value);
  159. }
  160. static void
  161. ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char *data, int size)
  162. {
  163. readfifo(cs->hw.sedl.adr, cs->hw.sedl.isac, 0x80, data, size);
  164. }
  165. static void
  166. WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char *data, int size)
  167. {
  168. writefifo(cs->hw.sedl.adr, cs->hw.sedl.isac, 0x80, data, size);
  169. }
  170. static u_char
  171. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  172. {
  173. return (readreg(cs->hw.sedl.adr,
  174. cs->hw.sedl.hscx, offset + (hscx ? 0x40 : 0)));
  175. }
  176. static void
  177. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  178. {
  179. writereg(cs->hw.sedl.adr,
  180. cs->hw.sedl.hscx, offset + (hscx ? 0x40 : 0), value);
  181. }
  182. /* ISAR access routines
  183. * mode = 0 access with IRQ on
  184. * mode = 1 access with IRQ off
  185. * mode = 2 access with IRQ off and using last offset
  186. */
  187. static u_char
  188. ReadISAR(struct IsdnCardState *cs, int mode, u_char offset)
  189. {
  190. if (mode == 0)
  191. return (readreg(cs->hw.sedl.adr, cs->hw.sedl.hscx, offset));
  192. else if (mode == 1)
  193. byteout(cs->hw.sedl.adr, offset);
  194. return (bytein(cs->hw.sedl.hscx));
  195. }
  196. static void
  197. WriteISAR(struct IsdnCardState *cs, int mode, u_char offset, u_char value)
  198. {
  199. if (mode == 0)
  200. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx, offset, value);
  201. else {
  202. if (mode == 1)
  203. byteout(cs->hw.sedl.adr, offset);
  204. byteout(cs->hw.sedl.hscx, value);
  205. }
  206. }
  207. /*
  208. * fast interrupt HSCX stuff goes here
  209. */
  210. #define READHSCX(cs, nr, reg) readreg(cs->hw.sedl.adr, \
  211. cs->hw.sedl.hscx, reg + (nr ? 0x40 : 0))
  212. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.sedl.adr, \
  213. cs->hw.sedl.hscx, reg + (nr ? 0x40 : 0), data)
  214. #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.sedl.adr, \
  215. cs->hw.sedl.hscx, (nr ? 0x40 : 0), ptr, cnt)
  216. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.sedl.adr, \
  217. cs->hw.sedl.hscx, (nr ? 0x40 : 0), ptr, cnt)
  218. #include "hscx_irq.c"
  219. static irqreturn_t
  220. sedlbauer_interrupt(int intno, void *dev_id)
  221. {
  222. struct IsdnCardState *cs = dev_id;
  223. u_char val;
  224. u_long flags;
  225. spin_lock_irqsave(&cs->lock, flags);
  226. if ((cs->hw.sedl.bus == SEDL_BUS_PCMCIA) && (*cs->busy_flag == 1)) {
  227. /* The card tends to generate interrupts while being removed
  228. causing us to just crash the kernel. bad. */
  229. spin_unlock_irqrestore(&cs->lock, flags);
  230. printk(KERN_WARNING "Sedlbauer: card not available!\n");
  231. return IRQ_NONE;
  232. }
  233. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.hscx, HSCX_ISTA + 0x40);
  234. Start_HSCX:
  235. if (val)
  236. hscx_int_main(cs, val);
  237. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_ISTA);
  238. Start_ISAC:
  239. if (val)
  240. isac_interrupt(cs, val);
  241. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.hscx, HSCX_ISTA + 0x40);
  242. if (val) {
  243. if (cs->debug & L1_DEB_HSCX)
  244. debugl1(cs, "HSCX IntStat after IntRoutine");
  245. goto Start_HSCX;
  246. }
  247. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_ISTA);
  248. if (val) {
  249. if (cs->debug & L1_DEB_ISAC)
  250. debugl1(cs, "ISAC IntStat after IntRoutine");
  251. goto Start_ISAC;
  252. }
  253. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx, HSCX_MASK, 0xFF);
  254. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx, HSCX_MASK + 0x40, 0xFF);
  255. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_MASK, 0xFF);
  256. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_MASK, 0x0);
  257. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx, HSCX_MASK, 0x0);
  258. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx, HSCX_MASK + 0x40, 0x0);
  259. spin_unlock_irqrestore(&cs->lock, flags);
  260. return IRQ_HANDLED;
  261. }
  262. static irqreturn_t
  263. sedlbauer_interrupt_ipac(int intno, void *dev_id)
  264. {
  265. struct IsdnCardState *cs = dev_id;
  266. u_char ista, val, icnt = 5;
  267. u_long flags;
  268. spin_lock_irqsave(&cs->lock, flags);
  269. ista = readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_ISTA);
  270. Start_IPAC:
  271. if (cs->debug & L1_DEB_IPAC)
  272. debugl1(cs, "IPAC ISTA %02X", ista);
  273. if (ista & 0x0f) {
  274. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.hscx, HSCX_ISTA + 0x40);
  275. if (ista & 0x01)
  276. val |= 0x01;
  277. if (ista & 0x04)
  278. val |= 0x02;
  279. if (ista & 0x08)
  280. val |= 0x04;
  281. if (val)
  282. hscx_int_main(cs, val);
  283. }
  284. if (ista & 0x20) {
  285. val = 0xfe & readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_ISTA | 0x80);
  286. if (val) {
  287. isac_interrupt(cs, val);
  288. }
  289. }
  290. if (ista & 0x10) {
  291. val = 0x01;
  292. isac_interrupt(cs, val);
  293. }
  294. ista = readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_ISTA);
  295. if ((ista & 0x3f) && icnt) {
  296. icnt--;
  297. goto Start_IPAC;
  298. }
  299. if (!icnt)
  300. if (cs->debug & L1_DEB_ISAC)
  301. debugl1(cs, "Sedlbauer IRQ LOOP");
  302. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_MASK, 0xFF);
  303. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_MASK, 0xC0);
  304. spin_unlock_irqrestore(&cs->lock, flags);
  305. return IRQ_HANDLED;
  306. }
  307. static irqreturn_t
  308. sedlbauer_interrupt_isar(int intno, void *dev_id)
  309. {
  310. struct IsdnCardState *cs = dev_id;
  311. u_char val;
  312. int cnt = 5;
  313. u_long flags;
  314. spin_lock_irqsave(&cs->lock, flags);
  315. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.hscx, ISAR_IRQBIT);
  316. Start_ISAR:
  317. if (val & ISAR_IRQSTA)
  318. isar_int_main(cs);
  319. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_ISTA);
  320. Start_ISAC:
  321. if (val)
  322. isac_interrupt(cs, val);
  323. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.hscx, ISAR_IRQBIT);
  324. if ((val & ISAR_IRQSTA) && --cnt) {
  325. if (cs->debug & L1_DEB_HSCX)
  326. debugl1(cs, "ISAR IntStat after IntRoutine");
  327. goto Start_ISAR;
  328. }
  329. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_ISTA);
  330. if (val && --cnt) {
  331. if (cs->debug & L1_DEB_ISAC)
  332. debugl1(cs, "ISAC IntStat after IntRoutine");
  333. goto Start_ISAC;
  334. }
  335. if (!cnt)
  336. if (cs->debug & L1_DEB_ISAC)
  337. debugl1(cs, "Sedlbauer IRQ LOOP");
  338. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx, ISAR_IRQBIT, 0);
  339. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_MASK, 0xFF);
  340. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, ISAC_MASK, 0x0);
  341. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx, ISAR_IRQBIT, ISAR_IRQMSK);
  342. spin_unlock_irqrestore(&cs->lock, flags);
  343. return IRQ_HANDLED;
  344. }
  345. static void
  346. release_io_sedlbauer(struct IsdnCardState *cs)
  347. {
  348. int bytecnt = 8;
  349. if (cs->subtyp == SEDL_SPEED_FAX) {
  350. bytecnt = 16;
  351. } else if (cs->hw.sedl.bus == SEDL_BUS_PCI) {
  352. bytecnt = 256;
  353. }
  354. if (cs->hw.sedl.cfg_reg)
  355. release_region(cs->hw.sedl.cfg_reg, bytecnt);
  356. }
  357. static void
  358. reset_sedlbauer(struct IsdnCardState *cs)
  359. {
  360. printk(KERN_INFO "Sedlbauer: resetting card\n");
  361. if (!((cs->hw.sedl.bus == SEDL_BUS_PCMCIA) &&
  362. (cs->hw.sedl.chip == SEDL_CHIP_ISAC_HSCX))) {
  363. if (cs->hw.sedl.chip == SEDL_CHIP_IPAC) {
  364. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_POTA2, 0x20);
  365. mdelay(2);
  366. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_POTA2, 0x0);
  367. mdelay(10);
  368. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_CONF, 0x0);
  369. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_ACFG, 0xff);
  370. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_AOE, 0x0);
  371. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_MASK, 0xc0);
  372. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_PCFG, 0x12);
  373. } else if ((cs->hw.sedl.chip == SEDL_CHIP_ISAC_ISAR) &&
  374. (cs->hw.sedl.bus == SEDL_BUS_PCI)) {
  375. byteout(cs->hw.sedl.cfg_reg + 3, cs->hw.sedl.reset_on);
  376. mdelay(2);
  377. byteout(cs->hw.sedl.cfg_reg + 3, cs->hw.sedl.reset_off);
  378. mdelay(10);
  379. } else {
  380. byteout(cs->hw.sedl.reset_on, SEDL_RESET); /* Reset On */
  381. mdelay(2);
  382. byteout(cs->hw.sedl.reset_off, 0); /* Reset Off */
  383. mdelay(10);
  384. }
  385. }
  386. }
  387. static int
  388. Sedl_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  389. {
  390. u_long flags;
  391. switch (mt) {
  392. case CARD_RESET:
  393. spin_lock_irqsave(&cs->lock, flags);
  394. reset_sedlbauer(cs);
  395. spin_unlock_irqrestore(&cs->lock, flags);
  396. return (0);
  397. case CARD_RELEASE:
  398. if (cs->hw.sedl.bus == SEDL_BUS_PCI)
  399. /* disable all IRQ */
  400. byteout(cs->hw.sedl.cfg_reg + 5, 0);
  401. if (cs->hw.sedl.chip == SEDL_CHIP_ISAC_ISAR) {
  402. spin_lock_irqsave(&cs->lock, flags);
  403. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx,
  404. ISAR_IRQBIT, 0);
  405. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac,
  406. ISAC_MASK, 0xFF);
  407. reset_sedlbauer(cs);
  408. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx,
  409. ISAR_IRQBIT, 0);
  410. writereg(cs->hw.sedl.adr, cs->hw.sedl.isac,
  411. ISAC_MASK, 0xFF);
  412. spin_unlock_irqrestore(&cs->lock, flags);
  413. }
  414. release_io_sedlbauer(cs);
  415. return (0);
  416. case CARD_INIT:
  417. spin_lock_irqsave(&cs->lock, flags);
  418. if (cs->hw.sedl.bus == SEDL_BUS_PCI)
  419. /* enable all IRQ */
  420. byteout(cs->hw.sedl.cfg_reg + 5, 0x02);
  421. reset_sedlbauer(cs);
  422. if (cs->hw.sedl.chip == SEDL_CHIP_ISAC_ISAR) {
  423. clear_pending_isac_ints(cs);
  424. writereg(cs->hw.sedl.adr, cs->hw.sedl.hscx,
  425. ISAR_IRQBIT, 0);
  426. initisac(cs);
  427. initisar(cs);
  428. /* Reenable all IRQ */
  429. cs->writeisac(cs, ISAC_MASK, 0);
  430. /* RESET Receiver and Transmitter */
  431. cs->writeisac(cs, ISAC_CMDR, 0x41);
  432. } else {
  433. inithscxisac(cs, 3);
  434. }
  435. spin_unlock_irqrestore(&cs->lock, flags);
  436. return (0);
  437. case CARD_TEST:
  438. return (0);
  439. case MDL_INFO_CONN:
  440. if (cs->subtyp != SEDL_SPEEDFAX_PYRAMID)
  441. return (0);
  442. spin_lock_irqsave(&cs->lock, flags);
  443. if ((long) arg)
  444. cs->hw.sedl.reset_off &= ~SEDL_ISAR_PCI_LED2;
  445. else
  446. cs->hw.sedl.reset_off &= ~SEDL_ISAR_PCI_LED1;
  447. byteout(cs->hw.sedl.cfg_reg + 3, cs->hw.sedl.reset_off);
  448. spin_unlock_irqrestore(&cs->lock, flags);
  449. break;
  450. case MDL_INFO_REL:
  451. if (cs->subtyp != SEDL_SPEEDFAX_PYRAMID)
  452. return (0);
  453. spin_lock_irqsave(&cs->lock, flags);
  454. if ((long) arg)
  455. cs->hw.sedl.reset_off |= SEDL_ISAR_PCI_LED2;
  456. else
  457. cs->hw.sedl.reset_off |= SEDL_ISAR_PCI_LED1;
  458. byteout(cs->hw.sedl.cfg_reg + 3, cs->hw.sedl.reset_off);
  459. spin_unlock_irqrestore(&cs->lock, flags);
  460. break;
  461. }
  462. return (0);
  463. }
  464. #ifdef __ISAPNP__
  465. static struct isapnp_device_id sedl_ids[] = {
  466. { ISAPNP_VENDOR('S', 'A', 'G'), ISAPNP_FUNCTION(0x01),
  467. ISAPNP_VENDOR('S', 'A', 'G'), ISAPNP_FUNCTION(0x01),
  468. (unsigned long) "Speed win" },
  469. { ISAPNP_VENDOR('S', 'A', 'G'), ISAPNP_FUNCTION(0x02),
  470. ISAPNP_VENDOR('S', 'A', 'G'), ISAPNP_FUNCTION(0x02),
  471. (unsigned long) "Speed Fax+" },
  472. { 0, }
  473. };
  474. static struct isapnp_device_id *ipid = &sedl_ids[0];
  475. static struct pnp_card *pnp_c = NULL;
  476. static int setup_sedlbauer_isapnp(struct IsdnCard *card, int *bytecnt)
  477. {
  478. struct IsdnCardState *cs = card->cs;
  479. struct pnp_dev *pnp_d;
  480. if (!isapnp_present())
  481. return -1;
  482. while (ipid->card_vendor) {
  483. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  484. ipid->card_device, pnp_c))) {
  485. pnp_d = NULL;
  486. if ((pnp_d = pnp_find_dev(pnp_c,
  487. ipid->vendor, ipid->function, pnp_d))) {
  488. int err;
  489. printk(KERN_INFO "HiSax: %s detected\n",
  490. (char *)ipid->driver_data);
  491. pnp_disable_dev(pnp_d);
  492. err = pnp_activate_dev(pnp_d);
  493. if (err < 0) {
  494. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  495. __func__, err);
  496. return (0);
  497. }
  498. card->para[1] = pnp_port_start(pnp_d, 0);
  499. card->para[0] = pnp_irq(pnp_d, 0);
  500. if (!card->para[0] || !card->para[1]) {
  501. printk(KERN_ERR "Sedlbauer PnP:some resources are missing %ld/%lx\n",
  502. card->para[0], card->para[1]);
  503. pnp_disable_dev(pnp_d);
  504. return (0);
  505. }
  506. cs->hw.sedl.cfg_reg = card->para[1];
  507. cs->irq = card->para[0];
  508. if (ipid->function == ISAPNP_FUNCTION(0x2)) {
  509. cs->subtyp = SEDL_SPEED_FAX;
  510. cs->hw.sedl.chip = SEDL_CHIP_ISAC_ISAR;
  511. *bytecnt = 16;
  512. } else {
  513. cs->subtyp = SEDL_SPEED_CARD_WIN;
  514. cs->hw.sedl.chip = SEDL_CHIP_TEST;
  515. }
  516. return (1);
  517. } else {
  518. printk(KERN_ERR "Sedlbauer PnP: PnP error card found, no device\n");
  519. return (0);
  520. }
  521. }
  522. ipid++;
  523. pnp_c = NULL;
  524. }
  525. printk(KERN_INFO "Sedlbauer PnP: no ISAPnP card found\n");
  526. return -1;
  527. }
  528. #else
  529. static int setup_sedlbauer_isapnp(struct IsdnCard *card, int *bytecnt)
  530. {
  531. return -1;
  532. }
  533. #endif /* __ISAPNP__ */
  534. #ifdef CONFIG_PCI
  535. static struct pci_dev *dev_sedl = NULL;
  536. static int setup_sedlbauer_pci(struct IsdnCard *card)
  537. {
  538. struct IsdnCardState *cs = card->cs;
  539. u16 sub_vendor_id, sub_id;
  540. if ((dev_sedl = hisax_find_pci_device(PCI_VENDOR_ID_TIGERJET,
  541. PCI_DEVICE_ID_TIGERJET_100, dev_sedl))) {
  542. if (pci_enable_device(dev_sedl))
  543. return (0);
  544. cs->irq = dev_sedl->irq;
  545. if (!cs->irq) {
  546. printk(KERN_WARNING "Sedlbauer: No IRQ for PCI card found\n");
  547. return (0);
  548. }
  549. cs->hw.sedl.cfg_reg = pci_resource_start(dev_sedl, 0);
  550. } else {
  551. printk(KERN_WARNING "Sedlbauer: No PCI card found\n");
  552. return (0);
  553. }
  554. cs->irq_flags |= IRQF_SHARED;
  555. cs->hw.sedl.bus = SEDL_BUS_PCI;
  556. sub_vendor_id = dev_sedl->subsystem_vendor;
  557. sub_id = dev_sedl->subsystem_device;
  558. printk(KERN_INFO "Sedlbauer: PCI subvendor:%x subid %x\n",
  559. sub_vendor_id, sub_id);
  560. printk(KERN_INFO "Sedlbauer: PCI base adr %#x\n",
  561. cs->hw.sedl.cfg_reg);
  562. if (sub_id != PCI_SUB_ID_SEDLBAUER) {
  563. printk(KERN_ERR "Sedlbauer: unknown sub id %#x\n", sub_id);
  564. return (0);
  565. }
  566. if (sub_vendor_id == PCI_SUBVENDOR_SPEEDFAX_PYRAMID) {
  567. cs->hw.sedl.chip = SEDL_CHIP_ISAC_ISAR;
  568. cs->subtyp = SEDL_SPEEDFAX_PYRAMID;
  569. } else if (sub_vendor_id == PCI_SUBVENDOR_SPEEDFAX_PCI) {
  570. cs->hw.sedl.chip = SEDL_CHIP_ISAC_ISAR;
  571. cs->subtyp = SEDL_SPEEDFAX_PCI;
  572. } else if (sub_vendor_id == PCI_SUBVENDOR_HST_SAPHIR3) {
  573. cs->hw.sedl.chip = SEDL_CHIP_IPAC;
  574. cs->subtyp = HST_SAPHIR3;
  575. } else if (sub_vendor_id == PCI_SUBVENDOR_SEDLBAUER_PCI) {
  576. cs->hw.sedl.chip = SEDL_CHIP_IPAC;
  577. cs->subtyp = SEDL_SPEED_PCI;
  578. } else {
  579. printk(KERN_ERR "Sedlbauer: unknown sub vendor id %#x\n",
  580. sub_vendor_id);
  581. return (0);
  582. }
  583. cs->hw.sedl.reset_on = SEDL_ISAR_PCI_ISAR_RESET_ON;
  584. cs->hw.sedl.reset_off = SEDL_ISAR_PCI_ISAR_RESET_OFF;
  585. byteout(cs->hw.sedl.cfg_reg, 0xff);
  586. byteout(cs->hw.sedl.cfg_reg, 0x00);
  587. byteout(cs->hw.sedl.cfg_reg + 2, 0xdd);
  588. byteout(cs->hw.sedl.cfg_reg + 5, 0); /* disable all IRQ */
  589. byteout(cs->hw.sedl.cfg_reg + 3, cs->hw.sedl.reset_on);
  590. mdelay(2);
  591. byteout(cs->hw.sedl.cfg_reg + 3, cs->hw.sedl.reset_off);
  592. mdelay(10);
  593. return (1);
  594. }
  595. #else
  596. static int setup_sedlbauer_pci(struct IsdnCard *card)
  597. {
  598. return (1);
  599. }
  600. #endif /* CONFIG_PCI */
  601. int setup_sedlbauer(struct IsdnCard *card)
  602. {
  603. int bytecnt = 8, ver, val, rc;
  604. struct IsdnCardState *cs = card->cs;
  605. char tmp[64];
  606. strcpy(tmp, Sedlbauer_revision);
  607. printk(KERN_INFO "HiSax: Sedlbauer driver Rev. %s\n", HiSax_getrev(tmp));
  608. if (cs->typ == ISDN_CTYPE_SEDLBAUER) {
  609. cs->subtyp = SEDL_SPEED_CARD_WIN;
  610. cs->hw.sedl.bus = SEDL_BUS_ISA;
  611. cs->hw.sedl.chip = SEDL_CHIP_TEST;
  612. } else if (cs->typ == ISDN_CTYPE_SEDLBAUER_PCMCIA) {
  613. cs->subtyp = SEDL_SPEED_STAR;
  614. cs->hw.sedl.bus = SEDL_BUS_PCMCIA;
  615. cs->hw.sedl.chip = SEDL_CHIP_TEST;
  616. } else if (cs->typ == ISDN_CTYPE_SEDLBAUER_FAX) {
  617. cs->subtyp = SEDL_SPEED_FAX;
  618. cs->hw.sedl.bus = SEDL_BUS_ISA;
  619. cs->hw.sedl.chip = SEDL_CHIP_ISAC_ISAR;
  620. } else
  621. return (0);
  622. bytecnt = 8;
  623. if (card->para[1]) {
  624. cs->hw.sedl.cfg_reg = card->para[1];
  625. cs->irq = card->para[0];
  626. if (cs->hw.sedl.chip == SEDL_CHIP_ISAC_ISAR) {
  627. bytecnt = 16;
  628. }
  629. } else {
  630. rc = setup_sedlbauer_isapnp(card, &bytecnt);
  631. if (!rc)
  632. return (0);
  633. if (rc > 0)
  634. goto ready;
  635. /* Probe for Sedlbauer speed pci */
  636. rc = setup_sedlbauer_pci(card);
  637. if (!rc)
  638. return (0);
  639. bytecnt = 256;
  640. }
  641. ready:
  642. /* In case of the sedlbauer pcmcia card, this region is in use,
  643. * reserved for us by the card manager. So we do not check it
  644. * here, it would fail.
  645. */
  646. if (cs->hw.sedl.bus != SEDL_BUS_PCMCIA &&
  647. !request_region(cs->hw.sedl.cfg_reg, bytecnt, "sedlbauer isdn")) {
  648. printk(KERN_WARNING
  649. "HiSax: %s config port %x-%x already in use\n",
  650. CardType[card->typ],
  651. cs->hw.sedl.cfg_reg,
  652. cs->hw.sedl.cfg_reg + bytecnt);
  653. return (0);
  654. }
  655. printk(KERN_INFO
  656. "Sedlbauer: defined at 0x%x-0x%x IRQ %d\n",
  657. cs->hw.sedl.cfg_reg,
  658. cs->hw.sedl.cfg_reg + bytecnt,
  659. cs->irq);
  660. cs->BC_Read_Reg = &ReadHSCX;
  661. cs->BC_Write_Reg = &WriteHSCX;
  662. cs->BC_Send_Data = &hscx_fill_fifo;
  663. cs->cardmsg = &Sedl_card_msg;
  664. /*
  665. * testing ISA and PCMCIA Cards for IPAC, default is ISAC
  666. * do not test for PCI card, because ports are different
  667. * and PCI card uses only IPAC (for the moment)
  668. */
  669. if (cs->hw.sedl.bus != SEDL_BUS_PCI) {
  670. val = readreg(cs->hw.sedl.cfg_reg + SEDL_IPAC_ANY_ADR,
  671. cs->hw.sedl.cfg_reg + SEDL_IPAC_ANY_IPAC, IPAC_ID);
  672. printk(KERN_DEBUG "Sedlbauer: testing IPAC version %x\n", val);
  673. if ((val == 1) || (val == 2)) {
  674. /* IPAC */
  675. cs->subtyp = SEDL_SPEED_WIN2_PC104;
  676. if (cs->hw.sedl.bus == SEDL_BUS_PCMCIA) {
  677. cs->subtyp = SEDL_SPEED_STAR2;
  678. }
  679. cs->hw.sedl.chip = SEDL_CHIP_IPAC;
  680. } else {
  681. /* ISAC_HSCX oder ISAC_ISAR */
  682. if (cs->hw.sedl.chip == SEDL_CHIP_TEST) {
  683. cs->hw.sedl.chip = SEDL_CHIP_ISAC_HSCX;
  684. }
  685. }
  686. }
  687. /*
  688. * hw.sedl.chip is now properly set
  689. */
  690. printk(KERN_INFO "Sedlbauer: %s detected\n",
  691. Sedlbauer_Types[cs->subtyp]);
  692. setup_isac(cs);
  693. if (cs->hw.sedl.chip == SEDL_CHIP_IPAC) {
  694. if (cs->hw.sedl.bus == SEDL_BUS_PCI) {
  695. cs->hw.sedl.adr = cs->hw.sedl.cfg_reg + SEDL_IPAC_PCI_ADR;
  696. cs->hw.sedl.isac = cs->hw.sedl.cfg_reg + SEDL_IPAC_PCI_IPAC;
  697. cs->hw.sedl.hscx = cs->hw.sedl.cfg_reg + SEDL_IPAC_PCI_IPAC;
  698. } else {
  699. cs->hw.sedl.adr = cs->hw.sedl.cfg_reg + SEDL_IPAC_ANY_ADR;
  700. cs->hw.sedl.isac = cs->hw.sedl.cfg_reg + SEDL_IPAC_ANY_IPAC;
  701. cs->hw.sedl.hscx = cs->hw.sedl.cfg_reg + SEDL_IPAC_ANY_IPAC;
  702. }
  703. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  704. cs->readisac = &ReadISAC_IPAC;
  705. cs->writeisac = &WriteISAC_IPAC;
  706. cs->readisacfifo = &ReadISACfifo_IPAC;
  707. cs->writeisacfifo = &WriteISACfifo_IPAC;
  708. cs->irq_func = &sedlbauer_interrupt_ipac;
  709. val = readreg(cs->hw.sedl.adr, cs->hw.sedl.isac, IPAC_ID);
  710. printk(KERN_INFO "Sedlbauer: IPAC version %x\n", val);
  711. } else {
  712. /* ISAC_HSCX oder ISAC_ISAR */
  713. cs->readisac = &ReadISAC;
  714. cs->writeisac = &WriteISAC;
  715. cs->readisacfifo = &ReadISACfifo;
  716. cs->writeisacfifo = &WriteISACfifo;
  717. if (cs->hw.sedl.chip == SEDL_CHIP_ISAC_ISAR) {
  718. if (cs->hw.sedl.bus == SEDL_BUS_PCI) {
  719. cs->hw.sedl.adr = cs->hw.sedl.cfg_reg +
  720. SEDL_ISAR_PCI_ADR;
  721. cs->hw.sedl.isac = cs->hw.sedl.cfg_reg +
  722. SEDL_ISAR_PCI_ISAC;
  723. cs->hw.sedl.hscx = cs->hw.sedl.cfg_reg +
  724. SEDL_ISAR_PCI_ISAR;
  725. } else {
  726. cs->hw.sedl.adr = cs->hw.sedl.cfg_reg +
  727. SEDL_ISAR_ISA_ADR;
  728. cs->hw.sedl.isac = cs->hw.sedl.cfg_reg +
  729. SEDL_ISAR_ISA_ISAC;
  730. cs->hw.sedl.hscx = cs->hw.sedl.cfg_reg +
  731. SEDL_ISAR_ISA_ISAR;
  732. cs->hw.sedl.reset_on = cs->hw.sedl.cfg_reg +
  733. SEDL_ISAR_ISA_ISAR_RESET_ON;
  734. cs->hw.sedl.reset_off = cs->hw.sedl.cfg_reg +
  735. SEDL_ISAR_ISA_ISAR_RESET_OFF;
  736. }
  737. cs->bcs[0].hw.isar.reg = &cs->hw.sedl.isar;
  738. cs->bcs[1].hw.isar.reg = &cs->hw.sedl.isar;
  739. test_and_set_bit(HW_ISAR, &cs->HW_Flags);
  740. cs->irq_func = &sedlbauer_interrupt_isar;
  741. cs->auxcmd = &isar_auxcmd;
  742. ISACVersion(cs, "Sedlbauer:");
  743. cs->BC_Read_Reg = &ReadISAR;
  744. cs->BC_Write_Reg = &WriteISAR;
  745. cs->BC_Send_Data = &isar_fill_fifo;
  746. bytecnt = 3;
  747. while (bytecnt) {
  748. ver = ISARVersion(cs, "Sedlbauer:");
  749. if (ver < 0)
  750. printk(KERN_WARNING
  751. "Sedlbauer: wrong ISAR version (ret = %d)\n", ver);
  752. else
  753. break;
  754. reset_sedlbauer(cs);
  755. bytecnt--;
  756. }
  757. if (!bytecnt) {
  758. release_io_sedlbauer(cs);
  759. return (0);
  760. }
  761. } else {
  762. if (cs->hw.sedl.bus == SEDL_BUS_PCMCIA) {
  763. cs->hw.sedl.adr = cs->hw.sedl.cfg_reg + SEDL_HSCX_PCMCIA_ADR;
  764. cs->hw.sedl.isac = cs->hw.sedl.cfg_reg + SEDL_HSCX_PCMCIA_ISAC;
  765. cs->hw.sedl.hscx = cs->hw.sedl.cfg_reg + SEDL_HSCX_PCMCIA_HSCX;
  766. cs->hw.sedl.reset_on = cs->hw.sedl.cfg_reg + SEDL_HSCX_PCMCIA_RESET;
  767. cs->hw.sedl.reset_off = cs->hw.sedl.cfg_reg + SEDL_HSCX_PCMCIA_RESET;
  768. cs->irq_flags |= IRQF_SHARED;
  769. } else {
  770. cs->hw.sedl.adr = cs->hw.sedl.cfg_reg + SEDL_HSCX_ISA_ADR;
  771. cs->hw.sedl.isac = cs->hw.sedl.cfg_reg + SEDL_HSCX_ISA_ISAC;
  772. cs->hw.sedl.hscx = cs->hw.sedl.cfg_reg + SEDL_HSCX_ISA_HSCX;
  773. cs->hw.sedl.reset_on = cs->hw.sedl.cfg_reg + SEDL_HSCX_ISA_RESET_ON;
  774. cs->hw.sedl.reset_off = cs->hw.sedl.cfg_reg + SEDL_HSCX_ISA_RESET_OFF;
  775. }
  776. cs->irq_func = &sedlbauer_interrupt;
  777. ISACVersion(cs, "Sedlbauer:");
  778. if (HscxVersion(cs, "Sedlbauer:")) {
  779. printk(KERN_WARNING
  780. "Sedlbauer: wrong HSCX versions check IO address\n");
  781. release_io_sedlbauer(cs);
  782. return (0);
  783. }
  784. }
  785. }
  786. return (1);
  787. }