summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2021-06-24 16:48:04 +0000
committerCommit Bot <commit-bot@chromium.org>2021-06-28 12:56:48 +0000
commitf4362c1b541ad3ca10b8cb2f7b72c8063dea6fd8 (patch)
tree12bc6fb0778f367a2331dd39acec48fddd99fc13
parent5d9859ffa6bc1687818bbc3c955a20c7e0a2db07 (diff)
downloadchrome-ec-f4362c1b541ad3ca10b8cb2f7b72c8063dea6fd8.tar.gz
zephyr: use DEVICE_DT_GET for various shim modules
Convert various device_get_binding to DEVICE_DT_GET, which is processed at link time and more efficient. Same pattern on different modules where the output is checked using device_is_ready. BRANCH=none BUG=none TEST=zmake configure -b -B ~/build-volteer/ zephyr/projects/volteer/volteer TEST=zmake configure -b -B ~/build-it8xxx2_evb/ zephyr/projects/it8xxx2_evb Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: If426420da2c61b3bc02eb77e122469a1a40799f7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2985463 Reviewed-by: Yuval Peress <peress@chromium.org>
-rw-r--r--zephyr/drivers/cros_system/cros_system_npcx.c9
-rw-r--r--zephyr/shim/chip/it8xxx2/system.c6
-rw-r--r--zephyr/shim/chip/npcx/shi.c16
-rw-r--r--zephyr/shim/chip/npcx/system.c6
-rw-r--r--zephyr/shim/src/adc.c12
-rw-r--r--zephyr/shim/src/espi.c8
-rw-r--r--zephyr/shim/src/keyboard_raw.c8
-rw-r--r--zephyr/shim/src/rtc.c6
-rw-r--r--zephyr/shim/src/system.c7
-rw-r--r--zephyr/shim/src/watchdog.c14
10 files changed, 52 insertions, 40 deletions
diff --git a/zephyr/drivers/cros_system/cros_system_npcx.c b/zephyr/drivers/cros_system/cros_system_npcx.c
index 74af8443a6..3e480fd1d9 100644
--- a/zephyr/drivers/cros_system/cros_system_npcx.c
+++ b/zephyr/drivers/cros_system/cros_system_npcx.c
@@ -120,11 +120,10 @@ enum npcx_chip_id {
static int system_npcx_watchdog_stop(void)
{
if (IS_ENABLED(CONFIG_WATCHDOG)) {
- const struct device *wdt_dev = device_get_binding(
- DT_LABEL(DT_INST(0, nuvoton_npcx_watchdog)));
-
- if (!wdt_dev) {
- LOG_ERR("wdt_dev get binding failed");
+ const struct device *wdt_dev = DEVICE_DT_GET(
+ DT_NODELABEL(twd0));
+ if (!device_is_ready(wdt_dev)) {
+ LOG_ERR("Error: device %s is not ready", wdt_dev->name);
return -ENODEV;
}
diff --git a/zephyr/shim/chip/it8xxx2/system.c b/zephyr/shim/chip/it8xxx2/system.c
index bb68a77b38..0ec138a415 100644
--- a/zephyr/shim/chip/it8xxx2/system.c
+++ b/zephyr/shim/chip/it8xxx2/system.c
@@ -74,9 +74,9 @@ static int chip_system_init(const struct device *unused)
{
ARG_UNUSED(unused);
- bbram_dev = device_get_binding(DT_LABEL(DT_NODELABEL(bbram)));
- if (!bbram_dev) {
- LOG_ERR("bbram_dev get binding failed");
+ bbram_dev = DEVICE_DT_GET(DT_NODELABEL(bbram));
+ if (!device_is_ready(bbram_dev)) {
+ LOG_ERR("Error: device %s is not ready", bbram_dev->name);
return -1;
}
diff --git a/zephyr/shim/chip/npcx/shi.c b/zephyr/shim/chip/npcx/shi.c
index 2f48b3a95e..22b153a806 100644
--- a/zephyr/shim/chip/npcx/shi.c
+++ b/zephyr/shim/chip/npcx/shi.c
@@ -19,13 +19,14 @@
LOG_MODULE_REGISTER(shim_cros_shi, LOG_LEVEL_DBG);
-#define CROS_SHI_DEV DT_LABEL(DT_NODELABEL(shi))
+#define SHI_NODE DT_NODELABEL(shi)
static void shi_enable(void)
{
- const struct device *cros_shi_dev = device_get_binding(CROS_SHI_DEV);
- if (!cros_shi_dev) {
- LOG_ERR("Fail to bind %s device", CROS_SHI_DEV);
+ const struct device *cros_shi_dev = DEVICE_DT_GET(SHI_NODE);
+
+ if (!device_is_ready(cros_shi_dev)) {
+ LOG_ERR("Error: device %s is not ready", cros_shi_dev->name);
return;
}
@@ -50,9 +51,10 @@ DECLARE_HOOK(HOOK_INIT, shi_reenable_on_sysjump, HOOK_PRIO_INIT_CHIPSET + 1);
static void shi_disable(void)
{
- const struct device *cros_shi_dev = device_get_binding(CROS_SHI_DEV);
- if (!cros_shi_dev) {
- LOG_ERR("Fail to bind %s device", CROS_SHI_DEV);
+ const struct device *cros_shi_dev = DEVICE_DT_GET(SHI_NODE);
+
+ if (!device_is_ready(cros_shi_dev)) {
+ LOG_ERR("Error: device %s is not ready", cros_shi_dev->name);
return;
}
diff --git a/zephyr/shim/chip/npcx/system.c b/zephyr/shim/chip/npcx/system.c
index 1c36174654..2e1e8c5168 100644
--- a/zephyr/shim/chip/npcx/system.c
+++ b/zephyr/shim/chip/npcx/system.c
@@ -110,9 +110,9 @@ static int chip_system_init(const struct device *unused)
* NPCX chip uses BBRAM to save the reset flag. Binding & check BBRAM
* here.
*/
- bbram_dev = device_get_binding(DT_LABEL(DT_NODELABEL(bbram)));
- if (!bbram_dev) {
- LOG_ERR("bbram_dev gets binding failed");
+ bbram_dev = DEVICE_DT_GET(DT_NODELABEL(bbram));
+ if (!device_is_ready(bbram_dev)) {
+ LOG_ERR("Error: device %s is not ready", bbram_dev->name);
return -1;
}
diff --git a/zephyr/shim/src/adc.c b/zephyr/shim/src/adc.c
index c6fbed23c5..93a99c3973 100644
--- a/zephyr/shim/src/adc.c
+++ b/zephyr/shim/src/adc.c
@@ -4,10 +4,13 @@
*/
#include <drivers/adc.h>
+#include <logging/log.h>
#include "adc.h"
#include "zephyr_adc.h"
-#define ADC_DEV DT_LABEL(DT_NODELABEL(adc0))
+LOG_MODULE_REGISTER(shim_adc, LOG_LEVEL_ERR);
+
+#define ADC_NODE DT_NODELABEL(adc0)
const struct device *adc_dev;
#define HAS_NAMED_ADC_CHANNELS DT_NODE_EXISTS(DT_INST(0, named_adc_channels))
@@ -35,7 +38,12 @@ const struct adc_t adc_channels[] = { DT_FOREACH_CHILD(
static int init_device_bindings(const struct device *device)
{
ARG_UNUSED(device);
- adc_dev = device_get_binding(ADC_DEV);
+ adc_dev = DEVICE_DT_GET(ADC_NODE);
+
+ if (!device_is_ready(adc_dev)) {
+ LOG_ERR("Error: device %s is not ready", adc_dev->name);
+ return -1;
+ }
#if HAS_NAMED_ADC_CHANNELS
for (int i = 0; i < ARRAY_SIZE(adc_channels); i++)
diff --git a/zephyr/shim/src/espi.c b/zephyr/shim/src/espi.c
index 446a51d1a1..ee53c6a66e 100644
--- a/zephyr/shim/src/espi.c
+++ b/zephyr/shim/src/espi.c
@@ -154,7 +154,7 @@ static void espi_reset_handler(const struct device *dev,
}
#endif /* CONFIG_PLATFORM_EC_CHIPSET_RESET_HOOK */
-#define ESPI_DEV DT_LABEL(DT_NODELABEL(espi0))
+#define ESPI_NODE DT_NODELABEL(espi0)
static const struct device *espi_dev;
@@ -541,9 +541,9 @@ int zephyr_shim_setup_espi(void)
.max_freq = 20,
};
- espi_dev = device_get_binding(ESPI_DEV);
- if (!espi_dev) {
- LOG_ERR("Failed to find device %s", ESPI_DEV);
+ espi_dev = DEVICE_DT_GET(ESPI_NODE);
+ if (!device_is_ready(espi_dev)) {
+ LOG_ERR("Error: device %s is not ready", espi_dev->name);
return -1;
}
diff --git a/zephyr/shim/src/keyboard_raw.c b/zephyr/shim/src/keyboard_raw.c
index a8017cc0cf..8de585a78f 100644
--- a/zephyr/shim/src/keyboard_raw.c
+++ b/zephyr/shim/src/keyboard_raw.c
@@ -15,7 +15,7 @@
LOG_MODULE_REGISTER(shim_cros_kb_raw, LOG_LEVEL_ERR);
-#define CROS_KB_RAW_DEV DT_LABEL(DT_NODELABEL(cros_kb_raw))
+#define CROS_KB_RAW_NODE DT_NODELABEL(cros_kb_raw)
static const struct device *cros_kb_raw_dev;
/**
@@ -23,9 +23,9 @@ static const struct device *cros_kb_raw_dev;
*/
void keyboard_raw_init(void)
{
- cros_kb_raw_dev = device_get_binding(CROS_KB_RAW_DEV);
- if (!cros_kb_raw_dev) {
- LOG_ERR("Fail to find %s", CROS_KB_RAW_DEV);
+ cros_kb_raw_dev = DEVICE_DT_GET(CROS_KB_RAW_NODE);
+ if (!device_is_ready(cros_kb_raw_dev)) {
+ LOG_ERR("Error: device %s is not ready", cros_kb_raw_dev->name);
return;
}
diff --git a/zephyr/shim/src/rtc.c b/zephyr/shim/src/rtc.c
index 0f07af2f86..002e60148d 100644
--- a/zephyr/shim/src/rtc.c
+++ b/zephyr/shim/src/rtc.c
@@ -15,7 +15,7 @@
LOG_MODULE_REGISTER(shim_cros_rtc, LOG_LEVEL_ERR);
-#define CROS_RTC_DEV DT_LABEL(DT_CHOSEN(cros_rtc))
+#define CROS_RTC_NODE DT_CHOSEN(cros_rtc)
static const struct device *cros_rtc_dev;
#ifdef CONFIG_HOSTCMD_EVENTS
@@ -40,9 +40,9 @@ static int system_init_rtc(const struct device *unused)
{
ARG_UNUSED(unused);
- cros_rtc_dev = device_get_binding(CROS_RTC_DEV);
+ cros_rtc_dev = DEVICE_DT_GET(CROS_RTC_NODE);
if (!cros_rtc_dev) {
- LOG_ERR("Fail to find %s", CROS_RTC_DEV);
+ LOG_ERR("Error: device %s is not ready", cros_rtc_dev->name);
return -ENODEV;
}
diff --git a/zephyr/shim/src/system.c b/zephyr/shim/src/system.c
index 5a725477ab..55fe5183b8 100644
--- a/zephyr/shim/src/system.c
+++ b/zephyr/shim/src/system.c
@@ -30,7 +30,12 @@ static int system_init(const struct device *unused)
{
ARG_UNUSED(unused);
- bbram_dev = device_get_binding(DT_LABEL(DT_NODELABEL(bbram)));
+ bbram_dev = DEVICE_DT_GET(DT_NODELABEL(bbram));
+ if (!device_is_ready(bbram_dev)) {
+ LOG_ERR("Error: device %s is not ready", bbram_dev->name);
+ return -1;
+ }
+
return 0;
}
diff --git a/zephyr/shim/src/watchdog.c b/zephyr/shim/src/watchdog.c
index 13d380bfcb..2895868757 100644
--- a/zephyr/shim/src/watchdog.c
+++ b/zephyr/shim/src/watchdog.c
@@ -26,9 +26,9 @@ int watchdog_init(void)
const struct device *wdt;
struct wdt_timeout_cfg wdt_config;
- wdt = device_get_binding(DT_LABEL(DT_NODELABEL(twd0)));
- if (!wdt) {
- LOG_ERR("Watchdog get binding failed");
+ wdt = DEVICE_DT_GET(DT_NODELABEL(twd0));
+ if (!device_is_ready(wdt)) {
+ LOG_ERR("Error: device %s is not ready", wdt->name);
return -1;
}
@@ -62,11 +62,9 @@ void watchdog_reload(void)
{
const struct device *wdt;
- wdt = device_get_binding(DT_LABEL(DT_NODELABEL(twd0)));
- if (!wdt) {
- LOG_ERR("Watchdog get binding failed");
- return;
- }
+ wdt = DEVICE_DT_GET(DT_NODELABEL(twd0));
+ if (!device_is_ready(wdt))
+ LOG_ERR("Error: device %s is not ready", wdt->name);
wdt_feed(wdt, 0);
}