From patchwork Tue May 15 16:36:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 135903 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1249672lji; Tue, 15 May 2018 09:37:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpU45fTIZMocYtwm4A7kQzvv8RrDM9vQ2ZlTlHXvS6199ETbPRlC6fkAqWF0kpFRpNsOUz5 X-Received: by 2002:a17:902:b7c9:: with SMTP id v9-v6mr14783562plz.224.1526402246240; Tue, 15 May 2018 09:37:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526402246; cv=none; d=google.com; s=arc-20160816; b=HbAntfomBzijrZDywIy+2WiMlKUIs+ERNHb3/mbOYUJEShOTrZpXmNGspMEIOHNX1a WRf6US7Lf1QSlGHUcHgmKx54eiMaIYALPM5LuJrs3Zbf43rek3fzgZJ6EJwU8EE08dc3 cCZMdeOj3/w+bJwrofgMInxlUsZMXkCFiqN0oXr5imV982LlNXar0hYRyECbVKwCSmpA pgXxOhY6CqmuhuFnNLdk6Cj1iDOjA1UfA2vhUxPUSqSTP/Jkhg8e8xcg9O1d1awKVcYU UlpvXTJy0ObCIAywMgoe0+k3fj0XM2rwXi/NgKyTyjwi7ArNfo3mDHH+nH/28SyuOMr7 JYeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=pArVSWiGUv01rgOTEvm5pe0HfHzEauyrp0qriMKr3zw=; b=dPndSn1dWbz9CPXyu0gXotKF+45DwFRWWslEmi5kNL9YeogkmI8tINw3Rc/s/tBrto bDEUoRa60xuli+VFk4QnzXu10nlf5oBQNxb0E1gzZwwIFl1vkdUyRhygh3s3+HAhnqvc oBkMDlG0HGJ0on2sDW+CDiLcpWXKbqALxsXhtcG7RCZmhyjZLr5PIssoQA3y0RF3d+Xd ROo1KFyUx4XVn/YZb3BpBJwgsJ0pUOLnBGyVvzTYJKJbMBLlVTMXijqQ328TYFzqDI4L 8sRs2QOuMwF6eznvrtQbPqTM2WN5y7ZinUaiCoD3SO6V452+wgTaEDPMymWvT9oCCw5O suEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=m4z5dhhX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w127-v6si395342pfd.313.2018.05.15.09.37.25; Tue, 15 May 2018 09:37:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=m4z5dhhX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932120AbeEOQhY (ORCPT + 29 others); Tue, 15 May 2018 12:37:24 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36859 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752750AbeEOQhA (ORCPT ); Tue, 15 May 2018 12:37:00 -0400 Received: by mail-wm0-f65.google.com with SMTP id n10-v6so2337588wmc.1 for ; Tue, 15 May 2018 09:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pArVSWiGUv01rgOTEvm5pe0HfHzEauyrp0qriMKr3zw=; b=m4z5dhhXcDUxMxfItX50tVCw4cCC/iQzjiIEv6hJjUhsjNvZnvApe4Vob7hQegv+SC 98246REIr2A1LOXKd+Xb03bHaOnlrwWbH4zJdo2COxb96RC1tGla87XKBQXphS2yOWui Mr9/SYE3hE0XEqbAnkknUIvu8jdLl7FsfstivpXb0UWwCJGk6SPrLeJUjMlXOxLoGmuM 6LLI184rTmSJVzIx9xndiaGlOSshlE1HWK5rKa+QsUI0KRJxgYVmDOqu6wkUBadoW46P UlJ/gcCyx+vF5zzrc02wp+PL/TIzwwQDzZ1z1ttBsN/J/9eKCBM+6l/KbXJzApgGwWZZ 5nqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pArVSWiGUv01rgOTEvm5pe0HfHzEauyrp0qriMKr3zw=; b=W0K7wAq5AqB4kNvT+ZNb5ty3VzO6sc9qsBvxYQERXCWy+1df/OBaYswGtw4Rhp/Ylq iX8J9WCZxt9pEJFF4oKF10aWKRW34L4IM8cC4eJMwQTkoqg/cZ9AupYzSupMX+onsD8A 7nRLTKDX/RcQF6obZw0BAvXSwYaFYgypAx9hn1NMz2SYauxY8CzKQfGWOw84EuemKhkC UCLrkEVOEPpDJGMl20kFqn0f5ImAChY9LBDi4HKRY7jYevbmrSCFg867IniaUCSjL0JZ nmrOdqCLoXIkL7zkulut9vc/HGOztT5FGBMvlxE7Re8I3GZr7AoNM9lNFceDRWJjSbmB F3LQ== X-Gm-Message-State: ALKqPwfsTNzgZ2XWnC3pUytqciBGABXjPRJLsDubdym0oc/cJLm0vOXs pfnkE03lEj0k7ot+jcE7+GnXew== X-Received: by 2002:a1c:459a:: with SMTP id l26-v6mr9257478wmi.95.1526402218933; Tue, 15 May 2018 09:36:58 -0700 (PDT) Received: from boomer.baylibre.local ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id o12-v6sm637317wrf.31.2018.05.15.09.36.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 09:36:58 -0700 (PDT) From: Jerome Brunet To: Neil Armstrong , Martin Blumenstingl , Kevin Hilman , Carlo Caione Cc: Jerome Brunet , linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] clk: meson: mpll: add round closest support Date: Tue, 15 May 2018 18:36:51 +0200 Message-Id: <20180515163652.19980-2-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180515163652.19980-1-jbrunet@baylibre.com> References: <20180515163652.19980-1-jbrunet@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow the mpll driver to round the requested rate up if CLK_MESON_MPLL_ROUND_CLOSEST is set and it provides a rate closer to the requested rate. Signed-off-by: Jerome Brunet --- drivers/clk/meson/clk-mpll.c | 24 +++++++++++++++++++----- drivers/clk/meson/clkc.h | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) -- 2.14.3 Acked-by: Neil Armstrong Acked-by: Martin Blumenstingl diff --git a/drivers/clk/meson/clk-mpll.c b/drivers/clk/meson/clk-mpll.c index 0df1227b65b3..d233549de244 100644 --- a/drivers/clk/meson/clk-mpll.c +++ b/drivers/clk/meson/clk-mpll.c @@ -89,10 +89,23 @@ static long rate_from_params(unsigned long parent_rate, static void params_from_rate(unsigned long requested_rate, unsigned long parent_rate, unsigned int *sdm, - unsigned int *n2) + unsigned int *n2, + u8 flags) { uint64_t div = parent_rate; - unsigned long rem = do_div(div, requested_rate); + uint64_t frac = do_div(div, requested_rate); + + frac *= SDM_DEN; + + if (flags & CLK_MESON_MPLL_ROUND_CLOSEST) + *sdm = DIV_ROUND_CLOSEST_ULL(frac, requested_rate); + else + *sdm = DIV_ROUND_UP_ULL(frac, requested_rate); + + if (*sdm == SDM_DEN) { + *sdm = 0; + div += 1; + } if (div < N2_MIN) { *n2 = N2_MIN; @@ -102,7 +115,6 @@ static void params_from_rate(unsigned long requested_rate, *sdm = SDM_DEN - 1; } else { *n2 = div; - *sdm = DIV_ROUND_UP_ULL((u64)rem * SDM_DEN, requested_rate); } } @@ -125,9 +137,11 @@ static long mpll_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { + struct clk_regmap *clk = to_clk_regmap(hw); + struct meson_clk_mpll_data *mpll = meson_clk_mpll_data(clk); unsigned int sdm, n2; - params_from_rate(rate, *parent_rate, &sdm, &n2); + params_from_rate(rate, *parent_rate, &sdm, &n2, mpll->flags); return rate_from_params(*parent_rate, sdm, n2); } @@ -140,7 +154,7 @@ static int mpll_set_rate(struct clk_hw *hw, unsigned int sdm, n2; unsigned long flags = 0; - params_from_rate(rate, parent_rate, &sdm, &n2); + params_from_rate(rate, parent_rate, &sdm, &n2, mpll->flags); if (mpll->lock) spin_lock_irqsave(mpll->lock, flags); diff --git a/drivers/clk/meson/clkc.h b/drivers/clk/meson/clkc.h index 8fe73c4edca8..8cc265cd3d2b 100644 --- a/drivers/clk/meson/clkc.h +++ b/drivers/clk/meson/clkc.h @@ -97,8 +97,11 @@ struct meson_clk_mpll_data { struct parm ssen; struct parm misc; spinlock_t *lock; + u8 flags; }; +#define CLK_MESON_MPLL_ROUND_CLOSEST BIT(0) + struct meson_clk_audio_div_data { struct parm div; u8 flags;