blob: 8d362e64a40e45ddfbac4bd68a16befe7152dd33 [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):
Joe Perches726a6452008-02-03 16:36:24 +020015 * AF Adam Fritzler
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * 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>
Russell Kingd052d1b2005-10-29 19:07:23 +010032#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
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>
39
40#include "tms380tr.h"
41
42#define PROTEON_IO_EXTENT 32
43
44/* A zero-terminated list of I/O addresses to be probed. */
45static 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.
50 0
51};
52
53/* A zero-terminated list of IRQs to be probed. */
54static unsigned short irqlist[] = {
55 7, 6, 5, 4, 3, 12, 11, 10, 9,
56 0
57};
58
59/* A zero-terminated list of DMAs to be probed. */
60static int dmalist[] __initdata = {
61 5, 6, 7,
62 0
63};
64
65static char cardname[] = "Proteon 1392\0";
Jochen Friedrich504ff162005-07-27 01:14:50 -070066static u64 dma_mask = ISA_MAX_ADDRESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static int proteon_open(struct net_device *dev);
68static void proteon_read_eeprom(struct net_device *dev);
69static unsigned short proteon_setnselout_pins(struct net_device *dev);
70
71static unsigned short proteon_sifreadb(struct net_device *dev, unsigned short reg)
72{
73 return inb(dev->base_addr + reg);
74}
75
76static unsigned short proteon_sifreadw(struct net_device *dev, unsigned short reg)
77{
78 return inw(dev->base_addr + reg);
79}
80
81static void proteon_sifwriteb(struct net_device *dev, unsigned short val, unsigned short reg)
82{
83 outb(val, dev->base_addr + reg);
84}
85
86static void proteon_sifwritew(struct net_device *dev, unsigned short val, unsigned short reg)
87{
88 outw(val, dev->base_addr + reg);
89}
90
91static int __init proteon_probe1(struct net_device *dev, int ioaddr)
92{
93 unsigned char chk1, chk2;
94 int i;
95
96 if (!request_region(ioaddr, PROTEON_IO_EXTENT, cardname))
97 return -ENODEV;
98
99
100 chk1 = inb(ioaddr + 0x1f); /* Get Proteon ID reg 1 */
101 if (chk1 != 0x1f)
102 goto nodev;
103
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;
110 }
111
112 dev->base_addr = ioaddr;
Eric Dumazet807540b2010-09-23 05:40:09 +0000113 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114nodev:
115 release_region(ioaddr, PROTEON_IO_EXTENT);
116 return -ENODEV;
117}
118
Stephen Hemminger79f8ae32009-03-26 15:11:23 +0000119static struct net_device_ops proteon_netdev_ops __read_mostly;
120
Jochen Friedrich504ff162005-07-27 01:14:50 -0700121static int __init setup_card(struct net_device *dev, struct device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122{
123 struct net_local *tp;
124 static int versionprinted;
125 const unsigned *port;
126 int j,err = 0;
127
128 if (!dev)
129 return -ENOMEM;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 if (dev->base_addr) /* probe specific location */
132 err = proteon_probe1(dev, dev->base_addr);
133 else {
134 for (port = portlist; *port; port++) {
135 err = proteon_probe1(dev, *port);
136 if (!err)
137 break;
138 }
139 }
140 if (err)
Jochen Friedrich504ff162005-07-27 01:14:50 -0700141 goto out5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* At this point we have found a valid card. */
144
145 if (versionprinted++ == 0)
146 printk(KERN_DEBUG "%s", version);
147
148 err = -EIO;
Jochen Friedrich504ff162005-07-27 01:14:50 -0700149 pdev->dma_mask = &dma_mask;
Jochen Friedrich84c3ea02005-08-19 21:05:56 -0400150 if (tmsdev_init(dev, pdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 goto out4;
152
153 dev->base_addr &= ~3;
154
155 proteon_read_eeprom(dev);
156
Johannes Berge1749612008-10-27 15:59:26 -0700157 printk(KERN_DEBUG "proteon.c: Ring Station Address: %pM\n",
158 dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160 tp = netdev_priv(dev);
161 tp->setnselout = proteon_setnselout_pins;
162
163 tp->sifreadb = proteon_sifreadb;
164 tp->sifreadw = proteon_sifreadw;
165 tp->sifwriteb = proteon_sifwriteb;
166 tp->sifwritew = proteon_sifwritew;
167
168 memcpy(tp->ProductID, cardname, PROD_ID_SIZE + 1);
169
170 tp->tmspriv = NULL;
171
Stephen Hemminger79f8ae32009-03-26 15:11:23 +0000172 dev->netdev_ops = &proteon_netdev_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 if (dev->irq == 0)
175 {
176 for(j = 0; irqlist[j] != 0; j++)
177 {
178 dev->irq = irqlist[j];
179 if (!request_irq(dev->irq, tms380tr_interrupt, 0,
180 cardname, dev))
181 break;
182 }
183
184 if(irqlist[j] == 0)
185 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700186 printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 goto out3;
188 }
189 }
190 else
191 {
192 for(j = 0; irqlist[j] != 0; j++)
193 if (irqlist[j] == dev->irq)
194 break;
195 if (irqlist[j] == 0)
196 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700197 printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n",
198 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 goto out3;
200 }
201 if (request_irq(dev->irq, tms380tr_interrupt, 0,
202 cardname, dev))
203 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700204 printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n",
205 dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 goto out3;
207 }
208 }
209
210 if (dev->dma == 0)
211 {
212 for(j = 0; dmalist[j] != 0; j++)
213 {
214 dev->dma = dmalist[j];
215 if (!request_dma(dev->dma, cardname))
216 break;
217 }
218
219 if(dmalist[j] == 0)
220 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700221 printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 goto out2;
223 }
224 }
225 else
226 {
227 for(j = 0; dmalist[j] != 0; j++)
228 if (dmalist[j] == dev->dma)
229 break;
230 if (dmalist[j] == 0)
231 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700232 printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n",
233 dev->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 goto out2;
235 }
236 if (request_dma(dev->dma, cardname))
237 {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700238 printk(KERN_INFO "proteon.c: Selected DMA %d not available\n",
239 dev->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 goto out2;
241 }
242 }
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 err = register_netdev(dev);
245 if (err)
246 goto out;
247
Jochen Friedrich504ff162005-07-27 01:14:50 -0700248 printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
249 dev->name, dev->base_addr, dev->irq, dev->dma);
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 return 0;
252out:
253 free_dma(dev->dma);
254out2:
255 free_irq(dev->irq, dev);
256out3:
257 tmsdev_term(dev);
258out4:
Jochen Friedrich504ff162005-07-27 01:14:50 -0700259 release_region(dev->base_addr, PROTEON_IO_EXTENT);
260out5:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 return err;
262}
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264/*
265 * Reads MAC address from adapter RAM, which should've read it from
266 * the onboard ROM.
267 *
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
272 */
273static void proteon_read_eeprom(struct net_device *dev)
274{
275 int i;
276
277 /* Address: 0000:0000 */
278 proteon_sifwritew(dev, 0, SIFADX);
279 proteon_sifwritew(dev, 0, SIFADR);
280
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;
285}
286
Hannes Eder27cd6ae2008-12-26 00:07:15 -0800287static unsigned short proteon_setnselout_pins(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 return 0;
290}
291
292static int proteon_open(struct net_device *dev)
293{
294 struct net_local *tp = netdev_priv(dev);
295 unsigned short val = 0;
296 int i;
297
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);
305
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;
314
315 outb(val, dev->base_addr + 0x11);
316 outb(0xff, dev->base_addr + 0x12);
317 for(i = 0; irqlist[i] != 0; i++)
318 {
319 if(irqlist[i] == dev->irq)
320 break;
321 }
322 val = i;
323 i = (7 - dev->dma) << 4;
324 val |= i;
325 outb(val, dev->base_addr + 0x13);
326
327 return tms380tr_open(dev);
328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330#define ISATR_MAX_ADAPTERS 3
331
332static int io[ISATR_MAX_ADAPTERS];
333static int irq[ISATR_MAX_ADAPTERS];
334static int dma[ISATR_MAX_ADAPTERS];
335
336MODULE_LICENSE("GPL");
337
338module_param_array(io, int, NULL, 0);
339module_param_array(irq, int, NULL, 0);
340module_param_array(dma, int, NULL, 0);
341
Jochen Friedrich504ff162005-07-27 01:14:50 -0700342static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Russell King3ae5eae2005-11-09 22:32:44 +0000344static struct platform_driver proteon_driver = {
345 .driver = {
346 .name = "proteon",
347 },
Jochen Friedrich504ff162005-07-27 01:14:50 -0700348};
349
350static int __init proteon_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
352 struct net_device *dev;
Jochen Friedrich504ff162005-07-27 01:14:50 -0700353 struct platform_device *pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 int i, num = 0, err = 0;
355
Stephen Hemminger79f8ae32009-03-26 15:11:23 +0000356 proteon_netdev_ops = tms380tr_netdev_ops;
357 proteon_netdev_ops.ndo_open = proteon_open;
358 proteon_netdev_ops.ndo_stop = tms380tr_close;
359
Russell King3ae5eae2005-11-09 22:32:44 +0000360 err = platform_driver_register(&proteon_driver);
Jochen Friedrich504ff162005-07-27 01:14:50 -0700361 if (err)
362 return err;
363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
365 dev = alloc_trdev(sizeof(struct net_local));
366 if (!dev)
367 continue;
368
369 dev->base_addr = io[i];
370 dev->irq = irq[i];
371 dev->dma = dma[i];
Jochen Friedrich504ff162005-07-27 01:14:50 -0700372 pdev = platform_device_register_simple("proteon",
373 i, NULL, 0);
Akinobu Mita9d4df9e2006-10-29 03:52:14 +0900374 if (IS_ERR(pdev)) {
375 free_netdev(dev);
376 continue;
377 }
Jochen Friedrich504ff162005-07-27 01:14:50 -0700378 err = setup_card(dev, &pdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 if (!err) {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700380 proteon_dev[i] = pdev;
Russell King3ae5eae2005-11-09 22:32:44 +0000381 platform_set_drvdata(pdev, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 ++num;
383 } else {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700384 platform_device_unregister(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 free_netdev(dev);
386 }
387 }
388
389 printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
390 /* Probe for cards. */
391 if (num == 0) {
392 printk(KERN_NOTICE "proteon.c: No cards found.\n");
Akinobu Mita9d4df9e2006-10-29 03:52:14 +0900393 platform_driver_unregister(&proteon_driver);
394 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
Akinobu Mita9d4df9e2006-10-29 03:52:14 +0900396 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398
Jochen Friedrich504ff162005-07-27 01:14:50 -0700399static void __exit proteon_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400{
Jochen Friedrich504ff162005-07-27 01:14:50 -0700401 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 int i;
403
404 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
Jochen Friedrich504ff162005-07-27 01:14:50 -0700405 struct platform_device *pdev = proteon_dev[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Jochen Friedrich504ff162005-07-27 01:14:50 -0700407 if (!pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 continue;
Russell King3ae5eae2005-11-09 22:32:44 +0000409 dev = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 unregister_netdev(dev);
411 release_region(dev->base_addr, PROTEON_IO_EXTENT);
412 free_irq(dev->irq, dev);
413 free_dma(dev->dma);
414 tmsdev_term(dev);
415 free_netdev(dev);
Russell King3ae5eae2005-11-09 22:32:44 +0000416 platform_set_drvdata(pdev, NULL);
Jochen Friedrich504ff162005-07-27 01:14:50 -0700417 platform_device_unregister(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
Russell King3ae5eae2005-11-09 22:32:44 +0000419 platform_driver_unregister(&proteon_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Jochen Friedrich504ff162005-07-27 01:14:50 -0700422module_init(proteon_init);
423module_exit(proteon_cleanup);