From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
To: netdev@vger.kernel.org
Cc: linus.walleij@linaro.org, alsi@bang-olufsen.dk, andrew@lunn.ch,
vivien.didelot@gmail.com, f.fainelli@gmail.com,
olteanv@gmail.com, davem@davemloft.net, kuba@kernel.org,
pabeni@redhat.com, robh+dt@kernel.org, krzk+dt@kernel.org,
arinc.unal@arinc9.com,
Luiz Angelo Daros de Luca <luizluca@gmail.com>
Subject: [RFC net-next 5/5] net: dsa: realtek: support reset controller
Date: Sat, 11 Nov 2023 18:51:08 -0300 [thread overview]
Message-ID: <20231111215647.4966-6-luizluca@gmail.com> (raw)
In-Reply-To: <20231111215647.4966-1-luizluca@gmail.com>
The 'reset-gpios' will not work when the switch reset is controlled by a
reset controller.
Although the reset is optional and the driver performs a soft reset
during setup, if the initial reset state was asserted, the driver will
not detect it.
The reset controller will take precedence over the reset GPIO.
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
drivers/net/dsa/realtek/realtek-common.c | 53 +++++++++++++++++++++---
drivers/net/dsa/realtek/realtek-common.h | 3 ++
drivers/net/dsa/realtek/realtek.h | 2 +
3 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/drivers/net/dsa/realtek/realtek-common.c b/drivers/net/dsa/realtek/realtek-common.c
index e383db21c776..1450e5c206c3 100644
--- a/drivers/net/dsa/realtek/realtek-common.c
+++ b/drivers/net/dsa/realtek/realtek-common.c
@@ -163,17 +163,25 @@ struct realtek_priv *realtek_common_probe(struct device *dev,
priv->leds_disabled = of_property_read_bool(np, "realtek,disable-leds");
/* TODO: if power is software controlled, set up any regulators here */
+ priv->reset_ctl = devm_reset_control_get_optional(dev, NULL);
+ if (IS_ERR(priv->reset_ctl)) {
+ ret = PTR_ERR(priv->reset_ctl);
+ dev_err_probe(dev, ret, "failed to get reset control\n");
+ goto err_variant_put;
+ }
+
priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(priv->reset)) {
ret = PTR_ERR(priv->reset);
dev_err(dev, "failed to get RESET GPIO\n");
goto err_variant_put;
}
- if (priv->reset) {
- gpiod_set_value(priv->reset, 1);
+
+ if (priv->reset_ctl || priv->reset) {
+ realtek_reset_assert(priv);
dev_dbg(dev, "asserted RESET\n");
msleep(REALTEK_HW_STOP_DELAY);
- gpiod_set_value(priv->reset, 0);
+ realtek_reset_deassert(priv);
msleep(REALTEK_HW_START_DELAY);
dev_dbg(dev, "deasserted RESET\n");
}
@@ -208,11 +216,46 @@ void realtek_common_remove(struct realtek_priv *priv)
realtek_variant_put(priv->variant);
/* leave the device reset asserted */
- if (priv->reset)
- gpiod_set_value(priv->reset, 1);
+ realtek_reset_assert(priv);
}
EXPORT_SYMBOL(realtek_common_remove);
+void realtek_reset_assert(struct realtek_priv *priv)
+{
+ int ret;
+
+ if (priv->reset_ctl) {
+ ret = reset_control_assert(priv->reset_ctl);
+ if (!ret)
+ return;
+
+ dev_warn(priv->dev,
+ "Failed to assert the switch reset control: %pe\n",
+ ERR_PTR(ret));
+ }
+
+ if (priv->reset)
+ gpiod_set_value(priv->reset, true);
+}
+
+void realtek_reset_deassert(struct realtek_priv *priv)
+{
+ int ret;
+
+ if (priv->reset_ctl) {
+ ret = reset_control_deassert(priv->reset_ctl);
+ if (!ret)
+ return;
+
+ dev_warn(priv->dev,
+ "Failed to deassert the switch reset control: %pe\n",
+ ERR_PTR(ret));
+ }
+
+ if (priv->reset)
+ gpiod_set_value(priv->reset, false);
+}
+
const struct of_device_id realtek_common_of_match[] = {
#if IS_ENABLED(CONFIG_NET_DSA_REALTEK_RTL8366RB)
{ .compatible = "realtek,rtl8366rb", .data = REALTEK_RTL8366RB_MODNAME, },
diff --git a/drivers/net/dsa/realtek/realtek-common.h b/drivers/net/dsa/realtek/realtek-common.h
index 089fda2d4fa9..603b4f9891d3 100644
--- a/drivers/net/dsa/realtek/realtek-common.h
+++ b/drivers/net/dsa/realtek/realtek-common.h
@@ -16,4 +16,7 @@ const struct realtek_variant *realtek_variant_get(
const struct of_device_id *match);
void realtek_variant_put(const struct realtek_variant *var);
+void realtek_reset_assert(struct realtek_priv *priv);
+void realtek_reset_deassert(struct realtek_priv *priv);
+
#endif
diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h
index f9bd6678e3bd..86f33327155b 100644
--- a/drivers/net/dsa/realtek/realtek.h
+++ b/drivers/net/dsa/realtek/realtek.h
@@ -12,6 +12,7 @@
#include <linux/platform_device.h>
#include <linux/gpio/consumer.h>
#include <net/dsa.h>
+#include <linux/reset.h>
#define REALTEK_HW_STOP_DELAY 25 /* msecs */
#define REALTEK_HW_START_DELAY 100 /* msecs */
@@ -80,6 +81,7 @@ struct rtl8366_vlan_4k {
struct realtek_priv {
struct device *dev;
+ struct reset_control *reset_ctl;
struct gpio_desc *reset;
struct gpio_desc *mdc;
struct gpio_desc *mdio;
--
2.42.1
prev parent reply other threads:[~2023-11-11 21:57 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-11 21:51 [RFC net-next 0/5] refactor realtek switches and add reset controller Luiz Angelo Daros de Luca
2023-11-11 21:51 ` [RFC net-next 1/5] dt-bindings: net: dsa: realtek: reset-gpios is not required Luiz Angelo Daros de Luca
2023-11-12 7:37 ` Krzysztof Kozlowski
2023-11-13 20:30 ` Luiz Angelo Daros de Luca
2023-11-13 8:31 ` Linus Walleij
2023-11-14 12:23 ` Alvin Šipraga
2023-11-11 21:51 ` [RFC net-next 2/5] dt-bindings: net: dsa: realtek: add reset controller Luiz Angelo Daros de Luca
2023-11-13 8:31 ` Linus Walleij
2023-11-14 12:23 ` Alvin Šipraga
2023-11-16 16:25 ` Rob Herring
2023-11-11 21:51 ` [RFC net-next 3/5] net: dsa: realtek: create realtek-common Luiz Angelo Daros de Luca
2023-11-12 7:39 ` Krzysztof Kozlowski
2023-11-13 8:35 ` Linus Walleij
2023-11-13 20:41 ` Luiz Angelo Daros de Luca
2023-11-13 22:01 ` Alvin Šipraga
2023-11-14 11:43 ` Alvin Šipraga
2023-11-17 23:04 ` Luiz Angelo Daros de Luca
2023-11-11 21:51 ` [RFC net-next 4/5] net: dsa: realtek: load switch variants on demand Luiz Angelo Daros de Luca
2023-11-12 3:54 ` kernel test robot
2023-11-14 12:17 ` Alvin Šipraga
2023-11-17 21:14 ` Luiz Angelo Daros de Luca
2023-11-11 21:51 ` Luiz Angelo Daros de Luca [this message]
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=20231111215647.4966-6-luizluca@gmail.com \
--to=luizluca@gmail.com \
--cc=alsi@bang-olufsen.dk \
--cc=andrew@lunn.ch \
--cc=arinc.unal@arinc9.com \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=netdev@vger.kernel.org \
--cc=olteanv@gmail.com \
--cc=pabeni@redhat.com \
--cc=robh+dt@kernel.org \
--cc=vivien.didelot@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.