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