8cc69625cc10adfdb24524f32c5fc8592eb7e8c0
[linux-flexiantxendom0-3.2.10.git] / drivers / net / arcnet / com20020-isa.c
1 /*
2  * Linux ARCnet driver - COM20020 chipset support
3  * 
4  * Written 1997 by David Woodhouse.
5  * Written 1994-1999 by Avery Pennarun.
6  * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
7  * Derived from skeleton.c by Donald Becker.
8  *
9  * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
10  *  for sponsoring the further development of this driver.
11  *
12  * **********************
13  *
14  * The original copyright of skeleton.c was as follows:
15  *
16  * skeleton.c Written 1993 by Donald Becker.
17  * Copyright 1993 United States Government as represented by the
18  * Director, National Security Agency.  This software may only be used
19  * and distributed according to the terms of the GNU General Public License as
20  * modified by SRC, incorporated herein by reference.
21  *
22  * **********************
23  *
24  * For more details, see drivers/net/arcnet.c
25  *
26  * **********************
27  */
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/ioport.h>
32 #include <linux/slab.h>
33 #include <linux/errno.h>
34 #include <linux/delay.h>
35 #include <linux/netdevice.h>
36 #include <linux/init.h>
37 #include <linux/bootmem.h>
38 #include <linux/arcdevice.h>
39 #include <linux/com20020.h>
40
41 #include <asm/io.h>
42
43
44 #define VERSION "arcnet: COM20020 ISA support (by David Woodhouse et al.)\n"
45
46
47 /*
48  * We cannot (yet) probe for an IO mapped card, although we can check that
49  * it's where we were told it was, and even do autoirq.
50  */
51 static int __init com20020isa_probe(struct net_device *dev)
52 {
53         int ioaddr;
54         unsigned long airqmask;
55         struct arcnet_local *lp = dev->priv;
56
57         BUGLVL(D_NORMAL) printk(VERSION);
58
59         ioaddr = dev->base_addr;
60         if (!ioaddr) {
61                 BUGMSG(D_NORMAL, "No autoprobe (yet) for IO mapped cards; you "
62                        "must specify the base address!\n");
63                 return -ENODEV;
64         }
65         if (check_region(ioaddr, ARCNET_TOTAL_SIZE)) {
66                 BUGMSG(D_NORMAL, "IO region %xh-%xh already allocated.\n",
67                        ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
68                 return -ENXIO;
69         }
70         if (ASTATUS() == 0xFF) {
71                 BUGMSG(D_NORMAL, "IO address %x empty\n", ioaddr);
72                 return -ENODEV;
73         }
74         if (com20020_check(dev))
75                 return -ENODEV;
76
77         if (!dev->irq) {
78                 /* if we do this, we're sure to get an IRQ since the
79                  * card has just reset and the NORXflag is on until
80                  * we tell it to start receiving.
81                  */
82                 BUGMSG(D_INIT_REASONS, "intmask was %02Xh\n", inb(_INTMASK));
83                 outb(0, _INTMASK);
84                 airqmask = probe_irq_on();
85                 outb(NORXflag, _INTMASK);
86                 udelay(1);
87                 outb(0, _INTMASK);
88                 dev->irq = probe_irq_off(airqmask);
89
90                 if (dev->irq <= 0) {
91                         BUGMSG(D_INIT_REASONS, "Autoprobe IRQ failed first time\n");
92                         airqmask = probe_irq_on();
93                         outb(NORXflag, _INTMASK);
94                         udelay(5);
95                         outb(0, _INTMASK);
96                         dev->irq = probe_irq_off(airqmask);
97                         if (dev->irq <= 0) {
98                                 BUGMSG(D_NORMAL, "Autoprobe IRQ failed.\n");
99                                 return -ENODEV;
100                         }
101                 }
102         }
103
104         lp->card_name = "ISA COM20020";
105         return com20020_found(dev, 0);
106 }
107
108
109 #ifdef MODULE
110
111 static struct net_device *my_dev;
112
113 /* Module parameters */
114
115 static int node = 0;
116 static int io = 0x0;            /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
117 static int irq = 0;             /* or use the insmod io= irq= shmem= options */
118 static char *device;            /* use eg. device="arc1" to change name */
119 static int timeout = 3;
120 static int backplane = 0;
121 static int clockp = 0;
122 static int clockm = 0;
123
124 MODULE_PARM(node, "i");
125 MODULE_PARM(io, "i");
126 MODULE_PARM(irq, "i");
127 MODULE_PARM(device, "s");
128 MODULE_PARM(timeout, "i");
129 MODULE_PARM(backplane, "i");
130 MODULE_PARM(clockp, "i");
131 MODULE_PARM(clockm, "i");
132 MODULE_LICENSE("GPL");
133
134 int init_module(void)
135 {
136         struct net_device *dev;
137         struct arcnet_local *lp;
138         int err;
139
140         dev = dev_alloc(device ? : "arc%d", &err);
141         if (!dev)
142                 return err;
143         lp = dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
144         if (!lp)
145                 return -ENOMEM;
146         memset(lp, 0, sizeof(struct arcnet_local));
147
148         if (node && node != 0xff)
149                 dev->dev_addr[0] = node;
150
151         lp->backplane = backplane;
152         lp->clockp = clockp & 7;
153         lp->clockm = clockm & 3;
154         lp->timeout = timeout & 3;
155         lp->owner = THIS_MODULE;
156
157         dev->base_addr = io;
158         dev->irq = irq;
159
160         if (dev->irq == 2)
161                 dev->irq = 9;
162
163         if (com20020isa_probe(dev))
164                 return -EIO;
165
166         my_dev = dev;
167         return 0;
168 }
169
170 void cleanup_module(void)
171 {
172         com20020_remove(my_dev);
173 }
174
175 #else
176
177 static int __init com20020isa_setup(char *s)
178 {
179         struct net_device *dev;
180         struct arcnet_local *lp;
181         int ints[8];
182
183         s = get_options(s, 8, ints);
184         if (!ints[0])
185                 return 1;
186         dev = alloc_bootmem(sizeof(struct net_device) + sizeof(struct arcnet_local));
187         memset(dev, 0, sizeof(struct net_device) + sizeof(struct arcnet_local));
188         lp = dev->priv = (struct arcnet_local *) (dev + 1);
189         dev->init = com20020isa_probe;
190
191         switch (ints[0]) {
192         default:                /* ERROR */
193                 printk("com90xx: Too many arguments.\n");
194         case 6:         /* Timeout */
195                 lp->timeout = ints[6];
196         case 5:         /* CKP value */
197                 lp->clockp = ints[5];
198         case 4:         /* Backplane flag */
199                 lp->backplane = ints[4];
200         case 3:         /* Node ID */
201                 dev->dev_addr[0] = ints[3];
202         case 2:         /* IRQ */
203                 dev->irq = ints[2];
204         case 1:         /* IO address */
205                 dev->base_addr = ints[1];
206         }
207         if (*s)
208                 strncpy(dev->name, s, 9);
209         else
210                 strcpy(dev->name, "arc%d");
211         if (register_netdev(dev))
212                 printk(KERN_ERR "com20020: Cannot register arcnet device\n");
213
214         return 1;
215 }
216
217 __setup("com20020=", com20020isa_setup);
218
219 #endif                          /* MODULE */