Commit d4beef41 authored by David S. Miller's avatar David S. Miller

Merge branch 'dsa-realtek-reset'

Luiz Angelo Daros de Luca says:

====================
net: dsa: realtek: support reset controller and update docs

The driver previously supported reset pins using GPIO, but it lacked
support for reset controllers. Although a reset method is generally not
required, the driver fails to detect the switch if the reset was kept
asserted by a previous driver.

This series adds support to reset a Realtek switch using a reset
controller. It also updates the binding documentation to remove the
requirement of a reset method and to add the new reset controller
property.

It was tested on a TL-WR1043ND v1 router (rtl8366rb via SMI).
Signed-off-by: default avatarLuiz Angelo Daros de Luca <luizluca@gmail.com>
---
Changes in v5:
- Fixed error checking logic when reset controller (de)assert fails
- Link to v4: https://lore.kernel.org/r/20240219-realtek-reset-v4-0-858b82a29503@gmail.com

Changes in v4:
- do not test for priv->reset,priv->reset_ctl
- updated commit message
- Link to v3: https://lore.kernel.org/r/20240213-realtek-reset-v3-0-37837e574713@gmail.com

Changes in v3:
- Rebased on the Realtek DSA driver refactoring (08f62716)
- Dropped the reset controller example in bindings
- Used %pe in error printing
- Linked to v2: https://lore.kernel.org/r/20231027190910.27044-1-luizluca@gmail.com/

Changes in v2:
- Introduced a dedicated commit for removing the reset-gpios requirement
- Placed binding patches before code changes
- Removed the 'reset-names' property
- Moved the example from the commit message to realtek.yaml
- Split the reset function into _assert/_deassert variants
- Modified reset functions to return a warning instead of a value
- Utilized devm_reset_control_get_optional to prevent failure when the
  reset control is missing
- Used 'true' and 'false' for boolean values
- Removed the CONFIG_RESET_CONTROLLER check as stub methods are
  sufficient when undefined
- Linked to v1: https://lore.kernel.org/r/20231024205805.19314-1-luizluca@gmail.com/
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4440873f 56998aa6
......@@ -59,6 +59,9 @@ properties:
description: GPIO to be used to reset the whole device
maxItems: 1
resets:
maxItems: 1
realtek,disable-leds:
type: boolean
description: |
......@@ -127,7 +130,6 @@ else:
- mdc-gpios
- mdio-gpios
- mdio
- reset-gpios
required:
- compatible
......
......@@ -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 */
......@@ -48,6 +49,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;
......
......@@ -184,6 +184,13 @@ rtl83xx_probe(struct device *dev,
"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");
return ERR_CAST(priv->reset_ctl);
}
priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(priv->reset)) {
dev_err(dev, "failed to get RESET GPIO\n");
......@@ -192,11 +199,11 @@ rtl83xx_probe(struct device *dev,
dev_set_drvdata(dev, priv);
if (priv->reset) {
gpiod_set_value(priv->reset, 1);
if (priv->reset_ctl || priv->reset) {
rtl83xx_reset_assert(priv);
dev_dbg(dev, "asserted RESET\n");
msleep(REALTEK_HW_STOP_DELAY);
gpiod_set_value(priv->reset, 0);
rtl83xx_reset_deassert(priv);
msleep(REALTEK_HW_START_DELAY);
dev_dbg(dev, "deasserted RESET\n");
}
......@@ -292,11 +299,36 @@ EXPORT_SYMBOL_NS_GPL(rtl83xx_shutdown, REALTEK_DSA);
void rtl83xx_remove(struct realtek_priv *priv)
{
/* leave the device reset asserted */
if (priv->reset)
gpiod_set_value(priv->reset, 1);
rtl83xx_reset_assert(priv);
}
EXPORT_SYMBOL_NS_GPL(rtl83xx_remove, REALTEK_DSA);
void rtl83xx_reset_assert(struct realtek_priv *priv)
{
int ret;
ret = reset_control_assert(priv->reset_ctl);
if (ret)
dev_warn(priv->dev,
"Failed to assert the switch reset control: %pe\n",
ERR_PTR(ret));
gpiod_set_value(priv->reset, true);
}
void rtl83xx_reset_deassert(struct realtek_priv *priv)
{
int ret;
ret = reset_control_deassert(priv->reset_ctl);
if (ret)
dev_warn(priv->dev,
"Failed to deassert the switch reset control: %pe\n",
ERR_PTR(ret));
gpiod_set_value(priv->reset, false);
}
MODULE_AUTHOR("Luiz Angelo Daros de Luca <luizluca@gmail.com>");
MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
MODULE_DESCRIPTION("Realtek DSA switches common module");
......
......@@ -18,5 +18,7 @@ int rtl83xx_register_switch(struct realtek_priv *priv);
void rtl83xx_unregister_switch(struct realtek_priv *priv);
void rtl83xx_shutdown(struct realtek_priv *priv);
void rtl83xx_remove(struct realtek_priv *priv);
void rtl83xx_reset_assert(struct realtek_priv *priv);
void rtl83xx_reset_deassert(struct realtek_priv *priv);
#endif /* _RTL83XX_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment