device property: Add fwnode_get_named_child_node()
[platform/kernel/linux-rpi.git] / drivers / base / property.c
index c458c63..538b248 100644 (file)
@@ -932,41 +932,88 @@ int device_add_properties(struct device *dev,
 EXPORT_SYMBOL_GPL(device_add_properties);
 
 /**
- * device_get_next_child_node - Return the next child node handle for a device
- * @dev: Device to find the next child node for.
- * @child: Handle to one of the device's child nodes or a null handle.
+ * fwnode_get_parent - Return parent firwmare node
+ * @fwnode: Firmware whose parent is retrieved
+ *
+ * Return parent firmware node of the given node if possible or %NULL if no
+ * parent was available.
  */
-struct fwnode_handle *device_get_next_child_node(struct device *dev,
+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;
+}
+EXPORT_SYMBOL_GPL(fwnode_get_parent);
+
+/**
+ * fwnode_get_next_child_node - Return the next child node handle for a node
+ * @fwnode: Firmware node to find the next child node for.
+ * @child: Handle to one of the node's child nodes or a %NULL handle.
+ */
+struct fwnode_handle *fwnode_get_next_child_node(struct fwnode_handle *fwnode,
                                                 struct fwnode_handle *child)
 {
-       if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
+       if (is_of_node(fwnode)) {
                struct device_node *node;
 
-               node = of_get_next_available_child(dev->of_node, to_of_node(child));
+               node = of_get_next_available_child(to_of_node(fwnode),
+                                                  to_of_node(child));
                if (node)
                        return &node->fwnode;
-       } else if (IS_ENABLED(CONFIG_ACPI)) {
-               return acpi_get_next_subnode(dev, child);
+       } else if (is_acpi_node(fwnode)) {
+               return acpi_get_next_subnode(fwnode, child);
        }
+
        return NULL;
 }
+EXPORT_SYMBOL_GPL(fwnode_get_next_child_node);
+
+/**
+ * device_get_next_child_node - Return the next child node handle for a device
+ * @dev: Device to find the next child node for.
+ * @child: Handle to one of the device's child nodes or a null handle.
+ */
+struct fwnode_handle *device_get_next_child_node(struct device *dev,
+                                                struct fwnode_handle *child)
+{
+       struct acpi_device *adev = ACPI_COMPANION(dev);
+       struct fwnode_handle *fwnode = NULL;
+
+       if (dev->of_node)
+               fwnode = &dev->of_node->fwnode;
+       else if (adev)
+               fwnode = acpi_fwnode_handle(adev);
+
+       return fwnode_get_next_child_node(fwnode, child);
+}
 EXPORT_SYMBOL_GPL(device_get_next_child_node);
 
 /**
- * device_get_named_child_node - Return first matching named child node handle
- * @dev: Device to find the named child node for.
+ * fwnode_get_named_child_node - Return first matching named child node handle
+ * @fwnode: Firmware node to find the named child node for.
  * @childname: String to match child node name against.
  */
-struct fwnode_handle *device_get_named_child_node(struct device *dev,
+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 device.
+        * Find first matching named child node of this fwnode.
         * For ACPI this will be a data only sub-node.
         */
-       device_for_each_child_node(dev, child) {
+       fwnode_for_each_child_node(fwnode, child) {
                if (is_of_node(child)) {
                        if (!of_node_cmp(to_of_node(child)->name, childname))
                                return child;
@@ -978,6 +1025,18 @@ struct fwnode_handle *device_get_named_child_node(struct device *dev,
 
        return NULL;
 }
+EXPORT_SYMBOL_GPL(fwnode_get_named_child_node);
+
+/**
+ * device_get_named_child_node - Return first matching named child node handle
+ * @dev: Device to find the named child node for.
+ * @childname: String to match child node name against.
+ */
+struct fwnode_handle *device_get_named_child_node(struct device *dev,
+                                                 const char *childname)
+{
+       return fwnode_get_named_child_node(dev_fwnode(dev), childname);
+}
 EXPORT_SYMBOL_GPL(device_get_named_child_node);
 
 /**