blob: eb1423ede75cae8032a0729fdb115e54fa9e7c86 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * proteon.c: A network driver for Proteon ISA token ring cards.
3 *
4 * Based on tmspci written 1999 by Adam Fritzler
5 *
6 * Written 2003 by Jochen Friedrich
7 *
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 * This driver module supports the following cards:
12 * - Proteon 1392, 1392+
13 *
14 * Maintainer(s):
15 * AF Adam Fritzler mid@auk.cx
16 * JF Jochen Friedrich jochen@scram.de
17 *
18 * Modification History:
19 * 02-Jan-03 JF Created
20 *
21 */
22static const char version[] = "proteon.c: v1.00 02/01/2003 by Jochen Friedrich\n";
23
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
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>
38
39#include "tms380tr.h"
40
41#define PROTEON_IO_EXTENT 32
42
43/* A zero-terminated list of I/O addresses to be probed. */
44static 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.
49 0
50};
51
52/* A zero-terminated list of IRQs to be probed. */
53static unsigned short irqlist[] = {
54 7, 6, 5, 4, 3, 12, 11, 10, 9,
55 0
56};
57
58/* A zero-terminated list of DMAs to be probed. */
59static int dmalist[] __initdata = {
60 5, 6, 7,
61 0
62};
63
64static char cardname[] = "Proteon 1392\0";
Jochen Friedrich504ff162005-07-27 01:14:50 -070065static u64 dma_mask = ISA_MAX_ADDRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static int proteon_open(struct net_device *dev);
67static void proteon_read_eeprom(struct net_device *dev);
68static unsigned short proteon_setnselout_pins(struct net_device *dev);
69
70static unsigned short proteon_sifreadb(struct net_device *dev, unsigned short reg)
71{
72 return inb(dev->base_addr + reg);
73}
74
75static unsigned short proteon_sifreadw(struct net_device *dev, unsigned short reg)
76{
77 return inw(dev->base_addr + reg);
78}
79
80static void proteon_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg)
81{
82 outb(val, dev->base_addr + reg);
83}
84
85static void proteon_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg)
86{
87 outw(val, dev->base_addr + reg);
88}
89
90static int __init proteon_probe1(struct net_device *dev, int ioaddr)
91{
92 unsigned char chk1, chk2;
93 int i;
94
95 if (!request_region(ioaddr, PROTEON_IO_EXTENT, cardname))
96 return -ENODEV;
97
98
99 chk1 = inb(ioaddr + 0x1f); /* Get Proteon ID reg 1 */
100 if (chk1 != 0x1f)
101 goto nodev;
102
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)
107 goto nodev;
108 chk1 = chk2;
109 }
110
111 dev->base_addr = ioaddr;
112 return (0);
113nodev:
114 release_region(ioaddr, PROTEON_IO_EXTENT);
115 return -ENODEV;
116}
117
Jochen Friedrich504ff162005-07-27 01:14:50 -0700118static int __init setup_card(struct net_device *dev, struct device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
120 struct net_local *tp;
121 static int versionprinted;
122 const unsigned *port;
123 int j,err = 0;
124
125 if (!dev)
126 return -ENOMEM;
127
128 SET_MODULE_OWNER(dev);
129 if (dev->base_addr) /* probe specific location */
130 err = proteon_probe1(dev, dev->base_addr);
131 else {
132 for (port = portlist; *port; port++) {
133 err = proteon_probe1(dev, *port);
134 if (!err)
135 break;
136 }
137 }
138 if (err)
Jochen Friedrich504ff162005-07-27 01:14:50 -0700139 goto out5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 /* At this point we have found a valid card. */
142
143 if (versionprinted++ == 0)
144 printk(KERN_DEBUG "%s", version);
145
146 err = -EIO;
Jochen Friedrich504ff162005-07-27 01:14:50 -0700147 pdev->dma_mask = &dma_mask;
Jochen Friedrich84c3ea02005-08-19 21:05:56 -0400148 if (tmsdev_init(dev, pdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 goto out4;
150
151 dev->base_addr &= ~3;
152
153 proteon_read_eeprom(dev);
154
Jochen Friedrich504ff162005-07-27 01:14:50 -0700155 printk(KERN_DEBUG "proteon.c: Ring Station Address: ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 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");
160
161 tp = netdev_priv(dev);
162 tp->setnselout = proteon_setnselout_pins;
163
164 tp->sifreadb = proteon_sifreadb;
165 tp->sifreadw = proteon_sifreadw;
166 tp->sifwriteb = proteon_sifwriteb;
167 tp->sifwritew = proteon_sifwritew;
168
169 memcpy(tp->ProductID, cardname, PROD_ID_SIZE + 1);
170
171 tp->tmspriv = NULL;
172
173 dev->open = proteon_open;
174 dev->stop = tms380tr_close;
175
176 if (dev->irq == 0)
177 {
178 for(j = 0; irqlist[j] != 0; j++)
179 {
180 dev->irq = irqlist[j];
181 if (!request_irq(dev->irq, tms380tr_interrupt, 0,
182 cardname, dev))
183 break;
184 }
185
186 if(irqlist[j] == 0)
187 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700188 printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 goto out3;
190 }
191 }
192 else
193 {
194 for(j = 0; irqlist[j] != 0; j++)
195 if (irqlist[j] == dev->irq)
196 break;
197 if (irqlist[j] == 0)
198 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700199 printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n",
200 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 goto out3;
202 }
203 if (request_irq(dev->irq, tms380tr_interrupt, 0,
204 cardname, dev))
205 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700206 printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n",
207 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 goto out3;
209 }
210 }
211
212 if (dev->dma == 0)
213 {
214 for(j = 0; dmalist[j] != 0; j++)
215 {
216 dev->dma = dmalist[j];
217 if (!request_dma(dev->dma, cardname))
218 break;
219 }
220
221 if(dmalist[j] == 0)
222 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700223 printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 goto out2;
225 }
226 }
227 else
228 {
229 for(j = 0; dmalist[j] != 0; j++)
230 if (dmalist[j] == dev->dma)
231 break;
232 if (dmalist[j] == 0)
233 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700234 printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n",
235 dev->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 goto out2;
237 }
238 if (request_dma(dev->dma, cardname))
239 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700240 printk(KERN_INFO "proteon.c: Selected DMA %d not available\n",
241 dev->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 goto out2;
243 }
244 }
245
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 err = register_netdev(dev);
247 if (err)
248 goto out;
249
Jochen Friedrich504ff162005-07-27 01:14:50 -0700250 printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
251 dev->name, dev->base_addr, dev->irq, dev->dma);
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 return 0;
254out:
255 free_dma(dev->dma);
256out2:
257 free_irq(dev->irq, dev);
258out3:
259 tmsdev_term(dev);
260out4:
Jochen Friedrich504ff162005-07-27 01:14:50 -0700261 release_region(dev->base_addr, PROTEON_IO_EXTENT);
262out5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 return err;
264}
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266/*
267 * Reads MAC address from adapter RAM, which should've read it from
268 * the onboard ROM.
269 *
270 * Calling this on a board that does not support it can be a very
271 * dangerous thing. The Madge board, for instance, will lock your
272 * machine hard when this is called. Luckily, its supported in a
273 * separate driver. --ASF
274 */
275static void proteon_read_eeprom(struct net_device *dev)
276{
277 int i;
278
279 /* Address: 0000:0000 */
280 proteon_sifwritew(dev, 0, SIFADX);
281 proteon_sifwritew(dev, 0, SIFADR);
282
283 /* Read six byte MAC address data */
284 dev->addr_len = 6;
285 for(i = 0; i < 6; i++)
286 dev->dev_addr[i] = proteon_sifreadw(dev, SIFINC) >> 8;
287}
288
289unsigned short proteon_setnselout_pins(struct net_device *dev)
290{
291 return 0;
292}
293
294static int proteon_open(struct net_device *dev)
295{
296 struct net_local *tp = netdev_priv(dev);
297 unsigned short val = 0;
298 int i;
299
300 /* Proteon reset sequence */
301 outb(0, dev->base_addr + 0x11);
302 mdelay(20);
303 outb(0x04, dev->base_addr + 0x11);
304 mdelay(20);
305 outb(0, dev->base_addr + 0x11);
306 mdelay(100);
307
308 /* set control/status reg */
309 val = inb(dev->base_addr + 0x11);
310 val |= 0x78;
311 val &= 0xf9;
312 if(tp->DataRate == SPEED_4)
313 val |= 0x20;
314 else
315 val &= ~0x20;
316
317 outb(val, dev->base_addr + 0x11);
318 outb(0xff, dev->base_addr + 0x12);
319 for(i = 0; irqlist[i] != 0; i++)
320 {
321 if(irqlist[i] == dev->irq)
322 break;
323 }
324 val = i;
325 i = (7 - dev->dma) << 4;
326 val |= i;
327 outb(val, dev->base_addr + 0x13);
328
329 return tms380tr_open(dev);
330}
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332#define ISATR_MAX_ADAPTERS 3
333
334static int io[ISATR_MAX_ADAPTERS];
335static int irq[ISATR_MAX_ADAPTERS];
336static int dma[ISATR_MAX_ADAPTERS];
337
338MODULE_LICENSE("GPL");
339
340module_param_array(io, int, NULL, 0);
341module_param_array(irq, int, NULL, 0);
342module_param_array(dma, int, NULL, 0);
343
Jochen Friedrich504ff162005-07-27 01:14:50 -0700344static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
Jochen Friedrich504ff162005-07-27 01:14:50 -0700346static struct device_driver proteon_driver = {
347 .name = "proteon",
348 .bus = &platform_bus_type,
349};
350
351static int __init proteon_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352{
353 struct net_device *dev;
Jochen Friedrich504ff162005-07-27 01:14:50 -0700354 struct platform_device *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 int i, num = 0, err = 0;
356
Jochen Friedrich504ff162005-07-27 01:14:50 -0700357 err = driver_register(&proteon_driver);
358 if (err)
359 return err;
360
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
362 dev = alloc_trdev(sizeof(struct net_local));
363 if (!dev)
364 continue;
365
366 dev->base_addr = io[i];
367 dev->irq = irq[i];
368 dev->dma = dma[i];
Jochen Friedrich504ff162005-07-27 01:14:50 -0700369 pdev = platform_device_register_simple("proteon",
370 i, NULL, 0);
371 err = setup_card(dev, &pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 if (!err) {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700373 proteon_dev[i] = pdev;
374 dev_set_drvdata(&pdev->dev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 ++num;
376 } else {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700377 platform_device_unregister(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 free_netdev(dev);
379 }
380 }
381
382 printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
383 /* Probe for cards. */
384 if (num == 0) {
385 printk(KERN_NOTICE "proteon.c: No cards found.\n");
386 return (-ENODEV);
387 }
388 return (0);
389}
390
Jochen Friedrich504ff162005-07-27 01:14:50 -0700391static void __exit proteon_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Jochen Friedrich504ff162005-07-27 01:14:50 -0700393 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 int i;
395
396 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700397 struct platform_device *pdev = proteon_dev[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Jochen Friedrich504ff162005-07-27 01:14:50 -0700399 if (!pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 continue;
Jochen Friedrich504ff162005-07-27 01:14:50 -0700401 dev = dev_get_drvdata(&pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 unregister_netdev(dev);
403 release_region(dev->base_addr, PROTEON_IO_EXTENT);
404 free_irq(dev->irq, dev);
405 free_dma(dev->dma);
406 tmsdev_term(dev);
407 free_netdev(dev);
Jochen Friedrich504ff162005-07-27 01:14:50 -0700408 dev_set_drvdata(&pdev->dev, NULL);
409 platform_device_unregister(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
Jochen Friedrich504ff162005-07-27 01:14:50 -0700411 driver_unregister(&proteon_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
Jochen Friedrich504ff162005-07-27 01:14:50 -0700414module_init(proteon_init);
415module_exit(proteon_cleanup);