Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2550546rdb; Mon, 5 Feb 2024 09:50:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPfJZzs/aKarMXnxyjkoYrzrmuwGH+EZiC0+SwiEySjwENz3kJfciAf/9OAfRNkSV9t5R4 X-Received: by 2002:a17:90a:ec0a:b0:296:2037:c8f4 with SMTP id l10-20020a17090aec0a00b002962037c8f4mr173825pjy.9.1707155446352; Mon, 05 Feb 2024 09:50:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707155446; cv=pass; d=google.com; s=arc-20160816; b=UlO+4CVnukB0rU3o5Ir1fZFZsvtCN/c1EVEql8cBeqXOUQHJvkdXYEEa9uWlj+PQ9v vHXkjVWBxam2p1sF2i6BeR3jJVIaCrXMHztZLs2N1hRPqUD77bPX0OZyXKHduUwP+sy/ /6QPff7o3132Cm7R1ah4gDzTSENOEL/K0pRqKrz9r6VCXBVXRQo97CxP4/PXPNW6/qis OHx/idROzm5Xz6uexRU2nJ7RlhePogsTrH6tIhwAk7NOgkDhAMFbh78Lg4DNbg942fHd ixcIph9SD7Xnc/Uoqx6Te0pKRMAqJfNZsORX7d5tJPtkKfUVNAY6zgC3YgB1tpx0IQty cAKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:in-reply-to :subject:cc:to:from:references:dkim-signature; bh=43fZUpSLN34Hcqn5D5P20QB99YjMTO5/RY6QxJlWZcc=; fh=AQO9HbtfpSLJI5XtHGzad3r1C/gHPsTEVZg7tvfTo5w=; b=yRYLU/OJHR/bZywsuEL9aLJT6DOWZkI79WXTKeWUGXZ4E2+gC4k9kzplIhmrDZ0Dxy vwsrKR9SJ3775YcW7Dk4bv8yonQqOVfEhD/mlSYnZhbc0CPVPaLGOwxT3A4z5C6ePlmT 9CF5LOVF1wF6xSW6UkMtJgRm7qK/8ePtjXb2gJHHhJx9ZElYzbwnpqviclxivIs7r8zN fwRF6sZ9W5lJEUvEBSkMa70l69CPZaWPKiJ7gnpyGS5/szH+ahWrmzuCCqG/JFpdMKdG PRpNQIXzYIPK70IFYQExbMejhy6/Nxq+aQz23dCX2YPfkSI812xKx8Jg5DzPz8+F2fKT xHgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=z8OZncQm; arc=pass (i=1 spf=pass spfdomain=oltmanns.dev dkim=pass dkdomain=oltmanns.dev dmarc=pass fromdomain=oltmanns.dev); spf=pass (google.com: domain of linux-kernel+bounces-53154-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53154-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev X-Forwarded-Encrypted: i=1; AJvYcCUgotbTlIuQURmKWrBD2jWDp1FmpTU55J5stDvlILj4doFEkZy6H2dcMOp3BJ25sBMtj+ywdjOGUGz7ssgvSz0lBDN80ULRz8xbHIxmBg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l3-20020a17090ac58300b00290be59078csi254756pjt.118.2024.02.05.09.50.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 09:50:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53154-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=z8OZncQm; arc=pass (i=1 spf=pass spfdomain=oltmanns.dev dkim=pass dkdomain=oltmanns.dev dmarc=pass fromdomain=oltmanns.dev); spf=pass (google.com: domain of linux-kernel+bounces-53154-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53154-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0439F283495 for ; Mon, 5 Feb 2024 17:50:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F45645957; Mon, 5 Feb 2024 17:50:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oltmanns.dev header.i=@oltmanns.dev header.b="z8OZncQm" 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 9CDB844C9C; Mon, 5 Feb 2024 17:50:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707155441; cv=none; b=uzmAQBgJNpwSDluhTYMc+RSOffIB+qplIcZcWPnpQaZ9ASqbttfnx1SkVdWJWNPGB47z+BUK5joVved8YeLOovAiY5joWXn0QYtGsELb1oRZFPZ/hjEcVKAqTdbUSAU+3bkxRL2iWX2/oH9rkTXaeje9jH/6sMjGZcmi2uu+dNI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707155441; c=relaxed/simple; bh=3bp8mP5LU2HDSVtF79gXm0Qv9vYGRpul41cBty4cm1c=; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID: MIME-Version:Content-Type; b=HyI+wgknH3ximWV8akSIkIwwwLMOTN7DnZPqQwoRSdPsc6EpNCw1kUtBRgS+NepyRquwhkGj/AKl/sOm72o+lDVs5EeDOFYCVixUcDQTuHazI1TJwsto3I/OCJJY7XE5s0CDiKYr1xAuKczFvdavVU+vRGJ7qUEiD/dCqVrtPGQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oltmanns.dev; spf=pass smtp.mailfrom=oltmanns.dev; dkim=pass (2048-bit key) header.d=oltmanns.dev header.i=@oltmanns.dev header.b=z8OZncQm; arc=none smtp.client-ip=80.241.56.171 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 smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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 4TTDSB2BbZz9t3K; Mon, 5 Feb 2024 18:50:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1707155434; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=43fZUpSLN34Hcqn5D5P20QB99YjMTO5/RY6QxJlWZcc=; b=z8OZncQmPoCuukgcv9bayNYF6H1VQwFrd6unqx8VhMMFMtIrMhf/fNo+5AotMY6TuM81bg 7Fkt5eZ9m3iSJOyUxq5WZvUhDgu+YdZbuB9ewPgKwL4VTpT5d9rTXZEfja5Y5+EJDjiZ6j UVuPVWVlS0295kPAw5dvwfBywpJ7yGTuQ4z3phV0l5youxBWccl8Zp3UubAGZjpZXnqQGN CG6h/RwBYk4/+hZb0mtOqEyQCzG9QtQ6W6B1PUBtzL/KTEya0zUcicy9Qr52W2hHtAx6jj 57HMGESf+WBq5jGEoYg55vPBZjcvjVIULphNXzZMIzgXfv2YOC3IZ522yOYEiA== References: <20240205-pinephone-pll-fixes-v2-0-96a46a2d8c9b@oltmanns.dev> <20240205-pinephone-pll-fixes-v2-1-96a46a2d8c9b@oltmanns.dev> <2717565.mvXUDI8C0e@jernej-laptop> From: Frank Oltmanns To: Jernej =?utf-8?Q?=C5=A0krabec?= Cc: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , 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 , Rob Herring , Krzysztof Kozlowski , Conor Dooley , 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, devicetree@vger.kernel.org Subject: Re: [PATCH v2 1/6] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate In-reply-to: <2717565.mvXUDI8C0e@jernej-laptop> Date: Mon, 05 Feb 2024 18:50:27 +0100 Message-ID: <87il32ztp8.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; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Jernej, On 2024-02-05 at 18:45:27 +0100, Jernej =C5=A0krabec wrote: > Dne ponedeljek, 05. februar 2024 ob 16:22:24 CET je Frank Oltmanns napisa= l(a): >> The Allwinner A64 manual lists the following constraints for the >> PLL-MIPI clock: >> - M/N <=3D 3 >> - (PLL_VIDEO0)/M >=3D 24MHz >> >> The PLL-MIPI clock is implemented as ccu_nkm. Therefore, add support for >> these constraints. >> >> Signed-off-by: Frank Oltmanns > > Haven't we discussed that this patch is unnecessary because same effect c= an > be reached by limiting minimum frequency? The patch for ccu_nm was unnecessary: https://lore.kernel.org/all/87jzoug2jz.fsf@oltmanns.dev/ Unfortunately, we still need this one. Best regards, Frank > > Best regards, > Jernej > >> --- >> drivers/clk/sunxi-ng/ccu_nkm.c | 21 +++++++++++++++++++++ >> drivers/clk/sunxi-ng/ccu_nkm.h | 2 ++ >> 2 files changed, 23 insertions(+) >> >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_n= km.c >> index 853f84398e2b..1168d894d636 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 l= ong parent, >> + unsigned long n, unsigned long m) >> +{ >> + struct ccu_nkm *nkm =3D container_of(common, struct ccu_nkm, common); >> + >> + if (nkm->max_m_n_ratio && (m > nkm->max_m_n_ratio * n)) >> + return false; >> + >> + if (nkm->min_parent_m_ratio && (parent < nkm->min_parent_m_ratio * m)) >> + return false; >> + >> + return true; >> +} >> + >> static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_commo= n *common, >> struct clk_hw *parent_hw, >> unsigned long *parent, unsigned long rate, >> @@ -31,6 +45,10 @@ static unsigned long ccu_nkm_find_best_with_parent_ad= j(struct ccu_common *common >> unsigned long tmp_rate, tmp_parent; >> >> tmp_parent =3D clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); >> + >> + if (!ccu_nkm_is_valid_rate(common, tmp_parent, _n, _m)) >> + continue; >> + >> tmp_rate =3D tmp_parent * _n * _k / _m; >> >> if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) || >> @@ -64,6 +82,9 @@ static unsigned long ccu_nkm_find_best(unsigned long p= arent, unsigned long rate, >> for (_k =3D nkm->min_k; _k <=3D nkm->max_k; _k++) { >> for (_n =3D nkm->min_n; _n <=3D nkm->max_n; _n++) { >> for (_m =3D nkm->min_m; _m <=3D nkm->max_m; _m++) { >> + if (!ccu_nkm_is_valid_rate(common, parent, _n, _m)) >> + continue; >> + >> unsigned long tmp_rate; >> >> tmp_rate =3D parent * _n * _k / _m; >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_n= km.h >> index 6601defb3f38..c409212ee40e 100644 >> --- a/drivers/clk/sunxi-ng/ccu_nkm.h >> +++ b/drivers/clk/sunxi-ng/ccu_nkm.h >> @@ -27,6 +27,8 @@ struct ccu_nkm { >> struct ccu_mux_internal mux; >> >> unsigned int fixed_post_div; >> + unsigned long max_m_n_ratio; >> + unsigned long min_parent_m_ratio; >> >> struct ccu_common common; >> }; >> >>