FILE
dwmac-sophgo.c
File preview with syntax highlighting.
linux-6.19.14/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c
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/property.h> 11#include <linux/mod_devicetable.h> 12#include <linux/platform_device.h> 13 14#include "stmmac_platform.h" 15 16struct sophgo_dwmac_data { 17 bool has_internal_rx_delay; 18}; 19 20static int sophgo_sg2044_dwmac_init(struct platform_device *pdev, 21 struct plat_stmmacenet_data *plat_dat, 22 struct stmmac_resources *stmmac_res) 23{ 24 plat_dat->clk_tx_i = devm_clk_get_enabled(&pdev->dev, "tx"); 25 if (IS_ERR(plat_dat->clk_tx_i)) 26 return dev_err_probe(&pdev->dev, PTR_ERR(plat_dat->clk_tx_i), 27 "failed to get tx clock\n"); 28 29 plat_dat->flags |= STMMAC_FLAG_SPH_DISABLE; 30 plat_dat->set_clk_tx_rate = stmmac_set_clk_tx_rate; 31 plat_dat->multicast_filter_bins = 0; 32 33 return 0; 34} 35 36static int sophgo_dwmac_probe(struct platform_device *pdev) 37{ 38 struct plat_stmmacenet_data *plat_dat; 39 const struct sophgo_dwmac_data *data; 40 struct stmmac_resources stmmac_res; 41 struct device *dev = &pdev->dev; 42 int ret; 43 44 ret = stmmac_get_platform_resources(pdev, &stmmac_res); 45 if (ret) 46 return dev_err_probe(dev, ret, 47 "failed to get platform resources\n"); 48 49 plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac); 50 if (IS_ERR(plat_dat)) 51 return dev_err_probe(dev, PTR_ERR(plat_dat), 52 "failed to parse DT parameters\n"); 53 54 ret = sophgo_sg2044_dwmac_init(pdev, plat_dat, &stmmac_res); 55 if (ret) 56 return ret; 57 58 data = device_get_match_data(&pdev->dev); 59 if (data && data->has_internal_rx_delay) { 60 plat_dat->phy_interface = phy_fix_phy_mode_for_mac_delays(plat_dat->phy_interface, 61 false, true); 62 if (plat_dat->phy_interface == PHY_INTERFACE_MODE_NA) 63 return -EINVAL; 64 } 65 66 return stmmac_dvr_probe(dev, plat_dat, &stmmac_res); 67} 68 69static const struct sophgo_dwmac_data sg2042_dwmac_data = { 70 .has_internal_rx_delay = true, 71}; 72 73static const struct of_device_id sophgo_dwmac_match[] = { 74 { .compatible = "sophgo,sg2042-dwmac", .data = &sg2042_dwmac_data }, 75 { .compatible = "sophgo,sg2044-dwmac" }, 76 { /* sentinel */ } 77}; 78MODULE_DEVICE_TABLE(of, sophgo_dwmac_match); 79 80static struct platform_driver sophgo_dwmac_driver = { 81 .probe = sophgo_dwmac_probe, 82 .remove = stmmac_pltfr_remove, 83 .driver = { 84 .name = "sophgo-dwmac", 85 .pm = &stmmac_pltfr_pm_ops, 86 .of_match_table = sophgo_dwmac_match, 87 }, 88}; 89module_platform_driver(sophgo_dwmac_driver); 90 91MODULE_AUTHOR("Inochi Amaoto <inochiama@gmail.com>"); 92MODULE_DESCRIPTION("Sophgo DWMAC platform driver"); 93MODULE_LICENSE("GPL");
~/
Read-only file preview.