1 /* drivers/net/ethernet/8390/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>
21 #include <linux/platform_device.h>
22 #include <linux/delay.h>
23 #include <linux/timer.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/ethtool.h>
27 #include <linux/mdio-bitbang.h>
28 #include <linux/phy.h>
29 #include <linux/eeprom_93cx6.h>
30 #include <linux/slab.h>
32 #include <net/ax88796.h>
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_start_xmit ax_ei_start_xmit
40 #define __ei_tx_timeout ax_ei_tx_timeout
41 #define __ei_get_stats ax_ei_get_stats
42 #define __ei_set_multicast_list ax_ei_set_multicast_list
43 #define __ei_interrupt ax_ei_interrupt
44 #define ____alloc_ei_netdev ax__alloc_ei_netdev
45 #define __NS8390_init ax_NS8390_init
47 /* force unsigned long back to 'void __iomem *' */
48 #define ax_convert_addr(_a) ((void __force __iomem *)(_a))
50 #define ei_inb(_a) readb(ax_convert_addr(_a))
51 #define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a))
53 #define ei_inb_p(_a) ei_inb(_a)
54 #define ei_outb_p(_v, _a) ei_outb(_v, _a)
56 /* define EI_SHIFT() to take into account our register offsets */
57 #define EI_SHIFT(x) (ei_local->reg_offset[(x)])
59 /* Ensure we have our RCR base value */
60 #define AX88796_PLATFORM
62 static unsigned char version[] = "ax88796.c: Copyright 2005,2007 Simtec Electronics\n";
66 #define DRV_NAME "ax88796"
67 #define DRV_VERSION "1.00"
70 #define NE_CMD EI_SHIFT(0x00)
71 #define NE_RESET EI_SHIFT(0x1f)
72 #define NE_DATAPORT EI_SHIFT(0x10)
74 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
75 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
76 #define NESM_START_PG 0x40 /* First page of TX buffer */
77 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
79 #define AX_GPOC_PPDSET BIT(6)
81 /* device private data */
84 struct mii_bus *mii_bus;
85 struct mdiobb_ctrl bb_ctrl;
86 struct phy_device *phy_dev;
87 void __iomem *addr_memr;
94 const struct ax_plat_data *plat;
96 unsigned char running;
97 unsigned char resume_open;
98 unsigned int irqflags;
100 u32 reg_offsets[0x20];
103 static inline struct ax_device *to_ax_dev(struct net_device *dev)
105 struct ei_device *ei_local = netdev_priv(dev);
106 return (struct ax_device *)(ei_local + 1);
112 * do an initial probe for the card to check whether it exists
115 static int ax_initial_check(struct net_device *dev)
117 struct ei_device *ei_local = netdev_priv(dev);
118 void __iomem *ioaddr = ei_local->mem;
122 reg0 = ei_inb(ioaddr);
126 ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, ioaddr + E8390_CMD);
127 regd = ei_inb(ioaddr + 0x0d);
128 ei_outb(0xff, ioaddr + 0x0d);
129 ei_outb(E8390_NODMA + E8390_PAGE0, ioaddr + E8390_CMD);
130 ei_inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */
131 if (ei_inb(ioaddr + EN0_COUNTER0) != 0) {
132 ei_outb(reg0, ioaddr);
133 ei_outb(regd, ioaddr + 0x0d); /* Restore the old values. */
141 * Hard reset the card. This used to pause for the same period that a
142 * 8390 reset command required, but that shouldn't be necessary.
144 static void ax_reset_8390(struct net_device *dev)
146 struct ei_device *ei_local = netdev_priv(dev);
147 unsigned long reset_start_time = jiffies;
148 void __iomem *addr = (void __iomem *)dev->base_addr;
151 netdev_dbg(dev, "resetting the 8390 t=%ld\n", jiffies);
153 ei_outb(ei_inb(addr + NE_RESET), addr + NE_RESET);
156 ei_local->dmaing = 0;
158 /* This check _should_not_ be necessary, omit eventually. */
159 while ((ei_inb(addr + EN0_ISR) & ENISR_RESET) == 0) {
160 if (jiffies - reset_start_time > 2 * HZ / 100) {
161 netdev_warn(dev, "%s: did not complete.\n", __func__);
166 ei_outb(ENISR_RESET, addr + EN0_ISR); /* Ack intr. */
170 static void ax_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
173 struct ei_device *ei_local = netdev_priv(dev);
174 void __iomem *nic_base = ei_local->mem;
176 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
177 if (ei_local->dmaing) {
178 netdev_err(dev, "DMAing conflict in %s "
179 "[DMAstat:%d][irqlock:%d].\n",
181 ei_local->dmaing, ei_local->irqlock);
185 ei_local->dmaing |= 0x01;
186 ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
187 ei_outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO);
188 ei_outb(0, nic_base + EN0_RCNTHI);
189 ei_outb(0, nic_base + EN0_RSARLO); /* On page boundary */
190 ei_outb(ring_page, nic_base + EN0_RSARHI);
191 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
193 if (ei_local->word16)
194 ioread16_rep(nic_base + NE_DATAPORT, hdr,
195 sizeof(struct e8390_pkt_hdr) >> 1);
197 ioread8_rep(nic_base + NE_DATAPORT, hdr,
198 sizeof(struct e8390_pkt_hdr));
200 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
201 ei_local->dmaing &= ~0x01;
203 le16_to_cpus(&hdr->count);
208 * Block input and output, similar to the Crynwr packet driver. If
209 * you are porting to a new ethercard, look at the packet driver
210 * source for hints. The NEx000 doesn't share the on-board packet
211 * memory -- you have to put the packet out through the "remote DMA"
212 * dataport using ei_outb.
214 static void ax_block_input(struct net_device *dev, int count,
215 struct sk_buff *skb, int ring_offset)
217 struct ei_device *ei_local = netdev_priv(dev);
218 void __iomem *nic_base = ei_local->mem;
219 char *buf = skb->data;
221 if (ei_local->dmaing) {
223 "DMAing conflict in %s "
224 "[DMAstat:%d][irqlock:%d].\n",
226 ei_local->dmaing, ei_local->irqlock);
230 ei_local->dmaing |= 0x01;
232 ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + NE_CMD);
233 ei_outb(count & 0xff, nic_base + EN0_RCNTLO);
234 ei_outb(count >> 8, nic_base + EN0_RCNTHI);
235 ei_outb(ring_offset & 0xff, nic_base + EN0_RSARLO);
236 ei_outb(ring_offset >> 8, nic_base + EN0_RSARHI);
237 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);
239 if (ei_local->word16) {
240 ioread16_rep(nic_base + NE_DATAPORT, buf, count >> 1);
242 buf[count-1] = ei_inb(nic_base + NE_DATAPORT);
245 ioread8_rep(nic_base + NE_DATAPORT, buf, count);
248 ei_local->dmaing &= ~1;
251 static void ax_block_output(struct net_device *dev, int count,
252 const unsigned char *buf, const int start_page)
254 struct ei_device *ei_local = netdev_priv(dev);
255 void __iomem *nic_base = ei_local->mem;
256 unsigned long dma_start;
259 * Round the count up for word writes. Do we need to do this?
260 * What effect will an odd byte count have on the 8390? I
261 * should check someday.
263 if (ei_local->word16 && (count & 0x01))
266 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
267 if (ei_local->dmaing) {
268 netdev_err(dev, "DMAing conflict in %s."
269 "[DMAstat:%d][irqlock:%d]\n",
271 ei_local->dmaing, ei_local->irqlock);
275 ei_local->dmaing |= 0x01;
276 /* We should already be in page 0, but to be safe... */
277 ei_outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);
279 ei_outb(ENISR_RDC, nic_base + EN0_ISR);
281 /* Now the normal output. */
282 ei_outb(count & 0xff, nic_base + EN0_RCNTLO);
283 ei_outb(count >> 8, nic_base + EN0_RCNTHI);
284 ei_outb(0x00, nic_base + EN0_RSARLO);
285 ei_outb(start_page, nic_base + EN0_RSARHI);
287 ei_outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD);
288 if (ei_local->word16)
289 iowrite16_rep(nic_base + NE_DATAPORT, buf, count >> 1);
291 iowrite8_rep(nic_base + NE_DATAPORT, buf, count);
295 while ((ei_inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) {
296 if (jiffies - dma_start > 2 * HZ / 100) { /* 20ms */
297 netdev_warn(dev, "timeout waiting for Tx RDC.\n");
299 ax_NS8390_init(dev, 1);
304 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
305 ei_local->dmaing &= ~0x01;
308 /* definitions for accessing MII/EEPROM interface */
310 #define AX_MEMR EI_SHIFT(0x14)
311 #define AX_MEMR_MDC BIT(0)
312 #define AX_MEMR_MDIR BIT(1)
313 #define AX_MEMR_MDI BIT(2)
314 #define AX_MEMR_MDO BIT(3)
315 #define AX_MEMR_EECS BIT(4)
316 #define AX_MEMR_EEI BIT(5)
317 #define AX_MEMR_EEO BIT(6)
318 #define AX_MEMR_EECLK BIT(7)
320 static void ax_handle_link_change(struct net_device *dev)
322 struct ax_device *ax = to_ax_dev(dev);
323 struct phy_device *phy_dev = ax->phy_dev;
324 int status_change = 0;
326 if (phy_dev->link && ((ax->speed != phy_dev->speed) ||
327 (ax->duplex != phy_dev->duplex))) {
329 ax->speed = phy_dev->speed;
330 ax->duplex = phy_dev->duplex;
334 if (phy_dev->link != ax->link) {
335 if (!phy_dev->link) {
339 ax->link = phy_dev->link;
345 phy_print_status(phy_dev);
348 static int ax_mii_probe(struct net_device *dev)
350 struct ax_device *ax = to_ax_dev(dev);
351 struct phy_device *phy_dev = NULL;
354 /* find the first phy */
355 phy_dev = phy_find_first(ax->mii_bus);
357 netdev_err(dev, "no PHY found\n");
361 ret = phy_connect_direct(dev, phy_dev, ax_handle_link_change,
362 PHY_INTERFACE_MODE_MII);
364 netdev_err(dev, "Could not attach to PHY\n");
368 /* mask with MAC supported features */
369 phy_dev->supported &= PHY_BASIC_FEATURES;
370 phy_dev->advertising = phy_dev->supported;
372 ax->phy_dev = phy_dev;
374 netdev_info(dev, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
375 phy_dev->drv->name, dev_name(&phy_dev->dev), phy_dev->irq);
380 static void ax_phy_switch(struct net_device *dev, int on)
382 struct ei_device *ei_local = netdev_priv(dev);
383 struct ax_device *ax = to_ax_dev(dev);
385 u8 reg_gpoc = ax->plat->gpoc_val;
388 reg_gpoc &= ~AX_GPOC_PPDSET;
390 reg_gpoc |= AX_GPOC_PPDSET;
392 ei_outb(reg_gpoc, ei_local->mem + EI_SHIFT(0x17));
395 static int ax_open(struct net_device *dev)
397 struct ax_device *ax = to_ax_dev(dev);
400 netdev_dbg(dev, "open\n");
402 ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags,
405 goto failed_request_irq;
407 /* turn the phy on (if turned off) */
408 ax_phy_switch(dev, 1);
410 ret = ax_mii_probe(dev);
412 goto failed_mii_probe;
413 phy_start(ax->phy_dev);
415 ret = ax_ei_open(dev);
417 goto failed_ax_ei_open;
424 phy_disconnect(ax->phy_dev);
426 ax_phy_switch(dev, 0);
427 free_irq(dev->irq, dev);
432 static int ax_close(struct net_device *dev)
434 struct ax_device *ax = to_ax_dev(dev);
436 netdev_dbg(dev, "close\n");
443 /* turn the phy off */
444 ax_phy_switch(dev, 0);
445 phy_disconnect(ax->phy_dev);
447 free_irq(dev->irq, dev);
451 static int ax_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
453 struct ax_device *ax = to_ax_dev(dev);
454 struct phy_device *phy_dev = ax->phy_dev;
456 if (!netif_running(dev))
462 return phy_mii_ioctl(phy_dev, req, cmd);
467 static void ax_get_drvinfo(struct net_device *dev,
468 struct ethtool_drvinfo *info)
470 struct platform_device *pdev = to_platform_device(dev->dev.parent);
472 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
473 strlcpy(info->version, DRV_VERSION, sizeof(info->version));
474 strlcpy(info->bus_info, pdev->name, sizeof(info->bus_info));
477 static int ax_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
479 struct ax_device *ax = to_ax_dev(dev);
480 struct phy_device *phy_dev = ax->phy_dev;
485 return phy_ethtool_gset(phy_dev, cmd);
488 static int ax_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
490 struct ax_device *ax = to_ax_dev(dev);
491 struct phy_device *phy_dev = ax->phy_dev;
496 return phy_ethtool_sset(phy_dev, cmd);
499 static const struct ethtool_ops ax_ethtool_ops = {
500 .get_drvinfo = ax_get_drvinfo,
501 .get_settings = ax_get_settings,
502 .set_settings = ax_set_settings,
503 .get_link = ethtool_op_get_link,
504 .get_ts_info = ethtool_op_get_ts_info,
507 #ifdef CONFIG_AX88796_93CX6
508 static void ax_eeprom_register_read(struct eeprom_93cx6 *eeprom)
510 struct ei_device *ei_local = eeprom->data;
511 u8 reg = ei_inb(ei_local->mem + AX_MEMR);
513 eeprom->reg_data_in = reg & AX_MEMR_EEI;
514 eeprom->reg_data_out = reg & AX_MEMR_EEO; /* Input pin */
515 eeprom->reg_data_clock = reg & AX_MEMR_EECLK;
516 eeprom->reg_chip_select = reg & AX_MEMR_EECS;
519 static void ax_eeprom_register_write(struct eeprom_93cx6 *eeprom)
521 struct ei_device *ei_local = eeprom->data;
522 u8 reg = ei_inb(ei_local->mem + AX_MEMR);
524 reg &= ~(AX_MEMR_EEI | AX_MEMR_EECLK | AX_MEMR_EECS);
526 if (eeprom->reg_data_in)
528 if (eeprom->reg_data_clock)
529 reg |= AX_MEMR_EECLK;
530 if (eeprom->reg_chip_select)
533 ei_outb(reg, ei_local->mem + AX_MEMR);
538 static const struct net_device_ops ax_netdev_ops = {
540 .ndo_stop = ax_close,
541 .ndo_do_ioctl = ax_ioctl,
543 .ndo_start_xmit = ax_ei_start_xmit,
544 .ndo_tx_timeout = ax_ei_tx_timeout,
545 .ndo_get_stats = ax_ei_get_stats,
546 .ndo_set_rx_mode = ax_ei_set_multicast_list,
547 .ndo_validate_addr = eth_validate_addr,
548 .ndo_set_mac_address = eth_mac_addr,
549 .ndo_change_mtu = eth_change_mtu,
550 #ifdef CONFIG_NET_POLL_CONTROLLER
551 .ndo_poll_controller = ax_ei_poll,
555 static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level)
557 struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
560 ax->reg_memr |= AX_MEMR_MDC;
562 ax->reg_memr &= ~AX_MEMR_MDC;
564 ei_outb(ax->reg_memr, ax->addr_memr);
567 static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output)
569 struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
572 ax->reg_memr &= ~AX_MEMR_MDIR;
574 ax->reg_memr |= AX_MEMR_MDIR;
576 ei_outb(ax->reg_memr, ax->addr_memr);
579 static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value)
581 struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
584 ax->reg_memr |= AX_MEMR_MDO;
586 ax->reg_memr &= ~AX_MEMR_MDO;
588 ei_outb(ax->reg_memr, ax->addr_memr);
591 static int ax_bb_get_data(struct mdiobb_ctrl *ctrl)
593 struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
594 int reg_memr = ei_inb(ax->addr_memr);
596 return reg_memr & AX_MEMR_MDI ? 1 : 0;
599 static struct mdiobb_ops bb_ops = {
600 .owner = THIS_MODULE,
601 .set_mdc = ax_bb_mdc,
602 .set_mdio_dir = ax_bb_dir,
603 .set_mdio_data = ax_bb_set_data,
604 .get_mdio_data = ax_bb_get_data,
609 static int ax_mii_init(struct net_device *dev)
611 struct platform_device *pdev = to_platform_device(dev->dev.parent);
612 struct ei_device *ei_local = netdev_priv(dev);
613 struct ax_device *ax = to_ax_dev(dev);
616 ax->bb_ctrl.ops = &bb_ops;
617 ax->addr_memr = ei_local->mem + AX_MEMR;
618 ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl);
624 ax->mii_bus->name = "ax88796_mii_bus";
625 ax->mii_bus->parent = dev->dev.parent;
626 snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
627 pdev->name, pdev->id);
629 ax->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
630 if (!ax->mii_bus->irq) {
632 goto out_free_mdio_bitbang;
635 for (i = 0; i < PHY_MAX_ADDR; i++)
636 ax->mii_bus->irq[i] = PHY_POLL;
638 err = mdiobus_register(ax->mii_bus);
645 kfree(ax->mii_bus->irq);
646 out_free_mdio_bitbang:
647 free_mdio_bitbang(ax->mii_bus);
652 static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local)
654 void __iomem *ioaddr = ei_local->mem;
655 struct ax_device *ax = to_ax_dev(dev);
658 ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_STOP, ioaddr + E8390_CMD);
660 /* set to byte access */
661 ei_outb(ax->plat->dcr_val & ~1, ioaddr + EN0_DCFG);
662 ei_outb(ax->plat->gpoc_val, ioaddr + EI_SHIFT(0x17));
668 * initialise the specified device, taking care to note the MAC
669 * address it may already have (if configured), ensure
670 * the device is ready to be used by lib8390.c and registerd with
673 static int ax_init_dev(struct net_device *dev)
675 struct ei_device *ei_local = netdev_priv(dev);
676 struct ax_device *ax = to_ax_dev(dev);
677 void __iomem *ioaddr = ei_local->mem;
678 unsigned int start_page;
679 unsigned int stop_page;
683 ret = ax_initial_check(dev);
687 /* setup goes here */
689 ax_initial_setup(dev, ei_local);
691 /* read the mac from the card prom if we need it */
693 if (ax->plat->flags & AXFLG_HAS_EEPROM) {
694 unsigned char SA_prom[32];
696 for (i = 0; i < sizeof(SA_prom); i += 2) {
697 SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT);
698 SA_prom[i + 1] = ei_inb(ioaddr + NE_DATAPORT);
701 if (ax->plat->wordlength == 2)
702 for (i = 0; i < 16; i++)
703 SA_prom[i] = SA_prom[i+i];
705 memcpy(dev->dev_addr, SA_prom, 6);
708 #ifdef CONFIG_AX88796_93CX6
709 if (ax->plat->flags & AXFLG_HAS_93CX6) {
710 unsigned char mac_addr[6];
711 struct eeprom_93cx6 eeprom;
713 eeprom.data = ei_local;
714 eeprom.register_read = ax_eeprom_register_read;
715 eeprom.register_write = ax_eeprom_register_write;
716 eeprom.width = PCI_EEPROM_WIDTH_93C56;
718 eeprom_93cx6_multiread(&eeprom, 0,
719 (__le16 __force *)mac_addr,
720 sizeof(mac_addr) >> 1);
722 memcpy(dev->dev_addr, mac_addr, 6);
725 if (ax->plat->wordlength == 2) {
726 /* We must set the 8390 for word mode. */
727 ei_outb(ax->plat->dcr_val, ei_local->mem + EN0_DCFG);
728 start_page = NESM_START_PG;
729 stop_page = NESM_STOP_PG;
731 start_page = NE1SM_START_PG;
732 stop_page = NE1SM_STOP_PG;
735 /* load the mac-address from the device */
736 if (ax->plat->flags & AXFLG_MAC_FROMDEV) {
737 ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP,
738 ei_local->mem + E8390_CMD); /* 0x61 */
739 for (i = 0; i < ETH_ALEN; i++)
741 ei_inb(ioaddr + EN1_PHYS_SHIFT(i));
744 if ((ax->plat->flags & AXFLG_MAC_FROMPLATFORM) &&
746 memcpy(dev->dev_addr, ax->plat->mac_addr, ETH_ALEN);
750 ei_local->name = "AX88796";
751 ei_local->tx_start_page = start_page;
752 ei_local->stop_page = stop_page;
753 ei_local->word16 = (ax->plat->wordlength == 2);
754 ei_local->rx_start_page = start_page + TX_PAGES;
756 #ifdef PACKETBUF_MEMSIZE
757 /* Allow the packet buffer size to be overridden by know-it-alls. */
758 ei_local->stop_page = ei_local->tx_start_page + PACKETBUF_MEMSIZE;
761 ei_local->reset_8390 = &ax_reset_8390;
762 ei_local->block_input = &ax_block_input;
763 ei_local->block_output = &ax_block_output;
764 ei_local->get_8390_hdr = &ax_get_8390_hdr;
767 dev->netdev_ops = &ax_netdev_ops;
768 dev->ethtool_ops = &ax_ethtool_ops;
770 ret = ax_mii_init(dev);
774 ax_NS8390_init(dev, 0);
776 ret = register_netdev(dev);
780 netdev_info(dev, "%dbit, irq %d, %lx, MAC: %pM\n",
781 ei_local->word16 ? 16 : 8, dev->irq, dev->base_addr,
788 free_irq(dev->irq, dev);
793 static int ax_remove(struct platform_device *pdev)
795 struct net_device *dev = platform_get_drvdata(pdev);
796 struct ei_device *ei_local = netdev_priv(dev);
797 struct ax_device *ax = to_ax_dev(dev);
798 struct resource *mem;
800 unregister_netdev(dev);
801 free_irq(dev->irq, dev);
803 iounmap(ei_local->mem);
804 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
805 release_mem_region(mem->start, resource_size(mem));
809 mem = platform_get_resource(pdev, IORESOURCE_MEM, 1);
810 release_mem_region(mem->start, resource_size(mem));
821 * This is the entry point when the platform device system uses to
822 * notify us of a new device to attach to. Allocate memory, find the
823 * resources and information passed, and map the necessary registers.
825 static int ax_probe(struct platform_device *pdev)
827 struct net_device *dev;
828 struct ei_device *ei_local;
829 struct ax_device *ax;
830 struct resource *irq, *mem, *mem2;
831 unsigned long mem_size, mem2_size = 0;
834 dev = ax__alloc_ei_netdev(sizeof(struct ax_device));
838 /* ok, let's setup our device */
839 SET_NETDEV_DEV(dev, &pdev->dev);
840 ei_local = netdev_priv(dev);
843 ax->plat = pdev->dev.platform_data;
844 platform_set_drvdata(pdev, dev);
846 ei_local->rxcr_base = ax->plat->rcr_val;
848 /* find the platform resources */
849 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
851 dev_err(&pdev->dev, "no IRQ specified\n");
856 dev->irq = irq->start;
857 ax->irqflags = irq->flags & IRQF_TRIGGER_MASK;
859 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
861 dev_err(&pdev->dev, "no MEM specified\n");
866 mem_size = resource_size(mem);
869 * setup the register offsets from either the platform data or
870 * by using the size of the resource provided
872 if (ax->plat->reg_offsets)
873 ei_local->reg_offset = ax->plat->reg_offsets;
875 ei_local->reg_offset = ax->reg_offsets;
876 for (ret = 0; ret < 0x18; ret++)
877 ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
880 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
881 dev_err(&pdev->dev, "cannot reserve registers\n");
886 ei_local->mem = ioremap(mem->start, mem_size);
887 dev->base_addr = (unsigned long)ei_local->mem;
889 if (ei_local->mem == NULL) {
890 dev_err(&pdev->dev, "Cannot ioremap area %pR\n", mem);
896 /* look for reset area */
897 mem2 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
899 if (!ax->plat->reg_offsets) {
900 for (ret = 0; ret < 0x20; ret++)
901 ax->reg_offsets[ret] = (mem_size / 0x20) * ret;
904 mem2_size = resource_size(mem2);
906 if (!request_mem_region(mem2->start, mem2_size, pdev->name)) {
907 dev_err(&pdev->dev, "cannot reserve registers\n");
912 ax->map2 = ioremap(mem2->start, mem2_size);
914 dev_err(&pdev->dev, "cannot map reset register\n");
919 ei_local->reg_offset[0x1f] = ax->map2 - ei_local->mem;
922 /* got resources, now initialise and register device */
923 ret = ax_init_dev(dev);
933 release_mem_region(mem2->start, mem2_size);
936 iounmap(ei_local->mem);
939 release_mem_region(mem->start, mem_size);
947 /* suspend and resume */
950 static int ax_suspend(struct platform_device *dev, pm_message_t state)
952 struct net_device *ndev = platform_get_drvdata(dev);
953 struct ax_device *ax = to_ax_dev(ndev);
955 ax->resume_open = ax->running;
957 netif_device_detach(ndev);
963 static int ax_resume(struct platform_device *pdev)
965 struct net_device *ndev = platform_get_drvdata(pdev);
966 struct ax_device *ax = to_ax_dev(ndev);
968 ax_initial_setup(ndev, netdev_priv(ndev));
969 ax_NS8390_init(ndev, ax->resume_open);
970 netif_device_attach(ndev);
979 #define ax_suspend NULL
980 #define ax_resume NULL
983 static struct platform_driver axdrv = {
986 .owner = THIS_MODULE,
990 .suspend = ax_suspend,
994 module_platform_driver(axdrv);
996 MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
997 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
998 MODULE_LICENSE("GPL v2");
999 MODULE_ALIAS("platform:ax88796");