niccy.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /* $Id: niccy.c,v 1.21.2.4 2004/01/13 23:48:39 keil Exp $
  2. *
  3. * low level stuff for Dr. Neuhaus NICCY PnP and NICCY PCI and
  4. * compatible (SAGEM cybermodem)
  5. *
  6. * Author Karsten Keil
  7. * Copyright by Karsten Keil <keil@isdn4linux.de>
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. * Thanks to Dr. Neuhaus and SAGEM for information
  13. *
  14. */
  15. #include <linux/config.h>
  16. #include <linux/init.h>
  17. #include "hisax.h"
  18. #include "isac.h"
  19. #include "hscx.h"
  20. #include "isdnl1.h"
  21. #include <linux/pci.h>
  22. #include <linux/isapnp.h>
  23. extern const char *CardType[];
  24. static const char *niccy_revision = "$Revision: 1.21.2.4 $";
  25. #define byteout(addr,val) outb(val,addr)
  26. #define bytein(addr) inb(addr)
  27. #define ISAC_PCI_DATA 0
  28. #define HSCX_PCI_DATA 1
  29. #define ISAC_PCI_ADDR 2
  30. #define HSCX_PCI_ADDR 3
  31. #define ISAC_PNP 0
  32. #define HSCX_PNP 1
  33. /* SUB Types */
  34. #define NICCY_PNP 1
  35. #define NICCY_PCI 2
  36. /* PCI stuff */
  37. #define PCI_IRQ_CTRL_REG 0x38
  38. #define PCI_IRQ_ENABLE 0x1f00
  39. #define PCI_IRQ_DISABLE 0xff0000
  40. #define PCI_IRQ_ASSERT 0x800000
  41. static inline u_char
  42. readreg(unsigned int ale, unsigned int adr, u_char off)
  43. {
  44. register u_char ret;
  45. byteout(ale, off);
  46. ret = bytein(adr);
  47. return (ret);
  48. }
  49. static inline void
  50. readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
  51. {
  52. byteout(ale, off);
  53. insb(adr, data, size);
  54. }
  55. static inline void
  56. writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
  57. {
  58. byteout(ale, off);
  59. byteout(adr, data);
  60. }
  61. static inline void
  62. writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
  63. {
  64. byteout(ale, off);
  65. outsb(adr, data, size);
  66. }
  67. /* Interface functions */
  68. static u_char
  69. ReadISAC(struct IsdnCardState *cs, u_char offset)
  70. {
  71. return (readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, offset));
  72. }
  73. static void
  74. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  75. {
  76. writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, offset, value);
  77. }
  78. static void
  79. ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  80. {
  81. readfifo(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, 0, data, size);
  82. }
  83. static void
  84. WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  85. {
  86. writefifo(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, 0, data, size);
  87. }
  88. static u_char
  89. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  90. {
  91. return (readreg(cs->hw.niccy.hscx_ale,
  92. cs->hw.niccy.hscx, offset + (hscx ? 0x40 : 0)));
  93. }
  94. static void
  95. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  96. {
  97. writereg(cs->hw.niccy.hscx_ale,
  98. cs->hw.niccy.hscx, offset + (hscx ? 0x40 : 0), value);
  99. }
  100. #define READHSCX(cs, nr, reg) readreg(cs->hw.niccy.hscx_ale, \
  101. cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0))
  102. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.niccy.hscx_ale, \
  103. cs->hw.niccy.hscx, reg + (nr ? 0x40 : 0), data)
  104. #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.niccy.hscx_ale, \
  105. cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
  106. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.niccy.hscx_ale, \
  107. cs->hw.niccy.hscx, (nr ? 0x40 : 0), ptr, cnt)
  108. #include "hscx_irq.c"
  109. static irqreturn_t
  110. niccy_interrupt(int intno, void *dev_id, struct pt_regs *regs)
  111. {
  112. struct IsdnCardState *cs = dev_id;
  113. u_char val;
  114. u_long flags;
  115. spin_lock_irqsave(&cs->lock, flags);
  116. if (cs->subtyp == NICCY_PCI) {
  117. int ival;
  118. ival = inl(cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
  119. if (!(ival & PCI_IRQ_ASSERT)) { /* IRQ not for us (shared) */
  120. spin_unlock_irqrestore(&cs->lock, flags);
  121. return IRQ_NONE;
  122. }
  123. outl(ival, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
  124. }
  125. val = readreg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_ISTA + 0x40);
  126. Start_HSCX:
  127. if (val)
  128. hscx_int_main(cs, val);
  129. val = readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_ISTA);
  130. Start_ISAC:
  131. if (val)
  132. isac_interrupt(cs, val);
  133. val = readreg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_ISTA + 0x40);
  134. if (val) {
  135. if (cs->debug & L1_DEB_HSCX)
  136. debugl1(cs, "HSCX IntStat after IntRoutine");
  137. goto Start_HSCX;
  138. }
  139. val = readreg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_ISTA);
  140. if (val) {
  141. if (cs->debug & L1_DEB_ISAC)
  142. debugl1(cs, "ISAC IntStat after IntRoutine");
  143. goto Start_ISAC;
  144. }
  145. writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK, 0xFF);
  146. writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK + 0x40, 0xFF);
  147. writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_MASK, 0xFF);
  148. writereg(cs->hw.niccy.isac_ale, cs->hw.niccy.isac, ISAC_MASK, 0);
  149. writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK, 0);
  150. writereg(cs->hw.niccy.hscx_ale, cs->hw.niccy.hscx, HSCX_MASK + 0x40, 0);
  151. spin_unlock_irqrestore(&cs->lock, flags);
  152. return IRQ_HANDLED;
  153. }
  154. static void
  155. release_io_niccy(struct IsdnCardState *cs)
  156. {
  157. if (cs->subtyp == NICCY_PCI) {
  158. int val;
  159. val = inl(cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
  160. val &= PCI_IRQ_DISABLE;
  161. outl(val, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
  162. release_region(cs->hw.niccy.cfg_reg, 0x40);
  163. release_region(cs->hw.niccy.isac, 4);
  164. } else {
  165. release_region(cs->hw.niccy.isac, 2);
  166. release_region(cs->hw.niccy.isac_ale, 2);
  167. }
  168. }
  169. static void
  170. niccy_reset(struct IsdnCardState *cs)
  171. {
  172. if (cs->subtyp == NICCY_PCI) {
  173. int val;
  174. val = inl(cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
  175. val |= PCI_IRQ_ENABLE;
  176. outl(val, cs->hw.niccy.cfg_reg + PCI_IRQ_CTRL_REG);
  177. }
  178. inithscxisac(cs, 3);
  179. }
  180. static int
  181. niccy_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  182. {
  183. u_long flags;
  184. switch (mt) {
  185. case CARD_RESET:
  186. spin_lock_irqsave(&cs->lock, flags);
  187. niccy_reset(cs);
  188. spin_unlock_irqrestore(&cs->lock, flags);
  189. return(0);
  190. case CARD_RELEASE:
  191. release_io_niccy(cs);
  192. return(0);
  193. case CARD_INIT:
  194. spin_lock_irqsave(&cs->lock, flags);
  195. niccy_reset(cs);
  196. spin_unlock_irqrestore(&cs->lock, flags);
  197. return(0);
  198. case CARD_TEST:
  199. return(0);
  200. }
  201. return(0);
  202. }
  203. static struct pci_dev *niccy_dev __initdata = NULL;
  204. #ifdef __ISAPNP__
  205. static struct pnp_card *pnp_c __devinitdata = NULL;
  206. #endif
  207. int __init
  208. setup_niccy(struct IsdnCard *card)
  209. {
  210. struct IsdnCardState *cs = card->cs;
  211. char tmp[64];
  212. strcpy(tmp, niccy_revision);
  213. printk(KERN_INFO "HiSax: Niccy driver Rev. %s\n", HiSax_getrev(tmp));
  214. if (cs->typ != ISDN_CTYPE_NICCY)
  215. return (0);
  216. #ifdef __ISAPNP__
  217. if (!card->para[1] && isapnp_present()) {
  218. struct pnp_dev *pnp_d = NULL;
  219. int err;
  220. if ((pnp_c = pnp_find_card(
  221. ISAPNP_VENDOR('S', 'D', 'A'),
  222. ISAPNP_FUNCTION(0x0150), pnp_c))) {
  223. if (!(pnp_d = pnp_find_dev(pnp_c,
  224. ISAPNP_VENDOR('S', 'D', 'A'),
  225. ISAPNP_FUNCTION(0x0150), pnp_d))) {
  226. printk(KERN_ERR "NiccyPnP: PnP error card found, no device\n");
  227. return (0);
  228. }
  229. pnp_disable_dev(pnp_d);
  230. err = pnp_activate_dev(pnp_d);
  231. if (err<0) {
  232. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  233. __FUNCTION__, err);
  234. return(0);
  235. }
  236. card->para[1] = pnp_port_start(pnp_d, 0);
  237. card->para[2] = pnp_port_start(pnp_d, 1);
  238. card->para[0] = pnp_irq(pnp_d, 0);
  239. if (!card->para[0] || !card->para[1] || !card->para[2]) {
  240. printk(KERN_ERR "NiccyPnP:some resources are missing %ld/%lx/%lx\n",
  241. card->para[0], card->para[1], card->para[2]);
  242. pnp_disable_dev(pnp_d);
  243. return(0);
  244. }
  245. } else {
  246. printk(KERN_INFO "NiccyPnP: no ISAPnP card found\n");
  247. }
  248. }
  249. #endif
  250. if (card->para[1]) {
  251. cs->hw.niccy.isac = card->para[1] + ISAC_PNP;
  252. cs->hw.niccy.hscx = card->para[1] + HSCX_PNP;
  253. cs->hw.niccy.isac_ale = card->para[2] + ISAC_PNP;
  254. cs->hw.niccy.hscx_ale = card->para[2] + HSCX_PNP;
  255. cs->hw.niccy.cfg_reg = 0;
  256. cs->subtyp = NICCY_PNP;
  257. cs->irq = card->para[0];
  258. if (!request_region(cs->hw.niccy.isac, 2, "niccy data")) {
  259. printk(KERN_WARNING
  260. "HiSax: %s data port %x-%x already in use\n",
  261. CardType[card->typ],
  262. cs->hw.niccy.isac,
  263. cs->hw.niccy.isac + 1);
  264. return (0);
  265. }
  266. if (!request_region(cs->hw.niccy.isac_ale, 2, "niccy addr")) {
  267. printk(KERN_WARNING
  268. "HiSax: %s address port %x-%x already in use\n",
  269. CardType[card->typ],
  270. cs->hw.niccy.isac_ale,
  271. cs->hw.niccy.isac_ale + 1);
  272. release_region(cs->hw.niccy.isac, 2);
  273. return (0);
  274. }
  275. } else {
  276. #ifdef CONFIG_PCI
  277. u_int pci_ioaddr;
  278. cs->subtyp = 0;
  279. if ((niccy_dev = pci_find_device(PCI_VENDOR_ID_SATSAGEM,
  280. PCI_DEVICE_ID_SATSAGEM_NICCY, niccy_dev))) {
  281. if (pci_enable_device(niccy_dev))
  282. return(0);
  283. /* get IRQ */
  284. if (!niccy_dev->irq) {
  285. printk(KERN_WARNING "Niccy: No IRQ for PCI card found\n");
  286. return(0);
  287. }
  288. cs->irq = niccy_dev->irq;
  289. cs->hw.niccy.cfg_reg = pci_resource_start(niccy_dev, 0);
  290. if (!cs->hw.niccy.cfg_reg) {
  291. printk(KERN_WARNING "Niccy: No IO-Adr for PCI cfg found\n");
  292. return(0);
  293. }
  294. pci_ioaddr = pci_resource_start(niccy_dev, 1);
  295. if (!pci_ioaddr) {
  296. printk(KERN_WARNING "Niccy: No IO-Adr for PCI card found\n");
  297. return(0);
  298. }
  299. cs->subtyp = NICCY_PCI;
  300. } else {
  301. printk(KERN_WARNING "Niccy: No PCI card found\n");
  302. return(0);
  303. }
  304. cs->irq_flags |= SA_SHIRQ;
  305. cs->hw.niccy.isac = pci_ioaddr + ISAC_PCI_DATA;
  306. cs->hw.niccy.isac_ale = pci_ioaddr + ISAC_PCI_ADDR;
  307. cs->hw.niccy.hscx = pci_ioaddr + HSCX_PCI_DATA;
  308. cs->hw.niccy.hscx_ale = pci_ioaddr + HSCX_PCI_ADDR;
  309. if (!request_region(cs->hw.niccy.isac, 4, "niccy")) {
  310. printk(KERN_WARNING
  311. "HiSax: %s data port %x-%x already in use\n",
  312. CardType[card->typ],
  313. cs->hw.niccy.isac,
  314. cs->hw.niccy.isac + 4);
  315. return (0);
  316. }
  317. if (!request_region(cs->hw.niccy.cfg_reg, 0x40, "niccy pci")) {
  318. printk(KERN_WARNING
  319. "HiSax: %s pci port %x-%x already in use\n",
  320. CardType[card->typ],
  321. cs->hw.niccy.cfg_reg,
  322. cs->hw.niccy.cfg_reg + 0x40);
  323. release_region(cs->hw.niccy.isac, 4);
  324. return (0);
  325. }
  326. #else
  327. printk(KERN_WARNING "Niccy: io0 0 and NO_PCI_BIOS\n");
  328. printk(KERN_WARNING "Niccy: unable to config NICCY PCI\n");
  329. return (0);
  330. #endif /* CONFIG_PCI */
  331. }
  332. printk(KERN_INFO "HiSax: %s %s config irq:%d data:0x%X ale:0x%X\n",
  333. CardType[cs->typ], (cs->subtyp==1) ? "PnP":"PCI",
  334. cs->irq, cs->hw.niccy.isac, cs->hw.niccy.isac_ale);
  335. setup_isac(cs);
  336. cs->readisac = &ReadISAC;
  337. cs->writeisac = &WriteISAC;
  338. cs->readisacfifo = &ReadISACfifo;
  339. cs->writeisacfifo = &WriteISACfifo;
  340. cs->BC_Read_Reg = &ReadHSCX;
  341. cs->BC_Write_Reg = &WriteHSCX;
  342. cs->BC_Send_Data = &hscx_fill_fifo;
  343. cs->cardmsg = &niccy_card_msg;
  344. cs->irq_func = &niccy_interrupt;
  345. ISACVersion(cs, "Niccy:");
  346. if (HscxVersion(cs, "Niccy:")) {
  347. printk(KERN_WARNING
  348. "Niccy: wrong HSCX versions check IO address\n");
  349. release_io_niccy(cs);
  350. return (0);
  351. }
  352. return (1);
  353. }