From db3e50f3234ba1a477413f56a9e5800a73dca786 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Fri, 21 Jul 2017 14:39:31 +0300 Subject: device property: Get rid of struct fwnode_handle type field Instead of relying on the struct fwnode_handle type field, define fwnode_operations structs for all separate types of fwnodes. To find out the type, compare to the ops field to relevant ops structs. This change has two benefits: 1. it avoids adding the type field to each and every instance of struct fwnode_handle, thus saving memory and 2. makes the ops field the single factor that defines both the types of the fwnode as well as defines the implementation of its operations, decreasing the possibility of bugs when developing code dealing with fwnode internals. Suggested-by: Rob Herring Signed-off-by: Sakari Ailus Reviewed-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki --- drivers/of/property.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/of/property.c') diff --git a/drivers/of/property.c b/drivers/of/property.c index eda50b4be934..2d5988820405 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -952,3 +952,4 @@ const struct fwnode_operations of_fwnode_ops = { .graph_get_port_parent = of_fwnode_graph_get_port_parent, .graph_parse_endpoint = of_fwnode_graph_parse_endpoint, }; +EXPORT_SYMBOL_GPL(of_fwnode_ops); -- cgit v1.2.3 From 37ba983cfb47cc7b353146422c437468fcb29c61 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Fri, 21 Jul 2017 14:39:36 +0300 Subject: device property: Constify fwnode property API Make fwnode arguments to the fwnode property API const. Signed-off-by: Sakari Ailus Reviewed-by: Rob Herring Signed-off-by: Rafael J. Wysocki --- drivers/of/property.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'drivers/of/property.c') diff --git a/drivers/of/property.c b/drivers/of/property.c index 2d5988820405..ae46a6f0ea36 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -815,23 +815,23 @@ static void of_fwnode_put(struct fwnode_handle *fwnode) of_node_put(to_of_node(fwnode)); } -static bool of_fwnode_device_is_available(struct fwnode_handle *fwnode) +static bool of_fwnode_device_is_available(const struct fwnode_handle *fwnode) { return of_device_is_available(to_of_node(fwnode)); } -static bool of_fwnode_property_present(struct fwnode_handle *fwnode, +static bool of_fwnode_property_present(const struct fwnode_handle *fwnode, const char *propname) { return of_property_read_bool(to_of_node(fwnode), propname); } -static int of_fwnode_property_read_int_array(struct fwnode_handle *fwnode, +static int of_fwnode_property_read_int_array(const struct fwnode_handle *fwnode, const char *propname, unsigned int elem_size, void *val, size_t nval) { - struct device_node *node = to_of_node(fwnode); + const struct device_node *node = to_of_node(fwnode); if (!val) return of_property_count_elems_of_size(node, propname, @@ -851,24 +851,26 @@ static int of_fwnode_property_read_int_array(struct fwnode_handle *fwnode, return -ENXIO; } -static int of_fwnode_property_read_string_array(struct fwnode_handle *fwnode, - const char *propname, - const char **val, size_t nval) +static int +of_fwnode_property_read_string_array(const struct fwnode_handle *fwnode, + const char *propname, const char **val, + size_t nval) { - struct device_node *node = to_of_node(fwnode); + const struct device_node *node = to_of_node(fwnode); return val ? of_property_read_string_array(node, propname, val, nval) : of_property_count_strings(node, propname); } -static struct fwnode_handle *of_fwnode_get_parent(struct fwnode_handle *fwnode) +static struct fwnode_handle * +of_fwnode_get_parent(const struct fwnode_handle *fwnode) { return of_fwnode_handle(of_get_parent(to_of_node(fwnode))); } static struct fwnode_handle * -of_fwnode_get_next_child_node(struct fwnode_handle *fwnode, +of_fwnode_get_next_child_node(const struct fwnode_handle *fwnode, struct fwnode_handle *child) { return of_fwnode_handle(of_get_next_available_child(to_of_node(fwnode), @@ -876,10 +878,10 @@ of_fwnode_get_next_child_node(struct fwnode_handle *fwnode, } static struct fwnode_handle * -of_fwnode_get_named_child_node(struct fwnode_handle *fwnode, +of_fwnode_get_named_child_node(const struct fwnode_handle *fwnode, const char *childname) { - struct device_node *node = to_of_node(fwnode); + const struct device_node *node = to_of_node(fwnode); struct device_node *child; for_each_available_child_of_node(node, child) @@ -890,7 +892,7 @@ of_fwnode_get_named_child_node(struct fwnode_handle *fwnode, } static struct fwnode_handle * -of_fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode, +of_fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode, struct fwnode_handle *prev) { return of_fwnode_handle(of_graph_get_next_endpoint(to_of_node(fwnode), @@ -898,7 +900,7 @@ of_fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode, } static struct fwnode_handle * -of_fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode) +of_fwnode_graph_get_remote_endpoint(const struct fwnode_handle *fwnode) { return of_fwnode_handle(of_parse_phandle(to_of_node(fwnode), "remote-endpoint", 0)); @@ -921,10 +923,10 @@ of_fwnode_graph_get_port_parent(struct fwnode_handle *fwnode) return of_fwnode_handle(of_get_next_parent(np)); } -static int of_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode, +static int of_fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode, struct fwnode_endpoint *endpoint) { - struct device_node *node = to_of_node(fwnode); + const struct device_node *node = to_of_node(fwnode); struct device_node *port_node = of_get_parent(node); endpoint->local_fwnode = fwnode; -- cgit v1.2.3 From 3e3119d3088f41106f3581d39e7694a50ca3fc02 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Fri, 21 Jul 2017 15:11:49 +0300 Subject: device property: Introduce fwnode_property_get_reference_args The new fwnode_property_get_reference_args() interface amends the fwnode property API with the functionality of both of_parse_phandle_with_args() and __acpi_node_get_property_reference(). The semantics is slightly different: the cells property is ignored on ACPI as the number of arguments can be explicitly obtained from the firmware interface. Signed-off-by: Sakari Ailus Signed-off-by: Rafael J. Wysocki --- drivers/of/property.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'drivers/of/property.c') diff --git a/drivers/of/property.c b/drivers/of/property.c index ae46a6f0ea36..3868400972b8 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -891,6 +891,36 @@ of_fwnode_get_named_child_node(const struct fwnode_handle *fwnode, return NULL; } +static int +of_fwnode_get_reference_args(const struct fwnode_handle *fwnode, + const char *prop, const char *nargs_prop, + unsigned int nargs, unsigned int index, + struct fwnode_reference_args *args) +{ + struct of_phandle_args of_args; + unsigned int i; + int ret; + + if (nargs_prop) + ret = of_parse_phandle_with_args(to_of_node(fwnode), prop, + nargs_prop, index, &of_args); + else + ret = of_parse_phandle_with_fixed_args(to_of_node(fwnode), prop, + nargs, index, &of_args); + if (ret < 0) + return ret; + if (!args) + return 0; + + args->nargs = of_args.args_count; + args->fwnode = of_fwnode_handle(of_args.np); + + for (i = 0; i < NR_FWNODE_REFERENCE_ARGS; i++) + args->args[i] = i < of_args.args_count ? of_args.args[i] : 0; + + return 0; +} + static struct fwnode_handle * of_fwnode_graph_get_next_endpoint(const struct fwnode_handle *fwnode, struct fwnode_handle *prev) @@ -949,6 +979,7 @@ const struct fwnode_operations of_fwnode_ops = { .get_parent = of_fwnode_get_parent, .get_next_child_node = of_fwnode_get_next_child_node, .get_named_child_node = of_fwnode_get_named_child_node, + .get_reference_args = of_fwnode_get_reference_args, .graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint, .graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint, .graph_get_port_parent = of_fwnode_graph_get_port_parent, -- cgit v1.2.3