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