teles3.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. /* $Id: teles3.c,v 2.19.2.4 2004/01/13 23:48:39 keil Exp $
  2. *
  3. * low level stuff for Teles 16.3 & PNP 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. * Thanks to Jan den Ouden
  12. * Fritz Elfert
  13. * Beat Doebeli
  14. *
  15. */
  16. #include <linux/init.h>
  17. #include <linux/isapnp.h>
  18. #include "hisax.h"
  19. #include "isac.h"
  20. #include "hscx.h"
  21. #include "isdnl1.h"
  22. static const char *teles3_revision = "$Revision: 2.19.2.4 $";
  23. #define byteout(addr, val) outb(val, addr)
  24. #define bytein(addr) inb(addr)
  25. static inline u_char
  26. readreg(unsigned int adr, u_char off)
  27. {
  28. return (bytein(adr + off));
  29. }
  30. static inline void
  31. writereg(unsigned int adr, u_char off, u_char data)
  32. {
  33. byteout(adr + off, data);
  34. }
  35. static inline void
  36. read_fifo(unsigned int adr, u_char *data, int size)
  37. {
  38. insb(adr, data, size);
  39. }
  40. static void
  41. write_fifo(unsigned int adr, u_char *data, int size)
  42. {
  43. outsb(adr, data, size);
  44. }
  45. /* Interface functions */
  46. static u_char
  47. ReadISAC(struct IsdnCardState *cs, u_char offset)
  48. {
  49. return (readreg(cs->hw.teles3.isac, offset));
  50. }
  51. static void
  52. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  53. {
  54. writereg(cs->hw.teles3.isac, offset, value);
  55. }
  56. static void
  57. ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  58. {
  59. read_fifo(cs->hw.teles3.isacfifo, data, size);
  60. }
  61. static void
  62. WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  63. {
  64. write_fifo(cs->hw.teles3.isacfifo, data, size);
  65. }
  66. static u_char
  67. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  68. {
  69. return (readreg(cs->hw.teles3.hscx[hscx], offset));
  70. }
  71. static void
  72. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  73. {
  74. writereg(cs->hw.teles3.hscx[hscx], offset, value);
  75. }
  76. /*
  77. * fast interrupt HSCX stuff goes here
  78. */
  79. #define READHSCX(cs, nr, reg) readreg(cs->hw.teles3.hscx[nr], reg)
  80. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.teles3.hscx[nr], reg, data)
  81. #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.teles3.hscxfifo[nr], ptr, cnt)
  82. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.teles3.hscxfifo[nr], ptr, cnt)
  83. #include "hscx_irq.c"
  84. static irqreturn_t
  85. teles3_interrupt(int intno, void *dev_id)
  86. {
  87. #define MAXCOUNT 5
  88. struct IsdnCardState *cs = dev_id;
  89. u_char val;
  90. u_long flags;
  91. int count = 0;
  92. spin_lock_irqsave(&cs->lock, flags);
  93. val = readreg(cs->hw.teles3.hscx[1], HSCX_ISTA);
  94. Start_HSCX:
  95. if (val)
  96. hscx_int_main(cs, val);
  97. val = readreg(cs->hw.teles3.isac, ISAC_ISTA);
  98. Start_ISAC:
  99. if (val)
  100. isac_interrupt(cs, val);
  101. count++;
  102. val = readreg(cs->hw.teles3.hscx[1], HSCX_ISTA);
  103. if (val && count < MAXCOUNT) {
  104. if (cs->debug & L1_DEB_HSCX)
  105. debugl1(cs, "HSCX IntStat after IntRoutine");
  106. goto Start_HSCX;
  107. }
  108. val = readreg(cs->hw.teles3.isac, ISAC_ISTA);
  109. if (val && count < MAXCOUNT) {
  110. if (cs->debug & L1_DEB_ISAC)
  111. debugl1(cs, "ISAC IntStat after IntRoutine");
  112. goto Start_ISAC;
  113. }
  114. if (count >= MAXCOUNT)
  115. printk(KERN_WARNING "Teles3: more than %d loops in teles3_interrupt\n", count);
  116. writereg(cs->hw.teles3.hscx[0], HSCX_MASK, 0xFF);
  117. writereg(cs->hw.teles3.hscx[1], HSCX_MASK, 0xFF);
  118. writereg(cs->hw.teles3.isac, ISAC_MASK, 0xFF);
  119. writereg(cs->hw.teles3.isac, ISAC_MASK, 0x0);
  120. writereg(cs->hw.teles3.hscx[0], HSCX_MASK, 0x0);
  121. writereg(cs->hw.teles3.hscx[1], HSCX_MASK, 0x0);
  122. spin_unlock_irqrestore(&cs->lock, flags);
  123. return IRQ_HANDLED;
  124. }
  125. static inline void
  126. release_ioregs(struct IsdnCardState *cs, int mask)
  127. {
  128. if (mask & 1)
  129. release_region(cs->hw.teles3.isac + 32, 32);
  130. if (mask & 2)
  131. release_region(cs->hw.teles3.hscx[0] + 32, 32);
  132. if (mask & 4)
  133. release_region(cs->hw.teles3.hscx[1] + 32, 32);
  134. }
  135. static void
  136. release_io_teles3(struct IsdnCardState *cs)
  137. {
  138. if (cs->typ == ISDN_CTYPE_TELESPCMCIA) {
  139. release_region(cs->hw.teles3.hscx[1], 96);
  140. } else {
  141. if (cs->hw.teles3.cfg_reg) {
  142. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  143. release_region(cs->hw.teles3.cfg_reg, 1);
  144. } else {
  145. release_region(cs->hw.teles3.cfg_reg, 8);
  146. }
  147. }
  148. release_ioregs(cs, 0x7);
  149. }
  150. }
  151. static int
  152. reset_teles3(struct IsdnCardState *cs)
  153. {
  154. u_char irqcfg;
  155. if (cs->typ != ISDN_CTYPE_TELESPCMCIA) {
  156. if ((cs->hw.teles3.cfg_reg) && (cs->typ != ISDN_CTYPE_COMPAQ_ISA)) {
  157. switch (cs->irq) {
  158. case 2:
  159. case 9:
  160. irqcfg = 0x00;
  161. break;
  162. case 3:
  163. irqcfg = 0x02;
  164. break;
  165. case 4:
  166. irqcfg = 0x04;
  167. break;
  168. case 5:
  169. irqcfg = 0x06;
  170. break;
  171. case 10:
  172. irqcfg = 0x08;
  173. break;
  174. case 11:
  175. irqcfg = 0x0A;
  176. break;
  177. case 12:
  178. irqcfg = 0x0C;
  179. break;
  180. case 15:
  181. irqcfg = 0x0E;
  182. break;
  183. default:
  184. return (1);
  185. }
  186. byteout(cs->hw.teles3.cfg_reg + 4, irqcfg);
  187. HZDELAY(HZ / 10 + 1);
  188. byteout(cs->hw.teles3.cfg_reg + 4, irqcfg | 1);
  189. HZDELAY(HZ / 10 + 1);
  190. } else if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  191. byteout(cs->hw.teles3.cfg_reg, 0xff);
  192. HZDELAY(2);
  193. byteout(cs->hw.teles3.cfg_reg, 0x00);
  194. HZDELAY(2);
  195. } else {
  196. /* Reset off for 16.3 PnP , thanks to Georg Acher */
  197. byteout(cs->hw.teles3.isac + 0x3c, 0);
  198. HZDELAY(2);
  199. byteout(cs->hw.teles3.isac + 0x3c, 1);
  200. HZDELAY(2);
  201. }
  202. }
  203. return (0);
  204. }
  205. static int
  206. Teles_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  207. {
  208. u_long flags;
  209. switch (mt) {
  210. case CARD_RESET:
  211. spin_lock_irqsave(&cs->lock, flags);
  212. reset_teles3(cs);
  213. spin_unlock_irqrestore(&cs->lock, flags);
  214. return (0);
  215. case CARD_RELEASE:
  216. release_io_teles3(cs);
  217. return (0);
  218. case CARD_INIT:
  219. spin_lock_irqsave(&cs->lock, flags);
  220. inithscxisac(cs, 3);
  221. spin_unlock_irqrestore(&cs->lock, flags);
  222. return (0);
  223. case CARD_TEST:
  224. return (0);
  225. }
  226. return (0);
  227. }
  228. #ifdef __ISAPNP__
  229. static struct isapnp_device_id teles_ids[] = {
  230. { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2110),
  231. ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2110),
  232. (unsigned long) "Teles 16.3 PnP" },
  233. { ISAPNP_VENDOR('C', 'T', 'X'), ISAPNP_FUNCTION(0x0),
  234. ISAPNP_VENDOR('C', 'T', 'X'), ISAPNP_FUNCTION(0x0),
  235. (unsigned long) "Creatix 16.3 PnP" },
  236. { ISAPNP_VENDOR('C', 'P', 'Q'), ISAPNP_FUNCTION(0x1002),
  237. ISAPNP_VENDOR('C', 'P', 'Q'), ISAPNP_FUNCTION(0x1002),
  238. (unsigned long) "Compaq ISDN S0" },
  239. { 0, }
  240. };
  241. static struct isapnp_device_id *ipid = &teles_ids[0];
  242. static struct pnp_card *pnp_c = NULL;
  243. #endif
  244. int setup_teles3(struct IsdnCard *card)
  245. {
  246. u_char val;
  247. struct IsdnCardState *cs = card->cs;
  248. char tmp[64];
  249. strcpy(tmp, teles3_revision);
  250. printk(KERN_INFO "HiSax: Teles IO driver Rev. %s\n", HiSax_getrev(tmp));
  251. if ((cs->typ != ISDN_CTYPE_16_3) && (cs->typ != ISDN_CTYPE_PNP)
  252. && (cs->typ != ISDN_CTYPE_TELESPCMCIA) && (cs->typ != ISDN_CTYPE_COMPAQ_ISA))
  253. return (0);
  254. #ifdef __ISAPNP__
  255. if (!card->para[1] && isapnp_present()) {
  256. struct pnp_dev *pnp_d;
  257. while (ipid->card_vendor) {
  258. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  259. ipid->card_device, pnp_c))) {
  260. pnp_d = NULL;
  261. if ((pnp_d = pnp_find_dev(pnp_c,
  262. ipid->vendor, ipid->function, pnp_d))) {
  263. int err;
  264. printk(KERN_INFO "HiSax: %s detected\n",
  265. (char *)ipid->driver_data);
  266. pnp_disable_dev(pnp_d);
  267. err = pnp_activate_dev(pnp_d);
  268. if (err < 0) {
  269. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  270. __func__, err);
  271. return (0);
  272. }
  273. card->para[3] = pnp_port_start(pnp_d, 2);
  274. card->para[2] = pnp_port_start(pnp_d, 1);
  275. card->para[1] = pnp_port_start(pnp_d, 0);
  276. card->para[0] = pnp_irq(pnp_d, 0);
  277. if (!card->para[0] || !card->para[1] || !card->para[2]) {
  278. printk(KERN_ERR "Teles PnP:some resources are missing %ld/%lx/%lx\n",
  279. card->para[0], card->para[1], card->para[2]);
  280. pnp_disable_dev(pnp_d);
  281. return (0);
  282. }
  283. break;
  284. } else {
  285. printk(KERN_ERR "Teles PnP: PnP error card found, no device\n");
  286. }
  287. }
  288. ipid++;
  289. pnp_c = NULL;
  290. }
  291. if (!ipid->card_vendor) {
  292. printk(KERN_INFO "Teles PnP: no ISAPnP card found\n");
  293. return (0);
  294. }
  295. }
  296. #endif
  297. if (cs->typ == ISDN_CTYPE_16_3) {
  298. cs->hw.teles3.cfg_reg = card->para[1];
  299. switch (cs->hw.teles3.cfg_reg) {
  300. case 0x180:
  301. case 0x280:
  302. case 0x380:
  303. cs->hw.teles3.cfg_reg |= 0xc00;
  304. break;
  305. }
  306. cs->hw.teles3.isac = cs->hw.teles3.cfg_reg - 0x420;
  307. cs->hw.teles3.hscx[0] = cs->hw.teles3.cfg_reg - 0xc20;
  308. cs->hw.teles3.hscx[1] = cs->hw.teles3.cfg_reg - 0x820;
  309. } else if (cs->typ == ISDN_CTYPE_TELESPCMCIA) {
  310. cs->hw.teles3.cfg_reg = 0;
  311. cs->hw.teles3.hscx[0] = card->para[1] - 0x20;
  312. cs->hw.teles3.hscx[1] = card->para[1];
  313. cs->hw.teles3.isac = card->para[1] + 0x20;
  314. } else if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  315. cs->hw.teles3.cfg_reg = card->para[3];
  316. cs->hw.teles3.isac = card->para[2] - 32;
  317. cs->hw.teles3.hscx[0] = card->para[1] - 32;
  318. cs->hw.teles3.hscx[1] = card->para[1];
  319. } else { /* PNP */
  320. cs->hw.teles3.cfg_reg = 0;
  321. cs->hw.teles3.isac = card->para[1] - 32;
  322. cs->hw.teles3.hscx[0] = card->para[2] - 32;
  323. cs->hw.teles3.hscx[1] = card->para[2];
  324. }
  325. cs->irq = card->para[0];
  326. cs->hw.teles3.isacfifo = cs->hw.teles3.isac + 0x3e;
  327. cs->hw.teles3.hscxfifo[0] = cs->hw.teles3.hscx[0] + 0x3e;
  328. cs->hw.teles3.hscxfifo[1] = cs->hw.teles3.hscx[1] + 0x3e;
  329. if (cs->typ == ISDN_CTYPE_TELESPCMCIA) {
  330. if (!request_region(cs->hw.teles3.hscx[1], 96, "HiSax Teles PCMCIA")) {
  331. printk(KERN_WARNING
  332. "HiSax: %s ports %x-%x already in use\n",
  333. CardType[cs->typ],
  334. cs->hw.teles3.hscx[1],
  335. cs->hw.teles3.hscx[1] + 96);
  336. return (0);
  337. }
  338. cs->irq_flags |= IRQF_SHARED; /* cardbus can share */
  339. } else {
  340. if (cs->hw.teles3.cfg_reg) {
  341. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  342. if (!request_region(cs->hw.teles3.cfg_reg, 1, "teles3 cfg")) {
  343. printk(KERN_WARNING
  344. "HiSax: %s config port %x already in use\n",
  345. CardType[card->typ],
  346. cs->hw.teles3.cfg_reg);
  347. return (0);
  348. }
  349. } else {
  350. if (!request_region(cs->hw.teles3.cfg_reg, 8, "teles3 cfg")) {
  351. printk(KERN_WARNING
  352. "HiSax: %s config port %x-%x already in use\n",
  353. CardType[card->typ],
  354. cs->hw.teles3.cfg_reg,
  355. cs->hw.teles3.cfg_reg + 8);
  356. return (0);
  357. }
  358. }
  359. }
  360. if (!request_region(cs->hw.teles3.isac + 32, 32, "HiSax isac")) {
  361. printk(KERN_WARNING
  362. "HiSax: %s isac ports %x-%x already in use\n",
  363. CardType[cs->typ],
  364. cs->hw.teles3.isac + 32,
  365. cs->hw.teles3.isac + 64);
  366. if (cs->hw.teles3.cfg_reg) {
  367. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  368. release_region(cs->hw.teles3.cfg_reg, 1);
  369. } else {
  370. release_region(cs->hw.teles3.cfg_reg, 8);
  371. }
  372. }
  373. return (0);
  374. }
  375. if (!request_region(cs->hw.teles3.hscx[0] + 32, 32, "HiSax hscx A")) {
  376. printk(KERN_WARNING
  377. "HiSax: %s hscx A ports %x-%x already in use\n",
  378. CardType[cs->typ],
  379. cs->hw.teles3.hscx[0] + 32,
  380. cs->hw.teles3.hscx[0] + 64);
  381. if (cs->hw.teles3.cfg_reg) {
  382. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  383. release_region(cs->hw.teles3.cfg_reg, 1);
  384. } else {
  385. release_region(cs->hw.teles3.cfg_reg, 8);
  386. }
  387. }
  388. release_ioregs(cs, 1);
  389. return (0);
  390. }
  391. if (!request_region(cs->hw.teles3.hscx[1] + 32, 32, "HiSax hscx B")) {
  392. printk(KERN_WARNING
  393. "HiSax: %s hscx B ports %x-%x already in use\n",
  394. CardType[cs->typ],
  395. cs->hw.teles3.hscx[1] + 32,
  396. cs->hw.teles3.hscx[1] + 64);
  397. if (cs->hw.teles3.cfg_reg) {
  398. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  399. release_region(cs->hw.teles3.cfg_reg, 1);
  400. } else {
  401. release_region(cs->hw.teles3.cfg_reg, 8);
  402. }
  403. }
  404. release_ioregs(cs, 3);
  405. return (0);
  406. }
  407. }
  408. if ((cs->hw.teles3.cfg_reg) && (cs->typ != ISDN_CTYPE_COMPAQ_ISA)) {
  409. if ((val = bytein(cs->hw.teles3.cfg_reg + 0)) != 0x51) {
  410. printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
  411. cs->hw.teles3.cfg_reg + 0, val);
  412. release_io_teles3(cs);
  413. return (0);
  414. }
  415. if ((val = bytein(cs->hw.teles3.cfg_reg + 1)) != 0x93) {
  416. printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
  417. cs->hw.teles3.cfg_reg + 1, val);
  418. release_io_teles3(cs);
  419. return (0);
  420. }
  421. val = bytein(cs->hw.teles3.cfg_reg + 2);/* 0x1e=without AB
  422. * 0x1f=with AB
  423. * 0x1c 16.3 ???
  424. * 0x39 16.3 1.1
  425. * 0x38 16.3 1.3
  426. * 0x46 16.3 with AB + Video (Teles-Vision)
  427. */
  428. if (val != 0x46 && val != 0x39 && val != 0x38 && val != 0x1c && val != 0x1e && val != 0x1f) {
  429. printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
  430. cs->hw.teles3.cfg_reg + 2, val);
  431. release_io_teles3(cs);
  432. return (0);
  433. }
  434. }
  435. printk(KERN_INFO
  436. "HiSax: %s config irq:%d isac:0x%X cfg:0x%X\n",
  437. CardType[cs->typ], cs->irq,
  438. cs->hw.teles3.isac + 32, cs->hw.teles3.cfg_reg);
  439. printk(KERN_INFO
  440. "HiSax: hscx A:0x%X hscx B:0x%X\n",
  441. cs->hw.teles3.hscx[0] + 32, cs->hw.teles3.hscx[1] + 32);
  442. setup_isac(cs);
  443. if (reset_teles3(cs)) {
  444. printk(KERN_WARNING "Teles3: wrong IRQ\n");
  445. release_io_teles3(cs);
  446. return (0);
  447. }
  448. cs->readisac = &ReadISAC;
  449. cs->writeisac = &WriteISAC;
  450. cs->readisacfifo = &ReadISACfifo;
  451. cs->writeisacfifo = &WriteISACfifo;
  452. cs->BC_Read_Reg = &ReadHSCX;
  453. cs->BC_Write_Reg = &WriteHSCX;
  454. cs->BC_Send_Data = &hscx_fill_fifo;
  455. cs->cardmsg = &Teles_card_msg;
  456. cs->irq_func = &teles3_interrupt;
  457. ISACVersion(cs, "Teles3:");
  458. if (HscxVersion(cs, "Teles3:")) {
  459. printk(KERN_WARNING
  460. "Teles3: wrong HSCX versions check IO address\n");
  461. release_io_teles3(cs);
  462. return (0);
  463. }
  464. return (1);
  465. }