Create platform_device.h to contain all the platform device details.
[deliverable/linux.git] / drivers / net / tokenring / proteon.c
CommitLineData
1da177e4
LT
1/*
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>
d052d1be 32#include <linux/platform_device.h>
1da177e4
LT
33
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";
504ff16c 66static u64 dma_mask = ISA_MAX_ADDRESS;
1da177e4
LT
67static 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;
113 return (0);
114nodev:
115 release_region(ioaddr, PROTEON_IO_EXTENT);
116 return -ENODEV;
117}
118
504ff16c 119static int __init setup_card(struct net_device *dev, struct device *pdev)
1da177e4
LT
120{
121 struct net_local *tp;
122 static int versionprinted;
123 const unsigned *port;
124 int j,err = 0;
125
126 if (!dev)
127 return -ENOMEM;
128
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;
137 }
138 }
139 if (err)
504ff16c 140 goto out5;
1da177e4
LT
141
142 /* At this point we have found a valid card. */
143
144 if (versionprinted++ == 0)
145 printk(KERN_DEBUG "%s", version);
146
147 err = -EIO;
504ff16c 148 pdev->dma_mask = &dma_mask;
84c3ea01 149 if (tmsdev_init(dev, pdev))
1da177e4
LT
150 goto out4;
151
152 dev->base_addr &= ~3;
153
154 proteon_read_eeprom(dev);
155
504ff16c 156 printk(KERN_DEBUG "proteon.c: Ring Station Address: ");
1da177e4
LT
157 printk("%2.2x", dev->dev_addr[0]);
158 for (j = 1; j < 6; j++)
159 printk(":%2.2x", dev->dev_addr[j]);
160 printk("\n");
161
162 tp = netdev_priv(dev);
163 tp->setnselout = proteon_setnselout_pins;
164
165 tp->sifreadb = proteon_sifreadb;
166 tp->sifreadw = proteon_sifreadw;
167 tp->sifwriteb = proteon_sifwriteb;
168 tp->sifwritew = proteon_sifwritew;
169
170 memcpy(tp->ProductID, cardname, PROD_ID_SIZE + 1);
171
172 tp->tmspriv = NULL;
173
174 dev->open = proteon_open;
175 dev->stop = tms380tr_close;
176
177 if (dev->irq == 0)
178 {
179 for(j = 0; irqlist[j] != 0; j++)
180 {
181 dev->irq = irqlist[j];
182 if (!request_irq(dev->irq, tms380tr_interrupt, 0,
183 cardname, dev))
184 break;
185 }
186
187 if(irqlist[j] == 0)
188 {
504ff16c 189 printk(KERN_INFO "proteon.c: AutoSelect no IRQ available\n");
1da177e4
LT
190 goto out3;
191 }
192 }
193 else
194 {
195 for(j = 0; irqlist[j] != 0; j++)
196 if (irqlist[j] == dev->irq)
197 break;
198 if (irqlist[j] == 0)
199 {
504ff16c
JF
200 printk(KERN_INFO "proteon.c: Illegal IRQ %d specified\n",
201 dev->irq);
1da177e4
LT
202 goto out3;
203 }
204 if (request_irq(dev->irq, tms380tr_interrupt, 0,
205 cardname, dev))
206 {
504ff16c
JF
207 printk(KERN_INFO "proteon.c: Selected IRQ %d not available\n",
208 dev->irq);
1da177e4
LT
209 goto out3;
210 }
211 }
212
213 if (dev->dma == 0)
214 {
215 for(j = 0; dmalist[j] != 0; j++)
216 {
217 dev->dma = dmalist[j];
218 if (!request_dma(dev->dma, cardname))
219 break;
220 }
221
222 if(dmalist[j] == 0)
223 {
504ff16c 224 printk(KERN_INFO "proteon.c: AutoSelect no DMA available\n");
1da177e4
LT
225 goto out2;
226 }
227 }
228 else
229 {
230 for(j = 0; dmalist[j] != 0; j++)
231 if (dmalist[j] == dev->dma)
232 break;
233 if (dmalist[j] == 0)
234 {
504ff16c
JF
235 printk(KERN_INFO "proteon.c: Illegal DMA %d specified\n",
236 dev->dma);
1da177e4
LT
237 goto out2;
238 }
239 if (request_dma(dev->dma, cardname))
240 {
504ff16c
JF
241 printk(KERN_INFO "proteon.c: Selected DMA %d not available\n",
242 dev->dma);
1da177e4
LT
243 goto out2;
244 }
245 }
246
1da177e4
LT
247 err = register_netdev(dev);
248 if (err)
249 goto out;
250
504ff16c
JF
251 printk(KERN_DEBUG "%s: IO: %#4lx IRQ: %d DMA: %d\n",
252 dev->name, dev->base_addr, dev->irq, dev->dma);
253
1da177e4
LT
254 return 0;
255out:
256 free_dma(dev->dma);
257out2:
258 free_irq(dev->irq, dev);
259out3:
260 tmsdev_term(dev);
261out4:
504ff16c
JF
262 release_region(dev->base_addr, PROTEON_IO_EXTENT);
263out5:
1da177e4
LT
264 return err;
265}
266
1da177e4
LT
267/*
268 * Reads MAC address from adapter RAM, which should've read it from
269 * the onboard ROM.
270 *
271 * Calling this on a board that does not support it can be a very
272 * dangerous thing. The Madge board, for instance, will lock your
273 * machine hard when this is called. Luckily, its supported in a
274 * separate driver. --ASF
275 */
276static void proteon_read_eeprom(struct net_device *dev)
277{
278 int i;
279
280 /* Address: 0000:0000 */
281 proteon_sifwritew(dev, 0, SIFADX);
282 proteon_sifwritew(dev, 0, SIFADR);
283
284 /* Read six byte MAC address data */
285 dev->addr_len = 6;
286 for(i = 0; i < 6; i++)
287 dev->dev_addr[i] = proteon_sifreadw(dev, SIFINC) >> 8;
288}
289
290unsigned short proteon_setnselout_pins(struct net_device *dev)
291{
292 return 0;
293}
294
295static int proteon_open(struct net_device *dev)
296{
297 struct net_local *tp = netdev_priv(dev);
298 unsigned short val = 0;
299 int i;
300
301 /* Proteon reset sequence */
302 outb(0, dev->base_addr + 0x11);
303 mdelay(20);
304 outb(0x04, dev->base_addr + 0x11);
305 mdelay(20);
306 outb(0, dev->base_addr + 0x11);
307 mdelay(100);
308
309 /* set control/status reg */
310 val = inb(dev->base_addr + 0x11);
311 val |= 0x78;
312 val &= 0xf9;
313 if(tp->DataRate == SPEED_4)
314 val |= 0x20;
315 else
316 val &= ~0x20;
317
318 outb(val, dev->base_addr + 0x11);
319 outb(0xff, dev->base_addr + 0x12);
320 for(i = 0; irqlist[i] != 0; i++)
321 {
322 if(irqlist[i] == dev->irq)
323 break;
324 }
325 val = i;
326 i = (7 - dev->dma) << 4;
327 val |= i;
328 outb(val, dev->base_addr + 0x13);
329
330 return tms380tr_open(dev);
331}
332
1da177e4
LT
333#define ISATR_MAX_ADAPTERS 3
334
335static int io[ISATR_MAX_ADAPTERS];
336static int irq[ISATR_MAX_ADAPTERS];
337static int dma[ISATR_MAX_ADAPTERS];
338
339MODULE_LICENSE("GPL");
340
341module_param_array(io, int, NULL, 0);
342module_param_array(irq, int, NULL, 0);
343module_param_array(dma, int, NULL, 0);
344
504ff16c
JF
345static struct platform_device *proteon_dev[ISATR_MAX_ADAPTERS];
346
347static struct device_driver proteon_driver = {
348 .name = "proteon",
349 .bus = &platform_bus_type,
350};
1da177e4 351
504ff16c 352static int __init proteon_init(void)
1da177e4
LT
353{
354 struct net_device *dev;
504ff16c 355 struct platform_device *pdev;
1da177e4
LT
356 int i, num = 0, err = 0;
357
504ff16c
JF
358 err = driver_register(&proteon_driver);
359 if (err)
360 return err;
361
1da177e4
LT
362 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
363 dev = alloc_trdev(sizeof(struct net_local));
364 if (!dev)
365 continue;
366
367 dev->base_addr = io[i];
368 dev->irq = irq[i];
369 dev->dma = dma[i];
504ff16c
JF
370 pdev = platform_device_register_simple("proteon",
371 i, NULL, 0);
372 err = setup_card(dev, &pdev->dev);
1da177e4 373 if (!err) {
504ff16c
JF
374 proteon_dev[i] = pdev;
375 dev_set_drvdata(&pdev->dev, dev);
1da177e4
LT
376 ++num;
377 } else {
504ff16c 378 platform_device_unregister(pdev);
1da177e4
LT
379 free_netdev(dev);
380 }
381 }
382
383 printk(KERN_NOTICE "proteon.c: %d cards found.\n", num);
384 /* Probe for cards. */
385 if (num == 0) {
386 printk(KERN_NOTICE "proteon.c: No cards found.\n");
387 return (-ENODEV);
388 }
389 return (0);
390}
391
504ff16c 392static void __exit proteon_cleanup(void)
1da177e4 393{
504ff16c 394 struct net_device *dev;
1da177e4
LT
395 int i;
396
397 for (i = 0; i < ISATR_MAX_ADAPTERS ; i++) {
504ff16c 398 struct platform_device *pdev = proteon_dev[i];
1da177e4 399
504ff16c 400 if (!pdev)
1da177e4 401 continue;
504ff16c 402 dev = dev_get_drvdata(&pdev->dev);
1da177e4
LT
403 unregister_netdev(dev);
404 release_region(dev->base_addr, PROTEON_IO_EXTENT);
405 free_irq(dev->irq, dev);
406 free_dma(dev->dma);
407 tmsdev_term(dev);
408 free_netdev(dev);
504ff16c
JF
409 dev_set_drvdata(&pdev->dev, NULL);
410 platform_device_unregister(pdev);
1da177e4 411 }
504ff16c 412 driver_unregister(&proteon_driver);
1da177e4 413}
1da177e4 414
504ff16c
JF
415module_init(proteon_init);
416module_exit(proteon_cleanup);
This page took 0.079733 seconds and 5 git commands to generate.