1 /* drivers/net/ethernet/8390/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/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/mdio-bitbang.h>
27 #include <linux/phy.h>
28 #include <linux/eeprom_93cx6.h>
29 #include <linux/slab.h>
31 #include <net/ax88796.h>
34 /* Rename the lib8390.c functions to show that they are in this driver */
35 #define __ei_open ax_ei_open
36 #define __ei_close ax_ei_close
37 #define __ei_poll ax_ei_poll
38 #define __ei_start_xmit ax_ei_start_xmit
39 #define __ei_tx_timeout ax_ei_tx_timeout
40 #define __ei_get_stats ax_ei_get_stats
41 #define __ei_set_multicast_list ax_ei_set_multicast_list
42 #define __ei_interrupt ax_ei_interrupt
43 #define ____alloc_ei_netdev ax__alloc_ei_netdev
44 #define __NS8390_init ax_NS8390_init
46 /* force unsigned long back to 'void __iomem *' */
47 #define ax_convert_addr(_a) ((void __force __iomem *)(_a))
49 #define ei_inb(_a) readb(ax_convert_addr(_a))
50 #define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a))
52 #define ei_inb_p(_a) ei_inb(_a)
53 #define ei_outb_p(_v, _a) ei_outb(_v, _a)
55 /* define EI_SHIFT() to take into account our register offsets */
56 #define EI_SHIFT(x) (ei_local->reg_offset[(x)])
58 /* Ensure we have our RCR base value */
59 #define AX88796_PLATFORM
61 static unsigned char version
[] = "ax88796.c: Copyright 2005,2007 Simtec Electronics\n";
65 #define DRV_NAME "ax88796"
66 #define DRV_VERSION "1.00"
69 #define NE_CMD EI_SHIFT(0x00)
70 #define NE_RESET EI_SHIFT(0x1f)
71 #define NE_DATAPORT EI_SHIFT(0x10)
73 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
74 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
75 #define NESM_START_PG 0x40 /* First page of TX buffer */
76 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
78 #define AX_GPOC_PPDSET BIT(6)
80 /* device private data */
83 struct mii_bus
*mii_bus
;
84 struct mdiobb_ctrl bb_ctrl
;
85 void __iomem
*addr_memr
;
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 whether 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
;
148 netif_dbg(ei_local
, hw
, dev
, "resetting the 8390 t=%ld...\n", jiffies
);
150 ei_outb(ei_inb(addr
+ NE_RESET
), addr
+ NE_RESET
);
153 ei_local
->dmaing
= 0;
155 /* This check _should_not_ be necessary, omit eventually. */
156 while ((ei_inb(addr
+ EN0_ISR
) & ENISR_RESET
) == 0) {
157 if (time_after(jiffies
, reset_start_time
+ 2 * HZ
/ 100)) {
158 netdev_warn(dev
, "%s: did not complete.\n", __func__
);
163 ei_outb(ENISR_RESET
, addr
+ EN0_ISR
); /* Ack intr. */
166 /* Wrapper for __ei_interrupt for platforms that have a platform-specific
167 * way to find out whether the interrupt request might be caused by
170 static irqreturn_t
ax_ei_interrupt_filtered(int irq
, void *dev_id
)
172 struct net_device
*dev
= dev_id
;
173 struct ax_device
*ax
= to_ax_dev(dev
);
174 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
176 if (!ax
->plat
->check_irq(pdev
))
179 return ax_ei_interrupt(irq
, dev_id
);
182 static void ax_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
185 struct ei_device
*ei_local
= netdev_priv(dev
);
186 void __iomem
*nic_base
= ei_local
->mem
;
188 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
189 if (ei_local
->dmaing
) {
190 netdev_err(dev
, "DMAing conflict in %s "
191 "[DMAstat:%d][irqlock:%d].\n",
193 ei_local
->dmaing
, ei_local
->irqlock
);
197 ei_local
->dmaing
|= 0x01;
198 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_START
, nic_base
+ NE_CMD
);
199 ei_outb(sizeof(struct e8390_pkt_hdr
), nic_base
+ EN0_RCNTLO
);
200 ei_outb(0, nic_base
+ EN0_RCNTHI
);
201 ei_outb(0, nic_base
+ EN0_RSARLO
); /* On page boundary */
202 ei_outb(ring_page
, nic_base
+ EN0_RSARHI
);
203 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
205 if (ei_local
->word16
)
206 ioread16_rep(nic_base
+ NE_DATAPORT
, hdr
,
207 sizeof(struct e8390_pkt_hdr
) >> 1);
209 ioread8_rep(nic_base
+ NE_DATAPORT
, hdr
,
210 sizeof(struct e8390_pkt_hdr
));
212 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
213 ei_local
->dmaing
&= ~0x01;
215 le16_to_cpus(&hdr
->count
);
220 * Block input and output, similar to the Crynwr packet driver. If
221 * you are porting to a new ethercard, look at the packet driver
222 * source for hints. The NEx000 doesn't share the on-board packet
223 * memory -- you have to put the packet out through the "remote DMA"
224 * dataport using ei_outb.
226 static void ax_block_input(struct net_device
*dev
, int count
,
227 struct sk_buff
*skb
, int ring_offset
)
229 struct ei_device
*ei_local
= netdev_priv(dev
);
230 void __iomem
*nic_base
= ei_local
->mem
;
231 char *buf
= skb
->data
;
233 if (ei_local
->dmaing
) {
235 "DMAing conflict in %s "
236 "[DMAstat:%d][irqlock:%d].\n",
238 ei_local
->dmaing
, ei_local
->irqlock
);
242 ei_local
->dmaing
|= 0x01;
244 ei_outb(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
245 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
246 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
247 ei_outb(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
248 ei_outb(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
249 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
251 if (ei_local
->word16
) {
252 ioread16_rep(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
254 buf
[count
-1] = ei_inb(nic_base
+ NE_DATAPORT
);
257 ioread8_rep(nic_base
+ NE_DATAPORT
, buf
, count
);
260 ei_local
->dmaing
&= ~1;
263 static void ax_block_output(struct net_device
*dev
, int count
,
264 const unsigned char *buf
, const int start_page
)
266 struct ei_device
*ei_local
= netdev_priv(dev
);
267 void __iomem
*nic_base
= ei_local
->mem
;
268 unsigned long dma_start
;
271 * Round the count up for word writes. Do we need to do this?
272 * What effect will an odd byte count have on the 8390? I
273 * should check someday.
275 if (ei_local
->word16
&& (count
& 0x01))
278 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
279 if (ei_local
->dmaing
) {
280 netdev_err(dev
, "DMAing conflict in %s."
281 "[DMAstat:%d][irqlock:%d]\n",
283 ei_local
->dmaing
, ei_local
->irqlock
);
287 ei_local
->dmaing
|= 0x01;
288 /* We should already be in page 0, but to be safe... */
289 ei_outb(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
+ NE_CMD
);
291 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
);
293 /* Now the normal output. */
294 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
295 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
296 ei_outb(0x00, nic_base
+ EN0_RSARLO
);
297 ei_outb(start_page
, nic_base
+ EN0_RSARHI
);
299 ei_outb(E8390_RWRITE
+E8390_START
, nic_base
+ NE_CMD
);
300 if (ei_local
->word16
)
301 iowrite16_rep(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
303 iowrite8_rep(nic_base
+ NE_DATAPORT
, buf
, count
);
307 while ((ei_inb(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0) {
308 if (time_after(jiffies
, dma_start
+ 2 * HZ
/ 100)) { /* 20ms */
309 netdev_warn(dev
, "timeout waiting for Tx RDC.\n");
311 ax_NS8390_init(dev
, 1);
316 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
317 ei_local
->dmaing
&= ~0x01;
320 /* definitions for accessing MII/EEPROM interface */
322 #define AX_MEMR EI_SHIFT(0x14)
323 #define AX_MEMR_MDC BIT(0)
324 #define AX_MEMR_MDIR BIT(1)
325 #define AX_MEMR_MDI BIT(2)
326 #define AX_MEMR_MDO BIT(3)
327 #define AX_MEMR_EECS BIT(4)
328 #define AX_MEMR_EEI BIT(5)
329 #define AX_MEMR_EEO BIT(6)
330 #define AX_MEMR_EECLK BIT(7)
332 static void ax_handle_link_change(struct net_device
*dev
)
334 struct ax_device
*ax
= to_ax_dev(dev
);
335 struct phy_device
*phy_dev
= dev
->phydev
;
336 int status_change
= 0;
338 if (phy_dev
->link
&& ((ax
->speed
!= phy_dev
->speed
) ||
339 (ax
->duplex
!= phy_dev
->duplex
))) {
341 ax
->speed
= phy_dev
->speed
;
342 ax
->duplex
= phy_dev
->duplex
;
346 if (phy_dev
->link
!= ax
->link
) {
347 if (!phy_dev
->link
) {
351 ax
->link
= phy_dev
->link
;
357 phy_print_status(phy_dev
);
360 static int ax_mii_probe(struct net_device
*dev
)
362 struct ax_device
*ax
= to_ax_dev(dev
);
363 struct phy_device
*phy_dev
= NULL
;
366 /* find the first phy */
367 phy_dev
= phy_find_first(ax
->mii_bus
);
369 netdev_err(dev
, "no PHY found\n");
373 ret
= phy_connect_direct(dev
, phy_dev
, ax_handle_link_change
,
374 PHY_INTERFACE_MODE_MII
);
376 netdev_err(dev
, "Could not attach to PHY\n");
380 /* mask with MAC supported features */
381 phy_dev
->supported
&= PHY_BASIC_FEATURES
;
382 phy_dev
->advertising
= phy_dev
->supported
;
384 netdev_info(dev
, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
385 phy_dev
->drv
->name
, phydev_name(phy_dev
), phy_dev
->irq
);
390 static void ax_phy_switch(struct net_device
*dev
, int on
)
392 struct ei_device
*ei_local
= netdev_priv(dev
);
393 struct ax_device
*ax
= to_ax_dev(dev
);
395 u8 reg_gpoc
= ax
->plat
->gpoc_val
;
398 reg_gpoc
&= ~AX_GPOC_PPDSET
;
400 reg_gpoc
|= AX_GPOC_PPDSET
;
402 ei_outb(reg_gpoc
, ei_local
->mem
+ EI_SHIFT(0x17));
405 static void ax_bb_mdc(struct mdiobb_ctrl
*ctrl
, int level
)
407 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
410 ax
->reg_memr
|= AX_MEMR_MDC
;
412 ax
->reg_memr
&= ~AX_MEMR_MDC
;
414 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
417 static void ax_bb_dir(struct mdiobb_ctrl
*ctrl
, int output
)
419 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
422 ax
->reg_memr
&= ~AX_MEMR_MDIR
;
424 ax
->reg_memr
|= AX_MEMR_MDIR
;
426 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
429 static void ax_bb_set_data(struct mdiobb_ctrl
*ctrl
, int value
)
431 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
434 ax
->reg_memr
|= AX_MEMR_MDO
;
436 ax
->reg_memr
&= ~AX_MEMR_MDO
;
438 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
441 static int ax_bb_get_data(struct mdiobb_ctrl
*ctrl
)
443 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
444 int reg_memr
= ei_inb(ax
->addr_memr
);
446 return reg_memr
& AX_MEMR_MDI
? 1 : 0;
449 static const struct mdiobb_ops bb_ops
= {
450 .owner
= THIS_MODULE
,
451 .set_mdc
= ax_bb_mdc
,
452 .set_mdio_dir
= ax_bb_dir
,
453 .set_mdio_data
= ax_bb_set_data
,
454 .get_mdio_data
= ax_bb_get_data
,
457 static int ax_mii_init(struct net_device
*dev
)
459 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
460 struct ei_device
*ei_local
= netdev_priv(dev
);
461 struct ax_device
*ax
= to_ax_dev(dev
);
464 ax
->bb_ctrl
.ops
= &bb_ops
;
465 ax
->addr_memr
= ei_local
->mem
+ AX_MEMR
;
466 ax
->mii_bus
= alloc_mdio_bitbang(&ax
->bb_ctrl
);
472 ax
->mii_bus
->name
= "ax88796_mii_bus";
473 ax
->mii_bus
->parent
= dev
->dev
.parent
;
474 snprintf(ax
->mii_bus
->id
, MII_BUS_ID_SIZE
, "%s-%x",
475 pdev
->name
, pdev
->id
);
477 err
= mdiobus_register(ax
->mii_bus
);
479 goto out_free_mdio_bitbang
;
483 out_free_mdio_bitbang
:
484 free_mdio_bitbang(ax
->mii_bus
);
489 static int ax_open(struct net_device
*dev
)
491 struct ax_device
*ax
= to_ax_dev(dev
);
494 netdev_dbg(dev
, "open\n");
496 ret
= ax_mii_init(dev
);
500 if (ax
->plat
->check_irq
)
501 ret
= request_irq(dev
->irq
, ax_ei_interrupt_filtered
,
502 ax
->irqflags
, dev
->name
, dev
);
504 ret
= request_irq(dev
->irq
, ax_ei_interrupt
, ax
->irqflags
,
507 goto failed_request_irq
;
509 /* turn the phy on (if turned off) */
510 ax_phy_switch(dev
, 1);
512 ret
= ax_mii_probe(dev
);
514 goto failed_mii_probe
;
515 phy_start(dev
->phydev
);
517 ret
= ax_ei_open(dev
);
519 goto failed_ax_ei_open
;
526 phy_disconnect(dev
->phydev
);
528 ax_phy_switch(dev
, 0);
529 free_irq(dev
->irq
, dev
);
531 /* unregister mdiobus */
532 mdiobus_unregister(ax
->mii_bus
);
533 free_mdio_bitbang(ax
->mii_bus
);
538 static int ax_close(struct net_device
*dev
)
540 struct ax_device
*ax
= to_ax_dev(dev
);
542 netdev_dbg(dev
, "close\n");
549 /* turn the phy off */
550 ax_phy_switch(dev
, 0);
551 phy_disconnect(dev
->phydev
);
553 free_irq(dev
->irq
, dev
);
555 mdiobus_unregister(ax
->mii_bus
);
556 free_mdio_bitbang(ax
->mii_bus
);
560 static int ax_ioctl(struct net_device
*dev
, struct ifreq
*req
, int cmd
)
562 struct phy_device
*phy_dev
= dev
->phydev
;
564 if (!netif_running(dev
))
570 return phy_mii_ioctl(phy_dev
, req
, cmd
);
575 static void ax_get_drvinfo(struct net_device
*dev
,
576 struct ethtool_drvinfo
*info
)
578 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
580 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
581 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
582 strlcpy(info
->bus_info
, pdev
->name
, sizeof(info
->bus_info
));
585 static u32
ax_get_msglevel(struct net_device
*dev
)
587 struct ei_device
*ei_local
= netdev_priv(dev
);
589 return ei_local
->msg_enable
;
592 static void ax_set_msglevel(struct net_device
*dev
, u32 v
)
594 struct ei_device
*ei_local
= netdev_priv(dev
);
596 ei_local
->msg_enable
= v
;
599 static const struct ethtool_ops ax_ethtool_ops
= {
600 .get_drvinfo
= ax_get_drvinfo
,
601 .get_link
= ethtool_op_get_link
,
602 .get_ts_info
= ethtool_op_get_ts_info
,
603 .get_msglevel
= ax_get_msglevel
,
604 .set_msglevel
= ax_set_msglevel
,
605 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
606 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
609 #ifdef CONFIG_AX88796_93CX6
610 static void ax_eeprom_register_read(struct eeprom_93cx6
*eeprom
)
612 struct ei_device
*ei_local
= eeprom
->data
;
613 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
615 eeprom
->reg_data_in
= reg
& AX_MEMR_EEI
;
616 eeprom
->reg_data_out
= reg
& AX_MEMR_EEO
; /* Input pin */
617 eeprom
->reg_data_clock
= reg
& AX_MEMR_EECLK
;
618 eeprom
->reg_chip_select
= reg
& AX_MEMR_EECS
;
621 static void ax_eeprom_register_write(struct eeprom_93cx6
*eeprom
)
623 struct ei_device
*ei_local
= eeprom
->data
;
624 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
626 reg
&= ~(AX_MEMR_EEI
| AX_MEMR_EECLK
| AX_MEMR_EECS
);
628 if (eeprom
->reg_data_in
)
630 if (eeprom
->reg_data_clock
)
631 reg
|= AX_MEMR_EECLK
;
632 if (eeprom
->reg_chip_select
)
635 ei_outb(reg
, ei_local
->mem
+ AX_MEMR
);
640 static const struct net_device_ops ax_netdev_ops
= {
642 .ndo_stop
= ax_close
,
643 .ndo_do_ioctl
= ax_ioctl
,
645 .ndo_start_xmit
= ax_ei_start_xmit
,
646 .ndo_tx_timeout
= ax_ei_tx_timeout
,
647 .ndo_get_stats
= ax_ei_get_stats
,
648 .ndo_set_rx_mode
= ax_ei_set_multicast_list
,
649 .ndo_validate_addr
= eth_validate_addr
,
650 .ndo_set_mac_address
= eth_mac_addr
,
651 #ifdef CONFIG_NET_POLL_CONTROLLER
652 .ndo_poll_controller
= ax_ei_poll
,
658 static void ax_initial_setup(struct net_device
*dev
, struct ei_device
*ei_local
)
660 void __iomem
*ioaddr
= ei_local
->mem
;
661 struct ax_device
*ax
= to_ax_dev(dev
);
664 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
666 /* set to byte access */
667 ei_outb(ax
->plat
->dcr_val
& ~1, ioaddr
+ EN0_DCFG
);
668 ei_outb(ax
->plat
->gpoc_val
, ioaddr
+ EI_SHIFT(0x17));
674 * initialise the specified device, taking care to note the MAC
675 * address it may already have (if configured), ensure
676 * the device is ready to be used by lib8390.c and registerd with
679 static int ax_init_dev(struct net_device
*dev
)
681 struct ei_device
*ei_local
= netdev_priv(dev
);
682 struct ax_device
*ax
= to_ax_dev(dev
);
683 void __iomem
*ioaddr
= ei_local
->mem
;
684 unsigned int start_page
;
685 unsigned int stop_page
;
689 ret
= ax_initial_check(dev
);
693 /* setup goes here */
695 ax_initial_setup(dev
, ei_local
);
697 /* read the mac from the card prom if we need it */
699 if (ax
->plat
->flags
& AXFLG_HAS_EEPROM
) {
700 unsigned char SA_prom
[32];
702 ei_outb(6, ioaddr
+ EN0_RCNTLO
);
703 ei_outb(0, ioaddr
+ EN0_RCNTHI
);
704 ei_outb(0, ioaddr
+ EN0_RSARLO
);
705 ei_outb(0, ioaddr
+ EN0_RSARHI
);
706 ei_outb(E8390_RREAD
+ E8390_START
, ioaddr
+ NE_CMD
);
707 for (i
= 0; i
< sizeof(SA_prom
); i
+= 2) {
708 SA_prom
[i
] = ei_inb(ioaddr
+ NE_DATAPORT
);
709 SA_prom
[i
+ 1] = ei_inb(ioaddr
+ NE_DATAPORT
);
711 ei_outb(ENISR_RDC
, ioaddr
+ EN0_ISR
); /* Ack intr. */
713 if (ax
->plat
->wordlength
== 2)
714 for (i
= 0; i
< 16; i
++)
715 SA_prom
[i
] = SA_prom
[i
+i
];
717 memcpy(dev
->dev_addr
, SA_prom
, ETH_ALEN
);
720 #ifdef CONFIG_AX88796_93CX6
721 if (ax
->plat
->flags
& AXFLG_HAS_93CX6
) {
722 unsigned char mac_addr
[ETH_ALEN
];
723 struct eeprom_93cx6 eeprom
;
725 eeprom
.data
= ei_local
;
726 eeprom
.register_read
= ax_eeprom_register_read
;
727 eeprom
.register_write
= ax_eeprom_register_write
;
728 eeprom
.width
= PCI_EEPROM_WIDTH_93C56
;
730 eeprom_93cx6_multiread(&eeprom
, 0,
731 (__le16 __force
*)mac_addr
,
732 sizeof(mac_addr
) >> 1);
734 memcpy(dev
->dev_addr
, mac_addr
, ETH_ALEN
);
737 if (ax
->plat
->wordlength
== 2) {
738 /* We must set the 8390 for word mode. */
739 ei_outb(ax
->plat
->dcr_val
, ei_local
->mem
+ EN0_DCFG
);
740 start_page
= NESM_START_PG
;
741 stop_page
= NESM_STOP_PG
;
743 start_page
= NE1SM_START_PG
;
744 stop_page
= NE1SM_STOP_PG
;
747 /* load the mac-address from the device */
748 if (ax
->plat
->flags
& AXFLG_MAC_FROMDEV
) {
749 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
,
750 ei_local
->mem
+ E8390_CMD
); /* 0x61 */
751 for (i
= 0; i
< ETH_ALEN
; i
++)
753 ei_inb(ioaddr
+ EN1_PHYS_SHIFT(i
));
756 if ((ax
->plat
->flags
& AXFLG_MAC_FROMPLATFORM
) &&
758 memcpy(dev
->dev_addr
, ax
->plat
->mac_addr
, ETH_ALEN
);
760 if (!is_valid_ether_addr(dev
->dev_addr
)) {
761 eth_hw_addr_random(dev
);
762 dev_info(&dev
->dev
, "Using random MAC address: %pM\n",
768 ei_local
->name
= "AX88796";
769 ei_local
->tx_start_page
= start_page
;
770 ei_local
->stop_page
= stop_page
;
771 ei_local
->word16
= (ax
->plat
->wordlength
== 2);
772 ei_local
->rx_start_page
= start_page
+ TX_PAGES
;
774 #ifdef PACKETBUF_MEMSIZE
775 /* Allow the packet buffer size to be overridden by know-it-alls. */
776 ei_local
->stop_page
= ei_local
->tx_start_page
+ PACKETBUF_MEMSIZE
;
779 ei_local
->reset_8390
= &ax_reset_8390
;
780 if (ax
->plat
->block_input
)
781 ei_local
->block_input
= ax
->plat
->block_input
;
783 ei_local
->block_input
= &ax_block_input
;
784 if (ax
->plat
->block_output
)
785 ei_local
->block_output
= ax
->plat
->block_output
;
787 ei_local
->block_output
= &ax_block_output
;
788 ei_local
->get_8390_hdr
= &ax_get_8390_hdr
;
791 dev
->netdev_ops
= &ax_netdev_ops
;
792 dev
->ethtool_ops
= &ax_ethtool_ops
;
794 ax_NS8390_init(dev
, 0);
796 ret
= register_netdev(dev
);
800 netdev_info(dev
, "%dbit, irq %d, %lx, MAC: %pM\n",
801 ei_local
->word16
? 16 : 8, dev
->irq
, dev
->base_addr
,
810 static int ax_remove(struct platform_device
*pdev
)
812 struct net_device
*dev
= platform_get_drvdata(pdev
);
813 struct ei_device
*ei_local
= netdev_priv(dev
);
814 struct ax_device
*ax
= to_ax_dev(dev
);
815 struct resource
*mem
;
817 unregister_netdev(dev
);
819 iounmap(ei_local
->mem
);
820 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
821 release_mem_region(mem
->start
, resource_size(mem
));
825 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
826 release_mem_region(mem
->start
, resource_size(mem
));
829 platform_set_drvdata(pdev
, NULL
);
838 * This is the entry point when the platform device system uses to
839 * notify us of a new device to attach to. Allocate memory, find the
840 * resources and information passed, and map the necessary registers.
842 static int ax_probe(struct platform_device
*pdev
)
844 struct net_device
*dev
;
845 struct ei_device
*ei_local
;
846 struct ax_device
*ax
;
847 struct resource
*irq
, *mem
, *mem2
;
848 unsigned long mem_size
, mem2_size
= 0;
851 dev
= ax__alloc_ei_netdev(sizeof(struct ax_device
));
855 /* ok, let's setup our device */
856 SET_NETDEV_DEV(dev
, &pdev
->dev
);
857 ei_local
= netdev_priv(dev
);
860 ax
->plat
= dev_get_platdata(&pdev
->dev
);
861 platform_set_drvdata(pdev
, dev
);
863 ei_local
->rxcr_base
= ax
->plat
->rcr_val
;
865 /* find the platform resources */
866 irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
868 dev_err(&pdev
->dev
, "no IRQ specified\n");
873 dev
->irq
= irq
->start
;
874 ax
->irqflags
= irq
->flags
& IRQF_TRIGGER_MASK
;
876 if (irq
->flags
& IORESOURCE_IRQ_SHAREABLE
)
877 ax
->irqflags
|= IRQF_SHARED
;
879 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
881 dev_err(&pdev
->dev
, "no MEM specified\n");
886 mem_size
= resource_size(mem
);
889 * setup the register offsets from either the platform data or
890 * by using the size of the resource provided
892 if (ax
->plat
->reg_offsets
)
893 ei_local
->reg_offset
= ax
->plat
->reg_offsets
;
895 ei_local
->reg_offset
= ax
->reg_offsets
;
896 for (ret
= 0; ret
< 0x18; ret
++)
897 ax
->reg_offsets
[ret
] = (mem_size
/ 0x18) * ret
;
900 if (!request_mem_region(mem
->start
, mem_size
, pdev
->name
)) {
901 dev_err(&pdev
->dev
, "cannot reserve registers\n");
906 ei_local
->mem
= ioremap(mem
->start
, mem_size
);
907 dev
->base_addr
= (unsigned long)ei_local
->mem
;
909 if (ei_local
->mem
== NULL
) {
910 dev_err(&pdev
->dev
, "Cannot ioremap area %pR\n", mem
);
916 /* look for reset area */
917 mem2
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
919 if (!ax
->plat
->reg_offsets
) {
920 for (ret
= 0; ret
< 0x20; ret
++)
921 ax
->reg_offsets
[ret
] = (mem_size
/ 0x20) * ret
;
924 mem2_size
= resource_size(mem2
);
926 if (!request_mem_region(mem2
->start
, mem2_size
, pdev
->name
)) {
927 dev_err(&pdev
->dev
, "cannot reserve registers\n");
932 ax
->map2
= ioremap(mem2
->start
, mem2_size
);
934 dev_err(&pdev
->dev
, "cannot map reset register\n");
939 ei_local
->reg_offset
[0x1f] = ax
->map2
- ei_local
->mem
;
942 /* got resources, now initialise and register device */
943 ret
= ax_init_dev(dev
);
954 release_mem_region(mem2
->start
, mem2_size
);
957 iounmap(ei_local
->mem
);
960 release_mem_region(mem
->start
, mem_size
);
963 platform_set_drvdata(pdev
, NULL
);
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
= {
1010 .remove
= ax_remove
,
1011 .suspend
= ax_suspend
,
1012 .resume
= ax_resume
,
1015 module_platform_driver(axdrv
);
1017 MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
1018 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
1019 MODULE_LICENSE("GPL v2");
1020 MODULE_ALIAS("platform:ax88796");