diff options
-rw-r--r-- | zephyr/projects/nissa/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/projects/nissa/nivviks_motionsense.dts | 10 | ||||
-rw-r--r-- | zephyr/projects/nissa/src/nivviks/form_factor.c | 48 | ||||
-rw-r--r-- | zephyr/shim/include/motionsense_sensors.h | 18 | ||||
-rw-r--r-- | zephyr/shim/src/motionsense_sensors.c | 4 |
5 files changed, 78 insertions, 3 deletions
diff --git a/zephyr/projects/nissa/CMakeLists.txt b/zephyr/projects/nissa/CMakeLists.txt index b22422d4ef..715fd3680d 100644 --- a/zephyr/projects/nissa/CMakeLists.txt +++ b/zephyr/projects/nissa/CMakeLists.txt @@ -14,6 +14,7 @@ zephyr_library_sources_ifdef(CONFIG_AP_PWRSEQ "src/board_power.c") if(DEFINED CONFIG_BOARD_NIVVIKS) project(nivviks) + zephyr_library_sources("src/nivviks/form_factor.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "src/nivviks/usbc.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CHARGER "src/nivviks/charger.c") endif() diff --git a/zephyr/projects/nissa/nivviks_motionsense.dts b/zephyr/projects/nissa/nivviks_motionsense.dts index ac5d4c390c..f14cadcb3d 100644 --- a/zephyr/projects/nissa/nivviks_motionsense.dts +++ b/zephyr/projects/nissa/nivviks_motionsense.dts @@ -42,6 +42,12 @@ 0 0 (-1)>; }; + base_rot_inverted: base-rot-inverted { + mat33 = <(-1) 0 0 + 0 1 0 + 0 0 (-1)>; + }; + base_rot_ref: base-rotation-ref { mat33 = <1 0 0 0 (-1) 0 @@ -85,6 +91,10 @@ location = "MOTIONSENSE_LOC_BASE"; mutex = <&base_mutex>; port = <&i2c_ec_i2c_sensor>; + /* + * May be replaced by alternate depending + * on board config. + */ rot-standard-ref = <&base_rot_ref>; drv-data = <&lsm6dso_data>; configs { diff --git a/zephyr/projects/nissa/src/nivviks/form_factor.c b/zephyr/projects/nissa/src/nivviks/form_factor.c new file mode 100644 index 0000000000..99ac7f65b8 --- /dev/null +++ b/zephyr/projects/nissa/src/nivviks/form_factor.c @@ -0,0 +1,48 @@ +/* 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 <devicetree.h> +#include <init.h> +#include <logging/log.h> + +#include "accelgyro.h" +#include "cros_cbi.h" +#include "hooks.h" +#include "motionsense_sensors.h" + +#include "nissa_common.h" + +LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL); + +/* + * Mainboard orientation support. + */ + +#define ALT_MAT SENSOR_ROT_STD_REF_NAME(DT_NODELABEL(base_rot_inverted)) +#define BASE_SENSOR SENSOR_ID(DT_NODELABEL(base_accel)) + +static int form_factor_init(const struct device *unused) +{ + int ret; + uint32_t val; + /* + * If the firmware config indicates + * an inverted form factor, use the alternative + * rotation matrix. + */ + ret = cros_cbi_get_fw_config(FW_BASE_INVERSION, &val); + if (ret != 0) { + LOG_ERR("Error retrieving CBI FW_CONFIG field %d", + FW_BASE_INVERSION); + return 0; + } + if (val == FW_BASE_INVERTED) { + LOG_INF("Switching to inverted base"); + motion_sensors[BASE_SENSOR].rot_standard_ref = &ALT_MAT; + } + return 0; +} + +SYS_INIT(form_factor_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/zephyr/shim/include/motionsense_sensors.h b/zephyr/shim/include/motionsense_sensors.h index e4ecf5d6de..0add50914a 100644 --- a/zephyr/shim/include/motionsense_sensors.h +++ b/zephyr/shim/include/motionsense_sensors.h @@ -12,6 +12,24 @@ extern struct motion_sensor_t motion_sensors_alt[]; /* + * Common macros. + */ +#define SENSOR_ROT_STD_REF_NAME(id) DT_CAT(ROT_REF_, id) +#define SENSOR_ROT_REF_NODE DT_PATH(motionsense_rotation_ref) + +/* + * Declare rotation parameters, since they may be + * dynamically selected. + */ +#define DECLARE_EXTERN_SENSOR_ROT_REF(id) \ + extern const mat33_fp_t SENSOR_ROT_STD_REF_NAME(id); + +#if DT_NODE_EXISTS(SENSOR_ROT_REF_NODE) +DT_FOREACH_CHILD(SENSOR_ROT_REF_NODE, DECLARE_EXTERN_SENSOR_ROT_REF) +#endif +#undef DECLARE_EXTERN_SENSOR_ROT_REF + +/* * Performs probing of an alternate sensor. * @param alt_idx Index in motion_sensors_alt of the sensor to be probed. * It should be gained with SENSOR_ID, diff --git a/zephyr/shim/src/motionsense_sensors.c b/zephyr/shim/src/motionsense_sensors.c index 0cc55339df..c720e8434e 100644 --- a/zephyr/shim/src/motionsense_sensors.c +++ b/zephyr/shim/src/motionsense_sensors.c @@ -28,11 +28,9 @@ LOG_MODULE_REGISTER(shim_cros_motionsense_sensors); DT_FOREACH_CHILD(SENSOR_MUTEX_NODE, DECLARE_SENSOR_MUTEX) #endif /* DT_NODE_EXISTS(SENSOR_MUTEX_NODE) */ -#define SENSOR_ROT_REF_NODE DT_PATH(motionsense_rotation_ref) -#define SENSOR_ROT_STD_REF_NAME(id) DT_CAT(ROT_REF_, id) #define MAT_ITEM(i, id) FLOAT_TO_FP((int32_t)(DT_PROP_BY_IDX(id, mat33, i))) #define DECLARE_SENSOR_ROT_REF(id) \ - static const mat33_fp_t SENSOR_ROT_STD_REF_NAME(id) = { \ + const mat33_fp_t SENSOR_ROT_STD_REF_NAME(id) = { \ { \ FOR_EACH_FIXED_ARG(MAT_ITEM, (,), id, 0, 1, 2) \ }, \ |