Message ID | 20230407110356.8449-7-samin.guo@starfivetech.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Add Ethernet driver for StarFive JH7110 SoC | expand |
Context | Check | Description |
---|---|---|
conchuod/cover_letter | success | Series has a cover letter |
conchuod/tree_selection | success | Guessed tree name to be for-next at HEAD d34a6b715a23 |
conchuod/fixes_present | success | Fixes tag not required for -next series |
conchuod/maintainers_pattern | success | MAINTAINERS pattern errors before the patch: 1 and now 1 |
conchuod/verify_signedoff | success | Signed-off-by tag matches author and committer |
conchuod/kdoc | success | Errors and warnings before: 0 this patch: 0 |
conchuod/build_rv64_clang_allmodconfig | success | Errors and warnings before: 18 this patch: 18 |
conchuod/module_param | success | Was 0 now: 0 |
conchuod/build_rv64_gcc_allmodconfig | success | Errors and warnings before: 18 this patch: 18 |
conchuod/build_rv32_defconfig | success | Build OK |
conchuod/dtb_warn_rv64 | success | Errors and warnings before: 3 this patch: 3 |
conchuod/header_inline | success | No static functions without inline keyword in header files |
conchuod/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 66 lines checked |
conchuod/source_inline | success | Was 0 now: 0 |
conchuod/build_rv64_nommu_k210_defconfig | success | Build OK |
conchuod/verify_fixes | success | No Fixes tag |
conchuod/build_rv64_nommu_virt_defconfig | success | Build OK |
Hi Samin, If you're respinning this series anyway, please use "net: stmmac: dwmac-starfive:" to match the filename. On Fri, 7 Apr 2023 at 13:05, Samin Guo <samin.guo@starfivetech.com> wrote: > > 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 <tomm.merciai@gmail.com> > Signed-off-by: Samin Guo <samin.guo@starfivetech.com> > --- > .../ethernet/stmicro/stmmac/dwmac-starfive.c | 48 +++++++++++++++++++ > 1 file changed, 48 insertions(+) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c > index 4963d4008485..d6a1eddb51e8 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c > @@ -13,6 +13,10 @@ > > #include "stmmac_platform.h" > > +#define STARFIVE_DWMAC_PHY_INFT_RGMII 0x1 > +#define STARFIVE_DWMAC_PHY_INFT_RMII 0x4 > +#define STARFIVE_DWMAC_PHY_INFT_FIELD 0x7U > + > struct starfive_dwmac { > struct device *dev; > struct clk *clk_tx; > @@ -46,6 +50,46 @@ static void starfive_dwmac_fix_mac_speed(void *priv, unsigned int speed) > dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate); > } > > +static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat) > +{ > + struct starfive_dwmac *dwmac = plat_dat->bsp_priv; > + struct regmap *regmap; > + unsigned int args[2]; > + unsigned int mode; > + int err; > + > + switch (plat_dat->interface) { > + case PHY_INTERFACE_MODE_RMII: > + mode = STARFIVE_DWMAC_PHY_INFT_RMII; > + break; > + > + case PHY_INTERFACE_MODE_RGMII: > + case PHY_INTERFACE_MODE_RGMII_ID: > + mode = STARFIVE_DWMAC_PHY_INFT_RGMII; > + break; > + > + default: > + dev_err(dwmac->dev, "unsupported interface %d\n", > + plat_dat->interface); > + return -EINVAL; > + } > + > + regmap = syscon_regmap_lookup_by_phandle_args(dwmac->dev->of_node, > + "starfive,syscon", > + 2, args); > + if (IS_ERR(regmap)) > + return dev_err_probe(dwmac->dev, PTR_ERR(regmap), "syscon regmap failed\n"); This message is a bit misleading. It's not actually that the regmap failed, but getting/looking up the regmap failed. > + /* args[0]:offset args[1]: shift */ > + err = regmap_update_bits(regmap, args[0], > + STARFIVE_DWMAC_PHY_INFT_FIELD << args[1], > + mode << args[1]); > + if (err) > + return dev_err_probe(dwmac->dev, err, "error setting phy mode\n"); > + > + return 0; > +} > + > static int starfive_dwmac_probe(struct platform_device *pdev) > { > struct plat_stmmacenet_data *plat_dat; > @@ -91,6 +135,10 @@ static int starfive_dwmac_probe(struct platform_device *pdev) > plat_dat->bsp_priv = dwmac; > plat_dat->dma_cfg->dche = true; > > + err = starfive_dwmac_set_mode(plat_dat); > + if (err) > + return err; > + > err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); > if (err) { > stmmac_remove_config_dt(pdev, plat_dat); > -- > 2.17.1 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [-net-next v11 6/6] net: stmmac: starfive-dmac: Add phy interface settings From: Emil Renner Berthing <emil.renner.berthing@canonical.com> to: Samin Guo <samin.guo@starfivetech.com> data: 2023/4/8 > Hi Samin, > > If you're respinning this series anyway, please use "net: stmmac: > dwmac-starfive:" to match the filename. > Thanks, will fix. > On Fri, 7 Apr 2023 at 13:05, Samin Guo <samin.guo@starfivetech.com> wrote: >> >> 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 <tomm.merciai@gmail.com> >> Signed-off-by: Samin Guo <samin.guo@starfivetech.com> >> --- >> .../ethernet/stmicro/stmmac/dwmac-starfive.c | 48 +++++++++++++++++++ >> 1 file changed, 48 insertions(+) >> >> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c >> index 4963d4008485..d6a1eddb51e8 100644 >> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c >> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c >> @@ -13,6 +13,10 @@ >> >> #include "stmmac_platform.h" >> >> +#define STARFIVE_DWMAC_PHY_INFT_RGMII 0x1 >> +#define STARFIVE_DWMAC_PHY_INFT_RMII 0x4 >> +#define STARFIVE_DWMAC_PHY_INFT_FIELD 0x7U >> + >> struct starfive_dwmac { >> struct device *dev; >> struct clk *clk_tx; >> @@ -46,6 +50,46 @@ static void starfive_dwmac_fix_mac_speed(void *priv, unsigned int speed) >> dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate); >> } >> >> +static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat) >> +{ >> + struct starfive_dwmac *dwmac = plat_dat->bsp_priv; >> + struct regmap *regmap; >> + unsigned int args[2]; >> + unsigned int mode; >> + int err; >> + >> + switch (plat_dat->interface) { >> + case PHY_INTERFACE_MODE_RMII: >> + mode = STARFIVE_DWMAC_PHY_INFT_RMII; >> + break; >> + >> + case PHY_INTERFACE_MODE_RGMII: >> + case PHY_INTERFACE_MODE_RGMII_ID: >> + mode = STARFIVE_DWMAC_PHY_INFT_RGMII; >> + break; >> + >> + default: >> + dev_err(dwmac->dev, "unsupported interface %d\n", >> + plat_dat->interface); >> + return -EINVAL; >> + } >> + >> + regmap = syscon_regmap_lookup_by_phandle_args(dwmac->dev->of_node, >> + "starfive,syscon", >> + 2, args); >> + if (IS_ERR(regmap)) >> + return dev_err_probe(dwmac->dev, PTR_ERR(regmap), "syscon regmap failed\n"); > > This message is a bit misleading. It's not actually that the regmap > failed, but getting/looking up the regmap failed. Will fix. Best regards, Samin > >> + /* args[0]:offset args[1]: shift */ >> + err = regmap_update_bits(regmap, args[0], >> + STARFIVE_DWMAC_PHY_INFT_FIELD << args[1], >> + mode << args[1]); >> + if (err) >> + return dev_err_probe(dwmac->dev, err, "error setting phy mode\n"); >> + >> + return 0; >> +} >> + >> static int starfive_dwmac_probe(struct platform_device *pdev) >> { >> struct plat_stmmacenet_data *plat_dat; >> @@ -91,6 +135,10 @@ static int starfive_dwmac_probe(struct platform_device *pdev) >> plat_dat->bsp_priv = dwmac; >> plat_dat->dma_cfg->dche = true; >> >> + err = starfive_dwmac_set_mode(plat_dat); >> + if (err) >> + return err; >> + >> err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); >> if (err) { >> stmmac_remove_config_dt(pdev, plat_dat); >> -- >> 2.17.1 >> >> >> _______________________________________________ >> linux-riscv mailing list >> linux-riscv@lists.infradead.org >> http://lists.infradead.org/mailman/listinfo/linux-riscv
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c index 4963d4008485..d6a1eddb51e8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c @@ -13,6 +13,10 @@ #include "stmmac_platform.h" +#define STARFIVE_DWMAC_PHY_INFT_RGMII 0x1 +#define STARFIVE_DWMAC_PHY_INFT_RMII 0x4 +#define STARFIVE_DWMAC_PHY_INFT_FIELD 0x7U + struct starfive_dwmac { struct device *dev; struct clk *clk_tx; @@ -46,6 +50,46 @@ static void starfive_dwmac_fix_mac_speed(void *priv, unsigned int speed) dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate); } +static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat) +{ + struct starfive_dwmac *dwmac = plat_dat->bsp_priv; + struct regmap *regmap; + unsigned int args[2]; + unsigned int mode; + int err; + + switch (plat_dat->interface) { + case PHY_INTERFACE_MODE_RMII: + mode = STARFIVE_DWMAC_PHY_INFT_RMII; + break; + + case PHY_INTERFACE_MODE_RGMII: + case PHY_INTERFACE_MODE_RGMII_ID: + mode = STARFIVE_DWMAC_PHY_INFT_RGMII; + break; + + default: + dev_err(dwmac->dev, "unsupported interface %d\n", + plat_dat->interface); + return -EINVAL; + } + + regmap = syscon_regmap_lookup_by_phandle_args(dwmac->dev->of_node, + "starfive,syscon", + 2, args); + if (IS_ERR(regmap)) + return dev_err_probe(dwmac->dev, PTR_ERR(regmap), "syscon regmap failed\n"); + + /* args[0]:offset args[1]: shift */ + err = regmap_update_bits(regmap, args[0], + STARFIVE_DWMAC_PHY_INFT_FIELD << args[1], + mode << args[1]); + if (err) + return dev_err_probe(dwmac->dev, err, "error setting phy mode\n"); + + return 0; +} + static int starfive_dwmac_probe(struct platform_device *pdev) { struct plat_stmmacenet_data *plat_dat; @@ -91,6 +135,10 @@ static int starfive_dwmac_probe(struct platform_device *pdev) plat_dat->bsp_priv = dwmac; plat_dat->dma_cfg->dche = true; + err = starfive_dwmac_set_mode(plat_dat); + if (err) + return err; + err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); if (err) { stmmac_remove_config_dt(pdev, plat_dat);