From patchwork Mon Dec 18 13:35:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13497498 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 EDBDDC35274 for ; Mon, 18 Dec 2023 19:33:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2D3AF10E377; Mon, 18 Dec 2023 19:33:09 +0000 (UTC) Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1C9E110E2AC for ; Mon, 18 Dec 2023 19:32:56 +0000 (UTC) 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 4Sv1736BG3z9srG; Mon, 18 Dec 2023 14:35:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1702906559; 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=lhH/bcgkoYYVusGSERNWzcLW4QNviF8TX6rnqWIzeCk=; b=R36Ei/tlA/gFrncF84P2coFPyvM/2UGH+zakg6uG0U2xBTPmMgBtM/aJDBiAOy7qbE++a1 u0eqzA6MY87MmDoGspbgp7M3GoPMF2seV4yqJrx4bSFKuHO64sFzxgmis8I9NmyDagi6KP Eaj7zcOsm9Yv1Dt2nIh1riZkpicGycYuif/tK27Ch9i7zn+sUMfpF3g92cRsLZ9S7fUl4O jZ1Wk2Y6Kt5Q+PIARxMjra8ChiJvwJVcFu8AFnIm/oyu9xBUjQQ2RoOSSNhzQ4rdc70dqS aa6Z+qQIhhMqFXorBq31wf7cWiRwSIh8tSnGHxKVLbd5Ujy9aohAaNk4eIFoag== From: Frank Oltmanns Date: Mon, 18 Dec 2023 14:35:19 +0100 Subject: [PATCH 1/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate MIME-Version: 1.0 Message-Id: <20231218-pinephone-pll-fixes-v1-1-e238b6ed6dc1@oltmanns.dev> References: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> In-Reply-To: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , =?utf-8?q?Guido_G=C3=BCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter X-Developer-Signature: v=1; a=openpgp-sha256; l=2994; i=frank@oltmanns.dev; h=from:subject:message-id; bh=Rra44nc/cyGyhsB+ze6yf+US4TD8Cx4NQMigrd6Oh5g=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBlgEq050/yrkshXjJqwGSt+TqqVkIWZwZHmQeVe ZO1qf59R+CJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZYBKtAAKCRCaaaIIlErT x4L5C/9hvff5Q65+OLSZfpUZPdoijXeP/TEQl4/8FkstsruiiD336QDB9l0KY9TIo7BmfDG2Xm+ 6bQ37ParFNTIddTR5t/iJ7aqaJpqNd23/AkVelTS77zBSnIFhhnA4TWq6ECVkq2aaEaHMnPXgAR BzbHRdygkHfhaFtwBU/Bq15B06d4Hp6vDO7+rSO2FQkdE4oKY6Hm3231xgcYZPu+juai/M+KsGE iiotrp0y0jlpiyp//LWdJjzRCVKFO4tJR0QgpxpaynX6aBeRM1F/FMOBk6KlZ7i3e9g5cZ1+9s+ 1y6AB02qRwDcggQHFQBcASrjApe/l9ACg4BS9tON9u1mIjZuO/wrskwtE+ivHbUkv3Tu9iPJtTW 15E1DOzSZGI0Kv0FT7L0I7SkSYjiJtGxXtjTw6Eu47FadaMMcxAVwxmMO6YN3rZ1jP68JHHOym0 6k4mMUr8/uHhjdGUt3trg58gYdjbUOzeYL30hTt7PNh0tRJBeOUSQhRjpdaGQDh6ScLK4= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Frank Oltmanns , linux-sunxi@lists.linux.dev, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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; + 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; }; From patchwork Mon Dec 18 13:35:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13497499 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 97932C35274 for ; Mon, 18 Dec 2023 19:33:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 72C8710E391; Mon, 18 Dec 2023 19:33:09 +0000 (UTC) Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1961610E07D for ; Mon, 18 Dec 2023 19:32:56 +0000 (UTC) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::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 4Sv1785yHbz9sdL; Mon, 18 Dec 2023 14:36:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1702906564; 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=eDFi8CTJUkTd5zxbOYuJnvPd3KneFrWxg/uiRc7lnPo=; b=tBVSsvYIVe0xQT3B+rWNnbM9Mi4E3pe48xmfJm1SiCfeYA6B8oTUhgzOtkiyY0819Cg1kU VoPkjVwLWJHmqoWMMcEPBUj+g/rZBDOV/EoK4f3EkXyJJVl0szABd9M3N80vfc3WjBNgJV 784nPvTIAfDAUid3GVK1SYBzdSBw76w3CxeytU8qZ+0kyknyj9Hu1HWYJKSdnD5d2Rf8gz /l7H8EwarwJpulkAHJ7i6gnfIu72MSHCAKOwPTOwDS996ynOkzOzvhZGlOXONBC9suUtaC MVdvzB1SmZQfcI0Dr/2YPy1MD2hXOeFFJGU1MgZOhQyCnJOj+HMApnw8nEUjHw== From: Frank Oltmanns Date: Mon, 18 Dec 2023 14:35:20 +0100 Subject: [PATCH 2/5] clk: sunxi-ng: a64: Add constraints on PLL-MIPI's n/m ratio and parent rate MIME-Version: 1.0 Message-Id: <20231218-pinephone-pll-fixes-v1-2-e238b6ed6dc1@oltmanns.dev> References: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> In-Reply-To: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , =?utf-8?q?Guido_G=C3=BCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter X-Developer-Signature: v=1; a=openpgp-sha256; l=831; i=frank@oltmanns.dev; h=from:subject:message-id; bh=9VxWwX1vCUxu7Hc741L8dSjIHrhsgQCwsWW/01PJBwE=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBlgEq19E5P79VQDYi6Zr///gDuzEr7rVmNkbiml VePSHhJbqeJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZYBKtQAKCRCaaaIIlErT x+SiC/oDWxNg5UY7m1mF7KBxsid/6Tsx9F75ZRYqKpRotMZqwuElIehxafv898mDjPDG2d0vqkM FeinlyPRktnISeycYImZL6xQCyhqipZn6aQnvPZPXHw7jvx9+sM3Ua2QktJ+GI4VBDgYIKh+2od 2EkRw270C90pMsuT/oHwwh3lSzE1MRTDtuGRyxT0PJbZ7sJfAgvFSEK/Gohm8AWpcDzU/QnFDbA 0R8uKC9mxI48xBzq+4Pma8DuVEmmFqSWeh7A7m58EE3pIzoSDC/n06f3U88bBFT/fCTjX2eXg/l DxFYwNwg8cqLmMuz/nWxfjbYItGpSRtu5+2eLNRDdMVqkgVUrNjNR8CVVbHLY1eEkvcf/W1NRcC Y6OTZvk4tvpfzAo7uR/yWo3RBXwDwmJ+UC5c4RE1uJXxje2pR4kCQvYHfx1FCb3HtoetLSXSPFN oBBfjNGeX5SrbcIahVWk7H5OF13yM0JEtFZSRP/Yt0zJIX8MBa7mD4+pIGVbMtnLKuyLI= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4Sv1785yHbz9sdL X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Frank Oltmanns , linux-sunxi@lists.linux.dev, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The Allwinner A64 manual lists the following constraints for the PLL-MIPI clock: - M/N >= 3 - (PLL_VIDEO0)/M >= 24MHz Use these constraints. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c index 8951ffc14ff5..c034ac027d1c 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -176,6 +176,8 @@ static struct ccu_nkm pll_mipi_clk = { .n = _SUNXI_CCU_MULT(8, 4), .k = _SUNXI_CCU_MULT_MIN(4, 2, 2), .m = _SUNXI_CCU_DIV(0, 4), + .max_mn_ratio = 3, + .parent_wo_nk = 24000000, .common = { .reg = 0x040, .hw.init = CLK_HW_INIT("pll-mipi", "pll-video0", From patchwork Mon Dec 18 13:35:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13497500 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 E64F9C35274 for ; Mon, 18 Dec 2023 19:33:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0918F10E144; Mon, 18 Dec 2023 19:33:14 +0000 (UTC) Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1281A10E2C9 for ; Mon, 18 Dec 2023 19:31:51 +0000 (UTC) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::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-202.mailbox.org (Postfix) with ESMTPS id 4Sv17D6pmMz9spY; Mon, 18 Dec 2023 14:36:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1702906569; 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=yxtk83TwUN0VceZvRnC2EeHgKW+WXgUR7ixken6dUY4=; b=apjSg2LzkrIFwQkduz6/06Bhype5LfUj7ino5vfUAXK9zTjohCQRTBH+FFMgVkb39DDsCC qe3XzKdyax4u/OOURdNRwvSmr7QTQtUicB0w/u6ENiF/kxzLmecOhIjtNKFuqaIxdXIumn w6ee7gCTx+qye5L4jyDucJmkn1hsuz7dN6/Lp9w4+kuBLk+4OAkV1yOCI9vvAMbsnoC/KC Qidxvxbw0GJnL5NVb0WtERQU2I2mowKwo76YKynse7kYFy60Ib0wKyZhThwx8XydTfBSCc F5ssg00kcTqhkSuXRlNKrsya0T1QLwMfTlFVSB1rf43koUltznzC2dd3PKrbyg== From: Frank Oltmanns Date: Mon, 18 Dec 2023 14:35:21 +0100 Subject: [PATCH 3/5] clk: sunxi-ng: nm: Support constraints on n/m ratio and parent rate MIME-Version: 1.0 Message-Id: <20231218-pinephone-pll-fixes-v1-3-e238b6ed6dc1@oltmanns.dev> References: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> In-Reply-To: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , =?utf-8?q?Guido_G=C3=BCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter X-Developer-Signature: v=1; a=openpgp-sha256; l=4021; i=frank@oltmanns.dev; h=from:subject:message-id; bh=mTT0TdC8MF6bUvNEQSrDhtACC0CeYZEAGGdbPaSNC/g=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBlgEq1kJc2STPHa/pkXQ2BvjxkjpLdFUr+xmDFH Wj0A1DilGSJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZYBKtQAKCRCaaaIIlErT xzvmC/wMINJUDhSp9FdIb8sCaRKy2CrTQhZXpufTzT8FNRdsxN3xV/HE+LVlhRzgOpzC5YpRGx2 JIbgtvX+ALwZ+MvUfTIBKjwMe7q7FWNsGBYvZDI8gsdIj3WvKn9WEpSaIOuz0zcmzfOtWrgIqFs uLSlq4az82QGazG/naM8sapiCc7ptqmj+cVyOihnSRevx3N1E8L07SPHKU1SSsyqmXuTwr/09Gm AUbDIqCN86uXQCCeBxWo6i8BkrYY5pkvRggXtAtK1kmQtRVYCjiIGJljenBahHR3+mWo8vUaEnz /8VxUVBzz4XGkqxWIJFhQyxJ+fswIgVJhurhTMnLGE3rXVNwnyNa72MVv2NyaC/YaS7B9L8/01R SsDC7sanA5tRZQU4IEpC9p0l/fBak4WMfUtucDLI39qgbMtrdgrJ9gUU9GY4407bRxyDF/EfKYz vNhO9JkjLZ2QYiYrT1yo2IfEyStnqcn6FZjLa8U2hq8mWBtkutbP10KNJMS02KO6Ou8T4= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4Sv17D6pmMz9spY X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Frank Oltmanns , linux-sunxi@lists.linux.dev, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The Allwinner A64 manual lists the following constraint for the PLL-VIDEO0 clock: 8 <= N/M <= 25 The PLL-MIPI clock is implemented as ccu_nm. Therefore, add support for this constraint. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_nm.c | 21 +++++++++++++++++++-- drivers/clk/sunxi-ng/ccu_nm.h | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_nm.c b/drivers/clk/sunxi-ng/ccu_nm.c index ffac3deb89d6..cfc6981e398b 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.c +++ b/drivers/clk/sunxi-ng/ccu_nm.c @@ -27,6 +27,19 @@ static unsigned long ccu_nm_calc_rate(unsigned long parent, return rate; } +static bool ccu_nm_is_valid_rate(struct ccu_common *common, unsigned long n, unsigned long m) +{ + struct ccu_nm *nm = container_of(common, struct ccu_nm, common); + + if (nm->max_nm_ratio && (n > nm->max_nm_ratio * m)) + return false; + + if (nm->min_nm_ratio && (n < nm->min_nm_ratio * m)) + return false; + + return true; +} + static unsigned long ccu_nm_find_best(struct ccu_common *common, unsigned long parent, unsigned long rate, struct _ccu_nm *nm) { @@ -36,8 +49,12 @@ static unsigned long ccu_nm_find_best(struct ccu_common *common, unsigned long p for (_n = nm->min_n; _n <= nm->max_n; _n++) { for (_m = nm->min_m; _m <= nm->max_m; _m++) { - unsigned long tmp_rate = ccu_nm_calc_rate(parent, - _n, _m); + unsigned long tmp_rate; + + if (!ccu_nm_is_valid_rate(common, _n, _m)) + continue; + + tmp_rate = ccu_nm_calc_rate(parent, _n, _m); if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { best_rate = tmp_rate; diff --git a/drivers/clk/sunxi-ng/ccu_nm.h b/drivers/clk/sunxi-ng/ccu_nm.h index 93c11693574f..0075df6d9697 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.h +++ b/drivers/clk/sunxi-ng/ccu_nm.h @@ -31,6 +31,8 @@ struct ccu_nm { unsigned int fixed_post_div; unsigned int min_rate; unsigned int max_rate; + unsigned long min_nm_ratio; /* minimum value for m/n */ + unsigned long max_nm_ratio; /* maximum value for m/n */ struct ccu_common common; }; @@ -108,7 +110,8 @@ struct ccu_nm { }, \ } -#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT_NM_RATIO( \ + _struct, _name, \ _parent, _reg, \ _min_rate, _max_rate, \ _nshift, _nwidth, \ @@ -117,7 +120,9 @@ struct ccu_nm { _frac_rate_0, \ _frac_rate_1, \ _gate, _lock, _flags, \ - _features) \ + _features, \ + _min_nm_ratio, \ + _max_nm_ratio) \ struct ccu_nm _struct = { \ .enable = _gate, \ .lock = _lock, \ @@ -128,6 +133,8 @@ struct ccu_nm { _frac_rate_1), \ .min_rate = _min_rate, \ .max_rate = _max_rate, \ + .min_nm_ratio = _min_nm_ratio, \ + .max_nm_ratio = _max_nm_ratio, \ .common = { \ .reg = _reg, \ .features = _features, \ @@ -138,6 +145,29 @@ struct ccu_nm { }, \ } +#define 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, \ + _features) \ + SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT_NM_RATIO( \ + _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, \ + _features, \ + 0, 0) + #define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \ _parent, _reg, \ _min_rate, _max_rate, \ From patchwork Mon Dec 18 13:35:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13497502 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 71F5EC46CD3 for ; Mon, 18 Dec 2023 19:35:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0685710E2AC; Mon, 18 Dec 2023 19:35:31 +0000 (UTC) Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1A84D10E144 for ; Mon, 18 Dec 2023 19:32:56 +0000 (UTC) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::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 4Sv17K2gCpz9ssY; Mon, 18 Dec 2023 14:36:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1702906573; 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=3knn0KnfHEWgYWaadr1J0evJJiSgFisyuPOwfE6u7RA=; b=WB3Doh5kKvL3k78nLJhWQFOk2fz64k4yLEVREuaYRL11WlmELNwJnVC4VMp90rfJ9MZ2ul dwbxOOckPhBVugw1Ja6zntM4xHkDYJxoYuCCiMKf25IhBnGbatVlzdZ/Bf7xBrFc3LYAjb UMkcloU9B44sJ+gLt0SAZXQKoBJmYDlhlDcN3bO6DvFaEjlsPdEuuneqRGEsUoErAJ0abH OrAFgyWCw2AEl6N/62c+eiR7zKJioQZTXYnnOKFp4gmZ7Uen2i+G7rtAASgJsQcJRZCbsH RzSxFpyKaGjap7H2pCuAxGqJ6PZetOb6i+qumcyTlMFXn51HRrIJBKQW1midvw== From: Frank Oltmanns Date: Mon, 18 Dec 2023 14:35:22 +0100 Subject: [PATCH 4/5] clk: sunxi-ng: a64: Add constraints on PLL-VIDEO0's n/m ratio MIME-Version: 1.0 Message-Id: <20231218-pinephone-pll-fixes-v1-4-e238b6ed6dc1@oltmanns.dev> References: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> In-Reply-To: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , =?utf-8?q?Guido_G=C3=BCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter X-Developer-Signature: v=1; a=openpgp-sha256; l=1435; i=frank@oltmanns.dev; h=from:subject:message-id; bh=jj1kC8r64WXDg1/5wbxM9P8hCH8A2GebZKvM1vIvFPo=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBlgEq1xinOlh9sftstb32086w7Ky1jm6/lGaxZ5 NrpDnJiE4+JAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZYBKtQAKCRCaaaIIlErT x93iC/9GPVPladgryx1JLV+61g8cBhKv2Cudg3FL/5IIT/LP93v+OTcSmNzjfcQNGNz1czgvP3P m2srxWLpJXHtskjrNSrFM2K16MDEUHig33MfYl1n8Q4vN0taaY+bLFbKlFKZjhuMvuQte12QG1m oRbq5Gm6B1ss/VIjAksUn+QzzMjHz0xlllP894PtmNR7yrfYU7eBdvEnV1xx53Q0nVuWFfww7AZ dTdG+1RiE4j68NAnJtiB4E4nni7OITmxS1es1FK4UDLC/38jSLl2FjGkvv+kLLwAJGRcmVt49PS vIRWeslKFohfcV7CJDoVhuKX1vExq6PBoTiB94VCmo3DgsIJPgZ6k/XusI2eFYQxpaEuQcYhzFD bwSOtn2l6ZGTf+nCqnTLltr3qAFY/flWypH1qs1fNzWOHtXZoPBpct6xJU3pEe0XPkA9tpQmUPk RsrQui/HQyrioIOF9OI+iJFPG9ZxK8J0p0xV3Zx0ABNPxg6fDgalK/l4zkxh1LeH5WwHA= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4Sv17K2gCpz9ssY X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Frank Oltmanns , linux-sunxi@lists.linux.dev, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The Allwinner A64 manual lists the following constraint for the PLL-VIDEO0 clock: 8 <= N/M <= 25 Use this constraint. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c index c034ac027d1c..75d839da446c 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -68,7 +68,8 @@ static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", BIT(28), /* lock */ CLK_SET_RATE_UNGATE); -static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(pll_video0_clk, "pll-video0", +static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT_NM_RATIO(pll_video0_clk, + "pll-video0", "osc24M", 0x010, 192000000, /* Minimum rate */ 1008000000, /* Maximum rate */ @@ -80,7 +81,10 @@ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(pll_video0_clk, "pll-vid 297000000, /* frac rate 1 */ BIT(31), /* gate */ BIT(28), /* lock */ - CLK_SET_RATE_UNGATE); + CLK_SET_RATE_UNGATE, + CCU_FEATURE_FRACTIONAL | + CCU_FEATURE_CLOSEST_RATE, + 8, 25); /* min/max nm ratio */ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve", "osc24M", 0x018, From patchwork Mon Dec 18 13:35:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13497501 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (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 B2DC6C35274 for ; Mon, 18 Dec 2023 19:33:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 61B5E10E07D; Mon, 18 Dec 2023 19:33:14 +0000 (UTC) Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1AD9D10E27F for ; Mon, 18 Dec 2023 19:32:56 +0000 (UTC) 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 4Sv17Q1Z1Cz9sv0; Mon, 18 Dec 2023 14:36:18 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1702906578; 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=zHjXX8T22A8vSDhmcbXCgVqx2gpy6+LirkB+PVRAonw=; b=eLflKYcE7WuO2izSmh+X4mn7M4W4r5tiLf9tLy/gpwJ+HYuWpLQlyVLDfp3gMot+v2Cv2N EiK/PmJIEErOafvsXPHmGQY90NZMbO/zi1o7/xuzR2ocO/zYJ/N6j/s/YVYfb39sT3SwtT aoww2i0Hke2YsfumQiIWt5egYYkJCVFq9CmRzwfLV3N+waySq5cjnUT1xoiZ3BSY9ChWB3 U7I7zD9g71JhPSGIUVT448PdHgMiaNjileX7O6INdR6Jrij23kJ3GNRPPEaVbmlIW+BcsX 1DwPFtGSrXbqD8QVz8/tksdd7MGBqGQ42fZMYiESibwLRyicfQwoUSb2sybBmQ== From: Frank Oltmanns Date: Mon, 18 Dec 2023 14:35:23 +0100 Subject: [PATCH 5/5] drm/panel: st7703: Drive XBD599 panel at higher clock rate MIME-Version: 1.0 Message-Id: <20231218-pinephone-pll-fixes-v1-5-e238b6ed6dc1@oltmanns.dev> References: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> In-Reply-To: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev> To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , =?utf-8?q?Guido_G=C3=BCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter X-Developer-Signature: v=1; a=openpgp-sha256; l=1524; i=frank@oltmanns.dev; h=from:subject:message-id; bh=SAMO997ikQjd5G5gtpw1xcptKu2mOxUiT+50d/YBtmI=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBlgEq1fGk87SLdf4iGeylAn1TQ+0H3qF+BNVT6u HjpEFxEqgCJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZYBKtQAKCRCaaaIIlErT x9WPC/97CEvcAl7/lqqTgFUkj4zb5ppCtk9rJIICkdmTftzH99U8PSxmXE0nEf8iTgYdjng9Bx0 k8h58NQZlu9Ps/sbc+lo0PbQuWCGnDUYRSw3H97Ct1ju7uKs714t69LhGUtgBK1JFsg4vrhv9Ch d9E6vrurGJ+KKUbl1lHArTu3cD9ygcg1q6K1kfD1AsHzfH/dQWXUYjSTsrv8jgagl7VerjnL4r6 dqLNaVl1q5iSJV/RqerAulhUjp6A0frnJOsnltaZiECVdfsoa2ermOBOgrApTJHE8wsJwTw0FXy pkBvnm9ZXsaQNI+jbMt5sWUZDld7hwsIn15rF6BpanhgXL0XS8fDVgpKQFLfLK6+HyfkX8js4u5 X9xCCISayV/Nd+L7Wlx0um2UprwxuUoJ5uwkLqD9urRVV6ievIWaBnoNMSnOoQs5Xk8GancYKVF Tun737PSoCemEJMoweiWRqO/Jb7lnbvPtEmDmapfv8mKeBY6rfIUXBPJc2BlVRJ+rq9Gs= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Frank Oltmanns , linux-sunxi@lists.linux.dev, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This panel is used in the pinephone that runs on a Allwinner A64 SOC. Acoording to it's datasheet, the SOC requires PLL-MIPI to run at more than 500 MHz. Therefore, change [hv]sync_(start|end) so that we reach a clock rate that is high enough to drive PLL-MIPI within its limits. Signed-off-by: Frank Oltmanns --- drivers/gpu/drm/panel/panel-sitronix-st7703.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/panel/panel-sitronix-st7703.c b/drivers/gpu/drm/panel/panel-sitronix-st7703.c index b55bafd1a8be..6886fd7f765e 100644 --- a/drivers/gpu/drm/panel/panel-sitronix-st7703.c +++ b/drivers/gpu/drm/panel/panel-sitronix-st7703.c @@ -320,14 +320,14 @@ static int xbd599_init_sequence(struct st7703 *ctx) static const struct drm_display_mode xbd599_mode = { .hdisplay = 720, - .hsync_start = 720 + 40, - .hsync_end = 720 + 40 + 40, - .htotal = 720 + 40 + 40 + 40, + .hsync_start = 720 + 65, + .hsync_end = 720 + 65 + 65, + .htotal = 720 + 65 + 65 + 65, .vdisplay = 1440, - .vsync_start = 1440 + 18, - .vsync_end = 1440 + 18 + 10, - .vtotal = 1440 + 18 + 10 + 17, - .clock = 69000, + .vsync_start = 1440 + 30, + .vsync_end = 1440 + 30 + 22, + .vtotal = 1440 + 30 + 22 + 29, + .clock = (720 + 65 + 65 + 65) * (1440 + 30 + 22 + 29) * 60 / 1000, .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC, .width_mm = 68, .height_mm = 136,