[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <670108d3-d8d7-102b-75fc-52e2db8945f2@starfivetech.com>
Date: Mon, 27 Mar 2023 09:29:52 +0800
From: Guo Samin <samin.guo@...rfivetech.com>
To: Emil Renner Berthing <emil.renner.berthing@...onical.com>
CC: <linux-kernel@...r.kernel.org>, <linux-riscv@...ts.infradead.org>,
<devicetree@...r.kernel.org>, <netdev@...r.kernel.org>,
"David S . Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Rob Herring <robh+dt@...nel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@...aro.org>,
Emil Renner Berthing <kernel@...il.dk>,
Jose Abreu <joabreu@...opsys.com>,
Richard Cochran <richardcochran@...il.com>,
Conor Dooley <conor@...nel.org>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Andrew Lunn <andrew@...n.ch>,
Heiner Kallweit <hkallweit1@...il.com>,
Peter Geis <pgwipeout@...il.com>,
Yanhong Wang <yanhong.wang@...rfivetech.com>,
Tommaso Merciai <tomm.merciai@...il.com>
Subject: Re: [PATCH v8 6/6] net: stmmac: starfive_dmac: Add phy interface
settings
Re: [PATCH v8 6/6] net: stmmac: starfive_dmac: Add phy interface settings
From: Emil Renner Berthing <emil.renner.berthing@...onical.com>
to: Samin Guo <samin.guo@...rfivetech.com>
data: 2023/3/24
> On Fri, 24 Mar 2023 at 03:30, Samin Guo <samin.guo@...rfivetech.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@...il.com>
>> Signed-off-by: Samin Guo <samin.guo@...rfivetech.com>
>> ---
>> .../ethernet/stmicro/stmmac/dwmac-starfive.c | 47 +++++++++++++++++++
>> 1 file changed, 47 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c
>> index ef5a769b1c75..84690c8f0250 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;
>> @@ -44,6 +48,43 @@ 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;
>> +
>> + 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)) {
>> + dev_err(dwmac->dev, "syscon regmap failed.\n");
>> + return -ENXIO;
>> + }
>> +
>> + /* args[0]:offset args[1]: shift */
>> + return regmap_update_bits(regmap, args[0],
>> + STARFIVE_DWMAC_PHY_INFT_FIELD << args[1],
>> + mode << args[1]);
>> +}
>> +
>> static int starfive_dwmac_probe(struct platform_device *pdev)
>> {
>> struct plat_stmmacenet_data *plat_dat;
>> @@ -89,6 +130,12 @@ 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) {
>> + dev_err(&pdev->dev, "dwmac set mode failed.\n");
>> + return err;
>> + }
>
> Usually it's better to keep all error messages at the same "level".
> Like this you'll get two error messages if
> syscon_regmap_lookup_by_phandle_args fails. So I'd suggest moving this
> message into the starfive_dwmac_set_mode function and while you're at
> it you can do
>
> err = regmap_update_bits(...);
> if (err)
> return dev_err_probe(dwmac->dev, err, "error setting phy mode\n");
>
> Also the file is called dwmac-starfive.c, so I'd expect the patch
> header to be "net: stmmac: dwmac-starfive: Add phy interface
> settings".
>
> /Emil
>
Thanks, the next version will be optimized.
Best regards,
Samin
>> 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@...ts.infradead.org
>> http://lists.infradead.org/mailman/listinfo/linux-riscv
Powered by blists - more mailing lists