Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 1 | /* drivers/net/ax88796.c |
| 2 | * |
| 3 | * Copyright 2005,2007 Simtec Electronics |
| 4 | * Ben Dooks <ben@simtec.co.uk> |
| 5 | * |
| 6 | * Asix AX88796 10/100 Ethernet controller support |
| 7 | * Based on ne.c, by Donald Becker, et-al. |
| 8 | * |
| 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. |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 12 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 13 | |
| 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> |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 20 | #include <linux/io.h> |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 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/mii.h> |
Magnus Damm | 89e536a | 2007-09-28 22:42:16 -0700 | [diff] [blame] | 28 | #include <linux/eeprom_93cx6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 30 | |
| 31 | #include <net/ax88796.h> |
| 32 | |
| 33 | #include <asm/system.h> |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 34 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 35 | static int phy_debug; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 36 | |
| 37 | /* Rename the lib8390.c functions to show that they are in this driver */ |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 38 | #define __ei_open ax_ei_open |
| 39 | #define __ei_close ax_ei_close |
| 40 | #define __ei_poll ax_ei_poll |
Magnus Damm | d57bc36 | 2009-01-14 21:05:55 -0800 | [diff] [blame] | 41 | #define __ei_start_xmit ax_ei_start_xmit |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 42 | #define __ei_tx_timeout ax_ei_tx_timeout |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 43 | #define __ei_get_stats ax_ei_get_stats |
Magnus Damm | d57bc36 | 2009-01-14 21:05:55 -0800 | [diff] [blame] | 44 | #define __ei_set_multicast_list ax_ei_set_multicast_list |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 45 | #define __ei_interrupt ax_ei_interrupt |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 46 | #define ____alloc_ei_netdev ax__alloc_ei_netdev |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 47 | #define __NS8390_init ax_NS8390_init |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 48 | |
| 49 | /* force unsigned long back to 'void __iomem *' */ |
| 50 | #define ax_convert_addr(_a) ((void __force __iomem *)(_a)) |
| 51 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 52 | #define ei_inb(_a) readb(ax_convert_addr(_a)) |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 53 | #define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a)) |
| 54 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 55 | #define ei_inb_p(_a) ei_inb(_a) |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 56 | #define ei_outb_p(_v, _a) ei_outb(_v, _a) |
| 57 | |
| 58 | /* define EI_SHIFT() to take into account our register offsets */ |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 59 | #define EI_SHIFT(x) (ei_local->reg_offset[(x)]) |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 60 | |
| 61 | /* Ensure we have our RCR base value */ |
| 62 | #define AX88796_PLATFORM |
| 63 | |
| 64 | static unsigned char version[] = "ax88796.c: Copyright 2005,2007 Simtec Electronics\n"; |
| 65 | |
| 66 | #include "lib8390.c" |
| 67 | |
| 68 | #define DRV_NAME "ax88796" |
| 69 | #define DRV_VERSION "1.00" |
| 70 | |
| 71 | /* from ne.c */ |
| 72 | #define NE_CMD EI_SHIFT(0x00) |
| 73 | #define NE_RESET EI_SHIFT(0x1f) |
| 74 | #define NE_DATAPORT EI_SHIFT(0x10) |
| 75 | |
| 76 | #define NE1SM_START_PG 0x20 /* First page of TX buffer */ |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 77 | #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 78 | #define NESM_START_PG 0x40 /* First page of TX buffer */ |
| 79 | #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ |
| 80 | |
| 81 | /* device private data */ |
| 82 | |
| 83 | struct ax_device { |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 84 | struct timer_list mii_timer; |
| 85 | spinlock_t mii_lock; |
| 86 | struct mii_if_info mii; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 87 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 88 | u32 msg_enable; |
| 89 | void __iomem *map2; |
| 90 | struct platform_device *dev; |
| 91 | struct resource *mem; |
| 92 | struct resource *mem2; |
| 93 | struct ax_plat_data *plat; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 94 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 95 | unsigned char running; |
| 96 | unsigned char resume_open; |
| 97 | unsigned int irqflags; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 98 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 99 | u32 reg_offsets[0x20]; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | static inline struct ax_device *to_ax_dev(struct net_device *dev) |
| 103 | { |
| 104 | struct ei_device *ei_local = netdev_priv(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 105 | return (struct ax_device *)(ei_local + 1); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 108 | /* |
| 109 | * ax_initial_check |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 110 | * |
| 111 | * do an initial probe for the card to check wether it exists |
| 112 | * and is functional |
| 113 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 114 | static int ax_initial_check(struct net_device *dev) |
| 115 | { |
| 116 | struct ei_device *ei_local = netdev_priv(dev); |
| 117 | void __iomem *ioaddr = ei_local->mem; |
| 118 | int reg0; |
| 119 | int regd; |
| 120 | |
| 121 | reg0 = ei_inb(ioaddr); |
| 122 | if (reg0 == 0xFF) |
| 123 | return -ENODEV; |
| 124 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 125 | ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, ioaddr + E8390_CMD); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 126 | regd = ei_inb(ioaddr + 0x0d); |
| 127 | ei_outb(0xff, ioaddr + 0x0d); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 128 | ei_outb(E8390_NODMA + E8390_PAGE0, ioaddr + E8390_CMD); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 129 | ei_inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */ |
| 130 | if (ei_inb(ioaddr + EN0_COUNTER0) != 0) { |
| 131 | ei_outb(reg0, ioaddr); |
| 132 | ei_outb(regd, ioaddr + 0x0d); /* Restore the old values. */ |
| 133 | return -ENODEV; |
| 134 | } |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 139 | /* |
| 140 | * Hard reset the card. This used to pause for the same period that a |
| 141 | * 8390 reset command required, but that shouldn't be necessary. |
| 142 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 143 | static void ax_reset_8390(struct net_device *dev) |
| 144 | { |
| 145 | struct ei_device *ei_local = netdev_priv(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 146 | struct ax_device *ax = to_ax_dev(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 147 | unsigned long reset_start_time = jiffies; |
| 148 | void __iomem *addr = (void __iomem *)dev->base_addr; |
| 149 | |
| 150 | if (ei_debug > 1) |
Ben Dooks | 237c5e8 | 2008-01-31 11:25:31 +0000 | [diff] [blame] | 151 | dev_dbg(&ax->dev->dev, "resetting the 8390 t=%ld\n", jiffies); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 152 | |
| 153 | ei_outb(ei_inb(addr + NE_RESET), addr + NE_RESET); |
| 154 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 155 | ei_local->txing = 0; |
| 156 | ei_local->dmaing = 0; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 157 | |
| 158 | /* This check _should_not_ be necessary, omit eventually. */ |
| 159 | while ((ei_inb(addr + EN0_ISR) & ENISR_RESET) == 0) { |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 160 | if (jiffies - reset_start_time > 2 * HZ / 100) { |
Ben Dooks | 237c5e8 | 2008-01-31 11:25:31 +0000 | [diff] [blame] | 161 | dev_warn(&ax->dev->dev, "%s: %s did not complete.\n", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 162 | __func__, dev->name); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 163 | break; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | ei_outb(ENISR_RESET, addr + EN0_ISR); /* Ack intr. */ |
| 168 | } |
| 169 | |
| 170 | |
| 171 | static void ax_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, |
| 172 | int ring_page) |
| 173 | { |
| 174 | struct ei_device *ei_local = netdev_priv(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 175 | struct ax_device *ax = to_ax_dev(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 176 | void __iomem *nic_base = ei_local->mem; |
| 177 | |
| 178 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 179 | if (ei_local->dmaing) { |
Ben Dooks | 237c5e8 | 2008-01-31 11:25:31 +0000 | [diff] [blame] | 180 | dev_err(&ax->dev->dev, "%s: DMAing conflict in %s " |
| 181 | "[DMAstat:%d][irqlock:%d].\n", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 182 | dev->name, __func__, |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 183 | ei_local->dmaing, ei_local->irqlock); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 184 | return; |
| 185 | } |
| 186 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 187 | ei_local->dmaing |= 0x01; |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 188 | ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 189 | ei_outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO); |
| 190 | ei_outb(0, nic_base + EN0_RCNTHI); |
| 191 | ei_outb(0, nic_base + EN0_RSARLO); /* On page boundary */ |
| 192 | ei_outb(ring_page, nic_base + EN0_RSARHI); |
| 193 | ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); |
| 194 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 195 | if (ei_local->word16) |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 196 | readsw(nic_base + NE_DATAPORT, hdr, |
| 197 | sizeof(struct e8390_pkt_hdr) >> 1); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 198 | else |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 199 | readsb(nic_base + NE_DATAPORT, hdr, |
| 200 | sizeof(struct e8390_pkt_hdr)); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 201 | |
| 202 | ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 203 | ei_local->dmaing &= ~0x01; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 204 | |
| 205 | le16_to_cpus(&hdr->count); |
| 206 | } |
| 207 | |
| 208 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 209 | /* |
| 210 | * Block input and output, similar to the Crynwr packet driver. If |
| 211 | * you are porting to a new ethercard, look at the packet driver |
| 212 | * source for hints. The NEx000 doesn't share the on-board packet |
| 213 | * memory -- you have to put the packet out through the "remote DMA" |
| 214 | * dataport using ei_outb. |
| 215 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 216 | static void ax_block_input(struct net_device *dev, int count, |
| 217 | struct sk_buff *skb, int ring_offset) |
| 218 | { |
| 219 | struct ei_device *ei_local = netdev_priv(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 220 | struct ax_device *ax = to_ax_dev(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 221 | void __iomem *nic_base = ei_local->mem; |
| 222 | char *buf = skb->data; |
| 223 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 224 | if (ei_local->dmaing) { |
Ben Dooks | 237c5e8 | 2008-01-31 11:25:31 +0000 | [diff] [blame] | 225 | dev_err(&ax->dev->dev, |
| 226 | "%s: DMAing conflict in %s " |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 227 | "[DMAstat:%d][irqlock:%d].\n", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 228 | dev->name, __func__, |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 229 | ei_local->dmaing, ei_local->irqlock); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 230 | return; |
| 231 | } |
| 232 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 233 | ei_local->dmaing |= 0x01; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 234 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 235 | ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + NE_CMD); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 236 | ei_outb(count & 0xff, nic_base + EN0_RCNTLO); |
| 237 | ei_outb(count >> 8, nic_base + EN0_RCNTHI); |
| 238 | ei_outb(ring_offset & 0xff, nic_base + EN0_RSARLO); |
| 239 | ei_outb(ring_offset >> 8, nic_base + EN0_RSARHI); |
| 240 | ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); |
| 241 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 242 | if (ei_local->word16) { |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 243 | readsw(nic_base + NE_DATAPORT, buf, count >> 1); |
| 244 | if (count & 0x01) |
| 245 | buf[count-1] = ei_inb(nic_base + NE_DATAPORT); |
| 246 | |
| 247 | } else { |
| 248 | readsb(nic_base + NE_DATAPORT, buf, count); |
| 249 | } |
| 250 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 251 | ei_local->dmaing &= ~1; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | static void ax_block_output(struct net_device *dev, int count, |
| 255 | const unsigned char *buf, const int start_page) |
| 256 | { |
| 257 | struct ei_device *ei_local = netdev_priv(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 258 | struct ax_device *ax = to_ax_dev(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 259 | void __iomem *nic_base = ei_local->mem; |
| 260 | unsigned long dma_start; |
| 261 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 262 | /* |
| 263 | * Round the count up for word writes. Do we need to do this? |
| 264 | * What effect will an odd byte count have on the 8390? I |
| 265 | * should check someday. |
| 266 | */ |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 267 | if (ei_local->word16 && (count & 0x01)) |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 268 | count++; |
| 269 | |
| 270 | /* This *shouldn't* happen. If it does, it's the last thing you'll see */ |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 271 | if (ei_local->dmaing) { |
Ben Dooks | 237c5e8 | 2008-01-31 11:25:31 +0000 | [diff] [blame] | 272 | dev_err(&ax->dev->dev, "%s: DMAing conflict in %s." |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 273 | "[DMAstat:%d][irqlock:%d]\n", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 274 | dev->name, __func__, |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 275 | ei_local->dmaing, ei_local->irqlock); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 276 | return; |
| 277 | } |
| 278 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 279 | ei_local->dmaing |= 0x01; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 280 | /* We should already be in page 0, but to be safe... */ |
| 281 | ei_outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); |
| 282 | |
| 283 | ei_outb(ENISR_RDC, nic_base + EN0_ISR); |
| 284 | |
| 285 | /* Now the normal output. */ |
| 286 | ei_outb(count & 0xff, nic_base + EN0_RCNTLO); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 287 | ei_outb(count >> 8, nic_base + EN0_RCNTHI); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 288 | ei_outb(0x00, nic_base + EN0_RSARLO); |
| 289 | ei_outb(start_page, nic_base + EN0_RSARHI); |
| 290 | |
| 291 | ei_outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD); |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 292 | if (ei_local->word16) |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 293 | writesw(nic_base + NE_DATAPORT, buf, count >> 1); |
| 294 | else |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 295 | writesb(nic_base + NE_DATAPORT, buf, count); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 296 | |
| 297 | dma_start = jiffies; |
| 298 | |
| 299 | while ((ei_inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) { |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 300 | if (jiffies - dma_start > 2 * HZ / 100) { /* 20ms */ |
Ben Dooks | 237c5e8 | 2008-01-31 11:25:31 +0000 | [diff] [blame] | 301 | dev_warn(&ax->dev->dev, |
| 302 | "%s: timeout waiting for Tx RDC.\n", dev->name); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 303 | ax_reset_8390(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 304 | ax_NS8390_init(dev, 1); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 305 | break; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 310 | ei_local->dmaing &= ~0x01; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /* definitions for accessing MII/EEPROM interface */ |
| 314 | |
| 315 | #define AX_MEMR EI_SHIFT(0x14) |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 316 | #define AX_MEMR_MDC BIT(0) |
| 317 | #define AX_MEMR_MDIR BIT(1) |
| 318 | #define AX_MEMR_MDI BIT(2) |
| 319 | #define AX_MEMR_MDO BIT(3) |
| 320 | #define AX_MEMR_EECS BIT(4) |
| 321 | #define AX_MEMR_EEI BIT(5) |
| 322 | #define AX_MEMR_EEO BIT(6) |
| 323 | #define AX_MEMR_EECLK BIT(7) |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 324 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 325 | /* |
| 326 | * ax_mii_ei_outbits |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 327 | * |
| 328 | * write the specified set of bits to the phy |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 329 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 330 | static void |
| 331 | ax_mii_ei_outbits(struct net_device *dev, unsigned int bits, int len) |
| 332 | { |
Joe Perches | ece4915 | 2010-11-15 11:12:31 +0000 | [diff] [blame] | 333 | struct ei_device *ei_local = netdev_priv(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 334 | void __iomem *memr_addr = (void __iomem *)dev->base_addr + AX_MEMR; |
| 335 | unsigned int memr; |
| 336 | |
| 337 | /* clock low, data to output mode */ |
| 338 | memr = ei_inb(memr_addr); |
| 339 | memr &= ~(AX_MEMR_MDC | AX_MEMR_MDIR); |
| 340 | ei_outb(memr, memr_addr); |
| 341 | |
| 342 | for (len--; len >= 0; len--) { |
| 343 | if (bits & (1 << len)) |
| 344 | memr |= AX_MEMR_MDO; |
| 345 | else |
| 346 | memr &= ~AX_MEMR_MDO; |
| 347 | |
| 348 | ei_outb(memr, memr_addr); |
| 349 | |
| 350 | /* clock high */ |
| 351 | |
| 352 | ei_outb(memr | AX_MEMR_MDC, memr_addr); |
| 353 | udelay(1); |
| 354 | |
| 355 | /* clock low */ |
| 356 | ei_outb(memr, memr_addr); |
| 357 | } |
| 358 | |
| 359 | /* leaves the clock line low, mdir input */ |
| 360 | memr |= AX_MEMR_MDIR; |
| 361 | ei_outb(memr, (void __iomem *)dev->base_addr + AX_MEMR); |
| 362 | } |
| 363 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 364 | /* |
| 365 | * ax_phy_ei_inbits |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 366 | * |
| 367 | * read a specified number of bits from the phy |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 368 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 369 | static unsigned int |
| 370 | ax_phy_ei_inbits(struct net_device *dev, int no) |
| 371 | { |
Joe Perches | ece4915 | 2010-11-15 11:12:31 +0000 | [diff] [blame] | 372 | struct ei_device *ei_local = netdev_priv(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 373 | void __iomem *memr_addr = (void __iomem *)dev->base_addr + AX_MEMR; |
| 374 | unsigned int memr; |
| 375 | unsigned int result = 0; |
| 376 | |
| 377 | /* clock low, data to input mode */ |
| 378 | memr = ei_inb(memr_addr); |
| 379 | memr &= ~AX_MEMR_MDC; |
| 380 | memr |= AX_MEMR_MDIR; |
| 381 | ei_outb(memr, memr_addr); |
| 382 | |
| 383 | for (no--; no >= 0; no--) { |
| 384 | ei_outb(memr | AX_MEMR_MDC, memr_addr); |
| 385 | |
| 386 | udelay(1); |
| 387 | |
| 388 | if (ei_inb(memr_addr) & AX_MEMR_MDI) |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 389 | result |= (1 << no); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 390 | |
| 391 | ei_outb(memr, memr_addr); |
| 392 | } |
| 393 | |
| 394 | return result; |
| 395 | } |
| 396 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 397 | /* |
| 398 | * ax_phy_issueaddr |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 399 | * |
| 400 | * use the low level bit shifting routines to send the address |
| 401 | * and command to the specified phy |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 402 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 403 | static void |
| 404 | ax_phy_issueaddr(struct net_device *dev, int phy_addr, int reg, int opc) |
| 405 | { |
| 406 | if (phy_debug) |
| 407 | pr_debug("%s: dev %p, %04x, %04x, %d\n", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 408 | __func__, dev, phy_addr, reg, opc); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 409 | |
| 410 | ax_mii_ei_outbits(dev, 0x3f, 6); /* pre-amble */ |
| 411 | ax_mii_ei_outbits(dev, 1, 2); /* frame-start */ |
| 412 | ax_mii_ei_outbits(dev, opc, 2); /* op code */ |
| 413 | ax_mii_ei_outbits(dev, phy_addr, 5); /* phy address */ |
| 414 | ax_mii_ei_outbits(dev, reg, 5); /* reg address */ |
| 415 | } |
| 416 | |
| 417 | static int |
| 418 | ax_phy_read(struct net_device *dev, int phy_addr, int reg) |
| 419 | { |
Joe Perches | ece4915 | 2010-11-15 11:12:31 +0000 | [diff] [blame] | 420 | struct ei_device *ei_local = netdev_priv(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 421 | unsigned long flags; |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 422 | unsigned int result; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 423 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 424 | spin_lock_irqsave(&ei_local->page_lock, flags); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 425 | |
| 426 | ax_phy_issueaddr(dev, phy_addr, reg, 2); |
| 427 | |
| 428 | result = ax_phy_ei_inbits(dev, 17); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 429 | result &= ~(3 << 16); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 430 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 431 | spin_unlock_irqrestore(&ei_local->page_lock, flags); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 432 | |
| 433 | if (phy_debug) |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 434 | pr_debug("%s: %04x.%04x => read %04x\n", __func__, |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 435 | phy_addr, reg, result); |
| 436 | |
| 437 | return result; |
| 438 | } |
| 439 | |
| 440 | static void |
| 441 | ax_phy_write(struct net_device *dev, int phy_addr, int reg, int value) |
| 442 | { |
Joe Perches | ece4915 | 2010-11-15 11:12:31 +0000 | [diff] [blame] | 443 | struct ei_device *ei = netdev_priv(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 444 | struct ax_device *ax = to_ax_dev(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 445 | unsigned long flags; |
| 446 | |
Ben Dooks | 237c5e8 | 2008-01-31 11:25:31 +0000 | [diff] [blame] | 447 | dev_dbg(&ax->dev->dev, "%s: %p, %04x, %04x %04x\n", |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 448 | __func__, dev, phy_addr, reg, value); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 449 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 450 | spin_lock_irqsave(&ei->page_lock, flags); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 451 | |
| 452 | ax_phy_issueaddr(dev, phy_addr, reg, 1); |
| 453 | ax_mii_ei_outbits(dev, 2, 2); /* send TA */ |
| 454 | ax_mii_ei_outbits(dev, value, 16); |
| 455 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 456 | spin_unlock_irqrestore(&ei->page_lock, flags); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static void ax_mii_expiry(unsigned long data) |
| 460 | { |
| 461 | struct net_device *dev = (struct net_device *)data; |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 462 | struct ax_device *ax = to_ax_dev(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 463 | unsigned long flags; |
| 464 | |
| 465 | spin_lock_irqsave(&ax->mii_lock, flags); |
| 466 | mii_check_media(&ax->mii, netif_msg_link(ax), 0); |
| 467 | spin_unlock_irqrestore(&ax->mii_lock, flags); |
| 468 | |
| 469 | if (ax->running) { |
| 470 | ax->mii_timer.expires = jiffies + HZ*2; |
| 471 | add_timer(&ax->mii_timer); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | static int ax_open(struct net_device *dev) |
| 476 | { |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 477 | struct ax_device *ax = to_ax_dev(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 478 | struct ei_device *ei_local = netdev_priv(dev); |
| 479 | int ret; |
| 480 | |
Al Viro | 2832e85 | 2007-07-15 21:00:51 +0100 | [diff] [blame] | 481 | dev_dbg(&ax->dev->dev, "%s: open\n", dev->name); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 482 | |
Daniel Mack | 47cb035 | 2009-03-24 23:31:22 -0700 | [diff] [blame] | 483 | ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags, |
| 484 | dev->name, dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 485 | if (ret) |
| 486 | return ret; |
| 487 | |
| 488 | ret = ax_ei_open(dev); |
Kulikov Vasiliy | 9f1e758 | 2010-07-08 23:42:40 -0700 | [diff] [blame] | 489 | if (ret) { |
| 490 | free_irq(dev->irq, dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 491 | return ret; |
Kulikov Vasiliy | 9f1e758 | 2010-07-08 23:42:40 -0700 | [diff] [blame] | 492 | } |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 493 | |
| 494 | /* turn the phy on (if turned off) */ |
| 495 | |
| 496 | ei_outb(ax->plat->gpoc_val, ei_local->mem + EI_SHIFT(0x17)); |
| 497 | ax->running = 1; |
| 498 | |
| 499 | /* start the MII timer */ |
| 500 | |
| 501 | init_timer(&ax->mii_timer); |
| 502 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 503 | ax->mii_timer.expires = jiffies + 1; |
| 504 | ax->mii_timer.data = (unsigned long) dev; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 505 | ax->mii_timer.function = ax_mii_expiry; |
| 506 | |
| 507 | add_timer(&ax->mii_timer); |
| 508 | |
| 509 | return 0; |
| 510 | } |
| 511 | |
| 512 | static int ax_close(struct net_device *dev) |
| 513 | { |
| 514 | struct ax_device *ax = to_ax_dev(dev); |
| 515 | struct ei_device *ei_local = netdev_priv(dev); |
| 516 | |
Al Viro | 2832e85 | 2007-07-15 21:00:51 +0100 | [diff] [blame] | 517 | dev_dbg(&ax->dev->dev, "%s: close\n", dev->name); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 518 | |
| 519 | /* turn the phy off */ |
| 520 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 521 | ei_outb(ax->plat->gpoc_val | (1 << 6), |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 522 | ei_local->mem + EI_SHIFT(0x17)); |
| 523 | |
| 524 | ax->running = 0; |
| 525 | wmb(); |
| 526 | |
| 527 | del_timer_sync(&ax->mii_timer); |
| 528 | ax_ei_close(dev); |
| 529 | |
| 530 | free_irq(dev->irq, dev); |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | static int ax_ioctl(struct net_device *dev, struct ifreq *req, int cmd) |
| 535 | { |
| 536 | struct ax_device *ax = to_ax_dev(dev); |
| 537 | unsigned long flags; |
| 538 | int rc; |
| 539 | |
| 540 | if (!netif_running(dev)) |
| 541 | return -EINVAL; |
| 542 | |
| 543 | spin_lock_irqsave(&ax->mii_lock, flags); |
| 544 | rc = generic_mii_ioctl(&ax->mii, if_mii(req), cmd, NULL); |
| 545 | spin_unlock_irqrestore(&ax->mii_lock, flags); |
| 546 | |
| 547 | return rc; |
| 548 | } |
| 549 | |
| 550 | /* ethtool ops */ |
| 551 | |
| 552 | static void ax_get_drvinfo(struct net_device *dev, |
| 553 | struct ethtool_drvinfo *info) |
| 554 | { |
| 555 | struct ax_device *ax = to_ax_dev(dev); |
| 556 | |
| 557 | strcpy(info->driver, DRV_NAME); |
| 558 | strcpy(info->version, DRV_VERSION); |
| 559 | strcpy(info->bus_info, ax->dev->name); |
| 560 | } |
| 561 | |
| 562 | static int ax_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 563 | { |
| 564 | struct ax_device *ax = to_ax_dev(dev); |
| 565 | unsigned long flags; |
| 566 | |
| 567 | spin_lock_irqsave(&ax->mii_lock, flags); |
| 568 | mii_ethtool_gset(&ax->mii, cmd); |
Ben Dooks | c091258 | 2008-08-07 17:21:09 +0100 | [diff] [blame] | 569 | spin_unlock_irqrestore(&ax->mii_lock, flags); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 570 | |
| 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | static int ax_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 575 | { |
| 576 | struct ax_device *ax = to_ax_dev(dev); |
| 577 | unsigned long flags; |
| 578 | int rc; |
| 579 | |
| 580 | spin_lock_irqsave(&ax->mii_lock, flags); |
| 581 | rc = mii_ethtool_sset(&ax->mii, cmd); |
Ben Dooks | c091258 | 2008-08-07 17:21:09 +0100 | [diff] [blame] | 582 | spin_unlock_irqrestore(&ax->mii_lock, flags); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 583 | |
| 584 | return rc; |
| 585 | } |
| 586 | |
| 587 | static int ax_nway_reset(struct net_device *dev) |
| 588 | { |
| 589 | struct ax_device *ax = to_ax_dev(dev); |
| 590 | return mii_nway_restart(&ax->mii); |
| 591 | } |
| 592 | |
| 593 | static u32 ax_get_link(struct net_device *dev) |
| 594 | { |
| 595 | struct ax_device *ax = to_ax_dev(dev); |
| 596 | return mii_link_ok(&ax->mii); |
| 597 | } |
| 598 | |
| 599 | static const struct ethtool_ops ax_ethtool_ops = { |
| 600 | .get_drvinfo = ax_get_drvinfo, |
| 601 | .get_settings = ax_get_settings, |
| 602 | .set_settings = ax_set_settings, |
| 603 | .nway_reset = ax_nway_reset, |
| 604 | .get_link = ax_get_link, |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 605 | }; |
| 606 | |
Magnus Damm | 89e536a | 2007-09-28 22:42:16 -0700 | [diff] [blame] | 607 | #ifdef CONFIG_AX88796_93CX6 |
| 608 | static void ax_eeprom_register_read(struct eeprom_93cx6 *eeprom) |
| 609 | { |
| 610 | struct ei_device *ei_local = eeprom->data; |
| 611 | u8 reg = ei_inb(ei_local->mem + AX_MEMR); |
| 612 | |
| 613 | eeprom->reg_data_in = reg & AX_MEMR_EEI; |
| 614 | eeprom->reg_data_out = reg & AX_MEMR_EEO; /* Input pin */ |
| 615 | eeprom->reg_data_clock = reg & AX_MEMR_EECLK; |
| 616 | eeprom->reg_chip_select = reg & AX_MEMR_EECS; |
| 617 | } |
| 618 | |
| 619 | static void ax_eeprom_register_write(struct eeprom_93cx6 *eeprom) |
| 620 | { |
| 621 | struct ei_device *ei_local = eeprom->data; |
| 622 | u8 reg = ei_inb(ei_local->mem + AX_MEMR); |
| 623 | |
| 624 | reg &= ~(AX_MEMR_EEI | AX_MEMR_EECLK | AX_MEMR_EECS); |
| 625 | |
| 626 | if (eeprom->reg_data_in) |
| 627 | reg |= AX_MEMR_EEI; |
| 628 | if (eeprom->reg_data_clock) |
| 629 | reg |= AX_MEMR_EECLK; |
| 630 | if (eeprom->reg_chip_select) |
| 631 | reg |= AX_MEMR_EECS; |
| 632 | |
| 633 | ei_outb(reg, ei_local->mem + AX_MEMR); |
| 634 | udelay(10); |
| 635 | } |
| 636 | #endif |
| 637 | |
Magnus Damm | d57bc36 | 2009-01-14 21:05:55 -0800 | [diff] [blame] | 638 | static const struct net_device_ops ax_netdev_ops = { |
| 639 | .ndo_open = ax_open, |
| 640 | .ndo_stop = ax_close, |
| 641 | .ndo_do_ioctl = ax_ioctl, |
| 642 | |
| 643 | .ndo_start_xmit = ax_ei_start_xmit, |
| 644 | .ndo_tx_timeout = ax_ei_tx_timeout, |
| 645 | .ndo_get_stats = ax_ei_get_stats, |
| 646 | .ndo_set_multicast_list = ax_ei_set_multicast_list, |
| 647 | .ndo_validate_addr = eth_validate_addr, |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 648 | .ndo_set_mac_address = eth_mac_addr, |
Magnus Damm | d57bc36 | 2009-01-14 21:05:55 -0800 | [diff] [blame] | 649 | .ndo_change_mtu = eth_change_mtu, |
| 650 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 651 | .ndo_poll_controller = ax_ei_poll, |
| 652 | #endif |
| 653 | }; |
| 654 | |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 655 | /* setup code */ |
| 656 | |
| 657 | static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local) |
| 658 | { |
| 659 | void __iomem *ioaddr = ei_local->mem; |
| 660 | struct ax_device *ax = to_ax_dev(dev); |
| 661 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 662 | /* Select page 0 */ |
| 663 | ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_STOP, ioaddr + E8390_CMD); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 664 | |
| 665 | /* set to byte access */ |
| 666 | ei_outb(ax->plat->dcr_val & ~1, ioaddr + EN0_DCFG); |
| 667 | ei_outb(ax->plat->gpoc_val, ioaddr + EI_SHIFT(0x17)); |
| 668 | } |
| 669 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 670 | /* |
| 671 | * ax_init_dev |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 672 | * |
| 673 | * initialise the specified device, taking care to note the MAC |
| 674 | * address it may already have (if configured), ensure |
| 675 | * the device is ready to be used by lib8390.c and registerd with |
| 676 | * the network layer. |
| 677 | */ |
Marc Kleine-Budde | 1cbece3 | 2011-02-19 23:07:09 +0100 | [diff] [blame^] | 678 | static int ax_init_dev(struct net_device *dev) |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 679 | { |
| 680 | struct ei_device *ei_local = netdev_priv(dev); |
| 681 | struct ax_device *ax = to_ax_dev(dev); |
| 682 | void __iomem *ioaddr = ei_local->mem; |
| 683 | unsigned int start_page; |
| 684 | unsigned int stop_page; |
| 685 | int ret; |
| 686 | int i; |
| 687 | |
| 688 | ret = ax_initial_check(dev); |
| 689 | if (ret) |
| 690 | goto err_out; |
| 691 | |
| 692 | /* setup goes here */ |
| 693 | |
| 694 | ax_initial_setup(dev, ei_local); |
| 695 | |
| 696 | /* read the mac from the card prom if we need it */ |
| 697 | |
Marc Kleine-Budde | 1cbece3 | 2011-02-19 23:07:09 +0100 | [diff] [blame^] | 698 | if (ax->plat->flags & AXFLG_HAS_EEPROM) { |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 699 | unsigned char SA_prom[32]; |
| 700 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 701 | for (i = 0; i < sizeof(SA_prom); i += 2) { |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 702 | SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 703 | SA_prom[i + 1] = ei_inb(ioaddr + NE_DATAPORT); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | if (ax->plat->wordlength == 2) |
| 707 | for (i = 0; i < 16; i++) |
| 708 | SA_prom[i] = SA_prom[i+i]; |
| 709 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 710 | memcpy(dev->dev_addr, SA_prom, 6); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 711 | } |
| 712 | |
Magnus Damm | 89e536a | 2007-09-28 22:42:16 -0700 | [diff] [blame] | 713 | #ifdef CONFIG_AX88796_93CX6 |
Marc Kleine-Budde | 1cbece3 | 2011-02-19 23:07:09 +0100 | [diff] [blame^] | 714 | if (ax->plat->flags & AXFLG_HAS_93CX6) { |
Magnus Damm | 89e536a | 2007-09-28 22:42:16 -0700 | [diff] [blame] | 715 | unsigned char mac_addr[6]; |
| 716 | struct eeprom_93cx6 eeprom; |
| 717 | |
| 718 | eeprom.data = ei_local; |
| 719 | eeprom.register_read = ax_eeprom_register_read; |
| 720 | eeprom.register_write = ax_eeprom_register_write; |
| 721 | eeprom.width = PCI_EEPROM_WIDTH_93C56; |
| 722 | |
| 723 | eeprom_93cx6_multiread(&eeprom, 0, |
| 724 | (__le16 __force *)mac_addr, |
| 725 | sizeof(mac_addr) >> 1); |
| 726 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 727 | memcpy(dev->dev_addr, mac_addr, 6); |
Magnus Damm | 89e536a | 2007-09-28 22:42:16 -0700 | [diff] [blame] | 728 | } |
| 729 | #endif |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 730 | if (ax->plat->wordlength == 2) { |
| 731 | /* We must set the 8390 for word mode. */ |
| 732 | ei_outb(ax->plat->dcr_val, ei_local->mem + EN0_DCFG); |
| 733 | start_page = NESM_START_PG; |
| 734 | stop_page = NESM_STOP_PG; |
| 735 | } else { |
| 736 | start_page = NE1SM_START_PG; |
| 737 | stop_page = NE1SM_STOP_PG; |
| 738 | } |
| 739 | |
Marc Kleine-Budde | 1cbece3 | 2011-02-19 23:07:09 +0100 | [diff] [blame^] | 740 | /* load the mac-address from the device */ |
| 741 | if (ax->plat->flags & AXFLG_MAC_FROMDEV) { |
| 742 | ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, |
| 743 | ei_local->mem + E8390_CMD); /* 0x61 */ |
| 744 | for (i = 0; i < ETHER_ADDR_LEN; i++) |
| 745 | dev->dev_addr[i] = |
| 746 | ei_inb(ioaddr + EN1_PHYS_SHIFT(i)); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Marc Kleine-Budde | 1cbece3 | 2011-02-19 23:07:09 +0100 | [diff] [blame^] | 749 | if ((ax->plat->flags & AXFLG_MAC_FROMPLATFORM) && |
| 750 | ax->plat->mac_addr) |
| 751 | memcpy(dev->dev_addr, ax->plat->mac_addr, |
| 752 | ETHER_ADDR_LEN); |
| 753 | |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 754 | ax_reset_8390(dev); |
| 755 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 756 | ei_local->name = "AX88796"; |
| 757 | ei_local->tx_start_page = start_page; |
| 758 | ei_local->stop_page = stop_page; |
| 759 | ei_local->word16 = (ax->plat->wordlength == 2); |
| 760 | ei_local->rx_start_page = start_page + TX_PAGES; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 761 | |
| 762 | #ifdef PACKETBUF_MEMSIZE |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 763 | /* Allow the packet buffer size to be overridden by know-it-alls. */ |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 764 | ei_local->stop_page = ei_local->tx_start_page + PACKETBUF_MEMSIZE; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 765 | #endif |
| 766 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 767 | ei_local->reset_8390 = &ax_reset_8390; |
| 768 | ei_local->block_input = &ax_block_input; |
| 769 | ei_local->block_output = &ax_block_output; |
| 770 | ei_local->get_8390_hdr = &ax_get_8390_hdr; |
| 771 | ei_local->priv = 0; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 772 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 773 | dev->netdev_ops = &ax_netdev_ops; |
| 774 | dev->ethtool_ops = &ax_ethtool_ops; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 775 | |
| 776 | ax->msg_enable = NETIF_MSG_LINK; |
| 777 | ax->mii.phy_id_mask = 0x1f; |
| 778 | ax->mii.reg_num_mask = 0x1f; |
| 779 | ax->mii.phy_id = 0x10; /* onboard phy */ |
| 780 | ax->mii.force_media = 0; |
| 781 | ax->mii.full_duplex = 0; |
| 782 | ax->mii.mdio_read = ax_phy_read; |
| 783 | ax->mii.mdio_write = ax_phy_write; |
| 784 | ax->mii.dev = dev; |
| 785 | |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 786 | ax_NS8390_init(dev, 0); |
| 787 | |
Marc Kleine-Budde | 1cbece3 | 2011-02-19 23:07:09 +0100 | [diff] [blame^] | 788 | dev_info(&ax->dev->dev, "%dbit, irq %d, %lx, MAC: %pM\n", |
| 789 | ei_local->word16 ? 16 : 8, dev->irq, dev->base_addr, |
| 790 | dev->dev_addr); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 791 | |
| 792 | ret = register_netdev(dev); |
| 793 | if (ret) |
| 794 | goto out_irq; |
| 795 | |
| 796 | return 0; |
| 797 | |
| 798 | out_irq: |
| 799 | /* cleanup irq */ |
| 800 | free_irq(dev->irq, dev); |
| 801 | err_out: |
| 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | static int ax_remove(struct platform_device *_dev) |
| 806 | { |
| 807 | struct net_device *dev = platform_get_drvdata(_dev); |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 808 | struct ei_device *ei_local = netdev_priv(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 809 | struct ax_device *ax; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 810 | |
| 811 | ax = to_ax_dev(dev); |
| 812 | |
| 813 | unregister_netdev(dev); |
| 814 | free_irq(dev->irq, dev); |
| 815 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 816 | iounmap(ei_local->mem); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 817 | release_resource(ax->mem); |
| 818 | kfree(ax->mem); |
| 819 | |
| 820 | if (ax->map2) { |
| 821 | iounmap(ax->map2); |
| 822 | release_resource(ax->mem2); |
| 823 | kfree(ax->mem2); |
| 824 | } |
| 825 | |
| 826 | free_netdev(dev); |
| 827 | |
| 828 | return 0; |
| 829 | } |
| 830 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 831 | /* |
| 832 | * ax_probe |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 833 | * |
| 834 | * This is the entry point when the platform device system uses to |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 835 | * notify us of a new device to attach to. Allocate memory, find the |
| 836 | * resources and information passed, and map the necessary registers. |
| 837 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 838 | static int ax_probe(struct platform_device *pdev) |
| 839 | { |
| 840 | struct net_device *dev; |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 841 | struct ei_device *ei_local; |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 842 | struct ax_device *ax; |
| 843 | struct resource *res; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 844 | size_t size; |
Daniel Mack | 47cb035 | 2009-03-24 23:31:22 -0700 | [diff] [blame] | 845 | int ret = 0; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 846 | |
| 847 | dev = ax__alloc_ei_netdev(sizeof(struct ax_device)); |
| 848 | if (dev == NULL) |
| 849 | return -ENOMEM; |
| 850 | |
| 851 | /* ok, let's setup our device */ |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 852 | ei_local = netdev_priv(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 853 | ax = to_ax_dev(dev); |
| 854 | |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 855 | spin_lock_init(&ax->mii_lock); |
| 856 | |
| 857 | ax->dev = pdev; |
| 858 | ax->plat = pdev->dev.platform_data; |
| 859 | platform_set_drvdata(pdev, dev); |
| 860 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 861 | ei_local->rxcr_base = ax->plat->rcr_val; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 862 | |
| 863 | /* find the platform resources */ |
Daniel Mack | 47cb035 | 2009-03-24 23:31:22 -0700 | [diff] [blame] | 864 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 865 | if (res == NULL) { |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 866 | dev_err(&pdev->dev, "no IRQ specified\n"); |
Julia Lawall | 13eea19 | 2010-10-18 04:11:14 +0000 | [diff] [blame] | 867 | ret = -ENXIO; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 868 | goto exit_mem; |
| 869 | } |
Daniel Mack | 47cb035 | 2009-03-24 23:31:22 -0700 | [diff] [blame] | 870 | |
| 871 | dev->irq = res->start; |
| 872 | ax->irqflags = res->flags & IRQF_TRIGGER_MASK; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 873 | |
| 874 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 875 | if (res == NULL) { |
| 876 | dev_err(&pdev->dev, "no MEM specified\n"); |
| 877 | ret = -ENXIO; |
| 878 | goto exit_mem; |
| 879 | } |
| 880 | |
| 881 | size = (res->end - res->start) + 1; |
| 882 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 883 | /* |
| 884 | * setup the register offsets from either the platform data or |
| 885 | * by using the size of the resource provided |
| 886 | */ |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 887 | if (ax->plat->reg_offsets) |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 888 | ei_local->reg_offset = ax->plat->reg_offsets; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 889 | else { |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 890 | ei_local->reg_offset = ax->reg_offsets; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 891 | for (ret = 0; ret < 0x18; ret++) |
| 892 | ax->reg_offsets[ret] = (size / 0x18) * ret; |
| 893 | } |
| 894 | |
| 895 | ax->mem = request_mem_region(res->start, size, pdev->name); |
| 896 | if (ax->mem == NULL) { |
| 897 | dev_err(&pdev->dev, "cannot reserve registers\n"); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 898 | ret = -ENXIO; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 899 | goto exit_mem; |
| 900 | } |
| 901 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 902 | ei_local->mem = ioremap(res->start, size); |
| 903 | dev->base_addr = (unsigned long)ei_local->mem; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 904 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 905 | if (ei_local->mem == NULL) { |
Andrew Morton | b4efe22 | 2007-08-10 14:05:21 -0700 | [diff] [blame] | 906 | dev_err(&pdev->dev, "Cannot ioremap area (%08llx,%08llx)\n", |
| 907 | (unsigned long long)res->start, |
| 908 | (unsigned long long)res->end); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 909 | |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 910 | ret = -ENXIO; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 911 | goto exit_req; |
| 912 | } |
| 913 | |
| 914 | /* look for reset area */ |
| 915 | |
| 916 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 917 | if (res == NULL) { |
| 918 | if (!ax->plat->reg_offsets) { |
| 919 | for (ret = 0; ret < 0x20; ret++) |
| 920 | ax->reg_offsets[ret] = (size / 0x20) * ret; |
| 921 | } |
| 922 | |
| 923 | ax->map2 = NULL; |
| 924 | } else { |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 925 | size = (res->end - res->start) + 1; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 926 | |
| 927 | ax->mem2 = request_mem_region(res->start, size, pdev->name); |
Julia Lawall | bcf4d81 | 2010-02-08 22:44:18 -0800 | [diff] [blame] | 928 | if (ax->mem2 == NULL) { |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 929 | dev_err(&pdev->dev, "cannot reserve registers\n"); |
| 930 | ret = -ENXIO; |
| 931 | goto exit_mem1; |
| 932 | } |
| 933 | |
| 934 | ax->map2 = ioremap(res->start, size); |
| 935 | if (ax->map2 == NULL) { |
Joe Perches | 898eb71 | 2007-10-18 03:06:30 -0700 | [diff] [blame] | 936 | dev_err(&pdev->dev, "cannot map reset register\n"); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 937 | ret = -ENXIO; |
| 938 | goto exit_mem2; |
| 939 | } |
| 940 | |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 941 | ei_local->reg_offset[0x1f] = ax->map2 - ei_local->mem; |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | /* got resources, now initialise and register device */ |
| 945 | |
Marc Kleine-Budde | 1cbece3 | 2011-02-19 23:07:09 +0100 | [diff] [blame^] | 946 | ret = ax_init_dev(dev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 947 | if (!ret) |
| 948 | return 0; |
| 949 | |
| 950 | if (ax->map2 == NULL) |
| 951 | goto exit_mem1; |
| 952 | |
| 953 | iounmap(ax->map2); |
| 954 | |
| 955 | exit_mem2: |
| 956 | release_resource(ax->mem2); |
| 957 | kfree(ax->mem2); |
| 958 | |
| 959 | exit_mem1: |
Marc Kleine-Budde | ea5a43d | 2011-02-19 22:08:33 +0100 | [diff] [blame] | 960 | iounmap(ei_local->mem); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 961 | |
| 962 | exit_req: |
| 963 | release_resource(ax->mem); |
| 964 | kfree(ax->mem); |
| 965 | |
| 966 | exit_mem: |
| 967 | free_netdev(dev); |
| 968 | |
| 969 | return ret; |
| 970 | } |
| 971 | |
| 972 | /* suspend and resume */ |
| 973 | |
| 974 | #ifdef CONFIG_PM |
| 975 | static int ax_suspend(struct platform_device *dev, pm_message_t state) |
| 976 | { |
| 977 | struct net_device *ndev = platform_get_drvdata(dev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 978 | struct ax_device *ax = to_ax_dev(ndev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 979 | |
| 980 | ax->resume_open = ax->running; |
| 981 | |
| 982 | netif_device_detach(ndev); |
| 983 | ax_close(ndev); |
| 984 | |
| 985 | return 0; |
| 986 | } |
| 987 | |
| 988 | static int ax_resume(struct platform_device *pdev) |
| 989 | { |
| 990 | struct net_device *ndev = platform_get_drvdata(pdev); |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 991 | struct ax_device *ax = to_ax_dev(ndev); |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 992 | |
| 993 | ax_initial_setup(ndev, netdev_priv(ndev)); |
| 994 | ax_NS8390_init(ndev, ax->resume_open); |
| 995 | netif_device_attach(ndev); |
| 996 | |
| 997 | if (ax->resume_open) |
| 998 | ax_open(ndev); |
| 999 | |
| 1000 | return 0; |
| 1001 | } |
| 1002 | |
| 1003 | #else |
| 1004 | #define ax_suspend NULL |
Marc Kleine-Budde | 9f07242 | 2011-02-19 17:07:40 +0100 | [diff] [blame] | 1005 | #define ax_resume NULL |
Ben Dooks | 825a2ff | 2007-07-03 16:53:09 +0100 | [diff] [blame] | 1006 | #endif |
| 1007 | |
| 1008 | static struct platform_driver axdrv = { |
| 1009 | .driver = { |
| 1010 | .name = "ax88796", |
| 1011 | .owner = THIS_MODULE, |
| 1012 | }, |
| 1013 | .probe = ax_probe, |
| 1014 | .remove = ax_remove, |
| 1015 | .suspend = ax_suspend, |
| 1016 | .resume = ax_resume, |
| 1017 | }; |
| 1018 | |
| 1019 | static int __init axdrv_init(void) |
| 1020 | { |
| 1021 | return platform_driver_register(&axdrv); |
| 1022 | } |
| 1023 | |
| 1024 | static void __exit axdrv_exit(void) |
| 1025 | { |
| 1026 | platform_driver_unregister(&axdrv); |
| 1027 | } |
| 1028 | |
| 1029 | module_init(axdrv_init); |
| 1030 | module_exit(axdrv_exit); |
| 1031 | |
| 1032 | MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver"); |
| 1033 | MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); |
| 1034 | MODULE_LICENSE("GPL v2"); |
Kay Sievers | 72abb46 | 2008-04-18 13:50:44 -0700 | [diff] [blame] | 1035 | MODULE_ALIAS("platform:ax88796"); |