summaryrefslogtreecommitdiff
path: root/board/storo/board.c
diff options
context:
space:
mode:
Diffstat (limited to 'board/storo/board.c')
-rw-r--r--board/storo/board.c334
1 files changed, 156 insertions, 178 deletions
diff --git a/board/storo/board.c b/board/storo/board.c
index d7e0305d1f..f6f3ed5750 100644
--- a/board/storo/board.c
+++ b/board/storo/board.c
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -48,8 +48,8 @@
#include "usb_pd.h"
#include "usb_pd_tcpm.h"
-#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
-#define CPRINTF(format, args...) cprints(CC_SYSTEM, format, ## args)
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ##args)
+#define CPRINTF(format, args...) cprints(CC_SYSTEM, format, ##args)
#define INT_RECHECK_US 5000
@@ -139,34 +139,26 @@ static void pen_detect_interrupt(enum gpio_signal s)
/* ADC channels */
const struct adc_t adc_channels[] = {
- [ADC_VSNS_PP3300_A] = {
- .name = "PP3300_A_PGOOD",
- .factor_mul = ADC_MAX_MVOLT,
- .factor_div = ADC_READ_MAX + 1,
- .shift = 0,
- .channel = CHIP_ADC_CH0
- },
- [ADC_TEMP_SENSOR_1] = {
- .name = "TEMP_SENSOR1",
- .factor_mul = ADC_MAX_MVOLT,
- .factor_div = ADC_READ_MAX + 1,
- .shift = 0,
- .channel = CHIP_ADC_CH2
- },
- [ADC_TEMP_SENSOR_2] = {
- .name = "TEMP_SENSOR2",
- .factor_mul = ADC_MAX_MVOLT,
- .factor_div = ADC_READ_MAX + 1,
- .shift = 0,
- .channel = CHIP_ADC_CH3
- },
- [ADC_TEMP_SENSOR_3] = {
- .name = "TEMP_SENSOR3",
- .factor_mul = ADC_MAX_MVOLT,
- .factor_div = ADC_READ_MAX + 1,
- .shift = 0,
- .channel = CHIP_ADC_CH15
- },
+ [ADC_VSNS_PP3300_A] = { .name = "PP3300_A_PGOOD",
+ .factor_mul = ADC_MAX_MVOLT,
+ .factor_div = ADC_READ_MAX + 1,
+ .shift = 0,
+ .channel = CHIP_ADC_CH0 },
+ [ADC_TEMP_SENSOR_1] = { .name = "TEMP_SENSOR1",
+ .factor_mul = ADC_MAX_MVOLT,
+ .factor_div = ADC_READ_MAX + 1,
+ .shift = 0,
+ .channel = CHIP_ADC_CH2 },
+ [ADC_TEMP_SENSOR_2] = { .name = "TEMP_SENSOR2",
+ .factor_mul = ADC_MAX_MVOLT,
+ .factor_div = ADC_READ_MAX + 1,
+ .shift = 0,
+ .channel = CHIP_ADC_CH3 },
+ [ADC_TEMP_SENSOR_3] = { .name = "TEMP_SENSOR3",
+ .factor_mul = ADC_MAX_MVOLT,
+ .factor_div = ADC_READ_MAX + 1,
+ .shift = 0,
+ .channel = CHIP_ADC_CH15 },
};
BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT);
@@ -226,14 +218,7 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = {
};
/* USB Retimer */
-enum tusb544_conf {
- USB_DP = 0,
- USB_DP_INV,
- USB,
- USB_INV,
- DP,
- DP_INV
-};
+enum tusb544_conf { USB_DP = 0, USB_DP_INV, USB, USB_INV, DP, DP_INV };
/*
* Registers we care about of are all the same between NCS8510 and TUSB544,
@@ -246,33 +231,32 @@ enum tusb544_conf {
*/
static int board_tusb544_set(const struct usb_mux *me, mux_state_t mux_state)
{
- int rv = EC_SUCCESS;
+ int rv = EC_SUCCESS;
int reg;
enum tusb544_conf usb_mode = 0;
if (mux_state & USB_PD_MUX_USB_ENABLED) {
if (mux_state & USB_PD_MUX_DP_ENABLED) {
/* USB with DP */
- usb_mode = (mux_state & USB_PD_MUX_POLARITY_INVERTED)
- ? USB_DP_INV
- : USB_DP;
+ usb_mode = (mux_state & USB_PD_MUX_POLARITY_INVERTED) ?
+ USB_DP_INV :
+ USB_DP;
} else {
/* USB without DP */
- usb_mode = (mux_state & USB_PD_MUX_POLARITY_INVERTED)
- ? USB_INV
- : USB;
+ usb_mode = (mux_state & USB_PD_MUX_POLARITY_INVERTED) ?
+ USB_INV :
+ USB;
}
} else if (mux_state & USB_PD_MUX_DP_ENABLED) {
/* DP without USB */
- usb_mode = (mux_state & USB_PD_MUX_POLARITY_INVERTED)
- ? DP_INV
- : DP;
+ usb_mode = (mux_state & USB_PD_MUX_POLARITY_INVERTED) ? DP_INV :
+ DP;
} else {
return EC_SUCCESS;
}
- rv = i2c_read8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_GENERAL6, &reg);
+ rv = i2c_read8(me->i2c_port, me->i2c_addr_flags, TUSB544_REG_GENERAL6,
+ &reg);
if (rv)
return rv;
@@ -280,52 +264,52 @@ static int board_tusb544_set(const struct usb_mux *me, mux_state_t mux_state)
reg &= ~TUSB544_VOD_DCGAIN_SEL;
reg |= (TUSB544_VOD_DCGAIN_SETTING_5 << 2);
- rv = i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_GENERAL6, reg);
+ rv = i2c_write8(me->i2c_port, me->i2c_addr_flags, TUSB544_REG_GENERAL6,
+ reg);
if (rv)
return rv;
/* Write the retimer config byte */
if (usb_mode == USB_INV) {
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_GENERAL4, 0x15);
+ TUSB544_REG_GENERAL4, 0x15);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_USB3_1_1, 0xff);
+ TUSB544_REG_USB3_1_1, 0xff);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_USB3_1_2, 0xff);
+ TUSB544_REG_USB3_1_2, 0xff);
} else if (usb_mode == USB) {
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_GENERAL4, 0x11);
+ TUSB544_REG_GENERAL4, 0x11);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_USB3_1_1, 0xff);
+ TUSB544_REG_USB3_1_1, 0xff);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_USB3_1_2, 0xff);
+ TUSB544_REG_USB3_1_2, 0xff);
} else if (usb_mode == USB_DP_INV) {
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_GENERAL4, 0x1F);
+ TUSB544_REG_GENERAL4, 0x1F);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_USB3_1_1, 0xff);
+ TUSB544_REG_USB3_1_1, 0xff);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_USB3_1_2, 0xff);
+ TUSB544_REG_USB3_1_2, 0xff);
} else if (usb_mode == USB_DP) {
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_GENERAL4, 0x1B);
+ TUSB544_REG_GENERAL4, 0x1B);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_USB3_1_1, 0xff);
+ TUSB544_REG_USB3_1_1, 0xff);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_USB3_1_2, 0xff);
+ TUSB544_REG_USB3_1_2, 0xff);
} else if (usb_mode == DP_INV) {
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_GENERAL4, 0x1E);
+ TUSB544_REG_GENERAL4, 0x1E);
} else if (usb_mode == DP) {
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_GENERAL4, 0x1A);
+ TUSB544_REG_GENERAL4, 0x1A);
}
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_DISPLAYPORT_1, 0x66);
+ TUSB544_REG_DISPLAYPORT_1, 0x66);
rv |= i2c_write8(me->i2c_port, me->i2c_addr_flags,
- TUSB544_REG_DISPLAYPORT_2, 0x66);
+ TUSB544_REG_DISPLAYPORT_2, 0x66);
if (rv)
return EC_ERROR_UNKNOWN;
else
@@ -333,28 +317,37 @@ static int board_tusb544_set(const struct usb_mux *me, mux_state_t mux_state)
}
/* USB Retimer */
-const struct usb_mux usbc1_retimer = {
- .usb_port = 1,
- .i2c_port = I2C_PORT_SUB_USB_C1,
- .i2c_addr_flags = TUSB544_I2C_ADDR_FLAGS0,
- .driver = &tusb544_drv,
- .board_set = &board_tusb544_set,
+const struct usb_mux_chain usbc1_retimer = {
+ .mux =
+ &(const struct usb_mux){
+ .usb_port = 1,
+ .i2c_port = I2C_PORT_SUB_USB_C1,
+ .i2c_addr_flags = TUSB544_I2C_ADDR_FLAGS0,
+ .driver = &tusb544_drv,
+ .board_set = &board_tusb544_set,
+ },
};
/* USB Muxes */
-const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+const struct usb_mux_chain usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = {
{
- .usb_port = 0,
- .i2c_port = I2C_PORT_USB_C0,
- .i2c_addr_flags = IT5205_I2C_ADDR1_FLAGS,
- .driver = &it5205_usb_mux_driver,
+ .mux =
+ &(const struct usb_mux){
+ .usb_port = 0,
+ .i2c_port = I2C_PORT_USB_C0,
+ .i2c_addr_flags = IT5205_I2C_ADDR1_FLAGS,
+ .driver = &it5205_usb_mux_driver,
+ },
},
{
- .usb_port = 1,
- .i2c_port = I2C_PORT_SUB_USB_C1,
- .i2c_addr_flags = IT5205_I2C_ADDR1_FLAGS,
- .driver = &it5205_usb_mux_driver,
- .next_mux = &usbc1_retimer,
+ .mux =
+ &(const struct usb_mux){
+ .usb_port = 1,
+ .i2c_port = I2C_PORT_SUB_USB_C1,
+ .i2c_addr_flags = IT5205_I2C_ADDR1_FLAGS,
+ .driver = &it5205_usb_mux_driver,
+ },
+ .next = &usbc1_retimer,
},
};
@@ -461,8 +454,7 @@ int board_is_sourcing_vbus(int port)
int board_set_active_charge_port(int port)
{
- int is_real_port = (port >= 0 &&
- port < board_get_usb_pd_port_count());
+ int is_real_port = (port >= 0 && port < board_get_usb_pd_port_count());
int i;
int old_port;
@@ -526,9 +518,8 @@ int board_set_active_charge_port(int port)
return EC_SUCCESS;
}
-__override void ocpc_get_pid_constants(int *kp, int *kp_div,
- int *ki, int *ki_div,
- int *kd, int *kd_div)
+__override void ocpc_get_pid_constants(int *kp, int *kp_div, int *ki,
+ int *ki_div, int *kd, int *kd_div)
{
*kp = 3;
*kp_div = 14;
@@ -553,17 +544,13 @@ static struct mutex g_lid_mutex;
static struct mutex g_base_mutex;
/* Matrices to rotate accelerometers into the standard reference. */
-static const mat33_fp_t lid_standard_ref = {
- { 0, FLOAT_TO_FP(1), 0},
- { FLOAT_TO_FP(1), 0, 0},
- { 0, 0, FLOAT_TO_FP(-1)}
-};
+static const mat33_fp_t lid_standard_ref = { { 0, FLOAT_TO_FP(1), 0 },
+ { FLOAT_TO_FP(1), 0, 0 },
+ { 0, 0, FLOAT_TO_FP(-1) } };
-static const mat33_fp_t base_standard_ref = {
- { 0, FLOAT_TO_FP(1), 0},
- { FLOAT_TO_FP(-1), 0, 0},
- { 0, 0, FLOAT_TO_FP(1)}
-};
+static const mat33_fp_t base_standard_ref = { { 0, FLOAT_TO_FP(1), 0 },
+ { FLOAT_TO_FP(-1), 0, 0 },
+ { 0, 0, FLOAT_TO_FP(1) } };
static struct accelgyro_saved_data_t g_bma253_data;
static struct bmi_drv_data_t g_bmi160_data;
@@ -639,11 +626,9 @@ struct motion_sensor_t motion_sensors[] = {
unsigned int motion_sensor_count = ARRAY_SIZE(motion_sensors);
-static const mat33_fp_t lid_lis2dwl_ref = {
- { 0, FLOAT_TO_FP(1), 0},
- { FLOAT_TO_FP(1), 0, 0},
- { 0, 0, FLOAT_TO_FP(-1)}
-};
+static const mat33_fp_t lid_lis2dwl_ref = { { 0, FLOAT_TO_FP(1), 0 },
+ { FLOAT_TO_FP(1), 0, 0 },
+ { 0, 0, FLOAT_TO_FP(-1) } };
/* Lid accel private data */
static struct stprivate_data g_lis2dwl_data;
@@ -675,11 +660,9 @@ struct motion_sensor_t lis2dwl_lid_accel = {
},
};
-static const mat33_fp_t lid_KX022_ref = {
- { 0, FLOAT_TO_FP(1), 0},
- { FLOAT_TO_FP(1), 0, 0},
- { 0, 0, FLOAT_TO_FP(-1)}
-};
+static const mat33_fp_t lid_KX022_ref = { { 0, FLOAT_TO_FP(1), 0 },
+ { FLOAT_TO_FP(1), 0, 0 },
+ { 0, 0, FLOAT_TO_FP(-1) } };
static struct kionix_accel_data g_kx022_data;
struct motion_sensor_t kx022_lid_accel = {
@@ -710,11 +693,9 @@ struct motion_sensor_t kx022_lid_accel = {
};
static struct icm_drv_data_t g_icm42607_data;
-const mat33_fp_t based_ref_icm42607 = {
- { FLOAT_TO_FP(1), 0, 0},
- { 0, FLOAT_TO_FP(1), 0},
- { 0, 0, FLOAT_TO_FP(1)}
-};
+const mat33_fp_t based_ref_icm42607 = { { FLOAT_TO_FP(1), 0, 0 },
+ { 0, FLOAT_TO_FP(1), 0 },
+ { 0, 0, FLOAT_TO_FP(1) } };
struct motion_sensor_t icm42607_base_accel = {
.name = "Base Accel",
.active_mask = SENSOR_ACTIVE_S0_S3,
@@ -743,29 +724,26 @@ struct motion_sensor_t icm42607_base_accel = {
};
struct motion_sensor_t icm42607_base_gyro = {
- .name = "Base Gyro",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_ICM42607,
- .type = MOTIONSENSE_TYPE_GYRO,
- .location = MOTIONSENSE_LOC_BASE,
- .drv = &icm42607_drv,
- .mutex = &g_base_mutex,
- .drv_data = &g_icm42607_data,
- .port = I2C_PORT_ACCEL,
- .i2c_spi_addr_flags = ICM42607_ADDR0_FLAGS,
- .default_range = 1000, /* dps */
- .rot_standard_ref = &based_ref_icm42607,
- .min_frequency = ICM42607_GYRO_MIN_FREQ,
- .max_frequency = ICM42607_GYRO_MAX_FREQ,
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_ICM42607,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &icm42607_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_icm42607_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = ICM42607_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &based_ref_icm42607,
+ .min_frequency = ICM42607_GYRO_MIN_FREQ,
+ .max_frequency = ICM42607_GYRO_MAX_FREQ,
};
-
static struct bmi_drv_data_t g_bmi220_data;
-const mat33_fp_t based_ref_bmi220 = {
- { 0, FLOAT_TO_FP(1), 0},
- { FLOAT_TO_FP(-1), 0, 0},
- { 0, 0, FLOAT_TO_FP(1)}
-};
+const mat33_fp_t based_ref_bmi220 = { { 0, FLOAT_TO_FP(1), 0 },
+ { FLOAT_TO_FP(-1), 0, 0 },
+ { 0, 0, FLOAT_TO_FP(1) } };
struct motion_sensor_t bmi220_base_accel = {
.name = "Base Accel",
.active_mask = SENSOR_ACTIVE_S0_S3,
@@ -794,20 +772,20 @@ struct motion_sensor_t bmi220_base_accel = {
};
struct motion_sensor_t bmi220_base_gyro = {
- .name = "Base Gyro",
- .active_mask = SENSOR_ACTIVE_S0_S3,
- .chip = MOTIONSENSE_CHIP_BMI220,
- .type = MOTIONSENSE_TYPE_GYRO,
- .location = MOTIONSENSE_LOC_BASE,
- .drv = &bmi260_drv,
- .mutex = &g_base_mutex,
- .drv_data = &g_bmi220_data,
- .port = I2C_PORT_ACCEL,
- .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS,
- .default_range = 1000, /* dps */
- .rot_standard_ref = &based_ref_bmi220,
- .min_frequency = BMI_GYRO_MIN_FREQ,
- .max_frequency = BMI_GYRO_MAX_FREQ,
+ .name = "Base Gyro",
+ .active_mask = SENSOR_ACTIVE_S0_S3,
+ .chip = MOTIONSENSE_CHIP_BMI220,
+ .type = MOTIONSENSE_TYPE_GYRO,
+ .location = MOTIONSENSE_LOC_BASE,
+ .drv = &bmi260_drv,
+ .mutex = &g_base_mutex,
+ .drv_data = &g_bmi220_data,
+ .port = I2C_PORT_ACCEL,
+ .i2c_spi_addr_flags = BMI260_ADDR0_FLAGS,
+ .default_range = 1000, /* dps */
+ .rot_standard_ref = &based_ref_bmi220,
+ .min_frequency = BMI_GYRO_MIN_FREQ,
+ .max_frequency = BMI_GYRO_MAX_FREQ,
};
void board_init(void)
@@ -846,13 +824,13 @@ void board_init(void)
if (board_id > 2) {
if (get_cbi_fw_config_tablet_mode()) {
if (get_cbi_ssfc_base_sensor() ==
- SSFC_SENSOR_ICM42607) {
+ SSFC_SENSOR_ICM42607) {
motion_sensors[BASE_ACCEL] =
- icm42607_base_accel;
+ icm42607_base_accel;
motion_sensors[BASE_GYRO] = icm42607_base_gyro;
CPRINTF("BASE GYRO is ICM42607");
} else if (get_cbi_ssfc_base_sensor() ==
- SSFC_SENSOR_BMI220) {
+ SSFC_SENSOR_BMI220) {
motion_sensors[BASE_ACCEL] = bmi220_base_accel;
motion_sensors[BASE_GYRO] = bmi220_base_gyro;
CPRINTF("BASE GYRO is BMI220");
@@ -864,7 +842,7 @@ void board_init(void)
motion_sensors[LID_ACCEL] = lis2dwl_lid_accel;
CPRINTF("LID_ACCEL is LIS2DWL");
} else if (get_cbi_ssfc_lid_sensor() ==
- SSFC_SENSOR_KX022) {
+ SSFC_SENSOR_KX022) {
motion_sensors[LID_ACCEL] = kx022_lid_accel;
CPRINTF("LID_ACCEL is KX022");
} else {
@@ -878,7 +856,7 @@ void board_init(void)
* line to float.
*/
gpio_set_flags(GPIO_BASE_SIXAXIS_INT_L,
- GPIO_INPUT | GPIO_PULL_DOWN);
+ GPIO_INPUT | GPIO_PULL_DOWN);
}
} else {
if (get_cbi_ssfc_base_sensor() == SSFC_SENSOR_ICM42607) {
@@ -908,34 +886,34 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
void motion_interrupt(enum gpio_signal signal)
{
- switch (get_cbi_ssfc_base_sensor()) {
- case SSFC_SENSOR_ICM42607:
- icm42607_interrupt(signal);
- break;
- case SSFC_SENSOR_BMI220:
- bmi260_interrupt(signal);
- break;
- case SSFC_SENSOR_BMI160:
- default:
- bmi160_interrupt(signal);
- break;
- }
+ switch (get_cbi_ssfc_base_sensor()) {
+ case SSFC_SENSOR_ICM42607:
+ icm42607_interrupt(signal);
+ break;
+ case SSFC_SENSOR_BMI220:
+ bmi260_interrupt(signal);
+ break;
+ case SSFC_SENSOR_BMI160:
+ default:
+ bmi160_interrupt(signal);
+ break;
+ }
}
/* Thermistors */
const struct temp_sensor_t temp_sensors[] = {
- [TEMP_SENSOR_1] = {.name = "Memory",
- .type = TEMP_SENSOR_TYPE_BOARD,
- .read = get_temp_3v3_51k1_47k_4050b,
- .idx = ADC_TEMP_SENSOR_1},
- [TEMP_SENSOR_2] = {.name = "Ambient",
- .type = TEMP_SENSOR_TYPE_BOARD,
- .read = get_temp_3v3_51k1_47k_4050b,
- .idx = ADC_TEMP_SENSOR_2},
- [TEMP_SENSOR_3] = {.name = "Cpu",
- .type = TEMP_SENSOR_TYPE_BOARD,
- .read = get_temp_3v3_51k1_47k_4050b,
- .idx = ADC_TEMP_SENSOR_3},
+ [TEMP_SENSOR_1] = { .name = "Memory",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_1 },
+ [TEMP_SENSOR_2] = { .name = "Ambient",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_2 },
+ [TEMP_SENSOR_3] = { .name = "Cpu",
+ .type = TEMP_SENSOR_TYPE_BOARD,
+ .read = get_temp_3v3_51k1_47k_4050b,
+ .idx = ADC_TEMP_SENSOR_3 },
};
BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT);