Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions drivers/hwspinlock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions drivers/hwspinlock/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions drivers/hwspinlock/Kconfig.test
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions drivers/hwspinlock/hwspinlock_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2025 Analog Devices, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/drivers/hwspinlock.h>

#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);
12 changes: 12 additions & 0 deletions dts/bindings/test/vnd,hwspinlock-device.yaml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions dts/bindings/test/vnd,hwspinlock.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/lib/devicetree/api_ext/app.overlay
Original file line number Diff line number Diff line change
@@ -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
*
Expand All @@ -21,6 +22,7 @@
reg = <0x20000000 0x1000>;
zephyr,memory-region = "SRAM_REGION";
};

test_sram2: sram@20001000 {
compatible = "zephyr,memory-region", "mmio-sram";
reg = <0x20001000 0x1000>;
Expand Down Expand Up @@ -74,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";
};
};
};
2 changes: 2 additions & 0 deletions tests/lib/devicetree/api_ext/prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CONFIG_ZTEST=y
CONFIG_ADC=y
CONFIG_MBOX=y
CONFIG_HWSPINLOCK=y
CONFIG_SPIN_VALIDATE=n
35 changes: 35 additions & 0 deletions tests/lib/devicetree/api_ext/src/main.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -11,6 +12,7 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/adc.h>
#include <zephyr/drivers/mbox.h>
#include <zephyr/drivers/hwspinlock.h>

#include <zephyr/linker/devicetree_regions.h>

Expand Down Expand Up @@ -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);