asuscom.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /* $Id: asuscom.c,v 1.14.2.4 2004/01/13 23:48:39 keil Exp $
  2. *
  3. * low level stuff for ASUSCOM NETWORK INC. ISDNLink cards
  4. *
  5. * Author Karsten Keil
  6. * Copyright by Karsten Keil <keil@isdn4linux.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. * Thanks to ASUSCOM NETWORK INC. Taiwan and Dynalink NL for information
  12. *
  13. */
  14. #include <linux/init.h>
  15. #include <linux/isapnp.h>
  16. #include "hisax.h"
  17. #include "isac.h"
  18. #include "ipac.h"
  19. #include "hscx.h"
  20. #include "isdnl1.h"
  21. static const char *Asuscom_revision = "$Revision: 1.14.2.4 $";
  22. #define byteout(addr,val) outb(val,addr)
  23. #define bytein(addr) inb(addr)
  24. #define ASUS_ISAC 0
  25. #define ASUS_HSCX 1
  26. #define ASUS_ADR 2
  27. #define ASUS_CTRL_U7 3
  28. #define ASUS_CTRL_POTS 5
  29. #define ASUS_IPAC_ALE 0
  30. #define ASUS_IPAC_DATA 1
  31. #define ASUS_ISACHSCX 1
  32. #define ASUS_IPAC 2
  33. /* CARD_ADR (Write) */
  34. #define ASUS_RESET 0x80 /* Bit 7 Reset-Leitung */
  35. static inline u_char
  36. readreg(unsigned int ale, unsigned int adr, u_char off)
  37. {
  38. register u_char ret;
  39. byteout(ale, off);
  40. ret = bytein(adr);
  41. return (ret);
  42. }
  43. static inline void
  44. readfifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
  45. {
  46. byteout(ale, off);
  47. insb(adr, data, size);
  48. }
  49. static inline void
  50. writereg(unsigned int ale, unsigned int adr, u_char off, u_char data)
  51. {
  52. byteout(ale, off);
  53. byteout(adr, data);
  54. }
  55. static inline void
  56. writefifo(unsigned int ale, unsigned int adr, u_char off, u_char * data, int size)
  57. {
  58. byteout(ale, off);
  59. outsb(adr, data, size);
  60. }
  61. /* Interface functions */
  62. static u_char
  63. ReadISAC(struct IsdnCardState *cs, u_char offset)
  64. {
  65. return (readreg(cs->hw.asus.adr, cs->hw.asus.isac, offset));
  66. }
  67. static void
  68. WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value)
  69. {
  70. writereg(cs->hw.asus.adr, cs->hw.asus.isac, offset, value);
  71. }
  72. static void
  73. ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  74. {
  75. readfifo(cs->hw.asus.adr, cs->hw.asus.isac, 0, data, size);
  76. }
  77. static void
  78. WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
  79. {
  80. writefifo(cs->hw.asus.adr, cs->hw.asus.isac, 0, data, size);
  81. }
  82. static u_char
  83. ReadISAC_IPAC(struct IsdnCardState *cs, u_char offset)
  84. {
  85. return (readreg(cs->hw.asus.adr, cs->hw.asus.isac, offset|0x80));
  86. }
  87. static void
  88. WriteISAC_IPAC(struct IsdnCardState *cs, u_char offset, u_char value)
  89. {
  90. writereg(cs->hw.asus.adr, cs->hw.asus.isac, offset|0x80, value);
  91. }
  92. static void
  93. ReadISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
  94. {
  95. readfifo(cs->hw.asus.adr, cs->hw.asus.isac, 0x80, data, size);
  96. }
  97. static void
  98. WriteISACfifo_IPAC(struct IsdnCardState *cs, u_char * data, int size)
  99. {
  100. writefifo(cs->hw.asus.adr, cs->hw.asus.isac, 0x80, data, size);
  101. }
  102. static u_char
  103. ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset)
  104. {
  105. return (readreg(cs->hw.asus.adr,
  106. cs->hw.asus.hscx, offset + (hscx ? 0x40 : 0)));
  107. }
  108. static void
  109. WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value)
  110. {
  111. writereg(cs->hw.asus.adr,
  112. cs->hw.asus.hscx, offset + (hscx ? 0x40 : 0), value);
  113. }
  114. /*
  115. * fast interrupt HSCX stuff goes here
  116. */
  117. #define READHSCX(cs, nr, reg) readreg(cs->hw.asus.adr, \
  118. cs->hw.asus.hscx, reg + (nr ? 0x40 : 0))
  119. #define WRITEHSCX(cs, nr, reg, data) writereg(cs->hw.asus.adr, \
  120. cs->hw.asus.hscx, reg + (nr ? 0x40 : 0), data)
  121. #define READHSCXFIFO(cs, nr, ptr, cnt) readfifo(cs->hw.asus.adr, \
  122. cs->hw.asus.hscx, (nr ? 0x40 : 0), ptr, cnt)
  123. #define WRITEHSCXFIFO(cs, nr, ptr, cnt) writefifo(cs->hw.asus.adr, \
  124. cs->hw.asus.hscx, (nr ? 0x40 : 0), ptr, cnt)
  125. #include "hscx_irq.c"
  126. static irqreturn_t
  127. asuscom_interrupt(int intno, void *dev_id)
  128. {
  129. struct IsdnCardState *cs = dev_id;
  130. u_char val;
  131. u_long flags;
  132. spin_lock_irqsave(&cs->lock, flags);
  133. val = readreg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_ISTA + 0x40);
  134. Start_HSCX:
  135. if (val)
  136. hscx_int_main(cs, val);
  137. val = readreg(cs->hw.asus.adr, cs->hw.asus.isac, ISAC_ISTA);
  138. Start_ISAC:
  139. if (val)
  140. isac_interrupt(cs, val);
  141. val = readreg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_ISTA + 0x40);
  142. if (val) {
  143. if (cs->debug & L1_DEB_HSCX)
  144. debugl1(cs, "HSCX IntStat after IntRoutine");
  145. goto Start_HSCX;
  146. }
  147. val = readreg(cs->hw.asus.adr, cs->hw.asus.isac, ISAC_ISTA);
  148. if (val) {
  149. if (cs->debug & L1_DEB_ISAC)
  150. debugl1(cs, "ISAC IntStat after IntRoutine");
  151. goto Start_ISAC;
  152. }
  153. writereg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_MASK, 0xFF);
  154. writereg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_MASK + 0x40, 0xFF);
  155. writereg(cs->hw.asus.adr, cs->hw.asus.isac, ISAC_MASK, 0xFF);
  156. writereg(cs->hw.asus.adr, cs->hw.asus.isac, ISAC_MASK, 0x0);
  157. writereg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_MASK, 0x0);
  158. writereg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_MASK + 0x40, 0x0);
  159. spin_unlock_irqrestore(&cs->lock, flags);
  160. return IRQ_HANDLED;
  161. }
  162. static irqreturn_t
  163. asuscom_interrupt_ipac(int intno, void *dev_id)
  164. {
  165. struct IsdnCardState *cs = dev_id;
  166. u_char ista, val, icnt = 5;
  167. u_long flags;
  168. spin_lock_irqsave(&cs->lock, flags);
  169. ista = readreg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_ISTA);
  170. Start_IPAC:
  171. if (cs->debug & L1_DEB_IPAC)
  172. debugl1(cs, "IPAC ISTA %02X", ista);
  173. if (ista & 0x0f) {
  174. val = readreg(cs->hw.asus.adr, cs->hw.asus.hscx, HSCX_ISTA + 0x40);
  175. if (ista & 0x01)
  176. val |= 0x01;
  177. if (ista & 0x04)
  178. val |= 0x02;
  179. if (ista & 0x08)
  180. val |= 0x04;
  181. if (val)
  182. hscx_int_main(cs, val);
  183. }
  184. if (ista & 0x20) {
  185. val = 0xfe & readreg(cs->hw.asus.adr, cs->hw.asus.isac, ISAC_ISTA | 0x80);
  186. if (val) {
  187. isac_interrupt(cs, val);
  188. }
  189. }
  190. if (ista & 0x10) {
  191. val = 0x01;
  192. isac_interrupt(cs, val);
  193. }
  194. ista = readreg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_ISTA);
  195. if ((ista & 0x3f) && icnt) {
  196. icnt--;
  197. goto Start_IPAC;
  198. }
  199. if (!icnt)
  200. printk(KERN_WARNING "ASUS IRQ LOOP\n");
  201. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_MASK, 0xFF);
  202. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_MASK, 0xC0);
  203. spin_unlock_irqrestore(&cs->lock, flags);
  204. return IRQ_HANDLED;
  205. }
  206. static void
  207. release_io_asuscom(struct IsdnCardState *cs)
  208. {
  209. int bytecnt = 8;
  210. if (cs->hw.asus.cfg_reg)
  211. release_region(cs->hw.asus.cfg_reg, bytecnt);
  212. }
  213. static void
  214. reset_asuscom(struct IsdnCardState *cs)
  215. {
  216. if (cs->subtyp == ASUS_IPAC)
  217. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_POTA2, 0x20);
  218. else
  219. byteout(cs->hw.asus.adr, ASUS_RESET); /* Reset On */
  220. mdelay(10);
  221. if (cs->subtyp == ASUS_IPAC)
  222. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_POTA2, 0x0);
  223. else
  224. byteout(cs->hw.asus.adr, 0); /* Reset Off */
  225. mdelay(10);
  226. if (cs->subtyp == ASUS_IPAC) {
  227. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_CONF, 0x0);
  228. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_ACFG, 0xff);
  229. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_AOE, 0x0);
  230. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_MASK, 0xc0);
  231. writereg(cs->hw.asus.adr, cs->hw.asus.isac, IPAC_PCFG, 0x12);
  232. }
  233. }
  234. static int
  235. Asus_card_msg(struct IsdnCardState *cs, int mt, void *arg)
  236. {
  237. u_long flags;
  238. switch (mt) {
  239. case CARD_RESET:
  240. spin_lock_irqsave(&cs->lock, flags);
  241. reset_asuscom(cs);
  242. spin_unlock_irqrestore(&cs->lock, flags);
  243. return(0);
  244. case CARD_RELEASE:
  245. release_io_asuscom(cs);
  246. return(0);
  247. case CARD_INIT:
  248. spin_lock_irqsave(&cs->lock, flags);
  249. cs->debug |= L1_DEB_IPAC;
  250. inithscxisac(cs, 3);
  251. spin_unlock_irqrestore(&cs->lock, flags);
  252. return(0);
  253. case CARD_TEST:
  254. return(0);
  255. }
  256. return(0);
  257. }
  258. #ifdef __ISAPNP__
  259. static struct isapnp_device_id asus_ids[] __devinitdata = {
  260. { ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1688),
  261. ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1688),
  262. (unsigned long) "Asus1688 PnP" },
  263. { ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1690),
  264. ISAPNP_VENDOR('A', 'S', 'U'), ISAPNP_FUNCTION(0x1690),
  265. (unsigned long) "Asus1690 PnP" },
  266. { ISAPNP_VENDOR('S', 'I', 'E'), ISAPNP_FUNCTION(0x0020),
  267. ISAPNP_VENDOR('S', 'I', 'E'), ISAPNP_FUNCTION(0x0020),
  268. (unsigned long) "Isurf2 PnP" },
  269. { ISAPNP_VENDOR('E', 'L', 'F'), ISAPNP_FUNCTION(0x0000),
  270. ISAPNP_VENDOR('E', 'L', 'F'), ISAPNP_FUNCTION(0x0000),
  271. (unsigned long) "Iscas TE320" },
  272. { 0, }
  273. };
  274. static struct isapnp_device_id *ipid __devinitdata = &asus_ids[0];
  275. static struct pnp_card *pnp_c __devinitdata = NULL;
  276. #endif
  277. int __devinit
  278. setup_asuscom(struct IsdnCard *card)
  279. {
  280. int bytecnt;
  281. struct IsdnCardState *cs = card->cs;
  282. u_char val;
  283. char tmp[64];
  284. strcpy(tmp, Asuscom_revision);
  285. printk(KERN_INFO "HiSax: Asuscom ISDNLink driver Rev. %s\n", HiSax_getrev(tmp));
  286. if (cs->typ != ISDN_CTYPE_ASUSCOM)
  287. return (0);
  288. #ifdef __ISAPNP__
  289. if (!card->para[1] && isapnp_present()) {
  290. struct pnp_dev *pnp_d;
  291. while(ipid->card_vendor) {
  292. if ((pnp_c = pnp_find_card(ipid->card_vendor,
  293. ipid->card_device, pnp_c))) {
  294. pnp_d = NULL;
  295. if ((pnp_d = pnp_find_dev(pnp_c,
  296. ipid->vendor, ipid->function, pnp_d))) {
  297. int err;
  298. printk(KERN_INFO "HiSax: %s detected\n",
  299. (char *)ipid->driver_data);
  300. pnp_disable_dev(pnp_d);
  301. err = pnp_activate_dev(pnp_d);
  302. if (err<0) {
  303. printk(KERN_WARNING "%s: pnp_activate_dev ret(%d)\n",
  304. __func__, err);
  305. return(0);
  306. }
  307. card->para[1] = pnp_port_start(pnp_d, 0);
  308. card->para[0] = pnp_irq(pnp_d, 0);
  309. if (!card->para[0] || !card->para[1]) {
  310. printk(KERN_ERR "AsusPnP:some resources are missing %ld/%lx\n",
  311. card->para[0], card->para[1]);
  312. pnp_disable_dev(pnp_d);
  313. return(0);
  314. }
  315. break;
  316. } else {
  317. printk(KERN_ERR "AsusPnP: PnP error card found, no device\n");
  318. }
  319. }
  320. ipid++;
  321. pnp_c = NULL;
  322. }
  323. if (!ipid->card_vendor) {
  324. printk(KERN_INFO "AsusPnP: no ISAPnP card found\n");
  325. return(0);
  326. }
  327. }
  328. #endif
  329. bytecnt = 8;
  330. cs->hw.asus.cfg_reg = card->para[1];
  331. cs->irq = card->para[0];
  332. if (!request_region(cs->hw.asus.cfg_reg, bytecnt, "asuscom isdn")) {
  333. printk(KERN_WARNING
  334. "HiSax: ISDNLink config port %x-%x already in use\n",
  335. cs->hw.asus.cfg_reg,
  336. cs->hw.asus.cfg_reg + bytecnt);
  337. return (0);
  338. }
  339. printk(KERN_INFO "ISDNLink: defined at 0x%x IRQ %d\n",
  340. cs->hw.asus.cfg_reg, cs->irq);
  341. setup_isac(cs);
  342. cs->BC_Read_Reg = &ReadHSCX;
  343. cs->BC_Write_Reg = &WriteHSCX;
  344. cs->BC_Send_Data = &hscx_fill_fifo;
  345. cs->cardmsg = &Asus_card_msg;
  346. val = readreg(cs->hw.asus.cfg_reg + ASUS_IPAC_ALE,
  347. cs->hw.asus.cfg_reg + ASUS_IPAC_DATA, IPAC_ID);
  348. if ((val == 1) || (val == 2)) {
  349. cs->subtyp = ASUS_IPAC;
  350. cs->hw.asus.adr = cs->hw.asus.cfg_reg + ASUS_IPAC_ALE;
  351. cs->hw.asus.isac = cs->hw.asus.cfg_reg + ASUS_IPAC_DATA;
  352. cs->hw.asus.hscx = cs->hw.asus.cfg_reg + ASUS_IPAC_DATA;
  353. test_and_set_bit(HW_IPAC, &cs->HW_Flags);
  354. cs->readisac = &ReadISAC_IPAC;
  355. cs->writeisac = &WriteISAC_IPAC;
  356. cs->readisacfifo = &ReadISACfifo_IPAC;
  357. cs->writeisacfifo = &WriteISACfifo_IPAC;
  358. cs->irq_func = &asuscom_interrupt_ipac;
  359. printk(KERN_INFO "Asus: IPAC version %x\n", val);
  360. } else {
  361. cs->subtyp = ASUS_ISACHSCX;
  362. cs->hw.asus.adr = cs->hw.asus.cfg_reg + ASUS_ADR;
  363. cs->hw.asus.isac = cs->hw.asus.cfg_reg + ASUS_ISAC;
  364. cs->hw.asus.hscx = cs->hw.asus.cfg_reg + ASUS_HSCX;
  365. cs->hw.asus.u7 = cs->hw.asus.cfg_reg + ASUS_CTRL_U7;
  366. cs->hw.asus.pots = cs->hw.asus.cfg_reg + ASUS_CTRL_POTS;
  367. cs->readisac = &ReadISAC;
  368. cs->writeisac = &WriteISAC;
  369. cs->readisacfifo = &ReadISACfifo;
  370. cs->writeisacfifo = &WriteISACfifo;
  371. cs->irq_func = &asuscom_interrupt;
  372. ISACVersion(cs, "ISDNLink:");
  373. if (HscxVersion(cs, "ISDNLink:")) {
  374. printk(KERN_WARNING
  375. "ISDNLink: wrong HSCX versions check IO address\n");
  376. release_io_asuscom(cs);
  377. return (0);
  378. }
  379. }
  380. return (1);
  381. }