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 1034CC46CA2 for ; Tue, 19 Dec 2023 16:46:47 +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=40UiCf+TNW4zu1hz3uEv2vuDIVf2Fabx+zl6kIaRW4o=; b=34yIcwWhlJk4sk 23MK7YrJ7lGBwWdFTU26WKCV1v/w2/ZjUgTDDh/CXsNb6N/sLMczwhmubQYtBC3wGyF4D31w934b2 FydLVCatF1ylszxIutFRggYTrQVC3aUxXnNXi5N6Ko9+x8L65FLojsvYhjKezYqUUFB9E9spc6FlG elsNef+Lmq0XanfIAGa5MXlmG55p7bnoEvwS7wA+POfuYsegwMU2+BEUtCb5YQ687CUbvksdjmN4f dstZSnj5/NWIVbXgC0mCFijuLUJvW2R/fZF9G4hGtKfIBTSV5OPN0+5MPBTcdR8+POkbQh93fUq6y 8+PtqtFPAq/VUzsv9VHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rFdEX-00EkoD-2L; Tue, 19 Dec 2023 16:46:17 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rFdEU-00Ekmw-2F for linux-arm-kernel@lists.infradead.org; Tue, 19 Dec 2023 16:46:16 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a1fae88e66eso533954166b.3 for ; Tue, 19 Dec 2023 08:46:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703004371; x=1703609171; darn=lists.infradead.org; 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=9iyYRRTfOYCdZhFzzYt7vcnK5tnPRi7bc1hwQ2Xgkro=; b=lMEx1EkHXo24Sud6jiW4Z6/VHyl2MJKr3J4QJ/645spbR9zUmvbMCGJV3Xe29+3/TD 9XzKMC+YRCZDME6GA1stqzPncbBo6EB22kxPuUJpy1H9WHzmcIZyf1n0ulCyliQwFNJQ Pm/MpRu1j0f+s7xzSyR6AZiop06h67QDwnOE6P7UWUzd4kVW0nLcqQndn1Zyc6a4KoP+ cIG58istj4Tfnc+uXSv+sWlhRvOr1HxOjQ896oVHrL1umNvYcEab5Yf6u1RCKnyXTq4j bexO6ovGhI3Rt6onnBFgl5q2Yg+JfwD4zjHxNYlNOMOWe0Jb9Tmc3z/PNqH5DM3FCDfB xLow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703004371; x=1703609171; 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=9iyYRRTfOYCdZhFzzYt7vcnK5tnPRi7bc1hwQ2Xgkro=; b=VUyW2t4+2q7CGywC0QRujQjnGiVwKsUs8m8xq5xHDSYFc2NXdmvUXME6WoZ64Q6hFW yLAUNYx4rfecbZNs55P6DjqR+GaIainKZntwn66PzEKW1Y/pSfGHFODabOYAx+XN3ogA vupjPN9L7AwnOxNGnnn52KwJ7mQNBaTTZZBJmzizMgEEUK4n0XCFdiUSlN8xiyOTXJK2 Eh671Un+C5ZVxnglXzstBksqZvnxbSLec4CP0Z774T/LKRWGm2JBoW+wxezu1drdCBNJ Bnl7ydz0KuWIyPfQeL0166P7OoKarYtpG6DQAB1bYi0OFDLLA5G45XLXf/koAy7Q0gH/ rqoA== X-Gm-Message-State: AOJu0Yyvn1ygVWaqCchWbNdlnJqTbLE9tlN6EqUC7HRtvXPDDTzUY9HG 4Le0tOE4nrsdfbZCWxLi5Ic= X-Google-Smtp-Source: AGHT+IFJfMra7NcuO7fQEfUYtCoN4Bxnp51stjqeihm0piqP+Wi1lNVa1b2/OyVghxfcNYQDfZPAyA== X-Received: by 2002:a17:906:2206:b0:a23:3299:f332 with SMTP id s6-20020a170906220600b00a233299f332mr2818692ejs.140.1703004370668; Tue, 19 Dec 2023 08:46:10 -0800 (PST) Received: from jernej-laptop.localnet (82-149-12-148.dynamic.telemach.net. [82.149.12.148]) by smtp.gmail.com with ESMTPSA id vx4-20020a170907a78400b00a0a2553ec99sm15564251ejc.65.2023.12.19.08.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 08:46:10 -0800 (PST) From: Jernej =?utf-8?B?xaBrcmFiZWM=?= To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Samuel Holland , Guido =?ISO-8859-1?Q?G=FCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Frank Oltmanns Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Frank Oltmanns Subject: Re: [PATCH 1/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate Date: Tue, 19 Dec 2023 17:46:08 +0100 Message-ID: <5736273.DvuYhMxLoT@jernej-laptop> In-Reply-To: <20231218-pinephone-pll-fixes-v1-1-e238b6ed6dc1@oltmanns.dev> References: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> <20231218-pinephone-pll-fixes-v1-1-e238b6ed6dc1@oltmanns.dev> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231219_084614_735888_BE9C49F5 X-CRM114-Status: GOOD ( 22.49 ) 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 Hi Frank! Dne ponedeljek, 18. december 2023 ob 14:35:19 CET je Frank Oltmanns napisal(a): > The Allwinner A64 manual lists the following constraints for the > PLL-MIPI clock: > - M/N >= 3 This should be "<=" > - (PLL_VIDEO0)/M >= 24MHz > > The PLL-MIPI clock is implemented as ccu_nkm. Therefore, add support for > these constraints. > > Signed-off-by: Frank Oltmanns > --- > drivers/clk/sunxi-ng/ccu_nkm.c | 23 +++++++++++++++++++++++ > drivers/clk/sunxi-ng/ccu_nkm.h | 8 ++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c > index eed64547ad42..2af5c1ebd527 100644 > --- a/drivers/clk/sunxi-ng/ccu_nkm.c > +++ b/drivers/clk/sunxi-ng/ccu_nkm.c > @@ -16,6 +16,20 @@ struct _ccu_nkm { > unsigned long m, min_m, max_m; > }; > > +static bool ccu_nkm_is_valid_rate(struct ccu_common *common, unsigned long parent, > + unsigned long n, unsigned long m) > +{ > + struct ccu_nkm *nkm = container_of(common, struct ccu_nkm, common); > + > + if (nkm->max_mn_ratio && (m > nkm->max_mn_ratio * n)) > + return false; > + > + if (nkm->parent_wo_nk && (parent < nkm->parent_wo_nk * m)) > + return false; > + > + return true; > +} > + > static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common, > struct clk_hw *parent_hw, > unsigned long *parent, unsigned long rate, > @@ -32,6 +46,9 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common > > tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); > > + if (!ccu_nkm_is_valid_rate(common, tmp_parent, _n, _m)) > + continue; > + > tmp_rate = tmp_parent * _n * _k / _m; > > if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) || > @@ -65,6 +82,12 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, > for (_k = nkm->min_k; _k <= nkm->max_k; _k++) { > for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { > for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { > + if ((common->reg == 0x040) && (_m > 3 * _n)) > + break; > + > + if ((common->reg == 0x040) && (parent < 24000000 * _m)) > + continue; > + You already figured this part. > unsigned long tmp_rate; > > tmp_rate = parent * _n * _k / _m; > diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_nkm.h > index 6601defb3f38..d3d3eaf55faf 100644 > --- a/drivers/clk/sunxi-ng/ccu_nkm.h > +++ b/drivers/clk/sunxi-ng/ccu_nkm.h > @@ -16,6 +16,12 @@ > * struct ccu_nkm - Definition of an N-K-M clock > * > * Clocks based on the formula parent * N * K / M > + * > + * @max_mn_ratio: Maximum value for M / N. > + * @parent_wo_nk: The minimum rate the parent must provide after applying the divisor, > + * but without applying the multipliers, i.e. the contstraint > + * (parent rate)/M >= parent_wo_nk > + * must be fulfilled. > */ > struct ccu_nkm { > u32 enable; > @@ -27,6 +33,8 @@ struct ccu_nkm { > struct ccu_mux_internal mux; > > unsigned int fixed_post_div; > + unsigned long max_mn_ratio; > + unsigned long parent_wo_nk; What about max_m_n_ratio and max_parent_m_ratio, to be consistent? This should also allow to simplify description. Best regards, Jernej > > struct ccu_common common; > }; > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel