avm_a1.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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 setup_avm_a1(struct IsdnCard *card)
  156. {
  157. u_char val;
  158. struct IsdnCardState *cs = card->cs;
  159. char tmp[64];
  160. strcpy(tmp, avm_revision);
  161. printk(KERN_INFO "HiSax: AVM driver Rev. %s\n", HiSax_getrev(tmp));
  162. if (cs->typ != ISDN_CTYPE_A1)
  163. return (0);
  164. cs->hw.avm.cfg_reg = card->para[1] + 0x1800;
  165. cs->hw.avm.isac = card->para[1] + 0x1400 - 0x20;
  166. cs->hw.avm.hscx[0] = card->para[1] + 0x400 - 0x20;
  167. cs->hw.avm.hscx[1] = card->para[1] + 0xc00 - 0x20;
  168. cs->hw.avm.isacfifo = card->para[1] + 0x1000;
  169. cs->hw.avm.hscxfifo[0] = card->para[1];
  170. cs->hw.avm.hscxfifo[1] = card->para[1] + 0x800;
  171. cs->irq = card->para[0];
  172. if (!request_region(cs->hw.avm.cfg_reg, 8, "avm cfg")) {
  173. printk(KERN_WARNING
  174. "HiSax: AVM A1 config port %x-%x already in use\n",
  175. cs->hw.avm.cfg_reg,
  176. cs->hw.avm.cfg_reg + 8);
  177. return (0);
  178. }
  179. if (!request_region(cs->hw.avm.isac + 32, 32, "HiSax isac")) {
  180. printk(KERN_WARNING
  181. "HiSax: AVM A1 isac ports %x-%x already in use\n",
  182. cs->hw.avm.isac + 32,
  183. cs->hw.avm.isac + 64);
  184. release_ioregs(cs, 0);
  185. return (0);
  186. }
  187. if (!request_region(cs->hw.avm.isacfifo, 1, "HiSax isac fifo")) {
  188. printk(KERN_WARNING
  189. "HiSax: AVM A1 isac fifo port %x already in use\n",
  190. cs->hw.avm.isacfifo);
  191. release_ioregs(cs, 1);
  192. return (0);
  193. }
  194. if (!request_region(cs->hw.avm.hscx[0] + 32, 32, "HiSax hscx A")) {
  195. printk(KERN_WARNING
  196. "HiSax: AVM A1 hscx A ports %x-%x already in use\n",
  197. cs->hw.avm.hscx[0] + 32,
  198. cs->hw.avm.hscx[0] + 64);
  199. release_ioregs(cs, 3);
  200. return (0);
  201. }
  202. if (!request_region(cs->hw.avm.hscxfifo[0], 1, "HiSax hscx A fifo")) {
  203. printk(KERN_WARNING
  204. "HiSax: AVM A1 hscx A fifo port %x already in use\n",
  205. cs->hw.avm.hscxfifo[0]);
  206. release_ioregs(cs, 7);
  207. return (0);
  208. }
  209. if (!request_region(cs->hw.avm.hscx[1] + 32, 32, "HiSax hscx B")) {
  210. printk(KERN_WARNING
  211. "HiSax: AVM A1 hscx B ports %x-%x already in use\n",
  212. cs->hw.avm.hscx[1] + 32,
  213. cs->hw.avm.hscx[1] + 64);
  214. release_ioregs(cs, 0xf);
  215. return (0);
  216. }
  217. if (!request_region(cs->hw.avm.hscxfifo[1], 1, "HiSax hscx B fifo")) {
  218. printk(KERN_WARNING
  219. "HiSax: AVM A1 hscx B fifo port %x already in use\n",
  220. cs->hw.avm.hscxfifo[1]);
  221. release_ioregs(cs, 0x1f);
  222. return (0);
  223. }
  224. byteout(cs->hw.avm.cfg_reg, 0x0);
  225. HZDELAY(HZ / 5 + 1);
  226. byteout(cs->hw.avm.cfg_reg, 0x1);
  227. HZDELAY(HZ / 5 + 1);
  228. byteout(cs->hw.avm.cfg_reg, 0x0);
  229. HZDELAY(HZ / 5 + 1);
  230. val = cs->irq;
  231. if (val == 9)
  232. val = 2;
  233. byteout(cs->hw.avm.cfg_reg + 1, val);
  234. HZDELAY(HZ / 5 + 1);
  235. byteout(cs->hw.avm.cfg_reg, 0x0);
  236. HZDELAY(HZ / 5 + 1);
  237. val = bytein(cs->hw.avm.cfg_reg);
  238. printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
  239. cs->hw.avm.cfg_reg, val);
  240. val = bytein(cs->hw.avm.cfg_reg + 3);
  241. printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
  242. cs->hw.avm.cfg_reg + 3, val);
  243. val = bytein(cs->hw.avm.cfg_reg + 2);
  244. printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
  245. cs->hw.avm.cfg_reg + 2, val);
  246. val = bytein(cs->hw.avm.cfg_reg);
  247. printk(KERN_INFO "AVM A1: Byte at %x is %x\n",
  248. cs->hw.avm.cfg_reg, val);
  249. printk(KERN_INFO "HiSax: AVM A1 config irq:%d cfg:0x%X\n",
  250. cs->irq,
  251. cs->hw.avm.cfg_reg);
  252. printk(KERN_INFO
  253. "HiSax: isac:0x%X/0x%X\n",
  254. cs->hw.avm.isac + 32, cs->hw.avm.isacfifo);
  255. printk(KERN_INFO
  256. "HiSax: hscx A:0x%X/0x%X hscx B:0x%X/0x%X\n",
  257. cs->hw.avm.hscx[0] + 32, cs->hw.avm.hscxfifo[0],
  258. cs->hw.avm.hscx[1] + 32, cs->hw.avm.hscxfifo[1]);
  259. cs->readisac = &ReadISAC;
  260. cs->writeisac = &WriteISAC;
  261. cs->readisacfifo = &ReadISACfifo;
  262. cs->writeisacfifo = &WriteISACfifo;
  263. cs->BC_Read_Reg = &ReadHSCX;
  264. cs->BC_Write_Reg = &WriteHSCX;
  265. cs->BC_Send_Data = &hscx_fill_fifo;
  266. setup_isac(cs);
  267. cs->cardmsg = &AVM_card_msg;
  268. cs->irq_func = &avm_a1_interrupt;
  269. ISACVersion(cs, "AVM A1:");
  270. if (HscxVersion(cs, "AVM A1:")) {
  271. printk(KERN_WARNING
  272. "AVM A1: wrong HSCX versions check IO address\n");
  273. release_ioregs(cs, 0x3f);
  274. return (0);
  275. }
  276. return (1);
  277. }