bkm_a8.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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 sct_alloc_io(u_int adr, u_int len)
  227. {
  228. if (!request_region(adr, len, "scitel")) {
  229. printk(KERN_WARNING
  230. "HiSax: Scitel port %#x-%#x already in use\n",
  231. adr, adr + len);
  232. return (1);
  233. }
  234. return (0);
  235. }
  236. static struct pci_dev *dev_a8 = NULL;
  237. static u16 sub_vendor_id = 0;
  238. static u16 sub_sys_id = 0;
  239. static u_char pci_bus = 0;
  240. static u_char pci_device_fn = 0;
  241. static u_char pci_irq = 0;
  242. int setup_sct_quadro(struct IsdnCard *card)
  243. {
  244. struct IsdnCardState *cs = card->cs;
  245. char tmp[64];
  246. u_int found = 0;
  247. u_int pci_ioaddr1, pci_ioaddr2, pci_ioaddr3, pci_ioaddr4, pci_ioaddr5;
  248. strcpy(tmp, sct_quadro_revision);
  249. printk(KERN_INFO "HiSax: T-Berkom driver Rev. %s\n", HiSax_getrev(tmp));
  250. if (cs->typ == ISDN_CTYPE_SCT_QUADRO) {
  251. cs->subtyp = SCT_1; /* Preset */
  252. } else
  253. return (0);
  254. /* Identify subtype by para[0] */
  255. if (card->para[0] >= SCT_1 && card->para[0] <= SCT_4)
  256. cs->subtyp = card->para[0];
  257. else {
  258. printk(KERN_WARNING "HiSax: Scitel Quadro: Invalid "
  259. "subcontroller in configuration, default to 1\n");
  260. return (0);
  261. }
  262. if ((cs->subtyp != SCT_1) && ((sub_sys_id != PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO) ||
  263. (sub_vendor_id != PCI_VENDOR_ID_BERKOM)))
  264. return (0);
  265. if (cs->subtyp == SCT_1) {
  266. while ((dev_a8 = hisax_find_pci_device(PCI_VENDOR_ID_PLX,
  267. PCI_DEVICE_ID_PLX_9050, dev_a8))) {
  268. sub_vendor_id = dev_a8->subsystem_vendor;
  269. sub_sys_id = dev_a8->subsystem_device;
  270. if ((sub_sys_id == PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO) &&
  271. (sub_vendor_id == PCI_VENDOR_ID_BERKOM)) {
  272. if (pci_enable_device(dev_a8))
  273. return (0);
  274. pci_ioaddr1 = pci_resource_start(dev_a8, 1);
  275. pci_irq = dev_a8->irq;
  276. pci_bus = dev_a8->bus->number;
  277. pci_device_fn = dev_a8->devfn;
  278. found = 1;
  279. break;
  280. }
  281. }
  282. if (!found) {
  283. printk(KERN_WARNING "HiSax: Scitel Quadro (%s): "
  284. "Card not found\n",
  285. sct_quadro_subtypes[cs->subtyp]);
  286. return (0);
  287. }
  288. #ifdef ATTEMPT_PCI_REMAPPING
  289. /* HACK: PLX revision 1 bug: PLX address bit 7 must not be set */
  290. if ((pci_ioaddr1 & 0x80) && (dev_a8->revision == 1)) {
  291. printk(KERN_WARNING "HiSax: Scitel Quadro (%s): "
  292. "PLX rev 1, remapping required!\n",
  293. sct_quadro_subtypes[cs->subtyp]);
  294. /* Restart PCI negotiation */
  295. pci_write_config_dword(dev_a8, PCI_BASE_ADDRESS_1, (u_int)-1);
  296. /* Move up by 0x80 byte */
  297. pci_ioaddr1 += 0x80;
  298. pci_ioaddr1 &= PCI_BASE_ADDRESS_IO_MASK;
  299. pci_write_config_dword(dev_a8, PCI_BASE_ADDRESS_1, pci_ioaddr1);
  300. dev_a8->resource[1].start = pci_ioaddr1;
  301. }
  302. #endif /* End HACK */
  303. }
  304. if (!pci_irq) { /* IRQ range check ?? */
  305. printk(KERN_WARNING "HiSax: Scitel Quadro (%s): No IRQ\n",
  306. sct_quadro_subtypes[cs->subtyp]);
  307. return (0);
  308. }
  309. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_1, &pci_ioaddr1);
  310. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_2, &pci_ioaddr2);
  311. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_3, &pci_ioaddr3);
  312. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_4, &pci_ioaddr4);
  313. pci_read_config_dword(dev_a8, PCI_BASE_ADDRESS_5, &pci_ioaddr5);
  314. if (!pci_ioaddr1 || !pci_ioaddr2 || !pci_ioaddr3 || !pci_ioaddr4 || !pci_ioaddr5) {
  315. printk(KERN_WARNING "HiSax: Scitel Quadro (%s): "
  316. "No IO base address(es)\n",
  317. sct_quadro_subtypes[cs->subtyp]);
  318. return (0);
  319. }
  320. pci_ioaddr1 &= PCI_BASE_ADDRESS_IO_MASK;
  321. pci_ioaddr2 &= PCI_BASE_ADDRESS_IO_MASK;
  322. pci_ioaddr3 &= PCI_BASE_ADDRESS_IO_MASK;
  323. pci_ioaddr4 &= PCI_BASE_ADDRESS_IO_MASK;
  324. pci_ioaddr5 &= PCI_BASE_ADDRESS_IO_MASK;
  325. /* Take over */
  326. cs->irq = pci_irq;
  327. cs->irq_flags |= IRQF_SHARED;
  328. /* pci_ioaddr1 is unique to all subdevices */
  329. /* pci_ioaddr2 is for the fourth subdevice only */
  330. /* pci_ioaddr3 is for the third subdevice only */
  331. /* pci_ioaddr4 is for the second subdevice only */
  332. /* pci_ioaddr5 is for the first subdevice only */
  333. cs->hw.ax.plx_adr = pci_ioaddr1;
  334. /* Enter all ipac_base addresses */
  335. switch (cs->subtyp) {
  336. case 1:
  337. cs->hw.ax.base = pci_ioaddr5 + 0x00;
  338. if (sct_alloc_io(pci_ioaddr1, 128))
  339. return (0);
  340. if (sct_alloc_io(pci_ioaddr5, 64))
  341. return (0);
  342. /* disable all IPAC */
  343. writereg(pci_ioaddr5, pci_ioaddr5 + 4,
  344. IPAC_MASK, 0xFF);
  345. writereg(pci_ioaddr4 + 0x08, pci_ioaddr4 + 0x0c,
  346. IPAC_MASK, 0xFF);
  347. writereg(pci_ioaddr3 + 0x10, pci_ioaddr3 + 0x14,
  348. IPAC_MASK, 0xFF);
  349. writereg(pci_ioaddr2 + 0x20, pci_ioaddr2 + 0x24,
  350. IPAC_MASK, 0xFF);
  351. break;
  352. case 2:
  353. cs->hw.ax.base = pci_ioaddr4 + 0x08;
  354. if (sct_alloc_io(pci_ioaddr4, 64))
  355. return (0);
  356. break;
  357. case 3:
  358. cs->hw.ax.base = pci_ioaddr3 + 0x10;
  359. if (sct_alloc_io(pci_ioaddr3, 64))
  360. return (0);
  361. break;
  362. case 4:
  363. cs->hw.ax.base = pci_ioaddr2 + 0x20;
  364. if (sct_alloc_io(pci_ioaddr2, 64))
  365. return (0);
  366. break;
  367. }
  368. /* For isac and hscx data path */
  369. cs->hw.ax.data_adr = cs->hw.ax.base + 4;
  370. printk(KERN_INFO "HiSax: Scitel Quadro (%s) configured at "
  371. "0x%.4lX, 0x%.4lX, 0x%.4lX and IRQ %d\n",
  372. sct_quadro_subtypes[cs->subtyp],
  373. cs->hw.ax.plx_adr,
  374. cs->hw.ax.base,
  375. cs->hw.ax.data_adr,
  376. cs->irq);
  377. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  378. cs->readisac = &ReadISAC;
  379. cs->writeisac = &WriteISAC;
  380. cs->readisacfifo = &ReadISACfifo;
  381. cs->writeisacfifo = &WriteISACfifo;
  382. cs->BC_Read_Reg = &ReadHSCX;
  383. cs->BC_Write_Reg = &WriteHSCX;
  384. cs->BC_Send_Data = &hscx_fill_fifo;
  385. cs->cardmsg = &BKM_card_msg;
  386. cs->irq_func = &bkm_interrupt_ipac;
  387. printk(KERN_INFO "HiSax: Scitel Quadro (%s): IPAC Version %d\n",
  388. sct_quadro_subtypes[cs->subtyp],
  389. readreg(cs->hw.ax.base, cs->hw.ax.data_adr, IPAC_ID));
  390. return (1);
  391. }