net: designware: Add decvicetree support
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
8c3c7c5d64
commit
c7278cc625
|
@ -29,12 +29,12 @@
|
||||||
#include <init.h>
|
#include <init.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
|
#include <of_net.h>
|
||||||
#include <asm/mmu.h>
|
#include <asm/mmu.h>
|
||||||
#include <net/designware.h>
|
#include <net/designware.h>
|
||||||
#include <linux/phy.h>
|
#include <linux/phy.h>
|
||||||
#include "designware.h"
|
#include "designware.h"
|
||||||
|
|
||||||
|
|
||||||
struct dw_eth_dev {
|
struct dw_eth_dev {
|
||||||
struct eth_device netdev;
|
struct eth_device netdev;
|
||||||
struct mii_bus miibus;
|
struct mii_bus miibus;
|
||||||
|
@ -57,6 +57,14 @@ struct dw_eth_dev {
|
||||||
int enh_desc;
|
int enh_desc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct dw_eth_drvdata {
|
||||||
|
bool enh_desc;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct dw_eth_drvdata dwmac_370a_drvdata = {
|
||||||
|
.enh_desc = 1,
|
||||||
|
};
|
||||||
|
|
||||||
/* Speed specific definitions */
|
/* Speed specific definitions */
|
||||||
#define SPEED_10M 1
|
#define SPEED_10M 1
|
||||||
#define SPEED_100M 2
|
#define SPEED_100M 2
|
||||||
|
@ -399,6 +407,14 @@ static void dwc_version(struct device_d *dev, u32 hwid)
|
||||||
uid, synid);
|
uid, synid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int dwc_probe_dt(struct device_d *dev, struct dw_eth_dev *priv)
|
||||||
|
{
|
||||||
|
priv->phy_addr = -1;
|
||||||
|
priv->interface = of_get_phy_mode(dev->device_node);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int dwc_ether_probe(struct device_d *dev)
|
static int dwc_ether_probe(struct device_d *dev)
|
||||||
{
|
{
|
||||||
struct dw_eth_dev *priv;
|
struct dw_eth_dev *priv;
|
||||||
|
@ -406,14 +422,27 @@ static int dwc_ether_probe(struct device_d *dev)
|
||||||
struct mii_bus *miibus;
|
struct mii_bus *miibus;
|
||||||
void __iomem *base;
|
void __iomem *base;
|
||||||
struct dwc_ether_platform_data *pdata = dev->platform_data;
|
struct dwc_ether_platform_data *pdata = dev->platform_data;
|
||||||
|
int ret;
|
||||||
if (!pdata) {
|
struct dw_eth_drvdata *drvdata;
|
||||||
printf("dwc_ether: no platform_data\n");
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv = xzalloc(sizeof(struct dw_eth_dev));
|
priv = xzalloc(sizeof(struct dw_eth_dev));
|
||||||
|
|
||||||
|
ret = dev_get_drvdata(dev, (unsigned long *)&drvdata);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
priv->enh_desc = drvdata->enh_desc;
|
||||||
|
|
||||||
|
if (pdata) {
|
||||||
|
priv->phy_addr = pdata->phy_addr;
|
||||||
|
priv->interface = pdata->interface;
|
||||||
|
priv->fix_mac_speed = pdata->fix_mac_speed;
|
||||||
|
} else {
|
||||||
|
ret = dwc_probe_dt(dev, priv);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
base = dev_request_mem_region(dev, 0);
|
base = dev_request_mem_region(dev, 0);
|
||||||
priv->mac_regs_p = base;
|
priv->mac_regs_p = base;
|
||||||
dwc_version(dev, readl(&priv->mac_regs_p->version));
|
dwc_version(dev, readl(&priv->mac_regs_p->version));
|
||||||
|
@ -424,7 +453,6 @@ static int dwc_ether_probe(struct device_d *dev)
|
||||||
CONFIG_RX_DESCR_NUM * sizeof(struct dmamacdescr));
|
CONFIG_RX_DESCR_NUM * sizeof(struct dmamacdescr));
|
||||||
priv->txbuffs = dma_alloc(TX_TOTAL_BUFSIZE);
|
priv->txbuffs = dma_alloc(TX_TOTAL_BUFSIZE);
|
||||||
priv->rxbuffs = dma_alloc(RX_TOTAL_BUFSIZE);
|
priv->rxbuffs = dma_alloc(RX_TOTAL_BUFSIZE);
|
||||||
priv->fix_mac_speed = pdata->fix_mac_speed;
|
|
||||||
|
|
||||||
edev = &priv->netdev;
|
edev = &priv->netdev;
|
||||||
miibus = &priv->miibus;
|
miibus = &priv->miibus;
|
||||||
|
@ -439,8 +467,6 @@ static int dwc_ether_probe(struct device_d *dev)
|
||||||
edev->get_ethaddr = dwc_ether_get_ethaddr;
|
edev->get_ethaddr = dwc_ether_get_ethaddr;
|
||||||
edev->set_ethaddr = dwc_ether_set_ethaddr;
|
edev->set_ethaddr = dwc_ether_set_ethaddr;
|
||||||
|
|
||||||
priv->phy_addr = pdata->phy_addr;
|
|
||||||
priv->interface = pdata->interface;
|
|
||||||
miibus->parent = dev;
|
miibus->parent = dev;
|
||||||
miibus->read = dwc_ether_mii_read;
|
miibus->read = dwc_ether_mii_read;
|
||||||
miibus->write = dwc_ether_mii_write;
|
miibus->write = dwc_ether_mii_write;
|
||||||
|
@ -455,9 +481,19 @@ static void dwc_ether_remove(struct device_d *dev)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static __maybe_unused struct of_device_id dwc_ether_compatible[] = {
|
||||||
|
{
|
||||||
|
.compatible = "snps,dwmac-3.70a",
|
||||||
|
.data = (unsigned long)&dwmac_370a_drvdata,
|
||||||
|
}, {
|
||||||
|
/* sentinel */
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static struct driver_d dwc_ether_driver = {
|
static struct driver_d dwc_ether_driver = {
|
||||||
.name = "designware_eth",
|
.name = "designware_eth",
|
||||||
.probe = dwc_ether_probe,
|
.probe = dwc_ether_probe,
|
||||||
.remove = dwc_ether_remove,
|
.remove = dwc_ether_remove,
|
||||||
|
.of_compatible = DRV_OF_COMPAT(dwc_ether_compatible),
|
||||||
};
|
};
|
||||||
device_platform_driver(dwc_ether_driver);
|
device_platform_driver(dwc_ether_driver);
|
||||||
|
|
|
@ -7,6 +7,7 @@ struct dwc_ether_platform_data {
|
||||||
int phy_addr;
|
int phy_addr;
|
||||||
phy_interface_t interface;
|
phy_interface_t interface;
|
||||||
void (*fix_mac_speed)(int speed);
|
void (*fix_mac_speed)(int speed);
|
||||||
|
bool enh_desc; /* use Alternate/Enhanced Descriptor configurations */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue