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 static u32 ax_msg_enable
;
82 /* device private data */
85 struct mii_bus
*mii_bus
;
86 struct mdiobb_ctrl bb_ctrl
;
87 void __iomem
*addr_memr
;
94 const struct ax_plat_data
*plat
;
96 unsigned char running
;
97 unsigned char resume_open
;
98 unsigned int irqflags
;
100 u32 reg_offsets
[0x20];
103 static inline struct ax_device
*to_ax_dev(struct net_device
*dev
)
105 struct ei_device
*ei_local
= netdev_priv(dev
);
106 return (struct ax_device
*)(ei_local
+ 1);
112 * do an initial probe for the card to check whether it exists
115 static int ax_initial_check(struct net_device
*dev
)
117 struct ei_device
*ei_local
= netdev_priv(dev
);
118 void __iomem
*ioaddr
= ei_local
->mem
;
122 reg0
= ei_inb(ioaddr
);
126 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
127 regd
= ei_inb(ioaddr
+ 0x0d);
128 ei_outb(0xff, ioaddr
+ 0x0d);
129 ei_outb(E8390_NODMA
+ E8390_PAGE0
, ioaddr
+ E8390_CMD
);
130 ei_inb(ioaddr
+ EN0_COUNTER0
); /* Clear the counter by reading. */
131 if (ei_inb(ioaddr
+ EN0_COUNTER0
) != 0) {
132 ei_outb(reg0
, ioaddr
);
133 ei_outb(regd
, ioaddr
+ 0x0d); /* Restore the old values. */
141 * Hard reset the card. This used to pause for the same period that a
142 * 8390 reset command required, but that shouldn't be necessary.
144 static void ax_reset_8390(struct net_device
*dev
)
146 struct ei_device
*ei_local
= netdev_priv(dev
);
147 unsigned long reset_start_time
= jiffies
;
148 void __iomem
*addr
= (void __iomem
*)dev
->base_addr
;
150 netif_dbg(ei_local
, hw
, dev
, "resetting the 8390 t=%ld...\n", jiffies
);
152 ei_outb(ei_inb(addr
+ NE_RESET
), addr
+ NE_RESET
);
155 ei_local
->dmaing
= 0;
157 /* This check _should_not_ be necessary, omit eventually. */
158 while ((ei_inb(addr
+ EN0_ISR
) & ENISR_RESET
) == 0) {
159 if (time_after(jiffies
, reset_start_time
+ 2 * HZ
/ 100)) {
160 netdev_warn(dev
, "%s: did not complete.\n", __func__
);
165 ei_outb(ENISR_RESET
, addr
+ EN0_ISR
); /* Ack intr. */
169 static void ax_get_8390_hdr(struct net_device
*dev
, struct e8390_pkt_hdr
*hdr
,
172 struct ei_device
*ei_local
= netdev_priv(dev
);
173 void __iomem
*nic_base
= ei_local
->mem
;
175 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
176 if (ei_local
->dmaing
) {
177 netdev_err(dev
, "DMAing conflict in %s "
178 "[DMAstat:%d][irqlock:%d].\n",
180 ei_local
->dmaing
, ei_local
->irqlock
);
184 ei_local
->dmaing
|= 0x01;
185 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_START
, nic_base
+ NE_CMD
);
186 ei_outb(sizeof(struct e8390_pkt_hdr
), nic_base
+ EN0_RCNTLO
);
187 ei_outb(0, nic_base
+ EN0_RCNTHI
);
188 ei_outb(0, nic_base
+ EN0_RSARLO
); /* On page boundary */
189 ei_outb(ring_page
, nic_base
+ EN0_RSARHI
);
190 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
192 if (ei_local
->word16
)
193 ioread16_rep(nic_base
+ NE_DATAPORT
, hdr
,
194 sizeof(struct e8390_pkt_hdr
) >> 1);
196 ioread8_rep(nic_base
+ NE_DATAPORT
, hdr
,
197 sizeof(struct e8390_pkt_hdr
));
199 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
200 ei_local
->dmaing
&= ~0x01;
202 le16_to_cpus(&hdr
->count
);
207 * Block input and output, similar to the Crynwr packet driver. If
208 * you are porting to a new ethercard, look at the packet driver
209 * source for hints. The NEx000 doesn't share the on-board packet
210 * memory -- you have to put the packet out through the "remote DMA"
211 * dataport using ei_outb.
213 static void ax_block_input(struct net_device
*dev
, int count
,
214 struct sk_buff
*skb
, int ring_offset
)
216 struct ei_device
*ei_local
= netdev_priv(dev
);
217 void __iomem
*nic_base
= ei_local
->mem
;
218 char *buf
= skb
->data
;
220 if (ei_local
->dmaing
) {
222 "DMAing conflict in %s "
223 "[DMAstat:%d][irqlock:%d].\n",
225 ei_local
->dmaing
, ei_local
->irqlock
);
229 ei_local
->dmaing
|= 0x01;
231 ei_outb(E8390_NODMA
+E8390_PAGE0
+E8390_START
, nic_base
+ NE_CMD
);
232 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
233 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
234 ei_outb(ring_offset
& 0xff, nic_base
+ EN0_RSARLO
);
235 ei_outb(ring_offset
>> 8, nic_base
+ EN0_RSARHI
);
236 ei_outb(E8390_RREAD
+E8390_START
, nic_base
+ NE_CMD
);
238 if (ei_local
->word16
) {
239 ioread16_rep(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
241 buf
[count
-1] = ei_inb(nic_base
+ NE_DATAPORT
);
244 ioread8_rep(nic_base
+ NE_DATAPORT
, buf
, count
);
247 ei_local
->dmaing
&= ~1;
250 static void ax_block_output(struct net_device
*dev
, int count
,
251 const unsigned char *buf
, const int start_page
)
253 struct ei_device
*ei_local
= netdev_priv(dev
);
254 void __iomem
*nic_base
= ei_local
->mem
;
255 unsigned long dma_start
;
258 * Round the count up for word writes. Do we need to do this?
259 * What effect will an odd byte count have on the 8390? I
260 * should check someday.
262 if (ei_local
->word16
&& (count
& 0x01))
265 /* This *shouldn't* happen. If it does, it's the last thing you'll see */
266 if (ei_local
->dmaing
) {
267 netdev_err(dev
, "DMAing conflict in %s."
268 "[DMAstat:%d][irqlock:%d]\n",
270 ei_local
->dmaing
, ei_local
->irqlock
);
274 ei_local
->dmaing
|= 0x01;
275 /* We should already be in page 0, but to be safe... */
276 ei_outb(E8390_PAGE0
+E8390_START
+E8390_NODMA
, nic_base
+ NE_CMD
);
278 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
);
280 /* Now the normal output. */
281 ei_outb(count
& 0xff, nic_base
+ EN0_RCNTLO
);
282 ei_outb(count
>> 8, nic_base
+ EN0_RCNTHI
);
283 ei_outb(0x00, nic_base
+ EN0_RSARLO
);
284 ei_outb(start_page
, nic_base
+ EN0_RSARHI
);
286 ei_outb(E8390_RWRITE
+E8390_START
, nic_base
+ NE_CMD
);
287 if (ei_local
->word16
)
288 iowrite16_rep(nic_base
+ NE_DATAPORT
, buf
, count
>> 1);
290 iowrite8_rep(nic_base
+ NE_DATAPORT
, buf
, count
);
294 while ((ei_inb(nic_base
+ EN0_ISR
) & ENISR_RDC
) == 0) {
295 if (time_after(jiffies
, dma_start
+ 2 * HZ
/ 100)) { /* 20ms */
296 netdev_warn(dev
, "timeout waiting for Tx RDC.\n");
298 ax_NS8390_init(dev
, 1);
303 ei_outb(ENISR_RDC
, nic_base
+ EN0_ISR
); /* Ack intr. */
304 ei_local
->dmaing
&= ~0x01;
307 /* definitions for accessing MII/EEPROM interface */
309 #define AX_MEMR EI_SHIFT(0x14)
310 #define AX_MEMR_MDC BIT(0)
311 #define AX_MEMR_MDIR BIT(1)
312 #define AX_MEMR_MDI BIT(2)
313 #define AX_MEMR_MDO BIT(3)
314 #define AX_MEMR_EECS BIT(4)
315 #define AX_MEMR_EEI BIT(5)
316 #define AX_MEMR_EEO BIT(6)
317 #define AX_MEMR_EECLK BIT(7)
319 static void ax_handle_link_change(struct net_device
*dev
)
321 struct ax_device
*ax
= to_ax_dev(dev
);
322 struct phy_device
*phy_dev
= dev
->phydev
;
323 int status_change
= 0;
325 if (phy_dev
->link
&& ((ax
->speed
!= phy_dev
->speed
) ||
326 (ax
->duplex
!= phy_dev
->duplex
))) {
328 ax
->speed
= phy_dev
->speed
;
329 ax
->duplex
= phy_dev
->duplex
;
333 if (phy_dev
->link
!= ax
->link
) {
334 if (!phy_dev
->link
) {
338 ax
->link
= phy_dev
->link
;
344 phy_print_status(phy_dev
);
347 static int ax_mii_probe(struct net_device
*dev
)
349 struct ax_device
*ax
= to_ax_dev(dev
);
350 struct phy_device
*phy_dev
= NULL
;
353 /* find the first phy */
354 phy_dev
= phy_find_first(ax
->mii_bus
);
356 netdev_err(dev
, "no PHY found\n");
360 ret
= phy_connect_direct(dev
, phy_dev
, ax_handle_link_change
,
361 PHY_INTERFACE_MODE_MII
);
363 netdev_err(dev
, "Could not attach to PHY\n");
367 /* mask with MAC supported features */
368 phy_dev
->supported
&= PHY_BASIC_FEATURES
;
369 phy_dev
->advertising
= phy_dev
->supported
;
371 netdev_info(dev
, "PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
372 phy_dev
->drv
->name
, phydev_name(phy_dev
), phy_dev
->irq
);
377 static void ax_phy_switch(struct net_device
*dev
, int on
)
379 struct ei_device
*ei_local
= netdev_priv(dev
);
380 struct ax_device
*ax
= to_ax_dev(dev
);
382 u8 reg_gpoc
= ax
->plat
->gpoc_val
;
385 reg_gpoc
&= ~AX_GPOC_PPDSET
;
387 reg_gpoc
|= AX_GPOC_PPDSET
;
389 ei_outb(reg_gpoc
, ei_local
->mem
+ EI_SHIFT(0x17));
392 static int ax_open(struct net_device
*dev
)
394 struct ax_device
*ax
= to_ax_dev(dev
);
397 netdev_dbg(dev
, "open\n");
399 ret
= request_irq(dev
->irq
, ax_ei_interrupt
, ax
->irqflags
,
402 goto failed_request_irq
;
404 /* turn the phy on (if turned off) */
405 ax_phy_switch(dev
, 1);
407 ret
= ax_mii_probe(dev
);
409 goto failed_mii_probe
;
410 phy_start(dev
->phydev
);
412 ret
= ax_ei_open(dev
);
414 goto failed_ax_ei_open
;
421 phy_disconnect(dev
->phydev
);
423 ax_phy_switch(dev
, 0);
424 free_irq(dev
->irq
, dev
);
429 static int ax_close(struct net_device
*dev
)
431 struct ax_device
*ax
= to_ax_dev(dev
);
433 netdev_dbg(dev
, "close\n");
440 /* turn the phy off */
441 ax_phy_switch(dev
, 0);
442 phy_disconnect(dev
->phydev
);
444 free_irq(dev
->irq
, dev
);
448 static int ax_ioctl(struct net_device
*dev
, struct ifreq
*req
, int cmd
)
450 struct phy_device
*phy_dev
= dev
->phydev
;
452 if (!netif_running(dev
))
458 return phy_mii_ioctl(phy_dev
, req
, cmd
);
463 static void ax_get_drvinfo(struct net_device
*dev
,
464 struct ethtool_drvinfo
*info
)
466 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
468 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
469 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
470 strlcpy(info
->bus_info
, pdev
->name
, sizeof(info
->bus_info
));
473 static u32
ax_get_msglevel(struct net_device
*dev
)
475 struct ei_device
*ei_local
= netdev_priv(dev
);
477 return ei_local
->msg_enable
;
480 static void ax_set_msglevel(struct net_device
*dev
, u32 v
)
482 struct ei_device
*ei_local
= netdev_priv(dev
);
484 ei_local
->msg_enable
= v
;
487 static const struct ethtool_ops ax_ethtool_ops
= {
488 .get_drvinfo
= ax_get_drvinfo
,
489 .get_link
= ethtool_op_get_link
,
490 .get_ts_info
= ethtool_op_get_ts_info
,
491 .get_msglevel
= ax_get_msglevel
,
492 .set_msglevel
= ax_set_msglevel
,
493 .get_link_ksettings
= phy_ethtool_get_link_ksettings
,
494 .set_link_ksettings
= phy_ethtool_set_link_ksettings
,
497 #ifdef CONFIG_AX88796_93CX6
498 static void ax_eeprom_register_read(struct eeprom_93cx6
*eeprom
)
500 struct ei_device
*ei_local
= eeprom
->data
;
501 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
503 eeprom
->reg_data_in
= reg
& AX_MEMR_EEI
;
504 eeprom
->reg_data_out
= reg
& AX_MEMR_EEO
; /* Input pin */
505 eeprom
->reg_data_clock
= reg
& AX_MEMR_EECLK
;
506 eeprom
->reg_chip_select
= reg
& AX_MEMR_EECS
;
509 static void ax_eeprom_register_write(struct eeprom_93cx6
*eeprom
)
511 struct ei_device
*ei_local
= eeprom
->data
;
512 u8 reg
= ei_inb(ei_local
->mem
+ AX_MEMR
);
514 reg
&= ~(AX_MEMR_EEI
| AX_MEMR_EECLK
| AX_MEMR_EECS
);
516 if (eeprom
->reg_data_in
)
518 if (eeprom
->reg_data_clock
)
519 reg
|= AX_MEMR_EECLK
;
520 if (eeprom
->reg_chip_select
)
523 ei_outb(reg
, ei_local
->mem
+ AX_MEMR
);
528 static const struct net_device_ops ax_netdev_ops
= {
530 .ndo_stop
= ax_close
,
531 .ndo_do_ioctl
= ax_ioctl
,
533 .ndo_start_xmit
= ax_ei_start_xmit
,
534 .ndo_tx_timeout
= ax_ei_tx_timeout
,
535 .ndo_get_stats
= ax_ei_get_stats
,
536 .ndo_set_rx_mode
= ax_ei_set_multicast_list
,
537 .ndo_validate_addr
= eth_validate_addr
,
538 .ndo_set_mac_address
= eth_mac_addr
,
539 .ndo_change_mtu
= eth_change_mtu
,
540 #ifdef CONFIG_NET_POLL_CONTROLLER
541 .ndo_poll_controller
= ax_ei_poll
,
545 static void ax_bb_mdc(struct mdiobb_ctrl
*ctrl
, int level
)
547 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
550 ax
->reg_memr
|= AX_MEMR_MDC
;
552 ax
->reg_memr
&= ~AX_MEMR_MDC
;
554 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
557 static void ax_bb_dir(struct mdiobb_ctrl
*ctrl
, int output
)
559 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
562 ax
->reg_memr
&= ~AX_MEMR_MDIR
;
564 ax
->reg_memr
|= AX_MEMR_MDIR
;
566 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
569 static void ax_bb_set_data(struct mdiobb_ctrl
*ctrl
, int value
)
571 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
574 ax
->reg_memr
|= AX_MEMR_MDO
;
576 ax
->reg_memr
&= ~AX_MEMR_MDO
;
578 ei_outb(ax
->reg_memr
, ax
->addr_memr
);
581 static int ax_bb_get_data(struct mdiobb_ctrl
*ctrl
)
583 struct ax_device
*ax
= container_of(ctrl
, struct ax_device
, bb_ctrl
);
584 int reg_memr
= ei_inb(ax
->addr_memr
);
586 return reg_memr
& AX_MEMR_MDI
? 1 : 0;
589 static struct mdiobb_ops bb_ops
= {
590 .owner
= THIS_MODULE
,
591 .set_mdc
= ax_bb_mdc
,
592 .set_mdio_dir
= ax_bb_dir
,
593 .set_mdio_data
= ax_bb_set_data
,
594 .get_mdio_data
= ax_bb_get_data
,
599 static int ax_mii_init(struct net_device
*dev
)
601 struct platform_device
*pdev
= to_platform_device(dev
->dev
.parent
);
602 struct ei_device
*ei_local
= netdev_priv(dev
);
603 struct ax_device
*ax
= to_ax_dev(dev
);
606 ax
->bb_ctrl
.ops
= &bb_ops
;
607 ax
->addr_memr
= ei_local
->mem
+ AX_MEMR
;
608 ax
->mii_bus
= alloc_mdio_bitbang(&ax
->bb_ctrl
);
614 ax
->mii_bus
->name
= "ax88796_mii_bus";
615 ax
->mii_bus
->parent
= dev
->dev
.parent
;
616 snprintf(ax
->mii_bus
->id
, MII_BUS_ID_SIZE
, "%s-%x",
617 pdev
->name
, pdev
->id
);
619 err
= mdiobus_register(ax
->mii_bus
);
621 goto out_free_mdio_bitbang
;
625 out_free_mdio_bitbang
:
626 free_mdio_bitbang(ax
->mii_bus
);
631 static void ax_initial_setup(struct net_device
*dev
, struct ei_device
*ei_local
)
633 void __iomem
*ioaddr
= ei_local
->mem
;
634 struct ax_device
*ax
= to_ax_dev(dev
);
637 ei_outb(E8390_NODMA
+ E8390_PAGE0
+ E8390_STOP
, ioaddr
+ E8390_CMD
);
639 /* set to byte access */
640 ei_outb(ax
->plat
->dcr_val
& ~1, ioaddr
+ EN0_DCFG
);
641 ei_outb(ax
->plat
->gpoc_val
, ioaddr
+ EI_SHIFT(0x17));
647 * initialise the specified device, taking care to note the MAC
648 * address it may already have (if configured), ensure
649 * the device is ready to be used by lib8390.c and registerd with
652 static int ax_init_dev(struct net_device
*dev
)
654 struct ei_device
*ei_local
= netdev_priv(dev
);
655 struct ax_device
*ax
= to_ax_dev(dev
);
656 void __iomem
*ioaddr
= ei_local
->mem
;
657 unsigned int start_page
;
658 unsigned int stop_page
;
662 ret
= ax_initial_check(dev
);
666 /* setup goes here */
668 ax_initial_setup(dev
, ei_local
);
670 /* read the mac from the card prom if we need it */
672 if (ax
->plat
->flags
& AXFLG_HAS_EEPROM
) {
673 unsigned char SA_prom
[32];
675 for (i
= 0; i
< sizeof(SA_prom
); i
+= 2) {
676 SA_prom
[i
] = ei_inb(ioaddr
+ NE_DATAPORT
);
677 SA_prom
[i
+ 1] = ei_inb(ioaddr
+ NE_DATAPORT
);
680 if (ax
->plat
->wordlength
== 2)
681 for (i
= 0; i
< 16; i
++)
682 SA_prom
[i
] = SA_prom
[i
+i
];
684 memcpy(dev
->dev_addr
, SA_prom
, ETH_ALEN
);
687 #ifdef CONFIG_AX88796_93CX6
688 if (ax
->plat
->flags
& AXFLG_HAS_93CX6
) {
689 unsigned char mac_addr
[ETH_ALEN
];
690 struct eeprom_93cx6 eeprom
;
692 eeprom
.data
= ei_local
;
693 eeprom
.register_read
= ax_eeprom_register_read
;
694 eeprom
.register_write
= ax_eeprom_register_write
;
695 eeprom
.width
= PCI_EEPROM_WIDTH_93C56
;
697 eeprom_93cx6_multiread(&eeprom
, 0,
698 (__le16 __force
*)mac_addr
,
699 sizeof(mac_addr
) >> 1);
701 memcpy(dev
->dev_addr
, mac_addr
, ETH_ALEN
);
704 if (ax
->plat
->wordlength
== 2) {
705 /* We must set the 8390 for word mode. */
706 ei_outb(ax
->plat
->dcr_val
, ei_local
->mem
+ EN0_DCFG
);
707 start_page
= NESM_START_PG
;
708 stop_page
= NESM_STOP_PG
;
710 start_page
= NE1SM_START_PG
;
711 stop_page
= NE1SM_STOP_PG
;
714 /* load the mac-address from the device */
715 if (ax
->plat
->flags
& AXFLG_MAC_FROMDEV
) {
716 ei_outb(E8390_NODMA
+ E8390_PAGE1
+ E8390_STOP
,
717 ei_local
->mem
+ E8390_CMD
); /* 0x61 */
718 for (i
= 0; i
< ETH_ALEN
; i
++)
720 ei_inb(ioaddr
+ EN1_PHYS_SHIFT(i
));
723 if ((ax
->plat
->flags
& AXFLG_MAC_FROMPLATFORM
) &&
725 memcpy(dev
->dev_addr
, ax
->plat
->mac_addr
, ETH_ALEN
);
729 ei_local
->name
= "AX88796";
730 ei_local
->tx_start_page
= start_page
;
731 ei_local
->stop_page
= stop_page
;
732 ei_local
->word16
= (ax
->plat
->wordlength
== 2);
733 ei_local
->rx_start_page
= start_page
+ TX_PAGES
;
735 #ifdef PACKETBUF_MEMSIZE
736 /* Allow the packet buffer size to be overridden by know-it-alls. */
737 ei_local
->stop_page
= ei_local
->tx_start_page
+ PACKETBUF_MEMSIZE
;
740 ei_local
->reset_8390
= &ax_reset_8390
;
741 ei_local
->block_input
= &ax_block_input
;
742 ei_local
->block_output
= &ax_block_output
;
743 ei_local
->get_8390_hdr
= &ax_get_8390_hdr
;
745 ei_local
->msg_enable
= ax_msg_enable
;
747 dev
->netdev_ops
= &ax_netdev_ops
;
748 dev
->ethtool_ops
= &ax_ethtool_ops
;
750 ret
= ax_mii_init(dev
);
754 ax_NS8390_init(dev
, 0);
756 ret
= register_netdev(dev
);
760 netdev_info(dev
, "%dbit, irq %d, %lx, MAC: %pM\n",
761 ei_local
->word16
? 16 : 8, dev
->irq
, dev
->base_addr
,
768 free_irq(dev
->irq
, dev
);
773 static int ax_remove(struct platform_device
*pdev
)
775 struct net_device
*dev
= platform_get_drvdata(pdev
);
776 struct ei_device
*ei_local
= netdev_priv(dev
);
777 struct ax_device
*ax
= to_ax_dev(dev
);
778 struct resource
*mem
;
780 unregister_netdev(dev
);
781 free_irq(dev
->irq
, dev
);
783 iounmap(ei_local
->mem
);
784 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
785 release_mem_region(mem
->start
, resource_size(mem
));
789 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
790 release_mem_region(mem
->start
, resource_size(mem
));
801 * This is the entry point when the platform device system uses to
802 * notify us of a new device to attach to. Allocate memory, find the
803 * resources and information passed, and map the necessary registers.
805 static int ax_probe(struct platform_device
*pdev
)
807 struct net_device
*dev
;
808 struct ei_device
*ei_local
;
809 struct ax_device
*ax
;
810 struct resource
*irq
, *mem
, *mem2
;
811 unsigned long mem_size
, mem2_size
= 0;
814 dev
= ax__alloc_ei_netdev(sizeof(struct ax_device
));
818 /* ok, let's setup our device */
819 SET_NETDEV_DEV(dev
, &pdev
->dev
);
820 ei_local
= netdev_priv(dev
);
823 ax
->plat
= dev_get_platdata(&pdev
->dev
);
824 platform_set_drvdata(pdev
, dev
);
826 ei_local
->rxcr_base
= ax
->plat
->rcr_val
;
828 /* find the platform resources */
829 irq
= platform_get_resource(pdev
, IORESOURCE_IRQ
, 0);
831 dev_err(&pdev
->dev
, "no IRQ specified\n");
836 dev
->irq
= irq
->start
;
837 ax
->irqflags
= irq
->flags
& IRQF_TRIGGER_MASK
;
839 mem
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
841 dev_err(&pdev
->dev
, "no MEM specified\n");
846 mem_size
= resource_size(mem
);
849 * setup the register offsets from either the platform data or
850 * by using the size of the resource provided
852 if (ax
->plat
->reg_offsets
)
853 ei_local
->reg_offset
= ax
->plat
->reg_offsets
;
855 ei_local
->reg_offset
= ax
->reg_offsets
;
856 for (ret
= 0; ret
< 0x18; ret
++)
857 ax
->reg_offsets
[ret
] = (mem_size
/ 0x18) * ret
;
860 if (!request_mem_region(mem
->start
, mem_size
, pdev
->name
)) {
861 dev_err(&pdev
->dev
, "cannot reserve registers\n");
866 ei_local
->mem
= ioremap(mem
->start
, mem_size
);
867 dev
->base_addr
= (unsigned long)ei_local
->mem
;
869 if (ei_local
->mem
== NULL
) {
870 dev_err(&pdev
->dev
, "Cannot ioremap area %pR\n", mem
);
876 /* look for reset area */
877 mem2
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
879 if (!ax
->plat
->reg_offsets
) {
880 for (ret
= 0; ret
< 0x20; ret
++)
881 ax
->reg_offsets
[ret
] = (mem_size
/ 0x20) * ret
;
884 mem2_size
= resource_size(mem2
);
886 if (!request_mem_region(mem2
->start
, mem2_size
, pdev
->name
)) {
887 dev_err(&pdev
->dev
, "cannot reserve registers\n");
892 ax
->map2
= ioremap(mem2
->start
, mem2_size
);
894 dev_err(&pdev
->dev
, "cannot map reset register\n");
899 ei_local
->reg_offset
[0x1f] = ax
->map2
- ei_local
->mem
;
902 /* got resources, now initialise and register device */
903 ret
= ax_init_dev(dev
);
914 release_mem_region(mem2
->start
, mem2_size
);
917 iounmap(ei_local
->mem
);
920 release_mem_region(mem
->start
, mem_size
);
928 /* suspend and resume */
931 static int ax_suspend(struct platform_device
*dev
, pm_message_t state
)
933 struct net_device
*ndev
= platform_get_drvdata(dev
);
934 struct ax_device
*ax
= to_ax_dev(ndev
);
936 ax
->resume_open
= ax
->running
;
938 netif_device_detach(ndev
);
944 static int ax_resume(struct platform_device
*pdev
)
946 struct net_device
*ndev
= platform_get_drvdata(pdev
);
947 struct ax_device
*ax
= to_ax_dev(ndev
);
949 ax_initial_setup(ndev
, netdev_priv(ndev
));
950 ax_NS8390_init(ndev
, ax
->resume_open
);
951 netif_device_attach(ndev
);
960 #define ax_suspend NULL
961 #define ax_resume NULL
964 static struct platform_driver axdrv
= {
970 .suspend
= ax_suspend
,
974 module_platform_driver(axdrv
);
976 MODULE_DESCRIPTION("AX88796 10/100 Ethernet platform driver");
977 MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
978 MODULE_LICENSE("GPL v2");
979 MODULE_ALIAS("platform:ax88796");