Commit bda73d4e authored by David S. Miller's avatar David S. Miller

Merge branch 'Amiga-xsurf100'

Michael Schmitz says:

====================
New network driver for Amiga X-Surf 100 (m68k)

[This is a resend of my v3 series which was based on the wrong version and
tree. Only substantial change is to Asix AX99796B PHY driver.]

This patch series adds support for the Individual Computers X-Surf 100
network card for m68k Amiga, a network adapter based on the AX88796 chip set.

The driver was originally written for kernel version 3.19 by Michael Karcher
(see CC:), and adapted to 4.16+ for submission to netdev by me. Questions
regarding motivation for some of the changes are probably best directed at
Michael Karcher.

The driver has been tested by Adrian <glaubitz@physik.fu-berlin.de> who will
send his Tested-by tag separately.

A few changes to the ax88796 driver were required:
- to read the MAC address, some setup of the ax99796 chip must be done,
- attach to the MII bus only on device open to allow module unloading,
- allow to supersede ax_block_input/ax_block_output by card-specific
  optimized code,
- use an optional interrupt status callback to allow easier sharing of the
  card interrupt,
- set IRQF_SHARED if platform IRQ resource is marked shareable

The Asix Electronix PHY used on the X-Surf 100 is buggy, and causes the
software reset to hang if the previous command sent to the PHY was also
a soft reset. This bug requires addition of a PHY driver for Asix PHYs
to provide a fixed .soft_reset function, included in this series.

Some additional cleanup:
- do not attempt to free IRQ in ax_remove (complements 82533ad9),
- clear platform drvdata on probe fail and module remove.

Changes since v1:

Raised in review by Andrew Lunn:
- move MII code around to avoid need for forward declaration,
- combine patches 2 and 7 to add cleanup in error path

Changes since v2:

- corrected authorship attribution to Michael Karcher

Suggested by Geert Uytterhoeven:
- use ei_local->reset_8390() instead of duplicating ax_reset_8390(),
- use %pR to format struct resource pointers,
- assign pdev and xs100 pointers in declaration,
- don't split error messages,
- change Kconfig logic to only require XSURF100 set on Amiga

Suggested by Andrew Lunn:
- add COMPILE_TEST to ax88796 Kconfig options,
- use new Asix PHY driver for X-Surf 100

Suggested by Andrew Lunn/Finn Thain:
- declare struct sk_buff in ax88796.h,
- correct whitespace error in ax88796.h

Changes since v3:

- various checkpatch cleanup

Andrew Lunn:
- don't duplicate genphy_soft_reset in Asix PHY driver, just call
  genphy_soft_reset after writing zero to control register
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 32e43779 861928f4
......@@ -29,8 +29,8 @@ config PCMCIA_AXNET
called axnet_cs. If unsure, say N.
config AX88796
tristate "ASIX AX88796 NE2000 clone support"
depends on (ARM || MIPS || SUPERH)
tristate "ASIX AX88796 NE2000 clone support" if !ZORRO
depends on (ARM || MIPS || SUPERH || ZORRO || COMPILE_TEST)
select CRC32
select PHYLIB
select MDIO_BITBANG
......@@ -45,6 +45,19 @@ config AX88796_93CX6
---help---
Select this if your platform comes with an external 93CX6 eeprom.
config XSURF100
tristate "Amiga XSurf 100 AX88796/NE2000 clone support"
depends on ZORRO
select AX88796
select ASIX_PHY
help
This driver is for the Individual Computers X-Surf 100 Ethernet
card (based on the Asix AX88796 chip). If you have such a card,
say Y. Otherwise, say N.
To compile this driver as a module, choose M here: the module
will be called xsurf100.
config HYDRA
tristate "Hydra support"
depends on ZORRO
......
......@@ -16,4 +16,5 @@ obj-$(CONFIG_PCMCIA_PCNET) += pcnet_cs.o 8390.o
obj-$(CONFIG_STNIC) += stnic.o 8390.o
obj-$(CONFIG_ULTRA) += smc-ultra.o 8390.o
obj-$(CONFIG_WD80x3) += wd.o 8390.o
obj-$(CONFIG_XSURF100) += xsurf100.o
obj-$(CONFIG_ZORRO8390) += zorro8390.o
......@@ -163,6 +163,21 @@ static void ax_reset_8390(struct net_device *dev)
ei_outb(ENISR_RESET, addr + EN0_ISR); /* Ack intr. */
}
/* Wrapper for __ei_interrupt for platforms that have a platform-specific
* way to find out whether the interrupt request might be caused by
* the ax88796 chip.
*/
static irqreturn_t ax_ei_interrupt_filtered(int irq, void *dev_id)
{
struct net_device *dev = dev_id;
struct ax_device *ax = to_ax_dev(dev);
struct platform_device *pdev = to_platform_device(dev->dev.parent);
if (!ax->plat->check_irq(pdev))
return IRQ_NONE;
return ax_ei_interrupt(irq, dev_id);
}
static void ax_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
int ring_page)
......@@ -387,6 +402,90 @@ static void ax_phy_switch(struct net_device *dev, int on)
ei_outb(reg_gpoc, ei_local->mem + EI_SHIFT(0x17));
}
static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level)
{
struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
if (level)
ax->reg_memr |= AX_MEMR_MDC;
else
ax->reg_memr &= ~AX_MEMR_MDC;
ei_outb(ax->reg_memr, ax->addr_memr);
}
static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output)
{
struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
if (output)
ax->reg_memr &= ~AX_MEMR_MDIR;
else
ax->reg_memr |= AX_MEMR_MDIR;
ei_outb(ax->reg_memr, ax->addr_memr);
}
static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value)
{
struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
if (value)
ax->reg_memr |= AX_MEMR_MDO;
else
ax->reg_memr &= ~AX_MEMR_MDO;
ei_outb(ax->reg_memr, ax->addr_memr);
}
static int ax_bb_get_data(struct mdiobb_ctrl *ctrl)
{
struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
int reg_memr = ei_inb(ax->addr_memr);
return reg_memr & AX_MEMR_MDI ? 1 : 0;
}
static const struct mdiobb_ops bb_ops = {
.owner = THIS_MODULE,
.set_mdc = ax_bb_mdc,
.set_mdio_dir = ax_bb_dir,
.set_mdio_data = ax_bb_set_data,
.get_mdio_data = ax_bb_get_data,
};
static int ax_mii_init(struct net_device *dev)
{
struct platform_device *pdev = to_platform_device(dev->dev.parent);
struct ei_device *ei_local = netdev_priv(dev);
struct ax_device *ax = to_ax_dev(dev);
int err;
ax->bb_ctrl.ops = &bb_ops;
ax->addr_memr = ei_local->mem + AX_MEMR;
ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl);
if (!ax->mii_bus) {
err = -ENOMEM;
goto out;
}
ax->mii_bus->name = "ax88796_mii_bus";
ax->mii_bus->parent = dev->dev.parent;
snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
pdev->name, pdev->id);
err = mdiobus_register(ax->mii_bus);
if (err)
goto out_free_mdio_bitbang;
return 0;
out_free_mdio_bitbang:
free_mdio_bitbang(ax->mii_bus);
out:
return err;
}
static int ax_open(struct net_device *dev)
{
struct ax_device *ax = to_ax_dev(dev);
......@@ -394,6 +493,14 @@ static int ax_open(struct net_device *dev)
netdev_dbg(dev, "open\n");
ret = ax_mii_init(dev);
if (ret)
goto failed_mii;
if (ax->plat->check_irq)
ret = request_irq(dev->irq, ax_ei_interrupt_filtered,
ax->irqflags, dev->name, dev);
else
ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags,
dev->name, dev);
if (ret)
......@@ -421,6 +528,10 @@ static int ax_open(struct net_device *dev)
ax_phy_switch(dev, 0);
free_irq(dev->irq, dev);
failed_request_irq:
/* unregister mdiobus */
mdiobus_unregister(ax->mii_bus);
free_mdio_bitbang(ax->mii_bus);
failed_mii:
return ret;
}
......@@ -440,6 +551,9 @@ static int ax_close(struct net_device *dev)
phy_disconnect(dev->phydev);
free_irq(dev->irq, dev);
mdiobus_unregister(ax->mii_bus);
free_mdio_bitbang(ax->mii_bus);
return 0;
}
......@@ -539,92 +653,8 @@ static const struct net_device_ops ax_netdev_ops = {
#endif
};
static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level)
{
struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
if (level)
ax->reg_memr |= AX_MEMR_MDC;
else
ax->reg_memr &= ~AX_MEMR_MDC;
ei_outb(ax->reg_memr, ax->addr_memr);
}
static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output)
{
struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
if (output)
ax->reg_memr &= ~AX_MEMR_MDIR;
else
ax->reg_memr |= AX_MEMR_MDIR;
ei_outb(ax->reg_memr, ax->addr_memr);
}
static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value)
{
struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
if (value)
ax->reg_memr |= AX_MEMR_MDO;
else
ax->reg_memr &= ~AX_MEMR_MDO;
ei_outb(ax->reg_memr, ax->addr_memr);
}
static int ax_bb_get_data(struct mdiobb_ctrl *ctrl)
{
struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
int reg_memr = ei_inb(ax->addr_memr);
return reg_memr & AX_MEMR_MDI ? 1 : 0;
}
static const struct mdiobb_ops bb_ops = {
.owner = THIS_MODULE,
.set_mdc = ax_bb_mdc,
.set_mdio_dir = ax_bb_dir,
.set_mdio_data = ax_bb_set_data,
.get_mdio_data = ax_bb_get_data,
};
/* setup code */
static int ax_mii_init(struct net_device *dev)
{
struct platform_device *pdev = to_platform_device(dev->dev.parent);
struct ei_device *ei_local = netdev_priv(dev);
struct ax_device *ax = to_ax_dev(dev);
int err;
ax->bb_ctrl.ops = &bb_ops;
ax->addr_memr = ei_local->mem + AX_MEMR;
ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl);
if (!ax->mii_bus) {
err = -ENOMEM;
goto out;
}
ax->mii_bus->name = "ax88796_mii_bus";
ax->mii_bus->parent = dev->dev.parent;
snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
pdev->name, pdev->id);
err = mdiobus_register(ax->mii_bus);
if (err)
goto out_free_mdio_bitbang;
return 0;
out_free_mdio_bitbang:
free_mdio_bitbang(ax->mii_bus);
out:
return err;
}
static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local)
{
void __iomem *ioaddr = ei_local->mem;
......@@ -669,10 +699,16 @@ static int ax_init_dev(struct net_device *dev)
if (ax->plat->flags & AXFLG_HAS_EEPROM) {
unsigned char SA_prom[32];
ei_outb(6, ioaddr + EN0_RCNTLO);
ei_outb(0, ioaddr + EN0_RCNTHI);
ei_outb(0, ioaddr + EN0_RSARLO);
ei_outb(0, ioaddr + EN0_RSARHI);
ei_outb(E8390_RREAD + E8390_START, ioaddr + NE_CMD);
for (i = 0; i < sizeof(SA_prom); i += 2) {
SA_prom[i] = ei_inb(ioaddr + NE_DATAPORT);
SA_prom[i + 1] = ei_inb(ioaddr + NE_DATAPORT);
}
ei_outb(ENISR_RDC, ioaddr + EN0_ISR); /* Ack intr. */
if (ax->plat->wordlength == 2)
for (i = 0; i < 16; i++)
......@@ -741,7 +777,13 @@ static int ax_init_dev(struct net_device *dev)
#endif
ei_local->reset_8390 = &ax_reset_8390;
if (ax->plat->block_input)
ei_local->block_input = ax->plat->block_input;
else
ei_local->block_input = &ax_block_input;
if (ax->plat->block_output)
ei_local->block_output = ax->plat->block_output;
else
ei_local->block_output = &ax_block_output;
ei_local->get_8390_hdr = &ax_get_8390_hdr;
ei_local->priv = 0;
......@@ -749,10 +791,6 @@ static int ax_init_dev(struct net_device *dev)
dev->netdev_ops = &ax_netdev_ops;
dev->ethtool_ops = &ax_ethtool_ops;
ret = ax_mii_init(dev);
if (ret)
goto err_out;
ax_NS8390_init(dev, 0);
ret = register_netdev(dev);
......@@ -777,7 +815,6 @@ static int ax_remove(struct platform_device *pdev)
struct resource *mem;
unregister_netdev(dev);
free_irq(dev->irq, dev);
iounmap(ei_local->mem);
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
......@@ -789,6 +826,7 @@ static int ax_remove(struct platform_device *pdev)
release_mem_region(mem->start, resource_size(mem));
}
platform_set_drvdata(pdev, NULL);
free_netdev(dev);
return 0;
......@@ -835,6 +873,9 @@ static int ax_probe(struct platform_device *pdev)
dev->irq = irq->start;
ax->irqflags = irq->flags & IRQF_TRIGGER_MASK;
if (irq->flags & IORESOURCE_IRQ_SHAREABLE)
ax->irqflags |= IRQF_SHARED;
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!mem) {
dev_err(&pdev->dev, "no MEM specified\n");
......@@ -919,6 +960,7 @@ static int ax_probe(struct platform_device *pdev)
release_mem_region(mem->start, mem_size);
exit_mem:
platform_set_drvdata(pdev, NULL);
free_netdev(dev);
return ret;
......
// SPDX-License-Identifier: GPL-2.0
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/platform_device.h>
#include <linux/zorro.h>
#include <net/ax88796.h>
#include <asm/amigaints.h>
#define ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF100 \
ZORRO_ID(INDIVIDUAL_COMPUTERS, 0x64, 0)
#define XS100_IRQSTATUS_BASE 0x40
#define XS100_8390_BASE 0x800
/* Longword-access area. Translated to 2 16-bit access cycles by the
* X-Surf 100 FPGA
*/
#define XS100_8390_DATA32_BASE 0x8000
#define XS100_8390_DATA32_SIZE 0x2000
/* Sub-Areas for fast data register access; addresses relative to area begin */
#define XS100_8390_DATA_READ32_BASE 0x0880
#define XS100_8390_DATA_WRITE32_BASE 0x0C80
#define XS100_8390_DATA_AREA_SIZE 0x80
#define __NS8390_init ax_NS8390_init
/* force unsigned long back to 'void __iomem *' */
#define ax_convert_addr(_a) ((void __force __iomem *)(_a))
#define ei_inb(_a) z_readb(ax_convert_addr(_a))
#define ei_outb(_v, _a) z_writeb(_v, ax_convert_addr(_a))
#define ei_inw(_a) z_readw(ax_convert_addr(_a))
#define ei_outw(_v, _a) z_writew(_v, ax_convert_addr(_a))
#define ei_inb_p(_a) ei_inb(_a)
#define ei_outb_p(_v, _a) ei_outb(_v, _a)
/* define EI_SHIFT() to take into account our register offsets */
#define EI_SHIFT(x) (ei_local->reg_offset[(x)])
/* Ensure we have our RCR base value */
#define AX88796_PLATFORM
static unsigned char version[] =
"ax88796.c: Copyright 2005,2007 Simtec Electronics\n";
#include "lib8390.c"
/* from ne.c */
#define NE_CMD EI_SHIFT(0x00)
#define NE_RESET EI_SHIFT(0x1f)
#define NE_DATAPORT EI_SHIFT(0x10)
struct xsurf100_ax_plat_data {
struct ax_plat_data ax;
void __iomem *base_regs;
void __iomem *data_area;
};
static int is_xsurf100_network_irq(struct platform_device *pdev)
{
struct xsurf100_ax_plat_data *xs100 = dev_get_platdata(&pdev->dev);
return (readw(xs100->base_regs + XS100_IRQSTATUS_BASE) & 0xaaaa) != 0;
}
/* These functions guarantee that the iomem is accessed with 32 bit
* cycles only. z_memcpy_fromio / z_memcpy_toio don't
*/
static void z_memcpy_fromio32(void *dst, const void __iomem *src, size_t bytes)
{
while (bytes > 32) {
asm __volatile__
("movem.l (%0)+,%%d0-%%d7\n"
"movem.l %%d0-%%d7,(%1)\n"
"adda.l #32,%1" : "=a"(src), "=a"(dst)
: "0"(src), "1"(dst) : "d0", "d1", "d2", "d3", "d4",
"d5", "d6", "d7", "memory");
bytes -= 32;
}
while (bytes) {
*(uint32_t *)dst = z_readl(src);
src += 4;
dst += 4;
bytes -= 4;
}
}
static void z_memcpy_toio32(void __iomem *dst, const void *src, size_t bytes)
{
while (bytes) {
z_writel(*(const uint32_t *)src, dst);
src += 4;
dst += 4;
bytes -= 4;
}
}
static void xs100_write(struct net_device *dev, const void *src,
unsigned int count)
{
struct ei_device *ei_local = netdev_priv(dev);
struct platform_device *pdev = to_platform_device(dev->dev.parent);
struct xsurf100_ax_plat_data *xs100 = dev_get_platdata(&pdev->dev);
/* copy whole blocks */
while (count > XS100_8390_DATA_AREA_SIZE) {
z_memcpy_toio32(xs100->data_area +
XS100_8390_DATA_WRITE32_BASE, src,
XS100_8390_DATA_AREA_SIZE);
src += XS100_8390_DATA_AREA_SIZE;
count -= XS100_8390_DATA_AREA_SIZE;
}
/* copy whole dwords */
z_memcpy_toio32(xs100->data_area + XS100_8390_DATA_WRITE32_BASE,
src, count & ~3);
src += count & ~3;
if (count & 2) {
ei_outw(*(uint16_t *)src, ei_local->mem + NE_DATAPORT);
src += 2;
}
if (count & 1)
ei_outb(*(uint8_t *)src, ei_local->mem + NE_DATAPORT);
}
static void xs100_read(struct net_device *dev, void *dst, unsigned int count)
{
struct ei_device *ei_local = netdev_priv(dev);
struct platform_device *pdev = to_platform_device(dev->dev.parent);
struct xsurf100_ax_plat_data *xs100 = dev_get_platdata(&pdev->dev);
/* copy whole blocks */
while (count > XS100_8390_DATA_AREA_SIZE) {
z_memcpy_fromio32(dst, xs100->data_area +
XS100_8390_DATA_READ32_BASE,
XS100_8390_DATA_AREA_SIZE);
dst += XS100_8390_DATA_AREA_SIZE;
count -= XS100_8390_DATA_AREA_SIZE;
}
/* copy whole dwords */
z_memcpy_fromio32(dst, xs100->data_area + XS100_8390_DATA_READ32_BASE,
count & ~3);
dst += count & ~3;
if (count & 2) {
*(uint16_t *)dst = ei_inw(ei_local->mem + NE_DATAPORT);
dst += 2;
}
if (count & 1)
*(uint8_t *)dst = ei_inb(ei_local->mem + NE_DATAPORT);
}
/* Block input and output, similar to the Crynwr packet driver. If
* you are porting to a new ethercard, look at the packet driver
* source for hints. The NEx000 doesn't share the on-board packet
* memory -- you have to put the packet out through the "remote DMA"
* dataport using ei_outb.
*/
static void xs100_block_input(struct net_device *dev, int count,
struct sk_buff *skb, int ring_offset)
{
struct ei_device *ei_local = netdev_priv(dev);
void __iomem *nic_base = ei_local->mem;
char *buf = skb->data;
if (ei_local->dmaing) {
netdev_err(dev,
"DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
__func__,
ei_local->dmaing, ei_local->irqlock);
return;
}
ei_local->dmaing |= 0x01;
ei_outb(E8390_NODMA + E8390_PAGE0 + E8390_START, nic_base + NE_CMD);
ei_outb(count & 0xff, nic_base + EN0_RCNTLO);
ei_outb(count >> 8, nic_base + EN0_RCNTHI);
ei_outb(ring_offset & 0xff, nic_base + EN0_RSARLO);
ei_outb(ring_offset >> 8, nic_base + EN0_RSARHI);
ei_outb(E8390_RREAD + E8390_START, nic_base + NE_CMD);
xs100_read(dev, buf, count);
ei_local->dmaing &= ~1;
}
static void xs100_block_output(struct net_device *dev, int count,
const unsigned char *buf, const int start_page)
{
struct ei_device *ei_local = netdev_priv(dev);
void __iomem *nic_base = ei_local->mem;
unsigned long dma_start;
/* Round the count up for word writes. Do we need to do this?
* What effect will an odd byte count have on the 8390? I
* should check someday.
*/
if (ei_local->word16 && (count & 0x01))
count++;
/* This *shouldn't* happen. If it does, it's the last thing
* you'll see
*/
if (ei_local->dmaing) {
netdev_err(dev,
"DMAing conflict in %s [DMAstat:%d][irqlock:%d]\n",
__func__,
ei_local->dmaing, ei_local->irqlock);
return;
}
ei_local->dmaing |= 0x01;
/* We should already be in page 0, but to be safe... */
ei_outb(E8390_PAGE0 + E8390_START + E8390_NODMA, nic_base + NE_CMD);
ei_outb(ENISR_RDC, nic_base + EN0_ISR);
/* Now the normal output. */
ei_outb(count & 0xff, nic_base + EN0_RCNTLO);
ei_outb(count >> 8, nic_base + EN0_RCNTHI);
ei_outb(0x00, nic_base + EN0_RSARLO);
ei_outb(start_page, nic_base + EN0_RSARHI);
ei_outb(E8390_RWRITE + E8390_START, nic_base + NE_CMD);
xs100_write(dev, buf, count);
dma_start = jiffies;
while ((ei_inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) {
if (jiffies - dma_start > 2 * HZ / 100) { /* 20ms */
netdev_warn(dev, "timeout waiting for Tx RDC.\n");
ei_local->reset_8390(dev);
ax_NS8390_init(dev, 1);
break;
}
}
ei_outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */
ei_local->dmaing &= ~0x01;
}
static int xsurf100_probe(struct zorro_dev *zdev,
const struct zorro_device_id *ent)
{
struct platform_device *pdev;
struct xsurf100_ax_plat_data ax88796_data;
struct resource res[2] = {
DEFINE_RES_NAMED(IRQ_AMIGA_PORTS, 1, NULL,
IORESOURCE_IRQ | IORESOURCE_IRQ_SHAREABLE),
DEFINE_RES_MEM(zdev->resource.start + XS100_8390_BASE,
4 * 0x20)
};
int reg;
/* This table is referenced in the device structure, so it must
* outlive the scope of xsurf100_probe.
*/
static u32 reg_offsets[32];
int ret = 0;
/* X-Surf 100 control and 32 bit ring buffer data access areas.
* These resources are not used by the ax88796 driver, so must
* be requested here and passed via platform data.
*/
if (!request_mem_region(zdev->resource.start, 0x100, zdev->name)) {
dev_err(&zdev->dev, "cannot reserve X-Surf 100 control registers\n");
return -ENXIO;
}
if (!request_mem_region(zdev->resource.start +
XS100_8390_DATA32_BASE,
XS100_8390_DATA32_SIZE,
"X-Surf 100 32-bit data access")) {
dev_err(&zdev->dev, "cannot reserve 32-bit area\n");
ret = -ENXIO;
goto exit_req;
}
for (reg = 0; reg < 0x20; reg++)
reg_offsets[reg] = 4 * reg;
memset(&ax88796_data, 0, sizeof(ax88796_data));
ax88796_data.ax.flags = AXFLG_HAS_EEPROM;
ax88796_data.ax.wordlength = 2;
ax88796_data.ax.dcr_val = 0x48;
ax88796_data.ax.rcr_val = 0x40;
ax88796_data.ax.reg_offsets = reg_offsets;
ax88796_data.ax.check_irq = is_xsurf100_network_irq;
ax88796_data.base_regs = ioremap(zdev->resource.start, 0x100);
/* error handling for ioremap regs */
if (!ax88796_data.base_regs) {
dev_err(&zdev->dev, "Cannot ioremap area %pR (registers)\n",
&zdev->resource);
ret = -ENXIO;
goto exit_req2;
}
ax88796_data.data_area = ioremap(zdev->resource.start +
XS100_8390_DATA32_BASE, XS100_8390_DATA32_SIZE);
/* error handling for ioremap data */
if (!ax88796_data.data_area) {
dev_err(&zdev->dev,
"Cannot ioremap area %pR offset %x (32-bit access)\n",
&zdev->resource, XS100_8390_DATA32_BASE);
ret = -ENXIO;
goto exit_mem;
}
ax88796_data.ax.block_output = xs100_block_output;
ax88796_data.ax.block_input = xs100_block_input;
pdev = platform_device_register_resndata(&zdev->dev, "ax88796",
zdev->slotaddr, res, 2,
&ax88796_data,
sizeof(ax88796_data));
if (IS_ERR(pdev)) {
dev_err(&zdev->dev, "cannot register platform device\n");
ret = -ENXIO;
goto exit_mem2;
}
zorro_set_drvdata(zdev, pdev);
if (!ret)
return 0;
exit_mem2:
iounmap(ax88796_data.data_area);
exit_mem:
iounmap(ax88796_data.base_regs);
exit_req2:
release_mem_region(zdev->resource.start + XS100_8390_DATA32_BASE,
XS100_8390_DATA32_SIZE);
exit_req:
release_mem_region(zdev->resource.start, 0x100);
return ret;
}
static void xsurf100_remove(struct zorro_dev *zdev)
{
struct platform_device *pdev = zorro_get_drvdata(zdev);
struct xsurf100_ax_plat_data *xs100 = dev_get_platdata(&pdev->dev);
platform_device_unregister(pdev);
iounmap(xs100->base_regs);
release_mem_region(zdev->resource.start, 0x100);
iounmap(xs100->data_area);
release_mem_region(zdev->resource.start + XS100_8390_DATA32_BASE,
XS100_8390_DATA32_SIZE);
}
static const struct zorro_device_id xsurf100_zorro_tbl[] = {
{ ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF100, },
{ 0 }
};
MODULE_DEVICE_TABLE(zorro, xsurf100_zorro_tbl);
static struct zorro_driver xsurf100_driver = {
.name = "xsurf100",
.id_table = xsurf100_zorro_tbl,
.probe = xsurf100_probe,
.remove = xsurf100_remove,
};
module_driver(xsurf100_driver, zorro_register_driver, zorro_unregister_driver);
MODULE_DESCRIPTION("X-Surf 100 driver");
MODULE_AUTHOR("Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>");
MODULE_LICENSE("GPL v2");
......@@ -218,6 +218,12 @@ config AQUANTIA_PHY
---help---
Currently supports the Aquantia AQ1202, AQ2104, AQR105, AQR405
config ASIX_PHY
tristate "Asix PHYs"
help
Currently supports the Asix Electronics PHY found in the X-Surf 100
AX88796B package.
config AT803X_PHY
tristate "AT803X PHYs"
---help---
......
......@@ -45,6 +45,7 @@ obj-y += $(sfp-obj-y) $(sfp-obj-m)
obj-$(CONFIG_AMD_PHY) += amd.o
obj-$(CONFIG_AQUANTIA_PHY) += aquantia.o
obj-$(CONFIG_ASIX_PHY) += asix.o
obj-$(CONFIG_AT803X_PHY) += at803x.o
obj-$(CONFIG_BCM63XX_PHY) += bcm63xx.o
obj-$(CONFIG_BCM7XXX_PHY) += bcm7xxx.o
......
// SPDX-License-Identifier: GPL-2.0
/* Driver for Asix PHYs
*
* Author: Michael Schmitz <schmitzmic@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
*/
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/mii.h>
#include <linux/phy.h>
#define PHY_ID_ASIX_AX88796B 0x003b1841
MODULE_DESCRIPTION("Asix PHY driver");
MODULE_AUTHOR("Michael Schmitz <schmitzmic@gmail.com>");
MODULE_LICENSE("GPL");
/**
* asix_soft_reset - software reset the PHY via BMCR_RESET bit
* @phydev: target phy_device struct
*
* Description: Perform a software PHY reset using the standard
* BMCR_RESET bit and poll for the reset bit to be cleared.
* Toggle BMCR_RESET bit off to accommodate broken AX8796B PHY implementation
* such as used on the Individual Computers' X-Surf 100 Zorro card.
*
* Returns: 0 on success, < 0 on failure
*/
static int asix_soft_reset(struct phy_device *phydev)
{
int ret;
/* Asix PHY won't reset unless reset bit toggles */
ret = phy_write(phydev, MII_BMCR, 0);
if (ret < 0)
return ret;
return genphy_soft_reset(phydev);
}
static struct phy_driver asix_driver[] = { {
.phy_id = PHY_ID_ASIX_AX88796B,
.name = "Asix Electronics AX88796B",
.phy_id_mask = 0xfffffff0,
.features = PHY_BASIC_FEATURES,
.soft_reset = asix_soft_reset,
} };
module_phy_driver(asix_driver);
static struct mdio_device_id __maybe_unused asix_tbl[] = {
{ PHY_ID_ASIX_AX88796B, 0xfffffff0 },
{ }
};
MODULE_DEVICE_TABLE(mdio, asix_tbl);
......@@ -12,6 +12,10 @@
#ifndef __NET_AX88796_PLAT_H
#define __NET_AX88796_PLAT_H
struct sk_buff;
struct net_device;
struct platform_device;
#define AXFLG_HAS_EEPROM (1<<0)
#define AXFLG_MAC_FROMDEV (1<<1) /* device already has MAC */
#define AXFLG_HAS_93CX6 (1<<2) /* use eeprom_93cx6 driver */
......@@ -26,6 +30,16 @@ struct ax_plat_data {
u32 *reg_offsets; /* register offsets */
u8 *mac_addr; /* MAC addr (only used when
AXFLG_MAC_FROMPLATFORM is used */
/* uses default ax88796 buffer if set to NULL */
void (*block_output)(struct net_device *dev, int count,
const unsigned char *buf, int star_page);
void (*block_input)(struct net_device *dev, int count,
struct sk_buff *skb, int ring_offset);
/* returns nonzero if a pending interrupt request might by caused by
* the ax88786. Handles all interrupts if set to NULL
*/
int (*check_irq)(struct platform_device *pdev);
};
#endif /* __NET_AX88796_PLAT_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment