From patchwork Fri Oct 27 19:00:55 2023 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: 13439069 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 876D218C2E; Fri, 27 Oct 2023 19:09:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gsEOGJ5s" Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A2FEFA; Fri, 27 Oct 2023 12:09:54 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5a7c011e113so19843007b3.1; Fri, 27 Oct 2023 12:09:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698433793; x=1699038593; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5DHal/WfnOt0F/bUzqgVKdReu0rsmHy97KCWbd2FIy4=; b=gsEOGJ5sRfwcn1SMLKcQCvKWn/vA2aAVCWiHW/+bSlKW/ZbzUDXY4GFiMfq3dWZjtR sJyANzBSTT2EuJFL/0lGwduAzcPfcUj/PcNx5MksOYPOv/9TjMAVhgXFBSuPswaBAxFV BU1pmwBpe7uKQBxupgK04u6dIcqR9DS4wVQIuh4vm4RpXMjF/KuqBfW0iaS4Xv8c0a6Y CrpkKfoCPs6YBBg3oLBCjhDa96p4n0Ly3BgZmXaKkDmY56zFAiCwyKGYM0KM69YDWvNP E/9oV0giJOFkg9wPK0dvTqORJLovDyx1jIhYqqXjJ4Fy7uIpO2IzNTrCD/Fme3/+15yp ErHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698433793; x=1699038593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5DHal/WfnOt0F/bUzqgVKdReu0rsmHy97KCWbd2FIy4=; b=vEJ9imthX4CGHK7IoFprMPBTE89W8Oq21HLJZgra2qK7XfefbEWZuWqAPuaorS3uu3 chax9T2WfU5m34NsS/Lbq6Lbc15fMkK+2OFbCKyX7AolvB5FT3IKOsbxujU8tfo+MNB8 9EU9dE89VMu9iXTHRucpnczFf236t8UxpSWBG549MOCPcCMKZkX0PRkFKXkhrDIiGewd fwf5V2u8C3S96Qx/sE8zofgLnvc38x0T/9x9kLCc1L6FgwqBk5cjht3R8VfN0ZlUSv4U 5wxhuMVL73Vo+Bp+IDzHpEhZ3ZawoUhcTTLOn+rUb2mMmFJbPucNXvBcqoHgqaZWs5uR NTcQ== X-Gm-Message-State: AOJu0YzQ+AyarAAs4hSylfG+scUbePDM7eTkN7iDWrXkBq5NvHsBfsxq 2aEj4EgWzAUVerqscwxDkJK3VTn1EMhMrw== X-Google-Smtp-Source: AGHT+IGmCJKCSHLQvZDv3+bYpIGHFwwmGuYO0V4HVvm0U6XgV7xPo3U4MmezZEzezmD4V8fi0j/3uA== X-Received: by 2002:a81:ac22:0:b0:5a7:bbd1:ec1d with SMTP id k34-20020a81ac22000000b005a7bbd1ec1dmr3565642ywh.17.1698433792785; Fri, 27 Oct 2023 12:09:52 -0700 (PDT) Received: from tresc054937.tre-sc.gov.br ([187.94.103.218]) by smtp.gmail.com with ESMTPSA id g190-20020a8152c7000000b0059c8387f673sm958696ywb.51.2023.10.27.12.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 12:09:52 -0700 (PDT) From: Luiz Angelo Daros de Luca 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 , devicetree@vger.kernel.org Subject: [PATCH net-next v2 1/3] dt-bindings: net: dsa: realtek: reset-gpios is not required Date: Fri, 27 Oct 2023 16:00:55 -0300 Message-ID: <20231027190910.27044-2-luizluca@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027190910.27044-1-luizluca@gmail.com> References: <20231027190910.27044-1-luizluca@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The 'reset-gpios' should not be mandatory. although they might be required for some devices if the switch reset was left asserted by a previous driver, such as the bootloader. Signed-off-by: Luiz Angelo Daros de Luca Cc: devicetree@vger.kernel.org Acked-by: Arınç ÜNAL Acked-by: Rob Herring --- Documentation/devicetree/bindings/net/dsa/realtek.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/devicetree/bindings/net/dsa/realtek.yaml b/Documentation/devicetree/bindings/net/dsa/realtek.yaml index cce692f57b08..46e113df77c8 100644 --- a/Documentation/devicetree/bindings/net/dsa/realtek.yaml +++ b/Documentation/devicetree/bindings/net/dsa/realtek.yaml @@ -127,7 +127,6 @@ else: - mdc-gpios - mdio-gpios - mdio - - reset-gpios required: - compatible From patchwork Fri Oct 27 19:00:56 2023 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: 13439070 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8B0A18C2E; Fri, 27 Oct 2023 19:09:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i52M5Ctk" Received: from mail-oi1-x22a.google.com (mail-oi1-x22a.google.com [IPv6:2607:f8b0:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75A25E1; Fri, 27 Oct 2023 12:09:58 -0700 (PDT) Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3b52360cdf0so1463872b6e.2; Fri, 27 Oct 2023 12:09:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698433797; x=1699038597; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oPqEy9jv1wfSRtPqoFs4WQDF0XgSUK8DzG8WnJXocV0=; b=i52M5CtkDcAN2HLiUsr0F5eNvCCH1jFbkv6etwtbuE+JCwsxy9PK9ty6Qytzb6Ioi7 63wwayajhidvszd1RuqYegN89HbaRoNQoS+XQMbpuuvRzYrs3k6PfsJuquJZ5KJqYEnT dBkuXTWufzYxHsqCsaTThcHRroj10IdYCUEl4aIxgNuu87vTATolY2Q/GWlsB3cG9qA2 tBMEXOJFBVyoj/p/viml59yCgueHf8rmYyc0i78YBCf5ODlR1rQnv8INeSwycmnhT1PM 1xMzATZzzpzO1banN5OpXoHrn1f3TW4lgZwBOKHo28cEyGEd70psAMVZSonf00haTN44 Wz5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698433797; x=1699038597; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oPqEy9jv1wfSRtPqoFs4WQDF0XgSUK8DzG8WnJXocV0=; b=ZlcOy9gVJDwKDiSR+Gw1ANcqaExkQXDRvz49RX5zzXQAsO0aNSEYqojhRczLDimUpx RoPiT1JdR8DSKHXs1q9OTkmsnyuzgajr3MIul2zftJetEflIuZQKwaSwl8SevfE/d2e/ a38pP9TYoKaXF+IFTW2a44fAm6Ac1UeMPe9WatZYJeQ1Ikos6qgD5VrCMCkLYaWMjXwh tzUxCQEDrTAZAj6orOsxcOFGW84Lrt0lGdiV8N4HTqOMy+nh0RzrBn6mDwenyNmqBhCI R960ezDgd5vDK1cRxozAORv55xRtGJkGe7uIpmnikazbtoqbcNpDQoUkttWD84ySa9pV YQSA== X-Gm-Message-State: AOJu0YzIOpKXgpB9+tOwPmrPd9HBnJTSbrtcF7ZsMgwYB0FgDS05pYlD lqbOBjwjuirlNJFf6nTLXLU/k9XyO16aKQ== X-Google-Smtp-Source: AGHT+IFdVvEh3Q4QtZj4reidkBZucpEkboPs3FCTlb7ywcKmUjIMx923UhFV5KD3cCXOrgZ2BYk62Q== X-Received: by 2002:a05:6808:2c9:b0:3b2:dd32:2fe9 with SMTP id a9-20020a05680802c900b003b2dd322fe9mr3514384oid.35.1698433796956; Fri, 27 Oct 2023 12:09:56 -0700 (PDT) Received: from tresc054937.tre-sc.gov.br ([187.94.103.218]) by smtp.gmail.com with ESMTPSA id g190-20020a8152c7000000b0059c8387f673sm958696ywb.51.2023.10.27.12.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 12:09:56 -0700 (PDT) From: Luiz Angelo Daros de Luca 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 , devicetree@vger.kernel.org Subject: [PATCH net-next v2 2/3] dt-bindings: net: dsa: realtek: add reset controller Date: Fri, 27 Oct 2023 16:00:56 -0300 Message-ID: <20231027190910.27044-3-luizluca@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027190910.27044-1-luizluca@gmail.com> References: <20231027190910.27044-1-luizluca@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org Realtek switches can use a reset controller instead of reset-gpios. Signed-off-by: Luiz Angelo Daros de Luca Cc: devicetree@vger.kernel.org Acked-by: Arınç ÜNAL --- .../devicetree/bindings/net/dsa/realtek.yaml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/Documentation/devicetree/bindings/net/dsa/realtek.yaml b/Documentation/devicetree/bindings/net/dsa/realtek.yaml index 46e113df77c8..ef7b27c3b1a3 100644 --- a/Documentation/devicetree/bindings/net/dsa/realtek.yaml +++ b/Documentation/devicetree/bindings/net/dsa/realtek.yaml @@ -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: | @@ -385,3 +388,75 @@ examples: }; }; }; + + - | + #include + + platform { + switch { + compatible = "realtek,rtl8365mb"; + mdc-gpios = <&gpio1 16 GPIO_ACTIVE_HIGH>; + mdio-gpios = <&gpio1 17 GPIO_ACTIVE_HIGH>; + + resets = <&rst 8>; + + ethernet-ports { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-port@0 { + reg = <0>; + label = "wan"; + phy-handle = <ðphy-0>; + }; + ethernet-port@1 { + reg = <1>; + label = "lan1"; + phy-handle = <ðphy-1>; + }; + ethernet-port@2 { + reg = <2>; + label = "lan2"; + phy-handle = <ðphy-2>; + }; + ethernet-port@3 { + reg = <3>; + label = "lan3"; + phy-handle = <ðphy-3>; + }; + ethernet-port@4 { + reg = <4>; + label = "lan4"; + phy-handle = <ðphy-4>; + }; + ethernet-port@5 { + reg = <5>; + ethernet = <ð0>; + phy-mode = "rgmii"; + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; + + mdio { + compatible = "realtek,smi-mdio"; + #address-cells = <1>; + #size-cells = <0>; + + ethphy-0: ethernet-phy@0 { + reg = <0>; + }; + ethphy-1: ethernet-phy@1 { + reg = <1>; + }; + ethphy-2: ethernet-phy@2 { + reg = <2>; + }; + ethphy-3: ethernet-phy@3 { + reg = <3>; + }; + }; + }; + }; From patchwork Fri Oct 27 19:00:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 13439071 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81CF13D3AE for ; Fri, 27 Oct 2023 19:10:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nje795Ha" Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 632FFE1 for ; Fri, 27 Oct 2023 12:10:02 -0700 (PDT) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-5a7c7262d5eso18387967b3.1 for ; Fri, 27 Oct 2023 12:10:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698433801; x=1699038601; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PFzNOTKyqREwFnzSabRhKpTozkYFxyw+8i73/F1Vdm0=; b=Nje795HaelETFs3JU9DZUjD26QnIIFqTcX+VGjPFVsqd5jdvvJAbb0FMF6Sv2GHF+w bi1oILXNmxeUhH+dIhFCLp19r0ndK1RhCRkQknocjprqPlvHRKfpb5WmnE4nbpyLSeq5 zn0beS99lripVsGciqrw/V8H0JeNwPnD3uhfJR7TCxyTNPSFXbGX4ZVsK6DvFLTwWo+0 OSxKvt4UFRhkUJ/ermQvHWzOlQn+erZidWgaV9gqQbwKIAxuk6gqurSYae1qi1btetY4 4DSg3eyx6XDpPW105rjLpYfbKHFTWxaOAZNygrvUEsOOMFsIi466eUt5cIo4NgGhKSbI XocQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698433801; x=1699038601; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PFzNOTKyqREwFnzSabRhKpTozkYFxyw+8i73/F1Vdm0=; b=szlRr4WidfplUXZ3vGoT+p9osWSvvX2PAkTJ6a/TT3I0B2WxuOttITZvqUXoqomcus xHtN6Uec+oDuQSjpe2w7FJQZgFeQrS4+71RaQapD6L8SQ+Mu5I5iB9EKCusPMpIS6bI9 6uKYBEF8wyQh8/+OkaXQeVw8QpB7qRSePG4tmW96pSUC6/ENfk28+SRh3b+xZy2fER07 XFErtR0maKW3vkEMvjmN+NR4FHMF85fuKVhYpLc0CnwVBu+aRHL5spXB/1LQq27OW8Yw l3mX6tQhxXEyXHixER9LerDwiGcwC/1ulKec8bUksN4IMrrNCSevca8xUFn1BSlV16JN 5+LA== X-Gm-Message-State: AOJu0YxJBsENF+fOVAKh/Vsa67gA5ffX/xY++Clruy63sAwvD58dKJ7D psBtcpnsfvW5sDyMYjHocV4cZP6LImSYQQ== X-Google-Smtp-Source: AGHT+IGuX1apouIbbqfkrqv89kk25tO2cQ7WHRBcVgRc1CrZgt6Yf75+9Dx+qidOcjOPz74BDxZTKQ== X-Received: by 2002:a81:400c:0:b0:5a7:b8a5:1474 with SMTP id l12-20020a81400c000000b005a7b8a51474mr3521401ywn.22.1698433800757; Fri, 27 Oct 2023 12:10:00 -0700 (PDT) Received: from tresc054937.tre-sc.gov.br ([187.94.103.218]) by smtp.gmail.com with ESMTPSA id g190-20020a8152c7000000b0059c8387f673sm958696ywb.51.2023.10.27.12.09.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 12:10:00 -0700 (PDT) From: Luiz Angelo Daros de Luca 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 Subject: [PATCH net-next v2 3/3] net: dsa: realtek: support reset controller Date: Fri, 27 Oct 2023 16:00:57 -0300 Message-ID: <20231027190910.27044-4-luizluca@gmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231027190910.27044-1-luizluca@gmail.com> References: <20231027190910.27044-1-luizluca@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org 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 --- drivers/net/dsa/realtek/realtek-mdio.c | 51 ++++++++++++++++++++++---- drivers/net/dsa/realtek/realtek-smi.c | 49 ++++++++++++++++++++++--- drivers/net/dsa/realtek/realtek.h | 2 + 3 files changed, 89 insertions(+), 13 deletions(-) diff --git a/drivers/net/dsa/realtek/realtek-mdio.c b/drivers/net/dsa/realtek/realtek-mdio.c index 292e6d087e8b..aad94e49d4c9 100644 --- a/drivers/net/dsa/realtek/realtek-mdio.c +++ b/drivers/net/dsa/realtek/realtek-mdio.c @@ -140,6 +140,40 @@ static const struct regmap_config realtek_mdio_nolock_regmap_config = { .disable_locking = true, }; +static void realtek_mdio_reset_assert(struct realtek_priv *priv) +{ + int ret; + + if (priv->reset_ctl) { + ret = reset_control_assert(priv->reset_ctl); + if (ret) + dev_warn(priv->dev, "Failed to assert the switch reset control. Error: %i", + ret); + + return; + } + + if (priv->reset) + gpiod_set_value(priv->reset, true); +} + +static void realtek_mdio_reset_deassert(struct realtek_priv *priv) +{ + int ret; + + if (priv->reset_ctl) { + ret = reset_control_deassert(priv->reset_ctl); + if (ret) + dev_warn(priv->dev, "Failed to deassert the switch reset control. Error: %i", + ret); + + return; + } + + if (priv->reset) + gpiod_set_value(priv->reset, false); +} + static int realtek_mdio_probe(struct mdio_device *mdiodev) { struct realtek_priv *priv; @@ -194,20 +228,24 @@ static int realtek_mdio_probe(struct mdio_device *mdiodev) dev_set_drvdata(dev, priv); - /* TODO: if power is software controlled, set up any regulators here */ priv->leds_disabled = of_property_read_bool(np, "realtek,disable-leds"); + priv->reset_ctl = devm_reset_control_get_optional(dev, NULL); + if (IS_ERR(priv->reset_ctl)) { + ret = PTR_ERR(priv->reset_ctl); + return dev_err_probe(dev, ret, "failed to get reset control\n"); + } + 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); + if (priv->reset_ctl || priv->reset) { + realtek_mdio_reset_assert(priv); dev_dbg(dev, "asserted RESET\n"); msleep(REALTEK_HW_STOP_DELAY); - gpiod_set_value(priv->reset, 0); + realtek_mdio_reset_deassert(priv); msleep(REALTEK_HW_START_DELAY); dev_dbg(dev, "deasserted RESET\n"); } @@ -246,8 +284,7 @@ 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); + realtek_mdio_reset_assert(priv); } static void realtek_mdio_shutdown(struct mdio_device *mdiodev) diff --git a/drivers/net/dsa/realtek/realtek-smi.c b/drivers/net/dsa/realtek/realtek-smi.c index bfd11591faf4..a99e53b5b662 100644 --- a/drivers/net/dsa/realtek/realtek-smi.c +++ b/drivers/net/dsa/realtek/realtek-smi.c @@ -408,6 +408,40 @@ static int realtek_smi_setup_mdio(struct dsa_switch *ds) return ret; } +static void realtek_smi_reset_assert(struct realtek_priv *priv) +{ + int ret; + + if (priv->reset_ctl) { + ret = reset_control_assert(priv->reset_ctl); + if (ret) + dev_warn(priv->dev, "Failed to assert the switch reset control. Error: %i", + ret); + + return; + } + + if (priv->reset) + gpiod_set_value(priv->reset, true); +} + +static void realtek_smi_reset_deassert(struct realtek_priv *priv) +{ + int ret; + + if (priv->reset_ctl) { + ret = reset_control_deassert(priv->reset_ctl); + if (ret) + dev_warn(priv->dev, "Failed to deassert the switch reset control. Error: %i", + ret); + + return; + } + + if (priv->reset) + gpiod_set_value(priv->reset, false); +} + static int realtek_smi_probe(struct platform_device *pdev) { const struct realtek_variant *var; @@ -457,18 +491,22 @@ static int realtek_smi_probe(struct platform_device *pdev) dev_set_drvdata(dev, priv); spin_lock_init(&priv->lock); - /* 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); + return dev_err_probe(dev, ret, "failed to get reset control\n"); + } 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); + if (priv->reset_ctl || priv->reset) { + realtek_smi_reset_assert(priv); dev_dbg(dev, "asserted RESET\n"); msleep(REALTEK_HW_STOP_DELAY); - gpiod_set_value(priv->reset, 0); + realtek_smi_reset_deassert(priv); msleep(REALTEK_HW_START_DELAY); dev_dbg(dev, "deasserted RESET\n"); } @@ -518,8 +556,7 @@ static void realtek_smi_remove(struct platform_device *pdev) of_node_put(priv->slave_mii_bus->dev.of_node); /* leave the device reset asserted */ - if (priv->reset) - gpiod_set_value(priv->reset, 1); + realtek_smi_reset_assert(priv); } static void realtek_smi_shutdown(struct platform_device *pdev) diff --git a/drivers/net/dsa/realtek/realtek.h b/drivers/net/dsa/realtek/realtek.h index 4fa7c6ba874a..516450837b74 100644 --- a/drivers/net/dsa/realtek/realtek.h +++ b/drivers/net/dsa/realtek/realtek.h @@ -12,6 +12,7 @@ #include #include #include +#include #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;