All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/20] Move firmware specific code to firmware specific locations
@ 2017-02-23 17:00 Sakari Ailus
  2017-02-23 17:00 ` [PATCH 01/20] device property: fwnode_property_read_string_array() may return -EILSEQ Sakari Ailus
                   ` (17 more replies)
  0 siblings, 18 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:00 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Hi,

This set moves firmware specific implementations of the device / fwnode
property API to locations that are specific to firmware implementation,
still leaving property set (which isn't really firmware) implementation in
drivers/base/property.c.

The set begins with a few bugfixes (patches 1--3), followed by adding
fwnode_operations struct and then gradually moving firmware dependent code
to drivers/acpi/property.c and drivers/of/base.c.

The set depends on the ACPI graph support here:

<URL:http://marc.info/?l=linux-acpi&m=148786716920942&w=2>

Comments are welcome.

-- 
Kind regards,
Sakari


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

* [PATCH 01/20] device property: fwnode_property_read_string_array() may return -EILSEQ
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
@ 2017-02-23 17:00 ` Sakari Ailus
  2017-02-23 17:00 ` [PATCH 02/20] device property: Fix reading pset strings using array access functions Sakari Ailus
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:00 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

fwnode_property_read_string_array() may return -EILSEQ through
of_property_read_string_array(). Document this.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/base/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 88e9f80..04c2174 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -584,7 +584,7 @@ static int __fwnode_property_read_string(struct fwnode_handle *fwnode,
  *         %0 if the property was found (success),
  *	   %-EINVAL if given arguments are not valid,
  *	   %-ENODATA if the property does not have a value,
- *	   %-EPROTO if the property is not an array of strings,
+ *	   %-EPROTO or %-EILSEQ if the property is not an array of strings,
  *	   %-EOVERFLOW if the size of the property is not as expected,
  *	   %-ENXIO if no suitable firmware interface is present.
  */
-- 
2.7.4


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

* [PATCH 02/20] device property: Fix reading pset strings using array access functions
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
  2017-02-23 17:00 ` [PATCH 01/20] device property: fwnode_property_read_string_array() may return -EILSEQ Sakari Ailus
@ 2017-02-23 17:00 ` Sakari Ailus
  2017-02-23 17:00 ` [PATCH 03/20] device property: of_property_read_string_array() returns number of strings Sakari Ailus
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:00 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

The length field value of non-array string properties is the length of the
string itself. Non-array string properties thus require specific handling.
Fix this.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/base/property.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 04c2174..e42dc93 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -547,13 +547,27 @@ static int __fwnode_property_read_string_array(struct fwnode_handle *fwnode,
 	else if (is_acpi_node(fwnode))
 		return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
 					   val, nval);
-	else if (is_pset_node(fwnode))
-		return val ?
-			pset_prop_read_string_array(to_pset_node(fwnode),
-						    propname, val, nval) :
-			pset_prop_count_elems_of_size(to_pset_node(fwnode),
-						      propname,
-						      sizeof(const char *));
+	else if (is_pset_node(fwnode)) {
+		struct property_set *node = to_pset_node(fwnode);
+		struct property_entry *prop;
+
+		/* Read properties if val is non-NULL */
+		if (val)
+			return pset_prop_read_string_array(node, propname,
+							   val, nval);
+
+		prop = pset_prop_get(node, propname);
+		if (!prop)
+			return -EINVAL;
+
+		/* The array length for a non-array string property is 1. */
+		if (!prop->is_array)
+			return 1;
+
+		/* Return the length of an array. */
+		return pset_prop_count_elems_of_size(node, propname,
+						     sizeof(const char *));
+	}
 	return -ENXIO;
 }
 
-- 
2.7.4


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

* [PATCH 03/20] device property: of_property_read_string_array() returns number of strings
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
  2017-02-23 17:00 ` [PATCH 01/20] device property: fwnode_property_read_string_array() may return -EILSEQ Sakari Ailus
  2017-02-23 17:00 ` [PATCH 02/20] device property: Fix reading pset strings using array access functions Sakari Ailus
@ 2017-02-23 17:00 ` Sakari Ailus
  2017-02-23 23:42   ` Rob Herring
  2017-02-23 17:01 ` [PATCH 04/20] device property: Add operations struct for fwnode operations Sakari Ailus
                   ` (14 subsequent siblings)
  17 siblings, 1 reply; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:00 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

of_property_read_string_array() returns number of strings read if the
target array of pointers is non-NULL. fwnode_property_read_string_array()
is documented to return 0 in that case. Fix this.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/base/property.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index e42dc93..5cb270f 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -539,12 +539,24 @@ static int __fwnode_property_read_string_array(struct fwnode_handle *fwnode,
 					       const char *propname,
 					       const char **val, size_t nval)
 {
-	if (is_of_node(fwnode))
-		return val ?
-			of_property_read_string_array(to_of_node(fwnode),
-						      propname, val, nval) :
-			of_property_count_strings(to_of_node(fwnode), propname);
-	else if (is_acpi_node(fwnode))
+	if (is_of_node(fwnode)) {
+		int rval;
+
+		if (!val)
+			return of_property_count_strings(to_of_node(fwnode),
+							 propname);
+
+		rval = of_property_read_string_array(to_of_node(fwnode),
+						     propname, val, nval);
+
+		if (rval < 0)
+			return rval;
+
+		if (rval == nval)
+			return 0;
+
+		return -EOVERFLOW;
+	} else if (is_acpi_node(fwnode))
 		return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
 					   val, nval);
 	else if (is_pset_node(fwnode)) {
-- 
2.7.4


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

* [PATCH 04/20] device property: Add operations struct for fwnode operations
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (2 preceding siblings ...)
  2017-02-23 17:00 ` [PATCH 03/20] device property: of_property_read_string_array() returns number of strings Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 05/20] device property: Add macros for calling " Sakari Ailus
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Prepare moving firmware specific implementations of the fwnode properties
under a common ops struct. This will allow having a single implementation
of firmware independent portions of the fwnode framework.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/linux/fwnode.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index cb60f29..ede74fb 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -33,4 +33,53 @@ struct fwnode_endpoint {
 	const struct fwnode_handle *local_fwnode;
 };
 
+/**
+ * struct fwnode_operations - Operations for fwnode interface
+ * @get: Get a reference to an fwnode.
+ * @put: Put a reference to an fwnode.
+ * @property_present: Return true if a property is present.
+ * @property_read_integer_array: Read an array of integer properties. Return
+ *				 zero on success, a negative error code
+ *				 otherwise.
+ * @property_read_string_array: Read an array of string properties. Return zero
+ *				on success, a negative error code otherwise.
+ * @get_parent: Return the parent of an fwnode.
+ * @get_next_child_node: Return the next child node in an iteration.
+ * @get_named_child_node: Return a child node with a given name.
+ * @graph_get_next_endpoint: Return an endpoint node in an iteration.
+ * @graph_get_remote_endpoint: Return the remote endpoint node of an endpoint
+ *			       node.
+ * @graph_get_remote_port: Return the remote port node of an endpoint node.
+ * @graph_get_remote_port_parent: Return the parent of a port node of the
+ *				  remote endpoint node of an endpoint node.
+ */
+struct fwnode_operations {
+	void (*get)(struct fwnode_handle *fwnode);
+	void (*put)(struct fwnode_handle *fwnode);
+	bool (*property_present)(struct fwnode_handle *fwnode,
+				 const char *propname);
+	int (*property_read_int_array)(struct fwnode_handle *fwnode,
+				       const char *propname,
+				       unsigned int elem_size, void *val,
+				       size_t nval);
+	int (*property_read_string_array)(struct fwnode_handle *fwnode_handle,
+					  const char *propname,
+					  const char **val, size_t nval);
+	struct fwnode_handle *(*get_parent)(struct fwnode_handle *fwnode);
+	struct fwnode_handle *(*get_next_child_node)(
+		struct fwnode_handle *fwnode, struct fwnode_handle *child);
+	struct fwnode_handle *(*get_named_child_node)(
+		struct fwnode_handle *fwnode, const char *name);
+	struct fwnode_handle *(*graph_get_next_endpoint)(
+		struct fwnode_handle *fwnode, struct fwnode_handle *prev);
+	struct fwnode_handle *(*graph_get_remote_endpoint)(
+		struct fwnode_handle *fwnode);
+	struct fwnode_handle *(*graph_get_remote_port)(
+		struct fwnode_handle *fwnode);
+	struct fwnode_handle *(*graph_get_remote_port_parent)(
+		struct fwnode_handle *fwnode);
+	int (*graph_parse_endpoint)(struct fwnode_handle *fwnode,
+				    struct fwnode_endpoint *endpoint);
+};
+
 #endif
-- 
2.7.4


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

* [PATCH 05/20] device property: Add macros for calling fwnode operations
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (3 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 04/20] device property: Add operations struct for fwnode operations Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-24  9:36   ` [PATCH v1.1 " Sakari Ailus
  2017-02-23 17:01 ` [PATCH 06/20] device property: Introduce firmware property operations, set them Sakari Ailus
                   ` (12 subsequent siblings)
  17 siblings, 1 reply; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Not all implementations may implement all fwnode operations. Instead of
leaving this up to the caller to figure out, add a few macros for the
purpose.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 include/linux/fwnode.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index ede74fb..37d6ee1 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -82,4 +82,19 @@ struct fwnode_operations {
 				    struct fwnode_endpoint *endpoint);
 };
 
+#define fwnode_has_op(fwnode, op)				\
+	((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
+#define fwnode_call_int_op(fwnode, op, ...)				\
+	(fwnode ? (fwnode_has_op(fwnode, op) ?				\
+		   (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : 0) :	\
+	 -ENXIO)
+#define fwnode_call_ptr_op(fwnode, op, ...)		\
+	(fwnode_has_op(fwnode, op) ?			\
+	 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
+#define fwnode_call_void_op(fwnode, op, ...)				\
+	do {								\
+		if (fwnode_has_op(fwnode, op))				\
+			(fwnode)->ops->op(fwnode, ## __VA_ARGS__);	\
+	} while (false)
+
 #endif
-- 
2.7.4


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

* [PATCH 06/20] device property: Introduce firmware property operations, set them
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (4 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 05/20] device property: Add macros for calling " Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 07/20] device property: Use fwnode_operations for fwnode_handle_{get,put} Sakari Ailus
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Add ops field for the firmware operations to struct fwnode_handle. Set the
ops pointer based on firmware type in fwnode initialisation.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c | 3 +++
 drivers/acpi/scan.c     | 1 +
 drivers/base/property.c | 3 +++
 drivers/of/base.c       | 2 ++
 include/linux/acpi.h    | 4 ++++
 include/linux/fwnode.h  | 5 +++++
 include/linux/of.h      | 2 ++
 7 files changed, 20 insertions(+)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 6e776de..0651a74 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -57,6 +57,7 @@ static bool acpi_nondev_subnode_extract(const union acpi_object *desc,
 
 	dn->name = link->package.elements[0].string.pointer;
 	dn->fwnode.type = FWNODE_ACPI_DATA;
+	dn->fwnode.ops = &acpi_fwnode_ops;
 	dn->parent = parent;
 	INIT_LIST_HEAD(&dn->data.subnodes);
 
@@ -1108,3 +1109,5 @@ int acpi_graph_get_remote_endpoint(struct fwnode_handle *fwnode,
 
 	return 0;
 }
+
+const struct fwnode_operations acpi_fwnode_ops;
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 1926918..901720f 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1441,6 +1441,7 @@ void acpi_init_device_object(struct acpi_device *device, acpi_handle handle,
 	device->handle = handle;
 	device->parent = acpi_bus_get_parent(handle);
 	device->fwnode.type = FWNODE_ACPI;
+	device->fwnode.ops = &acpi_fwnode_ops;
 	acpi_set_device_status(device, sta);
 	acpi_device_get_busid(device);
 	acpi_set_pnp_ids(handle, &device->pnp, type);
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 5cb270f..906411e 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -183,6 +183,8 @@ static int pset_prop_read_string(struct property_set *pset,
 	return 0;
 }
 
+static const struct fwnode_operations pset_fwnode_ops;
+
 /**
  * device_property_present - check if a property of a device is present
  * @dev: Device whose property is being checked
@@ -882,6 +884,7 @@ int device_add_properties(struct device *dev, struct property_entry *properties)
 		return PTR_ERR(p);
 
 	p->fwnode.type = FWNODE_PDATA;
+	p->fwnode.ops = &pset_fwnode_ops;
 	set_secondary_fwnode(dev, &p->fwnode);
 	return 0;
 }
diff --git a/drivers/of/base.c b/drivers/of/base.c
index d4bea3c..c08ed0e 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2469,3 +2469,5 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node)
 	return of_get_next_parent(np);
 }
 EXPORT_SYMBOL(of_graph_get_remote_port);
+
+const struct fwnode_operations of_fwnode_ops;
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 05ff957..85ca76d 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -56,6 +56,9 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
 	acpi_fwnode_handle(adev) : NULL)
 #define ACPI_HANDLE(dev)		acpi_device_handle(ACPI_COMPANION(dev))
 
+
+extern const struct fwnode_operations acpi_fwnode_ops;
+
 static inline struct fwnode_handle *acpi_alloc_fwnode_static(void)
 {
 	struct fwnode_handle *fwnode;
@@ -65,6 +68,7 @@ static inline struct fwnode_handle *acpi_alloc_fwnode_static(void)
 		return NULL;
 
 	fwnode->type = FWNODE_ACPI_STATIC;
+	fwnode->ops = &acpi_fwnode_ops;
 
 	return fwnode;
 }
diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index 37d6ee1..4edb60d 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -12,6 +12,8 @@
 #ifndef _LINUX_FWNODE_H_
 #define _LINUX_FWNODE_H_
 
+#include <linux/types.h>
+
 enum fwnode_type {
 	FWNODE_INVALID = 0,
 	FWNODE_OF,
@@ -22,9 +24,12 @@ enum fwnode_type {
 	FWNODE_IRQCHIP
 };
 
+struct fwnode_operations;
+
 struct fwnode_handle {
 	enum fwnode_type type;
 	struct fwnode_handle *secondary;
+	const struct fwnode_operations *ops;
 };
 
 struct fwnode_endpoint {
diff --git a/include/linux/of.h b/include/linux/of.h
index e0ddb22..21ecde3 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -100,10 +100,12 @@ struct of_reconfig_data {
 
 /* initialize a node */
 extern struct kobj_type of_node_ktype;
+extern const struct fwnode_operations of_fwnode_ops;
 static inline void of_node_init(struct device_node *node)
 {
 	kobject_init(&node->kobj, &of_node_ktype);
 	node->fwnode.type = FWNODE_OF;
+	node->fwnode.ops = &of_fwnode_ops;
 }
 
 /* true when node is initialized */
-- 
2.7.4


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

* [PATCH 07/20] device property: Use fwnode_operations for fwnode_handle_{get,put}
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (5 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 06/20] device property: Introduce firmware property operations, set them Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 08/20] device property: Use fwnode_operations for fwnode_property_present() Sakari Ailus
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Change the implementation of fwnode_handle_get() and fwnode_handle_put()
to use struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/base/property.c |  6 ++----
 drivers/of/base.c       | 15 ++++++++++++++-
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 906411e..0ab2ea5 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1033,8 +1033,7 @@ EXPORT_SYMBOL_GPL(device_get_named_child_node);
  */
 void fwnode_handle_get(struct fwnode_handle *fwnode)
 {
-	if (is_of_node(fwnode))
-		of_node_get(to_of_node(fwnode));
+	fwnode_call_void_op(fwnode, get);
 }
 EXPORT_SYMBOL_GPL(fwnode_handle_get);
 
@@ -1048,8 +1047,7 @@ EXPORT_SYMBOL_GPL(fwnode_handle_get);
  */
 void fwnode_handle_put(struct fwnode_handle *fwnode)
 {
-	if (is_of_node(fwnode))
-		of_node_put(to_of_node(fwnode));
+	fwnode_call_void_op(fwnode, put);
 }
 EXPORT_SYMBOL_GPL(fwnode_handle_put);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index c08ed0e..cbc4998 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2470,4 +2470,17 @@ struct device_node *of_graph_get_remote_port(const struct device_node *node)
 }
 EXPORT_SYMBOL(of_graph_get_remote_port);
 
-const struct fwnode_operations of_fwnode_ops;
+static void of_fwnode_get(struct fwnode_handle *fwnode)
+{
+	of_node_get(to_of_node(fwnode));
+}
+
+static void of_fwnode_put(struct fwnode_handle *fwnode)
+{
+	of_node_put(to_of_node(fwnode));
+}
+
+const struct fwnode_operations of_fwnode_ops = {
+	.get = of_fwnode_get,
+	.put = of_fwnode_put,
+};
-- 
2.7.4


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

* [PATCH 08/20] device property: Use fwnode_operations for fwnode_property_present()
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (6 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 07/20] device property: Use fwnode_operations for fwnode_handle_{get,put} Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 09/20] device property: Use fwnode_operations for reading integer arrays Sakari Ailus
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Change the implementation of fwnode_property_present() to use struct
fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c | 10 +++++++++-
 drivers/base/property.c | 27 ++++++++++++---------------
 drivers/of/base.c       |  7 +++++++
 3 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 0651a74..14b96ec 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1110,4 +1110,12 @@ int acpi_graph_get_remote_endpoint(struct fwnode_handle *fwnode,
 	return 0;
 }
 
-const struct fwnode_operations acpi_fwnode_ops;
+static bool acpi_fwnode_property_present(struct fwnode_handle *fwnode,
+					 const char *propname)
+{
+	return !acpi_node_prop_get(fwnode, propname, NULL);
+}
+
+const struct fwnode_operations acpi_fwnode_ops = {
+	.property_present = acpi_fwnode_property_present,
+};
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 0ab2ea5..37aea12 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -183,7 +183,15 @@ static int pset_prop_read_string(struct property_set *pset,
 	return 0;
 }
 
-static const struct fwnode_operations pset_fwnode_ops;
+static bool pset_fwnode_property_present(struct fwnode_handle *fwnode,
+					 const char *propname)
+{
+	return !!pset_prop_get(to_pset_node(fwnode), propname);
+}
+
+static const struct fwnode_operations pset_fwnode_ops = {
+	.property_present = pset_fwnode_property_present,
+};
 
 /**
  * device_property_present - check if a property of a device is present
@@ -198,18 +206,6 @@ bool device_property_present(struct device *dev, const char *propname)
 }
 EXPORT_SYMBOL_GPL(device_property_present);
 
-static bool __fwnode_property_present(struct fwnode_handle *fwnode,
-				      const char *propname)
-{
-	if (is_of_node(fwnode))
-		return of_property_read_bool(to_of_node(fwnode), propname);
-	else if (is_acpi_node(fwnode))
-		return !acpi_node_prop_get(fwnode, propname, NULL);
-	else if (is_pset_node(fwnode))
-		return !!pset_prop_get(to_pset_node(fwnode), propname);
-	return false;
-}
-
 /**
  * fwnode_property_present - check if a property of a firmware node is present
  * @fwnode: Firmware node whose property to check
@@ -219,10 +215,11 @@ bool fwnode_property_present(struct fwnode_handle *fwnode, const char *propname)
 {
 	bool ret;
 
-	ret = __fwnode_property_present(fwnode, propname);
+	ret = fwnode_call_int_op(fwnode, property_present, propname);
 	if (ret == false && !IS_ERR_OR_NULL(fwnode) &&
 	    !IS_ERR_OR_NULL(fwnode->secondary))
-		ret = __fwnode_property_present(fwnode->secondary, propname);
+		ret = fwnode_call_int_op(fwnode->secondary, property_present,
+					 propname);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(fwnode_property_present);
diff --git a/drivers/of/base.c b/drivers/of/base.c
index cbc4998..84f2530 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2480,7 +2480,14 @@ static void of_fwnode_put(struct fwnode_handle *fwnode)
 	of_node_put(to_of_node(fwnode));
 }
 
+static bool of_fwnode_property_present(struct fwnode_handle *fwnode,
+				       const char *propname)
+{
+	return of_property_read_bool(to_of_node(fwnode), propname);
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
+	.property_present = of_fwnode_property_present,
 };
-- 
2.7.4


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

* [PATCH 09/20] device property: Use fwnode_operations for reading integer arrays
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (7 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 08/20] device property: Use fwnode_operations for fwnode_property_present() Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 10/20] device property: Read strings using string array reading functions Sakari Ailus
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Change the implementation of fwnode_property_read_*_array() class of
functions to use struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c | 27 +++++++++++++++
 drivers/base/property.c | 92 ++++++++++++++++++++++++++-----------------------
 drivers/of/base.c       | 25 ++++++++++++++
 3 files changed, 100 insertions(+), 44 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 14b96ec..b84d0e5 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1116,6 +1116,33 @@ static bool acpi_fwnode_property_present(struct fwnode_handle *fwnode,
 	return !acpi_node_prop_get(fwnode, propname, NULL);
 }
 
+static int acpi_fwnode_property_read_int_array(
+	struct fwnode_handle *fwnode, const char *propname,
+	unsigned int elem_size, void *val, size_t nval)
+{
+	enum dev_prop_type type;
+
+	switch (elem_size) {
+	case sizeof(u8):
+		type = DEV_PROP_U8;
+		break;
+	case sizeof(u16):
+		type = DEV_PROP_U16;
+		break;
+	case sizeof(u32):
+		type = DEV_PROP_U32;
+		break;
+	case sizeof(u64):
+		type = DEV_PROP_U64;
+		break;
+	default:
+		return -ENXIO;
+	}
+
+	return acpi_node_prop_read(fwnode, propname, type, val, nval);
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
+	.property_read_int_array = acpi_fwnode_property_read_int_array,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 37aea12..8c2068a 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -189,8 +189,32 @@ static bool pset_fwnode_property_present(struct fwnode_handle *fwnode,
 	return !!pset_prop_get(to_pset_node(fwnode), propname);
 }
 
+static int pset_fwnode_read_int_array(
+	struct fwnode_handle *fwnode, const char *propname,
+	unsigned int elem_size, void *val, size_t nval)
+{
+	struct property_set *node = to_pset_node(fwnode);
+
+	if (!val)
+		return pset_prop_count_elems_of_size(node, propname, elem_size);
+
+	switch (elem_size) {
+	case sizeof(u8):
+		return pset_prop_read_u8_array(node, propname, val, nval);
+	case sizeof(u16):
+		return pset_prop_read_u16_array(node, propname, val, nval);
+	case sizeof(u32):
+		return pset_prop_read_u32_array(node, propname, val, nval);
+	case sizeof(u64):
+		return pset_prop_read_u64_array(node, propname, val, nval);
+	}
+
+	return -ENXIO;
+}
+
 static const struct fwnode_operations pset_fwnode_ops = {
 	.property_present = pset_fwnode_property_present,
+	.property_read_int_array = pset_fwnode_read_int_array,
 };
 
 /**
@@ -393,42 +417,22 @@ int device_property_match_string(struct device *dev, const char *propname,
 }
 EXPORT_SYMBOL_GPL(device_property_match_string);
 
-#define OF_DEV_PROP_READ_ARRAY(node, propname, type, val, nval)				\
-	(val) ? of_property_read_##type##_array((node), (propname), (val), (nval))	\
-	      : of_property_count_elems_of_size((node), (propname), sizeof(type))
-
-#define PSET_PROP_READ_ARRAY(node, propname, type, val, nval)				\
-	(val) ? pset_prop_read_##type##_array((node), (propname), (val), (nval))	\
-	      : pset_prop_count_elems_of_size((node), (propname), sizeof(type))
-
-#define FWNODE_PROP_READ(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_)	\
-({											\
-	int _ret_;									\
-	if (is_of_node(_fwnode_))							\
-		_ret_ = OF_DEV_PROP_READ_ARRAY(to_of_node(_fwnode_), _propname_,	\
-					       _type_, _val_, _nval_);			\
-	else if (is_acpi_node(_fwnode_))						\
-		_ret_ = acpi_node_prop_read(_fwnode_, _propname_, _proptype_,		\
-					    _val_, _nval_);				\
-	else if (is_pset_node(_fwnode_)) 						\
-		_ret_ = PSET_PROP_READ_ARRAY(to_pset_node(_fwnode_), _propname_,	\
-					     _type_, _val_, _nval_);			\
-	else										\
-		_ret_ = -ENXIO;								\
-	_ret_;										\
-})
-
-#define FWNODE_PROP_READ_ARRAY(_fwnode_, _propname_, _type_, _proptype_, _val_, _nval_)	\
-({											\
-	int _ret_;									\
-	_ret_ = FWNODE_PROP_READ(_fwnode_, _propname_, _type_, _proptype_,		\
-				 _val_, _nval_);					\
-	if (_ret_ == -EINVAL && !IS_ERR_OR_NULL(_fwnode_) &&				\
-	    !IS_ERR_OR_NULL(_fwnode_->secondary))					\
-		_ret_ = FWNODE_PROP_READ(_fwnode_->secondary, _propname_, _type_,	\
-				_proptype_, _val_, _nval_);				\
-	_ret_;										\
-})
+static int fwnode_property_read_int_array(
+	struct fwnode_handle *fwnode, const char *propname,
+	unsigned int elem_size, void *val, size_t nval)
+{
+	int ret;
+
+	ret = fwnode_call_int_op(fwnode, property_read_int_array, propname,
+				 elem_size, val, nval);
+	if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) &&
+	    !IS_ERR_OR_NULL(fwnode->secondary))
+		ret = fwnode_call_int_op(
+			fwnode->secondary, property_read_int_array, propname,
+			elem_size, val, nval);
+
+	return ret;
+}
 
 /**
  * fwnode_property_read_u8_array - return a u8 array property of firmware node
@@ -451,8 +455,8 @@ EXPORT_SYMBOL_GPL(device_property_match_string);
 int fwnode_property_read_u8_array(struct fwnode_handle *fwnode,
 				  const char *propname, u8 *val, size_t nval)
 {
-	return FWNODE_PROP_READ_ARRAY(fwnode, propname, u8, DEV_PROP_U8,
-				      val, nval);
+	return fwnode_property_read_int_array(fwnode, propname, sizeof(u8),
+					      val, nval);
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_u8_array);
 
@@ -477,8 +481,8 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u8_array);
 int fwnode_property_read_u16_array(struct fwnode_handle *fwnode,
 				   const char *propname, u16 *val, size_t nval)
 {
-	return FWNODE_PROP_READ_ARRAY(fwnode, propname, u16, DEV_PROP_U16,
-				      val, nval);
+	return fwnode_property_read_int_array(fwnode, propname, sizeof(u16),
+					      val, nval);
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_u16_array);
 
@@ -503,8 +507,8 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u16_array);
 int fwnode_property_read_u32_array(struct fwnode_handle *fwnode,
 				   const char *propname, u32 *val, size_t nval)
 {
-	return FWNODE_PROP_READ_ARRAY(fwnode, propname, u32, DEV_PROP_U32,
-				      val, nval);
+	return fwnode_property_read_int_array(fwnode, propname, sizeof(u32),
+					      val, nval);
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_u32_array);
 
@@ -529,8 +533,8 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_u32_array);
 int fwnode_property_read_u64_array(struct fwnode_handle *fwnode,
 				   const char *propname, u64 *val, size_t nval)
 {
-	return FWNODE_PROP_READ_ARRAY(fwnode, propname, u64, DEV_PROP_U64,
-				      val, nval);
+	return fwnode_property_read_int_array(fwnode, propname, sizeof(u64),
+					      val, nval);
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_u64_array);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 84f2530..80f736d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2486,8 +2486,33 @@ static bool of_fwnode_property_present(struct fwnode_handle *fwnode,
 	return of_property_read_bool(to_of_node(fwnode), propname);
 }
 
+static int of_fwnode_property_read_int_array(
+	struct fwnode_handle *fwnode, const char *propname,
+	unsigned int elem_size, void *val, size_t nval)
+{
+	struct device_node *node = to_of_node(fwnode);
+
+	if (!val)
+		return of_property_count_elems_of_size(node, propname,
+						       elem_size);
+
+	switch (elem_size) {
+	case sizeof(u8):
+		return of_property_read_u8_array(node, propname, val, nval);
+	case sizeof(u16):
+		return of_property_read_u16_array(node, propname, val, nval);
+	case sizeof(u32):
+		return of_property_read_u32_array(node, propname, val, nval);
+	case sizeof(u64):
+		return of_property_read_u64_array(node, propname, val, nval);
+	}
+
+	return -ENXIO;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
 	.property_present = of_fwnode_property_present,
+	.property_read_int_array = of_fwnode_property_read_int_array,
 };
-- 
2.7.4


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

* [PATCH 10/20] device property: Read strings using string array reading functions
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (8 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 09/20] device property: Use fwnode_operations for reading integer arrays Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 13/20] device property: Use fwnode_operations for obtaining next child node Sakari Ailus
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Always read strings using of_property_read_string_array() instead of
of_property_read_string(). This allows using a single operation struct
callback for accessing strings.

Same for pset_prop_read_string_array() and pset_prop_read_string().

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/base/property.c | 47 +----------------------------------------------
 1 file changed, 1 insertion(+), 46 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index 8c2068a..b251525 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -158,31 +158,6 @@ static int pset_prop_read_string_array(struct property_set *pset,
 	return 0;
 }
 
-static int pset_prop_read_string(struct property_set *pset,
-				 const char *propname, const char **strings)
-{
-	struct property_entry *prop;
-	const char **pointer;
-
-	prop = pset_prop_get(pset, propname);
-	if (!prop)
-		return -EINVAL;
-	if (!prop->is_string)
-		return -EILSEQ;
-	if (prop->is_array) {
-		pointer = prop->pointer.str;
-		if (!pointer)
-			return -ENODATA;
-	} else {
-		pointer = &prop->value.str;
-		if (*pointer && strnlen(*pointer, prop->length) >= prop->length)
-			return -EILSEQ;
-	}
-
-	*strings = *pointer;
-	return 0;
-}
-
 static bool pset_fwnode_property_present(struct fwnode_handle *fwnode,
 					 const char *propname)
 {
@@ -586,19 +561,6 @@ static int __fwnode_property_read_string_array(struct fwnode_handle *fwnode,
 	return -ENXIO;
 }
 
-static int __fwnode_property_read_string(struct fwnode_handle *fwnode,
-					 const char *propname, const char **val)
-{
-	if (is_of_node(fwnode))
-		return of_property_read_string(to_of_node(fwnode), propname, val);
-	else if (is_acpi_node(fwnode))
-		return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
-					   val, 1);
-	else if (is_pset_node(fwnode))
-		return pset_prop_read_string(to_pset_node(fwnode), propname, val);
-	return -ENXIO;
-}
-
 /**
  * fwnode_property_read_string_array - return string array property of a node
  * @fwnode: Firmware node to get the property of
@@ -650,14 +612,7 @@ EXPORT_SYMBOL_GPL(fwnode_property_read_string_array);
 int fwnode_property_read_string(struct fwnode_handle *fwnode,
 				const char *propname, const char **val)
 {
-	int ret;
-
-	ret = __fwnode_property_read_string(fwnode, propname, val);
-	if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) &&
-	    !IS_ERR_OR_NULL(fwnode->secondary))
-		ret = __fwnode_property_read_string(fwnode->secondary,
-						    propname, val);
-	return ret;
+	return fwnode_property_read_string_array(fwnode, propname, val, 1);
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_string);
 
-- 
2.7.4


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

* [PATCH 11/20] device property: Use fwnode_operations for reading string arrays
       [not found] ` <1487869276-25244-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2017-02-23 17:01   ` Sakari Ailus
  2017-02-23 17:01   ` [PATCH 12/20] device property: Use fwnode_operations for obtaining parent node Sakari Ailus
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: sudeep.holla-5wv7dgnIgG8, lorenzo.pieralisi-5wv7dgnIgG8,
	mika.westerberg-VuQAYsv1563Yd54FQh9/CA,
	rafael-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	broonie-DgEjT+Ai2ygdnm+yROfE0A, robh-DgEjT+Ai2ygdnm+yROfE0A,
	ahs3-H+wXaHxf7aLQT0dZR+AlfA

Change the implementation of fwnode_property_read_string_array() function
to use struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/acpi/property.c |  9 ++++++
 drivers/base/property.c | 81 ++++++++++++++++++-------------------------------
 drivers/of/base.c       | 22 ++++++++++++++
 3 files changed, 61 insertions(+), 51 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index b84d0e5..4e76b31 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1142,7 +1142,16 @@ static int acpi_fwnode_property_read_int_array(
 	return acpi_node_prop_read(fwnode, propname, type, val, nval);
 }
 
+static int acpi_fwnode_property_read_string_array(
+	struct fwnode_handle *fwnode, const char *propname, const char **val,
+	size_t nval)
+{
+	return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
+				   val, nval);
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
+	.property_read_string_array = acpi_fwnode_property_read_string_array,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index b251525..136ba66 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -187,9 +187,34 @@ static int pset_fwnode_read_int_array(
 	return -ENXIO;
 }
 
+static int pset_fwnode_property_read_string_array(
+	struct fwnode_handle *fwnode, const char *propname, const char **val,
+	size_t nval)
+{
+	struct property_set *node = to_pset_node(fwnode);
+	struct property_entry *prop;
+
+	/* Read properties if val is non-NULL */
+	if (val)
+		return pset_prop_read_string_array(node, propname, val, nval);
+
+	prop = pset_prop_get(node, propname);
+	if (!prop)
+		return -EINVAL;
+
+	/* The array length for a non-array string property is 1. */
+	if (!prop->is_array)
+		return 1;
+
+	/* Return the length of an array. */
+	return pset_prop_count_elems_of_size(node, propname,
+					     sizeof(const char *));
+}
+
 static const struct fwnode_operations pset_fwnode_ops = {
 	.property_present = pset_fwnode_property_present,
 	.property_read_int_array = pset_fwnode_read_int_array,
+	.property_read_string_array = pset_fwnode_property_read_string_array,
 };
 
 /**
@@ -513,54 +538,6 @@ int fwnode_property_read_u64_array(struct fwnode_handle *fwnode,
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_u64_array);
 
-static int __fwnode_property_read_string_array(struct fwnode_handle *fwnode,
-					       const char *propname,
-					       const char **val, size_t nval)
-{
-	if (is_of_node(fwnode)) {
-		int rval;
-
-		if (!val)
-			return of_property_count_strings(to_of_node(fwnode),
-							 propname);
-
-		rval = of_property_read_string_array(to_of_node(fwnode),
-						     propname, val, nval);
-
-		if (rval < 0)
-			return rval;
-
-		if (rval == nval)
-			return 0;
-
-		return -EOVERFLOW;
-	} else if (is_acpi_node(fwnode))
-		return acpi_node_prop_read(fwnode, propname, DEV_PROP_STRING,
-					   val, nval);
-	else if (is_pset_node(fwnode)) {
-		struct property_set *node = to_pset_node(fwnode);
-		struct property_entry *prop;
-
-		/* Read properties if val is non-NULL */
-		if (val)
-			return pset_prop_read_string_array(node, propname,
-							   val, nval);
-
-		prop = pset_prop_get(node, propname);
-		if (!prop)
-			return -EINVAL;
-
-		/* The array length for a non-array string property is 1. */
-		if (!prop->is_array)
-			return 1;
-
-		/* Return the length of an array. */
-		return pset_prop_count_elems_of_size(node, propname,
-						     sizeof(const char *));
-	}
-	return -ENXIO;
-}
-
 /**
  * fwnode_property_read_string_array - return string array property of a node
  * @fwnode: Firmware node to get the property of
@@ -585,11 +562,13 @@ int fwnode_property_read_string_array(struct fwnode_handle *fwnode,
 {
 	int ret;
 
-	ret = __fwnode_property_read_string_array(fwnode, propname, val, nval);
+	ret = fwnode_call_int_op(fwnode, property_read_string_array, propname,
+				 val, nval);
 	if (ret == -EINVAL && !IS_ERR_OR_NULL(fwnode) &&
 	    !IS_ERR_OR_NULL(fwnode->secondary))
-		ret = __fwnode_property_read_string_array(fwnode->secondary,
-							  propname, val, nval);
+		ret = fwnode_call_int_op(fwnode->secondary,
+					 property_read_string_array, propname,
+					 val, nval);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(fwnode_property_read_string_array);
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 80f736d..7bd9eec 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2510,9 +2510,31 @@ static int of_fwnode_property_read_int_array(
 	return -ENXIO;
 }
 
+static int of_fwnode_property_read_string_array(
+	struct fwnode_handle *fwnode, const char *propname,
+	const char **val, size_t nval)
+{
+	struct device_node *node = to_of_node(fwnode);
+	int rval;
+
+	if (!val)
+		return of_property_count_strings(node, propname);
+
+	rval = of_property_read_string_array(node, propname, val, nval);
+
+	if (rval < 0)
+		return rval;
+
+	if (rval == nval)
+		return 0;
+
+	return -EOVERFLOW;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
 	.property_present = of_fwnode_property_present,
 	.property_read_int_array = of_fwnode_property_read_int_array,
+	.property_read_string_array = of_fwnode_property_read_string_array,
 };
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 12/20] device property: Use fwnode_operations for obtaining parent node
       [not found] ` <1487869276-25244-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
  2017-02-23 17:01   ` [PATCH 11/20] device property: Use fwnode_operations for reading string arrays Sakari Ailus
@ 2017-02-23 17:01   ` Sakari Ailus
  2017-02-23 17:01   ` [PATCH 15/20] device property: Use fwnode_operations for obtaining next graph endpoint Sakari Ailus
  2017-02-23 17:01   ` [PATCH 17/20] device property: Use fwnode_operations for obtaining the remote port Sakari Ailus
  3 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: sudeep.holla-5wv7dgnIgG8, lorenzo.pieralisi-5wv7dgnIgG8,
	mika.westerberg-VuQAYsv1563Yd54FQh9/CA,
	rafael-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	broonie-DgEjT+Ai2ygdnm+yROfE0A, robh-DgEjT+Ai2ygdnm+yROfE0A,
	ahs3-H+wXaHxf7aLQT0dZR+AlfA

Change the implementation of fwnode_property_get_parent() function to use
struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/acpi/property.c |  7 +++++++
 drivers/base/property.c | 14 +-------------
 drivers/of/base.c       | 12 ++++++++++++
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 4e76b31..a20b81f 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1150,8 +1150,15 @@ static int acpi_fwnode_property_read_string_array(
 				   val, nval);
 }
 
+static struct fwnode_handle *acpi_fwnode_get_parent(
+	struct fwnode_handle *fwnode)
+{
+	return acpi_node_get_parent(fwnode);
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
 	.property_read_string_array = acpi_fwnode_property_read_string_array,
+	.get_parent = acpi_fwnode_get_parent,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 136ba66..e730f4f 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -863,19 +863,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_next_parent);
  */
 struct fwnode_handle *fwnode_get_parent(struct fwnode_handle *fwnode)
 {
-	struct fwnode_handle *parent = NULL;
-
-	if (is_of_node(fwnode)) {
-		struct device_node *node;
-
-		node = of_get_parent(to_of_node(fwnode));
-		if (node)
-			parent = &node->fwnode;
-	} else if (is_acpi_node(fwnode)) {
-		parent = acpi_node_get_parent(fwnode);
-	}
-
-	return parent;
+	return fwnode_call_ptr_op(fwnode, get_parent);
 }
 EXPORT_SYMBOL_GPL(fwnode_get_parent);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7bd9eec..5825eda 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2531,10 +2531,22 @@ static int of_fwnode_property_read_string_array(
 	return -EOVERFLOW;
 }
 
+static struct fwnode_handle *of_fwnode_get_parent(struct fwnode_handle *fwnode)
+{
+	struct device_node *node;
+
+	node = of_get_parent(to_of_node(fwnode));
+	if (node)
+		return of_fwnode_handle(node);
+
+	return NULL;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
 	.property_present = of_fwnode_property_present,
 	.property_read_int_array = of_fwnode_property_read_int_array,
 	.property_read_string_array = of_fwnode_property_read_string_array,
+	.get_parent = of_fwnode_get_parent,
 };
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 13/20] device property: Use fwnode_operations for obtaining next child node
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (9 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 10/20] device property: Read strings using string array reading functions Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 14/20] device property: Use fwnode_operations for obtaining a named " Sakari Ailus
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Change the implementation of fwnode_property_get_parent() function to use
struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c |  1 +
 drivers/base/property.c | 13 +------------
 drivers/of/base.c       | 14 ++++++++++++++
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index a20b81f..fc1d5da 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1161,4 +1161,5 @@ const struct fwnode_operations acpi_fwnode_ops = {
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
 	.property_read_string_array = acpi_fwnode_property_read_string_array,
 	.get_parent = acpi_fwnode_get_parent,
+	.get_next_child_node = acpi_get_next_subnode,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index e730f4f..e9068b1 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -875,18 +875,7 @@ EXPORT_SYMBOL_GPL(fwnode_get_parent);
 struct fwnode_handle *fwnode_get_next_child_node(struct fwnode_handle *fwnode,
 						 struct fwnode_handle *child)
 {
-	if (is_of_node(fwnode)) {
-		struct device_node *node;
-
-		node = of_get_next_available_child(to_of_node(fwnode),
-						   to_of_node(child));
-		if (node)
-			return &node->fwnode;
-	} else if (is_acpi_node(fwnode)) {
-		return acpi_get_next_subnode(fwnode, child);
-	}
-
-	return NULL;
+	return fwnode_call_ptr_op(fwnode, get_next_child_node, child);
 }
 EXPORT_SYMBOL_GPL(fwnode_get_next_child_node);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 5825eda..66a7970 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2542,6 +2542,19 @@ static struct fwnode_handle *of_fwnode_get_parent(struct fwnode_handle *fwnode)
 	return NULL;
 }
 
+static struct fwnode_handle *of_fwnode_get_next_child_node(
+	struct fwnode_handle *fwnode, struct fwnode_handle *child)
+{
+	struct device_node *node;
+
+	node = of_get_next_available_child(to_of_node(fwnode),
+					   to_of_node(child));
+	if (node)
+		return of_fwnode_handle(node);
+
+	return NULL;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
@@ -2549,4 +2562,5 @@ const struct fwnode_operations of_fwnode_ops = {
 	.property_read_int_array = of_fwnode_property_read_int_array,
 	.property_read_string_array = of_fwnode_property_read_string_array,
 	.get_parent = of_fwnode_get_parent,
+	.get_next_child_node = of_fwnode_get_next_child_node,
 };
-- 
2.7.4


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

* [PATCH 14/20] device property: Use fwnode_operations for obtaining a named child node
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (10 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 13/20] device property: Use fwnode_operations for obtaining next child node Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
       [not found] ` <1487869276-25244-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Change the implementation of fwnode_property_get_parent() function to use
struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c | 17 +++++++++++++++++
 drivers/base/property.c | 18 +-----------------
 drivers/of/base.c       | 14 ++++++++++++++
 3 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index fc1d5da..b704a33 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1156,10 +1156,27 @@ static struct fwnode_handle *acpi_fwnode_get_parent(
 	return acpi_node_get_parent(fwnode);
 }
 
+static struct fwnode_handle *acpi_fwnode_get_named_child_node(
+	struct fwnode_handle *fwnode, const char *childname)
+{
+	struct fwnode_handle *child;
+
+	/*
+	 * Find first matching named child node of this fwnode.
+	 * For ACPI this will be a data only sub-node.
+	 */
+	fwnode_for_each_child_node(fwnode, child)
+		if (acpi_data_node_match(child, childname))
+			return child;
+
+	return NULL;
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
 	.property_read_string_array = acpi_fwnode_property_read_string_array,
 	.get_parent = acpi_fwnode_get_parent,
 	.get_next_child_node = acpi_get_next_subnode,
+	.get_named_child_node = acpi_fwnode_get_named_child_node,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index e9068b1..5db8e26 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -907,23 +907,7 @@ EXPORT_SYMBOL_GPL(device_get_next_child_node);
 struct fwnode_handle *fwnode_get_named_child_node(struct fwnode_handle *fwnode,
 						  const char *childname)
 {
-	struct fwnode_handle *child;
-
-	/*
-	 * Find first matching named child node of this fwnode.
-	 * For ACPI this will be a data only sub-node.
-	 */
-	fwnode_for_each_child_node(fwnode, child) {
-		if (is_of_node(child)) {
-			if (!of_node_cmp(to_of_node(child)->name, childname))
-				return child;
-		} else if (is_acpi_data_node(child)) {
-			if (acpi_data_node_match(child, childname))
-				return child;
-		}
-	}
-
-	return NULL;
+	return fwnode_call_ptr_op(fwnode, get_named_child_node, childname);
 }
 EXPORT_SYMBOL_GPL(fwnode_get_named_child_node);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 66a7970..082490b 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2555,6 +2555,19 @@ static struct fwnode_handle *of_fwnode_get_next_child_node(
 	return NULL;
 }
 
+static struct fwnode_handle *of_fwnode_get_named_child_node(
+	struct fwnode_handle *fwnode, const char *childname)
+{
+	struct device_node *node = to_of_node(fwnode);
+	struct device_node *child;
+
+	for_each_available_child_of_node(node, child)
+		if (!of_node_cmp(child->name, childname))
+			return of_fwnode_handle(child);
+
+	return NULL;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
@@ -2563,4 +2576,5 @@ const struct fwnode_operations of_fwnode_ops = {
 	.property_read_string_array = of_fwnode_property_read_string_array,
 	.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,
 };
-- 
2.7.4


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

* [PATCH 15/20] device property: Use fwnode_operations for obtaining next graph endpoint
       [not found] ` <1487869276-25244-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
  2017-02-23 17:01   ` [PATCH 11/20] device property: Use fwnode_operations for reading string arrays Sakari Ailus
  2017-02-23 17:01   ` [PATCH 12/20] device property: Use fwnode_operations for obtaining parent node Sakari Ailus
@ 2017-02-23 17:01   ` Sakari Ailus
  2017-02-23 17:01   ` [PATCH 17/20] device property: Use fwnode_operations for obtaining the remote port Sakari Ailus
  3 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: sudeep.holla-5wv7dgnIgG8, lorenzo.pieralisi-5wv7dgnIgG8,
	mika.westerberg-VuQAYsv1563Yd54FQh9/CA,
	rafael-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	broonie-DgEjT+Ai2ygdnm+yROfE0A, robh-DgEjT+Ai2ygdnm+yROfE0A,
	ahs3-H+wXaHxf7aLQT0dZR+AlfA

Change the implementation of fwnode_graph_get_next_endpoint() function to
use struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/acpi/property.c | 13 +++++++++++++
 drivers/base/property.c | 19 +------------------
 drivers/of/base.c       | 14 ++++++++++++++
 3 files changed, 28 insertions(+), 18 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index b704a33..bf7b7f0 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1172,6 +1172,18 @@ static struct fwnode_handle *acpi_fwnode_get_named_child_node(
 	return NULL;
 }
 
+static struct fwnode_handle *acpi_fwnode_graph_get_next_endpoint(
+	struct fwnode_handle *fwnode, struct fwnode_handle *prev)
+{
+	struct fwnode_handle *endpoint;
+
+	endpoint = acpi_graph_get_next_endpoint(fwnode, prev);
+	if (IS_ERR(endpoint))
+		return NULL;
+
+	return endpoint;
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
@@ -1179,4 +1191,5 @@ const struct fwnode_operations acpi_fwnode_ops = {
 	.get_parent = acpi_fwnode_get_parent,
 	.get_next_child_node = acpi_get_next_subnode,
 	.get_named_child_node = acpi_fwnode_get_named_child_node,
+	.graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 5db8e26..01add33 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1082,24 +1082,7 @@ struct fwnode_handle *
 fwnode_graph_get_next_endpoint(struct fwnode_handle *fwnode,
 			       struct fwnode_handle *prev)
 {
-	struct fwnode_handle *endpoint = NULL;
-
-	if (is_of_node(fwnode)) {
-		struct device_node *node;
-
-		node = of_graph_get_next_endpoint(to_of_node(fwnode),
-						  to_of_node(prev));
-
-		if (node)
-			endpoint = &node->fwnode;
-	} else if (is_acpi_node(fwnode)) {
-		endpoint = acpi_graph_get_next_endpoint(fwnode, prev);
-		if (IS_ERR(endpoint))
-			endpoint = NULL;
-	}
-
-	return endpoint;
-
+	return fwnode_call_ptr_op(fwnode, graph_get_next_endpoint, prev);
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 082490b..b7adfb6 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2568,6 +2568,19 @@ static struct fwnode_handle *of_fwnode_get_named_child_node(
 	return NULL;
 }
 
+static struct fwnode_handle *of_fwnode_graph_get_next_endpoint(
+	struct fwnode_handle *fwnode, struct fwnode_handle *prev)
+{
+	struct device_node *node;
+
+	node = of_graph_get_next_endpoint(to_of_node(fwnode),
+					  to_of_node(prev));
+	if (node)
+		return of_fwnode_handle(node);
+
+	return NULL;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
@@ -2577,4 +2590,5 @@ 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,
+	.graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
 };
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 16/20] device property: Use fwnode_operations for obtaining the remote endpoint
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (12 preceding siblings ...)
       [not found] ` <1487869276-25244-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 18/20] device property: Use fwnode_operations for obtaining the remote port parent Sakari Ailus
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Change the implementation of fwnode_graph_get_remote_endpoint() function to
use struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c | 11 +++++++++++
 drivers/base/property.c | 20 +-------------------
 drivers/of/base.c       | 13 +++++++++++++
 3 files changed, 25 insertions(+), 19 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index bf7b7f0..39bffd3 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1184,6 +1184,16 @@ static struct fwnode_handle *acpi_fwnode_graph_get_next_endpoint(
 	return endpoint;
 }
 
+static struct fwnode_handle *acpi_fwnode_graph_get_remote_endpoint(
+	struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *endpoint = NULL;
+
+	acpi_graph_get_remote_endpoint(fwnode, NULL, NULL, &endpoint);
+
+	return endpoint;
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
@@ -1192,4 +1202,5 @@ const struct fwnode_operations acpi_fwnode_ops = {
 	.get_next_child_node = acpi_get_next_subnode,
 	.get_named_child_node = acpi_fwnode_get_named_child_node,
 	.graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
+	.graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 01add33..fbdd0a0 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1153,25 +1153,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
 struct fwnode_handle *
 fwnode_graph_get_remote_endpoint(struct fwnode_handle *fwnode)
 {
-	struct fwnode_handle *endpoint = NULL;
-
-	if (is_of_node(fwnode)) {
-		struct device_node *node;
-
-		node = of_parse_phandle(to_of_node(fwnode), "remote-endpoint",
-					0);
-		if (node)
-			endpoint = &node->fwnode;
-	} else if (is_acpi_node(fwnode)) {
-		int ret;
-
-		ret = acpi_graph_get_remote_endpoint(fwnode, NULL, NULL,
-						     &endpoint);
-		if (ret)
-			return NULL;
-	}
-
-	return endpoint;
+	return fwnode_call_ptr_op(fwnode, graph_get_remote_endpoint);
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index b7adfb6..17fce20 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2581,6 +2581,18 @@ static struct fwnode_handle *of_fwnode_graph_get_next_endpoint(
 	return NULL;
 }
 
+static struct fwnode_handle *of_fwnode_graph_get_remote_endpoint(
+	struct fwnode_handle *fwnode)
+{
+	struct device_node *node;
+
+	node = of_parse_phandle(to_of_node(fwnode), "remote-endpoint", 0);
+	if (node)
+		return of_fwnode_handle(node);
+
+	return NULL;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
@@ -2591,4 +2603,5 @@ const struct fwnode_operations of_fwnode_ops = {
 	.get_next_child_node = of_fwnode_get_next_child_node,
 	.get_named_child_node = of_fwnode_get_named_child_node,
 	.graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
+	.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
 };
-- 
2.7.4


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

* [PATCH 17/20] device property: Use fwnode_operations for obtaining the remote port
       [not found] ` <1487869276-25244-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
                     ` (2 preceding siblings ...)
  2017-02-23 17:01   ` [PATCH 15/20] device property: Use fwnode_operations for obtaining next graph endpoint Sakari Ailus
@ 2017-02-23 17:01   ` Sakari Ailus
  3 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi-u79uwXL29TY76Z2rM5mHXA, devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: sudeep.holla-5wv7dgnIgG8, lorenzo.pieralisi-5wv7dgnIgG8,
	mika.westerberg-VuQAYsv1563Yd54FQh9/CA,
	rafael-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	broonie-DgEjT+Ai2ygdnm+yROfE0A, robh-DgEjT+Ai2ygdnm+yROfE0A,
	ahs3-H+wXaHxf7aLQT0dZR+AlfA

Change the implementation of fwnode_graph_get_remote_port() function to
use struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 drivers/acpi/property.c | 11 +++++++++++
 drivers/base/property.c | 18 +-----------------
 drivers/of/base.c       | 13 +++++++++++++
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 39bffd3..623260d 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1194,6 +1194,16 @@ static struct fwnode_handle *acpi_fwnode_graph_get_remote_endpoint(
 	return endpoint;
 }
 
+static struct fwnode_handle *acpi_fwnode_graph_get_remote_port(
+	struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *port = NULL;
+
+	acpi_graph_get_remote_endpoint(fwnode, NULL, &port, NULL);
+
+	return port;
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
@@ -1203,4 +1213,5 @@ const struct fwnode_operations acpi_fwnode_ops = {
 	.get_named_child_node = acpi_fwnode_get_named_child_node,
 	.graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
 	.graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
+	.graph_get_remote_port = acpi_fwnode_graph_get_remote_port,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index fbdd0a0..5636290 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1124,23 +1124,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent);
  */
 struct fwnode_handle *fwnode_graph_get_remote_port(struct fwnode_handle *fwnode)
 {
-	struct fwnode_handle *port = NULL;
-
-	if (is_of_node(fwnode)) {
-		struct device_node *node;
-
-		node = of_graph_get_remote_port(to_of_node(fwnode));
-		if (node)
-			port = &node->fwnode;
-	} else if (is_acpi_node(fwnode)) {
-		int ret;
-
-		ret = acpi_graph_get_remote_endpoint(fwnode, NULL, &port, NULL);
-		if (ret)
-			return NULL;
-	}
-
-	return port;
+	return fwnode_call_ptr_op(fwnode, graph_get_remote_endpoint);
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 17fce20..bdc195c 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2593,6 +2593,18 @@ static struct fwnode_handle *of_fwnode_graph_get_remote_endpoint(
 	return NULL;
 }
 
+static struct fwnode_handle *of_fwnode_graph_get_remote_port(
+	struct fwnode_handle *fwnode)
+{
+	struct device_node *node;
+
+	node = of_graph_get_remote_port(to_of_node(fwnode));
+	if (node)
+		return of_fwnode_handle(node);
+
+	return NULL;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
@@ -2604,4 +2616,5 @@ const struct fwnode_operations of_fwnode_ops = {
 	.get_named_child_node = of_fwnode_get_named_child_node,
 	.graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
 	.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
+	.graph_get_remote_port = of_fwnode_graph_get_remote_port,
 };
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH 18/20] device property: Use fwnode_operations for obtaining the remote port parent
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (13 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 16/20] device property: Use fwnode_operations for obtaining the remote endpoint Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 19/20] device property: Use fwnode_operations for parsing graph endpoint Sakari Ailus
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Change the implementation of fwnode_graph_get_remote_port_parent()
function to use struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c | 11 +++++++++++
 drivers/base/property.c | 19 +------------------
 drivers/of/base.c       | 13 +++++++++++++
 3 files changed, 25 insertions(+), 18 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 623260d..1790256 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1204,6 +1204,16 @@ static struct fwnode_handle *acpi_fwnode_graph_get_remote_port(
 	return port;
 }
 
+static struct fwnode_handle *acpi_fwnode_graph_get_remote_port_parent(
+	struct fwnode_handle *fwnode)
+{
+	struct fwnode_handle *parent = NULL;
+
+	acpi_graph_get_remote_endpoint(fwnode, &parent, NULL, NULL);
+
+	return parent;
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
@@ -1214,4 +1224,5 @@ const struct fwnode_operations acpi_fwnode_ops = {
 	.graph_get_next_endpoint = acpi_fwnode_graph_get_next_endpoint,
 	.graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
 	.graph_get_remote_port = acpi_fwnode_graph_get_remote_port,
+	.graph_get_remote_port_parent = acpi_fwnode_graph_get_remote_port_parent,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 5636290..258c83d 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1095,24 +1095,7 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_next_endpoint);
 struct fwnode_handle *
 fwnode_graph_get_remote_port_parent(struct fwnode_handle *fwnode)
 {
-	struct fwnode_handle *parent = NULL;
-
-	if (is_of_node(fwnode)) {
-		struct device_node *node;
-
-		node = of_graph_get_remote_port_parent(to_of_node(fwnode));
-		if (node)
-			parent = &node->fwnode;
-	} else if (is_acpi_node(fwnode)) {
-		int ret;
-
-		ret = acpi_graph_get_remote_endpoint(fwnode, &parent, NULL,
-						     NULL);
-		if (ret)
-			return NULL;
-	}
-
-	return parent;
+	return fwnode_call_ptr_op(fwnode, graph_get_remote_port_parent);
 }
 EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_port_parent);
 
diff --git a/drivers/of/base.c b/drivers/of/base.c
index bdc195c..2b4a13f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2605,6 +2605,18 @@ static struct fwnode_handle *of_fwnode_graph_get_remote_port(
 	return NULL;
 }
 
+static struct fwnode_handle *of_fwnode_graph_get_remote_port_parent(
+	struct fwnode_handle *fwnode)
+{
+	struct device_node *node;
+
+	node = of_graph_get_remote_port_parent(to_of_node(fwnode));
+	if (node)
+		return of_fwnode_handle(node);
+
+	return NULL;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
@@ -2617,4 +2629,5 @@ const struct fwnode_operations of_fwnode_ops = {
 	.graph_get_next_endpoint = of_fwnode_graph_get_next_endpoint,
 	.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
 	.graph_get_remote_port = of_fwnode_graph_get_remote_port,
+	.graph_get_remote_port_parent = of_fwnode_graph_get_remote_port_parent,
 };
-- 
2.7.4


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

* [PATCH 19/20] device property: Use fwnode_operations for parsing graph endpoint
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (14 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 18/20] device property: Use fwnode_operations for obtaining the remote port parent Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 17:01 ` [PATCH 20/20] device property: Implement fwnode_get_next_parent() using fwnode interface Sakari Ailus
  2017-02-23 22:37 ` [PATCH 00/20] Move firmware specific code to firmware specific locations Rafael J. Wysocki
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Change the implementation of fwnode_graph_parse_endpoint() function to
use struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/acpi/property.c | 19 +++++++++++++++++++
 drivers/base/property.c | 22 +---------------------
 drivers/of/base.c       | 17 +++++++++++++++++
 3 files changed, 37 insertions(+), 21 deletions(-)

diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
index 1790256..23bc12d 100644
--- a/drivers/acpi/property.c
+++ b/drivers/acpi/property.c
@@ -1214,6 +1214,24 @@ static struct fwnode_handle *acpi_fwnode_graph_get_remote_port_parent(
 	return parent;
 }
 
+static int acpi_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
+					    struct fwnode_endpoint *endpoint)
+{
+	struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
+	struct fwnode_handle *iter;
+
+	endpoint->local_fwnode = fwnode;
+
+	fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
+
+	for (iter = fwnode_get_next_child_node(port_fwnode, NULL);
+	     iter != fwnode;
+	     iter = fwnode_get_next_child_node(port_fwnode, iter))
+		endpoint->id++;
+
+	return 0;
+}
+
 const struct fwnode_operations acpi_fwnode_ops = {
 	.property_present = acpi_fwnode_property_present,
 	.property_read_int_array = acpi_fwnode_property_read_int_array,
@@ -1225,4 +1243,5 @@ const struct fwnode_operations acpi_fwnode_ops = {
 	.graph_get_remote_endpoint = acpi_fwnode_graph_get_remote_endpoint,
 	.graph_get_remote_port = acpi_fwnode_graph_get_remote_port,
 	.graph_get_remote_port_parent = acpi_fwnode_graph_get_remote_port_parent,
+	.graph_parse_endpoint = acpi_fwnode_graph_parse_endpoint,
 };
diff --git a/drivers/base/property.c b/drivers/base/property.c
index 258c83d..f108469 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1134,28 +1134,8 @@ EXPORT_SYMBOL_GPL(fwnode_graph_get_remote_endpoint);
 int fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
 				struct fwnode_endpoint *endpoint)
 {
-	struct fwnode_handle *port_fwnode = fwnode_get_parent(fwnode);
-
 	memset(endpoint, 0, sizeof(*endpoint));
 
-	endpoint->local_fwnode = fwnode;
-
-	if (is_acpi_node(port_fwnode)) {
-		struct fwnode_handle *iter;
-
-		fwnode_property_read_u32(port_fwnode, "port", &endpoint->port);
-
-		for (iter = fwnode_get_next_child_node(port_fwnode, NULL);
-		     iter != fwnode;
-		     iter = fwnode_get_next_child_node(port_fwnode, iter))
-			endpoint->id++;
-	} else {
-		fwnode_property_read_u32(port_fwnode, "reg", &endpoint->port);
-		fwnode_property_read_u32(fwnode, "reg", &endpoint->id);
-	}
-
-	fwnode_handle_put(port_fwnode);
-
-	return 0;
+	return fwnode_call_int_op(fwnode, graph_parse_endpoint, endpoint);
 }
 EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 2b4a13f..d3757ab 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2617,6 +2617,22 @@ static struct fwnode_handle *of_fwnode_graph_get_remote_port_parent(
 	return NULL;
 }
 
+static int of_fwnode_graph_parse_endpoint(struct fwnode_handle *fwnode,
+					  struct fwnode_endpoint *endpoint)
+{
+	struct device_node *node = to_of_node(fwnode);
+	struct device_node *port_node = of_get_parent(node);
+
+	endpoint->local_fwnode = fwnode;
+
+	of_property_read_u32(port_node, "reg", &endpoint->port);
+	of_property_read_u32(node, "reg", &endpoint->id);
+
+	of_node_put(port_node);
+
+	return 0;
+}
+
 const struct fwnode_operations of_fwnode_ops = {
 	.get = of_fwnode_get,
 	.put = of_fwnode_put,
@@ -2630,4 +2646,5 @@ const struct fwnode_operations of_fwnode_ops = {
 	.graph_get_remote_endpoint = of_fwnode_graph_get_remote_endpoint,
 	.graph_get_remote_port = of_fwnode_graph_get_remote_port,
 	.graph_get_remote_port_parent = of_fwnode_graph_get_remote_port_parent,
+	.graph_parse_endpoint = of_fwnode_graph_parse_endpoint,
 };
-- 
2.7.4


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

* [PATCH 20/20] device property: Implement fwnode_get_next_parent() using fwnode interface
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (15 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 19/20] device property: Use fwnode_operations for parsing graph endpoint Sakari Ailus
@ 2017-02-23 17:01 ` Sakari Ailus
  2017-02-23 22:37 ` [PATCH 00/20] Move firmware specific code to firmware specific locations Rafael J. Wysocki
  17 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-23 17:01 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

fwnode_get_next_parent() can be implemented using fwnode interface. Do
that to avoid implementing an additional callback for the function in
struct fwnode_operations.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/base/property.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/base/property.c b/drivers/base/property.c
index f108469..6ee8f4f 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -838,17 +838,9 @@ EXPORT_SYMBOL_GPL(device_add_properties);
  */
 struct fwnode_handle *fwnode_get_next_parent(struct fwnode_handle *fwnode)
 {
-	struct fwnode_handle *parent = NULL;
+	struct fwnode_handle *parent = fwnode_call_ptr_op(fwnode, get_parent);
 
-	if (is_of_node(fwnode)) {
-		struct device_node *node;
-
-		node = of_get_next_parent(to_of_node(fwnode));
-		if (node)
-			parent = &node->fwnode;
-	} else if (is_acpi_node(fwnode)) {
-		parent = acpi_node_get_parent(fwnode);
-	}
+	fwnode_handle_put(fwnode);
 
 	return parent;
 }
-- 
2.7.4


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

* Re: [PATCH 00/20] Move firmware specific code to firmware specific locations
  2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
                   ` (16 preceding siblings ...)
  2017-02-23 17:01 ` [PATCH 20/20] device property: Implement fwnode_get_next_parent() using fwnode interface Sakari Ailus
@ 2017-02-23 22:37 ` Rafael J. Wysocki
       [not found]   ` <2915459.fDeP2CYj8T-yvgW3jdyMHm1GS7QM15AGw@public.gmane.org>
  17 siblings, 1 reply; 26+ messages in thread
From: Rafael J. Wysocki @ 2017-02-23 22:37 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-acpi, devicetree, sudeep.holla, lorenzo.pieralisi,
	mika.westerberg, rafael, mark.rutland, broonie, robh, ahs3

On Thursday, February 23, 2017 07:00:56 PM Sakari Ailus wrote:
> Hi,
> 
> This set moves firmware specific implementations of the device / fwnode
> property API to locations that are specific to firmware implementation,
> still leaving property set (which isn't really firmware) implementation in
> drivers/base/property.c.
> 
> The set begins with a few bugfixes (patches 1--3), followed by adding
> fwnode_operations struct and then gradually moving firmware dependent code
> to drivers/acpi/property.c and drivers/of/base.c.
> 
> The set depends on the ACPI graph support here:
> 
> <URL:http://marc.info/?l=linux-acpi&m=148786716920942&w=2>
> 
> Comments are welcome.

Patches [1-3/20] from this series seem to be fixes that don't depend on the
rest of it and don't depend on the other series you posted.

If that is the case, it would be good to get them in during this cycle instead
of sitting on them for several weeks.

So is that the case?

Thanks,
Rafael


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

* Re: [PATCH 03/20] device property: of_property_read_string_array() returns number of strings
  2017-02-23 17:00 ` [PATCH 03/20] device property: of_property_read_string_array() returns number of strings Sakari Ailus
@ 2017-02-23 23:42   ` Rob Herring
  2017-02-24  8:15     ` Sakari Ailus
  0 siblings, 1 reply; 26+ messages in thread
From: Rob Herring @ 2017-02-23 23:42 UTC (permalink / raw)
  To: Sakari Ailus
  Cc: linux-acpi, devicetree, Sudeep Holla, Lorenzo Pieralisi,
	mika.westerberg, Rafael J. Wysocki, Mark Rutland, Mark Brown,
	Al Stone

On Thu, Feb 23, 2017 at 11:00 AM, Sakari Ailus
<sakari.ailus@linux.intel.com> wrote:
> of_property_read_string_array() returns number of strings read if the
> target array of pointers is non-NULL. fwnode_property_read_string_array()
> is documented to return 0 in that case. Fix this.

It seems of_property_read_string_array is more capable. If the number
of strings is variable and I want use the fwnode API, then what do I
do? IMO, you should fix the fwnode API.

Rob

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

* Re: [PATCH 03/20] device property: of_property_read_string_array() returns number of strings
  2017-02-23 23:42   ` Rob Herring
@ 2017-02-24  8:15     ` Sakari Ailus
  0 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-24  8:15 UTC (permalink / raw)
  To: Rob Herring
  Cc: Sakari Ailus, linux-acpi, devicetree, Sudeep Holla,
	Lorenzo Pieralisi, mika.westerberg, Rafael J. Wysocki,
	Mark Rutland, Mark Brown, Al Stone

Hi Rob,

On Thu, Feb 23, 2017 at 05:42:07PM -0600, Rob Herring wrote:
> On Thu, Feb 23, 2017 at 11:00 AM, Sakari Ailus
> <sakari.ailus@linux.intel.com> wrote:
> > of_property_read_string_array() returns number of strings read if the
> > target array of pointers is non-NULL. fwnode_property_read_string_array()
> > is documented to return 0 in that case. Fix this.
> 
> It seems of_property_read_string_array is more capable. If the number
> of strings is variable and I want use the fwnode API, then what do I
> do? IMO, you should fix the fwnode API.

It is not more capable but simply different.

The caller typically needs to allocate memory to hold a pointer array, which
means it needs to call the function with NULL output array argument anyway.
There is the special case where the maximum number of strings is known,
though. You could remove an additional call in this case.

However, why I do argue for this interface is safety: returning zero on
success is always a safe choice. Programmers often check for zero only
because it might be shorter to write or someone might thing it looks nicer:

int ret = fwnode_property_read_string_array(fwnode, "foo");
if (ret)
	goto err;

Additionally, returning zero is consistent within the pack: the OF (and
fwnode) integer array access functions return zero on success, i.e. not the
number of array elements read.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

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

* Re: [PATCH 00/20] Move firmware specific code to firmware specific locations
       [not found]   ` <2915459.fDeP2CYj8T-yvgW3jdyMHm1GS7QM15AGw@public.gmane.org>
@ 2017-02-24  8:25     ` Sakari Ailus
  0 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-24  8:25 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Sakari Ailus, linux-acpi-u79uwXL29TY76Z2rM5mHXA,
	devicetree-u79uwXL29TY76Z2rM5mHXA, sudeep.holla-5wv7dgnIgG8,
	lorenzo.pieralisi-5wv7dgnIgG8,
	mika.westerberg-VuQAYsv1563Yd54FQh9/CA,
	rafael-DgEjT+Ai2ygdnm+yROfE0A, mark.rutland-5wv7dgnIgG8,
	broonie-DgEjT+Ai2ygdnm+yROfE0A, robh-DgEjT+Ai2ygdnm+yROfE0A,
	ahs3-H+wXaHxf7aLQT0dZR+AlfA

On Thu, Feb 23, 2017 at 11:37:12PM +0100, Rafael J. Wysocki wrote:
> On Thursday, February 23, 2017 07:00:56 PM Sakari Ailus wrote:
> > Hi,
> > 
> > This set moves firmware specific implementations of the device / fwnode
> > property API to locations that are specific to firmware implementation,
> > still leaving property set (which isn't really firmware) implementation in
> > drivers/base/property.c.
> > 
> > The set begins with a few bugfixes (patches 1--3), followed by adding
> > fwnode_operations struct and then gradually moving firmware dependent code
> > to drivers/acpi/property.c and drivers/of/base.c.
> > 
> > The set depends on the ACPI graph support here:
> > 
> > <URL:http://marc.info/?l=linux-acpi&m=148786716920942&w=2>
> > 
> > Comments are welcome.
> 
> Patches [1-3/20] from this series seem to be fixes that don't depend on the
> rest of it and don't depend on the other series you posted.
> 
> If that is the case, it would be good to get them in during this cycle instead
> of sitting on them for several weeks.
> 
> So is that the case?

Correct. There are no dependencies from patches 1--3 to the rest (first set
or this one).

-- 
Regards,

Sakari Ailus
e-mail: sakari.ailus-X3B1VOXEql0@public.gmane.org	XMPP: sailus-PCDdDYkjdNMDXYZnReoRVg@public.gmane.org
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [PATCH v1.1 05/20] device property: Add macros for calling fwnode operations
  2017-02-23 17:01 ` [PATCH 05/20] device property: Add macros for calling " Sakari Ailus
@ 2017-02-24  9:36   ` Sakari Ailus
  0 siblings, 0 replies; 26+ messages in thread
From: Sakari Ailus @ 2017-02-24  9:36 UTC (permalink / raw)
  To: linux-acpi, devicetree
  Cc: sudeep.holla, lorenzo.pieralisi, mika.westerberg, rafael,
	mark.rutland, broonie, robh, ahs3

Not all implementations may implement all fwnode operations. Instead of
leaving this up to the caller to figure out, add a few macros for the
purpose.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
since v1:

- Use correct return codes for ops returning integers. -ENXIO is returned if an op
  does not exist and -EINVAL is returned if fwnode is NULL.

 include/linux/fwnode.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h
index ede74fb..75e2a00 100644
--- a/include/linux/fwnode.h
+++ b/include/linux/fwnode.h
@@ -82,4 +82,19 @@ struct fwnode_operations {
 				    struct fwnode_endpoint *endpoint);
 };
 
+#define fwnode_has_op(fwnode, op)				\
+	((fwnode) && (fwnode)->ops && (fwnode)->ops->op)
+#define fwnode_call_int_op(fwnode, op, ...)				\
+	(fwnode ? (fwnode_has_op(fwnode, op) ?				\
+		   (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : -ENXIO) : \
+	 -EINVAL)
+#define fwnode_call_ptr_op(fwnode, op, ...)		\
+	(fwnode_has_op(fwnode, op) ?			\
+	 (fwnode)->ops->op(fwnode, ## __VA_ARGS__) : NULL)
+#define fwnode_call_void_op(fwnode, op, ...)				\
+	do {								\
+		if (fwnode_has_op(fwnode, op))				\
+			(fwnode)->ops->op(fwnode, ## __VA_ARGS__);	\
+	} while (false)
+
 #endif
-- 
2.7.4


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

end of thread, other threads:[~2017-02-24  9:43 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-23 17:00 [PATCH 00/20] Move firmware specific code to firmware specific locations Sakari Ailus
2017-02-23 17:00 ` [PATCH 01/20] device property: fwnode_property_read_string_array() may return -EILSEQ Sakari Ailus
2017-02-23 17:00 ` [PATCH 02/20] device property: Fix reading pset strings using array access functions Sakari Ailus
2017-02-23 17:00 ` [PATCH 03/20] device property: of_property_read_string_array() returns number of strings Sakari Ailus
2017-02-23 23:42   ` Rob Herring
2017-02-24  8:15     ` Sakari Ailus
2017-02-23 17:01 ` [PATCH 04/20] device property: Add operations struct for fwnode operations Sakari Ailus
2017-02-23 17:01 ` [PATCH 05/20] device property: Add macros for calling " Sakari Ailus
2017-02-24  9:36   ` [PATCH v1.1 " Sakari Ailus
2017-02-23 17:01 ` [PATCH 06/20] device property: Introduce firmware property operations, set them Sakari Ailus
2017-02-23 17:01 ` [PATCH 07/20] device property: Use fwnode_operations for fwnode_handle_{get,put} Sakari Ailus
2017-02-23 17:01 ` [PATCH 08/20] device property: Use fwnode_operations for fwnode_property_present() Sakari Ailus
2017-02-23 17:01 ` [PATCH 09/20] device property: Use fwnode_operations for reading integer arrays Sakari Ailus
2017-02-23 17:01 ` [PATCH 10/20] device property: Read strings using string array reading functions Sakari Ailus
2017-02-23 17:01 ` [PATCH 13/20] device property: Use fwnode_operations for obtaining next child node Sakari Ailus
2017-02-23 17:01 ` [PATCH 14/20] device property: Use fwnode_operations for obtaining a named " Sakari Ailus
     [not found] ` <1487869276-25244-1-git-send-email-sakari.ailus-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2017-02-23 17:01   ` [PATCH 11/20] device property: Use fwnode_operations for reading string arrays Sakari Ailus
2017-02-23 17:01   ` [PATCH 12/20] device property: Use fwnode_operations for obtaining parent node Sakari Ailus
2017-02-23 17:01   ` [PATCH 15/20] device property: Use fwnode_operations for obtaining next graph endpoint Sakari Ailus
2017-02-23 17:01   ` [PATCH 17/20] device property: Use fwnode_operations for obtaining the remote port Sakari Ailus
2017-02-23 17:01 ` [PATCH 16/20] device property: Use fwnode_operations for obtaining the remote endpoint Sakari Ailus
2017-02-23 17:01 ` [PATCH 18/20] device property: Use fwnode_operations for obtaining the remote port parent Sakari Ailus
2017-02-23 17:01 ` [PATCH 19/20] device property: Use fwnode_operations for parsing graph endpoint Sakari Ailus
2017-02-23 17:01 ` [PATCH 20/20] device property: Implement fwnode_get_next_parent() using fwnode interface Sakari Ailus
2017-02-23 22:37 ` [PATCH 00/20] Move firmware specific code to firmware specific locations Rafael J. Wysocki
     [not found]   ` <2915459.fDeP2CYj8T-yvgW3jdyMHm1GS7QM15AGw@public.gmane.org>
2017-02-24  8:25     ` Sakari Ailus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.