Skip to content

Commit b4a5afa

Browse files
Samin GuoPaolo Abeni
authored andcommitted
net: stmmac: dwmac-starfive: Add phy interface settings
dwmac supports multiple modess. When working under rmii and rgmii, you need to set different phy interfaces. According to the dwmac document, when working in rmii, it needs to be set to 0x4, and rgmii needs to be set to 0x1. The phy interface needs to be set in syscon, the format is as follows: starfive,syscon: <&syscon, offset, shift> Tested-by: Tommaso Merciai <[email protected]> Signed-off-by: Samin Guo <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 4bd3bb7 commit b4a5afa

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
#include "stmmac_platform.h"
1515

16+
#define STARFIVE_DWMAC_PHY_INFT_RGMII 0x1
17+
#define STARFIVE_DWMAC_PHY_INFT_RMII 0x4
18+
#define STARFIVE_DWMAC_PHY_INFT_FIELD 0x7U
19+
1620
struct starfive_dwmac {
1721
struct device *dev;
1822
struct clk *clk_tx;
@@ -46,6 +50,46 @@ static void starfive_dwmac_fix_mac_speed(void *priv, unsigned int speed)
4650
dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate);
4751
}
4852

53+
static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat)
54+
{
55+
struct starfive_dwmac *dwmac = plat_dat->bsp_priv;
56+
struct regmap *regmap;
57+
unsigned int args[2];
58+
unsigned int mode;
59+
int err;
60+
61+
switch (plat_dat->interface) {
62+
case PHY_INTERFACE_MODE_RMII:
63+
mode = STARFIVE_DWMAC_PHY_INFT_RMII;
64+
break;
65+
66+
case PHY_INTERFACE_MODE_RGMII:
67+
case PHY_INTERFACE_MODE_RGMII_ID:
68+
mode = STARFIVE_DWMAC_PHY_INFT_RGMII;
69+
break;
70+
71+
default:
72+
dev_err(dwmac->dev, "unsupported interface %d\n",
73+
plat_dat->interface);
74+
return -EINVAL;
75+
}
76+
77+
regmap = syscon_regmap_lookup_by_phandle_args(dwmac->dev->of_node,
78+
"starfive,syscon",
79+
2, args);
80+
if (IS_ERR(regmap))
81+
return dev_err_probe(dwmac->dev, PTR_ERR(regmap), "getting the regmap failed\n");
82+
83+
/* args[0]:offset args[1]: shift */
84+
err = regmap_update_bits(regmap, args[0],
85+
STARFIVE_DWMAC_PHY_INFT_FIELD << args[1],
86+
mode << args[1]);
87+
if (err)
88+
return dev_err_probe(dwmac->dev, err, "error setting phy mode\n");
89+
90+
return 0;
91+
}
92+
4993
static int starfive_dwmac_probe(struct platform_device *pdev)
5094
{
5195
struct plat_stmmacenet_data *plat_dat;
@@ -91,6 +135,10 @@ static int starfive_dwmac_probe(struct platform_device *pdev)
91135
plat_dat->bsp_priv = dwmac;
92136
plat_dat->dma_cfg->dche = true;
93137

138+
err = starfive_dwmac_set_mode(plat_dat);
139+
if (err)
140+
return err;
141+
94142
err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
95143
if (err) {
96144
stmmac_remove_config_dt(pdev, plat_dat);

0 commit comments

Comments
 (0)