xref: /linux/drivers/net/ethernet/stmicro/stmmac/dwmac-sophgo.c (revision 1a9239bb4253f9076b5b4b2a1a4e8d7defd77a95)
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 
sophgo_sg2044_dwmac_init(struct platform_device * pdev,struct plat_stmmacenet_data * plat_dat,struct stmmac_resources * stmmac_res)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 
sophgo_dwmac_probe(struct platform_device * pdev)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,sg2044-dwmac" },
58 	{ /* sentinel */ }
59 };
60 MODULE_DEVICE_TABLE(of, sophgo_dwmac_match);
61 
62 static struct platform_driver sophgo_dwmac_driver = {
63 	.probe  = sophgo_dwmac_probe,
64 	.remove = stmmac_pltfr_remove,
65 	.driver = {
66 		.name = "sophgo-dwmac",
67 		.pm = &stmmac_pltfr_pm_ops,
68 		.of_match_table = sophgo_dwmac_match,
69 	},
70 };
71 module_platform_driver(sophgo_dwmac_driver);
72 
73 MODULE_AUTHOR("Inochi Amaoto <inochiama@gmail.com>");
74 MODULE_DESCRIPTION("Sophgo DWMAC platform driver");
75 MODULE_LICENSE("GPL");
76