summaryrefslogtreecommitdiff
path: root/driver/sensorhub_lsm6dsm.h
diff options
context:
space:
mode:
authorKarthikeyan Ramasubramanian <kramasub@chromium.org>2018-10-01 14:21:51 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-10-19 15:07:40 -0700
commit58f4737ae117f0bd5e2a3a7ea35ef26791bdd146 (patch)
treeb96c8302a4c966c202fbc569f9ceb94472f718d4 /driver/sensorhub_lsm6dsm.h
parent88a0c56c873cd32fb69923fc5b5eba31c529c433 (diff)
downloadchrome-ec-58f4737ae117f0bd5e2a3a7ea35ef26791bdd146.tar.gz
driver/sensorhub_lsm6dsm: Add sensor hub support in LSM6DSM module
Add support for sensor hub in LSM6DSM accelerometer module so that external sensors module like magnetometer can be supported. BRANCH=none BUG=b:115587004 TEST=Collect magnetometer readings using ectool motionsense Change-Id: Id0fd4eea56b7106a89d55925ae488af6b0300119 Signed-off-by: Karthikeyan Ramasubramanian <kramasub@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1257503 Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'driver/sensorhub_lsm6dsm.h')
-rw-r--r--driver/sensorhub_lsm6dsm.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/driver/sensorhub_lsm6dsm.h b/driver/sensorhub_lsm6dsm.h
new file mode 100644
index 0000000000..6bb318e281
--- /dev/null
+++ b/driver/sensorhub_lsm6dsm.h
@@ -0,0 +1,83 @@
+/* Copyright 2018 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.
+ */
+
+/*
+ * LSM6DSM Sensor Hub driver to enable interfacing with external sensors
+ * like magnetometer for Chrome EC
+ */
+
+#ifndef __CROS_EC_SENSORHUB_LSM6DSM_H
+#define __CROS_EC_SENSORHUB_LSM6DSM_H
+
+#include "common.h"
+#include "motion_sense.h"
+
+/**
+ * Set the output data rate of the external sensor that is attached
+ * to the sensor hub to the requested rate.
+ *
+ * @param s Pointer to external motion sensor's data structure.
+ * @param rate Preferred output data rate from the sensor.
+ * @param rnd Flag to indicate rounding to the nearest supported
+ * output data rate by the sensor.
+ * @param ret_rate Rate configured by the sensor hub depending on the
+ * accelerometer data rate.
+ * @return EC_SUCCESS on success, EC error codes on failure.
+ */
+int sensorhub_set_ext_data_rate(const struct motion_sensor_t *s,
+ int rate, int rnd, int *ret_rate);
+
+/**
+ * Configure the register of an external sensor that is attached to sensor
+ * hub with a specific value.
+ *
+ * @param s Pointer to external motion sensor's data structure.
+ * @param slv_addr I2C Slave Address of the external sensor.
+ * @param reg Register Address to write within the external sensor.
+ * @param val Value to be written into the external sensor register.
+ * @return EC_SUCCESS on success, EC error codes on failure.
+ */
+int sensorhub_config_ext_reg(const struct motion_sensor_t *s,
+ uint8_t slv_addr, uint8_t reg, uint8_t val);
+
+/**
+ * Configure the sensor hub to read data from a specific register of an
+ * external sensor that is attached to it.
+ *
+ * @param s Pointer to external motion sensor's data structure.
+ * @param slv_addr I2C Slave Address of the external sensor.
+ * @param reg Register Address to read from the external sensor.
+ * @param len Length of data to be read.
+ * @return EC_SUCCESS on success, EC error codes on failure.
+ */
+int sensorhub_config_slv0_read(const struct motion_sensor_t *s,
+ uint8_t slv_addr, uint8_t reg, int len);
+
+/**
+ * Reads the data from the register bank that is associated with the slave0
+ * of the sensor hub.
+ *
+ * @param s Pointer to external motion sensor's data structure.
+ * @param v Vector to hold the data from the external sensor.
+ * @return EC_SUCCESS on success, EC error codes on failure.
+ */
+int sensorhub_slv0_data_read(const struct motion_sensor_t *s, intv3_t v);
+
+/**
+ * Check the identity of the external sensor and then reset the external
+ * sensor that is attached to the sensor hub.
+ *
+ * @param s Pointer to external motion sensor's data structure.
+ * @param slv_addr I2C Slave Address of the external sensor.
+ * @param whoami_reg Register address to identify the sensor.
+ * @param whoami_val Expected value to be read from the whoami_reg.
+ * @param rst_reg Register address to reset the external sensor.
+ * @param rst_val Value to be written to the reset register.
+ * @return EC_SUCCESS on success, EC error codes on failure.
+ */
+int sensorhub_check_and_rst(const struct motion_sensor_t *s, uint8_t slv_addr,
+ uint8_t whoami_reg, uint8_t whoami_val,
+ uint8_t rst_reg, uint8_t rst_val);
+#endif /* __CROS_EC_SENSORHUB_LSM6DSM_H */