starfive: add new target for StarFive JH7100/7110 SoC
[openwrt/staging/981213.git] / target / linux / starfive / patches-6.1 / 0045-net-stmmac-dwmac-starfive-Add-phy-interface-settings.patch
1 From 20886cd583e8d569d78ea0e723f98384a61ab54b Mon Sep 17 00:00:00 2001
2 From: Samin Guo <samin.guo@starfivetech.com>
3 Date: Thu, 2 Mar 2023 19:52:37 +0800
4 Subject: [PATCH 045/122] net: stmmac: dwmac-starfive: Add phy interface
5 settings
6
7 dwmac supports multiple modess. When working under rmii and rgmii,
8 you need to set different phy interfaces.
9
10 According to the dwmac document, when working in rmii, it needs to be
11 set to 0x4, and rgmii needs to be set to 0x1.
12
13 The phy interface needs to be set in syscon, the format is as follows:
14 starfive,syscon: <&syscon, offset, shift>
15
16 Tested-by: Tommaso Merciai <tomm.merciai@gmail.com>
17 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
18 Signed-off-by: Samin Guo <samin.guo@starfivetech.com>
19 ---
20 .../ethernet/stmicro/stmmac/dwmac-starfive.c | 48 +++++++++++++++++++
21 1 file changed, 48 insertions(+)
22
23 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c
24 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-starfive.c
25 @@ -13,6 +13,10 @@
26
27 #include "stmmac_platform.h"
28
29 +#define STARFIVE_DWMAC_PHY_INFT_RGMII 0x1
30 +#define STARFIVE_DWMAC_PHY_INFT_RMII 0x4
31 +#define STARFIVE_DWMAC_PHY_INFT_FIELD 0x7U
32 +
33 struct starfive_dwmac {
34 struct device *dev;
35 struct clk *clk_tx;
36 @@ -46,6 +50,46 @@ static void starfive_dwmac_fix_mac_speed
37 dev_err(dwmac->dev, "failed to set tx rate %lu\n", rate);
38 }
39
40 +static int starfive_dwmac_set_mode(struct plat_stmmacenet_data *plat_dat)
41 +{
42 + struct starfive_dwmac *dwmac = plat_dat->bsp_priv;
43 + struct regmap *regmap;
44 + unsigned int args[2];
45 + unsigned int mode;
46 + int err;
47 +
48 + switch (plat_dat->interface) {
49 + case PHY_INTERFACE_MODE_RMII:
50 + mode = STARFIVE_DWMAC_PHY_INFT_RMII;
51 + break;
52 +
53 + case PHY_INTERFACE_MODE_RGMII:
54 + case PHY_INTERFACE_MODE_RGMII_ID:
55 + mode = STARFIVE_DWMAC_PHY_INFT_RGMII;
56 + break;
57 +
58 + default:
59 + dev_err(dwmac->dev, "unsupported interface %d\n",
60 + plat_dat->interface);
61 + return -EINVAL;
62 + }
63 +
64 + regmap = syscon_regmap_lookup_by_phandle_args(dwmac->dev->of_node,
65 + "starfive,syscon",
66 + 2, args);
67 + if (IS_ERR(regmap))
68 + return dev_err_probe(dwmac->dev, PTR_ERR(regmap), "getting the regmap failed\n");
69 +
70 + /* args[0]:offset args[1]: shift */
71 + err = regmap_update_bits(regmap, args[0],
72 + STARFIVE_DWMAC_PHY_INFT_FIELD << args[1],
73 + mode << args[1]);
74 + if (err)
75 + return dev_err_probe(dwmac->dev, err, "error setting phy mode\n");
76 +
77 + return 0;
78 +}
79 +
80 static int starfive_dwmac_probe(struct platform_device *pdev)
81 {
82 struct plat_stmmacenet_data *plat_dat;
83 @@ -91,6 +135,10 @@ static int starfive_dwmac_probe(struct p
84 plat_dat->bsp_priv = dwmac;
85 plat_dat->dma_cfg->dche = true;
86
87 + err = starfive_dwmac_set_mode(plat_dat);
88 + if (err)
89 + return err;
90 +
91 err = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
92 if (err) {
93 stmmac_remove_config_dt(pdev, plat_dat);