sportster.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 get_io_range(struct IsdnCardState *cs)
  163. {
  164. int i, j, adr;
  165. for (i = 0; i < 64; i++) {
  166. adr = cs->hw.spt.cfg_reg + i * 1024;
  167. if (!request_region(adr, 8, "sportster")) {
  168. printk(KERN_WARNING "HiSax: USR Sportster config port "
  169. "%x-%x already in use\n",
  170. adr, adr + 8);
  171. break;
  172. }
  173. }
  174. if (i == 64)
  175. return (1);
  176. else {
  177. for (j = 0; j < i; j++) {
  178. adr = cs->hw.spt.cfg_reg + j * 1024;
  179. release_region(adr, 8);
  180. }
  181. return (0);
  182. }
  183. }
  184. int setup_sportster(struct IsdnCard *card)
  185. {
  186. struct IsdnCardState *cs = card->cs;
  187. char tmp[64];
  188. strcpy(tmp, sportster_revision);
  189. printk(KERN_INFO "HiSax: USR Sportster driver Rev. %s\n", HiSax_getrev(tmp));
  190. if (cs->typ != ISDN_CTYPE_SPORTSTER)
  191. return (0);
  192. cs->hw.spt.cfg_reg = card->para[1];
  193. cs->irq = card->para[0];
  194. if (!get_io_range(cs))
  195. return (0);
  196. cs->hw.spt.isac = cs->hw.spt.cfg_reg + SPORTSTER_ISAC;
  197. cs->hw.spt.hscx[0] = cs->hw.spt.cfg_reg + SPORTSTER_HSCXA;
  198. cs->hw.spt.hscx[1] = cs->hw.spt.cfg_reg + SPORTSTER_HSCXB;
  199. switch (cs->irq) {
  200. case 5: cs->hw.spt.res_irq = 1;
  201. break;
  202. case 7: cs->hw.spt.res_irq = 2;
  203. break;
  204. case 10:cs->hw.spt.res_irq = 3;
  205. break;
  206. case 11:cs->hw.spt.res_irq = 4;
  207. break;
  208. case 12:cs->hw.spt.res_irq = 5;
  209. break;
  210. case 14:cs->hw.spt.res_irq = 6;
  211. break;
  212. case 15:cs->hw.spt.res_irq = 7;
  213. break;
  214. default:release_io_sportster(cs);
  215. printk(KERN_WARNING "Sportster: wrong IRQ\n");
  216. return (0);
  217. }
  218. printk(KERN_INFO "HiSax: USR Sportster config irq:%d cfg:0x%X\n",
  219. cs->irq, cs->hw.spt.cfg_reg);
  220. setup_isac(cs);
  221. cs->readisac = &ReadISAC;
  222. cs->writeisac = &WriteISAC;
  223. cs->readisacfifo = &ReadISACfifo;
  224. cs->writeisacfifo = &WriteISACfifo;
  225. cs->BC_Read_Reg = &ReadHSCX;
  226. cs->BC_Write_Reg = &WriteHSCX;
  227. cs->BC_Send_Data = &hscx_fill_fifo;
  228. cs->cardmsg = &Sportster_card_msg;
  229. cs->irq_func = &sportster_interrupt;
  230. ISACVersion(cs, "Sportster:");
  231. if (HscxVersion(cs, "Sportster:")) {
  232. printk(KERN_WARNING
  233. "Sportster: wrong HSCX versions check IO address\n");
  234. release_io_sportster(cs);
  235. return (0);
  236. }
  237. return (1);
  238. }