telespci.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:9k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /* $Id: telespci.c,v 1.1.4.1 2001/11/20 14:19:36 kai Exp $
  2.  *
  3.  * low level stuff for Teles PCI isdn cards
  4.  *
  5.  * Author       Ton van Rosmalen
  6.  *              Karsten Keil
  7.  * Copyright    by Ton van Rosmalen
  8.  *              by Karsten Keil      <keil@isdn4linux.de>
  9.  * 
  10.  * This software may be used and distributed according to the terms
  11.  * of the GNU General Public License, incorporated herein by reference.
  12.  *
  13.  */
  14. #define __NO_VERSION__
  15. #include <linux/init.h>
  16. #include <linux/config.h>
  17. #include "hisax.h"
  18. #include "isac.h"
  19. #include "hscx.h"
  20. #include "isdnl1.h"
  21. #include <linux/pci.h>
  22. extern const char *CardType[];
  23. const char *telespci_revision = "$Revision: 1.1.4.1 $";
  24. #define ZORAN_PO_RQ_PEN 0x02000000
  25. #define ZORAN_PO_WR 0x00800000
  26. #define ZORAN_PO_GID0 0x00000000
  27. #define ZORAN_PO_GID1 0x00100000
  28. #define ZORAN_PO_GREG0 0x00000000
  29. #define ZORAN_PO_GREG1 0x00010000
  30. #define ZORAN_PO_DMASK 0xFF
  31. #define WRITE_ADDR_ISAC (ZORAN_PO_WR | ZORAN_PO_GID0 | ZORAN_PO_GREG0)
  32. #define READ_DATA_ISAC (ZORAN_PO_GID0 | ZORAN_PO_GREG1)
  33. #define WRITE_DATA_ISAC (ZORAN_PO_WR | ZORAN_PO_GID0 | ZORAN_PO_GREG1)
  34. #define WRITE_ADDR_HSCX (ZORAN_PO_WR | ZORAN_PO_GID1 | ZORAN_PO_GREG0)
  35. #define READ_DATA_HSCX (ZORAN_PO_GID1 | ZORAN_PO_GREG1)
  36. #define WRITE_DATA_HSCX (ZORAN_PO_WR | ZORAN_PO_GID1 | ZORAN_PO_GREG1)
  37. #define ZORAN_WAIT_NOBUSY do { 
  38. portdata = readl(adr + 0x200); 
  39. } while (portdata & ZORAN_PO_RQ_PEN)
  40. static inline u_char
  41. readisac(unsigned long adr, u_char off)
  42. {
  43. register unsigned int portdata;
  44. ZORAN_WAIT_NOBUSY;
  45. /* set address for ISAC */
  46. writel(WRITE_ADDR_ISAC | off, adr + 0x200);
  47. ZORAN_WAIT_NOBUSY;
  48. /* read data from ISAC */
  49. writel(READ_DATA_ISAC, adr + 0x200);
  50. ZORAN_WAIT_NOBUSY;
  51. return((u_char)(portdata & ZORAN_PO_DMASK));
  52. }
  53. static inline void
  54. writeisac(unsigned long adr, u_char off, u_char data)
  55. {
  56. register unsigned int portdata;
  57. ZORAN_WAIT_NOBUSY;
  58. /* set address for ISAC */
  59. writel(WRITE_ADDR_ISAC | off, adr + 0x200);
  60. ZORAN_WAIT_NOBUSY;
  61. /* write data to ISAC */
  62. writel(WRITE_DATA_ISAC | data, adr + 0x200);
  63. ZORAN_WAIT_NOBUSY;
  64. }
  65. static inline u_char
  66. readhscx(unsigned long adr, int hscx, u_char off)
  67. {
  68. register unsigned int portdata;
  69. ZORAN_WAIT_NOBUSY;
  70. /* set address for HSCX */
  71. writel(WRITE_ADDR_HSCX | ((hscx ? 0x40:0) + off), adr + 0x200);
  72. ZORAN_WAIT_NOBUSY;
  73. /* read data from HSCX */
  74. writel(READ_DATA_HSCX, adr + 0x200);
  75. ZORAN_WAIT_NOBUSY;
  76. return ((u_char)(portdata & ZORAN_PO_DMASK));
  77. }
  78. static inline void
  79. writehscx(unsigned long adr, int hscx, u_char off, u_char data)
  80. {
  81. register unsigned int portdata;
  82. ZORAN_WAIT_NOBUSY;
  83. /* set address for HSCX */
  84. writel(WRITE_ADDR_HSCX | ((hscx ? 0x40:0) + off), adr + 0x200);
  85. ZORAN_WAIT_NOBUSY;
  86. /* write data to HSCX */
  87. writel(WRITE_DATA_HSCX | data, adr + 0x200);
  88. ZORAN_WAIT_NOBUSY;
  89. }
  90. static inline void
  91. read_fifo_isac(unsigned long adr, u_char * data, int size)
  92. {
  93. register unsigned int portdata;
  94. register int i;
  95. ZORAN_WAIT_NOBUSY;
  96. /* read data from ISAC */
  97. for (i = 0; i < size; i++) {
  98. /* set address for ISAC fifo */
  99. writel(WRITE_ADDR_ISAC | 0x1E, adr + 0x200);
  100. ZORAN_WAIT_NOBUSY;
  101. writel(READ_DATA_ISAC, adr + 0x200);
  102. ZORAN_WAIT_NOBUSY;
  103. data[i] = (u_char)(portdata & ZORAN_PO_DMASK);
  104. }
  105. }
  106. static void
  107. write_fifo_isac(unsigned long adr, u_char * data, int size)
  108. {
  109. register unsigned int portdata;
  110. register int i;
  111. ZORAN_WAIT_NOBUSY;
  112. /* write data to ISAC */
  113. for (i = 0; i < size; i++) {
  114. /* set address for ISAC fifo */
  115. writel(WRITE_ADDR_ISAC | 0x1E, adr + 0x200);
  116. ZORAN_WAIT_NOBUSY;
  117. writel(WRITE_DATA_ISAC | data[i], adr + 0x200);
  118. ZORAN_WAIT_NOBUSY;
  119. }
  120. }
  121. static inline void
  122. read_fifo_hscx(unsigned long adr, int hscx, u_char * data, int size)
  123. {
  124. register unsigned int portdata;
  125. register int i;
  126. ZORAN_WAIT_NOBUSY;
  127. /* read data from HSCX */
  128. for (i = 0; i < size; i++) {
  129. /* set address for HSCX fifo */
  130. writel(WRITE_ADDR_HSCX |(hscx ? 0x5F:0x1F), adr + 0x200);
  131. ZORAN_WAIT_NOBUSY;
  132. writel(READ_DATA_HSCX, adr + 0x200);
  133. ZORAN_WAIT_NOBUSY;
  134. data[i] = (u_char) (portdata & ZORAN_PO_DMASK);
  135. }
  136. }
  137. static inline void
  138. write_fifo_hscx(unsigned long adr, int hscx, u_char * data, int size)
  139. {
  140. unsigned int portdata;
  141. register int i;
  142. ZORAN_WAIT_NOBUSY;
  143. /* write data to HSCX */
  144. for (i = 0; i < size; i++) {
  145. /* set address for HSCX fifo */
  146. writel(WRITE_ADDR_HSCX |(hscx ? 0x5F:0x1F), adr + 0x200);
  147. ZORAN_WAIT_NOBUSY;
  148. writel(WRITE_DATA_HSCX | data[i], adr + 0x200);
  149. ZORAN_WAIT_NOBUSY;
  150. udelay(10);
  151. }
  152. }
  153. /* Interface functions */
  154. static u_char
  155. ReadISAC(struct IsdnCardState *cs, u_char offset)
  156. {
  157. return (readisac(cs->hw.teles0.membase, offset));
  158. }
  159. static void
  160. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  161. {
  162. writeisac(cs->hw.teles0.membase, offset, value);
  163. }
  164. static void
  165. ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  166. {
  167. read_fifo_isac(cs->hw.teles0.membase, data, size);
  168. }
  169. static void
  170. WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  171. {
  172. write_fifo_isac(cs->hw.teles0.membase, data, size);
  173. }
  174. static u_char
  175. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  176. {
  177. return (readhscx(cs->hw.teles0.membase, hscx, offset));
  178. }
  179. static void
  180. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  181. {
  182. writehscx(cs->hw.teles0.membase, hscx, offset, value);
  183. }
  184. /*
  185.  * fast interrupt HSCX stuff goes here
  186.  */
  187. #define READHSCX(cs, nr, reg) readhscx(cs->hw.teles0.membase, nr, reg)
  188. #define WRITEHSCX(cs, nr, reg, data) writehscx(cs->hw.teles0.membase, nr, reg, data)
  189. #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo_hscx(cs->hw.teles0.membase, nr, ptr, cnt)
  190. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo_hscx(cs->hw.teles0.membase, nr, ptr, cnt)
  191. #include "hscx_irq.c"
  192. static void
  193. telespci_interrupt(int intno, void *dev_id, struct pt_regs *regs)
  194. {
  195. #define MAXCOUNT 20
  196. struct IsdnCardState *cs = dev_id;
  197. u_char val;
  198. if (!cs) {
  199. printk(KERN_WARNING "TelesPCI: Spurious interrupt!n");
  200. return;
  201. }
  202. val = readhscx(cs->hw.teles0.membase, 1, HSCX_ISTA);
  203. if (val)
  204. hscx_int_main(cs, val);
  205. val = readisac(cs->hw.teles0.membase, ISAC_ISTA);
  206. if (val)
  207. isac_interrupt(cs, val);
  208. /* Clear interrupt register for Zoran PCI controller */
  209. writel(0x70000000, cs->hw.teles0.membase + 0x3C);
  210. writehscx(cs->hw.teles0.membase, 0, HSCX_MASK, 0xFF);
  211. writehscx(cs->hw.teles0.membase, 1, HSCX_MASK, 0xFF);
  212. writeisac(cs->hw.teles0.membase, ISAC_MASK, 0xFF);
  213. writeisac(cs->hw.teles0.membase, ISAC_MASK, 0x0);
  214. writehscx(cs->hw.teles0.membase, 0, HSCX_MASK, 0x0);
  215. writehscx(cs->hw.teles0.membase, 1, HSCX_MASK, 0x0);
  216. }
  217. void
  218. release_io_telespci(struct IsdnCardState *cs)
  219. {
  220. iounmap((void *)cs->hw.teles0.membase);
  221. }
  222. static int
  223. TelesPCI_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  224. {
  225. switch (mt) {
  226. case CARD_RESET:
  227. return(0);
  228. case CARD_RELEASE:
  229. release_io_telespci(cs);
  230. return(0);
  231. case CARD_INIT:
  232. inithscxisac(cs, 3);
  233. return(0);
  234. case CARD_TEST:
  235. return(0);
  236. }
  237. return(0);
  238. }
  239. static struct pci_dev *dev_tel __initdata = NULL;
  240. int __init
  241. setup_telespci(struct IsdnCard *card)
  242. {
  243. struct IsdnCardState *cs = card->cs;
  244. char tmp[64];
  245. #ifdef __BIG_ENDIAN
  246. #error "not running on big endian machines now"
  247. #endif
  248. strcpy(tmp, telespci_revision);
  249. printk(KERN_INFO "HiSax: Teles/PCI driver Rev. %sn", HiSax_getrev(tmp));
  250. if (cs->typ != ISDN_CTYPE_TELESPCI)
  251. return (0);
  252. #if CONFIG_PCI
  253. if (!pci_present()) {
  254. printk(KERN_ERR "TelesPCI: no PCI bus presentn");
  255. return(0);
  256. }
  257. if ((dev_tel = pci_find_device (PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36120, dev_tel))) {
  258. if (pci_enable_device(dev_tel))
  259. return(0);
  260. cs->irq = dev_tel->irq;
  261. if (!cs->irq) {
  262. printk(KERN_WARNING "Teles: No IRQ for PCI card foundn");
  263. return(0);
  264. }
  265. cs->hw.teles0.membase = (u_long) ioremap(pci_resource_start(dev_tel, 0),
  266. PAGE_SIZE);
  267. printk(KERN_INFO "Found: Zoran, base-address: 0x%lx, irq: 0x%xn",
  268. pci_resource_start(dev_tel, 0), dev_tel->irq);
  269. } else {
  270. printk(KERN_WARNING "TelesPCI: No PCI card foundn");
  271. return(0);
  272. }
  273. #else
  274. printk(KERN_WARNING "HiSax: Teles/PCI and NO_PCI_BIOSn");
  275. printk(KERN_WARNING "HiSax: Teles/PCI unable to confign");
  276. return (0);
  277. #endif /* CONFIG_PCI */
  278. /* Initialize Zoran PCI controller */
  279. writel(0x00000000, cs->hw.teles0.membase + 0x28);
  280. writel(0x01000000, cs->hw.teles0.membase + 0x28);
  281. writel(0x01000000, cs->hw.teles0.membase + 0x28);
  282. writel(0x7BFFFFFF, cs->hw.teles0.membase + 0x2C);
  283. writel(0x70000000, cs->hw.teles0.membase + 0x3C);
  284. writel(0x61000000, cs->hw.teles0.membase + 0x40);
  285. /* writel(0x00800000, cs->hw.teles0.membase + 0x200); */
  286. printk(KERN_INFO
  287.        "HiSax: %s config irq:%d mem:%lxn",
  288.        CardType[cs->typ], cs->irq,
  289.        cs->hw.teles0.membase);
  290. cs->readisac = &ReadISAC;
  291. cs->writeisac = &WriteISAC;
  292. cs->readisacfifo = &ReadISACfifo;
  293. cs->writeisacfifo = &WriteISACfifo;
  294. cs->BC_Read_Reg = &ReadHSCX;
  295. cs->BC_Write_Reg = &WriteHSCX;
  296. cs->BC_Send_Data = &hscx_fill_fifo;
  297. cs->cardmsg = &TelesPCI_card_msg;
  298. cs->irq_func = &telespci_interrupt;
  299. cs->irq_flags |= SA_SHIRQ;
  300. ISACVersion(cs, "TelesPCI:");
  301. if (HscxVersion(cs, "TelesPCI:")) {
  302. printk(KERN_WARNING
  303.  "TelesPCI: wrong HSCX versions check IO/MEM addressesn");
  304. release_io_telespci(cs);
  305. return (0);
  306. }
  307. return (1);
  308. }