From patchwork Mon Jun 22 09:37:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 217416 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4BF8C433E0 for ; Mon, 22 Jun 2020 09:43:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9221B2071A for ; Mon, 22 Jun 2020 09:43:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="A2nZUOgn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728003AbgFVJnV (ORCPT ); Mon, 22 Jun 2020 05:43:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727005AbgFVJlc (ORCPT ); Mon, 22 Jun 2020 05:41:32 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 248F5C061796 for ; Mon, 22 Jun 2020 02:41:32 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id b6so15932524wrs.11 for ; Mon, 22 Jun 2020 02:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cfUc+TkUAgqz9MdoL32AGr8CBlEvrLInm5v62775Pps=; b=A2nZUOgnmx1UP+ORv6aiykQQt+lLSQ1KO7Odnx9nMWmPGWBB/9zwG2qDldAgXJmqFF xP5a4eGOadOLgU5l8x7N7j9+z2XQcTH/rFKkU1WWhZmJmVhXF2hTLLfHyQ5etAtMHKmX GzjJGiUtKBqAj3ZO+9U33Aqe6H7sc3uFms0oEry7uZGxugnSgJBjckjsDuq2/0a7BeEq I4qul8QuxKe+CEztgYEFZDIF1pwVYkuHKS4ZkApg+YQ/TcNclWYBEankibn6cVK3MPY7 ZU+9DUlAqUZCkiO9dP4Q1H37N9frUcXcUiOti5AX0YjukaK8I91Rvini9mJsIrmoYDWK Og9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cfUc+TkUAgqz9MdoL32AGr8CBlEvrLInm5v62775Pps=; b=oYNTzd6X3YZZ0BDStFbEg/X1z+ROKABZ0r2AoyqyNn57vFekt5S6/XP+u6X2PizpeY avdLKkyB6wNJPYqwacN1z1dNbnHqmYKJ47dHuThgRhyKBZbxFCU7WWGC+DDmDSSDde+z as3UkH+5G0qxo64VQrdFJFrPrZMskikt+WKAW4TiTp9mRtMpRcHJqG50fUIsy7stdI25 U00FG/VxkITR2Dl+dMT6Mjf0KGbLCIPE7jdsl6uQNncGzyPqb+rQqE/6SxgTKjCr02FU /dHNdmvdgO+zCqRBaQUsdCscUi+68lY/mfyi1rSa+Wo57EluDb98Vpsmz5cyONu1vge/ oqIA== X-Gm-Message-State: AOAM5312U8VDKFQaBcDFJF6cPpcL1rxrTEDeMv3rtfsOlqWmxg1G2+SE Q8+sUJ5qJKoc8YwodMlQ+GaJTg== X-Google-Smtp-Source: ABdhPJzkmYuQpu0uNoygH8mU35nl1Z6nB3WJ2gtz2NCWG24AiJQNaa6UhDtUjU6DEUC2R04sQUctyQ== X-Received: by 2002:a5d:470a:: with SMTP id y10mr5777035wrq.405.1592818890889; Mon, 22 Jun 2020 02:41:30 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:30 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 05/15] net: phy: reset the PHY even if probe() is not implemented Date: Mon, 22 Jun 2020 11:37:34 +0200 Message-Id: <20200622093744.13685-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bartosz Golaszewski Currently we only call phy_device_reset() if the PHY driver implements the probe() callback. This is not mandatory and many drivers (e.g. realtek) don't need probe() for most devices but still can have reset GPIOs defined. There's no reason to depend on the presence of probe() here so pull the reset code out of the if clause. Signed-off-by: Bartosz Golaszewski --- drivers/net/phy/phy_device.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 1b4df12c70ad..f6985db08340 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2690,16 +2690,13 @@ static int phy_probe(struct device *dev) mutex_lock(&phydev->lock); - if (phydev->drv->probe) { - /* Deassert the reset signal */ - phy_device_reset(phydev, 0); + /* Deassert the reset signal */ + phy_device_reset(phydev, 0); + if (phydev->drv->probe) { err = phydev->drv->probe(phydev); - if (err) { - /* Assert the reset signal */ - phy_device_reset(phydev, 1); + if (err) goto out; - } } /* Start out supporting everything. Eventually, @@ -2761,6 +2758,10 @@ static int phy_probe(struct device *dev) phydev->state = PHY_READY; out: + /* Assert the reset signal */ + if (err) + phy_device_reset(phydev, 1); + mutex_unlock(&phydev->lock); return err; @@ -2779,12 +2780,12 @@ static int phy_remove(struct device *dev) sfp_bus_del_upstream(phydev->sfp_bus); phydev->sfp_bus = NULL; - if (phydev->drv && phydev->drv->remove) { + if (phydev->drv && phydev->drv->remove) phydev->drv->remove(phydev); - /* Assert the reset signal */ - phy_device_reset(phydev, 1); - } + /* Assert the reset signal */ + phy_device_reset(phydev, 1); + phydev->drv = NULL; return 0; From patchwork Mon Jun 22 09:37:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 217417 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01983C433E1 for ; Mon, 22 Jun 2020 09:43:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D666420732 for ; Mon, 22 Jun 2020 09:43:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="swtzTFmL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727992AbgFVJnK (ORCPT ); Mon, 22 Jun 2020 05:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727072AbgFVJlf (ORCPT ); Mon, 22 Jun 2020 05:41:35 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E278DC061794 for ; Mon, 22 Jun 2020 02:41:33 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id g18so6882241wrm.2 for ; Mon, 22 Jun 2020 02:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nC0F5ZT+Ll5OOGkPAd3mIJIStND0frPBkptlTCmDLJg=; b=swtzTFmLVIWLX97Ka8BE4T1dWXPt5l1jiTgEty4wbnCrweWQw3HbeTXNza6y2qcCXR iIu5WIxWbsQs51WOv19l2MOnnx9biFYV7/MbY0YMlQ/cSE0G+PyDXwmHvUYyHhrnNdUq xAHqSoVXMheRLlPuN1KpgliIQIXbuBOHq+PCzME+TGn0K+/URvl99z5NPSrgSbWHtdpH 2XLpBaTp7Jhs4GFXZGq+gopioO0XNjhy5k4P+p0oSTll4HgmIBiAnRFMRF6aTZi4O2og vYAAkHtdQXctioWsdumoNSuMfzhqraPeWT6gTazq92hFSwkJkMSYyr7hlCsjXk1eVqPx 7WHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nC0F5ZT+Ll5OOGkPAd3mIJIStND0frPBkptlTCmDLJg=; b=QLlnuBlXIJmRNTcLajjTGmrYkDy62esvj5GLfzgU5f+zI+PoyqeP5db2C6q/oAcrtn 3rcqa//uSBCA9nNYFGU6zyuYH7IRGkdY1gE8cwsyT1oHOI8GWJ+9v8GmB6krKsqqb0hm V2RHCdPxZri1QxXEFDhZ7AMw8y6cpNFMpo6nHS/xzKC88DmdA8UGJ0MNAwFjci15bJYI 9ZY8V3c9O3Rh8NBNc5ztMO8SuhUnOAAw1TXdrv95hKLWj+wJewAF61x+Cb8xBj9RSgyz 4pN3qmJce+swde/Rmw1ek6tBUnKtvavw8fOwZPaqWqbf4vq0v1gQI9Bp6YgqGJx2/zGA V4WA== X-Gm-Message-State: AOAM531YczwgXHMoQRueW7M4QhtKcQ44xXX5d4ANVmk1tgcP7B3E4FYd P4R+anCqTkpjNc2ioc9Ufvj2Ug== X-Google-Smtp-Source: ABdhPJzxHCym+Ub6CuSXGJUTfH6gp7OLN1NQWcaww2Sg2sQLihShVVzipPqZpx45p1tV4dBze4Q9ew== X-Received: by 2002:a5d:6802:: with SMTP id w2mr18207943wru.68.1592818892680; Mon, 22 Jun 2020 02:41:32 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:32 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 06/15] net: phy: mdio: reset MDIO devices even if probe() is not implemented Date: Mon, 22 Jun 2020 11:37:35 +0200 Message-Id: <20200622093744.13685-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bartosz Golaszewski Similarily to PHY drivers - there's no reason to require probe() to be implemented in order to call mdio_device_reset(). MDIO devices can have resets defined without needing to do anything in probe(). Signed-off-by: Bartosz Golaszewski --- drivers/net/phy/mdio_device.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c index f60443e48622..be615504b829 100644 --- a/drivers/net/phy/mdio_device.c +++ b/drivers/net/phy/mdio_device.c @@ -150,10 +150,10 @@ static int mdio_probe(struct device *dev) struct mdio_driver *mdiodrv = to_mdio_driver(drv); int err = 0; - if (mdiodrv->probe) { - /* Deassert the reset signal */ - mdio_device_reset(mdiodev, 0); + /* Deassert the reset signal */ + mdio_device_reset(mdiodev, 0); + if (mdiodrv->probe) { err = mdiodrv->probe(mdiodev); if (err) { /* Assert the reset signal */ @@ -170,12 +170,11 @@ static int mdio_remove(struct device *dev) struct device_driver *drv = mdiodev->dev.driver; struct mdio_driver *mdiodrv = to_mdio_driver(drv); - if (mdiodrv->remove) { + if (mdiodrv->remove) mdiodrv->remove(mdiodev); - /* Assert the reset signal */ - mdio_device_reset(mdiodev, 1); - } + /* Assert the reset signal */ + mdio_device_reset(mdiodev, 1); return 0; } From patchwork Mon Jun 22 09:37:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 217418 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47201C433E0 for ; Mon, 22 Jun 2020 09:43:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1B4B720732 for ; Mon, 22 Jun 2020 09:43:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="A0YsIPLN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727983AbgFVJnA (ORCPT ); Mon, 22 Jun 2020 05:43:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727086AbgFVJlg (ORCPT ); Mon, 22 Jun 2020 05:41:36 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7F59C061798 for ; Mon, 22 Jun 2020 02:41:35 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id l11so15971662wru.0 for ; Mon, 22 Jun 2020 02:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GfxRtzTQEG/5B2vcAI0+WR3x7R55kmvGCSrvKLTEK2Q=; b=A0YsIPLNyYjq0ssEvXKicqSfckLBHv0GVryALC9d+AV98+m0KCKKpxY0AwyeTaC/SV 4ewNSwSYjUQsP4yxHm8UWF9gryWmZ5NreLHL6eNRWjMmIjJRCWiNutTjs4Dj5nQbR/al xKYExJnhmZzF3ijNBmLN0+9cPyr9XfVrG4iIqj5hbRDxQ5onbhon50y62e0SSGhWhkuw rmocxlBQDpuSpCL4KghX633TaDScTSjnEqyd5R5g43WJlC81zN4EIN3Bn8mQId8I8MeF 8+2wsc96b1npN8idQoXobDeawhU/GfrNBYEANPkdYosOat1y3XLGX18/UsW4P4z0HqDS YNGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GfxRtzTQEG/5B2vcAI0+WR3x7R55kmvGCSrvKLTEK2Q=; b=h9FYAUCffR1sWq0Az9jRy8gT7eekkJs41xy5v/kQLKUwYEz4lciUrRZQmUbSK832bQ 2FV3NzliCpz6ngQrWc4/tOo/VrW2NJPpKcixIs9V2pcdfUWkEo1nbxmCyveq1E28SFiy oxrSn4L/U+3HijBHbKS5U0pgnsF4V5WI+Ytt6lJ1ADrUkPIuA7yehtsgmXHqQkgQlGTF t0Jxq/V05aaSPRGDHqKOJZ7z89JJBRf6/Gn/mpKCyNy4YhYEWeDVRZEhbIfTeMraRGcA 79tyvNjnCW1/E8FNBkv77sR2ovqL0bnVVIk2l56SruqPO1D4qH5VT1aTfmPAhzggTnvr HM+Q== X-Gm-Message-State: AOAM531ma7Z27U10rGc6+7Q03fqZivMJxUrQ9060eBB5Id7dIqwUeiH4 DbmgjS5HGwpYsrG2HE1nwh2oSQ== X-Google-Smtp-Source: ABdhPJwe0PlqLfQqK/nfnfTmRDAPWRDDBJzvm26MZsgDYSHOQIM+GwOvMWfHdMQjezh7QNqFssNhEA== X-Received: by 2002:a5d:4bd2:: with SMTP id l18mr400661wrt.119.1592818894547; Mon, 22 Jun 2020 02:41:34 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:34 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 07/15] net: phy: split out the PHY driver request out of phy_device_create() Date: Mon, 22 Jun 2020 11:37:36 +0200 Message-Id: <20200622093744.13685-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bartosz Golaszewski Move the code requesting the PHY driver module out of phy_device_create() into a separate helper. This will be later reused when we delay the module loading. Signed-off-by: Bartosz Golaszewski --- drivers/net/phy/phy_device.c | 71 ++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index f6985db08340..8037a9663a85 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -558,7 +558,7 @@ static const struct device_type mdio_bus_phy_type = { .pm = MDIO_BUS_PHY_PM_OPS, }; -static int phy_request_driver_module(struct phy_device *dev, u32 phy_id) +static int phy_do_request_driver_module(struct phy_device *dev, u32 phy_id) { int ret; @@ -578,6 +578,40 @@ static int phy_request_driver_module(struct phy_device *dev, u32 phy_id) return 0; } +static int phy_request_driver_module(struct phy_device *phydev) +{ + int ret; + + /* Request the appropriate module unconditionally; don't + * bother trying to do so only if it isn't already loaded, + * because that gets complicated. A hotplug event would have + * done an unconditional modprobe anyway. + * We don't do normal hotplug because it won't work for MDIO + * -- because it relies on the device staying around for long + * enough for the driver to get loaded. With MDIO, the NIC + * driver will get bored and give up as soon as it finds that + * there's no driver _already_ loaded. + */ + if (phydev->is_c45) { + const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids); + int i; + + for (i = 1; i < num_ids; i++) { + if (phydev->c45_ids.device_ids[i] == 0xffffffff) + continue; + + ret = phy_do_request_driver_module(phydev, + phydev->c45_ids.device_ids[i]); + if (ret) + break; + } + } else { + ret = phy_do_request_driver_module(phydev, phydev->phy_id); + } + + return ret; +} + struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, bool is_c45, struct phy_c45_device_ids *c45_ids) @@ -622,38 +656,11 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, mutex_init(&dev->lock); INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); + device_initialize(&mdiodev->dev); - /* Request the appropriate module unconditionally; don't - * bother trying to do so only if it isn't already loaded, - * because that gets complicated. A hotplug event would have - * done an unconditional modprobe anyway. - * We don't do normal hotplug because it won't work for MDIO - * -- because it relies on the device staying around for long - * enough for the driver to get loaded. With MDIO, the NIC - * driver will get bored and give up as soon as it finds that - * there's no driver _already_ loaded. - */ - if (is_c45 && c45_ids) { - const int num_ids = ARRAY_SIZE(c45_ids->device_ids); - int i; - - for (i = 1; i < num_ids; i++) { - if (c45_ids->device_ids[i] == 0xffffffff) - continue; - - ret = phy_request_driver_module(dev, - c45_ids->device_ids[i]); - if (ret) - break; - } - } else { - ret = phy_request_driver_module(dev, phy_id); - } - - if (!ret) { - device_initialize(&mdiodev->dev); - } else { - kfree(dev); + ret = phy_request_driver_module(dev); + if (ret) { + phy_device_free(dev); dev = ERR_PTR(ret); } From patchwork Mon Jun 22 09:37:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 217419 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DBB4C433E0 for ; Mon, 22 Jun 2020 09:42:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AF6F2071A for ; Mon, 22 Jun 2020 09:42:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="UtNEe+Y7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727953AbgFVJmr (ORCPT ); Mon, 22 Jun 2020 05:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727102AbgFVJlh (ORCPT ); Mon, 22 Jun 2020 05:41:37 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F849C061795 for ; Mon, 22 Jun 2020 02:41:37 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id b6so15932835wrs.11 for ; Mon, 22 Jun 2020 02:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yy6XgmLu+rdPXztYG22qHG3UQylFLO0aZanRZZZSG+U=; b=UtNEe+Y7D5ArH7Qe/vs7TUd5yHPcILffWoYh4wTCQdtMBq36DtKsydxvi6z3a7HbGS FB2blBliY4Y+cVZyVIBbNCz/TMBZbmhI+WrSDUrAZc+nT9RqNVT9ahaolMbn+oxd3MXf 1G7L1Tcb6rs72hInUAFR8sZDDUZyVq9WQ8aEF0wR9UhVHcEeuUBRsA99mkWAfVG8D7Fm zKsJUFL1xKBJ0gZxZlQvxrVGukdEa54zY4pSR0TYGGrqagLXr4OzxpZFMV8ttxXXVHQU uiUpPpCNqmeepGbSEiBWxIRbMBVFfKFJKOIFmK8bRZsbBYVxA3/rlPTyqTaIaGU38MYj ac8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yy6XgmLu+rdPXztYG22qHG3UQylFLO0aZanRZZZSG+U=; b=WrOW08t40W8f+SbsDgZhEDJv/kGTf6+Brvv+FbEu6slj8GprBvdbf6LVga5RWxi2N3 6CDdBtKBt6pa/t+6O6u+MAZn1iYzHqlgy1uThTGwUg9OMf1VNHqlClrFzQajzM5q8Cuk PlQNGe0bDDlPMf5JOQxtn1zcflCS4LG5GWuWzZtfcWX34ck4o8Q4alw9KHDNCQi9QhhD 0uUDias9+UAfId2MI6uXXk+aL8PK436dYBr++ghYTZDyflUBNddNB7og/SvV0UlJxZXi tIvxRhbe9QAC3G0g+S6N74cFtr5NHMcrtYNcmuxK7brHHm8qDPfpXbgAm3fZl30pY8+W bjzA== X-Gm-Message-State: AOAM5304//9YyHjIM3sCXPiY+iZE9q5PcDMfVNfQ0LlSYqhooSlZg6tk maLp56HLc0Ul4HGIJyZAFuXZbA== X-Google-Smtp-Source: ABdhPJyFGfPZiEZAaPA05Oy9u/8YECmNenqKkrnMxPg4aIkaLDansk5+kyg8mkF5tPJf9KrUB0gUSQ== X-Received: by 2002:a5d:6987:: with SMTP id g7mr17998302wru.79.1592818896247; Mon, 22 Jun 2020 02:41:36 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:35 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 08/15] net: phy: check the PHY presence in get_phy_id() Date: Mon, 22 Jun 2020 11:37:37 +0200 Message-Id: <20200622093744.13685-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bartosz Golaszewski get_phy_id() is only called from get_phy_device() so the check for the 0x1fffffff value can be pulled into the former. This way it'll be easier to remove get_phy_device() later on. Signed-off-by: Bartosz Golaszewski --- drivers/net/phy/phy_device.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 8037a9663a85..eccbf6aea63d 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -806,6 +806,10 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id, *phy_id |= phy_reg; + /* If the phy_id is mostly Fs, there is no device there */ + if ((*phy_id & 0x1fffffff) == 0x1fffffff) + return -ENODEV; + return 0; } @@ -832,10 +836,6 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) if (r) return ERR_PTR(r); - /* If the phy_id is mostly Fs, there is no device there */ - if ((phy_id & 0x1fffffff) == 0x1fffffff) - return ERR_PTR(-ENODEV); - return phy_device_create(bus, addr, phy_id, is_c45, &c45_ids); } EXPORT_SYMBOL(get_phy_device); From patchwork Mon Jun 22 09:37:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 217420 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0848C433DF for ; Mon, 22 Jun 2020 09:42:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 995B020739 for ; Mon, 22 Jun 2020 09:42:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="16VBF2La" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727942AbgFVJmh (ORCPT ); Mon, 22 Jun 2020 05:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727111AbgFVJlk (ORCPT ); Mon, 22 Jun 2020 05:41:40 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B717C061799 for ; Mon, 22 Jun 2020 02:41:39 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id q5so3552954wru.6 for ; Mon, 22 Jun 2020 02:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iUydfUf825zuTrP/3rZhTozCzOm5XJhrM7EVYTY3Zy4=; b=16VBF2LawpzpJUoGplW1VMeRQBY+6kIReg/qh3Of8JJozgK7KV3a/y36LFnx7JJaGG +hsOoIVXR9n9Bwou+9lQTjVGf6VkErBZk56xecuHPO9LNdA3N6A87+7oJpGaJZr91+Ep BI6yveOiwM810Bvvg/LZCi0sL3+aPo8rBLYFEgvj1FYJqgvMM+hLxuy3zExLOJZWyH7g i9vpiSlC5Y0qhPNWicv+/56I51GI/LMpey2/OgWMvENvikCSExdgLe04MjH5nquwHbgt vxVipAPH8T2Nok3B4y9B9ucBQNKyRuG9bYn8DcPmhCNY+VwarjwpEe+1IYtpzERMpzWD 8lyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iUydfUf825zuTrP/3rZhTozCzOm5XJhrM7EVYTY3Zy4=; b=QYzEtVC4TvNdxWuq3/9ZeEP31Rem34+OkW3a5Y3acUgCgILB6N68XVrz06qq6wBURu 5i6nVb2vF9SNZS44+T7lU1Rf4wMASjMeOTE0MU8qX30PkWAd4bbZrTLZSdscuXO3TK+q UyfQsperegOaY9N6Kku89aKN4r8OtjKy4L5ZUnHEBxDiyvo8bL9AZXAtFZdahPo8+k6o hSI50oopFR+ULugsthbnKNXIKBnuJPOWrSvjuqYKmuygQlOs8z0xfTy5H/ueNGMw2gmM 7zEWWPHYChTMgwzWUEsRLduz2VoUt57XiO6sjtxMHkaNFc2Jf9tSQ1t9+mhtKmCzImCI NTcw== X-Gm-Message-State: AOAM533AdKY1EgDbNaSdXAdVowKJ4Ue3pBmUMxstOuqFVDuRgheCzhwN UIKVaJtnyZb/g1s1BPmss58sZFnp3gg= X-Google-Smtp-Source: ABdhPJw/YDc8BRLdz6R7EQpjrH3iix+fo/75QLcqChmbsRSUxGbc0J2kOfOhJKAo3W+XevgouG/a8A== X-Received: by 2002:adf:8168:: with SMTP id 95mr17445453wrm.104.1592818898066; Mon, 22 Jun 2020 02:41:38 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:37 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 09/15] net: phy: delay PHY driver probe until PHY registration Date: Mon, 22 Jun 2020 11:37:38 +0200 Message-Id: <20200622093744.13685-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bartosz Golaszewski Currently the PHY ID is read without taking the PHY out of reset. This can only work if no resets are defined. This change delays the ID read until we're actually registering the PHY device - this is needed because earlier (when creating the device) we don't have a struct device yet with resets already configured. While we could use the of_ helpers for GPIO and resets, we will be adding PHY regulator support layer on and there are no regulator APIs that work without struct device. This means that phy_device_create() now only instantiates the device but doesn't request the relevant driver. If no phy_id is passed to phy_device_create() (for that we introduce a new define: PHY_ID_NONE) then the ID will be read inside phy_device_register(). Signed-off-by: Bartosz Golaszewski --- drivers/net/phy/phy_device.c | 47 +++++++++++++++++++----------------- include/linux/phy.h | 1 + 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index eccbf6aea63d..94944fffa9bb 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -658,12 +658,6 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); device_initialize(&mdiodev->dev); - ret = phy_request_driver_module(dev); - if (ret) { - phy_device_free(dev); - dev = ERR_PTR(ret); - } - return dev; } EXPORT_SYMBOL(phy_device_create); @@ -813,30 +807,29 @@ static int get_phy_id(struct mii_bus *bus, int addr, u32 *phy_id, return 0; } +static int phy_device_read_id(struct phy_device *phydev) +{ + struct mdio_device *mdiodev = &phydev->mdio; + + phydev->c45_ids.devices_in_package = 0; + memset(phydev->c45_ids.device_ids, 0xff, + sizeof(phydev->c45_ids.device_ids)); + + return get_phy_id(mdiodev->bus, mdiodev->addr, &phydev->phy_id, + phydev->is_c45, &phydev->c45_ids); +} + /** - * get_phy_device - reads the specified PHY device and returns its @phy_device - * struct + * get_phy_device - create a phy_device withoug PHY ID * @bus: the target MII bus * @addr: PHY address on the MII bus * @is_c45: If true the PHY uses the 802.3 clause 45 protocol * - * Description: Reads the ID registers of the PHY at @addr on the - * @bus, then allocates and returns the phy_device to represent it. + * Allocates a new phy_device for @addr on the @bus. */ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) { - struct phy_c45_device_ids c45_ids; - u32 phy_id = 0; - int r; - - c45_ids.devices_in_package = 0; - memset(c45_ids.device_ids, 0xff, sizeof(c45_ids.device_ids)); - - r = get_phy_id(bus, addr, &phy_id, is_c45, &c45_ids); - if (r) - return ERR_PTR(r); - - return phy_device_create(bus, addr, phy_id, is_c45, &c45_ids); + return phy_device_create(bus, addr, PHY_ID_NONE, is_c45, NULL); } EXPORT_SYMBOL(get_phy_device); @@ -855,6 +848,16 @@ int phy_device_register(struct phy_device *phydev) /* Deassert the reset signal */ phy_device_reset(phydev, 0); + if (phydev->phy_id == PHY_ID_NONE) { + err = phy_device_read_id(phydev); + if (err) + goto err_unregister_mdio; + } + + err = phy_request_driver_module(phydev); + if (err) + goto err_unregister_mdio; + /* Run all of the fixups for this PHY */ err = phy_scan_fixups(phydev); if (err) { diff --git a/include/linux/phy.h b/include/linux/phy.h index 8c05d0fb5c00..2a695cd90c7c 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -742,6 +742,7 @@ struct phy_driver { #define PHY_ANY_ID "MATCH ANY PHY" #define PHY_ANY_UID 0xffffffff +#define PHY_ID_NONE 0 #define PHY_ID_MATCH_EXACT(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 0) #define PHY_ID_MATCH_MODEL(id) .phy_id = (id), .phy_id_mask = GENMASK(31, 4) From patchwork Mon Jun 22 09:37:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 217422 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C17E0C433DF for ; Mon, 22 Jun 2020 09:41:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F61C2074D for ; Mon, 22 Jun 2020 09:41:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="fwhLeGUT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727805AbgFVJlt (ORCPT ); Mon, 22 Jun 2020 05:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727781AbgFVJlp (ORCPT ); Mon, 22 Jun 2020 05:41:45 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBEF9C061796 for ; Mon, 22 Jun 2020 02:41:44 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id u26so13127066wmn.1 for ; Mon, 22 Jun 2020 02:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=H6LOSRZxGizpxzfF22Sv14N1k+l2XBln54kSc7WXTbU=; b=fwhLeGUTHzaOn5r0hKFAxOrI/4bP6cRMLAZ9vxuMsWmVTbLCLBfuv2c3zx2K+9WkzC 4510agGDHbhXy4FxLo2y6wSgQ64p20rVWdVPiqvbTzNx3rKJ0wAQIRkSuhTdzUPDyq33 EGJ7dP781SaoA69mOAe2VG//Mj+PraeucVuHaZFWBoluRKQxOPm81fI00ykep20zlmSB RPZYYFefMuTBJhmo6T+gCbA2sk4rO/dFZ8SsuCQmoiiBtm5IHQMXEHE2Tj3zbDGXmqd+ 33R1jARght4O0k5GCattCXLy0yW2yV908NCQr9OgF+g3eygrEUkhQhtDWFMWiBtAcU50 OBog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=H6LOSRZxGizpxzfF22Sv14N1k+l2XBln54kSc7WXTbU=; b=Tlw/MVMfJ/6oKXPmOssTZISVNuNTCpMm/JkxBADrBlS7W0qqxPNEI0+HRmEKsfRtc7 fdIrYNHcBzikQewHlYJqILcmDuMHQ9u+5dniumIoEti5mui9Cu7ieRXuIxAp6BypQDah Jb5E3oAvFV8z4TKlQXfS/2NNBpV/pRtB9hXOzTeeDlFVvk+KjtPu66gugc+QkuY39RVU Hi/senv0AbEG7cWXp9k9/cGJ+yYekt5KXw3WekH5GrqrNDZHN8WJjpb5F+3/Vdd6Xfti nPIWJOlwhEDfhK0HrNYqR+w3hL7d4miEvMu7GeHMBFa5uQbkHlWS8C7e8yHsslPg4dIg GuAg== X-Gm-Message-State: AOAM530NHe4Gzz0KqI+f4V6GnudlkCzpXf/CvrkvMyIjgGFzxzGtv6UQ auVwG1315qgIumsCkdP52zsTkw== X-Google-Smtp-Source: ABdhPJxKaZTzwaRgXjyD3lQOmmZEDuZrxf5WMvWd8aJTlxKoe6V5StaOUPB2OradOOO/ubvV2pVenA== X-Received: by 2002:a1c:1fd1:: with SMTP id f200mr17253456wmf.162.1592818903618; Mon, 22 Jun 2020 02:41:43 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:43 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 12/15] dt-bindings: mdio: add phy-supply property to ethernet phy node Date: Mon, 22 Jun 2020 11:37:41 +0200 Message-Id: <20200622093744.13685-13-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bartosz Golaszewski The phy-supply property is often added to MAC nodes but this is wrong conceptually. These supplies should be part of the PHY node on the MDIO bus. Add phy-supply property at PHY level to mdio.yaml. Signed-off-by: Bartosz Golaszewski --- Documentation/devicetree/bindings/net/mdio.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/net/mdio.yaml b/Documentation/devicetree/bindings/net/mdio.yaml index d6a3bf8550eb..9c10012c2093 100644 --- a/Documentation/devicetree/bindings/net/mdio.yaml +++ b/Documentation/devicetree/bindings/net/mdio.yaml @@ -90,6 +90,10 @@ patternProperties: Delay after the reset was deasserted in microseconds. If this property is missing the delay will be skipped. + phy-supply: + description: + Phandle to the regulator that provides the supply voltage to the PHY. + required: - reg From patchwork Mon Jun 22 09:37:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 217421 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E9DA7C433E0 for ; Mon, 22 Jun 2020 09:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE88B20738 for ; Mon, 22 Jun 2020 09:42:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="rox8r/P9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727846AbgFVJmF (ORCPT ); Mon, 22 Jun 2020 05:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727803AbgFVJls (ORCPT ); Mon, 22 Jun 2020 05:41:48 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A77F2C061798 for ; Mon, 22 Jun 2020 02:41:48 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id r9so14206953wmh.2 for ; Mon, 22 Jun 2020 02:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=39tcT1sImiChTRqBAQCitq8OvfITErWq/Xk+xRkWTtw=; b=rox8r/P9m0M75MrSrW0gaefUbBrzsyQiQQ+nuSUyw7jmgK72RdIrEAET+9NDW80nJV 6NoN3fQgrn8u3TAuYWY9vEZmFhT+PYmy+pixzcxBMoxFYd2WlDCvoisyxCnl9XIvgl4L 2UaUBXGdTuKrvDtQtBHE5L7odP4nDBB7nbDPbFnH6FoanY0lq1FWTQXI+whJq1jJA2hU Ot3SzrgslqAj4dfBjZPmBbOgClucsuSk5FJIDeFu2gEMTSGwLi4/f1DXekQJh5ClPfdx IiB0mjGPZS7Om5sXsEMBsr/HJQuJgLUO0T+W94WaGsZzXwZOeddJTllPhKS2Nil1ZvIb szOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=39tcT1sImiChTRqBAQCitq8OvfITErWq/Xk+xRkWTtw=; b=nPj8bRT1m3um0ZcOl1PfIVaOboaXs6ma8kYAtDpmod1GTIJxlg42i8WNJb7if0lhAU e65nknANHB1zHX7kGE3m4XuDk+g9fAFaVv5jqPcEIChR266rXGL+Lajd/iGU4uXCCAU6 PMLZkXz+eOa1Odpeh2RjOg9QN3c7jqHfwW0pcOzaBqEKy5kFLbODrna82Eq/BZbrFt+B moGghnYeEMe5obbGEbJkNeOVdAvPYBLEcMA1yXG2iHyebYiEXYguFUHO9ePpIjdoCBwT wcceXWAPAkMT0OCoKvOI26qrRsetV9ICsnAwduqo/cVSsokIFB9ZOjn4vsrPmlOhBPKx TaPQ== X-Gm-Message-State: AOAM533xTuTcChDoBXQbX462beD2+duaulQB4Pf9WhJatqiOcTC2xxoi 331R0NaecY8QI2Iv8aH60QI29Q== X-Google-Smtp-Source: ABdhPJxuZnlfHnNwpXMmEqVCYAbLPujZmk1SV/mDkcx4Z73yrAJcet27yegyTxUrUHZ6wyfJf9ZIqA== X-Received: by 2002:a1c:2d54:: with SMTP id t81mr18695221wmt.154.1592818907355; Mon, 22 Jun 2020 02:41:47 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:46 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 14/15] net: phy: add PHY regulator support Date: Mon, 22 Jun 2020 11:37:43 +0200 Message-Id: <20200622093744.13685-15-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Bartosz Golaszewski The MDIO sub-system now supports PHY regulators. Let's reuse the code to extend this support over to the PHY device. Signed-off-by: Bartosz Golaszewski --- drivers/net/phy/phy_device.c | 49 ++++++++++++++++++++++++++++-------- include/linux/phy.h | 10 ++++++++ 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 58923826838b..d755adb748a5 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -827,7 +827,12 @@ int phy_device_register(struct phy_device *phydev) err = mdiobus_register_device(&phydev->mdio); if (err) - return err; + goto err_out; + + /* Enable the PHY regulator */ + err = phy_device_power_on(phydev); + if (err) + goto err_unregister_mdio; /* Deassert the reset signal */ phy_device_reset(phydev, 0); @@ -846,22 +851,25 @@ int phy_device_register(struct phy_device *phydev) err = phy_scan_fixups(phydev); if (err) { phydev_err(phydev, "failed to initialize\n"); - goto out; + goto err_reset; } err = device_add(&phydev->mdio.dev); if (err) { phydev_err(phydev, "failed to add\n"); - goto out; + goto err_reset; } return 0; - out: +err_reset: /* Assert the reset signal */ phy_device_reset(phydev, 1); - + /* Disable the PHY regulator */ + phy_device_power_off(phydev); +err_unregister_mdio: mdiobus_unregister_device(&phydev->mdio); +err_out: return err; } EXPORT_SYMBOL(phy_device_register); @@ -883,6 +891,8 @@ void phy_device_remove(struct phy_device *phydev) /* Assert the reset signal */ phy_device_reset(phydev, 1); + /* Disable the PHY regulator */ + phy_device_power_off(phydev); mdiobus_unregister_device(&phydev->mdio); } @@ -1064,6 +1074,11 @@ int phy_init_hw(struct phy_device *phydev) { int ret = 0; + /* Enable the PHY regulator */ + ret = phy_device_power_on(phydev); + if (ret) + return ret; + /* Deassert the reset signal */ phy_device_reset(phydev, 0); @@ -1644,6 +1659,8 @@ void phy_detach(struct phy_device *phydev) /* Assert the reset signal */ phy_device_reset(phydev, 1); + /* Disable the PHY regulator */ + phy_device_power_off(phydev); } EXPORT_SYMBOL(phy_detach); @@ -2684,13 +2701,18 @@ static int phy_probe(struct device *dev) mutex_lock(&phydev->lock); + /* Enable the PHY regulator */ + err = phy_device_power_on(phydev); + if (err) + goto out; + /* Deassert the reset signal */ phy_device_reset(phydev, 0); if (phydev->drv->probe) { err = phydev->drv->probe(phydev); if (err) - goto out; + goto out_reset; } /* Start out supporting everything. Eventually, @@ -2708,7 +2730,7 @@ static int phy_probe(struct device *dev) } if (err) - goto out; + goto out_reset; if (!linkmode_test_bit(ETHTOOL_LINK_MODE_Autoneg_BIT, phydev->supported)) @@ -2751,11 +2773,16 @@ static int phy_probe(struct device *dev) /* Set the state to READY by default */ phydev->state = PHY_READY; -out: - /* Assert the reset signal */ - if (err) - phy_device_reset(phydev, 1); + mutex_unlock(&phydev->lock); + + return 0; +out_reset: + /* Assert the reset signal */ + phy_device_reset(phydev, 1); + /* Disable the PHY regulator */ + phy_device_power_off(phydev); +out: mutex_unlock(&phydev->lock); return err; diff --git a/include/linux/phy.h b/include/linux/phy.h index 01d24a934ad1..585ce8db32cf 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1291,6 +1291,16 @@ static inline void phy_device_reset(struct phy_device *phydev, int value) mdio_device_reset(&phydev->mdio, value); } +static inline int phy_device_power_on(struct phy_device *phydev) +{ + return mdio_device_power_on(&phydev->mdio); +} + +static inline int phy_device_power_off(struct phy_device *phydev) +{ + return mdio_device_power_off(&phydev->mdio); +} + #define phydev_err(_phydev, format, args...) \ dev_err(&_phydev->mdio.dev, format, ##args)