From nobody Thu Sep 19 23:15:06 2024 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07B3818133F for ; Thu, 22 Aug 2024 09:20:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318430; cv=none; b=KJVhL+TmP/ljwCHf8CqCj2DHszW/IfuryhT5NlagnutQkuwOZ/eVLtwV3peyf9odX3nGdBEQ6Jtb14g/OITh3XaqebTG5aZisEGJY+uPBaOW7Q4qsbKiqlfoctq2Vc/nYlIlmObN0w9+HQbmk5aWNMcu4GPETAmb9I0ElK69c00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724318430; c=relaxed/simple; bh=ELziOpfut8Y9y2QpRYtBASCpGbA0kgK45JJaJ9cGJa0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rWDzvuMtL6gkRYeFOxO/7aDrzUaYww8/MGUskSv2xvrX9u7cfLxiu7txUMqES8jDtuG5gCyj5WghvH3gdWVUFlmkWfDVycb+8+tJSTQCX9bxgnp81LeIutHLyUpIjheKFkZ8T/J6DWS+efCHzo1cEkE3ZFIDehql2X/KVS8cFtc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=XCvEyO1k; arc=none smtp.client-ip=209.85.210.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="XCvEyO1k" Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-7142448aaf9so403278b3a.1 for ; Thu, 22 Aug 2024 02:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1724318428; x=1724923228; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IeQTJP2FGJKC+q0TaK5nRU8de0bpWdLOhuHTxIn3w+o=; b=XCvEyO1k0ibjsaSyf8dxzO01+Ky8ND2Ns9P0ab6c608KB6/g4neRfRmIxE/zgZq6zp jNsiiQ7tNVkgbRkYJqg9c9K8Prh0zBzAOUAbknAznEQ/u2e32FzRc1e7vch2PTZcI7Rc TWgD117GPx8qW2LgNlLEuwBGrRLUJsOzXMqYo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724318428; x=1724923228; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IeQTJP2FGJKC+q0TaK5nRU8de0bpWdLOhuHTxIn3w+o=; b=TQJABuZZEb5Sp4WygtOJzEDdX40P9dn3BZzFf2UYYnxc2YImmvA8bXA5LJJh2X80dN 66o+0fD7568rmzm4NVmIaSpn9B3NG9af7PDxr8zQB8HNR9JhxmhA0AlvDNZZseyWMLcz +0TRX3lP4uCVheZk+DofDScRSMvOk8jtASqm1oX/ge1BZXdfOXOg6bts5sgPsUrbJLpR S/+ETcQUqdgD/Mlb5Fyh6YcLtxnHIud36GsWULRvjDLiqOSBX/8kvYlT5fiDA3qm+G5i yRw6z9zX34F+LKcCQLWBnjfZUAejkKXYLPfDgtj4ZBitSFZEMxNZr8rKzQBjYZ/uaWPm rgnQ== X-Forwarded-Encrypted: i=1; AJvYcCUlo2yqFXauNi+DI0kGVu5KYjM2lyKDGWGRKGb4JCL+0R7F6QLu8Vs9SqxlDu63jiNUC+kQLMgH1CfTesY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6pUCdUtOCYHvd+1VUmzMGYr/nJ0I62Y6IZb7rGh/kFof12AxR zj4K/IhxlLHEPm35CKPy+OdHg9RJ6ZApSNbYdLuRZkPeqxWUj3Cox/jYichQ3w== X-Google-Smtp-Source: AGHT+IH60pf2USyhbGl6hcFS70WibHe7v+VnRzo4raEis9sQGEqleOsBie2zhiyldOuUYRp+I/niuQ== X-Received: by 2002:a05:6a21:c94:b0:1ca:ccd0:1bdb with SMTP id adf61e73a8af0-1cae524ea12mr3283455637.20.1724318428213; Thu, 22 Aug 2024 02:20:28 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:8470:6a67:8877:ce2c]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71434335e69sm951398b3a.194.2024.08.22.02.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 02:20:27 -0700 (PDT) From: Chen-Yu Tsai To: Rob Herring , Saravana Kannan , Matthias Brugger , AngeloGioacchino Del Regno , Wolfram Sang , Benson Leung , Tzung-Bi Shih , Mark Brown , Liam Girdwood Cc: Chen-Yu Tsai , chrome-platform@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Douglas Anderson , Johan Hovold , Jiri Kosina , Andy Shevchenko , linux-i2c@vger.kernel.org Subject: [PATCH v5 02/10] regulator: Move OF-specific regulator lookup code to of_regulator.c Date: Thu, 22 Aug 2024 17:19:55 +0800 Message-ID: <20240822092006.3134096-3-wenst@chromium.org> X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog In-Reply-To: <20240822092006.3134096-1-wenst@chromium.org> References: <20240822092006.3134096-1-wenst@chromium.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There's still a bit of OF-specific code in the regulator device lookup function. Move those bits of code over to of_regulator.c, and create a new function of_regulator_dev_lookup() to encapsulate the code moved out of regulator_dev_lookup(). Also mark of_find_regulator_by_node() as static, since there are no other users in other compile units. There are no functional changes. Signed-off-by: Chen-Yu Tsai --- Changes since v4: - New patch --- drivers/regulator/core.c | 85 ++------------------------ drivers/regulator/internal.h | 9 +-- drivers/regulator/of_regulator.c | 102 ++++++++++++++++++++++++++++++- 3 files changed, 111 insertions(+), 85 deletions(-) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 9029de5395ee..361309fcae57 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -419,72 +419,6 @@ static void regulator_lock_dependent(struct regulator_= dev *rdev, mutex_unlock(®ulator_list_mutex); } =20 -/** - * of_get_child_regulator - get a child regulator device node - * based on supply name - * @parent: Parent device node - * @prop_name: Combination regulator supply name and "-supply" - * - * Traverse all child nodes. - * Extract the child regulator device node corresponding to the supply nam= e. - * returns the device node corresponding to the regulator if found, else - * returns NULL. - */ -static struct device_node *of_get_child_regulator(struct device_node *pare= nt, - const char *prop_name) -{ - struct device_node *regnode =3D NULL; - struct device_node *child =3D NULL; - - for_each_child_of_node(parent, child) { - regnode =3D of_parse_phandle(child, prop_name, 0); - - if (!regnode) { - regnode =3D of_get_child_regulator(child, prop_name); - if (regnode) - goto err_node_put; - } else { - goto err_node_put; - } - } - return NULL; - -err_node_put: - of_node_put(child); - return regnode; -} - -/** - * of_get_regulator - get a regulator device node based on supply name - * @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(struct device *dev, const char= *supply) -{ - struct device_node *regnode =3D NULL; - char prop_name[64]; /* 64 is max size of property name */ - - dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); - - snprintf(prop_name, 64, "%s-supply", supply); - regnode =3D of_parse_phandle(dev->of_node, prop_name, 0); - - if (!regnode) { - regnode =3D of_get_child_regulator(dev->of_node, prop_name); - if (regnode) - return regnode; - - dev_dbg(dev, "Looking up %s property in node %pOF failed\n", - prop_name, dev->of_node); - return NULL; - } - return regnode; -} - /* Platform voltage constraint check */ int regulator_check_voltage(struct regulator_dev *rdev, int *min_uV, int *max_uV) @@ -2009,7 +1943,6 @@ static struct regulator_dev *regulator_dev_lookup(str= uct device *dev, const char *supply) { struct regulator_dev *r =3D NULL; - struct device_node *node; struct regulator_map *map; const char *devname =3D NULL; =20 @@ -2017,19 +1950,11 @@ static struct regulator_dev *regulator_dev_lookup(s= truct device *dev, =20 /* first do a dt based lookup */ if (dev && dev->of_node) { - node =3D of_get_regulator(dev, supply); - if (node) { - r =3D of_find_regulator_by_node(node); - of_node_put(node); - if (r) - return r; - - /* - * We have a node, but there is no device. - * assume it has not registered yet. - */ - return ERR_PTR(-EPROBE_DEFER); - } + r =3D of_regulator_dev_lookup(dev, supply); + if (!IS_ERR(r)) + return r; + if (PTR_ERR(r) =3D=3D -EPROBE_DEFER) + return r; } =20 /* if not found, try doing it non-dt way */ diff --git a/drivers/regulator/internal.h b/drivers/regulator/internal.h index 77a502141089..ffeaef22169e 100644 --- a/drivers/regulator/internal.h +++ b/drivers/regulator/internal.h @@ -66,7 +66,8 @@ static inline struct regulator_dev *dev_to_rdev(struct de= vice *dev) } =20 #ifdef CONFIG_OF -struct regulator_dev *of_find_regulator_by_node(struct device_node *np); +struct regulator_dev *of_regulator_dev_lookup(struct device *dev, + const char *supply); struct regulator_init_data *regulator_of_get_init_data(struct device *dev, const struct regulator_desc *desc, struct regulator_config *config, @@ -80,10 +81,10 @@ int of_get_n_coupled(struct regulator_dev *rdev); bool of_check_coupling_data(struct regulator_dev *rdev); =20 #else -static inline struct regulator_dev * -of_find_regulator_by_node(struct device_node *np) +static inline struct regulator_dev *of_regulator_dev_lookup(struct device = *dev, + const char *supply) { - return NULL; + return -ENODEV; } =20 static inline struct regulator_init_data * diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regula= tor.c index d557f7b1ec7c..d924f5c1de59 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -550,7 +550,73 @@ struct regulator_init_data *regulator_of_get_init_data= (struct device *dev, return NULL; } =20 -struct regulator_dev *of_find_regulator_by_node(struct device_node *np) +/** + * of_get_child_regulator - get a child regulator device node + * based on supply name + * @parent: Parent device node + * @prop_name: Combination regulator supply name and "-supply" + * + * Traverse all child nodes. + * Extract the child regulator device node corresponding to the supply nam= e. + * returns the device node corresponding to the regulator if found, else + * returns NULL. + */ +static struct device_node *of_get_child_regulator(struct device_node *pare= nt, + const char *prop_name) +{ + struct device_node *regnode =3D NULL; + struct device_node *child =3D NULL; + + for_each_child_of_node(parent, child) { + regnode =3D of_parse_phandle(child, prop_name, 0); + + if (!regnode) { + regnode =3D of_get_child_regulator(child, prop_name); + if (regnode) + goto err_node_put; + } else { + goto err_node_put; + } + } + return NULL; + +err_node_put: + of_node_put(child); + return regnode; +} + +/** + * of_get_regulator - get a regulator device node based on supply name + * @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(struct device *dev, const char= *supply) +{ + struct device_node *regnode =3D NULL; + char prop_name[64]; /* 64 is max size of property name */ + + dev_dbg(dev, "Looking up %s-supply from device tree\n", supply); + + snprintf(prop_name, 64, "%s-supply", supply); + regnode =3D of_parse_phandle(dev->of_node, prop_name, 0); + + if (!regnode) { + regnode =3D of_get_child_regulator(dev->of_node, prop_name); + if (regnode) + return regnode; + + dev_dbg(dev, "Looking up %s property in node %pOF failed\n", + prop_name, dev->of_node); + return NULL; + } + return regnode; +} + +static struct regulator_dev *of_find_regulator_by_node(struct device_node = *np) { struct device *dev; =20 @@ -559,6 +625,40 @@ struct regulator_dev *of_find_regulator_by_node(struct= device_node *np) return dev ? dev_to_rdev(dev) : NULL; } =20 +/** of_regulator_dev_lookup - lookup a regulator device with device tree o= nly + * @dev: Device pointer for regulator supply lookup. + * @supply: Supply name or regulator ID. + * + * If successful, returns a struct regulator_dev that corresponds to the n= ame + * @supply and with the embedded struct device refcount incremented by one. + * The refcount must be dropped by calling put_device(). + * On failure one of the following ERR-PTR-encoded values is returned: + * -ENODEV if lookup fails permanently, -EPROBE_DEFER if lookup could succ= eed + * in the future. + */ +struct regulator_dev *of_regulator_dev_lookup(struct device *dev, + const char *supply) +{ + struct regulator_dev *r; + struct device_node *node; + + node =3D of_get_regulator(dev, supply); + if (node) { + r =3D of_find_regulator_by_node(node); + of_node_put(node); + if (r) + return r; + + /* + * We have a node, but there is no device. + * assume it has not registered yet. + */ + return ERR_PTR(-EPROBE_DEFER); + } + + return ERR_PTR(-ENODEV); +} + /* * Returns number of regulators coupled with rdev. */ --=20 2.46.0.184.g6999bdac58-goog