telespci.c 8.9 KB

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