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 */
com20020isa_probe(struct net_device * dev)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 #ifndef MODULE
58 arcnet_init();
59 #endif
60
61 BUGLVL(D_NORMAL) printk(VERSION);
62
63 ioaddr = dev->base_addr;
64 if (!ioaddr) {
65 BUGMSG(D_NORMAL, "No autoprobe (yet) for IO mapped cards; you "
66 "must specify the base address!\n");
67 return -ENODEV;
68 }
69 if (check_region(ioaddr, ARCNET_TOTAL_SIZE)) {
70 BUGMSG(D_NORMAL, "IO region %xh-%xh already allocated.\n",
71 ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1);
72 return -ENXIO;
73 }
74 if (ASTATUS() == 0xFF) {
75 BUGMSG(D_NORMAL, "IO address %x empty\n", ioaddr);
76 return -ENODEV;
77 }
78 if (com20020_check(dev))
79 return -ENODEV;
80
81 if (!dev->irq) {
82 /* if we do this, we're sure to get an IRQ since the
83 * card has just reset and the NORXflag is on until
84 * we tell it to start receiving.
85 */
86 BUGMSG(D_INIT_REASONS, "intmask was %02Xh\n", inb(_INTMASK));
87 outb(0, _INTMASK);
88 airqmask = probe_irq_on();
89 outb(NORXflag, _INTMASK);
90 udelay(1);
91 outb(0, _INTMASK);
92 dev->irq = probe_irq_off(airqmask);
93
94 if (dev->irq <= 0) {
95 BUGMSG(D_INIT_REASONS, "Autoprobe IRQ failed first time\n");
96 airqmask = probe_irq_on();
97 outb(NORXflag, _INTMASK);
98 udelay(5);
99 outb(0, _INTMASK);
100 dev->irq = probe_irq_off(airqmask);
101 if (dev->irq <= 0) {
102 BUGMSG(D_NORMAL, "Autoprobe IRQ failed.\n");
103 return -ENODEV;
104 }
105 }
106 }
107
108 lp->card_name = "ISA COM20020";
109 return com20020_found(dev, 0);
110 }
111
112
113 #ifdef MODULE
114
115 static struct net_device *my_dev;
116
117 /* Module parameters */
118
119 static int node = 0;
120 static int io = 0x0; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */
121 static int irq = 0; /* or use the insmod io= irq= shmem= options */
122 static char *device; /* use eg. device="arc1" to change name */
123 static int timeout = 3;
124 static int backplane = 0;
125 static int clockp = 0;
126 static int clockm = 0;
127
128 MODULE_PARM(node, "i");
129 MODULE_PARM(io, "i");
130 MODULE_PARM(irq, "i");
131 MODULE_PARM(device, "s");
132 MODULE_PARM(timeout, "i");
133 MODULE_PARM(backplane, "i");
134 MODULE_PARM(clockp, "i");
135 MODULE_PARM(clockm, "i");
136 MODULE_LICENSE("GPL");
137
com20020isa_open_close(struct net_device * dev,bool open)138 static void com20020isa_open_close(struct net_device *dev, bool open)
139 {
140 if (open)
141 MOD_INC_USE_COUNT;
142 else
143 MOD_DEC_USE_COUNT;
144 }
145
init_module(void)146 int init_module(void)
147 {
148 struct net_device *dev;
149 struct arcnet_local *lp;
150 int err;
151
152 dev = dev_alloc(device ? : "arc%d", &err);
153 if (!dev)
154 return err;
155 lp = dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
156 if (!lp)
157 return -ENOMEM;
158 memset(lp, 0, sizeof(struct arcnet_local));
159
160 if (node && node != 0xff)
161 dev->dev_addr[0] = node;
162
163 lp->backplane = backplane;
164 lp->clockp = clockp & 7;
165 lp->clockm = clockm & 3;
166 lp->timeout = timeout & 3;
167 lp->hw.open_close_ll = com20020isa_open_close;
168
169 dev->base_addr = io;
170 dev->irq = irq;
171
172 if (dev->irq == 2)
173 dev->irq = 9;
174
175 if (com20020isa_probe(dev))
176 return -EIO;
177
178 my_dev = dev;
179 return 0;
180 }
181
cleanup_module(void)182 void cleanup_module(void)
183 {
184 com20020_remove(my_dev);
185 }
186
187 #else
188
com20020isa_setup(char * s)189 static int __init com20020isa_setup(char *s)
190 {
191 struct net_device *dev;
192 struct arcnet_local *lp;
193 int ints[8];
194
195 s = get_options(s, 8, ints);
196 if (!ints[0])
197 return 1;
198 dev = alloc_bootmem(sizeof(struct net_device) + sizeof(struct arcnet_local));
199 memset(dev, 0, sizeof(struct net_device) + sizeof(struct arcnet_local));
200 lp = dev->priv = (struct arcnet_local *) (dev + 1);
201 dev->init = com20020isa_probe;
202
203 switch (ints[0]) {
204 default: /* ERROR */
205 printk("com90xx: Too many arguments.\n");
206 case 6: /* Timeout */
207 lp->timeout = ints[6];
208 case 5: /* CKP value */
209 lp->clockp = ints[5];
210 case 4: /* Backplane flag */
211 lp->backplane = ints[4];
212 case 3: /* Node ID */
213 dev->dev_addr[0] = ints[3];
214 case 2: /* IRQ */
215 dev->irq = ints[2];
216 case 1: /* IO address */
217 dev->base_addr = ints[1];
218 }
219 if (*s)
220 strncpy(dev->name, s, 9);
221 else
222 strcpy(dev->name, "arc%d");
223 if (register_netdev(dev))
224 printk(KERN_ERR "com20020: Cannot register arcnet device\n");
225
226 return 1;
227 }
228
229 __setup("com20020=", com20020isa_setup);
230
231 #endif /* MODULE */
232