From: Octavian Purdila <tavip@google.com>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, stefanst@google.com, pbonzini@redhat.com,
alex.bennee@linaro.org, thuth@redhat.com,
peter.maydell@linaro.org, marcandre.lureau@redhat.com,
alistair@alistair23.me, berrange@redhat.com, philmd@linaro.org,
jsnow@redhat.com, crosa@redhat.com, bleal@redhat.com
Subject: [RFC PATCH 19/23] test/unit: add unit tests for RT500's clock controller
Date: Mon, 5 Aug 2024 13:17:14 -0700 [thread overview]
Message-ID: <20240805201719.2345596-20-tavip@google.com> (raw)
In-Reply-To: <20240805201719.2345596-1-tavip@google.com>
Add test to exercise clocks set and clear, system PLL initialization,
audio PLL initialization, systick and ostimer clock source selection.
Signed-off-by: Octavian Purdila <tavip@google.com>
---
tests/unit/meson.build | 7 +
tests/unit/test-rt500-clkctl.c | 270 +++++++++++++++++++++++++++++++++
2 files changed, 277 insertions(+)
create mode 100644 tests/unit/test-rt500-clkctl.c
diff --git a/tests/unit/meson.build b/tests/unit/meson.build
index 7a28e7b521..be3062acbf 100644
--- a/tests/unit/meson.build
+++ b/tests/unit/meson.build
@@ -188,6 +188,13 @@ if have_system
meson.project_source_root() / 'hw/ssi/ssi.c',
'spi_tester.c',
],
+ 'test-rt500-clkctl': [
+ hwcore,
+ meson.project_source_root() / 'hw/core/gpio.c',
+ meson.project_source_root() / 'hw/misc/rt500_clkctl0.c',
+ meson.project_source_root() / 'hw/misc/rt500_clkctl1.c',
+ meson.project_source_root() / 'tests/unit/sysbus-mock.c',
+ ],
}
if config_host_data.get('CONFIG_INOTIFY1')
tests += {'test-util-filemonitor': []}
diff --git a/tests/unit/test-rt500-clkctl.c b/tests/unit/test-rt500-clkctl.c
new file mode 100644
index 0000000000..9312091c46
--- /dev/null
+++ b/tests/unit/test-rt500-clkctl.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright (c) 2024 Google LLC
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/log.h"
+#include "qemu/module.h"
+#include "qemu/main-loop.h"
+#include "exec/memory.h"
+#include "hw/clock.h"
+#include "hw/irq.h"
+#include "hw/qdev-clock.h"
+#include "hw/qdev-properties.h"
+
+#include "hw/misc/rt500_clkctl0.h"
+#include "hw/misc/rt500_clkctl1.h"
+#include "hw/misc/rt500_clk_freqs.h"
+#include "sysbus-mock.h"
+#include "reg-utils.h"
+
+typedef struct {
+ DeviceState *clk0;
+ DeviceState *clk1;
+ Clock *sysclk;
+ Clock *systick_clk;
+ Clock *ostimer_clk;
+} TestFixture;
+
+#define SYSCLK_HZ 100000000
+
+#define RT500_CLKCTL0_BASE 0x40001000UL
+#define RT500_CLKCTL1_BASE 0x40021000UL
+
+/*
+ * Test fixture initialization.
+ */
+static void set_up(TestFixture *f, gconstpointer data)
+{
+ f->clk0 = qdev_new(TYPE_RT500_CLKCTL0);
+ g_assert(f->clk0);
+
+ f->clk1 = qdev_new(TYPE_RT500_CLKCTL1);
+ g_assert(f->clk1);
+
+ f->sysclk = clock_new(OBJECT(&f->clk0->parent_obj), "SYSCLK");
+ clock_set_hz(f->sysclk, SYSCLK_HZ);
+
+ qdev_connect_clock_in(f->clk0, "sysclk", f->sysclk);
+ f->systick_clk = RT500_CLKCTL0(f->clk0)->systick_clk;
+
+ qdev_connect_clock_in(f->clk1, "sysclk", f->sysclk);
+ f->ostimer_clk = RT500_CLKCTL1(f->clk1)->ostimer_clk;
+
+ qdev_realize_and_unref(f->clk0, NULL, NULL);
+ sysbus_mmio_map(SYS_BUS_DEVICE(f->clk0), 0, RT500_CLKCTL0_BASE);
+
+ qdev_realize_and_unref(f->clk1, NULL, NULL);
+ sysbus_mmio_map(SYS_BUS_DEVICE(f->clk1), 0, RT500_CLKCTL1_BASE);
+
+ device_cold_reset(f->clk0);
+ device_cold_reset(f->clk1);
+}
+
+static void tear_down(TestFixture *f, gconstpointer user_data)
+{
+ qdev_unrealize(f->clk0);
+ qdev_unrealize(f->clk1);
+ g_free(f->clk0);
+ g_free(f->clk1);
+}
+
+#undef CLKCTL0
+#undef CLKCTL1
+
+static void pscctl_test(TestFixture *f, gconstpointer user_data)
+{
+ /* rom controller clock should be enabled at reset */
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, PSCCTL0, ROM_CTRLR_CLK)
+ == 1);
+
+ /* DSP clk is disabled at reset */
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, PSCCTL0, DSP_CLK) == 0);
+
+ /* check PSCTL_SET functionality */
+ REG32_WRITE(f->clk0, RT500_CLKCTL0, PSCCTL0_SET,
+ RT500_CLKCTL0_PSCCTL0_DSP_CLK_Msk);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, PSCCTL0, DSP_CLK) == 1);
+
+ /* check PSCTL_CLR functionality */
+ REG32_WRITE(f->clk0, RT500_CLKCTL0, PSCCTL0_CLR,
+ RT500_CLKCTL0_PSCCTL0_DSP_CLK_Msk);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, PSCCTL0, DSP_CLK) == 0);
+
+ /* FLEXIO clk is disabled at reset */
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, PSCCTL0, FlexIO) == 0);
+
+ /* check PSCTL_SET functionality */
+ REG32_WRITE(f->clk1, RT500_CLKCTL1, PSCCTL0_SET,
+ RT500_CLKCTL1_PSCCTL0_FlexIO_Msk);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, PSCCTL0, FlexIO) == 1);
+
+ /* check PSCTL_CLR functionality */
+ REG32_WRITE(f->clk1, RT500_CLKCTL1, PSCCTL0_CLR,
+ RT500_CLKCTL1_PSCCTL0_FlexIO_Msk);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, PSCCTL0, FlexIO) == 0);
+}
+
+static void audiopll0pfd_test(TestFixture *f, gconstpointer user_data)
+{
+ /* audio plls are gated at boot */
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD,
+ PFD3_CLKGATE) == 1);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD,
+ PFD2_CLKGATE) == 1);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD,
+ PFD1_CLKGATE) == 1);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD,
+ PFD0_CLKGATE) == 1);
+
+ /* ,,, and clocks are not ready */
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD3_CLKRDY)
+ == 0);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD2_CLKRDY)
+ == 0);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD1_CLKRDY)
+ == 0);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD0_CLKRDY)
+ == 0);
+
+ /* ungate all plls and check that clocks are ready */
+ REG32_WRITE_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD3_CLKGATE, 0);
+ REG32_WRITE_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD2_CLKGATE, 0);
+ REG32_WRITE_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD1_CLKGATE, 0);
+ REG32_WRITE_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD0_CLKGATE, 0);
+
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD3_CLKRDY)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD2_CLKRDY)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD1_CLKRDY)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk1, RT500_CLKCTL1, AUDIOPLL0PFD, PFD0_CLKRDY)
+ == 1);
+}
+
+static void syspll0pfd_test(TestFixture *f, gconstpointer user_data)
+{
+ /* system plls are gated at boot */
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD3_CLKGATE)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD2_CLKGATE)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD1_CLKGATE)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD0_CLKGATE)
+ == 1);
+
+ /* ,,, and clocks are not ready */
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD3_CLKRDY)
+ == 0);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD2_CLKRDY)
+ == 0);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD1_CLKRDY)
+ == 0);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD0_CLKRDY)
+ == 0);
+
+ /* ungate all plls and check that clocks are ready */
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD3_CLKGATE, 0);
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD2_CLKGATE, 0);
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD1_CLKGATE, 0);
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD0_CLKGATE, 0);
+
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD3_CLKRDY)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD2_CLKRDY)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD1_CLKRDY)
+ == 1);
+ g_assert(REG32_READ_FIELD(f->clk0, RT500_CLKCTL0, SYSPLL0PFD, PFD0_CLKRDY)
+ == 1);
+}
+
+static void systick_clk_test(TestFixture *f, gconstpointer user_data)
+{
+ /* systick is not running at reset */
+ g_assert(clock_get_hz(f->systick_clk) == 0);
+
+ /* select divout no divisor */
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSTICKFCLKSEL, SEL,
+ SYSTICKFCLKSEL_DIVOUT);
+ g_assert(clock_get_hz(f->systick_clk) == SYSCLK_HZ);
+
+ /* change divisor to 2 */
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSTICKFCLKDIV, DIV, 1);
+ g_assert(clock_get_hz(f->systick_clk) == SYSCLK_HZ / 2);
+
+ /* select lpsoc */
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSTICKFCLKSEL, SEL,
+ SYSTICKFCLKSEL_LPOSC);
+ g_assert(clock_get_hz(f->systick_clk) == LPOSC_CLK_HZ);
+
+ /* select lpsoc */
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSTICKFCLKSEL, SEL,
+ SYSTICKFCLKSEL_32KHZRTC);
+ g_assert(clock_get_hz(f->systick_clk) == RTC32KHZ_CLK_HZ);
+
+ /* disable clock */
+ REG32_WRITE_FIELD(f->clk0, RT500_CLKCTL0, SYSTICKFCLKSEL, SEL,
+ SYSTICKFCLKSEL_NONE);
+ g_assert(clock_get_hz(f->systick_clk) == 0);
+}
+
+static void ostimer_clk_test(TestFixture *f, gconstpointer user_data)
+{
+ /* systick is not running at reset */
+ g_assert(clock_get_hz(f->ostimer_clk) == 0);
+
+ /* select lpsoc */
+ REG32_WRITE_FIELD(f->clk1, RT500_CLKCTL1, OSEVENTTFCLKSEL, SEL,
+ OSEVENTTFCLKSEL_LPOSC);
+ g_assert(clock_get_hz(f->ostimer_clk) == LPOSC_CLK_HZ);
+
+
+ /* select 32khz RTC */
+ REG32_WRITE_FIELD(f->clk1, RT500_CLKCTL1, OSEVENTTFCLKSEL, SEL,
+ OSEVENTTFCLKSEL_32KHZRTC);
+ g_assert(clock_get_hz(f->ostimer_clk) == RTC32KHZ_CLK_HZ);
+
+ /* select hclk */
+ REG32_WRITE_FIELD(f->clk1, RT500_CLKCTL1, OSEVENTTFCLKSEL, SEL,
+ OSEVENTTFCLKSEL_HCLK);
+ g_assert(clock_get_hz(f->ostimer_clk) == SYSCLK_HZ);
+
+ /* disable clock */
+ REG32_WRITE_FIELD(f->clk1, RT500_CLKCTL1, OSEVENTTFCLKSEL, SEL,
+ OSEVENTTFCLKSEL_NONE);
+ g_assert(clock_get_hz(f->ostimer_clk) == 0);
+}
+
+int main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+
+ /* Initialize object types. */
+ sysbus_mock_init();
+ module_call_init(MODULE_INIT_QOM);
+
+ g_test_add("/rt500-clkctl/pscctl-test", TestFixture, NULL,
+ set_up, pscctl_test, tear_down);
+
+ g_test_add("/rt500-clkctl/syspll0pfd-test", TestFixture, NULL,
+ set_up, syspll0pfd_test, tear_down);
+
+ g_test_add("/rt500-clkctl/audiopll0pfd-test", TestFixture, NULL,
+ set_up, audiopll0pfd_test, tear_down);
+
+ g_test_add("/rt500-clkctl/systick-test", TestFixture, NULL,
+ set_up, systick_clk_test, tear_down);
+
+ g_test_add("/rt500-clkctl/ostimer-clk-test", TestFixture, NULL,
+ set_up, ostimer_clk_test, tear_down);
+
+ return g_test_run();
+}
--
2.46.0.rc2.264.g509ed76dc8-goog
next prev parent reply other threads:[~2024-08-05 20:17 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-05 20:16 [RFC PATCH 00/23] NXP i.MX RT595, ARM SVD and device model unit tests Octavian Purdila
2024-08-05 20:16 ` [RFC PATCH 01/23] fifo32: add peek function Octavian Purdila
2024-08-05 20:16 ` [RFC PATCH 02/23] tests/unit: add fifo test Octavian Purdila
2024-08-05 20:16 ` [RFC PATCH 03/23] scripts: add script to generate C header files from SVD XML files Octavian Purdila
2024-08-08 21:56 ` John Snow
2024-08-08 22:30 ` Octavian Purdila
2024-08-08 23:06 ` John Snow
2024-08-09 9:30 ` Philippe Mathieu-Daudé
2024-08-09 9:42 ` Paolo Bonzini
2024-08-09 9:59 ` Daniel P. Berrangé
2024-08-13 8:32 ` Philippe Mathieu-Daudé
2024-08-09 6:34 ` Paolo Bonzini
2024-08-09 19:28 ` Octavian Purdila
2024-08-12 15:27 ` Peter Maydell
2024-08-12 17:56 ` Octavian Purdila
2024-08-12 22:43 ` Richard Henderson
2024-08-13 15:47 ` Octavian Purdila
2024-08-05 20:16 ` [RFC PATCH 04/23] hw/arm: add SVD file for NXP i.MX RT595 Octavian Purdila
2024-08-06 14:06 ` Alex Bennée
2024-08-06 20:31 ` Octavian Purdila
2024-08-07 11:24 ` Philippe Mathieu-Daudé
2024-08-07 16:36 ` Octavian Purdila
2024-08-09 9:13 ` Daniel P. Berrangé
2024-08-09 22:40 ` Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 05/23] hw: add register access utility functions Octavian Purdila
2024-08-12 15:32 ` Peter Maydell
2024-08-12 21:14 ` Octavian Purdila
2024-08-12 22:35 ` Richard Henderson
2024-08-13 8:28 ` Philippe Mathieu-Daudé
2024-08-05 20:17 ` [RFC PATCH 06/23] hw/misc: add basic flexcomm device model Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 07/23] tests/unit: add system bus mock Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 08/23] test/unit: add register access macros and functions Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 09/23] test/unit: add flexcomm unit test Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 10/23] hw/char: add support for flexcomm usart Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 11/23] test/unit: add flexcomm usart unit test Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 12/23] hw/i2c: add support for flexcomm i2c Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 13/23] test/unit: add i2c-tester Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 14/23] test/unit: add unit tests for flexcomm i2c Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 15/23] hw/ssi: add support for flexcomm spi Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 16/23] test/unit: add spi-tester Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 17/23] test/unit: add unit tests for flexcomm spi Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 18/23] hw/misc: add support for RT500's clock controller Octavian Purdila
2024-08-05 20:17 ` Octavian Purdila [this message]
2024-08-05 20:17 ` [RFC PATCH 20/23] hw/ssi: add support for flexspi Octavian Purdila
2024-08-08 5:11 ` Philippe Mathieu-Daudé
2024-08-08 21:31 ` Octavian Purdila
2024-08-09 8:54 ` Philippe Mathieu-Daudé
2024-08-05 20:17 ` [RFC PATCH 21/23] hw/misc: add support for RT500 reset controller Octavian Purdila
2024-08-08 5:00 ` Philippe Mathieu-Daudé
2024-08-05 20:17 ` [RFC PATCH 22/23] hw/arm: add basic support for the RT500 SoC Octavian Purdila
2024-08-06 14:51 ` Philippe Mathieu-Daudé
2024-08-07 23:57 ` Octavian Purdila
2024-08-05 20:17 ` [RFC PATCH 23/23] hw/arm: add RT595-EVK board Octavian Purdila
2024-08-12 16:10 ` [RFC PATCH 00/23] NXP i.MX RT595, ARM SVD and device model unit tests Peter Maydell
2024-08-12 16:22 ` Daniel P. Berrangé
2024-08-12 18:39 ` Octavian Purdila
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=20240805201719.2345596-20-tavip@google.com \
--to=tavip@google.com \
--cc=alex.bennee@linaro.org \
--cc=alistair@alistair23.me \
--cc=berrange@redhat.com \
--cc=bleal@redhat.com \
--cc=crosa@redhat.com \
--cc=jsnow@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanst@google.com \
--cc=thuth@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.