Re: [PATCH v3] Allow device tree to be modified by additonal device tree sections

2010-02-26 Thread Jon Loeliger
 
 Oops, I was hoping to make a few tweaks to that before it was
 applied.  Oh well, it was basically only more thorough testcases, so
 that can be added later.

Sorry -- I had no idea about that.

Follow up patches welcome, of course!

jdl
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[PATCH] Add merging of labelled subnodes. This patch allows the following

2010-02-26 Thread Grant Likely
syntax:

/ {
child {
label: subchild {
};
};
};

label {
prop = value;
};

which will result in the following tree:
/ {
child {
label: subchild {
prop = value;
};
};
};

---

Hi Jon and David

This patch isn't quite finished yet, but I'm getting it out there for
feedback.  In particular, I'm don't know how best to handle errors in
livetree.c.  The way I'm currently handling it is calling yyerror()
from livetree.c, which results in a compile warning.

I also don't yet have a test case for referencing a label that doesn't
exist in the main tree.

I could use some help on how I should be implementing the error
handling.

Thanks,
g.
---

 dtc-lexer.l |2 +-
 dtc-parser.y|   13 +++
 dtc.h   |1 +
 livetree.c  |   30 ++
 tests/run_tests.sh  |2 ++
 tests/test_tree1.dts|2 +-
 tests/test_tree1_merge.dts  |4 +--
 tests/test_tree1_merge_labelled.dts |   41 +++
 8 files changed, 90 insertions(+), 5 deletions(-)
 create mode 100644 tests/test_tree1_merge_labelled.dts

diff --git a/dtc-lexer.l b/dtc-lexer.l
index 3c3434c..5a7e476 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -109,7 +109,7 @@ static int pop_input_file(void);
return DT_LITERAL;
}
 
-\{LABEL}  {   /* label reference */
+*\{LABEL}   {   /* label reference */
DPRINT(Ref: %s\n, yytext+1);
yylval.labelref = xstrdup(yytext+1);
return DT_REF;
diff --git a/dtc-parser.y b/dtc-parser.y
index dea19c1..be86e5b 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -76,6 +76,7 @@ static unsigned long long eval_literal(const char *s, int 
base, int bits);
 
 %type node devicetree
 %type node devicetrees
+%type node labelledtree
 %type node nodedef
 %type node subnode
 %type nodelist subnodes
@@ -129,6 +130,10 @@ devicetrees:
{
$$ = merge_nodes($1, $2);
}
+   | devicetrees labelledtree
+   {
+   $$ = merge_labelled_node($1, $2);
+   }
;
 
 devicetree:
@@ -138,6 +143,14 @@ devicetree:
}
;
 
+labelledtree:
+ DT_REF nodedef
+   {
+   add_label($2-labels, $1);
+   $$ = $2;
+   }
+   ;
+
 nodedef:
  '{' proplist subnodes '}' ';'
{
diff --git a/dtc.h b/dtc.h
index b36ac5d..af5e28c 100644
--- a/dtc.h
+++ b/dtc.h
@@ -175,6 +175,7 @@ struct node *build_node(struct property *proplist, struct 
node *children);
 struct node *name_node(struct node *node, char *name);
 struct node *chain_node(struct node *first, struct node *list);
 struct node *merge_nodes(struct node *old_node, struct node *new_node);
+struct node *merge_labelled_node(struct node *tree, struct node 
*labelled_node);
 
 void add_property(struct node *node, struct property *prop);
 void add_child(struct node *parent, struct node *child);
diff --git a/livetree.c b/livetree.c
index 13c5f10..0c8a24d 100644
--- a/livetree.c
+++ b/livetree.c
@@ -167,6 +167,36 @@ struct node *merge_nodes(struct node *old_node, struct 
node *new_node)
return old_node;
 }
 
+struct node *merge_labelled_node(struct node *tree, struct node *labelled_node)
+{
+   struct node *child, *rn;
+   struct label *tree_label, *child_label;
+
+   /* First, check if this node matches */
+   for_each_label(tree-labels, tree_label) {
+   for_each_label(labelled_node-labels, child_label) {
+   if (streq(tree_label-label, child_label-label))
+   return merge_nodes(tree, labelled_node);
+   }
+   }
+
+   /* Otherwise, recursivelly search the children for something matching */
+   for_each_child(tree, child) {
+   rn = merge_labelled_node(child, labelled_node);
+   if (rn)
+   return tree;
+   }
+
+   /* Nothing matched.  If this is the root node, then this is an error */
+   if (!tree-parent) {
+   yyerror(parse error: undefined label in node redefinition);
+   return tree;
+   }
+
+   /* return NULL so that recursive call knows nothing matched */
+   return NULL;
+}
+
 struct node *chain_node(struct node *first, struct node *list)
 {
assert(first-next_sibling == NULL);
diff --git a/tests/run_tests.sh b/tests/run_tests.sh
index 43b9d44..80a1e3c 100755
--- a/tests/run_tests.sh
+++ b/tests/run_tests.sh
@@ -300,6 +300,8 @@ dtc_tests () {
 # Check merge/overlay functionality
 run_dtc_test -I dts -O dtb -o dtc_tree1_merge.test.dtb test_tree1_merge.dts
 

[PATCH] of: add bus-number specification to spi_mpc8xxx

2010-02-26 Thread Ernst Schwab
From: Ernst Schwab esch...@online.de

Added devicetree parsing for SPI bus number. If no bus number is specified,
a dynamically assigned bus number will be used (typically 32766).

Signed-off-by: Ernst Schwab esch...@online.de
---
diff -upr a/Documentation/powerpc/dts-bindings/fsl/spi.txt 
b/Documentation/powerpc/dts-bindings/fsl/spi.txt
--- a/Documentation/powerpc/dts-bindings/fsl/spi.txt
+++ b/Documentation/powerpc/dts-bindings/fsl/spi.txt
@@ -4,6 +4,8 @@ Required properties:
 - cell-index : SPI controller index.
 - compatible : should be fsl,spi.
 - mode : the SPI operation mode, it can be cpu or cpu-qe.
+- bus-number : number of the SPI bus. If unspecified, a dynamically
+  assigned bus number will be used.
 - reg : Offset and length of the register set for the device
 - interrupts : a b where a is the interrupt number and b is a
   field that represents an encoding of the sense and level
@@ -21,4 +23,5 @@ Example:
interrupts = 82 0;
interrupt-parent = 700;
mode = cpu;
+   bus-number = 0;
};
diff -upr a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -1230,6 +1230,8 @@ static int __devinit of_mpc8xxx_spi_prob
struct resource mem;
struct resource irq;
const void *prop;
+   const int *bus_num;
+   int len;
int ret = -ENOMEM;
 
pinfo = kzalloc(sizeof(*pinfo), GFP_KERNEL);
@@ -1239,8 +1241,16 @@ static int __devinit of_mpc8xxx_spi_prob
pdata = pinfo-pdata;
dev-platform_data = pdata;
 
-   /* Allocate bus num dynamically. */
-   pdata-bus_num = -1;
+
+   bus_num = of_get_property(np, bus-number, len);
+   if (bus_num  len == sizeof(*bus_num)) {
+   /* bus number is specified in node */
+   pdata-bus_num = *bus_num;
+   } else {
+   /* Allocate bus num dynamically. */
+   pdata-bus_num = -1;
+   }
+
 
/* SPI controller is either clocked from QE or SoC clock. */
pdata-sysclk = get_brgfreq();


___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss


[patch] of: check for IS_ERR()

2010-02-26 Thread Dan Carpenter
get_phy_device() can return an ERR_PTR()

Signed-off-by: Dan Carpenter erro...@gmail.com
---
I don't have a cross compile environment set up so I can't even compile 
test this.  :/  But err.h is included so it should be OK.

diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
index 18ecae4..b474833 100644
--- a/drivers/of/of_mdio.c
+++ b/drivers/of/of_mdio.c
@@ -69,7 +69,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct 
device_node *np)
}
 
phy = get_phy_device(mdio, be32_to_cpup(addr));
-   if (!phy) {
+   if (!phy || IS_ERR(phy)) {
dev_err(mdio-dev, error probing PHY at address %i\n,
*addr);
continue;
___
devicetree-discuss mailing list
devicetree-discuss@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/devicetree-discuss