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
16static 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
36static 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
42static int rzn1_dwmac_probe(struct platform_device *pdev)
43{
44	struct plat_stmmacenet_data *plat_dat;
45	struct stmmac_resources stmmac_res;
46	struct device *dev = &pdev->dev;
47	int ret;
48
49	ret = stmmac_get_platform_resources(pdev, &stmmac_res);
50	if (ret)
51		return ret;
52
53	plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
54	if (IS_ERR(plat_dat))
55		return PTR_ERR(plat_dat);
56
57	plat_dat->bsp_priv = plat_dat;
58	plat_dat->pcs_init = rzn1_dwmac_pcs_init;
59	plat_dat->pcs_exit = rzn1_dwmac_pcs_exit;
60
61	ret = stmmac_dvr_probe(dev, plat_dat, &stmmac_res);
62	if (ret)
63		return ret;
64
65	return 0;
66}
67
68static const struct of_device_id rzn1_dwmac_match[] = {
69	{ .compatible = "renesas,rzn1-gmac" },
70	{ }
71};
72MODULE_DEVICE_TABLE(of, rzn1_dwmac_match);
73
74static struct platform_driver rzn1_dwmac_driver = {
75	.probe  = rzn1_dwmac_probe,
76	.remove_new = stmmac_pltfr_remove,
77	.driver = {
78		.name           = "rzn1-dwmac",
79		.of_match_table = rzn1_dwmac_match,
80	},
81};
82module_platform_driver(rzn1_dwmac_driver);
83
84MODULE_AUTHOR("Cl��ment L��ger <clement.leger@bootlin.com>");
85MODULE_DESCRIPTION("Renesas RZN1 DWMAC specific glue layer");
86MODULE_LICENSE("GPL");
87