Message ID | 20240213-realtek-reset-v3-0-37837e574713@gmail.com |
---|---|
Headers | show |
Series | net: dsa: realtek: support reset controller and update docs | expand |
Hi Luiz, thanks for your patch! On Wed, Feb 14, 2024 at 1:54 AM Luiz Angelo Daros de Luca <luizluca@gmail.com> wrote: > 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> (...) > +void rtl83xx_reset_assert(struct realtek_priv *priv) > +{ > + int ret; > + > + if (priv->reset_ctl) { > + ret = reset_control_assert(priv->reset_ctl); Actually, reset_control_assert() is NULL-tolerand (as well as the stubs) so you can just issue this unconditionally. If priv->reset_ctl is NULL it will just return 0. > + 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); Same here! Also NULL-tolerant. You do not need to check priv->reset. Just issue it. > +void rtl83xx_reset_deassert(struct realtek_priv *priv) Same comments for deassert. With this fixed (the rest looks just fine): Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Yours, Linus Walleij
> Hi Luiz, Hi Linus, > thanks for your patch! I'm glad to help ;-) > On Wed, Feb 14, 2024 at 1:54 AM Luiz Angelo Daros de Luca > <luizluca@gmail.com> wrote: > > > 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> > (...) > > +void rtl83xx_reset_assert(struct realtek_priv *priv) > > +{ > > + int ret; > > + > > + if (priv->reset_ctl) { > > + ret = reset_control_assert(priv->reset_ctl); > > Actually, reset_control_assert() is NULL-tolerand (as well as the > stubs) so you can just issue this unconditionally. If priv->reset_ctl > is NULL it will just return 0. The idea was to avoid gpiod_set_value if the reset_control_assert was configured and worked. However, I don't see a big issue in calling them both as you don't expect both to be configured. I'll remove the "ifs not null" and let both be called. > > > + 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); > > Same here! Also NULL-tolerant. You do not need to check priv->reset. > Just issue it. > > > +void rtl83xx_reset_deassert(struct realtek_priv *priv) > > Same comments for deassert. > > With this fixed (the rest looks just fine): > Reviewed-by: Linus Walleij <linus.walleij@linaro.org> > > Yours, > Linus Walleij
On Wed, Feb 14, 2024 at 07:17:55PM -0300, Luiz Angelo Daros de Luca wrote: > > On Wed, Feb 14, 2024 at 1:54 AM Luiz Angelo Daros de Luca > > <luizluca@gmail.com> wrote: > > > > > 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> > > (...) > > > +void rtl83xx_reset_assert(struct realtek_priv *priv) > > > +{ > > > + int ret; > > > + > > > + if (priv->reset_ctl) { > > > + ret = reset_control_assert(priv->reset_ctl); > > > > Actually, reset_control_assert() is NULL-tolerand (as well as the > > stubs) so you can just issue this unconditionally. If priv->reset_ctl > > is NULL it will just return 0. > > The idea was to avoid gpiod_set_value if the reset_control_assert was > configured and worked. However, I don't see a big issue in calling > them both as you don't expect both to be configured. > I'll remove the "ifs not null" and let both be called. In the defense of Linus' comment, your proposed code did not do what you seem to have intended anyway. If priv->reset_ctl was non-NULL, it fell through and potentially ran gpiod_set_value() anyway - there was no early "return". So, the simplification comment was predictable.
On Wed, Feb 14, 2024 at 07:17:55PM -0300, Luiz Angelo Daros de Luca wrote: > > > The reset controller will take precedence over the reset GPIO. > > I'll remove the "ifs not null" and let both be called. If you do, be sure to update the commit message about it (see first line).
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: Luiz Angelo Daros de Luca <luizluca@gmail.com> --- Changes in v3: - Rebased on the Realtek DSA driver refactoring (08f627164126) - 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/ --- Luiz Angelo Daros de Luca (3): dt-bindings: net: dsa: realtek: reset-gpios is not required dt-bindings: net: dsa: realtek: add reset controller net: dsa: realtek: support reset controller .../devicetree/bindings/net/dsa/realtek.yaml | 4 +- drivers/net/dsa/realtek/realtek.h | 2 + drivers/net/dsa/realtek/rtl83xx.c | 52 +++++++++++++++++++--- drivers/net/dsa/realtek/rtl83xx.h | 2 + 4 files changed, 54 insertions(+), 6 deletions(-) --- base-commit: 0f37666d87d2dea42ec21776c3d562b7cbd71612 change-id: 20240212-realtek-reset-88a0bf25bb22 Best regards,