apne.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. /*
  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. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/errno.h>
  32. #include <linux/pci.h>
  33. #include <linux/init.h>
  34. #include <linux/delay.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/jiffies.h>
  39. #include <asm/io.h>
  40. #include <asm/setup.h>
  41. #include <asm/amigaints.h>
  42. #include <asm/amigahw.h>
  43. #include <asm/amigayle.h>
  44. #include <asm/amipcmcia.h>
  45. #include "8390.h"
  46. /* ---- No user-serviceable parts below ---- */
  47. #define DRV_NAME "apne"
  48. #define NE_BASE (dev->base_addr)
  49. #define NE_CMD 0x00
  50. #define NE_DATAPORT 0x10 /* NatSemi-defined port window offset. */
  51. #define NE_RESET 0x1f /* Issue a read to reset, a write to clear. */
  52. #define NE_IO_EXTENT 0x20
  53. #define NE_EN0_ISR 0x07
  54. #define NE_EN0_DCFG 0x0e
  55. #define NE_EN0_RSARLO 0x08
  56. #define NE_EN0_RSARHI 0x09
  57. #define NE_EN0_RCNTLO 0x0a
  58. #define NE_EN0_RXCR 0x0c
  59. #define NE_EN0_TXCR 0x0d
  60. #define NE_EN0_RCNTHI 0x0b
  61. #define NE_EN0_IMR 0x0f
  62. #define NE1SM_START_PG 0x20 /* First page of TX buffer */
  63. #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
  64. #define NESM_START_PG 0x40 /* First page of TX buffer */
  65. #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
  66. struct net_device * __init apne_probe(int unit);
  67. static int apne_probe1(struct net_device *dev, int ioaddr);
  68. static void apne_reset_8390(struct net_device *dev);
  69. static void apne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  70. int ring_page);
  71. static void apne_block_input(struct net_device *dev, int count,
  72. struct sk_buff *skb, int ring_offset);
  73. static void apne_block_output(struct net_device *dev, const int count,
  74. const unsigned char *buf, const int start_page);
  75. static irqreturn_t apne_interrupt(int irq, void *dev_id);
  76. static int init_pcmcia(void);
  77. /* IO base address used for nic */
  78. #define IOBASE 0x300
  79. /*
  80. use MANUAL_CONFIG and MANUAL_OFFSET for enabling IO by hand
  81. you can find the values to use by looking at the cnet.device
  82. config file example (the default values are for the CNET40BC card)
  83. */
  84. /*
  85. #define MANUAL_CONFIG 0x20
  86. #define MANUAL_OFFSET 0x3f8
  87. #define MANUAL_HWADDR0 0x00
  88. #define MANUAL_HWADDR1 0x12
  89. #define MANUAL_HWADDR2 0x34
  90. #define MANUAL_HWADDR3 0x56
  91. #define MANUAL_HWADDR4 0x78
  92. #define MANUAL_HWADDR5 0x9a
  93. */
  94. static const char version[] =
  95. "apne.c:v1.1 7/10/98 Alain Malek (Alain.Malek@cryogen.ch)\n";
  96. static int apne_owned; /* signal if card already owned */
  97. static u32 apne_msg_enable;
  98. module_param_named(msg_enable, apne_msg_enable, uint, (S_IRUSR|S_IRGRP|S_IROTH));
  99. MODULE_PARM_DESC(msg_enable, "Debug message level (see linux/netdevice.h for bitmap)");
  100. struct net_device * __init apne_probe(int unit)
  101. {
  102. struct net_device *dev;
  103. struct ei_device *ei_local;
  104. #ifndef MANUAL_CONFIG
  105. char tuple[8];
  106. #endif
  107. int err;
  108. if (!MACH_IS_AMIGA)
  109. return ERR_PTR(-ENODEV);
  110. if (apne_owned)
  111. return ERR_PTR(-ENODEV);
  112. if ( !(AMIGAHW_PRESENT(PCMCIA)) )
  113. return ERR_PTR(-ENODEV);
  114. pr_info("Looking for PCMCIA ethernet card : ");
  115. /* check if a card is inserted */
  116. if (!(PCMCIA_INSERTED)) {
  117. pr_cont("NO PCMCIA card inserted\n");
  118. return ERR_PTR(-ENODEV);
  119. }
  120. dev = alloc_ei_netdev();
  121. if (!dev)
  122. return ERR_PTR(-ENOMEM);
  123. if (unit >= 0) {
  124. sprintf(dev->name, "eth%d", unit);
  125. netdev_boot_setup_check(dev);
  126. }
  127. ei_local = netdev_priv(dev);
  128. ei_local->msg_enable = apne_msg_enable;
  129. /* disable pcmcia irq for readtuple */
  130. pcmcia_disable_irq();
  131. #ifndef MANUAL_CONFIG
  132. if ((pcmcia_copy_tuple(CISTPL_FUNCID, tuple, 8) < 3) ||
  133. (tuple[2] != CISTPL_FUNCID_NETWORK)) {
  134. pr_cont("not an ethernet card\n");
  135. /* XXX: shouldn't we re-enable irq here? */
  136. free_netdev(dev);
  137. return ERR_PTR(-ENODEV);
  138. }
  139. #endif
  140. pr_cont("ethernet PCMCIA card inserted\n");
  141. if (!init_pcmcia()) {
  142. /* XXX: shouldn't we re-enable irq here? */
  143. free_netdev(dev);
  144. return ERR_PTR(-ENODEV);
  145. }
  146. if (!request_region(IOBASE, 0x20, DRV_NAME)) {
  147. free_netdev(dev);
  148. return ERR_PTR(-EBUSY);
  149. }
  150. err = apne_probe1(dev, IOBASE);
  151. if (err) {
  152. release_region(IOBASE, 0x20);
  153. free_netdev(dev);
  154. return ERR_PTR(err);
  155. }
  156. err = register_netdev(dev);
  157. if (!err)
  158. return dev;
  159. pcmcia_disable_irq();
  160. free_irq(IRQ_AMIGA_PORTS, dev);
  161. pcmcia_reset();
  162. release_region(IOBASE, 0x20);
  163. free_netdev(dev);
  164. return ERR_PTR(err);
  165. }
  166. static int __init apne_probe1(struct net_device *dev, int ioaddr)
  167. {
  168. int i;
  169. unsigned char SA_prom[32];
  170. int wordlength = 2;
  171. const char *name = NULL;
  172. int start_page, stop_page;
  173. #ifndef MANUAL_HWADDR0
  174. int neX000, ctron;
  175. #endif
  176. static unsigned version_printed;
  177. if ((apne_msg_enable & NETIF_MSG_DRV) && (version_printed++ == 0))
  178. netdev_info(dev, version);
  179. netdev_info(dev, "PCMCIA NE*000 ethercard probe");
  180. /* Reset card. Who knows what dain-bramaged state it was left in. */
  181. { unsigned long reset_start_time = jiffies;
  182. outb(inb(ioaddr + NE_RESET), ioaddr + NE_RESET);
  183. while ((inb(ioaddr + NE_EN0_ISR) & ENISR_RESET) == 0)
  184. if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
  185. pr_cont(" not found (no reset ack).\n");
  186. return -ENODEV;
  187. }
  188. outb(0xff, ioaddr + NE_EN0_ISR); /* Ack all intr. */
  189. }
  190. #ifndef MANUAL_HWADDR0
  191. /* Read the 16 bytes of station address PROM.
  192. We must first initialize registers, similar to NS8390_init(eifdev, 0).
  193. We can't reliably read the SAPROM address without this.
  194. (I learned the hard way!). */
  195. {
  196. struct {unsigned long value, offset; } program_seq[] = {
  197. {E8390_NODMA+E8390_PAGE0+E8390_STOP, NE_CMD}, /* Select page 0*/
  198. {0x48, NE_EN0_DCFG}, /* Set byte-wide (0x48) access. */
  199. {0x00, NE_EN0_RCNTLO}, /* Clear the count regs. */
  200. {0x00, NE_EN0_RCNTHI},
  201. {0x00, NE_EN0_IMR}, /* Mask completion irq. */
  202. {0xFF, NE_EN0_ISR},
  203. {E8390_RXOFF, NE_EN0_RXCR}, /* 0x20 Set to monitor */
  204. {E8390_TXOFF, NE_EN0_TXCR}, /* 0x02 and loopback mode. */
  205. {32, NE_EN0_RCNTLO},
  206. {0x00, NE_EN0_RCNTHI},
  207. {0x00, NE_EN0_RSARLO}, /* DMA starting at 0x0000. */
  208. {0x00, NE_EN0_RSARHI},
  209. {E8390_RREAD+E8390_START, NE_CMD},
  210. };
  211. for (i = 0; i < ARRAY_SIZE(program_seq); i++) {
  212. outb(program_seq[i].value, ioaddr + program_seq[i].offset);
  213. }
  214. }
  215. for(i = 0; i < 32 /*sizeof(SA_prom)*/; i+=2) {
  216. SA_prom[i] = inb(ioaddr + NE_DATAPORT);
  217. SA_prom[i+1] = inb(ioaddr + NE_DATAPORT);
  218. if (SA_prom[i] != SA_prom[i+1])
  219. wordlength = 1;
  220. }
  221. /* At this point, wordlength *only* tells us if the SA_prom is doubled
  222. up or not because some broken PCI cards don't respect the byte-wide
  223. request in program_seq above, and hence don't have doubled up values.
  224. These broken cards would otherwise be detected as an ne1000. */
  225. if (wordlength == 2)
  226. for (i = 0; i < 16; i++)
  227. SA_prom[i] = SA_prom[i+i];
  228. if (wordlength == 2) {
  229. /* We must set the 8390 for word mode. */
  230. outb(0x49, ioaddr + NE_EN0_DCFG);
  231. start_page = NESM_START_PG;
  232. stop_page = NESM_STOP_PG;
  233. } else {
  234. start_page = NE1SM_START_PG;
  235. stop_page = NE1SM_STOP_PG;
  236. }
  237. neX000 = (SA_prom[14] == 0x57 && SA_prom[15] == 0x57);
  238. ctron = (SA_prom[0] == 0x00 && SA_prom[1] == 0x00 && SA_prom[2] == 0x1d);
  239. /* Set up the rest of the parameters. */
  240. if (neX000) {
  241. name = (wordlength == 2) ? "NE2000" : "NE1000";
  242. } else if (ctron) {
  243. name = (wordlength == 2) ? "Ctron-8" : "Ctron-16";
  244. start_page = 0x01;
  245. stop_page = (wordlength == 2) ? 0x40 : 0x20;
  246. } else {
  247. pr_cont(" not found.\n");
  248. return -ENXIO;
  249. }
  250. #else
  251. wordlength = 2;
  252. /* We must set the 8390 for word mode. */
  253. outb(0x49, ioaddr + NE_EN0_DCFG);
  254. start_page = NESM_START_PG;
  255. stop_page = NESM_STOP_PG;
  256. SA_prom[0] = MANUAL_HWADDR0;
  257. SA_prom[1] = MANUAL_HWADDR1;
  258. SA_prom[2] = MANUAL_HWADDR2;
  259. SA_prom[3] = MANUAL_HWADDR3;
  260. SA_prom[4] = MANUAL_HWADDR4;
  261. SA_prom[5] = MANUAL_HWADDR5;
  262. name = "NE2000";
  263. #endif
  264. dev->base_addr = ioaddr;
  265. dev->irq = IRQ_AMIGA_PORTS;
  266. dev->netdev_ops = &ei_netdev_ops;
  267. /* Install the Interrupt handler */
  268. i = request_irq(dev->irq, apne_interrupt, IRQF_SHARED, DRV_NAME, dev);
  269. if (i) return i;
  270. for (i = 0; i < ETH_ALEN; i++)
  271. dev->dev_addr[i] = SA_prom[i];
  272. pr_cont(" %pM\n", dev->dev_addr);
  273. netdev_info(dev, "%s found.\n", name);
  274. ei_status.name = name;
  275. ei_status.tx_start_page = start_page;
  276. ei_status.stop_page = stop_page;
  277. ei_status.word16 = (wordlength == 2);
  278. ei_status.rx_start_page = start_page + TX_PAGES;
  279. ei_status.reset_8390 = &apne_reset_8390;
  280. ei_status.block_input = &apne_block_input;
  281. ei_status.block_output = &apne_block_output;
  282. ei_status.get_8390_hdr = &apne_get_8390_hdr;
  283. NS8390_init(dev, 0);
  284. pcmcia_ack_int(pcmcia_get_intreq()); /* ack PCMCIA int req */
  285. pcmcia_enable_irq();
  286. apne_owned = 1;
  287. return 0;
  288. }
  289. /* Hard reset the card. This used to pause for the same period that a
  290. 8390 reset command required, but that shouldn't be necessary. */
  291. static void
  292. apne_reset_8390(struct net_device *dev)
  293. {
  294. unsigned long reset_start_time = jiffies;
  295. struct ei_device *ei_local = netdev_priv(dev);
  296. init_pcmcia();
  297. netif_dbg(ei_local, hw, dev, "resetting the 8390 t=%ld...\n", jiffies);
  298. outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET);
  299. ei_status.txing = 0;
  300. ei_status.dmaing = 0;
  301. /* This check _should_not_ be necessary, omit eventually. */
  302. while ((inb(NE_BASE+NE_EN0_ISR) & ENISR_RESET) == 0)
  303. if (time_after(jiffies, reset_start_time + 2*HZ/100)) {
  304. netdev_err(dev, "ne_reset_8390() did not complete.\n");
  305. break;
  306. }
  307. outb(ENISR_RESET, NE_BASE + NE_EN0_ISR); /* Ack intr. */
  308. }
  309. /* Grab the 8390 specific header. Similar to the block_input routine, but
  310. we don't need to be concerned with ring wrap as the header will be at
  311. the start of a page, so we optimize accordingly. */
  312. static void
  313. apne_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  314. {
  315. int nic_base = dev->base_addr;
  316. int cnt;
  317. char *ptrc;
  318. short *ptrs;
  319. /* This *shouldn't* happen. If it does, it's the last thing you'll see */
  320. if (ei_status.dmaing) {
  321. netdev_err(dev, "DMAing conflict in ne_get_8390_hdr "
  322. "[DMAstat:%d][irqlock:%d][intr:%d].\n",
  323. ei_status.dmaing, ei_status.irqlock, dev->irq);
  324. return;
  325. }
  326. ei_status.dmaing |= 0x01;
  327. outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
  328. outb(ENISR_RDC, nic_base + NE_EN0_ISR);
  329. outb(sizeof(struct e8390_pkt_hdr), nic_base + NE_EN0_RCNTLO);
  330. outb(0, nic_base + NE_EN0_RCNTHI);
  331. outb(0, nic_base + NE_EN0_RSARLO); /* On page boundary */
  332. outb(ring_page, nic_base + NE_EN0_RSARHI);
  333. outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  334. if (ei_status.word16) {
  335. ptrs = (short*)hdr;
  336. for(cnt = 0; cnt < (sizeof(struct e8390_pkt_hdr)>>1); cnt++)
  337. *ptrs++ = inw(NE_BASE + NE_DATAPORT);
  338. } else {
  339. ptrc = (char*)hdr;
  340. for(cnt = 0; cnt < sizeof(struct e8390_pkt_hdr); cnt++)
  341. *ptrc++ = inb(NE_BASE + NE_DATAPORT);
  342. }
  343. outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
  344. ei_status.dmaing &= ~0x01;
  345. le16_to_cpus(&hdr->count);
  346. }
  347. /* Block input and output, similar to the Crynwr packet driver. If you
  348. are porting to a new ethercard, look at the packet driver source for hints.
  349. The NEx000 doesn't share the on-board packet memory -- you have to put
  350. the packet out through the "remote DMA" dataport using outb. */
  351. static void
  352. apne_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  353. {
  354. int nic_base = dev->base_addr;
  355. char *buf = skb->data;
  356. char *ptrc;
  357. short *ptrs;
  358. int cnt;
  359. /* This *shouldn't* happen. If it does, it's the last thing you'll see */
  360. if (ei_status.dmaing) {
  361. netdev_err(dev, "DMAing conflict in ne_block_input "
  362. "[DMAstat:%d][irqlock:%d][intr:%d].\n",
  363. ei_status.dmaing, ei_status.irqlock, dev->irq);
  364. return;
  365. }
  366. ei_status.dmaing |= 0x01;
  367. outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
  368. outb(ENISR_RDC, nic_base + NE_EN0_ISR);
  369. outb(count & 0xff, nic_base + NE_EN0_RCNTLO);
  370. outb(count >> 8, nic_base + NE_EN0_RCNTHI);
  371. outb(ring_offset & 0xff, nic_base + NE_EN0_RSARLO);
  372. outb(ring_offset >> 8, nic_base + NE_EN0_RSARHI);
  373. outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
  374. if (ei_status.word16) {
  375. ptrs = (short*)buf;
  376. for (cnt = 0; cnt < (count>>1); cnt++)
  377. *ptrs++ = inw(NE_BASE + NE_DATAPORT);
  378. if (count & 0x01) {
  379. buf[count-1] = inb(NE_BASE + NE_DATAPORT);
  380. }
  381. } else {
  382. ptrc = buf;
  383. for (cnt = 0; cnt < count; cnt++)
  384. *ptrc++ = inb(NE_BASE + NE_DATAPORT);
  385. }
  386. outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
  387. ei_status.dmaing &= ~0x01;
  388. }
  389. static void
  390. apne_block_output(struct net_device *dev, int count,
  391. const unsigned char *buf, const int start_page)
  392. {
  393. int nic_base = NE_BASE;
  394. unsigned long dma_start;
  395. char *ptrc;
  396. short *ptrs;
  397. int cnt;
  398. /* Round the count up for word writes. Do we need to do this?
  399. What effect will an odd byte count have on the 8390?
  400. I should check someday. */
  401. if (ei_status.word16 && (count & 0x01))
  402. count++;
  403. /* This *shouldn't* happen. If it does, it's the last thing you'll see */
  404. if (ei_status.dmaing) {
  405. netdev_err(dev, "DMAing conflict in ne_block_output."
  406. "[DMAstat:%d][irqlock:%d][intr:%d]\n",
  407. ei_status.dmaing, ei_status.irqlock, dev->irq);
  408. return;
  409. }
  410. ei_status.dmaing |= 0x01;
  411. /* We should already be in page 0, but to be safe... */
  412. outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
  413. outb(ENISR_RDC, nic_base + NE_EN0_ISR);
  414. /* Now the normal output. */
  415. outb(count & 0xff, nic_base + NE_EN0_RCNTLO);
  416. outb(count >> 8, nic_base + NE_EN0_RCNTHI);
  417. outb(0x00, nic_base + NE_EN0_RSARLO);
  418. outb(start_page, nic_base + NE_EN0_RSARHI);
  419. outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
  420. if (ei_status.word16) {
  421. ptrs = (short*)buf;
  422. for (cnt = 0; cnt < count>>1; cnt++)
  423. outw(*ptrs++, NE_BASE+NE_DATAPORT);
  424. } else {
  425. ptrc = (char*)buf;
  426. for (cnt = 0; cnt < count; cnt++)
  427. outb(*ptrc++, NE_BASE + NE_DATAPORT);
  428. }
  429. dma_start = jiffies;
  430. while ((inb(NE_BASE + NE_EN0_ISR) & ENISR_RDC) == 0)
  431. if (time_after(jiffies, dma_start + 2*HZ/100)) { /* 20ms */
  432. netdev_warn(dev, "timeout waiting for Tx RDC.\n");
  433. apne_reset_8390(dev);
  434. NS8390_init(dev,1);
  435. break;
  436. }
  437. outb(ENISR_RDC, nic_base + NE_EN0_ISR); /* Ack intr. */
  438. ei_status.dmaing &= ~0x01;
  439. }
  440. static irqreturn_t apne_interrupt(int irq, void *dev_id)
  441. {
  442. unsigned char pcmcia_intreq;
  443. if (!(gayle.inten & GAYLE_IRQ_IRQ))
  444. return IRQ_NONE;
  445. pcmcia_intreq = pcmcia_get_intreq();
  446. if (!(pcmcia_intreq & GAYLE_IRQ_IRQ)) {
  447. pcmcia_ack_int(pcmcia_intreq);
  448. return IRQ_NONE;
  449. }
  450. if (apne_msg_enable & NETIF_MSG_INTR)
  451. pr_debug("pcmcia intreq = %x\n", pcmcia_intreq);
  452. pcmcia_disable_irq(); /* to get rid of the sti() within ei_interrupt */
  453. ei_interrupt(irq, dev_id);
  454. pcmcia_ack_int(pcmcia_get_intreq());
  455. pcmcia_enable_irq();
  456. return IRQ_HANDLED;
  457. }
  458. #ifdef MODULE
  459. static struct net_device *apne_dev;
  460. static int __init apne_module_init(void)
  461. {
  462. apne_dev = apne_probe(-1);
  463. return PTR_ERR_OR_ZERO(apne_dev);
  464. }
  465. static void __exit apne_module_exit(void)
  466. {
  467. unregister_netdev(apne_dev);
  468. pcmcia_disable_irq();
  469. free_irq(IRQ_AMIGA_PORTS, apne_dev);
  470. pcmcia_reset();
  471. release_region(IOBASE, 0x20);
  472. free_netdev(apne_dev);
  473. }
  474. module_init(apne_module_init);
  475. module_exit(apne_module_exit);
  476. #endif
  477. static int init_pcmcia(void)
  478. {
  479. u_char config;
  480. #ifndef MANUAL_CONFIG
  481. u_char tuple[32];
  482. int offset_len;
  483. #endif
  484. u_long offset;
  485. pcmcia_reset();
  486. pcmcia_program_voltage(PCMCIA_0V);
  487. pcmcia_access_speed(PCMCIA_SPEED_250NS);
  488. pcmcia_write_enable();
  489. #ifdef MANUAL_CONFIG
  490. config = MANUAL_CONFIG;
  491. #else
  492. /* get and write config byte to enable IO port */
  493. if (pcmcia_copy_tuple(CISTPL_CFTABLE_ENTRY, tuple, 32) < 3)
  494. return 0;
  495. config = tuple[2] & 0x3f;
  496. #endif
  497. #ifdef MANUAL_OFFSET
  498. offset = MANUAL_OFFSET;
  499. #else
  500. if (pcmcia_copy_tuple(CISTPL_CONFIG, tuple, 32) < 6)
  501. return 0;
  502. offset_len = (tuple[2] & 0x3) + 1;
  503. offset = 0;
  504. while(offset_len--) {
  505. offset = (offset << 8) | tuple[4+offset_len];
  506. }
  507. #endif
  508. out_8(GAYLE_ATTRIBUTE+offset, config);
  509. return 1;
  510. }
  511. MODULE_LICENSE("GPL");