Schemas for device trees
jonsmirl at gmail.com
jonsmirl at gmail.com
Mon Apr 2 23:38:36 EST 2012
On Thu, Mar 29, 2012 at 9:59 PM, jonsmirl at gmail.com <jonsmirl at gmail.com> wrote:
> i2c provides an example of where a schema would be useful.
> From the binding text files, I removed the common items
Another reason for schemas, I just misspelled an attribute. It took me
several hours to figure out why my system wasn't working. I ended up
inserting printks in the driver looking for what was wrong before I
figured out that the attribute was simply misspelled. I used
slave-address when the attribute was slave-addr. Schema would have
flagged the unknown attribute at compile time.
------------------------------------------------------------
Using XML schemas is a crazy idea. It would better to leverage the DTC
and kernel infrastructure. We can use a scheme similar to kernel
module support.
The driver source for each OF compatible device would contain macros
that generate a small schema that describes the device.
Instantiation of the device in a real device tree...
ads7846 at 1 {
compatible = "ti,ads7846";
spi-max-frequency = <1200000>;
reg = <1>;
gpio_pendown = <&gpio_gpio 4 0>;
gpio_cs = <&gpio_ebi_i2stx_0 3 0>;
};
schema for this would be something like
{
compatible = "ti,ads7846";
inherits-from = "schema,spi-device"
gpio_pendown* = <&gpio_reference>; /* star = optional */
gpio_cs = <&gpio_reference>;
}
for a spi host...
{
compatible = "nxp,lpc31xx-spi";
inherits-from = "schema,spi-bus"
};
Compiling these drivers would generate two small files containing the
schema snippets into a temp directory.
Another permanent directory would hold the generic definitions.
{
compatible = "schema,spi-device";
inherits-from = "schema,generic-device"
spi-max-frequency* = <0-50M>; /* range validation */
};
{
compatible = "schema,generic-device";
reg = <>;
interrupts = <>;
};
{
compatible = "schema,spi-bus";
inherits-from = "schema,generic-bus"
contains = {"schema,spi-device"}
};
{
compatible = "schema,generic-bus";
reg = <>;
interrupts = <>;
#address-cells = <>;
#size-cells = <>;
};
Now the DT compiler can read in these schema snippets and use them to
pattern match against the DT being compiled and perform validation.
--
Jon Smirl
jonsmirl at gmail.com
More information about the devicetree-discuss
mailing list