remove platform specific initialization from ethernet driver

Hardware filtering must always be enabled as long as there is an Ethernet
device registered, and use device tree for setting the link activity and
buffer shifting enable/disable bit.

SVN-Revision: 32486
This commit is contained in:
Florian Fainelli 2012-06-23 11:03:35 +00:00
parent 2c47bbc199
commit 7c984552ed
4 changed files with 90 additions and 24 deletions

View File

@ -37,11 +37,12 @@
ranges; ranges;
eth0: ethernet@40084000 { eth0: ethernet@40084000 {
//compatible = "moschip,mcs814x-eth";
compatible = "moschip,nuport-mac"; compatible = "moschip,nuport-mac";
reg = <0x40084000 0xd8 // mac reg = <0x40084000 0xd8 // mac
0x40080000 0x58>; // dma channels 0x40080000 0x58>; // dma channels
interrupts = <4 5 29>; /* tx, rx, link */ interrupts = <4 5 29>; /* tx, rx, link */
nuport-mac,buffer-shifting;
nuport-mac,link-activity = <0>;
}; };
tso@40088000 { tso@40088000 {

View File

@ -19,6 +19,9 @@
ahb { ahb {
vci { vci {
eth0: ethernet@40084000 {
nuport-mac,link-activity = <0x01>;
};
adc { adc {
sdram: memory@0,0 { sdram: memory@0,0 {

View File

@ -12,6 +12,8 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <asm/setup.h> #include <asm/setup.h>
#include <asm/mach-types.h> #include <asm/mach-types.h>
@ -31,9 +33,12 @@ static struct map_desc mcs814x_io_desc[] __initdata = {
}; };
#define SYSDBG_BS2 0x04 #define SYSDBG_BS2 0x04
#define LED_CFG_MASK 0x03
#define CPU_MODE_SHIFT 23 #define CPU_MODE_SHIFT 23
#define CPU_MODE_MASK 0x03 #define CPU_MODE_MASK 0x03
#define SYSDBG_SYSCTL_MAC 0x1d
struct cpu_mode { struct cpu_mode {
const char *name; const char *name;
int gpio_start; int gpio_start;
@ -63,6 +68,70 @@ static const struct cpu_mode cpu_modes[] = {
}, },
}; };
static void mcs814x_eth_hardware_filter_set(u8 value)
{
u32 reg;
reg = __raw_readl(_CONFADDR_DBGLED);
if (value)
reg |= 0x80;
else
reg &= ~0x80;
__raw_writel(reg, _CONFADDR_DBGLED);
}
static void mcs814x_eth_led_cfg_set(u8 cfg)
{
u32 reg;
reg = __raw_readl(_CONFADDR_SYSDBG + SYSDBG_BS2);
reg &= ~LED_CFG_MASK;
reg |= cfg;
__raw_writel(reg, _CONFADDR_SYSDBG + SYSDBG_BS2);
}
static void mcs814x_eth_buffer_shifting_set(u8 value)
{
u8 reg;
reg = __raw_readb(_CONFADDR_SYSDBG + SYSDBG_SYSCTL_MAC);
if (value)
reg |= 0x01;
else
reg &= ~0x01;
__raw_writeb(reg, _CONFADDR_SYSDBG + SYSDBG_SYSCTL_MAC);
}
static struct of_device_id mcs814x_eth_ids[] __initdata = {
{ .compatible = "moschip,nuport-mac", },
{ /* sentinel */ },
};
/* Configure platform specific knobs based on ethernet device node
* properties */
static void mcs814x_eth_init(void)
{
struct device_node *np;
const unsigned int *intspec;
np = of_find_matching_node(NULL, mcs814x_eth_ids);
if (!np)
return;
/* hardware filter must always be enabled */
mcs814x_eth_hardware_filter_set(1);
intspec = of_get_property(np, "nuport-mac,buffer-shifting", NULL);
if (!intspec)
mcs814x_eth_buffer_shifting_set(0);
else
mcs814x_eth_buffer_shifting_set(1);
intspec = of_get_property(np, "nuport-mac,link-activity", NULL);
if (intspec)
mcs814x_eth_led_cfg_set(be32_to_cpup(intspec));
}
void __init mcs814x_init_machine(void) void __init mcs814x_init_machine(void)
{ {
u32 bs2, cpu_mode; u32 bs2, cpu_mode;
@ -79,6 +148,8 @@ void __init mcs814x_init_machine(void)
if (gpio != -1) if (gpio != -1)
gpio_request(gpio, cpu_modes[cpu_mode].name); gpio_request(gpio, cpu_modes[cpu_mode].name);
} }
mcs814x_eth_init();
} }
void __init mcs814x_map_io(void) void __init mcs814x_map_io(void)

View File

@ -27,7 +27,6 @@
#include <asm/unaligned.h> #include <asm/unaligned.h>
#include <asm/sizes.h> #include <asm/sizes.h>
#include <mach/hardware.h>
/* Hardware registers */ /* Hardware registers */
#define MAC_BASE_ADDR ((priv->mac_base)) #define MAC_BASE_ADDR ((priv->mac_base))
@ -140,6 +139,7 @@ struct nuport_mac_priv {
int old_link; int old_link;
int old_duplex; int old_duplex;
u32 msg_level; u32 msg_level;
unsigned int buffer_shifting_len;
}; };
static inline int nuport_mac_mii_busy_wait(struct nuport_mac_priv *priv) static inline int nuport_mac_mii_busy_wait(struct nuport_mac_priv *priv)
@ -515,8 +515,8 @@ static int nuport_mac_rx(struct net_device *dev, int limit)
len = priv->pkt_len[priv->cur_rx]; len = priv->pkt_len[priv->cur_rx];
/* Remove 2 bytes added by RX buffer shifting */ /* Remove 2 bytes added by RX buffer shifting */
len = len - 2; len = len - priv->buffer_shifting_len;
skb->data = skb->data + 2; skb->data = skb->data + priv->buffer_shifting_len;
/* Get packet status */ /* Get packet status */
status = get_unaligned((u32 *) (skb->data + len)); status = get_unaligned((u32 *) (skb->data + len));
@ -691,18 +691,6 @@ static int nuport_mac_open(struct net_device *dev)
int ret; int ret;
struct nuport_mac_priv *priv = netdev_priv(dev); struct nuport_mac_priv *priv = netdev_priv(dev);
unsigned long flags; unsigned long flags;
u32 reg;
u8 tmp;
/* Enable hardware filters */
reg = nuport_mac_readl((void __iomem *)_CONFADDR_DBGLED);
reg |= 0x80;
nuport_mac_writel(reg, (void __iomem *)_CONFADDR_DBGLED);
/* Set LEDs to Link act and RX/TX mode */
reg = nuport_mac_readl((void __iomem *)(_CONFADDR_SYSDBG + 0x04));
reg |= 0x01;
nuport_mac_writel(reg, (void __iomem *)(_CONFADDR_SYSDBG + 0x04));
ret = clk_enable(priv->emac_clk); ret = clk_enable(priv->emac_clk);
if (ret) { if (ret) {
@ -747,11 +735,6 @@ static int nuport_mac_open(struct net_device *dev)
goto out_tx_irq; goto out_tx_irq;
} }
/* Enable buffer shifting in RX */
tmp = nuport_mac_readb((void __iomem *)(_CONFADDR_SYSDBG + 0x1D));
tmp |= 0x01;
nuport_mac_writeb(tmp, (void __iomem *)(_CONFADDR_SYSDBG + 0x1D));
netif_start_queue(dev); netif_start_queue(dev);
nuport_mac_init_tx_ring(priv); nuport_mac_init_tx_ring(priv);
@ -947,6 +930,7 @@ static int __init nuport_mac_probe(struct platform_device *pdev)
int ret = 0; int ret = 0;
int rx_irq, tx_irq, link_irq; int rx_irq, tx_irq, link_irq;
int i; int i;
const unsigned int *intspec;
dev = alloc_etherdev(sizeof(struct nuport_mac_priv)); dev = alloc_etherdev(sizeof(struct nuport_mac_priv));
if (!dev) { if (!dev) {
@ -977,6 +961,13 @@ static int __init nuport_mac_probe(struct platform_device *pdev)
priv->dev = dev; priv->dev = dev;
spin_lock_init(&priv->lock); spin_lock_init(&priv->lock);
intspec = of_get_property(pdev->dev.of_node,
"nuport-mac,buffer-shifting", NULL);
if (!intspec)
priv->buffer_shifting_len = 0;
else
priv->buffer_shifting_len = 2;
priv->mac_base = devm_ioremap(&pdev->dev, priv->mac_base = devm_ioremap(&pdev->dev,
regs->start, resource_size(regs)); regs->start, resource_size(regs));
if (!priv->mac_base) { if (!priv->mac_base) {