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);
104 void ax_NS8390_reinit(struct net_device
*dev
)
106 ax_NS8390_init(dev
, 1);
109 EXPORT_SYMBOL_GPL(ax_NS8390_reinit
);
114 * do an initial probe for the card to check whether it exists
117 static int ax_initial_check(struct net_device
*dev
)
119 struct ei_device
*ei_local
= netdev_priv(dev
);
120 void __iomem
*ioaddr
= ei_local
->mem
;
124 reg0
= ei_inb(ioaddr
);
128 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
129 regd
= ei_inb(ioaddr
+ 0x0d);
130 ei_outb(0xff, ioaddr
+ 0x0d);
131 ei_outb(E8390_NODMA
+ E8390_PAGE0
, ioaddr
+ E8390_CMD
);
132 ei_inb(ioaddr
+ EN0_COUNTER0
); /* Clear the counter by reading. */
133 if (ei_inb(ioaddr
+ EN0_COUNTER0
) != 0) {
134 ei_outb(reg0
, ioaddr
);
135 ei_outb(regd
, ioaddr
+ 0x0d); /* Restore the old values. */
143 * Hard reset the card. This used to pause for the same period that a
144 * 8390 reset command required, but that shouldn't be necessary.
146 static void ax_reset_8390(struct net_device
*dev
)
148 struct ei_device
*ei_local
= netdev_priv(dev
);
149 unsigned long reset_start_time
= jiffies
;
150 void __iomem
*addr
= (void __iomem
*)dev
->base_addr
;
152 netif_dbg(ei_local
, hw
, dev
, "resetting the 8390 t=%ld...\n", jiffies
);
154 ei_outb(ei_inb(addr
+ NE_RESET
), addr
+ NE_RESET
);
157 ei_local
->dmaing
= 0;
159 /* This check _should_not_ be necessary, omit eventually. */
160 while ((ei_inb(addr
+ EN0_ISR
) & ENISR_RESET
) == 0) {
161 if (time_after(jiffies
, reset_start_time
+ 2 * HZ
/ 100)) {
162 netdev_warn(dev
, "%s: did not complete.\n", __func__
);
167 ei_outb(ENISR_RESET
, addr
+ EN0_ISR
); /* Ack intr. */
170 /* Wrapper for __ei_interrupt for platforms that have a platform-specific
171 * way to find out whether the interrupt request might be caused by
174 static irqreturn_t
ax_ei_interrupt_filtered(int irq
, void *dev_id
)
176 struct net_device
*dev
= dev_id
;
177 struct ax_device
*ax
= to_ax_dev(dev
);
178 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
180 if (!ax
->plat
->check_irq(pdev
))
183 return ax_ei_interrupt(irq
, dev_id
);
186 static void ax_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
189 struct ei_device
*ei_local
= netdev_priv(dev
);
190 void __iomem
*nic_base
= ei_local
->mem
;
192 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
193 if (ei_local
->dmaing
) {
194 netdev_err(dev
, "DMAing conflict in %s "
195 "[DMAstat:%d][irqlock:%d].\n",
197 ei_local
->dmaing
, ei_local
->irqlock
);
201 ei_local
->dmaing
|= 0x01;
202 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_START
, nic_base
+ NE_CMD
);
203 ei_outb(sizeof(struct e8390_pkt_hdr
), nic_base
+ EN0_RCNTLO
);
204 ei_outb(0, nic_base
+ EN0_RCNTHI
);
205 ei_outb(0, nic_base
+ EN0_RSARLO
); /* On page boundary */
206 ei_outb(ring_page
, nic_base
+ EN0_RSARHI
);
207 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
209 if (ei_local
->word16
)
210 ioread16_rep(nic_base
+ NE_DATAPORT
, hdr
,
211 sizeof(struct e8390_pkt_hdr
) >> 1);
213 ioread8_rep(nic_base
+ NE_DATAPORT
, hdr
,
214 sizeof(struct e8390_pkt_hdr
));
216 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
217 ei_local
->dmaing
&= ~0x01;
219 le16_to_cpus(&hdr
->count
);
224 * Block input and output, similar to the Crynwr packet driver. If
225 * you are porting to a new ethercard, look at the packet driver
226 * source for hints. The NEx000 doesn't share the on-board packet
227 * memory -- you have to put the packet out through the "remote DMA"
228 * dataport using ei_outb.
230 static void ax_block_input(struct net_device
*dev
, int count
,
231 struct sk_buff
*skb
, int ring_offset
)
233 struct ei_device
*ei_local
= netdev_priv(dev
);
234 void __iomem
*nic_base
= ei_local
->mem
;
235 char *buf
= skb
->data
;
237 if (ei_local
->dmaing
) {
239 "DMAing conflict in %s "
240 "[DMAstat:%d][irqlock:%d].\n",
242 ei_local
->dmaing
, ei_local
->irqlock
);
246 ei_local
->dmaing
|= 0x01;
248 ei_outb(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
249 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
250 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
251 ei_outb(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
252 ei_outb(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
253 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
255 if (ei_local
->word16
) {
256 ioread16_rep(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
258 buf
[count
-1] = ei_inb(nic_base
+ NE_DATAPORT
);
261 ioread8_rep(nic_base
+ NE_DATAPORT
, buf
, count
);
264 ei_local
->dmaing
&= ~1;
267 static void ax_block_output(struct net_device
*dev
, int count
,
268 const unsigned char *buf
, const int start_page
)
270 struct ei_device
*ei_local
= netdev_priv(dev
);
271 void __iomem
*nic_base
= ei_local
->mem
;
272 unsigned long dma_start
;
275 * Round the count up for word writes. Do we need to do this?
276 * What effect will an odd byte count have on the 8390? I
277 * should check someday.
279 if (ei_local
->word16
&& (count
& 0x01))
282 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
283 if (ei_local
->dmaing
) {
284 netdev_err(dev
, "DMAing conflict in %s."
285 "[DMAstat:%d][irqlock:%d]\n",
287 ei_local
->dmaing
, ei_local
->irqlock
);
291 ei_local
->dmaing
|= 0x01;
292 /* We should already be in page 0, but to be safe... */
293 ei_outb(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
+ NE_CMD
);
295 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
);
297 /* Now the normal output. */
298 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
299 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
300 ei_outb(0x00, nic_base
+ EN0_RSARLO
);
301 ei_outb(start_page
, nic_base
+ EN0_RSARHI
);
303 ei_outb(E8390_RWRITE
+E8390_START
, nic_base
+ NE_CMD
);
304 if (ei_local
->word16
)
305 iowrite16_rep(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
307 iowrite8_rep(nic_base
+ NE_DATAPORT
, buf
, count
);
311 while ((ei_inb(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0) {
312 if (time_after(jiffies
, dma_start
+ 2 * HZ
/ 100)) { /* 20ms */
313 netdev_warn(dev
, "timeout waiting for Tx RDC.\n");
315 ax_NS8390_init(dev
, 1);
320 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
321 ei_local
->dmaing
&= ~0x01;
324 /* definitions for accessing MII/EEPROM interface */
326 #define AX_MEMR EI_SHIFT(0x14)
327 #define AX_MEMR_MDC BIT(0)
328 #define AX_MEMR_MDIR BIT(1)
329 #define AX_MEMR_MDI BIT(2)
330 #define AX_MEMR_MDO BIT(3)
331 #define AX_MEMR_EECS BIT(4)
332 #define AX_MEMR_EEI BIT(5)
333 #define AX_MEMR_EEO BIT(6)
334 #define AX_MEMR_EECLK BIT(7)
336 static void ax_handle_link_change(struct net_device
*dev
)
338 struct ax_device
*ax
= to_ax_dev(dev
);
339 struct phy_device
*phy_dev
= dev
->phydev
;
340 int status_change
= 0;
342 if (phy_dev
->link
&& ((ax
->speed
!= phy_dev
->speed
) ||
343 (ax
->duplex
!= phy_dev
->duplex
))) {
345 ax
->speed
= phy_dev
->speed
;
346 ax
->duplex
= phy_dev
->duplex
;
350 if (phy_dev
->link
!= ax
->link
) {
351 if (!phy_dev
->link
) {
355 ax
->link
= phy_dev
->link
;
361 phy_print_status(phy_dev
);
364 static int ax_mii_probe(struct net_device
*dev
)
366 struct ax_device
*ax
= to_ax_dev(dev
);
367 struct phy_device
*phy_dev
= NULL
;
370 /* find the first phy */
371 phy_dev
= phy_find_first(ax
->mii_bus
);
373 netdev_err(dev
, "no PHY found\n");
377 ret
= phy_connect_direct(dev
, phy_dev
, ax_handle_link_change
,
378 PHY_INTERFACE_MODE_MII
);
380 netdev_err(dev
, "Could not attach to PHY\n");
384 phy_set_max_speed(phy_dev
, SPEED_100
);
386 netdev_info(dev
, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
387 phy_dev
->drv
->name
, phydev_name(phy_dev
), phy_dev
->irq
);
392 static void ax_phy_switch(struct net_device
*dev
, int on
)
394 struct ei_device
*ei_local
= netdev_priv(dev
);
395 struct ax_device
*ax
= to_ax_dev(dev
);
397 u8 reg_gpoc
= ax
->plat
->gpoc_val
;
400 reg_gpoc
&= ~AX_GPOC_PPDSET
;
402 reg_gpoc
|= AX_GPOC_PPDSET
;
404 ei_outb(reg_gpoc
, ei_local
->mem
+ EI_SHIFT(0x17));
407 static void ax_bb_mdc(struct mdiobb_ctrl
*ctrl
, int level
)
409 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
412 ax
->reg_memr
|= AX_MEMR_MDC
;
414 ax
->reg_memr
&= ~AX_MEMR_MDC
;
416 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
419 static void ax_bb_dir(struct mdiobb_ctrl
*ctrl
, int output
)
421 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
424 ax
->reg_memr
&= ~AX_MEMR_MDIR
;
426 ax
->reg_memr
|= AX_MEMR_MDIR
;
428 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
431 static void ax_bb_set_data(struct mdiobb_ctrl
*ctrl
, int value
)
433 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
436 ax
->reg_memr
|= AX_MEMR_MDO
;
438 ax
->reg_memr
&= ~AX_MEMR_MDO
;
440 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
443 static int ax_bb_get_data(struct mdiobb_ctrl
*ctrl
)
445 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
446 int reg_memr
= ei_inb(ax
->addr_memr
);
448 return reg_memr
& AX_MEMR_MDI
? 1 : 0;
451 static const struct mdiobb_ops bb_ops
= {
452 .owner
= THIS_MODULE
,
453 .set_mdc
= ax_bb_mdc
,
454 .set_mdio_dir
= ax_bb_dir
,
455 .set_mdio_data
= ax_bb_set_data
,
456 .get_mdio_data
= ax_bb_get_data
,
459 static int ax_mii_init(struct net_device
*dev
)
461 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
462 struct ei_device
*ei_local
= netdev_priv(dev
);
463 struct ax_device
*ax
= to_ax_dev(dev
);
466 ax
->bb_ctrl
.ops
= &bb_ops
;
467 ax
->addr_memr
= ei_local
->mem
+ AX_MEMR
;
468 ax
->mii_bus
= alloc_mdio_bitbang(&ax
->bb_ctrl
);
474 ax
->mii_bus
->name
= "ax88796_mii_bus";
475 ax
->mii_bus
->parent
= dev
->dev
.parent
;
476 snprintf(ax
->mii_bus
->id
, MII_BUS_ID_SIZE
, "%s-%x",
477 pdev
->name
, pdev
->id
);
479 err
= mdiobus_register(ax
->mii_bus
);
481 goto out_free_mdio_bitbang
;
485 out_free_mdio_bitbang
:
486 free_mdio_bitbang(ax
->mii_bus
);
491 static int ax_open(struct net_device
*dev
)
493 struct ax_device
*ax
= to_ax_dev(dev
);
496 netdev_dbg(dev
, "open\n");
498 ret
= ax_mii_init(dev
);
502 if (ax
->plat
->check_irq
)
503 ret
= request_irq(dev
->irq
, ax_ei_interrupt_filtered
,
504 ax
->irqflags
, dev
->name
, dev
);
506 ret
= request_irq(dev
->irq
, ax_ei_interrupt
, ax
->irqflags
,
509 goto failed_request_irq
;
511 /* turn the phy on (if turned off) */
512 ax_phy_switch(dev
, 1);
514 ret
= ax_mii_probe(dev
);
516 goto failed_mii_probe
;
517 phy_start(dev
->phydev
);
519 ret
= ax_ei_open(dev
);
521 goto failed_ax_ei_open
;
528 phy_disconnect(dev
->phydev
);
530 ax_phy_switch(dev
, 0);
531 free_irq(dev
->irq
, dev
);
533 /* unregister mdiobus */
534 mdiobus_unregister(ax
->mii_bus
);
535 free_mdio_bitbang(ax
->mii_bus
);
540 static int ax_close(struct net_device
*dev
)
542 struct ax_device
*ax
= to_ax_dev(dev
);
544 netdev_dbg(dev
, "close\n");
551 /* turn the phy off */
552 ax_phy_switch(dev
, 0);
553 phy_disconnect(dev
->phydev
);
555 free_irq(dev
->irq
, dev
);
557 mdiobus_unregister(ax
->mii_bus
);
558 free_mdio_bitbang(ax
->mii_bus
);
562 static int ax_ioctl(struct net_device
*dev
, struct ifreq
*req
, int cmd
)
564 struct phy_device
*phy_dev
= dev
->phydev
;
566 if (!netif_running(dev
))
572 return phy_mii_ioctl(phy_dev
, req
, cmd
);
577 static void ax_get_drvinfo(struct net_device
*dev
,
578 struct ethtool_drvinfo
*info
)
580 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
582 strscpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
583 strscpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
584 strscpy(info
->bus_info
, pdev
->name
, sizeof(info
->bus_info
));
587 static u32
ax_get_msglevel(struct net_device
*dev
)
589 struct ei_device
*ei_local
= netdev_priv(dev
);
591 return ei_local
->msg_enable
;
594 static void ax_set_msglevel(struct net_device
*dev
, u32 v
)
596 struct ei_device
*ei_local
= netdev_priv(dev
);
598 ei_local
->msg_enable
= v
;
601 static const struct ethtool_ops ax_ethtool_ops
= {
602 .get_drvinfo
= ax_get_drvinfo
,
603 .get_link
= ethtool_op_get_link
,
604 .get_ts_info
= ethtool_op_get_ts_info
,
605 .get_msglevel
= ax_get_msglevel
,
606 .set_msglevel
= ax_set_msglevel
,
607 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
608 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
611 #ifdef CONFIG_AX88796_93CX6
612 static void ax_eeprom_register_read(struct eeprom_93cx6
*eeprom
)
614 struct ei_device
*ei_local
= eeprom
->data
;
615 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
617 eeprom
->reg_data_in
= reg
& AX_MEMR_EEI
;
618 eeprom
->reg_data_out
= reg
& AX_MEMR_EEO
; /* Input pin */
619 eeprom
->reg_data_clock
= reg
& AX_MEMR_EECLK
;
620 eeprom
->reg_chip_select
= reg
& AX_MEMR_EECS
;
623 static void ax_eeprom_register_write(struct eeprom_93cx6
*eeprom
)
625 struct ei_device
*ei_local
= eeprom
->data
;
626 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
628 reg
&= ~(AX_MEMR_EEI
| AX_MEMR_EECLK
| AX_MEMR_EECS
);
630 if (eeprom
->reg_data_in
)
632 if (eeprom
->reg_data_clock
)
633 reg
|= AX_MEMR_EECLK
;
634 if (eeprom
->reg_chip_select
)
637 ei_outb(reg
, ei_local
->mem
+ AX_MEMR
);
642 static const struct net_device_ops ax_netdev_ops
= {
644 .ndo_stop
= ax_close
,
645 .ndo_eth_ioctl
= ax_ioctl
,
647 .ndo_start_xmit
= ax_ei_start_xmit
,
648 .ndo_tx_timeout
= ax_ei_tx_timeout
,
649 .ndo_get_stats
= ax_ei_get_stats
,
650 .ndo_set_rx_mode
= ax_ei_set_multicast_list
,
651 .ndo_validate_addr
= eth_validate_addr
,
652 .ndo_set_mac_address
= eth_mac_addr
,
653 #ifdef CONFIG_NET_POLL_CONTROLLER
654 .ndo_poll_controller
= ax_ei_poll
,
660 static void ax_initial_setup(struct net_device
*dev
, struct ei_device
*ei_local
)
662 void __iomem
*ioaddr
= ei_local
->mem
;
663 struct ax_device
*ax
= to_ax_dev(dev
);
666 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
668 /* set to byte access */
669 ei_outb(ax
->plat
->dcr_val
& ~1, ioaddr
+ EN0_DCFG
);
670 ei_outb(ax
->plat
->gpoc_val
, ioaddr
+ EI_SHIFT(0x17));
676 * initialise the specified device, taking care to note the MAC
677 * address it may already have (if configured), ensure
678 * the device is ready to be used by lib8390.c and registerd with
681 static int ax_init_dev(struct net_device
*dev
)
683 struct ei_device
*ei_local
= netdev_priv(dev
);
684 struct ax_device
*ax
= to_ax_dev(dev
);
685 void __iomem
*ioaddr
= ei_local
->mem
;
686 unsigned int start_page
;
687 unsigned int stop_page
;
691 ret
= ax_initial_check(dev
);
695 /* setup goes here */
697 ax_initial_setup(dev
, ei_local
);
699 /* read the mac from the card prom if we need it */
701 if (ax
->plat
->flags
& AXFLG_HAS_EEPROM
) {
702 unsigned char SA_prom
[32];
704 ei_outb(6, ioaddr
+ EN0_RCNTLO
);
705 ei_outb(0, ioaddr
+ EN0_RCNTHI
);
706 ei_outb(0, ioaddr
+ EN0_RSARLO
);
707 ei_outb(0, ioaddr
+ EN0_RSARHI
);
708 ei_outb(E8390_RREAD
+ E8390_START
, ioaddr
+ NE_CMD
);
709 for (i
= 0; i
< sizeof(SA_prom
); i
+= 2) {
710 SA_prom
[i
] = ei_inb(ioaddr
+ NE_DATAPORT
);
711 SA_prom
[i
+ 1] = ei_inb(ioaddr
+ NE_DATAPORT
);
713 ei_outb(ENISR_RDC
, ioaddr
+ EN0_ISR
); /* Ack intr. */
715 if (ax
->plat
->wordlength
== 2)
716 for (i
= 0; i
< 16; i
++)
717 SA_prom
[i
] = SA_prom
[i
+i
];
719 eth_hw_addr_set(dev
, SA_prom
);
722 #ifdef CONFIG_AX88796_93CX6
723 if (ax
->plat
->flags
& AXFLG_HAS_93CX6
) {
724 unsigned char mac_addr
[ETH_ALEN
];
725 struct eeprom_93cx6 eeprom
;
727 eeprom
.data
= ei_local
;
728 eeprom
.register_read
= ax_eeprom_register_read
;
729 eeprom
.register_write
= ax_eeprom_register_write
;
730 eeprom
.width
= PCI_EEPROM_WIDTH_93C56
;
732 eeprom_93cx6_multiread(&eeprom
, 0,
733 (__le16 __force
*)mac_addr
,
734 sizeof(mac_addr
) >> 1);
736 eth_hw_addr_set(dev
, mac_addr
);
739 if (ax
->plat
->wordlength
== 2) {
740 /* We must set the 8390 for word mode. */
741 ei_outb(ax
->plat
->dcr_val
, ei_local
->mem
+ EN0_DCFG
);
742 start_page
= NESM_START_PG
;
743 stop_page
= NESM_STOP_PG
;
745 start_page
= NE1SM_START_PG
;
746 stop_page
= NE1SM_STOP_PG
;
749 /* load the mac-address from the device */
750 if (ax
->plat
->flags
& AXFLG_MAC_FROMDEV
) {
753 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
,
754 ei_local
->mem
+ E8390_CMD
); /* 0x61 */
755 for (i
= 0; i
< ETH_ALEN
; i
++)
756 addr
[i
] = ei_inb(ioaddr
+ EN1_PHYS_SHIFT(i
));
757 eth_hw_addr_set(dev
, addr
);
760 if ((ax
->plat
->flags
& AXFLG_MAC_FROMPLATFORM
) &&
762 eth_hw_addr_set(dev
, ax
->plat
->mac_addr
);
764 if (!is_valid_ether_addr(dev
->dev_addr
)) {
765 eth_hw_addr_random(dev
);
766 dev_info(&dev
->dev
, "Using random MAC address: %pM\n",
772 ei_local
->name
= "AX88796";
773 ei_local
->tx_start_page
= start_page
;
774 ei_local
->stop_page
= stop_page
;
775 ei_local
->word16
= (ax
->plat
->wordlength
== 2);
776 ei_local
->rx_start_page
= start_page
+ TX_PAGES
;
778 #ifdef PACKETBUF_MEMSIZE
779 /* Allow the packet buffer size to be overridden by know-it-alls. */
780 ei_local
->stop_page
= ei_local
->tx_start_page
+ PACKETBUF_MEMSIZE
;
783 ei_local
->reset_8390
= &ax_reset_8390
;
784 if (ax
->plat
->block_input
)
785 ei_local
->block_input
= ax
->plat
->block_input
;
787 ei_local
->block_input
= &ax_block_input
;
788 if (ax
->plat
->block_output
)
789 ei_local
->block_output
= ax
->plat
->block_output
;
791 ei_local
->block_output
= &ax_block_output
;
792 ei_local
->get_8390_hdr
= &ax_get_8390_hdr
;
795 dev
->netdev_ops
= &ax_netdev_ops
;
796 dev
->ethtool_ops
= &ax_ethtool_ops
;
798 ax_NS8390_init(dev
, 0);
800 ret
= register_netdev(dev
);
804 netdev_info(dev
, "%dbit, irq %d, %lx, MAC: %pM\n",
805 ei_local
->word16
? 16 : 8, dev
->irq
, dev
->base_addr
,
814 static void ax_remove(struct platform_device
*pdev
)
816 struct net_device
*dev
= platform_get_drvdata(pdev
);
817 struct ei_device
*ei_local
= netdev_priv(dev
);
818 struct ax_device
*ax
= to_ax_dev(dev
);
819 struct resource
*mem
;
821 unregister_netdev(dev
);
823 iounmap(ei_local
->mem
);
824 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
825 release_mem_region(mem
->start
, resource_size(mem
));
829 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
830 release_mem_region(mem
->start
, resource_size(mem
));
833 platform_set_drvdata(pdev
, NULL
);
840 * This is the entry point when the platform device system uses to
841 * notify us of a new device to attach to. Allocate memory, find the
842 * resources and information passed, and map the necessary registers.
844 static int ax_probe(struct platform_device
*pdev
)
846 struct net_device
*dev
;
847 struct ei_device
*ei_local
;
848 struct ax_device
*ax
;
849 struct resource
*irq
, *mem
, *mem2
;
850 unsigned long mem_size
, mem2_size
= 0;
853 dev
= ax__alloc_ei_netdev(sizeof(struct ax_device
));
857 /* ok, let's setup our device */
858 SET_NETDEV_DEV(dev
, &pdev
->dev
);
859 ei_local
= netdev_priv(dev
);
862 ax
->plat
= dev_get_platdata(&pdev
->dev
);
863 platform_set_drvdata(pdev
, dev
);
865 ei_local
->rxcr_base
= ax
->plat
->rcr_val
;
867 /* find the platform resources */
868 irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
870 dev_err(&pdev
->dev
, "no IRQ specified\n");
875 dev
->irq
= irq
->start
;
876 ax
->irqflags
= irq
->flags
& IRQF_TRIGGER_MASK
;
878 if (irq
->flags
& IORESOURCE_IRQ_SHAREABLE
)
879 ax
->irqflags
|= IRQF_SHARED
;
881 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
883 dev_err(&pdev
->dev
, "no MEM specified\n");
888 mem_size
= resource_size(mem
);
891 * setup the register offsets from either the platform data or
892 * by using the size of the resource provided
894 if (ax
->plat
->reg_offsets
)
895 ei_local
->reg_offset
= ax
->plat
->reg_offsets
;
897 ei_local
->reg_offset
= ax
->reg_offsets
;
898 for (ret
= 0; ret
< 0x18; ret
++)
899 ax
->reg_offsets
[ret
] = (mem_size
/ 0x18) * ret
;
902 if (!request_mem_region(mem
->start
, mem_size
, pdev
->name
)) {
903 dev_err(&pdev
->dev
, "cannot reserve registers\n");
908 ei_local
->mem
= ioremap(mem
->start
, mem_size
);
909 dev
->base_addr
= (unsigned long)ei_local
->mem
;
911 if (ei_local
->mem
== NULL
) {
912 dev_err(&pdev
->dev
, "Cannot ioremap area %pR\n", mem
);
918 /* look for reset area */
919 mem2
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
921 if (!ax
->plat
->reg_offsets
) {
922 for (ret
= 0; ret
< 0x20; ret
++)
923 ax
->reg_offsets
[ret
] = (mem_size
/ 0x20) * ret
;
926 mem2_size
= resource_size(mem2
);
928 if (!request_mem_region(mem2
->start
, mem2_size
, pdev
->name
)) {
929 dev_err(&pdev
->dev
, "cannot reserve registers\n");
934 ax
->map2
= ioremap(mem2
->start
, mem2_size
);
936 dev_err(&pdev
->dev
, "cannot map reset register\n");
941 ei_local
->reg_offset
[0x1f] = ax
->map2
- ei_local
->mem
;
944 /* got resources, now initialise and register device */
945 ret
= ax_init_dev(dev
);
956 release_mem_region(mem2
->start
, mem2_size
);
959 iounmap(ei_local
->mem
);
962 release_mem_region(mem
->start
, mem_size
);
965 platform_set_drvdata(pdev
, NULL
);
971 /* suspend and resume */
974 static int ax_suspend(struct platform_device
*dev
, pm_message_t state
)
976 struct net_device
*ndev
= platform_get_drvdata(dev
);
977 struct ax_device
*ax
= to_ax_dev(ndev
);
979 ax
->resume_open
= ax
->running
;
981 netif_device_detach(ndev
);
987 static int ax_resume(struct platform_device
*pdev
)
989 struct net_device
*ndev
= platform_get_drvdata(pdev
);
990 struct ax_device
*ax
= to_ax_dev(ndev
);
992 ax_initial_setup(ndev
, netdev_priv(ndev
));
993 ax_NS8390_init(ndev
, ax
->resume_open
);
994 netif_device_attach(ndev
);
1003 #define ax_suspend NULL
1004 #define ax_resume NULL
1007 static struct platform_driver axdrv
= {
1012 .remove
= ax_remove
,
1013 .suspend
= ax_suspend
,
1014 .resume
= ax_resume
,
1017 module_platform_driver(axdrv
);
1019 MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
1020 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
1021 MODULE_LICENSE("GPL v2");
1022 MODULE_ALIAS("platform:ax88796");