Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'net/ax88796' of git://git.pengutronix.de/git/mkl/linux-2.6

+401 -425
+2 -2
drivers/net/Kconfig
··· 238 238 config AX88796 239 239 tristate "ASIX AX88796 NE2000 clone support" 240 240 depends on ARM || MIPS || SUPERH 241 - select CRC32 242 - select MII 241 + select PHYLIB 242 + select MDIO_BITBANG 243 243 help 244 244 AX88796 driver, using platform bus to provide 245 245 chip detection and resources
+399 -423
drivers/net/ax88796.c
··· 9 9 * This program is free software; you can redistribute it and/or modify 10 10 * it under the terms of the GNU General Public License version 2 as 11 11 * published by the Free Software Foundation. 12 - */ 12 + */ 13 13 14 14 #include <linux/module.h> 15 15 #include <linux/kernel.h> ··· 17 17 #include <linux/isapnp.h> 18 18 #include <linux/init.h> 19 19 #include <linux/interrupt.h> 20 + #include <linux/io.h> 20 21 #include <linux/platform_device.h> 21 22 #include <linux/delay.h> 22 23 #include <linux/timer.h> 23 24 #include <linux/netdevice.h> 24 25 #include <linux/etherdevice.h> 25 26 #include <linux/ethtool.h> 26 - #include <linux/mii.h> 27 + #include <linux/mdio-bitbang.h> 28 + #include <linux/phy.h> 27 29 #include <linux/eeprom_93cx6.h> 28 30 #include <linux/slab.h> 29 31 30 32 #include <net/ax88796.h> 31 33 32 34 #include <asm/system.h> 33 - #include <asm/io.h> 34 - 35 - static int phy_debug = 0; 36 35 37 36 /* Rename the lib8390.c functions to show that they are in this driver */ 38 - #define __ei_open ax_ei_open 39 - #define __ei_close ax_ei_close 40 - #define __ei_poll ax_ei_poll 37 + #define __ei_open ax_ei_open 38 + #define __ei_close ax_ei_close 39 + #define __ei_poll ax_ei_poll 41 40 #define __ei_start_xmit ax_ei_start_xmit 42 41 #define __ei_tx_timeout ax_ei_tx_timeout 43 - #define __ei_get_stats ax_ei_get_stats 42 + #define __ei_get_stats ax_ei_get_stats 44 43 #define __ei_set_multicast_list ax_ei_set_multicast_list 45 - #define __ei_interrupt ax_ei_interrupt 44 + #define __ei_interrupt ax_ei_interrupt 46 45 #define ____alloc_ei_netdev ax__alloc_ei_netdev 47 - #define __NS8390_init ax_NS8390_init 46 + #define __NS8390_init ax_NS8390_init 48 47 49 48 /* force unsigned long back to 'void __iomem *' */ 50 49 #define ax_convert_addr(_a) ((void __force __iomem *)(_a)) 51 50 52 - #define ei_inb(_a) readb(ax_convert_addr(_a)) 51 + #define ei_inb(_a) readb(ax_convert_addr(_a)) 53 52 #define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a)) 54 53 55 - #define ei_inb_p(_a) ei_inb(_a) 54 + #define ei_inb_p(_a) ei_inb(_a) 56 55 #define ei_outb_p(_v, _a) ei_outb(_v, _a) 57 56 58 57 /* define EI_SHIFT() to take into account our register offsets */ 59 - #define EI_SHIFT(x) (ei_local->reg_offset[(x)]) 58 + #define EI_SHIFT(x) (ei_local->reg_offset[(x)]) 60 59 61 60 /* Ensure we have our RCR base value */ 62 61 #define AX88796_PLATFORM ··· 73 74 #define NE_DATAPORT EI_SHIFT(0x10) 74 75 75 76 #define NE1SM_START_PG 0x20 /* First page of TX buffer */ 76 - #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */ 77 + #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */ 77 78 #define NESM_START_PG 0x40 /* First page of TX buffer */ 78 79 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */ 80 + 81 + #define AX_GPOC_PPDSET BIT(6) 79 82 80 83 /* device private data */ 81 84 82 85 struct ax_device { 83 - struct timer_list mii_timer; 84 - spinlock_t mii_lock; 85 - struct mii_if_info mii; 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; 86 94 87 - u32 msg_enable; 88 - void __iomem *map2; 89 - struct platform_device *dev; 90 - struct resource *mem; 91 - struct resource *mem2; 92 - struct ax_plat_data *plat; 95 + void __iomem *map2; 96 + const struct ax_plat_data *plat; 93 97 94 - unsigned char running; 95 - unsigned char resume_open; 96 - unsigned int irqflags; 98 + unsigned char running; 99 + unsigned char resume_open; 100 + unsigned int irqflags; 97 101 98 - u32 reg_offsets[0x20]; 102 + u32 reg_offsets[0x20]; 99 103 }; 100 104 101 105 static inline struct ax_device *to_ax_dev(struct net_device *dev) 102 106 { 103 107 struct ei_device *ei_local = netdev_priv(dev); 104 - return (struct ax_device *)(ei_local+1); 108 + return (struct ax_device *)(ei_local + 1); 105 109 } 106 110 107 - /* ax_initial_check 111 + /* 112 + * ax_initial_check 108 113 * 109 114 * do an initial probe for the card to check wether it exists 110 115 * and is functional 111 116 */ 112 - 113 117 static int ax_initial_check(struct net_device *dev) 114 118 { 115 119 struct ei_device *ei_local = netdev_priv(dev); ··· 124 122 if (reg0 == 0xFF) 125 123 return -ENODEV; 126 124 127 - ei_outb(E8390_NODMA+E8390_PAGE1+E8390_STOP, ioaddr + E8390_CMD); 125 + ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, ioaddr + E8390_CMD); 128 126 regd = ei_inb(ioaddr + 0x0d); 129 127 ei_outb(0xff, ioaddr + 0x0d); 130 - ei_outb(E8390_NODMA+E8390_PAGE0, ioaddr + E8390_CMD); 128 + ei_outb(E8390_NODMA + E8390_PAGE0, ioaddr + E8390_CMD); 131 129 ei_inb(ioaddr + EN0_COUNTER0); /* Clear the counter by reading. */ 132 130 if (ei_inb(ioaddr + EN0_COUNTER0) != 0) { 133 131 ei_outb(reg0, ioaddr); ··· 138 136 return 0; 139 137 } 140 138 141 - /* Hard reset the card. This used to pause for the same period that a 142 - 8390 reset command required, but that shouldn't be necessary. */ 143 - 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 + */ 144 143 static void ax_reset_8390(struct net_device *dev) 145 144 { 146 145 struct ei_device *ei_local = netdev_priv(dev); 147 - struct ax_device *ax = to_ax_dev(dev); 148 146 unsigned long reset_start_time = jiffies; 149 147 void __iomem *addr = (void __iomem *)dev->base_addr; 150 148 151 149 if (ei_debug > 1) 152 - dev_dbg(&ax->dev->dev, "resetting the 8390 t=%ld\n", jiffies); 150 + netdev_dbg(dev, "resetting the 8390 t=%ld\n", jiffies); 153 151 154 152 ei_outb(ei_inb(addr + NE_RESET), addr + NE_RESET); 155 153 156 - ei_status.txing = 0; 157 - ei_status.dmaing = 0; 154 + ei_local->txing = 0; 155 + ei_local->dmaing = 0; 158 156 159 157 /* This check _should_not_ be necessary, omit eventually. */ 160 158 while ((ei_inb(addr + EN0_ISR) & ENISR_RESET) == 0) { 161 - if (jiffies - reset_start_time > 2*HZ/100) { 162 - dev_warn(&ax->dev->dev, "%s: %s did not complete.\n", 163 - __func__, dev->name); 159 + if (jiffies - reset_start_time > 2 * HZ / 100) { 160 + netdev_warn(dev, "%s: did not complete.\n", __func__); 164 161 break; 165 162 } 166 163 } ··· 172 171 int ring_page) 173 172 { 174 173 struct ei_device *ei_local = netdev_priv(dev); 175 - struct ax_device *ax = to_ax_dev(dev); 176 174 void __iomem *nic_base = ei_local->mem; 177 175 178 176 /* This *shouldn't* happen. If it does, it's the last thing you'll see */ 179 - if (ei_status.dmaing) { 180 - dev_err(&ax->dev->dev, "%s: DMAing conflict in %s " 177 + if (ei_local->dmaing) { 178 + netdev_err(dev, "DMAing conflict in %s " 181 179 "[DMAstat:%d][irqlock:%d].\n", 182 - dev->name, __func__, 183 - ei_status.dmaing, ei_status.irqlock); 180 + __func__, 181 + ei_local->dmaing, ei_local->irqlock); 184 182 return; 185 183 } 186 184 187 - ei_status.dmaing |= 0x01; 188 - ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); 185 + ei_local->dmaing |= 0x01; 186 + ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD); 189 187 ei_outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO); 190 188 ei_outb(0, nic_base + EN0_RCNTHI); 191 189 ei_outb(0, nic_base + EN0_RSARLO); /* On page boundary */ 192 190 ei_outb(ring_page, nic_base + EN0_RSARHI); 193 191 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); 194 192 195 - if (ei_status.word16) 196 - readsw(nic_base + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1); 193 + if (ei_local->word16) 194 + readsw(nic_base + NE_DATAPORT, hdr, 195 + sizeof(struct e8390_pkt_hdr) >> 1); 197 196 else 198 - readsb(nic_base + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)); 197 + readsb(nic_base + NE_DATAPORT, hdr, 198 + sizeof(struct e8390_pkt_hdr)); 199 199 200 200 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ 201 - ei_status.dmaing &= ~0x01; 201 + ei_local->dmaing &= ~0x01; 202 202 203 203 le16_to_cpus(&hdr->count); 204 204 } 205 205 206 206 207 - /* Block input and output, similar to the Crynwr packet driver. If you 208 - are porting to a new ethercard, look at the packet driver source for hints. 209 - The NEx000 doesn't share the on-board packet memory -- you have to put 210 - the packet out through the "remote DMA" dataport using ei_outb. */ 211 - 207 + /* 208 + * Block input and output, similar to the Crynwr packet driver. If 209 + * you are porting to a new ethercard, look at the packet driver 210 + * source for hints. The NEx000 doesn't share the on-board packet 211 + * memory -- you have to put the packet out through the "remote DMA" 212 + * dataport using ei_outb. 213 + */ 212 214 static void ax_block_input(struct net_device *dev, int count, 213 215 struct sk_buff *skb, int ring_offset) 214 216 { 215 217 struct ei_device *ei_local = netdev_priv(dev); 216 - struct ax_device *ax = to_ax_dev(dev); 217 218 void __iomem *nic_base = ei_local->mem; 218 219 char *buf = skb->data; 219 220 220 - if (ei_status.dmaing) { 221 - dev_err(&ax->dev->dev, 222 - "%s: DMAing conflict in %s " 221 + if (ei_local->dmaing) { 222 + netdev_err(dev, 223 + "DMAing conflict in %s " 223 224 "[DMAstat:%d][irqlock:%d].\n", 224 - dev->name, __func__, 225 - ei_status.dmaing, ei_status.irqlock); 225 + __func__, 226 + ei_local->dmaing, ei_local->irqlock); 226 227 return; 227 228 } 228 229 229 - ei_status.dmaing |= 0x01; 230 + ei_local->dmaing |= 0x01; 230 231 231 - ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); 232 + ei_outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base + NE_CMD); 232 233 ei_outb(count & 0xff, nic_base + EN0_RCNTLO); 233 234 ei_outb(count >> 8, nic_base + EN0_RCNTHI); 234 235 ei_outb(ring_offset & 0xff, nic_base + EN0_RSARLO); 235 236 ei_outb(ring_offset >> 8, nic_base + EN0_RSARHI); 236 237 ei_outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); 237 238 238 - if (ei_status.word16) { 239 + if (ei_local->word16) { 239 240 readsw(nic_base + NE_DATAPORT, buf, count >> 1); 240 241 if (count & 0x01) 241 242 buf[count-1] = ei_inb(nic_base + NE_DATAPORT); ··· 246 243 readsb(nic_base + NE_DATAPORT, buf, count); 247 244 } 248 245 249 - ei_status.dmaing &= ~1; 246 + ei_local->dmaing &= ~1; 250 247 } 251 248 252 249 static void ax_block_output(struct net_device *dev, int count, 253 250 const unsigned char *buf, const int start_page) 254 251 { 255 252 struct ei_device *ei_local = netdev_priv(dev); 256 - struct ax_device *ax = to_ax_dev(dev); 257 253 void __iomem *nic_base = ei_local->mem; 258 254 unsigned long dma_start; 259 255 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? 262 - I should check someday. */ 263 - 264 - if (ei_status.word16 && (count & 0x01)) 256 + /* 257 + * Round the count up for word writes. Do we need to do this? 258 + * What effect will an odd byte count have on the 8390? I 259 + * should check someday. 260 + */ 261 + if (ei_local->word16 && (count & 0x01)) 265 262 count++; 266 263 267 264 /* This *shouldn't* happen. If it does, it's the last thing you'll see */ 268 - if (ei_status.dmaing) { 269 - dev_err(&ax->dev->dev, "%s: DMAing conflict in %s." 265 + if (ei_local->dmaing) { 266 + netdev_err(dev, "DMAing conflict in %s." 270 267 "[DMAstat:%d][irqlock:%d]\n", 271 - dev->name, __func__, 272 - ei_status.dmaing, ei_status.irqlock); 268 + __func__, 269 + ei_local->dmaing, ei_local->irqlock); 273 270 return; 274 271 } 275 272 276 - ei_status.dmaing |= 0x01; 273 + ei_local->dmaing |= 0x01; 277 274 /* We should already be in page 0, but to be safe... */ 278 275 ei_outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD); 279 276 ··· 281 278 282 279 /* Now the normal output. */ 283 280 ei_outb(count & 0xff, nic_base + EN0_RCNTLO); 284 - ei_outb(count >> 8, nic_base + EN0_RCNTHI); 281 + ei_outb(count >> 8, nic_base + EN0_RCNTHI); 285 282 ei_outb(0x00, nic_base + EN0_RSARLO); 286 283 ei_outb(start_page, nic_base + EN0_RSARHI); 287 284 288 285 ei_outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD); 289 - if (ei_status.word16) { 290 - writesw(nic_base + NE_DATAPORT, buf, count>>1); 291 - } else { 286 + if (ei_local->word16) 287 + writesw(nic_base + NE_DATAPORT, buf, count >> 1); 288 + else 292 289 writesb(nic_base + NE_DATAPORT, buf, count); 293 - } 294 290 295 291 dma_start = jiffies; 296 292 297 293 while ((ei_inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) { 298 - if (jiffies - dma_start > 2*HZ/100) { /* 20ms */ 299 - dev_warn(&ax->dev->dev, 300 - "%s: timeout waiting for Tx RDC.\n", dev->name); 294 + if (jiffies - dma_start > 2 * HZ / 100) { /* 20ms */ 295 + netdev_warn(dev, "timeout waiting for Tx RDC.\n"); 301 296 ax_reset_8390(dev); 302 - ax_NS8390_init(dev,1); 297 + ax_NS8390_init(dev, 1); 303 298 break; 304 299 } 305 300 } 306 301 307 302 ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ 308 - ei_status.dmaing &= ~0x01; 303 + ei_local->dmaing &= ~0x01; 309 304 } 310 305 311 306 /* definitions for accessing MII/EEPROM interface */ 312 307 313 308 #define AX_MEMR EI_SHIFT(0x14) 314 - #define AX_MEMR_MDC (1<<0) 315 - #define AX_MEMR_MDIR (1<<1) 316 - #define AX_MEMR_MDI (1<<2) 317 - #define AX_MEMR_MDO (1<<3) 318 - #define AX_MEMR_EECS (1<<4) 319 - #define AX_MEMR_EEI (1<<5) 320 - #define AX_MEMR_EEO (1<<6) 321 - #define AX_MEMR_EECLK (1<<7) 309 + #define AX_MEMR_MDC BIT(0) 310 + #define AX_MEMR_MDIR BIT(1) 311 + #define AX_MEMR_MDI BIT(2) 312 + #define AX_MEMR_MDO BIT(3) 313 + #define AX_MEMR_EECS BIT(4) 314 + #define AX_MEMR_EEI BIT(5) 315 + #define AX_MEMR_EEO BIT(6) 316 + #define AX_MEMR_EECLK BIT(7) 322 317 323 - /* ax_mii_ei_outbits 324 - * 325 - * write the specified set of bits to the phy 326 - */ 327 - 328 - static void 329 - ax_mii_ei_outbits(struct net_device *dev, unsigned int bits, int len) 318 + static void ax_handle_link_change(struct net_device *dev) 330 319 { 331 - struct ei_device *ei_local = netdev_priv(dev); 332 - void __iomem *memr_addr = (void __iomem *)dev->base_addr + AX_MEMR; 333 - unsigned int memr; 334 - 335 - /* clock low, data to output mode */ 336 - memr = ei_inb(memr_addr); 337 - memr &= ~(AX_MEMR_MDC | AX_MEMR_MDIR); 338 - ei_outb(memr, memr_addr); 339 - 340 - for (len--; len >= 0; len--) { 341 - if (bits & (1 << len)) 342 - memr |= AX_MEMR_MDO; 343 - else 344 - memr &= ~AX_MEMR_MDO; 345 - 346 - ei_outb(memr, memr_addr); 347 - 348 - /* clock high */ 349 - 350 - ei_outb(memr | AX_MEMR_MDC, memr_addr); 351 - udelay(1); 352 - 353 - /* clock low */ 354 - ei_outb(memr, memr_addr); 355 - } 356 - 357 - /* leaves the clock line low, mdir input */ 358 - memr |= AX_MEMR_MDIR; 359 - ei_outb(memr, (void __iomem *)dev->base_addr + AX_MEMR); 360 - } 361 - 362 - /* ax_phy_ei_inbits 363 - * 364 - * read a specified number of bits from the phy 365 - */ 366 - 367 - static unsigned int 368 - ax_phy_ei_inbits(struct net_device *dev, int no) 369 - { 370 - struct ei_device *ei_local = netdev_priv(dev); 371 - void __iomem *memr_addr = (void __iomem *)dev->base_addr + AX_MEMR; 372 - unsigned int memr; 373 - unsigned int result = 0; 374 - 375 - /* clock low, data to input mode */ 376 - memr = ei_inb(memr_addr); 377 - memr &= ~AX_MEMR_MDC; 378 - memr |= AX_MEMR_MDIR; 379 - ei_outb(memr, memr_addr); 380 - 381 - for (no--; no >= 0; no--) { 382 - ei_outb(memr | AX_MEMR_MDC, memr_addr); 383 - 384 - udelay(1); 385 - 386 - if (ei_inb(memr_addr) & AX_MEMR_MDI) 387 - result |= (1<<no); 388 - 389 - ei_outb(memr, memr_addr); 390 - } 391 - 392 - return result; 393 - } 394 - 395 - /* ax_phy_issueaddr 396 - * 397 - * use the low level bit shifting routines to send the address 398 - * and command to the specified phy 399 - */ 400 - 401 - static void 402 - ax_phy_issueaddr(struct net_device *dev, int phy_addr, int reg, int opc) 403 - { 404 - if (phy_debug) 405 - pr_debug("%s: dev %p, %04x, %04x, %d\n", 406 - __func__, dev, phy_addr, reg, opc); 407 - 408 - ax_mii_ei_outbits(dev, 0x3f, 6); /* pre-amble */ 409 - ax_mii_ei_outbits(dev, 1, 2); /* frame-start */ 410 - ax_mii_ei_outbits(dev, opc, 2); /* op code */ 411 - ax_mii_ei_outbits(dev, phy_addr, 5); /* phy address */ 412 - ax_mii_ei_outbits(dev, reg, 5); /* reg address */ 413 - } 414 - 415 - static int 416 - ax_phy_read(struct net_device *dev, int phy_addr, int reg) 417 - { 418 - struct ei_device *ei_local = netdev_priv(dev); 419 - unsigned long flags; 420 - unsigned int result; 421 - 422 - spin_lock_irqsave(&ei_local->page_lock, flags); 423 - 424 - ax_phy_issueaddr(dev, phy_addr, reg, 2); 425 - 426 - result = ax_phy_ei_inbits(dev, 17); 427 - result &= ~(3<<16); 428 - 429 - spin_unlock_irqrestore(&ei_local->page_lock, flags); 430 - 431 - if (phy_debug) 432 - pr_debug("%s: %04x.%04x => read %04x\n", __func__, 433 - phy_addr, reg, result); 434 - 435 - return result; 436 - } 437 - 438 - static void 439 - ax_phy_write(struct net_device *dev, int phy_addr, int reg, int value) 440 - { 441 - struct ei_device *ei = netdev_priv(dev); 442 320 struct ax_device *ax = to_ax_dev(dev); 443 - unsigned long flags; 321 + struct phy_device *phy_dev = ax->phy_dev; 322 + int status_change = 0; 444 323 445 - dev_dbg(&ax->dev->dev, "%s: %p, %04x, %04x %04x\n", 446 - __func__, dev, phy_addr, reg, value); 324 + if (phy_dev->link && ((ax->speed != phy_dev->speed) || 325 + (ax->duplex != phy_dev->duplex))) { 447 326 448 - spin_lock_irqsave(&ei->page_lock, flags); 327 + ax->speed = phy_dev->speed; 328 + ax->duplex = phy_dev->duplex; 329 + status_change = 1; 330 + } 449 331 450 - ax_phy_issueaddr(dev, phy_addr, reg, 1); 451 - ax_mii_ei_outbits(dev, 2, 2); /* send TA */ 452 - ax_mii_ei_outbits(dev, value, 16); 332 + if (phy_dev->link != ax->link) { 333 + if (!phy_dev->link) { 334 + ax->speed = 0; 335 + ax->duplex = -1; 336 + } 337 + ax->link = phy_dev->link; 453 338 454 - spin_unlock_irqrestore(&ei->page_lock, flags); 339 + status_change = 1; 340 + } 341 + 342 + if (status_change) 343 + phy_print_status(phy_dev); 455 344 } 456 345 457 - static void ax_mii_expiry(unsigned long data) 346 + static int ax_mii_probe(struct net_device *dev) 458 347 { 459 - struct net_device *dev = (struct net_device *)data; 460 348 struct ax_device *ax = to_ax_dev(dev); 461 - unsigned long flags; 349 + struct phy_device *phy_dev = NULL; 350 + int ret; 462 351 463 - spin_lock_irqsave(&ax->mii_lock, flags); 464 - mii_check_media(&ax->mii, netif_msg_link(ax), 0); 465 - spin_unlock_irqrestore(&ax->mii_lock, flags); 466 - 467 - if (ax->running) { 468 - ax->mii_timer.expires = jiffies + HZ*2; 469 - add_timer(&ax->mii_timer); 352 + /* find the first phy */ 353 + phy_dev = phy_find_first(ax->mii_bus); 354 + if (!phy_dev) { 355 + netdev_err(dev, "no PHY found\n"); 356 + return -ENODEV; 470 357 } 358 + 359 + ret = phy_connect_direct(dev, phy_dev, ax_handle_link_change, 0, 360 + PHY_INTERFACE_MODE_MII); 361 + if (ret) { 362 + netdev_err(dev, "Could not attach to PHY\n"); 363 + return ret; 364 + } 365 + 366 + /* mask with MAC supported features */ 367 + phy_dev->supported &= PHY_BASIC_FEATURES; 368 + phy_dev->advertising = phy_dev->supported; 369 + 370 + ax->phy_dev = phy_dev; 371 + 372 + netdev_info(dev, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", 373 + phy_dev->drv->name, dev_name(&phy_dev->dev), phy_dev->irq); 374 + 375 + return 0; 376 + } 377 + 378 + static void ax_phy_switch(struct net_device *dev, int on) 379 + { 380 + struct ei_device *ei_local = netdev_priv(dev); 381 + struct ax_device *ax = to_ax_dev(dev); 382 + 383 + u8 reg_gpoc = ax->plat->gpoc_val; 384 + 385 + if (!!on) 386 + reg_gpoc &= ~AX_GPOC_PPDSET; 387 + else 388 + reg_gpoc |= AX_GPOC_PPDSET; 389 + 390 + ei_outb(reg_gpoc, ei_local->mem + EI_SHIFT(0x17)); 471 391 } 472 392 473 393 static int ax_open(struct net_device *dev) 474 394 { 475 - struct ax_device *ax = to_ax_dev(dev); 476 - struct ei_device *ei_local = netdev_priv(dev); 395 + struct ax_device *ax = to_ax_dev(dev); 477 396 int ret; 478 397 479 - dev_dbg(&ax->dev->dev, "%s: open\n", dev->name); 398 + netdev_dbg(dev, "open\n"); 480 399 481 400 ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags, 482 401 dev->name, dev); 483 402 if (ret) 484 - return ret; 485 - 486 - ret = ax_ei_open(dev); 487 - if (ret) { 488 - free_irq(dev->irq, dev); 489 - return ret; 490 - } 403 + goto failed_request_irq; 491 404 492 405 /* turn the phy on (if turned off) */ 406 + ax_phy_switch(dev, 1); 493 407 494 - ei_outb(ax->plat->gpoc_val, ei_local->mem + EI_SHIFT(0x17)); 408 + ret = ax_mii_probe(dev); 409 + if (ret) 410 + goto failed_mii_probe; 411 + phy_start(ax->phy_dev); 412 + 413 + ret = ax_ei_open(dev); 414 + if (ret) 415 + goto failed_ax_ei_open; 416 + 495 417 ax->running = 1; 496 418 497 - /* start the MII timer */ 498 - 499 - init_timer(&ax->mii_timer); 500 - 501 - ax->mii_timer.expires = jiffies+1; 502 - ax->mii_timer.data = (unsigned long) dev; 503 - ax->mii_timer.function = ax_mii_expiry; 504 - 505 - add_timer(&ax->mii_timer); 506 - 507 419 return 0; 420 + 421 + failed_ax_ei_open: 422 + phy_disconnect(ax->phy_dev); 423 + failed_mii_probe: 424 + ax_phy_switch(dev, 0); 425 + free_irq(dev->irq, dev); 426 + failed_request_irq: 427 + return ret; 508 428 } 509 429 510 430 static int ax_close(struct net_device *dev) 511 431 { 512 432 struct ax_device *ax = to_ax_dev(dev); 513 - struct ei_device *ei_local = netdev_priv(dev); 514 433 515 - dev_dbg(&ax->dev->dev, "%s: close\n", dev->name); 516 - 517 - /* turn the phy off */ 518 - 519 - ei_outb(ax->plat->gpoc_val | (1<<6), 520 - ei_local->mem + EI_SHIFT(0x17)); 434 + netdev_dbg(dev, "close\n"); 521 435 522 436 ax->running = 0; 523 437 wmb(); 524 438 525 - del_timer_sync(&ax->mii_timer); 526 439 ax_ei_close(dev); 440 + 441 + /* turn the phy off */ 442 + ax_phy_switch(dev, 0); 443 + phy_disconnect(ax->phy_dev); 527 444 528 445 free_irq(dev->irq, dev); 529 446 return 0; ··· 452 529 static int ax_ioctl(struct net_device *dev, struct ifreq *req, int cmd) 453 530 { 454 531 struct ax_device *ax = to_ax_dev(dev); 455 - unsigned long flags; 456 - int rc; 532 + struct phy_device *phy_dev = ax->phy_dev; 457 533 458 534 if (!netif_running(dev)) 459 535 return -EINVAL; 460 536 461 - spin_lock_irqsave(&ax->mii_lock, flags); 462 - rc = generic_mii_ioctl(&ax->mii, if_mii(req), cmd, NULL); 463 - spin_unlock_irqrestore(&ax->mii_lock, flags); 537 + if (!phy_dev) 538 + return -ENODEV; 464 539 465 - return rc; 540 + return phy_mii_ioctl(phy_dev, req, cmd); 466 541 } 467 542 468 543 /* ethtool ops */ ··· 468 547 static void ax_get_drvinfo(struct net_device *dev, 469 548 struct ethtool_drvinfo *info) 470 549 { 471 - struct ax_device *ax = to_ax_dev(dev); 550 + struct platform_device *pdev = to_platform_device(dev->dev.parent); 472 551 473 552 strcpy(info->driver, DRV_NAME); 474 553 strcpy(info->version, DRV_VERSION); 475 - strcpy(info->bus_info, ax->dev->name); 554 + strcpy(info->bus_info, pdev->name); 476 555 } 477 556 478 557 static int ax_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 479 558 { 480 559 struct ax_device *ax = to_ax_dev(dev); 481 - unsigned long flags; 560 + struct phy_device *phy_dev = ax->phy_dev; 482 561 483 - spin_lock_irqsave(&ax->mii_lock, flags); 484 - mii_ethtool_gset(&ax->mii, cmd); 485 - spin_unlock_irqrestore(&ax->mii_lock, flags); 562 + if (!phy_dev) 563 + return -ENODEV; 486 564 487 - return 0; 565 + return phy_ethtool_gset(phy_dev, cmd); 488 566 } 489 567 490 568 static int ax_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) 491 569 { 492 570 struct ax_device *ax = to_ax_dev(dev); 493 - unsigned long flags; 494 - int rc; 571 + struct phy_device *phy_dev = ax->phy_dev; 495 572 496 - spin_lock_irqsave(&ax->mii_lock, flags); 497 - rc = mii_ethtool_sset(&ax->mii, cmd); 498 - spin_unlock_irqrestore(&ax->mii_lock, flags); 573 + if (!phy_dev) 574 + return -ENODEV; 499 575 500 - return rc; 501 - } 502 - 503 - static int ax_nway_reset(struct net_device *dev) 504 - { 505 - struct ax_device *ax = to_ax_dev(dev); 506 - return mii_nway_restart(&ax->mii); 507 - } 508 - 509 - static u32 ax_get_link(struct net_device *dev) 510 - { 511 - struct ax_device *ax = to_ax_dev(dev); 512 - return mii_link_ok(&ax->mii); 576 + return phy_ethtool_sset(phy_dev, cmd); 513 577 } 514 578 515 579 static const struct ethtool_ops ax_ethtool_ops = { 516 580 .get_drvinfo = ax_get_drvinfo, 517 581 .get_settings = ax_get_settings, 518 582 .set_settings = ax_set_settings, 519 - .nway_reset = ax_nway_reset, 520 - .get_link = ax_get_link, 583 + .get_link = ethtool_op_get_link, 521 584 }; 522 585 523 586 #ifdef CONFIG_AX88796_93CX6 ··· 545 640 .ndo_get_stats = ax_ei_get_stats, 546 641 .ndo_set_multicast_list = ax_ei_set_multicast_list, 547 642 .ndo_validate_addr = eth_validate_addr, 548 - .ndo_set_mac_address = eth_mac_addr, 643 + .ndo_set_mac_address = eth_mac_addr, 549 644 .ndo_change_mtu = eth_change_mtu, 550 645 #ifdef CONFIG_NET_POLL_CONTROLLER 551 646 .ndo_poll_controller = ax_ei_poll, 552 647 #endif 553 648 }; 554 649 650 + static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level) 651 + { 652 + struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl); 653 + 654 + if (level) 655 + ax->reg_memr |= AX_MEMR_MDC; 656 + else 657 + ax->reg_memr &= ~AX_MEMR_MDC; 658 + 659 + ei_outb(ax->reg_memr, ax->addr_memr); 660 + } 661 + 662 + static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output) 663 + { 664 + struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl); 665 + 666 + if (output) 667 + ax->reg_memr &= ~AX_MEMR_MDIR; 668 + else 669 + ax->reg_memr |= AX_MEMR_MDIR; 670 + 671 + ei_outb(ax->reg_memr, ax->addr_memr); 672 + } 673 + 674 + static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value) 675 + { 676 + struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl); 677 + 678 + if (value) 679 + ax->reg_memr |= AX_MEMR_MDO; 680 + else 681 + ax->reg_memr &= ~AX_MEMR_MDO; 682 + 683 + ei_outb(ax->reg_memr, ax->addr_memr); 684 + } 685 + 686 + static int ax_bb_get_data(struct mdiobb_ctrl *ctrl) 687 + { 688 + struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl); 689 + int reg_memr = ei_inb(ax->addr_memr); 690 + 691 + return reg_memr & AX_MEMR_MDI ? 1 : 0; 692 + } 693 + 694 + static struct mdiobb_ops bb_ops = { 695 + .owner = THIS_MODULE, 696 + .set_mdc = ax_bb_mdc, 697 + .set_mdio_dir = ax_bb_dir, 698 + .set_mdio_data = ax_bb_set_data, 699 + .get_mdio_data = ax_bb_get_data, 700 + }; 701 + 555 702 /* setup code */ 703 + 704 + static int ax_mii_init(struct net_device *dev) 705 + { 706 + struct platform_device *pdev = to_platform_device(dev->dev.parent); 707 + struct ei_device *ei_local = netdev_priv(dev); 708 + struct ax_device *ax = to_ax_dev(dev); 709 + int err, i; 710 + 711 + ax->bb_ctrl.ops = &bb_ops; 712 + ax->addr_memr = ei_local->mem + AX_MEMR; 713 + ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl); 714 + if (!ax->mii_bus) { 715 + err = -ENOMEM; 716 + goto out; 717 + } 718 + 719 + ax->mii_bus->name = "ax88796_mii_bus"; 720 + ax->mii_bus->parent = dev->dev.parent; 721 + snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%x", pdev->id); 722 + 723 + ax->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); 724 + if (!ax->mii_bus->irq) { 725 + err = -ENOMEM; 726 + goto out_free_mdio_bitbang; 727 + } 728 + 729 + for (i = 0; i < PHY_MAX_ADDR; i++) 730 + ax->mii_bus->irq[i] = PHY_POLL; 731 + 732 + err = mdiobus_register(ax->mii_bus); 733 + if (err) 734 + goto out_free_irq; 735 + 736 + return 0; 737 + 738 + out_free_irq: 739 + kfree(ax->mii_bus->irq); 740 + out_free_mdio_bitbang: 741 + free_mdio_bitbang(ax->mii_bus); 742 + out: 743 + return err; 744 + } 556 745 557 746 static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local) 558 747 { 559 748 void __iomem *ioaddr = ei_local->mem; 560 749 struct ax_device *ax = to_ax_dev(dev); 561 750 562 - /* Select page 0*/ 563 - ei_outb(E8390_NODMA+E8390_PAGE0+E8390_STOP, ioaddr + E8390_CMD); 751 + /* Select page 0 */ 752 + ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_STOP, ioaddr + E8390_CMD); 564 753 565 754 /* set to byte access */ 566 755 ei_outb(ax->plat->dcr_val & ~1, ioaddr + EN0_DCFG); 567 756 ei_outb(ax->plat->gpoc_val, ioaddr + EI_SHIFT(0x17)); 568 757 } 569 758 570 - /* ax_init_dev 759 + /* 760 + * ax_init_dev 571 761 * 572 762 * initialise the specified device, taking care to note the MAC 573 763 * address it may already have (if configured), ensure 574 764 * the device is ready to be used by lib8390.c and registerd with 575 765 * the network layer. 576 766 */ 577 - 578 - static int ax_init_dev(struct net_device *dev, int first_init) 767 + static int ax_init_dev(struct net_device *dev) 579 768 { 580 769 struct ei_device *ei_local = netdev_priv(dev); 581 770 struct ax_device *ax = to_ax_dev(dev); ··· 689 690 690 691 /* read the mac from the card prom if we need it */ 691 692 692 - if (first_init && ax->plat->flags & AXFLG_HAS_EEPROM) { 693 + if (ax->plat->flags & AXFLG_HAS_EEPROM) { 693 694 unsigned char SA_prom[32]; 694 695 695 - for(i = 0; i < sizeof(SA_prom); i+=2) { 696 + for (i = 0; i < sizeof(SA_prom); i += 2) { 696 697 SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT); 697 - SA_prom[i+1] = ei_inb(ioaddr + NE_DATAPORT); 698 + SA_prom[i + 1] = ei_inb(ioaddr + NE_DATAPORT); 698 699 } 699 700 700 701 if (ax->plat->wordlength == 2) 701 702 for (i = 0; i < 16; i++) 702 703 SA_prom[i] = SA_prom[i+i]; 703 704 704 - memcpy(dev->dev_addr, SA_prom, 6); 705 + memcpy(dev->dev_addr, SA_prom, 6); 705 706 } 706 707 707 708 #ifdef CONFIG_AX88796_93CX6 708 - if (first_init && ax->plat->flags & AXFLG_HAS_93CX6) { 709 + if (ax->plat->flags & AXFLG_HAS_93CX6) { 709 710 unsigned char mac_addr[6]; 710 711 struct eeprom_93cx6 eeprom; 711 712 ··· 718 719 (__le16 __force *)mac_addr, 719 720 sizeof(mac_addr) >> 1); 720 721 721 - memcpy(dev->dev_addr, mac_addr, 6); 722 + memcpy(dev->dev_addr, mac_addr, 6); 722 723 } 723 724 #endif 724 725 if (ax->plat->wordlength == 2) { ··· 731 732 stop_page = NE1SM_STOP_PG; 732 733 } 733 734 734 - /* load the mac-address from the device if this is the 735 - * first time we've initialised */ 736 - 737 - if (first_init) { 738 - if (ax->plat->flags & AXFLG_MAC_FROMDEV) { 739 - ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, 740 - ei_local->mem + E8390_CMD); /* 0x61 */ 741 - for (i = 0; i < ETHER_ADDR_LEN; i++) 742 - dev->dev_addr[i] = 743 - ei_inb(ioaddr + EN1_PHYS_SHIFT(i)); 744 - } 745 - 746 - if ((ax->plat->flags & AXFLG_MAC_FROMPLATFORM) && 747 - ax->plat->mac_addr) 748 - memcpy(dev->dev_addr, ax->plat->mac_addr, 749 - ETHER_ADDR_LEN); 735 + /* load the mac-address from the device */ 736 + if (ax->plat->flags & AXFLG_MAC_FROMDEV) { 737 + ei_outb(E8390_NODMA + E8390_PAGE1 + E8390_STOP, 738 + ei_local->mem + E8390_CMD); /* 0x61 */ 739 + for (i = 0; i < ETHER_ADDR_LEN; i++) 740 + dev->dev_addr[i] = 741 + ei_inb(ioaddr + EN1_PHYS_SHIFT(i)); 750 742 } 743 + 744 + if ((ax->plat->flags & AXFLG_MAC_FROMPLATFORM) && 745 + ax->plat->mac_addr) 746 + memcpy(dev->dev_addr, ax->plat->mac_addr, 747 + ETHER_ADDR_LEN); 751 748 752 749 ax_reset_8390(dev); 753 750 754 - ei_status.name = "AX88796"; 755 - ei_status.tx_start_page = start_page; 756 - ei_status.stop_page = stop_page; 757 - ei_status.word16 = (ax->plat->wordlength == 2); 758 - ei_status.rx_start_page = start_page + TX_PAGES; 751 + ei_local->name = "AX88796"; 752 + ei_local->tx_start_page = start_page; 753 + ei_local->stop_page = stop_page; 754 + ei_local->word16 = (ax->plat->wordlength == 2); 755 + ei_local->rx_start_page = start_page + TX_PAGES; 759 756 760 757 #ifdef PACKETBUF_MEMSIZE 761 - /* Allow the packet buffer size to be overridden by know-it-alls. */ 762 - ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE; 758 + /* Allow the packet buffer size to be overridden by know-it-alls. */ 759 + ei_local->stop_page = ei_local->tx_start_page + PACKETBUF_MEMSIZE; 763 760 #endif 764 761 765 - ei_status.reset_8390 = &ax_reset_8390; 766 - ei_status.block_input = &ax_block_input; 767 - ei_status.block_output = &ax_block_output; 768 - ei_status.get_8390_hdr = &ax_get_8390_hdr; 769 - ei_status.priv = 0; 762 + ei_local->reset_8390 = &ax_reset_8390; 763 + ei_local->block_input = &ax_block_input; 764 + ei_local->block_output = &ax_block_output; 765 + ei_local->get_8390_hdr = &ax_get_8390_hdr; 766 + ei_local->priv = 0; 770 767 771 - dev->netdev_ops = &ax_netdev_ops; 772 - dev->ethtool_ops = &ax_ethtool_ops; 768 + dev->netdev_ops = &ax_netdev_ops; 769 + dev->ethtool_ops = &ax_ethtool_ops; 773 770 774 - ax->msg_enable = NETIF_MSG_LINK; 775 - ax->mii.phy_id_mask = 0x1f; 776 - ax->mii.reg_num_mask = 0x1f; 777 - ax->mii.phy_id = 0x10; /* onboard phy */ 778 - ax->mii.force_media = 0; 779 - ax->mii.full_duplex = 0; 780 - ax->mii.mdio_read = ax_phy_read; 781 - ax->mii.mdio_write = ax_phy_write; 782 - ax->mii.dev = dev; 771 + ret = ax_mii_init(dev); 772 + if (ret) 773 + goto out_irq; 783 774 784 775 ax_NS8390_init(dev, 0); 785 - 786 - if (first_init) 787 - dev_info(&ax->dev->dev, "%dbit, irq %d, %lx, MAC: %pM\n", 788 - ei_status.word16 ? 16:8, dev->irq, dev->base_addr, 789 - dev->dev_addr); 790 776 791 777 ret = register_netdev(dev); 792 778 if (ret) 793 779 goto out_irq; 780 + 781 + netdev_info(dev, "%dbit, irq %d, %lx, MAC: %pM\n", 782 + ei_local->word16 ? 16 : 8, dev->irq, dev->base_addr, 783 + dev->dev_addr); 794 784 795 785 return 0; 796 786 ··· 790 802 return ret; 791 803 } 792 804 793 - static int ax_remove(struct platform_device *_dev) 805 + static int ax_remove(struct platform_device *pdev) 794 806 { 795 - struct net_device *dev = platform_get_drvdata(_dev); 796 - struct ax_device *ax; 797 - 798 - ax = to_ax_dev(dev); 807 + struct net_device *dev = platform_get_drvdata(pdev); 808 + struct ei_device *ei_local = netdev_priv(dev); 809 + struct ax_device *ax = to_ax_dev(dev); 810 + struct resource *mem; 799 811 800 812 unregister_netdev(dev); 801 813 free_irq(dev->irq, dev); 802 814 803 - iounmap(ei_status.mem); 804 - release_resource(ax->mem); 805 - kfree(ax->mem); 815 + iounmap(ei_local->mem); 816 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 817 + release_mem_region(mem->start, resource_size(mem)); 806 818 807 819 if (ax->map2) { 808 820 iounmap(ax->map2); 809 - release_resource(ax->mem2); 810 - kfree(ax->mem2); 821 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 1); 822 + release_mem_region(mem->start, resource_size(mem)); 811 823 } 812 824 813 825 free_netdev(dev); ··· 815 827 return 0; 816 828 } 817 829 818 - /* ax_probe 830 + /* 831 + * ax_probe 819 832 * 820 833 * This is the entry point when the platform device system uses to 821 - * notify us of a new device to attach to. Allocate memory, find 822 - * the resources and information passed, and map the necessary registers. 823 - */ 824 - 834 + * notify us of a new device to attach to. Allocate memory, find the 835 + * resources and information passed, and map the necessary registers. 836 + */ 825 837 static int ax_probe(struct platform_device *pdev) 826 838 { 827 839 struct net_device *dev; 828 - struct ax_device *ax; 829 - struct resource *res; 830 - size_t size; 840 + struct ei_device *ei_local; 841 + struct ax_device *ax; 842 + struct resource *irq, *mem, *mem2; 843 + resource_size_t mem_size, mem2_size = 0; 831 844 int ret = 0; 832 845 833 846 dev = ax__alloc_ei_netdev(sizeof(struct ax_device)); ··· 836 847 return -ENOMEM; 837 848 838 849 /* ok, let's setup our device */ 850 + SET_NETDEV_DEV(dev, &pdev->dev); 851 + ei_local = netdev_priv(dev); 839 852 ax = to_ax_dev(dev); 840 853 841 - memset(ax, 0, sizeof(struct ax_device)); 842 - 843 - spin_lock_init(&ax->mii_lock); 844 - 845 - ax->dev = pdev; 846 854 ax->plat = pdev->dev.platform_data; 847 855 platform_set_drvdata(pdev, dev); 848 856 849 - ei_status.rxcr_base = ax->plat->rcr_val; 857 + ei_local->rxcr_base = ax->plat->rcr_val; 850 858 851 859 /* find the platform resources */ 852 - 853 - res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 854 - if (res == NULL) { 860 + irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 861 + if (!irq) { 855 862 dev_err(&pdev->dev, "no IRQ specified\n"); 856 863 ret = -ENXIO; 857 864 goto exit_mem; 858 865 } 859 866 860 - dev->irq = res->start; 861 - ax->irqflags = res->flags & IRQF_TRIGGER_MASK; 867 + dev->irq = irq->start; 868 + ax->irqflags = irq->flags & IRQF_TRIGGER_MASK; 862 869 863 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 864 - if (res == NULL) { 870 + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 871 + if (!mem) { 865 872 dev_err(&pdev->dev, "no MEM specified\n"); 866 873 ret = -ENXIO; 867 874 goto exit_mem; 868 875 } 869 876 870 - size = (res->end - res->start) + 1; 877 + mem_size = resource_size(mem); 871 878 872 - /* setup the register offsets from either the platform data 873 - * or by using the size of the resource provided */ 874 - 879 + /* 880 + * setup the register offsets from either the platform data or 881 + * by using the size of the resource provided 882 + */ 875 883 if (ax->plat->reg_offsets) 876 - ei_status.reg_offset = ax->plat->reg_offsets; 884 + ei_local->reg_offset = ax->plat->reg_offsets; 877 885 else { 878 - ei_status.reg_offset = ax->reg_offsets; 886 + ei_local->reg_offset = ax->reg_offsets; 879 887 for (ret = 0; ret < 0x18; ret++) 880 - ax->reg_offsets[ret] = (size / 0x18) * ret; 888 + ax->reg_offsets[ret] = (mem_size / 0x18) * ret; 881 889 } 882 890 883 - ax->mem = request_mem_region(res->start, size, pdev->name); 884 - if (ax->mem == NULL) { 891 + if (!request_mem_region(mem->start, mem_size, pdev->name)) { 885 892 dev_err(&pdev->dev, "cannot reserve registers\n"); 886 - ret = -ENXIO; 893 + ret = -ENXIO; 887 894 goto exit_mem; 888 895 } 889 896 890 - ei_status.mem = ioremap(res->start, size); 891 - dev->base_addr = (unsigned long)ei_status.mem; 897 + ei_local->mem = ioremap(mem->start, mem_size); 898 + dev->base_addr = (unsigned long)ei_local->mem; 892 899 893 - if (ei_status.mem == NULL) { 894 - dev_err(&pdev->dev, "Cannot ioremap area (%08llx,%08llx)\n", 895 - (unsigned long long)res->start, 896 - (unsigned long long)res->end); 900 + if (ei_local->mem == NULL) { 901 + dev_err(&pdev->dev, "Cannot ioremap area %pR\n", mem); 897 902 898 - ret = -ENXIO; 903 + ret = -ENXIO; 899 904 goto exit_req; 900 905 } 901 906 902 907 /* look for reset area */ 903 - 904 - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); 905 - if (res == NULL) { 908 + mem2 = platform_get_resource(pdev, IORESOURCE_MEM, 1); 909 + if (!mem2) { 906 910 if (!ax->plat->reg_offsets) { 907 911 for (ret = 0; ret < 0x20; ret++) 908 - ax->reg_offsets[ret] = (size / 0x20) * ret; 912 + ax->reg_offsets[ret] = (mem_size / 0x20) * ret; 909 913 } 910 - 911 - ax->map2 = NULL; 912 914 } else { 913 - size = (res->end - res->start) + 1; 915 + mem2_size = resource_size(mem2); 914 916 915 - ax->mem2 = request_mem_region(res->start, size, pdev->name); 916 - if (ax->mem2 == NULL) { 917 + if (!request_mem_region(mem2->start, mem2_size, pdev->name)) { 917 918 dev_err(&pdev->dev, "cannot reserve registers\n"); 918 919 ret = -ENXIO; 919 920 goto exit_mem1; 920 921 } 921 922 922 - ax->map2 = ioremap(res->start, size); 923 - if (ax->map2 == NULL) { 923 + ax->map2 = ioremap(mem2->start, mem2_size); 924 + if (!ax->map2) { 924 925 dev_err(&pdev->dev, "cannot map reset register\n"); 925 926 ret = -ENXIO; 926 927 goto exit_mem2; 927 928 } 928 929 929 - ei_status.reg_offset[0x1f] = ax->map2 - ei_status.mem; 930 + ei_local->reg_offset[0x1f] = ax->map2 - ei_local->mem; 930 931 } 931 932 932 933 /* got resources, now initialise and register device */ 933 - 934 - ret = ax_init_dev(dev, 1); 934 + ret = ax_init_dev(dev); 935 935 if (!ret) 936 936 return 0; 937 937 938 - if (ax->map2 == NULL) 938 + if (!ax->map2) 939 939 goto exit_mem1; 940 940 941 941 iounmap(ax->map2); 942 942 943 943 exit_mem2: 944 - release_resource(ax->mem2); 945 - kfree(ax->mem2); 944 + release_mem_region(mem2->start, mem2_size); 946 945 947 946 exit_mem1: 948 - iounmap(ei_status.mem); 947 + iounmap(ei_local->mem); 949 948 950 949 exit_req: 951 - release_resource(ax->mem); 952 - kfree(ax->mem); 950 + release_mem_region(mem->start, mem_size); 953 951 954 952 exit_mem: 955 953 free_netdev(dev); ··· 950 974 static int ax_suspend(struct platform_device *dev, pm_message_t state) 951 975 { 952 976 struct net_device *ndev = platform_get_drvdata(dev); 953 - struct ax_device *ax = to_ax_dev(ndev); 977 + struct ax_device *ax = to_ax_dev(ndev); 954 978 955 979 ax->resume_open = ax->running; 956 980 ··· 963 987 static int ax_resume(struct platform_device *pdev) 964 988 { 965 989 struct net_device *ndev = platform_get_drvdata(pdev); 966 - struct ax_device *ax = to_ax_dev(ndev); 990 + struct ax_device *ax = to_ax_dev(ndev); 967 991 968 992 ax_initial_setup(ndev, netdev_priv(ndev)); 969 993 ax_NS8390_init(ndev, ax->resume_open); ··· 977 1001 978 1002 #else 979 1003 #define ax_suspend NULL 980 - #define ax_resume NULL 1004 + #define ax_resume NULL 981 1005 #endif 982 1006 983 1007 static struct platform_driver axdrv = {