Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp87715rdb; Mon, 18 Dec 2023 09:36:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEIW9lswnpJEK6HGfdy8NJ+UKWRM4PbcPCkFlgGZBPpqApaEYkIEP0awb8IGYWINlg3sb3r X-Received: by 2002:a17:902:a9c4:b0:1cf:b14d:8939 with SMTP id b4-20020a170902a9c400b001cfb14d8939mr8190924plr.63.1702920974336; Mon, 18 Dec 2023 09:36:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702920974; cv=none; d=google.com; s=arc-20160816; b=wywow38HtGRbPm1eN1xW9sP92l6vczw6yBjRBC/r82Kx5KqcCKrMpVKm0pPEwm2rrC OutLx8eCmpYwG8OeHe3gZK09Qwskb9OJ3E5Zip2powBghMdz8RGU9SywbQxO7okZDPzY nTtIai5bN4rDVXqTatgaIABBLmNg8BSi/QNc90DB0YhU/OMkQ29BiYYQQn61MzG6ppih itvgUBFn4qSZJW7nZyCSu4/up0CubSPo9fgQCRlx+QeG5XZQnWvq/TJ8xT1TtyAlUMuu TxObAiFzV/MmjoFyC7ol2LWCAN63FGbjq27HFn3yYjxR2bONSCKxw3X195CWQNRjgUEl 1i5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:in-reply-to:date:subject:cc:to:from:references :dkim-signature; bh=+vve0NiBqF/ep9e79zQnM4N2qRMtt/LCYu4PuzewmJ0=; fh=sIxz+ar02CewIQ+Z7g1/Ttr0o8jVOTApOXH++XWt3DA=; b=SyDtw9Xa1SNLXCWW9R7Vv7QXV6n9Rx6SYCseAFBXk+PfrwLk6MS/sg+e89srmMVljQ Uu/Jabwi80m/TQMNTrmjSi4D+PxblOhT7p7c6560exQEpRXo2VlJ9BiEVB2gJ3DwZvDQ w60v0c7qR2NRpJcLMedMr4mcWnEyPj3kJa6NZii+k2aqaketMrJDi7H+0DQkWTaqfVxR PQlLCSCue2sgnCT5KL9aWad+0rqsq74Q0BT6VGIT4eZButaM76XtcZoTDy92NdOcM2z9 /SKeIBBBF9wiCfuTYtHTbXohe8fk3/2Jzw7RQs2pmGb8/M9TMl3mQS4GnyYX/+/y+Zr6 6H1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=QZq2hHey; spf=pass (google.com: domain of linux-kernel+bounces-4173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id bc6-20020a170902930600b001d36c62d5fdsi7529666plb.621.2023.12.18.09.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 09:36:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=QZq2hHey; spf=pass (google.com: domain of linux-kernel+bounces-4173-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4173-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 38F70B22C6F for ; Mon, 18 Dec 2023 17:32:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 921F95A878; Mon, 18 Dec 2023 17:32:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oltmanns.dev header.i=@oltmanns.dev header.b="QZq2hHey" X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4EF22125C8; Mon, 18 Dec 2023 17:32:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oltmanns.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oltmanns.dev Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4Sv6MX6LDzz9sp7; Mon, 18 Dec 2023 18:32:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1702920728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+vve0NiBqF/ep9e79zQnM4N2qRMtt/LCYu4PuzewmJ0=; b=QZq2hHeyxhgZWBwpbBlpRX5VLY/977BHVX6kCqLDDjCUMrNBHnvN7SIPIneOtBnKlkjMmC iL89+dK142E8S9UB7gyrpj/QdCIratTBdOK61d5RGJogDWj7BcgsfioU/ZG0efG3gOxI2J WLIEovlqlukfGthr9hjkicgKNe/JuVFvIZIe0ykW47p4XXTlhjVff6bjOnAsW8L5Q3fl7k RMQ2eDrZcOYd/fiXy+waNgXtKFFWs858qVZ29wnY2wSo5SgFZYvg9Ldw8420NCTrakhywn x3/XY/u2ZqDgfjA2u/pizqRWIC1RqlVAYAdqBwM0EVYpcvGKp1uVgIu3+0uMRw== References: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> <20231218-pinephone-pll-fixes-v1-1-e238b6ed6dc1@oltmanns.dev> From: Frank Oltmanns To: Frank Oltmanns Cc: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Guido =?utf-8?Q?G=C3=BCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , 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 Subject: Re: [PATCH 1/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate Date: Mon, 18 Dec 2023 18:26:51 +0100 In-reply-to: <20231218-pinephone-pll-fixes-v1-1-e238b6ed6dc1@oltmanns.dev> Message-ID: <8734vz1kok.fsf@oltmanns.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On 2023-12-18 at 14:35:19 +0100, Frank Oltmanns wrote: > The Allwinner A64 manual lists the following constraints for the > PLL-MIPI clock: > - M/N >= 3 > - (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; > + This, of course, is rubbish and should be this instead: + if (!ccu_nkm_is_valid_rate(common, parent, _n, _m)) + continue; + I'll submit a V2 after receiving some feedback. > 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; > > struct ccu_common common; > };