-
Notifications
You must be signed in to change notification settings - Fork 7.4k
support default property values in devicetree bindings #17829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Only skimmed, but would making |
That's what I'm going to do, but it's not ideal since the common case is there is no delay and so no need for the property to be specified. It just clutters the devicetree source. This is at least the third time I've had a situation where I want a property to be optional in the device tree because I can infer a reasonable default in the driver from other information. This is the first time I've had to handle multiple instances of the device, and C simply doesn't provide the preprocessor capability to abstract the conditional into the generator macro. |
Yeah... just spent a while trying to make an Seems like a reasonable feature now, even if some I'll add it to my todo list. |
For optional properties, it can be handy to generate a default value instead of no value if the property is missing, to cut down on #ifdefs. Allow a default value to be specified in the binding, via a new 'default: <default value>' key on properties in 'properties:'. Suggested by Peter A. Bigot in zephyrproject-rtos#17829. The documentation changes in binding-template.yaml explain the syntax. Fixes: zephyrproject-rtos#17829 Signed-off-by: Ulf Magnusson <[email protected]>
I'm not a fan of this approach, if a default is desired, just have the value set in the .dts file. |
For missing optional properties, it can be handy to generate a default value instead of no value, to cut down on #ifdefs. Allow a default value to be specified in the binding, via a new 'default: <default value>' setting for properties in bindings. Defaults are supported for both scalar and array types. YAML arrays are used to specify the value for array types. 'default:' also appears in json-schema, with the same meaning. Include misc. sanity checks, like the 'default' value matching 'type'. The documentation changes in binding-template.yaml explain the syntax. Suggested by Peter A. Bigot in zephyrproject-rtos#17829. Fixes: zephyrproject-rtos#17829 Signed-off-by: Ulf Magnusson <[email protected]>
For missing optional properties, it can be handy to generate a default value instead of no value, to cut down on #ifdefs. Allow a default value to be specified in the binding, via a new 'default: <default value>' setting for properties in bindings. Defaults are supported for both scalar and array types. YAML arrays are used to specify the value for array types. 'default:' also appears in json-schema, with the same meaning. Include misc. sanity checks, like the 'default' value matching 'type'. The documentation changes in binding-template.yaml explain the syntax. Suggested by Peter A. Bigot in #17829. Fixes: #17829 Signed-off-by: Ulf Magnusson <[email protected]>
I have a device for which the binding should include a property like this:
where absence of the property means that no delay is required.
There may be multiple of these devices, so I'd like the driver implementation file to use a trick like this[*]:
The killer is that
REGULATOR_GPIO_DEVICE(id)
needs to populate a config structure field like this:DT_INST_0_REGULATOR_GPIO_STARTUP_DELAY_US
will either be undefined, or will be defined to a value that is unlikely to be1
, so preprocessor tricks likeCOND_CODE()
won't work forCPP_MAGIC_WRAPPER
.If I could add this to the yaml:
and have the Zephyr scripting provide the default if there isn't one in the node that would make life easier. (Because there are actually multiple properties of this type, and having to do:
rapidly becomes tedious.)
Is there another way to solve this?
[*] well, no, I'd like to have something that does that without having to unroll all the instances up to an arbitrary maximum, but I don't know how to make that happen, either.
The text was updated successfully, but these errors were encountered: