14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
24 #include <linux/netdevice.h>
26 #include <linux/ethtool.h>
30 #include <linux/slab.h>
36 #define __ei_open ax_ei_open
37 #define __ei_close ax_ei_close
38 #define __ei_poll ax_ei_poll
39 #define __ei_start_xmit ax_ei_start_xmit
40 #define __ei_tx_timeout ax_ei_tx_timeout
41 #define __ei_get_stats ax_ei_get_stats
42 #define __ei_set_multicast_list ax_ei_set_multicast_list
43 #define __ei_interrupt ax_ei_interrupt
44 #define ____alloc_ei_netdev ax__alloc_ei_netdev
45 #define __NS8390_init ax_NS8390_init
48 #define ax_convert_addr(_a) ((void __force __iomem *)(_a))
50 #define ei_inb(_a) readb(ax_convert_addr(_a))
51 #define ei_outb(_v, _a) writeb(_v, ax_convert_addr(_a))
53 #define ei_inb_p(_a) ei_inb(_a)
54 #define ei_outb_p(_v, _a) ei_outb(_v, _a)
57 #define EI_SHIFT(x) (ei_local->reg_offset[(x)])
60 #define AX88796_PLATFORM
62 static unsigned char version[] =
"ax88796.c: Copyright 2005,2007 Simtec Electronics\n";
66 #define DRV_NAME "ax88796"
67 #define DRV_VERSION "1.00"
70 #define NE_CMD EI_SHIFT(0x00)
71 #define NE_RESET EI_SHIFT(0x1f)
72 #define NE_DATAPORT EI_SHIFT(0x10)
74 #define NE1SM_START_PG 0x20
75 #define NE1SM_STOP_PG 0x40
76 #define NESM_START_PG 0x40
77 #define NESM_STOP_PG 0x80
79 #define AX_GPOC_PPDSET BIT(6)
105 struct ei_device *ei_local = netdev_priv(dev);
106 return (
struct ax_device *)(ei_local + 1);
117 struct ei_device *ei_local = netdev_priv(dev);
127 regd =
ei_inb(ioaddr + 0x0d);
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;
151 netdev_dbg(dev,
"resetting the 8390 t=%ld\n", jiffies);
160 if (jiffies - reset_start_time > 2 *
HZ / 100) {
161 netdev_warn(dev,
"%s: did not complete.\n", __func__);
173 struct ei_device *ei_local = netdev_priv(dev);
178 netdev_err(dev,
"DMAing conflict in %s "
179 "[DMAstat:%d][irqlock:%d].\n",
201 ei_local->
dmaing &= ~0x01;
217 struct ei_device *ei_local = netdev_priv(dev);
223 "DMAing conflict in %s "
224 "[DMAstat:%d][irqlock:%d].\n",
251 static void ax_block_output(
struct net_device *dev,
int count,
252 const unsigned char *buf,
const int start_page)
254 struct ei_device *ei_local = netdev_priv(dev);
263 if (ei_local->
word16 && (count & 0x01))
268 netdev_err(dev,
"DMAing conflict in %s."
269 "[DMAstat:%d][irqlock:%d]\n",
296 if (jiffies - dma_start > 2 *
HZ / 100) {
297 netdev_warn(dev,
"timeout waiting for Tx RDC.\n");
299 ax_NS8390_init(dev, 1);
305 ei_local->
dmaing &= ~0x01;
310 #define AX_MEMR EI_SHIFT(0x14)
311 #define AX_MEMR_MDC BIT(0)
312 #define AX_MEMR_MDIR BIT(1)
313 #define AX_MEMR_MDI BIT(2)
314 #define AX_MEMR_MDO BIT(3)
315 #define AX_MEMR_EECS BIT(4)
316 #define AX_MEMR_EEI BIT(5)
317 #define AX_MEMR_EEO BIT(6)
318 #define AX_MEMR_EECLK BIT(7)
320 static void ax_handle_link_change(
struct net_device *dev)
324 int status_change = 0;
335 if (!phy_dev->
link) {
348 static int ax_mii_probe(
struct net_device *dev)
357 netdev_err(dev,
"no PHY found\n");
364 netdev_err(dev,
"Could not attach to PHY\n");
374 netdev_info(dev,
"PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
375 phy_dev->
drv->name, dev_name(&phy_dev->
dev), phy_dev->
irq);
380 static void ax_phy_switch(
struct net_device *dev,
int on)
382 struct ei_device *ei_local = netdev_priv(dev);
385 u8 reg_gpoc = ax->
plat->gpoc_val;
405 goto failed_request_irq;
408 ax_phy_switch(dev, 1);
410 ret = ax_mii_probe(dev);
412 goto failed_mii_probe;
415 ret = ax_ei_open(dev);
417 goto failed_ax_ei_open;
426 ax_phy_switch(dev, 0);
444 ax_phy_switch(dev, 0);
456 if (!netif_running(dev))
467 static void ax_get_drvinfo(
struct net_device *dev,
500 .get_drvinfo = ax_get_drvinfo,
501 .get_settings = ax_get_settings,
502 .set_settings = ax_set_settings,
507 #ifdef CONFIG_AX88796_93CX6
540 .ndo_stop = ax_close,
541 .ndo_do_ioctl = ax_ioctl,
543 .ndo_start_xmit = ax_ei_start_xmit,
544 .ndo_tx_timeout = ax_ei_tx_timeout,
545 .ndo_get_stats = ax_ei_get_stats,
546 .ndo_set_rx_mode = ax_ei_set_multicast_list,
550 #ifdef CONFIG_NET_POLL_CONTROLLER
551 .ndo_poll_controller = ax_ei_poll,
567 static void ax_bb_dir(
struct mdiobb_ctrl *ctrl,
int output)
591 static int ax_bb_get_data(
struct mdiobb_ctrl *ctrl)
601 .set_mdc = ax_bb_mdc,
602 .set_mdio_dir = ax_bb_dir,
603 .set_mdio_data = ax_bb_set_data,
604 .get_mdio_data = ax_bb_get_data,
609 static int ax_mii_init(
struct net_device *dev)
612 struct ei_device *ei_local = netdev_priv(dev);
624 ax->
mii_bus->name =
"ax88796_mii_bus";
632 goto out_free_mdio_bitbang;
646 out_free_mdio_bitbang:
673 static int ax_init_dev(
struct net_device *dev)
675 struct ei_device *ei_local = netdev_priv(dev);
678 unsigned int start_page;
679 unsigned int stop_page;
683 ret = ax_initial_check(dev);
689 ax_initial_setup(dev, ei_local);
694 unsigned char SA_prom[32];
696 for (i = 0; i <
sizeof(SA_prom); i += 2) {
701 if (ax->
plat->wordlength == 2)
702 for (i = 0; i < 16; i++)
703 SA_prom[i] = SA_prom[i+i];
708 #ifdef CONFIG_AX88796_93CX6
713 eeprom.
data = ei_local;
720 sizeof(mac_addr) >> 1);
725 if (ax->
plat->wordlength == 2) {
750 ei_local->
name =
"AX88796";
753 ei_local->
word16 = (ax->
plat->wordlength == 2);
756 #ifdef PACKETBUF_MEMSIZE
770 ret = ax_mii_init(dev);
774 ax_NS8390_init(dev, 0);
780 netdev_info(dev,
"%dbit, irq %d, %lx, MAC: %pM\n",
795 struct net_device *dev = platform_get_drvdata(pdev);
796 struct ei_device *ei_local = netdev_priv(dev);
834 dev = ax__alloc_ei_netdev(
sizeof(
struct ax_device));
840 ei_local = netdev_priv(dev);
843 ax->
plat = pdev->
dev.platform_data;
844 platform_set_drvdata(pdev, dev);
846 ei_local->rxcr_base = ax->
plat->rcr_val;
866 mem_size = resource_size(mem);
872 if (ax->
plat->reg_offsets)
876 for (ret = 0; ret < 0x18; ret++)
881 dev_err(&pdev->
dev,
"cannot reserve registers\n");
890 dev_err(&pdev->
dev,
"Cannot ioremap area %pR\n", mem);
899 if (!ax->
plat->reg_offsets) {
900 for (ret = 0; ret < 0x20; ret++)
904 mem2_size = resource_size(mem2);
907 dev_err(&pdev->
dev,
"cannot reserve registers\n");
914 dev_err(&pdev->
dev,
"cannot map reset register\n");
923 ret = ax_init_dev(dev);
968 ax_initial_setup(ndev, netdev_priv(ndev));
979 #define ax_suspend NULL
980 #define ax_resume NULL