diff --git a/tests/drivers/spi/dt_spec/CMakeLists.txt b/tests/drivers/spi/dt_spec/CMakeLists.txt new file mode 100644 index 00000000000..03fe6710d3b --- /dev/null +++ b/tests/drivers/spi/dt_spec/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(spi_dt_spec) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/drivers/spi/dt_spec/app.overlay b/tests/drivers/spi/dt_spec/app.overlay new file mode 100644 index 00000000000..868cebb5e60 --- /dev/null +++ b/tests/drivers/spi/dt_spec/app.overlay @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + * + */ + +/ { + test { + #address-cells = <0x1>; + #size-cells = <0x1>; + + test_gpio: gpio@deadbeef { + compatible = "vnd,gpio"; + gpio-controller; + reg = <0xdeadbeef 0x1000>; + #gpio-cells = <0x2>; + label = "TEST_GPIO"; + status = "okay"; + }; + + test_spi_cs: spi@33334444 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "vnd,spi"; + reg = <0x33334444 0x1000>; + label = "TEST_SPI_CTLR_CS"; + status = "okay"; + clock-frequency = <2000000>; + + cs-gpios = <&test_gpio 0x10 0x20>; + + test_spi_dev_cs: test-spi-dev@0 { + compatible = "vnd,spi-device"; + label = "TEST_SPI_DEV_0"; + reg = <0>; + spi-max-frequency = <2000000>; + }; + }; + + test_spi_no_cs: spi@55556666 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "vnd,spi"; + reg = <0x55556666 0x1000>; + label = "TEST_SPI_CTLR_NO_CS"; + status = "okay"; + clock-frequency = <2000000>; + + test_spi_dev_no_cs: test-spi-dev@0 { + compatible = "vnd,spi-device"; + label = "TEST_SPI_DEV_NO_CS"; + reg = <0>; + spi-max-frequency = <2000000>; + }; + }; + }; +}; diff --git a/tests/drivers/spi/dt_spec/prj.conf b/tests/drivers/spi/dt_spec/prj.conf new file mode 100644 index 00000000000..e86373a9930 --- /dev/null +++ b/tests/drivers/spi/dt_spec/prj.conf @@ -0,0 +1,3 @@ +CONFIG_ZTEST=y +CONFIG_SPI=y +CONFIG_GPIO=y diff --git a/tests/drivers/spi/dt_spec/src/main.c b/tests/drivers/spi/dt_spec/src/main.c new file mode 100644 index 00000000000..e25a4398c01 --- /dev/null +++ b/tests/drivers/spi/dt_spec/src/main.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2022 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(test, CONFIG_LOG_DEFAULT_LEVEL); + +static void test_dt_spec(void) +{ + const struct spi_dt_spec spi_cs = + SPI_DT_SPEC_GET(DT_NODELABEL(test_spi_dev_cs), 0, 0); + + LOG_DBG("spi_cs.bus = %p", spi_cs.bus); + LOG_DBG("spi_cs.config.cs->gpio_dev = %p", spi_cs.config.cs->gpio_dev); + LOG_DBG("spi_cs.config.cs->gpio.port = %p", spi_cs.config.cs->gpio.port); + + zassert_equal(spi_cs.bus, DEVICE_DT_GET(DT_NODELABEL(test_spi_cs)), ""); + zassert_equal(spi_cs.config.cs->gpio_dev, DEVICE_DT_GET(DT_NODELABEL(test_gpio)), ""); + zassert_equal(spi_cs.config.cs->gpio.port, DEVICE_DT_GET(DT_NODELABEL(test_gpio)), ""); + + const struct spi_dt_spec spi_no_cs = + SPI_DT_SPEC_GET(DT_NODELABEL(test_spi_dev_no_cs), 0, 0); + + LOG_DBG("spi_no_cs.bus = %p", spi_no_cs.bus); + LOG_DBG("spi_no_cs.config.cs = %p", spi_no_cs.config.cs); + + zassert_equal(spi_no_cs.bus, DEVICE_DT_GET(DT_NODELABEL(test_spi_no_cs)), ""); + zassert_is_null(spi_no_cs.config.cs, ""); +} + +void test_main(void) +{ + ztest_test_suite(spi_dt_spec, + ztest_unit_test(test_dt_spec) + ); + ztest_run_test_suite(spi_dt_spec); +} diff --git a/tests/drivers/spi/dt_spec/testcase.yaml b/tests/drivers/spi/dt_spec/testcase.yaml new file mode 100644 index 00000000000..8c0909b455e --- /dev/null +++ b/tests/drivers/spi/dt_spec/testcase.yaml @@ -0,0 +1,4 @@ +tests: + drivers.spi.dt_spec: + tags: drivers spi devicetree + depends_on: spi gpio