2014-09-20 20:29:16 +07:00
|
|
|
/*
|
2016-09-07 04:38:48 +07:00
|
|
|
* Amlogic Meson6 and Meson8 DWMAC glue layer
|
2014-09-20 20:29:16 +07:00
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/ioport.h>
|
2015-05-14 17:11:01 +07:00
|
|
|
#include <linux/module.h>
|
2014-09-20 20:29:16 +07:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/stmmac.h>
|
|
|
|
|
2014-11-07 21:46:42 +07:00
|
|
|
#include "stmmac_platform.h"
|
|
|
|
|
2014-09-20 20:29:16 +07:00
|
|
|
#define ETHMAC_SPEED_100 BIT(1)
|
|
|
|
|
|
|
|
struct meson_dwmac {
|
|
|
|
struct device *dev;
|
|
|
|
void __iomem *reg;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void meson6_dwmac_fix_mac_speed(void *priv, unsigned int speed)
|
|
|
|
{
|
|
|
|
struct meson_dwmac *dwmac = priv;
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
val = readl(dwmac->reg);
|
|
|
|
|
|
|
|
switch (speed) {
|
|
|
|
case SPEED_10:
|
|
|
|
val &= ~ETHMAC_SPEED_100;
|
|
|
|
break;
|
|
|
|
case SPEED_100:
|
|
|
|
val |= ETHMAC_SPEED_100;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(val, dwmac->reg);
|
|
|
|
}
|
|
|
|
|
2015-07-17 05:26:11 +07:00
|
|
|
static int meson6_dwmac_probe(struct platform_device *pdev)
|
2014-09-20 20:29:16 +07:00
|
|
|
{
|
2015-07-17 05:26:11 +07:00
|
|
|
struct plat_stmmacenet_data *plat_dat;
|
|
|
|
struct stmmac_resources stmmac_res;
|
2014-09-20 20:29:16 +07:00
|
|
|
struct meson_dwmac *dwmac;
|
|
|
|
struct resource *res;
|
2015-07-17 05:26:11 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = stmmac_get_platform_resources(pdev, &stmmac_res);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
|
|
|
|
if (IS_ERR(plat_dat))
|
|
|
|
return PTR_ERR(plat_dat);
|
2014-09-20 20:29:16 +07:00
|
|
|
|
|
|
|
dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
|
|
|
|
if (!dwmac)
|
2015-07-17 05:26:11 +07:00
|
|
|
return -ENOMEM;
|
2014-09-20 20:29:16 +07:00
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
|
|
|
|
dwmac->reg = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(dwmac->reg))
|
2015-07-17 05:26:11 +07:00
|
|
|
return PTR_ERR(dwmac->reg);
|
2014-09-20 20:29:16 +07:00
|
|
|
|
2015-07-17 05:26:11 +07:00
|
|
|
plat_dat->bsp_priv = dwmac;
|
|
|
|
plat_dat->fix_mac_speed = meson6_dwmac_fix_mac_speed;
|
2014-09-20 20:29:16 +07:00
|
|
|
|
2015-07-17 05:26:11 +07:00
|
|
|
return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
|
|
|
|
}
|
2015-05-14 17:11:01 +07:00
|
|
|
|
|
|
|
static const struct of_device_id meson6_dwmac_match[] = {
|
2015-07-17 05:26:11 +07:00
|
|
|
{ .compatible = "amlogic,meson6-dwmac" },
|
2015-05-14 17:11:01 +07:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, meson6_dwmac_match);
|
|
|
|
|
|
|
|
static struct platform_driver meson6_dwmac_driver = {
|
2015-07-17 05:26:11 +07:00
|
|
|
.probe = meson6_dwmac_probe,
|
2015-05-14 17:11:01 +07:00
|
|
|
.remove = stmmac_pltfr_remove,
|
|
|
|
.driver = {
|
|
|
|
.name = "meson6-dwmac",
|
|
|
|
.pm = &stmmac_pltfr_pm_ops,
|
|
|
|
.of_match_table = meson6_dwmac_match,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
module_platform_driver(meson6_dwmac_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
|
2016-09-07 04:38:48 +07:00
|
|
|
MODULE_DESCRIPTION("Amlogic Meson6 and Meson8 DWMAC glue layer");
|
2015-05-14 17:11:01 +07:00
|
|
|
MODULE_LICENSE("GPL v2");
|