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: 11617879 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0697113A0 for ; Mon, 22 Jun 2020 14:04:17 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D10D120720 for ; Mon, 22 Jun 2020 14:04:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MN8kuHS5"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="16VBF2La" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D10D120720 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LKdzwUs49yMCyyxIdQqiyzGVcffFSgLHUJeW1VW985M=; b=MN8kuHS5Y5YKSzCQCdx+eSlxW cqWRfjsViuPHCt3gU4qEpPQiwy/MXXden7hoY8XxSlN/BXTgX69JafTYG9529eVgc0jEQQmsRF7mb L6D4aweQHK8007yMpGu5gsLJTyrwAlpUZxMd0bd0pQaL+pDj277TcRHpV0uvdwl8CwOfTLHriPDuF S+owmh+b/g2Uzn1KEqtU9VWgQUBqBQx+GIyL8Ojqgqbv1wPgaZTZhJIN+EvStgO+d2rZm/ojnh8Sx WlVEF2nHA9jqBZhx2QzUcBgswxi5CFlnfmfFYOEjHWueHa03t7aZ2UpvVF7glJnDPO8RUMYE5oVe/ VziC5ALJw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnN1L-0005vx-TR; Mon, 22 Jun 2020 14:01:59 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jnIxQ-0007hG-LI for linux-arm-kernel@lists.infradead.org; Mon, 22 Jun 2020 09:41:41 +0000 Received: by mail-wr1-x443.google.com with SMTP id o11so8242251wrv.9 for ; Mon, 22 Jun 2020 02:41:40 -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=qLjjgKyRo+l9OqiBYJcTxbbkVWd3oDpDtsWOpWVlEdmDcJIijAJrDzQwqi1YDTv55W aKxpXA/jnAwnKI6lLWnc5UMunAk/GkbpBTmOBacu4pQFYr81+DeoYWPBdsdAxsffuSlr UEfT7zXAEoCEgMV0MNuJ6BQnsOpxdi9NT8j+xvaAM/9EXEqzEYSMaSAiNDMRrzFMpoO9 +h10htwPRHBk9mg0s/3LggCU2irhISN6sfVtKlaGu1jVidHpAyDCV7S8REi5+HSiCCWN ZUzgB1FASEjXHulrDcARA3ucOXh7jG7uyALd6PMXxpXgYa/FeonIz2nrRt88OiXtTXJB WBbQ== X-Gm-Message-State: AOAM5328+DLocqvd6WjkKSY8wak1CdjG0DWqMCko1E9Am2uw6viTQ2ln ajdGjb8PvCfmIG75zfJMBEg6fg== 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 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 X-Spam-Note: CRM114 invocation failed X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:443 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Stephane Le Provost , Bartosz Golaszewski , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Fabien Parent , linux-mediatek@lists.infradead.org, Andrew Perepech , Pedro Tsai , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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)