asuscom.c 11 KB

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