Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp858316pxb; Thu, 15 Apr 2021 08:12:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7vdVctzz/QqaYZqnQq/RYEFqYgd9aeVlCh5bDGcVwOxS6/5L9ezgUxYyH/9ZyNhnfGA6Z X-Received: by 2002:a17:90a:a589:: with SMTP id b9mr566351pjq.80.1618499542472; Thu, 15 Apr 2021 08:12:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618499542; cv=none; d=google.com; s=arc-20160816; b=P3s3cb0Smcv07Z/hL3786kwFuHmYaEUgfZhrJVTd7IIgmgdjHajyUXo1m69Gz8yF++ uCVKKiG5LyhXX9Q/nIoZc9Ydf87PQTd/5OlKyiLqKJ7K+Lnzx2tpwVaA9bnnH7iP+yvj YRvd5rb65Le5Xur2iIe/73pRSA+z/bmzmtJBU8aU6QBWQWjhxwK6B5VDxY5nbw9Odgpe 7hCaNRDvJZGAn7wq2jH0MKz0Owf60Id1Lbs76vO8w9XmdAWZ1etz914V/0UMHpLcJzrK brsMHAOISo1MUNUnIeNETJ2mCCsia8eyYURQ/wQc6nLJUjsr6ER1293gG9LfrAqEQQaj bbxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=pKl9USW4Lb4q2lT4TkJijaFrzIIfUx2rrVu/7hEAIwg=; b=zrcFqMLUH+sGYJokVyn1JfLI755iMHVFSY0Tq0cRIP1/iNBtoPI1HyMep1UReEUTuS qrTe2UMslbuue6puoRAJfZ4bvM6BLTjSsJlpMO0hzSr/hA3I1LiWasFnXZU3/XLwRAlt sgrYrqRGIEB3m/hMrYRQvTiAZyVyRrw31kV1HljBjhG94tJu8F64VZblwk2IjJfchB84 rBSQKKWBxtPCrLnn3OBfqJCzPGEKJdVHEjLBvk95OkTOY2jCHQ7vKzxpQoqfeegjrE0s DWWLMwZwyNgex4aQHsL3EVA3vWJtN87Kx5spaLJOprKhL+YrwLOwe0DYQd3nXFCsgmgz btfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="IpcH/Wot"; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l6si3509130plt.391.2021.04.15.08.12.10; Thu, 15 Apr 2021 08:12:22 -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=@ti.com header.s=ti-com-17Q1 header.b="IpcH/Wot"; 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=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234626AbhDOPMC (ORCPT + 99 others); Thu, 15 Apr 2021 11:12:02 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:37698 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235366AbhDOPBE (ORCPT ); Thu, 15 Apr 2021 11:01:04 -0400 Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 13FF0WgP101805; Thu, 15 Apr 2021 10:00:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1618498832; bh=pKl9USW4Lb4q2lT4TkJijaFrzIIfUx2rrVu/7hEAIwg=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=IpcH/Wot0NJFgpovlSvrAMOg9Odk3OJmWmyBfGoQON3QRTjAuRndajqjOAcqBIa9t ko7d9o0ZcL8vL4ULPPKHYFwWKfAMWBhEJMCvWLw77cE7N6e/zK92l+nYaLg7dFHju3 e1c12kCm/1KgPXQx5HsZPyWv4AzygpmoMr+kZrxc= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 13FF0W7k105205 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 15 Apr 2021 10:00:32 -0500 Received: from DFLE107.ent.ti.com (10.64.6.28) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 15 Apr 2021 10:00:31 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE107.ent.ti.com (10.64.6.28) 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; Thu, 15 Apr 2021 10:00:31 -0500 Received: from [10.250.233.30] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 13FF0RlR061690; Thu, 15 Apr 2021 10:00:28 -0500 Subject: Re: [PATCH v3 2/4] phy: Add API for devm_of_phy_optional_get_by_index To: Aswath Govindraju CC: , , , , Vinod Koul , Rob Herring , Marc Kleine-Budde , Wolfgang Grandegger , Lokesh Vutla , Vignesh Raghavendra , Grygorii Strashko References: <20210415144947.4725-1-a-govindraju@ti.com> <20210415144947.4725-3-a-govindraju@ti.com> From: Kishon Vijay Abraham I Message-ID: Date: Thu, 15 Apr 2021 20:30:26 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210415144947.4725-3-a-govindraju@ti.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Aswath, On 15/04/21 8:19 pm, Aswath Govindraju wrote: > Add API for devm_of_phy_optional_get_by_index, to obtain a reference to an > optional phy by index. Rob has posted a patch http://lore.kernel.org/r/20210414135525.3535787-1-robh@kernel.org that doesn't require consumers to get a phy by using string. Since your usecase also requires only one PHY, that patch should be sufficient. $patch could be deferred until a real use case comes. Thanks Kishon > > 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); >