From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 96616C001DE for ; Sun, 6 Aug 2023 13:42:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7rAybk2c5AiLr+I0PM7v4NcQ6lfCp6fRyzXF+n1Ox78=; b=I8PA+0VKveqwJB xgVLwNKYuAT+nAoT6UINeE5FjvUxJIO9tB/kaU5g4M+kGthiUbx917c7lc8QGjipoJoZarpBMEzLb yFMRTrMnI3GKlaAI99yGByO+mMTaTu/VH0P7QexJfF5gVblFxeB05gz2RiMaEs+Ba77N7F4F5cEwd E0g3QyAU0lBPLkLIbtkZ1Xc1bcd7OHJWsTfGzhp8d81/hTMSuLodwla2WZhtc+/MD9OFuJFHlD3OR HdTpuZYCzHR9E1NUPZFBp0Keu3LPsz2Z+BTVIt4b49KkJNLnHIsf8nfndvPGwTpz6z+tdupbH8yq5 tuKJQB6cNeNTpy1Alf9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSe1G-00FSsz-05; Sun, 06 Aug 2023 13:42:06 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSe1D-00FSsa-2z for linux-arm-kernel@lists.infradead.org; Sun, 06 Aug 2023 13:42:05 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-99c1c66876aso506611766b.2 for ; Sun, 06 Aug 2023 06:42:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691329322; x=1691934122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WALMtuY1q1u1v35LOtFmRB/W8nnlZgs+IUgJZUZJB0U=; b=A9eYjVViIUx+U9ndZZB3LBOJzWoPLQQrEzAEL8Mmh8TnVNZQc49pdCRWQtj7JtEb8F 0tNn3ojMm1cKd9dr2sxCx6/vFzf+jpu5Kd4RaOQXaSid6j+L9y0rqjwyqIxf2e1u1tBo vIfHBOdNcjKUa+fMQpcTiqjkOH1Ap8DCmcBGPA+4SX6s33/zxJgv2x2GBU80D1eS615v d5Zyyyn4HcR4Ue0IkRmXchg4PytWoPG71mKFn4LRymr8C61l3fKnD29mjGP83m25/l4H 6ToQEEC93r3Yo6MU1ofAcdVDVHwB48A52JhneL9DoWPa9ye7Qt4P8D5I7ioz5dOuT5R/ AVAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691329322; x=1691934122; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WALMtuY1q1u1v35LOtFmRB/W8nnlZgs+IUgJZUZJB0U=; b=M5Xt05M1mS5ocy4VZh3sDUkkG3S6nqhM+4jxtbmDJsYCekMlk7dDz84wKUhkTux4vS zgAhbtNxwrGJdolMnAxq7H8MuCSa9FI8pHs+w3twCpNDyR0UM1LDe6NET5mO3fWY8Cof pmGXvZVY0rlEqTAg7GFU5JvjBcv87XXGkVKe3H8G+1pwjAe/+Y1/t2NjxipnHCsOfxAd ERbIG1Nr50VDpAk5osQtbD7oPJeR6v5HsccohVqMRPpc6hPcMNSCc6Wjd/0pM7frTwVn NsF8d/V4IiWtUg/ZAfgnRpi01nAYvh1/3icenVGziRJjb5DnitM+brWsBRqJj9oox5Hv aJbA== X-Gm-Message-State: AOJu0Yyud7M8lDGKLMW7pkLfdE0LZT2e7REUtxMmMc6f/uD6RpIAdOEj ANH4lPenP/XpPb1mNHdhhvc= X-Google-Smtp-Source: AGHT+IEtEzCGJpEmyOm8rqHxaOABvTf08nsDkY1uDvN0+mjBqCJOh9uBwh7X4BPVJzO7KxvRNvs3og== X-Received: by 2002:a17:906:142:b0:99b:d698:152e with SMTP id 2-20020a170906014200b0099bd698152emr6406034ejh.42.1691329322434; Sun, 06 Aug 2023 06:42:02 -0700 (PDT) Received: from jernej-laptop.localnet (82-149-1-233.dynamic.telemach.net. [82.149.1.233]) by smtp.gmail.com with ESMTPSA id bg14-20020a170906a04e00b009786c8249d6sm4001307ejb.175.2023.08.06.06.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Aug 2023 06:42:01 -0700 (PDT) From: Jernej =?utf-8?B?xaBrcmFiZWM=?= To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Samuel Holland , Andre Przywara , Roman Beranek , Frank Oltmanns Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns Subject: Re: [PATCH v5 06/11] clk: sunxi-ng: nm: Support finding closest rate Date: Sun, 06 Aug 2023 15:42:00 +0200 Message-ID: <3432648.QJadu78ljV@jernej-laptop> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-6-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> <20230806-pll-mipi_set_rate_parent-v5-6-db4f5ca33fc3@oltmanns.dev> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230806_064203_966689_1376ADFB X-CRM114-Status: GOOD ( 21.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Dne nedelja, 06. avgust 2023 ob 15:06:51 CEST je Frank Oltmanns napisal(a): > Use the helper function ccu_is_better_rate() to determine the rate that > is closest to the requested rate, thereby supporting rates that are > higher than the requested rate if the clock uses the > CCU_FEATURE_CLOSEST_RATE. > > Add the macro SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST which > sets CCU_FEATURE_CLOSEST_RATE. > > To avoid code duplication, add the macros > SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT that allows selecting > arbitrary features and use it in the original > SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX as well as the newly introduced > SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST macros. > > Acked-by: Maxime Ripard > Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec Best regards, Jernej > --- > drivers/clk/sunxi-ng/ccu_nm.c | 13 +++++------- > drivers/clk/sunxi-ng/ccu_nm.h | 48 > ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 50 > insertions(+), 11 deletions(-) > > diff --git a/drivers/clk/sunxi-ng/ccu_nm.c b/drivers/clk/sunxi-ng/ccu_nm.c > index c1fd11542c45..ffac3deb89d6 100644 > --- a/drivers/clk/sunxi-ng/ccu_nm.c > +++ b/drivers/clk/sunxi-ng/ccu_nm.c > @@ -27,8 +27,8 @@ static unsigned long ccu_nm_calc_rate(unsigned long > parent, return rate; > } > > -static unsigned long ccu_nm_find_best(unsigned long parent, unsigned long > rate, - struct _ccu_nm *nm) > +static unsigned long ccu_nm_find_best(struct ccu_common *common, unsigned > long parent, + unsigned long rate, struct _ccu_nm *nm) > { > unsigned long best_rate = 0; > unsigned long best_n = 0, best_m = 0; > @@ -39,10 +39,7 @@ static unsigned long ccu_nm_find_best(unsigned long > parent, unsigned long rate, unsigned long tmp_rate = > ccu_nm_calc_rate(parent, > _n, _m); > > - if (tmp_rate > rate) > - continue; > - > - if ((rate - tmp_rate) < (rate - best_rate)) { > + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { > best_rate = tmp_rate; > best_n = _n; > best_m = _m; > @@ -159,7 +156,7 @@ static long ccu_nm_round_rate(struct clk_hw *hw, > unsigned long rate, _nm.min_m = 1; > _nm.max_m = nm->m.max ?: 1 << nm->m.width; > > - rate = ccu_nm_find_best(*parent_rate, rate, &_nm); > + rate = ccu_nm_find_best(&nm->common, *parent_rate, rate, &_nm); > > if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) > rate /= nm->fixed_post_div; > @@ -210,7 +207,7 @@ static int ccu_nm_set_rate(struct clk_hw *hw, unsigned > long rate, &_nm.m, &_nm.n); > } else { > ccu_sdm_helper_disable(&nm->common, &nm->sdm); > - ccu_nm_find_best(parent_rate, rate, &_nm); > + ccu_nm_find_best(&nm->common, parent_rate, rate, &_nm); > } > > spin_lock_irqsave(nm->common.lock, flags); > diff --git a/drivers/clk/sunxi-ng/ccu_nm.h b/drivers/clk/sunxi-ng/ccu_nm.h > index 2904e67f05a8..93c11693574f 100644 > --- a/drivers/clk/sunxi-ng/ccu_nm.h > +++ b/drivers/clk/sunxi-ng/ccu_nm.h > @@ -108,7 +108,7 @@ struct ccu_nm { > }, \ > } > > -#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \ > +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ > _parent, _reg, \ > _min_rate, _max_rate, \ > _nshift, _nwidth, \ > @@ -116,7 +116,8 @@ struct ccu_nm { > _frac_en, _frac_sel, \ > _frac_rate_0, \ > _frac_rate_1, \ > - _gate, _lock, _flags) \ > + _gate, _lock, _flags, \ > + _features) \ > struct ccu_nm _struct = { \ > .enable = _gate, \ > .lock = _lock, \ > @@ -129,7 +130,7 @@ struct ccu_nm { > .max_rate = _max_rate, \ > .common = { \ > .reg = _reg, \ > - .features = CCU_FEATURE_FRACTIONAL, \ > + .features = _features, \ > .hw.init = CLK_HW_INIT(_name, \ > _parent, \ > &ccu_nm_ops, \ > @@ -137,6 +138,47 @@ struct ccu_nm { > }, \ > } > > +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \ > + _parent, _reg, \ > + _min_rate, _max_rate, \ > + _nshift, _nwidth, \ > + _mshift, _mwidth, \ > + _frac_en, _frac_sel, \ > + _frac_rate_0, \ > + _frac_rate_1, \ > + _gate, _lock, _flags) \ > + SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ > + _parent, _reg, \ > + _min_rate, _max_rate, \ > + _nshift, _nwidth, \ > + _mshift, _mwidth, \ > + _frac_en, _frac_sel, \ > + _frac_rate_0, \ > + _frac_rate_1, \ > + _gate, _lock, _flags, \ > + CCU_FEATURE_FRACTIONAL) > + > +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(_struct, _name, \ > + _parent, _reg, \ > + _min_rate, _max_rate, \ > + _nshift, _nwidth, \ > + _mshift, _mwidth, \ > + _frac_en, _frac_sel, \ > + _frac_rate_0, \ > + _frac_rate_1, \ > + _gate, _lock, _flags) \ > + SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ > + _parent, _reg, \ > + _min_rate, _max_rate, \ > + _nshift, _nwidth, \ > + _mshift, _mwidth, \ > + _frac_en, _frac_sel, \ > + _frac_rate_0, \ > + _frac_rate_1, \ > + _gate, _lock, _flags, \ > + CCU_FEATURE_FRACTIONAL |\ > + CCU_FEATURE_CLOSEST_RATE) > + > #define SUNXI_CCU_NM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \ > _nshift, _nwidth, \ > _mshift, _mwidth, \ _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel