Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | /* $Id: isurf.c,v 1.10.6.1 2001/02/16 16:43:27 kai Exp $ * * isurf.c low level stuff for Siemens I-Surf/I-Talk cards * * Author Karsten Keil (keil@isdn4linux.de) * * This file is (c) under GNU General Public License * */ #define __NO_VERSION__ #include <linux/init.h> #include "hisax.h" #include "isac.h" #include "isar.h" #include "isdnl1.h" extern const char *CardType[]; static const char *ISurf_revision = "$Revision: 1.10.6.1 $"; #define byteout(addr,val) outb(val,addr) #define bytein(addr) inb(addr) #define ISURF_ISAR_RESET 1 #define ISURF_ISAC_RESET 2 #define ISURF_ISAR_EA 4 #define ISURF_ARCOFI_RESET 8 #define ISURF_RESET (ISURF_ISAR_RESET | ISURF_ISAC_RESET | ISURF_ARCOFI_RESET) #define ISURF_ISAR_OFFSET 0 #define ISURF_ISAC_OFFSET 0x100 #define ISURF_IOMEM_SIZE 0x400 /* Interface functions */ static u_char ReadISAC(struct IsdnCardState *cs, u_char offset) { return (readb(cs->hw.isurf.isac + offset)); } static void WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value) { writeb(value, cs->hw.isurf.isac + offset); mb(); } static void ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size) { register int i; for (i = 0; i < size; i++) data[i] = readb(cs->hw.isurf.isac); } static void WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size) { register int i; for (i = 0; i < size; i++){ writeb(data[i], cs->hw.isurf.isac);mb(); } } /* ISAR access routines * mode = 0 access with IRQ on * mode = 1 access with IRQ off * mode = 2 access with IRQ off and using last offset */ static u_char ReadISAR(struct IsdnCardState *cs, int mode, u_char offset) { return(readb(cs->hw.isurf.isar + offset)); } static void WriteISAR(struct IsdnCardState *cs, int mode, u_char offset, u_char value) { writeb(value, cs->hw.isurf.isar + offset);mb(); } static void isurf_interrupt(int intno, void *dev_id, struct pt_regs *regs) { struct IsdnCardState *cs = dev_id; u_char val; int cnt = 5; if (!cs) { printk(KERN_WARNING "ISurf: Spurious interrupt!\n"); return; } val = readb(cs->hw.isurf.isar + ISAR_IRQBIT); Start_ISAR: if (val & ISAR_IRQSTA) isar_int_main(cs); val = readb(cs->hw.isurf.isac + ISAC_ISTA); Start_ISAC: if (val) isac_interrupt(cs, val); val = readb(cs->hw.isurf.isar + ISAR_IRQBIT); if ((val & ISAR_IRQSTA) && --cnt) { if (cs->debug & L1_DEB_HSCX) debugl1(cs, "ISAR IntStat after IntRoutine"); goto Start_ISAR; } val = readb(cs->hw.isurf.isac + ISAC_ISTA); if (val && --cnt) { if (cs->debug & L1_DEB_ISAC) debugl1(cs, "ISAC IntStat after IntRoutine"); goto Start_ISAC; } if (!cnt) printk(KERN_WARNING "ISurf IRQ LOOP\n"); writeb(0, cs->hw.isurf.isar + ISAR_IRQBIT); mb(); writeb(0xFF, cs->hw.isurf.isac + ISAC_MASK);mb(); writeb(0, cs->hw.isurf.isac + ISAC_MASK);mb(); writeb(ISAR_IRQMSK, cs->hw.isurf.isar + ISAR_IRQBIT); mb(); } void release_io_isurf(struct IsdnCardState *cs) { release_region(cs->hw.isurf.reset, 1); iounmap((unsigned char *)cs->hw.isurf.isar); release_mem_region(cs->hw.isurf.phymem, ISURF_IOMEM_SIZE); } static void reset_isurf(struct IsdnCardState *cs, u_char chips) { long flags; printk(KERN_INFO "ISurf: resetting card\n"); byteout(cs->hw.isurf.reset, chips); /* Reset On */ save_flags(flags); sti(); set_current_state(TASK_UNINTERRUPTIBLE); schedule_timeout((10*HZ)/1000); byteout(cs->hw.isurf.reset, ISURF_ISAR_EA); /* Reset Off */ set_current_state(TASK_UNINTERRUPTIBLE); schedule_timeout((10*HZ)/1000); restore_flags(flags); } static int ISurf_card_msg(struct IsdnCardState *cs, int mt, void *arg) { switch (mt) { case CARD_RESET: reset_isurf(cs, ISURF_RESET); return(0); case CARD_RELEASE: release_io_isurf(cs); return(0); case CARD_INIT: clear_pending_isac_ints(cs); writeb(0, cs->hw.isurf.isar+ISAR_IRQBIT);mb(); initisac(cs); initisar(cs); /* Reenable ISAC IRQ */ cs->writeisac(cs, ISAC_MASK, 0); /* RESET Receiver and Transmitter */ cs->writeisac(cs, ISAC_CMDR, 0x41); return(0); case CARD_TEST: return(0); } return(0); } static int isurf_auxcmd(struct IsdnCardState *cs, isdn_ctrl *ic) { int ret; if ((ic->command == ISDN_CMD_IOCTL) && (ic->arg == 9)) { ret = isar_auxcmd(cs, ic); if (!ret) { reset_isurf(cs, ISURF_ISAR_EA | ISURF_ISAC_RESET | ISURF_ARCOFI_RESET); initisac(cs); cs->writeisac(cs, ISAC_MASK, 0); cs->writeisac(cs, ISAC_CMDR, 0x41); } return(ret); } return(isar_auxcmd(cs, ic)); } int __init setup_isurf(struct IsdnCard *card) { int ver; struct IsdnCardState *cs = card->cs; char tmp[64]; strcpy(tmp, ISurf_revision); printk(KERN_INFO "HiSax: ISurf driver Rev. %s\n", HiSax_getrev(tmp)); if (cs->typ != ISDN_CTYPE_ISURF) return(0); if (card->para[1] && card->para[2]) { cs->hw.isurf.reset = card->para[1]; cs->hw.isurf.phymem = card->para[2]; cs->irq = card->para[0]; } else { printk(KERN_WARNING "HiSax: %s port/mem not set\n", CardType[card->typ]); return (0); } if (check_region(cs->hw.isurf.reset, 1)) { printk(KERN_WARNING "HiSax: %s config port %x already in use\n", CardType[card->typ], cs->hw.isurf.reset); return (0); } else { request_region(cs->hw.isurf.reset, 1, "isurf isdn"); } if (check_mem_region(cs->hw.isurf.phymem, ISURF_IOMEM_SIZE)) { printk(KERN_WARNING "HiSax: %s memory region %lx-%lx already in use\n", CardType[card->typ], cs->hw.isurf.phymem, cs->hw.isurf.phymem + ISURF_IOMEM_SIZE); release_region(cs->hw.isurf.reset, 1); return (0); } else { request_mem_region(cs->hw.isurf.phymem, ISURF_IOMEM_SIZE, "isurf iomem"); } cs->hw.isurf.isar = (unsigned long) ioremap(cs->hw.isurf.phymem, ISURF_IOMEM_SIZE); cs->hw.isurf.isac = cs->hw.isurf.isar + ISURF_ISAC_OFFSET; printk(KERN_INFO "ISurf: defined at 0x%x 0x%lx IRQ %d\n", cs->hw.isurf.reset, cs->hw.isurf.phymem, cs->irq); cs->cardmsg = &ISurf_card_msg; cs->irq_func = &isurf_interrupt; cs->auxcmd = &isurf_auxcmd; cs->readisac = &ReadISAC; cs->writeisac = &WriteISAC; cs->readisacfifo = &ReadISACfifo; cs->writeisacfifo = &WriteISACfifo; cs->bcs[0].hw.isar.reg = &cs->hw.isurf.isar_r; cs->bcs[1].hw.isar.reg = &cs->hw.isurf.isar_r; reset_isurf(cs, ISURF_RESET); test_and_set_bit(HW_ISAR, &cs->HW_Flags); ISACVersion(cs, "ISurf:"); cs->BC_Read_Reg = &ReadISAR; cs->BC_Write_Reg = &WriteISAR; cs->BC_Send_Data = &isar_fill_fifo; ver = ISARVersion(cs, "ISurf:"); if (ver < 0) { printk(KERN_WARNING "ISurf: wrong ISAR version (ret = %d)\n", ver); release_io_isurf(cs); return (0); } return (1); } |