From patchwork Tue Jan 19 14:51:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sperl X-Patchwork-Id: 8063221 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 626D99F744 for ; Tue, 19 Jan 2016 14:55:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8B51920439 for ; Tue, 19 Jan 2016 14:55:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB57020411 for ; Tue, 19 Jan 2016 14:55:46 +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 1aLXfg-0008NG-KI; Tue, 19 Jan 2016 14:54:12 +0000 Received: from 212-186-180-163.dynamic.surfer.at ([212.186.180.163] helo=cgate.sperl.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aLXeH-0007IH-F6; Tue, 19 Jan 2016 14:52:46 +0000 Received: from raspcm.intern.sperl.org (account martin@sperl.org [10.10.10.41] verified) by sperl.org (CommuniGate Pro SMTP 6.1.2) with ESMTPSA id 6392116; Tue, 19 Jan 2016 14:51:50 +0000 From: kernel@martin.sperl.org To: Rob Herring , Stephen Warren , Lee Jones , Eric Anholt , Michael Turquette , Stephen Boyd , Remi Pommarel , devicetree@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-clk@vger.kernel.org Subject: [RFC 5/9] clk: bcm2835: prefer clocks that use integer dividers Date: Tue, 19 Jan 2016 14:51:36 +0000 Message-Id: <1453215100-2382-6-git-send-email-kernel@martin.sperl.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1453215100-2382-1-git-send-email-kernel@martin.sperl.org> References: <1453215100-2382-1-git-send-email-kernel@martin.sperl.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160119_065245_710595_B084447A X-CRM114-Status: UNSURE ( 8.33 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.9 (/) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Sperl 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.2 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: Martin Sperl To reduce possible jitter prefer integer dividers over fractional dividers. Signed-off-by: Martin Sperl --- drivers/clk/bcm/clk-bcm2835.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c index f1ab525..e5313ba 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -1686,6 +1686,24 @@ static int bcm2835_clock_determine_rate_set(struct clk_rate_request *req, return 0; } +static int bcm2835_clock_determine_integer_rate(struct clk_hw *hw, + struct clk_rate_request *req, + struct bcm2835_rates *rates, + size_t rate_cnt) +{ + size_t i; + + /* find first matching */ + for (i = 0; i < rate_cnt; i++) { + if (!divmash_get_divf(rates[i].dmash)) + return bcm2835_clock_determine_rate_set(req, + &rates[i]); + } + + /* nothing found */ + return -EINVAL; +} + static int bcm2835_clock_determine_closest_rate(struct clk_hw *hw, struct clk_rate_request *req, struct bcm2835_rates *rates, @@ -1729,6 +1747,7 @@ static int bcm2835_clock_determine_rate(struct clk_hw *hw, struct bcm2835_rates rates[BIT(CM_SRC_BITS)]; size_t i, rate_cnt = 0; divmash dm; + int err; /* fill in rates */ for (i = 0; i < clk_hw_get_num_parents(hw); ++i) { @@ -1745,7 +1764,12 @@ static int bcm2835_clock_determine_rate(struct clk_hw *hw, rate_cnt++; } - /* choose the "closest" one */ + /* find integer rates with preference */ + err = bcm2835_clock_determine_integer_rate(hw, req, rates, rate_cnt); + if (!err) + return 0; + + /* otherwise choose the "closest" one */ return bcm2835_clock_determine_closest_rate(hw, req, rates, rate_cnt); }