From patchwork Fri Sep 9 17:55:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 12972033 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB0AFC6FA8A for ; Fri, 9 Sep 2022 17:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=I95Q9GvD95NjOVUwhq2QS+UFCu6Asr2vv5d4Pp6LOpQ=; b=3VBnFLeMOW9ray UEOYdQjmhOojKcU9eeAjkwaDv7dW9GyfXQPzXqCChmVkatITAtad8Clnq/kLv/TrIPUMDtHCTliYC U2hzrirONXoNnKFFzCcpbaSZlAR/CgXUxrHnt4XQdp5WVcyN+a+BzQTtFYNlLxZDIEMzMWLSPrPHn 3MvlJxy1j9Ros/QJTMOuDF7FGTb1XTd/I65+iyOzyv4Axueo8TAaHav5mKDqJPyuzJCN1UyTYEAKQ plyORstGDhqE9hgKYKjYkvRba1s7Xv+eH4zRf6O9EITx3UOAHAsgYwD41P6OrXT3za00K4LhpWMR6 OLXo8/0bqiv1yamv8bUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWiED-000u4A-VL; Fri, 09 Sep 2022 17:55:45 +0000 Received: from madras.collabora.co.uk ([46.235.227.172]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oWiE5-000trk-NX for linux-rockchip@lists.infradead.org; Fri, 09 Sep 2022 17:55:43 +0000 Received: from jupiter.universe (dyndsl-095-033-168-128.ewe-ip-backbone.de [95.33.168.128]) (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 29F7B6601FDD; Fri, 9 Sep 2022 18:55:31 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1662746131; bh=kzk3PENOBXyzcLbtO9AejMO4H0OZ0Ng5+GZx5DRtbtY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SLvAGZAOWH9Dh3mFAsovgdhPLnvlcCj+7jBmSUCTClvBllpaXTNvsItwYkKPIoF2/ NNBHLMEmx1nJ6+GbrpC5mc2rR0hXo2hl3ffMTyLMraPFbuI6w5InFEUPygZjcziqA4 A3+iYb5Xq344FvTQEl78b1f7COgFqJ6qFvr7wIieLQq0wuJSNAx7uNQeYl/z5OZQbB zLM9qHoS7N3BiGzlUYbdBGjD5rRVRO7yVsr2BgOJZMbp/N9tBpFfckdoalBqi+kWsW cEIKhiZUogtUF8inHYE+bKLQ42ZUen8dYnEroo0YkenLA4KOZ4ul6Sb71PWNKu4d8b 6y9HRTZYiQsXg== Received: by jupiter.universe (Postfix, from userid 1000) id 2C5EE4805A5; Fri, 9 Sep 2022 19:55:27 +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 Subject: [PATCHv3 12/14] regulator: expose regmap_find_closest_bigger Date: Fri, 9 Sep 2022 19:55:20 +0200 Message-Id: <20220909175522.179175-13-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220909175522.179175-1-sebastian.reichel@collabora.com> References: <20220909175522.179175-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220909_105537_999644_7BD56404 X-CRM114-Status: GOOD ( 15.90 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.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. Signed-off-by: Sebastian Reichel Acked-by: Matti Vaittinen --- drivers/regulator/helpers.c | 20 +++++++++++++++++--- include/linux/regulator/driver.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index ad2237a95572..eb1f18917d05 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -902,7 +902,20 @@ 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, +/** + * regmap_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 regmap_find_closest_bigger(unsigned int target, const unsigned int *table, unsigned int num_sel, unsigned int *sel) { unsigned int s, tmp, max, maxsel = 0; @@ -933,6 +946,7 @@ static int find_closest_bigger(unsigned int target, const unsigned int *table, return 0; } +EXPORT_SYMBOL_GPL(regmap_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 = regmap_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 f9a7461e72b8..9501dbec64da 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -757,6 +757,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 regmap_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);