Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Linux ARCnet driver - COM20020 chipset support | |
cb334648 | 3 | * |
1da177e4 LT |
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/moduleparam.h> | |
30 | #include <linux/kernel.h> | |
31 | #include <linux/types.h> | |
32 | #include <linux/ioport.h> | |
1da177e4 LT |
33 | #include <linux/errno.h> |
34 | #include <linux/delay.h> | |
35 | #include <linux/netdevice.h> | |
36 | #include <linux/init.h> | |
a6b7a407 | 37 | #include <linux/interrupt.h> |
1da177e4 LT |
38 | #include <linux/bootmem.h> |
39 | #include <linux/arcdevice.h> | |
40 | #include <linux/com20020.h> | |
41 | ||
42 | #include <asm/io.h> | |
43 | ||
44 | #define VERSION "arcnet: COM20020 ISA support (by David Woodhouse et al.)\n" | |
45 | ||
1da177e4 LT |
46 | /* |
47 | * We cannot (yet) probe for an IO mapped card, although we can check that | |
48 | * it's where we were told it was, and even do autoirq. | |
49 | */ | |
50 | static int __init com20020isa_probe(struct net_device *dev) | |
51 | { | |
52 | int ioaddr; | |
53 | unsigned long airqmask; | |
454d7c9b | 54 | struct arcnet_local *lp = netdev_priv(dev); |
1da177e4 LT |
55 | int err; |
56 | ||
57 | BUGLVL(D_NORMAL) printk(VERSION); | |
58 | ||
59 | ioaddr = dev->base_addr; | |
60 | if (!ioaddr) { | |
3b4e5551 | 61 | BUGMSG(D_NORMAL, "No autoprobe (yet) for IO mapped cards; you must specify the base address!\n"); |
1da177e4 LT |
62 | return -ENODEV; |
63 | } | |
64 | if (!request_region(ioaddr, ARCNET_TOTAL_SIZE, "arcnet (COM20020)")) { | |
65 | BUGMSG(D_NORMAL, "IO region %xh-%xh already allocated.\n", | |
66 | ioaddr, ioaddr + ARCNET_TOTAL_SIZE - 1); | |
67 | return -ENXIO; | |
68 | } | |
69 | if (ASTATUS() == 0xFF) { | |
70 | BUGMSG(D_NORMAL, "IO address %x empty\n", ioaddr); | |
71 | err = -ENODEV; | |
72 | goto out; | |
73 | } | |
74 | if (com20020_check(dev)) { | |
75 | err = -ENODEV; | |
76 | goto out; | |
77 | } | |
78 | ||
79 | if (!dev->irq) { | |
80 | /* if we do this, we're sure to get an IRQ since the | |
81 | * card has just reset and the NORXflag is on until | |
82 | * we tell it to start receiving. | |
83 | */ | |
84 | BUGMSG(D_INIT_REASONS, "intmask was %02Xh\n", inb(_INTMASK)); | |
85 | outb(0, _INTMASK); | |
86 | airqmask = probe_irq_on(); | |
87 | outb(NORXflag, _INTMASK); | |
88 | udelay(1); | |
89 | outb(0, _INTMASK); | |
90 | dev->irq = probe_irq_off(airqmask); | |
91 | ||
0a6efc78 | 92 | if ((int)dev->irq <= 0) { |
1da177e4 LT |
93 | BUGMSG(D_INIT_REASONS, "Autoprobe IRQ failed first time\n"); |
94 | airqmask = probe_irq_on(); | |
95 | outb(NORXflag, _INTMASK); | |
96 | udelay(5); | |
97 | outb(0, _INTMASK); | |
98 | dev->irq = probe_irq_off(airqmask); | |
0a6efc78 | 99 | if ((int)dev->irq <= 0) { |
1da177e4 LT |
100 | BUGMSG(D_NORMAL, "Autoprobe IRQ failed.\n"); |
101 | err = -ENODEV; | |
102 | goto out; | |
103 | } | |
104 | } | |
105 | } | |
106 | ||
107 | lp->card_name = "ISA COM20020"; | |
108 | if ((err = com20020_found(dev, 0)) != 0) | |
109 | goto out; | |
110 | ||
111 | return 0; | |
112 | ||
113 | out: | |
114 | release_region(ioaddr, ARCNET_TOTAL_SIZE); | |
115 | return err; | |
116 | } | |
117 | ||
118 | static int node = 0; | |
119 | static int io = 0x0; /* <--- EDIT THESE LINES FOR YOUR CONFIGURATION */ | |
120 | static int irq = 0; /* or use the insmod io= irq= shmem= options */ | |
121 | static char device[9]; /* use eg. device="arc1" to change name */ | |
122 | static int timeout = 3; | |
123 | static int backplane = 0; | |
124 | static int clockp = 0; | |
125 | static int clockm = 0; | |
126 | ||
127 | module_param(node, int, 0); | |
128 | module_param(io, int, 0); | |
129 | module_param(irq, int, 0); | |
130 | module_param_string(device, device, sizeof(device), 0); | |
131 | module_param(timeout, int, 0); | |
132 | module_param(backplane, int, 0); | |
133 | module_param(clockp, int, 0); | |
134 | module_param(clockm, int, 0); | |
135 | ||
136 | MODULE_LICENSE("GPL"); | |
137 | ||
138 | static struct net_device *my_dev; | |
139 | ||
140 | static int __init com20020_init(void) | |
141 | { | |
142 | struct net_device *dev; | |
143 | struct arcnet_local *lp; | |
144 | ||
145 | dev = alloc_arcdev(device); | |
146 | if (!dev) | |
147 | return -ENOMEM; | |
148 | ||
149 | if (node && node != 0xff) | |
150 | dev->dev_addr[0] = node; | |
151 | ||
a1799af4 SH |
152 | dev->netdev_ops = &com20020_netdev_ops; |
153 | ||
454d7c9b | 154 | lp = netdev_priv(dev); |
1da177e4 LT |
155 | lp->backplane = backplane; |
156 | lp->clockp = clockp & 7; | |
157 | lp->clockm = clockm & 3; | |
158 | lp->timeout = timeout & 3; | |
159 | lp->hw.owner = THIS_MODULE; | |
160 | ||
161 | dev->base_addr = io; | |
162 | dev->irq = irq; | |
163 | ||
164 | if (dev->irq == 2) | |
165 | dev->irq = 9; | |
166 | ||
167 | if (com20020isa_probe(dev)) { | |
168 | free_netdev(dev); | |
169 | return -EIO; | |
170 | } | |
171 | ||
172 | my_dev = dev; | |
173 | return 0; | |
174 | } | |
175 | ||
176 | static void __exit com20020_exit(void) | |
177 | { | |
178 | unregister_netdev(my_dev); | |
179 | free_irq(my_dev->irq, my_dev); | |
180 | release_region(my_dev->base_addr, ARCNET_TOTAL_SIZE); | |
181 | free_netdev(my_dev); | |
182 | } | |
183 | ||
184 | #ifndef MODULE | |
185 | static int __init com20020isa_setup(char *s) | |
186 | { | |
187 | int ints[8]; | |
188 | ||
189 | s = get_options(s, 8, ints); | |
190 | if (!ints[0]) | |
191 | return 1; | |
192 | ||
193 | switch (ints[0]) { | |
194 | default: /* ERROR */ | |
195 | printk("com90xx: Too many arguments.\n"); | |
196 | case 6: /* Timeout */ | |
197 | timeout = ints[6]; | |
198 | case 5: /* CKP value */ | |
199 | clockp = ints[5]; | |
200 | case 4: /* Backplane flag */ | |
201 | backplane = ints[4]; | |
202 | case 3: /* Node ID */ | |
203 | node = ints[3]; | |
204 | case 2: /* IRQ */ | |
205 | irq = ints[2]; | |
206 | case 1: /* IO address */ | |
207 | io = ints[1]; | |
208 | } | |
209 | if (*s) | |
210 | snprintf(device, sizeof(device), "%s", s); | |
211 | return 1; | |
212 | } | |
213 | ||
214 | __setup("com20020=", com20020isa_setup); | |
215 | ||
216 | #endif /* MODULE */ | |
217 | ||
218 | module_init(com20020_init) | |
219 | module_exit(com20020_exit) |