Initial commit
[wrt350n-kernel.git] / drivers / net / tokenring / proteon.c
blob00ea94513460d5e118b811a3496625b98ad4a9cb
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
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>
34 #include <asm/system.h>
35 #include <asm/io.h>
36 #include <asm/irq.h>
37 #include <asm/pci.h>
38 #include <asm/dma.h>
40 #include "tms380tr.h"
42 #define PROTEON_IO_EXTENT 32
44 /* A zero-terminated list of I/O addresses to be probed. */
45 static unsigned int portlist[] __initdata = {
46 0x0A20, 0x0E20, 0x1A20, 0x1E20, 0x2A20, 0x2E20, 0x3A20, 0x3E20,// Prot.
47 0x4A20, 0x4E20, 0x5A20, 0x5E20, 0x6A20, 0x6E20, 0x7A20, 0x7E20,// Prot.
48 0x8A20, 0x8E20, 0x9A20, 0x9E20, 0xAA20, 0xAE20, 0xBA20, 0xBE20,// Prot.
49 0xCA20, 0xCE20, 0xDA20, 0xDE20, 0xEA20, 0xEE20, 0xFA20, 0xFE20,// Prot.
53 /* A zero-terminated list of IRQs to be probed. */
54 static unsigned short irqlist[] = {
55 7, 6, 5, 4, 3, 12, 11, 10, 9,
59 /* A zero-terminated list of DMAs to be probed. */
60 static int dmalist[] __initdata = {
61 5, 6, 7,
65 static char cardname[] = "Proteon 1392\0";
66 static u64 dma_mask = ISA_MAX_ADDRESS;
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, struct device *pdev)
121 struct net_local *tp;
122 static int versionprinted;
123 const unsigned *port;
124 int j,err = 0;
125 DECLARE_MAC_BUF(mac);
127 if (!dev)
128 return -ENOMEM;
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 out5;
142 /* At this point we have found a valid card. */
144 if (versionprinted++ == 0)
145 printk(KERN_DEBUG "%s", version);
147 err = -EIO;
148 pdev->dma_mask = &dma_mask;
149 if (tmsdev_init(dev, pdev))
150 goto out4;
152 dev->base_addr &= ~3;
154 proteon_read_eeprom(dev);
156 printk(KERN_DEBUG "proteon.c: Ring Station Address: %s\n",
157 print_mac(mac, dev->dev_addr));
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);
169 tp->tmspriv = NULL;
171 dev->open = proteon_open;
172 dev->stop = tms380tr_close;
174 if (dev->irq == 0)
176 for(j = 0; irqlist[j] != 0; j++)
178 dev->irq = irqlist[j];
179 if (!request_irq(dev->irq, tms380tr_interrupt, 0,
180 cardname, dev))
181 break;
184 if(irqlist[j] == 0)
186 printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n");
187 goto out3;
190 else
192 for(j = 0; irqlist[j] != 0; j++)
193 if (irqlist[j] == dev->irq)
194 break;
195 if (irqlist[j] == 0)
197 printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n",
198 dev->irq);
199 goto out3;
201 if (request_irq(dev->irq, tms380tr_interrupt, 0,
202 cardname, dev))
204 printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n",
205 dev->irq);
206 goto out3;
210 if (dev->dma == 0)
212 for(j = 0; dmalist[j] != 0; j++)
214 dev->dma = dmalist[j];
215 if (!request_dma(dev->dma, cardname))
216 break;
219 if(dmalist[j] == 0)
221 printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n");
222 goto out2;
225 else
227 for(j = 0; dmalist[j] != 0; j++)
228 if (dmalist[j] == dev->dma)
229 break;
230 if (dmalist[j] == 0)
232 printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n",
233 dev->dma);
234 goto out2;
236 if (request_dma(dev->dma, cardname))
238 printk(KERN_INFO "proteon.c: Selected DMA %d not available\n",
239 dev->dma);
240 goto out2;
244 err = register_netdev(dev);
245 if (err)
246 goto out;
248 printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
249 dev->name, dev->base_addr, dev->irq, dev->dma);
251 return 0;
252 out:
253 free_dma(dev->dma);
254 out2:
255 free_irq(dev->irq, dev);
256 out3:
257 tmsdev_term(dev);
258 out4:
259 release_region(dev->base_addr, PROTEON_IO_EXTENT);
260 out5:
261 return err;
265 * Reads MAC address from adapter RAM, which should've read it from
266 * the onboard ROM.
268 * Calling this on a board that does not support it can be a very
269 * dangerous thing. The Madge board, for instance, will lock your
270 * machine hard when this is called. Luckily, its supported in a
271 * separate driver. --ASF
273 static void proteon_read_eeprom(struct net_device *dev)
275 int i;
277 /* Address: 0000:0000 */
278 proteon_sifwritew(dev, 0, SIFADX);
279 proteon_sifwritew(dev, 0, SIFADR);
281 /* Read six byte MAC address data */
282 dev->addr_len = 6;
283 for(i = 0; i < 6; i++)
284 dev->dev_addr[i] = proteon_sifreadw(dev, SIFINC) >> 8;
287 unsigned short proteon_setnselout_pins(struct net_device *dev)
289 return 0;
292 static int proteon_open(struct net_device *dev)
294 struct net_local *tp = netdev_priv(dev);
295 unsigned short val = 0;
296 int i;
298 /* Proteon reset sequence */
299 outb(0, dev->base_addr + 0x11);
300 mdelay(20);
301 outb(0x04, dev->base_addr + 0x11);
302 mdelay(20);
303 outb(0, dev->base_addr + 0x11);
304 mdelay(100);
306 /* set control/status reg */
307 val = inb(dev->base_addr + 0x11);
308 val |= 0x78;
309 val &= 0xf9;
310 if(tp->DataRate == SPEED_4)
311 val |= 0x20;
312 else
313 val &= ~0x20;
315 outb(val, dev->base_addr + 0x11);
316 outb(0xff, dev->base_addr + 0x12);
317 for(i = 0; irqlist[i] != 0; i++)
319 if(irqlist[i] == dev->irq)
320 break;
322 val = i;
323 i = (7 - dev->dma) << 4;
324 val |= i;
325 outb(val, dev->base_addr + 0x13);
327 return tms380tr_open(dev);
330 #define ISATR_MAX_ADAPTERS 3
332 static int io[ISATR_MAX_ADAPTERS];
333 static int irq[ISATR_MAX_ADAPTERS];
334 static int dma[ISATR_MAX_ADAPTERS];
336 MODULE_LICENSE("GPL");
338 module_param_array(io, int, NULL, 0);
339 module_param_array(irq, int, NULL, 0);
340 module_param_array(dma, int, NULL, 0);
342 static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS];
344 static struct platform_driver proteon_driver = {
345 .driver = {
346 .name = "proteon",
350 static int __init proteon_init(void)
352 struct net_device *dev;
353 struct platform_device *pdev;
354 int i, num = 0, err = 0;
356 err = platform_driver_register(&proteon_driver);
357 if (err)
358 return err;
360 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
361 dev = alloc_trdev(sizeof(struct net_local));
362 if (!dev)
363 continue;
365 dev->base_addr = io[i];
366 dev->irq = irq[i];
367 dev->dma = dma[i];
368 pdev = platform_device_register_simple("proteon",
369 i, NULL, 0);
370 if (IS_ERR(pdev)) {
371 free_netdev(dev);
372 continue;
374 err = setup_card(dev, &pdev->dev);
375 if (!err) {
376 proteon_dev[i] = pdev;
377 platform_set_drvdata(pdev, dev);
378 ++num;
379 } else {
380 platform_device_unregister(pdev);
381 free_netdev(dev);
385 printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
386 /* Probe for cards. */
387 if (num == 0) {
388 printk(KERN_NOTICE "proteon.c: No cards found.\n");
389 platform_driver_unregister(&proteon_driver);
390 return -ENODEV;
392 return 0;
395 static void __exit proteon_cleanup(void)
397 struct net_device *dev;
398 int i;
400 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
401 struct platform_device *pdev = proteon_dev[i];
403 if (!pdev)
404 continue;
405 dev = platform_get_drvdata(pdev);
406 unregister_netdev(dev);
407 release_region(dev->base_addr, PROTEON_IO_EXTENT);
408 free_irq(dev->irq, dev);
409 free_dma(dev->dma);
410 tmsdev_term(dev);
411 free_netdev(dev);
412 platform_set_drvdata(pdev, NULL);
413 platform_device_unregister(pdev);
415 platform_driver_unregister(&proteon_driver);
418 module_init(proteon_init);
419 module_exit(proteon_cleanup);