summaryrefslogtreecommitdiff
path: root/board/bobba/board.c
diff options
context:
space:
mode:
authorJustin TerAvest <teravest@chromium.org>2018-06-29 14:58:48 -0600
committerchrome-bot <chrome-bot@chromium.org>2018-07-02 15:32:46 -0700
commita2ef0dabfcec633d92d40a817b31dd167246bc3c (patch)
tree561a518a8c5411d57d5f65bffcd8b1fa3570249b /board/bobba/board.c
parent90e5f21c4e104aa7861875dd4b66f2828a578fbb (diff)
downloadchrome-ec-a2ef0dabfcec633d92d40a817b31dd167246bc3c.tar.gz
bobba: initial files commit
The contents of Bobba are copied from yorp, with the exception of board.c and gpio.inc, which were modified to always use V1 settings. Bobba proto is equivalent to yorp proto2. BRANCH=none BUG=b:110781720 TEST=build Change-Id: I10937ef6eb8b20fc5e58c3871c679fc80bdcca70 Signed-off-by: Justin TerAvest <teravest@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1121110 Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'board/bobba/board.c')
-rw-r--r--board/bobba/board.c234
1 files changed, 234 insertions, 0 deletions
diff --git a/board/bobba/board.c b/board/bobba/board.c
new file mode 100644
index 0000000000..c106971a87
--- /dev/null
+++ b/board/bobba/board.c
@@ -0,0 +1,234 @@
+/* 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.
+ */
+
+/* Bobba board-specific configuration */
+
+#include "adc.h"
+#include "adc_chip.h"
+#include "battery.h"
+#include "charge_manager.h"
+#include "charge_state.h"
+#include "common.h"
+#include "cros_board_info.h"
+#include "driver/accel_kionix.h"
+#include "driver/accelgyro_lsm6dsm.h"
+#include "driver/bc12/bq24392.h"
+#include "driver/charger/bd9995x.h"
+#include "driver/ppc/nx20p3483.h"
+#include "driver/tcpm/anx7447.h"
+#include "driver/tcpm/ps8xxx.h"
+#include "driver/tcpm/tcpci.h"
+#include "driver/tcpm/tcpm.h"
+#include "extpower.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "i2c.h"
+#include "keyboard_scan.h"
+#include "lid_switch.h"
+#include "motion_sense.h"
+#include "power.h"
+#include "power_button.h"
+#include "switch.h"
+#include "system.h"
+#include "tablet_mode.h"
+#include "tcpci.h"
+#include "temp_sensor.h"
+#include "thermistor.h"
+#include "usb_mux.h"
+#include "usbc_ppc.h"
+#include "util.h"
+
+#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTFUSB(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
+static void tcpc_alert_event(enum gpio_signal signal)
+{
+ if ((signal == GPIO_USB_C1_MUX_INT_ODL) &&
+ !gpio_get_level(GPIO_USB_C1_PD_RST_ODL))
+ return;
+
+#ifdef HAS_TASK_PDCMD
+ /* Exchange status with TCPCs */
+ host_command_pd_send_status(PD_CHARGE_NO_CHANGE);
+#endif
+}
+
+static void ppc_interrupt(enum gpio_signal signal)
+{
+ switch (signal) {
+ case GPIO_USB_PD_C0_INT_ODL:
+ nx20p3483_interrupt(0);
+ break;
+
+ case GPIO_USB_PD_C1_INT_ODL:
+ nx20p3483_interrupt(1);
+ break;
+
+ default:
+ break;
+ }
+}
+
+/* Must come after other header files and GPIO interrupts*/
+#include "gpio_list.h"
+
+/* ADC channels */
+const struct adc_t adc_channels[] = {
+ [ADC_TEMP_SENSOR_AMB] = {
+ "TEMP_AMB", NPCX_ADC_CH0, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+ [ADC_TEMP_SENSOR_CHARGER] = {
+ "TEMP_CHARGER", NPCX_ADC_CH1, ADC_MAX_VOLT, ADC_READ_MAX+1, 0},
+};
+BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
+
+const struct temp_sensor_t temp_sensors[] = {
+ [TEMP_SENSOR_BATTERY] = {.name = "Battery",
+ .type = TEMP_SENSOR_TYPE_BATTERY,
+ .read = charge_get_battery_temp,
+ .idx = 0,
+ .action_delay_sec = 1},
+ [TEMP_SENSOR_AMBIENT] = {.name = "Ambient",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_AMB,
+ .action_delay_sec = 5},
+ [TEMP_SENSOR_CHARGER] = {.name = "Charger",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_13k7_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_CHARGER,
+ .action_delay_sec = 1},
+};
+BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);
+
+/* Motion sensors */
+/* Mutexes */
+static struct mutex g_lid_mutex;
+static struct mutex g_base_mutex;
+
+/* Matrix to rotate accelrator into standard reference frame */
+const matrix_3x3_t base_standard_ref = {
+ { 0, FLOAT_TO_FP(-1), 0},
+ { FLOAT_TO_FP(1), 0, 0},
+ { 0, 0, FLOAT_TO_FP(1)}
+};
+
+/* sensor private data */
+static struct kionix_accel_data g_kx022_data;
+static struct lsm6dsm_data lsm6dsm_g_data;
+static struct lsm6dsm_data lsm6dsm_a_data;
+
+/* Drivers */
+struct motion_sensor_t motion_sensors[] = {
+ [LID_ACCEL] = {
+ .name = "Lid Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_KX022,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_LID,
+ .drv = &kionix_accel_drv,
+ .mutex = &g_lid_mutex,
+ .drv_data = &g_kx022_data,
+ .port = I2C_PORT_SENSOR,
+ .addr = KX022_ADDR1,
+ .rot_standard_ref = NULL, /* Identity matrix. */
+ .default_range = 4, /* g */
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ /* Sensor on for lid angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ },
+ },
+ },
+
+ [BASE_ACCEL] = {
+ .name = "Base Accel",
+ .active_mask = SENSOR_ACTIVE_S0_S3_S5,
+ .chip = MOTIONSENSE_CHIP_LSM6DSM,
+ .type = MOTIONSENSE_TYPE_ACCEL,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &lsm6dsm_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &lsm6dsm_a_data,
+ .port = I2C_PORT_SENSOR,
+ .addr = LSM6DSM_ADDR0,
+ .rot_standard_ref = &base_standard_ref,
+ .default_range = 4, /* g */
+ .min_frequency = LSM6DSM_ODR_MIN_VAL,
+ .max_frequency = LSM6DSM_ODR_MAX_VAL,
+ .config = {
+ /* EC use accel for angle detection */
+ [SENSOR_CONFIG_EC_S0] = {
+ .odr = 13000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ /* Sensor on for angle detection */
+ [SENSOR_CONFIG_EC_S3] = {
+ .odr = 10000 | ROUND_UP_FLAG,
+ .ec_rate = 100 * MSEC,
+ },
+ },
+ },
+
+ [BASE_GYRO] = {
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0,
+ .chip = MOTIONSENSE_CHIP_LSM6DSM,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &lsm6dsm_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &lsm6dsm_g_data,
+ .port = I2C_PORT_SENSOR,
+ .addr = LSM6DSM_ADDR0,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &base_standard_ref,
+ .min_frequency = LSM6DSM_ODR_MIN_VAL,
+ .max_frequency = LSM6DSM_ODR_MAX_VAL,
+ },
+};
+
+const unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
+
+/* Initialize board. */
+static void board_init(void)
+{
+ /* Enable Base Accel interrupt */
+ gpio_enable_interrupt(GPIO_BASE_SIXAXIS_INT_L);
+}
+DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
+
+void board_hibernate_late(void) {
+
+ int i;
+
+ const uint32_t hibernate_pins[][2] = {
+ /* Turn off LEDs before going to hibernate */
+ {GPIO_BAT_LED_BLUE_L, GPIO_INPUT | GPIO_PULL_UP},
+ {GPIO_BAT_LED_ORANGE_L, GPIO_INPUT | GPIO_PULL_UP},
+ };
+
+ for (i = 0; i < ARRAY_SIZE(hibernate_pins); ++i)
+ gpio_set_flags(hibernate_pins[i][0], hibernate_pins[i][1]);
+}
+
+#ifndef TEST_BUILD
+/* This callback disables keyboard when convertibles are fully open */
+void lid_angle_peripheral_enable(int enable)
+{
+ /*
+ * If the lid is in tablet position via other sensors,
+ * ignore the lid angle, which might be faulty then
+ * disable keyboard.
+ */
+ if (tablet_get_mode())
+ enable = 0;
+
+ keyboard_scan_enable(enable, KB_SCAN_DISABLE_LID_ANGLE);
+}
+#endif