From patchwork Wed Feb 5 08:37:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 3585171 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 DB3709F382 for ; Wed, 5 Feb 2014 08:43:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 391B6201B6 for ; Wed, 5 Feb 2014 08:43:30 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (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 45AF8201B4 for ; Wed, 5 Feb 2014 08:43:29 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WAy3b-0005mH-Pw; Wed, 05 Feb 2014 08:42:08 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WAy3N-0003PF-KD; Wed, 05 Feb 2014 08:41:53 +0000 Received: from mail-wi0-f178.google.com ([209.85.212.178]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WAy32-0003Lg-LE for linux-arm-kernel@lists.infradead.org; Wed, 05 Feb 2014 08:41:34 +0000 Received: by mail-wi0-f178.google.com with SMTP id cc10so292917wib.5 for ; Wed, 05 Feb 2014 00:41:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZjW2FC0Quj1DrOz1b3ktfbYOI5Q3KPpXgWLzQyHun7s=; b=RE6tBBMP68gwYmHjEkrGb/SfilSAf8TQu74DMKXVgWJ5Dv8PLYivcOPY/LvCn8YMOf sTtP0nq5F1Yx9Xfs/s9e+gXEX6+jw+B80/6LA5kPNB35LpjakhRHVuxcICQXZsBe4Ms8 DiZkwlsxP+8tKa92XDv3X2D4u9LPtWcdqXusJrLJ0EJLSAyoA1rBJCkSjrsYUqqs+OfC 4iSxyi/VVmokM+77mk/uTn9FHhh84xOAzT0+IC6TRdg0uOEzmvsajxz8knHbmJkmQJtO KSVKMrPxF8O3tk3XgD3Agt4RCfhhDT3b+SqNO5T+HtjJ09mxjdm2zDPMGznPRA/UGato BWlg== X-Received: by 10.180.103.227 with SMTP id fz3mr15778359wib.29.1391589665317; Wed, 05 Feb 2014 00:41:05 -0800 (PST) Received: from stedf17-labo202.ds.jdsu.net. (4-161.80-90.static-ip.oleane.fr. [90.80.161.4]) by mx.google.com with ESMTPSA id j9sm59538503wjz.13.2014.02.05.00.41.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Feb 2014 00:41:04 -0800 (PST) From: Jean-Jacques Hiblot To: nicolas.ferre@atmel.com, mturquette@linaro.org Subject: [PATCH v2 1/4] clk: at91: replace prog clk round_rate with determine_rate Date: Wed, 5 Feb 2014 09:37:35 +0100 Message-Id: <1391589458-28018-2-git-send-email-jjhiblot@traphandler.com> X-Mailer: git-send-email 1.8.5.2 In-Reply-To: <1391589458-28018-1-git-send-email-jjhiblot@traphandler.com> References: <1391589458-28018-1-git-send-email-jjhiblot@traphandler.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140205_034132_856365_6696D13B X-CRM114-Status: GOOD ( 11.35 ) X-Spam-Score: -2.6 (--) Cc: jason@lakedaemon.net, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, b.brezillon@overkiz.com 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 From: Boris BREZILLON Implement the determine_rate callback to choose the best parent clk that fulfills the requested rate. Signed-off-by: Boris BREZILLON --- drivers/clk/at91/clk-programmable.c | 56 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/drivers/clk/at91/clk-programmable.c b/drivers/clk/at91/clk-programmable.c index fd792b2..eff7016 100644 --- a/drivers/clk/at91/clk-programmable.c +++ b/drivers/clk/at91/clk-programmable.c @@ -102,40 +102,40 @@ static unsigned long clk_programmable_recalc_rate(struct clk_hw *hw, return parent_rate >> prog->pres; } -static long clk_programmable_round_rate(struct clk_hw *hw, unsigned long rate, - unsigned long *parent_rate) +static long clk_programmable_determine_rate(struct clk_hw *hw, + unsigned long rate, + unsigned long *best_parent_rate, + struct clk **best_parent_clk) { - unsigned long best_rate = *parent_rate; - unsigned long best_diff; - unsigned long new_diff; - unsigned long cur_rate; - int shift = shift; - - if (rate > *parent_rate) - return *parent_rate; - else - best_diff = *parent_rate - rate; - - if (!best_diff) - return best_rate; + struct clk *parent = NULL; + long best_rate = -EINVAL; + unsigned long parent_rate; + unsigned long tmp_rate; + int shift; + int i; - for (shift = 1; shift < PROG_PRES_MASK; shift++) { - cur_rate = *parent_rate >> shift; + for (i = 0; i < __clk_get_num_parents(hw->clk); i++) { + parent = clk_get_parent_by_index(hw->clk, i); + if (!parent) + continue; - if (cur_rate > rate) - new_diff = cur_rate - rate; - else - new_diff = rate - cur_rate; + parent_rate = __clk_get_rate(parent); + for (shift = 0; shift < PROG_PRES_MASK; shift++) { + tmp_rate = parent_rate >> shift; + if (tmp_rate <= rate) + break; + } - if (!new_diff) - return cur_rate; + if (tmp_rate > rate) + continue; - if (new_diff < best_diff) { - best_diff = new_diff; - best_rate = cur_rate; + if (best_rate < 0 || (rate - tmp_rate) < (rate - best_rate)) { + best_rate = tmp_rate; + *best_parent_rate = parent_rate; + *best_parent_clk = parent; } - if (rate > cur_rate) + if (!best_rate) break; } @@ -228,7 +228,7 @@ static const struct clk_ops programmable_ops = { .prepare = clk_programmable_prepare, .is_prepared = clk_programmable_is_ready, .recalc_rate = clk_programmable_recalc_rate, - .round_rate = clk_programmable_round_rate, + .determine_rate = clk_programmable_determine_rate, .get_parent = clk_programmable_get_parent, .set_parent = clk_programmable_set_parent, .set_rate = clk_programmable_set_rate,