2 * Amlogic Meson6 and Meson8 DWMAC glue layer
4 * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * You should have received a copy of the GNU General Public License
11 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 #include <linux/device.h>
15 #include <linux/ethtool.h>
17 #include <linux/ioport.h>
18 #include <linux/module.h>
19 #include <linux/platform_device.h>
20 #include <linux/stmmac.h>
22 #include "stmmac_platform.h"
24 #define ETHMAC_SPEED_100 BIT(1)
31 static void meson6_dwmac_fix_mac_speed(void *priv
, unsigned int speed
)
33 struct meson_dwmac
*dwmac
= priv
;
36 val
= readl(dwmac
->reg
);
40 val
&= ~ETHMAC_SPEED_100
;
43 val
|= ETHMAC_SPEED_100
;
47 writel(val
, dwmac
->reg
);
50 static int meson6_dwmac_probe(struct platform_device
*pdev
)
52 struct plat_stmmacenet_data
*plat_dat
;
53 struct stmmac_resources stmmac_res
;
54 struct meson_dwmac
*dwmac
;
58 ret
= stmmac_get_platform_resources(pdev
, &stmmac_res
);
62 plat_dat
= stmmac_probe_config_dt(pdev
, &stmmac_res
.mac
);
64 return PTR_ERR(plat_dat
);
66 dwmac
= devm_kzalloc(&pdev
->dev
, sizeof(*dwmac
), GFP_KERNEL
);
69 goto err_remove_config_dt
;
72 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
73 dwmac
->reg
= devm_ioremap_resource(&pdev
->dev
, res
);
74 if (IS_ERR(dwmac
->reg
)) {
75 ret
= PTR_ERR(dwmac
->reg
);
76 goto err_remove_config_dt
;
79 plat_dat
->bsp_priv
= dwmac
;
80 plat_dat
->fix_mac_speed
= meson6_dwmac_fix_mac_speed
;
82 ret
= stmmac_dvr_probe(&pdev
->dev
, plat_dat
, &stmmac_res
);
84 goto err_remove_config_dt
;
89 stmmac_remove_config_dt(pdev
, plat_dat
);
94 static const struct of_device_id meson6_dwmac_match
[] = {
95 { .compatible
= "amlogic,meson6-dwmac" },
98 MODULE_DEVICE_TABLE(of
, meson6_dwmac_match
);
100 static struct platform_driver meson6_dwmac_driver
= {
101 .probe
= meson6_dwmac_probe
,
102 .remove
= stmmac_pltfr_remove
,
104 .name
= "meson6-dwmac",
105 .pm
= &stmmac_pltfr_pm_ops
,
106 .of_match_table
= meson6_dwmac_match
,
109 module_platform_driver(meson6_dwmac_driver
);
111 MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
112 MODULE_DESCRIPTION("Amlogic Meson6 and Meson8 DWMAC glue layer");
113 MODULE_LICENSE("GPL v2");