mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] of: implement of_property_present helper
@ 2023-03-31  9:04 Ahmad Fatoum
  2023-04-03  7:05 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2023-03-31  9:04 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We have various code using of_find_property(np, propname, NULL) to
detect whether propname exists and some more that uses
of_property_read_bool on non-boolean properties.

There's work underway in Linux to switch a lot of these instances to
of_property_present[1]. Let's prepare for porting Linux code that
uses the property by adding it.

[1]: https://lore.kernel.org/linux-devicetree/?q=of_property_present

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/of.h | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/include/of.h b/include/of.h
index 3fb6ecec8dfe..22358f5579ec 100644
--- a/include/of.h
+++ b/include/of.h
@@ -1038,8 +1038,10 @@ static inline int of_property_read_string_index(const struct device_node *np,
  * @np:		device node from which the property value is to be read.
  * @propname:	name of the property to be searched.
  *
- * Search for a property in a device node.
- * Returns true if the property exist false otherwise.
+ * Search for a boolean property in a device node. Usage on non-boolean
+ * property types is deprecated.
+
+ * Return: true if the property exist false otherwise.
  */
 static inline bool of_property_read_bool(const struct device_node *np,
 					 const char *propname)
@@ -1049,6 +1051,20 @@ static inline bool of_property_read_bool(const struct device_node *np,
 	return prop ? true : false;
 }
 
+/**
+ * of_property_present - Test if a property is present in a node
+ * @np:		device node to search for the property.
+ * @propname:	name of the property to be searched.
+ *
+ * Test for a property present in a device node.
+ *
+ * Return: true if the property exists false otherwise.
+ */
+static inline bool of_property_present(const struct device_node *np, const char *propname)
+{
+	return of_property_read_bool(np, propname);
+}
+
 static inline int of_property_read_u8(const struct device_node *np,
 				       const char *propname,
 				       u8 *out_value)
-- 
2.39.2




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

* Re: [PATCH] of: implement of_property_present helper
  2023-03-31  9:04 [PATCH] of: implement of_property_present helper Ahmad Fatoum
@ 2023-04-03  7:05 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2023-04-03  7:05 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Fri, Mar 31, 2023 at 11:04:53AM +0200, Ahmad Fatoum wrote:
> We have various code using of_find_property(np, propname, NULL) to
> detect whether propname exists and some more that uses
> of_property_read_bool on non-boolean properties.
> 
> There's work underway in Linux to switch a lot of these instances to
> of_property_present[1]. Let's prepare for porting Linux code that
> uses the property by adding it.
> 
> [1]: https://lore.kernel.org/linux-devicetree/?q=of_property_present
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  include/of.h | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/include/of.h b/include/of.h
> index 3fb6ecec8dfe..22358f5579ec 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -1038,8 +1038,10 @@ static inline int of_property_read_string_index(const struct device_node *np,
>   * @np:		device node from which the property value is to be read.
>   * @propname:	name of the property to be searched.
>   *
> - * Search for a property in a device node.
> - * Returns true if the property exist false otherwise.
> + * Search for a boolean property in a device node. Usage on non-boolean
> + * property types is deprecated.
> +
> + * Return: true if the property exist false otherwise.
>   */
>  static inline bool of_property_read_bool(const struct device_node *np,
>  					 const char *propname)
> @@ -1049,6 +1051,20 @@ static inline bool of_property_read_bool(const struct device_node *np,
>  	return prop ? true : false;
>  }
>  
> +/**
> + * of_property_present - Test if a property is present in a node
> + * @np:		device node to search for the property.
> + * @propname:	name of the property to be searched.
> + *
> + * Test for a property present in a device node.
> + *
> + * Return: true if the property exists false otherwise.
> + */
> +static inline bool of_property_present(const struct device_node *np, const char *propname)
> +{
> +	return of_property_read_bool(np, propname);
> +}
> +
>  static inline int of_property_read_u8(const struct device_node *np,
>  				       const char *propname,
>  				       u8 *out_value)
> -- 
> 2.39.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:[~2023-04-03  7:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-31  9:04 [PATCH] of: implement of_property_present helper Ahmad Fatoum
2023-04-03  7:05 ` Sascha Hauer

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