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"
18 #include <asm/arch/system_manager.h>
20 struct dwmac_socfpga_platdata {
21 struct dw_eth_pdata dw_eth_pdata;
26 static int dwmac_socfpga_ofdata_to_platdata(struct udevice *dev)
28 struct dwmac_socfpga_platdata *pdata = dev_get_platdata(dev);
29 struct regmap *regmap;
30 struct ofnode_phandle_args args;
34 ret = dev_read_phandle_with_args(dev, "altr,sysmgr-syscon", NULL,
37 dev_err(dev, "Failed to get syscon: %d\n", ret);
41 if (args.args_count != 2) {
42 dev_err(dev, "Invalid number of syscon args\n");
46 regmap = syscon_node_to_regmap(args.node);
48 ret = PTR_ERR(regmap);
49 dev_err(dev, "Failed to get regmap: %d\n", ret);
53 range = regmap_get_range(regmap, 0);
55 dev_err(dev, "Failed to get regmap range\n");
59 pdata->phy_intf = range + args.args[0];
60 pdata->reg_shift = args.args[1];
62 return designware_eth_ofdata_to_platdata(dev);
65 static int dwmac_socfpga_probe(struct udevice *dev)
67 struct dwmac_socfpga_platdata *pdata = dev_get_platdata(dev);
68 struct eth_pdata *edata = &pdata->dw_eth_pdata.eth_pdata;
69 struct reset_ctl_bulk reset_bulk;
74 switch (edata->phy_interface) {
75 case PHY_INTERFACE_MODE_MII:
76 case PHY_INTERFACE_MODE_GMII:
77 modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_GMII_MII;
79 case PHY_INTERFACE_MODE_RMII:
80 modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RMII;
82 case PHY_INTERFACE_MODE_RGMII:
83 modereg = SYSMGR_EMACGRP_CTRL_PHYSEL_ENUM_RGMII;
86 dev_err(dev, "Unsupported PHY mode\n");
90 ret = reset_get_bulk(dev, &reset_bulk);
92 dev_err(dev, "Failed to get reset: %d\n", ret);
96 reset_assert_bulk(&reset_bulk);
98 modemask = SYSMGR_EMACGRP_CTRL_PHYSEL_MASK << pdata->reg_shift;
99 clrsetbits_le32(pdata->phy_intf, modemask,
100 modereg << pdata->reg_shift);
102 reset_release_bulk(&reset_bulk);
104 return designware_eth_probe(dev);
107 static const struct udevice_id dwmac_socfpga_ids[] = {
108 { .compatible = "altr,socfpga-stmmac" },
112 U_BOOT_DRIVER(dwmac_socfpga) = {
113 .name = "dwmac_socfpga",
115 .of_match = dwmac_socfpga_ids,
116 .ofdata_to_platdata = dwmac_socfpga_ofdata_to_platdata,
117 .probe = dwmac_socfpga_probe,
118 .ops = &designware_eth_ops,
119 .priv_auto_alloc_size = sizeof(struct dw_eth_dev),
120 .platdata_auto_alloc_size = sizeof(struct dwmac_socfpga_platdata),
121 .flags = DM_FLAG_ALLOC_PRIV_DMA,