1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (C) 2024 Schneider-Electric 4 * 5 * Clément Léger <clement.leger@bootlin.com> 6 */ 7 8 #include <linux/of.h> 9 #include <linux/pcs-rzn1-miic.h> 10 #include <linux/phylink.h> 11 #include <linux/platform_device.h> 12 13 #include "stmmac_platform.h" 14 #include "stmmac.h" 15 16 static int rzn1_dwmac_pcs_init(struct stmmac_priv *priv) 17 { 18 struct device_node *np = priv->device->of_node; 19 struct device_node *pcs_node; 20 struct phylink_pcs *pcs; 21 22 pcs_node = of_parse_phandle(np, "pcs-handle", 0); 23 24 if (pcs_node) { 25 pcs = miic_create(priv->device, pcs_node); 26 of_node_put(pcs_node); 27 if (IS_ERR(pcs)) 28 return PTR_ERR(pcs); 29 30 priv->hw->phylink_pcs = pcs; 31 } 32 33 return 0; 34 } 35 36 static void rzn1_dwmac_pcs_exit(struct stmmac_priv *priv) 37 { 38 if (priv->hw->phylink_pcs) 39 miic_destroy(priv->hw->phylink_pcs); 40 } 41 42 static struct phylink_pcs *rzn1_dwmac_select_pcs(struct stmmac_priv *priv, 43 phy_interface_t interface) 44 { 45 return priv->hw->phylink_pcs; 46 } 47 48 static int rzn1_dwmac_probe(struct platform_device *pdev) 49 { 50 struct plat_stmmacenet_data *plat_dat; 51 struct stmmac_resources stmmac_res; 52 struct device *dev = &pdev->dev; 53 int ret; 54 55 ret = stmmac_get_platform_resources(pdev, &stmmac_res); 56 if (ret) 57 return ret; 58 59 plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac); 60 if (IS_ERR(plat_dat)) 61 return PTR_ERR(plat_dat); 62 63 plat_dat->bsp_priv = plat_dat; 64 plat_dat->pcs_init = rzn1_dwmac_pcs_init; 65 plat_dat->pcs_exit = rzn1_dwmac_pcs_exit; 66 plat_dat->select_pcs = rzn1_dwmac_select_pcs; 67 68 ret = stmmac_dvr_probe(dev, plat_dat, &stmmac_res); 69 if (ret) 70 return ret; 71 72 return 0; 73 } 74 75 static const struct of_device_id rzn1_dwmac_match[] = { 76 { .compatible = "renesas,rzn1-gmac" }, 77 { } 78 }; 79 MODULE_DEVICE_TABLE(of, rzn1_dwmac_match); 80 81 static struct platform_driver rzn1_dwmac_driver = { 82 .probe = rzn1_dwmac_probe, 83 .remove = stmmac_pltfr_remove, 84 .driver = { 85 .name = "rzn1-dwmac", 86 .of_match_table = rzn1_dwmac_match, 87 }, 88 }; 89 module_platform_driver(rzn1_dwmac_driver); 90 91 MODULE_AUTHOR("Clément Léger <clement.leger@bootlin.com>"); 92 MODULE_DESCRIPTION("Renesas RZN1 DWMAC specific glue layer"); 93 MODULE_LICENSE("GPL"); 94