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>
20 #include <linux/platform_device.h>
21 #include <linux/delay.h>
22 #include <linux/timer.h>
23 #include <linux/netdevice.h>
24 #include <linux/etherdevice.h>
25 #include <linux/ethtool.h>
26 #include <linux/mii.h>
27 #include <linux/eeprom_93cx6.h>
28 #include <linux/slab.h>
30 #include <net/ax88796.h>
32 #include <asm/system.h>
35 static int phy_debug
= 0;
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
;
90 struct platform_device
*dev
;
92 struct resource
*mem2
;
93 struct ax_plat_data
*plat
;
95 unsigned char running
;
96 unsigned char resume_open
;
97 unsigned int irqflags
;
99 u32 reg_offsets
[0x20];
102 static inline struct ax_device
*to_ax_dev(struct net_device
*dev
)
104 struct ei_device
*ei_local
= netdev_priv(dev
);
105 return (struct ax_device
*)(ei_local
+1);
110 * do an initial probe for the card to check wether it exists
114 static int ax_initial_check(struct net_device
*dev
)
116 struct ei_device
*ei_local
= netdev_priv(dev
);
117 void __iomem
*ioaddr
= ei_local
->mem
;
121 reg0
= ei_inb(ioaddr
);
125 ei_outb(E8390_NODMA
+E8390_PAGE1
+E8390_STOP
, ioaddr
+ E8390_CMD
);
126 regd
= ei_inb(ioaddr
+ 0x0d);
127 ei_outb(0xff, ioaddr
+ 0x0d);
128 ei_outb(E8390_NODMA
+E8390_PAGE0
, ioaddr
+ E8390_CMD
);
129 ei_inb(ioaddr
+ EN0_COUNTER0
); /* Clear the counter by reading. */
130 if (ei_inb(ioaddr
+ EN0_COUNTER0
) != 0) {
131 ei_outb(reg0
, ioaddr
);
132 ei_outb(regd
, ioaddr
+ 0x0d); /* Restore the old values. */
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 struct ax_device
*ax
= to_ax_dev(dev
);
146 unsigned long reset_start_time
= jiffies
;
147 void __iomem
*addr
= (void __iomem
*)dev
->base_addr
;
150 dev_dbg(&ax
->dev
->dev
, "resetting the 8390 t=%ld\n", jiffies
);
152 ei_outb(ei_inb(addr
+ NE_RESET
), addr
+ NE_RESET
);
155 ei_status
.dmaing
= 0;
157 /* This check _should_not_ be necessary, omit eventually. */
158 while ((ei_inb(addr
+ EN0_ISR
) & ENISR_RESET
) == 0) {
159 if (jiffies
- reset_start_time
> 2*HZ
/100) {
160 dev_warn(&ax
->dev
->dev
, "%s: %s did not complete.\n",
161 __func__
, dev
->name
);
166 ei_outb(ENISR_RESET
, addr
+ EN0_ISR
); /* Ack intr. */
170 static void ax_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
173 struct ei_device
*ei_local
= netdev_priv(dev
);
174 struct ax_device
*ax
= to_ax_dev(dev
);
175 void __iomem
*nic_base
= ei_local
->mem
;
177 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
178 if (ei_status
.dmaing
) {
179 dev_err(&ax
->dev
->dev
, "%s: DMAing conflict in %s "
180 "[DMAstat:%d][irqlock:%d].\n",
182 ei_status
.dmaing
, ei_status
.irqlock
);
186 ei_status
.dmaing
|= 0x01;
187 ei_outb(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
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
);
194 if (ei_status
.word16
)
195 readsw(nic_base
+ NE_DATAPORT
, hdr
, sizeof(struct e8390_pkt_hdr
)>>1);
197 readsb(nic_base
+ NE_DATAPORT
, hdr
, sizeof(struct e8390_pkt_hdr
));
199 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
200 ei_status
.dmaing
&= ~0x01;
202 le16_to_cpus(&hdr
->count
);
206 /* Block input and output, similar to the Crynwr packet driver. If you
207 are porting to a new ethercard, look at the packet driver source for hints.
208 The NEx000 doesn't share the on-board packet memory -- you have to put
209 the packet out through the "remote DMA" dataport using ei_outb. */
211 static void ax_block_input(struct net_device
*dev
, int count
,
212 struct sk_buff
*skb
, int ring_offset
)
214 struct ei_device
*ei_local
= netdev_priv(dev
);
215 struct ax_device
*ax
= to_ax_dev(dev
);
216 void __iomem
*nic_base
= ei_local
->mem
;
217 char *buf
= skb
->data
;
219 if (ei_status
.dmaing
) {
220 dev_err(&ax
->dev
->dev
,
221 "%s: DMAing conflict in %s "
222 "[DMAstat:%d][irqlock:%d].\n",
224 ei_status
.dmaing
, ei_status
.irqlock
);
228 ei_status
.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_status
.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_status
.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 struct ax_device
*ax
= to_ax_dev(dev
);
254 void __iomem
*nic_base
= ei_local
->mem
;
255 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?
259 I should check someday. */
261 if (ei_status
.word16
&& (count
& 0x01))
264 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
265 if (ei_status
.dmaing
) {
266 dev_err(&ax
->dev
->dev
, "%s: DMAing conflict in %s."
267 "[DMAstat:%d][irqlock:%d]\n",
269 ei_status
.dmaing
, ei_status
.irqlock
);
273 ei_status
.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_status
.word16
) {
287 writesw(nic_base
+ NE_DATAPORT
, buf
, count
>>1);
289 writesb(nic_base
+ NE_DATAPORT
, buf
, count
);
294 while ((ei_inb(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0) {
295 if (jiffies
- dma_start
> 2*HZ
/100) { /* 20ms */
296 dev_warn(&ax
->dev
->dev
,
297 "%s: timeout waiting for Tx RDC.\n", dev
->name
);
299 ax_NS8390_init(dev
,1);
304 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
305 ei_status
.dmaing
&= ~0x01;
309 /* definitions for accessing MII/EEPROM interface */
311 #define AX_MEMR EI_SHIFT(0x14)
312 #define AX_MEMR_MDC (1<<0)
313 #define AX_MEMR_MDIR (1<<1)
314 #define AX_MEMR_MDI (1<<2)
315 #define AX_MEMR_MDO (1<<3)
316 #define AX_MEMR_EECS (1<<4)
317 #define AX_MEMR_EEI (1<<5)
318 #define AX_MEMR_EEO (1<<6)
319 #define AX_MEMR_EECLK (1<<7)
323 * write the specified set of bits to the phy
327 ax_mii_ei_outbits(struct net_device
*dev
, unsigned int bits
, int len
)
329 struct ei_device
*ei_local
= (struct ei_device
*) netdev_priv(dev
);
330 void __iomem
*memr_addr
= (void __iomem
*)dev
->base_addr
+ AX_MEMR
;
333 /* clock low, data to output mode */
334 memr
= ei_inb(memr_addr
);
335 memr
&= ~(AX_MEMR_MDC
| AX_MEMR_MDIR
);
336 ei_outb(memr
, memr_addr
);
338 for (len
--; len
>= 0; len
--) {
339 if (bits
& (1 << len
))
342 memr
&= ~AX_MEMR_MDO
;
344 ei_outb(memr
, memr_addr
);
348 ei_outb(memr
| AX_MEMR_MDC
, memr_addr
);
352 ei_outb(memr
, memr_addr
);
355 /* leaves the clock line low, mdir input */
356 memr
|= AX_MEMR_MDIR
;
357 ei_outb(memr
, (void __iomem
*)dev
->base_addr
+ AX_MEMR
);
362 * read a specified number of bits from the phy
366 ax_phy_ei_inbits(struct net_device
*dev
, int no
)
368 struct ei_device
*ei_local
= (struct ei_device
*) netdev_priv(dev
);
369 void __iomem
*memr_addr
= (void __iomem
*)dev
->base_addr
+ AX_MEMR
;
371 unsigned int result
= 0;
373 /* clock low, data to input mode */
374 memr
= ei_inb(memr_addr
);
375 memr
&= ~AX_MEMR_MDC
;
376 memr
|= AX_MEMR_MDIR
;
377 ei_outb(memr
, memr_addr
);
379 for (no
--; no
>= 0; no
--) {
380 ei_outb(memr
| AX_MEMR_MDC
, memr_addr
);
384 if (ei_inb(memr_addr
) & AX_MEMR_MDI
)
387 ei_outb(memr
, memr_addr
);
395 * use the low level bit shifting routines to send the address
396 * and command to the specified phy
400 ax_phy_issueaddr(struct net_device
*dev
, int phy_addr
, int reg
, int opc
)
403 pr_debug("%s: dev %p, %04x, %04x, %d\n",
404 __func__
, dev
, phy_addr
, reg
, opc
);
406 ax_mii_ei_outbits(dev
, 0x3f, 6); /* pre-amble */
407 ax_mii_ei_outbits(dev
, 1, 2); /* frame-start */
408 ax_mii_ei_outbits(dev
, opc
, 2); /* op code */
409 ax_mii_ei_outbits(dev
, phy_addr
, 5); /* phy address */
410 ax_mii_ei_outbits(dev
, reg
, 5); /* reg address */
414 ax_phy_read(struct net_device
*dev
, int phy_addr
, int reg
)
416 struct ei_device
*ei_local
= (struct ei_device
*) netdev_priv(dev
);
420 spin_lock_irqsave(&ei_local
->page_lock
, flags
);
422 ax_phy_issueaddr(dev
, phy_addr
, reg
, 2);
424 result
= ax_phy_ei_inbits(dev
, 17);
427 spin_unlock_irqrestore(&ei_local
->page_lock
, flags
);
430 pr_debug("%s: %04x.%04x => read %04x\n", __func__
,
431 phy_addr
, reg
, result
);
437 ax_phy_write(struct net_device
*dev
, int phy_addr
, int reg
, int value
)
439 struct ei_device
*ei
= (struct ei_device
*) netdev_priv(dev
);
440 struct ax_device
*ax
= to_ax_dev(dev
);
443 dev_dbg(&ax
->dev
->dev
, "%s: %p, %04x, %04x %04x\n",
444 __func__
, dev
, phy_addr
, reg
, value
);
446 spin_lock_irqsave(&ei
->page_lock
, flags
);
448 ax_phy_issueaddr(dev
, phy_addr
, reg
, 1);
449 ax_mii_ei_outbits(dev
, 2, 2); /* send TA */
450 ax_mii_ei_outbits(dev
, value
, 16);
452 spin_unlock_irqrestore(&ei
->page_lock
, flags
);
455 static void ax_mii_expiry(unsigned long data
)
457 struct net_device
*dev
= (struct net_device
*)data
;
458 struct ax_device
*ax
= to_ax_dev(dev
);
461 spin_lock_irqsave(&ax
->mii_lock
, flags
);
462 mii_check_media(&ax
->mii
, netif_msg_link(ax
), 0);
463 spin_unlock_irqrestore(&ax
->mii_lock
, flags
);
466 ax
->mii_timer
.expires
= jiffies
+ HZ
*2;
467 add_timer(&ax
->mii_timer
);
471 static int ax_open(struct net_device
*dev
)
473 struct ax_device
*ax
= to_ax_dev(dev
);
474 struct ei_device
*ei_local
= netdev_priv(dev
);
477 dev_dbg(&ax
->dev
->dev
, "%s: open\n", dev
->name
);
479 ret
= request_irq(dev
->irq
, ax_ei_interrupt
, ax
->irqflags
,
484 ret
= ax_ei_open(dev
);
488 /* turn the phy on (if turned off) */
490 ei_outb(ax
->plat
->gpoc_val
, ei_local
->mem
+ EI_SHIFT(0x17));
493 /* start the MII timer */
495 init_timer(&ax
->mii_timer
);
497 ax
->mii_timer
.expires
= jiffies
+1;
498 ax
->mii_timer
.data
= (unsigned long) dev
;
499 ax
->mii_timer
.function
= ax_mii_expiry
;
501 add_timer(&ax
->mii_timer
);
506 static int ax_close(struct net_device
*dev
)
508 struct ax_device
*ax
= to_ax_dev(dev
);
509 struct ei_device
*ei_local
= netdev_priv(dev
);
511 dev_dbg(&ax
->dev
->dev
, "%s: close\n", dev
->name
);
513 /* turn the phy off */
515 ei_outb(ax
->plat
->gpoc_val
| (1<<6),
516 ei_local
->mem
+ EI_SHIFT(0x17));
521 del_timer_sync(&ax
->mii_timer
);
524 free_irq(dev
->irq
, dev
);
528 static int ax_ioctl(struct net_device
*dev
, struct ifreq
*req
, int cmd
)
530 struct ax_device
*ax
= to_ax_dev(dev
);
534 if (!netif_running(dev
))
537 spin_lock_irqsave(&ax
->mii_lock
, flags
);
538 rc
= generic_mii_ioctl(&ax
->mii
, if_mii(req
), cmd
, NULL
);
539 spin_unlock_irqrestore(&ax
->mii_lock
, flags
);
546 static void ax_get_drvinfo(struct net_device
*dev
,
547 struct ethtool_drvinfo
*info
)
549 struct ax_device
*ax
= to_ax_dev(dev
);
551 strcpy(info
->driver
, DRV_NAME
);
552 strcpy(info
->version
, DRV_VERSION
);
553 strcpy(info
->bus_info
, ax
->dev
->name
);
556 static int ax_get_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
558 struct ax_device
*ax
= to_ax_dev(dev
);
561 spin_lock_irqsave(&ax
->mii_lock
, flags
);
562 mii_ethtool_gset(&ax
->mii
, cmd
);
563 spin_unlock_irqrestore(&ax
->mii_lock
, flags
);
568 static int ax_set_settings(struct net_device
*dev
, struct ethtool_cmd
*cmd
)
570 struct ax_device
*ax
= to_ax_dev(dev
);
574 spin_lock_irqsave(&ax
->mii_lock
, flags
);
575 rc
= mii_ethtool_sset(&ax
->mii
, cmd
);
576 spin_unlock_irqrestore(&ax
->mii_lock
, flags
);
581 static int ax_nway_reset(struct net_device
*dev
)
583 struct ax_device
*ax
= to_ax_dev(dev
);
584 return mii_nway_restart(&ax
->mii
);
587 static u32
ax_get_link(struct net_device
*dev
)
589 struct ax_device
*ax
= to_ax_dev(dev
);
590 return mii_link_ok(&ax
->mii
);
593 static const struct ethtool_ops ax_ethtool_ops
= {
594 .get_drvinfo
= ax_get_drvinfo
,
595 .get_settings
= ax_get_settings
,
596 .set_settings
= ax_set_settings
,
597 .nway_reset
= ax_nway_reset
,
598 .get_link
= ax_get_link
,
601 #ifdef CONFIG_AX88796_93CX6
602 static void ax_eeprom_register_read(struct eeprom_93cx6
*eeprom
)
604 struct ei_device
*ei_local
= eeprom
->data
;
605 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
607 eeprom
->reg_data_in
= reg
& AX_MEMR_EEI
;
608 eeprom
->reg_data_out
= reg
& AX_MEMR_EEO
; /* Input pin */
609 eeprom
->reg_data_clock
= reg
& AX_MEMR_EECLK
;
610 eeprom
->reg_chip_select
= reg
& AX_MEMR_EECS
;
613 static void ax_eeprom_register_write(struct eeprom_93cx6
*eeprom
)
615 struct ei_device
*ei_local
= eeprom
->data
;
616 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
618 reg
&= ~(AX_MEMR_EEI
| AX_MEMR_EECLK
| AX_MEMR_EECS
);
620 if (eeprom
->reg_data_in
)
622 if (eeprom
->reg_data_clock
)
623 reg
|= AX_MEMR_EECLK
;
624 if (eeprom
->reg_chip_select
)
627 ei_outb(reg
, ei_local
->mem
+ AX_MEMR
);
632 static const struct net_device_ops ax_netdev_ops
= {
634 .ndo_stop
= ax_close
,
635 .ndo_do_ioctl
= ax_ioctl
,
637 .ndo_start_xmit
= ax_ei_start_xmit
,
638 .ndo_tx_timeout
= ax_ei_tx_timeout
,
639 .ndo_get_stats
= ax_ei_get_stats
,
640 .ndo_set_multicast_list
= ax_ei_set_multicast_list
,
641 .ndo_validate_addr
= eth_validate_addr
,
642 .ndo_set_mac_address
= eth_mac_addr
,
643 .ndo_change_mtu
= eth_change_mtu
,
644 #ifdef CONFIG_NET_POLL_CONTROLLER
645 .ndo_poll_controller
= ax_ei_poll
,
651 static void ax_initial_setup(struct net_device
*dev
, struct ei_device
*ei_local
)
653 void __iomem
*ioaddr
= ei_local
->mem
;
654 struct ax_device
*ax
= to_ax_dev(dev
);
657 ei_outb(E8390_NODMA
+E8390_PAGE0
+E8390_STOP
, ioaddr
+ E8390_CMD
);
659 /* set to byte access */
660 ei_outb(ax
->plat
->dcr_val
& ~1, ioaddr
+ EN0_DCFG
);
661 ei_outb(ax
->plat
->gpoc_val
, ioaddr
+ EI_SHIFT(0x17));
666 * initialise the specified device, taking care to note the MAC
667 * address it may already have (if configured), ensure
668 * the device is ready to be used by lib8390.c and registerd with
672 static int ax_init_dev(struct net_device
*dev
, int first_init
)
674 struct ei_device
*ei_local
= netdev_priv(dev
);
675 struct ax_device
*ax
= to_ax_dev(dev
);
676 void __iomem
*ioaddr
= ei_local
->mem
;
677 unsigned int start_page
;
678 unsigned int stop_page
;
682 ret
= ax_initial_check(dev
);
686 /* setup goes here */
688 ax_initial_setup(dev
, ei_local
);
690 /* read the mac from the card prom if we need it */
692 if (first_init
&& ax
->plat
->flags
& AXFLG_HAS_EEPROM
) {
693 unsigned char SA_prom
[32];
695 for(i
= 0; i
< sizeof(SA_prom
); i
+=2) {
696 SA_prom
[i
] = ei_inb(ioaddr
+ NE_DATAPORT
);
697 SA_prom
[i
+1] = ei_inb(ioaddr
+ NE_DATAPORT
);
700 if (ax
->plat
->wordlength
== 2)
701 for (i
= 0; i
< 16; i
++)
702 SA_prom
[i
] = SA_prom
[i
+i
];
704 memcpy(dev
->dev_addr
, SA_prom
, 6);
707 #ifdef CONFIG_AX88796_93CX6
708 if (first_init
&& ax
->plat
->flags
& AXFLG_HAS_93CX6
) {
709 unsigned char mac_addr
[6];
710 struct eeprom_93cx6 eeprom
;
712 eeprom
.data
= ei_local
;
713 eeprom
.register_read
= ax_eeprom_register_read
;
714 eeprom
.register_write
= ax_eeprom_register_write
;
715 eeprom
.width
= PCI_EEPROM_WIDTH_93C56
;
717 eeprom_93cx6_multiread(&eeprom
, 0,
718 (__le16 __force
*)mac_addr
,
719 sizeof(mac_addr
) >> 1);
721 memcpy(dev
->dev_addr
, mac_addr
, 6);
724 if (ax
->plat
->wordlength
== 2) {
725 /* We must set the 8390 for word mode. */
726 ei_outb(ax
->plat
->dcr_val
, ei_local
->mem
+ EN0_DCFG
);
727 start_page
= NESM_START_PG
;
728 stop_page
= NESM_STOP_PG
;
730 start_page
= NE1SM_START_PG
;
731 stop_page
= NE1SM_STOP_PG
;
734 /* load the mac-address from the device if this is the
735 * first time we've initialised */
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
++)
743 ei_inb(ioaddr
+ EN1_PHYS_SHIFT(i
));
746 if ((ax
->plat
->flags
& AXFLG_MAC_FROMPLATFORM
) &&
748 memcpy(dev
->dev_addr
, ax
->plat
->mac_addr
,
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
;
760 #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
;
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
;
771 dev
->netdev_ops
= &ax_netdev_ops
;
772 dev
->ethtool_ops
= &ax_ethtool_ops
;
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
;
784 ax_NS8390_init(dev
, 0);
787 dev_info(&ax
->dev
->dev
, "%dbit, irq %d, %lx, MAC: %pM\n",
788 ei_status
.word16
? 16:8, dev
->irq
, dev
->base_addr
,
791 ret
= register_netdev(dev
);
799 free_irq(dev
->irq
, dev
);
804 static int ax_remove(struct platform_device
*_dev
)
806 struct net_device
*dev
= platform_get_drvdata(_dev
);
807 struct ax_device
*ax
;
811 unregister_netdev(dev
);
812 free_irq(dev
->irq
, dev
);
814 iounmap(ei_status
.mem
);
815 release_resource(ax
->mem
);
820 release_resource(ax
->mem2
);
831 * This is the entry point when the platform device system uses to
832 * notify us of a new device to attach to. Allocate memory, find
833 * the resources and information passed, and map the necessary registers.
836 static int ax_probe(struct platform_device
*pdev
)
838 struct net_device
*dev
;
839 struct ax_device
*ax
;
840 struct resource
*res
;
844 dev
= ax__alloc_ei_netdev(sizeof(struct ax_device
));
848 /* ok, let's setup our device */
851 memset(ax
, 0, sizeof(struct ax_device
));
853 spin_lock_init(&ax
->mii_lock
);
856 ax
->plat
= pdev
->dev
.platform_data
;
857 platform_set_drvdata(pdev
, dev
);
859 ei_status
.rxcr_base
= ax
->plat
->rcr_val
;
861 /* find the platform resources */
863 res
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
865 dev_err(&pdev
->dev
, "no IRQ specified\n");
869 dev
->irq
= res
->start
;
870 ax
->irqflags
= res
->flags
& IRQF_TRIGGER_MASK
;
872 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
874 dev_err(&pdev
->dev
, "no MEM specified\n");
879 size
= (res
->end
- res
->start
) + 1;
881 /* setup the register offsets from either the platform data
882 * or by using the size of the resource provided */
884 if (ax
->plat
->reg_offsets
)
885 ei_status
.reg_offset
= ax
->plat
->reg_offsets
;
887 ei_status
.reg_offset
= ax
->reg_offsets
;
888 for (ret
= 0; ret
< 0x18; ret
++)
889 ax
->reg_offsets
[ret
] = (size
/ 0x18) * ret
;
892 ax
->mem
= request_mem_region(res
->start
, size
, pdev
->name
);
893 if (ax
->mem
== NULL
) {
894 dev_err(&pdev
->dev
, "cannot reserve registers\n");
899 ei_status
.mem
= ioremap(res
->start
, size
);
900 dev
->base_addr
= (unsigned long)ei_status
.mem
;
902 if (ei_status
.mem
== NULL
) {
903 dev_err(&pdev
->dev
, "Cannot ioremap area (%08llx,%08llx)\n",
904 (unsigned long long)res
->start
,
905 (unsigned long long)res
->end
);
911 /* look for reset area */
913 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
915 if (!ax
->plat
->reg_offsets
) {
916 for (ret
= 0; ret
< 0x20; ret
++)
917 ax
->reg_offsets
[ret
] = (size
/ 0x20) * ret
;
922 size
= (res
->end
- res
->start
) + 1;
924 ax
->mem2
= request_mem_region(res
->start
, size
, pdev
->name
);
925 if (ax
->mem2
== NULL
) {
926 dev_err(&pdev
->dev
, "cannot reserve registers\n");
931 ax
->map2
= ioremap(res
->start
, size
);
932 if (ax
->map2
== NULL
) {
933 dev_err(&pdev
->dev
, "cannot map reset register\n");
938 ei_status
.reg_offset
[0x1f] = ax
->map2
- ei_status
.mem
;
941 /* got resources, now initialise and register device */
943 ret
= ax_init_dev(dev
, 1);
947 if (ax
->map2
== NULL
)
953 release_resource(ax
->mem2
);
957 iounmap(ei_status
.mem
);
960 release_resource(ax
->mem
);
969 /* suspend and resume */
972 static int ax_suspend(struct platform_device
*dev
, pm_message_t state
)
974 struct net_device
*ndev
= platform_get_drvdata(dev
);
975 struct ax_device
*ax
= to_ax_dev(ndev
);
977 ax
->resume_open
= ax
->running
;
979 netif_device_detach(ndev
);
985 static int ax_resume(struct platform_device
*pdev
)
987 struct net_device
*ndev
= platform_get_drvdata(pdev
);
988 struct ax_device
*ax
= to_ax_dev(ndev
);
990 ax_initial_setup(ndev
, netdev_priv(ndev
));
991 ax_NS8390_init(ndev
, ax
->resume_open
);
992 netif_device_attach(ndev
);
1001 #define ax_suspend NULL
1002 #define ax_resume NULL
1005 static struct platform_driver axdrv
= {
1008 .owner
= THIS_MODULE
,
1011 .remove
= ax_remove
,
1012 .suspend
= ax_suspend
,
1013 .resume
= ax_resume
,
1016 static int __init
axdrv_init(void)
1018 return platform_driver_register(&axdrv
);
1021 static void __exit
axdrv_exit(void)
1023 platform_driver_unregister(&axdrv
);
1026 module_init(axdrv_init
);
1027 module_exit(axdrv_exit
);
1029 MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
1030 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
1031 MODULE_LICENSE("GPL v2");
1032 MODULE_ALIAS("platform:ax88796");