Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp872868rwr; Thu, 4 May 2023 10:39:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6i19tfIX2GGeGTmZacp1NQtccpsWaA3tbcjgQ0i3/Du5mOY/LaKgAZbMuvCJOh9vV9/1Fk X-Received: by 2002:a17:902:7d85:b0:1a8:bc5:4912 with SMTP id a5-20020a1709027d8500b001a80bc54912mr4090125plm.52.1683221974822; Thu, 04 May 2023 10:39:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683221974; cv=none; d=google.com; s=arc-20160816; b=dLC6uLIT8H+SaAFgr8IKeUSnH4nS3tmGeWK3o2PqVCrl2numTfRtHAiWxdcIE7/FzS GYtkJsJL51JajZ+FQnUN5SSBDsvg7C7dpihXEhwStxXATd/CS5MxssVQGKosWiWKfzvB w2pviz5Os09hSlaXxC8FIEdHRJFelCRH9dvPJZtmIxG39Wc9pQWe7OEi6OASJLf+ZuZ1 t9CxBtdixX3rC9lC86JEmgkDY3UgzU+ggx/iIf2Ubl7DG/gBUO2j58I9l3ihL9Pt7WNo Ma+fUyNovBa1WSsMtoULYMjzk+uLUJDzK5lHLZW84NyM9CMinJ38k/YN6AdeglbezZh5 Ge0A== 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=nwr8OJDuMCaDHGORJIiiav9OSfPg1TAgdgnhs/prZ/A=; b=I3RgdU+4uy2IqgwbtpoUhVLZ2AeGarX3k+8MhqnJU9G6jyB+a/ToYXzf9eZ7TmkpYU YniDTIKpX9v7yT6vTF1bxm2si9RCSOSXW0OsEliEjntsVlk/7dgw+Fyp/fDGVD+y7xqN 1na6H20X66WwcSIJBqqAt1Xqnmpaq9cNauhUbWy+4TjwUAYNSmMGIFUjvfZkyGYURU/9 p6fnxN5JYhA5V8EuMTiSGXckRcQy2TkgTeCzdhB6GMbh6yTEpP1PWkUTtTZqoW7PuzJ2 Lrgbk3oQFhDNbcGE5oq3iIRUyS+sYRCpUhgKnvq8ahjPtyLo6fcKlTQ+Am0GHWhppSm/ jxCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=JqKTtmxM; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bc2-20020a170902930200b001aade552f84si12454904plb.93.2023.05.04.10.39.22; Thu, 04 May 2023 10:39:34 -0700 (PDT) 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=@collabora.com header.s=mail header.b=JqKTtmxM; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230106AbjEDRgu (ORCPT + 99 others); Thu, 4 May 2023 13:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230016AbjEDRga (ORCPT ); Thu, 4 May 2023 13:36:30 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 688345586; Thu, 4 May 2023 10:36:28 -0700 (PDT) Received: from jupiter.universe (dyndsl-091-248-211-176.ewe-ip-backbone.de [91.248.211.176]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: sre) by madras.collabora.co.uk (Postfix) with ESMTPSA id 307766605702; Thu, 4 May 2023 18:36:25 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1683221785; bh=X6eDCzkh4sNwrVY93vOLfEcsRkHyxCN7KA4Kl9mw1hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JqKTtmxMyaZGWGRoTzGuNU30OLXqXlxde5HpkbmVAjUC+VASoB56o4yuG3rOQUJVq jAsd/c+tt+ICLZG7CwGDQDhMKSCtfYnzHs4Zk+wtZz93ZRMjCBn8w5cRCqhT2zdllD tzb6v0KMmvmS2k46baEzVCfVDF0FmaQUsK9lPufmmCtU4GldxPGJroydOPK9wO37hn zo6FU4p2dGi21exPRjv+GWJa9ZgvhADLSKlaor/UhOJkP0PXhXo0SRop/3Um5VdsI3 H5ZwdD5vFNWZOsn8aur/Oo45hygNOf6Q+v4+7TxZ+2UuIh3IcczyJLrn3lOiM64umX Ctrl2vohiGV8w== Received: by jupiter.universe (Postfix, from userid 1000) id E44D24807F4; Thu, 4 May 2023 19:36:20 +0200 (CEST) From: Sebastian Reichel To: Heiko Stuebner , Rob Herring , Krzysztof Kozlowski , Lee Jones Cc: Michael Turquette , Stephen Boyd , Linus Walleij , Mark Brown , Liam Girdwood , Alexandre Belloni , Alessandro Zummo , linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel , kernel@collabora.com, Diederik de Haas , Vincent Legoll Subject: [PATCH v8 10/14] regulator: expose regulator_find_closest_bigger Date: Thu, 4 May 2023 19:36:14 +0200 Message-Id: <20230504173618.142075-11-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230504173618.142075-1-sebastian.reichel@collabora.com> References: <20230504173618.142075-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 Expose and document the table lookup logic used by regulator_set_ramp_delay_regmap, so that it can be reused for devices that cannot be configured via regulator_set_ramp_delay_regmap. Tested-by: Diederik de Haas # Rock64, Quartz64 Model A + B Tested-by: Vincent Legoll # Pine64 QuartzPro64 Signed-off-by: Sebastian Reichel --- drivers/regulator/helpers.c | 22 ++++++++++++++++++---- include/linux/regulator/driver.h | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index ad2237a95572..586f42e378ee 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -902,8 +902,21 @@ bool regulator_is_equal(struct regulator *reg1, struct regulator *reg2) } EXPORT_SYMBOL_GPL(regulator_is_equal); -static int find_closest_bigger(unsigned int target, const unsigned int *table, - unsigned int num_sel, unsigned int *sel) +/** + * regulator_find_closest_bigger - helper to find offset in ramp delay table + * + * @target: targeted ramp_delay + * @table: table with supported ramp delays + * @num_sel: number of entries in the table + * @sel: Pointer to store table offset + * + * This is the internal helper used by regulator_set_ramp_delay_regmap to + * map ramp delay to register value. It should only be used directly if + * regulator_set_ramp_delay_regmap cannot handle a specific device setup + * (e.g. because the value is split over multiple registers). + */ +int regulator_find_closest_bigger(unsigned int target, const unsigned int *table, + unsigned int num_sel, unsigned int *sel) { unsigned int s, tmp, max, maxsel = 0; bool found = false; @@ -933,6 +946,7 @@ static int find_closest_bigger(unsigned int target, const unsigned int *table, return 0; } +EXPORT_SYMBOL_GPL(regulator_find_closest_bigger); /** * regulator_set_ramp_delay_regmap - set_ramp_delay() helper @@ -951,8 +965,8 @@ int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay) if (WARN_ON(!rdev->desc->n_ramp_values || !rdev->desc->ramp_delay_table)) return -EINVAL; - ret = find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table, - rdev->desc->n_ramp_values, &sel); + ret = regulator_find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table, + rdev->desc->n_ramp_values, &sel); if (ret) { dev_warn(rdev_get_dev(rdev), diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index d3b4a3d4514a..c6ef7d68eb9a 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -758,6 +758,8 @@ int regulator_set_current_limit_regmap(struct regulator_dev *rdev, int min_uA, int max_uA); int regulator_get_current_limit_regmap(struct regulator_dev *rdev); void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data); +int regulator_find_closest_bigger(unsigned int target, const unsigned int *table, + unsigned int num_sel, unsigned int *sel); int regulator_set_ramp_delay_regmap(struct regulator_dev *rdev, int ramp_delay); int regulator_sync_voltage_rdev(struct regulator_dev *rdev); -- 2.39.2