1 From 8bca458990dd8c6d001b2fb52063aa18e8ca7444 Mon Sep 17 00:00:00 2001
2 From: Christian 'Ansuel' Marangi <ansuelsmth@gmail.com>
3 Date: Tue, 14 Jun 2022 13:22:28 +0200
4 Subject: [PATCH 2/2] net: ethernet: stmmac: reset force speed bit for ipq806x
6 Some bootloader may set the force speed regs even if the actual
7 interface should use autonegotiation between PCS and PHY.
8 This cause the complete malfuction of the interface.
10 To fix this correctly reset the force speed regs if a fixed-link is not
11 defined in the DTS. With a fixed-link node correctly configure the
12 forced speed regs to handle any misconfiguration by the bootloader.
14 Reported-by: Mark Mentovai <mark@moxienet.com>
15 Co-developed-by: Mark Mentovai <mark@moxienet.com>
16 Signed-off-by: Mark Mentovai <mark@moxienet.com>
17 Signed-off-by: Christian 'Ansuel' Marangi <ansuelsmth@gmail.com>
18 Link: https://lore.kernel.org/r/20220614112228.1998-2-ansuelsmth@gmail.com
19 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
21 .../ethernet/stmicro/stmmac/dwmac-ipq806x.c | 64 +++++++++++++++++++
22 1 file changed, 64 insertions(+)
24 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
25 +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-ipq806x.c
27 #define NSS_COMMON_CLK_DIV_SGMII_100 4
28 #define NSS_COMMON_CLK_DIV_SGMII_10 49
30 +#define QSGMII_PCS_ALL_CH_CTL 0x80
31 +#define QSGMII_PCS_CH_SPEED_FORCE BIT(1)
32 +#define QSGMII_PCS_CH_SPEED_10 0x0
33 +#define QSGMII_PCS_CH_SPEED_100 BIT(2)
34 +#define QSGMII_PCS_CH_SPEED_1000 BIT(3)
35 +#define QSGMII_PCS_CH_SPEED_MASK (QSGMII_PCS_CH_SPEED_FORCE | \
36 + QSGMII_PCS_CH_SPEED_10 | \
37 + QSGMII_PCS_CH_SPEED_100 | \
38 + QSGMII_PCS_CH_SPEED_1000)
39 +#define QSGMII_PCS_CH_SPEED_SHIFT(x) ((x) * 4)
41 #define QSGMII_PCS_CAL_LCKDT_CTL 0x120
42 #define QSGMII_PCS_CAL_LCKDT_CTL_RST BIT(19)
44 @@ -253,6 +264,55 @@ static void ipq806x_gmac_fix_mac_speed(v
45 ipq806x_gmac_set_speed(gmac, speed);
49 +ipq806x_gmac_configure_qsgmii_pcs_speed(struct ipq806x_gmac *gmac)
51 + struct platform_device *pdev = gmac->pdev;
52 + struct device *dev = &pdev->dev;
53 + struct device_node *dn;
58 + /* Some bootloader may apply wrong configuration and cause
59 + * not functioning port. If fixed link is not set,
60 + * reset the force speed bit.
62 + if (!of_phy_is_fixed_link(pdev->dev.of_node))
65 + dn = of_get_child_by_name(pdev->dev.of_node, "fixed-link");
66 + ret = of_property_read_u32(dn, "speed", &link_speed);
69 + dev_err(dev, "found fixed-link node with no speed");
73 + val = QSGMII_PCS_CH_SPEED_FORCE;
75 + switch (link_speed) {
77 + val |= QSGMII_PCS_CH_SPEED_1000;
80 + val |= QSGMII_PCS_CH_SPEED_100;
83 + val |= QSGMII_PCS_CH_SPEED_10;
88 + regmap_update_bits(gmac->qsgmii_csr, QSGMII_PCS_ALL_CH_CTL,
89 + QSGMII_PCS_CH_SPEED_MASK <<
90 + QSGMII_PCS_CH_SPEED_SHIFT(gmac->id),
92 + QSGMII_PCS_CH_SPEED_SHIFT(gmac->id));
97 static const struct soc_device_attribute ipq806x_gmac_soc_v1[] = {
100 @@ -400,6 +460,10 @@ static int ipq806x_gmac_probe(struct pla
101 err = ipq806x_gmac_configure_qsgmii_params(gmac);
103 goto err_remove_config_dt;
105 + err = ipq806x_gmac_configure_qsgmii_pcs_speed(gmac);
107 + goto err_remove_config_dt;
110 plat_dat->has_gmac = true;