Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / tokenring / proteon.c
blob675b063508e37a8b66117594b4c50c3f66cfbadd
1 /*
2 * proteon.c: A network driver for Proteon ISA token ring cards.
4 * Based on tmspci written 1999 by Adam Fritzler
5 *
6 * Written 2003 by Jochen Friedrich
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
11 * This driver module supports the following cards:
12 * - Proteon 1392, 1392+
14 * Maintainer(s):
15 * AF Adam Fritzler mid@auk.cx
16 * JF Jochen Friedrich jochen@scram.de
18 * Modification History:
19 * 02-Jan-03 JF Created
22 static const char version[] = "proteon.c: v1.00 02/01/2003 by Jochen Friedrich\n";
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/delay.h>
27 #include <linux/errno.h>
28 #include <linux/pci.h>
29 #include <linux/init.h>
30 #include <linux/netdevice.h>
31 #include <linux/trdevice.h>
33 #include <asm/system.h>
34 #include <asm/io.h>
35 #include <asm/irq.h>
36 #include <asm/pci.h>
37 #include <asm/dma.h>
39 #include "tms380tr.h"
41 #define PROTEON_IO_EXTENT 32
43 /* A zero-terminated list of I/O addresses to be probed. */
44 static unsigned int portlist[] __initdata = {
45 0x0A20, 0x0E20, 0x1A20, 0x1E20, 0x2A20, 0x2E20, 0x3A20, 0x3E20,// Prot.
46 0x4A20, 0x4E20, 0x5A20, 0x5E20, 0x6A20, 0x6E20, 0x7A20, 0x7E20,// Prot.
47 0x8A20, 0x8E20, 0x9A20, 0x9E20, 0xAA20, 0xAE20, 0xBA20, 0xBE20,// Prot.
48 0xCA20, 0xCE20, 0xDA20, 0xDE20, 0xEA20, 0xEE20, 0xFA20, 0xFE20,// Prot.
52 /* A zero-terminated list of IRQs to be probed. */
53 static unsigned short irqlist[] = {
54 7, 6, 5, 4, 3, 12, 11, 10, 9,
58 /* A zero-terminated list of DMAs to be probed. */
59 static int dmalist[] __initdata = {
60 5, 6, 7,
64 static char cardname[] = "Proteon 1392\0";
66 struct net_device *proteon_probe(int unit);
67 static int proteon_open(struct net_device *dev);
68 static void proteon_read_eeprom(struct net_device *dev);
69 static unsigned short proteon_setnselout_pins(struct net_device *dev);
71 static unsigned short proteon_sifreadb(struct net_device *dev, unsigned short reg)
73 return inb(dev->base_addr + reg);
76 static unsigned short proteon_sifreadw(struct net_device *dev, unsigned short reg)
78 return inw(dev->base_addr + reg);
81 static void proteon_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg)
83 outb(val, dev->base_addr + reg);
86 static void proteon_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg)
88 outw(val, dev->base_addr + reg);
91 static int __init proteon_probe1(struct net_device *dev, int ioaddr)
93 unsigned char chk1, chk2;
94 int i;
96 if (!request_region(ioaddr, PROTEON_IO_EXTENT, cardname))
97 return -ENODEV;
100 chk1 = inb(ioaddr + 0x1f); /* Get Proteon ID reg 1 */
101 if (chk1 != 0x1f)
102 goto nodev;
104 chk1 = inb(ioaddr + 0x1e) & 0x07; /* Get Proteon ID reg 0 */
105 for (i=0; i<16; i++) {
106 chk2 = inb(ioaddr + 0x1e) & 0x07;
107 if (((chk1 + 1) & 0x07) != chk2)
108 goto nodev;
109 chk1 = chk2;
112 dev->base_addr = ioaddr;
113 return (0);
114 nodev:
115 release_region(ioaddr, PROTEON_IO_EXTENT);
116 return -ENODEV;
119 static int __init setup_card(struct net_device *dev)
121 struct net_local *tp;
122 static int versionprinted;
123 const unsigned *port;
124 int j,err = 0;
126 if (!dev)
127 return -ENOMEM;
129 SET_MODULE_OWNER(dev);
130 if (dev->base_addr) /* probe specific location */
131 err = proteon_probe1(dev, dev->base_addr);
132 else {
133 for (port = portlist; *port; port++) {
134 err = proteon_probe1(dev, *port);
135 if (!err)
136 break;
139 if (err)
140 goto out4;
142 /* At this point we have found a valid card. */
144 if (versionprinted++ == 0)
145 printk(KERN_DEBUG "%s", version);
147 err = -EIO;
148 if (tmsdev_init(dev, ISA_MAX_ADDRESS, NULL))
149 goto out4;
151 dev->base_addr &= ~3;
153 proteon_read_eeprom(dev);
155 printk(KERN_DEBUG "%s: Ring Station Address: ", dev->name);
156 printk("%2.2x", dev->dev_addr[0]);
157 for (j = 1; j < 6; j++)
158 printk(":%2.2x", dev->dev_addr[j]);
159 printk("\n");
161 tp = netdev_priv(dev);
162 tp->setnselout = proteon_setnselout_pins;
164 tp->sifreadb = proteon_sifreadb;
165 tp->sifreadw = proteon_sifreadw;
166 tp->sifwriteb = proteon_sifwriteb;
167 tp->sifwritew = proteon_sifwritew;
169 memcpy(tp->ProductID, cardname, PROD_ID_SIZE + 1);
171 tp->tmspriv = NULL;
173 dev->open = proteon_open;
174 dev->stop = tms380tr_close;
176 if (dev->irq == 0)
178 for(j = 0; irqlist[j] != 0; j++)
180 dev->irq = irqlist[j];
181 if (!request_irq(dev->irq, tms380tr_interrupt, 0,
182 cardname, dev))
183 break;
186 if(irqlist[j] == 0)
188 printk(KERN_INFO "%s: AutoSelect no IRQ available\n", dev->name);
189 goto out3;
192 else
194 for(j = 0; irqlist[j] != 0; j++)
195 if (irqlist[j] == dev->irq)
196 break;
197 if (irqlist[j] == 0)
199 printk(KERN_INFO "%s: Illegal IRQ %d specified\n",
200 dev->name, dev->irq);
201 goto out3;
203 if (request_irq(dev->irq, tms380tr_interrupt, 0,
204 cardname, dev))
206 printk(KERN_INFO "%s: Selected IRQ %d not available\n",
207 dev->name, dev->irq);
208 goto out3;
212 if (dev->dma == 0)
214 for(j = 0; dmalist[j] != 0; j++)
216 dev->dma = dmalist[j];
217 if (!request_dma(dev->dma, cardname))
218 break;
221 if(dmalist[j] == 0)
223 printk(KERN_INFO "%s: AutoSelect no DMA available\n", dev->name);
224 goto out2;
227 else
229 for(j = 0; dmalist[j] != 0; j++)
230 if (dmalist[j] == dev->dma)
231 break;
232 if (dmalist[j] == 0)
234 printk(KERN_INFO "%s: Illegal DMA %d specified\n",
235 dev->name, dev->dma);
236 goto out2;
238 if (request_dma(dev->dma, cardname))
240 printk(KERN_INFO "%s: Selected DMA %d not available\n",
241 dev->name, dev->dma);
242 goto out2;
246 printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
247 dev->name, dev->base_addr, dev->irq, dev->dma);
249 err = register_netdev(dev);
250 if (err)
251 goto out;
253 return 0;
254 out:
255 free_dma(dev->dma);
256 out2:
257 free_irq(dev->irq, dev);
258 out3:
259 tmsdev_term(dev);
260 out4:
261 release_region(dev->base_addr, PROTEON_IO_EXTENT);
262 return err;
265 struct net_device * __init proteon_probe(int unit)
267 struct net_device *dev = alloc_trdev(sizeof(struct net_local));
268 int err = 0;
270 if (!dev)
271 return ERR_PTR(-ENOMEM);
273 if (unit >= 0) {
274 sprintf(dev->name, "tr%d", unit);
275 netdev_boot_setup_check(dev);
278 err = setup_card(dev);
279 if (err)
280 goto out;
282 return dev;
284 out:
285 free_netdev(dev);
286 return ERR_PTR(err);
290 * Reads MAC address from adapter RAM, which should've read it from
291 * the onboard ROM.
293 * Calling this on a board that does not support it can be a very
294 * dangerous thing. The Madge board, for instance, will lock your
295 * machine hard when this is called. Luckily, its supported in a
296 * separate driver. --ASF
298 static void proteon_read_eeprom(struct net_device *dev)
300 int i;
302 /* Address: 0000:0000 */
303 proteon_sifwritew(dev, 0, SIFADX);
304 proteon_sifwritew(dev, 0, SIFADR);
306 /* Read six byte MAC address data */
307 dev->addr_len = 6;
308 for(i = 0; i < 6; i++)
309 dev->dev_addr[i] = proteon_sifreadw(dev, SIFINC) >> 8;
312 unsigned short proteon_setnselout_pins(struct net_device *dev)
314 return 0;
317 static int proteon_open(struct net_device *dev)
319 struct net_local *tp = netdev_priv(dev);
320 unsigned short val = 0;
321 int i;
323 /* Proteon reset sequence */
324 outb(0, dev->base_addr + 0x11);
325 mdelay(20);
326 outb(0x04, dev->base_addr + 0x11);
327 mdelay(20);
328 outb(0, dev->base_addr + 0x11);
329 mdelay(100);
331 /* set control/status reg */
332 val = inb(dev->base_addr + 0x11);
333 val |= 0x78;
334 val &= 0xf9;
335 if(tp->DataRate == SPEED_4)
336 val |= 0x20;
337 else
338 val &= ~0x20;
340 outb(val, dev->base_addr + 0x11);
341 outb(0xff, dev->base_addr + 0x12);
342 for(i = 0; irqlist[i] != 0; i++)
344 if(irqlist[i] == dev->irq)
345 break;
347 val = i;
348 i = (7 - dev->dma) << 4;
349 val |= i;
350 outb(val, dev->base_addr + 0x13);
352 return tms380tr_open(dev);
355 #ifdef MODULE
357 #define ISATR_MAX_ADAPTERS 3
359 static int io[ISATR_MAX_ADAPTERS];
360 static int irq[ISATR_MAX_ADAPTERS];
361 static int dma[ISATR_MAX_ADAPTERS];
363 MODULE_LICENSE("GPL");
365 module_param_array(io, int, NULL, 0);
366 module_param_array(irq, int, NULL, 0);
367 module_param_array(dma, int, NULL, 0);
369 static struct net_device *proteon_dev[ISATR_MAX_ADAPTERS];
371 int init_module(void)
373 struct net_device *dev;
374 int i, num = 0, err = 0;
376 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
377 dev = alloc_trdev(sizeof(struct net_local));
378 if (!dev)
379 continue;
381 dev->base_addr = io[i];
382 dev->irq = irq[i];
383 dev->dma = dma[i];
384 err = setup_card(dev);
385 if (!err) {
386 proteon_dev[i] = dev;
387 ++num;
388 } else {
389 free_netdev(dev);
393 printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
394 /* Probe for cards. */
395 if (num == 0) {
396 printk(KERN_NOTICE "proteon.c: No cards found.\n");
397 return (-ENODEV);
399 return (0);
402 void cleanup_module(void)
404 int i;
406 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
407 struct net_device *dev = proteon_dev[i];
409 if (!dev)
410 continue;
412 unregister_netdev(dev);
413 release_region(dev->base_addr, PROTEON_IO_EXTENT);
414 free_irq(dev->irq, dev);
415 free_dma(dev->dma);
416 tmsdev_term(dev);
417 free_netdev(dev);
420 #endif /* MODULE */
424 * Local variables:
425 * compile-command: "gcc -DMODVERSIONS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c proteon.c"
426 * alt-compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer -I/usr/src/linux/drivers/net/tokenring/ -c proteon.c"
427 * c-set-style "K&R"
428 * c-indent-level: 8
429 * c-basic-offset: 8
430 * tab-width: 8
431 * End: