mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] of: implement of_rename_property()
@ 2022-09-05 10:36 Ahmad Fatoum
  2022-09-12  8:54 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2022-09-05 10:36 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

It's often desirable to have the same barebox binary for multiple
variants. DT-level differences between the variants are often handled
by having extra device tree nodes that are disabled by default and
patched as appropriate by board code. It can be useful to have a finer
granularity for patching though, that covers only a select property, e.g.:

   usbotg1 {
	vbus-supply = <&reg_vbus_common>;
	vendor,specialvariant-vbus-supply = <&reg_vbus_specialvariant>;
   };

The new of_rename_property allows board code to easily activate the
alternative vbus supply on the specialvariant:

  of_rename_property(np, "vendor,specialvariant-vbus-supply",
			 "vbus-supply");

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/of/base.c             | 16 ++++++++++++++++
 include/of.h                  |  8 ++++++++
 test/self/of_manipulation.c   | 10 ++++++++++
 test/self/of_manipulation.dts |  6 ++++--
 4 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 6a51dd71793d..212b226eb55c 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2301,6 +2301,22 @@ void of_delete_property(struct property *pp)
 	free(pp);
 }
 
+struct property *of_rename_property(struct device_node *np,
+				    const char *old_name, const char *new_name)
+{
+	struct property *pp;
+
+	pp = of_find_property(np, old_name, NULL);
+	if (!pp)
+		return NULL;
+
+	of_property_write_bool(np, new_name, false);
+
+	free(pp->name);
+	pp->name = xstrdup(new_name);
+	return pp;
+}
+
 /**
  * of_set_property - create a property for a given node
  * @node - the node
diff --git a/include/of.h b/include/of.h
index 29df7d912b33..153e75d3e51d 100644
--- a/include/of.h
+++ b/include/of.h
@@ -143,6 +143,8 @@ extern struct property *of_new_property_const(struct device_node *node,
 extern struct property *__of_new_property(struct device_node *node,
 					  const char *name, void *data, int len);
 extern void of_delete_property(struct property *pp);
+extern struct property *of_rename_property(struct device_node *np,
+					   const char *old_name, const char *new_name);
 
 extern struct device_node *of_find_node_by_name(struct device_node *from,
 	const char *name);
@@ -550,6 +552,12 @@ static inline void of_delete_property(struct property *pp)
 {
 }
 
+static inline struct property *of_rename_property(struct device_node *np,
+						  const char *old_name, const char *new_name)
+{
+	return NULL;
+}
+
 static inline int of_property_read_u32_index(const struct device_node *np,
 				const char *propname, u32 index, u32 *out_value)
 {
diff --git a/test/self/of_manipulation.c b/test/self/of_manipulation.c
index 6eb6062e126b..7e30a60ca687 100644
--- a/test/self/of_manipulation.c
+++ b/test/self/of_manipulation.c
@@ -57,6 +57,16 @@ static void test_of_basics(struct device_node *root)
 	of_property_write_bool(node1, "property1", true);
 
 	assert_equal(node1, node2);
+
+	of_property_write_bool(node2, "property1", false);
+	of_property_write_u32(node2, "property1", 1);
+	of_property_write_u32(node2, "property2", 2);
+
+	of_property_write_u32(node1, "property3", 1);
+	of_property_write_u32(node1, "property2", 2);
+	of_rename_property(node1, "property3", "property1");
+
+	assert_equal(node1, node2);
 }
 
 static void test_of_property_strings(struct device_node *root)
diff --git a/test/self/of_manipulation.dts b/test/self/of_manipulation.dts
index a69d944c1eb5..2cc6773fa98e 100644
--- a/test/self/of_manipulation.dts
+++ b/test/self/of_manipulation.dts
@@ -4,12 +4,14 @@
 
 / {
 	node1 {
-		property1;
+		property1 = <1>;
+		property2 = <2>;
 		node21 { };
 	};
 
 	node2 {
-		property1;
+		property1 = <1>;
+		property2 = <2>;
 		node21 { };
 	};
 
-- 
2.30.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] of: implement of_rename_property()
  2022-09-05 10:36 [PATCH] of: implement of_rename_property() Ahmad Fatoum
@ 2022-09-12  8:54 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-09-12  8:54 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Mon, Sep 05, 2022 at 12:36:39PM +0200, Ahmad Fatoum wrote:
> It's often desirable to have the same barebox binary for multiple
> variants. DT-level differences between the variants are often handled
> by having extra device tree nodes that are disabled by default and
> patched as appropriate by board code. It can be useful to have a finer
> granularity for patching though, that covers only a select property, e.g.:
> 
>    usbotg1 {
> 	vbus-supply = <&reg_vbus_common>;
> 	vendor,specialvariant-vbus-supply = <&reg_vbus_specialvariant>;
>    };
> 
> The new of_rename_property allows board code to easily activate the
> alternative vbus supply on the specialvariant:
> 
>   of_rename_property(np, "vendor,specialvariant-vbus-supply",
> 			 "vbus-supply");
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  drivers/of/base.c             | 16 ++++++++++++++++
>  include/of.h                  |  8 ++++++++
>  test/self/of_manipulation.c   | 10 ++++++++++
>  test/self/of_manipulation.dts |  6 ++++--
>  4 files changed, 38 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 6a51dd71793d..212b226eb55c 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2301,6 +2301,22 @@ void of_delete_property(struct property *pp)
>  	free(pp);
>  }
>  
> +struct property *of_rename_property(struct device_node *np,
> +				    const char *old_name, const char *new_name)
> +{
> +	struct property *pp;
> +
> +	pp = of_find_property(np, old_name, NULL);
> +	if (!pp)
> +		return NULL;
> +
> +	of_property_write_bool(np, new_name, false);
> +
> +	free(pp->name);
> +	pp->name = xstrdup(new_name);
> +	return pp;
> +}
> +
>  /**
>   * of_set_property - create a property for a given node
>   * @node - the node
> diff --git a/include/of.h b/include/of.h
> index 29df7d912b33..153e75d3e51d 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -143,6 +143,8 @@ extern struct property *of_new_property_const(struct device_node *node,
>  extern struct property *__of_new_property(struct device_node *node,
>  					  const char *name, void *data, int len);
>  extern void of_delete_property(struct property *pp);
> +extern struct property *of_rename_property(struct device_node *np,
> +					   const char *old_name, const char *new_name);
>  
>  extern struct device_node *of_find_node_by_name(struct device_node *from,
>  	const char *name);
> @@ -550,6 +552,12 @@ static inline void of_delete_property(struct property *pp)
>  {
>  }
>  
> +static inline struct property *of_rename_property(struct device_node *np,
> +						  const char *old_name, const char *new_name)
> +{
> +	return NULL;
> +}
> +
>  static inline int of_property_read_u32_index(const struct device_node *np,
>  				const char *propname, u32 index, u32 *out_value)
>  {
> diff --git a/test/self/of_manipulation.c b/test/self/of_manipulation.c
> index 6eb6062e126b..7e30a60ca687 100644
> --- a/test/self/of_manipulation.c
> +++ b/test/self/of_manipulation.c
> @@ -57,6 +57,16 @@ static void test_of_basics(struct device_node *root)
>  	of_property_write_bool(node1, "property1", true);
>  
>  	assert_equal(node1, node2);
> +
> +	of_property_write_bool(node2, "property1", false);
> +	of_property_write_u32(node2, "property1", 1);
> +	of_property_write_u32(node2, "property2", 2);
> +
> +	of_property_write_u32(node1, "property3", 1);
> +	of_property_write_u32(node1, "property2", 2);
> +	of_rename_property(node1, "property3", "property1");
> +
> +	assert_equal(node1, node2);
>  }
>  
>  static void test_of_property_strings(struct device_node *root)
> diff --git a/test/self/of_manipulation.dts b/test/self/of_manipulation.dts
> index a69d944c1eb5..2cc6773fa98e 100644
> --- a/test/self/of_manipulation.dts
> +++ b/test/self/of_manipulation.dts
> @@ -4,12 +4,14 @@
>  
>  / {
>  	node1 {
> -		property1;
> +		property1 = <1>;
> +		property2 = <2>;
>  		node21 { };
>  	};
>  
>  	node2 {
> -		property1;
> +		property1 = <1>;
> +		property2 = <2>;
>  		node21 { };
>  	};
>  
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-12  8:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 10:36 [PATCH] of: implement of_rename_property() Ahmad Fatoum
2022-09-12  8:54 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox