From patchwork Mon Feb 17 15:24:51 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: 3663531 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 0E6359F1EE for ; Mon, 17 Feb 2014 15:28:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 31DB5201E7 for ; Mon, 17 Feb 2014 15:28:47 +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 46995201DE for ; Mon, 17 Feb 2014 15:28:46 +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 1WFQ7T-0004Dr-1w; Mon, 17 Feb 2014 15:28:31 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFQ7N-0001UK-IQ; Mon, 17 Feb 2014 15:28:25 +0000 Received: from mail-we0-f181.google.com ([74.125.82.181]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WFQ7K-0001Sq-Do for linux-arm-kernel@lists.infradead.org; Mon, 17 Feb 2014 15:28:23 +0000 Received: by mail-we0-f181.google.com with SMTP id w61so10864665wes.12 for ; Mon, 17 Feb 2014 07:28:00 -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=Bsz+cVFFzu53CkLeYd09awCuH3lMZdOniwTWm+vvolo=; b=Ue3R/CjmMvqUWmnN10emsCkAPj4GQZz3H05ebWTpzMnSgcQxVbS3S7QN0CoZ+ocnNq Z8LBbjEHy7D7EmH3HBOMSBCMsLtl8CjDSGJ3fVegDBg8ABVA2MZ+2p5dmPT9MdB8bRoN pk8eKsm+A52qBCb/KS3XaSIx6gNC4imAoMjx05AQUYo4VD1Le8vkJscmRH5PUdD7ZQmw j1pU4b9SniA5eYgazqWprnwmtnuAzW8Mk9l5M+zYevMCVPdYN06E2gts4BgMO2hyOEUF QZoFpB/Zfzinr5DuTIV4QrOUu14HI3BdRqOClkHTqmp2Nsk98HmPTfYyW4GHnuAZGEer dG5Q== X-Received: by 10.180.101.230 with SMTP id fj6mr13424770wib.27.1392650880449; Mon, 17 Feb 2014 07:28:00 -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 fm3sm33286283wib.8.2014.02.17.07.27.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Feb 2014 07:27:59 -0800 (PST) From: Jean-Jacques Hiblot To: nicolas.ferre@atmel.com, mturquette@linaro.org Subject: [PATCH v2] clk: at91: optimization of the set_rate callback Date: Mon, 17 Feb 2014 16:24:51 +0100 Message-Id: <1392650691-20215-1-git-send-email-jjhiblot@traphandler.com> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <52F1FC52.1040205@overkiz.com> References: <52F1FC52.1040205@overkiz.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140217_102822_572674_A1758458 X-CRM114-Status: GOOD ( 11.37 ) X-Spam-Score: -2.6 (--) Cc: linux-kernel@vger.kernel.org, Jean-Jacques Hiblot , jason@lakedaemon.net, 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.8 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 --- Hi, this fixes the commit's log as indicated by Boris. cheers, Jean-jacques 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));