Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp795159iob; Wed, 18 May 2022 13:10:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztyDn8lU4AtAqp0W/yJhzr5HFTrEhLcqHsBfoquWU3xAOMAqjcF21qaOT6Hq1TwrLSjr+/ X-Received: by 2002:a17:902:d717:b0:15e:b6ed:4824 with SMTP id w23-20020a170902d71700b0015eb6ed4824mr1329416ply.110.1652904625060; Wed, 18 May 2022 13:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652904625; cv=none; d=google.com; s=arc-20160816; b=Yzr1MvVytnbcEN0I8GL9iQMDL6ECSMZXTPndnmIrPbhbvT+JN1rfdJF/cf6xCZZ9T1 9pUn5wvG03RAunVNZAUCFCAsc7fXPuGPq7T3Ok/oeg5WvhhuRcN+D+FlkvHHpUPYDJKR 0N/NbZvJXltOM7aV4K9HXp6fc7cppOOazEHn0tXlMtrLAbV9YOyRAIZHAB/l/kp8JYVC M2at0XVYpq/DQ4iROsLKND7qiS7EkJxhng41LgvYJpPnix8plhCliYCM3X5ybbyqZznt bhTDd5lo8BtG9BQjKud/bPHKEyKbHdvdMKZQ//7JfKZx73KoYwhABFDAdbWnqC7frFFX V5pw== 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=0KczXNl/9anABcy3K+RQeZFJPAxsjOIOqB1/DLsrKFc=; b=HikguRMJDIu5qtbe6FXv2fy9yqkydZm7g1yll8e7Qga+XH4N9gNNs/t7z0aOFyY8+n 2OFthqREGrquFHVV6zRRqQWdYAcm9rdQG2PoBbj9T1EzWj2hD3VFaRqe7XTIy96V/S4i +5VpgXHyIUqHaDcOk5O0lY+WDdcWY+i5bvh0odaKdoBx/UXGIU0/AKvc5JLTSMSpsqB0 XBin+yEceh1GNSU/CM2mMfae7BLqr9X13d2t7Qa5G7Lqnc4z1hJI4Ngawm/Wn4340JsF pzhpvXYtNQfZZ2b/9ykAiNaLZAzrGUdTqzRXBrR8YNnLW6DLToIaBAf7m4/MG65YMuBt sdAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=NyHVRqHr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id jj11-20020a170903048b00b0015827ec0073si3422702plb.452.2022.05.18.13.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:10:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=NyHVRqHr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A7CA0244F0E; Wed, 18 May 2022 13:10:14 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242384AbiERUJy (ORCPT + 99 others); Wed, 18 May 2022 16:09:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242364AbiERUJu (ORCPT ); Wed, 18 May 2022 16:09:50 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65E272375DE for ; Wed, 18 May 2022 13:09:49 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id e28so3571243wra.10 for ; Wed, 18 May 2022 13:09:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0KczXNl/9anABcy3K+RQeZFJPAxsjOIOqB1/DLsrKFc=; b=NyHVRqHreDZKcytz8hWSWGRyMBK/Gyu/ugTIj5yEj9xTVltz5sneAJBFLbJHE93iEv uIvMsS6cq1K6950Twamwn/p8HkDYu7ytRmsH4Vi1I2PpB86LAsnZhoETu1oBPRwhRKOh dw4Z50DfUo5AE1P4eFpaBiXHirzI3xETzvAtYq4mTQhjn5nwog9pVPbJOZ25opwuDjXo mN2dHmI6K3B+snsTrb3h8xYMjIHoCy8tMsxUFV0zzeD+IpzqH0R3vJ0AVZTXv0++E3Va PNrPpg/QOEQXWoPC1zPW9vuiIjrnUeAKcazOxUgSYb/kQvIEOOim1hSfPDyM7XHUoQqw It2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0KczXNl/9anABcy3K+RQeZFJPAxsjOIOqB1/DLsrKFc=; b=4pQNbr4nChj25hxcsRIZpKMxIg6Z8cI9l3zS0hp3cToBhgI9DKeSmeEJLbCXmDkzXH hApJnKNXUZJ7/nCRWCR4gPHPoQfD42Mm52I98R5Xzrq1YG+eyGwpibqF6ZxK4WLlyory +jDGI9xeUXDCgad3lb+PMaCju8J2mGCUiB64r+Z3wMDIj4yHvPBK+kdWIxj3jpPHgCv8 fbLOnVVu4krxsNN9tOcYbe70Gj78KmeLBqbKui1Zabk9FX+iu5SI5Jhkue0TXFCxo61N 0w8Rutj5Oq80WzLAiJF2SZu0hE+4B0fLWyTXS/S706LuEaSo8OvJpcEuCx+S/Wi9cN11 k2JQ== X-Gm-Message-State: AOAM531SE/LgbJdSpyDZTMC4B3i0IjSH68hS80LovgwkQteMqgmfx266 7Mlypk3H7jkclCFnDz48FlJETA== X-Received: by 2002:a5d:47c9:0:b0:20c:80bb:a296 with SMTP id o9-20020a5d47c9000000b0020c80bba296mr1117991wrc.384.1652904587664; Wed, 18 May 2022 13:09:47 -0700 (PDT) Received: from localhost.localdomain (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.googlemail.com with ESMTPSA id o23-20020a05600c511700b0039456c00ba7sm6859281wms.1.2022.05.18.13.09.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:09:47 -0700 (PDT) From: Corentin Labbe To: andrew@lunn.ch, broonie@kernel.org, calvin.johnson@oss.nxp.com, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, jernej.skrabec@gmail.com, krzysztof.kozlowski+dt@linaro.org, kuba@kernel.org, lgirdwood@gmail.com, linux@armlinux.org.uk, pabeni@redhat.com, robh+dt@kernel.org, samuel@sholland.org, wens@csie.org Cc: devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev, netdev@vger.kernel.org, Corentin Labbe Subject: [PATCH v2 1/5] regulator: Add of_get_regulator_from_list Date: Wed, 18 May 2022 20:09:35 +0000 Message-Id: <20220518200939.689308-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com> References: <20220518200939.689308-1-clabbe@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org of_get_regulator_from_list() permits to get a regulator from a regulators list. Then add support for such list in of_get_regulator() Signed-off-by: Corentin Labbe --- drivers/regulator/core.c | 44 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1e54a833f2cf..09578c3595de 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -351,6 +351,33 @@ static void regulator_lock_dependent(struct regulator_dev *rdev, mutex_unlock(®ulator_list_mutex); } +/** + * of_get_regulator_from_list - get a regulator device node based on supply name + * from a DT regulators list + * @dev: Device pointer for the consumer (of regulator) device + * @np: The device node where to search for regulators list + * @supply: regulator supply name + * + * Extract the regulator device node corresponding to the supply name. + * returns the device node corresponding to the regulator if found, else + * returns NULL. + */ +static struct device_node *of_get_regulator_from_list(struct device *dev, + struct device_node *np, + const char *supply) +{ + struct of_phandle_args regspec; + int index, ret; + + index = of_property_match_string(np, "regulator-names", supply); + if (index >= 0) { + ret = of_parse_phandle_with_args(np, "regulators", NULL, index, ®spec); + if (ret == 0) + return regspec.np; + } + return NULL; +} + /** * of_get_child_regulator - get a child regulator device node * based on supply name @@ -362,17 +389,23 @@ static void regulator_lock_dependent(struct regulator_dev *rdev, * returns the device node corresponding to the regulator if found, else * returns NULL. */ -static struct device_node *of_get_child_regulator(struct device_node *parent, - const char *prop_name) +static struct device_node *of_get_child_regulator(struct device *dev, + struct device_node *parent, + const char *supply) { struct device_node *regnode = NULL; struct device_node *child = NULL; + char prop_name[64]; /* 64 is max size of property name */ + snprintf(prop_name, 64, "%s-supply", supply); for_each_child_of_node(parent, child) { + regnode = of_get_regulator_from_list(dev, child, supply); + if (regnode) + return regnode; regnode = of_parse_phandle(child, prop_name, 0); if (!regnode) { - regnode = of_get_child_regulator(child, prop_name); + regnode = of_get_child_regulator(dev, child, prop_name); if (regnode) goto err_node_put; } else { @@ -401,12 +434,15 @@ static struct device_node *of_get_regulator(struct device *dev, const char *supp char prop_name[64]; /* 64 is max size of property name */ dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); + regnode = of_get_regulator_from_list(dev, dev->of_node, supply); + if (regnode) + return regnode; snprintf(prop_name, 64, "%s-supply", supply); regnode = of_parse_phandle(dev->of_node, prop_name, 0); if (!regnode) { - regnode = of_get_child_regulator(dev->of_node, prop_name); + regnode = of_get_child_regulator(dev, dev->of_node, supply); if (regnode) return regnode; -- 2.35.1