mirror of
https://github.com/zephyrproject-rtos/zephyr
synced 2025-08-08 09:15:25 +00:00
Now that device_api attribute is unmodified at runtime, as well as all the other attributes, it is possible to switch all device driver instance to be constant. A coccinelle rule is used for this: @r_const_dev_1 disable optional_qualifier @ @@ -struct device * +const struct device * @r_const_dev_2 disable optional_qualifier @ @@ -struct device * const +const struct device * Fixes #27399 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
64 lines
1.3 KiB
C
64 lines
1.3 KiB
C
/*
|
|
* Copyright 2020 Google LLC
|
|
* Copyright (c) 2020 Nordic Semiconductor ASA
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#define LOG_LEVEL CONFIG_EMUL_LOG_LEVEL
|
|
#include <logging/log.h>
|
|
LOG_MODULE_REGISTER(emul);
|
|
|
|
#include <device.h>
|
|
#include <emul.h>
|
|
#include <string.h>
|
|
|
|
/**
|
|
* Find a an emulator using its link information
|
|
*
|
|
* @param emul Emulator info to find
|
|
* @return pointer to emulator, or NULL if not found
|
|
*/
|
|
static const struct emul *
|
|
emul_find_by_link(const struct emul_link_for_bus *emul)
|
|
{
|
|
const struct emul *erp;
|
|
|
|
for (erp = __emul_list_start; erp < __emul_list_end; erp++) {
|
|
if (strcmp(erp->dev_label, emul->label) == 0) {
|
|
return erp;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
int emul_init_for_bus_from_list(const struct device *dev,
|
|
const struct emul_list_for_bus *list)
|
|
{
|
|
const struct emul_list_for_bus *cfg = dev->config;
|
|
|
|
/*
|
|
* Walk the list of children, find the corresponding emulator and
|
|
* initialise it.
|
|
*/
|
|
const struct emul_link_for_bus *elp;
|
|
const struct emul_link_for_bus *const end =
|
|
cfg->children + cfg->num_children;
|
|
|
|
for (elp = cfg->children; elp < end; elp++) {
|
|
const struct emul *emul = emul_find_by_link(elp);
|
|
|
|
__ASSERT_NO_MSG(emul);
|
|
|
|
int rc = emul->init(emul, dev);
|
|
|
|
if (rc != 0) {
|
|
LOG_WRN("Init %s emulator failed: %d\n",
|
|
elp->label, rc);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|