mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Munique Feitoza <muniquefeitoz4@gmail.com>
To: Lyude Paul <lyude.paul@maintainer.cc>,
	Danilo Krummrich <dakr@kernel.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org,
	Munique Feitoza <muniquefeitoz4@gmail.com>
Subject: [PATCH 2/2] drm/nouveau: add KUnit tests for gt215_pll_calc()
Date: Sun,  6 Dec 2026 05:50:43 -0300	[thread overview]
Message-ID: <20261206085043.76059-3-muniquefeitoz4@gmail.com> (raw)
In-Reply-To: <20261206085043.76059-1-muniquefeitoz4@gmail.com>

Export gt215_pll_calc() for KUnit testing and add unit tests covering
integer mode, fractional mode, and post-divider P clamping.

Signed-off-by: Munique Feitoza <muniquefeitoz4@gmail.com>
---
 .../drm/nouveau/nvkm/subdev/clk/pllgt215.c    |  2 +
 drivers/gpu/drm/nouveau/tests/Makefile        |  3 +-
 drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c | 99 +++++++++++++++++++
 3 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/pllgt215.c b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/pllgt215.c
index c6fccd600db4d0..b236d50d627ffc 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/pllgt215.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/pllgt215.c
@@ -23,6 +23,7 @@
  */
 #include "pll.h"
 
+#include <kunit/visibility.h>
 #include <subdev/bios.h>
 #include <subdev/bios/pll.h>
 
@@ -85,3 +86,4 @@ gt215_pll_calc(struct nvkm_subdev *subdev, struct nvbios_pll *info,
 
 	return info->refclk * *pN / *pM / *P;
 }
+EXPORT_SYMBOL_IF_KUNIT(gt215_pll_calc);
diff --git a/drivers/gpu/drm/nouveau/tests/Makefile b/drivers/gpu/drm/nouveau/tests/Makefile
index e9e16933295a6a..d050e70fde61ad 100644
--- a/drivers/gpu/drm/nouveau/tests/Makefile
+++ b/drivers/gpu/drm/nouveau/tests/Makefile
@@ -6,6 +6,7 @@ ccflags-y += -I $(src)/../nvkm
 ccflags-y += -I $(src)/..
 
 nouveau-kunit-tests-y := \
-	nv50_head_test.o
+	nv50_head_test.o \
+	nvkm_pll_test.o
 
 obj-$(CONFIG_DRM_NOUVEAU_KUNIT_TEST) += nouveau-kunit-tests.o
diff --git a/drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c b/drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c
new file mode 100644
index 00000000000000..72ea1831deef6f
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <kunit/test.h>
+
+#include <subdev/bios.h>
+#include <subdev/bios/pll.h>
+#include <subdev/clk/pll.h>
+
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+
+static struct nvbios_pll make_gf108_vpll(void)
+{
+	return (struct nvbios_pll) {
+		.refclk = 27000,
+		.min_p = 1,
+		.max_p = 16,
+		.vco1 = {
+			.min_freq = 400000,
+			.max_freq = 1000000,
+			.min_inputfreq = 1000,
+			.max_inputfreq = 27000,
+			.min_m = 1,
+			.max_m = 14,
+			.min_n = 8,
+			.max_n = 255,
+		},
+	};
+}
+
+static void nvkm_pll_test_gt215_integer(struct kunit *test)
+{
+	struct nvbios_pll info = make_gf108_vpll();
+	int N = 0, M = 0, P = 0;
+	int ret;
+
+	ret = gt215_pll_calc(NULL, &info, 148500, &N, NULL, &M, &P);
+
+	KUNIT_EXPECT_GT(test, ret, 0);
+	KUNIT_EXPECT_GE(test, P, (int)info.min_p);
+	KUNIT_EXPECT_LE(test, P, (int)info.max_p);
+	KUNIT_EXPECT_GE(test, M, (int)info.vco1.min_m);
+	KUNIT_EXPECT_LE(test, M, (int)info.vco1.max_m);
+	KUNIT_EXPECT_GE(test, N, (int)info.vco1.min_n);
+	KUNIT_EXPECT_LE(test, N, (int)info.vco1.max_n);
+	KUNIT_EXPECT_EQ(test, ret, (int)(info.refclk * N / M / P));
+	/* 148500 kHz from 27000 kHz refclk: exact match with N=66, M=2, P=6 */
+	KUNIT_EXPECT_EQ(test, ret, 148500);
+}
+
+static void nvkm_pll_test_gt215_fractional(struct kunit *test)
+{
+	struct nvbios_pll info = make_gf108_vpll();
+	int N = 0, fN = 0, M = 0, P = 0;
+	int ret;
+
+	ret = gt215_pll_calc(NULL, &info, 106500, &N, &fN, &M, &P);
+
+	KUNIT_EXPECT_EQ(test, ret, 106500);
+	KUNIT_EXPECT_GE(test, P, (int)info.min_p);
+	KUNIT_EXPECT_LE(test, P, (int)info.max_p);
+	KUNIT_EXPECT_GE(test, M, (int)info.vco1.min_m);
+	KUNIT_EXPECT_LE(test, M, (int)info.vco1.max_m);
+	KUNIT_EXPECT_GE(test, N, (int)info.vco1.min_n);
+	KUNIT_EXPECT_LE(test, N, (int)info.vco1.max_n);
+}
+
+static void nvkm_pll_test_gt215_p_clamping(struct kunit *test)
+{
+	struct nvbios_pll info = make_gf108_vpll();
+	int N = 0, M = 0, P = 0;
+	int ret;
+
+	/* High frequency forces P down to min_p (1) */
+	ret = gt215_pll_calc(NULL, &info, 1200000, &N, NULL, &M, &P);
+	KUNIT_EXPECT_GT(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, P, (int)info.min_p);
+
+	/* Low frequency forces P up to max_p (16) */
+	ret = gt215_pll_calc(NULL, &info, 25175, &N, NULL, &M, &P);
+	KUNIT_EXPECT_GT(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, P, (int)info.max_p);
+}
+
+static struct kunit_case nvkm_pll_test_cases[] = {
+	KUNIT_CASE(nvkm_pll_test_gt215_integer),
+	KUNIT_CASE(nvkm_pll_test_gt215_fractional),
+	KUNIT_CASE(nvkm_pll_test_gt215_p_clamping),
+	{ }
+};
+
+static struct kunit_suite nvkm_pll_test_suite = {
+	.name = "nouveau-nvkm-pll",
+	.test_cases = nvkm_pll_test_cases,
+};
+
+kunit_test_suite(nvkm_pll_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for Nouveau nvkm PLL helpers");
+MODULE_LICENSE("GPL");
-- 
2.56.1


      parent reply	other threads:[~2026-12-06  8:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  8:50 [PATCH 0/2] drm/nouveau: add initial KUnit test suite Munique Feitoza
2026-12-06  8:50 ` [PATCH 1/2] drm/nouveau: add KUnit tests for dispnv50 head helpers Munique Feitoza
2026-12-06  8:50 ` Munique Feitoza [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261206085043.76059-3-muniquefeitoz4@gmail.com \
    --to=muniquefeitoz4@gmail.com \
    --cc=airlied@gmail.com \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lyude.paul@maintainer.cc \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®