From 2028b095c0f0474752fb9b880ee415fd538047cb Mon Sep 17 00:00:00 2001 From: "YongBeum.Ha" Date: Tue, 3 Aug 2021 11:13:18 +0900 Subject: bugzzy : modify EC Modify EC for buggzy based on schemetics. BUG=b:192521391,b:194554146 BRANCH=None TEST=make -j BOARD=bugzzy Signed-off-by: YongBeum.Ha Change-Id: Ia0dad01f71c9a3db671427aadde286d18b2c1677 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3068484 Reviewed-by: Aseda Aboagye --- board/bugzzy/battery.c | 113 ++++++++++++++++++++----- board/bugzzy/board.c | 222 ++++++++++++++++++++++++++++++------------------- board/bugzzy/board.h | 61 ++++++++------ board/bugzzy/gpio.inc | 46 +++++----- board/bugzzy/led.c | 159 ++++++++++++++++++++++++----------- 5 files changed, 399 insertions(+), 202 deletions(-) (limited to 'board/bugzzy') diff --git a/board/bugzzy/battery.c b/board/bugzzy/battery.c index 12ec2c42aa..5f6c54cb9a 100644 --- a/board/bugzzy/battery.c +++ b/board/bugzzy/battery.c @@ -8,9 +8,12 @@ #include "battery_fuel_gauge.h" #include "charge_state.h" #include "common.h" +#include "hooks.h" +#include "usb_pd.h" +#include "util.h" /* - * Battery info for all waddledoo battery types. Note that the fields + * Battery info for all bugzzy battery types. Note that the fields * start_charging_min/max and charging_min/max are not used for the charger. * The effective temperature limits are given by discharging_min/max_c. * @@ -30,37 +33,105 @@ * The assumption for battery types supported is that the charge/discharge FET * status can be read with a sb_read() command and therefore, only the register * address, mask, and disconnect value need to be provided. + * + * Battery FET Status in Manufacture Access : bit15 & bit14 + * b'00 - dfet : on / cfet : on + * b'01 - dfet : on / cfet : off + * b'10 - dfet : off / cfet : off + * b'11 - dfet : off / cfet : on + * The value b'10 is disconnect_val, so we can use b'01 for cfet_off_val */ + +/* charging current is limited to 0.45C */ +#define CHARGING_CURRENT_45C 2804 + const struct board_batt_params board_battery_info[] = { - /* POW-TECH Battery Information */ - [BATTERY_POWER_TECH] = { + /* SDI Battery Information */ + [BATTERY_SDI] = { .fuel_gauge = { - .manuf_name = "POW-TECH", + .manuf_name = "SDI", + .device_name = "4404D57", .ship_mode = { - .reg_addr = 0x0, - .reg_data = { 0x10, 0x10 }, + .reg_addr = 0x00, + .reg_data = { 0x0010, 0x0010 }, }, .fet = { - .reg_addr = 0x00, - .reg_mask = 0x2000, - .disconnect_val = 0x2000, + .mfgacc_support = 0, + .reg_addr = 0x00, + .reg_mask = 0xc000, + .disconnect_val = 0x8000, + .cfet_mask = 0xc000, + .cfet_off_val = 0x2000, } }, .batt_info = { - .voltage_max = 8800, /* mV */ - .voltage_normal = 7700, - .voltage_min = 6000, - .precharge_current = 160, /* mA */ - .start_charging_min_c = 0, - .start_charging_max_c = 45, - .charging_min_c = 0, - .charging_max_c = 45, - .discharging_min_c = -20, - .discharging_max_c = 60, + .voltage_max = 8800, + .voltage_normal = 7700, /* mV */ + .voltage_min = 6000, /* mV */ + .precharge_current = 200, /* mA */ + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 55, + .discharging_min_c = -20, + .discharging_max_c = 70, }, - }, }; BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); -const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_POWER_TECH; +const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_SDI; + +int charger_profile_override(struct charge_state_data *curr) +{ + if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) + return 0; + + if (curr->requested_current > CHARGING_CURRENT_45C) + curr->requested_current = CHARGING_CURRENT_45C; + + return 0; +} + +/* Customs options controllable by host command. */ +#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0) + +enum ec_status charger_profile_override_get_param(uint32_t param, + uint32_t *value) +{ + return EC_RES_INVALID_PARAM; +} + +enum ec_status charger_profile_override_set_param(uint32_t param, + uint32_t value) +{ + return EC_RES_INVALID_PARAM; +} + +/* Lower our input voltage to 5V in S0iX when battery is full. */ +#define PD_VOLTAGE_WHEN_FULL 5000 +static void reduce_input_voltage_when_full(void) +{ + static int saved_input_voltage = -1; + int max_pd_voltage_mv = pd_get_max_voltage(); + int port; + + if (charge_get_percent() == 100 && + chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) { + if (max_pd_voltage_mv != PD_VOLTAGE_WHEN_FULL) { + saved_input_voltage = max_pd_voltage_mv; + max_pd_voltage_mv = PD_VOLTAGE_WHEN_FULL; + } + } else if (saved_input_voltage != -1) { + if (max_pd_voltage_mv == PD_VOLTAGE_WHEN_FULL) + max_pd_voltage_mv = saved_input_voltage; + saved_input_voltage = -1; + } + + if (pd_get_max_voltage() != max_pd_voltage_mv) { + for (port = 0; port < CONFIG_USB_PD_PORT_MAX_COUNT; port++) + pd_set_external_voltage_limit(port, max_pd_voltage_mv); + } +} +DECLARE_HOOK(HOOK_SECOND, reduce_input_voltage_when_full, + HOOK_PRIO_DEFAULT); diff --git a/board/bugzzy/board.c b/board/bugzzy/board.c index 4828232e0a..95ce46db44 100644 --- a/board/bugzzy/board.c +++ b/board/bugzzy/board.c @@ -14,30 +14,31 @@ #include "chipset.h" #include "common.h" #include "compile_time_macros.h" -#include "driver/accel_bma2x2.h" +#include "cros_board_info.h" +#include "driver/accel_lis2ds.h" #include "driver/accelgyro_bmi_common.h" #include "driver/bc12/pi3usb9201.h" #include "driver/charger/isl923x.h" -#include "driver/retimer/nb7v904m.h" #include "driver/tcpm/raa489000.h" #include "driver/tcpm/tcpci.h" -#include "driver/usb_mux/pi3usb3x532.h" +#include "driver/temp_sensor/thermistor.h" +#include "driver/usb_mux/ps8743.h" #include "extpower.h" #include "gpio.h" #include "hooks.h" #include "i2c.h" +#include "keyboard_8042.h" #include "keyboard_scan.h" #include "lid_switch.h" #include "motion_sense.h" #include "power.h" #include "power_button.h" -#include "pwm.h" -#include "pwm_chip.h" #include "stdbool.h" #include "switch.h" #include "system.h" #include "tablet_mode.h" #include "task.h" +#include "temp_sensor.h" #include "usb_mux.h" #include "usb_pd.h" #include "usb_pd_tcpm.h" @@ -146,6 +147,20 @@ const struct adc_t adc_channels[] = { .factor_div = ADC_READ_MAX + 1, .shift = 0, }, + [ADC_TEMP_SENSOR_3] = { + .name = "TEMP_SENSOR3", + .input_ch = NPCX_ADC_CH5, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, + [ADC_TEMP_SENSOR_4] = { + .name = "TEMP_SENSOR4", + .input_ch = NPCX_ADC_CH6, + .factor_mul = ADC_MAX_VOLT, + .factor_div = ADC_READ_MAX + 1, + .shift = 0, + }, [ADC_SUB_ANALOG] = { .name = "SUB_ANALOG", .input_ch = NPCX_ADC_CH2, @@ -163,6 +178,28 @@ const struct adc_t adc_channels[] = { }; BUILD_ASSERT(ARRAY_SIZE(adc_channels) == ADC_CH_COUNT); +/* 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 = "Charger", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = get_temp_3v3_51k1_47k_4050b, + .idx = ADC_TEMP_SENSOR_2}, + [TEMP_SENSOR_3] = {.name = "Skin1", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = get_temp_3v3_51k1_47k_4050b, + .idx = ADC_TEMP_SENSOR_3}, + [TEMP_SENSOR_4] = {.name = "Skin2", + .type = TEMP_SENSOR_TYPE_BOARD, + .read = get_temp_3v3_51k1_47k_4050b, + .idx = ADC_TEMP_SENSOR_4}, +}; +BUILD_ASSERT(ARRAY_SIZE(temp_sensors) == TEMP_SENSOR_COUNT); + + void board_init(void) { int on; @@ -231,7 +268,7 @@ void board_hibernate(void) */ if (board_get_charger_chip_count() > 1) raa489000_hibernate(1, true); - raa489000_hibernate(0, true); + raa489000_hibernate(0, false); } void board_reset_pd_mcu(void) @@ -242,45 +279,9 @@ void board_reset_pd_mcu(void) */ } -#ifdef BOARD_WADDLEDOO -static void reconfigure_5v_gpio(void) -{ - /* - * b/147257497: On early waddledoo boards, GPIO_EN_PP5000 was swapped - * with GPIO_VOLUP_BTN_ODL. Therefore, we'll actually need to set that - * GPIO instead for those boards. Note that this breaks the volume up - * button functionality. - */ - if (system_get_board_version() < 0) { - CPRINTS("old board - remapping 5V en"); - gpio_set_flags(GPIO_VOLUP_BTN_ODL, GPIO_OUT_LOW); - } -} -DECLARE_HOOK(HOOK_INIT, reconfigure_5v_gpio, HOOK_PRIO_INIT_I2C+1); -#endif /* BOARD_WADDLEDOO */ - static void set_5v_gpio(int level) { - int version; - enum gpio_signal gpio = GPIO_EN_PP5000; - - /* - * b/147257497: On early waddledoo boards, GPIO_EN_PP5000 was swapped - * with GPIO_VOLUP_BTN_ODL. Therefore, we'll actually need to set that - * GPIO instead for those boards. Note that this breaks the volume up - * button functionality. - */ - if (IS_ENABLED(BOARD_WADDLEDOO)) { - version = system_get_board_version(); - - /* - * If the CBI EEPROM wasn't formatted, assume it's a very early - * board. - */ - gpio = version < 0 ? GPIO_VOLUP_BTN_ODL : GPIO_EN_PP5000; - } - - gpio_set_level(gpio, level); + gpio_set_level(GPIO_EN_PP5000, level); } __override void board_power_5v_enable(int enable) @@ -433,31 +434,33 @@ static const mat33_fp_t base_standard_ref = { { 0, 0, FLOAT_TO_FP(1)} }; -static struct accelgyro_saved_data_t g_bma253_data; +static struct stprivate_data g_lis2ds_data; static struct bmi_drv_data_t g_bmi160_data; struct motion_sensor_t motion_sensors[] = { [LID_ACCEL] = { .name = "Lid Accel", .active_mask = SENSOR_ACTIVE_S0_S3, - .chip = MOTIONSENSE_CHIP_BMA255, + .chip = MOTIONSENSE_CHIP_LIS2DS, .type = MOTIONSENSE_TYPE_ACCEL, .location = MOTIONSENSE_LOC_LID, - .drv = &bma2x2_accel_drv, + .drv = &lis2ds_drv, .mutex = &g_lid_mutex, - .drv_data = &g_bma253_data, + .drv_data = &g_lis2ds_data, .port = I2C_PORT_SENSOR, - .i2c_spi_addr_flags = BMA2x2_I2C_ADDR1_FLAGS, + .i2c_spi_addr_flags = LIS2DS_ADDR1_FLAGS, .rot_standard_ref = &lid_standard_ref, - .default_range = 2, - .min_frequency = BMA255_ACCEL_MIN_FREQ, - .max_frequency = BMA255_ACCEL_MAX_FREQ, + .min_frequency = LIS2DS_ODR_MIN_VAL, + .max_frequency = LIS2DS_ODR_MAX_VAL, + .default_range = 2, /* g, to support lid angle calculation. */ .config = { + /* EC use accel for angle detection */ [SENSOR_CONFIG_EC_S0] = { - .odr = 10000 | ROUND_UP_FLAG, + .odr = 12500 | ROUND_UP_FLAG, }, + /* Sensor on in S3 */ [SENSOR_CONFIG_EC_S3] = { - .odr = 10000 | ROUND_UP_FLAG, + .odr = 12500 | ROUND_UP_FLAG, }, }, }, @@ -552,28 +555,6 @@ const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = { }, }; -/* PWM channels. Must be in the exactly same order as in enum pwm_channel. */ -const struct pwm_t pwm_channels[] = { - [PWM_CH_KBLIGHT] = { - .channel = 3, - .flags = PWM_CONFIG_DSLEEP, - .freq = 10000, - }, - - [PWM_CH_LED1_AMBER] = { - .channel = 2, - .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW, - .freq = 2400, - }, - - [PWM_CH_LED2_WHITE] = { - .channel = 0, - .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW, - .freq = 2400, - } -}; -BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); - const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { { .bus_type = EC_BUS_TYPE_I2C, @@ -596,27 +577,43 @@ const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { }, }; -const struct usb_mux usbc1_retimer = { - .usb_port = 1, - .i2c_port = I2C_PORT_SUB_USB_C1, - .i2c_addr_flags = NB7V904M_I2C_ADDR0, - .driver = &nb7v904m_usb_redriver_drv, -}; +static int ps8743_tune_mux_c0(const struct usb_mux *me); +static int ps8743_tune_mux_c1(const struct usb_mux *me); + const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = { { .usb_port = 0, .i2c_port = I2C_PORT_USB_C0, - .i2c_addr_flags = PI3USB3X532_I2C_ADDR0, - .driver = &pi3usb3x532_usb_mux_driver, + .i2c_addr_flags = PS8743_I2C_ADDR0_FLAG, + .driver = &ps8743_usb_mux_driver, + .board_init = &ps8743_tune_mux_c0, }, { .usb_port = 1, .i2c_port = I2C_PORT_SUB_USB_C1, - .i2c_addr_flags = PI3USB3X532_I2C_ADDR0, - .driver = &pi3usb3x532_usb_mux_driver, - .next_mux = &usbc1_retimer, + .i2c_addr_flags = PS8743_I2C_ADDR0_FLAG, + .driver = &ps8743_usb_mux_driver, + .board_init = &ps8743_tune_mux_c1, } }; +/* USB Mux C0 : board_init of PS8743 */ +static int ps8743_tune_mux_c0(const struct usb_mux *me) +{ + ps8743_tune_usb_eq(me, + PS8743_USB_EQ_TX_3_6_DB, + PS8743_USB_EQ_RX_16_0_DB); + + return EC_SUCCESS; +} +/* USB Mux C1 : board_init of PS8743 */ +static int ps8743_tune_mux_c1(const struct usb_mux *me) +{ + ps8743_tune_usb_eq(me, + PS8743_USB_EQ_TX_3_6_DB, + PS8743_USB_EQ_RX_16_0_DB); + + return EC_SUCCESS; +} uint16_t tcpc_get_alert_status(void) { @@ -653,6 +650,32 @@ uint16_t tcpc_get_alert_status(void) return status; } +static const struct ec_response_keybd_config keybd1 = { + .num_top_row_keys = 10, + .action_keys = { + TK_BACK, /* T1 */ + TK_FORWARD, /* T2 */ + TK_REFRESH, /* T3 */ + TK_FULLSCREEN, /* T4 */ + TK_OVERVIEW, /* T5 */ + TK_BRIGHTNESS_DOWN, /* T6 */ + TK_BRIGHTNESS_UP, /* T7 */ + TK_VOL_MUTE, /* T8 */ + TK_VOL_DOWN, /* T9 */ + TK_VOL_UP, /* T10 */ + }, + /* No function keys, no numeric keypad, has screenlock key */ + .capabilities = KEYBD_CAP_SCRNLOCK_KEY, +}; +__override const struct ec_response_keybd_config +*board_vivaldi_keybd_config(void) +{ + /* + * Future boards should use fw_config if needed. + */ + + return &keybd1; +} #ifndef TEST_BUILD /* This callback disables keyboard when convertibles are fully open */ @@ -681,3 +704,30 @@ void lid_angle_peripheral_enable(int enable) } } #endif +/** + * Enable panel power detection + */ +static void panel_power_detect_init(void) +{ + gpio_enable_interrupt(GPIO_EN_PP1800_PANEL_S0); +} +DECLARE_HOOK(HOOK_INIT, panel_power_detect_init, HOOK_PRIO_DEFAULT); + +/** + * Handle VPN / VSN for mipi display. + */ +static void panel_power_change_deferred(void) +{ + int signal = gpio_get_level(GPIO_EN_PP1800_PANEL_S0); + + gpio_set_level(GPIO_EN_LCD_ENP, signal); + msleep(1); + gpio_set_level(GPIO_EN_LCD_ENN, signal); +} +DECLARE_DEFERRED(panel_power_change_deferred); + +void panel_power_change_interrupt(enum gpio_signal signal) +{ + /* Reset lid debounce time */ + hook_call_deferred(&panel_power_change_deferred_data, 1 * MSEC); +} diff --git a/board/bugzzy/board.h b/board/bugzzy/board.h index 0ee270a453..6954d9d524 100644 --- a/board/bugzzy/board.h +++ b/board/bugzzy/board.h @@ -29,6 +29,7 @@ #undef CONFIG_CMD_BATTFAKE /* EC console commands */ +#define CONFIG_CMD_TCPC_DUMP #define CONFIG_CMD_CHARGER_DUMP /* Battery */ @@ -40,9 +41,12 @@ #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_OCPC_DEF_RBATT_MOHMS 22 /* R_DS(on) 11.6mOhm + 10mOhm sns rstr */ #define CONFIG_OCPC +#define CONFIG_CHARGER_PROFILE_OVERRIDE +#define CONFIG_CHARGE_RAMP_HW #undef CONFIG_CHARGER_SINGLE_CHIP #undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE #define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC) +#define CONFIG_BATTERY_CHECK_CHARGE_TEMP_LIMITS /* * GPIO for C1 interrupts, for baseboard use @@ -53,31 +57,33 @@ #define GPIO_USB_C1_INT_ODL GPIO_SUB_C1_INT_EN_RAILS_ODL /* Keyboard */ -#define CONFIG_PWM_KBLIGHT /* LED */ -#define CONFIG_LED_PWM -#define CONFIG_LED_PWM_COUNT 1 -#undef CONFIG_LED_PWM_NEAR_FULL_COLOR -#undef CONFIG_LED_PWM_SOC_ON_COLOR -#undef CONFIG_LED_PWM_SOC_SUSPEND_COLOR -#undef CONFIG_LED_PWM_LOW_BATT_COLOR -#define CONFIG_LED_PWM_NEAR_FULL_COLOR EC_LED_COLOR_WHITE -#define CONFIG_LED_PWM_SOC_ON_COLOR EC_LED_COLOR_WHITE -#define CONFIG_LED_PWM_SOC_SUSPEND_COLOR EC_LED_COLOR_WHITE -#define CONFIG_LED_PWM_LOW_BATT_COLOR EC_LED_COLOR_AMBER +#define CONFIG_LED_COMMON +#define CONFIG_LED_ONOFF_STATES +#define GPIO_BAT_LED_RED_L GPIO_LED_R_ODL +#define GPIO_BAT_LED_GREEN_L GPIO_LED_G_ODL +#define GPIO_PWR_LED_BLUE_L GPIO_LED_B_ODL + /* PWM */ -#define CONFIG_PWM -#define NPCX7_PWM1_SEL 1 /* GPIO C2 is used as PWM1. */ +#define NPCX7_PWM1_SEL 0 /* GPIO C2 is not used as PWM1. */ + +/* Thermistors */ +#define CONFIG_TEMP_SENSOR +#define CONFIG_THERMISTOR +#define CONFIG_STEINHART_HART_3V3_51K1_47K_4050B /* USB */ #define CONFIG_BC12_DETECT_PI3USB9201 -#define CONFIG_USBC_RETIMER_NB7V904M +#define CONFIG_USB_MUX_PS8743 /* USB PD */ #define CONFIG_USB_PD_PORT_MAX_COUNT 2 #define CONFIG_USB_PD_TCPM_RAA489000 +#undef CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE +#define CONFIG_USB_PD_TCPC_LPM_EXIT_DEBOUNCE (100 * MSEC) +#define CONFIG_USB_PD_COMM_LOCKED /* USB defines specific to external TCPCs */ #define CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE @@ -97,7 +103,6 @@ #undef CONFIG_USBC_VCONN_SWAP_DELAY_US #define CONFIG_USBC_VCONN_SWAP_DELAY_US 787 /* us */ - /* I2C configuration */ #define I2C_PORT_EEPROM NPCX_I2C_PORT7_0 #define I2C_PORT_BATTERY NPCX_I2C_PORT5_0 @@ -125,7 +130,6 @@ #define CONFIG_CMD_ACCELS #define CONFIG_CMD_ACCEL_INFO -#define CONFIG_ACCEL_BMA255 /* Lid accel */ #define CONFIG_ACCELGYRO_BMI160 /* Base accel */ /* Lid operates in forced mode, base in FIFO */ @@ -147,6 +151,11 @@ #define CONFIG_TABLET_MODE_SWITCH #define CONFIG_GMR_TABLET_MODE +/* LIS2DS Lid accel */ +#define CONFIG_ACCEL_LIS2DS +#define CONFIG_ACCEL_LIS2DS_INT_EVENT \ + TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL) + #ifndef __ASSEMBLER__ #include "gpio_signal.h" @@ -158,9 +167,19 @@ enum chg_id { CHARGER_NUM, }; +enum temp_sensor_id { + TEMP_SENSOR_1, + TEMP_SENSOR_2, + TEMP_SENSOR_3, + TEMP_SENSOR_4, + TEMP_SENSOR_COUNT +}; + enum adc_channel { ADC_TEMP_SENSOR_1, /* ADC0 */ ADC_TEMP_SENSOR_2, /* ADC1 */ + ADC_TEMP_SENSOR_3, /* ADC5 */ + ADC_TEMP_SENSOR_4, /* ADC6 */ ADC_SUB_ANALOG, /* ADC2 */ ADC_VSNS_PP3300_A, /* ADC9 */ ADC_CH_COUNT @@ -173,18 +192,12 @@ enum sensor_id { SENSOR_COUNT }; -enum pwm_channel { - PWM_CH_KBLIGHT, - PWM_CH_LED1_AMBER, - PWM_CH_LED2_WHITE, - PWM_CH_COUNT, -}; - /* List of possible batteries */ enum battery_type { - BATTERY_POWER_TECH, + BATTERY_SDI, BATTERY_TYPE_COUNT, }; +void panel_power_change_interrupt(enum gpio_signal signal); #endif /* !__ASSEMBLER__ */ #endif /* __CROS_EC_BOARD_H */ diff --git a/board/bugzzy/gpio.inc b/board/bugzzy/gpio.inc index 78d41aab16..9d5cc2d932 100644 --- a/board/bugzzy/gpio.inc +++ b/board/bugzzy/gpio.inc @@ -31,14 +31,15 @@ GPIO_INT(EC_I2C_SUB_C1_SDA_HDMI_HPD_ODL, PIN(9, 1), GPIO_INT_BOTH, sub_hdmi_hpd_ /* Button interrupts */ GPIO_INT(H1_EC_PWR_BTN_ODL, PIN(0, 1), GPIO_INT_BOTH | GPIO_PULL_UP, power_button_interrupt) -GPIO_INT(VOLDN_BTN_ODL, PIN(4, 0), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) -GPIO_INT(VOLUP_BTN_ODL, PIN(7, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) +GPIO_INT(VOLDN_BTN_ODL, PIN(4, 0), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) +GPIO_INT(VOLUP_BTN_ODL, PIN(7, 3), GPIO_INT_BOTH | GPIO_PULL_UP, button_interrupt) /* Other interrupts */ GPIO_INT(LID_OPEN, PIN(D, 2), GPIO_INT_BOTH, lid_interrupt) GPIO_INT(EC_WP_OD, PIN(A, 1), GPIO_INT_BOTH, switch_interrupt) GPIO_INT(BASE_SIXAXIS_INT_L, PIN(5, 6), GPIO_INT_FALLING | GPIO_SEL_1P8V, bmi160_interrupt) GPIO_INT(LID_360_L, PIN(9, 5), GPIO_INT_BOTH, gmr_tablet_switch_isr) +GPIO_INT(EN_PP1800_PANEL_S0, PIN(4, 1), GPIO_INT_BOTH, panel_power_change_interrupt) /* I2C Ports */ GPIO(EC_I2C_EEPROM_SCL, PIN(B, 3), GPIO_INPUT) @@ -51,22 +52,21 @@ GPIO(EC_I2C_USB_C0_SCL, PIN(9, 0), GPIO_INPUT) GPIO(EC_I2C_USB_C0_SDA, PIN(8, 7), GPIO_INPUT) GPIO(EC_I2C_SUB_C1_SCL_HDMI_EN_ODL, PIN(9, 2), GPIO_INPUT) /* C1 I2C SCL OR HDMI en */ -/* Extra Sub-board I/O pins */ -GPIO(EC_SUB_IO_1, PIN(3, 7), GPIO_OUT_LOW) -GPIO(EC_SUB_IO_2, PIN(3, 4), GPIO_OUT_LOW) - /* Misc Enables */ GPIO(EN_VCCIO_EXT, PIN(6, 1), GPIO_OUT_LOW) /* TODO(b:149775160) - Modify if needed if we ever use this signal. */ GPIO(EN_VCCST, PIN(A, 7), GPIO_INPUT) -GPIO(EN_PP3300_PEN, PIN(6, 3), GPIO_OUT_LOW) GPIO(EN_PP3300_A, PIN(0, 3), GPIO_OUT_LOW) GPIO(EN_PP5000_U, PIN(A, 4), GPIO_OUT_LOW) GPIO(EN_SLP_Z, PIN(8, 3), GPIO_OUT_LOW) -GPIO(EN_KB_BL, PIN(6, 0), GPIO_OUT_LOW) GPIO(EN_BL_OD, PIN(D, 3), GPIO_ODR_LOW) GPIO(IMVP9_PE, PIN(E, 0), GPIO_OUT_LOW) GPIO(ECH1_PACKET_MODE, PIN(7, 5), GPIO_OUT_LOW) +GPIO(LED_R_ODL, PIN(C, 4), GPIO_OUT_HIGH) +GPIO(LED_G_ODL, PIN(C, 3), GPIO_OUT_HIGH) +GPIO(LED_B_ODL, PIN(C, 2), GPIO_OUT_HIGH) +GPIO(EN_LCD_ENN, PIN(9, 7), GPIO_OUT_LOW) +GPIO(EN_LCD_ENP, PIN(8, 6), GPIO_OUT_LOW) /* Power Sequencing */ GPIO(EC_AP_PSYS, PIN(B, 7), GPIO_OUT_LOW) @@ -85,7 +85,6 @@ GPIO(ALL_SYS_PWRGD, PIN(A, 0), GPIO_OUT_LOW) GPIO(SYS_RST_ODL, PIN(C, 5), GPIO_ODR_HIGH) GPIO(CCD_MODE_ODL, PIN(E, 5), GPIO_ODR_HIGH) -GPIO(USB_C0_RST_ODL, PIN(9, 7), GPIO_OUT_HIGH) /* currently unused */ GPIO(EC_AP_USB_C1_HDMI_HPD, PIN(9, 6), GPIO_OUT_LOW) GPIO(EC_AP_USB_C0_HPD, PIN(9, 3), GPIO_OUT_LOW) GPIO(HDMI_SEL_L, PIN(7, 2), GPIO_OUT_HIGH) @@ -103,6 +102,7 @@ UNIMPLEMENTED(PG_EC_ALL_SYS_PWRGD) /* ADC */ ALTERNATE(PIN_MASK(F, BIT(0)), 0, MODULE_ADC, 0) /* ADC9 */ ALTERNATE(PIN_MASK(4, 0x38), 0, MODULE_ADC, 0) /* ADC0-2 */ +ALTERNATE(PIN_MASK(3, 0x90), 0, MODULE_ADC, 0) /* ADC5-6 */ /* Keyboard */ ALTERNATE(PIN_MASK(3, 0x03), 0, MODULE_KEYBOARD_SCAN, GPIO_INPUT | GPIO_PULL_UP) /* KSI0, KSI1 */ @@ -113,10 +113,6 @@ ALTERNATE(PIN_MASK(0, 0xF0), 0, MODULE_KEYBOARD_SCAN, GPIO_ODR_HIGH) /* KSO10- ALTERNATE(PIN_MASK(8, 0x04), 0, MODULE_KEYBOARD_SCAN, GPIO_ODR_HIGH) /* KSO14 */ GPIO(EC_KSO_02_INV, PIN(1, 7), GPIO_OUT_LOW) /* KSO2 inverted */ -/* PWM */ -ALTERNATE(PIN_MASK(C, 0x1C), 0, MODULE_PWM, 0) /* PWM0-2 */ -ALTERNATE(PIN_MASK(8, BIT(0)), 0, MODULE_PWM, 0) /* PWM3 */ - /* UART */ ALTERNATE(PIN_MASK(6, 0x30), 0, MODULE_UART, 0) /* UART1 */ @@ -127,13 +123,17 @@ ALTERNATE(PIN_MASK(9, 0x07), 0, MODULE_I2C, 0) /* I2C2, I2C1 SCL */ ALTERNATE(PIN_MASK(8, 0x80), 0, MODULE_I2C, 0) /* I2C1 SDA */ /* NC pins, enable internal pull-up to avoid floating state. */ -GPIO(GPIO32_NC, PIN(3, 2), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIO35_NC, PIN(3, 5), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIO41_NC, PIN(4, 1), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIO57_NC, PIN(5, 7), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIO81_NC, PIN(8, 1), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIO86_NC, PIN(8, 6), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIOC0_NC, PIN(C, 0), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIOD0_NC, PIN(D, 0), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIOD1_NC, PIN(D, 1), GPIO_INPUT | GPIO_PULL_UP) -GPIO(GPIOD6_NC, PIN(D, 6), GPIO_INPUT | GPIO_PULL_UP) +GPIO(GPIO00_NC, PIN(0, 0), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIO32_NC, PIN(3, 2), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIO35_NC, PIN(3, 5), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIO50_NC, PIN(5, 0), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIO57_NC, PIN(5, 7), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIO60_NC, PIN(6, 0), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIO63_NC, PIN(6, 3), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIO80_NC, PIN(8, 0), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIO81_NC, PIN(8, 1), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIOA2_NC, PIN(A, 2), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIOC0_NC, PIN(C, 0), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIOD0_NC, PIN(D, 0), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIOD1_NC, PIN(D, 1), GPIO_INPUT | GPIO_PULL_DOWN) +GPIO(GPIOD6_NC, PIN(D, 6), GPIO_INPUT | GPIO_PULL_DOWN) diff --git a/board/bugzzy/led.c b/board/bugzzy/led.c index 52a8e503a4..d04026e0f0 100644 --- a/board/bugzzy/led.c +++ b/board/bugzzy/led.c @@ -1,70 +1,133 @@ /* 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. + * + * Power and battery LED control for bugzzy */ -/* Waddledoo specific PWM LED settings. */ - -#include "common.h" +#include "chipset.h" #include "ec_commands.h" -#include "led_pwm.h" -#include "pwm.h" -#include "util.h" +#include "gpio.h" +#include "hooks.h" +#include "led_common.h" +#include "led_onoff_states.h" + +#define LED_OFF_LVL 1 +#define LED_ON_LVL 0 + +__override const int led_charge_lvl_1 = 1; + +__override const int led_charge_lvl_2 = 100; + +/* bugzzy : There are 3 leds for AC, Battery and Power */ +__override struct led_descriptor + led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = { + [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_RED, 1 * LED_ONE_SEC}, + {LED_OFF, 1 * LED_ONE_SEC} }, + [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_RED, LED_INDEFINITE} }, + [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_GREEN, LED_INDEFINITE} }, + [STATE_DISCHARGE_S0] = {{EC_LED_COLOR_GREEN, LED_INDEFINITE} }, + [STATE_DISCHARGE_S0_BAT_LOW] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_DISCHARGE_S3] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_BATTERY_ERROR] = {{EC_LED_COLOR_RED, 0.5 * LED_ONE_SEC}, + {LED_OFF, 0.5 * LED_ONE_SEC} }, + [STATE_FACTORY_TEST] = {{EC_LED_COLOR_RED, 1 * LED_ONE_SEC}, + {LED_OFF, 1 * LED_ONE_SEC} }, +}; + +__override const struct led_descriptor + led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES] = { + [PWR_LED_STATE_ON] = {{EC_LED_COLOR_BLUE, LED_INDEFINITE} }, + [PWR_LED_STATE_SUSPEND_AC] = {{LED_OFF, LED_INDEFINITE} }, + [PWR_LED_STATE_SUSPEND_NO_AC] = {{LED_OFF, LED_INDEFINITE} }, + [PWR_LED_STATE_OFF] = {{LED_OFF, LED_INDEFINITE} }, +}; const enum ec_led_id supported_led_ids[] = { - EC_LED_ID_POWER_LED, + EC_LED_ID_BATTERY_LED, + EC_LED_ID_POWER_LED }; + const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); -/* - * We only have a white and an amber LED, so setting any other colour results in - * both LEDs being off. - */ -struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = { - /* Amber, White */ - [EC_LED_COLOR_RED] = { 0, 0 }, - [EC_LED_COLOR_GREEN] = { 0, 0 }, - [EC_LED_COLOR_BLUE] = { 0, 0 }, - [EC_LED_COLOR_YELLOW] = { 0, 0 }, - [EC_LED_COLOR_WHITE] = { 0, 100 }, - [EC_LED_COLOR_AMBER] = { 100, 0 }, -}; -/* One logical LED with amber and white channels. */ -struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = { +__override void led_set_color_power(enum ec_led_colors color) +{ + /* Don't set led if led_auto_control is disabled. */ + if (!led_auto_control_is_enabled(EC_LED_ID_POWER_LED) || + !led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) { + return; + } + + if (color == EC_LED_COLOR_BLUE) { - .ch0 = PWM_CH_LED1_AMBER, - .ch1 = PWM_CH_LED2_WHITE, - .ch2 = PWM_LED_NO_CHANNEL, - .enable = &pwm_enable, - .set_duty = &pwm_set_duty, - }, -}; + gpio_set_level(GPIO_BAT_LED_RED_L, LED_OFF_LVL); + gpio_set_level(GPIO_BAT_LED_GREEN_L, LED_OFF_LVL); + gpio_set_level(GPIO_PWR_LED_BLUE_L, LED_ON_LVL); + } else { + /* LED_OFF and unsupported colors */ + gpio_set_level(GPIO_PWR_LED_BLUE_L, LED_OFF_LVL); + } +} + +__override void led_set_color_battery(enum ec_led_colors color) +{ + /* Don't set led if led_auto_control is disabled. */ + if (!led_auto_control_is_enabled(EC_LED_ID_POWER_LED) || + !led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) { + return; + } + + /* + * Battery leds must be turn off when blue led is on + * because bugzzy has 3-in-1 led. + */ + if (!gpio_get_level(GPIO_PWR_LED_BLUE_L)) { + gpio_set_level(GPIO_BAT_LED_RED_L, LED_OFF_LVL); /*red*/ + gpio_set_level(GPIO_BAT_LED_GREEN_L, LED_OFF_LVL); /*green*/ + return; + } + + switch (color) { + case EC_LED_COLOR_GREEN: + gpio_set_level(GPIO_BAT_LED_RED_L, LED_OFF_LVL); /*red*/ + gpio_set_level(GPIO_BAT_LED_GREEN_L, LED_ON_LVL); /*green*/ + break; + case EC_LED_COLOR_RED: + gpio_set_level(GPIO_BAT_LED_RED_L, LED_ON_LVL); /*red*/ + gpio_set_level(GPIO_BAT_LED_GREEN_L, LED_OFF_LVL); /*green*/ + break; + default: /* LED_OFF and other unsupported colors */ + gpio_set_level(GPIO_BAT_LED_RED_L, LED_OFF_LVL); /*red*/ + gpio_set_level(GPIO_BAT_LED_GREEN_L, LED_OFF_LVL); /*green*/ + break; + } +} void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) { - memset(brightness_range, '\0', - sizeof(*brightness_range) * EC_LED_COLOR_COUNT); - brightness_range[EC_LED_COLOR_AMBER] = 100; - brightness_range[EC_LED_COLOR_WHITE] = 100; + if (led_id == EC_LED_ID_BATTERY_LED) { + brightness_range[EC_LED_COLOR_GREEN] = 1; + brightness_range[EC_LED_COLOR_RED] = 1; + } else if (led_id == EC_LED_ID_POWER_LED) { + brightness_range[EC_LED_COLOR_BLUE] = 1; + } } int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) { - enum pwm_led_id pwm_id; - - /* Convert ec_led_id to pwm_led_id. */ - if (led_id == EC_LED_ID_POWER_LED) - pwm_id = PWM_LED0; - else - return EC_ERROR_UNKNOWN; - - if (brightness[EC_LED_COLOR_WHITE]) - set_pwm_led_color(pwm_id, EC_LED_COLOR_WHITE); - else if (brightness[EC_LED_COLOR_AMBER]) - set_pwm_led_color(pwm_id, EC_LED_COLOR_AMBER); - else - /* Otherwise, the "color" is "off". */ - set_pwm_led_color(pwm_id, -1); + if (led_id == EC_LED_ID_BATTERY_LED) { + gpio_set_level(GPIO_PWR_LED_BLUE_L, LED_OFF_LVL); + gpio_set_level(GPIO_BAT_LED_GREEN_L, + !brightness[EC_LED_COLOR_GREEN]); + gpio_set_level(GPIO_BAT_LED_RED_L, + !brightness[EC_LED_COLOR_RED]); + } else if (led_id == EC_LED_ID_POWER_LED) { + gpio_set_level(GPIO_PWR_LED_BLUE_L, + !brightness[EC_LED_COLOR_BLUE]); + gpio_set_level(GPIO_BAT_LED_GREEN_L, LED_OFF_LVL); + gpio_set_level(GPIO_BAT_LED_RED_L, LED_OFF_LVL); + } return EC_SUCCESS; } -- cgit v1.2.1