blob: 867f6fff543c848bfd95a741173c746005344017 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Amiga Linux/68k 8390 based PCMCIA Ethernet Driver for the Amiga 1200
3 *
4 * (C) Copyright 1997 Alain Malek
5 * (Alain.Malek@cryogen.com)
6 *
7 * ----------------------------------------------------------------------------
8 *
9 * This program is based on
10 *
11 * ne.c: A general non-shared-memory NS8390 ethernet driver for linux
12 * Written 1992-94 by Donald Becker.
13 *
14 * 8390.c: A general NS8390 ethernet driver core for linux.
15 * Written 1992-94 by Donald Becker.
16 *
17 * cnetdevice: A Sana-II ethernet driver for AmigaOS
18 * Written by Bruce Abbott (bhabbott@inhb.co.nz)
19 *
20 * ----------------------------------------------------------------------------
21 *
22 * This file is subject to the terms and conditions of the GNU General Public
23 * License. See the file COPYING in the main directory of the Linux
24 * distribution for more details.
25 *
26 * ----------------------------------------------------------------------------
27 *
28 */
29
30
31#include <linux/module.h>
32#include <linux/kernel.h>
33#include <linux/errno.h>
34#include <linux/pci.h>
35#include <linux/init.h>
36#include <linux/delay.h>
37#include <linux/netdevice.h>
38#include <linux/etherdevice.h>
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -080039#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#include <asm/system.h>
42#include <asm/io.h>
43#include <asm/setup.h>
44#include <asm/amigaints.h>
45#include <asm/amigahw.h>
46#include <asm/amigayle.h>
47#include <asm/amipcmcia.h>
48
49#include "8390.h"
50
51/* ---- No user-serviceable parts below ---- */
52
53#define DRV_NAME "apne"
54
55#define NE_BASE (dev->base_addr)
56#define NE_CMD 0x00
57#define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
58#define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
59#define NE_IO_EXTENT 0x20
60
61#define NE_EN0_ISR 0x07
62#define NE_EN0_DCFG 0x0e
63
64#define NE_EN0_RSARLO 0x08
65#define NE_EN0_RSARHI 0x09
66#define NE_EN0_RCNTLO 0x0a
67#define NE_EN0_RXCR 0x0c
68#define NE_EN0_TXCR 0x0d
69#define NE_EN0_RCNTHI 0x0b
70#define NE_EN0_IMR 0x0f
71
72#define NE1SM_START_PG 0x20 /* First page of TX buffer */
73#define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
74#define NESM_START_PG 0x40 /* First page of TX buffer */
75#define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
76
77
78struct net_device * __init apne_probe(int unit);
79static int apne_probe1(struct net_device *dev, int ioaddr);
80
81static int apne_open(struct net_device *dev);
82static int apne_close(struct net_device *dev);
83
84static void apne_reset_8390(struct net_device *dev);
85static void apne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
86 int ring_page);
87static void apne_block_input(struct net_device *dev, int count,
88 struct sk_buff *skb, int ring_offset);
89static void apne_block_output(struct net_device *dev, const int count,
90 const unsigned char *buf, const int start_page);
David Howells7d12e782006-10-05 14:55:46 +010091static irqreturn_t apne_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93static int init_pcmcia(void);
94
95/* IO base address used for nic */
96
97#define IOBASE 0x300
98
99/*
100 use MANUAL_CONFIG and MANUAL_OFFSET for enabling IO by hand
101 you can find the values to use by looking at the cnet.device
102 config file example (the default values are for the CNET40BC card)
103*/
104
105/*
106#define MANUAL_CONFIG 0x20
107#define MANUAL_OFFSET 0x3f8
108
109#define MANUAL_HWADDR0 0x00
110#define MANUAL_HWADDR1 0x12
111#define MANUAL_HWADDR2 0x34
112#define MANUAL_HWADDR3 0x56
113#define MANUAL_HWADDR4 0x78
114#define MANUAL_HWADDR5 0x9a
115*/
116
117static const char version[] =
118 "apne.c:v1.1 7/10/98 Alain Malek (Alain.Malek@cryogen.ch)\n";
119
120static int apne_owned; /* signal if card already owned */
121
122struct net_device * __init apne_probe(int unit)
123{
124 struct net_device *dev;
125#ifndef MANUAL_CONFIG
126 char tuple[8];
127#endif
128 int err;
129
Geert Uytterhoeven0f734482008-05-18 20:47:16 +0200130 if (!MACH_IS_AMIGA)
131 return ERR_PTR(-ENODEV);
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 if (apne_owned)
134 return ERR_PTR(-ENODEV);
135
136 if ( !(AMIGAHW_PRESENT(PCMCIA)) )
137 return ERR_PTR(-ENODEV);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 printk("Looking for PCMCIA ethernet card : ");
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 /* check if a card is inserted */
142 if (!(PCMCIA_INSERTED)) {
143 printk("NO PCMCIA card inserted\n");
144 return ERR_PTR(-ENODEV);
145 }
146
147 dev = alloc_ei_netdev();
148 if (!dev)
149 return ERR_PTR(-ENOMEM);
150 if (unit >= 0) {
151 sprintf(dev->name, "eth%d", unit);
152 netdev_boot_setup_check(dev);
153 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 /* disable pcmcia irq for readtuple */
156 pcmcia_disable_irq();
157
158#ifndef MANUAL_CONFIG
159 if ((pcmcia_copy_tuple(CISTPL_FUNCID, tuple, 8) < 3) ||
160 (tuple[2] != CISTPL_FUNCID_NETWORK)) {
161 printk("not an ethernet card\n");
162 /* XXX: shouldn't we re-enable irq here? */
163 free_netdev(dev);
164 return ERR_PTR(-ENODEV);
165 }
166#endif
167
168 printk("ethernet PCMCIA card inserted\n");
169
170 if (!init_pcmcia()) {
171 /* XXX: shouldn't we re-enable irq here? */
172 free_netdev(dev);
173 return ERR_PTR(-ENODEV);
174 }
175
176 if (!request_region(IOBASE, 0x20, DRV_NAME)) {
177 free_netdev(dev);
178 return ERR_PTR(-EBUSY);
179 }
180
181 err = apne_probe1(dev, IOBASE);
182 if (err) {
183 release_region(IOBASE, 0x20);
184 free_netdev(dev);
185 return ERR_PTR(err);
186 }
187 err = register_netdev(dev);
188 if (!err)
189 return dev;
190
191 pcmcia_disable_irq();
192 free_irq(IRQ_AMIGA_PORTS, dev);
193 pcmcia_reset();
194 release_region(IOBASE, 0x20);
195 free_netdev(dev);
196 return ERR_PTR(err);
197}
198
199static int __init apne_probe1(struct net_device *dev, int ioaddr)
200{
201 int i;
202 unsigned char SA_prom[32];
203 int wordlength = 2;
204 const char *name = NULL;
205 int start_page, stop_page;
206#ifndef MANUAL_HWADDR0
207 int neX000, ctron;
208#endif
209 static unsigned version_printed;
Joe Perches0795af52007-10-03 17:59:30 -0700210 DECLARE_MAC_BUF(mac);
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 if (ei_debug && version_printed++ == 0)
213 printk(version);
214
215 printk("PCMCIA NE*000 ethercard probe");
216
217 /* Reset card. Who knows what dain-bramaged state it was left in. */
218 { unsigned long reset_start_time = jiffies;
219
220 outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
221
222 while ((inb(ioaddr + NE_EN0_ISR) & ENISR_RESET) == 0)
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800223 if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 printk(" not found (no reset ack).\n");
225 return -ENODEV;
226 }
227
228 outb(0xff, ioaddr + NE_EN0_ISR); /* Ack all intr. */
229 }
230
231#ifndef MANUAL_HWADDR0
232
233 /* Read the 16 bytes of station address PROM.
234 We must first initialize registers, similar to NS8390_init(eifdev, 0).
235 We can't reliably read the SAPROM address without this.
236 (I learned the hard way!). */
237 {
238 struct {unsigned long value, offset; } program_seq[] = {
239 {E8390_NODMA+E8390_PAGE0+E8390_STOP, NE_CMD}, /* Select page 0*/
240 {0x48, NE_EN0_DCFG}, /* Set byte-wide (0x48) access. */
241 {0x00, NE_EN0_RCNTLO}, /* Clear the count regs. */
242 {0x00, NE_EN0_RCNTHI},
243 {0x00, NE_EN0_IMR}, /* Mask completion irq. */
244 {0xFF, NE_EN0_ISR},
245 {E8390_RXOFF, NE_EN0_RXCR}, /* 0x20 Set to monitor */
246 {E8390_TXOFF, NE_EN0_TXCR}, /* 0x02 and loopback mode. */
247 {32, NE_EN0_RCNTLO},
248 {0x00, NE_EN0_RCNTHI},
249 {0x00, NE_EN0_RSARLO}, /* DMA starting at 0x0000. */
250 {0x00, NE_EN0_RSARHI},
251 {E8390_RREAD+E8390_START, NE_CMD},
252 };
Denis Chengff8ac602007-09-02 18:30:18 +0800253 for (i = 0; i < ARRAY_SIZE(program_seq); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 outb(program_seq[i].value, ioaddr + program_seq[i].offset);
255 }
256
257 }
258 for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
259 SA_prom[i] = inb(ioaddr + NE_DATAPORT);
260 SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
261 if (SA_prom[i] != SA_prom[i+1])
262 wordlength = 1;
263 }
264
265 /* At this point, wordlength *only* tells us if the SA_prom is doubled
266 up or not because some broken PCI cards don't respect the byte-wide
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400267 request in program_seq above, and hence don't have doubled up values.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 These broken cards would otherwise be detected as an ne1000. */
269
270 if (wordlength == 2)
271 for (i = 0; i < 16; i++)
272 SA_prom[i] = SA_prom[i+i];
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (wordlength == 2) {
275 /* We must set the 8390 for word mode. */
276 outb(0x49, ioaddr + NE_EN0_DCFG);
277 start_page = NESM_START_PG;
278 stop_page = NESM_STOP_PG;
279 } else {
280 start_page = NE1SM_START_PG;
281 stop_page = NE1SM_STOP_PG;
282 }
283
284 neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
285 ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
286
287 /* Set up the rest of the parameters. */
288 if (neX000) {
289 name = (wordlength == 2) ? "NE2000" : "NE1000";
290 } else if (ctron) {
291 name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
292 start_page = 0x01;
293 stop_page = (wordlength == 2) ? 0x40 : 0x20;
294 } else {
295 printk(" not found.\n");
296 return -ENXIO;
297
298 }
299
300#else
301 wordlength = 2;
302 /* We must set the 8390 for word mode. */
303 outb(0x49, ioaddr + NE_EN0_DCFG);
304 start_page = NESM_START_PG;
305 stop_page = NESM_STOP_PG;
306
307 SA_prom[0] = MANUAL_HWADDR0;
308 SA_prom[1] = MANUAL_HWADDR1;
309 SA_prom[2] = MANUAL_HWADDR2;
310 SA_prom[3] = MANUAL_HWADDR3;
311 SA_prom[4] = MANUAL_HWADDR4;
312 SA_prom[5] = MANUAL_HWADDR5;
313 name = "NE2000";
314#endif
315
316 dev->base_addr = ioaddr;
Kars de Jongd8a53b32006-12-09 10:51:03 +0100317 dev->irq = IRQ_AMIGA_PORTS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 /* Install the Interrupt handler */
Kars de Jongd8a53b32006-12-09 10:51:03 +0100320 i = request_irq(dev->irq, apne_interrupt, IRQF_SHARED, DRV_NAME, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 if (i) return i;
322
Joe Perches0795af52007-10-03 17:59:30 -0700323 for(i = 0; i < ETHER_ADDR_LEN; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 dev->dev_addr[i] = SA_prom[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
Joe Perches0795af52007-10-03 17:59:30 -0700326 printk(" %s\n", print_mac(mac, dev->dev_addr));
327
328 printk("%s: %s found.\n", dev->name, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 ei_status.name = name;
331 ei_status.tx_start_page = start_page;
332 ei_status.stop_page = stop_page;
333 ei_status.word16 = (wordlength == 2);
334
335 ei_status.rx_start_page = start_page + TX_PAGES;
336
337 ei_status.reset_8390 = &apne_reset_8390;
338 ei_status.block_input = &apne_block_input;
339 ei_status.block_output = &apne_block_output;
340 ei_status.get_8390_hdr = &apne_get_8390_hdr;
341 dev->open = &apne_open;
342 dev->stop = &apne_close;
343#ifdef CONFIG_NET_POLL_CONTROLLER
344 dev->poll_controller = ei_poll;
345#endif
346 NS8390_init(dev, 0);
347
348 pcmcia_ack_int(pcmcia_get_intreq()); /* ack PCMCIA int req */
349 pcmcia_enable_irq();
350
351 apne_owned = 1;
352
353 return 0;
354}
355
356static int
357apne_open(struct net_device *dev)
358{
359 ei_open(dev);
360 return 0;
361}
362
363static int
364apne_close(struct net_device *dev)
365{
366 if (ei_debug > 1)
367 printk("%s: Shutting down ethercard.\n", dev->name);
368 ei_close(dev);
369 return 0;
370}
371
372/* Hard reset the card. This used to pause for the same period that a
373 8390 reset command required, but that shouldn't be necessary. */
374static void
375apne_reset_8390(struct net_device *dev)
376{
377 unsigned long reset_start_time = jiffies;
378
379 init_pcmcia();
380
381 if (ei_debug > 1) printk("resetting the 8390 t=%ld...", jiffies);
382
383 outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
384
385 ei_status.txing = 0;
386 ei_status.dmaing = 0;
387
388 /* This check _should_not_ be necessary, omit eventually. */
389 while ((inb(NE_BASE+NE_EN0_ISR) & ENISR_RESET) == 0)
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800390 if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 printk("%s: ne_reset_8390() did not complete.\n", dev->name);
392 break;
393 }
394 outb(ENISR_RESET, NE_BASE + NE_EN0_ISR); /* Ack intr. */
395}
396
397/* Grab the 8390 specific header. Similar to the block_input routine, but
398 we don't need to be concerned with ring wrap as the header will be at
399 the start of a page, so we optimize accordingly. */
400
401static void
402apne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
403{
404
405 int nic_base = dev->base_addr;
406 int cnt;
407 char *ptrc;
408 short *ptrs;
409
410 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
411 if (ei_status.dmaing) {
412 printk("%s: DMAing conflict in ne_get_8390_hdr "
413 "[DMAstat:%d][irqlock:%d][intr:%d].\n",
414 dev->name, ei_status.dmaing, ei_status.irqlock, dev->irq);
415 return;
416 }
417
418 ei_status.dmaing |= 0x01;
419 outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
420 outb(ENISR_RDC, nic_base + NE_EN0_ISR);
421 outb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO);
422 outb(0, nic_base + NE_EN0_RCNTHI);
423 outb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */
424 outb(ring_page, nic_base + NE_EN0_RSARHI);
425 outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
426
427 if (ei_status.word16) {
428 ptrs = (short*)hdr;
429 for(cnt = 0; cnt < (sizeof(struct e8390_pkt_hdr)>>1); cnt++)
430 *ptrs++ = inw(NE_BASE + NE_DATAPORT);
431 } else {
432 ptrc = (char*)hdr;
433 for(cnt = 0; cnt < sizeof(struct e8390_pkt_hdr); cnt++)
434 *ptrc++ = inb(NE_BASE + NE_DATAPORT);
435 }
436
437 outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
438 ei_status.dmaing &= ~0x01;
439
440 le16_to_cpus(&hdr->count);
441}
442
443/* Block input and output, similar to the Crynwr packet driver. If you
444 are porting to a new ethercard, look at the packet driver source for hints.
445 The NEx000 doesn't share the on-board packet memory -- you have to put
446 the packet out through the "remote DMA" dataport using outb. */
447
448static void
449apne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
450{
451 int nic_base = dev->base_addr;
452 char *buf = skb->data;
453 char *ptrc;
454 short *ptrs;
455 int cnt;
456
457 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
458 if (ei_status.dmaing) {
459 printk("%s: DMAing conflict in ne_block_input "
460 "[DMAstat:%d][irqlock:%d][intr:%d].\n",
461 dev->name, ei_status.dmaing, ei_status.irqlock, dev->irq);
462 return;
463 }
464 ei_status.dmaing |= 0x01;
465 outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
466 outb(ENISR_RDC, nic_base + NE_EN0_ISR);
467 outb(count & 0xff, nic_base + NE_EN0_RCNTLO);
468 outb(count >> 8, nic_base + NE_EN0_RCNTHI);
469 outb(ring_offset & 0xff, nic_base + NE_EN0_RSARLO);
470 outb(ring_offset >> 8, nic_base + NE_EN0_RSARHI);
471 outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
472 if (ei_status.word16) {
473 ptrs = (short*)buf;
474 for (cnt = 0; cnt < (count>>1); cnt++)
475 *ptrs++ = inw(NE_BASE + NE_DATAPORT);
476 if (count & 0x01) {
477 buf[count-1] = inb(NE_BASE + NE_DATAPORT);
478 }
479 } else {
480 ptrc = (char*)buf;
481 for (cnt = 0; cnt < count; cnt++)
482 *ptrc++ = inb(NE_BASE + NE_DATAPORT);
483 }
484
485 outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
486 ei_status.dmaing &= ~0x01;
487}
488
489static void
490apne_block_output(struct net_device *dev, int count,
491 const unsigned char *buf, const int start_page)
492{
493 int nic_base = NE_BASE;
494 unsigned long dma_start;
495 char *ptrc;
496 short *ptrs;
497 int cnt;
498
499 /* Round the count up for word writes. Do we need to do this?
500 What effect will an odd byte count have on the 8390?
501 I should check someday. */
502 if (ei_status.word16 && (count & 0x01))
503 count++;
504
505 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
506 if (ei_status.dmaing) {
507 printk("%s: DMAing conflict in ne_block_output."
508 "[DMAstat:%d][irqlock:%d][intr:%d]\n",
509 dev->name, ei_status.dmaing, ei_status.irqlock, dev->irq);
510 return;
511 }
512 ei_status.dmaing |= 0x01;
513 /* We should already be in page 0, but to be safe... */
514 outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
515
516 outb(ENISR_RDC, nic_base + NE_EN0_ISR);
517
518 /* Now the normal output. */
519 outb(count & 0xff, nic_base + NE_EN0_RCNTLO);
520 outb(count >> 8, nic_base + NE_EN0_RCNTHI);
521 outb(0x00, nic_base + NE_EN0_RSARLO);
522 outb(start_page, nic_base + NE_EN0_RSARHI);
523
524 outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
525 if (ei_status.word16) {
526 ptrs = (short*)buf;
527 for (cnt = 0; cnt < count>>1; cnt++)
528 outw(*ptrs++, NE_BASE+NE_DATAPORT);
529 } else {
530 ptrc = (char*)buf;
531 for (cnt = 0; cnt < count; cnt++)
532 outb(*ptrc++, NE_BASE + NE_DATAPORT);
533 }
534
535 dma_start = jiffies;
536
537 while ((inb(NE_BASE + NE_EN0_ISR) & ENISR_RDC) == 0)
Marcelo Feitoza Parisiff5688a2006-01-09 18:37:15 -0800538 if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 printk("%s: timeout waiting for Tx RDC.\n", dev->name);
540 apne_reset_8390(dev);
541 NS8390_init(dev,1);
542 break;
543 }
544
545 outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
546 ei_status.dmaing &= ~0x01;
547 return;
548}
549
David Howells7d12e782006-10-05 14:55:46 +0100550static irqreturn_t apne_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551{
552 unsigned char pcmcia_intreq;
553
554 if (!(gayle.inten & GAYLE_IRQ_IRQ))
555 return IRQ_NONE;
556
557 pcmcia_intreq = pcmcia_get_intreq();
558
559 if (!(pcmcia_intreq & GAYLE_IRQ_IRQ)) {
560 pcmcia_ack_int(pcmcia_intreq);
561 return IRQ_NONE;
562 }
563 if (ei_debug > 3)
564 printk("pcmcia intreq = %x\n", pcmcia_intreq);
565 pcmcia_disable_irq(); /* to get rid of the sti() within ei_interrupt */
David Howells7d12e782006-10-05 14:55:46 +0100566 ei_interrupt(irq, dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 pcmcia_ack_int(pcmcia_get_intreq());
568 pcmcia_enable_irq();
569 return IRQ_HANDLED;
570}
571
572#ifdef MODULE
573static struct net_device *apne_dev;
574
Jon Schindler3cfbb672008-03-05 18:50:16 -0800575static int __init apne_module_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
577 apne_dev = apne_probe(-1);
578 if (IS_ERR(apne_dev))
579 return PTR_ERR(apne_dev);
580 return 0;
581}
582
Jon Schindler3cfbb672008-03-05 18:50:16 -0800583static void __exit apne_module_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
585 unregister_netdev(apne_dev);
586
587 pcmcia_disable_irq();
588
589 free_irq(IRQ_AMIGA_PORTS, apne_dev);
590
591 pcmcia_reset();
592
593 release_region(IOBASE, 0x20);
594
595 free_netdev(apne_dev);
596}
Jon Schindler3cfbb672008-03-05 18:50:16 -0800597module_init(apne_module_init);
598module_exit(apne_module_exit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599#endif
600
601static int init_pcmcia(void)
602{
603 u_char config;
604#ifndef MANUAL_CONFIG
605 u_char tuple[32];
606 int offset_len;
607#endif
608 u_long offset;
609
610 pcmcia_reset();
611 pcmcia_program_voltage(PCMCIA_0V);
612 pcmcia_access_speed(PCMCIA_SPEED_250NS);
613 pcmcia_write_enable();
614
615#ifdef MANUAL_CONFIG
616 config = MANUAL_CONFIG;
617#else
618 /* get and write config byte to enable IO port */
619
620 if (pcmcia_copy_tuple(CISTPL_CFTABLE_ENTRY, tuple, 32) < 3)
621 return 0;
622
623 config = tuple[2] & 0x3f;
624#endif
625#ifdef MANUAL_OFFSET
626 offset = MANUAL_OFFSET;
627#else
628 if (pcmcia_copy_tuple(CISTPL_CONFIG, tuple, 32) < 6)
629 return 0;
630
631 offset_len = (tuple[2] & 0x3) + 1;
632 offset = 0;
633 while(offset_len--) {
634 offset = (offset << 8) | tuple[4+offset_len];
635 }
636#endif
637
638 out_8(GAYLE_ATTRIBUTE+offset, config);
639
640 return 1;
641}
642
643MODULE_LICENSE("GPL");