Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6677474iob; Wed, 11 May 2022 02:58:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXdGfwnrH3p+Kh9xetMwLjMB+8LmlHUdBEbZCPYVms8qMM12FDfRKrG06PdVf5heJNkWLM X-Received: by 2002:a17:906:dc8d:b0:6f4:75da:2fc8 with SMTP id cs13-20020a170906dc8d00b006f475da2fc8mr23077104ejc.7.1652263124917; Wed, 11 May 2022 02:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652263124; cv=none; d=google.com; s=arc-20160816; b=aRHg6AYnoskJ7MqhUyFjqXz1Xmb45uERWK5g3LMP9+VCpxI8bj3YoNnZZG2Q57Kn0/ S9pIWBUFWaeka7B50yn6aqBFvUSAWZukKJNrnzRQKobjlzmAXXCjsQfsy56RS6eyqTfr cqU86eVvKpFCWIA5Bxdgix4CFy6YaO6TmbmT6BIe1FuklpBkno7TnqrhVvf9C+dq1pv/ MAxTiHadm1zMvFBRTd5T/8pcwO7gOjDP9cZNOcX5FTn8ut+4EODOUnkc3KhnFkQNM8SH KXG7w7ZzWZsmLmm9SR7iDRBTCM+IXuwclQlYeEccUs0JHnKzVKnGXRWjf/WY1/T9JBaD 7Lhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GcjkZzrLn6gMWk4BhtvbTNa6RAyAFLU8Gib10fMIL6M=; b=g15E0YEt1Ii9LBNevE5s0iNHsif/lyBUaken0TzeTzUO0yG5qhNkw5elkhPIp97GOg FeT+m69FBLLB9FjOql7vQF4iB5tp3iFShRwZDM8RR92HV8Ly8hcpJAEdCR8/3H/47FVh 7/46090NNEnK2h5yDYBb0RYTWaHpVNU7x93YRc6ST6+eb1187qmu1ZPBJsXFecnShBqn QV4KKsTE3A2afx/yL95m78FlWwAC50I2UoL7+wgFjmZKsykGXz1xNYQYqVjbrLzu5OS0 K/EqG1gWkqgBhxitR6QxwnN2/eF108iZUvuRdzuimk0oNQqV3xDu+6Z2PQI+Iydv9HZF d6pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=UFsCqPur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rl24-20020a170907217800b006f3a070d863si1634889ejb.710.2022.05.11.02.58.20; Wed, 11 May 2022 02:58:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=UFsCqPur; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239763AbiEKIDI (ORCPT + 99 others); Wed, 11 May 2022 04:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241805AbiEKIDE (ORCPT ); Wed, 11 May 2022 04:03:04 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC5608B08C for ; Wed, 11 May 2022 01:03:02 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id q23so1789507wra.1 for ; Wed, 11 May 2022 01:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=GcjkZzrLn6gMWk4BhtvbTNa6RAyAFLU8Gib10fMIL6M=; b=UFsCqPurNA77DAQgdLeQK8XeRTaY48TIY6s55owkQ/HgvOvfVLRQqmVns5XkEwBZm6 56SK0SRGUPqyFSHm6kzFsqS/WCSavHeFIJcunmiB8T6YQVsHAP976fuV0RDx1fancQkE pSz4Dy+7QjawQo5E9RZCzBbjfCovqAgf6SQnM4htoYjHzRGklIi+IRKyQ3Vq3sfQUUFj Ob5BtPJ9es4c7J1OqHqdFMkzvbg3vandDzGIcfssTWeB3TYQ7BdlOt4vC2SQ69owYueh YcwkeL249xYiu+DEr2CGR6yORYiafhfJr4LYTW0bAPJZE22e2aHtcWk3YZKi6NGCe6bD pUow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=GcjkZzrLn6gMWk4BhtvbTNa6RAyAFLU8Gib10fMIL6M=; b=ThWHTi7+xrZddH07PbteIcmLpYz9NoNeyE6oUymr9w1Z4Ylb+Nn4NGnE920HZpGFu8 /P3808oF/9P86QpibvZCVLH7beF8WmpCJI0UOi2qe6Jb+ecXikA3LW72j4xdS8/HO+B0 MEFWBoxkJ1VeQyQ6UYhlCzjFOZ6nvyaoQ0pEcVnmUvzDlpK58ud1ED+iNuwsDvcgWBBP 5aMhQLZpm8cVcy+LxKn3UcgLWFaSojR4IVq/VV/2M2IBZZFIDsLgq6lXf+uFGc0ycyvT 1P2Msp0PUF9PAZgxLZa8/kH0xHc7zg2l4ggLUaNE1m0Vxz/QxqyHaL4pCnVlhy1OeW8z FyPw== X-Gm-Message-State: AOAM532/sLjPN8OmVNrlOIXPt3oUgyfswgx9nc7k4xbnnB/n7vPSr/PD 1hcMZesNndKz7ugJeuWC3qUDBA== X-Received: by 2002:a05:6000:1c09:b0:20c:b986:e593 with SMTP id ba9-20020a0560001c0900b0020cb986e593mr16089270wrb.170.1652256181310; Wed, 11 May 2022 01:03:01 -0700 (PDT) Received: from Red ([2a01:cb1d:3d5:a100:264b:feff:fe03:2806]) by smtp.googlemail.com with ESMTPSA id z15-20020a05600c220f00b00394538d039esm4602915wml.6.2022.05.11.01.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 01:03:00 -0700 (PDT) Date: Wed, 11 May 2022 10:02:58 +0200 From: LABBE Corentin To: Mark Brown Cc: Andrew Lunn , alexandre.torgue@foss.st.com, calvin.johnson@oss.nxp.com, davem@davemloft.net, edumazet@google.com, hkallweit1@gmail.com, jernej.skrabec@gmail.com, joabreu@synopsys.com, krzysztof.kozlowski+dt@linaro.org, kuba@kernel.org, lgirdwood@gmail.com, linux@armlinux.org.uk, pabeni@redhat.com, peppe.cavallaro@st.com, robh+dt@kernel.org, samuel@sholland.org, wens@csie.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-sunxi@lists.linux.dev Subject: Re: [PATCH 3/6] dt-bindings: net: Add documentation for phy-supply Message-ID: References: <20220509074857.195302-1-clabbe@baylibre.com> <20220509074857.195302-4-clabbe@baylibre.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Le Mon, May 09, 2022 at 05:56:34PM +0100, Mark Brown a ?crit : > On Mon, May 09, 2022 at 06:38:05PM +0200, Andrew Lunn wrote: > > > So we have a collection of regulators, varying in numbers between > > different PHYs, with different vendor names and purposes. In general, > > they all should be turned on. Yet we want them named so it is clear > > what is going on. > > > Is there a generic solution here so that the phylib core can somehow > > enumerate them and turn them on, without actually knowing what they > > are called because they have vendor specific names in order to be > > clear what they are? > > > There must be a solution to this, phylib cannot be the first subsystem > > to have this requirement, so if you could point to an example, that > > would be great. > > No, it's not really come up much before - generally things with > regulator control that have generic drivers tend not to be sophisticated > enough to have more than one supply, or to be on an enumerable bus where > the power is part of the bus specification so have the power specified > as part of the bus. You'd need to extend the regulator bindings to > support parallel array of phandles and array of names properties like > clocks have as an option like you were asking for, which would doubtless > be fun for validation but is probably the thing here. Does you mean something like this: diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 1e54a833f2cf..404f5b874b59 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -351,6 +351,32 @@ 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 + * @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) +{ + int index, ret; + struct of_phandle_args regspec; + + 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 +388,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 +433,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; And then for our case, a regulator_get_bulk will be needed. Does I well understood what you mean ?