Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp131747lqr; Wed, 5 Jun 2024 00:50:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1G8AUKkSuA8uTYXt5mmsQKOck9dHJgsRWx+YKth6l7j6PmaI3d+VzxmfbUHTrazHcwp5SQnfCMhVroRIAHfsxIERCAqVA8oeo4cDQMw== X-Google-Smtp-Source: AGHT+IENohyzTDPkIA3CeOuUQ2ZHBOMk9x2vBYRMTior/eWIl9BLqlZhgh9AC4WO6O2UIWmjFE3x X-Received: by 2002:a05:6214:4b09:b0:6ae:d419:74a8 with SMTP id 6a1803df08f44-6b02266c86fmr22523416d6.6.1717573844071; Wed, 05 Jun 2024 00:50:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717573844; cv=pass; d=google.com; s=arc-20160816; b=StWQk8jWyZFi1/YkJKHU5zQ25ufaOgZtxembvzmOI2pBO5Z3q7vn++aePWYuLHPn+K L6pbk6BtUWItg0u6akBOKyVW6VkD6en+0KPuWY6XaDJE3ADp9JWG1lzmovapNUIZwPm4 qPXvahSBnynSewcLzzTeiwnn0sSmRgMblldAbX1ZKItsJimk+EeUaOWxP+iz8A8vCfU7 dJyg2QtRNVkqV2/UwiAU+Pp6VAGGoCm6T/YtjumzNvT/Rh5LWUQX5Udxgc0teFXWIYwZ Mvu92wf8bK+ZlNYgeCSyXiBgzBAfF9qtEHXSpFND0lyWrrv1RGzvVBbB34JEMot1oEEA dCYQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JOPojFycEKbDb+6xYRN5lk81bk8N46X2BGBEfSW2AyQ=; fh=FZ/ltIMnVaZIqO21TN8T3V9sMo209SOp7YAT/NX3lAw=; b=KYdKfyBAWSTCh+BLVfA6kUQ2xcND7WeoFUuYy2IadbxzxWdpTvRGEnvA9qRrtd+6NX e4xE/qXgwkW1WArqg13OWj9iWZfeerDXgZrc87ZpOhh+5qQ00bFLFkyxsvmZitLka6Il KdWwQJLZqWwaxRtFn6IzyPjEC9L/ryKxl43LRqSnmXmihU09KNUiPbfUAxhvyNCox2y+ tZhNuFNizY37ItRyptUe7ptSfVLXg2D61Q2ZlZgIzbc1eR/IUifBiYGCWtXB9chF0gdN EOpdkVvVK2smR5aAPLuUOj6dMWUSesv0NN3+pCNoYLn99qDqcp7dR+E0mTov0T/wv1zm ookQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZYBtDMNP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-201903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201903-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6ae4a732b39si133178496d6.47.2024.06.05.00.50.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 00:50:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZYBtDMNP; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-201903-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201903-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B94E81C22177 for ; Wed, 5 Jun 2024 07:50:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ADB5618FDDF; Wed, 5 Jun 2024 07:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZYBtDMNP" Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3173718F2FF; Wed, 5 Jun 2024 07:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717573791; cv=none; b=GU8kMfX0Q4QGqF4N+84PdebpaQMvbNaiotQQMCoUUILKQZFY4OKQxcm663YvMV9hzrbqzwoSqwoa/WFqlQ6D+DnusraLcOUEfu3MevCQxhvSJmVNyFtfZteFxx3c7ln6MzDmhGPR5KUHdh2Lr0aRI8VWrBRDkOggW5jJcepOb7o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717573791; c=relaxed/simple; bh=GH/4yyA1cV2+k32gNINOfNb0ZQS63KppAFTgUxvFX1k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=lHALVC0/YruOZUxYkdtKHA3SJTSJ6aDIOz9q5PeO6vm0uJu3lRB4aeAGcZcekzHX/eWE4gER4cMMqb/aB+dbBhdgmzNpq1oRbO/zOO4U8zcJT43N97Bek5+lIBLAxorrj0zzYhAbp+oA8zUbFU1n31cq9fOzZtQKZOV1trcz78w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZYBtDMNP; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-421392b8156so18806875e9.3; Wed, 05 Jun 2024 00:49:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717573788; x=1718178588; darn=vger.kernel.org; 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=JOPojFycEKbDb+6xYRN5lk81bk8N46X2BGBEfSW2AyQ=; b=ZYBtDMNPkdh6k0aqbFpCqtHLGd+xZIWBcUseZR++Ph/hAPRgJ94k1qlTNsL3a3gqe9 yDC/od/P14SsyvgwB22uPoD5muUVt7CVbnx/tXoqO8KykIXf7lo/XJDSiyVOtDRlQRBr e8TMBwzwA5xiB1CMghc60Y4f/g/m0nrzZn3K19CkLqRg2zttUm8AMC9qeMzbIyYaw39W NXQ3QoCmLiRU0KK15dTFTVnwoMpAdFfnX0dAwKXCCDMYWd5LaDC8ODZTeRbI3kiM+Fqv jfXn1j6bDXb7hMHPLWXjAonSasOk29+73qIkuUT9dng97oKqcVyvKCwel7+BEZmSLwqA nYqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717573788; x=1718178588; 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=JOPojFycEKbDb+6xYRN5lk81bk8N46X2BGBEfSW2AyQ=; b=WlUFeEqcv53pXmpms2x/sO4jA/nNgIQ19o6Ijs6hx4BFIdc6LoUyypkdHulN4D/D8n ufbgnkt2NIE4pHAVixg6tnDK35oBSgvm4LTfWdzi6JCZcbTTv7I/CDLtr0ToF0uxAulo nk+xV6wf2H74BHXvHk+G87BkaJm/kJw6yTSMW5V8M6hWzQVzuGyQxUCKTd8mhRUaFCf7 ow1AjyMrexzkpg3MbtRkcDSie5z2bSNzJecCTUh801fEGSZEKAfXkj4V24LHTNgiz/WJ f7bZ137KcVp3QFRZivOnCS/thNjyyvOXbUUspqu72FFyy3lBMGPYacJ/RIOdEc6Z8adz cMSQ== X-Forwarded-Encrypted: i=1; AJvYcCUw+e772x6PworQjqrRjl7Odh+9ppiygdsj3EFoCAHcJmjma0A/DViftZq1Cw40GpCawYrpItxabN+cjkvGKne2sLaMHFm3EWyKWBBEme++bb3V8LHa2EcoYv1IU3vZui3hAJOGcToHgjNiUXBlwnbJDmQ6Enp9hTHBnc8ez74jnqXGBUTi2MoL1rom X-Gm-Message-State: AOJu0YwYN92t2S8fW/QjQVGdrRvjslmEuWBltXXAYmoaykCjLS/zu3hw j6U0o1RZ2hrNZMtVHEDBV+PhM2UZKJaKWsSuaXs4EGeTfd/DLhAs X-Received: by 2002:a05:600c:4e08:b0:421:5242:ee2 with SMTP id 5b1f17b1804b1-42156f8cfb8mr11024645e9.25.1717573788214; Wed, 05 Jun 2024 00:49:48 -0700 (PDT) Received: from prasmi.home ([2a00:23c8:2500:a01:2595:4364:d152:dff3]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35dd064bbb1sm13527200f8f.101.2024.06.05.00.49.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 00:49:47 -0700 (PDT) From: Prabhakar X-Google-Original-From: Prabhakar To: Geert Uytterhoeven , Ulf Hansson , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Wolfram Sang , Liam Girdwood , Mark Brown , Magnus Damm Cc: linux-mmc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, Prabhakar , Fabrizio Castro , Biju Das , Lad Prabhakar Subject: [RFC PATCH 2/4] regulator: core: Add regulator_map_voltage_descend() API Date: Wed, 5 Jun 2024 08:49:34 +0100 Message-Id: <20240605074936.578687-3-prabhakar.mahadev-lad.rj@bp.renesas.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605074936.578687-1-prabhakar.mahadev-lad.rj@bp.renesas.com> References: <20240605074936.578687-1-prabhakar.mahadev-lad.rj@bp.renesas.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Lad Prabhakar Similarly to regulator_map_voltage_ascend() api add regulator_map_voltage_descend() api and export it. Drivers that have descendant voltage list can use this as their map_voltage() operation. Signed-off-by: Lad Prabhakar --- drivers/regulator/helpers.c | 31 +++++++++++++++++++++++++++++++ include/linux/regulator/driver.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index 6e1ace660b8c..ac62d778e3c0 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -368,6 +368,37 @@ int regulator_map_voltage_ascend(struct regulator_dev *rdev, } EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend); +/** + * regulator_map_voltage_descend - map_voltage() for descendant voltage list + * + * @rdev: Regulator to operate on + * @min_uV: Lower bound for voltage + * @max_uV: Upper bound for voltage + * + * Drivers that have descendant voltage list can use this as their + * map_voltage() operation. + */ +int regulator_map_voltage_descend(struct regulator_dev *rdev, + int min_uV, int max_uV) +{ + int i, ret; + + for (i = rdev->desc->n_voltages - 1; i >= 0 ; i--) { + ret = rdev->desc->ops->list_voltage(rdev, i); + if (ret < 0) + continue; + + if (ret > min_uV) + break; + + if (ret >= min_uV && ret <= max_uV) + return i; + } + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(regulator_map_voltage_descend); + /** * regulator_map_voltage_linear - map_voltage() for simple linear mappings * diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index f230a472ccd3..6410c57ba85a 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h @@ -735,6 +735,8 @@ int regulator_map_voltage_iterate(struct regulator_dev *rdev, int min_uV, int max_uV); int regulator_map_voltage_ascend(struct regulator_dev *rdev, int min_uV, int max_uV); +int regulator_map_voltage_descend(struct regulator_dev *rdev, + int min_uV, int max_uV); int regulator_get_voltage_sel_pickable_regmap(struct regulator_dev *rdev); int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev, unsigned int sel); -- 2.34.1