device: allow initializing any device
Remove restrictions from device_init by allowing to perform device initialization if the device state flags it being not initialized. This makes the API usable in contexts where device_deinit has been called before. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
8e59d4cd9d
commit
0d4b957b11
2 changed files with 6 additions and 14 deletions
|
@ -825,13 +825,12 @@ __syscall bool device_is_ready(const struct device *dev);
|
||||||
*
|
*
|
||||||
* A device whose initialization was deferred (by marking it as
|
* A device whose initialization was deferred (by marking it as
|
||||||
* ``zephyr,deferred-init`` on devicetree) needs to be initialized manually via
|
* ``zephyr,deferred-init`` on devicetree) needs to be initialized manually via
|
||||||
* this call. Note that only devices whose initialization was deferred can be
|
* this call. De-initialized devices can also be initialized again via this
|
||||||
* initialized via this call - one can not try to initialize a non
|
* call.
|
||||||
* initialization deferred device that failed initialization with this call.
|
|
||||||
*
|
*
|
||||||
* @param dev device to be initialized.
|
* @param dev device to be initialized.
|
||||||
*
|
*
|
||||||
* @retval -ENOENT If device was not found - or isn't a deferred one.
|
* @retval -EALREADY Device is already initialized.
|
||||||
* @retval -errno For other errors.
|
* @retval -errno For other errors.
|
||||||
*/
|
*/
|
||||||
__syscall int device_init(const struct device *dev);
|
__syscall int device_init(const struct device *dev);
|
||||||
|
|
|
@ -378,18 +378,11 @@ static void z_sys_init_run_level(enum init_level level)
|
||||||
|
|
||||||
int z_impl_device_init(const struct device *dev)
|
int z_impl_device_init(const struct device *dev)
|
||||||
{
|
{
|
||||||
const struct device *devs;
|
if (dev->state->initialized) {
|
||||||
size_t devc;
|
return -EALREADY;
|
||||||
|
|
||||||
devc = z_device_get_all_static(&devs);
|
|
||||||
|
|
||||||
for (const struct device *dev_ = devs; dev_ < (devs + devc); dev_++) {
|
|
||||||
if ((dev_ == dev) && ((dev->flags & DEVICE_FLAG_INIT_DEFERRED) != 0U)) {
|
|
||||||
return do_device_init(dev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -ENOENT;
|
return do_device_init(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_USERSPACE
|
#ifdef CONFIG_USERSPACE
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue