PCI based devices can share devicetree info parse with platform device based devices after split dt parse frpm dt probe. Signed-off-by: Jiaxun Yang <jiaxun.yang@xxxxxxxxxxx> --- .../ethernet/stmicro/stmmac/stmmac_platform.c | 63 ++++++++++++++----- .../ethernet/stmicro/stmmac/stmmac_platform.h | 3 + 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c index 170c3a052b14..7e29bc76b7c3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c @@ -385,25 +385,19 @@ static int stmmac_of_get_mac_mode(struct device_node *np) } /** - * stmmac_probe_config_dt - parse device-tree driver parameters - * @pdev: platform_device structure - * @mac: MAC address to use + * stmmac_parse_config_dt - parse device-tree driver parameters + * @np: device_mode structure + * @plat: plat_stmmacenet_data structure * Description: * this function is to read the driver parameters from device-tree and * set some private fields that will be used by the main at runtime. */ -struct plat_stmmacenet_data * -stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) +int stmmac_parse_config_dt(struct device_node *np, + struct plat_stmmacenet_data *plat) { - struct device_node *np = pdev->dev.of_node; - struct plat_stmmacenet_data *plat; struct stmmac_dma_cfg *dma_cfg; int rc; - plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); - if (!plat) - return ERR_PTR(-ENOMEM); - *mac = of_get_mac_address(np); if (IS_ERR(*mac)) { if (PTR_ERR(*mac) == -EPROBE_DEFER) @@ -414,7 +408,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) plat->phy_interface = of_get_phy_mode(np); if (plat->phy_interface < 0) - return ERR_PTR(plat->phy_interface); + return plat->phy_interface; plat->interface = stmmac_of_get_mac_mode(np); if (plat->interface < 0) @@ -453,7 +447,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) /* To Configure PHY by using all device-tree supported properties */ rc = stmmac_dt_phy(plat, np, &pdev->dev); if (rc) - return ERR_PTR(rc); + return rc; of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size); @@ -531,7 +525,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) GFP_KERNEL); if (!dma_cfg) { stmmac_remove_config_dt(pdev, plat); - return ERR_PTR(-ENOMEM); + return -ENOMEM; } plat->dma_cfg = dma_cfg; @@ -560,7 +554,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) rc = stmmac_mtl_setup(pdev, plat); if (rc) { stmmac_remove_config_dt(pdev, plat); - return ERR_PTR(rc); + return rc; } /* clock setup */ @@ -604,14 +598,43 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) plat->stmmac_rst = NULL; } - return plat; + return 0; error_hw_init: clk_disable_unprepare(plat->pclk); error_pclk_get: clk_disable_unprepare(plat->stmmac_clk); - return ERR_PTR(-EPROBE_DEFER); + return -EPROBE_DEFER; +} + +/** + * stmmac_probe_config_dt - probe and setup stmmac platform data by devicetree + * @pdev: platform_device structure + * @mac: MAC address to use + * Description: + * this function is to set up plat_stmmacenet_data private structure + * for platform drivers. + */ +struct plat_stmmacenet_data * +stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) +{ + struct device_node *np = pdev->dev.of_node; + struct plat_stmmacenet_data *plat; + int rc; + + plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); + if (!plat) + return ERR_PTR(-ENOMEM); + + rc = stmmac_parse_config_dt(np, plat); + + if (rc) { + free(plat); + return ERR_PTR(rc); + } + + return plat; } /** @@ -628,6 +651,11 @@ void stmmac_remove_config_dt(struct platform_device *pdev, of_node_put(plat->mdio_node); } #else +int stmmac_parse_config_dt(struct device_node *np, + struct plat_stmmacenet_data *plat) +{ + return -EINVAL; +} struct plat_stmmacenet_data * stmmac_probe_config_dt(struct platform_device *pdev, const char **mac) { @@ -639,6 +667,7 @@ void stmmac_remove_config_dt(struct platform_device *pdev, { } #endif /* CONFIG_OF */ +EXPORT_SYMBOL_GPL(stmmac_parse_config_dt); EXPORT_SYMBOL_GPL(stmmac_probe_config_dt); EXPORT_SYMBOL_GPL(stmmac_remove_config_dt); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h index 3a4663b7b460..0e4aec1f502a 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h @@ -11,6 +11,9 @@ #include "stmmac.h" +int stmmac_parse_config_dt(struct device_node *np, + struct plat_stmmacenet_data *plat); + struct plat_stmmacenet_data * stmmac_probe_config_dt(struct platform_device *pdev, const char **mac); void stmmac_remove_config_dt(struct platform_device *pdev, -- 2.23.0