From patchwork Wed Apr 14 14:05:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aswath Govindraju X-Patchwork-Id: 421947 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=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 1B446C43461 for ; Wed, 14 Apr 2021 14:06:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DDE606121E for ; Wed, 14 Apr 2021 14:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351648AbhDNOGW (ORCPT ); Wed, 14 Apr 2021 10:06:22 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:47944 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347931AbhDNOGS (ORCPT ); Wed, 14 Apr 2021 10:06:18 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 13EE5bHc011888; Wed, 14 Apr 2021 09:05:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1618409137; bh=nOtbADv7gq9oWC93nIeG2KyriW+0wEaqeFfExSfoA3U=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=S2NEY8hPC/8Lpjqh1WebsZZ/UVUExP+RgWh5GBR5CAu2RuX6sJwmQ42ZPrGbuiPRe s1XSm1zbV6uX3PcuYhBXwtugtcEwCtXihY6NexPS01uFR4sbcjtdcO44lb4VFBiAd7 bFCAUKCrMSI/hZqOSHcMXQtN/SVMeRstFXXXtfhQ= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 13EE5a2c041986 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 14 Apr 2021 09:05:36 -0500 Received: from DLEE108.ent.ti.com (157.170.170.38) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Wed, 14 Apr 2021 09:05:36 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE108.ent.ti.com (157.170.170.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2 via Frontend Transport; Wed, 14 Apr 2021 09:05:36 -0500 Received: from gsaswath-HP-ProBook-640-G5.dal.design.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 13EE5LuA074247; Wed, 14 Apr 2021 09:05:32 -0500 From: Aswath Govindraju CC: , , , Chandrasekar Ramakrishnan , Wolfgang Grandegger , Marc Kleine-Budde , "David S . Miller" , Jakub Kicinski , Rob Herring , Kishon Vijay Abraham I , Vinod Koul , , , Vignesh Raghavendra , Lokesh Vutla , Grygorii Strashko , Aswath Govindraju Subject: [PATCH v2 2/6] phy: Add API for devm_of_phy_optional_get_by_index Date: Wed, 14 Apr 2021 19:35:17 +0530 Message-ID: <20210414140521.11463-3-a-govindraju@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210414140521.11463-1-a-govindraju@ti.com> References: <20210414140521.11463-1-a-govindraju@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add API for devm_of_phy_optional_get_by_index, to obtain a reference to an optional phy by index. Signed-off-by: Aswath Govindraju --- drivers/phy/phy-core.c | 26 ++++++++++++++++++++++++++ include/linux/phy/phy.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c index ccb575b13777..bf06d4e0ede2 100644 --- a/drivers/phy/phy-core.c +++ b/drivers/phy/phy-core.c @@ -839,6 +839,32 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, } EXPORT_SYMBOL_GPL(devm_of_phy_get); +/** + * devm_of_phy_optional_get_by_index() - lookup and obtain a reference to an optional phy by index. + * @dev: device that requests this phy + * @np: node containing the phy + * @index: index of the phy + * + * Gets the phy using _of_phy_get(), then gets a refcount to it, + * and associates a device with it using devres. On driver detach, + * release function is invoked on the devres data, then, + * devres data is freed. This differs to devm_of_phy_get_by_index() in + * that if the phy does not exist, it is not considered an error and + * -ENODEV will not be returned. Instead the NULL phy is returned, + * which can be passed to all other phy consumer calls. + */ +struct phy *devm_of_phy_optional_get_by_index(struct device *dev, struct device_node *np, + int index) +{ + struct phy *phy = devm_of_phy_get_by_index(dev, np, index); + + if (PTR_ERR(phy) == -ENODEV) + phy = NULL; + + return phy; +} +EXPORT_SYMBOL_GPL(devm_of_phy_optional_get_by_index); + /** * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index. * @dev: device that requests this phy diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h index f3286f4cd306..c5f32b4fadd6 100644 --- a/include/linux/phy/phy.h +++ b/include/linux/phy/phy.h @@ -253,6 +253,8 @@ struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, const char *con_id); struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, int index); +struct phy *devm_of_phy_optional_get_by_index(struct device *dev, struct device_node *np, + int index); void of_phy_put(struct phy *phy); void phy_put(struct device *dev, struct phy *phy); void devm_phy_put(struct device *dev, struct phy *phy);