summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/build.mk3
-rw-r--r--common/motion_sense.c21
-rw-r--r--common/sensor_common.c25
-rw-r--r--driver/accel_bma2x2.c8
-rw-r--r--driver/accel_kionix.c9
-rw-r--r--driver/accel_lis2dh.c15
-rw-r--r--driver/accel_lis2dh.h2
-rw-r--r--driver/accelgyro_bmi160.c4
-rw-r--r--driver/accelgyro_lsm6ds0.c19
-rw-r--r--driver/accelgyro_lsm6dsm.c5
-rw-r--r--driver/als_si114x.c5
-rw-r--r--driver/baro_bmp280.c7
-rw-r--r--driver/gyro_l3gd20h.c18
-rw-r--r--include/motion_sense.h8
14 files changed, 51 insertions, 98 deletions
diff --git a/common/build.mk b/common/build.mk
index a792bca3ad..57eb0c9d82 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -124,7 +124,7 @@ common-$(HAS_TASK_HOSTCMD)+=host_command.o ec_features.o
common-$(HAS_TASK_PDCMD)+=host_command_pd.o
common-$(HAS_TASK_KEYSCAN)+=keyboard_scan.o
common-$(HAS_TASK_LIGHTBAR)+=lb_common.o lightbar.o
-common-$(HAS_TASK_MOTIONSENSE)+=motion_sense.o sensor_common.o
+common-$(HAS_TASK_MOTIONSENSE)+=motion_sense.o
common-$(HAS_TASK_TPM)+=tpm_registers.o
ifeq ($(CONFIG_MALLOC),y)
@@ -138,7 +138,6 @@ common-$(TEST_BUILD)+=test_util.o
else
common-y+=test_util.o
endif
-common-$(TEST_BUILD)+=sensor_common.o
ifneq ($(CONFIG_RSA_OPTIMIZED),)
$(out)/RW/common/rsa.o: CFLAGS+=-O3
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 77ddd29e3c..4e3711842b 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -442,6 +442,27 @@ static inline int motion_sense_init(struct motion_sensor_t *sensor)
}
/*
+ * sensor_init_done
+ *
+ * Called by init routine of each sensors when successful.
+ */
+int sensor_init_done(const struct motion_sensor_t *s)
+{
+ int ret;
+
+ ret = s->drv->set_range(s, s->default_range, 0);
+ if (ret == EC_RES_SUCCESS) {
+#ifdef CONFIG_CONSOLE_VERBOSE
+ CPRINTS("%s: MS Done Init type:0x%X range:%d",
+ s->name, s->type, s->drv->get_range(s));
+#else
+ CPRINTS("%c%d InitDone r:%d", s->name[0], s->type,
+ s->drv->get_range(s));
+#endif
+ }
+ return ret;
+}
+/*
* motion_sense_switch_sensor_rate
*
* Suspend all sensors that are not needed.
diff --git a/common/sensor_common.c b/common/sensor_common.c
deleted file mode 100644
index b80fd69366..0000000000
--- a/common/sensor_common.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Copyright 2017 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.
- */
-
-/* Sensor common routines. */
-
-#include "common.h"
-#include "console.h"
-#include "motion_sense.h"
-
-/* Console output macros */
-#define CPUTS(outstr) cputs(CC_MOTION_SENSE, outstr)
-#define CPRINTS(format, args...) cprints(CC_MOTION_SENSE, format, ## args)
-#define CPRINTF(format, args...) cprintf(CC_MOTION_SENSE, format, ## args)
-
-void sensor_init_done(const struct motion_sensor_t *s, int range)
-{
-#ifdef CONFIG_CONSOLE_VERBOSE
- CPRINTS("%s: MS Done Init type:0x%X range:%d",
- s->name, s->type, range);
-#else
- CPRINTS("%c%d InitDone r:%d", s->name[0], s->type, range);
-#endif
-}
diff --git a/driver/accel_bma2x2.c b/driver/accel_bma2x2.c
index 8cb90a1ca2..b48ad864ff 100644
--- a/driver/accel_bma2x2.c
+++ b/driver/accel_bma2x2.c
@@ -311,17 +311,11 @@ static int init(const struct motion_sensor_t *s)
mutex_unlock(s->mutex);
/* Initialize with the desired parameters. */
- ret = set_range(s, s->default_range, 1);
- if (ret != EC_SUCCESS)
- return ret;
-
ret = set_resolution(s, 12, 1);
if (ret != EC_SUCCESS)
return ret;
- sensor_init_done(s, get_range(s));
-
- return ret;
+ return sensor_init_done(s);
}
const struct accelgyro_drv bma2x2_accel_drv = {
diff --git a/driver/accel_kionix.c b/driver/accel_kionix.c
index 8697a17d66..062a3896fd 100644
--- a/driver/accel_kionix.c
+++ b/driver/accel_kionix.c
@@ -575,10 +575,6 @@ static int init(const struct motion_sensor_t *s)
mutex_unlock(s->mutex);
/* Initialize with the desired parameters. */
- ret = set_range(s, s->default_range, 1);
- if (ret != EC_SUCCESS)
- return ret;
-
if (V(s))
ret = set_resolution(s, 12, 1);
else
@@ -586,10 +582,7 @@ static int init(const struct motion_sensor_t *s)
if (ret != EC_SUCCESS)
return ret;
- sensor_init_done(s, get_range(s));
-
- mutex_unlock(s->mutex);
- return ret;
+ return sensor_init_done(s);
}
const struct accelgyro_drv kionix_accel_drv = {
diff --git a/driver/accel_lis2dh.c b/driver/accel_lis2dh.c
index eadc66cf71..18a0ade444 100644
--- a/driver/accel_lis2dh.c
+++ b/driver/accel_lis2dh.c
@@ -16,6 +16,7 @@
#include "task.h"
#include "util.h"
#include "driver/accel_lis2dh.h"
+#include "driver/stm_mems_common.h"
#ifdef CONFIG_ACCEL_FIFO
/**
@@ -324,7 +325,7 @@ static int init(const struct motion_sensor_t *s)
ret = raw_read8(s->port, s->addr, LIS2DH_WHO_AM_I_REG, &tmp);
if (ret != EC_SUCCESS)
- return EC_ERROR_UNKNOWN;
+ return ret;
if (tmp != LIS2DH_WHO_AM_I)
return EC_ERROR_ACCESS_DENIED;
@@ -367,26 +368,22 @@ static int init(const struct motion_sensor_t *s)
mutex_unlock(s->mutex);
- /* Config initial Acc Range */
- ret = set_range(s, s->default_range, 0);
- if (ret != EC_SUCCESS)
- return ret;
-
/* Set default resolution */
data->resol = LIS2DH_RESOLUTION;
#ifdef CONFIG_ACCEL_INTERRUPTS
ret = config_interrupt(s);
+ if (ret != EC_SUCCESS)
+ return ret;
#endif
- sensor_init_done(s, get_range(s));
- return ret;
+ return sensor_init_done(s);
err_unlock:
CPRINTF("[%T %s: MS Init type:0x%X Error]\n", s->name, s->type);
mutex_unlock(s->mutex);
- return EC_ERROR_UNKNOWN;
+ return ret;
}
const struct accelgyro_drv lis2dh_drv = {
diff --git a/driver/accel_lis2dh.h b/driver/accel_lis2dh.h
index 9872ccabe4..3b87ffff8b 100644
--- a/driver/accel_lis2dh.h
+++ b/driver/accel_lis2dh.h
@@ -8,8 +8,6 @@
#ifndef __CROS_EC_ACCEL_LIS2DH_H
#define __CROS_EC_ACCEL_LIS2DH_H
-#include "driver/stm_mems_common.h"
-
#define LIS2DH_I2C_ADDR(__x) (__x << 1)
/* 7-bit address is 000110Xb. Where 'X' is determined
diff --git a/driver/accelgyro_bmi160.c b/driver/accelgyro_bmi160.c
index dcba2ae17f..8d2c93f686 100644
--- a/driver/accelgyro_bmi160.c
+++ b/driver/accelgyro_bmi160.c
@@ -1269,7 +1269,6 @@ static int init(const struct motion_sensor_t *s)
* so set data rate to 0.
*/
data->odr = 0;
- set_range(s, s->default_range, 0);
if (s->type == MOTIONSENSE_TYPE_ACCEL) {
#ifdef CONFIG_ACCEL_INTERRUPTS
@@ -1277,8 +1276,7 @@ static int init(const struct motion_sensor_t *s)
#endif
}
- sensor_init_done(s, get_range(s));
- return ret;
+ return sensor_init_done(s);
}
const struct accelgyro_drv bmi160_drv = {
diff --git a/driver/accelgyro_lsm6ds0.c b/driver/accelgyro_lsm6ds0.c
index 9f98b5b417..67f3fffd85 100644
--- a/driver/accelgyro_lsm6ds0.c
+++ b/driver/accelgyro_lsm6ds0.c
@@ -411,28 +411,15 @@ static int init(const struct motion_sensor_t *s)
mutex_unlock(s->mutex);
if (ret)
- return EC_ERROR_UNKNOWN;
+ return ret;
/* Power Down Gyro */
ret = raw_write8(s->port, s->addr,
LSM6DS0_CTRL_REG1_G, 0x0);
if (ret)
- return EC_ERROR_UNKNOWN;
-
- ret = set_range(s, s->default_range, 1);
- if (ret)
- return EC_ERROR_UNKNOWN;
- }
-
- if (MOTIONSENSE_TYPE_GYRO == s->type) {
- /* Config GYRO Range */
- ret = set_range(s, s->default_range, 1);
- if (ret)
- return EC_ERROR_UNKNOWN;
+ return ret;
}
-
- sensor_init_done(s, get_range(s));
- return ret;
+ return sensor_init_done(s);
}
const struct accelgyro_drv lsm6ds0_drv = {
diff --git a/driver/accelgyro_lsm6dsm.c b/driver/accelgyro_lsm6dsm.c
index 9550159c73..d4466d5482 100644
--- a/driver/accelgyro_lsm6dsm.c
+++ b/driver/accelgyro_lsm6dsm.c
@@ -325,10 +325,7 @@ static int init(const struct motion_sensor_t *s)
mutex_unlock(s->mutex);
}
- ret = set_range(s, s->default_range, 1);
-
- sensor_init_done(s, get_range(s));
- return ret;
+ return sensor_init_done(s);
err_unlock:
mutex_unlock(s->mutex);
diff --git a/driver/als_si114x.c b/driver/als_si114x.c
index dd01fc1a55..3b4cf39daa 100644
--- a/driver/als_si114x.c
+++ b/driver/als_si114x.c
@@ -557,16 +557,13 @@ static int init(const struct motion_sensor_t *s)
resol = 5;
}
- set_range(s, s->default_range, 0);
/*
* Sensor is most likely behind a glass.
* Max out the gain to get correct measurement
*/
set_resolution(s, resol, 0);
- sensor_init_done(s, get_range(s));
-
- return EC_SUCCESS;
+ return sensor_init_done(s);
}
const struct accelgyro_drv si114x_drv = {
diff --git a/driver/baro_bmp280.c b/driver/baro_bmp280.c
index 2e939ceac3..3ca0084704 100644
--- a/driver/baro_bmp280.c
+++ b/driver/baro_bmp280.c
@@ -322,9 +322,12 @@ static int bmp280_init(const struct motion_sensor_t *s)
if (ret)
return ret;
- bmp280_set_range(s, s->default_range, 0);
/* Read bmp280 calibration parameter */
- return bmp280_get_calib_param(s);
+ ret = bmp280_get_calib_param(s);
+ if (ret)
+ return ret;
+
+ return sensor_init_done(s);
}
static int bmp280_read(const struct motion_sensor_t *s, vector_3_t v)
diff --git a/driver/gyro_l3gd20h.c b/driver/gyro_l3gd20h.c
index adcf347f90..53ee98961f 100644
--- a/driver/gyro_l3gd20h.c
+++ b/driver/gyro_l3gd20h.c
@@ -373,7 +373,7 @@ static int init(const struct motion_sensor_t *s)
ret = raw_read8(s->port, s->addr, L3GD20_WHO_AM_I_REG, &tmp);
if (ret)
- return EC_ERROR_UNKNOWN;
+ return ret;
if (tmp != L3GD20_WHO_AM_I)
return EC_ERROR_ACCESS_DENIED;
@@ -381,33 +381,27 @@ static int init(const struct motion_sensor_t *s)
/* All axes are enabled */
ret = raw_write8(s->port, s->addr, L3GD20_CTRL_REG1, 0x0f);
if (ret)
- return EC_ERROR_UNKNOWN;
+ return ret;
mutex_lock(s->mutex);
ret = raw_read8(s->port, s->addr, L3GD20_CTRL_REG4, &tmp);
if (ret) {
mutex_unlock(s->mutex);
- return EC_ERROR_UNKNOWN;
+ return ret;
}
tmp |= L3GD20_BDU_ENABLE;
ret = raw_write8(s->port, s->addr, L3GD20_CTRL_REG4, tmp);
mutex_unlock(s->mutex);
if (ret)
- return EC_ERROR_UNKNOWN;
+ return ret;
/* Config GYRO ODR */
ret = set_data_rate(s, s->default_range, 1);
if (ret)
- return EC_ERROR_UNKNOWN;
-
- /* Config GYRO Range */
- ret = set_range(s, s->default_range, 1);
- if (ret)
- return EC_ERROR_UNKNOWN;
+ return ret;
- sensor_init_done(s, get_range(s));
- return ret;
+ return sensor_init_done(s);
}
const struct accelgyro_drv l3gd20h_drv = {
diff --git a/include/motion_sense.h b/include/motion_sense.h
index 478468022e..10ebfd05b3 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -193,13 +193,13 @@ void motion_sense_fifo_add_unit(struct ec_response_motion_sensor_data *data,
#endif
/**
- * Take actions at end of sensor initialization (currently only printing
- * init done status to console).
+ * Take actions at end of sensor initialization:
+ * - print init done status to console,
+ * - set default range.
*
* @param sensor sensor which was just initialized
- * @param range range of sensor
*/
-void sensor_init_done(const struct motion_sensor_t *sensor, int range);
+int sensor_init_done(const struct motion_sensor_t *sensor);
/**
* Board specific function that is called when a double_tap event is detected.