avm_a1.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* $Id: avm_a1.c,v 2.15.2.4 2004/01/13 21:46:03 keil Exp $
  2. *
  3. * low level stuff for AVM A1 (Fritz) 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. */
  12. #include <linux/init.h>
  13. #include "hisax.h"
  14. #include "isac.h"
  15. #include "hscx.h"
  16. #include "isdnl1.h"
  17. static const char *avm_revision = "$Revision: 2.15.2.4 $";
  18. #define AVM_A1_STAT_ISAC 0x01
  19. #define AVM_A1_STAT_HSCX 0x02
  20. #define AVM_A1_STAT_TIMER 0x04
  21. #define byteout(addr,val) outb(val,addr)
  22. #define bytein(addr) inb(addr)
  23. static inline u_char
  24. readreg(unsigned int adr, u_char off)
  25. {
  26. return (bytein(adr + off));
  27. }
  28. static inline void
  29. writereg(unsigned int adr, u_char off, u_char data)
  30. {
  31. byteout(adr + off, data);
  32. }
  33. static inline void
  34. read_fifo(unsigned int adr, u_char * data, int size)
  35. {
  36. insb(adr, data, size);
  37. }
  38. static void
  39. write_fifo(unsigned int adr, u_char * data, int size)
  40. {
  41. outsb(adr, data, size);
  42. }
  43. /* Interface functions */
  44. static u_char
  45. ReadISAC(struct IsdnCardState *cs, u_char offset)
  46. {
  47. return (readreg(cs->hw.avm.isac, offset));
  48. }
  49. static void
  50. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  51. {
  52. writereg(cs->hw.avm.isac, offset, value);
  53. }
  54. static void
  55. ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  56. {
  57. read_fifo(cs->hw.avm.isacfifo, data, size);
  58. }
  59. static void
  60. WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  61. {
  62. write_fifo(cs->hw.avm.isacfifo, data, size);
  63. }
  64. static u_char
  65. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  66. {
  67. return (readreg(cs->hw.avm.hscx[hscx], offset));
  68. }
  69. static void
  70. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  71. {
  72. writereg(cs->hw.avm.hscx[hscx], offset, value);
  73. }
  74. /*
  75. * fast interrupt HSCX stuff goes here
  76. */
  77. #define READHSCX(cs, nr, reg) readreg(cs->hw.avm.hscx[nr], reg)
  78. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.avm.hscx[nr], reg, data)
  79. #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.avm.hscxfifo[nr], ptr, cnt)
  80. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.avm.hscxfifo[nr], ptr, cnt)
  81. #include "hscx_irq.c"
  82. static irqreturn_t
  83. avm_a1_interrupt(int intno, void *dev_id)
  84. {
  85. struct IsdnCardState *cs = dev_id;
  86. u_char val, sval;
  87. u_long flags;
  88. spin_lock_irqsave(&cs->lock, flags);
  89. while (((sval = bytein(cs->hw.avm.cfg_reg)) & 0xf) != 0x7) {
  90. if (!(sval & AVM_A1_STAT_TIMER)) {
  91. byteout(cs->hw.avm.cfg_reg, 0x1E);
  92. sval = bytein(cs->hw.avm.cfg_reg);
  93. } else if (cs->debug & L1_DEB_INTSTAT)
  94. debugl1(cs, "avm IntStatus %x", sval);
  95. if (!(sval & AVM_A1_STAT_HSCX)) {
  96. val = readreg(cs->hw.avm.hscx[1], HSCX_ISTA);
  97. if (val)
  98. hscx_int_main(cs, val);
  99. }
  100. if (!(sval & AVM_A1_STAT_ISAC)) {
  101. val = readreg(cs->hw.avm.isac, ISAC_ISTA);
  102. if (val)
  103. isac_interrupt(cs, val);
  104. }
  105. }
  106. writereg(cs->hw.avm.hscx[0], HSCX_MASK, 0xFF);
  107. writereg(cs->hw.avm.hscx[1], HSCX_MASK, 0xFF);
  108. writereg(cs->hw.avm.isac, ISAC_MASK, 0xFF);
  109. writereg(cs->hw.avm.isac, ISAC_MASK, 0x0);
  110. writereg(cs->hw.avm.hscx[0], HSCX_MASK, 0x0);
  111. writereg(cs->hw.avm.hscx[1], HSCX_MASK, 0x0);
  112. spin_unlock_irqrestore(&cs->lock, flags);
  113. return IRQ_HANDLED;
  114. }
  115. static inline void
  116. release_ioregs(struct IsdnCardState *cs, int mask)
  117. {
  118. release_region(cs->hw.avm.cfg_reg, 8);
  119. if (mask & 1)
  120. release_region(cs->hw.avm.isac + 32, 32);
  121. if (mask & 2)
  122. release_region(cs->hw.avm.isacfifo, 1);
  123. if (mask & 4)
  124. release_region(cs->hw.avm.hscx[0] + 32, 32);
  125. if (mask & 8)
  126. release_region(cs->hw.avm.hscxfifo[0], 1);
  127. if (mask & 0x10)
  128. release_region(cs->hw.avm.hscx[1] + 32, 32);
  129. if (mask & 0x20)
  130. release_region(cs->hw.avm.hscxfifo[1], 1);
  131. }
  132. static int
  133. AVM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  134. {
  135. u_long flags;
  136. switch (mt) {
  137. case CARD_RESET:
  138. return(0);
  139. case CARD_RELEASE:
  140. release_ioregs(cs, 0x3f);
  141. return(0);
  142. case CARD_INIT:
  143. spin_lock_irqsave(&cs->lock, flags);
  144. inithscxisac(cs, 1);
  145. byteout(cs->hw.avm.cfg_reg, 0x16);
  146. byteout(cs->hw.avm.cfg_reg, 0x1E);
  147. inithscxisac(cs, 2);
  148. spin_unlock_irqrestore(&cs->lock, flags);
  149. return(0);
  150. case CARD_TEST:
  151. return(0);
  152. }
  153. return(0);
  154. }
  155. int __devinit
  156. setup_avm_a1(struct IsdnCard *card)
  157. {
  158. u_char val;
  159. struct IsdnCardState *cs = card->cs;
  160. char tmp[64];
  161. strcpy(tmp, avm_revision);
  162. printk(KERN_INFO "HiSax: AVM driver Rev. %s\n", HiSax_getrev(tmp));
  163. if (cs->typ != ISDN_CTYPE_A1)
  164. return (0);
  165. cs->hw.avm.cfg_reg = card->para[1] + 0x1800;
  166. cs->hw.avm.isac = card->para[1] + 0x1400 - 0x20;
  167. cs->hw.avm.hscx[0] = card->para[1] + 0x400 - 0x20;
  168. cs->hw.avm.hscx[1] = card->para[1] + 0xc00 - 0x20;
  169. cs->hw.avm.isacfifo = card->para[1] + 0x1000;
  170. cs->hw.avm.hscxfifo[0] = card->para[1];
  171. cs->hw.avm.hscxfifo[1] = card->para[1] + 0x800;
  172. cs->irq = card->para[0];
  173. if (!request_region(cs->hw.avm.cfg_reg, 8, "avm cfg")) {
  174. printk(KERN_WARNING
  175. "HiSax: AVM A1 config port %x-%x already in use\n",
  176. cs->hw.avm.cfg_reg,
  177. cs->hw.avm.cfg_reg + 8);
  178. return (0);
  179. }
  180. if (!request_region(cs->hw.avm.isac + 32, 32, "HiSax isac")) {
  181. printk(KERN_WARNING
  182. "HiSax: AVM A1 isac ports %x-%x already in use\n",
  183. cs->hw.avm.isac + 32,
  184. cs->hw.avm.isac + 64);
  185. release_ioregs(cs, 0);
  186. return (0);
  187. }
  188. if (!request_region(cs->hw.avm.isacfifo, 1, "HiSax isac fifo")) {
  189. printk(KERN_WARNING
  190. "HiSax: AVM A1 isac fifo port %x already in use\n",
  191. cs->hw.avm.isacfifo);
  192. release_ioregs(cs, 1);
  193. return (0);
  194. }
  195. if (!request_region(cs->hw.avm.hscx[0] + 32, 32, "HiSax hscx A")) {
  196. printk(KERN_WARNING
  197. "HiSax: AVM A1 hscx A ports %x-%x already in use\n",
  198. cs->hw.avm.hscx[0] + 32,
  199. cs->hw.avm.hscx[0] + 64);
  200. release_ioregs(cs, 3);
  201. return (0);
  202. }
  203. if (!request_region(cs->hw.avm.hscxfifo[0], 1, "HiSax hscx A fifo")) {
  204. printk(KERN_WARNING
  205. "HiSax: AVM A1 hscx A fifo port %x already in use\n",
  206. cs->hw.avm.hscxfifo[0]);
  207. release_ioregs(cs, 7);
  208. return (0);
  209. }
  210. if (!request_region(cs->hw.avm.hscx[1] + 32, 32, "HiSax hscx B")) {
  211. printk(KERN_WARNING
  212. "HiSax: AVM A1 hscx B ports %x-%x already in use\n",
  213. cs->hw.avm.hscx[1] + 32,
  214. cs->hw.avm.hscx[1] + 64);
  215. release_ioregs(cs, 0xf);
  216. return (0);
  217. }
  218. if (!request_region(cs->hw.avm.hscxfifo[1], 1, "HiSax hscx B fifo")) {
  219. printk(KERN_WARNING
  220. "HiSax: AVM A1 hscx B fifo port %x already in use\n",
  221. cs->hw.avm.hscxfifo[1]);
  222. release_ioregs(cs, 0x1f);
  223. return (0);
  224. }
  225. byteout(cs->hw.avm.cfg_reg, 0x0);
  226. HZDELAY(HZ / 5 + 1);
  227. byteout(cs->hw.avm.cfg_reg, 0x1);
  228. HZDELAY(HZ / 5 + 1);
  229. byteout(cs->hw.avm.cfg_reg, 0x0);
  230. HZDELAY(HZ / 5 + 1);
  231. val = cs->irq;
  232. if (val == 9)
  233. val = 2;
  234. byteout(cs->hw.avm.cfg_reg + 1, val);
  235. HZDELAY(HZ / 5 + 1);
  236. byteout(cs->hw.avm.cfg_reg, 0x0);
  237. HZDELAY(HZ / 5 + 1);
  238. val = bytein(cs->hw.avm.cfg_reg);
  239. printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
  240. cs->hw.avm.cfg_reg, val);
  241. val = bytein(cs->hw.avm.cfg_reg + 3);
  242. printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
  243. cs->hw.avm.cfg_reg + 3, val);
  244. val = bytein(cs->hw.avm.cfg_reg + 2);
  245. printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
  246. cs->hw.avm.cfg_reg + 2, val);
  247. val = bytein(cs->hw.avm.cfg_reg);
  248. printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
  249. cs->hw.avm.cfg_reg, val);
  250. printk(KERN_INFO "HiSax: AVM A1 config irq:%d cfg:0x%X\n",
  251. cs->irq,
  252. cs->hw.avm.cfg_reg);
  253. printk(KERN_INFO
  254. "HiSax: isac:0x%X/0x%X\n",
  255. cs->hw.avm.isac + 32, cs->hw.avm.isacfifo);
  256. printk(KERN_INFO
  257. "HiSax: hscx A:0x%X/0x%X hscx B:0x%X/0x%X\n",
  258. cs->hw.avm.hscx[0] + 32, cs->hw.avm.hscxfifo[0],
  259. cs->hw.avm.hscx[1] + 32, cs->hw.avm.hscxfifo[1]);
  260. cs->readisac = &ReadISAC;
  261. cs->writeisac = &WriteISAC;
  262. cs->readisacfifo = &ReadISACfifo;
  263. cs->writeisacfifo = &WriteISACfifo;
  264. cs->BC_Read_Reg = &ReadHSCX;
  265. cs->BC_Write_Reg = &WriteHSCX;
  266. cs->BC_Send_Data = &hscx_fill_fifo;
  267. setup_isac(cs);
  268. cs->cardmsg = &AVM_card_msg;
  269. cs->irq_func = &avm_a1_interrupt;
  270. ISACVersion(cs, "AVM A1:");
  271. if (HscxVersion(cs, "AVM A1:")) {
  272. printk(KERN_WARNING
  273. "AVM A1: wrong HSCX versions check IO address\n");
  274. release_ioregs(cs, 0x3f);
  275. return (0);
  276. }
  277. return (1);
  278. }