mic.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* $Id: mic.c,v 1.12.2.4 2004/01/13 23:48:39 keil Exp $
  2. *
  3. * low level stuff for mic cards
  4. *
  5. * Author Stephan von Krawczynski
  6. * Copyright by Stephan von Krawczynski <skraw@ithnet.com>
  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 *mic_revision = "$Revision: 1.12.2.4 $";
  18. #define byteout(addr, val) outb(val, addr)
  19. #define bytein(addr) inb(addr)
  20. #define MIC_ISAC 2
  21. #define MIC_HSCX 1
  22. #define MIC_ADR 7
  23. /* CARD_ADR (Write) */
  24. #define MIC_RESET 0x3 /* same as DOS driver */
  25. static inline u_char
  26. readreg(unsigned int ale, unsigned int adr, u_char off)
  27. {
  28. register u_char ret;
  29. byteout(ale, off);
  30. ret = bytein(adr);
  31. return (ret);
  32. }
  33. static inline void
  34. readfifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
  35. {
  36. byteout(ale, off);
  37. insb(adr, data, size);
  38. }
  39. static inline void
  40. writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
  41. {
  42. byteout(ale, off);
  43. byteout(adr, data);
  44. }
  45. static inline void
  46. writefifo(unsigned int ale, unsigned int adr, u_char off, u_char *data, int size)
  47. {
  48. byteout(ale, off);
  49. outsb(adr, data, size);
  50. }
  51. /* Interface functions */
  52. static u_char
  53. ReadISAC(struct IsdnCardState *cs, u_char offset)
  54. {
  55. return (readreg(cs->hw.mic.adr, cs->hw.mic.isac, offset));
  56. }
  57. static void
  58. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  59. {
  60. writereg(cs->hw.mic.adr, cs->hw.mic.isac, offset, value);
  61. }
  62. static void
  63. ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  64. {
  65. readfifo(cs->hw.mic.adr, cs->hw.mic.isac, 0, data, size);
  66. }
  67. static void
  68. WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  69. {
  70. writefifo(cs->hw.mic.adr, cs->hw.mic.isac, 0, data, size);
  71. }
  72. static u_char
  73. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  74. {
  75. return (readreg(cs->hw.mic.adr,
  76. cs->hw.mic.hscx, offset + (hscx ? 0x40 : 0)));
  77. }
  78. static void
  79. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  80. {
  81. writereg(cs->hw.mic.adr,
  82. cs->hw.mic.hscx, offset + (hscx ? 0x40 : 0), value);
  83. }
  84. /*
  85. * fast interrupt HSCX stuff goes here
  86. */
  87. #define READHSCX(cs, nr, reg) readreg(cs->hw.mic.adr, \
  88. cs->hw.mic.hscx, reg + (nr ? 0x40 : 0))
  89. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.mic.adr, \
  90. cs->hw.mic.hscx, reg + (nr ? 0x40 : 0), data)
  91. #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.mic.adr, \
  92. cs->hw.mic.hscx, (nr ? 0x40 : 0), ptr, cnt)
  93. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.mic.adr, \
  94. cs->hw.mic.hscx, (nr ? 0x40 : 0), ptr, cnt)
  95. #include "hscx_irq.c"
  96. static irqreturn_t
  97. mic_interrupt(int intno, void *dev_id)
  98. {
  99. struct IsdnCardState *cs = dev_id;
  100. u_char val;
  101. u_long flags;
  102. spin_lock_irqsave(&cs->lock, flags);
  103. val = readreg(cs->hw.mic.adr, cs->hw.mic.hscx, HSCX_ISTA + 0x40);
  104. Start_HSCX:
  105. if (val)
  106. hscx_int_main(cs, val);
  107. val = readreg(cs->hw.mic.adr, cs->hw.mic.isac, ISAC_ISTA);
  108. Start_ISAC:
  109. if (val)
  110. isac_interrupt(cs, val);
  111. val = readreg(cs->hw.mic.adr, cs->hw.mic.hscx, HSCX_ISTA + 0x40);
  112. if (val) {
  113. if (cs->debug & L1_DEB_HSCX)
  114. debugl1(cs, "HSCX IntStat after IntRoutine");
  115. goto Start_HSCX;
  116. }
  117. val = readreg(cs->hw.mic.adr, cs->hw.mic.isac, ISAC_ISTA);
  118. if (val) {
  119. if (cs->debug & L1_DEB_ISAC)
  120. debugl1(cs, "ISAC IntStat after IntRoutine");
  121. goto Start_ISAC;
  122. }
  123. writereg(cs->hw.mic.adr, cs->hw.mic.hscx, HSCX_MASK, 0xFF);
  124. writereg(cs->hw.mic.adr, cs->hw.mic.hscx, HSCX_MASK + 0x40, 0xFF);
  125. writereg(cs->hw.mic.adr, cs->hw.mic.isac, ISAC_MASK, 0xFF);
  126. writereg(cs->hw.mic.adr, cs->hw.mic.isac, ISAC_MASK, 0x0);
  127. writereg(cs->hw.mic.adr, cs->hw.mic.hscx, HSCX_MASK, 0x0);
  128. writereg(cs->hw.mic.adr, cs->hw.mic.hscx, HSCX_MASK + 0x40, 0x0);
  129. spin_unlock_irqrestore(&cs->lock, flags);
  130. return IRQ_HANDLED;
  131. }
  132. static void
  133. release_io_mic(struct IsdnCardState *cs)
  134. {
  135. int bytecnt = 8;
  136. if (cs->hw.mic.cfg_reg)
  137. release_region(cs->hw.mic.cfg_reg, bytecnt);
  138. }
  139. static int
  140. mic_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  141. {
  142. u_long flags;
  143. switch (mt) {
  144. case CARD_RESET:
  145. return (0);
  146. case CARD_RELEASE:
  147. release_io_mic(cs);
  148. return (0);
  149. case CARD_INIT:
  150. spin_lock_irqsave(&cs->lock, flags);
  151. inithscx(cs); /* /RTSA := ISAC RST */
  152. inithscxisac(cs, 3);
  153. spin_unlock_irqrestore(&cs->lock, flags);
  154. return (0);
  155. case CARD_TEST:
  156. return (0);
  157. }
  158. return (0);
  159. }
  160. int setup_mic(struct IsdnCard *card)
  161. {
  162. int bytecnt;
  163. struct IsdnCardState *cs = card->cs;
  164. char tmp[64];
  165. strcpy(tmp, mic_revision);
  166. printk(KERN_INFO "HiSax: mic driver Rev. %s\n", HiSax_getrev(tmp));
  167. if (cs->typ != ISDN_CTYPE_MIC)
  168. return (0);
  169. bytecnt = 8;
  170. cs->hw.mic.cfg_reg = card->para[1];
  171. cs->irq = card->para[0];
  172. cs->hw.mic.adr = cs->hw.mic.cfg_reg + MIC_ADR;
  173. cs->hw.mic.isac = cs->hw.mic.cfg_reg + MIC_ISAC;
  174. cs->hw.mic.hscx = cs->hw.mic.cfg_reg + MIC_HSCX;
  175. if (!request_region(cs->hw.mic.cfg_reg, bytecnt, "mic isdn")) {
  176. printk(KERN_WARNING
  177. "HiSax: ith mic config port %x-%x already in use\n",
  178. cs->hw.mic.cfg_reg,
  179. cs->hw.mic.cfg_reg + bytecnt);
  180. return (0);
  181. }
  182. printk(KERN_INFO "mic: defined at 0x%x IRQ %d\n",
  183. cs->hw.mic.cfg_reg, cs->irq);
  184. setup_isac(cs);
  185. cs->readisac = &ReadISAC;
  186. cs->writeisac = &WriteISAC;
  187. cs->readisacfifo = &ReadISACfifo;
  188. cs->writeisacfifo = &WriteISACfifo;
  189. cs->BC_Read_Reg = &ReadHSCX;
  190. cs->BC_Write_Reg = &WriteHSCX;
  191. cs->BC_Send_Data = &hscx_fill_fifo;
  192. cs->cardmsg = &mic_card_msg;
  193. cs->irq_func = &mic_interrupt;
  194. ISACVersion(cs, "mic:");
  195. if (HscxVersion(cs, "mic:")) {
  196. printk(KERN_WARNING
  197. "mic: wrong HSCX versions check IO address\n");
  198. release_io_mic(cs);
  199. return (0);
  200. }
  201. return (1);
  202. }