2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2010-06-29 05:23:34 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2010
|
|
|
|
* Vipin Kumar, ST Micoelectronics, vipin.kumar@st.com.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2015-04-05 22:07:40 +00:00
|
|
|
* Designware ethernet IP driver for U-Boot
|
2010-06-29 05:23:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2017-11-29 08:06:11 +00:00
|
|
|
#include <clk.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2015-04-05 22:07:41 +00:00
|
|
|
#include <dm.h>
|
2015-04-05 22:07:40 +00:00
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2010-06-29 05:23:34 +00:00
|
|
|
#include <miiphy.h>
|
|
|
|
#include <malloc.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <net.h>
|
2015-09-11 10:24:35 +00:00
|
|
|
#include <pci.h>
|
2018-06-14 10:45:23 +00:00
|
|
|
#include <reset.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2021-02-24 14:02:39 +00:00
|
|
|
#include <dm/device-internal.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <dm/devres.h>
|
2021-02-24 14:02:39 +00:00
|
|
|
#include <dm/lists.h>
|
2012-05-07 10:04:25 +00:00
|
|
|
#include <linux/compiler.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2010-06-29 05:23:34 +00:00
|
|
|
#include <linux/err.h>
|
2017-12-09 22:59:55 +00:00
|
|
|
#include <linux/kernel.h>
|
2010-06-29 05:23:34 +00:00
|
|
|
#include <asm/io.h>
|
2017-03-27 08:54:17 +00:00
|
|
|
#include <power/regulator.h>
|
2010-06-29 05:23:34 +00:00
|
|
|
#include "designware.h"
|
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
static int dw_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
|
|
|
|
{
|
2016-02-28 21:24:55 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct dw_eth_dev *priv = dev_get_priv((struct udevice *)bus->priv);
|
|
|
|
struct eth_mac_regs *mac_p = priv->mac_regs_p;
|
|
|
|
#else
|
2014-01-22 16:54:06 +00:00
|
|
|
struct eth_mac_regs *mac_p = bus->priv;
|
2016-02-28 21:24:55 +00:00
|
|
|
#endif
|
2014-01-22 16:54:06 +00:00
|
|
|
ulong start;
|
|
|
|
u16 miiaddr;
|
|
|
|
int timeout = CONFIG_MDIO_TIMEOUT;
|
|
|
|
|
|
|
|
miiaddr = ((addr << MIIADDRSHIFT) & MII_ADDRMSK) |
|
|
|
|
((reg << MIIREGSHIFT) & MII_REGMSK);
|
|
|
|
|
|
|
|
writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr);
|
|
|
|
|
|
|
|
start = get_timer(0);
|
|
|
|
while (get_timer(start) < timeout) {
|
|
|
|
if (!(readl(&mac_p->miiaddr) & MII_BUSY))
|
|
|
|
return readl(&mac_p->miidata);
|
|
|
|
udelay(10);
|
|
|
|
};
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
return -ETIMEDOUT;
|
2014-01-22 16:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
|
|
|
|
u16 val)
|
|
|
|
{
|
2016-02-28 21:24:55 +00:00
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
struct dw_eth_dev *priv = dev_get_priv((struct udevice *)bus->priv);
|
|
|
|
struct eth_mac_regs *mac_p = priv->mac_regs_p;
|
|
|
|
#else
|
2014-01-22 16:54:06 +00:00
|
|
|
struct eth_mac_regs *mac_p = bus->priv;
|
2016-02-28 21:24:55 +00:00
|
|
|
#endif
|
2014-01-22 16:54:06 +00:00
|
|
|
ulong start;
|
|
|
|
u16 miiaddr;
|
2015-04-05 22:07:40 +00:00
|
|
|
int ret = -ETIMEDOUT, timeout = CONFIG_MDIO_TIMEOUT;
|
2014-01-22 16:54:06 +00:00
|
|
|
|
|
|
|
writel(val, &mac_p->miidata);
|
|
|
|
miiaddr = ((addr << MIIADDRSHIFT) & MII_ADDRMSK) |
|
|
|
|
((reg << MIIREGSHIFT) & MII_REGMSK) | MII_WRITE;
|
|
|
|
|
|
|
|
writel(miiaddr | MII_CLKRANGE_150_250M | MII_BUSY, &mac_p->miiaddr);
|
|
|
|
|
|
|
|
start = get_timer(0);
|
|
|
|
while (get_timer(start) < timeout) {
|
|
|
|
if (!(readl(&mac_p->miiaddr) & MII_BUSY)) {
|
|
|
|
ret = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
udelay(10);
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-12-07 04:41:35 +00:00
|
|
|
#if defined(CONFIG_DM_ETH) && CONFIG_IS_ENABLED(DM_GPIO)
|
2016-02-28 21:24:55 +00:00
|
|
|
static int dw_mdio_reset(struct mii_dev *bus)
|
|
|
|
{
|
|
|
|
struct udevice *dev = bus->priv;
|
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
2020-12-03 23:55:20 +00:00
|
|
|
struct dw_eth_pdata *pdata = dev_get_plat(dev);
|
2016-02-28 21:24:55 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!dm_gpio_is_valid(&priv->reset_gpio))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* reset the phy */
|
|
|
|
ret = dm_gpio_set_value(&priv->reset_gpio, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
udelay(pdata->reset_delays[0]);
|
|
|
|
|
|
|
|
ret = dm_gpio_set_value(&priv->reset_gpio, 1);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
udelay(pdata->reset_delays[1]);
|
|
|
|
|
|
|
|
ret = dm_gpio_set_value(&priv->reset_gpio, 0);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
udelay(pdata->reset_delays[2]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-02-24 14:02:39 +00:00
|
|
|
#if IS_ENABLED(CONFIG_DM_MDIO)
|
|
|
|
int designware_eth_mdio_read(struct udevice *mdio_dev, int addr, int devad, int reg)
|
|
|
|
{
|
|
|
|
struct mdio_perdev_priv *pdata = dev_get_uclass_priv(mdio_dev);
|
|
|
|
|
|
|
|
return dw_mdio_read(pdata->mii_bus, addr, devad, reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
int designware_eth_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 val)
|
|
|
|
{
|
|
|
|
struct mdio_perdev_priv *pdata = dev_get_uclass_priv(mdio_dev);
|
|
|
|
|
|
|
|
return dw_mdio_write(pdata->mii_bus, addr, devad, reg, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
|
|
|
int designware_eth_mdio_reset(struct udevice *mdio_dev)
|
|
|
|
{
|
|
|
|
struct mdio_perdev_priv *pdata = dev_get_uclass_priv(mdio_dev);
|
|
|
|
|
|
|
|
return dw_mdio_reset(pdata->mii_bus);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static const struct mdio_ops designware_eth_mdio_ops = {
|
|
|
|
.read = designware_eth_mdio_read,
|
|
|
|
.write = designware_eth_mdio_write,
|
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
|
|
|
.reset = designware_eth_mdio_reset,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static int designware_eth_mdio_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
/* Use the priv data of parent */
|
|
|
|
dev_set_priv(dev, dev_get_priv(dev->parent));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(designware_eth_mdio) = {
|
|
|
|
.name = "eth_designware_mdio",
|
|
|
|
.id = UCLASS_MDIO,
|
|
|
|
.probe = designware_eth_mdio_probe,
|
|
|
|
.ops = &designware_eth_mdio_ops,
|
|
|
|
.plat_auto = sizeof(struct mdio_perdev_priv),
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-02-28 21:24:55 +00:00
|
|
|
static int dw_mdio_init(const char *name, void *priv)
|
2014-01-22 16:54:06 +00:00
|
|
|
{
|
|
|
|
struct mii_dev *bus = mdio_alloc();
|
|
|
|
|
|
|
|
if (!bus) {
|
|
|
|
printf("Failed to allocate MDIO bus\n");
|
2015-04-05 22:07:40 +00:00
|
|
|
return -ENOMEM;
|
2014-01-22 16:54:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bus->read = dw_mdio_read;
|
|
|
|
bus->write = dw_mdio_write;
|
2015-12-30 13:05:58 +00:00
|
|
|
snprintf(bus->name, sizeof(bus->name), "%s", name);
|
2019-12-07 04:41:35 +00:00
|
|
|
#if defined(CONFIG_DM_ETH) && CONFIG_IS_ENABLED(DM_GPIO)
|
2016-02-28 21:24:55 +00:00
|
|
|
bus->reset = dw_mdio_reset;
|
|
|
|
#endif
|
2014-01-22 16:54:06 +00:00
|
|
|
|
2016-02-28 21:24:55 +00:00
|
|
|
bus->priv = priv;
|
2014-01-22 16:54:06 +00:00
|
|
|
|
|
|
|
return mdio_register(bus);
|
|
|
|
}
|
2012-03-26 00:09:56 +00:00
|
|
|
|
2021-02-24 14:02:39 +00:00
|
|
|
#if IS_ENABLED(CONFIG_DM_MDIO)
|
|
|
|
static int dw_dm_mdio_init(const char *name, void *priv)
|
|
|
|
{
|
|
|
|
struct udevice *dev = priv;
|
|
|
|
ofnode node;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ofnode_for_each_subnode(node, dev_ofnode(dev)) {
|
|
|
|
const char *subnode_name = ofnode_get_name(node);
|
|
|
|
struct udevice *mdiodev;
|
|
|
|
|
|
|
|
if (strcmp(subnode_name, "mdio"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret = device_bind_driver_to_node(dev, "eth_designware_mdio",
|
|
|
|
subnode_name, node, &mdiodev);
|
|
|
|
if (ret)
|
|
|
|
debug("%s: not able to bind mdio device node\n", __func__);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s: mdio node is missing, registering legacy mdio bus", __func__);
|
|
|
|
|
|
|
|
return dw_mdio_init(name, priv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
static void tx_descs_init(struct dw_eth_dev *priv)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
|
|
|
struct eth_dma_regs *dma_p = priv->dma_regs_p;
|
|
|
|
struct dmamacdescr *desc_table_p = &priv->tx_mac_descrtable[0];
|
|
|
|
char *txbuffs = &priv->txbuffs[0];
|
|
|
|
struct dmamacdescr *desc_p;
|
|
|
|
u32 idx;
|
|
|
|
|
|
|
|
for (idx = 0; idx < CONFIG_TX_DESCR_NUM; idx++) {
|
|
|
|
desc_p = &desc_table_p[idx];
|
2016-05-08 06:30:15 +00:00
|
|
|
desc_p->dmamac_addr = (ulong)&txbuffs[idx * CONFIG_ETH_BUFSIZE];
|
|
|
|
desc_p->dmamac_next = (ulong)&desc_table_p[idx + 1];
|
2010-06-29 05:23:34 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_DW_ALTDESCRIPTOR)
|
|
|
|
desc_p->txrx_status &= ~(DESC_TXSTS_TXINT | DESC_TXSTS_TXLAST |
|
2015-12-20 02:59:23 +00:00
|
|
|
DESC_TXSTS_TXFIRST | DESC_TXSTS_TXCRCDIS |
|
|
|
|
DESC_TXSTS_TXCHECKINSCTRL |
|
2010-06-29 05:23:34 +00:00
|
|
|
DESC_TXSTS_TXRINGEND | DESC_TXSTS_TXPADDIS);
|
|
|
|
|
|
|
|
desc_p->txrx_status |= DESC_TXSTS_TXCHAIN;
|
|
|
|
desc_p->dmamac_cntl = 0;
|
|
|
|
desc_p->txrx_status &= ~(DESC_TXSTS_MSK | DESC_TXSTS_OWNBYDMA);
|
|
|
|
#else
|
|
|
|
desc_p->dmamac_cntl = DESC_TXCTRL_TXCHAIN;
|
|
|
|
desc_p->txrx_status = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Correcting the last pointer of the chain */
|
2016-05-08 06:30:15 +00:00
|
|
|
desc_p->dmamac_next = (ulong)&desc_table_p[0];
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:49:09 +00:00
|
|
|
/* Flush all Tx buffer descriptors at once */
|
2016-05-08 06:30:15 +00:00
|
|
|
flush_dcache_range((ulong)priv->tx_mac_descrtable,
|
|
|
|
(ulong)priv->tx_mac_descrtable +
|
2014-01-22 16:49:09 +00:00
|
|
|
sizeof(priv->tx_mac_descrtable));
|
|
|
|
|
2010-06-29 05:23:34 +00:00
|
|
|
writel((ulong)&desc_table_p[0], &dma_p->txdesclistaddr);
|
2014-01-13 09:28:38 +00:00
|
|
|
priv->tx_currdescnum = 0;
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
static void rx_descs_init(struct dw_eth_dev *priv)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
|
|
|
struct eth_dma_regs *dma_p = priv->dma_regs_p;
|
|
|
|
struct dmamacdescr *desc_table_p = &priv->rx_mac_descrtable[0];
|
|
|
|
char *rxbuffs = &priv->rxbuffs[0];
|
|
|
|
struct dmamacdescr *desc_p;
|
|
|
|
u32 idx;
|
|
|
|
|
2014-01-22 16:49:09 +00:00
|
|
|
/* Before passing buffers to GMAC we need to make sure zeros
|
|
|
|
* written there right after "priv" structure allocation were
|
|
|
|
* flushed into RAM.
|
|
|
|
* Otherwise there's a chance to get some of them flushed in RAM when
|
|
|
|
* GMAC is already pushing data to RAM via DMA. This way incoming from
|
|
|
|
* GMAC data will be corrupted. */
|
2016-05-08 06:30:15 +00:00
|
|
|
flush_dcache_range((ulong)rxbuffs, (ulong)rxbuffs + RX_TOTAL_BUFSIZE);
|
2014-01-22 16:49:09 +00:00
|
|
|
|
2010-06-29 05:23:34 +00:00
|
|
|
for (idx = 0; idx < CONFIG_RX_DESCR_NUM; idx++) {
|
|
|
|
desc_p = &desc_table_p[idx];
|
2016-05-08 06:30:15 +00:00
|
|
|
desc_p->dmamac_addr = (ulong)&rxbuffs[idx * CONFIG_ETH_BUFSIZE];
|
|
|
|
desc_p->dmamac_next = (ulong)&desc_table_p[idx + 1];
|
2010-06-29 05:23:34 +00:00
|
|
|
|
|
|
|
desc_p->dmamac_cntl =
|
2015-12-20 02:59:23 +00:00
|
|
|
(MAC_MAX_FRAME_SZ & DESC_RXCTRL_SIZE1MASK) |
|
2010-06-29 05:23:34 +00:00
|
|
|
DESC_RXCTRL_RXCHAIN;
|
|
|
|
|
|
|
|
desc_p->txrx_status = DESC_RXSTS_OWNBYDMA;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Correcting the last pointer of the chain */
|
2016-05-08 06:30:15 +00:00
|
|
|
desc_p->dmamac_next = (ulong)&desc_table_p[0];
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:49:09 +00:00
|
|
|
/* Flush all Rx buffer descriptors at once */
|
2016-05-08 06:30:15 +00:00
|
|
|
flush_dcache_range((ulong)priv->rx_mac_descrtable,
|
|
|
|
(ulong)priv->rx_mac_descrtable +
|
2014-01-22 16:49:09 +00:00
|
|
|
sizeof(priv->rx_mac_descrtable));
|
|
|
|
|
2010-06-29 05:23:34 +00:00
|
|
|
writel((ulong)&desc_table_p[0], &dma_p->rxdesclistaddr);
|
2014-01-13 09:28:38 +00:00
|
|
|
priv->rx_currdescnum = 0;
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
static int _dw_write_hwaddr(struct dw_eth_dev *priv, u8 *mac_id)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
2014-01-22 16:54:06 +00:00
|
|
|
struct eth_mac_regs *mac_p = priv->mac_regs_p;
|
|
|
|
u32 macid_lo, macid_hi;
|
|
|
|
|
|
|
|
macid_lo = mac_id[0] + (mac_id[1] << 8) + (mac_id[2] << 16) +
|
|
|
|
(mac_id[3] << 24);
|
|
|
|
macid_hi = mac_id[4] + (mac_id[5] << 8);
|
|
|
|
|
|
|
|
writel(macid_hi, &mac_p->macaddr0hi);
|
|
|
|
writel(macid_lo, &mac_p->macaddr0lo);
|
|
|
|
|
|
|
|
return 0;
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:08 +00:00
|
|
|
static int dw_adjust_link(struct dw_eth_dev *priv, struct eth_mac_regs *mac_p,
|
|
|
|
struct phy_device *phydev)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
2014-01-22 16:54:06 +00:00
|
|
|
u32 conf = readl(&mac_p->conf) | FRAMEBURSTENABLE | DISABLERXOWN;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
if (!phydev->link) {
|
|
|
|
printf("%s: No link.\n", phydev->dev->name);
|
2017-01-11 10:46:08 +00:00
|
|
|
return 0;
|
2014-01-22 16:54:06 +00:00
|
|
|
}
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
if (phydev->speed != 1000)
|
|
|
|
conf |= MII_PORTSELECT;
|
2016-01-13 13:59:36 +00:00
|
|
|
else
|
|
|
|
conf &= ~MII_PORTSELECT;
|
2012-12-13 11:52:51 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
if (phydev->speed == 100)
|
|
|
|
conf |= FES_100;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
if (phydev->duplex)
|
|
|
|
conf |= FULLDPLXMODE;
|
2012-03-26 00:09:59 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
writel(conf, &mac_p->conf);
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
printf("Speed: %d, %s duplex%s\n", phydev->speed,
|
|
|
|
(phydev->duplex) ? "full" : "half",
|
|
|
|
(phydev->port == PORT_FIBRE) ? ", fiber mode" : "");
|
2017-01-11 10:46:08 +00:00
|
|
|
|
|
|
|
return 0;
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
static void _dw_eth_halt(struct dw_eth_dev *priv)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
|
|
|
struct eth_mac_regs *mac_p = priv->mac_regs_p;
|
2014-01-22 16:54:06 +00:00
|
|
|
struct eth_dma_regs *dma_p = priv->dma_regs_p;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
writel(readl(&mac_p->conf) & ~(RXENABLE | TXENABLE), &mac_p->conf);
|
|
|
|
writel(readl(&dma_p->opmode) & ~(RXSTART | TXSTART), &dma_p->opmode);
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
phy_shutdown(priv->phydev);
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
int designware_eth_init(struct dw_eth_dev *priv, u8 *enetaddr)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
|
|
|
struct eth_mac_regs *mac_p = priv->mac_regs_p;
|
|
|
|
struct eth_dma_regs *dma_p = priv->dma_regs_p;
|
2014-01-22 16:54:06 +00:00
|
|
|
unsigned int start;
|
2015-04-05 22:07:40 +00:00
|
|
|
int ret;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
writel(readl(&dma_p->busmode) | DMAMAC_SRST, &dma_p->busmode);
|
2012-03-26 00:09:56 +00:00
|
|
|
|
net: designware: set the PS bit when resetting DMA bus in MII configuration
On the SPEAr600 SoC, which has the dwmac1000 variant of the IP block,
the DMA reset never succeeds when a MII PHY is used (no problem with a
GMII PHY). The designware_eth_init() function sets the
DMAMAC_SRST bit in the DMA_BUS_MODE register, and then
polls until this bit clears. When a MII PHY is used, with the current
driver, this bit never clears and the driver therefore doesn't work.
The reason is that the PS bit of the GMAC_CONTROL register should be
correctly configured for the DMA reset to work. When the PS bit is 0,
it tells the MAC we have a GMII PHY, when the PS bit is 1, it tells
the MAC we have a MII PHY.
Doing a DMA reset clears all registers, so the PS bit is cleared as
well. This makes the DMA reset work fine with a GMII PHY. However,
with MII PHY, the PS bit should be set.
We have identified this issue thanks to two SPEAr600 platform:
- One equipped with a GMII PHY, with which the existing driver was
working fine.
- One equipped with a MII PHY, where the current driver fails because
the DMA reset times out.
Note: Taken from https://www.spinics.net/lists/netdev/msg432578.html
Signed-off-by: Quentin Schulz <quentin.schulz@bootlin.com>
Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2018-06-04 10:17:33 +00:00
|
|
|
/*
|
|
|
|
* When a MII PHY is used, we must set the PS bit for the DMA
|
|
|
|
* reset to succeed.
|
|
|
|
*/
|
|
|
|
if (priv->phydev->interface == PHY_INTERFACE_MODE_MII)
|
|
|
|
writel(readl(&mac_p->conf) | MII_PORTSELECT, &mac_p->conf);
|
|
|
|
else
|
|
|
|
writel(readl(&mac_p->conf) & ~MII_PORTSELECT, &mac_p->conf);
|
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
start = get_timer(0);
|
|
|
|
while (readl(&dma_p->busmode) & DMAMAC_SRST) {
|
2015-01-13 14:10:24 +00:00
|
|
|
if (get_timer(start) >= CONFIG_MACRESET_TIMEOUT) {
|
|
|
|
printf("DMA reset timeout\n");
|
2015-04-05 22:07:40 +00:00
|
|
|
return -ETIMEDOUT;
|
2015-01-13 14:10:24 +00:00
|
|
|
}
|
2012-05-07 10:04:25 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
mdelay(100);
|
|
|
|
};
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2015-06-15 10:40:19 +00:00
|
|
|
/*
|
|
|
|
* Soft reset above clears HW address registers.
|
|
|
|
* So we have to set it here once again.
|
|
|
|
*/
|
|
|
|
_dw_write_hwaddr(priv, enetaddr);
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
rx_descs_init(priv);
|
|
|
|
tx_descs_init(priv);
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-05-08 21:26:35 +00:00
|
|
|
writel(FIXEDBURST | PRIORXTX_41 | DMA_PBL, &dma_p->busmode);
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2015-01-29 06:38:50 +00:00
|
|
|
#ifndef CONFIG_DW_MAC_FORCE_THRESHOLD_MODE
|
2014-01-22 16:54:06 +00:00
|
|
|
writel(readl(&dma_p->opmode) | FLUSHTXFIFO | STOREFORWARD,
|
|
|
|
&dma_p->opmode);
|
2015-01-29 06:38:50 +00:00
|
|
|
#else
|
|
|
|
writel(readl(&dma_p->opmode) | FLUSHTXFIFO,
|
|
|
|
&dma_p->opmode);
|
|
|
|
#endif
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
writel(readl(&dma_p->opmode) | RXSTART | TXSTART, &dma_p->opmode);
|
2012-05-07 07:36:44 +00:00
|
|
|
|
2015-01-29 05:37:31 +00:00
|
|
|
#ifdef CONFIG_DW_AXI_BURST_LEN
|
|
|
|
writel((CONFIG_DW_AXI_BURST_LEN & 0x1FF >> 1), &dma_p->axibus);
|
|
|
|
#endif
|
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
/* Start up the PHY */
|
2015-04-05 22:07:40 +00:00
|
|
|
ret = phy_startup(priv->phydev);
|
|
|
|
if (ret) {
|
2014-01-22 16:54:06 +00:00
|
|
|
printf("Could not initialize PHY %s\n",
|
|
|
|
priv->phydev->dev->name);
|
2015-04-05 22:07:40 +00:00
|
|
|
return ret;
|
2012-05-07 07:36:44 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:08 +00:00
|
|
|
ret = dw_adjust_link(priv, mac_p, priv->phydev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2017-01-11 10:46:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
int designware_eth_enable(struct dw_eth_dev *priv)
|
2017-01-11 10:46:09 +00:00
|
|
|
{
|
|
|
|
struct eth_mac_regs *mac_p = priv->mac_regs_p;
|
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
if (!priv->phydev->link)
|
2015-04-05 22:07:40 +00:00
|
|
|
return -EIO;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2012-03-26 00:09:55 +00:00
|
|
|
writel(readl(&mac_p->conf) | RXENABLE | TXENABLE, &mac_p->conf);
|
2010-06-29 05:23:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-12-09 22:59:55 +00:00
|
|
|
#define ETH_ZLEN 60
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
static int _dw_eth_send(struct dw_eth_dev *priv, void *packet, int length)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
|
|
|
struct eth_dma_regs *dma_p = priv->dma_regs_p;
|
|
|
|
u32 desc_num = priv->tx_currdescnum;
|
|
|
|
struct dmamacdescr *desc_p = &priv->tx_mac_descrtable[desc_num];
|
2016-05-08 06:30:15 +00:00
|
|
|
ulong desc_start = (ulong)desc_p;
|
|
|
|
ulong desc_end = desc_start +
|
2014-09-14 23:05:23 +00:00
|
|
|
roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
|
2016-05-08 06:30:15 +00:00
|
|
|
ulong data_start = desc_p->dmamac_addr;
|
|
|
|
ulong data_end = data_start + roundup(length, ARCH_DMA_MINALIGN);
|
2014-05-08 21:26:33 +00:00
|
|
|
/*
|
|
|
|
* Strictly we only need to invalidate the "txrx_status" field
|
|
|
|
* for the following check, but on some platforms we cannot
|
2014-09-14 23:05:23 +00:00
|
|
|
* invalidate only 4 bytes, so we flush the entire descriptor,
|
|
|
|
* which is 16 bytes in total. This is safe because the
|
|
|
|
* individual descriptors in the array are each aligned to
|
|
|
|
* ARCH_DMA_MINALIGN and padded appropriately.
|
2014-05-08 21:26:33 +00:00
|
|
|
*/
|
2014-09-14 23:05:23 +00:00
|
|
|
invalidate_dcache_range(desc_start, desc_end);
|
2014-01-22 16:49:09 +00:00
|
|
|
|
2010-06-29 05:23:34 +00:00
|
|
|
/* Check if the descriptor is owned by CPU */
|
|
|
|
if (desc_p->txrx_status & DESC_TXSTS_OWNBYDMA) {
|
|
|
|
printf("CPU not owner of tx frame\n");
|
2015-04-05 22:07:40 +00:00
|
|
|
return -EPERM;
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 06:30:15 +00:00
|
|
|
memcpy((void *)data_start, packet, length);
|
2018-11-17 09:24:42 +00:00
|
|
|
if (length < ETH_ZLEN) {
|
|
|
|
memset(&((char *)data_start)[length], 0, ETH_ZLEN - length);
|
|
|
|
length = ETH_ZLEN;
|
|
|
|
}
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:49:09 +00:00
|
|
|
/* Flush data to be sent */
|
2014-09-14 23:05:23 +00:00
|
|
|
flush_dcache_range(data_start, data_end);
|
2014-01-22 16:49:09 +00:00
|
|
|
|
2010-06-29 05:23:34 +00:00
|
|
|
#if defined(CONFIG_DW_ALTDESCRIPTOR)
|
|
|
|
desc_p->txrx_status |= DESC_TXSTS_TXFIRST | DESC_TXSTS_TXLAST;
|
2018-11-17 09:24:41 +00:00
|
|
|
desc_p->dmamac_cntl = (desc_p->dmamac_cntl & ~DESC_TXCTRL_SIZE1MASK) |
|
|
|
|
((length << DESC_TXCTRL_SIZE1SHFT) &
|
|
|
|
DESC_TXCTRL_SIZE1MASK);
|
2010-06-29 05:23:34 +00:00
|
|
|
|
|
|
|
desc_p->txrx_status &= ~(DESC_TXSTS_MSK);
|
|
|
|
desc_p->txrx_status |= DESC_TXSTS_OWNBYDMA;
|
|
|
|
#else
|
2018-11-17 09:24:41 +00:00
|
|
|
desc_p->dmamac_cntl = (desc_p->dmamac_cntl & ~DESC_TXCTRL_SIZE1MASK) |
|
|
|
|
((length << DESC_TXCTRL_SIZE1SHFT) &
|
|
|
|
DESC_TXCTRL_SIZE1MASK) | DESC_TXCTRL_TXLAST |
|
|
|
|
DESC_TXCTRL_TXFIRST;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
|
|
|
desc_p->txrx_status = DESC_TXSTS_OWNBYDMA;
|
|
|
|
#endif
|
|
|
|
|
2014-01-22 16:49:09 +00:00
|
|
|
/* Flush modified buffer descriptor */
|
2014-09-14 23:05:23 +00:00
|
|
|
flush_dcache_range(desc_start, desc_end);
|
2014-01-22 16:49:09 +00:00
|
|
|
|
2010-06-29 05:23:34 +00:00
|
|
|
/* Test the wrap-around condition. */
|
|
|
|
if (++desc_num >= CONFIG_TX_DESCR_NUM)
|
|
|
|
desc_num = 0;
|
|
|
|
|
|
|
|
priv->tx_currdescnum = desc_num;
|
|
|
|
|
|
|
|
/* Start the transmission */
|
|
|
|
writel(POLL_DATA, &dma_p->txpolldemand);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-05 22:07:41 +00:00
|
|
|
static int _dw_eth_recv(struct dw_eth_dev *priv, uchar **packetp)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
2014-01-22 16:49:09 +00:00
|
|
|
u32 status, desc_num = priv->rx_currdescnum;
|
2010-06-29 05:23:34 +00:00
|
|
|
struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num];
|
2015-04-05 22:07:41 +00:00
|
|
|
int length = -EAGAIN;
|
2016-05-08 06:30:15 +00:00
|
|
|
ulong desc_start = (ulong)desc_p;
|
|
|
|
ulong desc_end = desc_start +
|
2014-09-14 23:05:23 +00:00
|
|
|
roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
|
2016-05-08 06:30:15 +00:00
|
|
|
ulong data_start = desc_p->dmamac_addr;
|
|
|
|
ulong data_end;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:49:09 +00:00
|
|
|
/* Invalidate entire buffer descriptor */
|
2014-09-14 23:05:23 +00:00
|
|
|
invalidate_dcache_range(desc_start, desc_end);
|
2014-01-22 16:49:09 +00:00
|
|
|
|
|
|
|
status = desc_p->txrx_status;
|
|
|
|
|
2010-06-29 05:23:34 +00:00
|
|
|
/* Check if the owner is the CPU */
|
|
|
|
if (!(status & DESC_RXSTS_OWNBYDMA)) {
|
|
|
|
|
2015-12-20 02:59:23 +00:00
|
|
|
length = (status & DESC_RXSTS_FRMLENMSK) >>
|
2010-06-29 05:23:34 +00:00
|
|
|
DESC_RXSTS_FRMLENSHFT;
|
|
|
|
|
2014-01-22 16:49:09 +00:00
|
|
|
/* Invalidate received data */
|
2014-09-14 23:05:23 +00:00
|
|
|
data_end = data_start + roundup(length, ARCH_DMA_MINALIGN);
|
|
|
|
invalidate_dcache_range(data_start, data_end);
|
2016-05-08 06:30:15 +00:00
|
|
|
*packetp = (uchar *)(ulong)desc_p->dmamac_addr;
|
2015-04-05 22:07:41 +00:00
|
|
|
}
|
2014-01-22 16:49:09 +00:00
|
|
|
|
2015-04-05 22:07:41 +00:00
|
|
|
return length;
|
|
|
|
}
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2015-04-05 22:07:41 +00:00
|
|
|
static int _dw_free_pkt(struct dw_eth_dev *priv)
|
|
|
|
{
|
|
|
|
u32 desc_num = priv->rx_currdescnum;
|
|
|
|
struct dmamacdescr *desc_p = &priv->rx_mac_descrtable[desc_num];
|
2016-05-08 06:30:15 +00:00
|
|
|
ulong desc_start = (ulong)desc_p;
|
|
|
|
ulong desc_end = desc_start +
|
2015-04-05 22:07:41 +00:00
|
|
|
roundup(sizeof(*desc_p), ARCH_DMA_MINALIGN);
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2015-04-05 22:07:41 +00:00
|
|
|
/*
|
|
|
|
* Make the current descriptor valid again and go to
|
|
|
|
* the next one
|
|
|
|
*/
|
|
|
|
desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA;
|
2014-01-22 16:49:09 +00:00
|
|
|
|
2015-04-05 22:07:41 +00:00
|
|
|
/* Flush only status field - others weren't changed */
|
|
|
|
flush_dcache_range(desc_start, desc_end);
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2015-04-05 22:07:41 +00:00
|
|
|
/* Test the wrap-around condition. */
|
|
|
|
if (++desc_num >= CONFIG_RX_DESCR_NUM)
|
|
|
|
desc_num = 0;
|
2010-06-29 05:23:34 +00:00
|
|
|
priv->rx_currdescnum = desc_num;
|
|
|
|
|
2015-04-05 22:07:41 +00:00
|
|
|
return 0;
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
static int dw_phy_init(struct dw_eth_dev *priv, void *dev)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
2014-01-22 16:54:06 +00:00
|
|
|
struct phy_device *phydev;
|
2021-02-24 14:02:39 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_DM_MDIO) && IS_ENABLED(CONFIG_DM_ETH)
|
|
|
|
phydev = dm_eth_phy_connect(dev);
|
|
|
|
if (!phydev)
|
|
|
|
return -ENODEV;
|
|
|
|
#else
|
|
|
|
int phy_addr = -1;
|
2012-03-26 00:09:59 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
#ifdef CONFIG_PHY_ADDR
|
2019-07-15 19:53:05 +00:00
|
|
|
phy_addr = CONFIG_PHY_ADDR;
|
2010-06-29 05:23:34 +00:00
|
|
|
#endif
|
|
|
|
|
2019-07-15 19:53:05 +00:00
|
|
|
phydev = phy_connect(priv->bus, phy_addr, dev, priv->interface);
|
2014-01-22 16:54:06 +00:00
|
|
|
if (!phydev)
|
2015-04-05 22:07:40 +00:00
|
|
|
return -ENODEV;
|
2021-02-24 14:02:39 +00:00
|
|
|
#endif
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
phydev->supported &= PHY_GBIT_FEATURES;
|
2016-01-13 13:59:37 +00:00
|
|
|
if (priv->max_speed) {
|
|
|
|
ret = phy_set_supported(phydev, priv->max_speed);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
2014-01-22 16:54:06 +00:00
|
|
|
phydev->advertising = phydev->supported;
|
2010-06-29 05:23:34 +00:00
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
priv->phydev = phydev;
|
|
|
|
phy_config(phydev);
|
2012-05-07 10:04:25 +00:00
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-05 22:07:41 +00:00
|
|
|
#ifndef CONFIG_DM_ETH
|
2020-06-26 06:13:33 +00:00
|
|
|
static int dw_eth_init(struct eth_device *dev, struct bd_info *bis)
|
2015-04-05 22:07:40 +00:00
|
|
|
{
|
2017-01-11 10:46:09 +00:00
|
|
|
int ret;
|
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
ret = designware_eth_init(dev->priv, dev->enetaddr);
|
2017-01-11 10:46:09 +00:00
|
|
|
if (!ret)
|
|
|
|
ret = designware_eth_enable(dev->priv);
|
|
|
|
|
|
|
|
return ret;
|
2015-04-05 22:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_eth_send(struct eth_device *dev, void *packet, int length)
|
|
|
|
{
|
|
|
|
return _dw_eth_send(dev->priv, packet, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_eth_recv(struct eth_device *dev)
|
|
|
|
{
|
2015-04-05 22:07:41 +00:00
|
|
|
uchar *packet;
|
|
|
|
int length;
|
|
|
|
|
|
|
|
length = _dw_eth_recv(dev->priv, &packet);
|
|
|
|
if (length == -EAGAIN)
|
|
|
|
return 0;
|
|
|
|
net_process_received_packet(packet, length);
|
|
|
|
|
|
|
|
_dw_free_pkt(dev->priv);
|
|
|
|
|
|
|
|
return 0;
|
2015-04-05 22:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dw_eth_halt(struct eth_device *dev)
|
|
|
|
{
|
|
|
|
return _dw_eth_halt(dev->priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dw_write_hwaddr(struct eth_device *dev)
|
|
|
|
{
|
|
|
|
return _dw_write_hwaddr(dev->priv, dev->enetaddr);
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
int designware_initialize(ulong base_addr, u32 interface)
|
2010-06-29 05:23:34 +00:00
|
|
|
{
|
|
|
|
struct eth_device *dev;
|
|
|
|
struct dw_eth_dev *priv;
|
|
|
|
|
|
|
|
dev = (struct eth_device *) malloc(sizeof(struct eth_device));
|
|
|
|
if (!dev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since the priv structure contains the descriptors which need a strict
|
|
|
|
* buswidth alignment, memalign is used to allocate memory
|
|
|
|
*/
|
2014-05-08 21:26:32 +00:00
|
|
|
priv = (struct dw_eth_dev *) memalign(ARCH_DMA_MINALIGN,
|
|
|
|
sizeof(struct dw_eth_dev));
|
2010-06-29 05:23:34 +00:00
|
|
|
if (!priv) {
|
|
|
|
free(dev);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2016-05-08 06:30:15 +00:00
|
|
|
if ((phys_addr_t)priv + sizeof(*priv) > (1ULL << 32)) {
|
|
|
|
printf("designware: buffers are outside DMA memory\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-06-29 05:23:34 +00:00
|
|
|
memset(dev, 0, sizeof(struct eth_device));
|
|
|
|
memset(priv, 0, sizeof(struct dw_eth_dev));
|
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
sprintf(dev->name, "dwmac.%lx", base_addr);
|
2010-06-29 05:23:34 +00:00
|
|
|
dev->iobase = (int)base_addr;
|
|
|
|
dev->priv = priv;
|
|
|
|
|
|
|
|
priv->dev = dev;
|
|
|
|
priv->mac_regs_p = (struct eth_mac_regs *)base_addr;
|
|
|
|
priv->dma_regs_p = (struct eth_dma_regs *)(base_addr +
|
|
|
|
DW_DMA_BASE_OFFSET);
|
|
|
|
|
|
|
|
dev->init = dw_eth_init;
|
|
|
|
dev->send = dw_eth_send;
|
|
|
|
dev->recv = dw_eth_recv;
|
|
|
|
dev->halt = dw_eth_halt;
|
|
|
|
dev->write_hwaddr = dw_write_hwaddr;
|
|
|
|
|
|
|
|
eth_register(dev);
|
|
|
|
|
2014-01-22 16:54:06 +00:00
|
|
|
priv->interface = interface;
|
|
|
|
|
|
|
|
dw_mdio_init(dev->name, priv->mac_regs_p);
|
|
|
|
priv->bus = miiphy_get_dev_by_name(dev->name);
|
|
|
|
|
2015-04-05 22:07:40 +00:00
|
|
|
return dw_phy_init(priv, dev);
|
2010-06-29 05:23:34 +00:00
|
|
|
}
|
2015-04-05 22:07:41 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_DM_ETH
|
|
|
|
static int designware_eth_start(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2017-01-11 10:46:09 +00:00
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
2015-04-05 22:07:41 +00:00
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
ret = designware_eth_init(priv, pdata->enetaddr);
|
2017-01-11 10:46:09 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = designware_eth_enable(priv);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
2015-04-05 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
int designware_eth_send(struct udevice *dev, void *packet, int length)
|
2015-04-05 22:07:41 +00:00
|
|
|
{
|
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return _dw_eth_send(priv, packet, length);
|
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
int designware_eth_recv(struct udevice *dev, int flags, uchar **packetp)
|
2015-04-05 22:07:41 +00:00
|
|
|
{
|
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return _dw_eth_recv(priv, packetp);
|
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
int designware_eth_free_pkt(struct udevice *dev, uchar *packet, int length)
|
2015-04-05 22:07:41 +00:00
|
|
|
{
|
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return _dw_free_pkt(priv);
|
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
void designware_eth_stop(struct udevice *dev)
|
2015-04-05 22:07:41 +00:00
|
|
|
{
|
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return _dw_eth_halt(priv);
|
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:10 +00:00
|
|
|
int designware_eth_write_hwaddr(struct udevice *dev)
|
2015-04-05 22:07:41 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2015-04-05 22:07:41 +00:00
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return _dw_write_hwaddr(priv, pdata->enetaddr);
|
|
|
|
}
|
|
|
|
|
2015-09-11 10:24:35 +00:00
|
|
|
static int designware_eth_bind(struct udevice *dev)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_DM_PCI
|
|
|
|
static int num_cards;
|
|
|
|
char name[20];
|
|
|
|
|
|
|
|
/* Create a unique device name for PCI type devices */
|
|
|
|
if (device_is_on_pci_bus(dev)) {
|
|
|
|
sprintf(name, "eth_designware#%u", num_cards++);
|
|
|
|
device_set_name(dev, name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:07 +00:00
|
|
|
int designware_eth_probe(struct udevice *dev)
|
2015-04-05 22:07:41 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct eth_pdata *pdata = dev_get_plat(dev);
|
2015-04-05 22:07:41 +00:00
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
2015-09-03 12:37:29 +00:00
|
|
|
u32 iobase = pdata->iobase;
|
2016-05-08 06:30:15 +00:00
|
|
|
ulong ioaddr;
|
2019-07-12 19:07:03 +00:00
|
|
|
int ret, err;
|
2018-06-14 10:45:23 +00:00
|
|
|
struct reset_ctl_bulk reset_bulk;
|
2017-11-29 08:06:11 +00:00
|
|
|
#ifdef CONFIG_CLK
|
2019-07-12 19:07:03 +00:00
|
|
|
int i, clock_nb;
|
2017-11-29 08:06:11 +00:00
|
|
|
|
|
|
|
priv->clock_count = 0;
|
2020-09-25 07:41:14 +00:00
|
|
|
clock_nb = dev_count_phandle_with_args(dev, "clocks", "#clock-cells",
|
|
|
|
0);
|
2017-11-29 08:06:11 +00:00
|
|
|
if (clock_nb > 0) {
|
|
|
|
priv->clocks = devm_kcalloc(dev, clock_nb, sizeof(struct clk),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!priv->clocks)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
for (i = 0; i < clock_nb; i++) {
|
|
|
|
err = clk_get_by_index(dev, i, &priv->clocks[i]);
|
|
|
|
if (err < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
err = clk_enable(&priv->clocks[i]);
|
2018-02-06 14:12:09 +00:00
|
|
|
if (err && err != -ENOSYS && err != -ENOTSUPP) {
|
2017-11-29 08:06:11 +00:00
|
|
|
pr_err("failed to enable clock %d\n", i);
|
|
|
|
clk_free(&priv->clocks[i]);
|
|
|
|
goto clk_err;
|
|
|
|
}
|
|
|
|
priv->clock_count++;
|
|
|
|
}
|
|
|
|
} else if (clock_nb != -ENOENT) {
|
|
|
|
pr_err("failed to get clock phandle(%d)\n", clock_nb);
|
|
|
|
return clock_nb;
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-05 22:07:41 +00:00
|
|
|
|
2017-03-27 08:54:17 +00:00
|
|
|
#if defined(CONFIG_DM_REGULATOR)
|
|
|
|
struct udevice *phy_supply;
|
|
|
|
|
|
|
|
ret = device_get_supply_regulator(dev, "phy-supply",
|
|
|
|
&phy_supply);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: No phy supply\n", dev->name);
|
|
|
|
} else {
|
|
|
|
ret = regulator_set_enable(phy_supply, true);
|
|
|
|
if (ret) {
|
|
|
|
puts("Error enabling phy supply\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-14 10:45:23 +00:00
|
|
|
ret = reset_get_bulk(dev, &reset_bulk);
|
|
|
|
if (ret)
|
|
|
|
dev_warn(dev, "Can't get reset: %d\n", ret);
|
|
|
|
else
|
|
|
|
reset_deassert_bulk(&reset_bulk);
|
|
|
|
|
2015-09-11 10:24:35 +00:00
|
|
|
#ifdef CONFIG_DM_PCI
|
|
|
|
/*
|
|
|
|
* If we are on PCI bus, either directly attached to a PCI root port,
|
2020-12-03 23:55:18 +00:00
|
|
|
* or via a PCI bridge, fill in plat before we probe the hardware.
|
2015-09-11 10:24:35 +00:00
|
|
|
*/
|
|
|
|
if (device_is_on_pci_bus(dev)) {
|
|
|
|
dm_pci_read_config32(dev, PCI_BASE_ADDRESS_0, &iobase);
|
|
|
|
iobase &= PCI_BASE_ADDRESS_MEM_MASK;
|
2016-02-02 13:58:00 +00:00
|
|
|
iobase = dm_pci_mem_to_phys(dev, iobase);
|
2015-09-11 10:24:35 +00:00
|
|
|
|
|
|
|
pdata->iobase = iobase;
|
|
|
|
pdata->phy_interface = PHY_INTERFACE_MODE_RMII;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-09-03 12:37:29 +00:00
|
|
|
debug("%s, iobase=%x, priv=%p\n", __func__, iobase, priv);
|
2016-05-08 06:30:15 +00:00
|
|
|
ioaddr = iobase;
|
|
|
|
priv->mac_regs_p = (struct eth_mac_regs *)ioaddr;
|
|
|
|
priv->dma_regs_p = (struct eth_dma_regs *)(ioaddr + DW_DMA_BASE_OFFSET);
|
2015-04-05 22:07:41 +00:00
|
|
|
priv->interface = pdata->phy_interface;
|
2016-01-13 13:59:37 +00:00
|
|
|
priv->max_speed = pdata->max_speed;
|
2015-04-05 22:07:41 +00:00
|
|
|
|
2021-02-24 14:02:39 +00:00
|
|
|
#if IS_ENABLED(CONFIG_DM_MDIO)
|
|
|
|
ret = dw_dm_mdio_init(dev->name, dev);
|
|
|
|
#else
|
2019-07-12 19:07:03 +00:00
|
|
|
ret = dw_mdio_init(dev->name, dev);
|
2021-02-24 14:02:39 +00:00
|
|
|
#endif
|
2019-07-12 19:07:03 +00:00
|
|
|
if (ret) {
|
|
|
|
err = ret;
|
|
|
|
goto mdio_err;
|
|
|
|
}
|
2015-04-05 22:07:41 +00:00
|
|
|
priv->bus = miiphy_get_dev_by_name(dev->name);
|
|
|
|
|
|
|
|
ret = dw_phy_init(priv, dev);
|
|
|
|
debug("%s, ret=%d\n", __func__, ret);
|
2019-07-12 19:07:03 +00:00
|
|
|
if (!ret)
|
|
|
|
return 0;
|
2015-04-05 22:07:41 +00:00
|
|
|
|
2019-07-12 19:07:03 +00:00
|
|
|
/* continue here for cleanup if no PHY found */
|
|
|
|
err = ret;
|
|
|
|
mdio_unregister(priv->bus);
|
|
|
|
mdio_free(priv->bus);
|
|
|
|
mdio_err:
|
2017-11-29 08:06:11 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_CLK
|
|
|
|
clk_err:
|
|
|
|
ret = clk_release_all(priv->clocks, priv->clock_count);
|
|
|
|
if (ret)
|
|
|
|
pr_err("failed to disable all clocks\n");
|
|
|
|
|
|
|
|
#endif
|
2019-07-12 19:07:03 +00:00
|
|
|
return err;
|
2015-04-05 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
2015-10-08 04:32:38 +00:00
|
|
|
static int designware_eth_remove(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
free(priv->phydev);
|
|
|
|
mdio_unregister(priv->bus);
|
|
|
|
mdio_free(priv->bus);
|
|
|
|
|
2017-11-29 08:06:11 +00:00
|
|
|
#ifdef CONFIG_CLK
|
|
|
|
return clk_release_all(priv->clocks, priv->clock_count);
|
|
|
|
#else
|
2015-10-08 04:32:38 +00:00
|
|
|
return 0;
|
2017-11-29 08:06:11 +00:00
|
|
|
#endif
|
2015-10-08 04:32:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 10:46:07 +00:00
|
|
|
const struct eth_ops designware_eth_ops = {
|
2015-04-05 22:07:41 +00:00
|
|
|
.start = designware_eth_start,
|
|
|
|
.send = designware_eth_send,
|
|
|
|
.recv = designware_eth_recv,
|
|
|
|
.free_pkt = designware_eth_free_pkt,
|
|
|
|
.stop = designware_eth_stop,
|
|
|
|
.write_hwaddr = designware_eth_write_hwaddr,
|
|
|
|
};
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
int designware_eth_of_to_plat(struct udevice *dev)
|
2015-04-05 22:07:41 +00:00
|
|
|
{
|
2020-12-03 23:55:20 +00:00
|
|
|
struct dw_eth_pdata *dw_pdata = dev_get_plat(dev);
|
2019-12-07 04:41:35 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
2016-02-28 21:24:55 +00:00
|
|
|
struct dw_eth_dev *priv = dev_get_priv(dev);
|
2016-06-27 10:17:51 +00:00
|
|
|
#endif
|
2016-02-28 21:24:55 +00:00
|
|
|
struct eth_pdata *pdata = &dw_pdata->eth_pdata;
|
2015-04-05 22:07:41 +00:00
|
|
|
const char *phy_mode;
|
2019-12-07 04:41:35 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
2016-02-28 21:24:55 +00:00
|
|
|
int reset_flags = GPIOD_IS_OUT;
|
2016-06-27 10:17:51 +00:00
|
|
|
#endif
|
2016-02-28 21:24:55 +00:00
|
|
|
int ret = 0;
|
2015-04-05 22:07:41 +00:00
|
|
|
|
2017-09-11 20:04:13 +00:00
|
|
|
pdata->iobase = dev_read_addr(dev);
|
2015-04-05 22:07:41 +00:00
|
|
|
pdata->phy_interface = -1;
|
2017-09-11 20:04:13 +00:00
|
|
|
phy_mode = dev_read_string(dev, "phy-mode");
|
2015-04-05 22:07:41 +00:00
|
|
|
if (phy_mode)
|
|
|
|
pdata->phy_interface = phy_get_interface_by_name(phy_mode);
|
|
|
|
if (pdata->phy_interface == -1) {
|
|
|
|
debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-09-11 20:04:13 +00:00
|
|
|
pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0);
|
2016-01-13 13:59:37 +00:00
|
|
|
|
2019-12-07 04:41:35 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_GPIO)
|
2017-06-07 16:46:01 +00:00
|
|
|
if (dev_read_bool(dev, "snps,reset-active-low"))
|
2016-02-28 21:24:55 +00:00
|
|
|
reset_flags |= GPIOD_ACTIVE_LOW;
|
|
|
|
|
|
|
|
ret = gpio_request_by_name(dev, "snps,reset-gpio", 0,
|
|
|
|
&priv->reset_gpio, reset_flags);
|
|
|
|
if (ret == 0) {
|
2017-06-07 16:46:01 +00:00
|
|
|
ret = dev_read_u32_array(dev, "snps,reset-delays-us",
|
|
|
|
dw_pdata->reset_delays, 3);
|
2016-02-28 21:24:55 +00:00
|
|
|
} else if (ret == -ENOENT) {
|
|
|
|
ret = 0;
|
|
|
|
}
|
2016-06-27 10:17:51 +00:00
|
|
|
#endif
|
2016-02-28 21:24:55 +00:00
|
|
|
|
|
|
|
return ret;
|
2015-04-05 22:07:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id designware_eth_ids[] = {
|
|
|
|
{ .compatible = "allwinner,sun7i-a20-gmac" },
|
2016-08-16 09:49:50 +00:00
|
|
|
{ .compatible = "amlogic,meson6-dwmac" },
|
2017-01-22 15:04:27 +00:00
|
|
|
{ .compatible = "st,stm32-dwmac" },
|
2019-10-07 16:10:50 +00:00
|
|
|
{ .compatible = "snps,arc-dwmac-3.70a" },
|
2015-04-05 22:07:41 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2015-07-25 16:42:34 +00:00
|
|
|
U_BOOT_DRIVER(eth_designware) = {
|
2015-04-05 22:07:41 +00:00
|
|
|
.name = "eth_designware",
|
|
|
|
.id = UCLASS_ETH,
|
|
|
|
.of_match = designware_eth_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = designware_eth_of_to_plat,
|
2015-09-11 10:24:35 +00:00
|
|
|
.bind = designware_eth_bind,
|
2015-04-05 22:07:41 +00:00
|
|
|
.probe = designware_eth_probe,
|
2015-10-08 04:32:38 +00:00
|
|
|
.remove = designware_eth_remove,
|
2015-04-05 22:07:41 +00:00
|
|
|
.ops = &designware_eth_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct dw_eth_dev),
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat_auto = sizeof(struct dw_eth_pdata),
|
2015-04-05 22:07:41 +00:00
|
|
|
.flags = DM_FLAG_ALLOC_PRIV_DMA,
|
|
|
|
};
|
2015-09-11 10:24:35 +00:00
|
|
|
|
|
|
|
static struct pci_device_id supported[] = {
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_QRK_EMAC) },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_PCI_DEVICE(eth_designware, supported);
|
2015-04-05 22:07:41 +00:00
|
|
|
#endif
|