1 // SPDX-License-Identifier: GPL-2.0-only
3 * Amlogic Meson6 and Meson8 DWMAC glue layer
5 * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
8 #include <linux/device.h>
9 #include <linux/ethtool.h>
11 #include <linux/ioport.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/stmmac.h>
16 #include "stmmac_platform.h"
18 #define ETHMAC_SPEED_100 BIT(1)
25 static void meson6_dwmac_fix_mac_speed(void *priv
, unsigned int speed
)
27 struct meson_dwmac
*dwmac
= priv
;
30 val
= readl(dwmac
->reg
);
34 val
&= ~ETHMAC_SPEED_100
;
37 val
|= ETHMAC_SPEED_100
;
41 writel(val
, dwmac
->reg
);
44 static int meson6_dwmac_probe(struct platform_device
*pdev
)
46 struct plat_stmmacenet_data
*plat_dat
;
47 struct stmmac_resources stmmac_res
;
48 struct meson_dwmac
*dwmac
;
51 ret
= stmmac_get_platform_resources(pdev
, &stmmac_res
);
55 plat_dat
= stmmac_probe_config_dt(pdev
, &stmmac_res
.mac
);
57 return PTR_ERR(plat_dat
);
59 dwmac
= devm_kzalloc(&pdev
->dev
, sizeof(*dwmac
), GFP_KERNEL
);
62 goto err_remove_config_dt
;
65 dwmac
->reg
= devm_platform_ioremap_resource(pdev
, 1);
66 if (IS_ERR(dwmac
->reg
)) {
67 ret
= PTR_ERR(dwmac
->reg
);
68 goto err_remove_config_dt
;
71 plat_dat
->bsp_priv
= dwmac
;
72 plat_dat
->fix_mac_speed
= meson6_dwmac_fix_mac_speed
;
74 ret
= stmmac_dvr_probe(&pdev
->dev
, plat_dat
, &stmmac_res
);
76 goto err_remove_config_dt
;
81 stmmac_remove_config_dt(pdev
, plat_dat
);
86 static const struct of_device_id meson6_dwmac_match
[] = {
87 { .compatible
= "amlogic,meson6-dwmac" },
90 MODULE_DEVICE_TABLE(of
, meson6_dwmac_match
);
92 static struct platform_driver meson6_dwmac_driver
= {
93 .probe
= meson6_dwmac_probe
,
94 .remove
= stmmac_pltfr_remove
,
96 .name
= "meson6-dwmac",
97 .pm
= &stmmac_pltfr_pm_ops
,
98 .of_match_table
= meson6_dwmac_match
,
101 module_platform_driver(meson6_dwmac_driver
);
103 MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
104 MODULE_DESCRIPTION("Amlogic Meson6 and Meson8 DWMAC glue layer");
105 MODULE_LICENSE("GPL v2");