diff --git a/dts/bindings/test/vnd,gpio-intc-device.yaml b/dts/bindings/test/vnd,gpio-intc-device.yaml new file mode 100644 index 00000000000000..b506062792c4b0 --- /dev/null +++ b/dts/bindings/test/vnd,gpio-intc-device.yaml @@ -0,0 +1,29 @@ +# Copyright (c) 2023 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +description: Test GPIO with INTC node + +compatible: "vnd,gpio-intc-device" + +include: + - gpio-controller.yaml + - interrupt-controller.yaml + - base.yaml + +properties: + reg: + required: true + + "#gpio-cells": + const: 2 + + "#interrupt-cells": + const: 2 + +gpio-cells: + - pin + - flags + +interrupt-cells: + - pin + - flags diff --git a/dts/bindings/test/vnd,interrupt-holder-extended.yaml b/dts/bindings/test/vnd,interrupt-holder-extended.yaml new file mode 100644 index 00000000000000..795b15d9313041 --- /dev/null +++ b/dts/bindings/test/vnd,interrupt-holder-extended.yaml @@ -0,0 +1,15 @@ +# Copyright (c) 2023 Bjarki Arge Andreasen +# SPDX-License-Identifier: Apache-2.0 + +description: Test Interrupt Controller with extended interrupts + +compatible: "vnd,interrupt-holder-extended" + +include: [base.yaml] + +properties: + interrupts-extended: + required: true + + interrupt-names: + required: true diff --git a/tests/lib/devicetree/api/app.overlay b/tests/lib/devicetree/api/app.overlay index 66ff605bfcdca7..00fc428d733900 100644 --- a/tests/lib/devicetree/api/app.overlay +++ b/tests/lib/devicetree/api/app.overlay @@ -203,6 +203,16 @@ status = "okay"; }; + test_gpio_4: gpio@1234abcd { + compatible = "vnd,gpio-intc-device"; + reg = <0x1234abcd 0x500>; + gpio-controller; + #gpio-cells = <0x2>; + interrupt-controller; + #interrupt-cells = <0x2>; + status = "okay"; + }; + test_i2c: i2c@11112222 { #address-cells = < 1 >; #size-cells = < 0 >; @@ -431,6 +441,15 @@ interrupt-names = "err", "stat", "done"; }; + /* there should only be one of these */ + test_irq_extended: interrupt-holder-extended { + compatible = "vnd,interrupt-holder-extended"; + status = "okay"; + interrupts-extended = <&test_intc 70 7>, + <&test_gpio_4 30 3>; + interrupt-names = "int1", "int2"; + }; + test_fixed_clk: test-fixed-clock { compatible = "fixed-clock"; clock-frequency = <25000000>; diff --git a/tests/lib/devicetree/api/src/main.c b/tests/lib/devicetree/api/src/main.c index 72c5426e01a79c..19e5c9e4767b07 100644 --- a/tests/lib/devicetree/api/src/main.c +++ b/tests/lib/devicetree/api/src/main.c @@ -21,12 +21,14 @@ #define TEST_ARRAYS DT_NODELABEL(test_arrays) #define TEST_PH DT_NODELABEL(test_phandles) #define TEST_IRQ DT_NODELABEL(test_irq) +#define TEST_IRQ_EXT DT_NODELABEL(test_irq_extended) #define TEST_TEMP DT_NODELABEL(test_temp_sensor) #define TEST_REG DT_NODELABEL(test_reg) #define TEST_VENDOR DT_NODELABEL(test_vendor) #define TEST_MODEL DT_NODELABEL(test_vendor) #define TEST_ENUM_0 DT_NODELABEL(test_enum_0) #define TEST_64BIT DT_NODELABEL(test_reg_64) +#define TEST_INTC DT_NODELABEL(test_intc) #define TEST_I2C DT_NODELABEL(test_i2c) #define TEST_I2C_DEV DT_PATH(test, i2c_11112222, test_i2c_dev_10) @@ -44,6 +46,7 @@ #define TEST_GPIO_1 DT_NODELABEL(test_gpio_1) #define TEST_GPIO_2 DT_NODELABEL(test_gpio_2) +#define TEST_GPIO_4 DT_NODELABEL(test_gpio_4) #define TEST_GPIO_HOG_1 DT_PATH(test, gpio_deadbeef, test_gpio_hog_1) #define TEST_GPIO_HOG_2 DT_PATH(test, gpio_deadbeef, test_gpio_hog_2) @@ -3149,4 +3152,31 @@ ZTEST(devicetree_api, test_reset) zassert_equal(DT_INST_RESET_ID(0), 10, ""); } +#undef DT_DRV_COMPAT +#define DT_DRV_COMPAT vnd_interrupt_holder_extended +ZTEST(devicetree_api, test_interrupt_controller) +{ + /* DT_IRQ_INTC_BY_IDX */ + zassert_true(DT_SAME_NODE(DT_IRQ_INTC_BY_IDX(TEST_IRQ_EXT, 0), TEST_INTC), ""); + zassert_true(DT_SAME_NODE(DT_IRQ_INTC_BY_IDX(TEST_IRQ_EXT, 1), TEST_GPIO_4), ""); + + /* DT_IRQ_INTC_BY_NAME */ + zassert_true(DT_SAME_NODE(DT_IRQ_INTC_BY_NAME(TEST_IRQ_EXT, int1), TEST_INTC), ""); + zassert_true(DT_SAME_NODE(DT_IRQ_INTC_BY_NAME(TEST_IRQ_EXT, int2), TEST_GPIO_4), ""); + + /* DT_IRQ_INTC */ + zassert_true(DT_SAME_NODE(DT_IRQ_INTC(TEST_IRQ_EXT), TEST_INTC), ""); + + /* DT_INST_IRQ_INTC_BY_IDX */ + zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC_BY_IDX(0, 0), TEST_INTC), ""); + zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC_BY_IDX(0, 1), TEST_GPIO_4), ""); + + /* DT_INST_IRQ_INTC_BY_NAME */ + zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC_BY_NAME(0, int1), TEST_INTC), ""); + zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC_BY_NAME(0, int2), TEST_GPIO_4), ""); + + /* DT_INST_IRQ_INTC */ + zassert_true(DT_SAME_NODE(DT_INST_IRQ_INTC(0), TEST_INTC), ""); +} + ZTEST_SUITE(devicetree_api, NULL, NULL, NULL, NULL, NULL);