Re: [RFC PATCH 4/9] of: Add property_ops callback for devices with of_node

From: Rob Herring
Date: Mon Aug 18 2014 - 08:35:56 EST


On 08/17/2014 01:04 AM, Mika Westerberg wrote:
> From: Aaron Lu <aaron.lu@xxxxxxxxx>
>
> With the unified device properties interface in place, add device tree support.
> By adding the dev_prop_ops for of_node devices, drivers can access properties
> from ACPI or Device Tree in a generic way.
>
> Signed-off-by: Aaron Lu <aaron.lu@xxxxxxxxx>
> Reviewed-by: Darren Hart <dvhart@xxxxxxxxxxxxxxx>
> Signed-off-by: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx>
> ---
> drivers/of/base.c | 194 ++++++++++++++++++++++++++++++++++++++++++++++-
> drivers/of/platform.c | 4 +-
> include/linux/property.h | 4 +
> 3 files changed, 200 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index b9864806e9b8..527004d01423 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -20,7 +20,7 @@
> #include <linux/ctype.h>
> #include <linux/cpu.h>
> #include <linux/module.h>
> -#include <linux/of.h>
> +#include <linux/property.h>
> #include <linux/of_graph.h>
> #include <linux/spinlock.h>
> #include <linux/slab.h>
> @@ -1343,6 +1343,39 @@ int of_property_read_u64(const struct device_node *np, const char *propname,
> EXPORT_SYMBOL_GPL(of_property_read_u64);
>
> /**
> + * of_property_read_u64_array - Find and read an array of 64 bit integers
> + * from a property.
> + *
> + * @np: device node from which the property value is to be read.
> + * @propname: name of the property to be searched.
> + * @out_values: pointer to return value, modified only if return value is 0.
> + * @sz: number of array elements to read
> + *
> + * Search for a property in a device node and read 64-bit value(s) from
> + * it. Returns 0 on success, -EINVAL if the property does not exist,
> + * -ENODATA if property does not have a value, and -EOVERFLOW if the
> + * property data isn't large enough.
> + *
> + * The out_values is modified only if a valid u64 value can be decoded.
> + */
> +int of_property_read_u64_array(const struct device_node *np,
> + const char *propname, u64 *out_values,
> + size_t sz)

Quite frequently the array functions have turned out to be less useful
as you often don't know how many elements you have upfront. So you end
up parsing the property twice. Using for_each iterators has been a
better fit for most users, so I'd like to see them here. We may need
both, but read_*_array can be a wrapper around for_each.

Rob

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/