Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp797055iob; Wed, 18 May 2022 13:13:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+f3+NHiDXsj0piYkPC6ce4HxWHT14PjKQsjAmwilUccfFKdfAOrzAx6Rb2ditN5yZxlg8 X-Received: by 2002:a17:902:e484:b0:161:6657:dc5b with SMTP id i4-20020a170902e48400b001616657dc5bmr1301277ple.2.1652904806571; Wed, 18 May 2022 13:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652904806; cv=none; d=google.com; s=arc-20160816; b=CK2XOuakQHGifurLWWln5iaX75shzYk1g3BImj/HZefBvviEWjXP3oIV9ZqxWhvLWY kKJ+WArOjMgUxdlV7dJaTQ/9wokXClqTFB5wPaOOgeVrVznCKAH9Wafs8F1l9tf3vOHE Yql7EXTfA9MjYDRrQV2kORIL3/puT+ljFjUSKnZMnsBsCTB4WGxL3f+8qYga2SJcqIgM n9PA4IQTRTp+SU0T3FqQ6YLhdRI9bDvLPndIRGiA5o9Koa5SaoIMsvxl1LB3mgcdO6Xj Pm1K7bcxQJEvbg/1AORvLFwVu6hIaWIzpBfLTwJEATsrOgWW0vQuMYhCHkREWQKeW5y5 UTKw== 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=SriQP5QFvjv+22faclUlTpDEJWTfd/KIKG1YNKb9hlI=; b=WSZLKlz1D2Jjftf4QJ1nBPN4B/5vl+99UUShNevrlSPVGOBT7B/I5F3Pvl1uojdL92 NFL2nO3RG/dRvIF7cVbLruQ1MXOyDXn9Sv6IgQkuRN+gq1m/TKRTVMX4iVAMFQ4w6O/Z Jh1vsR+8WfquVDC6G844YzwKHWz4hwwPQcYjhOie2V/5rwsb3Qdgkir45JeRlHC5105m fmVJSSgO+XXv/vzFuGcSZsrFrF6UU1l6tcF0/r9im5qsUHD8VMAfTmYoJ/zOuTMn4UiQ rVuXeQHeeDbBqsbZqbXGmM6sSgtlXol5nFl7IdnRo3X2whJza82U+O+uYTdccWyoUMf4 MbHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=J4LewnuH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t9-20020a170902bc4900b00161b60ec148si3420105plz.172.2022.05.18.13.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:13:26 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20210112.gappssmtp.com header.s=20210112 header.b=J4LewnuH; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0140244F39; Wed, 18 May 2022 13:10:31 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242377AbiERUKE (ORCPT + 99 others); Wed, 18 May 2022 16:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242350AbiERUJv (ORCPT ); Wed, 18 May 2022 16:09:51 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70A512375DD for ; Wed, 18 May 2022 13:09:50 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id w4so4131462wrg.12 for ; Wed, 18 May 2022 13:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SriQP5QFvjv+22faclUlTpDEJWTfd/KIKG1YNKb9hlI=; b=J4LewnuHwL3OxcTIVsMV6xN29ahSYB41PufuCCLLZzBavi8wqCUKbAi0RjpMnBEpa5 noxOj3l/Q0xa0pfPtdvf18gKW9Zb/EZaRa/SOxIXnyxjw+nuiJb5QP5Q6GQR5P1GglVi JFHu9Ng85tUZ/O9Sni3weCi6mg7weoktZDBqFRtWbtamXTRTq3qS6/kmEPrzaItPPhXM KyOlMGsf+AphBrM5hvPo9sL4hpneCx/gYzeyF2xGgBAX7rF84qgKn4c3qUhmUOWjcsDg tHhCmxt7XboKoK+gHTmUYvQd0fnpwDrMxVY+s2J+1UdWz6fGjXwJ8f6y7QumTnTlUZ3R AZTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SriQP5QFvjv+22faclUlTpDEJWTfd/KIKG1YNKb9hlI=; b=naQcGApTybp6BQzl+V9biY0BDoKmb1+8WzyuOXj01eilD5ABx+dC7Slp0I8b+oetWI QgwTdF2w2K8JPrFEnJWiheCZ9UR210qaEA3j7EaQa/KeePObJSnqNPCMFfHqRcWwL4wU R2B6xSB1Bi+gug9qnt59lJhYLQUtEjezHTBhXnwk9FtD8k+9IPYYFxey9gBt4UTdf8MH 3L+xfTpD0PWNhlqnG2/+euh1K3bCnWYTYQNBMe50wpEIQ1uDog7LYD2JdQC/hs3zKpLe VwIpAqSsThcpLU7Ychjswvi2hq2RKw6WaL51liryD2r0dG9L40oDDpuZQYRq2K3ikUpT Vz0Q== X-Gm-Message-State: AOAM530ioZk+uhYwyhsl4PaSoczGuAUdZhbNY2xxLaBke8VzYSIjc8rG Tg0V6l2u9+bMZ3bNSa/YM0LTAw== X-Received: by 2002:a05:6000:186f:b0:20c:5f3d:44a4 with SMTP id d15-20020a056000186f00b0020c5f3d44a4mr1126253wri.152.1652904588901; Wed, 18 May 2022 13:09:48 -0700 (PDT) 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 o23-20020a05600c511700b0039456c00ba7sm6859281wms.1.2022.05.18.13.09.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:09:48 -0700 (PDT) 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, Corentin Labbe Subject: [PATCH v2 2/5] regulator: Add regulator_bulk_get_all Date: Wed, 18 May 2022 20:09:36 +0000 Message-Id: <20220518200939.689308-3-clabbe@baylibre.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518200939.689308-1-clabbe@baylibre.com> References: <20220518200939.689308-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,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 get names from a regulators list. Signed-off-by: Corentin Labbe --- drivers/regulator/core.c | 49 ++++++++++++++++++++++++++++++ include/linux/regulator/consumer.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 09578c3595de..719ce9a0db1b 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c @@ -4849,6 +4849,55 @@ static void regulator_bulk_enable_async(void *data, async_cookie_t cookie) bulk->ret = regulator_enable(bulk->consumer); } +/** + * regulator_bulk_get_all - get multiple regulator consumers + * + * @dev: Device to supply + * @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 regulator_bulk_get_all(struct device *dev, struct device_node *np, + struct regulator_bulk_data **consumers) +{ + int num_consumers; + int i, ret; + struct regulator *tmp; + const char *p; + + num_consumers = of_property_count_elems_of_size(np, "regulators", + sizeof(phandle)); + if (num_consumers <= 0) + return num_consumers; + + ret = of_property_count_strings(np, "regulator-names"); + if (ret != num_consumers) { + dev_err(dev, "regulators and regulator-names does not have the same size\n"); + return -EINVAL; + } + *consumers = kmalloc_array(num_consumers, sizeof(struct regulator_bulk_data), GFP_KERNEL); + if (!*consumers) + return -ENOMEM; + for (i = 0; i < num_consumers; i++) { + ret = of_property_read_string_helper(np, "regulator-names", &p, 1, i); + if (ret <= 0) + goto error; + tmp = regulator_get(dev, p); + (*consumers)[i].consumer = tmp; + } + return num_consumers; +error: + while (--i >= 0) + regulator_put(consumers[i]->consumer); + return ret; +} +EXPORT_SYMBOL_GPL(regulator_bulk_get_all); + /** * regulator_bulk_enable - enable multiple regulator consumers * diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index bbf6590a6dec..b9b1d1cbdd07 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h @@ -238,6 +238,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 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); int __must_check regulator_bulk_enable(int num_consumers, -- 2.35.1