bkm_a8.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. /* $Id: bkm_a8.c,v 1.22.2.4 2004/01/15 14:02:34 keil Exp $
  2. *
  3. * low level stuff for Scitel Quadro (4*S0, passive)
  4. *
  5. * Author Roland Klabunde
  6. * Copyright by Roland Klabunde <R.Klabunde@Berkom.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 "ipac.h"
  16. #include "hscx.h"
  17. #include "isdnl1.h"
  18. #include <linux/pci.h>
  19. #include "bkm_ax.h"
  20. #define ATTEMPT_PCI_REMAPPING /* Required for PLX rev 1 */
  21. static const char sct_quadro_revision[] = "$Revision: 1.22.2.4 $";
  22. static const char *sct_quadro_subtypes[] =
  23. {
  24. "",
  25. "#1",
  26. "#2",
  27. "#3",
  28. "#4"
  29. };
  30. #define wordout(addr,val) outw(val,addr)
  31. #define wordin(addr) inw(addr)
  32. static inline u_char
  33. readreg(unsigned int ale, unsigned int adr, u_char off)
  34. {
  35. register u_char ret;
  36. wordout(ale, off);
  37. ret = wordin(adr) & 0xFF;
  38. return (ret);
  39. }
  40. static inline void
  41. readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
  42. {
  43. int i;
  44. wordout(ale, off);
  45. for (i = 0; i < size; i++)
  46. data[i] = wordin(adr) & 0xFF;
  47. }
  48. static inline void
  49. writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
  50. {
  51. wordout(ale, off);
  52. wordout(adr, data);
  53. }
  54. static inline void
  55. writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
  56. {
  57. int i;
  58. wordout(ale, off);
  59. for (i = 0; i < size; i++)
  60. wordout(adr, data[i]);
  61. }
  62. /* Interface functions */
  63. static u_char
  64. ReadISAC(struct IsdnCardState *cs, u_char offset)
  65. {
  66. return (readreg(cs->hw.ax.base, cs->hw.ax.data_adr, offset | 0x80));
  67. }
  68. static void
  69. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  70. {
  71. writereg(cs->hw.ax.base, cs->hw.ax.data_adr, offset | 0x80, value);
  72. }
  73. static void
  74. ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  75. {
  76. readfifo(cs->hw.ax.base, cs->hw.ax.data_adr, 0x80, data, size);
  77. }
  78. static void
  79. WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  80. {
  81. writefifo(cs->hw.ax.base, cs->hw.ax.data_adr, 0x80, data, size);
  82. }
  83. static u_char
  84. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  85. {
  86. return (readreg(cs->hw.ax.base, cs->hw.ax.data_adr, offset + (hscx ? 0x40 : 0)));
  87. }
  88. static void
  89. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  90. {
  91. writereg(cs->hw.ax.base, cs->hw.ax.data_adr, offset + (hscx ? 0x40 : 0), value);
  92. }
  93. /* Set the specific ipac to active */
  94. static void
  95. set_ipac_active(struct IsdnCardState *cs, u_int active)
  96. {
  97. /* set irq mask */
  98. writereg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_MASK,
  99. active ? 0xc0 : 0xff);
  100. }
  101. /*
  102. * fast interrupt HSCX stuff goes here
  103. */
  104. #define READHSCX(cs, nr, reg) readreg(cs->hw.ax.base, \
  105. cs->hw.ax.data_adr, reg + (nr ? 0x40 : 0))
  106. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.ax.base, \
  107. cs->hw.ax.data_adr, reg + (nr ? 0x40 : 0), data)
  108. #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.ax.base, \
  109. cs->hw.ax.data_adr, (nr ? 0x40 : 0), ptr, cnt)
  110. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.ax.base, \
  111. cs->hw.ax.data_adr, (nr ? 0x40 : 0), ptr, cnt)
  112. #include "hscx_irq.c"
  113. static irqreturn_t
  114. bkm_interrupt_ipac(int intno, void *dev_id)
  115. {
  116. struct IsdnCardState *cs = dev_id;
  117. u_char ista, val, icnt = 5;
  118. u_long flags;
  119. spin_lock_irqsave(&cs->lock, flags);
  120. ista = readreg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_ISTA);
  121. if (!(ista & 0x3f)) { /* not this IPAC */
  122. spin_unlock_irqrestore(&cs->lock, flags);
  123. return IRQ_NONE;
  124. }
  125. Start_IPAC:
  126. if (cs->debug & L1_DEB_IPAC)
  127. debugl1(cs, "IPAC ISTA %02X", ista);
  128. if (ista & 0x0f) {
  129. val = readreg(cs->hw.ax.base, cs->hw.ax.data_adr, HSCX_ISTA + 0x40);
  130. if (ista & 0x01)
  131. val |= 0x01;
  132. if (ista & 0x04)
  133. val |= 0x02;
  134. if (ista & 0x08)
  135. val |= 0x04;
  136. if (val) {
  137. hscx_int_main(cs, val);
  138. }
  139. }
  140. if (ista & 0x20) {
  141. val = 0xfe & readreg(cs->hw.ax.base, cs->hw.ax.data_adr, ISAC_ISTA | 0x80);
  142. if (val) {
  143. isac_interrupt(cs, val);
  144. }
  145. }
  146. if (ista & 0x10) {
  147. val = 0x01;
  148. isac_interrupt(cs, val);
  149. }
  150. ista = readreg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_ISTA);
  151. if ((ista & 0x3f) && icnt) {
  152. icnt--;
  153. goto Start_IPAC;
  154. }
  155. if (!icnt)
  156. printk(KERN_WARNING "HiSax: Scitel Quadro (%s) IRQ LOOP\n",
  157. sct_quadro_subtypes[cs->subtyp]);
  158. writereg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_MASK, 0xFF);
  159. writereg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_MASK, 0xC0);
  160. spin_unlock_irqrestore(&cs->lock, flags);
  161. return IRQ_HANDLED;
  162. }
  163. static void
  164. release_io_sct_quadro(struct IsdnCardState *cs)
  165. {
  166. release_region(cs->hw.ax.base & 0xffffffc0, 128);
  167. if (cs->subtyp == SCT_1)
  168. release_region(cs->hw.ax.plx_adr, 64);
  169. }
  170. static void
  171. enable_bkm_int(struct IsdnCardState *cs, unsigned bEnable)
  172. {
  173. if (cs->typ == ISDN_CTYPE_SCT_QUADRO) {
  174. if (bEnable)
  175. wordout(cs->hw.ax.plx_adr + 0x4C, (wordin(cs->hw.ax.plx_adr + 0x4C) | 0x41));
  176. else
  177. wordout(cs->hw.ax.plx_adr + 0x4C, (wordin(cs->hw.ax.plx_adr + 0x4C) & ~0x41));
  178. }
  179. }
  180. static void
  181. reset_bkm(struct IsdnCardState *cs)
  182. {
  183. if (cs->subtyp == SCT_1) {
  184. wordout(cs->hw.ax.plx_adr + 0x50, (wordin(cs->hw.ax.plx_adr + 0x50) & ~4));
  185. mdelay(10);
  186. /* Remove the soft reset */
  187. wordout(cs->hw.ax.plx_adr + 0x50, (wordin(cs->hw.ax.plx_adr + 0x50) | 4));
  188. mdelay(10);
  189. }
  190. }
  191. static int
  192. BKM_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  193. {
  194. u_long flags;
  195. switch (mt) {
  196. case CARD_RESET:
  197. spin_lock_irqsave(&cs->lock, flags);
  198. /* Disable ints */
  199. set_ipac_active(cs, 0);
  200. enable_bkm_int(cs, 0);
  201. reset_bkm(cs);
  202. spin_unlock_irqrestore(&cs->lock, flags);
  203. return (0);
  204. case CARD_RELEASE:
  205. /* Sanity */
  206. spin_lock_irqsave(&cs->lock, flags);
  207. set_ipac_active(cs, 0);
  208. enable_bkm_int(cs, 0);
  209. spin_unlock_irqrestore(&cs->lock, flags);
  210. release_io_sct_quadro(cs);
  211. return (0);
  212. case CARD_INIT:
  213. spin_lock_irqsave(&cs->lock, flags);
  214. cs->debug |= L1_DEB_IPAC;
  215. set_ipac_active(cs, 1);
  216. inithscxisac(cs, 3);
  217. /* Enable ints */
  218. enable_bkm_int(cs, 1);
  219. spin_unlock_irqrestore(&cs->lock, flags);
  220. return (0);
  221. case CARD_TEST:
  222. return (0);
  223. }
  224. return (0);
  225. }
  226. static int __devinit
  227. sct_alloc_io(u_int adr, u_int len)
  228. {
  229. if (!request_region(adr, len, "scitel")) {
  230. printk(KERN_WARNING
  231. "HiSax: Scitel port %#x-%#x already in use\n",
  232. adr, adr + len);
  233. return (1);
  234. }
  235. return(0);
  236. }
  237. static struct pci_dev *dev_a8 __devinitdata = NULL;
  238. static u16 sub_vendor_id __devinitdata = 0;
  239. static u16 sub_sys_id __devinitdata = 0;
  240. static u_char pci_bus __devinitdata = 0;
  241. static u_char pci_device_fn __devinitdata = 0;
  242. static u_char pci_irq __devinitdata = 0;
  243. int __devinit
  244. setup_sct_quadro(struct IsdnCard *card)
  245. {
  246. struct IsdnCardState *cs = card->cs;
  247. char tmp[64];
  248. u_int found = 0;
  249. u_int pci_ioaddr1, pci_ioaddr2, pci_ioaddr3, pci_ioaddr4, pci_ioaddr5;
  250. strcpy(tmp, sct_quadro_revision);
  251. printk(KERN_INFO "HiSax: T-Berkom driver Rev. %s\n", HiSax_getrev(tmp));
  252. if (cs->typ == ISDN_CTYPE_SCT_QUADRO) {
  253. cs->subtyp = SCT_1; /* Preset */
  254. } else
  255. return (0);
  256. /* Identify subtype by para[0] */
  257. if (card->para[0] >= SCT_1 && card->para[0] <= SCT_4)
  258. cs->subtyp = card->para[0];
  259. else {
  260. printk(KERN_WARNING "HiSax: Scitel Quadro: Invalid "
  261. "subcontroller in configuration, default to 1\n");
  262. return (0);
  263. }
  264. if ((cs->subtyp != SCT_1) && ((sub_sys_id != PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO) ||
  265. (sub_vendor_id != PCI_VENDOR_ID_BERKOM)))
  266. return (0);
  267. if (cs->subtyp == SCT_1) {
  268. while ((dev_a8 = hisax_find_pci_device(PCI_VENDOR_ID_PLX,
  269. PCI_DEVICE_ID_PLX_9050, dev_a8))) {
  270. sub_vendor_id = dev_a8->subsystem_vendor;
  271. sub_sys_id = dev_a8->subsystem_device;
  272. if ((sub_sys_id == PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO) &&
  273. (sub_vendor_id == PCI_VENDOR_ID_BERKOM)) {
  274. if (pci_enable_device(dev_a8))
  275. return(0);
  276. pci_ioaddr1 = pci_resource_start(dev_a8, 1);
  277. pci_irq = dev_a8->irq;
  278. pci_bus = dev_a8->bus->number;
  279. pci_device_fn = dev_a8->devfn;
  280. found = 1;
  281. break;
  282. }
  283. }
  284. if (!found) {
  285. printk(KERN_WARNING "HiSax: Scitel Quadro (%s): "
  286. "Card not found\n",
  287. sct_quadro_subtypes[cs->subtyp]);
  288. return (0);
  289. }
  290. #ifdef ATTEMPT_PCI_REMAPPING
  291. /* HACK: PLX revision 1 bug: PLX address bit 7 must not be set */
  292. if ((pci_ioaddr1 & 0x80) && (dev_a8->revision == 1)) {
  293. printk(KERN_WARNING "HiSax: Scitel Quadro (%s): "
  294. "PLX rev 1, remapping required!\n",
  295. sct_quadro_subtypes[cs->subtyp]);
  296. /* Restart PCI negotiation */
  297. pci_write_config_dword(dev_a8, PCI_BASE_ADDRESS_1, (u_int) - 1);
  298. /* Move up by 0x80 byte */
  299. pci_ioaddr1 += 0x80;
  300. pci_ioaddr1 &= PCI_BASE_ADDRESS_IO_MASK;
  301. pci_write_config_dword(dev_a8, PCI_BASE_ADDRESS_1, pci_ioaddr1);
  302. dev_a8->resource[ 1].start = pci_ioaddr1;
  303. }
  304. #endif /* End HACK */
  305. }
  306. if (!pci_irq) { /* IRQ range check ?? */
  307. printk(KERN_WARNING "HiSax: Scitel Quadro (%s): No IRQ\n",
  308. sct_quadro_subtypes[cs->subtyp]);
  309. return (0);
  310. }
  311. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_1, &pci_ioaddr1);
  312. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_2, &pci_ioaddr2);
  313. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_3, &pci_ioaddr3);
  314. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_4, &pci_ioaddr4);
  315. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_5, &pci_ioaddr5);
  316. if (!pci_ioaddr1 || !pci_ioaddr2 || !pci_ioaddr3 || !pci_ioaddr4 || !pci_ioaddr5) {
  317. printk(KERN_WARNING "HiSax: Scitel Quadro (%s): "
  318. "No IO base address(es)\n",
  319. sct_quadro_subtypes[cs->subtyp]);
  320. return (0);
  321. }
  322. pci_ioaddr1 &= PCI_BASE_ADDRESS_IO_MASK;
  323. pci_ioaddr2 &= PCI_BASE_ADDRESS_IO_MASK;
  324. pci_ioaddr3 &= PCI_BASE_ADDRESS_IO_MASK;
  325. pci_ioaddr4 &= PCI_BASE_ADDRESS_IO_MASK;
  326. pci_ioaddr5 &= PCI_BASE_ADDRESS_IO_MASK;
  327. /* Take over */
  328. cs->irq = pci_irq;
  329. cs->irq_flags |= IRQF_SHARED;
  330. /* pci_ioaddr1 is unique to all subdevices */
  331. /* pci_ioaddr2 is for the fourth subdevice only */
  332. /* pci_ioaddr3 is for the third subdevice only */
  333. /* pci_ioaddr4 is for the second subdevice only */
  334. /* pci_ioaddr5 is for the first subdevice only */
  335. cs->hw.ax.plx_adr = pci_ioaddr1;
  336. /* Enter all ipac_base addresses */
  337. switch(cs->subtyp) {
  338. case 1:
  339. cs->hw.ax.base = pci_ioaddr5 + 0x00;
  340. if (sct_alloc_io(pci_ioaddr1, 128))
  341. return(0);
  342. if (sct_alloc_io(pci_ioaddr5, 64))
  343. return(0);
  344. /* disable all IPAC */
  345. writereg(pci_ioaddr5, pci_ioaddr5 + 4,
  346. IPAC_MASK, 0xFF);
  347. writereg(pci_ioaddr4 + 0x08, pci_ioaddr4 + 0x0c,
  348. IPAC_MASK, 0xFF);
  349. writereg(pci_ioaddr3 + 0x10, pci_ioaddr3 + 0x14,
  350. IPAC_MASK, 0xFF);
  351. writereg(pci_ioaddr2 + 0x20, pci_ioaddr2 + 0x24,
  352. IPAC_MASK, 0xFF);
  353. break;
  354. case 2:
  355. cs->hw.ax.base = pci_ioaddr4 + 0x08;
  356. if (sct_alloc_io(pci_ioaddr4, 64))
  357. return(0);
  358. break;
  359. case 3:
  360. cs->hw.ax.base = pci_ioaddr3 + 0x10;
  361. if (sct_alloc_io(pci_ioaddr3, 64))
  362. return(0);
  363. break;
  364. case 4:
  365. cs->hw.ax.base = pci_ioaddr2 + 0x20;
  366. if (sct_alloc_io(pci_ioaddr2, 64))
  367. return(0);
  368. break;
  369. }
  370. /* For isac and hscx data path */
  371. cs->hw.ax.data_adr = cs->hw.ax.base + 4;
  372. printk(KERN_INFO "HiSax: Scitel Quadro (%s) configured at "
  373. "0x%.4lX, 0x%.4lX, 0x%.4lX and IRQ %d\n",
  374. sct_quadro_subtypes[cs->subtyp],
  375. cs->hw.ax.plx_adr,
  376. cs->hw.ax.base,
  377. cs->hw.ax.data_adr,
  378. cs->irq);
  379. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  380. cs->readisac = &ReadISAC;
  381. cs->writeisac = &WriteISAC;
  382. cs->readisacfifo = &ReadISACfifo;
  383. cs->writeisacfifo = &WriteISACfifo;
  384. cs->BC_Read_Reg = &ReadHSCX;
  385. cs->BC_Write_Reg = &WriteHSCX;
  386. cs->BC_Send_Data = &hscx_fill_fifo;
  387. cs->cardmsg = &BKM_card_msg;
  388. cs->irq_func = &bkm_interrupt_ipac;
  389. printk(KERN_INFO "HiSax: Scitel Quadro (%s): IPAC Version %d\n",
  390. sct_quadro_subtypes[cs->subtyp],
  391. readreg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_ID));
  392. return (1);
  393. }