summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com>2021-01-19 21:18:36 -0800
committerCommit Bot <commit-bot@chromium.org>2021-01-22 21:43:16 +0000
commit90995b4a525442b448384e8c5e6d77f541283c4d (patch)
tree9e68cdf860d4080a258115edc447c9e488b3688c
parent90dea61948cfcb668f6d893a7d8f6aef419ef942 (diff)
downloadchrome-ec-90995b4a525442b448384e8c5e6d77f541283c4d.tar.gz
zephyr: add motion sense support
Add support for motion sense in zephyr. This change adds basic functions for motion sense task to do meaningful work. sensor_map.h included by board.h will be used to get board specific sensor configuration. BUG=b:173507858 BRANCH=none TEST=make buildall -j8 build volteer on zephyr Signed-off-by: Hyungwoo Yang <hyungwoo.yang@intel.corp-partner.google.com> Change-Id: I906316d2e97428cf46b9a15071666c8e3b039b18 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2638909 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org> Tested-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--common/motion_sense.c14
-rw-r--r--include/motion_sense.h7
-rw-r--r--zephyr/CMakeLists.txt11
-rw-r--r--zephyr/Kconfig1
-rw-r--r--zephyr/Kconfig.motionsense124
-rw-r--r--zephyr/Kconfig.tasks17
-rw-r--r--zephyr/shim/include/board.h5
-rw-r--r--zephyr/shim/include/config_chip.h55
-rw-r--r--zephyr/shim/include/shimmed_task_id.h3
-rw-r--r--zephyr/shim/include/shimmed_tasks.h4
10 files changed, 236 insertions, 5 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 7a306bfb4a..9564012abe 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -53,7 +53,7 @@ STATIC_IF(CONFIG_CMD_ACCEL_INFO) int accel_disp;
*/
#define MOTION_SENSOR_INT_ADJUSTMENT_US 10
-struct mutex g_sensor_mutex;
+mutex_t g_sensor_mutex;
/*
* Current power level (S0, S3, S5, ...)
@@ -78,6 +78,18 @@ static uint32_t odr_event_required;
/* Whether or not the FIFO interrupt should be enabled (set from the AP). */
__maybe_unused static int fifo_int_enabled;
+#ifdef CONFIG_ZEPHYR
+static int init_sensor_mutex(const struct device *dev)
+{
+ ARG_UNUSED(dev);
+
+ k_mutex_init(&g_sensor_mutex);
+
+ return 0;
+}
+SYS_INIT(init_sensor_mutex, POST_KERNEL, 50);
+#endif /* CONFIG_ZEPHYR */
+
static inline int motion_sensor_in_forced_mode(
const struct motion_sensor_t *sensor)
{
diff --git a/include/motion_sense.h b/include/motion_sense.h
index e19107e290..29ac220395 100644
--- a/include/motion_sense.h
+++ b/include/motion_sense.h
@@ -15,6 +15,7 @@
#include "i2c.h"
#include "math_util.h"
#include "queue.h"
+#include "task.h"
#include "timer.h"
#include "util.h"
@@ -72,7 +73,7 @@ enum sensor_config {
TASK_EVENT_MOTION_FIRST_SW_EVENT + (_activity_id)))
-#define ROUND_UP_FLAG BIT(31)
+#define ROUND_UP_FLAG ((uint32_t)BIT(31))
#define BASE_ODR(_odr) ((_odr) & ~ROUND_UP_FLAG)
#define BASE_RANGE(_range) ((_range) & ~ROUND_UP_FLAG)
@@ -160,7 +161,7 @@ struct motion_sensor_t {
enum motionsensor_location location;
const struct accelgyro_drv *drv;
/* One mutex per physical chip. */
- struct mutex *mutex;
+ mutex_t *mutex;
void *drv_data;
/* Only valid if flags & MOTIONSENSE_FLAG_INT_SIGNAL is true. */
enum gpio_signal int_signal;
@@ -256,7 +257,7 @@ struct motion_sensor_t {
* When we process CMD_DUMP, we want to be sure the motion sense
* task is not updating the sensor values at the same time.
*/
-extern struct mutex g_sensor_mutex;
+extern mutex_t g_sensor_mutex;
/* Defined at board level. */
extern struct motion_sensor_t motion_sensors[];
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index 55c8e5a138..de5ba324c7 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -75,6 +75,8 @@ zephyr_sources_ifdef(CONFIG_PLATFORM_EC "${PLATFORM_EC}/common/base32.c"
# Now include files that depend on or relate to other CONFIG options, sorted by
# CONFIG
+zephyr_sources_ifdef(CONFIG_PLATFORM_EC_ACCEL_FIFO
+ "${PLATFORM_EC}/common/motion_sense_fifo.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_ACPI "${PLATFORM_EC}/common/acpi.c"
"${PLATFORM_EC}/common/ec_features.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_BATTERY "${PLATFORM_EC}/common/battery.c")
@@ -111,8 +113,14 @@ zephyr_sources_ifdef(CONFIG_PLATFORM_EC_KEYBOARD
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_KEYBOARD_PROTOCOL_8042
"${PLATFORM_EC}/common/keyboard_8042.c"
"${PLATFORM_EC}/common/keyboard_8042_sharedlib.c")
+zephyr_sources_ifdef(CONFIG_PLATFORM_EC_LID_ANGLE
+ "${PLATFORM_EC}/common/lid_angle.c"
+ "${PLATFORM_EC}/common/motion_lid.c"
+ "${PLATFORM_EC}/common/math_util.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_LID_SWITCH
"${PLATFORM_EC}/common/lid_switch.c")
+zephyr_sources_ifdef(CONFIG_PLATFORM_EC_MOTIONSENSE
+ "${PLATFORM_EC}/common/motion_sense.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_PORT80 "${PLATFORM_EC}/common/port80.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_POWER_BUTTON
"${PLATFORM_EC}/common/power_button.c")
@@ -129,7 +137,8 @@ zephyr_sources_ifdef(CONFIG_PLATFORM_EC_POWERSEQ_HOST_SLEEP
"${PLATFORM_EC}/power/host_sleep.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_THROTTLE_AP
"${PLATFORM_EC}/common/throttle_ap.c")
-
+zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TABLET_MODE
+ "${PLATFORM_EC}/common/tablet_mode.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_TIMER "${PLATFORM_EC}/common/timer.c")
zephyr_sources_ifdef(CONFIG_PLATFORM_EC_USB_CHARGER
diff --git a/zephyr/Kconfig b/zephyr/Kconfig
index c9d4e10a2d..822d75f65d 100644
--- a/zephyr/Kconfig
+++ b/zephyr/Kconfig
@@ -33,6 +33,7 @@ if PLATFORM_EC
rsource "Kconfig.battery"
rsource "Kconfig.powerseq"
+rsource "Kconfig.motionsense"
rsource "Kconfig.tasks"
rsource "Kconfig.usbc"
diff --git a/zephyr/Kconfig.motionsense b/zephyr/Kconfig.motionsense
new file mode 100644
index 0000000000..b73d1b9d35
--- /dev/null
+++ b/zephyr/Kconfig.motionsense
@@ -0,0 +1,124 @@
+# 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.
+
+menuconfig PLATFORM_EC_MOTIONSENSE
+ bool "Motion Sense"
+ select HAS_TASK_MOTIONSENSE
+ help
+ Enable motion sense task. The task collects data from available sensors
+ and report them to AP. Besides the task reports the sensor data to AP.
+ Based on the data, it also does other things like calculating lid angle
+ and detect tablet mode.
+
+config PLATFORM_EC_ACCEL_FIFO
+ bool "Sensor FIFO"
+ help
+ Enable this to add the sensor FIFO used by sensor device drivers to fill.
+ Using FIFO reduces power consumption since it reduces the number of
+ AP wake-ups.
+
+if PLATFORM_EC_ACCEL_FIFO
+
+config PLATFORM_EC_ACCEL_FIFO_SIZE
+ int "Motion Sense FIFO Size"
+ default 256
+ help
+ This sets the size of the sensor FIFO, must be a power of 2.
+
+config PLATFORM_EC_ACCEL_FIFO_THRES
+ int "FIFO Threshold"
+ default 85 # (PLATFORM_EC_ACCEL_FIFO_SIZE / 3)
+ help
+ This sets the amount of free entries that trigger an interrupt to the AP.
+
+endif # PLATFORM_EC_ACCEL_FIFO
+
+config PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS
+ bool "Extra Sensor Timestamp"
+ help
+ If this is defined, motion_sense sends
+ sensor events to the AP in the format
+ +-----------+
+ | Timestamp |
+ | Payload |
+ | Timestamp |
+ | Payload |
+ | ... |
+ +-----------+
+ If this is not defined, the events will be sent in the format
+ +-----------+
+ | Payload |
+ | Payload |
+ | Payload |
+ | ... |
+ | Timestamp |
+ +-----------+
+ The former format enables improved filtering of sensor event
+ timestamps on the AP, but comes with stricter jitter requirements.
+
+config PLATFORM_EC_ACCEL_INTERRUPTS
+ bool "Accelerometer Interrupts"
+ help
+ Enable this to allow a sensor driver to send an event to motion task when
+ the sensor gets the data ready interrupt. On the event, motion task calls
+ the driver's irq_handler to collect data.
+
+# TODO(b/173507858) config PLATFORM_EC_MOTION_FILL_LPC_SENSE_DATA
+# if PLATFORM_EC_MOTION_FILL_LPC_SENSE_DATA
+#endif # PLATFORM_EC_MOTION_FILL_LPC_SENSE_DATA
+
+config PLATFORM_EC_ALS
+ bool "Ambient Light Sensor(ALS)"
+ default y if HAS_TASK_ALS
+ help
+ Enable this to indicate there's at least one or more ALS devices available.
+ If PLATFORM_EC_MOTION_FILL_LPC_SENSE_DATA is set, then motion task updates
+ the designated part of EC memmap with the ALS data. The updating EC memmap
+ can be also done by the dedicated ALS task with HAS_ALS_TASK set.
+ Number of ALS entries reserved in EC memmap are defined by EC_ALS_ENTRIES
+ in ec_commands.h.
+
+if PLATFORM_EC_ALS
+
+config PLATFORM_EC_ALS_COUNT
+ int "Number of ALS devices"
+ default 1
+ help
+ This sets the number of ALS devices. This should be less than or equal to
+ EC_ALS_ENTRIES in ec_commands.h
+ TODO(b/173507858) move this to device tree
+
+endif # PLATFORM_EC_ALS
+
+config PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT
+ bool "Dynamic Motion Sensor Count"
+ help
+ Enable this to allow changing motion sensor count dynamically.
+
+config PLATFORM_EC_LID_ANGLE
+ bool "Lid Angle Sensor"
+ help
+ Enable this to detect lid angle with two accelerometers. The andgle
+ calculation requires the information about which sensor is on the lid
+ and which one is on the base. The calculated lid angle is used to
+ decide start/stop other peripherals like stop/start keyboard scanning.
+ # TODO(b/173507858): add more detail after .dts change
+
+if PLATFORM_EC_LID_ANGLE
+
+config PLATFORM_EC_TABLET_MODE
+ bool "Tablet Mode"
+ help
+ Enable this for a device which can be a tablet as well as a clamshell.
+ Tablet mode detection is done with current lid angle.
+
+config PLATFORM_EC_GMR_TABLET_MODE
+ bool "Giant Magnetoresistance(GMR) Tablet Mode"
+ help
+ Enable this to use GMR sensor to detect tablet mode.
+ It requires to set GMR_TABLET_MODE_GPIO_L to map the interrupt from
+ the sensor and direct its mapping to gmr_tablet_switch_isr
+ in common/tablet_mode.c.
+
+endif # PLATFORM_EC_LID_ANGLE
diff --git a/zephyr/Kconfig.tasks b/zephyr/Kconfig.tasks
index ebdf59748b..35232eb1dd 100644
--- a/zephyr/Kconfig.tasks
+++ b/zephyr/Kconfig.tasks
@@ -125,6 +125,23 @@ config TASK_KEYSCAN_STACK_SIZE
endif # HAS_TASK_KEYSCAN
+config HAS_TASK_MOTIONSENSE
+ bool "Enable motionsense task"
+ help
+ This turns on the motion sense task which collects sensor data from the
+ sensors and reports them to AP. Using the data, it also produces other
+ meaningful reports to AP like lid angle and tablet mode.
+
+if HAS_TASK_MOTIONSENSE
+
+config TASK_MOTIONSENSE_STACK_SIZE
+ hex "motionsense task stack size"
+ default 0x1000
+ help
+ The size of the motion sense task stack.
+
+endif # HAS_TASK_MOTIONSENSE
+
config HAS_TASK_POWERBTN
bool "Power-button task (x86)"
depends on PLATFORM_EC_POWER_BUTTON
diff --git a/zephyr/shim/include/board.h b/zephyr/shim/include/board.h
index 43625b4625..87ec7ed33a 100644
--- a/zephyr/shim/include/board.h
+++ b/zephyr/shim/include/board.h
@@ -21,4 +21,9 @@
#include "i2c_map.h"
#endif
+/* Include board specific sensor configuration if motionsense is enabled */
+#ifdef CONFIG_MOTIONSENSE
+#include "sensor_map.h"
+#endif
+
#endif /* __BOARD_H */
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index bed93ceb62..4219a85f63 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -620,4 +620,59 @@ enum battery_type {
#define CONFIG_VSTORE_SLOT_COUNT CONFIG_PLATFORM_EC_VSTORE_SLOT_COUNT
#endif
+/* motion sense */
+#undef CONFIG_MOTIONSENSE
+#ifdef CONFIG_PLATFORM_EC_MOTIONSENSE
+#define CONFIG_MOTIONSENSE
+
+#undef CONFIG_ACCEL_FIFO
+#undef CONFIG_ACCEL_FIFO_SIZE
+#undef CONFIG_ACCEL_FIFO_THRES
+#ifdef CONFIG_PLATFORM_EC_ACCEL_FIFO
+#define CONFIG_ACCEL_FIFO
+#define CONFIG_ACCEL_FIFO_SIZE CONFIG_PLATFORM_EC_ACCEL_FIFO_SIZE
+#define CONFIG_ACCEL_FIFO_THRES CONFIG_PLATFORM_EC_ACCEL_FIFO_THRES
+#endif /* CONFIG_PLATFORM_EC_ACCEL_FIFO */
+
+#undef CONFIG_SENSOR_TIGHT_TIMESTAMPS
+#ifdef CONFIG_PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS
+#define CONFIG_SENSOR_TIGHT_TIMESTAMPS
+#endif
+
+#undef CONFIG_ACCEL_INTERRUPTS
+#ifdef CONFIG_PLATFORM_EC_ACCEL_INTERRUPTS
+#define CONFIG_ACCEL_INTERRUPTS
+#endif
+
+#undef CONFIG_ALS
+#undef CONFIG_ALS_COUNT
+#ifdef CONFIG_PLATFORM_EC_ALS
+#define CONFIG_ALS
+#define ALS_COUNT CONFIG_PLATFORM_EC_ALS_COUNT
+#else
+#define ALS_COUNT 0
+#endif
+
+#undef CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
+#ifdef CONFIG_PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT
+#define CONFIG_DYNAMIC_MOTION_SENSOR_COUNT
+#endif
+
+#undef CONFIG_LID_ANGLE
+#ifdef CONFIG_PLATFORM_EC_LID_ANGLE
+#define CONFIG_LID_ANGLE
+#endif
+
+#undef CONFIG_TABLET_MODE
+#ifdef CONFIG_PLATFORM_EC_TABLET_MODE
+#define CONFIG_TABLET_MODE
+#endif
+
+#undef CONFIG_GMR_TABLET_MODE
+#ifdef CONFIG_PLATFORM_EC_GMR_TABLET_MODE
+#define CONFIG_GMR_TABLET_MODE
+#endif
+
+#endif /* CONFIG_PLATFORM_EC_MOTIONSENSE */
+
#endif /* __CROS_EC_CONFIG_CHIP_H */
diff --git a/zephyr/shim/include/shimmed_task_id.h b/zephyr/shim/include/shimmed_task_id.h
index 2b16d43a80..f0999834cc 100644
--- a/zephyr/shim/include/shimmed_task_id.h
+++ b/zephyr/shim/include/shimmed_task_id.h
@@ -37,6 +37,9 @@ typedef uint8_t task_id_t;
COND_CODE_1(HAS_TASK_CHIPSET, \
(CROS_EC_TASK(CHIPSET, chipset_task, 0, \
CONFIG_TASK_CHIPSET_STACK_SIZE)), ()) \
+ COND_CODE_1(HAS_TASK_MOTIONSENSE, \
+ (CROS_EC_TASK(MOTIONSENSE, motion_sense_task, 0, \
+ CONFIG_TASK_MOTIONSENSE_STACK_SIZE)), ()) \
COND_CODE_1(HAS_TASK_HOSTCMD, \
(CROS_EC_TASK(HOSTCMD, host_command_task, 0, \
CONFIG_TASK_HOSTCMD_STACK_SIZE)), ()) \
diff --git a/zephyr/shim/include/shimmed_tasks.h b/zephyr/shim/include/shimmed_tasks.h
index f75dffff20..4db1672a30 100644
--- a/zephyr/shim/include/shimmed_tasks.h
+++ b/zephyr/shim/include/shimmed_tasks.h
@@ -31,6 +31,10 @@
#define HAS_TASK_KEYPROTO 1
#endif /* CONFIG_HAS_TASK_KEYPROTO */
+#ifdef CONFIG_HAS_TASK_MOTIONSENSE
+#define HAS_TASK_MOTIONSENSE 1
+#endif /* CONFIG_HAS_TASK_MOTIONSENSE */
+
#ifdef CONFIG_HAS_TASK_PD_C0
#define HAS_TASK_PD_C0 1
#endif /* CONFIG_HAS_TASK_PD_C0 */