1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Sophgo DWMAC platform driver 4 * 5 * Copyright (C) 2024 Inochi Amaoto <inochiama@gmail.com> 6 */ 7 8 #include <linux/clk.h> 9 #include <linux/module.h> 10 #include <linux/mod_devicetable.h> 11 #include <linux/platform_device.h> 12 13 #include "stmmac_platform.h" 14 15 static int sophgo_sg2044_dwmac_init(struct platform_device *pdev, 16 struct plat_stmmacenet_data *plat_dat, 17 struct stmmac_resources *stmmac_res) 18 { 19 plat_dat->clk_tx_i = devm_clk_get_enabled(&pdev->dev, "tx"); 20 if (IS_ERR(plat_dat->clk_tx_i)) 21 return dev_err_probe(&pdev->dev, PTR_ERR(plat_dat->clk_tx_i), 22 "failed to get tx clock\n"); 23 24 plat_dat->flags |= STMMAC_FLAG_SPH_DISABLE; 25 plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate; 26 plat_dat->multicast_filter_bins = 0; 27 plat_dat->unicast_filter_entries = 1; 28 29 return 0; 30 } 31 32 static int sophgo_dwmac_probe(struct platform_device *pdev) 33 { 34 struct plat_stmmacenet_data *plat_dat; 35 struct stmmac_resources stmmac_res; 36 struct device *dev = &pdev->dev; 37 int ret; 38 39 ret = stmmac_get_platform_resources(pdev, &stmmac_res); 40 if (ret) 41 return dev_err_probe(dev, ret, 42 "failed to get platform resources\n"); 43 44 plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac); 45 if (IS_ERR(plat_dat)) 46 return dev_err_probe(dev, PTR_ERR(plat_dat), 47 "failed to parse DT parameters\n"); 48 49 ret = sophgo_sg2044_dwmac_init(pdev, plat_dat, &stmmac_res); 50 if (ret) 51 return ret; 52 53 return stmmac_dvr_probe(dev, plat_dat, &stmmac_res); 54 } 55 56 static const struct of_device_id sophgo_dwmac_match[] = { 57 { .compatible = "sophgo,sg2042-dwmac" }, 58 { .compatible = "sophgo,sg2044-dwmac" }, 59 { /* sentinel */ } 60 }; 61 MODULE_DEVICE_TABLE(of, sophgo_dwmac_match); 62 63 static struct platform_driver sophgo_dwmac_driver = { 64 .probe = sophgo_dwmac_probe, 65 .remove = stmmac_pltfr_remove, 66 .driver = { 67 .name = "sophgo-dwmac", 68 .pm = &stmmac_pltfr_pm_ops, 69 .of_match_table = sophgo_dwmac_match, 70 }, 71 }; 72 module_platform_driver(sophgo_dwmac_driver); 73 74 MODULE_AUTHOR("Inochi Amaoto <inochiama@gmail.com>"); 75 MODULE_DESCRIPTION("Sophgo DWMAC platform driver"); 76 MODULE_LICENSE("GPL"); 77