Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp803142ybj; Tue, 5 May 2020 07:47:24 -0700 (PDT) X-Google-Smtp-Source: APiQypJgCp90mR97v2X+dnsluC6T6czCsGgCh/BqyxWvyp0Pia1VtvcT3M1M8CB9wq2B7UUzHQbW X-Received: by 2002:a17:906:8549:: with SMTP id h9mr2938563ejy.145.1588690043852; Tue, 05 May 2020 07:47:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588690043; cv=none; d=google.com; s=arc-20160816; b=wPjD8/5GotnDHQ3PR+gFMV0k7qP5SseYqgNtLga+lazkPRRzjbNCeDFoMZp3u/VOmM O2+i8i1GtPX7QRoq+u8NUGKYIeF5VakOFRmq1ekC2fDfxsk9MPt3ugGuFHzB3+IrdD+J fXZ89oipd/krIFtu796FFzi/R6fOWBh8uKB2bgjvk44fFY0VSTkBE2jAmwJD18NSpHsP sR1ZrBXa/KIp6iAPylZb9YBZZy9v6kV3GgZrH90gYvT1FcNkq4OA1dNLCbA/I92bUi/C teSge8sYmnKdFi9CwVLi0QdhQPcipaAMKbEwBVz33+DPihpLEvT3O4H1o9lMNkg72Og7 /N5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=bce39cuhX+v1hhfYsPnYxLnuYR5lP/z3GapCTjD03hM=; b=w7gA5bmWl8vY4s3HR7+oHQEhMK/Np1Lu/bVkPXSicScEeb5tJK/YCDfSwMdTowdgvf Re1/8ZUcZQ0M6J3KMuy6850ydnqXZ9SymlkfYgHPfMEQnN881y1ETs50bq3E/REkf/uX wpTsoGZvavgyos2IIPPdYZ2kZF8O7Pri4DCRYUtcW04v1wUe2YibNNeSDC6vKcCRuoOL w2h0dAZI7JVvX9Di1fEihTUEY9LtPuvTuNv7fc/yLNuN2D2H7IXq/JB2pKp6PwdHVfKV lbU9fB94vcGm/5kpZbkNfHWkjnNJNN5izl8wt9kZ50PRnTfmLT/9lV0zniG0zTaE36co aRVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=b2Jt5T0j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si1389501edw.78.2020.05.05.07.46.59; Tue, 05 May 2020 07:47:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=b2Jt5T0j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729359AbgEEOpV (ORCPT + 99 others); Tue, 5 May 2020 10:45:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727857AbgEEOpV (ORCPT ); Tue, 5 May 2020 10:45:21 -0400 Received: from pandora.armlinux.org.uk (pandora.armlinux.org.uk [IPv6:2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7878C061A0F; Tue, 5 May 2020 07:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bce39cuhX+v1hhfYsPnYxLnuYR5lP/z3GapCTjD03hM=; b=b2Jt5T0jNdoZl3RJSWosMCfhx kgLFhgINbBWKyjtBOcxA48/fC1ckaCPZjO8j937EwIiBU4erqDB7D6RmWvm8RHrOqtENm7l8eHZ+C f+YnQvZk6yGKlVtaXZAhBkEuJPKAa4fA/+tCo2SJgGVFLrHiMw5b0aA/webhWeJX1A9tmjuzfpMMQ EiOLtC5g8TLkvnMlRURyYhWvzpC9ddO9H52wFyZmELgmCDazwji3PP3ueKlVEUEmJyQzS45eFLsci AQQd2bWz7zT+OGSLFNkNYkd/lkL8nV3EZKre9zaUHj8OX/lu/HbIGwE8iBgAHEbT5LLfJR4IuBDFP ucLMiqVAw==; Received: from shell.armlinux.org.uk ([2001:4d48:ad52:3201:5054:ff:fe00:4ec]:36340) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVyod-00030V-EZ; Tue, 05 May 2020 15:44:59 +0100 Received: from linux by shell.armlinux.org.uk with local (Exim 4.92) (envelope-from ) id 1jVyoc-0007F0-7K; Tue, 05 May 2020 15:44:58 +0100 Date: Tue, 5 May 2020 15:44:58 +0100 From: Russell King - ARM Linux admin To: Calvin Johnson Cc: "Rafael J . Wysocki" , linux.cj@gmail.com, Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Cristi Sovaiala , Florin Laurentiu Chiculita , Ioana Ciornei , Madalin Bucur , Greg Kroah-Hartman , Heikki Krogerus , Varun Sethi , "Rajesh V . Bikkina" , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, Diana Madalina Craciun , netdev@vger.kernel.org, Marcin Wojtas , Laurentiu Tudor , Makarand Pawagi , linux-arm-kernel@lists.infradead.org, Pankaj Bansal , "David S. Miller" , Heiner Kallweit Subject: Re: [net-next PATCH v3 1/5] net: phy: Introduce phy related fwnode functions Message-ID: <20200505144458.GK1551@shell.armlinux.org.uk> References: <20200505132905.10276-1-calvin.johnson@oss.nxp.com> <20200505132905.10276-2-calvin.johnson@oss.nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200505132905.10276-2-calvin.johnson@oss.nxp.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 05, 2020 at 06:59:01PM +0530, Calvin Johnson wrote: > Define fwnode_phy_find_device() to iterate an mdiobus and find the > phy device of the provided phy fwnode. Additionally define > device_phy_find_device() to find phy device of provided device. > > Define fwnode_get_phy_node() to get phy_node using named reference. > > Signed-off-by: Calvin Johnson > --- > > Changes in v3: > move fwnode APIs to appropriate place > stubs fwnode APIs for !CONFIG_PHYLIB > improve comment on function return condition. > > Changes in v2: > move phy code from base/property.c to net/phy/phy_device.c > replace acpi & of code to get phy-handle with fwnode_find_reference > > drivers/net/phy/phy_device.c | 53 ++++++++++++++++++++++++++++++++++++ > include/linux/phy.h | 19 +++++++++++++ > 2 files changed, 72 insertions(+) > > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c > index 7e1ddd5745d2..3e8224132218 100644 > --- a/drivers/net/phy/phy_device.c > +++ b/drivers/net/phy/phy_device.c > @@ -31,6 +31,7 @@ > #include > #include > #include > +#include > > MODULE_DESCRIPTION("PHY library"); > MODULE_AUTHOR("Andy Fleming"); > @@ -2436,6 +2437,58 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv) > return phydrv->config_intr && phydrv->ack_interrupt; > } > > +/** > + * fwnode_phy_find_device - Find phy_device on the mdiobus for the provided > + * phy_fwnode. > + * @phy_fwnode: Pointer to the phy's fwnode. > + * > + * If successful, returns a pointer to the phy_device with the embedded > + * struct device refcount incremented by one, or NULL on failure. > + */ > +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) > +{ > + struct device *d; > + struct mdio_device *mdiodev; > + > + if (!phy_fwnode) > + return NULL; > + > + d = bus_find_device_by_fwnode(&mdio_bus_type, phy_fwnode); > + if (d) { > + mdiodev = to_mdio_device(d); > + if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) > + return to_phy_device(d); > + put_device(d); > + } > + > + return NULL; > +} > +EXPORT_SYMBOL(fwnode_phy_find_device); This is basically functionally equivalent to of_phy_find_device(). If we replaced of_mdio_find_device() with a fwnode equivalent and used that above, we could have both of_mdio_find_device() and of_phy_find_device() be wrappers around their fwnode equivalents. That also means less lines of code to maintain, and means that we're unlikely to have two implementations that may drift apart functionally over time because their separated in two different parts of the kernel. That is an especially important point given that fwnodes can be DT nodes, so one may call fwnode APIs on a DT platform. > + > +/** > + * device_phy_find_device - For the given device, get the phy_device > + * @dev: Pointer to the given device > + * > + * Refer return conditions of fwnode_phy_find_device(). > + */ > +struct phy_device *device_phy_find_device(struct device *dev) > +{ > + return fwnode_phy_find_device(dev_fwnode(dev)); > +} > +EXPORT_SYMBOL_GPL(device_phy_find_device); > + > +/** > + * fwnode_get_phy_node - Get the phy_node using the named reference. > + * @fwnode: Pointer to fwnode from which phy_node has to be obtained. > + * > + * Refer return conditions of fwnode_find_reference(). > + */ > +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode) > +{ > + return fwnode_find_reference(fwnode, "phy-handle", 0); > +} > +EXPORT_SYMBOL_GPL(fwnode_get_phy_node); What if the fwnode is a DT device handle? Shouldn't this also check for the legacy properties as well, so we can transition code over to this new interface? > + > /** > * phy_probe - probe and init a PHY device > * @dev: device to probe and init > diff --git a/include/linux/phy.h b/include/linux/phy.h > index e2bfb9240587..f2664730a331 100644 > --- a/include/linux/phy.h > +++ b/include/linux/phy.h > @@ -1141,10 +1141,29 @@ 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); > #if IS_ENABLED(CONFIG_PHYLIB) > +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode); > +struct phy_device *device_phy_find_device(struct device *dev); > +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode); > struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45); > int phy_device_register(struct phy_device *phy); > void phy_device_free(struct phy_device *phydev); > #else > +static inline > +struct phy_device *fwnode_phy_find_device(struct fwnode_handle *phy_fwnode) > +{ > + return NULL; > +} > + > +static inline struct phy_device *device_phy_find_device(struct device *dev) > +{ > + return NULL; > +} > + > +struct fwnode_handle *fwnode_get_phy_node(struct fwnode_handle *fwnode) > +{ > + return NULL; > +} > + > static inline > struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) > { > -- > 2.17.1 > > -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 10.2Mbps down 587kbps up