Skip to content

Commit b2cc526

Browse files
mbolivar-nordicgalak
authored andcommitted
tests: dts: test child bindings with compatibles
Make sure that child bindings with their own compatibles are treated as first-class bindings. Do this by making sure that nodes whose bindings are defined via 'child-binding:' are picked up as bus nodes, instead of a parent bus node of the same type. Signed-off-by: Martí Bolívar <[email protected]>
1 parent 2dca9f4 commit b2cc526

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

dts/bindings/test/vnd,i2c-mux.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
I2C mux
6+
7+
This is an I2C device that is also (multiple) I2C controllers. We
8+
model this as a node which is an I2C device, whose children are I2C
9+
controllers, and whose grandchildren are therefore I2C devices.
10+
11+
compatible: "vnd,i2c-mux"
12+
13+
include: "i2c-device.yaml"
14+
15+
child-binding:
16+
description: I2C mux controller
17+
compatible: "vnd,i2c-mux-controller"
18+
include: "i2c-controller.yaml"

tests/lib/devicetree/api/app.overlay

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,34 @@
161161
reg = <0x11>;
162162
label = "TEST_EXPANDER_I2C";
163163
};
164+
165+
test_i2c_mux: i2c-mux@12 {
166+
compatible = "vnd,i2c-mux";
167+
label = "I2C_MUX";
168+
reg = <0x12>;
169+
i2c-mux-ctlr-1 {
170+
compatible = "vnd,i2c-mux-controller";
171+
#address-cells = <1>;
172+
#size-cells = <0>;
173+
label = "I2C_MUX_CTLR_1";
174+
test_muxed_i2c_dev_1: muxed-i2c-dev@10 {
175+
compatible = "vnd,i2c-device";
176+
status = "disabled";
177+
reg = <0x10>;
178+
};
179+
};
180+
i2c-mux-ctlr-2 {
181+
compatible = "vnd,i2c-mux-controller";
182+
#address-cells = <1>;
183+
#size-cells = <0>;
184+
label = "I2C_MUX_CTLR_1";
185+
test_muxed_i2c_dev_2: muxed-i2c-dev@10 {
186+
compatible = "vnd,i2c-device";
187+
status = "disabled";
188+
reg = <0x10>;
189+
};
190+
};
191+
};
164192
};
165193

166194
test_i2c_no_reg: i2c {

tests/lib/devicetree/api/src/main.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
#define TEST_I2C_DEV DT_PATH(test, i2c_11112222, test_i2c_dev_10)
5353
#define TEST_I2C_BUS DT_BUS(TEST_I2C_DEV)
5454

55+
#define TEST_I2C_MUX DT_NODELABEL(test_i2c_mux)
56+
#define TEST_I2C_MUX_CTLR_1 DT_CHILD(TEST_I2C_MUX, i2c_mux_ctlr_1)
57+
#define TEST_I2C_MUX_CTLR_2 DT_CHILD(TEST_I2C_MUX, i2c_mux_ctlr_2)
58+
#define TEST_MUXED_I2C_DEV_1 DT_NODELABEL(test_muxed_i2c_dev_1)
59+
#define TEST_MUXED_I2C_DEV_2 DT_NODELABEL(test_muxed_i2c_dev_2)
60+
5561
#define TEST_SPI DT_NODELABEL(test_spi)
5662

5763
#define TEST_SPI_DEV_0 DT_PATH(test, spi_33334444, test_spi_dev_0)
@@ -304,6 +310,12 @@ static void test_bus(void)
304310
zassert_equal(DT_SPI_DEV_HAS_CS_GPIOS(TEST_SPI_DEV_0), 1, "");
305311
zassert_equal(DT_SPI_DEV_HAS_CS_GPIOS(TEST_SPI_DEV_NO_CS), 0, "");
306312

313+
/* Test a nested I2C bus using vnd,i2c-mux. */
314+
zassert_true(DT_SAME_NODE(TEST_I2C_MUX_CTLR_1,
315+
DT_BUS(TEST_MUXED_I2C_DEV_1)), "");
316+
zassert_true(DT_SAME_NODE(TEST_I2C_MUX_CTLR_2,
317+
DT_BUS(TEST_MUXED_I2C_DEV_2)), "");
318+
307319
#undef DT_DRV_COMPAT
308320
#define DT_DRV_COMPAT vnd_spi_device_2
309321
/* there is only one instance, and it has no CS */

0 commit comments

Comments
 (0)