From patchwork Wed May 14 22:30:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Soren Brinkmann X-Patchwork-Id: 4178581 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B78499F1C0 for ; Wed, 14 May 2014 22:36:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D4BEE20306 for ; Wed, 14 May 2014 22:36:14 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB637202EB for ; Wed, 14 May 2014 22:36:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wkhk9-0003n6-4z; Wed, 14 May 2014 22:33:45 +0000 Received: from mail-qc0-x22c.google.com ([2607:f8b0:400d:c01::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wkhjv-0003h5-3d for linux-arm-kernel@lists.infradead.org; Wed, 14 May 2014 22:33:31 +0000 Received: by mail-qc0-f172.google.com with SMTP id l6so402183qcy.17 for ; Wed, 14 May 2014 15:33:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=HhstVSYhIqzpb4aKlqBWWKMeqGFtU0AJYewogGyDxLg=; b=NR8fvP3FqEEDEiETRV8LiNZzGifaKgnMgzxfsbdQjJIR70nMzJSAP2sdcR+EqJW4q9 /Z3jLV6JdCUpV9cJdhZvzuFvtC1EebrO+UlhKSwk1/Is5OrDLTAhOZNlXQjN31RF6wsB /qiyfQ+U799WMONIWiQgU1h7YIvfuv/LgUvnRbQPz19nNaYM9cortX/K5Nmwqz53xjCf 0knE7REQNSL/jOapzuarOrzCp4BSR1aOaqu5loghQxdPDX8Sj1U5/DNMXwMwbgnhlWbU tV9wCR4yXyabWIKQMVRQD9nE6Xi4/yZAIp3DliLiChN8r3jW99RWqomdR/HPs9Qbvrex pQIA== X-Received: by 10.224.40.76 with SMTP id j12mr7813612qae.90.1400106789387; Wed, 14 May 2014 15:33:09 -0700 (PDT) Received: from localhost ([149.199.62.254]) by mx.google.com with ESMTPSA id j1sm4903842qan.32.2014.05.14.15.33.08 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 14 May 2014 15:33:08 -0700 (PDT) From: Soren Brinkmann To: Mike Turquette , "Rafael J. Wysocki" , Viresh Kumar , Russell King Subject: [RFC PATCH 2/5] clk: Introduce 'clk_round_rate_nearest()' Date: Wed, 14 May 2014 15:30:52 -0700 Message-Id: <1400106655-22465-3-git-send-email-soren.brinkmann@xilinx.com> X-Mailer: git-send-email 1.9.3.1.ga73a6ad In-Reply-To: <1400106655-22465-1-git-send-email-soren.brinkmann@xilinx.com> References: <1400106655-22465-1-git-send-email-soren.brinkmann@xilinx.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140514_153331_255341_A557ED54 X-CRM114-Status: GOOD ( 14.37 ) X-Spam-Score: 0.0 (/) Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, cpufreq@vger.kernel.org, Michal Simek , Soren Brinkmann , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce a new API function to round a rate to the closest possible rate the HW clock can generate. In contrast to 'clk_round_rate()' which works similar, but always returns a frequency <= its input rate. The code comes from Uwe and was copied from this LKML thread: https://lkml.org/lkml/2013/3/21/115 Signed-off-by: Soren Brinkmann --- drivers/clk/clk.c | 26 ++++++++++++++++++++++++-- include/linux/clk.h | 14 ++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index dff0373f53c1..b715f5a9826c 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1011,8 +1011,9 @@ unsigned long __clk_round_rate(struct clk *clk, unsigned long rate) * @rate: the rate which is to be rounded * * Takes in a rate as input and rounds it to a rate that the clk can actually - * use which is then returned. If clk doesn't support round_rate operation - * then the parent rate is returned. + * use and does not exceed the requested frequency, which is then returned. + * If clk doesn't support round_rate operation then the parent rate + * is returned. */ long clk_round_rate(struct clk *clk, unsigned long rate) { @@ -1027,6 +1028,27 @@ long clk_round_rate(struct clk *clk, unsigned long rate) EXPORT_SYMBOL_GPL(clk_round_rate); /** + * clk_round_rate_nearest - round the given rate for a clk + * @clk: the clk for which we are rounding a rate + * @rate: the rate which is to be rounded + * + * Takes in a rate as input and rounds it to the closest rate that the clk + * can actually use which is then returned. If clk doesn't support + * round_rate operation then the parent rate is returned. + */ +long clk_round_rate_nearest(struct clk *clk, unsigned long rate) +{ + long lower_limit = clk_round_rate(clk, rate); + long upper_limit = clk_round_rate(clk, rate + (rate - lower_limit)); + + if (rate - lower_limit < upper_limit - rate) + return lower_limit; + else + return upper_limit; +} +EXPORT_SYMBOL_GPL(clk_round_rate_nearest); + +/** * __clk_notify - call clk notifier chain * @clk: struct clk * that is changing rate * @msg: clk notifier type (see include/linux/clk.h) diff --git a/include/linux/clk.h b/include/linux/clk.h index fb5e097d8f72..2f83bf030ac6 100644 --- a/include/linux/clk.h +++ b/include/linux/clk.h @@ -255,15 +255,25 @@ void devm_clk_put(struct device *dev, struct clk *clk); /** - * clk_round_rate - adjust a rate to the exact rate a clock can provide + * clk_round_rate - round a rate to the exact rate a clock can provide not + * exceeding @rate * @clk: clock source * @rate: desired clock rate in Hz * - * Returns rounded clock rate in Hz, or negative errno. + * Returns rounded clock rate in Hz, or parent rate */ long clk_round_rate(struct clk *clk, unsigned long rate); /** + * clk_round_rate_nearest - round a rate to the exact rate a clock can provide + * @clk: the clk for which we are rounding a rate + * @rate: the rate which is to be rounded + * + * Returns rounded clock rate in Hz, or parent rate + */ +long clk_round_rate_nearest(struct clk *clk, unsigned long rate); + +/** * clk_set_rate - set the clock rate for a clock source * @clk: clock source * @rate: desired clock rate in Hz