1 /* drivers/net/ax88796.c
3 * Copyright 2005,2007 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
6 * Asix AX88796 10/100 Ethernet controller support
7 * Based on ne.c, by Donald Becker, et-al.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/isapnp.h>
18 #include <linux/init.h>
19 #include <linux/interrupt.h>
21 #include <linux/platform_device.h>
22 #include <linux/delay.h>
23 #include <linux/timer.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/ethtool.h>
27 #include <linux/mii.h>
28 #include <linux/eeprom_93cx6.h>
29 #include <linux/slab.h>
31 #include <net/ax88796.h>
33 #include <asm/system.h>
37 /* 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
41 #define __ei_start_xmit ax_ei_start_xmit
42 #define __ei_tx_timeout ax_ei_tx_timeout
43 #define __ei_get_stats ax_ei_get_stats
44 #define __ei_set_multicast_list ax_ei_set_multicast_list
45 #define __ei_interrupt ax_ei_interrupt
46 #define ____alloc_ei_netdev ax__alloc_ei_netdev
47 #define __NS8390_init ax_NS8390_init
49 /* force unsigned long back to 'void __iomem *' */
50 #define ax_convert_addr(_a) ((void __force __iomem *)(_a))
52 #define ei_inb(_a) readb(ax_convert_addr(_a))
53 #define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a))
55 #define ei_inb_p(_a) ei_inb(_a)
56 #define ei_outb_p(_v, _a) ei_outb(_v, _a)
58 /* define EI_SHIFT() to take into account our register offsets */
59 #define EI_SHIFT(x) (ei_local->reg_offset[(x)])
61 /* Ensure we have our RCR base value */
62 #define AX88796_PLATFORM
64 static unsigned char version
[] = "ax88796.c: Copyright 2005,2007 Simtec Electronics\n";
68 #define DRV_NAME "ax88796"
69 #define DRV_VERSION "1.00"
72 #define NE_CMD EI_SHIFT(0x00)
73 #define NE_RESET EI_SHIFT(0x1f)
74 #define NE_DATAPORT EI_SHIFT(0x10)
76 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
77 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
78 #define NESM_START_PG 0x40 /* First page of TX buffer */
79 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
81 /* device private data */
84 struct timer_list mii_timer
;
86 struct mii_if_info mii
;
91 struct resource
*mem2
;
92 const struct ax_plat_data
*plat
;
94 unsigned char running
;
95 unsigned char resume_open
;
96 unsigned int irqflags
;
98 u32 reg_offsets
[0x20];
101 static inline struct ax_device
*to_ax_dev(struct net_device
*dev
)
103 struct ei_device
*ei_local
= netdev_priv(dev
);
104 return (struct ax_device
*)(ei_local
+ 1);
110 * do an initial probe for the card to check wether it exists
113 static int ax_initial_check(struct net_device
*dev
)
115 struct ei_device
*ei_local
= netdev_priv(dev
);
116 void __iomem
*ioaddr
= ei_local
->mem
;
120 reg0
= ei_inb(ioaddr
);
124 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
125 regd
= ei_inb(ioaddr
+ 0x0d);
126 ei_outb(0xff, ioaddr
+ 0x0d);
127 ei_outb(E8390_NODMA
+ E8390_PAGE0
, ioaddr
+ E8390_CMD
);
128 ei_inb(ioaddr
+ EN0_COUNTER0
); /* Clear the counter by reading. */
129 if (ei_inb(ioaddr
+ EN0_COUNTER0
) != 0) {
130 ei_outb(reg0
, ioaddr
);
131 ei_outb(regd
, ioaddr
+ 0x0d); /* Restore the old values. */
139 * Hard reset the card. This used to pause for the same period that a
140 * 8390 reset command required, but that shouldn't be necessary.
142 static void ax_reset_8390(struct net_device
*dev
)
144 struct ei_device
*ei_local
= netdev_priv(dev
);
145 unsigned long reset_start_time
= jiffies
;
146 void __iomem
*addr
= (void __iomem
*)dev
->base_addr
;
149 netdev_dbg(dev
, "resetting the 8390 t=%ld\n", jiffies
);
151 ei_outb(ei_inb(addr
+ NE_RESET
), addr
+ NE_RESET
);
154 ei_local
->dmaing
= 0;
156 /* This check _should_not_ be necessary, omit eventually. */
157 while ((ei_inb(addr
+ EN0_ISR
) & ENISR_RESET
) == 0) {
158 if (jiffies
- reset_start_time
> 2 * HZ
/ 100) {
159 netdev_warn(dev
, "%s: did not complete.\n", __func__
);
164 ei_outb(ENISR_RESET
, addr
+ EN0_ISR
); /* Ack intr. */
168 static void ax_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
171 struct ei_device
*ei_local
= netdev_priv(dev
);
172 void __iomem
*nic_base
= ei_local
->mem
;
174 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
175 if (ei_local
->dmaing
) {
176 netdev_err(dev
, "DMAing conflict in %s "
177 "[DMAstat:%d][irqlock:%d].\n",
179 ei_local
->dmaing
, ei_local
->irqlock
);
183 ei_local
->dmaing
|= 0x01;
184 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_START
, nic_base
+ NE_CMD
);
185 ei_outb(sizeof(struct e8390_pkt_hdr
), nic_base
+ EN0_RCNTLO
);
186 ei_outb(0, nic_base
+ EN0_RCNTHI
);
187 ei_outb(0, nic_base
+ EN0_RSARLO
); /* On page boundary */
188 ei_outb(ring_page
, nic_base
+ EN0_RSARHI
);
189 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
191 if (ei_local
->word16
)
192 readsw(nic_base
+ NE_DATAPORT
, hdr
,
193 sizeof(struct e8390_pkt_hdr
) >> 1);
195 readsb(nic_base
+ NE_DATAPORT
, hdr
,
196 sizeof(struct e8390_pkt_hdr
));
198 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
199 ei_local
->dmaing
&= ~0x01;
201 le16_to_cpus(&hdr
->count
);
206 * Block input and output, similar to the Crynwr packet driver. If
207 * you are porting to a new ethercard, look at the packet driver
208 * source for hints. The NEx000 doesn't share the on-board packet
209 * memory -- you have to put the packet out through the "remote DMA"
210 * dataport using ei_outb.
212 static void ax_block_input(struct net_device
*dev
, int count
,
213 struct sk_buff
*skb
, int ring_offset
)
215 struct ei_device
*ei_local
= netdev_priv(dev
);
216 void __iomem
*nic_base
= ei_local
->mem
;
217 char *buf
= skb
->data
;
219 if (ei_local
->dmaing
) {
221 "DMAing conflict in %s "
222 "[DMAstat:%d][irqlock:%d].\n",
224 ei_local
->dmaing
, ei_local
->irqlock
);
228 ei_local
->dmaing
|= 0x01;
230 ei_outb(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
231 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
232 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
233 ei_outb(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
234 ei_outb(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
235 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
237 if (ei_local
->word16
) {
238 readsw(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
240 buf
[count
-1] = ei_inb(nic_base
+ NE_DATAPORT
);
243 readsb(nic_base
+ NE_DATAPORT
, buf
, count
);
246 ei_local
->dmaing
&= ~1;
249 static void ax_block_output(struct net_device
*dev
, int count
,
250 const unsigned char *buf
, const int start_page
)
252 struct ei_device
*ei_local
= netdev_priv(dev
);
253 void __iomem
*nic_base
= ei_local
->mem
;
254 unsigned long dma_start
;
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.
261 if (ei_local
->word16
&& (count
& 0x01))
264 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
265 if (ei_local
->dmaing
) {
266 netdev_err(dev
, "DMAing conflict in %s."
267 "[DMAstat:%d][irqlock:%d]\n",
269 ei_local
->dmaing
, ei_local
->irqlock
);
273 ei_local
->dmaing
|= 0x01;
274 /* We should already be in page 0, but to be safe... */
275 ei_outb(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
+ NE_CMD
);
277 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
);
279 /* Now the normal output. */
280 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
281 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
282 ei_outb(0x00, nic_base
+ EN0_RSARLO
);
283 ei_outb(start_page
, nic_base
+ EN0_RSARHI
);
285 ei_outb(E8390_RWRITE
+E8390_START
, nic_base
+ NE_CMD
);
286 if (ei_local
->word16
)
287 writesw(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
289 writesb(nic_base
+ NE_DATAPORT
, buf
, count
);
293 while ((ei_inb(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0) {
294 if (jiffies
- dma_start
> 2 * HZ
/ 100) { /* 20ms */
295 netdev_warn(dev
, "timeout waiting for Tx RDC.\n");
297 ax_NS8390_init(dev
, 1);
302 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
303 ei_local
->dmaing
&= ~0x01;
306 /* definitions for accessing MII/EEPROM interface */
308 #define AX_MEMR EI_SHIFT(0x14)
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)
321 * write the specified set of bits to the phy
324 ax_mii_ei_outbits(struct net_device
*dev
, unsigned int bits
, int len
)
326 struct ei_device
*ei_local
= netdev_priv(dev
);
327 void __iomem
*memr_addr
= (void __iomem
*)dev
->base_addr
+ AX_MEMR
;
330 /* clock low, data to output mode */
331 memr
= ei_inb(memr_addr
);
332 memr
&= ~(AX_MEMR_MDC
| AX_MEMR_MDIR
);
333 ei_outb(memr
, memr_addr
);
335 for (len
--; len
>= 0; len
--) {
336 if (bits
& (1 << len
))
339 memr
&= ~AX_MEMR_MDO
;
341 ei_outb(memr
, memr_addr
);
345 ei_outb(memr
| AX_MEMR_MDC
, memr_addr
);
349 ei_outb(memr
, memr_addr
);
352 /* leaves the clock line low, mdir input */
353 memr
|= AX_MEMR_MDIR
;
354 ei_outb(memr
, (void __iomem
*)dev
->base_addr
+ AX_MEMR
);
360 * read a specified number of bits from the phy
363 ax_phy_ei_inbits(struct net_device
*dev
, int no
)
365 struct ei_device
*ei_local
= netdev_priv(dev
);
366 void __iomem
*memr_addr
= (void __iomem
*)dev
->base_addr
+ AX_MEMR
;
368 unsigned int result
= 0;
370 /* clock low, data to input mode */
371 memr
= ei_inb(memr_addr
);
372 memr
&= ~AX_MEMR_MDC
;
373 memr
|= AX_MEMR_MDIR
;
374 ei_outb(memr
, memr_addr
);
376 for (no
--; no
>= 0; no
--) {
377 ei_outb(memr
| AX_MEMR_MDC
, memr_addr
);
381 if (ei_inb(memr_addr
) & AX_MEMR_MDI
)
384 ei_outb(memr
, memr_addr
);
393 * use the low level bit shifting routines to send the address
394 * and command to the specified phy
397 ax_phy_issueaddr(struct net_device
*dev
, int phy_addr
, int reg
, int opc
)
400 netdev_dbg(dev
, "%s: dev %p, %04x, %04x, %d\n",
401 __func__
, dev
, phy_addr
, reg
, opc
);
403 ax_mii_ei_outbits(dev
, 0x3f, 6); /* pre-amble */
404 ax_mii_ei_outbits(dev
, 1, 2); /* frame-start */
405 ax_mii_ei_outbits(dev
, opc
, 2); /* op code */
406 ax_mii_ei_outbits(dev
, phy_addr
, 5); /* phy address */
407 ax_mii_ei_outbits(dev
, reg
, 5); /* reg address */
411 ax_phy_read(struct net_device
*dev
, int phy_addr
, int reg
)
413 struct ei_device
*ei_local
= netdev_priv(dev
);
417 spin_lock_irqsave(&ei_local
->page_lock
, flags
);
419 ax_phy_issueaddr(dev
, phy_addr
, reg
, 2);
421 result
= ax_phy_ei_inbits(dev
, 17);
422 result
&= ~(3 << 16);
424 spin_unlock_irqrestore(&ei_local
->page_lock
, flags
);
427 netdev_dbg(dev
, "%s: %04x.%04x => read %04x\n", __func__
,
428 phy_addr
, reg
, result
);
434 ax_phy_write(struct net_device
*dev
, int phy_addr
, int reg
, int value
)
436 struct ei_device
*ei
= netdev_priv(dev
);
439 netdev_dbg(dev
, "%s: %p, %04x, %04x %04x\n",
440 __func__
, dev
, phy_addr
, reg
, value
);
442 spin_lock_irqsave(&ei
->page_lock
, flags
);
444 ax_phy_issueaddr(dev
, phy_addr
, reg
, 1);
445 ax_mii_ei_outbits(dev
, 2, 2); /* send TA */
446 ax_mii_ei_outbits(dev
, value
, 16);
448 spin_unlock_irqrestore(&ei
->page_lock
, flags
);
451 static void ax_mii_expiry(unsigned long data
)
453 struct net_device
*dev
= (struct net_device
*)data
;
454 struct ax_device
*ax
= to_ax_dev(dev
);
457 spin_lock_irqsave(&ax
->mii_lock
, flags
);
458 mii_check_media(&ax
->mii
, netif_msg_link(ax
), 0);
459 spin_unlock_irqrestore(&ax
->mii_lock
, flags
);
462 ax
->mii_timer
.expires
= jiffies
+ HZ
*2;
463 add_timer(&ax
->mii_timer
);
467 static int ax_open(struct net_device
*dev
)
469 struct ax_device
*ax
= to_ax_dev(dev
);
470 struct ei_device
*ei_local
= netdev_priv(dev
);
473 netdev_dbg(dev
, "open\n");
475 ret
= request_irq(dev
->irq
, ax_ei_interrupt
, ax
->irqflags
,
480 ret
= ax_ei_open(dev
);
482 free_irq(dev
->irq
, dev
);
486 /* turn the phy on (if turned off) */
488 ei_outb(ax
->plat
->gpoc_val
, ei_local
->mem
+ EI_SHIFT(0x17));
491 /* start the MII timer */
493 init_timer(&ax
->mii_timer
);
495 ax
->mii_timer
.expires
= jiffies
+ 1;
496 ax
->mii_timer
.data
= (unsigned long) dev
;
497 ax
->mii_timer
.function
= ax_mii_expiry
;
499 add_timer(&ax
->mii_timer
);
504 static int ax_close(struct net_device
*dev
)
506 struct ax_device
*ax
= to_ax_dev(dev
);
507 struct ei_device
*ei_local
= netdev_priv(dev
);
509 netdev_dbg(dev
, "close\n");
511 /* turn the phy off */
513 ei_outb(ax
->plat
->gpoc_val
| (1 << 6),
514 ei_local
->mem
+ EI_SHIFT(0x17));
519 del_timer_sync(&ax
->mii_timer
);
522 free_irq(dev
->irq
, dev
);
526 static int ax_ioctl(struct net_device
*dev
, struct ifreq
*req
, int cmd
)
528 struct ax_device
*ax
= to_ax_dev(dev
);
532 if (!netif_running(dev
))
535 spin_lock_irqsave(&ax
->mii_lock
, flags
);
536 rc
= generic_mii_ioctl(&ax
->mii
, if_mii(req
), cmd
, NULL
);
537 spin_unlock_irqrestore(&ax
->mii_lock
, flags
);
544 static void ax_get_drvinfo(struct net_device
*dev
,
545 struct ethtool_drvinfo
*info
)
547 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
549 strcpy(info
->driver
, DRV_NAME
);
550 strcpy(info
->version
, DRV_VERSION
);
551 strcpy(info
->bus_info
, pdev
->name
);
554 static int ax_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
556 struct ax_device
*ax
= to_ax_dev(dev
);
559 spin_lock_irqsave(&ax
->mii_lock
, flags
);
560 mii_ethtool_gset(&ax
->mii
, cmd
);
561 spin_unlock_irqrestore(&ax
->mii_lock
, flags
);
566 static int ax_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
568 struct ax_device
*ax
= to_ax_dev(dev
);
572 spin_lock_irqsave(&ax
->mii_lock
, flags
);
573 rc
= mii_ethtool_sset(&ax
->mii
, cmd
);
574 spin_unlock_irqrestore(&ax
->mii_lock
, flags
);
579 static int ax_nway_reset(struct net_device
*dev
)
581 struct ax_device
*ax
= to_ax_dev(dev
);
582 return mii_nway_restart(&ax
->mii
);
585 static u32
ax_get_link(struct net_device
*dev
)
587 struct ax_device
*ax
= to_ax_dev(dev
);
588 return mii_link_ok(&ax
->mii
);
591 static const struct ethtool_ops ax_ethtool_ops
= {
592 .get_drvinfo
= ax_get_drvinfo
,
593 .get_settings
= ax_get_settings
,
594 .set_settings
= ax_set_settings
,
595 .nway_reset
= ax_nway_reset
,
596 .get_link
= ax_get_link
,
599 #ifdef CONFIG_AX88796_93CX6
600 static void ax_eeprom_register_read(struct eeprom_93cx6
*eeprom
)
602 struct ei_device
*ei_local
= eeprom
->data
;
603 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
605 eeprom
->reg_data_in
= reg
& AX_MEMR_EEI
;
606 eeprom
->reg_data_out
= reg
& AX_MEMR_EEO
; /* Input pin */
607 eeprom
->reg_data_clock
= reg
& AX_MEMR_EECLK
;
608 eeprom
->reg_chip_select
= reg
& AX_MEMR_EECS
;
611 static void ax_eeprom_register_write(struct eeprom_93cx6
*eeprom
)
613 struct ei_device
*ei_local
= eeprom
->data
;
614 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
616 reg
&= ~(AX_MEMR_EEI
| AX_MEMR_EECLK
| AX_MEMR_EECS
);
618 if (eeprom
->reg_data_in
)
620 if (eeprom
->reg_data_clock
)
621 reg
|= AX_MEMR_EECLK
;
622 if (eeprom
->reg_chip_select
)
625 ei_outb(reg
, ei_local
->mem
+ AX_MEMR
);
630 static const struct net_device_ops ax_netdev_ops
= {
632 .ndo_stop
= ax_close
,
633 .ndo_do_ioctl
= ax_ioctl
,
635 .ndo_start_xmit
= ax_ei_start_xmit
,
636 .ndo_tx_timeout
= ax_ei_tx_timeout
,
637 .ndo_get_stats
= ax_ei_get_stats
,
638 .ndo_set_multicast_list
= ax_ei_set_multicast_list
,
639 .ndo_validate_addr
= eth_validate_addr
,
640 .ndo_set_mac_address
= eth_mac_addr
,
641 .ndo_change_mtu
= eth_change_mtu
,
642 #ifdef CONFIG_NET_POLL_CONTROLLER
643 .ndo_poll_controller
= ax_ei_poll
,
649 static void ax_initial_setup(struct net_device
*dev
, struct ei_device
*ei_local
)
651 void __iomem
*ioaddr
= ei_local
->mem
;
652 struct ax_device
*ax
= to_ax_dev(dev
);
655 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
657 /* set to byte access */
658 ei_outb(ax
->plat
->dcr_val
& ~1, ioaddr
+ EN0_DCFG
);
659 ei_outb(ax
->plat
->gpoc_val
, ioaddr
+ EI_SHIFT(0x17));
665 * initialise the specified device, taking care to note the MAC
666 * address it may already have (if configured), ensure
667 * the device is ready to be used by lib8390.c and registerd with
670 static int ax_init_dev(struct net_device
*dev
)
672 struct ei_device
*ei_local
= netdev_priv(dev
);
673 struct ax_device
*ax
= to_ax_dev(dev
);
674 void __iomem
*ioaddr
= ei_local
->mem
;
675 unsigned int start_page
;
676 unsigned int stop_page
;
680 ret
= ax_initial_check(dev
);
684 /* setup goes here */
686 ax_initial_setup(dev
, ei_local
);
688 /* read the mac from the card prom if we need it */
690 if (ax
->plat
->flags
& AXFLG_HAS_EEPROM
) {
691 unsigned char SA_prom
[32];
693 for (i
= 0; i
< sizeof(SA_prom
); i
+= 2) {
694 SA_prom
[i
] = ei_inb(ioaddr
+ NE_DATAPORT
);
695 SA_prom
[i
+ 1] = ei_inb(ioaddr
+ NE_DATAPORT
);
698 if (ax
->plat
->wordlength
== 2)
699 for (i
= 0; i
< 16; i
++)
700 SA_prom
[i
] = SA_prom
[i
+i
];
702 memcpy(dev
->dev_addr
, SA_prom
, 6);
705 #ifdef CONFIG_AX88796_93CX6
706 if (ax
->plat
->flags
& AXFLG_HAS_93CX6
) {
707 unsigned char mac_addr
[6];
708 struct eeprom_93cx6 eeprom
;
710 eeprom
.data
= ei_local
;
711 eeprom
.register_read
= ax_eeprom_register_read
;
712 eeprom
.register_write
= ax_eeprom_register_write
;
713 eeprom
.width
= PCI_EEPROM_WIDTH_93C56
;
715 eeprom_93cx6_multiread(&eeprom
, 0,
716 (__le16 __force
*)mac_addr
,
717 sizeof(mac_addr
) >> 1);
719 memcpy(dev
->dev_addr
, mac_addr
, 6);
722 if (ax
->plat
->wordlength
== 2) {
723 /* We must set the 8390 for word mode. */
724 ei_outb(ax
->plat
->dcr_val
, ei_local
->mem
+ EN0_DCFG
);
725 start_page
= NESM_START_PG
;
726 stop_page
= NESM_STOP_PG
;
728 start_page
= NE1SM_START_PG
;
729 stop_page
= NE1SM_STOP_PG
;
732 /* load the mac-address from the device */
733 if (ax
->plat
->flags
& AXFLG_MAC_FROMDEV
) {
734 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
,
735 ei_local
->mem
+ E8390_CMD
); /* 0x61 */
736 for (i
= 0; i
< ETHER_ADDR_LEN
; i
++)
738 ei_inb(ioaddr
+ EN1_PHYS_SHIFT(i
));
741 if ((ax
->plat
->flags
& AXFLG_MAC_FROMPLATFORM
) &&
743 memcpy(dev
->dev_addr
, ax
->plat
->mac_addr
,
748 ei_local
->name
= "AX88796";
749 ei_local
->tx_start_page
= start_page
;
750 ei_local
->stop_page
= stop_page
;
751 ei_local
->word16
= (ax
->plat
->wordlength
== 2);
752 ei_local
->rx_start_page
= start_page
+ TX_PAGES
;
754 #ifdef PACKETBUF_MEMSIZE
755 /* Allow the packet buffer size to be overridden by know-it-alls. */
756 ei_local
->stop_page
= ei_local
->tx_start_page
+ PACKETBUF_MEMSIZE
;
759 ei_local
->reset_8390
= &ax_reset_8390
;
760 ei_local
->block_input
= &ax_block_input
;
761 ei_local
->block_output
= &ax_block_output
;
762 ei_local
->get_8390_hdr
= &ax_get_8390_hdr
;
765 dev
->netdev_ops
= &ax_netdev_ops
;
766 dev
->ethtool_ops
= &ax_ethtool_ops
;
768 ax
->msg_enable
= NETIF_MSG_LINK
;
769 ax
->mii
.phy_id_mask
= 0x1f;
770 ax
->mii
.reg_num_mask
= 0x1f;
771 ax
->mii
.phy_id
= 0x10; /* onboard phy */
772 ax
->mii
.force_media
= 0;
773 ax
->mii
.full_duplex
= 0;
774 ax
->mii
.mdio_read
= ax_phy_read
;
775 ax
->mii
.mdio_write
= ax_phy_write
;
778 ax_NS8390_init(dev
, 0);
780 ret
= register_netdev(dev
);
784 netdev_info(dev
, "%dbit, irq %d, %lx, MAC: %pM\n",
785 ei_local
->word16
? 16 : 8, dev
->irq
, dev
->base_addr
,
792 free_irq(dev
->irq
, dev
);
797 static int ax_remove(struct platform_device
*_dev
)
799 struct net_device
*dev
= platform_get_drvdata(_dev
);
800 struct ei_device
*ei_local
= netdev_priv(dev
);
801 struct ax_device
*ax
;
805 unregister_netdev(dev
);
806 free_irq(dev
->irq
, dev
);
808 iounmap(ei_local
->mem
);
809 release_resource(ax
->mem
);
814 release_resource(ax
->mem2
);
826 * This is the entry point when the platform device system uses to
827 * notify us of a new device to attach to. Allocate memory, find the
828 * resources and information passed, and map the necessary registers.
830 static int ax_probe(struct platform_device
*pdev
)
832 struct net_device
*dev
;
833 struct ei_device
*ei_local
;
834 struct ax_device
*ax
;
835 struct resource
*res
;
839 dev
= ax__alloc_ei_netdev(sizeof(struct ax_device
));
843 /* ok, let's setup our device */
844 SET_NETDEV_DEV(dev
, &pdev
->dev
);
845 ei_local
= netdev_priv(dev
);
848 spin_lock_init(&ax
->mii_lock
);
850 ax
->plat
= pdev
->dev
.platform_data
;
851 platform_set_drvdata(pdev
, dev
);
853 ei_local
->rxcr_base
= ax
->plat
->rcr_val
;
855 /* find the platform resources */
856 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
858 dev_err(&pdev
->dev
, "no IRQ specified\n");
863 dev
->irq
= res
->start
;
864 ax
->irqflags
= res
->flags
& IRQF_TRIGGER_MASK
;
866 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
868 dev_err(&pdev
->dev
, "no MEM specified\n");
873 size
= (res
->end
- res
->start
) + 1;
876 * setup the register offsets from either the platform data or
877 * by using the size of the resource provided
879 if (ax
->plat
->reg_offsets
)
880 ei_local
->reg_offset
= ax
->plat
->reg_offsets
;
882 ei_local
->reg_offset
= ax
->reg_offsets
;
883 for (ret
= 0; ret
< 0x18; ret
++)
884 ax
->reg_offsets
[ret
] = (size
/ 0x18) * ret
;
887 ax
->mem
= request_mem_region(res
->start
, size
, pdev
->name
);
888 if (ax
->mem
== NULL
) {
889 dev_err(&pdev
->dev
, "cannot reserve registers\n");
894 ei_local
->mem
= ioremap(res
->start
, size
);
895 dev
->base_addr
= (unsigned long)ei_local
->mem
;
897 if (ei_local
->mem
== NULL
) {
898 dev_err(&pdev
->dev
, "Cannot ioremap area (%08llx,%08llx)\n",
899 (unsigned long long)res
->start
,
900 (unsigned long long)res
->end
);
906 /* look for reset area */
908 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
910 if (!ax
->plat
->reg_offsets
) {
911 for (ret
= 0; ret
< 0x20; ret
++)
912 ax
->reg_offsets
[ret
] = (size
/ 0x20) * ret
;
917 size
= (res
->end
- res
->start
) + 1;
919 ax
->mem2
= request_mem_region(res
->start
, size
, pdev
->name
);
920 if (ax
->mem2
== NULL
) {
921 dev_err(&pdev
->dev
, "cannot reserve registers\n");
926 ax
->map2
= ioremap(res
->start
, size
);
927 if (ax
->map2
== NULL
) {
928 dev_err(&pdev
->dev
, "cannot map reset register\n");
933 ei_local
->reg_offset
[0x1f] = ax
->map2
- ei_local
->mem
;
936 /* got resources, now initialise and register device */
938 ret
= ax_init_dev(dev
);
942 if (ax
->map2
== NULL
)
948 release_resource(ax
->mem2
);
952 iounmap(ei_local
->mem
);
955 release_resource(ax
->mem
);
964 /* suspend and resume */
967 static int ax_suspend(struct platform_device
*dev
, pm_message_t state
)
969 struct net_device
*ndev
= platform_get_drvdata(dev
);
970 struct ax_device
*ax
= to_ax_dev(ndev
);
972 ax
->resume_open
= ax
->running
;
974 netif_device_detach(ndev
);
980 static int ax_resume(struct platform_device
*pdev
)
982 struct net_device
*ndev
= platform_get_drvdata(pdev
);
983 struct ax_device
*ax
= to_ax_dev(ndev
);
985 ax_initial_setup(ndev
, netdev_priv(ndev
));
986 ax_NS8390_init(ndev
, ax
->resume_open
);
987 netif_device_attach(ndev
);
996 #define ax_suspend NULL
997 #define ax_resume NULL
1000 static struct platform_driver axdrv
= {
1003 .owner
= THIS_MODULE
,
1006 .remove
= ax_remove
,
1007 .suspend
= ax_suspend
,
1008 .resume
= ax_resume
,
1011 static int __init
axdrv_init(void)
1013 return platform_driver_register(&axdrv
);
1016 static void __exit
axdrv_exit(void)
1018 platform_driver_unregister(&axdrv
);
1021 module_init(axdrv_init
);
1022 module_exit(axdrv_exit
);
1024 MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
1025 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
1026 MODULE_LICENSE("GPL v2");
1027 MODULE_ALIAS("platform:ax88796");