From patchwork Mon Feb 14 02:20:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 12744753 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6BCBC433F5 for ; Mon, 14 Feb 2022 02:21:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231382AbiBNCVV (ORCPT ); Sun, 13 Feb 2022 21:21:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235444AbiBNCVU (ORCPT ); Sun, 13 Feb 2022 21:21:20 -0500 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56A7F54FA0 for ; Sun, 13 Feb 2022 18:21:13 -0800 (PST) Received: by mail-ot1-x32f.google.com with SMTP id s6-20020a0568301e0600b0059ea5472c98so10674481otr.11 for ; Sun, 13 Feb 2022 18:21:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XHBYJ0FhYYa/VplEQ75FFPvzacvbyVuJcGwPiTu1/s8=; b=nDHrm9dSVRJvyCGqHqL7I31R3t/+V6Zai5XvbUHIw7B5pRIPiC80OmEsvaBOX3AKtf lWkGW40e1NnEUTjE3y17KRdH8oKOfsJcAfDq4J2wxTwRMETP7mzelLsDTaHIIVJRLzW4 A4iDJa+sJYgz4svSR2OTKQ4+ZNQAvZvpp3Hkka5VMFJZen8T3Ap0rHoxYND3hXopSdsW a0D4VHxgi65BOoX9ooi61KF9C+vxoio1oyEiGV36wqTFtb0Q/IhKBduuaudtMKSE1I0c WypbIGvdSnPbYsTa/4OyYzdrSqPHWap5DCUIUr1dpt7VYKrHZAAUQo1m8Xkf3IgfRChn dTaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XHBYJ0FhYYa/VplEQ75FFPvzacvbyVuJcGwPiTu1/s8=; b=WocbvwhjqETOKaa1mkV89F2wrty8kq/3fhDG3fNYsEWPaIguLcwJZ/4qBF0xBqxJfI hWOf2vM8L0UTNmQ/zeDC3z+LEDPgIGMBwkUqcB4/18V5llzbrm0U6ZkPYgF+Yil9gkhc xBPJ1I/CDi/EsTrxuaM7r2gABieOtJM02KnKklkbG+rIrtjaDMj+PeAkNFAfTu0KymGD g8G6zQw/Z4cVjVrAHCVoaJRQXEz34pFKrclg9NB87cOZZFVDYJMmu8wavUgNwSXuczwV M7EbrgTYG3gqFLaD/1iy7LbVpUQO4RliFPL2HzbBMRWutZA7hJgbQknT5OGSEb6VuUMb +4Xw== X-Gm-Message-State: AOAM532mVJbm6ry2kp1ALDpbczQ/gtH/2MdZXgLtSkhmb6dBFvIYPlc0 iAiho1+aMRZHO06WOxMMe0yrYjc5KroN8w== X-Google-Smtp-Source: ABdhPJxdi/Yu5gHZuNnMeUAvyDC6ipg4MkUq1DwnFpypo3o8MiT9Fs1pYy4GYT3MyP6KEK08t4mJVg== X-Received: by 2002:a9d:2781:: with SMTP id c1mr4232273otb.267.1644805270765; Sun, 13 Feb 2022 18:21:10 -0800 (PST) Received: from tresc043793.tre-sc.gov.br (187-049-235-234.floripa.net.br. [187.49.235.234]) by smtp.gmail.com with ESMTPSA id h203sm12321150oif.27.2022.02.13.18.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 18:21:10 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, kuba@kernel.org, alsi@bang-olufsen.dk, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca Subject: [PATCH net-next v3 1/2] net: dsa: realtek: realtek-smi: clean-up reset Date: Sun, 13 Feb 2022 23:20:11 -0300 Message-Id: <20220214022012.14787-2-luizluca@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214022012.14787-1-luizluca@gmail.com> References: <20220214022012.14787-1-luizluca@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When reset GPIO was missing, the driver was still printing an info message and still trying to assert the reset. Although gpiod_set_value() will silently ignore calls with NULL gpio_desc, it is better to make it clear the driver might allow gpio_desc to be NULL. The initial value for the reset pin was changed to GPIOD_OUT_LOW, followed by a gpiod_set_value() asserting the reset. This way, it will be easier to spot if and where the reset really happens. A new "asserted RESET" message was added just after the reset is asserted, similar to the existing "deasserted RESET" message. Both messages were demoted to dbg. The code comment is not needed anymore. Signed-off-by: Luiz Angelo Daros de Luca Acked-by: Arınç ÜNAL --- drivers/net/dsa/realtek/realtek-smi.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 946fbbd70153..33cf5a0692de 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -420,16 +420,19 @@ static int realtek_smi_probe(struct platform_device *pdev) /* TODO: if power is software controlled, set up any regulators here */ - /* Assert then deassert RESET */ - priv->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + 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"); return PTR_ERR(priv->reset); } - msleep(REALTEK_SMI_HW_STOP_DELAY); - gpiod_set_value(priv->reset, 0); - msleep(REALTEK_SMI_HW_START_DELAY); - dev_info(dev, "deasserted RESET\n"); + if (priv->reset) { + gpiod_set_value(priv->reset, 1); + dev_dbg(dev, "asserted RESET\n"); + msleep(REALTEK_SMI_HW_STOP_DELAY); + gpiod_set_value(priv->reset, 0); + msleep(REALTEK_SMI_HW_START_DELAY); + dev_dbg(dev, "deasserted RESET\n"); + } /* Fetch MDIO pins */ priv->mdc = devm_gpiod_get_optional(dev, "mdc", GPIOD_OUT_LOW); @@ -474,7 +477,10 @@ static int realtek_smi_remove(struct platform_device *pdev) dsa_unregister_switch(priv->ds); if (priv->slave_mii_bus) of_node_put(priv->slave_mii_bus->dev.of_node); - gpiod_set_value(priv->reset, 1); + + /* leave the device reset asserted */ + if (priv->reset) + gpiod_set_value(priv->reset, 1); platform_set_drvdata(pdev, NULL); From patchwork Mon Feb 14 02:20:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 12744754 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01153C433F5 for ; Mon, 14 Feb 2022 02:21:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233742AbiBNCV1 (ORCPT ); Sun, 13 Feb 2022 21:21:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238841AbiBNCVX (ORCPT ); Sun, 13 Feb 2022 21:21:23 -0500 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A48D355496 for ; Sun, 13 Feb 2022 18:21:15 -0800 (PST) Received: by mail-oi1-x22c.google.com with SMTP id y23so15960388oia.13 for ; Sun, 13 Feb 2022 18:21:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q4U77wHQmDqUfeCh34vVheVm6z6dQNy1UJnXJPf9w3E=; b=Tu0akXWdXLFlPT5UPHshwxheKD3hcQ7lMU415aKqADGI7lkUH2bjq+ztC8SoYsjIYG AFOj1ANT6jY/wRs/7oLj7tEZtExOrMHr9QLUUeHTYPsa0MIGCDQv0eLmjo+piXJzN1Ml i6nLKGaUDanFbw/5/O+K3328v4XQ2mKupgrYs0sB4KT+3DuDHpbpZ0lSvjJrt18ybezH HOWipSmykSg7dZbJE5Vo+eDM55ufdC03zNRJUHzFlNrsJATqUeb7tPVspdyTHlL0TKM2 M9p8M+NJB+DXgZGyHsKYoxkPeoEhzp9cwinZrwjdkF28GRHYhU8nigpJon17nt1Ki6/6 EqvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q4U77wHQmDqUfeCh34vVheVm6z6dQNy1UJnXJPf9w3E=; b=pc9c+t2aPT89pBAVi8XGFWRcBxKoSt7Dao/R/q4cTZtt7t//52wnHl9iEAEjdkl5i7 w/5vZUzLGLhTLuw3Ar3t5fr5kaJlFu9fUzpakdfiA5OVF+SiklhAMc0Iob/jX+o63AZZ 1r/5tNuLnPlmG22B/Xdb77MEMUG/D3ATM/ALJgP87cL8fzXXRDT/MOsxzE1m7OfpvvuA Zy5umoXiSmdz1/zYlE23XCyaCTI++TeYIE/gpArl8C7/O0KVnKVA/13j15qgyR/W1jyy 8AFgRbRaQVbWIFee5T4F6v0roR6spsy7tDjN3wiVjNBTUEzijuTi1A+LsWJ8/YyMhXJy rsJA== X-Gm-Message-State: AOAM531IsEFx1M+6UnKfpypM5jz0oAMsL3sL6P/8WKQwzIVwFIY6xudj tUvJZpiEQ1SAM1xzOaRS6/8o82tr7EV42A== X-Google-Smtp-Source: ABdhPJxF3W6KWR8o4wJ6jVlH7YZZdyV29BSOZ/1xTQqTrN7lbVmjWVnLUujyEQitU6QeM4/++zFpYw== X-Received: by 2002:a05:6808:e82:: with SMTP id k2mr4710111oil.10.1644805274286; Sun, 13 Feb 2022 18:21:14 -0800 (PST) Received: from tresc043793.tre-sc.gov.br (187-049-235-234.floripa.net.br. [187.49.235.234]) by smtp.gmail.com with ESMTPSA id h203sm12321150oif.27.2022.02.13.18.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Feb 2022 18:21:13 -0800 (PST) From: Luiz Angelo Daros de Luca To: netdev@vger.kernel.org Cc: linus.walleij@linaro.org, andrew@lunn.ch, vivien.didelot@gmail.com, f.fainelli@gmail.com, olteanv@gmail.com, davem@davemloft.net, kuba@kernel.org, alsi@bang-olufsen.dk, arinc.unal@arinc9.com, Luiz Angelo Daros de Luca , Frank Wunderlich Subject: [PATCH net-next v3 2/2] net: dsa: realtek: realtek-mdio: reset before setup Date: Sun, 13 Feb 2022 23:20:12 -0300 Message-Id: <20220214022012.14787-3-luizluca@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214022012.14787-1-luizluca@gmail.com> References: <20220214022012.14787-1-luizluca@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Some devices, like the switch in Banana Pi BPI R64 only starts to answer after a HW reset. It is the same reset code from realtek-smi. Reported-by: Frank Wunderlich Signed-off-by: Luiz Angelo Daros de Luca Tested-by: Frank Wunderlich Reviewed-by: Linus Walleij Reviewed-by: Alvin Šipraga Acked-by: Arınç ÜNAL --- drivers/net/dsa/realtek/realtek-mdio.c | 19 +++++++++++++++++++ drivers/net/dsa/realtek/realtek-smi.c | 6 ++---- drivers/net/dsa/realtek/realtek.h | 3 +++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 0c5f2bdced9d..0308be95d00a 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -152,6 +152,21 @@ static int realtek_mdio_probe(struct mdio_device *mdiodev) /* TODO: if power is software controlled, set up any regulators here */ priv->leds_disabled = of_property_read_bool(np, "realtek,disable-leds"); + 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"); + return PTR_ERR(priv->reset); + } + + if (priv->reset) { + gpiod_set_value(priv->reset, 1); + dev_dbg(dev, "asserted RESET\n"); + msleep(REALTEK_HW_STOP_DELAY); + gpiod_set_value(priv->reset, 0); + msleep(REALTEK_HW_START_DELAY); + dev_dbg(dev, "deasserted RESET\n"); + } + ret = priv->ops->detect(priv); if (ret) { dev_err(dev, "unable to detect switch\n"); @@ -185,6 +200,10 @@ static void realtek_mdio_remove(struct mdio_device *mdiodev) dsa_unregister_switch(priv->ds); + /* leave the device reset asserted */ + if (priv->reset) + gpiod_set_value(priv->reset, 1); + dev_set_drvdata(&mdiodev->dev, NULL); } diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index 33cf5a0692de..8806b74bd7a8 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -43,8 +43,6 @@ #include "realtek.h" #define REALTEK_SMI_ACK_RETRY_COUNT 5 -#define REALTEK_SMI_HW_STOP_DELAY 25 /* msecs */ -#define REALTEK_SMI_HW_START_DELAY 100 /* msecs */ static inline void realtek_smi_clk_delay(struct realtek_priv *priv) { @@ -428,9 +426,9 @@ static int realtek_smi_probe(struct platform_device *pdev) if (priv->reset) { gpiod_set_value(priv->reset, 1); dev_dbg(dev, "asserted RESET\n"); - msleep(REALTEK_SMI_HW_STOP_DELAY); + msleep(REALTEK_HW_STOP_DELAY); gpiod_set_value(priv->reset, 0); - msleep(REALTEK_SMI_HW_START_DELAY); + msleep(REALTEK_HW_START_DELAY); dev_dbg(dev, "deasserted RESET\n"); } diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index ed5abf6cb3d6..443cf51cb918 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -13,6 +13,9 @@ #include #include +#define REALTEK_HW_STOP_DELAY 25 /* msecs */ +#define REALTEK_HW_START_DELAY 100 /* msecs */ + struct realtek_ops; struct dentry; struct inode;