Skip to content

Commit e3c8c09

Browse files
committed
device: re-implement device_init
Re-implement device_init using device_get(). For now, recommend direct usage of device_get(). This allows to keep client code the same regardless of when a device is initialized. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
1 parent 8f7b425 commit e3c8c09

File tree

2 files changed

+21
-43
lines changed

2 files changed

+21
-43
lines changed

include/zephyr/device.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -835,22 +835,6 @@ size_t z_device_get_all_static(const struct device **devices);
835835
*/
836836
__syscall bool device_is_ready(const struct device *dev);
837837

838-
/**
839-
* @brief Initialize a device.
840-
*
841-
* A device whose initialization was deferred (by marking it as
842-
* ``zephyr,deferred-init`` on devicetree) needs to be initialized manually via
843-
* this call. Note that only devices whose initialization was deferred can be
844-
* initialized via this call - one can not try to initialize a non
845-
* initialization deferred device that failed initialization with this call.
846-
*
847-
* @param dev device to be initialized.
848-
*
849-
* @retval -ENOENT If device was not found - or isn't a deferred one.
850-
* @retval -errno For other errors.
851-
*/
852-
__syscall int device_init(const struct device *dev);
853-
854838
/**
855839
* Get a device.
856840
*
@@ -866,6 +850,27 @@ __syscall int device_init(const struct device *dev);
866850
*/
867851
__syscall int device_get(const struct device *dev);
868852

853+
/**
854+
* @brief Initialize a device.
855+
*
856+
* A device whose initialization was deferred (by marking it as
857+
* ``zephyr,deferred-init`` on devicetree) needs to be initialized manually via
858+
* this call. Note that only devices whose initialization was deferred can be
859+
* initialized via this call - one can not try to initialize a non
860+
* initialization deferred device that failed initialization with this call.
861+
*
862+
* @param dev device to be initialized.
863+
*
864+
* @note Usage of device_get() is preferred, this function will be deprecated.
865+
*
866+
* @retval -ENOENT If device was not found - or isn't a deferred one.
867+
* @retval -errno For other errors.
868+
*/
869+
static inline int device_init(const struct device *dev)
870+
{
871+
return device_get(dev);
872+
}
873+
869874
/**
870875
* @}
871876
*/

kernel/init.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -373,33 +373,6 @@ static void z_sys_init_run_level(enum init_level level)
373373
}
374374
}
375375

376-
377-
int z_impl_device_init(const struct device *dev)
378-
{
379-
const struct device *devs;
380-
size_t devc;
381-
382-
devc = z_device_get_all_static(&devs);
383-
384-
for (const struct device *dev_ = devs; dev_ < (devs + devc); dev_++) {
385-
if ((dev_ == dev) && ((dev->flags & DEVICE_FLAG_INIT_DEFERRED) != 0U)) {
386-
return do_device_init(dev);
387-
}
388-
}
389-
390-
return -ENOENT;
391-
}
392-
393-
#ifdef CONFIG_USERSPACE
394-
static inline int z_vrfy_device_init(const struct device *dev)
395-
{
396-
K_OOPS(K_SYSCALL_OBJ_INIT(dev, K_OBJ_ANY));
397-
398-
return z_impl_device_init(dev);
399-
}
400-
#include <zephyr/syscalls/device_init_mrsh.c>
401-
#endif
402-
403376
extern void boot_banner(void);
404377

405378
#ifdef CONFIG_BOOTARGS

0 commit comments

Comments
 (0)