1 /* drivers/net/ax88796.c
3 * Copyright 2005,2007 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * Asix AX88796 10/100 Ethernet controller support
7 * Based on ne.c, by Donald Becker, et-al.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/isapnp.h>
18 #include <linux/init.h>
19 #include <linux/interrupt.h>
20 #include <linux/platform_device.h>
21 #include <linux/delay.h>
22 #include <linux/timer.h>
23 #include <linux/netdevice.h>
24 #include <linux/etherdevice.h>
25 #include <linux/ethtool.h>
26 #include <linux/mii.h>
28 #include <net/ax88796.h>
30 #include <asm/system.h>
33 static int phy_debug = 0;
35 /* Rename the lib8390.c functions to show that they are in this driver */
36 #define __ei_open ax_ei_open
37 #define __ei_close ax_ei_close
38 #define __ei_poll ax_ei_poll
39 #define __ei_tx_timeout ax_ei_tx_timeout
40 #define __ei_interrupt ax_ei_interrupt
41 #define ____alloc_ei_netdev ax__alloc_ei_netdev
42 #define __NS8390_init ax_NS8390_init
44 /* force unsigned long back to 'void __iomem *' */
45 #define ax_convert_addr(_a) ((void __force __iomem *)(_a))
47 #define ei_inb(_a) readb(ax_convert_addr(_a))
48 #define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a))
50 #define ei_inb_p(_a) ei_inb(_a)
51 #define ei_outb_p(_v, _a) ei_outb(_v, _a)
53 /* define EI_SHIFT() to take into account our register offsets */
54 #define EI_SHIFT(x) (ei_local->reg_offset[(x)])
56 /* Ensure we have our RCR base value */
57 #define AX88796_PLATFORM
59 static unsigned char version[] = "ax88796.c: Copyright 2005,2007 Simtec Electronics\n";
63 #define DRV_NAME "ax88796"
64 #define DRV_VERSION "1.00"
67 #define NE_CMD EI_SHIFT(0x00)
68 #define NE_RESET EI_SHIFT(0x1f)
69 #define NE_DATAPORT EI_SHIFT(0x10)
71 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
72 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
73 #define NESM_START_PG 0x40 /* First page of TX buffer */
74 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
76 /* device private data */
79 struct timer_list mii_timer;
81 struct mii_if_info mii;
85 struct platform_device *dev;
87 struct resource *mem2;
88 struct ax_plat_data *plat;
90 unsigned char running;
91 unsigned char resume_open;
93 u32 reg_offsets[0x20];
96 static inline struct ax_device *to_ax_dev(struct net_device *dev)
98 struct ei_device *ei_local = netdev_priv(dev);
99 return (struct ax_device *)(ei_local+1);
104 * do an initial probe for the card to check wether it exists
108 static int ax_initial_check(struct net_device *dev)
110 struct ei_device *ei_local = netdev_priv(dev);
111 void __iomem *ioaddr = ei_local->mem;
115 reg0 = ei_inb(ioaddr);
119 ei_outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD);
120 regd = ei_inb(ioaddr + 0x0d);
121 ei_outb(0xff, ioaddr + 0x0d);
122 ei_outb(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD);
123 ei_inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
124 if (ei_inb(ioaddr + EN0_COUNTER0) != 0) {
125 ei_outb(reg0, ioaddr);
126 ei_outb(regd, ioaddr + 0x0d); /* Restore the old values. */
133 /* Hard reset the card. This used to pause for the same period that a
134 8390 reset command required, but that shouldn't be necessary. */
136 static void ax_reset_8390(struct net_device *dev)
138 struct ei_device *ei_local = netdev_priv(dev);
139 unsigned long reset_start_time = jiffies;
140 void __iomem *addr = (void __iomem *)dev->base_addr;
143 printk(KERN_DEBUG "resetting the 8390 t=%ld...", jiffies);
145 ei_outb(ei_inb(addr + NE_RESET), addr + NE_RESET);
148 ei_status.dmaing = 0;
150 /* This check _should_not_ be necessary, omit eventually. */
151 while ((ei_inb(addr + EN0_ISR) & ENISR_RESET) == 0) {
152 if (jiffies - reset_start_time > 2*HZ/100) {
153 printk(KERN_WARNING "%s: %s did not complete.\n",
154 __FUNCTION__, dev->name);
159 ei_outb(ENISR_RESET, addr + EN0_ISR); /* Ack intr. */
163 static void ax_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
166 struct ei_device *ei_local = netdev_priv(dev);
167 void __iomem *nic_base = ei_local->mem;
169 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
170 if (ei_status.dmaing) {
171 printk(KERN_EMERG "%s: DMAing conflict in %s [DMAstat:%d][irqlock:%d].\n",
172 dev->name, __FUNCTION__,
173 ei_status.dmaing, ei_status.irqlock);
177 ei_status.dmaing |= 0x01;
178 ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
179 ei_outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
180 ei_outb(0, nic_base + EN0_RCNTHI);
181 ei_outb(0, nic_base + EN0_RSARLO); /* On page boundary */
182 ei_outb(ring_page, nic_base + EN0_RSARHI);
183 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
185 if (ei_status.word16)
186 readsw(nic_base + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1);
188 readsb(nic_base + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr));
190 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
191 ei_status.dmaing &= ~0x01;
193 le16_to_cpus(&hdr->count);
197 /* Block input and output, similar to the Crynwr packet driver. If you
198 are porting to a new ethercard, look at the packet driver source for hints.
199 The NEx000 doesn't share the on-board packet memory -- you have to put
200 the packet out through the "remote DMA" dataport using ei_outb. */
202 static void ax_block_input(struct net_device *dev, int count,
203 struct sk_buff *skb, int ring_offset)
205 struct ei_device *ei_local = netdev_priv(dev);
206 void __iomem *nic_base = ei_local->mem;
207 char *buf = skb->data;
209 if (ei_status.dmaing) {
210 printk(KERN_EMERG "%s: DMAing conflict in ax_block_input "
211 "[DMAstat:%d][irqlock:%d].\n",
212 dev->name, ei_status.dmaing, ei_status.irqlock);
216 ei_status.dmaing |= 0x01;
218 ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD);
219 ei_outb(count & 0xff, nic_base + EN0_RCNTLO);
220 ei_outb(count >> 8, nic_base + EN0_RCNTHI);
221 ei_outb(ring_offset & 0xff, nic_base + EN0_RSARLO);
222 ei_outb(ring_offset >> 8, nic_base + EN0_RSARHI);
223 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
225 if (ei_status.word16) {
226 readsw(nic_base + NE_DATAPORT, buf, count >> 1);
228 buf[count-1] = ei_inb(nic_base + NE_DATAPORT);
231 readsb(nic_base + NE_DATAPORT, buf, count);
234 ei_status.dmaing &= ~1;
237 static void ax_block_output(struct net_device *dev, int count,
238 const unsigned char *buf, const int start_page)
240 struct ei_device *ei_local = netdev_priv(dev);
241 void __iomem *nic_base = ei_local->mem;
242 unsigned long dma_start;
244 /* Round the count up for word writes. Do we need to do this?
245 What effect will an odd byte count have on the 8390?
246 I should check someday. */
248 if (ei_status.word16 && (count & 0x01))
251 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
252 if (ei_status.dmaing) {
253 printk(KERN_EMERG "%s: DMAing conflict in %s."
254 "[DMAstat:%d][irqlock:%d]\n",
255 dev->name, __FUNCTION__,
256 ei_status.dmaing, ei_status.irqlock);
260 ei_status.dmaing |= 0x01;
261 /* We should already be in page 0, but to be safe... */
262 ei_outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
264 ei_outb(ENISR_RDC, nic_base + EN0_ISR);
266 /* Now the normal output. */
267 ei_outb(count & 0xff, nic_base + EN0_RCNTLO);
268 ei_outb(count >> 8, nic_base + EN0_RCNTHI);
269 ei_outb(0x00, nic_base + EN0_RSARLO);
270 ei_outb(start_page, nic_base + EN0_RSARHI);
272 ei_outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
273 if (ei_status.word16) {
274 writesw(nic_base + NE_DATAPORT, buf, count>>1);
276 writesb(nic_base + NE_DATAPORT, buf, count);
281 while ((ei_inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) {
282 if (jiffies - dma_start > 2*HZ/100) { /* 20ms */
283 printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name);
285 ax_NS8390_init(dev,1);
290 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
291 ei_status.dmaing &= ~0x01;
295 /* definitions for accessing MII/EEPROM interface */
297 #define AX_MEMR EI_SHIFT(0x14)
298 #define AX_MEMR_MDC (1<<0)
299 #define AX_MEMR_MDIR (1<<1)
300 #define AX_MEMR_MDI (1<<2)
301 #define AX_MEMR_MDO (1<<3)
302 #define AX_MEMR_EECS (1<<4)
303 #define AX_MEMR_EEI (1<<5)
304 #define AX_MEMR_EEO (1<<6)
305 #define AX_MEMR_EECLK (1<<7)
309 * write the specified set of bits to the phy
313 ax_mii_ei_outbits(struct net_device *dev, unsigned int bits, int len)
315 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
316 void __iomem *memr_addr = (void __iomem *)dev->base_addr + AX_MEMR;
319 /* clock low, data to output mode */
320 memr = ei_inb(memr_addr);
321 memr &= ~(AX_MEMR_MDC | AX_MEMR_MDIR);
322 ei_outb(memr, memr_addr);
324 for (len--; len >= 0; len--) {
325 if (bits & (1 << len))
328 memr &= ~AX_MEMR_MDO;
330 ei_outb(memr, memr_addr);
334 ei_outb(memr | AX_MEMR_MDC, memr_addr);
338 ei_outb(memr, memr_addr);
341 /* leaves the clock line low, mdir input */
342 memr |= AX_MEMR_MDIR;
343 ei_outb(memr, (void __iomem *)dev->base_addr + AX_MEMR);
348 * read a specified number of bits from the phy
352 ax_phy_ei_inbits(struct net_device *dev, int no)
354 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
355 void __iomem *memr_addr = (void __iomem *)dev->base_addr + AX_MEMR;
357 unsigned int result = 0;
359 /* clock low, data to input mode */
360 memr = ei_inb(memr_addr);
361 memr &= ~AX_MEMR_MDC;
362 memr |= AX_MEMR_MDIR;
363 ei_outb(memr, memr_addr);
365 for (no--; no >= 0; no--) {
366 ei_outb(memr | AX_MEMR_MDC, memr_addr);
370 if (ei_inb(memr_addr) & AX_MEMR_MDI)
373 ei_outb(memr, memr_addr);
381 * use the low level bit shifting routines to send the address
382 * and command to the specified phy
386 ax_phy_issueaddr(struct net_device *dev, int phy_addr, int reg, int opc)
389 pr_debug("%s: dev %p, %04x, %04x, %d\n",
390 __FUNCTION__, dev, phy_addr, reg, opc);
392 ax_mii_ei_outbits(dev, 0x3f, 6); /* pre-amble */
393 ax_mii_ei_outbits(dev, 1, 2); /* frame-start */
394 ax_mii_ei_outbits(dev, opc, 2); /* op code */
395 ax_mii_ei_outbits(dev, phy_addr, 5); /* phy address */
396 ax_mii_ei_outbits(dev, reg, 5); /* reg address */
400 ax_phy_read(struct net_device *dev, int phy_addr, int reg)
402 struct ei_device *ei_local = (struct ei_device *) netdev_priv(dev);
406 spin_lock_irqsave(&ei_local->page_lock, flags);
408 ax_phy_issueaddr(dev, phy_addr, reg, 2);
410 result = ax_phy_ei_inbits(dev, 17);
413 spin_unlock_irqrestore(&ei_local->page_lock, flags);
416 pr_debug("%s: %04x.%04x => read %04x\n", __FUNCTION__,
417 phy_addr, reg, result);
423 ax_phy_write(struct net_device *dev, int phy_addr, int reg, int value)
425 struct ei_device *ei = (struct ei_device *) netdev_priv(dev);
428 printk(KERN_DEBUG "%s: %p, %04x, %04x %04x\n",
429 __FUNCTION__, dev, phy_addr, reg, value);
431 spin_lock_irqsave(&ei->page_lock, flags);
433 ax_phy_issueaddr(dev, phy_addr, reg, 1);
434 ax_mii_ei_outbits(dev, 2, 2); /* send TA */
435 ax_mii_ei_outbits(dev, value, 16);
437 spin_unlock_irqrestore(&ei->page_lock, flags);
440 static void ax_mii_expiry(unsigned long data)
442 struct net_device *dev = (struct net_device *)data;
443 struct ax_device *ax = to_ax_dev(dev);
446 spin_lock_irqsave(&ax->mii_lock, flags);
447 mii_check_media(&ax->mii, netif_msg_link(ax), 0);
448 spin_unlock_irqrestore(&ax->mii_lock, flags);
451 ax->mii_timer.expires = jiffies + HZ*2;
452 add_timer(&ax->mii_timer);
456 static int ax_open(struct net_device *dev)
458 struct ax_device *ax = to_ax_dev(dev);
459 struct ei_device *ei_local = netdev_priv(dev);
462 dev_dbg(&ax->dev->dev, "%s: open\n", dev->name);
464 ret = request_irq(dev->irq, ax_ei_interrupt, 0, dev->name, dev);
468 ret = ax_ei_open(dev);
472 /* turn the phy on (if turned off) */
474 ei_outb(ax->plat->gpoc_val, ei_local->mem + EI_SHIFT(0x17));
477 /* start the MII timer */
479 init_timer(&ax->mii_timer);
481 ax->mii_timer.expires = jiffies+1;
482 ax->mii_timer.data = (unsigned long) dev;
483 ax->mii_timer.function = ax_mii_expiry;
485 add_timer(&ax->mii_timer);
490 static int ax_close(struct net_device *dev)
492 struct ax_device *ax = to_ax_dev(dev);
493 struct ei_device *ei_local = netdev_priv(dev);
495 dev_dbg(&ax->dev->dev, "%s: close\n", dev->name);
497 /* turn the phy off */
499 ei_outb(ax->plat->gpoc_val | (1<<6),
500 ei_local->mem + EI_SHIFT(0x17));
505 del_timer_sync(&ax->mii_timer);
508 free_irq(dev->irq, dev);
512 static int ax_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
514 struct ax_device *ax = to_ax_dev(dev);
518 if (!netif_running(dev))
521 spin_lock_irqsave(&ax->mii_lock, flags);
522 rc = generic_mii_ioctl(&ax->mii, if_mii(req), cmd, NULL);
523 spin_unlock_irqrestore(&ax->mii_lock, flags);
530 static void ax_get_drvinfo(struct net_device *dev,
531 struct ethtool_drvinfo *info)
533 struct ax_device *ax = to_ax_dev(dev);
535 strcpy(info->driver, DRV_NAME);
536 strcpy(info->version, DRV_VERSION);
537 strcpy(info->bus_info, ax->dev->name);
540 static int ax_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
542 struct ax_device *ax = to_ax_dev(dev);
545 spin_lock_irqsave(&ax->mii_lock, flags);
546 mii_ethtool_gset(&ax->mii, cmd);
547 spin_lock_irqsave(&ax->mii_lock, flags);
552 static int ax_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
554 struct ax_device *ax = to_ax_dev(dev);
558 spin_lock_irqsave(&ax->mii_lock, flags);
559 rc = mii_ethtool_sset(&ax->mii, cmd);
560 spin_lock_irqsave(&ax->mii_lock, flags);
565 static int ax_nway_reset(struct net_device *dev)
567 struct ax_device *ax = to_ax_dev(dev);
568 return mii_nway_restart(&ax->mii);
571 static u32 ax_get_link(struct net_device *dev)
573 struct ax_device *ax = to_ax_dev(dev);
574 return mii_link_ok(&ax->mii);
577 static const struct ethtool_ops ax_ethtool_ops = {
578 .get_drvinfo = ax_get_drvinfo,
579 .get_settings = ax_get_settings,
580 .set_settings = ax_set_settings,
581 .nway_reset = ax_nway_reset,
582 .get_link = ax_get_link,
583 .get_perm_addr = ethtool_op_get_perm_addr,
588 static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local)
590 void __iomem *ioaddr = ei_local->mem;
591 struct ax_device *ax = to_ax_dev(dev);
594 ei_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, ioaddr + E8390_CMD);
596 /* set to byte access */
597 ei_outb(ax->plat->dcr_val & ~1, ioaddr + EN0_DCFG);
598 ei_outb(ax->plat->gpoc_val, ioaddr + EI_SHIFT(0x17));
603 * initialise the specified device, taking care to note the MAC
604 * address it may already have (if configured), ensure
605 * the device is ready to be used by lib8390.c and registerd with
609 static int ax_init_dev(struct net_device *dev, int first_init)
611 struct ei_device *ei_local = netdev_priv(dev);
612 struct ax_device *ax = to_ax_dev(dev);
613 void __iomem *ioaddr = ei_local->mem;
614 unsigned int start_page;
615 unsigned int stop_page;
619 ret = ax_initial_check(dev);
623 /* setup goes here */
625 ax_initial_setup(dev, ei_local);
627 /* read the mac from the card prom if we need it */
629 if (first_init && ax->plat->flags & AXFLG_HAS_EEPROM) {
630 unsigned char SA_prom[32];
632 for(i = 0; i < sizeof(SA_prom); i+=2) {
633 SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT);
634 SA_prom[i+1] = ei_inb(ioaddr + NE_DATAPORT);
637 if (ax->plat->wordlength == 2)
638 for (i = 0; i < 16; i++)
639 SA_prom[i] = SA_prom[i+i];
641 memcpy(dev->dev_addr, SA_prom, 6);
644 if (ax->plat->wordlength == 2) {
645 /* We must set the 8390 for word mode. */
646 ei_outb(ax->plat->dcr_val, ei_local->mem + EN0_DCFG);
647 start_page = NESM_START_PG;
648 stop_page = NESM_STOP_PG;
650 start_page = NE1SM_START_PG;
651 stop_page = NE1SM_STOP_PG;
654 /* load the mac-address from the device if this is the
655 * first time we've initialised */
657 if (first_init && ax->plat->flags & AXFLG_MAC_FROMDEV) {
658 ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP,
659 ei_local->mem + E8390_CMD); /* 0x61 */
661 for (i = 0 ; i < ETHER_ADDR_LEN ; i++)
662 dev->dev_addr[i] = ei_inb(ioaddr + EN1_PHYS_SHIFT(i));
667 ei_status.name = "AX88796";
668 ei_status.tx_start_page = start_page;
669 ei_status.stop_page = stop_page;
670 ei_status.word16 = (ax->plat->wordlength == 2);
671 ei_status.rx_start_page = start_page + TX_PAGES;
673 #ifdef PACKETBUF_MEMSIZE
674 /* Allow the packet buffer size to be overridden by know-it-alls. */
675 ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;
678 ei_status.reset_8390 = &ax_reset_8390;
679 ei_status.block_input = &ax_block_input;
680 ei_status.block_output = &ax_block_output;
681 ei_status.get_8390_hdr = &ax_get_8390_hdr;
685 dev->stop = ax_close;
686 dev->do_ioctl = ax_ioctl;
687 dev->ethtool_ops = &ax_ethtool_ops;
689 ax->msg_enable = NETIF_MSG_LINK;
690 ax->mii.phy_id_mask = 0x1f;
691 ax->mii.reg_num_mask = 0x1f;
692 ax->mii.phy_id = 0x10; /* onboard phy */
693 ax->mii.force_media = 0;
694 ax->mii.full_duplex = 0;
695 ax->mii.mdio_read = ax_phy_read;
696 ax->mii.mdio_write = ax_phy_write;
699 #ifdef CONFIG_NET_POLL_CONTROLLER
700 dev->poll_controller = ax_ei_poll;
702 ax_NS8390_init(dev, 0);
705 printk("AX88796: %dbit, irq %d, %lx, MAC: ",
706 ei_status.word16 ? 16:8, dev->irq, dev->base_addr);
708 for (i = 0; i < ETHER_ADDR_LEN; i++)
709 printk("%2.2x%c", dev->dev_addr[i],
710 (i < (ETHER_ADDR_LEN-1) ? ':' : ' '));
715 ret = register_netdev(dev);
723 free_irq(dev->irq, dev);
728 static int ax_remove(struct platform_device *_dev)
730 struct net_device *dev = platform_get_drvdata(_dev);
731 struct ax_device *ax;
735 unregister_netdev(dev);
736 free_irq(dev->irq, dev);
738 iounmap(ei_status.mem);
739 release_resource(ax->mem);
744 release_resource(ax->mem2);
755 * This is the entry point when the platform device system uses to
756 * notify us of a new device to attach to. Allocate memory, find
757 * the resources and information passed, and map the necessary registers.
760 static int ax_probe(struct platform_device *pdev)
762 struct net_device *dev;
763 struct ax_device *ax;
764 struct resource *res;
768 dev = ax__alloc_ei_netdev(sizeof(struct ax_device));
772 /* ok, let's setup our device */
775 memset(ax, 0, sizeof(struct ax_device));
777 spin_lock_init(&ax->mii_lock);
780 ax->plat = pdev->dev.platform_data;
781 platform_set_drvdata(pdev, dev);
783 ei_status.rxcr_base = ax->plat->rcr_val;
785 /* find the platform resources */
787 dev->irq = platform_get_irq(pdev, 0);
789 dev_err(&pdev->dev, "no IRQ specified\n");
794 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
796 dev_err(&pdev->dev, "no MEM specified\n");
801 size = (res->end - res->start) + 1;
803 /* setup the register offsets from either the platform data
804 * or by using the size of the resource provided */
806 if (ax->plat->reg_offsets)
807 ei_status.reg_offset = ax->plat->reg_offsets;
809 ei_status.reg_offset = ax->reg_offsets;
810 for (ret = 0; ret < 0x18; ret++)
811 ax->reg_offsets[ret] = (size / 0x18) * ret;
814 ax->mem = request_mem_region(res->start, size, pdev->name);
815 if (ax->mem == NULL) {
816 dev_err(&pdev->dev, "cannot reserve registers\n");
821 ei_status.mem = ioremap(res->start, size);
822 dev->base_addr = (unsigned long)ei_status.mem;
824 if (ei_status.mem == NULL) {
825 dev_err(&pdev->dev, "Cannot ioremap area (%08zx,%08zx)\n",
826 res->start, res->end);
832 /* look for reset area */
834 res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
836 if (!ax->plat->reg_offsets) {
837 for (ret = 0; ret < 0x20; ret++)
838 ax->reg_offsets[ret] = (size / 0x20) * ret;
843 size = (res->end - res->start) + 1;
845 ax->mem2 = request_mem_region(res->start, size, pdev->name);
846 if (ax->mem == NULL) {
847 dev_err(&pdev->dev, "cannot reserve registers\n");
852 ax->map2 = ioremap(res->start, size);
853 if (ax->map2 == NULL) {
854 dev_err(&pdev->dev, "cannot map reset register");
859 ei_status.reg_offset[0x1f] = ax->map2 - ei_status.mem;
862 /* got resources, now initialise and register device */
864 ret = ax_init_dev(dev, 1);
868 if (ax->map2 == NULL)
874 release_resource(ax->mem2);
878 iounmap(ei_status.mem);
881 release_resource(ax->mem);
890 /* suspend and resume */
893 static int ax_suspend(struct platform_device *dev, pm_message_t state)
895 struct net_device *ndev = platform_get_drvdata(dev);
896 struct ax_device *ax = to_ax_dev(ndev);
898 ax->resume_open = ax->running;
900 netif_device_detach(ndev);
906 static int ax_resume(struct platform_device *pdev)
908 struct net_device *ndev = platform_get_drvdata(pdev);
909 struct ax_device *ax = to_ax_dev(ndev);
911 ax_initial_setup(ndev, netdev_priv(ndev));
912 ax_NS8390_init(ndev, ax->resume_open);
913 netif_device_attach(ndev);
922 #define ax_suspend NULL
923 #define ax_resume NULL
926 static struct platform_driver axdrv = {
929 .owner = THIS_MODULE,
933 .suspend = ax_suspend,
937 static int __init axdrv_init(void)
939 return platform_driver_register(&axdrv);
942 static void __exit axdrv_exit(void)
944 platform_driver_unregister(&axdrv);
947 module_init(axdrv_init);
948 module_exit(axdrv_exit);
950 MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
951 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
952 MODULE_LICENSE("GPL v2");