From patchwork Thu Oct 20 20:42:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Reichel X-Patchwork-Id: 6387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp315382wrr; Thu, 20 Oct 2022 13:46:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5usEKG1cd0+rmCaVJQkj3DwwWOGGdi2Ak05oMePh5aJe6RHoxnRMt4WfVQ7f7kYM838Gjo X-Received: by 2002:a17:906:4fc3:b0:72e:eab4:d9d7 with SMTP id i3-20020a1709064fc300b0072eeab4d9d7mr12439413ejw.599.1666298804435; Thu, 20 Oct 2022 13:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666298804; cv=none; d=google.com; s=arc-20160816; b=Pwp5jFg61xJk9HQsD05hvR9RlwEI7G/qnuIJ2YFQJUbKGeTlaih4TyZohAT9X+6mD0 /zjLkA/b2y9YctNYCeVvAaB25YKAneOa9jXJKQTpHWwCVANMcGAKwdPGbHUEcXpXlzap o1a0V6V2iofM3gSgQyKpP5i4KfKDMa6zkYUQlIwAATbzuQpUJjLh6qYHUlcESVjDhD68 hnfMJA66X/6W8LUuUzt2gYmlxyu6xfYEmttOVSxK6TKCO9FDF10k/CmOSnB61gehnqLf kTUJt3RxrTqLel5DnxmXwmmC9eONADmX4psY13+JnygBgR6ol9dMBjJfV26XTeopoHeA C88A== 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=wa2x69kxWVPE3owbJBMzCKhQryTeOX3q7SrT0+d6gzo=; b=P8IbPuDbnNKoJ9q0YRT/THgFKYFqzsXCv+hia3VoC9G4hEuuGJ+Kw5Axhfw5WENG0z 7pP9W6oAndWBt76pcogb9v0rwZ/lGw4zvS9aDaduv5gUb8Q+xjQMGOd7uuespbxDj1PE yAmdR1HcDiKJkQo4WApBxS1xuL9v8KWbDbJacr7S9xEZu6NLxxBUA/NTchrhPbqC7ED6 w/tDp9U8nYNrvKHtco7Vb7MyU7NeQOXkhurMPGqh5AOaMc3+ASYCgHMWc5tcf/HTAeat vQ7Wp8IhDBEDuTDogRHnZ1SZQMLCr2xcRndX3ZDsPVtjJ7K8rdJNk/4siLkRkBqNiFlN wYig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=k6L3i3c5; 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=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx21-20020a0564020b5500b004602a5a1397si2384414edb.284.2022.10.20.13.46.20; Thu, 20 Oct 2022 13:46:44 -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=k6L3i3c5; 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=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229828AbiJTUnq (ORCPT + 99 others); Thu, 20 Oct 2022 16:43:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbiJTUnN (ORCPT ); Thu, 20 Oct 2022 16:43:13 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C4771FB79C; Thu, 20 Oct 2022 13:43:12 -0700 (PDT) Received: from jupiter.universe (dyndsl-091-096-059-009.ewe-ip-backbone.de [91.96.59.9]) (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 7C8B96602532; Thu, 20 Oct 2022 21:42:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1666298577; bh=9l2ogIEUX00Yo0bIs5uYnwOEpXhr3e3hBee9Uwelalo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k6L3i3c51QiTi3hhbMTz8QRxRyUdnjJGw/seCIfrVSoAVi3RD6KZ5RAoOtqhmvAFQ QaDVPk4MIy7V2rnWdOGBRkkJaWbd4RoR/2UZh6LldklHGFkh7d5MP+US6S5gu5ej+u 8Uev3NYPyAGzlcYjUzVVCAaLuzlUwTonT2e7pCycPftzppNoYNHVxyBS62ZeVZmsiV y2hjxmiBff5GeYrTVtdq9xv0e/D4xRVuiIZmuDZ3HbGOI2SIH+Fa2UmQCm1koVgqZx CJxy1wIMUbZuuvCe9++JBHQ1jC9hBAO7U3dEkf5uWwIiUgQlZ1bg+IU8e/dKDF1Xh0 R7jIN3XslBgpg== Received: by jupiter.universe (Postfix, from userid 1000) id 68DF64808A1; Thu, 20 Oct 2022 22:42:52 +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: [PATCHv4 12/13] regulator: expose regulator_find_closest_bigger Date: Thu, 20 Oct 2022 22:42:50 +0200 Message-Id: <20221020204251.108565-13-sebastian.reichel@collabora.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221020204251.108565-1-sebastian.reichel@collabora.com> References: <20221020204251.108565-1-sebastian.reichel@collabora.com> MIME-Version: 1.0 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, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747240935209937332?= X-GMAIL-MSGID: =?utf-8?q?1747240935209937332?= 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 --- 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 f9a7461e72b8..d6a3bb39d7dc 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 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);