From patchwork Tue Nov 15 07:36:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corentin LABBE X-Patchwork-Id: 20228 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2571914wru; Mon, 14 Nov 2022 23:39:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf7BLDnrPmzjDTGl11Ohii/9CW5TfyBTFPZQ0GOCbt51TZ5pCZeySKQ/iDdM/ifFMVdmumna X-Received: by 2002:aa7:92ca:0:b0:56c:6bcc:cf0e with SMTP id k10-20020aa792ca000000b0056c6bcccf0emr17177807pfa.64.1668497956268; Mon, 14 Nov 2022 23:39:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668497956; cv=none; d=google.com; s=arc-20160816; b=L9jibeNaK9KRJZyGXdcwFMe5V8ivxCfX9I42jhENzdgXAd9dirLAiFIC3fXD/XRoBk DU1HaxID8CBXmdgOgeITCWc8K8aN1WMq71HwhKCn/OsnE/UmpYhSyRMhsFqPlAgy9zyn Jm0Ji9vCOsJKEqQkFwcBITqHPzE9Mzj8QA+RYnEVTRdBch31zq1+n/57SJYmAO68p1QV IBsf1s56H7kr/Qu43nodxTDFP/B33X2ZXy+n/hk7qZXxDGwPX/T4N0kDUT/RUHMtZuum VgP11pRM42ZEa2IFCdLRyCgSNv+qB9lEbXT3VQBanIn1JQUtvfiMghzozVtek+w5sHxV DBaA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m21-20020a170902d19500b00186971db5fbsi10346649plb.220.2022.11.14.23.39.02; Mon, 14 Nov 2022 23:39:16 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749546912941615972?= X-GMAIL-MSGID: =?utf-8?q?1749546912941615972?= 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) {