Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6577324rwb; Tue, 15 Nov 2022 00:05:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7gxZZ14B6b7u/ReAkgDS52LlkIroBsysrqybpBsT7vtnXDiOrJLfo2duGLIBFi5qsQVmso X-Received: by 2002:a17:906:53c7:b0:780:8144:a41f with SMTP id p7-20020a17090653c700b007808144a41fmr13332507ejo.189.1668499519683; Tue, 15 Nov 2022 00:05:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668499519; cv=none; d=google.com; s=arc-20160816; b=CY4mtq2c4La3cbbyjz+TyeJKkSn1ulRZVy3GBSPxOtRogWUWAa5L3n2Ai7OpLWTYB8 RH1ELza46uD+VHp626jEcxddslEaDEBqYL77DkHhRJjLrB/FWlH8r9u0ToFTnx/j0NaL qY1/kAIWM3lky+VZmUBx5TT/ioW6AI5jx9caotHY++7ZV6tHMEGiL5lqI5+QD2D4vaHi 32jXvOxkcneDoffSYaFBPx5kALAzMT3Gtd3OBOg8wO9yLzAyo4O1R31uPXbp/nL4fAl9 FHGR31gJBNnlQ32YuJakRlmVQWo7nPwB+U6ehgglDNQojZlmrU0J8CfUO0kQ5S6ORVqj chxQ== 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=U/b/69ztk+aptsMOgAQxQD/dTqenV+HzjSfACGH7onc=; b=XhAwixs5TQrkDe4JdjKa1kSWxNnnzxFCKnntaqMNrAjTbsfW/jBXDKt3tnirpxcYjn z76kOoNrrfmP1m4jExyemsikFsKxYLzTxFjIz5MRyXSPuiEKJyY5BUtkHaf+BjIq59VR di31y37p/Us13PfYO9VQ5bRsMtIXILGydzYmPGP4az9f/PAgr03RcImuDQOefw5yhx4B YMTAc347xCLaQy7zvl8ffRUQuu54c5gKunhI48l3UCCgC9h9NQ/LcW9VSQe3fKn1xT+V HhIIdicoWEjs7uLZwaMspaYyoCR4z7mikN2uhy8l81jHwwcC6xzZykmYSw8jajRzophB X91w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=kfFW7nNB; 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 m21-20020a056402431500b00462e5d768b3si11871715edc.612.2022.11.15.00.04.55; Tue, 15 Nov 2022 00:05:19 -0800 (PST) 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=kfFW7nNB; 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 S231966AbiKOHgY (ORCPT + 88 others); Tue, 15 Nov 2022 02:36:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232421AbiKOHgP (ORCPT ); Tue, 15 Nov 2022 02:36:15 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3797A209B9 for ; Mon, 14 Nov 2022 23:36:14 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id i186-20020a1c3bc3000000b003cfe29a5733so2598638wma.3 for ; Mon, 14 Nov 2022 23:36:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; 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=U/b/69ztk+aptsMOgAQxQD/dTqenV+HzjSfACGH7onc=; b=kfFW7nNBy9y1NH/vtLXH1qcMRSZFvJhZSTlD6RUgpoKsd4z8Xk0zZlCvMM84IDkLz5 rnkrCf/OidYwiIK4MqFgMco/ZEoxgOmpJQtCcdkyM9OsOWM7YqjFkmXaDrtQwlT3/zeM k332/Yry/hrhX6V9epzsOwGUh/xN5IArxlmtqw9wZNSJpVKE7dccUpw/C7n3WUOTRhNG XpnGjh86LPFhIhMEJsrmrspLpX48eLRGmaONxfhb6pzoCYqJAAfVM+Qrsz5Nqce57N2L POCFZHTouB6elYP25kSjPhK8lVaVmaWxYhKH9+3CWqgDQW8jn0dNCrc5Z3h4Bq4tIMAF Q+9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=U/b/69ztk+aptsMOgAQxQD/dTqenV+HzjSfACGH7onc=; b=xsPzynpx1FEI71/TbeUau0veEUS2k6311QgVFRfCO3wQPggLPuQSINlS2Wrg/lWqav fxaJLSWxuzo/ODGKztESx0vRLEt6xHFQt+mKPCL0/fSYjFTs8YQHx1/UF352VqP9cFre Iw6+TmPs0UDonxlx7N5JKUy27kYJ+baqP5byBdV999TXnRiAwy+Zn7WWNGmCG8NET0lS nZbi+sTtnXHeK8RM/7zDcNwDz8OywYqhKDwd3EVekkAFM5kHDzTdLXFhO0MJ37PjWCh/ sEHYjG9Ek6W/4OqqtzffIyPBhG91inP8cGRmBnDKcMIqeh6g4JOUi0mvJI+2OIrZ9U6e 5o7g== X-Gm-Message-State: ANoB5pnMxykrYPbrnC72SGJC1NsW3zecj0FZK6zaAqy6QwskePhoh7HW izucKe1OL+6iEeP4sI0Eau8fkA== X-Received: by 2002:a05:600c:4196:b0:3c6:c05a:a50e with SMTP id p22-20020a05600c419600b003c6c05aa50emr433684wmh.81.1668497772752; Mon, 14 Nov 2022 23:36:12 -0800 (PST) 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 j13-20020a5d452d000000b0022cbf4cda62sm13836811wra.27.2022.11.14.23.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 23:36:12 -0800 (PST) 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, linux-sunxi@googlegroups.com, Corentin Labbe Subject: [PATCH v4 1/3] regulator: Add of_regulator_bulk_get_all Date: Tue, 15 Nov 2022 07:36:01 +0000 Message-Id: <20221115073603.3425396-2-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221115073603.3425396-1-clabbe@baylibre.com> References: <20221115073603.3425396-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,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 It work exactly like regulator_bulk_get() but instead of working on a provided list of names, it seek all consumers properties matching xxx-supply. Signed-off-by: Corentin Labbe --- drivers/regulator/of_regulator.c | 92 ++++++++++++++++++++++++++++++ include/linux/regulator/consumer.h | 8 +++ 2 files changed, 100 insertions(+) diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regulator.c index 0aff1c2886b5..584c92f1a317 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -701,3 +701,95 @@ struct regulator_dev *of_parse_coupled_regulator(struct regulator_dev *rdev, return c_rdev; } + +/* + * Check if name is a supply name according to the '*-supply' pattern + * return 0 if false + * return length of supply name without the -supply + */ +static int is_supply_name(const char *name) +{ + int strs, i; + + strs = strlen(name); + /* string need to be at minimum len(x-supply) */ + if (strs < 8) + return 0; + for (i = strs - 6; i > 0; i--) { + /* find first '-' and check if right part is supply */ + if (name[i] != '-') + continue; + if (strcmp(name + i + 1, "supply") != 0) + return 0; + return i; + } + return 0; +} + +/* + * of_regulator_bulk_get_all - get multiple regulator consumers + * + * @dev: Device to supply + * @np: device node to search for consumers + * @consumers: Configuration of consumers; clients are stored here. + * + * @return number of regulators on success, an errno on failure. + * + * This helper function allows drivers to get several regulator + * consumers in one operation. If any of the regulators cannot be + * acquired then any regulators that were allocated will be freed + * before returning to the caller. + */ +int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, + struct regulator_bulk_data **consumers) +{ + int num_consumers = 0; + struct regulator *tmp; + struct property *prop; + int i, n = 0, ret; + char name[64]; + + *consumers = NULL; + + /* + * first pass: get numbers of xxx-supply + * second pass: fill consumers + */ +restart: + for_each_property_of_node(np, prop) { + i = is_supply_name(prop->name); + if (i == 0) + continue; + if (!*consumers) { + num_consumers++; + continue; + } else { + memcpy(name, prop->name, i); + name[i] = '\0'; + tmp = regulator_get(dev, name); + if (!tmp) { + ret = -EINVAL; + goto error; + } + (*consumers)[n].consumer = tmp; + n++; + continue; + } + } + if (*consumers) + return num_consumers; + if (num_consumers == 0) + return 0; + *consumers = kmalloc_array(num_consumers, + sizeof(struct regulator_bulk_data), + GFP_KERNEL); + if (!*consumers) + return -ENOMEM; + goto restart; + +error: + while (--n >= 0) + regulator_put(consumers[n]->consumer); + return ret; +} +EXPORT_SYMBOL_GPL(of_regulator_bulk_get_all); diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 628a52b8e63f..39b666b40ea6 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -244,6 +244,8 @@ int regulator_disable_deferred(struct regulator *regulator, int ms); int __must_check regulator_bulk_get(struct device *dev, int num_consumers, struct regulator_bulk_data *consumers); +int __must_check of_regulator_bulk_get_all(struct device *dev, struct device_node *np, + struct regulator_bulk_data **consumers); int __must_check devm_regulator_bulk_get(struct device *dev, int num_consumers, struct regulator_bulk_data *consumers); void devm_regulator_bulk_put(struct regulator_bulk_data *consumers); @@ -481,6 +483,12 @@ static inline int devm_regulator_bulk_get(struct device *dev, int num_consumers, return 0; } +static inline int of_regulator_bulk_get_all(struct device *dev, struct device_node *np, + struct regulator_bulk_data **consumers) +{ + return 0; +} + static inline int regulator_bulk_enable(int num_consumers, struct regulator_bulk_data *consumers) { -- 2.37.4