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: 10401641 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 97337600F4 for ; Tue, 15 May 2018 16:37:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 878CA27F10 for ; Tue, 15 May 2018 16:37:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BFF127F93; Tue, 15 May 2018 16:37:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E76CD27F10 for ; Tue, 15 May 2018 16:37:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=53GOBw+RI2snU6vPW3gpSJkrwW1RDStc7y0VMX0ylf4=; b=PHPTNYWcGgMEhQ2m3q2Q2oWmD1 d3rcQaPPFbWXUJUzxxueHK3M4XeP1D8JyqgxRPJJ5RIFJgIlw7ykLm47a5m80Ipeb7IOIumre9tHW z4Q6XhJfDKCEUs9+cFjdGo1o62UA99RWBO9CqCWUZ/Insf7Q7B43YtgydQRJPS+5vVgwkQkj+e4rp +KtYLvC2BmoS5Rfc1VXXCqAJquf77JIEPzjqmtAXCxGe/kGn3SFPLoDCqlBb2qIO6izXfMzsm+K8w EEr37Ff01Z6uF3UDudo5UKFC9fOkS/bKfjqt468W50cCCUdyz0VKL/meseD9wwy5LavGmriVUgS/t ukpesdig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIcxD-0004uw-1h; Tue, 15 May 2018 16:37:35 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIcwp-0004RW-4M for linux-amlogic@lists.infradead.org; Tue, 15 May 2018 16:37:14 +0000 Received: by mail-wm0-x244.google.com with SMTP id f8-v6so2316363wmc.4 for ; Tue, 15 May 2018 09:37:00 -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=eLlTofJvnyXvfYpYSV5oqsxwSNkYHR4uE1X6cZjv4bNYxfn9tRC14XFevk+6Bewiiz IGlyH8pmoFLigPq8dGJTLNq+u+Bxscz9GfBPsL5d0K3As8NGv70CNOBMfBs++FXF2Cuc PPz4I0QzjDwoCSHJNKiEisjgrWKqaGG1eAHAyKg57Hc+0gYUFgAyWixmRcUpE6+dtF6E AEGMn9iXBDiPCm0kCxsRU+Ns7SCOTZ3kE3ZcKGWNhcky3GkVsFB6AJvs9VU/9Towuljr 32/sGRlpfGxueQlh7sAY4ZrQ3tmv6+wU/qlFWj0qHl6Jgih41VTaMuaTJpcBzSx6bq5b Br7w== X-Gm-Message-State: ALKqPwdMMqxaimZPUrNS9+H1qAaIPkha9YW9FJ9Yc02T/RftvAzHsiaf K85ZCrvoZ+sjYFjeu71sXXxWpgl6 X-Google-Smtp-Source: AB8JxZqplFPL0N9JF8E+5qDpYKgX8criJWrFlFCMLSV6sOnoKY4wtaIusIb60us4jnFv3f6jDD4o8g== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180515_093711_184686_0A1A50A8 X-CRM114-Status: GOOD ( 13.93 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Jerome Brunet MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Neil Armstrong Acked-by: Martin Blumenstingl --- drivers/clk/meson/clk-mpll.c | 24 +++++++++++++++++++----- drivers/clk/meson/clkc.h | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-) 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;