|
@@ -12,6 +12,7 @@
|
|
|
|
|
|
#include <linux/device.h>
|
|
|
#include <linux/err.h>
|
|
|
+#include <linux/fwnode.h>
|
|
|
#include <linux/init.h>
|
|
|
#include <linux/module.h>
|
|
|
#include <linux/slab.h>
|
|
@@ -2133,3 +2134,53 @@ define_dev_printk_level(dev_notice, KERN_NOTICE);
|
|
|
define_dev_printk_level(_dev_info, KERN_INFO);
|
|
|
|
|
|
#endif
|
|
|
+
|
|
|
+static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
|
|
|
+{
|
|
|
+ return fwnode && !IS_ERR(fwnode->secondary);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * set_primary_fwnode - Change the primary firmware node of a given device.
|
|
|
+ * @dev: Device to handle.
|
|
|
+ * @fwnode: New primary firmware node of the device.
|
|
|
+ *
|
|
|
+ * Set the device's firmware node pointer to @fwnode, but if a secondary
|
|
|
+ * firmware node of the device is present, preserve it.
|
|
|
+ */
|
|
|
+void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
|
|
|
+{
|
|
|
+ if (fwnode) {
|
|
|
+ struct fwnode_handle *fn = dev->fwnode;
|
|
|
+
|
|
|
+ if (fwnode_is_primary(fn))
|
|
|
+ fn = fn->secondary;
|
|
|
+
|
|
|
+ fwnode->secondary = fn;
|
|
|
+ dev->fwnode = fwnode;
|
|
|
+ } else {
|
|
|
+ dev->fwnode = fwnode_is_primary(dev->fwnode) ?
|
|
|
+ dev->fwnode->secondary : NULL;
|
|
|
+ }
|
|
|
+}
|
|
|
+EXPORT_SYMBOL_GPL(set_primary_fwnode);
|
|
|
+
|
|
|
+/**
|
|
|
+ * set_secondary_fwnode - Change the secondary firmware node of a given device.
|
|
|
+ * @dev: Device to handle.
|
|
|
+ * @fwnode: New secondary firmware node of the device.
|
|
|
+ *
|
|
|
+ * If a primary firmware node of the device is present, set its secondary
|
|
|
+ * pointer to @fwnode. Otherwise, set the device's firmware node pointer to
|
|
|
+ * @fwnode.
|
|
|
+ */
|
|
|
+void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
|
|
|
+{
|
|
|
+ if (fwnode)
|
|
|
+ fwnode->secondary = ERR_PTR(-ENODEV);
|
|
|
+
|
|
|
+ if (fwnode_is_primary(dev->fwnode))
|
|
|
+ dev->fwnode->secondary = fwnode;
|
|
|
+ else
|
|
|
+ dev->fwnode = fwnode;
|
|
|
+}
|