2bcf17751a61820974dc7e64e43e16010f131b8a
[openwrt/staging/wigyori.git] / target / linux / ipq806x / patches-5.10 / 108-v5.14-net-stmmac-explicitly-deassert-gmac-ahb-reset.patch
1 From e67f325e9cd67562b761e884680c0fec03a6f404 Mon Sep 17 00:00:00 2001
2 From: Matthew Hagan <mnhagan88@gmail.com>
3 Date: Tue, 8 Jun 2021 19:59:06 +0100
4 Subject: net: stmmac: explicitly deassert GMAC_AHB_RESET
5
6 We are currently assuming that GMAC_AHB_RESET will already be deasserted
7 by the bootloader. However if this has not been done, probing of the GMAC
8 will fail. To remedy this we must ensure GMAC_AHB_RESET has been deasserted
9 prior to probing.
10
11 v2 changes:
12 - remove NULL condition check for stmmac_ahb_rst in stmmac_main.c
13 - unwrap dev_err() message in stmmac_main.c
14 - add PTR_ERR() around plat->stmmac_ahb_rst in stmmac_platform.c
15
16 v3 changes:
17 - add error pointer to dev_err() output
18 - add reset_control_assert(stmmac_ahb_rst) in stmmac_dvr_remove
19 - revert PTR_ERR() around plat->stmmac_ahb_rst since this is performed
20 on the returned value of ret by the calling function
21
22 Signed-off-by: Matthew Hagan <mnhagan88@gmail.com>
23 Signed-off-by: David S. Miller <davem@davemloft.net>
24 ---
25 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 5 +++++
26 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 6 ++++++
27 include/linux/stmmac.h | 1 +
28 3 files changed, 12 insertions(+)
29
30 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
31 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
32 @@ -5023,6 +5023,10 @@ int stmmac_dvr_probe(struct device *devi
33 reset_control_reset(priv->plat->stmmac_rst);
34 }
35
36 + ret = reset_control_deassert(priv->plat->stmmac_ahb_rst);
37 + if (ret == -ENOTSUPP)
38 + dev_err(priv->device, "unable to bring out of ahb reset\n");
39 +
40 /* Init MAC and get the capabilities */
41 ret = stmmac_hw_init(priv);
42 if (ret)
43 @@ -5247,6 +5251,7 @@ int stmmac_dvr_remove(struct device *dev
44 phylink_destroy(priv->phylink);
45 if (priv->plat->stmmac_rst)
46 reset_control_assert(priv->plat->stmmac_rst);
47 + reset_control_assert(priv->plat->stmmac_ahb_rst);
48 pm_runtime_put(dev);
49 pm_runtime_disable(dev);
50 if (priv->hw->pcs != STMMAC_PCS_TBI &&
51 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
52 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
53 @@ -617,6 +617,12 @@ stmmac_probe_config_dt(struct platform_d
54 plat->stmmac_rst = NULL;
55 }
56
57 + plat->stmmac_ahb_rst = devm_reset_control_get_optional_shared(
58 + &pdev->dev, "ahb");
59 + if (IS_ERR(plat->stmmac_ahb_rst))
60 + if (PTR_ERR(plat->stmmac_ahb_rst) == -EPROBE_DEFER)
61 + goto error_hw_init;
62 +
63 return plat;
64
65 error_hw_init:
66 --- a/include/linux/stmmac.h
67 +++ b/include/linux/stmmac.h
68 @@ -192,6 +192,7 @@ struct plat_stmmacenet_data {
69 unsigned int clk_ref_rate;
70 s32 ptp_max_adj;
71 struct reset_control *stmmac_rst;
72 + struct reset_control *stmmac_ahb_rst;
73 struct stmmac_axi *axi;
74 int has_gmac4;
75 bool has_sun8i;