net: dwc_eth_qos: Adapt probe() for PCI devices

PCI devices do not necessarily use a device tree. In that case, the
driver currently fails to find eqos->config and eqos->regs.

This commit factors out the respective functionality. Device tree usage
remains default, but board specific implementations will be possible as
well.

Signed-off-by: Philip Oberfichtner <pro@denx.de>
This commit is contained in:
Philip Oberfichtner
2024-08-02 11:25:37 +02:00
committed by Tom Rini
parent 14b237a8bd
commit beabef6511
7 changed files with 79 additions and 8 deletions

View File

@@ -32,6 +32,7 @@
#include <clk.h> #include <clk.h>
#include <cpu_func.h> #include <cpu_func.h>
#include <dm.h> #include <dm.h>
#include <dm/device_compat.h>
#include <errno.h> #include <errno.h>
#include <eth_phy.h> #include <eth_phy.h>
#include <log.h> #include <log.h>
@@ -1301,6 +1302,13 @@ static int eqos_probe_resources_tegra186(struct udevice *dev)
debug("%s(dev=%p):\n", __func__, dev); debug("%s(dev=%p):\n", __func__, dev);
ret = eqos_get_base_addr_dt(dev);
if (ret) {
pr_err("eqos_get_base_addr_dt failed: %d\n", ret);
return ret;
}
eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE);
ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl); ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl);
if (ret) { if (ret) {
pr_err("reset_get_by_name(rst) failed: %d\n", ret); pr_err("reset_get_by_name(rst) failed: %d\n", ret);
@@ -1375,6 +1383,42 @@ static int eqos_remove_resources_tegra186(struct udevice *dev)
return 0; return 0;
} }
/*
* Get driver data based on the device tree. Boards not using a device tree can
* overwrite this function.
*/
__weak void *eqos_get_driver_data(struct udevice *dev)
{
return (void *)dev_get_driver_data(dev);
}
static fdt_addr_t eqos_get_base_addr_common(struct udevice *dev, fdt_addr_t addr)
{
struct eqos_priv *eqos = dev_get_priv(dev);
if (addr == FDT_ADDR_T_NONE) {
#if CONFIG_IS_ENABLED(FDT_64BIT)
dev_err(dev, "addr=0x%llx is invalid.\n", addr);
#else
dev_err(dev, "addr=0x%x is invalid.\n", addr);
#endif
return -EINVAL;
}
eqos->regs = addr;
eqos->mac_regs = (void *)(addr + EQOS_MAC_REGS_BASE);
eqos->mtl_regs = (void *)(addr + EQOS_MTL_REGS_BASE);
eqos->dma_regs = (void *)(addr + EQOS_DMA_REGS_BASE);
return 0;
}
int eqos_get_base_addr_dt(struct udevice *dev)
{
fdt_addr_t addr = dev_read_addr(dev);
return eqos_get_base_addr_common(dev, addr);
}
static int eqos_probe(struct udevice *dev) static int eqos_probe(struct udevice *dev)
{ {
struct eqos_priv *eqos = dev_get_priv(dev); struct eqos_priv *eqos = dev_get_priv(dev);
@@ -1383,17 +1427,12 @@ static int eqos_probe(struct udevice *dev)
debug("%s(dev=%p):\n", __func__, dev); debug("%s(dev=%p):\n", __func__, dev);
eqos->dev = dev; eqos->dev = dev;
eqos->config = (void *)dev_get_driver_data(dev);
eqos->regs = dev_read_addr(dev); eqos->config = eqos_get_driver_data(dev);
if (eqos->regs == FDT_ADDR_T_NONE) { if (!eqos->config) {
pr_err("dev_read_addr() failed\n"); pr_err("Failed to get driver data.\n");
return -ENODEV; return -ENODEV;
} }
eqos->mac_regs = (void *)(eqos->regs + EQOS_MAC_REGS_BASE);
eqos->mtl_regs = (void *)(eqos->regs + EQOS_MTL_REGS_BASE);
eqos->dma_regs = (void *)(eqos->regs + EQOS_DMA_REGS_BASE);
eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE);
eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0); eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0);

View File

@@ -289,7 +289,9 @@ void eqos_inval_desc_generic(void *desc);
void eqos_flush_desc_generic(void *desc); void eqos_flush_desc_generic(void *desc);
void eqos_inval_buffer_generic(void *buf, size_t size); void eqos_inval_buffer_generic(void *buf, size_t size);
void eqos_flush_buffer_generic(void *buf, size_t size); void eqos_flush_buffer_generic(void *buf, size_t size);
int eqos_get_base_addr_dt(struct udevice *dev);
int eqos_null_ops(struct udevice *dev); int eqos_null_ops(struct udevice *dev);
void *eqos_get_driver_data(struct udevice *dev);
extern struct eqos_config eqos_imx_config; extern struct eqos_config eqos_imx_config;
extern struct eqos_config eqos_rockchip_config; extern struct eqos_config eqos_rockchip_config;

View File

@@ -47,6 +47,12 @@ static int eqos_probe_resources_imx(struct udevice *dev)
debug("%s(dev=%p):\n", __func__, dev); debug("%s(dev=%p):\n", __func__, dev);
ret = eqos_get_base_addr_dt(dev);
if (ret) {
dev_dbg(dev, "eqos_get_base_addr_dt failed: %d", ret);
goto err_probe;
}
interface = eqos->config->interface(dev); interface = eqos->config->interface(dev);
if (interface == PHY_INTERFACE_MODE_NA) { if (interface == PHY_INTERFACE_MODE_NA) {

View File

@@ -522,6 +522,12 @@ static int eqos_probe_resources_qcom(struct udevice *dev)
debug("%s(dev=%p):\n", __func__, dev); debug("%s(dev=%p):\n", __func__, dev);
ret = eqos_get_base_addr_dt(dev);
if (ret) {
pr_err("eqos_get_base_addr_dt failed: %d\n", ret);
return ret;
}
interface = eqos->config->interface(dev); interface = eqos->config->interface(dev);
if (interface == PHY_INTERFACE_MODE_NA) { if (interface == PHY_INTERFACE_MODE_NA) {

View File

@@ -311,6 +311,12 @@ static int eqos_probe_resources_rk(struct udevice *dev)
int reset_flags = GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE; int reset_flags = GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE;
int ret; int ret;
ret = eqos_get_base_addr_dt(dev);
if (ret) {
dev_err(dev, "eqos_get_base_addr_dt failed: %d\n", ret);
return ret;
}
data = calloc(1, sizeof(struct rockchip_platform_data)); data = calloc(1, sizeof(struct rockchip_platform_data));
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;

View File

@@ -183,6 +183,12 @@ static int eqos_probe_resources_jh7110(struct udevice *dev)
struct starfive_platform_data *data; struct starfive_platform_data *data;
int ret; int ret;
ret = eqos_get_base_addr_dt(dev);
if (ret) {
pr_err("eqos_get_base_addr_dt failed: %d\n", ret);
return ret;
}
data = calloc(1, sizeof(struct starfive_platform_data)); data = calloc(1, sizeof(struct starfive_platform_data));
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;

View File

@@ -234,6 +234,12 @@ static int eqos_probe_resources_stm32(struct udevice *dev)
interface = eqos->config->interface(dev); interface = eqos->config->interface(dev);
ret = eqos_get_base_addr_dt(dev);
if (ret) {
dev_err(dev, "eqos_get_base_addr_dt failed: %d\n", ret);
return ret;
}
if (interface == PHY_INTERFACE_MODE_NA) { if (interface == PHY_INTERFACE_MODE_NA) {
dev_err(dev, "Invalid PHY interface\n"); dev_err(dev, "Invalid PHY interface\n");
return -EINVAL; return -EINVAL;