Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp472726pxj; Fri, 11 Jun 2021 03:59:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlIjPoYjlZWbzQrYCrv63rkZ3T0ucgPn+XpLQRDKYS4FqxEJasz0FXfQaJ3hKHK7c62bHX X-Received: by 2002:a17:906:1986:: with SMTP id g6mr3061259ejd.265.1623409163654; Fri, 11 Jun 2021 03:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623409163; cv=none; d=google.com; s=arc-20160816; b=kVBUEhX8G8HK9skInaBEdA5+Hxqy4qD+nFHAz8UAwQyZaNZ46E1AFCr0d6EoQ0YHOB g7lA07MYlxc+4n3rWb5IT4CF9+ZNk4kNZX0FIyXaa7NpfMi9T45utIEajFPq1TAW+U+d u5J+7aK8p6sqGdrqNAlHT33UT8NfIxN4VsiUpRwKhokj6LSAXbw97EkFUqcSeDMME6yW CS/CcciUskVwVBvRz6/ogGuN0CFFHCo9ZRf+/zdBOnq1egwOxaPiG2AgE2YYVrJHfs5J nGdiDQWbeyIpIrA6Hzk90KlRqHlY65PyEi9G6ESspt7npj30psqdYM46qu21Hg2Kz2mk 7mjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GzH0xLYISJ6Vd/Atl9MgKS6w5X2okzZek72YxwDeWYI=; b=npqvAJ3oKBmGOYDByKpt5qsxbvhYk0K0mUrnNm39u31puP9V888/4DiW/gfgxv5WnW /sOKUSRbvz7vVhY47vnqJLbb3lsgxGOJDfm/vvPv7UqABXwIryMILUj/R2EVMx9IjN3z I0YNNEW7YzJQmXnW4uMVAXcUguvS9rIlmWhFJL8aqwwtB4ZeP0FgnpVpd9SoMYqsoBN/ g+opzWPN9QFzIOG0DWO2pjyiioz3F8bs+8cdpR+kj240VUfB2O/C/JYrimbuK+Mh3L0h HFmwKCAELKW+gXgVBU2KidFolSxp8V4B0nBc6VV/XecpEav4WKjghDKCt3FexWcfzdAw mIUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iKwdlqzx; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c7si4597279ejz.386.2021.06.11.03.58.59; Fri, 11 Jun 2021 03:59: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=pass header.i=@gmail.com header.s=20161025 header.b=iKwdlqzx; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231836AbhFKK6Q (ORCPT + 99 others); Fri, 11 Jun 2021 06:58:16 -0400 Received: from mail-ej1-f50.google.com ([209.85.218.50]:47045 "EHLO mail-ej1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231742AbhFKK5l (ORCPT ); Fri, 11 Jun 2021 06:57:41 -0400 Received: by mail-ej1-f50.google.com with SMTP id he7so3863177ejc.13; Fri, 11 Jun 2021 03:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GzH0xLYISJ6Vd/Atl9MgKS6w5X2okzZek72YxwDeWYI=; b=iKwdlqzxNZSLbu0xyCxy17Aux6M2F/HwDuxcFSI0O3mkYzJAZh6GTHfVlaJ7QvL2ui EzjiEBCKQIzCGr8cjpPgIR515dtXNAoSRLgHELR4k/Az2RNRHo9UtbrEIDDSY98ypVSW +SICbnKsFfLkc28HfVxR63DDADv/sVm9VQPKwa4W65hf9mPYykTI3ZGtwtb545SS4DtU u8ZWHTyO6hEc/lh38l0AOKTX3cBQ8DKYL7NizhQ1u+NYnsh7M/mN86OurE6X8Qdz8p9V //6q1bgxWOKPZG7gZPMw7LTbFALPmRAjjx0Yw1BWszx+OL53OzAzKDbo9Ik417JqRyPZ j6tw== 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=GzH0xLYISJ6Vd/Atl9MgKS6w5X2okzZek72YxwDeWYI=; b=jkl4dzXD6M3PdC4uSQ1vyFAAzieBs2HSKxuLENIU+5rIatJnEEPuQxg+7umQWGt82V f2ibwMrwLnzlBSsh8Cb8iYjMep3U3boJnmIhFUogQ0O5Gm8W9lIrRPkxa58lnEOLy9Be z//WwEpV80c8Hd563r7Cw9PBczBhyZuJYXhhzb64fFJ0Y4mjm22VkAi1X6i+6GjhlnWp MwYM4AkfOW8f0Ie+6VjufK8GcJsnQCfle0u0VwnADKATDQmMEMaHHRmKB1YbkOhzIvqs aDqB8DXXc/8RTlMXI2PLbOx/uHE3Age+rLri/b6Z58PCb2TLBCwKWTv4AhhpwZV3yvF5 zgKw== X-Gm-Message-State: AOAM533K3ZuXR3F055s57rEud3z9Lxhe61+ppeIsD5dpyMmjpDTE79ja yW1bmqXw7bYX0hnnwJhr8Ek= X-Received: by 2002:a17:906:c2d6:: with SMTP id ch22mr3085535ejb.227.1623408882632; Fri, 11 Jun 2021 03:54:42 -0700 (PDT) Received: from yoga-910.localhost ([188.26.52.84]) by smtp.gmail.com with ESMTPSA id r19sm2492051eds.75.2021.06.11.03.54.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jun 2021 03:54:42 -0700 (PDT) From: Ioana Ciornei To: davem@davemloft.net, kuba@kernel.org, hkallweit1@gmail.com, netdev@vger.kernel.org, Grant Likely , "Rafael J . Wysocki" , Jeremy Linton , Andrew Lunn , Andy Shevchenko , Florian Fainelli , Russell King - ARM Linux admin , Heikki Krogerus , Marcin Wojtas , Pieter Jansen Van Vuuren , Jon , Saravana Kannan , Randy Dunlap , calvin.johnson@oss.nxp.com Cc: Cristi Sovaiala , Florin Laurentiu Chiculita , Madalin Bucur , linux-arm-kernel@lists.infradead.org, Diana Madalina Craciun , linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, linux.cj@gmail.com, Laurentiu Tudor , Len Brown , "Rafael J . Wysocki" , Ioana Ciornei Subject: [PATCH net-next v9 02/15] net: phy: Introduce fwnode_mdio_find_device() Date: Fri, 11 Jun 2021 13:53:48 +0300 Message-Id: <20210611105401.270673-3-ciorneiioana@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210611105401.270673-1-ciorneiioana@gmail.com> References: <20210611105401.270673-1-ciorneiioana@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Calvin Johnson Define fwnode_mdio_find_device() to get a pointer to the mdio_device from fwnode passed to the function. Refactor of_mdio_find_device() to use fwnode_mdio_find_device(). Signed-off-by: Calvin Johnson Signed-off-by: Ioana Ciornei Acked-by: Grant Likely --- Changes in v9: None Changes in v8: None Changes in v7: - correct fwnode_mdio_find_device() description Changes in v6: - fix warning for function parameter of fwnode_mdio_find_device() Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None drivers/net/mdio/of_mdio.c | 11 +---------- drivers/net/phy/phy_device.c | 23 +++++++++++++++++++++++ include/linux/phy.h | 7 +++++++ 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/drivers/net/mdio/of_mdio.c b/drivers/net/mdio/of_mdio.c index 8e97d5b825f5..6ef8b6e40189 100644 --- a/drivers/net/mdio/of_mdio.c +++ b/drivers/net/mdio/of_mdio.c @@ -347,16 +347,7 @@ EXPORT_SYMBOL(of_mdiobus_register); */ struct mdio_device *of_mdio_find_device(struct device_node *np) { - struct device *d; - - if (!np) - return NULL; - - d = bus_find_device_by_of_node(&mdio_bus_type, np); - if (!d) - return NULL; - - return to_mdio_device(d); + return fwnode_mdio_find_device(of_fwnode_handle(np)); } EXPORT_SYMBOL(of_mdio_find_device); diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 495d86b4af7c..dca454b5c209 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -2875,6 +2875,29 @@ static bool phy_drv_supports_irq(struct phy_driver *phydrv) return phydrv->config_intr && phydrv->handle_interrupt; } +/** + * fwnode_mdio_find_device - Given a fwnode, find the mdio_device + * @fwnode: pointer to the mdio_device's fwnode + * + * If successful, returns a pointer to the mdio_device with the embedded + * struct device refcount incremented by one, or NULL on failure. + * The caller should call put_device() on the mdio_device after its use. + */ +struct mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) +{ + struct device *d; + + if (!fwnode) + return NULL; + + d = bus_find_device_by_fwnode(&mdio_bus_type, fwnode); + if (!d) + return NULL; + + return to_mdio_device(d); +} +EXPORT_SYMBOL(fwnode_mdio_find_device); + /** * 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 ed332ac92e25..7aa97f4e5387 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1377,10 +1377,17 @@ 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 mdio_device *fwnode_mdio_find_device(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 mdio_device *fwnode_mdio_find_device(struct fwnode_handle *fwnode) +{ + return 0; +} + static inline struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45) { -- 2.31.1