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; From patchwork Tue May 15 16:36:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 135902 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1249325lji; Tue, 15 May 2018 09:37:09 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr25WUCorGUiKwa7xLnqpu+avil0DrTBCDAopkuJSh2b0yVsJMf+1P8EiRwWeSbHTZh3j2g X-Received: by 2002:a65:65ce:: with SMTP id y14-v6mr2367260pgv.270.1526402229607; Tue, 15 May 2018 09:37:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526402229; cv=none; d=google.com; s=arc-20160816; b=Heb7F7FzgRjOUglgMoCT47nq3pxPNi30LUXFNtWn+QGk4K3KKG5QdIdyubO5hdTTS1 pL6/SBF6oCYf6Wsq4XpSSxCTdvOwd1hwFb0C8lEO1QObIFdrSZqO2r3qVGyCuUVIJdZU V06s+zWE9tVIen+ZoGjAFTAitLAbJhlAte4PXN2Drp3VMRViw1jkBP3A5Hd1WgbWcx2Y 4IQWNXVe/w+KD3J0OlBmBUZvJ0eucX6mOcReVsBaLzceX1OHeygAz02XWFW/Jmj0XSy/ sOGatwhCdjxnPJlI1/4iEXsj0LPV8Q5JdS0A1/3GAC1XZ9enhDDfQ9sH/TOze4rgcQMj Uhug== 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=xlipNCPIHP1kQTkEVMNyH8fmfI1WeuC8PKe0sQw0lXc=; b=KRkikA/vfPjWyaMlnKuwrSq05/zx+UCm8tIp8A5Y76EHXE1zpON7A5cnLfHsFwZDGt QLFoPTl0tY8zm248ysa7HkjBrcPQFsvkqoU2LJ5dF8HJMaLKxfXgSJWyuYwKJo936Pd7 91VLg43AkWix/FNw5iMdkxdql+/K/BneoBqP3uZqrHxrCp5SRITZu+zxAI8/YPu0AG4h VZA31cApUcC8vu7bUfyNRU39i2fwowO5BBDbQQdwW53npr9dYtWR9Njoz94pCOOIae09 eYUC8EhKSFirHbiZr1agAemYtxygUmqvOwomB/hzTiElKs3LtRBLLM9H6QPNK/BjULt6 Gvnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=iXwcbowP; 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 a17-v6si336547pgf.15.2018.05.15.09.37.09; Tue, 15 May 2018 09:37:09 -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=iXwcbowP; 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 S932093AbeEOQhG (ORCPT + 29 others); Tue, 15 May 2018 12:37:06 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:39194 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753474AbeEOQhB (ORCPT ); Tue, 15 May 2018 12:37:01 -0400 Received: by mail-wr0-f194.google.com with SMTP id q3-v6so823675wrj.6 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=xlipNCPIHP1kQTkEVMNyH8fmfI1WeuC8PKe0sQw0lXc=; b=iXwcbowPaNntU4YP6MBD2f0Xtj/H8eYZ9UwPnTs5zT87gKl7ibsBX+FTDOL5pTnI6A j04WOxHB5Ay6d9rWdPtzoS0N9T5Axc8HjXkCXOeLfZ3oK30OjjVBe27rL3narFdiCfxQ QYrXXM/k/9CmAMDhHUivTTd+WbwngPMvXHe9WCR68ez/c95Uhvw5P2m2vkuh2NpSLwmd Af7QNLkimIG6XWRB+BdCaaRmVLtV96T97RwzC8kACWIUmB0uMwp1TPb5AUKCx3dn54df N1lGJ2lXXxTiyoZt0B0qmlK/c1ccvr/ZXsu2t2GCY4zFFDCwnVsKpmgxmGOYY9G/KO3x GMQA== 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=xlipNCPIHP1kQTkEVMNyH8fmfI1WeuC8PKe0sQw0lXc=; b=giyDDOjc63NL8Gx9KPBt35zNuJ2rHCL6k1tzvkCWE5UnTXXRR+86o96LpU0xILAdlE OiOKQ2vI4+R/MWPtKyO5+uBi/aW1C8WEJNm4DdacF1ZmlU4DqPzmWNLnCo8ZAc5K/ySY mtc22T3Qn+zo8CC1AqYE1PGO4Kvqt1CRbnS9q8IolsQWVhh7ElAcdo2ZS9KnjNQX5aHQ HxyQhvpWB11pslArDHDPX2DpkpD0DzkKlgCU02H264aQP9G/zboxH4OzsuQDnBXkzuVO o7AkHN6R19Jxfjua2gDLYb2O/JPoj6W9pyMQegaMHD8A/ktsLFABt2a66exGXS3ztt3j 0jlA== X-Gm-Message-State: ALKqPwdPaL/Tp0RPIwpOgaYGLa5gx9IaUkT+DZsAWB0/waZTz7tvN4MR uH7UQF6LO5kvtiX/1g6OLtGdyg== X-Received: by 2002:adf:92a5:: with SMTP id 34-v6mr10301084wrn.226.1526402220205; Tue, 15 May 2018 09:37:00 -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.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 09:36:59 -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 2/2] clk: meson: axg: let mpll clocks round closest Date: Tue, 15 May 2018 18:36:52 +0200 Message-Id: <20180515163652.19980-3-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 Let the mpll dividers achieve the closest rate possible, even if it means rounding the requested rate up. This is done to improve the accuracy of the rates provided by these plls to the audio subsystem Signed-off-by: Jerome Brunet --- drivers/clk/meson/axg.c | 4 ++++ 1 file changed, 4 insertions(+) -- 2.14.3 Acked-by: Neil Armstrong diff --git a/drivers/clk/meson/axg.c b/drivers/clk/meson/axg.c index 5f5d468c1efe..bd4dbc696b88 100644 --- a/drivers/clk/meson/axg.c +++ b/drivers/clk/meson/axg.c @@ -461,6 +461,7 @@ static struct clk_regmap axg_mpll0_div = { .width = 1, }, .lock = &meson_clk_lock, + .flags = CLK_MESON_MPLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mpll0_div", @@ -507,6 +508,7 @@ static struct clk_regmap axg_mpll1_div = { .width = 1, }, .lock = &meson_clk_lock, + .flags = CLK_MESON_MPLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mpll1_div", @@ -553,6 +555,7 @@ static struct clk_regmap axg_mpll2_div = { .width = 1, }, .lock = &meson_clk_lock, + .flags = CLK_MESON_MPLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mpll2_div", @@ -599,6 +602,7 @@ static struct clk_regmap axg_mpll3_div = { .width = 1, }, .lock = &meson_clk_lock, + .flags = CLK_MESON_MPLL_ROUND_CLOSEST, }, .hw.init = &(struct clk_init_data){ .name = "mpll3_div",