Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: sportster.c,v 1.16.2.4 2004/01/13 23:48:39 keil Exp $ |
| 2 | * |
| 3 | * low level stuff for USR Sportster internal TA |
| 4 | * |
| 5 | * Author Karsten Keil |
| 6 | * Copyright by Karsten Keil <keil@isdn4linux.de> |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Christian "naddy" Weisgerber (3Com, US Robotics) for documentation |
| 12 | * |
| 13 | * |
| 14 | */ |
| 15 | #include <linux/init.h> |
| 16 | #include "hisax.h" |
| 17 | #include "isac.h" |
| 18 | #include "hscx.h" |
| 19 | #include "isdnl1.h" |
| 20 | |
Adrian Bunk | 672c3fd | 2005-06-25 14:59:18 -0700 | [diff] [blame] | 21 | static const char *sportster_revision = "$Revision: 1.16.2.4 $"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 23 | #define byteout(addr, val) outb(val, addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #define bytein(addr) inb(addr) |
| 25 | |
| 26 | #define SPORTSTER_ISAC 0xC000 |
| 27 | #define SPORTSTER_HSCXA 0x0000 |
| 28 | #define SPORTSTER_HSCXB 0x4000 |
| 29 | #define SPORTSTER_RES_IRQ 0x8000 |
| 30 | #define SPORTSTER_RESET 0x80 |
| 31 | #define SPORTSTER_INTE 0x40 |
| 32 | |
| 33 | static inline int |
| 34 | calc_off(unsigned int base, unsigned int off) |
| 35 | { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 36 | return (base + ((off & 0xfc) << 8) + ((off & 3) << 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static inline void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 40 | read_fifo(unsigned int adr, u_char *data, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
| 42 | insb(adr, data, size); |
| 43 | } |
| 44 | |
| 45 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 46 | write_fifo(unsigned int adr, u_char *data, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
| 48 | outsb(adr, data, size); |
| 49 | } |
| 50 | |
| 51 | /* Interface functions */ |
| 52 | |
| 53 | static u_char |
| 54 | ReadISAC(struct IsdnCardState *cs, u_char offset) |
| 55 | { |
| 56 | return (bytein(calc_off(cs->hw.spt.isac, offset))); |
| 57 | } |
| 58 | |
| 59 | static void |
| 60 | WriteISAC(struct IsdnCardState *cs, u_char offset, u_char value) |
| 61 | { |
| 62 | byteout(calc_off(cs->hw.spt.isac, offset), value); |
| 63 | } |
| 64 | |
| 65 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 66 | ReadISACfifo(struct IsdnCardState *cs, u_char *data, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
| 68 | read_fifo(cs->hw.spt.isac, data, size); |
| 69 | } |
| 70 | |
| 71 | static void |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 72 | WriteISACfifo(struct IsdnCardState *cs, u_char *data, int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 74 | write_fifo(cs->hw.spt.isac, data, size); |
| 75 | } |
| 76 | |
| 77 | static u_char |
| 78 | ReadHSCX(struct IsdnCardState *cs, int hscx, u_char offset) |
| 79 | { |
| 80 | return (bytein(calc_off(cs->hw.spt.hscx[hscx], offset))); |
| 81 | } |
| 82 | |
| 83 | static void |
| 84 | WriteHSCX(struct IsdnCardState *cs, int hscx, u_char offset, u_char value) |
| 85 | { |
| 86 | byteout(calc_off(cs->hw.spt.hscx[hscx], offset), value); |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * fast interrupt HSCX stuff goes here |
| 91 | */ |
| 92 | |
| 93 | #define READHSCX(cs, nr, reg) bytein(calc_off(cs->hw.spt.hscx[nr], reg)) |
| 94 | #define WRITEHSCX(cs, nr, reg, data) byteout(calc_off(cs->hw.spt.hscx[nr], reg), data) |
| 95 | #define READHSCXFIFO(cs, nr, ptr, cnt) read_fifo(cs->hw.spt.hscx[nr], ptr, cnt) |
| 96 | #define WRITEHSCXFIFO(cs, nr, ptr, cnt) write_fifo(cs->hw.spt.hscx[nr], ptr, cnt) |
| 97 | |
| 98 | #include "hscx_irq.c" |
| 99 | |
| 100 | static irqreturn_t |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 101 | sportster_interrupt(int intno, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | struct IsdnCardState *cs = dev_id; |
| 104 | u_char val; |
| 105 | u_long flags; |
| 106 | |
| 107 | spin_lock_irqsave(&cs->lock, flags); |
| 108 | val = READHSCX(cs, 1, HSCX_ISTA); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 109 | Start_HSCX: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | if (val) |
| 111 | hscx_int_main(cs, val); |
| 112 | val = ReadISAC(cs, ISAC_ISTA); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 113 | Start_ISAC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | if (val) |
| 115 | isac_interrupt(cs, val); |
| 116 | val = READHSCX(cs, 1, HSCX_ISTA); |
| 117 | if (val) { |
| 118 | if (cs->debug & L1_DEB_HSCX) |
| 119 | debugl1(cs, "HSCX IntStat after IntRoutine"); |
| 120 | goto Start_HSCX; |
| 121 | } |
| 122 | val = ReadISAC(cs, ISAC_ISTA); |
| 123 | if (val) { |
| 124 | if (cs->debug & L1_DEB_ISAC) |
| 125 | debugl1(cs, "ISAC IntStat after IntRoutine"); |
| 126 | goto Start_ISAC; |
| 127 | } |
| 128 | /* get a new irq impulse if there any pending */ |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 129 | bytein(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | spin_unlock_irqrestore(&cs->lock, flags); |
| 131 | return IRQ_HANDLED; |
| 132 | } |
| 133 | |
Adrian Bunk | 672c3fd | 2005-06-25 14:59:18 -0700 | [diff] [blame] | 134 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | release_io_sportster(struct IsdnCardState *cs) |
| 136 | { |
| 137 | int i, adr; |
| 138 | |
| 139 | byteout(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ, 0); |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 140 | for (i = 0; i < 64; i++) { |
| 141 | adr = cs->hw.spt.cfg_reg + i * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | release_region(adr, 8); |
| 143 | } |
| 144 | } |
| 145 | |
Adrian Bunk | 672c3fd | 2005-06-25 14:59:18 -0700 | [diff] [blame] | 146 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | reset_sportster(struct IsdnCardState *cs) |
| 148 | { |
| 149 | cs->hw.spt.res_irq |= SPORTSTER_RESET; /* Reset On */ |
| 150 | byteout(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ, cs->hw.spt.res_irq); |
| 151 | mdelay(10); |
| 152 | cs->hw.spt.res_irq &= ~SPORTSTER_RESET; /* Reset Off */ |
| 153 | byteout(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ, cs->hw.spt.res_irq); |
| 154 | mdelay(10); |
| 155 | } |
| 156 | |
| 157 | static int |
| 158 | Sportster_card_msg(struct IsdnCardState *cs, int mt, void *arg) |
| 159 | { |
| 160 | u_long flags; |
| 161 | |
| 162 | switch (mt) { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 163 | case CARD_RESET: |
| 164 | spin_lock_irqsave(&cs->lock, flags); |
| 165 | reset_sportster(cs); |
| 166 | spin_unlock_irqrestore(&cs->lock, flags); |
| 167 | return (0); |
| 168 | case CARD_RELEASE: |
| 169 | release_io_sportster(cs); |
| 170 | return (0); |
| 171 | case CARD_INIT: |
| 172 | spin_lock_irqsave(&cs->lock, flags); |
| 173 | reset_sportster(cs); |
| 174 | inithscxisac(cs, 1); |
| 175 | cs->hw.spt.res_irq |= SPORTSTER_INTE; /* IRQ On */ |
| 176 | byteout(cs->hw.spt.cfg_reg + SPORTSTER_RES_IRQ, cs->hw.spt.res_irq); |
| 177 | inithscxisac(cs, 2); |
| 178 | spin_unlock_irqrestore(&cs->lock, flags); |
| 179 | return (0); |
| 180 | case CARD_TEST: |
| 181 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 183 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Greg Kroah-Hartman | ed5a84c | 2012-12-21 13:13:05 -0800 | [diff] [blame] | 186 | static int get_io_range(struct IsdnCardState *cs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | { |
| 188 | int i, j, adr; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 189 | |
| 190 | for (i = 0; i < 64; i++) { |
| 191 | adr = cs->hw.spt.cfg_reg + i * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | if (!request_region(adr, 8, "sportster")) { |
Jeff Garzik | 8349304 | 2007-10-31 03:42:07 -0400 | [diff] [blame] | 193 | printk(KERN_WARNING "HiSax: USR Sportster config port " |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 194 | "%x-%x already in use\n", |
| 195 | adr, adr + 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | break; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 197 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 199 | if (i == 64) |
| 200 | return (1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | else { |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 202 | for (j = 0; j < i; j++) { |
| 203 | adr = cs->hw.spt.cfg_reg + j * 1024; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | release_region(adr, 8); |
| 205 | } |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 206 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
Greg Kroah-Hartman | ed5a84c | 2012-12-21 13:13:05 -0800 | [diff] [blame] | 210 | int setup_sportster(struct IsdnCard *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | struct IsdnCardState *cs = card->cs; |
| 213 | char tmp[64]; |
| 214 | |
| 215 | strcpy(tmp, sportster_revision); |
| 216 | printk(KERN_INFO "HiSax: USR Sportster driver Rev. %s\n", HiSax_getrev(tmp)); |
| 217 | if (cs->typ != ISDN_CTYPE_SPORTSTER) |
| 218 | return (0); |
| 219 | |
| 220 | cs->hw.spt.cfg_reg = card->para[1]; |
| 221 | cs->irq = card->para[0]; |
| 222 | if (!get_io_range(cs)) |
| 223 | return (0); |
| 224 | cs->hw.spt.isac = cs->hw.spt.cfg_reg + SPORTSTER_ISAC; |
| 225 | cs->hw.spt.hscx[0] = cs->hw.spt.cfg_reg + SPORTSTER_HSCXA; |
| 226 | cs->hw.spt.hscx[1] = cs->hw.spt.cfg_reg + SPORTSTER_HSCXB; |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 227 | |
| 228 | switch (cs->irq) { |
| 229 | case 5: cs->hw.spt.res_irq = 1; |
| 230 | break; |
| 231 | case 7: cs->hw.spt.res_irq = 2; |
| 232 | break; |
| 233 | case 10:cs->hw.spt.res_irq = 3; |
| 234 | break; |
| 235 | case 11:cs->hw.spt.res_irq = 4; |
| 236 | break; |
| 237 | case 12:cs->hw.spt.res_irq = 5; |
| 238 | break; |
| 239 | case 14:cs->hw.spt.res_irq = 6; |
| 240 | break; |
| 241 | case 15:cs->hw.spt.res_irq = 7; |
| 242 | break; |
| 243 | default:release_io_sportster(cs); |
| 244 | printk(KERN_WARNING "Sportster: wrong IRQ\n"); |
| 245 | return (0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
Jeff Garzik | 8349304 | 2007-10-31 03:42:07 -0400 | [diff] [blame] | 247 | printk(KERN_INFO "HiSax: USR Sportster config irq:%d cfg:0x%X\n", |
Joe Perches | 475be4d | 2012-02-19 19:52:38 -0800 | [diff] [blame] | 248 | cs->irq, cs->hw.spt.cfg_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | setup_isac(cs); |
| 250 | cs->readisac = &ReadISAC; |
| 251 | cs->writeisac = &WriteISAC; |
| 252 | cs->readisacfifo = &ReadISACfifo; |
| 253 | cs->writeisacfifo = &WriteISACfifo; |
| 254 | cs->BC_Read_Reg = &ReadHSCX; |
| 255 | cs->BC_Write_Reg = &WriteHSCX; |
| 256 | cs->BC_Send_Data = &hscx_fill_fifo; |
| 257 | cs->cardmsg = &Sportster_card_msg; |
| 258 | cs->irq_func = &sportster_interrupt; |
| 259 | ISACVersion(cs, "Sportster:"); |
| 260 | if (HscxVersion(cs, "Sportster:")) { |
| 261 | printk(KERN_WARNING |
| 262 | "Sportster: wrong HSCX versions check IO address\n"); |
| 263 | release_io_sportster(cs); |
| 264 | return (0); |
| 265 | } |
| 266 | return (1); |
| 267 | } |