summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommy Chung <tommy.chung@quanta.corp-partner.google.com>2023-04-21 20:31:14 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-16 02:12:02 +0000
commit638a938c277e6f214277f3ec97dfec6257fa040e (patch)
tree74708337fc3c7fecf16a53502422e7ff00c67b03
parentefe0fbc416966340abae6539df8b2ab5a7e5a219 (diff)
downloadchrome-ec-638a938c277e6f214277f3ec97dfec6257fa040e.tar.gz
yavilla: Add convertible related functions
Yavilla has convertible sku, add convertible related functions, including motion sensors, gmr sensor, vol button. Disable motion sensors and gmr semsor for clamesell sku. BUG=b:273791621 TEST=make sure all convertible functions work. Change-Id: I29beaaae8f002c811ad1ccb8ecdd77fa78840a5d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4457658 Commit-Queue: Tommy Chung <tommy.chung@quanta.corp-partner.google.com> Tested-by: Tommy Chung <tommy.chung@quanta.corp-partner.google.com> Reviewed-by: Peter Marheine <pmarheine@chromium.org> Reviewed-by: Devin Lu <devin.lu@quantatw.com>
-rw-r--r--zephyr/program/nissa/yavilla/gpio.dtsi18
-rw-r--r--zephyr/program/nissa/yavilla/motionsense.dtsi148
-rw-r--r--zephyr/program/nissa/yavilla/overlay.dtsi34
-rw-r--r--zephyr/program/nissa/yavilla/project.conf16
-rw-r--r--zephyr/program/nissa/yavilla/project.overlay1
-rw-r--r--zephyr/program/nissa/yavilla/src/board.c36
6 files changed, 234 insertions, 19 deletions
diff --git a/zephyr/program/nissa/yavilla/gpio.dtsi b/zephyr/program/nissa/yavilla/gpio.dtsi
index a18e674b11..8c76048f25 100644
--- a/zephyr/program/nissa/yavilla/gpio.dtsi
+++ b/zephyr/program/nissa/yavilla/gpio.dtsi
@@ -34,6 +34,9 @@
named-gpios {
compatible = "named-gpios";
+ gpio_acc_int_l: acc_int_l {
+ gpios = <&gpioc 0 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>;
+ };
gpio_all_sys_pwrgd: all_sys_pwrgd {
gpios = <&gpiob 7 GPIO_INPUT>;
};
@@ -134,6 +137,9 @@
gpios = <&gpioe 2 GPIO_INPUT_PULL_UP>;
enum-name = "GPIO_POWER_BUTTON_L";
};
+ gpio_imu_int_l: imu_int_l {
+ gpios = <&gpioj 0 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>;
+ };
gpio_imvp91_vrrdy_od: imvp91_vrrdy_od {
gpios = <&gpioj 4 GPIO_INPUT>;
no-auto-init;
@@ -178,6 +184,10 @@
gpios = <&gpiod 1 GPIO_ODR_HIGH>;
no-auto-init;
};
+ gpio_tablet_mode_l: tablet_mode_l {
+ gpios = <&gpioa 7 GPIO_INPUT>;
+ enum-name = "GPIO_TABLET_MODE_L";
+ };
gpio_usb_a0_ilimit_sdp: usb_a0_ilimit_sdp {
gpios = <&gpiol 5 GPIO_OUTPUT>;
enum-name = "GPIO_USB1_ILIM_SEL";
@@ -216,6 +226,14 @@
gpios = <&gpioksol 2 GPIO_OUTPUT_HIGH>;
enum-name = "GPIO_KBD_KSO2";
};
+ gpio_voldn_btn_odl: voldn_btn_odl {
+ gpios = <&gpioi 6 GPIO_INPUT_PULL_UP>;
+ enum-name = "GPIO_VOLUME_DOWN_L";
+ };
+ gpio_volup_btn_odl: volup_btn_odl {
+ gpios = <&gpioi 7 GPIO_INPUT_PULL_UP>;
+ enum-name = "GPIO_VOLUME_UP_L";
+ };
};
named-i2c-ports {
diff --git a/zephyr/program/nissa/yavilla/motionsense.dtsi b/zephyr/program/nissa/yavilla/motionsense.dtsi
new file mode 100644
index 0000000000..df84c36471
--- /dev/null
+++ b/zephyr/program/nissa/yavilla/motionsense.dtsi
@@ -0,0 +1,148 @@
+/* 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 <dt-bindings/motionsense/utils.h>
+
+
+/ {
+ aliases {
+ /*
+ * Interrupt bindings for sensor devices.
+ */
+ bmi3xx-int = &base_accel;
+ bma4xx-int = &lid_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";
+ lid_mutex: lid-mutex {
+ };
+
+ base_mutex: base-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 = <0 1 0
+ 1 0 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 {
+ bmi323_data: bmi323-drv-data {
+ compatible = "cros-ec,drvdata-bmi3xx";
+ status = "okay";
+ };
+
+ bma422_data: bma4xx-drv-data {
+ compatible = "cros-ec,drvdata-bma4xx";
+ status = "okay";
+ };
+ };
+
+ /*
+ * List of motion sensors that creates motion_sensors array.
+ * The nodelabel "lid_accel" and "base_accel" are used to indicate
+ * motion sensor IDs for lid angle calculation.
+ * TODO(b/238139272): The first entries of the array must be
+ * accelerometers,then gyroscope. Fix this dependency in the DTS
+ * processing which makes the devicetree entries independent.
+ */
+ motionsense-sensor {
+ lid_accel: lid-accel {
+ compatible = "cros-ec,bma4xx";
+ status = "okay";
+
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_LID";
+ mutex = <&lid_mutex>;
+ port = <&i2c_ec_i2c_sensor>;
+ rot-standard-ref = <&lid_rot_ref>;
+ default-range = <2>;
+ drv-data = <&bma422_data>;
+ i2c-spi-addr-flags = "BMA4_I2C_ADDR_PRIMARY";
+ configs {
+ compatible =
+ "cros-ec,motionsense-sensor-config";
+ ec-s0 {
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ ec-s3 {
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ };
+ };
+
+ base_accel: base-accel {
+ compatible = "cros-ec,bmi3xx-accel";
+ status = "okay";
+
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&base_mutex>;
+ port = <&i2c_ec_i2c_sensor>;
+ rot-standard-ref = <&base_rot_ref>;
+ drv-data = <&bmi323_data>;
+ configs {
+ compatible =
+ "cros-ec,motionsense-sensor-config";
+ ec-s0 {
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ ec-s3 {
+ odr = <(10000 | ROUND_UP_FLAG)>;
+ };
+ };
+ };
+
+ base_gyro: base-gyro {
+ compatible = "cros-ec,bmi3xx-gyro";
+ status = "okay";
+
+ active-mask = "SENSOR_ACTIVE_S0_S3";
+ location = "MOTIONSENSE_LOC_BASE";
+ mutex = <&base_mutex>;
+ port = <&i2c_ec_i2c_sensor>;
+ rot-standard-ref = <&base_rot_ref>;
+ drv-data = <&bmi323_data>;
+ };
+ };
+
+ motionsense-sensor-info {
+ compatible = "cros-ec,motionsense-sensor-info";
+
+ /*
+ * list of GPIO interrupts that have to
+ * be enabled at initial stage
+ */
+ sensor-irqs = <&int_imu &int_acc>;
+ };
+};
diff --git a/zephyr/program/nissa/yavilla/overlay.dtsi b/zephyr/program/nissa/yavilla/overlay.dtsi
index b60ad2f476..c75ae9dd79 100644
--- a/zephyr/program/nissa/yavilla/overlay.dtsi
+++ b/zephyr/program/nissa/yavilla/overlay.dtsi
@@ -49,6 +49,16 @@
flags = <GPIO_INT_EDGE_BOTH>;
handler = "power_button_interrupt";
};
+ int_vol_down: vol_down {
+ irq-pin = <&gpio_voldn_btn_odl>;
+ flags = <GPIO_INT_EDGE_BOTH>;
+ handler = "button_interrupt";
+ };
+ int_vol_up: vol_up {
+ irq-pin = <&gpio_volup_btn_odl>;
+ flags = <GPIO_INT_EDGE_BOTH>;
+ handler = "button_interrupt";
+ };
int_wp_l: wp_l {
irq-pin = <&gpio_ec_wp_odl>;
flags = <GPIO_INT_EDGE_BOTH>;
@@ -59,6 +69,21 @@
flags = <GPIO_INT_EDGE_BOTH>;
handler = "lid_interrupt";
};
+ int_tablet_mode: tablet_mode {
+ irq-pin = <&gpio_tablet_mode_l>;
+ flags = <GPIO_INT_EDGE_BOTH>;
+ handler = "gmr_tablet_switch_isr";
+ };
+ int_acc: lid_imu {
+ irq-pin = <&gpio_acc_int_l>;
+ flags = <GPIO_INT_EDGE_FALLING>;
+ handler = "bma4xx_interrupt";
+ };
+ int_imu: ec_imu {
+ irq-pin = <&gpio_imu_int_l>;
+ flags = <GPIO_INT_EDGE_FALLING>;
+ handler = "bmi3xx_interrupt";
+ };
int_usb_c0: usb_c0 {
irq-pin = <&gpio_usb_c0_int_odl>;
flags = <GPIO_INT_EDGE_FALLING>;
@@ -73,14 +98,9 @@
unused-pins {
compatible = "unused-gpios";
- unused-gpios = <&gpioa 7 0>,
- <&gpioc 0 0>,
- <&gpioc 6 0>,
+ unused-gpios = <&gpioc 6 0>,
<&gpiod 7 0>,
<&gpioh 2 0>,
- <&gpioi 6 0>,
- <&gpioi 7 0>,
- <&gpioj 0 0>,
<&gpioj 3 0>,
<&gpiok 7 GPIO_OUTPUT>;
};
@@ -292,7 +312,7 @@
&i2c2 {
label = "I2C_SENSOR";
- clock-frequency = <I2C_BITRATE_FAST>;
+ clock-frequency = <I2C_BITRATE_STANDARD>;
pinctrl-0 = <&i2c2_clk_gpf6_default
&i2c2_data_gpf7_default>;
pinctrl-names = "default";
diff --git a/zephyr/program/nissa/yavilla/project.conf b/zephyr/program/nissa/yavilla/project.conf
index 30818c4419..8011391adf 100644
--- a/zephyr/program/nissa/yavilla/project.conf
+++ b/zephyr/program/nissa/yavilla/project.conf
@@ -8,17 +8,11 @@ CONFIG_BOARD_YAVILLA=y
CONFIG_PLATFORM_EC_KEYBOARD_PWRBTN_ASSERTS_KSI3=y
CONFIG_PLATFORM_EC_KEYBOARD_REFRESH_ROW3=y
-# Sensors: disabled; yavilla is clamshell-only
-CONFIG_PLATFORM_EC_LID_ANGLE=n
-CONFIG_PLATFORM_EC_LID_ANGLE_UPDATE=n
-CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCELS=n
-CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCEL_INFO=n
-CONFIG_PLATFORM_EC_ACCEL_FIFO=n
-CONFIG_PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS=n
-CONFIG_PLATFORM_EC_GMR_TABLET_MODE=n
-CONFIG_PLATFORM_EC_TABLET_MODE=n
-CONFIG_PLATFORM_EC_TABLET_MODE_SWITCH=n
-CONFIG_PLATFORM_EC_VOLUME_BUTTONS=n
+# Sensors
+CONFIG_PLATFORM_EC_ACCELGYRO_BMI_COMM_I2C=y
+CONFIG_PLATFORM_EC_ACCELGYRO_BMI3XX=y
+CONFIG_PLATFORM_EC_ACCEL_BMA4XX=y
+CONFIG_PLATFORM_EC_DYNAMIC_MOTION_SENSOR_COUNT=y
CONFIG_PLATFORM_EC_MAX_SENSOR_FREQ_MILLIHZ=100000
# Keyboard
diff --git a/zephyr/program/nissa/yavilla/project.overlay b/zephyr/program/nissa/yavilla/project.overlay
index 97f431022c..40bbaec4bb 100644
--- a/zephyr/program/nissa/yavilla/project.overlay
+++ b/zephyr/program/nissa/yavilla/project.overlay
@@ -9,5 +9,6 @@
#include "fan.dtsi"
#include "gpio.dtsi"
#include "keyboard.dtsi"
+#include "motionsense.dtsi"
#include "overlay.dtsi"
#include "power_signals.dtsi"
diff --git a/zephyr/program/nissa/yavilla/src/board.c b/zephyr/program/nissa/yavilla/src/board.c
index f89b92ebd8..feee5fa91f 100644
--- a/zephyr/program/nissa/yavilla/src/board.c
+++ b/zephyr/program/nissa/yavilla/src/board.c
@@ -3,14 +3,19 @@
* found in the LICENSE file.
*/
/* yavilla hardware configuration */
+#include "cros_cbi.h"
#include "gpio/gpio_int.h"
#include "hooks.h"
+#include "motion_sense.h"
+#include "tablet_mode.h"
#include "task.h"
+#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/init.h>
#include <zephyr/kernel.h>
+#include <zephyr/logging/log.h>
#include <zephyr/sys/printk.h>
LOG_MODULE_DECLARE(nissa, CONFIG_NISSA_LOG_LEVEL);
__override uint8_t board_get_usb_pd_port_count(void)
@@ -22,10 +27,39 @@ __override uint8_t board_get_usb_pd_port_count(void)
*/
static void board_init(void)
{
+ int ret;
+ uint32_t val;
+
+ /*
+ * Retrieve the tablet config.
+ */
+ ret = cros_cbi_get_fw_config(FW_TABLET, &val);
+ if (ret != 0) {
+ LOG_ERR("Error retrieving CBI FW_CONFIG field %d", FW_TABLET);
+ return;
+ }
+
/*
* Enable USB-C interrupts.
*/
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_usb_c0));
gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_usb_c1));
+
+ /*
+ * Disable tablet related interrupts for tablet absent DUT.
+ */
+ if (val == FW_TABLET_ABSENT) {
+ motion_sensor_count = 0;
+ gmr_tablet_switch_disable();
+ gpio_disable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_imu));
+ /* Base accel is not stuffed, don't allow line to float */
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_imu_int_l),
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ /* Lid accel is not stuffed, don't allow line to float */
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_acc_int_l),
+ GPIO_INPUT | GPIO_PULL_DOWN);
+ LOG_INF("Clameshell: Disable motion sensors and gmr sensor!");
+ } else
+ LOG_INF("Convertible!!!");
}
-DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_POST_I2C);