From nobody Sun Nov 24 08:05:24 2024 Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 780381DFDBF; Thu, 21 Nov 2024 14:44:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200247; cv=none; b=WPUBSPxJfyuXBagjGqKZuEWFZ0j5w+cYnWklxLAnM6wxPgFGCWIDfIo3D3qfsl/kaJHxR3qqV7uA0g9ydPcSimv5uDdS1Y0ntKiY8u8ir4fVoLQU7jGwmvGFbaAq3cSuvKNAbDOP8NSNShvg8jPylwE8I/thYXfbeuzpmcRbLLs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732200247; c=relaxed/simple; bh=yCdz15S5n9bwP+eHaxIWj26ftD8GPdXVftvaKhrORvA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EKqAfJSW2UbRN09lSNBRdhOqKRd3oTswFL3+eP2DPFcL/VI7YegcON72acbPaBKZvF1xTygGhImnYBhJzqEkAi6D+2ljUv9xMSu/5ruiahqsJRPOk8kQdZ8wRFl3MRcayE86/frak8bATc0dAJWRD4wtOeytmArfiEqTFweD1Hw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=MuOmbRms; arc=none smtp.client-ip=217.70.183.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="MuOmbRms" Received: by mail.gandi.net (Postfix) with ESMTPSA id 0A0C340003; Thu, 21 Nov 2024 14:44:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732200244; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u04a+OXero5sCODR6WNJl3zCEzppF8sFRXUhrvCAEFA=; b=MuOmbRmsOjc4Ak4mjQG71ptircy1YwGmFjL+4izltDHAczySCSRRb44DGGapgcBlg1tkWo BlmiGzQK8lQrfiNG64vczgNWpVWK1Qba2x2Dsh4j0QbfU/iF3CdVFcXh1+0t+noPKAsRQJ HfCWA3aKyxfpjqzywprzrGN1ubt/GSxEaz5BCby5cNenkhGPyO/b8sPg7PO8EYYZnXDnlM ujet5rfH9zCFgRi7oOBnbRC07ddZbQ/hTB8daGGjadvhgwcqpkjlvRMQ01yo4NMYGpkhdY 9jHcsqztnF6aqp0pqJl2tk21TAc8+DQzsZEqnBnQaLhZ62YAqI1u+lydR3BLew== From: Kory Maincent Date: Thu, 21 Nov 2024 15:42:41 +0100 Subject: [PATCH RFC net-next v3 15/27] regulator: core: Resolve supply using of_node from regulator_config Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241121-feature_poe_port_prio-v3-15-83299fa6967c@bootlin.com> References: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> In-Reply-To: <20241121-feature_poe_port_prio-v3-0-83299fa6967c@bootlin.com> To: Andrew Lunn , Oleksij Rempel , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jonathan Corbet , Donald Hunter , Rob Herring , Andrew Lunn , Simon Horman , Heiner Kallweit , Russell King , Liam Girdwood , Mark Brown Cc: Thomas Petazzoni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-doc@vger.kernel.org, Kyle Swenson , Dent Project , kernel@pengutronix.de, Maxime Chevallier , Kory Maincent X-Mailer: b4 0.15-dev-8cb71 X-GND-Sasl: kory.maincent@bootlin.com From: Kory Maincent (Dent Project) Previously, the regulator core resolved its supply only from the parent device or its children, ignoring the of_node specified in the regulator_config structure. This behavior causes issues in scenarios where multiple regulator devices are registered for components described as children of a controller, each with their own specific regulator supply. For instance, in a PSE controller with multiple PIs (Power Interfaces), each PI may have a distinct regulator supply. However, the regulator core would incorrectly use the PSE controller node or its first child to look up the regulator supply, rather than the node specified by the regulator_config->of_node for the PI. This update modifies the behavior to prioritize the of_node in regulator_config for resolving the supply. This ensures correct resolution of the power supply for each device. If no supply is found in the provided of_node, the core falls back to searching within the parent device as before. Signed-off-by: Kory Maincent --- It is weird that it wasn't seen before, maybe there was not any case were it can't find the supply_name from the parent device. Changes in v3: - New patch --- drivers/regulator/core.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 2948a7eca734..b49f751893b9 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -1936,6 +1936,20 @@ static struct regulator_dev *regulator_lookup_by_nam= e(const char *name) return dev ? dev_to_rdev(dev) : NULL; } =20 +static struct regulator_dev *regulator_dt_lookup(struct device *dev, + const char *supply) +{ + struct regulator_dev *r =3D NULL; + + if (dev && dev->of_node) { + r =3D of_regulator_dev_lookup(dev, supply); + if (PTR_ERR(r) =3D=3D -ENODEV) + r =3D NULL; + } + + return r; +} + /** * regulator_dev_lookup - lookup a regulator device. * @dev: device for regulator "consumer". @@ -1960,16 +1974,9 @@ static struct regulator_dev *regulator_dev_lookup(st= ruct device *dev, regulator_supply_alias(&dev, &supply); =20 /* first do a dt based lookup */ - if (dev && dev->of_node) { - r =3D of_regulator_dev_lookup(dev, supply); - if (!IS_ERR(r)) - return r; - if (PTR_ERR(r) =3D=3D -EPROBE_DEFER) - return r; - - if (PTR_ERR(r) =3D=3D -ENODEV) - r =3D NULL; - } + r =3D regulator_dt_lookup(dev, supply); + if (r) + return r; =20 /* if not found, try doing it non-dt way */ if (dev) @@ -2002,8 +2009,8 @@ static struct regulator_dev *regulator_dev_lookup(str= uct device *dev, =20 static int regulator_resolve_supply(struct regulator_dev *rdev) { - struct regulator_dev *r; struct device *dev =3D rdev->dev.parent; + struct regulator_dev *r =3D NULL; struct ww_acquire_ctx ww_ctx; int ret =3D 0; =20 @@ -2015,7 +2022,18 @@ static int regulator_resolve_supply(struct regulator= _dev *rdev) if (rdev->supply) return 0; =20 - r =3D regulator_dev_lookup(dev, rdev->supply_name); + /* first do a dt based lookup on the node described in the virtual + * device. + */ + if (rdev->dev.of_node) + r =3D regulator_dt_lookup(&rdev->dev, rdev->supply_name); + + /* If regulator not found use usual search path in the parent + * device. + */ + if (!r) + r =3D regulator_dev_lookup(dev, rdev->supply_name); + if (IS_ERR(r)) { ret =3D PTR_ERR(r); =20 --=20 2.34.1