hfcscard.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:8k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id: hfcscard.c,v 1.1.4.1 2001/11/20 14:19:35 kai Exp $
  2.  *
  3.  * low level stuff for hfcs based cards (Teles3c, ACER P10)
  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. #define __NO_VERSION__
  13. #include <linux/init.h>
  14. #include <linux/isapnp.h>
  15. #include "hisax.h"
  16. #include "hfc_2bds0.h"
  17. #include "isdnl1.h"
  18. extern const char *CardType[];
  19. static const char *hfcs_revision = "$Revision: 1.1.4.1 $";
  20. static void
  21. hfcs_interrupt(int intno, void *dev_id, struct pt_regs *regs)
  22. {
  23. struct IsdnCardState *cs = dev_id;
  24. u_char val, stat;
  25. if (!cs) {
  26. printk(KERN_WARNING "HFCS: Spurious interrupt!n");
  27. return;
  28. }
  29. if ((HFCD_ANYINT | HFCD_BUSY_NBUSY) & 
  30. (stat = cs->BC_Read_Reg(cs, HFCD_DATA, HFCD_STAT))) {
  31. val = cs->BC_Read_Reg(cs, HFCD_DATA, HFCD_INT_S1);
  32. if (cs->debug & L1_DEB_ISAC)
  33. debugl1(cs, "HFCS: stat(%02x) s1(%02x)", stat, val);
  34. hfc2bds0_interrupt(cs, val);
  35. } else {
  36. if (cs->debug & L1_DEB_ISAC)
  37. debugl1(cs, "HFCS: irq_no_irq stat(%02x)", stat);
  38. }
  39. }
  40. static void
  41. hfcs_Timer(struct IsdnCardState *cs)
  42. {
  43. cs->hw.hfcD.timer.expires = jiffies + 75;
  44. /* WD RESET */
  45. /* WriteReg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt | 0x80);
  46. add_timer(&cs->hw.hfcD.timer);
  47. */
  48. }
  49. void
  50. release_io_hfcs(struct IsdnCardState *cs)
  51. {
  52. release2bds0(cs);
  53. del_timer(&cs->hw.hfcD.timer);
  54. if (cs->hw.hfcD.addr)
  55. release_region(cs->hw.hfcD.addr, 2);
  56. }
  57. static void
  58. reset_hfcs(struct IsdnCardState *cs)
  59. {
  60. long flags;
  61. printk(KERN_INFO "HFCS: resetting cardn");
  62. cs->hw.hfcD.cirm = HFCD_RESET;
  63. if (cs->typ == ISDN_CTYPE_TELES3C)
  64. cs->hw.hfcD.cirm |= HFCD_MEM8K;
  65. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CIRM, cs->hw.hfcD.cirm); /* Reset On */
  66. save_flags(flags);
  67. sti();
  68. set_current_state(TASK_UNINTERRUPTIBLE);
  69. schedule_timeout((30*HZ)/1000);
  70. cs->hw.hfcD.cirm = 0;
  71. if (cs->typ == ISDN_CTYPE_TELES3C)
  72. cs->hw.hfcD.cirm |= HFCD_MEM8K;
  73. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CIRM, cs->hw.hfcD.cirm); /* Reset Off */
  74. set_current_state(TASK_UNINTERRUPTIBLE);
  75. schedule_timeout((10*HZ)/1000);
  76. if (cs->typ == ISDN_CTYPE_TELES3C)
  77. cs->hw.hfcD.cirm |= HFCD_INTB;
  78. else if (cs->typ == ISDN_CTYPE_ACERP10)
  79. cs->hw.hfcD.cirm |= HFCD_INTA;
  80. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CIRM, cs->hw.hfcD.cirm);
  81. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CLKDEL, 0x0e);
  82. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_TEST, HFCD_AUTO_AWAKE); /* S/T Auto awake */
  83. cs->hw.hfcD.ctmt = HFCD_TIM25 | HFCD_AUTO_TIMER;
  84. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt);
  85. cs->hw.hfcD.int_m2 = HFCD_IRQ_ENABLE;
  86. cs->hw.hfcD.int_m1 = HFCD_INTS_B1TRANS | HFCD_INTS_B2TRANS |
  87. HFCD_INTS_DTRANS | HFCD_INTS_B1REC | HFCD_INTS_B2REC |
  88. HFCD_INTS_DREC | HFCD_INTS_L1STATE;
  89. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_INT_M1, cs->hw.hfcD.int_m1);
  90. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_INT_M2, cs->hw.hfcD.int_m2);
  91. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_STATES, HFCD_LOAD_STATE | 2); /* HFC ST 2 */
  92. udelay(10);
  93. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_STATES, 2); /* HFC ST 2 */
  94. cs->hw.hfcD.mst_m = HFCD_MASTER;
  95. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_MST_MODE, cs->hw.hfcD.mst_m); /* HFC Master */
  96. cs->hw.hfcD.sctrl = 0;
  97. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_SCTRL, cs->hw.hfcD.sctrl);
  98. restore_flags(flags);
  99. }
  100. static int
  101. hfcs_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  102. {
  103. long flags;
  104. if (cs->debug & L1_DEB_ISAC)
  105. debugl1(cs, "HFCS: card_msg %x", mt);
  106. switch (mt) {
  107. case CARD_RESET:
  108. reset_hfcs(cs);
  109. return(0);
  110. case CARD_RELEASE:
  111. release_io_hfcs(cs);
  112. return(0);
  113. case CARD_INIT:
  114. cs->hw.hfcD.timer.expires = jiffies + 75;
  115. add_timer(&cs->hw.hfcD.timer);
  116. init2bds0(cs);
  117. save_flags(flags);
  118. sti();
  119. set_current_state(TASK_UNINTERRUPTIBLE);
  120. schedule_timeout((80*HZ)/1000);
  121. cs->hw.hfcD.ctmt |= HFCD_TIM800;
  122. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_CTMT, cs->hw.hfcD.ctmt); 
  123. cs->BC_Write_Reg(cs, HFCD_DATA, HFCD_MST_MODE, cs->hw.hfcD.mst_m);
  124. restore_flags(flags);
  125. return(0);
  126. case CARD_TEST:
  127. return(0);
  128. }
  129. return(0);
  130. }
  131. #ifdef __ISAPNP__
  132. static struct isapnp_device_id hfc_ids[] __initdata = {
  133. { ISAPNP_VENDOR('A', 'N', 'X'), ISAPNP_FUNCTION(0x1114),
  134.   ISAPNP_VENDOR('A', 'N', 'X'), ISAPNP_FUNCTION(0x1114), 
  135.   (unsigned long) "Acer P10" },
  136. { ISAPNP_VENDOR('B', 'I', 'L'), ISAPNP_FUNCTION(0x0002),
  137.   ISAPNP_VENDOR('B', 'I', 'L'), ISAPNP_FUNCTION(0x0002), 
  138.   (unsigned long) "Billion 2" },
  139. { ISAPNP_VENDOR('B', 'I', 'L'), ISAPNP_FUNCTION(0x0001),
  140.   ISAPNP_VENDOR('B', 'I', 'L'), ISAPNP_FUNCTION(0x0001), 
  141.   (unsigned long) "Billion 1" },
  142. { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x7410),
  143.   ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x7410), 
  144.   (unsigned long) "IStar PnP" },
  145. { ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2610),
  146.   ISAPNP_VENDOR('T', 'A', 'G'), ISAPNP_FUNCTION(0x2610), 
  147.   (unsigned long) "Teles 16.3c" },
  148. { ISAPNP_VENDOR('S', 'F', 'M'), ISAPNP_FUNCTION(0x0001),
  149.   ISAPNP_VENDOR('S', 'F', 'M'), ISAPNP_FUNCTION(0x0001), 
  150.   (unsigned long) "Tornado Tipa C" },
  151. { ISAPNP_VENDOR('K', 'Y', 'E'), ISAPNP_FUNCTION(0x0001),
  152.   ISAPNP_VENDOR('K', 'Y', 'E'), ISAPNP_FUNCTION(0x0001), 
  153.   (unsigned long) "Genius Speed Surfer" },
  154. { 0, }
  155. };
  156. static struct isapnp_device_id *hdev = &hfc_ids[0];
  157. static struct pci_bus *pnp_c __devinitdata = NULL;
  158. #endif
  159. int __init
  160. setup_hfcs(struct IsdnCard *card)
  161. {
  162. struct IsdnCardState *cs = card->cs;
  163. char tmp[64];
  164. strcpy(tmp, hfcs_revision);
  165. printk(KERN_INFO "HiSax: HFC-S driver Rev. %sn", HiSax_getrev(tmp));
  166. #ifdef __ISAPNP__
  167. if (!card->para[1] && isapnp_present()) {
  168. struct pci_bus *pb;
  169. struct pci_dev *pd;
  170. while(hdev->card_vendor) {
  171. if ((pb = isapnp_find_card(hdev->card_vendor,
  172. hdev->card_device, pnp_c))) {
  173. pnp_c = pb;
  174. pd = NULL;
  175. if ((pd = isapnp_find_dev(pnp_c,
  176. hdev->vendor, hdev->function, pd))) {
  177. printk(KERN_INFO "HiSax: %s detectedn",
  178. (char *)hdev->driver_data);
  179. pd->prepare(pd);
  180. pd->deactivate(pd);
  181. pd->activate(pd);
  182. card->para[1] = pd->resource[0].start;
  183. card->para[0] = pd->irq_resource[0].start;
  184. if (!card->para[0] || !card->para[1]) {
  185. printk(KERN_ERR "HFC PnP:some resources are missing %ld/%lxn",
  186. card->para[0], card->para[1]);
  187. pd->deactivate(pd);
  188. return(0);
  189. }
  190. break;
  191. } else {
  192. printk(KERN_ERR "HFC PnP: PnP error card found, no devicen");
  193. }
  194. }
  195. hdev++;
  196. pnp_c=NULL;
  197. if (!hdev->card_vendor) {
  198. printk(KERN_INFO "HFC PnP: no ISAPnP card foundn");
  199. return(0);
  200. }
  201. }
  202. #endif
  203. cs->hw.hfcD.addr = card->para[1] & 0xfffe;
  204. cs->irq = card->para[0];
  205. cs->hw.hfcD.cip = 0;
  206. cs->hw.hfcD.int_s1 = 0;
  207. cs->hw.hfcD.send = NULL;
  208. cs->bcs[0].hw.hfc.send = NULL;
  209. cs->bcs[1].hw.hfc.send = NULL;
  210. cs->hw.hfcD.dfifosize = 512;
  211. cs->dc.hfcd.ph_state = 0;
  212. cs->hw.hfcD.fifo = 255;
  213. if (cs->typ == ISDN_CTYPE_TELES3C) {
  214. cs->hw.hfcD.bfifosize = 1024 + 512;
  215. } else if (cs->typ == ISDN_CTYPE_ACERP10) {
  216. cs->hw.hfcD.bfifosize = 7*1024 + 512;
  217. } else
  218. return (0);
  219. if (check_region((cs->hw.hfcD.addr), 2)) {
  220. printk(KERN_WARNING
  221.        "HiSax: %s config port %x-%x already in usen",
  222.        CardType[card->typ],
  223.        cs->hw.hfcD.addr,
  224.        cs->hw.hfcD.addr + 2);
  225. return (0);
  226. } else {
  227. request_region(cs->hw.hfcD.addr, 2, "HFCS isdn");
  228. }
  229. printk(KERN_INFO
  230.        "HFCS: defined at 0x%x IRQ %d HZ %dn",
  231.        cs->hw.hfcD.addr,
  232.        cs->irq, HZ);
  233. if (cs->typ == ISDN_CTYPE_TELES3C) {
  234. /* Teles 16.3c IO ADR is 0x200 | YY0U (YY Bit 15/14 address) */
  235. outb(0x00, cs->hw.hfcD.addr);
  236. outb(0x56, cs->hw.hfcD.addr | 1);
  237. } else if (cs->typ == ISDN_CTYPE_ACERP10) {
  238. /* Acer P10 IO ADR is 0x300 */
  239. outb(0x00, cs->hw.hfcD.addr);
  240. outb(0x57, cs->hw.hfcD.addr | 1);
  241. }
  242. set_cs_func(cs);
  243. cs->hw.hfcD.timer.function = (void *) hfcs_Timer;
  244. cs->hw.hfcD.timer.data = (long) cs;
  245. init_timer(&cs->hw.hfcD.timer);
  246. reset_hfcs(cs);
  247. cs->cardmsg = &hfcs_card_msg;
  248. cs->irq_func = &hfcs_interrupt;
  249. return (1);
  250. }