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 <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-02-08 16:40:15 -08:00 committed by Kumar Gala
parent 2dca9f4ade
commit b2cc526061
3 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,18 @@
# Copyright (c) 2021 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
description: |
I2C mux
This is an I2C device that is also (multiple) I2C controllers. We
model this as a node which is an I2C device, whose children are I2C
controllers, and whose grandchildren are therefore I2C devices.
compatible: "vnd,i2c-mux"
include: "i2c-device.yaml"
child-binding:
description: I2C mux controller
compatible: "vnd,i2c-mux-controller"
include: "i2c-controller.yaml"

View file

@ -161,6 +161,34 @@
reg = <0x11>;
label = "TEST_EXPANDER_I2C";
};
test_i2c_mux: i2c-mux@12 {
compatible = "vnd,i2c-mux";
label = "I2C_MUX";
reg = <0x12>;
i2c-mux-ctlr-1 {
compatible = "vnd,i2c-mux-controller";
#address-cells = <1>;
#size-cells = <0>;
label = "I2C_MUX_CTLR_1";
test_muxed_i2c_dev_1: muxed-i2c-dev@10 {
compatible = "vnd,i2c-device";
status = "disabled";
reg = <0x10>;
};
};
i2c-mux-ctlr-2 {
compatible = "vnd,i2c-mux-controller";
#address-cells = <1>;
#size-cells = <0>;
label = "I2C_MUX_CTLR_1";
test_muxed_i2c_dev_2: muxed-i2c-dev@10 {
compatible = "vnd,i2c-device";
status = "disabled";
reg = <0x10>;
};
};
};
};
test_i2c_no_reg: i2c {

View file

@ -52,6 +52,12 @@
#define TEST_I2C_DEV DT_PATH(test, i2c_11112222, test_i2c_dev_10)
#define TEST_I2C_BUS DT_BUS(TEST_I2C_DEV)
#define TEST_I2C_MUX DT_NODELABEL(test_i2c_mux)
#define TEST_I2C_MUX_CTLR_1 DT_CHILD(TEST_I2C_MUX, i2c_mux_ctlr_1)
#define TEST_I2C_MUX_CTLR_2 DT_CHILD(TEST_I2C_MUX, i2c_mux_ctlr_2)
#define TEST_MUXED_I2C_DEV_1 DT_NODELABEL(test_muxed_i2c_dev_1)
#define TEST_MUXED_I2C_DEV_2 DT_NODELABEL(test_muxed_i2c_dev_2)
#define TEST_SPI DT_NODELABEL(test_spi)
#define TEST_SPI_DEV_0 DT_PATH(test, spi_33334444, test_spi_dev_0)
@ -304,6 +310,12 @@ static void test_bus(void)
zassert_equal(DT_SPI_DEV_HAS_CS_GPIOS(TEST_SPI_DEV_0), 1, "");
zassert_equal(DT_SPI_DEV_HAS_CS_GPIOS(TEST_SPI_DEV_NO_CS), 0, "");
/* Test a nested I2C bus using vnd,i2c-mux. */
zassert_true(DT_SAME_NODE(TEST_I2C_MUX_CTLR_1,
DT_BUS(TEST_MUXED_I2C_DEV_1)), "");
zassert_true(DT_SAME_NODE(TEST_I2C_MUX_CTLR_2,
DT_BUS(TEST_MUXED_I2C_DEV_2)), "");
#undef DT_DRV_COMPAT
#define DT_DRV_COMPAT vnd_spi_device_2
/* there is only one instance, and it has no CS */