From c02592c6ae87a643131719b6372565e2fe055194 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Thu, 13 Nov 2025 13:52:13 -0600 Subject: [PATCH 1/2] tests: lib: devicetree: Fix devicetree overlay formatting Fixes formatting of the devicetree overlay to make the new DevicetreeLinting compliance check happy. Signed-off-by: Maureen Helm --- tests/lib/devicetree/api_ext/app.overlay | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/devicetree/api_ext/app.overlay b/tests/lib/devicetree/api_ext/app.overlay index 8be62885b8825..cd270ec51d1eb 100644 --- a/tests/lib/devicetree/api_ext/app.overlay +++ b/tests/lib/devicetree/api_ext/app.overlay @@ -21,6 +21,7 @@ reg = <0x20000000 0x1000>; zephyr,memory-region = "SRAM_REGION"; }; + test_sram2: sram@20001000 { compatible = "zephyr,memory-region", "mmio-sram"; reg = <0x20001000 0x1000>; From 389c4384759f2627cd29b2137986eb2b5ce88aed Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Thu, 6 Nov 2025 14:09:01 -0600 Subject: [PATCH 2/2] tests: lib: devicetree: Add hwspinlock dt spec test Extends the devicetree library test to exercise the hwspinlock dt spec macros and detect the context initializer build warning that was fixed in commit 8b208b0d5a358e24e57b5795e0bfaaac9fc1e38c. Previously the build warning wasn't reproducible in-tree. Signed-off-by: Maureen Helm --- drivers/hwspinlock/CMakeLists.txt | 1 + drivers/hwspinlock/Kconfig | 1 + drivers/hwspinlock/Kconfig.test | 6 ++++ drivers/hwspinlock/hwspinlock_test.c | 36 ++++++++++++++++++++ dts/bindings/test/vnd,hwspinlock-device.yaml | 12 +++++++ dts/bindings/test/vnd,hwspinlock.yaml | 11 ++++++ tests/lib/devicetree/api_ext/app.overlay | 14 ++++++++ tests/lib/devicetree/api_ext/prj.conf | 2 ++ tests/lib/devicetree/api_ext/src/main.c | 35 +++++++++++++++++++ 9 files changed, 118 insertions(+) create mode 100644 drivers/hwspinlock/Kconfig.test create mode 100644 drivers/hwspinlock/hwspinlock_test.c create mode 100644 dts/bindings/test/vnd,hwspinlock-device.yaml create mode 100644 dts/bindings/test/vnd,hwspinlock.yaml diff --git a/drivers/hwspinlock/CMakeLists.txt b/drivers/hwspinlock/CMakeLists.txt index 12eb438627317..6de410b190eea 100644 --- a/drivers/hwspinlock/CMakeLists.txt +++ b/drivers/hwspinlock/CMakeLists.txt @@ -3,3 +3,4 @@ zephyr_library() zephyr_library_sources_ifdef(CONFIG_SQN_HWSPINLOCK sqn_hwspinlock.c) +zephyr_library_sources_ifdef(CONFIG_HWSPINLOCK_TEST hwspinlock_test.c) diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig index 22e58528c57c1..dbdd2d6d753d7 100644 --- a/drivers/hwspinlock/Kconfig +++ b/drivers/hwspinlock/Kconfig @@ -22,6 +22,7 @@ config HWSPINLOCK_INIT_PRIORITY # zephyr-keep-sorted-start source "drivers/hwspinlock/Kconfig.sqn" +source "drivers/hwspinlock/Kconfig.test" # zephyr-keep-sorted-stop endif diff --git a/drivers/hwspinlock/Kconfig.test b/drivers/hwspinlock/Kconfig.test new file mode 100644 index 0000000000000..65fab8133e660 --- /dev/null +++ b/drivers/hwspinlock/Kconfig.test @@ -0,0 +1,6 @@ +# Copyright (c) 2025 Analog Devices, Inc. +# SPDX-License-Identifier: Apache-2.0 +# +config HWSPINLOCK_TEST + def_bool DT_HAS_VND_HWSPINLOCK_ENABLED + depends on DT_HAS_VND_HWSPINLOCK_ENABLED diff --git a/drivers/hwspinlock/hwspinlock_test.c b/drivers/hwspinlock/hwspinlock_test.c new file mode 100644 index 0000000000000..215403c8bec87 --- /dev/null +++ b/drivers/hwspinlock/hwspinlock_test.c @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 Analog Devices, Inc. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#define DT_DRV_COMPAT vnd_hwspinlock + +static void vnd_hwspinlock_lock(const struct device *dev, uint32_t id) +{ +} + +static void vnd_hwspinlock_unlock(const struct device *dev, uint32_t id) +{ +} + +static uint32_t vnd_hwspinlock_get_max_id(const struct device *dev) +{ + return 0; +} + +static DEVICE_API(hwspinlock, vnd_hwspinlock_api) = { + .lock = vnd_hwspinlock_lock, + .unlock = vnd_hwspinlock_unlock, + .get_max_id = vnd_hwspinlock_get_max_id, +}; + +#define VND_HWSPINLOCK_INIT(idx) \ + DEVICE_DT_INST_DEFINE(idx, NULL, NULL, NULL, NULL, POST_KERNEL, \ + CONFIG_HWSPINLOCK_INIT_PRIORITY, \ + &vnd_hwspinlock_api) + +DT_INST_FOREACH_STATUS_OKAY(VND_HWSPINLOCK_INIT); diff --git a/dts/bindings/test/vnd,hwspinlock-device.yaml b/dts/bindings/test/vnd,hwspinlock-device.yaml new file mode 100644 index 0000000000000..0d2ad5bb7094f --- /dev/null +++ b/dts/bindings/test/vnd,hwspinlock-device.yaml @@ -0,0 +1,12 @@ +# Copyright (c) 2025 Analog Devices, Inc. +# SPDX-License-Identifier: Apache-2.0 + +description: Test hardware spinlock device node + +compatible: "vnd,hwspinlock-device" + +include: base.yaml + +properties: + hwlocks: + required: true diff --git a/dts/bindings/test/vnd,hwspinlock.yaml b/dts/bindings/test/vnd,hwspinlock.yaml new file mode 100644 index 0000000000000..0248a6f273438 --- /dev/null +++ b/dts/bindings/test/vnd,hwspinlock.yaml @@ -0,0 +1,11 @@ +# Copyright (c) 2025 Analog Devices, Inc. +# SPDX-License-Identifier: Apache-2.0 + +description: Test hardware spinlock node + +compatible: "vnd,hwspinlock" + +include: [base.yaml, hwspinlock-controller.yaml] + +hwlock-cells: + - id diff --git a/tests/lib/devicetree/api_ext/app.overlay b/tests/lib/devicetree/api_ext/app.overlay index cd270ec51d1eb..660be4d0b0101 100644 --- a/tests/lib/devicetree/api_ext/app.overlay +++ b/tests/lib/devicetree/api_ext/app.overlay @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, Commonwealth Scientific and Industrial Research * Organisation (CSIRO) ABN 41 687 119 230. + * Copyright (c) 2025 Analog Devices, Inc. * * SPDX-License-Identifier: Apache-2.0 * @@ -75,5 +76,18 @@ mboxes = <&test_mbox 1>, <&test_mbox 2>, <&test_mbox_zero_cell>; mbox-names = "tx", "rx", "zero"; }; + + test_hwspinlock: hwspinlock { + compatible = "vnd,hwspinlock"; + #hwlock-cells = <1>; + status = "okay"; + }; + + test_hwspinlock_dev: hwspinlock-dev { + compatible = "vnd,hwspinlock-device"; + hwlocks = <&test_hwspinlock 1>, <&test_hwspinlock 2>; + hwlock-names = "rd", "wr"; + status = "okay"; + }; }; }; diff --git a/tests/lib/devicetree/api_ext/prj.conf b/tests/lib/devicetree/api_ext/prj.conf index 80789f1bf709c..bf7098573c99d 100644 --- a/tests/lib/devicetree/api_ext/prj.conf +++ b/tests/lib/devicetree/api_ext/prj.conf @@ -1,3 +1,5 @@ CONFIG_ZTEST=y CONFIG_ADC=y CONFIG_MBOX=y +CONFIG_HWSPINLOCK=y +CONFIG_SPIN_VALIDATE=n diff --git a/tests/lib/devicetree/api_ext/src/main.c b/tests/lib/devicetree/api_ext/src/main.c index d3f742990d501..3be0ce60720d6 100644 --- a/tests/lib/devicetree/api_ext/src/main.c +++ b/tests/lib/devicetree/api_ext/src/main.c @@ -1,6 +1,7 @@ /* * Copyright (c) 2021, Commonwealth Scientific and Industrial Research * Organisation (CSIRO) ABN 41 687 119 230. + * Copyright (c) 2025 Analog Devices, Inc. * * SPDX-License-Identifier: Apache-2.0 */ @@ -11,6 +12,7 @@ #include #include #include +#include #include @@ -59,4 +61,37 @@ ZTEST(devicetree_api_ext, test_mbox_dt_spec) zassert_equal(channel_zero.channel_id, 0, ""); } +#define TEST_HWSPINLOCK \ + DT_NODELABEL(test_hwspinlock) + +#define TEST_HWSPINLOCK_DEV \ + DT_NODELABEL(test_hwspinlock_dev) + +#define HWSPINLOCK_BY_IDX(node_id, prop, idx) \ + HWSPINLOCK_DT_SPEC_GET_BY_IDX(node_id, idx) + +static const struct hwspinlock_dt_spec spec[] = { + DT_FOREACH_PROP_ELEM_SEP(TEST_HWSPINLOCK_DEV, hwlocks, HWSPINLOCK_BY_IDX, (,)) +}; + +static const struct hwspinlock_dt_spec rd = + HWSPINLOCK_DT_SPEC_GET_BY_NAME(TEST_HWSPINLOCK_DEV, rd); + +static const struct hwspinlock_dt_spec wr = + HWSPINLOCK_DT_SPEC_GET_BY_NAME(TEST_HWSPINLOCK_DEV, wr); + +ZTEST(devicetree_api_ext, test_hwspinlock_dt_spec) +{ + for (int i = 0; i < ARRAY_SIZE(spec); i++) { + zassert_equal(spec[i].dev, DEVICE_DT_GET(TEST_HWSPINLOCK)); + zassert_equal(spec[i].id, i + 1); + } + + zassert_equal(rd.dev, DEVICE_DT_GET(TEST_HWSPINLOCK)); + zassert_equal(rd.id, 1); + + zassert_equal(wr.dev, DEVICE_DT_GET(TEST_HWSPINLOCK)); + zassert_equal(wr.id, 2); +} + ZTEST_SUITE(devicetree_api_ext, NULL, NULL, NULL, NULL, NULL);