sportster.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* $Id: sportster.c,v 1.16.2.4 2004/01/13 23:48:39 keil Exp $
  2. *
  3. * low level stuff for USR Sportster internal TA
  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 Christian "naddy" Weisgerber (3Com, US Robotics) for documentation
  12. *
  13. *
  14. */
  15. #include <linux/init.h>
  16. #include "hisax.h"
  17. #include "isac.h"
  18. #include "hscx.h"
  19. #include "isdnl1.h"
  20. static const char *sportster_revision = "$Revision: 1.16.2.4 $";
  21. #define byteout(addr,val) outb(val,addr)
  22. #define bytein(addr) inb(addr)
  23. #define SPORTSTER_ISAC 0xC000
  24. #define SPORTSTER_HSCXA 0x0000
  25. #define SPORTSTER_HSCXB 0x4000
  26. #define SPORTSTER_RES_IRQ 0x8000
  27. #define SPORTSTER_RESET 0x80
  28. #define SPORTSTER_INTE 0x40
  29. static inline int
  30. calc_off(unsigned int base, unsigned int off)
  31. {
  32. return(base + ((off & 0xfc)<<8) + ((off & 3)<<1));
  33. }
  34. static inline void
  35. read_fifo(unsigned int adr, u_char * data, int size)
  36. {
  37. insb(adr, data, size);
  38. }
  39. static void
  40. write_fifo(unsigned int adr, u_char * data, int size)
  41. {
  42. outsb(adr, data, size);
  43. }
  44. /* Interface functions */
  45. static u_char
  46. ReadISAC(struct IsdnCardState *cs, u_char offset)
  47. {
  48. return (bytein(calc_off(cs->hw.spt.isac, offset)));
  49. }
  50. static void
  51. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  52. {
  53. byteout(calc_off(cs->hw.spt.isac, offset), value);
  54. }
  55. static void
  56. ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  57. {
  58. read_fifo(cs->hw.spt.isac, data, size);
  59. }
  60. static void
  61. WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  62. {
  63. write_fifo(cs->hw.spt.isac, data, size);
  64. }
  65. static u_char
  66. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  67. {
  68. return (bytein(calc_off(cs->hw.spt.hscx[hscx], offset)));
  69. }
  70. static void
  71. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  72. {
  73. byteout(calc_off(cs->hw.spt.hscx[hscx], offset), value);
  74. }
  75. /*
  76. * fast interrupt HSCX stuff goes here
  77. */
  78. #define READHSCX(cs, nr, reg) bytein(calc_off(cs->hw.spt.hscx[nr], reg))
  79. #define WRITEHSCX(cs, nr, reg, data) byteout(calc_off(cs->hw.spt.hscx[nr], reg), data)
  80. #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.spt.hscx[nr], ptr, cnt)
  81. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.spt.hscx[nr], ptr, cnt)
  82. #include "hscx_irq.c"
  83. static irqreturn_t
  84. sportster_interrupt(int intno, void *dev_id)
  85. {
  86. struct IsdnCardState *cs = dev_id;
  87. u_char val;
  88. u_long flags;
  89. spin_lock_irqsave(&cs->lock, flags);
  90. val = READHSCX(cs, 1, HSCX_ISTA);
  91. Start_HSCX:
  92. if (val)
  93. hscx_int_main(cs, val);
  94. val = ReadISAC(cs, ISAC_ISTA);
  95. Start_ISAC:
  96. if (val)
  97. isac_interrupt(cs, val);
  98. val = READHSCX(cs, 1, HSCX_ISTA);
  99. if (val) {
  100. if (cs->debug & L1_DEB_HSCX)
  101. debugl1(cs, "HSCX IntStat after IntRoutine");
  102. goto Start_HSCX;
  103. }
  104. val = ReadISAC(cs, ISAC_ISTA);
  105. if (val) {
  106. if (cs->debug & L1_DEB_ISAC)
  107. debugl1(cs, "ISAC IntStat after IntRoutine");
  108. goto Start_ISAC;
  109. }
  110. /* get a new irq impulse if there any pending */
  111. bytein(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ +1);
  112. spin_unlock_irqrestore(&cs->lock, flags);
  113. return IRQ_HANDLED;
  114. }
  115. static void
  116. release_io_sportster(struct IsdnCardState *cs)
  117. {
  118. int i, adr;
  119. byteout(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ, 0);
  120. for (i=0; i<64; i++) {
  121. adr = cs->hw.spt.cfg_reg + i *1024;
  122. release_region(adr, 8);
  123. }
  124. }
  125. static void
  126. reset_sportster(struct IsdnCardState *cs)
  127. {
  128. cs->hw.spt.res_irq |= SPORTSTER_RESET; /* Reset On */
  129. byteout(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ, cs->hw.spt.res_irq);
  130. mdelay(10);
  131. cs->hw.spt.res_irq &= ~SPORTSTER_RESET; /* Reset Off */
  132. byteout(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ, cs->hw.spt.res_irq);
  133. mdelay(10);
  134. }
  135. static int
  136. Sportster_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  137. {
  138. u_long flags;
  139. switch (mt) {
  140. case CARD_RESET:
  141. spin_lock_irqsave(&cs->lock, flags);
  142. reset_sportster(cs);
  143. spin_unlock_irqrestore(&cs->lock, flags);
  144. return(0);
  145. case CARD_RELEASE:
  146. release_io_sportster(cs);
  147. return(0);
  148. case CARD_INIT:
  149. spin_lock_irqsave(&cs->lock, flags);
  150. reset_sportster(cs);
  151. inithscxisac(cs, 1);
  152. cs->hw.spt.res_irq |= SPORTSTER_INTE; /* IRQ On */
  153. byteout(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ, cs->hw.spt.res_irq);
  154. inithscxisac(cs, 2);
  155. spin_unlock_irqrestore(&cs->lock, flags);
  156. return(0);
  157. case CARD_TEST:
  158. return(0);
  159. }
  160. return(0);
  161. }
  162. static int __devinit
  163. get_io_range(struct IsdnCardState *cs)
  164. {
  165. int i, j, adr;
  166. for (i=0;i<64;i++) {
  167. adr = cs->hw.spt.cfg_reg + i *1024;
  168. if (!request_region(adr, 8, "sportster")) {
  169. printk(KERN_WARNING "HiSax: USR Sportster config port "
  170. "%x-%x already in use\n",
  171. adr, adr + 8);
  172. break;
  173. }
  174. }
  175. if (i==64)
  176. return(1);
  177. else {
  178. for (j=0; j<i; j++) {
  179. adr = cs->hw.spt.cfg_reg + j *1024;
  180. release_region(adr, 8);
  181. }
  182. return(0);
  183. }
  184. }
  185. int __devinit
  186. setup_sportster(struct IsdnCard *card)
  187. {
  188. struct IsdnCardState *cs = card->cs;
  189. char tmp[64];
  190. strcpy(tmp, sportster_revision);
  191. printk(KERN_INFO "HiSax: USR Sportster driver Rev. %s\n", HiSax_getrev(tmp));
  192. if (cs->typ != ISDN_CTYPE_SPORTSTER)
  193. return (0);
  194. cs->hw.spt.cfg_reg = card->para[1];
  195. cs->irq = card->para[0];
  196. if (!get_io_range(cs))
  197. return (0);
  198. cs->hw.spt.isac = cs->hw.spt.cfg_reg + SPORTSTER_ISAC;
  199. cs->hw.spt.hscx[0] = cs->hw.spt.cfg_reg + SPORTSTER_HSCXA;
  200. cs->hw.spt.hscx[1] = cs->hw.spt.cfg_reg + SPORTSTER_HSCXB;
  201. switch(cs->irq) {
  202. case 5: cs->hw.spt.res_irq = 1;
  203. break;
  204. case 7: cs->hw.spt.res_irq = 2;
  205. break;
  206. case 10:cs->hw.spt.res_irq = 3;
  207. break;
  208. case 11:cs->hw.spt.res_irq = 4;
  209. break;
  210. case 12:cs->hw.spt.res_irq = 5;
  211. break;
  212. case 14:cs->hw.spt.res_irq = 6;
  213. break;
  214. case 15:cs->hw.spt.res_irq = 7;
  215. break;
  216. default:release_io_sportster(cs);
  217. printk(KERN_WARNING "Sportster: wrong IRQ\n");
  218. return(0);
  219. }
  220. printk(KERN_INFO "HiSax: USR Sportster config irq:%d cfg:0x%X\n",
  221. cs->irq, cs->hw.spt.cfg_reg);
  222. setup_isac(cs);
  223. cs->readisac = &ReadISAC;
  224. cs->writeisac = &WriteISAC;
  225. cs->readisacfifo = &ReadISACfifo;
  226. cs->writeisacfifo = &WriteISACfifo;
  227. cs->BC_Read_Reg = &ReadHSCX;
  228. cs->BC_Write_Reg = &WriteHSCX;
  229. cs->BC_Send_Data = &hscx_fill_fifo;
  230. cs->cardmsg = &Sportster_card_msg;
  231. cs->irq_func = &sportster_interrupt;
  232. ISACVersion(cs, "Sportster:");
  233. if (HscxVersion(cs, "Sportster:")) {
  234. printk(KERN_WARNING
  235. "Sportster: wrong HSCX versions check IO address\n");
  236. release_io_sportster(cs);
  237. return (0);
  238. }
  239. return (1);
  240. }