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: 4178491 Return-Path: X-Original-To: patchwork-linux-pm@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 0E3F09F1C0 for ; Wed, 14 May 2014 22:33:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D657202FF for ; Wed, 14 May 2014 22:33:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 49ABC20265 for ; Wed, 14 May 2014 22:33:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754015AbaENWdM (ORCPT ); Wed, 14 May 2014 18:33:12 -0400 Received: from mail-qc0-f169.google.com ([209.85.216.169]:42012 "EHLO mail-qc0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752694AbaENWdK (ORCPT ); Wed, 14 May 2014 18:33:10 -0400 Received: by mail-qc0-f169.google.com with SMTP id e16so404406qcx.28 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 Cc: Michal Simek , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, cpufreq@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Soren Brinkmann 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 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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