From 52465b23eccfc779bd358c0495918d8c0baa884e Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Thu, 15 Apr 2021 20:14:31 -0600 Subject: zephyr: lazor: Add sensors to lazor Enable the motionsense task in lazor and along with it the GMR tablet mode and lid angle calculations. BRANCH=none BUG=b:185966444 TEST=zmake testall TEST=Flash on lazor and check sensors (done by keith since I don't have a board). Change-Id: Iccd1e6e0d503f759255cf3d9c162922788e915a0 Signed-off-by: Yuval Peress Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2830532 Tested-by: Keith Short Reviewed-by: Keith Short Reviewed-by: Jack Rosenthal Commit-Queue: Keith Short --- .../trogdor/boards/arm/trogdor/trogdor.dts | 11 +- zephyr/projects/trogdor/lazor/gpio.dts | 6 +- zephyr/projects/trogdor/lazor/include/gpio_map.h | 8 +- zephyr/projects/trogdor/lazor/motionsense.dts | 157 +++++++++++++++++++++ zephyr/projects/trogdor/lazor/prj.conf | 17 +++ zephyr/projects/trogdor/lazor/zmake.yaml | 1 + 6 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 zephyr/projects/trogdor/lazor/motionsense.dts (limited to 'zephyr/projects') diff --git a/zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts b/zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts index 12179d60cb..8a7cb84b3a 100644 --- a/zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts +++ b/zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts @@ -72,10 +72,19 @@ enum-name = "I2C_PORT_EEPROM"; label = "EEPROM"; }; - sensor { + i2c_sensor: sensor { i2c-port = <&i2c7_0>; enum-name = "I2C_PORT_SENSOR"; label = "SENSOR"; + config { + frequency = <400>; + scl { + enum-name = "GPIO_EC_I2C_SENSOR_SCL"; + }; + sda { + enum-name = "GPIO_EC_I2C_SENSOR_SDA"; + }; + }; }; accel { i2c-port = <&i2c7_0>; diff --git a/zephyr/projects/trogdor/lazor/gpio.dts b/zephyr/projects/trogdor/lazor/gpio.dts index 6b92f406f8..ff9d5210d6 100644 --- a/zephyr/projects/trogdor/lazor/gpio.dts +++ b/zephyr/projects/trogdor/lazor/gpio.dts @@ -113,10 +113,12 @@ }; tablet_mode_l { gpios = <&gpioc 6 GPIO_INPUT>; + enum-name = "GPIO_TABLET_MODE_L"; label = "TABLET_MODE_L"; }; - accel_gyro_int_l { + gpio_accel_gyro_int_l: accel_gyro_int_l { gpios = <&gpioa 0 GPIO_INPUT>; + enum-name = "GPIO_EC_IMU_INT_L"; label = "ACCEL_GYRO_INT_L"; }; da9313_gpio0 { @@ -315,10 +317,12 @@ }; ec_i2c_sensor_scl { gpios = <&gpiob 3 GPIO_INPUT>; + enum-name = "GPIO_EC_I2C_SENSOR_SCL"; label = "EC_I2C_SENSOR_SCL"; }; ec_i2c_sensor_sda { gpios = <&gpiob 2 GPIO_INPUT>; + enum-name = "GPIO_EC_I2C_SENSOR_SDA"; label = "EC_I2C_SENSOR_SDA"; }; brd_id0 { diff --git a/zephyr/projects/trogdor/lazor/include/gpio_map.h b/zephyr/projects/trogdor/lazor/include/gpio_map.h index 3c0a6baddb..c21fdc2126 100644 --- a/zephyr/projects/trogdor/lazor/include/gpio_map.h +++ b/zephyr/projects/trogdor/lazor/include/gpio_map.h @@ -9,6 +9,10 @@ #include #include +#ifdef CONFIG_PLATFORM_EC_GMR_TABLET_MODE +#define GMR_TABLET_MODE_GPIO_L GPIO_TABLET_MODE_L +#endif + /* * Set EC_CROS_GPIO_INTERRUPTS to a space-separated list of GPIO_INT items. * @@ -54,6 +58,8 @@ GPIO_INT(GPIO_USB_C1_BC12_INT_L, GPIO_INT_EDGE_FALLING, usb1_evt) \ GPIO_INT(GPIO_USB_A0_OC_ODL, GPIO_INT_EDGE_BOTH, usba_oc_interrupt) \ GPIO_INT(GPIO_CCD_MODE_ODL, GPIO_INT_EDGE_FALLING, \ - board_connect_c0_sbu) + board_connect_c0_sbu) \ + GPIO_INT(GPIO_EC_IMU_INT_L, GPIO_INT_EDGE_FALLING, bmi160_interrupt) \ + GPIO_INT(GPIO_TABLET_MODE_L, GPIO_INT_EDGE_BOTH, gmr_tablet_switch_isr) #endif /* __ZEPHYR_GPIO_MAP_H */ diff --git a/zephyr/projects/trogdor/lazor/motionsense.dts b/zephyr/projects/trogdor/lazor/motionsense.dts new file mode 100644 index 0000000000..2dfee0969e --- /dev/null +++ b/zephyr/projects/trogdor/lazor/motionsense.dts @@ -0,0 +1,157 @@ +/* Copyright 2020 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 + + +/ { + aliases { + /* + * motion sense's <>_INT_EVENT is handled + * by alias. Using the alias, each driver creates + * its own <>_INT_EVENT. + */ + bmi160-int = &base_accel; + }; + + /* + * Declare mutexes used by sensor drivers. + * A mutex node is used to create an instance of mutex_t. + * A mutex node is referenced by a sensor node if the + * corresponding sensor driver needs to use the + * instance of the mutex. + */ + motionsense-mutex { + compatible = "cros-ec,motionsense-mutex"; + mutex_bma255: bma255-mutex { + label = "BMA255_MUTEX"; + }; + + mutex_bmi160: bmi160-mutex { + label = "BMI160_MUTEX"; + }; + }; + + /* Rotation matrix used by drivers. */ + motionsense-rotation-ref { + compatible = "cros-ec,motionsense-rotation-ref"; + lid_rot_ref: lid-rotation-ref { + mat33 = <(-1) 0 0 + 0 (-1) 0 + 0 0 1>; + }; + + base_rot_ref: base-rotation-ref { + mat33 = <1 0 0 + 0 (-1) 0 + 0 0 (-1)>; + }; + }; + + /* + * Driver specific data. A driver-specific data can be shared with + * different motion sensors while they are using the same driver. + * + * If a node's compatible starts with "cros-ec,accelgyro-", it is for + * a common structure defined in accelgyro.h. + * e.g) compatible = "cros-ec,accelgyro-als-drv-data" is for + * "struct als_drv_data_t" in accelgyro.h + */ + motionsense-sensor-data { + bma255_data: bma255-drv-data { + compatible = "cros-ec,drvdata-bma255"; + status = "okay"; + }; + + bmi160_data: bmi160-drv-data { + compatible = "cros-ec,drvdata-bmi160"; + status = "okay"; + }; + }; + + /* + * List of motion sensors that creates motion_sensors array. + * The label "lid_accel" and "base_accel" are used to indicate + * motion sensor IDs for lid angle calculation. + */ + motionsense-sensor { + lid_accel: lid-accel { + compatible = "cros-ec,bma255"; + status = "okay"; + + label = "Lid Accel"; + active-mask = "SENSOR_ACTIVE_S0_S3_S5"; + location = "MOTIONSENSE_LOC_LID"; + mutex = <&mutex_bma255>; + port = <&i2c_sensor>; + rot-standard-ref = <&lid_rot_ref>; + default-range = <2>; + drv-data = <&bma255_data>; + i2c-spi-addr-flags = "BMA2x2_I2C_ADDR1_FLAGS"; + configs { + compatible = + "cros-ec,motionsense-sensor-config"; + ec-s0 { + label = "SENSOR_CONFIG_EC_S0"; + odr = <(10000 | ROUND_UP_FLAG)>; + }; + ec-s3 { + label = "SENSOR_CONFIG_EC_S3"; + odr = <(10000 | ROUND_UP_FLAG)>; + }; + }; + }; + + base_accel: base-accel { + compatible = "cros-ec,bmi160-accel"; + status = "okay"; + + label = "Base Accel"; + active-mask = "SENSOR_ACTIVE_S0_S3_S5"; + location = "MOTIONSENSE_LOC_BASE"; + mutex = <&mutex_bmi160>; + port = <&i2c_sensor>; + rot-standard-ref = <&base_rot_ref>; + drv-data = <&bmi160_data>; + configs { + compatible = + "cros-ec,motionsense-sensor-config"; + ec-s0 { + label = "SENSOR_CONFIG_EC_S0"; + odr = <(10000 | ROUND_UP_FLAG)>; + }; + ec-s3 { + label = "SENSOR_CONFIG_EC_S3"; + odr = <(10000 | ROUND_UP_FLAG)>; + }; + }; + }; + + base-gyro { + compatible = "cros-ec,bmi160-gyro"; + status = "okay"; + + label = "Base Gyro"; + active-mask = "SENSOR_ACTIVE_S0_S3_S5"; + location = "MOTIONSENSE_LOC_BASE"; + mutex = <&mutex_bmi160>; + port = <&i2c_sensor>; + rot-standard-ref = <&base_rot_ref>; + drv-data = <&bmi160_data>; + }; + }; + + motionsense-sensor-info { + compatible = "cros-ec,motionsense-sensor-info"; + + /* + * list of GPIO interrupts that have to + * be enabled at initial stage + */ + sensor-irqs = <&gpio_accel_gyro_int_l>; + /* list of sensors in force mode */ + accel-force-mode-sensors = <&lid_accel>; + }; +}; diff --git a/zephyr/projects/trogdor/lazor/prj.conf b/zephyr/projects/trogdor/lazor/prj.conf index f946b85d60..9cea5451a3 100644 --- a/zephyr/projects/trogdor/lazor/prj.conf +++ b/zephyr/projects/trogdor/lazor/prj.conf @@ -121,3 +121,20 @@ CONFIG_PLATFORM_EC_VBOOT_HASH=y # Serial Host Interface (SHI) device. CONFIG_CROS_SHI_NPCX=y + +# Sensors +CONFIG_PLATFORM_EC_MOTIONSENSE=y +CONFIG_PLATFORM_EC_ACCEL_FIFO=y +CONFIG_PLATFORM_EC_ACCEL_INTERRUPTS=y +CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCELS=y +CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCEL_INFO=y +CONFIG_PLATFORM_EC_GMR_TABLET_MODE=y +CONFIG_PLATFORM_EC_LID_ANGLE=y +CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=y +CONFIG_PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS=y +CONFIG_PLATFORM_EC_TABLET_MODE=y + +# Sensor Drivers +CONFIG_PLATFORM_EC_ACCEL_BMA255=y +CONFIG_PLATFORM_EC_ACCELGYRO_BMI160=y +CONFIG_PLATFORM_EC_ACCELGYRO_BMI_COMM_I2C=y diff --git a/zephyr/projects/trogdor/lazor/zmake.yaml b/zephyr/projects/trogdor/lazor/zmake.yaml index 641513395b..18942aa82b 100644 --- a/zephyr/projects/trogdor/lazor/zmake.yaml +++ b/zephyr/projects/trogdor/lazor/zmake.yaml @@ -6,6 +6,7 @@ board: trogdor dts-overlays: - gpio.dts - battery.dts + - motionsense.dts supported-zephyr-versions: - v2.5 toolchain: coreboot-sdk -- cgit v1.2.1