teles3.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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[] __devinitdata = {
  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 __devinitdata = &teles_ids[0];
  242. static struct pnp_card *pnp_c __devinitdata = NULL;
  243. #endif
  244. int __devinit
  245. setup_teles3(struct IsdnCard *card)
  246. {
  247. u_char val;
  248. struct IsdnCardState *cs = card->cs;
  249. char tmp[64];
  250. strcpy(tmp, teles3_revision);
  251. printk(KERN_INFO "HiSax: Teles IO driver Rev. %s\n", HiSax_getrev(tmp));
  252. if ((cs->typ != ISDN_CTYPE_16_3) && (cs->typ != ISDN_CTYPE_PNP)
  253. && (cs->typ != ISDN_CTYPE_TELESPCMCIA) && (cs->typ != ISDN_CTYPE_COMPAQ_ISA))
  254. return (0);
  255. #ifdef __ISAPNP__
  256. if (!card->para[1] && isapnp_present()) {
  257. struct pnp_dev *pnp_d;
  258. while(ipid->card_vendor) {
  259. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  260. ipid->card_device, pnp_c))) {
  261. pnp_d = NULL;
  262. if ((pnp_d = pnp_find_dev(pnp_c,
  263. ipid->vendor, ipid->function, pnp_d))) {
  264. int err;
  265. printk(KERN_INFO "HiSax: %s detected\n",
  266. (char *)ipid->driver_data);
  267. pnp_disable_dev(pnp_d);
  268. err = pnp_activate_dev(pnp_d);
  269. if (err<0) {
  270. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  271. __func__, err);
  272. return(0);
  273. }
  274. card->para[3] = pnp_port_start(pnp_d, 2);
  275. card->para[2] = pnp_port_start(pnp_d, 1);
  276. card->para[1] = pnp_port_start(pnp_d, 0);
  277. card->para[0] = pnp_irq(pnp_d, 0);
  278. if (!card->para[0] || !card->para[1] || !card->para[2]) {
  279. printk(KERN_ERR "Teles PnP:some resources are missing %ld/%lx/%lx\n",
  280. card->para[0], card->para[1], card->para[2]);
  281. pnp_disable_dev(pnp_d);
  282. return(0);
  283. }
  284. break;
  285. } else {
  286. printk(KERN_ERR "Teles PnP: PnP error card found, no device\n");
  287. }
  288. }
  289. ipid++;
  290. pnp_c = NULL;
  291. }
  292. if (!ipid->card_vendor) {
  293. printk(KERN_INFO "Teles PnP: no ISAPnP card found\n");
  294. return(0);
  295. }
  296. }
  297. #endif
  298. if (cs->typ == ISDN_CTYPE_16_3) {
  299. cs->hw.teles3.cfg_reg = card->para[1];
  300. switch (cs->hw.teles3.cfg_reg) {
  301. case 0x180:
  302. case 0x280:
  303. case 0x380:
  304. cs->hw.teles3.cfg_reg |= 0xc00;
  305. break;
  306. }
  307. cs->hw.teles3.isac = cs->hw.teles3.cfg_reg - 0x420;
  308. cs->hw.teles3.hscx[0] = cs->hw.teles3.cfg_reg - 0xc20;
  309. cs->hw.teles3.hscx[1] = cs->hw.teles3.cfg_reg - 0x820;
  310. } else if (cs->typ == ISDN_CTYPE_TELESPCMCIA) {
  311. cs->hw.teles3.cfg_reg = 0;
  312. cs->hw.teles3.hscx[0] = card->para[1] - 0x20;
  313. cs->hw.teles3.hscx[1] = card->para[1];
  314. cs->hw.teles3.isac = card->para[1] + 0x20;
  315. } else if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  316. cs->hw.teles3.cfg_reg = card->para[3];
  317. cs->hw.teles3.isac = card->para[2] - 32;
  318. cs->hw.teles3.hscx[0] = card->para[1] - 32;
  319. cs->hw.teles3.hscx[1] = card->para[1];
  320. } else { /* PNP */
  321. cs->hw.teles3.cfg_reg = 0;
  322. cs->hw.teles3.isac = card->para[1] - 32;
  323. cs->hw.teles3.hscx[0] = card->para[2] - 32;
  324. cs->hw.teles3.hscx[1] = card->para[2];
  325. }
  326. cs->irq = card->para[0];
  327. cs->hw.teles3.isacfifo = cs->hw.teles3.isac + 0x3e;
  328. cs->hw.teles3.hscxfifo[0] = cs->hw.teles3.hscx[0] + 0x3e;
  329. cs->hw.teles3.hscxfifo[1] = cs->hw.teles3.hscx[1] + 0x3e;
  330. if (cs->typ == ISDN_CTYPE_TELESPCMCIA) {
  331. if (!request_region(cs->hw.teles3.hscx[1], 96, "HiSax Teles PCMCIA")) {
  332. printk(KERN_WARNING
  333. "HiSax: %s ports %x-%x already in use\n",
  334. CardType[cs->typ],
  335. cs->hw.teles3.hscx[1],
  336. cs->hw.teles3.hscx[1] + 96);
  337. return (0);
  338. }
  339. cs->irq_flags |= IRQF_SHARED; /* cardbus can share */
  340. } else {
  341. if (cs->hw.teles3.cfg_reg) {
  342. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  343. if (!request_region(cs->hw.teles3.cfg_reg, 1, "teles3 cfg")) {
  344. printk(KERN_WARNING
  345. "HiSax: %s config port %x already in use\n",
  346. CardType[card->typ],
  347. cs->hw.teles3.cfg_reg);
  348. return (0);
  349. }
  350. } else {
  351. if (!request_region(cs->hw.teles3.cfg_reg, 8, "teles3 cfg")) {
  352. printk(KERN_WARNING
  353. "HiSax: %s config port %x-%x already in use\n",
  354. CardType[card->typ],
  355. cs->hw.teles3.cfg_reg,
  356. cs->hw.teles3.cfg_reg + 8);
  357. return (0);
  358. }
  359. }
  360. }
  361. if (!request_region(cs->hw.teles3.isac + 32, 32, "HiSax isac")) {
  362. printk(KERN_WARNING
  363. "HiSax: %s isac ports %x-%x already in use\n",
  364. CardType[cs->typ],
  365. cs->hw.teles3.isac + 32,
  366. cs->hw.teles3.isac + 64);
  367. if (cs->hw.teles3.cfg_reg) {
  368. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  369. release_region(cs->hw.teles3.cfg_reg, 1);
  370. } else {
  371. release_region(cs->hw.teles3.cfg_reg, 8);
  372. }
  373. }
  374. return (0);
  375. }
  376. if (!request_region(cs->hw.teles3.hscx[0] + 32, 32, "HiSax hscx A")) {
  377. printk(KERN_WARNING
  378. "HiSax: %s hscx A ports %x-%x already in use\n",
  379. CardType[cs->typ],
  380. cs->hw.teles3.hscx[0] + 32,
  381. cs->hw.teles3.hscx[0] + 64);
  382. if (cs->hw.teles3.cfg_reg) {
  383. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  384. release_region(cs->hw.teles3.cfg_reg, 1);
  385. } else {
  386. release_region(cs->hw.teles3.cfg_reg, 8);
  387. }
  388. }
  389. release_ioregs(cs, 1);
  390. return (0);
  391. }
  392. if (!request_region(cs->hw.teles3.hscx[1] + 32, 32, "HiSax hscx B")) {
  393. printk(KERN_WARNING
  394. "HiSax: %s hscx B ports %x-%x already in use\n",
  395. CardType[cs->typ],
  396. cs->hw.teles3.hscx[1] + 32,
  397. cs->hw.teles3.hscx[1] + 64);
  398. if (cs->hw.teles3.cfg_reg) {
  399. if (cs->typ == ISDN_CTYPE_COMPAQ_ISA) {
  400. release_region(cs->hw.teles3.cfg_reg, 1);
  401. } else {
  402. release_region(cs->hw.teles3.cfg_reg, 8);
  403. }
  404. }
  405. release_ioregs(cs, 3);
  406. return (0);
  407. }
  408. }
  409. if ((cs->hw.teles3.cfg_reg) && (cs->typ != ISDN_CTYPE_COMPAQ_ISA)) {
  410. if ((val = bytein(cs->hw.teles3.cfg_reg + 0)) != 0x51) {
  411. printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
  412. cs->hw.teles3.cfg_reg + 0, val);
  413. release_io_teles3(cs);
  414. return (0);
  415. }
  416. if ((val = bytein(cs->hw.teles3.cfg_reg + 1)) != 0x93) {
  417. printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
  418. cs->hw.teles3.cfg_reg + 1, val);
  419. release_io_teles3(cs);
  420. return (0);
  421. }
  422. val = bytein(cs->hw.teles3.cfg_reg + 2);/* 0x1e=without AB
  423. * 0x1f=with AB
  424. * 0x1c 16.3 ???
  425. * 0x39 16.3 1.1
  426. * 0x38 16.3 1.3
  427. * 0x46 16.3 with AB + Video (Teles-Vision)
  428. */
  429. if (val != 0x46 && val != 0x39 && val != 0x38 && val != 0x1c && val != 0x1e && val != 0x1f) {
  430. printk(KERN_WARNING "Teles: 16.3 Byte at %x is %x\n",
  431. cs->hw.teles3.cfg_reg + 2, val);
  432. release_io_teles3(cs);
  433. return (0);
  434. }
  435. }
  436. printk(KERN_INFO
  437. "HiSax: %s config irq:%d isac:0x%X cfg:0x%X\n",
  438. CardType[cs->typ], cs->irq,
  439. cs->hw.teles3.isac + 32, cs->hw.teles3.cfg_reg);
  440. printk(KERN_INFO
  441. "HiSax: hscx A:0x%X hscx B:0x%X\n",
  442. cs->hw.teles3.hscx[0] + 32, cs->hw.teles3.hscx[1] + 32);
  443. setup_isac(cs);
  444. if (reset_teles3(cs)) {
  445. printk(KERN_WARNING "Teles3: wrong IRQ\n");
  446. release_io_teles3(cs);
  447. return (0);
  448. }
  449. cs->readisac = &ReadISAC;
  450. cs->writeisac = &WriteISAC;
  451. cs->readisacfifo = &ReadISACfifo;
  452. cs->writeisacfifo = &WriteISACfifo;
  453. cs->BC_Read_Reg = &ReadHSCX;
  454. cs->BC_Write_Reg = &WriteHSCX;
  455. cs->BC_Send_Data = &hscx_fill_fifo;
  456. cs->cardmsg = &Teles_card_msg;
  457. cs->irq_func = &teles3_interrupt;
  458. ISACVersion(cs, "Teles3:");
  459. if (HscxVersion(cs, "Teles3:")) {
  460. printk(KERN_WARNING
  461. "Teles3: wrong HSCX versions check IO address\n");
  462. release_io_teles3(cs);
  463. return (0);
  464. }
  465. return (1);
  466. }