summaryrefslogtreecommitdiff
path: root/zephyr/program/nissa/uldren/src/form_factor.c
diff options
context:
space:
mode:
authormick_hsiao <mick_hsiao@compal.corp-partner.google.com>2023-03-15 19:43:56 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-22 02:28:30 +0000
commite2716061d0044831df63944261d2b26e100a307e (patch)
tree62f0c565325b699aea7a30343cb424d4d6355c32 /zephyr/program/nissa/uldren/src/form_factor.c
parent43c707e5def93a9ee6b03cf62e6ce2d6cfe6f099 (diff)
downloadchrome-ec-e2716061d0044831df63944261d2b26e100a307e.tar.gz
uldren: Initial Zephyr EC image
Create the initial Zephyr EC image for the uldren variant based on the nereid reference board. (Auto-Generated by create_zephyr_ec_image.sh version 1.0.0) BUG=b:271513530 BRANCH=None TEST=PASS Change-Id: I46de308cbed951f6637079dff7696ffe9806b6d7 Signed-off-by: mick_hsiao <mick_hsiao@compal.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4340169 Reviewed-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com> Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Diffstat (limited to 'zephyr/program/nissa/uldren/src/form_factor.c')
-rw-r--r--zephyr/program/nissa/uldren/src/form_factor.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/zephyr/program/nissa/uldren/src/form_factor.c b/zephyr/program/nissa/uldren/src/form_factor.c
new file mode 100644
index 0000000000..72c0ba04d3
--- /dev/null
+++ b/zephyr/program/nissa/uldren/src/form_factor.c
@@ -0,0 +1,45 @@
+/* Copyright 2023 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "accelgyro.h"
+#include "cros_cbi.h"
+#include "hooks.h"
+#include "motionsense_sensors.h"
+
+#include <zephyr/devicetree.h>
+#include <zephyr/logging/log.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))
+#define BASE_GYRO SENSOR_ID(DT_NODELABEL(base_gyro))
+
+static void form_factor_init(void)
+{
+ 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;
+ }
+ if (val == FW_BASE_INVERTED) {
+ LOG_INF("Switching to inverted base");
+ motion_sensors[BASE_SENSOR].rot_standard_ref = &ALT_MAT;
+ motion_sensors[BASE_GYRO].rot_standard_ref = &ALT_MAT;
+ }
+}
+DECLARE_HOOK(HOOK_INIT, form_factor_init, HOOK_PRIO_POST_I2C);