niccy.c 10 KB

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