Skip to content

Commit

Permalink
dts: bindings: base.yaml: Add hw instance id
Browse files Browse the repository at this point in the history
Durant the process to convert Atmel drivers to use DT_INST_ defines
was detected the necessity of a hardware instance identificator.
Some drivers need configure port pins, clocks, DMA etc. This will
track the hw instance on the DT_INST_x_ independent of the 'x' value.

This will keep simple the conversion this add a new non mandatory
property called <id>. The driver that need these feature need add
'required=true' on the dts/binding/driver  and complement any
device tree with proper value.

Examples:

foo0: foo@1000 {
	compatible = "man,foo-drv";
	id = <0>;
	status="disabled";
};
foo1: foo@1001 {
	compatible = "man,foo-drv";
	id = <1>;
};
barn: bar@2001 {
	compatible = "man,bar-drv";
	id = <10>;
};
barm: bar@3001 {
	compatible = "man,bar-drv";
	id = <20>;
};

Will generate:

DT_INST_0_MAN_FOO_DRV_ID=1
DT_INST_0_MAN_BAR_DRV_ID=10
DT_INST_1_MAN_BAR_DRV_ID=20

It is intent to be used as below to propagate the hardware id on all
driver defines.

DRV_FOO_DEVICE_INIT(0, DT_INST_0_MAN_FOO_DRV_ID);

A good driver example that need this definition:

static const struct drv_foo_dev_cfg drv##n##_sam_config = {	\
	.regs = (Drv *)DT_INST_##n##_MAN_DRV_FOO_BASE_ADDRESS,	\
	.pin_rx = PIN_FOO##m##_RXD,				\
	.pin_tx = PIN_FOO##m##_TXD,				\
}

If 'm' isn't defined the driver will invariably configure the wrong
pins and communication won't happen. This can't be derived by node
name for many reasons. For instance. the above DT snip defined 'barn'
and 'barm' that have a name without number and an unusual value. It
represents two instances of bar that shouldn't assume values other
than defined on the id property.

see zephyrproject-rtos#23107

Signed-off-by: Gerson Fernando Budke <[email protected]>
  • Loading branch information
nandojve committed Mar 8, 2020
1 parent 45bd195 commit 7d7da18
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dts/bindings/base/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ properties:
required: true
description: compatible strings

id:
type: int
description: hardware instance identificator
required: false

reg:
type: array
description: register space
Expand Down

0 comments on commit 7d7da18

Please sign in to comment.