1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Marek Vasut <marex@denx.de>
5 * Altera SoCFPGA EMAC extras
16 #include "designware.h"
17 #include <dm/device_compat.h>
18 #include <linux/err.h>
20 #include <asm/arch/system_manager.h>
22 struct dwmac_socfpga_platdata {
23 struct dw_eth_pdata dw_eth_pdata;
28 static int dwmac_socfpga_of_to_plat(struct udevice *dev)
30 struct dwmac_socfpga_platdata *pdata = dev_get_plat(dev);
31 struct regmap *regmap;
32 struct ofnode_phandle_args args;
36 ret = dev_read_phandle_with_args(dev, "altr,sysmgr-syscon", NULL,
39 dev_err(dev, "Failed to get syscon: %d\n", ret);
43 if (args.args_count != 2) {
44 dev_err(dev, "Invalid number of syscon args\n");
48 regmap = syscon_node_to_regmap(args.node);
50 ret = PTR_ERR(regmap);
51 dev_err(dev, "Failed to get regmap: %d\n", ret);
55 range = regmap_get_range(regmap, 0);
57 dev_err(dev, "Failed to get regmap range\n");
61 pdata->phy_intf = range + args.args[0];
62 pdata->reg_shift = args.args[1];
64 return designware_eth_of_to_plat(dev);
67 static int dwmac_socfpga_probe(struct udevice *dev)
69 struct dwmac_socfpga_platdata *pdata = dev_get_plat(dev);
70 struct eth_pdata *edata = &pdata->dw_eth_pdata.eth_pdata;
71 struct reset_ctl_bulk reset_bulk;
76 switch (edata->phy_interface) {
77 case PHY_INTERFACE_MODE_MII:
78 case PHY_INTERFACE_MODE_GMII:
79 modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
81 case PHY_INTERFACE_MODE_RMII:
82 modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
84 case PHY_INTERFACE_MODE_RGMII:
85 modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
88 dev_err(dev, "Unsupported PHY mode\n");
92 ret = reset_get_bulk(dev, &reset_bulk);
94 dev_err(dev, "Failed to get reset: %d\n", ret);
98 reset_assert_bulk(&reset_bulk);
100 modemask = SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << pdata->reg_shift;
101 clrsetbits_le32(pdata->phy_intf, modemask,
102 modereg << pdata->reg_shift);
104 reset_release_bulk(&reset_bulk);
106 return designware_eth_probe(dev);
109 static const struct udevice_id dwmac_socfpga_ids[] = {
110 { .compatible = "altr,socfpga-stmmac" },
114 U_BOOT_DRIVER(dwmac_socfpga) = {
115 .name = "dwmac_socfpga",
117 .of_match = dwmac_socfpga_ids,
118 .of_to_plat = dwmac_socfpga_of_to_plat,
119 .probe = dwmac_socfpga_probe,
120 .ops = &designware_eth_ops,
121 .priv_auto = sizeof(struct dw_eth_dev),
122 .plat_auto = sizeof(struct dwmac_socfpga_platdata),
123 .flags = DM_FLAG_ALLOC_PRIV_DMA,