isurf.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* $Id: isurf.c,v 1.12.2.4 2004/01/13 21:46:03 keil Exp $
  2. *
  3. * low level stuff for Siemens I-Surf/I-Talk 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 "isar.h"
  16. #include "isdnl1.h"
  17. #include <linux/isapnp.h>
  18. static const char *ISurf_revision = "$Revision: 1.12.2.4 $";
  19. #define byteout(addr, val) outb(val, addr)
  20. #define bytein(addr) inb(addr)
  21. #define ISURF_ISAR_RESET 1
  22. #define ISURF_ISAC_RESET 2
  23. #define ISURF_ISAR_EA 4
  24. #define ISURF_ARCOFI_RESET 8
  25. #define ISURF_RESET (ISURF_ISAR_RESET | ISURF_ISAC_RESET | ISURF_ARCOFI_RESET)
  26. #define ISURF_ISAR_OFFSET 0
  27. #define ISURF_ISAC_OFFSET 0x100
  28. #define ISURF_IOMEM_SIZE 0x400
  29. /* Interface functions */
  30. static u_char
  31. ReadISAC(struct IsdnCardState *cs, u_char offset)
  32. {
  33. return (readb(cs->hw.isurf.isac + offset));
  34. }
  35. static void
  36. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  37. {
  38. writeb(value, cs->hw.isurf.isac + offset); mb();
  39. }
  40. static void
  41. ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  42. {
  43. register int i;
  44. for (i = 0; i < size; i++)
  45. data[i] = readb(cs->hw.isurf.isac);
  46. }
  47. static void
  48. WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size)
  49. {
  50. register int i;
  51. for (i = 0; i < size; i++) {
  52. writeb(data[i], cs->hw.isurf.isac); mb();
  53. }
  54. }
  55. /* ISAR access routines
  56. * mode = 0 access with IRQ on
  57. * mode = 1 access with IRQ off
  58. * mode = 2 access with IRQ off and using last offset
  59. */
  60. static u_char
  61. ReadISAR(struct IsdnCardState *cs, int mode, u_char offset)
  62. {
  63. return (readb(cs->hw.isurf.isar + offset));
  64. }
  65. static void
  66. WriteISAR(struct IsdnCardState *cs, int mode, u_char offset, u_char value)
  67. {
  68. writeb(value, cs->hw.isurf.isar + offset); mb();
  69. }
  70. static irqreturn_t
  71. isurf_interrupt(int intno, void *dev_id)
  72. {
  73. struct IsdnCardState *cs = dev_id;
  74. u_char val;
  75. int cnt = 5;
  76. u_long flags;
  77. spin_lock_irqsave(&cs->lock, flags);
  78. val = readb(cs->hw.isurf.isar + ISAR_IRQBIT);
  79. Start_ISAR:
  80. if (val & ISAR_IRQSTA)
  81. isar_int_main(cs);
  82. val = readb(cs->hw.isurf.isac + ISAC_ISTA);
  83. Start_ISAC:
  84. if (val)
  85. isac_interrupt(cs, val);
  86. val = readb(cs->hw.isurf.isar + ISAR_IRQBIT);
  87. if ((val & ISAR_IRQSTA) && --cnt) {
  88. if (cs->debug & L1_DEB_HSCX)
  89. debugl1(cs, "ISAR IntStat after IntRoutine");
  90. goto Start_ISAR;
  91. }
  92. val = readb(cs->hw.isurf.isac + ISAC_ISTA);
  93. if (val && --cnt) {
  94. if (cs->debug & L1_DEB_ISAC)
  95. debugl1(cs, "ISAC IntStat after IntRoutine");
  96. goto Start_ISAC;
  97. }
  98. if (!cnt)
  99. printk(KERN_WARNING "ISurf IRQ LOOP\n");
  100. writeb(0, cs->hw.isurf.isar + ISAR_IRQBIT); mb();
  101. writeb(0xFF, cs->hw.isurf.isac + ISAC_MASK); mb();
  102. writeb(0, cs->hw.isurf.isac + ISAC_MASK); mb();
  103. writeb(ISAR_IRQMSK, cs->hw.isurf.isar + ISAR_IRQBIT); mb();
  104. spin_unlock_irqrestore(&cs->lock, flags);
  105. return IRQ_HANDLED;
  106. }
  107. static void
  108. release_io_isurf(struct IsdnCardState *cs)
  109. {
  110. release_region(cs->hw.isurf.reset, 1);
  111. iounmap(cs->hw.isurf.isar);
  112. release_mem_region(cs->hw.isurf.phymem, ISURF_IOMEM_SIZE);
  113. }
  114. static void
  115. reset_isurf(struct IsdnCardState *cs, u_char chips)
  116. {
  117. printk(KERN_INFO "ISurf: resetting card\n");
  118. byteout(cs->hw.isurf.reset, chips); /* Reset On */
  119. mdelay(10);
  120. byteout(cs->hw.isurf.reset, ISURF_ISAR_EA); /* Reset Off */
  121. mdelay(10);
  122. }
  123. static int
  124. ISurf_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  125. {
  126. u_long flags;
  127. switch (mt) {
  128. case CARD_RESET:
  129. spin_lock_irqsave(&cs->lock, flags);
  130. reset_isurf(cs, ISURF_RESET);
  131. spin_unlock_irqrestore(&cs->lock, flags);
  132. return (0);
  133. case CARD_RELEASE:
  134. release_io_isurf(cs);
  135. return (0);
  136. case CARD_INIT:
  137. spin_lock_irqsave(&cs->lock, flags);
  138. reset_isurf(cs, ISURF_RESET);
  139. clear_pending_isac_ints(cs);
  140. writeb(0, cs->hw.isurf.isar + ISAR_IRQBIT); mb();
  141. initisac(cs);
  142. initisar(cs);
  143. /* Reenable ISAC IRQ */
  144. cs->writeisac(cs, ISAC_MASK, 0);
  145. /* RESET Receiver and Transmitter */
  146. cs->writeisac(cs, ISAC_CMDR, 0x41);
  147. spin_unlock_irqrestore(&cs->lock, flags);
  148. return (0);
  149. case CARD_TEST:
  150. return (0);
  151. }
  152. return (0);
  153. }
  154. static int
  155. isurf_auxcmd(struct IsdnCardState *cs, isdn_ctrl *ic) {
  156. int ret;
  157. u_long flags;
  158. if ((ic->command == ISDN_CMD_IOCTL) && (ic->arg == 9)) {
  159. ret = isar_auxcmd(cs, ic);
  160. spin_lock_irqsave(&cs->lock, flags);
  161. if (!ret) {
  162. reset_isurf(cs, ISURF_ISAR_EA | ISURF_ISAC_RESET |
  163. ISURF_ARCOFI_RESET);
  164. initisac(cs);
  165. cs->writeisac(cs, ISAC_MASK, 0);
  166. cs->writeisac(cs, ISAC_CMDR, 0x41);
  167. }
  168. spin_unlock_irqrestore(&cs->lock, flags);
  169. return (ret);
  170. }
  171. return (isar_auxcmd(cs, ic));
  172. }
  173. #ifdef __ISAPNP__
  174. static struct pnp_card *pnp_c = NULL;
  175. #endif
  176. int setup_isurf(struct IsdnCard *card)
  177. {
  178. int ver;
  179. struct IsdnCardState *cs = card->cs;
  180. char tmp[64];
  181. strcpy(tmp, ISurf_revision);
  182. printk(KERN_INFO "HiSax: ISurf driver Rev. %s\n", HiSax_getrev(tmp));
  183. if (cs->typ != ISDN_CTYPE_ISURF)
  184. return (0);
  185. if (card->para[1] && card->para[2]) {
  186. cs->hw.isurf.reset = card->para[1];
  187. cs->hw.isurf.phymem = card->para[2];
  188. cs->irq = card->para[0];
  189. } else {
  190. #ifdef __ISAPNP__
  191. if (isapnp_present()) {
  192. struct pnp_dev *pnp_d = NULL;
  193. int err;
  194. cs->subtyp = 0;
  195. if ((pnp_c = pnp_find_card(
  196. ISAPNP_VENDOR('S', 'I', 'E'),
  197. ISAPNP_FUNCTION(0x0010), pnp_c))) {
  198. if (!(pnp_d = pnp_find_dev(pnp_c,
  199. ISAPNP_VENDOR('S', 'I', 'E'),
  200. ISAPNP_FUNCTION(0x0010), pnp_d))) {
  201. printk(KERN_ERR "ISurfPnP: PnP error card found, no device\n");
  202. return (0);
  203. }
  204. pnp_disable_dev(pnp_d);
  205. err = pnp_activate_dev(pnp_d);
  206. if (err < 0) {
  207. pr_warn("%s: pnp_activate_dev ret=%d\n",
  208. __func__, err);
  209. return 0;
  210. }
  211. cs->hw.isurf.reset = pnp_port_start(pnp_d, 0);
  212. cs->hw.isurf.phymem = pnp_mem_start(pnp_d, 1);
  213. cs->irq = pnp_irq(pnp_d, 0);
  214. if (!cs->irq || !cs->hw.isurf.reset || !cs->hw.isurf.phymem) {
  215. printk(KERN_ERR "ISurfPnP:some resources are missing %d/%x/%lx\n",
  216. cs->irq, cs->hw.isurf.reset, cs->hw.isurf.phymem);
  217. pnp_disable_dev(pnp_d);
  218. return (0);
  219. }
  220. } else {
  221. printk(KERN_INFO "ISurfPnP: no ISAPnP card found\n");
  222. return (0);
  223. }
  224. } else {
  225. printk(KERN_INFO "ISurfPnP: no ISAPnP bus found\n");
  226. return (0);
  227. }
  228. #else
  229. printk(KERN_WARNING "HiSax: Siemens I-Surf port/mem not set\n");
  230. return (0);
  231. #endif
  232. }
  233. if (!request_region(cs->hw.isurf.reset, 1, "isurf isdn")) {
  234. printk(KERN_WARNING
  235. "HiSax: Siemens I-Surf config port %x already in use\n",
  236. cs->hw.isurf.reset);
  237. return (0);
  238. }
  239. if (!request_region(cs->hw.isurf.phymem, ISURF_IOMEM_SIZE, "isurf iomem")) {
  240. printk(KERN_WARNING "HiSax: Siemens I-Surf memory region "
  241. "%lx-%lx already in use\n",
  242. cs->hw.isurf.phymem,
  243. cs->hw.isurf.phymem + ISURF_IOMEM_SIZE);
  244. release_region(cs->hw.isurf.reset, 1);
  245. return (0);
  246. }
  247. cs->hw.isurf.isar = ioremap(cs->hw.isurf.phymem, ISURF_IOMEM_SIZE);
  248. cs->hw.isurf.isac = cs->hw.isurf.isar + ISURF_ISAC_OFFSET;
  249. printk(KERN_INFO
  250. "ISurf: defined at 0x%x 0x%lx IRQ %d\n",
  251. cs->hw.isurf.reset,
  252. cs->hw.isurf.phymem,
  253. cs->irq);
  254. setup_isac(cs);
  255. cs->cardmsg = &ISurf_card_msg;
  256. cs->irq_func = &isurf_interrupt;
  257. cs->auxcmd = &isurf_auxcmd;
  258. cs->readisac = &ReadISAC;
  259. cs->writeisac = &WriteISAC;
  260. cs->readisacfifo = &ReadISACfifo;
  261. cs->writeisacfifo = &WriteISACfifo;
  262. cs->bcs[0].hw.isar.reg = &cs->hw.isurf.isar_r;
  263. cs->bcs[1].hw.isar.reg = &cs->hw.isurf.isar_r;
  264. test_and_set_bit(HW_ISAR, &cs->HW_Flags);
  265. ISACVersion(cs, "ISurf:");
  266. cs->BC_Read_Reg = &ReadISAR;
  267. cs->BC_Write_Reg = &WriteISAR;
  268. cs->BC_Send_Data = &isar_fill_fifo;
  269. ver = ISARVersion(cs, "ISurf:");
  270. if (ver < 0) {
  271. printk(KERN_WARNING
  272. "ISurf: wrong ISAR version (ret = %d)\n", ver);
  273. release_io_isurf(cs);
  274. return (0);
  275. }
  276. return (1);
  277. }