2 * proteon.c: A network driver for Proteon ISA token ring cards.
4 * Based on tmspci written 1999 by Adam Fritzler
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+
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>
32 #include <linux/platform_device.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 = {
64 static char cardname[] = "Proteon 1392\0";
65 static u64 dma_mask = ISA_MAX_ADDRESS;
66 static int proteon_open(struct net_device *dev);
67 static void proteon_read_eeprom(struct net_device *dev);
68 static unsigned short proteon_setnselout_pins(struct net_device *dev);
70 static unsigned short proteon_sifreadb(struct net_device *dev, unsigned short reg)
72 return inb(dev->base_addr + reg);
75 static unsigned short proteon_sifreadw(struct net_device *dev, unsigned short reg)
77 return inw(dev->base_addr + reg);
80 static void proteon_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg)
82 outb(val, dev->base_addr + reg);
85 static void proteon_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg)
87 outw(val, dev->base_addr + reg);
90 static int __init proteon_probe1(struct net_device *dev, int ioaddr)
92 unsigned char chk1, chk2;
95 if (!request_region(ioaddr, PROTEON_IO_EXTENT, cardname))
99 chk1 = inb(ioaddr + 0x1f); /* Get Proteon ID reg 1 */
103 chk1 = inb(ioaddr + 0x1e) & 0x07; /* Get Proteon ID reg 0 */
104 for (i=0; i<16; i++) {
105 chk2 = inb(ioaddr + 0x1e) & 0x07;
106 if (((chk1 + 1) & 0x07) != chk2)
111 dev->base_addr = ioaddr;
114 release_region(ioaddr, PROTEON_IO_EXTENT);
118 static struct net_device_ops proteon_netdev_ops __read_mostly;
120 static int __init setup_card(struct net_device *dev, struct device *pdev)
122 struct net_local *tp;
123 static int versionprinted;
124 const unsigned *port;
130 if (dev->base_addr) /* probe specific location */
131 err = proteon_probe1(dev, dev->base_addr);
133 for (port = portlist; *port; port++) {
134 err = proteon_probe1(dev, *port);
142 /* At this point we have found a valid card. */
144 if (versionprinted++ == 0)
145 printk(KERN_DEBUG "%s", version);
148 pdev->dma_mask = &dma_mask;
149 if (tmsdev_init(dev, pdev))
152 dev->base_addr &= ~3;
154 proteon_read_eeprom(dev);
156 printk(KERN_DEBUG "proteon.c: Ring Station Address: %pM\n",
159 tp = netdev_priv(dev);
160 tp->setnselout = proteon_setnselout_pins;
162 tp->sifreadb = proteon_sifreadb;
163 tp->sifreadw = proteon_sifreadw;
164 tp->sifwriteb = proteon_sifwriteb;
165 tp->sifwritew = proteon_sifwritew;
167 memcpy(tp->ProductID, cardname, PROD_ID_SIZE + 1);
171 dev->netdev_ops = &proteon_netdev_ops;
175 for(j = 0; irqlist[j] != 0; j++)
177 dev->irq = irqlist[j];
178 if (!request_irq(dev->irq, tms380tr_interrupt, 0,
185 printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n");
191 for(j = 0; irqlist[j] != 0; j++)
192 if (irqlist[j] == dev->irq)
196 printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n",
200 if (request_irq(dev->irq, tms380tr_interrupt, 0,
203 printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n",
211 for(j = 0; dmalist[j] != 0; j++)
213 dev->dma = dmalist[j];
214 if (!request_dma(dev->dma, cardname))
220 printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n");
226 for(j = 0; dmalist[j] != 0; j++)
227 if (dmalist[j] == dev->dma)
231 printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n",
235 if (request_dma(dev->dma, cardname))
237 printk(KERN_INFO "proteon.c: Selected DMA %d not available\n",
243 err = register_netdev(dev);
247 printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
248 dev->name, dev->base_addr, dev->irq, dev->dma);
254 free_irq(dev->irq, dev);
258 release_region(dev->base_addr, PROTEON_IO_EXTENT);
264 * Reads MAC address from adapter RAM, which should've read it from
267 * Calling this on a board that does not support it can be a very
268 * dangerous thing. The Madge board, for instance, will lock your
269 * machine hard when this is called. Luckily, its supported in a
270 * separate driver. --ASF
272 static void proteon_read_eeprom(struct net_device *dev)
276 /* Address: 0000:0000 */
277 proteon_sifwritew(dev, 0, SIFADX);
278 proteon_sifwritew(dev, 0, SIFADR);
280 /* Read six byte MAC address data */
282 for(i = 0; i < 6; i++)
283 dev->dev_addr[i] = proteon_sifreadw(dev, SIFINC) >> 8;
286 static unsigned short proteon_setnselout_pins(struct net_device *dev)
291 static int proteon_open(struct net_device *dev)
293 struct net_local *tp = netdev_priv(dev);
294 unsigned short val = 0;
297 /* Proteon reset sequence */
298 outb(0, dev->base_addr + 0x11);
300 outb(0x04, dev->base_addr + 0x11);
302 outb(0, dev->base_addr + 0x11);
305 /* set control/status reg */
306 val = inb(dev->base_addr + 0x11);
309 if(tp->DataRate == SPEED_4)
314 outb(val, dev->base_addr + 0x11);
315 outb(0xff, dev->base_addr + 0x12);
316 for(i = 0; irqlist[i] != 0; i++)
318 if(irqlist[i] == dev->irq)
322 i = (7 - dev->dma) << 4;
324 outb(val, dev->base_addr + 0x13);
326 return tms380tr_open(dev);
329 #define ISATR_MAX_ADAPTERS 3
331 static int io[ISATR_MAX_ADAPTERS];
332 static int irq[ISATR_MAX_ADAPTERS];
333 static int dma[ISATR_MAX_ADAPTERS];
335 MODULE_LICENSE("GPL");
337 module_param_array(io, int, NULL, 0);
338 module_param_array(irq, int, NULL, 0);
339 module_param_array(dma, int, NULL, 0);
341 static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS];
343 static struct platform_driver proteon_driver = {
349 static int __init proteon_init(void)
351 struct net_device *dev;
352 struct platform_device *pdev;
353 int i, num = 0, err = 0;
355 proteon_netdev_ops = tms380tr_netdev_ops;
356 proteon_netdev_ops.ndo_open = proteon_open;
357 proteon_netdev_ops.ndo_stop = tms380tr_close;
359 err = platform_driver_register(&proteon_driver);
363 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
364 dev = alloc_trdev(sizeof(struct net_local));
368 dev->base_addr = io[i];
371 pdev = platform_device_register_simple("proteon",
377 err = setup_card(dev, &pdev->dev);
379 proteon_dev[i] = pdev;
380 platform_set_drvdata(pdev, dev);
383 platform_device_unregister(pdev);
388 printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
389 /* Probe for cards. */
391 printk(KERN_NOTICE "proteon.c: No cards found.\n");
392 platform_driver_unregister(&proteon_driver);
398 static void __exit proteon_cleanup(void)
400 struct net_device *dev;
403 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
404 struct platform_device *pdev = proteon_dev[i];
408 dev = platform_get_drvdata(pdev);
409 unregister_netdev(dev);
410 release_region(dev->base_addr, PROTEON_IO_EXTENT);
411 free_irq(dev->irq, dev);
415 platform_set_drvdata(pdev, NULL);
416 platform_device_unregister(pdev);
418 platform_driver_unregister(&proteon_driver);
421 module_init(proteon_init);
422 module_exit(proteon_cleanup);