diff --git a/common/firmware.c b/common/firmware.c index 9d55d73..609cf11 100644 --- a/common/firmware.c +++ b/common/firmware.c @@ -63,6 +63,24 @@ } /* + * firmwaremgr_find_by_node - find a firmware device handler + * + * Find a firmware device handler using the device node of the firmware + * handler. This allows to retrieve the firmware handler with a phandle from + * the device tree. + */ +struct firmware_mgr *firmwaremgr_find_by_node(const struct device_node *np) +{ + struct firmware_mgr *mgr; + + list_for_each_entry(mgr, &firmwaremgr_list, list) + if (mgr->handler->dev->parent->device_node == np) + return mgr; + + return NULL; +} + +/* * firmwaremgr_list_handlers - list registered firmware device handlers * in pretty format */ diff --git a/include/firmware.h b/include/firmware.h index 284e0f9..7c01a77 100644 --- a/include/firmware.h +++ b/include/firmware.h @@ -34,10 +34,25 @@ int firmwaremgr_register(struct firmware_handler *); struct firmware_mgr *firmwaremgr_find(const char *); +#ifdef CONFIG_FIRMWARE +struct firmware_mgr *firmwaremgr_find_by_node(const struct device_node *np); +#else +static inline struct firmware_mgr *firmwaremgr_find_by_node(const struct device_node *np) +{ + return NULL; +} +#endif void firmwaremgr_list_handlers(void); +#ifdef CONFIG_FIRMWARE int firmwaremgr_load_file(struct firmware_mgr *, const char *path); +#else +static inline int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *path) +{ + return -ENOSYS; +} +#endif #define get_builtin_firmware(name, start, size) \ { \