From patchwork Wed Sep 29 04:42:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 12524629 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D06BC433EF for ; Wed, 29 Sep 2021 04:46:09 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 0DC8D61247 for ; Wed, 29 Sep 2021 04:46:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0DC8D61247 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sholland.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=UV9xdL1wxfUYlTwUy1C++f9oxv76YQ8BWLuiDkD8m1Y=; b=Jc4xUuwRS14U0H OcK9ZqSsswhscDV0B/6CYdztWgQNAwrcx5RweBcJ0L+ZDoOAqSiOnlIhFH18kI9Og7EGsDrdxyRcb VrDlh+yK9u8e5bsDLs4+mpzEEpHLu0cRIZK1CER7mXjwr99OsIgyQjIbzXQJZmCl+yHMZTpOqUqQV wBmt3/AaNJzpsHMk4hlJf2jsQ4BITWDn8sr24bdeLfVbAGkfcFl4JB7859Fy8F8GODzdqjzi3BS+u vKPM0G+nczyh2vL7D/shAsnYfFCDyYGThfojorRWjxpkiTkpGfPEo/RH2TyUiS/gd5dHVVNrux7jZ l727Lj8PBBIfTBAX/xzA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVRRF-009zsZ-UR; Wed, 29 Sep 2021 04:43:26 +0000 Received: from new1-smtp.messagingengine.com ([66.111.4.221]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVRQq-009zjj-2h for linux-arm-kernel@lists.infradead.org; Wed, 29 Sep 2021 04:43:02 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id 765FB580DCC; Wed, 29 Sep 2021 00:42:59 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 29 Sep 2021 00:42:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sholland.org; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm3; bh=WoIva3nZ/OvlI FuKcUaObQyBgwdR2tNV2TTl4sUUNog=; b=S2C8vuFAYoR2BbXNgEq2fwZlLmD4m FmS1y3sN1Y5x3e1jtDXqzjFqVOYUvmkUpRfgVn4ebRLMK/4dNrITKyBzxYleLmWZ IMWcNJXdsJ6vBjuMytf6lg0YZlxcrnW1ix51DjaJwnCpSgAVRdrpx37jplmGxeEr eFRHVEar3PZemg177qeW1vixvTMnUlDFTHxgjFF+5upyEYu+EUPP4rYLm9+RANHs JcyI/ivhyAKNRaFfJhliTtOeAUCDAIGFRVs5UuIHJ4N6rmIe4cN8hgsUV7RdU234 XA81FgDXU5YKRQFlCw8Sqs6HEOf9+TWaS7QxLv+8kI08fQRIHSYcn5Oxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=WoIva3nZ/OvlIFuKcUaObQyBgwdR2tNV2TTl4sUUNog=; b=qv+hYIi+ /G0Z6cuudD85y+InDX6ojari7YLfKQQXv82OmU2NIAo1M8tak9X+704oYXlbuf9r /EkfJQsNE15Q+56vgp0UQhKJYssDAkHJWOq3WzfFftMZ3VCqVaXpginHzDiIHyW1 8jE5kdAXQO7W971Pn7mBpR5v97T29wyCp2kb/kevHnPktyK824er6MCUIePNZZiv zZOhqE+PmCzhexPPQHMytI+zB9kdkuuaH8o+w3pfd8siDTvaFe6FHvxNFBIQvUYy NF9Ru8MTMum281w/psAbTDcUH/hMaPBzHs1pnkT7EOrsYgDmzpRTsa8Ln4m/IguU Ddpj8vXkjQXFzg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrudekuddgkeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefurghmuhgv lhcujfholhhlrghnugcuoehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhgqeenucggtf frrghtthgvrhhnpeduhfejfedvhffgfeehtefghfeiiefgfeehgfdvvdevfeegjeehjedv gfejheeuieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehsrghmuhgvlhesshhhohhllhgrnhgurdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 29 Sep 2021 00:42:58 -0400 (EDT) From: Samuel Holland To: MyungJoo Ham , Kyungmin Park , Chanwoo Choi , Maxime Ripard , Chen-Yu Tsai , Jernej Skrabec , Rob Herring Cc: Michael Turquette , Stephen Boyd , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH 04/10] PM / devfreq: Add a recommended frequency helper Date: Tue, 28 Sep 2021 23:42:48 -0500 Message-Id: <20210929044254.38301-5-samuel@sholland.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210929044254.38301-1-samuel@sholland.org> References: <20210929044254.38301-1-samuel@sholland.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210928_214300_222524_1A3063D1 X-CRM114-Status: GOOD ( 15.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This helper peforms the same function as devfreq_recommended_opp(). However, it works on devices without OPPs by iterating over freq_table. Since freq_table is assumed to be sorted in ascending order, the algorithm is relatively simple. Devices with OPPs should continue using devfreq_recommended_opp(), as that function respects disabled OPPs. Signed-off-by: Samuel Holland --- drivers/devfreq/devfreq.c | 27 +++++++++++++++++++++++++++ include/linux/devfreq.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c index f5d27f5285db..fd46792297ad 100644 --- a/drivers/devfreq/devfreq.c +++ b/drivers/devfreq/devfreq.c @@ -1984,6 +1984,33 @@ subsys_initcall(devfreq_init); * OPP framework. */ +/** + * devfreq_recommended_freq() - Helper function to get the proper frequency from + * freq_table for the value given to target callback. + * @devfreq: The devfreq device. + * @freq: The frequency given to target function. + * @flags: Flags handed from devfreq framework. + */ +void devfreq_recommended_freq(struct devfreq *devfreq, + unsigned long *freq, u32 flags) +{ + const unsigned long *min = devfreq->profile->freq_table; + const unsigned long *max = min + devfreq->profile->max_state - 1; + const unsigned long *f; + + if (flags & DEVFREQ_FLAG_LEAST_UPPER_BOUND) { + /* Find the first item lower than freq, or else min. */ + for (f = max; f > min && *f > *freq; --f) + ; + } else { + /* Find the first item higher than freq, or else max. */ + for (f = min; f < max && *f < *freq; ++f) + ; + } + *freq = *f; +} +EXPORT_SYMBOL(devfreq_recommended_freq); + /** * devfreq_recommended_opp() - Helper function to get proper OPP for the * freq value given to target callback. diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h index 142474b4af96..4d324fea8a78 100644 --- a/include/linux/devfreq.h +++ b/include/linux/devfreq.h @@ -239,6 +239,8 @@ void devfreq_resume(void); int update_devfreq(struct devfreq *devfreq); /* Helper functions for devfreq user device driver with OPP. */ +void devfreq_recommended_freq(struct devfreq *devfreq, + unsigned long *freq, u32 flags); struct dev_pm_opp *devfreq_recommended_opp(struct device *dev, unsigned long *freq, u32 flags); int devfreq_register_opp_notifier(struct device *dev,