kernel: backport b53/bcm_sf2 changes from v5.5
[openwrt/staging/hauke.git] / target / linux / generic / backport-5.4 / 703-v5.5-0003-net-dsa-bcm_sf2-Add-support-for-optional-reset-contr.patch
1 From eee87e4377a4b86dc2eea0ade162b0dc33f40576 Mon Sep 17 00:00:00 2001
2 From: Florian Fainelli <f.fainelli@gmail.com>
3 Date: Mon, 4 Nov 2019 13:51:39 -0800
4 Subject: [PATCH] net: dsa: bcm_sf2: Add support for optional reset controller
5 line
6
7 Grab an optional and exclusive reset controller line for the switch and
8 manage it during probe/remove functions accordingly. For 7278 devices we
9 change bcm_sf2_sw_rst() to use the reset controller line since the
10 WATCHDOG_CTRL register does not reset the switch contrary to stated
11 documentation.
12
13 Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
14 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
16 ---
17 drivers/net/dsa/bcm_sf2.c | 19 +++++++++++++++++++
18 drivers/net/dsa/bcm_sf2.h | 3 +++
19 2 files changed, 22 insertions(+)
20
21 --- a/drivers/net/dsa/bcm_sf2.c
22 +++ b/drivers/net/dsa/bcm_sf2.c
23 @@ -346,6 +346,18 @@ static int bcm_sf2_sw_rst(struct bcm_sf2
24 {
25 unsigned int timeout = 1000;
26 u32 reg;
27 + int ret;
28 +
29 + /* The watchdog reset does not work on 7278, we need to hit the
30 + * "external" reset line through the reset controller.
31 + */
32 + if (priv->type == BCM7278_DEVICE_ID && !IS_ERR(priv->rcdev)) {
33 + ret = reset_control_assert(priv->rcdev);
34 + if (ret)
35 + return ret;
36 +
37 + return reset_control_deassert(priv->rcdev);
38 + }
39
40 reg = core_readl(priv, CORE_WATCHDOG_CTRL);
41 reg |= SOFTWARE_RESET | EN_CHIP_RST | EN_SW_RESET;
42 @@ -1099,6 +1111,11 @@ static int bcm_sf2_sw_probe(struct platf
43 priv->core_reg_align = data->core_reg_align;
44 priv->num_cfp_rules = data->num_cfp_rules;
45
46 + priv->rcdev = devm_reset_control_get_optional_exclusive(&pdev->dev,
47 + "switch");
48 + if (PTR_ERR(priv->rcdev) == -EPROBE_DEFER)
49 + return PTR_ERR(priv->rcdev);
50 +
51 /* Auto-detection using standard registers will not work, so
52 * provide an indication of what kind of device we are for
53 * b53_common to work with
54 @@ -1237,6 +1254,8 @@ static int bcm_sf2_sw_remove(struct plat
55 dsa_unregister_switch(priv->dev->ds);
56 bcm_sf2_cfp_exit(priv->dev->ds);
57 bcm_sf2_mdio_unregister(priv);
58 + if (priv->type == BCM7278_DEVICE_ID && !IS_ERR(priv->rcdev))
59 + reset_control_assert(priv->rcdev);
60
61 return 0;
62 }
63 --- a/drivers/net/dsa/bcm_sf2.h
64 +++ b/drivers/net/dsa/bcm_sf2.h
65 @@ -18,6 +18,7 @@
66 #include <linux/types.h>
67 #include <linux/bitops.h>
68 #include <linux/if_vlan.h>
69 +#include <linux/reset.h>
70
71 #include <net/dsa.h>
72
73 @@ -64,6 +65,8 @@ struct bcm_sf2_priv {
74 void __iomem *fcb;
75 void __iomem *acb;
76
77 + struct reset_control *rcdev;
78 +
79 /* Register offsets indirection tables */
80 u32 type;
81 const u16 *reg_offsets;