aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/core.c')
-rw-r--r--drivers/base/core.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index cadf165651d8..21d13038534e 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/device.h> 13#include <linux/device.h>
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/fwnode.h>
15#include <linux/init.h> 16#include <linux/init.h>
16#include <linux/module.h> 17#include <linux/module.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
@@ -2144,3 +2145,53 @@ define_dev_printk_level(dev_notice, KERN_NOTICE);
2144define_dev_printk_level(_dev_info, KERN_INFO); 2145define_dev_printk_level(_dev_info, KERN_INFO);
2145 2146
2146#endif 2147#endif
2148
2149static inline bool fwnode_is_primary(struct fwnode_handle *fwnode)
2150{
2151 return fwnode && !IS_ERR(fwnode->secondary);
2152}
2153
2154/**
2155 * set_primary_fwnode - Change the primary firmware node of a given device.
2156 * @dev: Device to handle.
2157 * @fwnode: New primary firmware node of the device.
2158 *
2159 * Set the device's firmware node pointer to @fwnode, but if a secondary
2160 * firmware node of the device is present, preserve it.
2161 */
2162void set_primary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
2163{
2164 if (fwnode) {
2165 struct fwnode_handle *fn = dev->fwnode;
2166
2167 if (fwnode_is_primary(fn))
2168 fn = fn->secondary;
2169
2170 fwnode->secondary = fn;
2171 dev->fwnode = fwnode;
2172 } else {
2173 dev->fwnode = fwnode_is_primary(dev->fwnode) ?
2174 dev->fwnode->secondary : NULL;
2175 }
2176}
2177EXPORT_SYMBOL_GPL(set_primary_fwnode);
2178
2179/**
2180 * set_secondary_fwnode - Change the secondary firmware node of a given device.
2181 * @dev: Device to handle.
2182 * @fwnode: New secondary firmware node of the device.
2183 *
2184 * If a primary firmware node of the device is present, set its secondary
2185 * pointer to @fwnode. Otherwise, set the device's firmware node pointer to
2186 * @fwnode.
2187 */
2188void set_secondary_fwnode(struct device *dev, struct fwnode_handle *fwnode)
2189{
2190 if (fwnode)
2191 fwnode->secondary = ERR_PTR(-ENODEV);
2192
2193 if (fwnode_is_primary(dev->fwnode))
2194 dev->fwnode->secondary = fwnode;
2195 else
2196 dev->fwnode = fwnode;
2197}