From patchwork Wed Feb 5 08:37:38 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: 3585161 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D20F3C02DC for ; Wed, 5 Feb 2014 08:42:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E8EC6201B6 for ; Wed, 5 Feb 2014 08:42:54 +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 EA9DD201B4 for ; Wed, 5 Feb 2014 08:42:53 +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 1WAy3S-0005ha-Ir; Wed, 05 Feb 2014 08:41:58 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WAy3H-0003Op-He; Wed, 05 Feb 2014 08:41:47 +0000 Received: from mail-wg0-f47.google.com ([74.125.82.47]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WAy31-0003Lh-VN for linux-arm-kernel@lists.infradead.org; Wed, 05 Feb 2014 08:41:33 +0000 Received: by mail-wg0-f47.google.com with SMTP id m15so53259wgh.26 for ; Wed, 05 Feb 2014 00:41:10 -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=Rjq/Qwd+GEk3vCEoFc2lodDbSKNpnhrhpzf7r3m2DR8=; b=UJk8kgIi5/3ZFRpU8eUHcwsuwx1FAWcVYEQhGm28Lj4ZgEyViC9GCAMvv07eRtvpo4 qjtCzDQc2JLvyHuk0jO/u5pW7S2b9Up2wGYQ3JVxACiyP5SW8UwmFHXx19zRd9Mnz9mR MCpl3HdW7UGN4dxUv6VFHZZjtlOudMhBTYuJCfpWhv/oiFnyOVYY58IVGcx6IaGgKUjd rsjhpdPkWcMcfArnngdD4sHgX8T9x9650shm7yMax2+SyNMvRzxgDzNkvvmXpFY2X16a BAAwhoH80dkJlMwFnrt20yMZTg5bSBuD3txDPDhmeg5M2hxpASgy3YK4E5Qp8CdR1IOa L0uQ== X-Received: by 10.194.185.237 with SMTP id ff13mr262353wjc.64.1391589670463; Wed, 05 Feb 2014 00:41:10 -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.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Feb 2014 00:41:09 -0800 (PST) From: Jean-Jacques Hiblot To: nicolas.ferre@atmel.com, mturquette@linaro.org Subject: [PATCH v2 4/4] clk: at91: optimization of the determine_rate callback Date: Wed, 5 Feb 2014 09:37:38 +0100 Message-Id: <1391589458-28018-5-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_151142_91FC1D82 X-CRM114-Status: GOOD ( 11.19 ) X-Spam-Score: -2.6 (--) Cc: jason@lakedaemon.net, Jean-Jacques Hiblot , 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 Signed-off-by: Boris BREZILLON Signed-off-by: Jean-Jacques Hiblot --- drivers/clk/at91/clk-programmable.c | 38 ++++++++----------------------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/drivers/clk/at91/clk-programmable.c b/drivers/clk/at91/clk-programmable.c index 7bcc725..62e2509 100644 --- a/drivers/clk/at91/clk-programmable.c +++ b/drivers/clk/at91/clk-programmable.c @@ -139,43 +139,21 @@ static int clk_programmable_set_rate(struct clk_hw *hw, unsigned long rate, struct clk_programmable *prog = to_clk_programmable(hw); struct at91_pmc *pmc = prog->pmc; const struct clk_programmable_layout *layout = prog->layout; - unsigned long best_rate = parent_rate; - unsigned long best_diff; - unsigned long new_diff; - unsigned long cur_rate; + unsigned long div = parent_rate / rate; int shift = 0; u32 tmp = pmc_read(pmc, AT91_PMC_PCKR(prog->id)) & ~(PROG_PRES_MASK << layout->pres_shift); - if (rate > parent_rate) - return parent_rate; - else - best_diff = parent_rate - rate; + if (!div) + return -EINVAL; - if (!best_diff) { - pmc_write(pmc, AT91_PMC_PCKR(prog->id), tmp | shift); - return 0; - } - - for (shift = 1; shift < PROG_PRES_MASK; shift++) { - cur_rate = parent_rate >> shift; - - if (cur_rate > rate) - new_diff = cur_rate - rate; - else - new_diff = rate - cur_rate; - - if (!new_diff) - break; + shift = fls(div) - 1; - if (new_diff < best_diff) { - best_diff = new_diff; - best_rate = cur_rate; - } + if (div != (1< cur_rate) - break; - } + if (shift >= PROG_PRES_MASK) + return -EINVAL; pmc_write(pmc, AT91_PMC_PCKR(prog->id), tmp | (shift << layout->pres_shift));