From: Samin Guo <samin.guo@starfivetech.com>
To: <linux-riscv@lists.infradead.org>, <netdev@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Emil Renner Berthing <kernel@esmil.dk>,
Richard Cochran <richardcochran@gmail.com>,
Andrew Lunn <andrew@lunn.ch>,
Heiner Kallweit <hkallweit1@gmail.com>,
Peter Geis <pgwipeout@gmail.com>,
Yanhong Wang <yanhong.wang@starfivetech.com>,
Samin Guo <samin.guo@starfivetech.com>
Subject: [PATCH v6 6/8] net: stmmac: starfive_dmac: Add phy interface settings
Date: Mon, 13 Mar 2023 11:46:43 +0800 [thread overview]
Message-ID: <20230313034645.5469-7-samin.guo@starfivetech.com> (raw)
In-Reply-To: <20230313034645.5469-1-samin.guo@starfivetech.com>
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>
Signed-off-by: Samin Guo <samin.guo@starfivetech.com>
Tested-by: Tommaso Merciai <tomm.merciai@gmail.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;
+ }
+
err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
if (err) {
stmmac_remove_config_dt(pdev, plat_dat);
--
2.17.1
next prev parent reply other threads:[~2023-03-13 3:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 3:46 [PATCH v6 0/8] Add Ethernet driver for StarFive JH7110 SoC Samin Guo
2023-03-13 3:46 ` [PATCH v6 1/8] dt-bindings: net: snps,dwmac: Add dwmac-5.20 version Samin Guo
2023-03-13 3:46 ` [PATCH v6 2/8] net: stmmac: platform: Add snps,dwmac-5.20 IP compatible string Samin Guo
2023-03-13 3:46 ` [PATCH v6 3/8] dt-bindings: net: snps,dwmac: Add 'ahb' reset/reset-name Samin Guo
2023-03-13 3:46 ` [PATCH v6 4/8] dt-bindings: net: Add support StarFive dwmac Samin Guo
2023-03-13 3:46 ` [PATCH v6 5/8] net: stmmac: Add glue layer for StarFive JH7110 SoC Samin Guo
2023-03-13 3:46 ` Samin Guo [this message]
2023-03-13 3:46 ` [PATCH v6 7/8] riscv: dts: starfive: jh7110: Add ethernet device nodes Samin Guo
2023-03-13 3:46 ` [PATCH v6 8/8] riscv: dts: starfive: visionfive 2: Add configuration of gmac and phy Samin Guo
2023-03-14 0:33 ` [PATCH v6 0/8] Add Ethernet driver for StarFive JH7110 SoC Jakub Kicinski
2023-03-15 1:31 ` Guo Samin
2023-07-01 21:57 ` Aurelien Jarno
2023-07-04 1:58 ` Guo Samin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230313034645.5469-7-samin.guo@starfivetech.com \
--to=samin.guo@starfivetech.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kernel@esmil.dk \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pgwipeout@gmail.com \
--cc=richardcochran@gmail.com \
--cc=robh+dt@kernel.org \
--cc=yanhong.wang@starfivetech.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).