diff mbox

dtc: parser: Add label while overriding nodes

Message ID 1422456611-15447-1-git-send-email-nikhil.nd@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Nikhil Devshatwar Jan. 28, 2015, 2:50 p.m. UTC
This patch changes the dtc grammar to allow following syntax

i2cexp: &i2c2 {
    ...
};

Current device tree compiler allows to define multiple labels when defining
the device node the first time. Typically device nodes are defined in
DTSI files. Now these nodes can be overwritten for updating some of the
properties. Typically, device nodes are overridden in DTS files.

When working with adapter boards, most of the time adapter board can fit to
multiple base boards. But depending on which base board it is connected to,
the devices on the adapter board would be children of different devices.

e.g. On dra7-evm.dts, i2c2 is exported for expansion connector whereas
on dra72-evm.dts, i2c5 is exported for expansion connector.
This causes a problem when writing a generic device tree file for
the adapter board. Because, you cannot know whether all the devices on
adapter board are present on i2c or i2c5.

The problem can be solved by adding a common label (e.g. i2cexp) in both
of the DTS files when overriding the device nodes for i2c2 or i2c5.
This way, generic adapter board file would override the i2cexp. And
depending on which base board you use the adapter board, all the devices
are automatically added for correct device nodes.

Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
---
 dtc-parser.y |   12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

David Gibson Jan. 29, 2015, 10:07 a.m. UTC | #1
On Wed, Jan 28, 2015 at 08:20:11PM +0530, Nikhil Devshatwar wrote:
> This patch changes the dtc grammar to allow following syntax
> 
> i2cexp: &i2c2 {
>     ...
> };
> 
> Current device tree compiler allows to define multiple labels when defining
> the device node the first time. Typically device nodes are defined in
> DTSI files. Now these nodes can be overwritten for updating some of the
> properties. Typically, device nodes are overridden in DTS files.
> 
> When working with adapter boards, most of the time adapter board can fit to
> multiple base boards. But depending on which base board it is connected to,
> the devices on the adapter board would be children of different devices.
> 
> e.g. On dra7-evm.dts, i2c2 is exported for expansion connector whereas
> on dra72-evm.dts, i2c5 is exported for expansion connector.
> This causes a problem when writing a generic device tree file for
> the adapter board. Because, you cannot know whether all the devices on
> adapter board are present on i2c or i2c5.
> 
> The problem can be solved by adding a common label (e.g. i2cexp) in both
> of the DTS files when overriding the device nodes for i2c2 or i2c5.
> This way, generic adapter board file would override the i2cexp. And
> depending on which base board you use the adapter board, all the devices
> are automatically added for correct device nodes.
> 
> Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>

Hi, sorry I didn't get around to responding to your earlier posting of
this.

The concept is good, and the implementation looks fine.

Only 2 things before I'm ready to merge:
  1) It wants a testcase
  2) I need to stare at the syntax for a while and convince myself
     it's as good as we can reasonably do.
David Gibson Jan. 29, 2015, 10:13 a.m. UTC | #2
On Thu, Jan 29, 2015 at 09:07:31PM +1100, David Gibson wrote:
> On Wed, Jan 28, 2015 at 08:20:11PM +0530, Nikhil Devshatwar wrote:
> > This patch changes the dtc grammar to allow following syntax
> > 
> > i2cexp: &i2c2 {
> >     ...
> > };
> > 
> > Current device tree compiler allows to define multiple labels when defining
> > the device node the first time. Typically device nodes are defined in
> > DTSI files. Now these nodes can be overwritten for updating some of the
> > properties. Typically, device nodes are overridden in DTS files.
> > 
> > When working with adapter boards, most of the time adapter board can fit to
> > multiple base boards. But depending on which base board it is connected to,
> > the devices on the adapter board would be children of different devices.
> > 
> > e.g. On dra7-evm.dts, i2c2 is exported for expansion connector whereas
> > on dra72-evm.dts, i2c5 is exported for expansion connector.
> > This causes a problem when writing a generic device tree file for
> > the adapter board. Because, you cannot know whether all the devices on
> > adapter board are present on i2c or i2c5.
> > 
> > The problem can be solved by adding a common label (e.g. i2cexp) in both
> > of the DTS files when overriding the device nodes for i2c2 or i2c5.
> > This way, generic adapter board file would override the i2cexp. And
> > depending on which base board you use the adapter board, all the devices
> > are automatically added for correct device nodes.
> > 
> > Signed-off-by: Nikhil Devshatwar <nikhil.nd@ti.com>
> 
> Hi, sorry I didn't get around to responding to your earlier posting of
> this.
> 
> The concept is good, and the implementation looks fine.
> 
> Only 2 things before I'm ready to merge:
>   1) It wants a testcase
>   2) I need to stare at the syntax for a while and convince myself
>      it's as good as we can reasonably do.

..and.. #2 is now done.  Give me a testcase, and I'll merge.
diff mbox

Patch

diff --git a/dtc-parser.y b/dtc-parser.y
index ea57e0a..5a897e3 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -140,6 +140,18 @@  devicetree:
 		{
 			$$ = merge_nodes($1, $3);
 		}
+
+	| devicetree DT_LABEL DT_REF nodedef
+		{
+			struct node *target = get_node_by_ref($1, $3);
+
+			add_label(&target->labels, $2);
+			if (target)
+				merge_nodes(target, $4);
+			else
+				ERROR(&@3, "Label or path %s not found", $3);
+			$$ = $1;
+		}
 	| devicetree DT_REF nodedef
 		{
 			struct node *target = get_node_by_ref($1, $2);