|
13 | 13 |
|
14 | 14 | #include "stmmac_platform.h"
|
15 | 15 |
|
| 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 | + |
16 | 20 | struct starfive_dwmac {
|
17 | 21 | struct device *dev;
|
18 | 22 | struct clk *clk_tx;
|
@@ -46,6 +50,46 @@ static void starfive_dwmac_fix_mac_speed(void *priv, unsigned int speed)
|
46 | 50 | dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate);
|
47 | 51 | }
|
48 | 52 |
|
| 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 | + |
49 | 93 | static int starfive_dwmac_probe(struct platform_device *pdev)
|
50 | 94 | {
|
51 | 95 | struct plat_stmmacenet_data *plat_dat;
|
@@ -91,6 +135,10 @@ static int starfive_dwmac_probe(struct platform_device *pdev)
|
91 | 135 | plat_dat->bsp_priv = dwmac;
|
92 | 136 | plat_dat->dma_cfg->dche = true;
|
93 | 137 |
|
| 138 | + err = starfive_dwmac_set_mode(plat_dat); |
| 139 | + if (err) |
| 140 | + return err; |
| 141 | + |
94 | 142 | err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
|
95 | 143 | if (err) {
|
96 | 144 | stmmac_remove_config_dt(pdev, plat_dat);
|
|
0 commit comments