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