2018-08-13 17:32:14 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Marek Vasut <marex@denx.de>
|
|
|
|
*
|
|
|
|
* Altera SoCFPGA EMAC extras
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <phy.h>
|
|
|
|
#include <regmap.h>
|
|
|
|
#include <reset.h>
|
|
|
|
#include <syscon.h>
|
|
|
|
#include "designware.h"
|
2020-02-03 14:36:16 +00:00
|
|
|
#include <dm/device_compat.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2018-08-13 17:32:14 +00:00
|
|
|
|
|
|
|
#include <asm/arch/system_manager.h>
|
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
struct dwmac_socfpga_plat {
|
2018-08-13 17:32:14 +00:00
|
|
|
struct dw_eth_pdata dw_eth_pdata;
|
|
|
|
void *phy_intf;
|
net: designware: socfpga: adapt to Gen5
This driver was written for Arria10, but it applies to Gen5, too.
The main difference is that Gen5 has 2 MACs (Arria10 has 3) and the
syscon bits are encoded in the same register, thus an offset is needed.
This offset is already read from the devicetree, but for Arria10 it is
always 0, which is probably why it has been ignored. By using this
offset when writing the phy mode into the syscon regiter, we can use
this driver to set the phy mode for both of the MACs on Gen5.
Since the PHY mode bits in sysmgr are the same even for Stratix10,
let's drop the detection of the sub-mach by checking compatible
version and just use the same code for all FPGAs.
To work correctly, this driver depends on SYSCON and REGMAP, so select
those via Kconfig when it is enabeld.
Tested on socfpga_socrates (where the 2nd MAC is connected, so a shift
offset is required).
Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-01-13 18:58:40 +00:00
|
|
|
u32 reg_shift;
|
2018-08-13 17:32:14 +00:00
|
|
|
};
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int dwmac_socfpga_of_to_plat(struct udevice *dev)
|
2018-08-13 17:32:14 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct dwmac_socfpga_plat *pdata = dev_get_plat(dev);
|
2018-08-13 17:32:14 +00:00
|
|
|
struct regmap *regmap;
|
|
|
|
struct ofnode_phandle_args args;
|
|
|
|
void *range;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dev_read_phandle_with_args(dev, "altr,sysmgr-syscon", NULL,
|
|
|
|
2, 0, &args);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Failed to get syscon: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.args_count != 2) {
|
|
|
|
dev_err(dev, "Invalid number of syscon args\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
regmap = syscon_node_to_regmap(args.node);
|
|
|
|
if (IS_ERR(regmap)) {
|
|
|
|
ret = PTR_ERR(regmap);
|
|
|
|
dev_err(dev, "Failed to get regmap: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
range = regmap_get_range(regmap, 0);
|
|
|
|
if (!range) {
|
|
|
|
dev_err(dev, "Failed to get regmap range\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata->phy_intf = range + args.args[0];
|
net: designware: socfpga: adapt to Gen5
This driver was written for Arria10, but it applies to Gen5, too.
The main difference is that Gen5 has 2 MACs (Arria10 has 3) and the
syscon bits are encoded in the same register, thus an offset is needed.
This offset is already read from the devicetree, but for Arria10 it is
always 0, which is probably why it has been ignored. By using this
offset when writing the phy mode into the syscon regiter, we can use
this driver to set the phy mode for both of the MACs on Gen5.
Since the PHY mode bits in sysmgr are the same even for Stratix10,
let's drop the detection of the sub-mach by checking compatible
version and just use the same code for all FPGAs.
To work correctly, this driver depends on SYSCON and REGMAP, so select
those via Kconfig when it is enabeld.
Tested on socfpga_socrates (where the 2nd MAC is connected, so a shift
offset is required).
Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-01-13 18:58:40 +00:00
|
|
|
pdata->reg_shift = args.args[1];
|
2018-08-13 17:32:14 +00:00
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
return designware_eth_of_to_plat(dev);
|
2018-08-13 17:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dwmac_socfpga_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct dwmac_socfpga_plat *pdata = dev_get_plat(dev);
|
2018-08-13 17:32:14 +00:00
|
|
|
struct eth_pdata *edata = &pdata->dw_eth_pdata.eth_pdata;
|
|
|
|
struct reset_ctl_bulk reset_bulk;
|
|
|
|
int ret;
|
net: designware: socfpga: adapt to Gen5
This driver was written for Arria10, but it applies to Gen5, too.
The main difference is that Gen5 has 2 MACs (Arria10 has 3) and the
syscon bits are encoded in the same register, thus an offset is needed.
This offset is already read from the devicetree, but for Arria10 it is
always 0, which is probably why it has been ignored. By using this
offset when writing the phy mode into the syscon regiter, we can use
this driver to set the phy mode for both of the MACs on Gen5.
Since the PHY mode bits in sysmgr are the same even for Stratix10,
let's drop the detection of the sub-mach by checking compatible
version and just use the same code for all FPGAs.
To work correctly, this driver depends on SYSCON and REGMAP, so select
those via Kconfig when it is enabeld.
Tested on socfpga_socrates (where the 2nd MAC is connected, so a shift
offset is required).
Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-01-13 18:58:40 +00:00
|
|
|
u32 modereg;
|
|
|
|
u32 modemask;
|
|
|
|
|
|
|
|
switch (edata->phy_interface) {
|
|
|
|
case PHY_INTERFACE_MODE_MII:
|
|
|
|
case PHY_INTERFACE_MODE_GMII:
|
|
|
|
modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
|
|
|
|
break;
|
|
|
|
case PHY_INTERFACE_MODE_RMII:
|
|
|
|
modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
|
|
|
|
break;
|
|
|
|
case PHY_INTERFACE_MODE_RGMII:
|
|
|
|
modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dev_err(dev, "Unsupported PHY mode\n");
|
|
|
|
return -EINVAL;
|
2018-08-13 17:32:14 +00:00
|
|
|
}
|
|
|
|
|
net: designware: socfpga: adapt to Gen5
This driver was written for Arria10, but it applies to Gen5, too.
The main difference is that Gen5 has 2 MACs (Arria10 has 3) and the
syscon bits are encoded in the same register, thus an offset is needed.
This offset is already read from the devicetree, but for Arria10 it is
always 0, which is probably why it has been ignored. By using this
offset when writing the phy mode into the syscon regiter, we can use
this driver to set the phy mode for both of the MACs on Gen5.
Since the PHY mode bits in sysmgr are the same even for Stratix10,
let's drop the detection of the sub-mach by checking compatible
version and just use the same code for all FPGAs.
To work correctly, this driver depends on SYSCON and REGMAP, so select
those via Kconfig when it is enabeld.
Tested on socfpga_socrates (where the 2nd MAC is connected, so a shift
offset is required).
Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
2019-01-13 18:58:40 +00:00
|
|
|
ret = reset_get_bulk(dev, &reset_bulk);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "Failed to get reset: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
reset_assert_bulk(&reset_bulk);
|
|
|
|
|
|
|
|
modemask = SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << pdata->reg_shift;
|
|
|
|
clrsetbits_le32(pdata->phy_intf, modemask,
|
|
|
|
modereg << pdata->reg_shift);
|
|
|
|
|
|
|
|
reset_release_bulk(&reset_bulk);
|
|
|
|
|
2018-08-13 17:32:14 +00:00
|
|
|
return designware_eth_probe(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id dwmac_socfpga_ids[] = {
|
|
|
|
{ .compatible = "altr,socfpga-stmmac" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(dwmac_socfpga) = {
|
|
|
|
.name = "dwmac_socfpga",
|
|
|
|
.id = UCLASS_ETH,
|
|
|
|
.of_match = dwmac_socfpga_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = dwmac_socfpga_of_to_plat,
|
2018-08-13 17:32:14 +00:00
|
|
|
.probe = dwmac_socfpga_probe,
|
|
|
|
.ops = &designware_eth_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct dw_eth_dev),
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct dwmac_socfpga_plat),
|
2018-08-13 17:32:14 +00:00
|
|
|
.flags = DM_FLAG_ALLOC_PRIV_DMA,
|
|
|
|
};
|