summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDawid Niedzwiecki <dn@semihalf.com>2022-02-11 13:10:54 +0100
committerCommit Bot <commit-bot@chromium.org>2022-02-24 13:17:20 +0000
commit1c7d86616ae90c35596077c84213a4fd34ce7518 (patch)
tree279e8ee74e5ee94e089b94beff86eec8f1706e24
parenteae8b999ddad333e9a4e8b468f610ad01a59eb43 (diff)
downloadchrome-ec-1c7d86616ae90c35596077c84213a4fd34ce7518.tar.gz
zephyr: cbi: drop the driver model
Start using CBI SSFC and CBI FW_CONFIG via the shim layer, drop the driver model for CBI. The CBI is used only by EC via EEPROM operations in cros code. The change simplifies the initialization of CBI and saves memory(104B of FLASH and 8B of SRAM for Herobrine). BUG=b:216802531 BRANCH=main TEST=Verify the CBI SSFC and FW_CONFIG operation in Zephyr Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I1dc14806c29bb67578445e7b3029c6b168a0d9e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3471596 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Dawid Niedzwiecki <dawidn@google.com>
-rw-r--r--docs/zephyr/zephyr_fw_config.md6
-rw-r--r--zephyr/drivers/CMakeLists.txt1
-rw-r--r--zephyr/drivers/cros_cbi/CMakeLists.txt6
-rw-r--r--zephyr/drivers/cros_cbi/cros_cbi.c52
-rw-r--r--zephyr/drivers/cros_cbi/cros_cbi_common.h32
-rw-r--r--zephyr/drivers/cros_cbi/cros_cbi_ssfc.c57
-rw-r--r--zephyr/projects/nissa/src/common.c56
-rw-r--r--zephyr/shim/include/cros_cbi.h (renamed from zephyr/include/drivers/cros_cbi.h)100
-rw-r--r--zephyr/shim/src/CMakeLists.txt5
-rw-r--r--zephyr/shim/src/cbi.c22
-rw-r--r--zephyr/shim/src/cbi/CMakeLists.txt9
-rw-r--r--zephyr/shim/src/cbi/cbi_eeprom.c (renamed from zephyr/shim/src/cbi_eeprom.c)0
-rw-r--r--zephyr/shim/src/cbi/cros_cbi.c17
-rw-r--r--zephyr/shim/src/cbi/cros_cbi_fw_config.c (renamed from zephyr/drivers/cros_cbi/cros_cbi_fw_config.c)41
-rw-r--r--zephyr/shim/src/cbi/cros_cbi_ssfc.c (renamed from zephyr/drivers/cros_cbi/cros_cbi_ssfc.h)71
-rw-r--r--zephyr/shim/src/motionsense_sensors.c2
-rw-r--r--zephyr/test/drivers/src/cros_cbi.c23
17 files changed, 151 insertions, 349 deletions
diff --git a/docs/zephyr/zephyr_fw_config.md b/docs/zephyr/zephyr_fw_config.md
index ca76fba734..abe66addde 100644
--- a/docs/zephyr/zephyr_fw_config.md
+++ b/docs/zephyr/zephyr_fw_config.md
@@ -90,19 +90,17 @@ should be used to access the CBI API to retrieve selected fields,
and then the defined enums used e.g:
```
-#include <drivers/cros_cbi.h>
+#include "cros_cbi.h"
int get_power_watts()
{
- const struct device *dev;
int ret;
uint32_t val;
- dev = device_get_binding(CROS_CBI_LABEL);
if (dev == null)
return -1;
- ret = cros_cbi_get_fw_config(dev, FW_BJ_POWER, &val);
+ ret = cros_cbi_get_fw_config(FW_BJ_POWER, &val);
if (ret < 0)
return -1;
diff --git a/zephyr/drivers/CMakeLists.txt b/zephyr/drivers/CMakeLists.txt
index a9fab56f36..55b5269b6e 100644
--- a/zephyr/drivers/CMakeLists.txt
+++ b/zephyr/drivers/CMakeLists.txt
@@ -2,7 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-add_subdirectory(cros_cbi)
add_subdirectory(cros_flash)
add_subdirectory(cros_kb_raw)
add_subdirectory(cros_kblight)
diff --git a/zephyr/drivers/cros_cbi/CMakeLists.txt b/zephyr/drivers/cros_cbi/CMakeLists.txt
deleted file mode 100644
index 01b566c676..0000000000
--- a/zephyr/drivers/cros_cbi/CMakeLists.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-# SPDX-License-Identifier: Apache-2.0
-
-zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_EEPROM
- cros_cbi.c cros_cbi_ssfc.c cros_cbi_fw_config.c)
-zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_GPIO
- cros_cbi.c cros_cbi_ssfc.c cros_cbi_fw_config.c)
diff --git a/zephyr/drivers/cros_cbi/cros_cbi.c b/zephyr/drivers/cros_cbi/cros_cbi.c
deleted file mode 100644
index af1776a477..0000000000
--- a/zephyr/drivers/cros_cbi/cros_cbi.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <drivers/cros_cbi.h>
-
-#include "cros_board_info.h"
-#include "cros_cbi_ssfc.h"
-#include "cros_cbi_common.h"
-
-static int cros_cbi_ec_init(const struct device *dev)
-{
- cros_cbi_ssfc_init(dev);
- cros_cbi_fw_config_init(dev);
-
- return 0;
-}
-
-/* cros ec cbi driver registration */
-static const struct cros_cbi_driver_api cros_cbi_driver_api = {
- .init = cros_cbi_ec_init,
- .ssfc_check_match = cros_cbi_ec_ssfc_check_match,
- .get_fw_config = cros_cbi_ec_get_fw_config,
-};
-
-static int cbi_init(const struct device *dev)
-{
- ARG_UNUSED(dev);
-
- return 0;
-}
-
-/*
- * These belong in the SSFC specific code, but the array
- * is referenced in the cfg data.
- */
-#define DT_DRV_COMPAT named_cbi_ssfc_value
-static const uint8_t ssfc_values[] = {
- DT_INST_FOREACH_STATUS_OKAY(CBI_SSFC_VALUE_ARRAY)
-};
-#undef DT_DRV_COMPAT
-
-static const struct cros_cbi_config cros_cbi_cfg = {
- .ssfc_values = ssfc_values,
-};
-
-static struct cros_cbi_data cros_cbi_data;
-
-DEVICE_DEFINE(cros_cbi, CROS_CBI_LABEL, cbi_init, NULL, &cros_cbi_data,
- &cros_cbi_cfg, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
- &cros_cbi_driver_api);
diff --git a/zephyr/drivers/cros_cbi/cros_cbi_common.h b/zephyr/drivers/cros_cbi/cros_cbi_common.h
deleted file mode 100644
index ef48fdfd11..0000000000
--- a/zephyr/drivers/cros_cbi/cros_cbi_common.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef __CROS_CBI_CROS_CBI_COMMON_H
-#define __CROS_CBI_CROS_CBI_COMMON_H
-
-/* Device config */
-struct cros_cbi_config {
- /* SSFC values for specific configs */
- const uint8_t *ssfc_values;
-};
-
-/* Device data */
-struct cros_cbi_data {
- /* Cached SSFC configs */
- union cbi_ssfc cached_ssfc;
- /* Cached FW_CONFIG bits */
- uint32_t cached_fw_config;
-};
-
-void cros_cbi_ssfc_init(const struct device *dev);
-bool cros_cbi_ec_ssfc_check_match(const struct device *dev,
- enum cbi_ssfc_value_id value_id);
-void cros_cbi_fw_config_init(const struct device *dev);
-int cros_cbi_ec_get_fw_config(const struct device *dev,
- enum cbi_fw_config_field_id field_id,
- uint32_t *value);
-
-
-#endif /* __CROS_CBI_CROS_CBI_COMMON_H */
diff --git a/zephyr/drivers/cros_cbi/cros_cbi_ssfc.c b/zephyr/drivers/cros_cbi/cros_cbi_ssfc.c
deleted file mode 100644
index 624b0ddc5f..0000000000
--- a/zephyr/drivers/cros_cbi/cros_cbi_ssfc.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <drivers/cros_cbi.h>
-#include <logging/log.h>
-
-#include "cros_board_info.h"
-#include "cros_cbi_ssfc.h"
-#include "cros_cbi_common.h"
-
-#define DT_DRV_COMPAT named_cbi_ssfc_value
-
-LOG_MODULE_REGISTER(cros_cbi_ssfc, LOG_LEVEL_ERR);
-
-void cros_cbi_ssfc_init(const struct device *dev)
-{
- struct cros_cbi_data *data = (struct cros_cbi_data *)(dev->data);
-
- if (cbi_get_ssfc(&data->cached_ssfc.raw_value) != EC_SUCCESS) {
- DT_INST_FOREACH_STATUS_OKAY_VARGS(CBI_SSFC_INIT_DEFAULT, data)
- }
-
- LOG_INF("Read CBI SSFC : 0x%08X\n", data->cached_ssfc.raw_value);
-}
-
-static int cros_cbi_ssfc_get_parent_field_value(union cbi_ssfc cached_ssfc,
- enum cbi_ssfc_value_id value_id,
- uint32_t *value)
-{
- switch (value_id) {
- DT_INST_FOREACH_STATUS_OKAY_VARGS(CBI_SSFC_PARENT_VALUE_CASE,
- cached_ssfc, value)
- default:
- LOG_ERR("CBI SSFC parent field value not found: %d\n",
- value_id);
- return -EINVAL;
- }
- return 0;
-}
-
-bool cros_cbi_ec_ssfc_check_match(const struct device *dev,
- enum cbi_ssfc_value_id value_id)
-{
- struct cros_cbi_data *data = (struct cros_cbi_data *)(dev->data);
- struct cros_cbi_config *cfg = (struct cros_cbi_config *)(dev->config);
- int rc;
- uint32_t value;
-
- rc = cros_cbi_ssfc_get_parent_field_value(data->cached_ssfc,
- value_id, &value);
- if (rc) {
- return false;
- }
- return value == cfg->ssfc_values[value_id];
-}
diff --git a/zephyr/projects/nissa/src/common.c b/zephyr/projects/nissa/src/common.c
index de19264c71..74c2b8dc9d 100644
--- a/zephyr/projects/nissa/src/common.c
+++ b/zephyr/projects/nissa/src/common.c
@@ -4,12 +4,12 @@
*/
#include <device.h>
-#include <drivers/cros_cbi.h>
#include "battery.h"
#include "charger.h"
#include "charge_state_v2.h"
#include "chipset.h"
+#include "cros_cbi.h"
#include "hooks.h"
#include "usb_mux.h"
#include "system.h"
@@ -99,7 +99,6 @@ enum nissa_sub_board_type nissa_get_sb_type(void)
static enum nissa_sub_board_type sb = NISSA_SB_UNKNOWN;
int ret;
uint32_t val;
- const struct device *dev;
/*
* Return cached value.
@@ -108,35 +107,30 @@ enum nissa_sub_board_type nissa_get_sb_type(void)
return sb;
sb = NISSA_SB_NONE; /* Defaults to none */
- dev = device_get_binding(CROS_CBI_LABEL);
- if (dev == NULL) {
- LOG_WRN("No %s device", CROS_CBI_LABEL);
- } else {
- ret = cros_cbi_get_fw_config(dev, FW_SUB_BOARD, &val);
- if (ret != 0) {
- LOG_WRN("Error retrieving CBI FW_CONFIG field %d",
- FW_SUB_BOARD);
- return sb;
- }
- switch (val) {
- default:
- LOG_WRN("No sub-board defined");
- break;
- case FW_SUB_BOARD_1:
- sb = NISSA_SB_C_A;
- LOG_INF("SB: USB type C, USB type A");
- break;
-
- case FW_SUB_BOARD_2:
- sb = NISSA_SB_C_LTE;
- LOG_INF("SB: USB type C, WWAN LTE");
- break;
-
- case FW_SUB_BOARD_3:
- sb = NISSA_SB_HDMI_A;
- LOG_INF("SB: HDMI, USB type A");
- break;
- }
+ ret = cros_cbi_get_fw_config(FW_SUB_BOARD, &val);
+ if (ret != 0) {
+ LOG_WRN("Error retrieving CBI FW_CONFIG field %d",
+ FW_SUB_BOARD);
+ return sb;
+ }
+ switch (val) {
+ default:
+ LOG_WRN("No sub-board defined");
+ break;
+ case FW_SUB_BOARD_1:
+ sb = NISSA_SB_C_A;
+ LOG_INF("SB: USB type C, USB type A");
+ break;
+
+ case FW_SUB_BOARD_2:
+ sb = NISSA_SB_C_LTE;
+ LOG_INF("SB: USB type C, WWAN LTE");
+ break;
+
+ case FW_SUB_BOARD_3:
+ sb = NISSA_SB_HDMI_A;
+ LOG_INF("SB: HDMI, USB type A");
+ break;
}
return sb;
}
diff --git a/zephyr/include/drivers/cros_cbi.h b/zephyr/shim/include/cros_cbi.h
index 906f2c5825..cde0649155 100644
--- a/zephyr/include/drivers/cros_cbi.h
+++ b/zephyr/shim/include/cros_cbi.h
@@ -3,13 +3,8 @@
* found in the LICENSE file.
*/
-/**
- * @file
- * @brief Chrome OS-specific API for access to Cros Board Info(CBI)
- */
-
-#ifndef ZEPHYR_INCLUDE_DRIVERS_CROS_CBI_H_
-#define ZEPHYR_INCLUDE_DRIVERS_CROS_CBI_H_
+#ifndef __CROS_EC_CROS_CBI_H
+#define __CROS_EC_CROS_CBI_H
#include <kernel.h>
#include <device.h>
@@ -85,79 +80,31 @@ enum cbi_fw_config_value_id {
};
/**
- * @cond INTERNAL_HIDDEN
+ * @brief Initialize CBI SSFC
*
- * cros cbi raw driver API definition and system call entry points
- *
- * (Internal use only.)
+ * The function has to be called before checking SSFC values.
*/
-typedef int (*cros_cbi_api_init)(const struct device *dev);
-typedef bool (*cros_cbi_api_ssfc_check_match)(const struct device *dev,
- enum cbi_ssfc_value_id value_id);
-typedef int (*cros_cbi_api_get_fw_config)(const struct device *dev,
- enum cbi_fw_config_field_id field_id,
- uint32_t *value);
-
-__subsystem struct cros_cbi_driver_api {
- cros_cbi_api_init init;
- cros_cbi_api_ssfc_check_match ssfc_check_match;
- cros_cbi_api_get_fw_config get_fw_config;
-};
+void cros_cbi_ssfc_init(void);
/**
- * @endcond
- */
-
-/**
- * @brief Initialize CBI.
- *
- * @param dev Pointer to the device structure for the CBI instance.
+ * @brief Initialize CBI FW
*
- * @return 0 If successful.
- * @retval -ENOTSUP Not supported api function.
+ * The function has to be called before getting CBI FW_CONFIG.
*/
-__syscall int cros_cbi_init(const struct device *dev);
-
-static inline int z_impl_cros_cbi_init(const struct device *dev)
-{
- const struct cros_cbi_driver_api *api =
- (const struct cros_cbi_driver_api *)dev->api;
-
- if (!api->init) {
- return -ENOTSUP;
- }
-
- return api->init(dev);
-}
+void cros_cbi_fw_config_init(void);
/**
* @brief Check if the CBI SSFC value matches the one in the EEPROM
*
- * @param dev Pointer to the device.
+ * @param value_id The SSFC value to check in EEPROM.
*
- * @return 1 If matches, 0 if not.
- * @retval -ENOTSUP Not supported api function.
+ * @return true If matches, false if not.
*/
-__syscall int cros_cbi_ssfc_check_match(const struct device *dev,
- enum cbi_ssfc_value_id value_id);
-
-static inline int
-z_impl_cros_cbi_ssfc_check_match(const struct device *dev,
- enum cbi_ssfc_value_id value_id)
-{
- const struct cros_cbi_driver_api *api =
- (const struct cros_cbi_driver_api *)dev->api;
-
- if (!api->ssfc_check_match)
- return -ENOTSUP;
-
- return api->ssfc_check_match(dev, value_id);
-}
+bool cros_cbi_ssfc_check_match(enum cbi_ssfc_value_id value_id);
/**
* @brief Retrieve the value of the FW_CONFIG field
*
- * @param dev Pointer to the device.
* @param field_id Enum identifying the field to return.
* @param value Pointer to the returned value.
*
@@ -165,26 +112,7 @@ z_impl_cros_cbi_ssfc_check_match(const struct device *dev,
* @retval -ENOTSUP Not supported api function.
* @retval -EINVAL Invalid field_id.
*/
-__syscall int cros_cbi_get_fw_config(const struct device *dev,
- enum cbi_fw_config_field_id field_id,
- uint32_t *value);
+int cros_cbi_get_fw_config(enum cbi_fw_config_field_id field_id,
+ uint32_t *value);
-static inline int
-z_impl_cros_cbi_get_fw_config(const struct device *dev,
- enum cbi_fw_config_field_id field_id,
- uint32_t *value)
-{
- const struct cros_cbi_driver_api *api =
- (const struct cros_cbi_driver_api *)dev->api;
-
- if (!api->get_fw_config)
- return -ENOTSUP;
-
- return api->get_fw_config(dev, field_id, value);
-}
-
-/**
- * @}
- */
-#include <syscalls/cros_cbi.h>
-#endif /* ZEPHYR_INCLUDE_DRIVERS_CROS_CBI_H_ */
+#endif /* __CROS_EC_CROS_CBI_H */
diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt
index 0dccfa1f8d..5674986605 100644
--- a/zephyr/shim/src/CMakeLists.txt
+++ b/zephyr/shim/src/CMakeLists.txt
@@ -9,6 +9,8 @@ zephyr_library_sources(gpio_id.c)
zephyr_library_sources(gpio_int.c)
zephyr_library_sources(power.c)
+add_subdirectory("cbi")
+
if (DEFINED CONFIG_ARCH_POSIX)
zephyr_library_sources(ztest_system.c)
else()
@@ -21,9 +23,6 @@ zephyr_library_sources_ifdef(no_libgcc libgcc_${ARCH}.S)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_ADC adc.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_BATTERY
battery.c)
-zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_EEPROM cbi.c)
-zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_EEPROM cbi_eeprom.c)
-zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_GPIO cbi.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_HOST_INTERFACE_ESPI
espi.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_FAN fan.c)
diff --git a/zephyr/shim/src/cbi.c b/zephyr/shim/src/cbi.c
deleted file mode 100644
index e9d85b6088..0000000000
--- a/zephyr/shim/src/cbi.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include <drivers/cros_cbi.h>
-#include <logging/log.h>
-#include "hooks.h"
-
-LOG_MODULE_REGISTER(shim_cbi, LOG_LEVEL_ERR);
-
-static void cbi_dev_init(void)
-{
- const struct device *dev = device_get_binding(CROS_CBI_LABEL);
-
- if (!dev)
- LOG_ERR("Fail to find %s", CROS_CBI_LABEL);
-
- cros_cbi_init(dev);
-}
-
-DECLARE_HOOK(HOOK_INIT, cbi_dev_init, HOOK_PRIO_FIRST);
diff --git a/zephyr/shim/src/cbi/CMakeLists.txt b/zephyr/shim/src/cbi/CMakeLists.txt
new file mode 100644
index 0000000000..4b14f0bb1d
--- /dev/null
+++ b/zephyr/shim/src/cbi/CMakeLists.txt
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: Apache-2.0
+
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_EEPROM cbi_eeprom.c
+ cros_cbi.c
+ cros_cbi_fw_config.c
+ cros_cbi_ssfc.c)
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_GPIO cros_cbi.c
+ cros_cbi_fw_config.c
+ cros_cbi_ssfc.c)
diff --git a/zephyr/shim/src/cbi_eeprom.c b/zephyr/shim/src/cbi/cbi_eeprom.c
index 5603b1c63a..5603b1c63a 100644
--- a/zephyr/shim/src/cbi_eeprom.c
+++ b/zephyr/shim/src/cbi/cbi_eeprom.c
diff --git a/zephyr/shim/src/cbi/cros_cbi.c b/zephyr/shim/src/cbi/cros_cbi.c
new file mode 100644
index 0000000000..7ae1fbc098
--- /dev/null
+++ b/zephyr/shim/src/cbi/cros_cbi.c
@@ -0,0 +1,17 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "cros_cbi.h"
+
+#include "cros_board_info.h"
+#include "hooks.h"
+
+static void cros_cbi_ec_init(void)
+{
+ cros_cbi_ssfc_init();
+ cros_cbi_fw_config_init();
+}
+
+DECLARE_HOOK(HOOK_INIT, cros_cbi_ec_init, HOOK_PRIO_FIRST);
diff --git a/zephyr/drivers/cros_cbi/cros_cbi_fw_config.c b/zephyr/shim/src/cbi/cros_cbi_fw_config.c
index c2e5c2a30a..b411f0ac7f 100644
--- a/zephyr/drivers/cros_cbi/cros_cbi_fw_config.c
+++ b/zephyr/shim/src/cbi/cros_cbi_fw_config.c
@@ -3,12 +3,10 @@
* found in the LICENSE file.
*/
-#include <drivers/cros_cbi.h>
#include <logging/log.h>
#include "cros_board_info.h"
-#include "cros_cbi_ssfc.h"
-#include "cros_cbi_common.h"
+#include "cros_cbi.h"
LOG_MODULE_REGISTER(cros_cbi_fw_config, LOG_LEVEL_ERR);
@@ -109,12 +107,12 @@ DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_VALUE_COMPAT, FW_VALUE_BUILD_ASSERT)
/*
* Macro to initialise the fields to default value (if specified)
*/
-#define CBI_FW_CONFIG_INIT_DEFAULT(id, data) \
- do { \
- if (DT_PROP(id, default)) { \
- data->cached_fw_config |= \
- DT_PROP(id, value) << FW_PARENT_START(id); \
- } \
+#define CBI_FW_CONFIG_INIT_DEFAULT(id, fw_config) \
+ do { \
+ if (DT_PROP(id, default)) { \
+ fw_config |= DT_PROP(id, value) \
+ << FW_PARENT_START(id); \
+ } \
} while (0);
/*
* Define bit fields based on the device tree entries. Example:
@@ -157,22 +155,22 @@ DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_VALUE_COMPAT, FW_VALUE_BUILD_ASSERT)
#define FW_FIELD_NODES(inst, cached, value) \
DT_FOREACH_CHILD_STATUS_OKAY_VARGS(inst, FW_FIELD_CASE, cached, value)
-void cros_cbi_fw_config_init(const struct device *dev)
-{
- struct cros_cbi_data *data = (struct cros_cbi_data *)(dev->data);
+uint32_t cached_fw_config;
- if (cbi_get_fw_config(&data->cached_fw_config) != EC_SUCCESS) {
+void cros_cbi_fw_config_init(void)
+{
+ if (cbi_get_fw_config(&cached_fw_config) != EC_SUCCESS) {
/*
* Missing fw config will set the default or 0 for
* every field.
*/
- data->cached_fw_config = 0;
+ cached_fw_config = 0;
DT_FOREACH_STATUS_OKAY_VARGS(CBI_FW_CONFIG_VALUE_COMPAT,
- CBI_FW_CONFIG_INIT_DEFAULT,
- data)
+ CBI_FW_CONFIG_INIT_DEFAULT,
+ cached_fw_config)
}
- LOG_INF("Read CBI FW Config : 0x%08X\n", data->cached_fw_config);
+ LOG_INF("Read CBI FW Config : 0x%08X\n", cached_fw_config);
}
static int cros_cbi_fw_config_get_field(
@@ -195,15 +193,12 @@ static int cros_cbi_fw_config_get_field(
return 0;
}
-int cros_cbi_ec_get_fw_config(const struct device *dev,
- enum cbi_fw_config_field_id field_id,
- uint32_t *value)
+int cros_cbi_get_fw_config(enum cbi_fw_config_field_id field_id,
+ uint32_t *value)
{
- struct cros_cbi_data *data = (struct cros_cbi_data *)(dev->data);
int rc;
- rc = cros_cbi_fw_config_get_field(data->cached_fw_config,
- field_id, value);
+ rc = cros_cbi_fw_config_get_field(cached_fw_config, field_id, value);
if (rc)
LOG_ERR("CBI FW Config field not found: %d\n", field_id);
return rc;
diff --git a/zephyr/drivers/cros_cbi/cros_cbi_ssfc.h b/zephyr/shim/src/cbi/cros_cbi_ssfc.c
index 3ee3a7eeb6..2a4e591eb5 100644
--- a/zephyr/drivers/cros_cbi/cros_cbi_ssfc.h
+++ b/zephyr/shim/src/cbi/cros_cbi_ssfc.c
@@ -3,13 +3,14 @@
* found in the LICENSE file.
*/
-#ifndef __CROS_CBI_CROS_CBI_SSFC_H
-#define __CROS_CBI_CROS_CBI_SSFC_H
+#include <logging/log.h>
-/* CBI SSFC part */
+#include "cros_board_info.h"
+#include "cros_cbi.h"
-/* This part of the driver is about CBI SSFC part.
- * Actually, two "compatible" values are handle here -
+LOG_MODULE_REGISTER(cros_cbi_ssfc, LOG_LEVEL_ERR);
+
+/* Actually, two "compatible" values are handle here -
* named_cbi_ssfc_value and named_cbi_ssfc. named_cbi_ssfc_value nodes are
* grandchildren of the named_cbi_ssfc node. named_cbi_ssfc_value is introduced
* to iterate over grandchildren of the named_cbi_ssfc(macro
@@ -22,16 +23,16 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(named_cbi_ssfc) < 2,
"More than 1 CBI SSFS node");
#define CBI_SSFC_NODE DT_INST(0, named_cbi_ssfc)
-#define CBI_SSFC_INIT_DEFAULT_ID(id, data) \
- do { \
- if (DT_PROP(id, default)) { \
- data->cached_ssfc.CBI_SSFC_UNION_ENTRY_NAME( \
- DT_PARENT(id)) = DT_PROP(id, value); \
- } \
+#define CBI_SSFC_INIT_DEFAULT_ID(id, ssfc) \
+ do { \
+ if (DT_PROP(id, default)) { \
+ ssfc.CBI_SSFC_UNION_ENTRY_NAME(DT_PARENT(id)) = \
+ DT_PROP(id, value); \
+ } \
} while (0);
-#define CBI_SSFC_INIT_DEFAULT(inst, data) \
- CBI_SSFC_INIT_DEFAULT_ID(DT_DRV_INST(inst), data)
+#define CBI_SSFC_INIT_DEFAULT(inst, ssfc) \
+ CBI_SSFC_INIT_DEFAULT_ID(DT_DRV_INST(inst), ssfc)
#define CBI_SSFC_VALUE_ARRAY_ID(id) \
[CBI_SSFC_VALUE_ID(id)] = DT_PROP(id, value),
@@ -128,6 +129,46 @@ BUILD_ASSERT(sizeof(union cbi_ssfc) == sizeof(uint32_t),
DT_INST_FOREACH_STATUS_OKAY(CBI_SSFC_VALUE_BUILD_ASSERT)
-#undef DT_DRV_COMPAT
+static const uint8_t ssfc_values[] = {
+ DT_INST_FOREACH_STATUS_OKAY(CBI_SSFC_VALUE_ARRAY)
+};
-#endif /* __CROS_CBI_CROS_CBI_SSFC_H */
+static union cbi_ssfc cached_ssfc;
+
+void cros_cbi_ssfc_init(void)
+{
+ if (cbi_get_ssfc(&cached_ssfc.raw_value) != EC_SUCCESS) {
+ DT_INST_FOREACH_STATUS_OKAY_VARGS(CBI_SSFC_INIT_DEFAULT,
+ cached_ssfc)
+ }
+
+ LOG_INF("Read CBI SSFC : 0x%08X\n", cached_ssfc.raw_value);
+}
+
+static int cros_cbi_ssfc_get_parent_field_value(union cbi_ssfc cached_ssfc,
+ enum cbi_ssfc_value_id value_id,
+ uint32_t *value)
+{
+ switch (value_id) {
+ DT_INST_FOREACH_STATUS_OKAY_VARGS(CBI_SSFC_PARENT_VALUE_CASE,
+ cached_ssfc, value)
+ default:
+ LOG_ERR("CBI SSFC parent field value not found: %d\n",
+ value_id);
+ return -EINVAL;
+ }
+ return 0;
+}
+
+bool cros_cbi_ssfc_check_match(enum cbi_ssfc_value_id value_id)
+{
+ int rc;
+ uint32_t value;
+
+ rc = cros_cbi_ssfc_get_parent_field_value(cached_ssfc, value_id,
+ &value);
+ if (rc) {
+ return false;
+ }
+ return value == ssfc_values[value_id];
+}
diff --git a/zephyr/shim/src/motionsense_sensors.c b/zephyr/shim/src/motionsense_sensors.c
index 8cfd9a3315..9ec8e06472 100644
--- a/zephyr/shim/src/motionsense_sensors.c
+++ b/zephyr/shim/src/motionsense_sensors.c
@@ -6,9 +6,9 @@
#include <logging/log.h>
#include "common.h"
#include "accelgyro.h"
+#include "cros_cbi.h"
#include "hooks.h"
#include "gpio/gpio_int.h"
-#include "drivers/cros_cbi.h"
#include "motionsense_sensors.h"
LOG_MODULE_REGISTER(shim_cros_motionsense_sensors);
diff --git a/zephyr/test/drivers/src/cros_cbi.c b/zephyr/test/drivers/src/cros_cbi.c
index 02df5fec7b..37094e1a49 100644
--- a/zephyr/test/drivers/src/cros_cbi.c
+++ b/zephyr/test/drivers/src/cros_cbi.c
@@ -6,55 +6,46 @@
#include <device.h>
#include <ztest.h>
-#include "drivers/cros_cbi.h"
+#include "cros_cbi.h"
#include "test_state.h"
ZTEST(cros_cbi, test_check_match)
{
- const struct device *dev = device_get_binding(CROS_CBI_LABEL);
int value;
- zassert_not_null(dev, NULL);
-
value = cros_cbi_ssfc_check_match(
- dev, CBI_SSFC_VALUE_ID(DT_NODELABEL(base_sensor_0)));
+ CBI_SSFC_VALUE_ID(DT_NODELABEL(base_sensor_0)));
zassert_true(value, "Expected cbi ssfc to match base_sensor_0");
value = cros_cbi_ssfc_check_match(
- dev, CBI_SSFC_VALUE_ID(DT_NODELABEL(base_sensor_1)));
+ CBI_SSFC_VALUE_ID(DT_NODELABEL(base_sensor_1)));
zassert_false(value, "Expected cbi ssfc not to match base_sensor_1");
- value = cros_cbi_ssfc_check_match(dev, CBI_SSFC_VALUE_COUNT);
+ value = cros_cbi_ssfc_check_match(CBI_SSFC_VALUE_COUNT);
zassert_false(value, "Expected cbi ssfc to fail on invalid enum");
}
ZTEST(cros_cbi, test_fail_check_match)
{
- const struct device *dev = device_get_binding(CROS_CBI_LABEL);
int value;
- zassert_not_null(dev, NULL);
-
- value = cros_cbi_ssfc_check_match(dev, CBI_SSFC_VALUE_COUNT);
+ value = cros_cbi_ssfc_check_match(CBI_SSFC_VALUE_COUNT);
zassert_false(value,
"Expected cbi ssfc to never match CBI_SSFC_VALUE_COUNT");
}
ZTEST(cros_cbi, test_fw_config)
{
- const struct device *dev = device_get_binding(CROS_CBI_LABEL);
uint32_t value;
int ret;
- zassert_not_null(dev, NULL);
-
- ret = cros_cbi_get_fw_config(dev, FW_CONFIG_FIELD_1, &value);
+ ret = cros_cbi_get_fw_config(FW_CONFIG_FIELD_1, &value);
zassert_true(ret == 0,
"Expected no error return from cros_cbi_get_fw_config");
zassert_true(value == FW_FIELD_1_B,
"Expected field value to match FW_FIELD_1_B as default");
- ret = cros_cbi_get_fw_config(dev, FW_CONFIG_FIELD_2, &value);
+ ret = cros_cbi_get_fw_config(FW_CONFIG_FIELD_2, &value);
zassert_true(ret == 0,
"Expected no error return from cros_cbi_get_fw_config");
zassert_false(value == FW_FIELD_2_X,