1 // SPDX-License-Identifier: GPL-2.0-only
2 /* drivers/net/ethernet/8390/ax88796.c
4 * Copyright 2005,2007 Simtec Electronics
5 * Ben Dooks <ben@simtec.co.uk>
7 * Asix AX88796 10/100 Ethernet controller support
8 * Based on ne.c, by Donald Becker, et-al.
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/isapnp.h>
15 #include <linux/interrupt.h>
17 #include <linux/platform_device.h>
18 #include <linux/delay.h>
19 #include <linux/timer.h>
20 #include <linux/netdevice.h>
21 #include <linux/etherdevice.h>
22 #include <linux/ethtool.h>
23 #include <linux/mdio-bitbang.h>
24 #include <linux/phy.h>
25 #include <linux/eeprom_93cx6.h>
26 #include <linux/slab.h>
28 #include <net/ax88796.h>
31 /* Rename the lib8390.c functions to show that they are in this driver */
32 #define __ei_open ax_ei_open
33 #define __ei_close ax_ei_close
34 #define __ei_poll ax_ei_poll
35 #define __ei_start_xmit ax_ei_start_xmit
36 #define __ei_tx_timeout ax_ei_tx_timeout
37 #define __ei_get_stats ax_ei_get_stats
38 #define __ei_set_multicast_list ax_ei_set_multicast_list
39 #define __ei_interrupt ax_ei_interrupt
40 #define ____alloc_ei_netdev ax__alloc_ei_netdev
41 #define __NS8390_init ax_NS8390_init
43 /* force unsigned long back to 'void __iomem *' */
44 #define ax_convert_addr(_a) ((void __force __iomem *)(_a))
46 #define ei_inb(_a) readb(ax_convert_addr(_a))
47 #define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a))
49 #define ei_inb_p(_a) ei_inb(_a)
50 #define ei_outb_p(_v, _a) ei_outb(_v, _a)
52 /* define EI_SHIFT() to take into account our register offsets */
53 #define EI_SHIFT(x) (ei_local->reg_offset[(x)])
55 /* Ensure we have our RCR base value */
56 #define AX88796_PLATFORM
58 static unsigned char version
[] = "ax88796.c: Copyright 2005,2007 Simtec Electronics\n";
62 #define DRV_NAME "ax88796"
63 #define DRV_VERSION "1.00"
66 #define NE_CMD EI_SHIFT(0x00)
67 #define NE_RESET EI_SHIFT(0x1f)
68 #define NE_DATAPORT EI_SHIFT(0x10)
70 #define NE1SM_START_PG 0x20 /* First page of TX buffer */
71 #define NE1SM_STOP_PG 0x40 /* Last page +1 of RX ring */
72 #define NESM_START_PG 0x40 /* First page of TX buffer */
73 #define NESM_STOP_PG 0x80 /* Last page +1 of RX ring */
75 #define AX_GPOC_PPDSET BIT(6)
77 /* device private data */
80 struct mii_bus
*mii_bus
;
81 struct mdiobb_ctrl bb_ctrl
;
82 void __iomem
*addr_memr
;
89 const struct ax_plat_data
*plat
;
91 unsigned char running
;
92 unsigned char resume_open
;
93 unsigned int irqflags
;
95 u32 reg_offsets
[0x20];
98 static inline struct ax_device
*to_ax_dev(struct net_device
*dev
)
100 struct ei_device
*ei_local
= netdev_priv(dev
);
101 return (struct ax_device
*)(ei_local
+ 1);
107 * do an initial probe for the card to check whether it exists
110 static int ax_initial_check(struct net_device
*dev
)
112 struct ei_device
*ei_local
= netdev_priv(dev
);
113 void __iomem
*ioaddr
= ei_local
->mem
;
117 reg0
= ei_inb(ioaddr
);
121 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
122 regd
= ei_inb(ioaddr
+ 0x0d);
123 ei_outb(0xff, ioaddr
+ 0x0d);
124 ei_outb(E8390_NODMA
+ E8390_PAGE0
, ioaddr
+ E8390_CMD
);
125 ei_inb(ioaddr
+ EN0_COUNTER0
); /* Clear the counter by reading. */
126 if (ei_inb(ioaddr
+ EN0_COUNTER0
) != 0) {
127 ei_outb(reg0
, ioaddr
);
128 ei_outb(regd
, ioaddr
+ 0x0d); /* Restore the old values. */
136 * Hard reset the card. This used to pause for the same period that a
137 * 8390 reset command required, but that shouldn't be necessary.
139 static void ax_reset_8390(struct net_device
*dev
)
141 struct ei_device
*ei_local
= netdev_priv(dev
);
142 unsigned long reset_start_time
= jiffies
;
143 void __iomem
*addr
= (void __iomem
*)dev
->base_addr
;
145 netif_dbg(ei_local
, hw
, dev
, "resetting the 8390 t=%ld...\n", jiffies
);
147 ei_outb(ei_inb(addr
+ NE_RESET
), addr
+ NE_RESET
);
150 ei_local
->dmaing
= 0;
152 /* This check _should_not_ be necessary, omit eventually. */
153 while ((ei_inb(addr
+ EN0_ISR
) & ENISR_RESET
) == 0) {
154 if (time_after(jiffies
, reset_start_time
+ 2 * HZ
/ 100)) {
155 netdev_warn(dev
, "%s: did not complete.\n", __func__
);
160 ei_outb(ENISR_RESET
, addr
+ EN0_ISR
); /* Ack intr. */
163 /* Wrapper for __ei_interrupt for platforms that have a platform-specific
164 * way to find out whether the interrupt request might be caused by
167 static irqreturn_t
ax_ei_interrupt_filtered(int irq
, void *dev_id
)
169 struct net_device
*dev
= dev_id
;
170 struct ax_device
*ax
= to_ax_dev(dev
);
171 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
173 if (!ax
->plat
->check_irq(pdev
))
176 return ax_ei_interrupt(irq
, dev_id
);
179 static void ax_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
182 struct ei_device
*ei_local
= netdev_priv(dev
);
183 void __iomem
*nic_base
= ei_local
->mem
;
185 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
186 if (ei_local
->dmaing
) {
187 netdev_err(dev
, "DMAing conflict in %s "
188 "[DMAstat:%d][irqlock:%d].\n",
190 ei_local
->dmaing
, ei_local
->irqlock
);
194 ei_local
->dmaing
|= 0x01;
195 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_START
, nic_base
+ NE_CMD
);
196 ei_outb(sizeof(struct e8390_pkt_hdr
), nic_base
+ EN0_RCNTLO
);
197 ei_outb(0, nic_base
+ EN0_RCNTHI
);
198 ei_outb(0, nic_base
+ EN0_RSARLO
); /* On page boundary */
199 ei_outb(ring_page
, nic_base
+ EN0_RSARHI
);
200 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
202 if (ei_local
->word16
)
203 ioread16_rep(nic_base
+ NE_DATAPORT
, hdr
,
204 sizeof(struct e8390_pkt_hdr
) >> 1);
206 ioread8_rep(nic_base
+ NE_DATAPORT
, hdr
,
207 sizeof(struct e8390_pkt_hdr
));
209 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
210 ei_local
->dmaing
&= ~0x01;
212 le16_to_cpus(&hdr
->count
);
217 * Block input and output, similar to the Crynwr packet driver. If
218 * you are porting to a new ethercard, look at the packet driver
219 * source for hints. The NEx000 doesn't share the on-board packet
220 * memory -- you have to put the packet out through the "remote DMA"
221 * dataport using ei_outb.
223 static void ax_block_input(struct net_device
*dev
, int count
,
224 struct sk_buff
*skb
, int ring_offset
)
226 struct ei_device
*ei_local
= netdev_priv(dev
);
227 void __iomem
*nic_base
= ei_local
->mem
;
228 char *buf
= skb
->data
;
230 if (ei_local
->dmaing
) {
232 "DMAing conflict in %s "
233 "[DMAstat:%d][irqlock:%d].\n",
235 ei_local
->dmaing
, ei_local
->irqlock
);
239 ei_local
->dmaing
|= 0x01;
241 ei_outb(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
242 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
243 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
244 ei_outb(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
245 ei_outb(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
246 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
248 if (ei_local
->word16
) {
249 ioread16_rep(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
251 buf
[count
-1] = ei_inb(nic_base
+ NE_DATAPORT
);
254 ioread8_rep(nic_base
+ NE_DATAPORT
, buf
, count
);
257 ei_local
->dmaing
&= ~1;
260 static void ax_block_output(struct net_device
*dev
, int count
,
261 const unsigned char *buf
, const int start_page
)
263 struct ei_device
*ei_local
= netdev_priv(dev
);
264 void __iomem
*nic_base
= ei_local
->mem
;
265 unsigned long dma_start
;
268 * Round the count up for word writes. Do we need to do this?
269 * What effect will an odd byte count have on the 8390? I
270 * should check someday.
272 if (ei_local
->word16
&& (count
& 0x01))
275 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
276 if (ei_local
->dmaing
) {
277 netdev_err(dev
, "DMAing conflict in %s."
278 "[DMAstat:%d][irqlock:%d]\n",
280 ei_local
->dmaing
, ei_local
->irqlock
);
284 ei_local
->dmaing
|= 0x01;
285 /* We should already be in page 0, but to be safe... */
286 ei_outb(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
+ NE_CMD
);
288 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
);
290 /* Now the normal output. */
291 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
292 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
293 ei_outb(0x00, nic_base
+ EN0_RSARLO
);
294 ei_outb(start_page
, nic_base
+ EN0_RSARHI
);
296 ei_outb(E8390_RWRITE
+E8390_START
, nic_base
+ NE_CMD
);
297 if (ei_local
->word16
)
298 iowrite16_rep(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
300 iowrite8_rep(nic_base
+ NE_DATAPORT
, buf
, count
);
304 while ((ei_inb(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0) {
305 if (time_after(jiffies
, dma_start
+ 2 * HZ
/ 100)) { /* 20ms */
306 netdev_warn(dev
, "timeout waiting for Tx RDC.\n");
308 ax_NS8390_init(dev
, 1);
313 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
314 ei_local
->dmaing
&= ~0x01;
317 /* definitions for accessing MII/EEPROM interface */
319 #define AX_MEMR EI_SHIFT(0x14)
320 #define AX_MEMR_MDC BIT(0)
321 #define AX_MEMR_MDIR BIT(1)
322 #define AX_MEMR_MDI BIT(2)
323 #define AX_MEMR_MDO BIT(3)
324 #define AX_MEMR_EECS BIT(4)
325 #define AX_MEMR_EEI BIT(5)
326 #define AX_MEMR_EEO BIT(6)
327 #define AX_MEMR_EECLK BIT(7)
329 static void ax_handle_link_change(struct net_device
*dev
)
331 struct ax_device
*ax
= to_ax_dev(dev
);
332 struct phy_device
*phy_dev
= dev
->phydev
;
333 int status_change
= 0;
335 if (phy_dev
->link
&& ((ax
->speed
!= phy_dev
->speed
) ||
336 (ax
->duplex
!= phy_dev
->duplex
))) {
338 ax
->speed
= phy_dev
->speed
;
339 ax
->duplex
= phy_dev
->duplex
;
343 if (phy_dev
->link
!= ax
->link
) {
344 if (!phy_dev
->link
) {
348 ax
->link
= phy_dev
->link
;
354 phy_print_status(phy_dev
);
357 static int ax_mii_probe(struct net_device
*dev
)
359 struct ax_device
*ax
= to_ax_dev(dev
);
360 struct phy_device
*phy_dev
= NULL
;
363 /* find the first phy */
364 phy_dev
= phy_find_first(ax
->mii_bus
);
366 netdev_err(dev
, "no PHY found\n");
370 ret
= phy_connect_direct(dev
, phy_dev
, ax_handle_link_change
,
371 PHY_INTERFACE_MODE_MII
);
373 netdev_err(dev
, "Could not attach to PHY\n");
377 phy_set_max_speed(phy_dev
, SPEED_100
);
379 netdev_info(dev
, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
380 phy_dev
->drv
->name
, phydev_name(phy_dev
), phy_dev
->irq
);
385 static void ax_phy_switch(struct net_device
*dev
, int on
)
387 struct ei_device
*ei_local
= netdev_priv(dev
);
388 struct ax_device
*ax
= to_ax_dev(dev
);
390 u8 reg_gpoc
= ax
->plat
->gpoc_val
;
393 reg_gpoc
&= ~AX_GPOC_PPDSET
;
395 reg_gpoc
|= AX_GPOC_PPDSET
;
397 ei_outb(reg_gpoc
, ei_local
->mem
+ EI_SHIFT(0x17));
400 static void ax_bb_mdc(struct mdiobb_ctrl
*ctrl
, int level
)
402 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
405 ax
->reg_memr
|= AX_MEMR_MDC
;
407 ax
->reg_memr
&= ~AX_MEMR_MDC
;
409 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
412 static void ax_bb_dir(struct mdiobb_ctrl
*ctrl
, int output
)
414 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
417 ax
->reg_memr
&= ~AX_MEMR_MDIR
;
419 ax
->reg_memr
|= AX_MEMR_MDIR
;
421 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
424 static void ax_bb_set_data(struct mdiobb_ctrl
*ctrl
, int value
)
426 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
429 ax
->reg_memr
|= AX_MEMR_MDO
;
431 ax
->reg_memr
&= ~AX_MEMR_MDO
;
433 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
436 static int ax_bb_get_data(struct mdiobb_ctrl
*ctrl
)
438 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
439 int reg_memr
= ei_inb(ax
->addr_memr
);
441 return reg_memr
& AX_MEMR_MDI
? 1 : 0;
444 static const struct mdiobb_ops bb_ops
= {
445 .owner
= THIS_MODULE
,
446 .set_mdc
= ax_bb_mdc
,
447 .set_mdio_dir
= ax_bb_dir
,
448 .set_mdio_data
= ax_bb_set_data
,
449 .get_mdio_data
= ax_bb_get_data
,
452 static int ax_mii_init(struct net_device
*dev
)
454 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
455 struct ei_device
*ei_local
= netdev_priv(dev
);
456 struct ax_device
*ax
= to_ax_dev(dev
);
459 ax
->bb_ctrl
.ops
= &bb_ops
;
460 ax
->addr_memr
= ei_local
->mem
+ AX_MEMR
;
461 ax
->mii_bus
= alloc_mdio_bitbang(&ax
->bb_ctrl
);
467 ax
->mii_bus
->name
= "ax88796_mii_bus";
468 ax
->mii_bus
->parent
= dev
->dev
.parent
;
469 snprintf(ax
->mii_bus
->id
, MII_BUS_ID_SIZE
, "%s-%x",
470 pdev
->name
, pdev
->id
);
472 err
= mdiobus_register(ax
->mii_bus
);
474 goto out_free_mdio_bitbang
;
478 out_free_mdio_bitbang
:
479 free_mdio_bitbang(ax
->mii_bus
);
484 static int ax_open(struct net_device
*dev
)
486 struct ax_device
*ax
= to_ax_dev(dev
);
489 netdev_dbg(dev
, "open\n");
491 ret
= ax_mii_init(dev
);
495 if (ax
->plat
->check_irq
)
496 ret
= request_irq(dev
->irq
, ax_ei_interrupt_filtered
,
497 ax
->irqflags
, dev
->name
, dev
);
499 ret
= request_irq(dev
->irq
, ax_ei_interrupt
, ax
->irqflags
,
502 goto failed_request_irq
;
504 /* turn the phy on (if turned off) */
505 ax_phy_switch(dev
, 1);
507 ret
= ax_mii_probe(dev
);
509 goto failed_mii_probe
;
510 phy_start(dev
->phydev
);
512 ret
= ax_ei_open(dev
);
514 goto failed_ax_ei_open
;
521 phy_disconnect(dev
->phydev
);
523 ax_phy_switch(dev
, 0);
524 free_irq(dev
->irq
, dev
);
526 /* unregister mdiobus */
527 mdiobus_unregister(ax
->mii_bus
);
528 free_mdio_bitbang(ax
->mii_bus
);
533 static int ax_close(struct net_device
*dev
)
535 struct ax_device
*ax
= to_ax_dev(dev
);
537 netdev_dbg(dev
, "close\n");
544 /* turn the phy off */
545 ax_phy_switch(dev
, 0);
546 phy_disconnect(dev
->phydev
);
548 free_irq(dev
->irq
, dev
);
550 mdiobus_unregister(ax
->mii_bus
);
551 free_mdio_bitbang(ax
->mii_bus
);
555 static int ax_ioctl(struct net_device
*dev
, struct ifreq
*req
, int cmd
)
557 struct phy_device
*phy_dev
= dev
->phydev
;
559 if (!netif_running(dev
))
565 return phy_mii_ioctl(phy_dev
, req
, cmd
);
570 static void ax_get_drvinfo(struct net_device
*dev
,
571 struct ethtool_drvinfo
*info
)
573 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
575 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
576 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
577 strlcpy(info
->bus_info
, pdev
->name
, sizeof(info
->bus_info
));
580 static u32
ax_get_msglevel(struct net_device
*dev
)
582 struct ei_device
*ei_local
= netdev_priv(dev
);
584 return ei_local
->msg_enable
;
587 static void ax_set_msglevel(struct net_device
*dev
, u32 v
)
589 struct ei_device
*ei_local
= netdev_priv(dev
);
591 ei_local
->msg_enable
= v
;
594 static const struct ethtool_ops ax_ethtool_ops
= {
595 .get_drvinfo
= ax_get_drvinfo
,
596 .get_link
= ethtool_op_get_link
,
597 .get_ts_info
= ethtool_op_get_ts_info
,
598 .get_msglevel
= ax_get_msglevel
,
599 .set_msglevel
= ax_set_msglevel
,
600 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
601 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
604 #ifdef CONFIG_AX88796_93CX6
605 static void ax_eeprom_register_read(struct eeprom_93cx6
*eeprom
)
607 struct ei_device
*ei_local
= eeprom
->data
;
608 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
610 eeprom
->reg_data_in
= reg
& AX_MEMR_EEI
;
611 eeprom
->reg_data_out
= reg
& AX_MEMR_EEO
; /* Input pin */
612 eeprom
->reg_data_clock
= reg
& AX_MEMR_EECLK
;
613 eeprom
->reg_chip_select
= reg
& AX_MEMR_EECS
;
616 static void ax_eeprom_register_write(struct eeprom_93cx6
*eeprom
)
618 struct ei_device
*ei_local
= eeprom
->data
;
619 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
621 reg
&= ~(AX_MEMR_EEI
| AX_MEMR_EECLK
| AX_MEMR_EECS
);
623 if (eeprom
->reg_data_in
)
625 if (eeprom
->reg_data_clock
)
626 reg
|= AX_MEMR_EECLK
;
627 if (eeprom
->reg_chip_select
)
630 ei_outb(reg
, ei_local
->mem
+ AX_MEMR
);
635 static const struct net_device_ops ax_netdev_ops
= {
637 .ndo_stop
= ax_close
,
638 .ndo_do_ioctl
= ax_ioctl
,
640 .ndo_start_xmit
= ax_ei_start_xmit
,
641 .ndo_tx_timeout
= ax_ei_tx_timeout
,
642 .ndo_get_stats
= ax_ei_get_stats
,
643 .ndo_set_rx_mode
= ax_ei_set_multicast_list
,
644 .ndo_validate_addr
= eth_validate_addr
,
645 .ndo_set_mac_address
= eth_mac_addr
,
646 #ifdef CONFIG_NET_POLL_CONTROLLER
647 .ndo_poll_controller
= ax_ei_poll
,
653 static void ax_initial_setup(struct net_device
*dev
, struct ei_device
*ei_local
)
655 void __iomem
*ioaddr
= ei_local
->mem
;
656 struct ax_device
*ax
= to_ax_dev(dev
);
659 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
661 /* set to byte access */
662 ei_outb(ax
->plat
->dcr_val
& ~1, ioaddr
+ EN0_DCFG
);
663 ei_outb(ax
->plat
->gpoc_val
, ioaddr
+ EI_SHIFT(0x17));
669 * initialise the specified device, taking care to note the MAC
670 * address it may already have (if configured), ensure
671 * the device is ready to be used by lib8390.c and registerd with
674 static int ax_init_dev(struct net_device
*dev
)
676 struct ei_device
*ei_local
= netdev_priv(dev
);
677 struct ax_device
*ax
= to_ax_dev(dev
);
678 void __iomem
*ioaddr
= ei_local
->mem
;
679 unsigned int start_page
;
680 unsigned int stop_page
;
684 ret
= ax_initial_check(dev
);
688 /* setup goes here */
690 ax_initial_setup(dev
, ei_local
);
692 /* read the mac from the card prom if we need it */
694 if (ax
->plat
->flags
& AXFLG_HAS_EEPROM
) {
695 unsigned char SA_prom
[32];
697 ei_outb(6, ioaddr
+ EN0_RCNTLO
);
698 ei_outb(0, ioaddr
+ EN0_RCNTHI
);
699 ei_outb(0, ioaddr
+ EN0_RSARLO
);
700 ei_outb(0, ioaddr
+ EN0_RSARHI
);
701 ei_outb(E8390_RREAD
+ E8390_START
, ioaddr
+ NE_CMD
);
702 for (i
= 0; i
< sizeof(SA_prom
); i
+= 2) {
703 SA_prom
[i
] = ei_inb(ioaddr
+ NE_DATAPORT
);
704 SA_prom
[i
+ 1] = ei_inb(ioaddr
+ NE_DATAPORT
);
706 ei_outb(ENISR_RDC
, ioaddr
+ EN0_ISR
); /* Ack intr. */
708 if (ax
->plat
->wordlength
== 2)
709 for (i
= 0; i
< 16; i
++)
710 SA_prom
[i
] = SA_prom
[i
+i
];
712 memcpy(dev
->dev_addr
, SA_prom
, ETH_ALEN
);
715 #ifdef CONFIG_AX88796_93CX6
716 if (ax
->plat
->flags
& AXFLG_HAS_93CX6
) {
717 unsigned char mac_addr
[ETH_ALEN
];
718 struct eeprom_93cx6 eeprom
;
720 eeprom
.data
= ei_local
;
721 eeprom
.register_read
= ax_eeprom_register_read
;
722 eeprom
.register_write
= ax_eeprom_register_write
;
723 eeprom
.width
= PCI_EEPROM_WIDTH_93C56
;
725 eeprom_93cx6_multiread(&eeprom
, 0,
726 (__le16 __force
*)mac_addr
,
727 sizeof(mac_addr
) >> 1);
729 memcpy(dev
->dev_addr
, mac_addr
, ETH_ALEN
);
732 if (ax
->plat
->wordlength
== 2) {
733 /* We must set the 8390 for word mode. */
734 ei_outb(ax
->plat
->dcr_val
, ei_local
->mem
+ EN0_DCFG
);
735 start_page
= NESM_START_PG
;
736 stop_page
= NESM_STOP_PG
;
738 start_page
= NE1SM_START_PG
;
739 stop_page
= NE1SM_STOP_PG
;
742 /* load the mac-address from the device */
743 if (ax
->plat
->flags
& AXFLG_MAC_FROMDEV
) {
744 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
,
745 ei_local
->mem
+ E8390_CMD
); /* 0x61 */
746 for (i
= 0; i
< ETH_ALEN
; i
++)
748 ei_inb(ioaddr
+ EN1_PHYS_SHIFT(i
));
751 if ((ax
->plat
->flags
& AXFLG_MAC_FROMPLATFORM
) &&
753 memcpy(dev
->dev_addr
, ax
->plat
->mac_addr
, ETH_ALEN
);
755 if (!is_valid_ether_addr(dev
->dev_addr
)) {
756 eth_hw_addr_random(dev
);
757 dev_info(&dev
->dev
, "Using random MAC address: %pM\n",
763 ei_local
->name
= "AX88796";
764 ei_local
->tx_start_page
= start_page
;
765 ei_local
->stop_page
= stop_page
;
766 ei_local
->word16
= (ax
->plat
->wordlength
== 2);
767 ei_local
->rx_start_page
= start_page
+ TX_PAGES
;
769 #ifdef PACKETBUF_MEMSIZE
770 /* Allow the packet buffer size to be overridden by know-it-alls. */
771 ei_local
->stop_page
= ei_local
->tx_start_page
+ PACKETBUF_MEMSIZE
;
774 ei_local
->reset_8390
= &ax_reset_8390
;
775 if (ax
->plat
->block_input
)
776 ei_local
->block_input
= ax
->plat
->block_input
;
778 ei_local
->block_input
= &ax_block_input
;
779 if (ax
->plat
->block_output
)
780 ei_local
->block_output
= ax
->plat
->block_output
;
782 ei_local
->block_output
= &ax_block_output
;
783 ei_local
->get_8390_hdr
= &ax_get_8390_hdr
;
786 dev
->netdev_ops
= &ax_netdev_ops
;
787 dev
->ethtool_ops
= &ax_ethtool_ops
;
789 ax_NS8390_init(dev
, 0);
791 ret
= register_netdev(dev
);
795 netdev_info(dev
, "%dbit, irq %d, %lx, MAC: %pM\n",
796 ei_local
->word16
? 16 : 8, dev
->irq
, dev
->base_addr
,
805 static int ax_remove(struct platform_device
*pdev
)
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
;
812 unregister_netdev(dev
);
814 iounmap(ei_local
->mem
);
815 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
816 release_mem_region(mem
->start
, resource_size(mem
));
820 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
821 release_mem_region(mem
->start
, resource_size(mem
));
824 platform_set_drvdata(pdev
, NULL
);
833 * This is the entry point when the platform device system uses to
834 * notify us of a new device to attach to. Allocate memory, find the
835 * resources and information passed, and map the necessary registers.
837 static int ax_probe(struct platform_device
*pdev
)
839 struct net_device
*dev
;
840 struct ei_device
*ei_local
;
841 struct ax_device
*ax
;
842 struct resource
*irq
, *mem
, *mem2
;
843 unsigned long mem_size
, mem2_size
= 0;
846 dev
= ax__alloc_ei_netdev(sizeof(struct ax_device
));
850 /* ok, let's setup our device */
851 SET_NETDEV_DEV(dev
, &pdev
->dev
);
852 ei_local
= netdev_priv(dev
);
855 ax
->plat
= dev_get_platdata(&pdev
->dev
);
856 platform_set_drvdata(pdev
, dev
);
858 ei_local
->rxcr_base
= ax
->plat
->rcr_val
;
860 /* find the platform resources */
861 irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
863 dev_err(&pdev
->dev
, "no IRQ specified\n");
868 dev
->irq
= irq
->start
;
869 ax
->irqflags
= irq
->flags
& IRQF_TRIGGER_MASK
;
871 if (irq
->flags
& IORESOURCE_IRQ_SHAREABLE
)
872 ax
->irqflags
|= IRQF_SHARED
;
874 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
876 dev_err(&pdev
->dev
, "no MEM specified\n");
881 mem_size
= resource_size(mem
);
884 * setup the register offsets from either the platform data or
885 * by using the size of the resource provided
887 if (ax
->plat
->reg_offsets
)
888 ei_local
->reg_offset
= ax
->plat
->reg_offsets
;
890 ei_local
->reg_offset
= ax
->reg_offsets
;
891 for (ret
= 0; ret
< 0x18; ret
++)
892 ax
->reg_offsets
[ret
] = (mem_size
/ 0x18) * ret
;
895 if (!request_mem_region(mem
->start
, mem_size
, pdev
->name
)) {
896 dev_err(&pdev
->dev
, "cannot reserve registers\n");
901 ei_local
->mem
= ioremap(mem
->start
, mem_size
);
902 dev
->base_addr
= (unsigned long)ei_local
->mem
;
904 if (ei_local
->mem
== NULL
) {
905 dev_err(&pdev
->dev
, "Cannot ioremap area %pR\n", mem
);
911 /* look for reset area */
912 mem2
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
914 if (!ax
->plat
->reg_offsets
) {
915 for (ret
= 0; ret
< 0x20; ret
++)
916 ax
->reg_offsets
[ret
] = (mem_size
/ 0x20) * ret
;
919 mem2_size
= resource_size(mem2
);
921 if (!request_mem_region(mem2
->start
, mem2_size
, pdev
->name
)) {
922 dev_err(&pdev
->dev
, "cannot reserve registers\n");
927 ax
->map2
= ioremap(mem2
->start
, mem2_size
);
929 dev_err(&pdev
->dev
, "cannot map reset register\n");
934 ei_local
->reg_offset
[0x1f] = ax
->map2
- ei_local
->mem
;
937 /* got resources, now initialise and register device */
938 ret
= ax_init_dev(dev
);
949 release_mem_region(mem2
->start
, mem2_size
);
952 iounmap(ei_local
->mem
);
955 release_mem_region(mem
->start
, mem_size
);
958 platform_set_drvdata(pdev
, NULL
);
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
= {
1005 .remove
= ax_remove
,
1006 .suspend
= ax_suspend
,
1007 .resume
= ax_resume
,
1010 module_platform_driver(axdrv
);
1012 MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
1013 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
1014 MODULE_LICENSE("GPL v2");
1015 MODULE_ALIAS("platform:ax88796");