diff options
Diffstat (limited to 'zephyr/projects/corsola')
42 files changed, 1914 insertions, 765 deletions
diff --git a/zephyr/projects/corsola/BUILD.py b/zephyr/projects/corsola/BUILD.py new file mode 100644 index 0000000000..1254b01003 --- /dev/null +++ b/zephyr/projects/corsola/BUILD.py @@ -0,0 +1,50 @@ +# 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. + +# Default chip is it8xxx2, some variants will use NPCX9X. + + +def register_corsola_project( + project_name, + chip="it8xxx2", + extra_dts_overlays=(), + extra_kconfig_files=(), +): + register_func = register_binman_project + if chip.startswith("npcx9"): + register_func = register_npcx_project + + register_func( + project_name=project_name, + zephyr_board=chip, + dts_overlays=[here / "power_signal.dts", *extra_dts_overlays], + kconfig_files=[here / "prj.conf", *extra_kconfig_files], + ) + + +register_corsola_project( + "krabby", + extra_dts_overlays=[ + here / "adc_krabby.dts", + here / "battery_krabby.dts", + here / "gpio_krabby.dts", + here / "i2c_krabby.dts", + here / "motionsense_krabby.dts", + here / "pwm_krabby.dts", + ], + extra_kconfig_files=[here / "prj_krabby.conf"], +) + +register_corsola_project( + project_name="kingler", + chip="npcx9", + extra_dts_overlays=[ + here / "adc_kingler.dts", + here / "battery_kingler.dts", + here / "i2c_kingler.dts", + here / "cbi_eeprom_kingler.dts", + here / "gpio_kingler.dts", + ], + extra_kconfig_files=[here / "prj_kingler.conf"], +) diff --git a/zephyr/projects/corsola/CMakeLists.txt b/zephyr/projects/corsola/CMakeLists.txt new file mode 100644 index 0000000000..3e9cac9f83 --- /dev/null +++ b/zephyr/projects/corsola/CMakeLists.txt @@ -0,0 +1,35 @@ +# 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. + +cmake_minimum_required(VERSION 3.13.1) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +zephyr_library_include_directories(include) + +# Include selected EC source from the baseboard +zephyr_library_sources( + "src/board_chipset.c" + "src/hibernate.c" +) + +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "src/usbc_config.c") +zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "src/usb_pd_policy.c") +zephyr_library_sources_ifdef(CONFIG_VARIANT_CORSOLA_DB_DETECTION + "src/variant_db_detection.c") + +if(DEFINED CONFIG_BOARD_KRABBY) + project(krabby) + zephyr_library_sources("src/krabby/hooks.c") + zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C "src/krabby/i2c.c") + zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON + "src/krabby/led.c") + zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC + "src/krabby/usb_pd_policy.c") + zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC + "src/krabby/usbc_config.c") +elseif(DEFINED CONFIG_BOARD_KINGLER) + project(kingler) +endif() + diff --git a/zephyr/projects/corsola/Kconfig b/zephyr/projects/corsola/Kconfig new file mode 100644 index 0000000000..746c8b8cc8 --- /dev/null +++ b/zephyr/projects/corsola/Kconfig @@ -0,0 +1,32 @@ +# 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. + +config BOARD_KRABBY + bool "Google Krabby Board" + help + Build Google Krabby reference board. Krabby has MediaTek MT8186 SoC + with ITE it81202-bx EC. + +config BOARD_KINGLER + bool "Google Kingler Board" + help + Build Google Kingler reference board. Krabby has MediaTek MT8186 SoC + with NPCX993FA0BX EC. + +config VARIANT_CORSOLA_DB_DETECTION + bool "Corsola Platform Runtime Daughter Board Detection" + help + Daughter board detection for Type-C subboard or HDMI subboard. This + includes pin configuration and driver loading. + default y + +config VARIANT_CORSOLA_USBA + bool "Corsola Platform USB-A support" + help + Support Corsola USB-A related functions. Enable this function if + it has USB-A ports. + depends on PLATFORM_EC_USBC + default y + +source "Kconfig.zephyr" diff --git a/zephyr/projects/corsola/adc_kingler.dts b/zephyr/projects/corsola/adc_kingler.dts new file mode 100644 index 0000000000..7b2e9817e4 --- /dev/null +++ b/zephyr/projects/corsola/adc_kingler.dts @@ -0,0 +1,41 @@ +/* Copyright 2022 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. + */ + +/ { + named-adc-channels { + compatible = "named-adc-channels"; + + adc_charger_pmon_r { + label = "ADC_CHARGER_PMON_R"; + enum-name = "ADC_PSYS"; + channel = <0>; + /* + * ISL9238C PSYS output is 1.44 uA/W over 33K resistor. + */ + mul = <21043>; + }; + adc_ec_id0 { + label = "ADC_EC_ID0"; + enum-name = "ADC_ID_0"; + channel = <1>; + }; + adc_ec_id1 { + label = "ADC_EC_ID1"; + enum-name = "ADC_ID_1"; + channel = <2>; + }; + adc_charger_amon_r { + label = "ADC_AMON_R"; + enum-name = "ADC_AMON_BMON"; + channel = <3>; + mul = <1000>; + div = <18>; + }; + }; +}; + +&adc0 { + status = "okay"; +}; diff --git a/zephyr/projects/corsola/krabby/adc.dts b/zephyr/projects/corsola/adc_krabby.dts index 7f308c04f9..938fc42cd1 100644 --- a/zephyr/projects/corsola/krabby/adc.dts +++ b/zephyr/projects/corsola/adc_krabby.dts @@ -8,44 +8,27 @@ compatible = "named-adc-channels"; adc_vbus_c0 { - label = "ADC_VBUS_C0"; + label = "VBUS_C0"; enum-name = "ADC_VBUS_C0"; channel = <0>; mul = <10>; }; adc_board_id0 { - label = "ADC_BOARD_ID_0"; + label = "BOARD_ID_0"; enum-name = "ADC_BOARD_ID_0"; channel = <1>; }; adc_board_id1 { - label = "ADC_BOARD_ID_1"; + label = "BOARD_ID_1"; enum-name = "ADC_BOARD_ID_1"; channel = <2>; }; - adc_charger_amon_r { - label = "ADC_AMON_BMON"; - enum-name = "ADC_AMON_BMON"; - channel = <3>; - mul = <1000>; - div = <18>; - }; adc_vbus_c1 { - label = "ADC_VBUS_C1"; + label = "VBUS_C1"; enum-name = "ADC_VBUS_C1"; - channel = <5>; + channel = <7>; mul = <10>; }; - adc_charger_pmon { - label = "ADC_PMON"; - enum-name = "ADC_PMON"; - channel = <6>; - }; - adc-psys { - label = "ADC_PSYS"; - enum-name = "ADC_PSYS"; - channel = <6>; - }; }; }; diff --git a/zephyr/projects/corsola/kingler/battery.dts b/zephyr/projects/corsola/battery_kingler.dts index 02a6d0d3b9..c234dca7c9 100644 --- a/zephyr/projects/corsola/kingler/battery.dts +++ b/zephyr/projects/corsola/battery_kingler.dts @@ -5,8 +5,11 @@ / { batteries { - default_battery: aec_5477109 { - compatible = "aec,5477109"; + default_battery: smp_l20m3pg2 { + compatible = "smp,l20m3pg2"; + }; + lgc_l20l3pg2 { + compatible = "lgc,l20l3pg2"; }; }; }; diff --git a/zephyr/projects/corsola/krabby/battery.dts b/zephyr/projects/corsola/battery_krabby.dts index deb803bb8c..deb803bb8c 100644 --- a/zephyr/projects/corsola/krabby/battery.dts +++ b/zephyr/projects/corsola/battery_krabby.dts diff --git a/zephyr/projects/corsola/cbi_eeprom_kingler.dts b/zephyr/projects/corsola/cbi_eeprom_kingler.dts new file mode 100644 index 0000000000..0886a05280 --- /dev/null +++ b/zephyr/projects/corsola/cbi_eeprom_kingler.dts @@ -0,0 +1,17 @@ +/* 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. + */ + + &i2c_pwr_cbi { + cbi_eeprom: eeprom@50 { + compatible = "atmel,at24"; + reg = <0x50>; + label = "EEPROM_CBI"; + size = <2048>; + pagesize = <16>; + address-width = <8>; + timeout = <5>; + wp-gpios = <&gpio_ec_wp_l>; + }; +}; diff --git a/zephyr/projects/corsola/gpio_kingler.dts b/zephyr/projects/corsola/gpio_kingler.dts new file mode 100644 index 0000000000..4ea7b30710 --- /dev/null +++ b/zephyr/projects/corsola/gpio_kingler.dts @@ -0,0 +1,242 @@ +/* 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. + */ + +/ { + named-gpios { + compatible = "named-gpios"; + + base_imu_int_l { + gpios = <&gpio5 6 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + enum-name = "GPIO_BASE_IMU_INT_L"; + }; + spi_ap_clk_ec { + gpios = <&gpio5 5 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + }; + spi_ap_cs_ec_l { + gpios = <&gpio5 3 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + enum-name = "GPIO_SHI_CS_L"; + }; + spi_ap_do_ec_di { + gpios = <&gpio4 6 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + }; + spi_ap_di_ec_do { + gpios = <&gpio4 7 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + }; + ap_ec_warm_rst_req: ap_ec_warm_rst_req { + gpios = <&gpio5 1 (GPIO_INPUT | GPIO_VOLTAGE_1P8 | + GPIO_ACTIVE_HIGH)>; + enum-name = "GPIO_AP_EC_WARM_RST_REQ"; + }; + ap_ec_wdtrst_l: ap_ec_wdtrst_l { + gpios = <&gpio5 2 (GPIO_INPUT | GPIO_VOLTAGE_1P8 | + GPIO_ACTIVE_LOW)>; + enum-name = "GPIO_AP_EC_WDTRST_L"; + }; + ap_in_sleep_l: ap_in_sleep_l { + gpios = <&gpio5 4 (GPIO_INPUT | GPIO_VOLTAGE_1P8 | + GPIO_ACTIVE_LOW)>; + enum-name = "GPIO_AP_IN_SLEEP_L"; + }; + en_ulp { + gpios = <&gpioc 6 GPIO_OUT_LOW>; + enum-name = "GPIO_EN_ULP"; + }; + en_ec_id_odl { + gpios = <&gpio7 6 GPIO_ODR_LOW>; + enum-name = "GPIO_EN_EC_ID_ODL"; + }; + sys_rst_odl { + gpios = <&gpioc 5 (GPIO_ODR_LOW | GPIO_VOLTAGE_1P8)>; + enum-name = "GPIO_SYS_RST_ODL"; + }; + ec_i2c_sensor_scl { + gpios = <&gpiob 5 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + }; + ec_i2c_sensor_sda { + gpios = <&gpiob 4 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + }; + ec_i2c_usb_c0_scl { + gpios = <&gpio9 0 GPIO_INPUT>; + }; + ec_i2c_usb_c0_sda { + gpios = <&gpio8 7 GPIO_INPUT>; + }; + ec_i2c_usb_c1_scl { + gpios = <&gpio9 2 GPIO_INPUT>; + }; + ec_i2c_usb_c1_sda { + gpios = <&gpio9 1 GPIO_INPUT>; + }; + ec_i2c_pwr_cbi_scl { + gpios = <&gpiod 1 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + }; + ec_i2c_pwr_cbi_sda { + gpios = <&gpiod 0 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + }; + ec_i2c_batt_scl { + gpios = <&gpio3 3 GPIO_INPUT>; + }; + ec_i2c_batt_sda { + gpios = <&gpio3 6 GPIO_INPUT>; + }; + ec_pen_chg_dis_odl { + gpios = <&gpioe 4 GPIO_INPUT>; + enum-name = "GPIO_EC_PEN_CHG_DIS_ODL"; + }; + gpio_ec_wp_l: ec_wp_odl { + #gpio-cells = <0>; + gpios = <&gpioe 3 (GPIO_OPEN_DRAIN)>; + enum-name = "GPIO_WP_L"; + }; + lid_accel_int_l { + gpios = <&gpiob 3 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + enum-name = "GPIO_LID_ACCEL_INT_L"; + }; + tablet_mode_l { + gpios = <&gpiob 2 GPIO_INPUT>; + enum-name = "GPIO_TABLET_MODE_L"; + }; + ec_ap_int_odl { + gpios = <&gpioc 1 (GPIO_ODR_HIGH | GPIO_VOLTAGE_1P8)>; + enum-name = "GPIO_EC_INT_L"; + }; + ec_kso_02_inv { + gpios = <&gpio1 7 GPIO_OUT_LOW>; + enum-name = "GPIO_KBD_KSO2"; + }; + usb_c0_bc12_int_odl { + gpios = <&gpio8 3 GPIO_INPUT>; + }; + ec_entering_rw { + gpios = <&gpio0 3 GPIO_OUT_LOW>; + enum-name = "GPIO_ENTERING_RW"; + }; + charger_prochot_odl { + gpios = <&gpiob 1 GPIO_INPUT>; + enum-name = "GPIO_CHARGER_PROCHOT_ODL"; + }; + ec_rst_odl { + gpios = <&gpio7 7 GPIO_INPUT>; + enum-name = "GPIO_EC_RST_ODL"; + }; + lid_open { + gpios = <&gpiod 2 GPIO_INPUT>; + enum-name = "GPIO_LID_OPEN"; + }; + acok_od { + gpios = <&gpio0 0 GPIO_INPUT>; + enum-name = "GPIO_AC_PRESENT"; + }; + gsc_ec_pwr_btn_odl { + gpios = <&gpio0 1 GPIO_INPUT>; + enum-name = "GPIO_POWER_BUTTON_L"; + }; + en_5v_usm { + gpios = <&gpio0 2 GPIO_OUT_LOW>; + enum-name = "GPIO_EN_5V_USM"; + }; + packet_mode_en { + gpios = <&gpio0 2 GPIO_OUT_LOW>; + enum-name = "GPIO_PACKET_MODE_EN"; + }; + x_ec_gpio2 { + gpios = <&gpiod 4 GPIO_INPUT>; + enum-name = "GPIO_X_EC_GPIO2"; + }; + ap_sysrst_odl_r: ap_sysrst_odl_r { + gpios = <&gpioa 1 (GPIO_INPUT | GPIO_VOLTAGE_1P8 | + GPIO_ACTIVE_LOW)>; + enum-name = "GPIO_AP_EC_SYSRST_ODL"; + }; + ap_xhci_init_done { + gpios = <&gpioa 3 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + enum-name = "GPIO_AP_XHCI_INIT_DONE"; + }; + usb_c0_ppc_int_odl { + gpios = <&gpio6 7 GPIO_INPUT>; + enum-name = "GPIO_USB_C0_PPC_INT_ODL"; + }; + pg_pp5000_z2_od { + gpios = <&gpio7 0 GPIO_INPUT>; + enum-name = "GPIO_PG_PP5000_Z2_OD"; + }; + ec_x_gpio1 { + gpios = <&gpio6 2 GPIO_OUT_LOW>; + enum-name = "GPIO_EC_X_GPIO1"; + }; + dp_aux_path_sel { + gpios = <&gpio6 3 GPIO_OUT_LOW>; + enum-name = "GPIO_DP_AUX_PATH_SEL"; + }; + ec_bl_en_od { + gpios = <&gpio4 0 (GPIO_ODR_LOW | GPIO_VOLTAGE_1P8)>; + enum-name = "GPIO_EC_BL_EN_OD"; + }; + ec_x_gpio3 { + gpios = <&gpiod 3 GPIO_OUT_LOW>; + enum-name = "GPIO_EC_X_GPIO3"; + }; + usb_c0_tcpc_int_odl { + gpios = <&gpio7 3 GPIO_INPUT>; + enum-name = "GPIO_USB_C0_TCPC_INT_ODL"; + }; + usb_c0_tcpc_rst { + gpios = <&gpioc 0 GPIO_OUT_LOW>; + enum-name = "GPIO_USB_C0_TCPC_RST"; + }; + en_pp5000_usb_a0_vbus_x { + gpios = <&gpio6 0 GPIO_OUT_LOW>; + enum-name = "GPIO_EN_PP5000_USB_A0_VBUS"; + }; + hdmi_prsnt_odl { + gpios = <&gpio3 7 GPIO_INPUT>; + enum-name = "GPIO_HDMI_PRSNT_ODL"; + }; + en_pp5000_z2 { + gpios = <&gpio3 4 GPIO_OUT_HIGH>; + enum-name = "GPIO_EN_PP5000_Z2"; + }; + usb_c1_tcpc_int_odl { + gpios = <&gpioe 1 GPIO_INPUT>; + enum-name = "GPIO_USB_C1_TCPC_INT_ODL"; + }; + ec_batt_pres_odl { + gpios = <&gpioe 0 GPIO_INPUT>; + enum-name = "GPIO_BATT_PRES_ODL"; + }; + usb_a0_fault_odl { + gpios = <&gpioc 7 GPIO_INPUT>; + enum-name = "GPIO_USB_A0_FAULT_ODL"; + }; + ec_ap_dp_hpd_odl { + gpios = <&gpio6 1 GPIO_ODR_HIGH>; + enum-name = "GPIO_EC_AP_DP_HPD_ODL"; + }; + ec_pmic_en_odl { + gpios = <&gpio7 4 (GPIO_ODR_HIGH | GPIO_VOLTAGE_1P8)>; + enum-name = "GPIO_EC_PMIC_EN_ODL"; + }; + ec_volup_btn_odl { + gpios = <&gpiod 5 GPIO_INPUT>; + enum-name = "GPIO_VOLUME_UP_L"; + }; + ec_voldn_btn_odl { + gpios = <&gpioe 2 GPIO_INPUT>; + enum-name = "GPIO_VOLUME_DOWN_L"; + }; + ccd_mode_odl { + gpios = <&gpioe 5 GPIO_INPUT>; + enum-name = "GPIO_CCD_MODE_ODL"; + }; + }; + + def-lvol-io-list { + compatible = "nuvoton,npcx-lvolctrl-def"; + lvol-io-pads = < + &lvol_ioe3 /* GPIOE3 GPIO_EC_WP_L */ + &lvol_io40 /* GPIO40 GPIO_EC_BL_EN_OD */ + >; + }; +}; diff --git a/zephyr/projects/corsola/krabby/gpio.dts b/zephyr/projects/corsola/gpio_krabby.dts index 29fc7dd879..9ecf5e007f 100644 --- a/zephyr/projects/corsola/krabby/gpio.dts +++ b/zephyr/projects/corsola/gpio_krabby.dts @@ -3,280 +3,226 @@ * found in the LICENSE file. */ -/ { - gpiox: gpio@0 { - status = "okay"; - compatible = "zephyr,gpio-emul"; - label = "GPIO_UNIMPLEMENTED"; - reg = <0x800 0x4>; - rising-edge; - falling-edge; - high-level; - low-level; - gpio-controller; - #gpio-cells = <2>; - }; +#include <dt-bindings/gpio_defines.h> +#include <dt-bindings/wake_mask_event_defines.h> +/ { named-gpios { compatible = "named-gpios"; power_button_l: power_button_l { gpios = <&gpioe 4 GPIO_INPUT>; enum-name = "GPIO_POWER_BUTTON_L"; - label = "POWER_BUTTON_L"; }; lid_open: lid_open { gpios = <&gpioe 2 GPIO_INPUT>; enum-name = "GPIO_LID_OPEN"; - label = "LID_OPEN"; }; tablet_mode_l: tablet_mode_l { gpios = <&gpioj 7 GPIO_INPUT>; enum-name = "GPIO_TABLET_MODE_L"; - label = "TABLET_MODE_L"; }; ap_ec_warm_rst_req: ap_ec_warm_rst_req { - gpios = <&gpiod 3 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + gpios = <&gpiod 3 (GPIO_INPUT | GPIO_VOLTAGE_1P8 | + GPIO_ACTIVE_HIGH)>; enum-name = "GPIO_AP_EC_WARM_RST_REQ"; - label = "AP_EC_WARM_RST_REQ"; }; ap_in_sleep_l: ap_in_sleep_l { - gpios = <&gpiob 6 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + gpios = <&gpiob 6 (GPIO_INPUT | GPIO_VOLTAGE_1P8 | + GPIO_ACTIVE_LOW)>; enum-name = "GPIO_AP_IN_SLEEP_L"; - label = "AP_IN_SLEEP_L"; }; base_imu_int_l: base_imu_int_l { gpios = <&gpiom 3 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_BASE_IMU_INT_L"; - label = "BASE_IMU_INT_L"; }; lid_accel_int_l: lid_accel_int_l { gpios = <&gpiom 2 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_LID_ACCEL_INT_L"; - label = "LID_ACCEL_INT_L"; }; volume_down_l: volume_down_l { gpios = <&gpiod 5 GPIO_INPUT>; enum-name = "GPIO_VOLUME_DOWN_L"; - label = "VOLUME_DOWN_L"; }; volume_up_l: volume_up_l { gpios = <&gpiod 6 GPIO_INPUT>; enum-name = "GPIO_VOLUME_UP_L"; - label = "VOLUME_UP_L"; }; ap_xhci_init_done: ap_xhci_init_done { gpios = <&gpioj 5 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_AP_XHCI_INIT_DONE"; - label = "AP_XHCI_INIT_DONE"; }; ac_present: ac_present { gpios = <&gpioe 5 GPIO_INPUT>; enum-name = "GPIO_AC_PRESENT"; - label = "AC_PRESENT"; }; - wp: wp { + ec_flash_wp_odl: ec_flash_wp_odl { gpios = <&gpioi 4 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; - enum-name = "GPIO_WP"; - label = "WP"; + enum-name = "GPIO_WP_L"; }; spi0_cs: spi0_cs { gpios = <&gpiom 5 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_SPI0_CS"; - label = "SPI0_CS"; }; x_ec_gpio2: x_ec_gpio2 { gpios = <&gpiob 2 (GPIO_INPUT | GPIO_ODR_HIGH)>; enum-name = "GPIO_X_EC_GPIO2"; - label = "X_EC_GPIO2"; }; usb_c0_ppc_bc12_int_odl: usb_c0_ppc_bc12_int_odl { gpios = <&gpiod 1 GPIO_INPUT>; enum-name = "GPIO_USB_C0_PPC_BC12_INT_ODL"; - label = "USB_C0_PPC_BC12_INT_ODL"; }; usb_c1_bc12_charger_int_odl: usb_c1_bc12_charger_int_odl { gpios = <&gpioj 4 GPIO_INPUT>; enum-name = "GPIO_USB_C1_BC12_CHARGER_INT_ODL"; - label = "USB_C1_BC12_CHARGER_INT_ODL"; }; ec_pmic_en_odl: ec_pmic_en_odl { gpios = <&gpiod 0 (GPIO_ODR_HIGH | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_EC_PMIC_EN_ODL"; - label = "EC_PMIC_EN_ODL"; }; en_pp5000_z2: en_pp5000_z2 { gpios = <&gpioc 6 GPIO_OUT_HIGH>; enum-name = "GPIO_EN_PP5000_Z2"; - label = "EN_PP5000_Z2"; }; en_ulp: en_ulp { gpios = <&gpioe 3 GPIO_OUT_LOW>; enum-name = "GPIO_EN_ULP"; - label = "EN_ULP"; }; sys_rst_odl: sys_rst_odl { gpios = <&gpiog 1 GPIO_ODR_LOW>; enum-name = "GPIO_SYS_RST_ODL"; - label = "SYS_RST_ODL"; }; ec_bl_en_od: ec_bl_en_od { gpios = <&gpiob 5 (GPIO_ODR_LOW | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_EC_BL_EN_OD"; - label = "EC_BL_EN_OD"; }; - ap_ec_sysrst_odl: ap_ec_sysrst_odl { - gpios = <&gpioj 2 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + ap_sysrst_odl_r: ap_ec_sysrst_odl { + gpios = <&gpioj 2 (GPIO_INPUT | GPIO_VOLTAGE_1P8 | + GPIO_ACTIVE_LOW)>; enum-name = "GPIO_AP_EC_SYSRST_ODL"; - label = "AP_EC_SYSRST_ODL"; }; ap_ec_wdtrst_l: ap_ec_wdtrst_l { - gpios = <&gpioc 7 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; + gpios = <&gpioc 7 (GPIO_INPUT | GPIO_VOLTAGE_1P8 | + GPIO_ACTIVE_LOW)>; enum-name = "GPIO_AP_EC_WDTRST_L"; - label = "AP_EC_WDTRST_L"; }; ec_int_l: ec_int_l { gpios = <&gpioe 6 (GPIO_ODR_HIGH | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_EC_INT_L"; - label = "EC_INT_L"; }; dp_aux_path_sel: dp_aux_path_sel { gpios = <&gpiog 0 GPIO_OUT_HIGH>; enum-name = "GPIO_DP_AUX_PATH_SEL"; - label = "DP_AUX_PATH_SEL"; }; ec_ap_dp_hpd_odl: ec_ap_dp_hpd_odl { gpios = <&gpioj 0 GPIO_ODR_HIGH>; enum-name = "GPIO_EC_AP_DP_HPD_ODL"; - label = "EC_AP_DP_HPD_ODL"; }; en_pp5000_usb_a0_vbus: en_pp5000_usb_a0_vbus { gpios = <&gpiob 7 GPIO_OUT_LOW>; enum-name = "GPIO_EN_PP5000_USB_A0_VBUS"; - label = "EN_PP5000_USB_A0_VBUS"; }; usb_c0_ppc_frsinfo: usb_c0_ppc_frsinfo { gpios = <&gpiof 0 GPIO_INPUT>; enum-name = "GPIO_USB_C0_PPC_FRSINFO"; - label = "USB_C0_PPC_FRSINFO"; }; ec_batt_pres_odl: ec_batt_pres_odl { gpios = <&gpioc 0 GPIO_INPUT>; enum-name = "GPIO_BATT_PRES_ODL"; - label = "BATT_PRES_ODL"; }; en_ec_id_odl: en_ec_id_odl { gpios = <&gpioh 5 GPIO_ODR_LOW>; enum-name = "GPIO_EN_EC_ID_ODL"; - label = "EN_EC_ID_ODL"; }; entering_rw: entering_rw { gpios = <&gpioc 5 GPIO_OUT_LOW>; enum-name = "GPIO_ENTERING_RW"; - label = "ENTERING_RW"; }; en_5v_usm: en_5v_usm { gpios = <&gpiog 3 GPIO_OUT_LOW>; enum-name = "GPIO_EN_5V_USM"; - label = "EN_5V_USM"; }; usb_a0_fault_odl: usb_a0_fault_odl { gpios = <&gpioj 6 GPIO_INPUT>; enum-name = "GPIO_USB_A0_FAULT_ODL"; - label = "USB_A0_FAULT_ODL"; }; i2c_a_scl: i2c_a_scl { gpios = <&gpiob 3 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_I2C_A_SCL"; - label = "I2C_A_SCL"; }; i2c_a_sda: i2c_a_sda { gpios = <&gpiob 4 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_I2C_A_SDA"; - label = "I2C_A_SDA"; }; i2c_b_scl: i2c_b_scl { gpios = <&gpioc 1 GPIO_INPUT>; enum-name = "GPIO_I2C_B_SCL"; - label = "I2C_B_SCL"; }; i2c_b_sda: i2c_b_sda { gpios = <&gpioc 2 GPIO_INPUT>; enum-name = "GPIO_I2C_B_SDA"; - label = "I2C_B_SDA"; }; i2c_c_scl: i2c_c_scl { gpios = <&gpiof 6 GPIO_INPUT>; enum-name = "GPIO_I2C_C_SCL"; - label = "I2C_C_SCL"; }; i2c_c_sda: i2c_c_sda { gpios = <&gpiof 7 GPIO_INPUT>; enum-name = "GPIO_I2C_C_SDA"; - label = "I2C_C_SDA"; }; i2c_d_scl: i2c_d_scl { gpios = <&gpiof 2 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_I2C_D_SCL"; - label = "I2C_D_SCL"; }; i2c_d_sda: i2c_d_sda { gpios = <&gpiof 3 (GPIO_INPUT | GPIO_VOLTAGE_1P8)>; enum-name = "GPIO_I2C_D_SDA"; - label = "I2C_D_SDA"; }; i2c_e_scl: i2c_e_scl { gpios = <&gpioe 0 GPIO_INPUT>; enum-name = "GPIO_I2C_E_SCL"; - label = "I2C_E_SCL"; }; i2c_e_sda: i2c_e_sda { gpios = <&gpioe 7 GPIO_INPUT>; enum-name = "GPIO_I2C_E_SDA"; - label = "I2C_E_SDA"; }; i2c_f_scl: i2c_f_scl { gpios = <&gpioa 4 GPIO_INPUT>; enum-name = "GPIO_I2C_F_SCL"; - label = "I2C_F_SCL"; }; i2c_f_sda: i2c_f_sda { gpios = <&gpioa 5 GPIO_INPUT>; enum-name = "GPIO_I2C_F_SDA"; - label = "I2C_F_SDA"; }; ec_x_gpio1: ec_x_gpio1 { gpios = <&gpioh 4 GPIO_OUT_LOW>; enum-name = "GPIO_EC_X_GPIO1"; - label = "EC_X_GPIO1"; }; ec_x_gpio3: ec_x_gpio3 { gpios = <&gpioj 1 GPIO_INPUT>; enum-name = "GPIO_EC_X_GPIO3"; - label = "EC_X_GPIO3"; }; hdmi_prsnt_odl: hdmi_prsnt_odl { gpios = <&gpioj 3 GPIO_INPUT>; enum-name = "GPIO_HDMI_PRSNT_ODL"; - label = "HDMI_PRSNT_ODL"; }; + }; - /* pins used in power/mt8192, to be removed */ - ap_ec_watchdog_l: ap_ec_watchdog_l { - gpios = <&gpiox 0 GPIO_INPUT>; - enum-name = "GPIO_AP_EC_WATCHDOG_L"; - label = "AP_EC_WATCHDOG_L"; - }; - ec_pmic_watchdog_l: ec_pmic_watchdog_l { - gpios = <&gpiox 0 GPIO_INPUT>; - enum-name = "GPIO_EC_PMIC_WATCHDOG_L"; - label = "EC_PMIC_WATCHDOG_L"; - }; - pmic_ec_pwrgd: pmic_ec_pwrgd { - gpios = <&gpiox 0 GPIO_INPUT>; - enum-name = "GPIO_PMIC_EC_PWRGD"; - label = "PMIC_EC_PWRGD"; - }; + ec-mkbp-host-event-wakeup-mask { + compatible = "ec-wake-mask-event"; + wakeup-mask = <( + HOST_EVENT_MASK(HOST_EVENT_AC_CONNECTED) | + HOST_EVENT_MASK(HOST_EVENT_AC_DISCONNECTED) | + HOST_EVENT_MASK(HOST_EVENT_LID_OPEN) | + HOST_EVENT_MASK(HOST_EVENT_POWER_BUTTON) | + HOST_EVENT_MASK(HOST_EVENT_HANG_DETECT) | + HOST_EVENT_MASK(HOST_EVENT_MODE_CHANGE))>; + }; + + ec-mkbp-event-wakeup-mask { + compatible = "ec-wake-mask-event"; + wakeup-mask = <(MKBP_EVENT_KEY_MATRIX | + MKBP_EVENT_HOST_EVENT)>; }; hibernate-wake-pins { @@ -286,22 +232,6 @@ &lid_open>; }; - power_signal_list: power-signal-list { - compatible = "mt8192,power-signal-list"; - pmic_pwr_good { - power-enum-name = "PMIC_PWR_GOOD"; - power-gpio-pin = <&pmic_ec_pwrgd>; - }; - ap_in_s3_l { - power-enum-name = "AP_IN_S3_L"; - power-gpio-pin = <&ap_in_sleep_l>; - }; - ap_wdt_asserted { - power-enum-name = "AP_WDT_ASSERTED"; - power-gpio-pin = <&ap_ec_watchdog_l>; - }; - }; - unused-pins { compatible = "unused-gpios"; @@ -316,21 +246,21 @@ <&gpioh 3 GPIO_ODR_HIGH>, /* ccd_mode_odl */ <&gpioc 4 GPIO_INPUT>, - /* uart1_rx */ - <&gpiob 0 GPIO_INPUT>, /* unnamed nc pins */ - <&gpioa 3 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpioa 6 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpioa 7 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpioc 3 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpiod 7 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpiof 1 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpioh 0 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpioh 6 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpioi 7 (GPIO_INPUT | GPIO_PULL_DOWN)>, - <&gpiom 6 (GPIO_INPUT | GPIO_PULL_DOWN)>, + <&gpioa 3 GPIO_INPUT_PULL_DOWN>, + <&gpioa 6 GPIO_INPUT_PULL_DOWN>, + <&gpioa 7 GPIO_INPUT_PULL_DOWN>, + <&gpioc 3 GPIO_INPUT_PULL_DOWN>, + <&gpiod 7 GPIO_INPUT_PULL_DOWN>, + <&gpiof 1 GPIO_INPUT_PULL_DOWN>, + <&gpioh 0 GPIO_INPUT_PULL_DOWN>, + <&gpioh 6 GPIO_INPUT_PULL_DOWN>, + <&gpioi 3 GPIO_INPUT_PULL_DOWN>, + <&gpioi 5 GPIO_INPUT_PULL_DOWN>, + <&gpioi 6 GPIO_INPUT_PULL_DOWN>, + <&gpiom 6 GPIO_INPUT_PULL_DOWN>, /* spi_clk_gpg6 */ - <&gpiog 6 (GPIO_INPUT | GPIO_PULL_UP)>, + <&gpiog 6 GPIO_INPUT_PULL_UP>, /* spi_mosi_gpg4 */ <&gpiog 4 GPIO_OUT_LOW>, /* spi_miso_gpg5 */ diff --git a/zephyr/projects/corsola/i2c_kingler.dts b/zephyr/projects/corsola/i2c_kingler.dts new file mode 100644 index 0000000000..21701bddb2 --- /dev/null +++ b/zephyr/projects/corsola/i2c_kingler.dts @@ -0,0 +1,93 @@ +/* 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. + */ + +/ { + named-i2c-ports { + compatible = "named-i2c-ports"; + + i2c_sensor: sensor { + i2c-port = <&i2c0_0>; + enum-name = "I2C_PORT_SENSOR"; + }; + i2c_usb_c0: usb-c0 { + i2c-port = <&i2c1_0>; + enum-name = "I2C_PORT_USB_C0"; + }; + i2c_usb_c1: usb-c1 { + i2c-port = <&i2c2_0>; + enum-name = "I2C_PORT_USB_C1"; + }; + tcpc1 { + i2c-port = <&i2c2_0>; + enum-name = "I2C_PORT_USB_C1_TCPC"; + }; + ppc1 { + i2c-port = <&i2c2_0>; + enum-name = "I2C_PORT_USB_C1_PPC"; + }; + eeprom { + i2c-port = <&i2c3_0>; + enum-name = "I2C_PORT_EEPROM"; + }; + charger { + i2c-port = <&i2c3_0>; + enum-name = "I2C_PORT_POWER"; + }; + battery { + i2c-port = <&i2c5_0>; + enum-name = "I2C_PORT_BATTERY"; + }; + }; +}; + +&i2c0_0 { + label = "I2C_SENSOR"; + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; +}; + +&i2c_ctrl0 { + status = "okay"; +}; + +&i2c1_0 { + label = "I2C_USB_C0"; + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST_PLUS>; +}; + +&i2c_ctrl1 { + status = "okay"; +}; + +&i2c2_0 { + label = "I2C_USB_C1"; + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST_PLUS>; +}; + +&i2c_ctrl2 { + status = "okay"; +}; + +i2c_pwr_cbi: &i2c3_0 { + label = "I2C_PWR_CBI"; + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; +}; + +&i2c_ctrl3 { + status = "okay"; +}; + +&i2c5_0 { + label = "I2C_BATTERY"; + status = "okay"; + clock-frequency = <I2C_BITRATE_STANDARD>; +}; + +&i2c_ctrl5 { + status = "okay"; +}; diff --git a/zephyr/projects/corsola/krabby/i2c.dts b/zephyr/projects/corsola/i2c_krabby.dts index 7205bf19bc..1dbfd83782 100644 --- a/zephyr/projects/corsola/krabby/i2c.dts +++ b/zephyr/projects/corsola/i2c_krabby.dts @@ -7,71 +7,50 @@ named-i2c-ports { compatible = "named-i2c-ports"; - power { - i2c-port = <&i2c0>; - enum-name = "I2C_PORT_POWER"; - label = "POWER"; - }; battery { - i2c-port = <&i2c0>; - remote-port = <0>; + i2c-port = <&i2c1>; + remote-port = <1>; enum-name = "I2C_PORT_BATTERY"; - label = "BATTERY"; }; virtual-battery { - i2c-port = <&i2c0>; + i2c-port = <&i2c1>; enum-name = "I2C_PORT_VIRTUAL_BATTERY"; - label = "VIRTUAL_BATTERY"; }; eeprom { i2c-port = <&i2c0>; enum-name = "I2C_PORT_EEPROM"; - label = "EEPROM"; }; charger { i2c-port = <&i2c0>; enum-name = "I2C_PORT_CHARGER"; - label = "CHARGER"; }; i2c_sensor: sensor { - i2c-port = <&i2c1>; + i2c-port = <&i2c3>; enum-name = "I2C_PORT_SENSOR"; - label = "SENSOR"; - }; - i2c-accel { - i2c-port = <&i2c1>; - enum-name = "I2C_PORT_ACCEL"; - label = "ACCEL"; }; ppc0 { i2c-port = <&i2c2>; enum-name = "I2C_PORT_PPC0"; - label = "PPC0"; }; ppc1 { i2c-port = <&i2c4>; enum-name = "I2C_PORT_PPC1"; - label = "PPC1"; }; usb-c0 { i2c-port = <&i2c2>; enum-name = "I2C_PORT_USB_C0"; - label = "USB_C0"; }; usb-c1 { i2c-port = <&i2c4>; enum-name = "I2C_PORT_USB_C1"; - label = "USB_C1"; }; usb-mux0 { i2c-port = <&i2c2>; enum-name = "I2C_PORT_USB_MUX0"; - label = "USB_MUX0"; }; usb-mux1 { i2c-port = <&i2c4>; enum-name = "I2C_PORT_USB_MUX1"; - label = "USB_MUX1"; }; }; @@ -79,24 +58,42 @@ &i2c0 { /* EC_I2C_PWR_CBI */ + label = "I2C_PWR_CBI"; status = "okay"; - clock-frequency = <I2C_BITRATE_STANDARD>; + clock-frequency = <I2C_BITRATE_FAST>; }; &i2c1 { - /* EC_I2C_SENSOR */ + /* EC_I2C_BATTERY */ + label = "I2C_BATTERY"; status = "okay"; - clock-frequency = <I2C_BITRATE_FAST>; + clock-frequency = <I2C_BITRATE_STANDARD>; }; &i2c2 { /* EC_I2C_USB_C0 */ + label = "I2C_USB_C0"; + status = "okay"; + clock-frequency = <I2C_BITRATE_FAST>; +}; + +&i2c3 { + /* EC_I2C_SENSOR */ + label = "I2C_SENSOR"; status = "okay"; clock-frequency = <I2C_BITRATE_FAST>; + /* + * b/210800948: i2c3 is not working at this moment. + * + * The driver support for i2c3 on GPF2/F3 is under review in + * following PR. + * https://github.com/zephyrproject-rtos/zephyr/pull/41389 + */ }; &i2c4 { /* EC_I2C_USB_C1 */ + label = "I2C_USB_C1"; status = "okay"; clock-frequency = <I2C_BITRATE_FAST>; }; diff --git a/zephyr/projects/corsola/include/baseboard_usbc_config.h b/zephyr/projects/corsola/include/baseboard_usbc_config.h new file mode 100644 index 0000000000..8fa0ff5cd6 --- /dev/null +++ b/zephyr/projects/corsola/include/baseboard_usbc_config.h @@ -0,0 +1,15 @@ +/* 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. + */ + +/* Corsola daughter board detection */ + +#ifndef __CROS_EC_BASEBOARD_USBC_CONFIG_H +#define __CROS_EC_BASEBOARD_USBC_CONFIG_H + +#include "gpio.h" + +void ppc_interrupt(enum gpio_signal signal); + +#endif /* __CROS_EC_BASEBOARD_USBC_CONFIG_H */ diff --git a/zephyr/projects/corsola/include/gpio_map.h b/zephyr/projects/corsola/include/gpio_map.h new file mode 100644 index 0000000000..8fda7b77d0 --- /dev/null +++ b/zephyr/projects/corsola/include/gpio_map.h @@ -0,0 +1,171 @@ +/* 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. + */ + +#ifndef __ZEPHYR_GPIO_MAP_H +#define __ZEPHYR_GPIO_MAP_H + +#include <devicetree.h> +#include <gpio_signal.h> + +#define GPIO_BATT_PRES_ODL NAMED_GPIO(ec_batt_pres_odl) + +#define GPIO_ENTERING_RW GPIO_UNIMPLEMENTED + +/* daughterboard GPIO remap */ +#define GPIO_EN_HDMI_PWR GPIO_EC_X_GPIO1 +#define GPIO_USB_C1_FRS_EN GPIO_EC_X_GPIO1 +#define GPIO_USB_C1_PPC_INT_ODL GPIO_X_EC_GPIO2 +#define GPIO_PS185_EC_DP_HPD GPIO_X_EC_GPIO2 +#define GPIO_USB_C1_DP_IN_HPD GPIO_EC_X_GPIO3 +#define GPIO_PS185_PWRDN_ODL GPIO_EC_X_GPIO3 + +#ifdef CONFIG_PLATFORM_EC_POWER_BUTTON + #define PWRBTN_INT() GPIO_INT(GPIO_POWER_BUTTON_L, \ + GPIO_INT_EDGE_BOTH, \ + power_button_interrupt) +#else + #define PWRBTN_INT() +#endif + +#ifdef CONFIG_PLATFORM_EC_VOLUME_BUTTONS + #define VOLBTN_INT(pin) GPIO_INT(pin, \ + GPIO_INT_EDGE_BOTH, \ + button_interrupt) +#else + #define VOLBTN_INT(pin) +#endif + +#ifdef CONFIG_SOC_IT8XXX2 + #define AP_SPI_INT() GPIO_INT(GPIO_SPI0_CS, \ + GPIO_INT_EDGE_BOTH, \ + spi_event) +#elif defined(CONFIG_SOC_NPCX9M3F) + /* The interrupt is configured by dts */ + #define AP_SPI_INT() +#endif + +#ifdef CONFIG_PLATFORM_EC_TABLET_MODE + #define GMR_TABLET_INT() GPIO_INT(GPIO_TABLET_MODE_L, \ + GPIO_INT_EDGE_BOTH, \ + gmr_tablet_switch_isr) +#else + #define GMR_TABLET_INT() +#endif + +#ifdef CONFIG_PLATFORM_EC_POWERSEQ_MT8186 + #define WARM_RST_REQ_INT() GPIO_INT(GPIO_AP_EC_WARM_RST_REQ, \ + GPIO_INT_EDGE_RISING, \ + chipset_reset_request_interrupt) + + #define AP_IN_SLEEP_INT() GPIO_INT(GPIO_AP_IN_SLEEP_L, \ + GPIO_INT_EDGE_BOTH, \ + power_signal_interrupt) + + #define AP_IN_RST_INT() GPIO_INT(GPIO_AP_EC_SYSRST_ODL, \ + GPIO_INT_EDGE_BOTH, \ + power_signal_interrupt) + + #define AP_EC_WDTRST_INT() GPIO_INT(GPIO_AP_EC_WDTRST_L, \ + GPIO_INT_EDGE_BOTH, \ + power_signal_interrupt) +#else + #define WARM_RST_REQ_INT() + #define AP_IN_SLEEP_INT() + #define AP_IN_RST_INT() + #define AP_EC_WDTRST_INT() +#endif + +#ifdef CONFIG_PLATFORM_EC_ACCEL_LIS2DW12 + #define LID_ACCEL_INT() GPIO_INT(GPIO_LID_ACCEL_INT_L, \ + GPIO_INT_EDGE_FALLING, \ + lis2dw12_interrupt) +#else + #define LID_ACCEL_INT() +#endif + +#ifdef CONFIG_PLATFORM_EC_EXTPOWER_GPIO + #define EXTPWR_INT() GPIO_INT(GPIO_AC_PRESENT, \ + GPIO_INT_EDGE_BOTH, \ + extpower_interrupt) +#else + #define EXTPWR_INT() +#endif + +#ifdef CONFIG_PLATFORM_EC_LID_SWITCH + #define LID_SWITCH_INT() GPIO_INT(GPIO_LID_OPEN, \ + GPIO_INT_EDGE_BOTH, \ + lid_interrupt) +#else + #define LID_SWITCH_INT() +#endif + +#ifdef CONFIG_PLATFORM_EC_SWITCH + #define SWITCH_INT() GPIO_INT(GPIO_WP_L, \ + GPIO_INT_EDGE_BOTH, \ + switch_interrupt) +#else + #define SWITCH_INT() +#endif + +#ifdef CONFIG_VARIANT_CORSOLA_DB_DETECTION + #define X_EC_GPIO2_INT() GPIO_INT(GPIO_X_EC_GPIO2, \ + GPIO_INT_EDGE_BOTH, \ + x_ec_interrupt) +#else + #define X_EC_GPIO2_INT() +#endif + +#ifdef CONFIG_VARIANT_CORSOLA_USBA + #define USBA_INT() GPIO_INT(GPIO_AP_XHCI_INIT_DONE, \ + GPIO_INT_EDGE_BOTH, \ + usb_a0_interrupt) +#else + #define USBA_INT() +#endif + +#ifdef CONFIG_PLATFORM_EC_GMR_TABLET_MODE +#define GMR_TABLET_MODE_GPIO_L GPIO_TABLET_MODE_L +#endif + +/* TODO: remove after icm426xx driver added */ +static inline void motion_interrupt(enum gpio_signal signal) +{ +} + +/* + * Set EC_CROS_GPIO_INTERRUPTS to a space-separated list of GPIO_INT items. + * + * Each GPIO_INT requires three parameters: + * gpio_signal - The enum gpio_signal for the interrupt gpio + * interrupt_flags - The interrupt-related flags (e.g. GPIO_INT_EDGE_BOTH) + * handler - The platform/ec interrupt handler. + * + * Ensure that this files includes all necessary headers to declare all + * referenced handler functions. + * + * For example, one could use the follow definition: + * #define EC_CROS_GPIO_INTERRUPTS \ + * GPIO_INT(NAMED_GPIO(h1_ec_pwr_btn_odl), GPIO_INT_EDGE_BOTH, button_print) + */ +#define EC_CROS_GPIO_INTERRUPTS \ + PWRBTN_INT() \ + VOLBTN_INT(GPIO_VOLUME_DOWN_L) \ + VOLBTN_INT(GPIO_VOLUME_UP_L) \ + LID_SWITCH_INT() \ + WARM_RST_REQ_INT() \ + AP_IN_SLEEP_INT() \ + AP_IN_RST_INT() \ + AP_EC_WDTRST_INT() \ + GMR_TABLET_INT() \ + GPIO_INT(GPIO_BASE_IMU_INT_L, \ + GPIO_INT_EDGE_FALLING, motion_interrupt) \ + LID_ACCEL_INT() \ + USBA_INT() \ + EXTPWR_INT() \ + SWITCH_INT() \ + AP_SPI_INT() \ + X_EC_GPIO2_INT() + +#endif /* __ZEPHYR_GPIO_MAP_H */ diff --git a/zephyr/projects/corsola/krabby/include/i2c_map.h b/zephyr/projects/corsola/include/i2c_map.h index 898d5c398c..898d5c398c 100644 --- a/zephyr/projects/corsola/krabby/include/i2c_map.h +++ b/zephyr/projects/corsola/include/i2c_map.h diff --git a/zephyr/projects/corsola/include/variant_db_detection.h b/zephyr/projects/corsola/include/variant_db_detection.h new file mode 100644 index 0000000000..40853016f8 --- /dev/null +++ b/zephyr/projects/corsola/include/variant_db_detection.h @@ -0,0 +1,32 @@ +/* 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. + */ + +/* Corsola daughter board detection */ + +#ifndef __CROS_EC_CORSOLA_DB_DETECTION_H +#define __CROS_EC_CORSOLA_DB_DETECTION_H + +enum corsola_db_type { + CORSOLA_DB_NONE = -1, + CORSOLA_DB_TYPEC, + CORSOLA_DB_HDMI, + CORSOLA_DB_COUNT, +}; + +#ifdef CONFIG_VARIANT_CORSOLA_DB_DETECTION +/* + * Get the connected daughterboard type. + * + * @return The daughterboard type. + */ +enum corsola_db_type corsola_get_db_type(void); +#else +inline enum corsola_db_type corsola_get_db_type(void) +{ + return CORSOLA_DB_NONE; +}; +#endif /* CONFIG_VARIANT_CORSOLA_DB_DETECTION */ + +#endif /* __CROS_EC_CORSOLA_DB_DETECTION_H */ diff --git a/zephyr/projects/corsola/kingler/CMakeLists.txt b/zephyr/projects/corsola/kingler/CMakeLists.txt deleted file mode 100644 index 33e56afc0e..0000000000 --- a/zephyr/projects/corsola/kingler/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# 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. - -cmake_minimum_required(VERSION 3.13.1) - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(kingler) - -zephyr_library_include_directories(include) diff --git a/zephyr/projects/corsola/kingler/gpio.dts b/zephyr/projects/corsola/kingler/gpio.dts deleted file mode 100644 index 638e95c9fb..0000000000 --- a/zephyr/projects/corsola/kingler/gpio.dts +++ /dev/null @@ -1,337 +0,0 @@ -/ { - named-gpios { - compatible = "named-gpios"; - - ec_wp_l { - gpios = <&gpio5 0 GPIO_INPUT>; - label = "EC_WP_L"; - enum-name = "GPIO_WP_L"; - }; - ccd_mode_odl { - gpios = <&gpioc 6 GPIO_ODR_HIGH>; - label = "CCD_MODE_ODL"; - }; - ec_gsc_packet_mode { - gpios = <&gpiob 1 GPIO_OUT_LOW>; - label = "EC_GSC_PACKET_MODE"; - }; - mech_pwr_btn_odl { - gpios = <&gpiod 2 GPIO_INPUT>; - label = "MECH_PWR_BTN_ODL"; - enum-name = "GPIO_POWER_BUTTON_L"; - }; - ec_pwr_btn_odl { - gpios = <&gpio0 1 GPIO_INPUT>; - label = "EC_PWR_BTN_ODL"; - enum-name = "GPIO_EC_PWR_BTN_ODL"; - }; - slp_s3_l { - gpios = <&gpio6 1 GPIO_INPUT>; - label = "SLP_S3_L"; - enum-name = "GPIO_PCH_SLP_S3_L"; - }; - slp_s5_l { - gpios = <&gpio7 2 GPIO_INPUT>; - label = "SLP_S5_L"; - enum-name = "GPIO_PCH_SLP_S5_L"; - }; - slp_s3_s0i3_l { - gpios = <&gpio7 4 GPIO_INPUT>; - label = "SLP_S3_S0I3_L"; - enum-name = "GPIO_PCH_SLP_S0_L"; - }; - pg_pwr_s5 { - gpios = <&gpioc 0 GPIO_INPUT>; - label = "PG_PWR_S5"; - enum-name = "GPIO_S5_PGOOD"; - }; - pg_pcore_s0_r_od { - gpios = <&gpiob 6 GPIO_INPUT>; - label = "PG_PCORE_S0_R_OD"; - enum-name = "GPIO_S0_PGOOD"; - }; - acok_od { - gpios = <&gpio0 0 GPIO_INPUT>; - label = "ACOK_OD"; - enum-name = "GPIO_AC_PRESENT"; - }; - ec_pcore_int_odl { - gpios = <&gpiof 0 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_PCORE_INT_ODL"; - enum-name = "GPIO_EC_PCORE_INT_ODL"; - }; - pg_groupc_s0_od { - gpios = <&gpioa 3 GPIO_INPUT>; - label = "PG_GROUPC_S0_OD"; - enum-name = "GPIO_PG_GROUPC_S0_OD"; - }; - pg_lpddr4x_s3_od { - gpios = <&gpio9 5 GPIO_INPUT>; - label = "PG_LPDDR4X_S3_OD"; - enum-name = "GPIO_PG_LPDDR4X_S3_OD"; - }; - en_pwr_s5 { - gpios = <&gpiob 7 GPIO_OUT_LOW>; - label = "EN_PWR_S5"; - enum-name = "GPIO_EN_PWR_A"; - }; - en_pwr_s0_r { - gpios = <&gpiof 1 GPIO_OUT_LOW>; - label = "EN_PWR_S0_R"; - enum-name = "GPIO_EN_PWR_S0_R"; - }; - en_pwr_pcore_s0_r { - gpios = <&gpioe 1 GPIO_OUT_LOW>; - label = "EN_PWR_PCORE_S0_R"; - enum-name = "GPIO_EN_PWR_PCORE_S0_R"; - }; - ec_entering_rw { - gpios = <&gpio6 6 GPIO_OUT_LOW>; - label = "EC_ENTERING_RW"; - enum-name = "GPIO_ENTERING_RW"; - }; - ec_sys_rst_l { - gpios = <&gpio7 6 GPIO_ODR_HIGH>; - label = "EC_SYS_RST_L"; - enum-name = "GPIO_SYS_RESET_L"; - }; - ec_soc_rsmrst_l { - gpios = <&gpioc 5 GPIO_OUT_LOW>; - label = "EC_SOC_RSMRST_L"; - enum-name = "GPIO_PCH_RSMRST_L"; - }; - ec_clr_cmos { - gpios = <&gpioa 1 GPIO_OUT_LOW>; - label = "EC_CLR_CMOS"; - }; - ec_mem_event { - gpios = <&gpioa 5 GPIO_OUT_LOW>; - label = "EC_MEM_EVENT"; - }; - ec_soc_pwr_btn_l { - gpios = <&gpio6 3 GPIO_OUT_HIGH>; - label = "EC_SOC_PWR_BTN_L"; - enum-name = "GPIO_PCH_PWRBTN_L"; - }; - ec_soc_pwr_good { - gpios = <&gpiod 3 GPIO_OUT_LOW>; - label = "EC_SOC_PWR_GOOD"; - enum-name = "GPIO_PCH_SYS_PWROK"; - }; - ec_soc_wake_l { - gpios = <&gpio0 3 GPIO_OUT_HIGH>; - label = "EC_SOC_WAKE_L"; - enum-name = "GPIO_EC_PCH_WAKE_ODL"; - }; - ec_soc_int_l { - gpios = <&gpio8 3 GPIO_OUT_HIGH>; - label = "EC_SOC_INT_L"; - }; - prochot_odl { - gpios = <&gpiod 5 GPIO_ODR_HIGH>; - label = "PROCHOT_ODL"; - enum-name = "GPIO_CPU_PROCHOT"; - }; - soc_alert_ec_l { - gpios = <&gpioe 2 GPIO_INPUT>; - label = "SOC_ALERT_EC_L"; - }; - soc_thermtrip_odl { - gpios = <&gpioe 5 GPIO_INPUT>; - label = "SOC_THERMTRIP_ODL"; - }; - usb_c0_tcpc_int_odl { - gpios = <&gpioe 0 GPIO_INPUT>; - label = "USB_C0_TCPC_INT_ODL"; - }; - usb_c1_tcpc_int_odl { - gpios = <&gpioc 7 GPIO_INPUT>; - label = "USB_C1_TCPC_INT_ODL"; - }; - usb_c0_ppc_int_odl { - gpios = <&gpio7 5 GPIO_INPUT>; - label = "USB_C0_PPC_INT_ODL"; - }; - usb_c1_ppc_int_odl { - gpios = <&gpiod 4 GPIO_INPUT>; - label = "USB_C1_PPC_INT_ODL"; - }; - usb_c0_bc12_int_odl { - gpios = <&gpioa 4 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "USB_C0_BC12_INT_ODL"; - }; - usb_c1_bc12_int_odl { - gpios = <&gpio9 6 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "USB_C1_BC12_INT_ODL"; - }; - usb_c0_c1_fault_odl { - gpios = <&gpio7 3 GPIO_ODR_HIGH>; - label = "USB_C0_C1_FAULT_ODL"; - }; - usb_c0_tcpc_rst_l { - gpios = <&gpio3 4 GPIO_OUT_HIGH>; - label = "USB_C0_TCPC_RST_L"; - }; - usb_c1_tcpc_rst_l { - gpios = <&gpio3 7 GPIO_OUT_HIGH>; - label = "USB_C1_TCPC_RST_L"; - }; - usb_c0_hpd { - gpios = <&gpiof 5 GPIO_OUT_LOW>; - label = "USB_C0_HPD"; - }; - usb_c1_hpd { - gpios = <&gpiof 4 GPIO_OUT_LOW>; - label = "USB_C1_HPD"; - }; - 3axis_int_l { - gpios = <&gpioa 2 (GPIO_INPUT | GPIO_PULL_DOWN)>; - label = "3AXIS_INT_L"; - }; - lid_open { - gpios = <&gpio0 2 GPIO_INPUT>; - label = "LID_OPEN"; - enum-name = "GPIO_LID_OPEN"; - }; - voldn_btn_odl { - gpios = <&gpioa 7 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "VOLDN_BTN_ODL"; - enum-name = "GPIO_VOLUME_DOWN_L"; - }; - volup_btn_odl { - gpios = <&gpio9 3 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "VOLUP_BTN_ODL"; - enum-name = "GPIO_VOLUME_UP_L"; - }; - ec_batt_pres_odl { - gpios = <&gpio9 4 GPIO_INPUT>; - label = "EC_BATT_PRES_ODL"; - enum-name = "GPIO_BATT_PRES_ODL"; - }; - ec_disable_disp_bl { - gpios = <&gpioa 6 GPIO_OUT_HIGH>; - label = "EC_DISABLE_DISP_BL"; - }; - ec_i2c_usb_a0_c0_scl { - gpios = <&gpiob 5 GPIO_INPUT>; - label = "EC_I2C_USB_A0_C0_SCL"; - }; - ec_i2c_usb_a0_c0_sda { - gpios = <&gpiob 4 GPIO_INPUT>; - label = "EC_I2C_USB_A0_C0_SDA"; - }; - ec_i2c_usb_a1_c1_scl { - gpios = <&gpio9 0 GPIO_INPUT>; - label = "EC_I2C_USB_A1_C1_SCL"; - }; - ec_i2c_usb_a1_c1_sda { - gpios = <&gpio8 7 GPIO_INPUT>; - label = "EC_I2C_USB_A1_C1_SDA"; - }; - ec_i2c_batt_scl { - gpios = <&gpio9 2 GPIO_INPUT>; - label = "EC_I2C_BATT_SCL"; - }; - ec_i2c_batt_sda { - gpios = <&gpio9 1 GPIO_INPUT>; - label = "EC_I2C_BATT_SDA"; - }; - ec_i2c_usbc_mux_scl { - gpios = <&gpiod 1 GPIO_INPUT>; - label = "EC_I2C_USBC_MUX_SCL"; - }; - ec_i2c_usbc_mux_sda { - gpios = <&gpiod 0 GPIO_INPUT>; - label = "EC_I2C_USBC_MUX_SDA"; - }; - ec_i2c_power_scl { - gpios = <&gpiof 3 GPIO_INPUT>; - label = "EC_I2C_POWER_SCL"; - }; - ec_i2c_power_sda { - gpios = <&gpiof 2 GPIO_INPUT>; - label = "EC_I2C_POWER_SDA"; - }; - ec_i2c_cbi_scl { - gpios = <&gpio3 3 GPIO_INPUT>; - label = "EC_I2C_CBI_SCL"; - }; - ec_i2c_cbi_sda { - gpios = <&gpio3 6 GPIO_INPUT>; - label = "EC_I2C_CBI_SDA"; - }; - ec_i2c_sensor_scl { - gpios = <&gpioe 4 GPIO_INPUT>; - label = "EC_I2C_SENSOR_SCL"; - }; - ec_i2c_sensor_sda { - gpios = <&gpioe 3 GPIO_INPUT>; - label = "EC_I2C_SENSOR_SDA"; - }; - ec_i2c_soc_sic { - gpios = <&gpiob 3 GPIO_INPUT>; - label = "EC_I2C_SOC_SIC"; - }; - ec_i2c_soc_sid { - gpios = <&gpiob 2 GPIO_INPUT>; - label = "EC_I2C_SOC_SID"; - }; - en_kb_bl { - gpios = <&gpio9 7 GPIO_OUT_HIGH>; - label = "EN_KB_BL"; - }; - ec_kso_02_inv { - gpios = <&gpio1 7 GPIO_OUT_LOW>; - label = "EC_KSO_02_INV"; - enum-name = "GPIO_KBD_KSO2"; - }; - ec_espi_rst_l { - gpios = <&gpio5 4 GPIO_PULL_UP>; - label = "EC_ESPI_RST_L"; - }; - 6axis_int_l { - gpios = <&gpioa 0 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "6AXIS_INT_L"; - }; - tablet_mode { - gpios = <&gpioc 1 GPIO_INPUT>; - label = "TABLET_MODE"; - }; - ec_gpio56 { - gpios = <&gpio5 6 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_GPIO56"; - }; - ec_ps2_clk { - gpios = <&gpio6 7 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_PS2_CLK"; - }; - ec_ps2_dat { - gpios = <&gpio7 0 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_PS2_DAT"; - }; - ec_ps2_rst { - gpios = <&gpio6 2 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_PS2_RST"; - }; - ec_gpiob0 { - gpios = <&gpiob 0 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_GPIOB0"; - }; - ec_gpio81 { - gpios = <&gpio8 1 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_GPIO81"; - }; - ec_flprg2 { - gpios = <&gpio8 6 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_FLPRG2"; - }; - ec_psl_gpo { - gpios = <&gpiod 7 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_PSL_GPO"; - }; - ec_pwm7 { - gpios = <&gpio6 0 (GPIO_INPUT | GPIO_PULL_UP)>; - label = "EC_PWM7"; - }; - }; -}; diff --git a/zephyr/projects/corsola/kingler/i2c.dts b/zephyr/projects/corsola/kingler/i2c.dts deleted file mode 100644 index 699c4b9b7b..0000000000 --- a/zephyr/projects/corsola/kingler/i2c.dts +++ /dev/null @@ -1,38 +0,0 @@ -/* 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. - */ - -/ { - aliases { - i2c-0 = &i2c0_0; - i2c-1 = &i2c1_0; - i2c-2 = &i2c2_0; - i2c-3 = &i2c3_0; - i2c-4 = &i2c4_1; - i2c-5 = &i2c5_0; - i2c-7 = &i2c7_0; - }; - - named-i2c-ports { - compatible = "named-i2c-ports"; - - battery { - i2c-port = <&i2c2_0>; - remote-port = <0>; - enum-name = "I2C_PORT_BATTERY"; - label = "BATTERY"; - }; - }; - - -}; - -&i2c2_0 { - status = "okay"; - clock-frequency = <I2C_BITRATE_STANDARD>; -}; - -&i2c_ctrl2 { - status = "okay"; -}; diff --git a/zephyr/projects/corsola/kingler/include/gpio_map.h b/zephyr/projects/corsola/kingler/include/gpio_map.h deleted file mode 100644 index 025bb78743..0000000000 --- a/zephyr/projects/corsola/kingler/include/gpio_map.h +++ /dev/null @@ -1,29 +0,0 @@ -/* 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. - */ - -#ifndef __ZEPHYR_GPIO_MAP_H -#define __ZEPHYR_GPIO_MAP_H - -#include <devicetree.h> -#include <gpio_signal.h> - -/* - * Set EC_CROS_GPIO_INTERRUPTS to a space-separated list of GPIO_INT items. - * - * Each GPIO_INT requires three parameters: - * gpio_signal - The enum gpio_signal for the interrupt gpio - * interrupt_flags - The interrupt-related flags (e.g. GPIO_INT_EDGE_BOTH) - * handler - The platform/ec interrupt handler. - * - * Ensure that this files includes all necessary headers to declare all - * referenced handler functions. - * - * For example, one could use the follow definition: - * #define EC_CROS_GPIO_INTERRUPTS \ - * GPIO_INT(NAMED_GPIO(h1_ec_pwr_btn_odl), GPIO_INT_EDGE_BOTH, button_print) - */ -#define EC_CROS_GPIO_INTERRUPTS - -#endif /* __ZEPHYR_GPIO_MAP_H */ diff --git a/zephyr/projects/corsola/kingler/prj.conf b/zephyr/projects/corsola/kingler/prj.conf deleted file mode 100644 index d09697de5d..0000000000 --- a/zephyr/projects/corsola/kingler/prj.conf +++ /dev/null @@ -1,52 +0,0 @@ -# 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. - -CONFIG_CROS_EC=y -CONFIG_PLATFORM_EC=y -CONFIG_SHIMMED_TASKS=y -CONFIG_ESPI=y - -# Shell features -CONFIG_SHELL_HELP=y -CONFIG_SHELL_HISTORY=y -CONFIG_SHELL_TAB_AUTOCOMPLETION=y -CONFIG_KERNEL_SHELL=y - -CONFIG_PLATFORM_EC_VBOOT_EFS2=n - -# Power sequencing -CONFIG_AP=y - -# Power button -CONFIG_PLATFORM_EC_POWER_BUTTON=y - -# External power -CONFIG_PLATFORM_EC_HOSTCMD=y -CONFIG_PLATFORM_EC_EXTPOWER_GPIO=y -CONFIG_PLATFORM_EC_BACKLIGHT_LID=n - -# Lid switch -CONFIG_PLATFORM_EC_LID_SWITCH=y - -# Keyboard -CONFIG_PLATFORM_EC_KEYBOARD=y -CONFIG_PLATFORM_EC_KEYBOARD_COL2_INVERTED=y -CONFIG_PLATFORM_EC_VOLUME_BUTTONS=y - -CONFIG_SYSCON=y - -# Battery -CONFIG_PLATFORM_EC_BATTERY=y -CONFIG_PLATFORM_EC_BATTERY_SMART=y -CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y -CONFIG_PLATFORM_EC_BATTERY_CUT_OFF=n -CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y - -CONFIG_PLATFORM_EC_CHARGER=n -CONFIG_PLATFORM_EC_USBC=n - -# This is not yet supported -CONFIG_PLATFORM_EC_ADC=n -CONFIG_PLATFORM_EC_BOARD_VERSION_CBI=n -CONFIG_PLATFORM_EC_BOARD_VERSION_GPIO=n diff --git a/zephyr/projects/corsola/krabby/BUILD.py b/zephyr/projects/corsola/krabby/BUILD.py deleted file mode 100644 index e533544d8c..0000000000 --- a/zephyr/projects/corsola/krabby/BUILD.py +++ /dev/null @@ -1,16 +0,0 @@ -# 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. - -register_binman_project( - project_name="krabby", - zephyr_board="it8xxx2", - dts_overlays=[ - "adc.dts", - "battery.dts", - "gpio.dts", - "i2c.dts", - "motionsense.dts", - "pwm.dts", - ], -) diff --git a/zephyr/projects/corsola/krabby/CMakeLists.txt b/zephyr/projects/corsola/krabby/CMakeLists.txt deleted file mode 100644 index dd59e4e2fb..0000000000 --- a/zephyr/projects/corsola/krabby/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -# 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. - -cmake_minimum_required(VERSION 3.13.1) -add_compile_definitions(BOARD_KRABBY) - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -project(krabby) - -zephyr_library_include_directories(include) - -set(PLATFORM_EC_BASEBOARD "${PLATFORM_EC}/baseboard/corsola" CACHE PATH - "Path to the platform/ec baseboard directory") -set(PLATFORM_EC_BOARD "${PLATFORM_EC}/board/krabby" CACHE PATH - "Path to the platform/ec board directory") - -# Include selected EC source from the baseboard -zephyr_library_sources( - "${PLATFORM_EC_BASEBOARD}/board_chipset.c" - "${PLATFORM_EC_BASEBOARD}/board_id.c" - "${PLATFORM_EC_BASEBOARD}/hibernate.c" - "${PLATFORM_EC_BASEBOARD}/regulator.c" - "${PLATFORM_EC_BASEBOARD}/usbc_config.c" - "${PLATFORM_EC_BASEBOARD}/usb_pd_policy.c") - -# Include selected EC source from the board -zephyr_library_sources( - "${PLATFORM_EC_BOARD}/hooks.c" - "${PLATFORM_EC_BOARD}/led.c") - -zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_I2C - "src/i2c.c") diff --git a/zephyr/projects/corsola/krabby/include/gpio_map.h b/zephyr/projects/corsola/krabby/include/gpio_map.h deleted file mode 100644 index 9122c85ffc..0000000000 --- a/zephyr/projects/corsola/krabby/include/gpio_map.h +++ /dev/null @@ -1,69 +0,0 @@ -/* 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. - */ - -#ifndef __ZEPHYR_GPIO_MAP_H -#define __ZEPHYR_GPIO_MAP_H - -#include <devicetree.h> -#include <gpio_signal.h> - -#define GPIO_ENTERING_RW GPIO_UNIMPLEMENTED -#define GPIO_WP_L GPIO_UNIMPLEMENTED - -#ifdef CONFIG_PLATFORM_EC_GMR_TABLET_MODE -#define GMR_TABLET_MODE_GPIO_L GPIO_TABLET_MODE_L -#endif - -/* TODO: remove after icm426xx driver added */ -static inline void motion_interrupt(enum gpio_signal signal) -{ -} - -/* - * Set EC_CROS_GPIO_INTERRUPTS to a space-separated list of GPIO_INT items. - * - * Each GPIO_INT requires three parameters: - * gpio_signal - The enum gpio_signal for the interrupt gpio - * interrupt_flags - The interrupt-related flags (e.g. GPIO_INT_EDGE_BOTH) - * handler - The platform/ec interrupt handler. - * - * Ensure that this files includes all necessary headers to declare all - * referenced handler functions. - * - * For example, one could use the follow definition: - * #define EC_CROS_GPIO_INTERRUPTS \ - * GPIO_INT(NAMED_GPIO(h1_ec_pwr_btn_odl), GPIO_INT_EDGE_BOTH, button_print) - */ -#define EC_CROS_GPIO_INTERRUPTS \ - GPIO_INT(GPIO_POWER_BUTTON_L, \ - GPIO_INT_EDGE_BOTH, power_button_interrupt) \ - GPIO_INT(GPIO_LID_OPEN, \ - GPIO_INT_EDGE_BOTH, lid_interrupt) \ - GPIO_INT(GPIO_TABLET_MODE_L, \ - GPIO_INT_EDGE_BOTH, gmr_tablet_switch_isr) \ - GPIO_INT(GPIO_AP_EC_WARM_RST_REQ, \ - GPIO_INT_EDGE_RISING, chipset_reset_request_interrupt) \ - GPIO_INT(GPIO_AP_IN_SLEEP_L, \ - GPIO_INT_EDGE_BOTH, power_signal_interrupt) \ - GPIO_INT(GPIO_BASE_IMU_INT_L, \ - GPIO_INT_EDGE_FALLING, motion_interrupt) \ - GPIO_INT(GPIO_LID_ACCEL_INT_L, \ - GPIO_INT_EDGE_FALLING, lis2dw12_interrupt) \ - GPIO_INT(GPIO_VOLUME_DOWN_L, \ - GPIO_INT_EDGE_BOTH, button_interrupt) \ - GPIO_INT(GPIO_VOLUME_UP_L, \ - GPIO_INT_EDGE_BOTH, button_interrupt) \ - GPIO_INT(GPIO_AP_XHCI_INIT_DONE, \ - GPIO_INT_EDGE_BOTH, usb_a0_interrupt) \ - GPIO_INT(GPIO_AC_PRESENT, \ - GPIO_INT_EDGE_BOTH, extpower_interrupt) \ - GPIO_INT(GPIO_WP, \ - GPIO_INT_EDGE_BOTH, switch_interrupt) \ - GPIO_INT(GPIO_SPI0_CS, \ - GPIO_INT_EDGE_FALLING, spi_event) \ - GPIO_INT(GPIO_X_EC_GPIO2, \ - GPIO_INT_EDGE_BOTH, x_ec_interrupt) - -#endif /* __ZEPHYR_GPIO_MAP_H */ diff --git a/zephyr/projects/corsola/krabby/motionsense.dts b/zephyr/projects/corsola/motionsense_krabby.dts index 00434e6be9..00434e6be9 100644 --- a/zephyr/projects/corsola/krabby/motionsense.dts +++ b/zephyr/projects/corsola/motionsense_krabby.dts diff --git a/zephyr/projects/corsola/power_signal.dts b/zephyr/projects/corsola/power_signal.dts new file mode 100644 index 0000000000..2603a53bb4 --- /dev/null +++ b/zephyr/projects/corsola/power_signal.dts @@ -0,0 +1,26 @@ +/* Copyright 2022 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_signal_list: power-signal-list { + compatible = "mt8186,power-signal-list"; + ap_in_rst { + power-enum-name = "AP_IN_RST"; + power-gpio-pin = <&ap_sysrst_odl_r>; + }; + ap_in_s3 { + power-enum-name = "AP_IN_S3"; + power-gpio-pin = <&ap_in_sleep_l>; + }; + ap_wdt_asserted { + power-enum-name = "AP_WDT_ASSERTED"; + power-gpio-pin = <&ap_ec_wdtrst_l>; + }; + ap_warm_rst_req { + power-enum-name = "AP_WARM_RST_REQ"; + power-gpio-pin = <&ap_ec_warm_rst_req>; + }; + }; +}; diff --git a/zephyr/projects/corsola/kingler/BUILD.py b/zephyr/projects/corsola/prj.conf index 5a4b9722ea..80f1d03d96 100644 --- a/zephyr/projects/corsola/kingler/BUILD.py +++ b/zephyr/projects/corsola/prj.conf @@ -1,9 +1,3 @@ # 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. - -register_npcx_project( - project_name="kingler", - zephyr_board="npcx9", - dts_overlays=["battery.dts", "gpio.dts", "i2c.dts"], -) diff --git a/zephyr/projects/corsola/prj_kingler.conf b/zephyr/projects/corsola/prj_kingler.conf new file mode 100644 index 0000000000..d86036816c --- /dev/null +++ b/zephyr/projects/corsola/prj_kingler.conf @@ -0,0 +1,75 @@ +# 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. + +# Cros EC +CONFIG_CROS_EC=y +CONFIG_PLATFORM_EC=y +CONFIG_PLATFORM_EC_BRINGUP=y +CONFIG_SHIMMED_TASKS=y +CONFIG_PLATFORM_EC_SWITCH=y + +# Variant config +CONFIG_BOARD_KINGLER=y +CONFIG_VARIANT_CORSOLA_DB_DETECTION=n +CONFIG_VARIANT_CORSOLA_USBA=n + +# Shell features +CONFIG_KERNEL_SHELL=y +CONFIG_SHELL_HELP=y +CONFIG_SHELL_TAB=y +CONFIG_SHELL_TAB_AUTOCOMPLETION=y +CONFIG_SHELL_HISTORY=y + +# Bring up options +CONFIG_PLATFORM_EC_SYSTEM_UNLOCKED=y + +CONFIG_PLATFORM_EC_VBOOT_EFS2=n + +# ADC +CONFIG_ADC=y +CONFIG_PLATFORM_EC_ADC=y + +# CBI +CONFIG_PLATFORM_EC_CBI_EEPROM=y +CONFIG_PLATFORM_EC_BOARD_VERSION_CBI=y + +# Host command +CONFIG_PLATFORM_EC_HOSTCMD=y + +# I2C +CONFIG_I2C=y +CONFIG_PLATFORM_EC_I2C=y + +# Power sequencing +CONFIG_AP=y +CONFIG_AP_ARM_MTK_MT8186=y +CONFIG_PLATFORM_EC_POWERSEQ_MT8186=y + +# Treat 2nd reset from H1 as Power-On +CONFIG_PLATFORM_EC_BOARD_RESET_AFTER_POWER_ON=y +CONFIG_PLATFORM_EC_POWERSEQ=y +CONFIG_PLATFORM_EC_POWERSEQ_S4=n +CONFIG_PLATFORM_EC_POWERSEQ_PP5000_CONTROL=n + +# Button +CONFIG_PLATFORM_EC_POWER_BUTTON=y +CONFIG_PLATFORM_EC_VOLUME_BUTTONS=y + +# Sensors +CONFIG_PLATFORM_EC_LID_SWITCH=y + +# External power +CONFIG_PLATFORM_EC_BACKLIGHT_LID=n +CONFIG_PLATFORM_EC_EXTPOWER_GPIO=y + +# Keyboard +CONFIG_PLATFORM_EC_KEYBOARD=n +CONFIG_CROS_KB_RAW_NPCX=n + +CONFIG_SYSCON=y + +CONFIG_PLATFORM_EC_CHARGER=n +CONFIG_PLATFORM_EC_USBC=n + +CONFIG_PLATFORM_EC_BOARD_VERSION_GPIO=n diff --git a/zephyr/projects/corsola/krabby/prj.conf b/zephyr/projects/corsola/prj_krabby.conf index ad86923679..0a3ddcaf6e 100644 --- a/zephyr/projects/corsola/krabby/prj.conf +++ b/zephyr/projects/corsola/prj_krabby.conf @@ -6,10 +6,26 @@ CONFIG_CROS_EC=y CONFIG_PLATFORM_EC=y CONFIG_SHIMMED_TASKS=y +CONFIG_BOARD_KRABBY=y + +# AP SoC configuration +CONFIG_AP=y +CONFIG_AP_ARM_MTK_MT8186=y + # Bring up options CONFIG_KERNEL_SHELL=y CONFIG_PLATFORM_EC_SYSTEM_UNLOCKED=y -CONFIG_GPIO_EMUL=y +CONFIG_PLATFORM_EC_BRINGUP=y + +# Power Sequencing +CONFIG_PLATFORM_EC_POWERSEQ=y +CONFIG_PLATFORM_EC_POWERSEQ_HOST_SLEEP=y +CONFIG_PLATFORM_EC_POWERSEQ_PP5000_CONTROL=n +CONFIG_PLATFORM_EC_EXTPOWER_GPIO=y +CONFIG_PLATFORM_EC_CHIPSET_RESET_HOOK=y + +# Lid Switch +CONFIG_PLATFORM_EC_LID_SWITCH=y # Battery CONFIG_PLATFORM_EC_BATTERY=y @@ -26,7 +42,6 @@ CONFIG_PLATFORM_EC_CHARGE_MANAGER=y CONFIG_PLATFORM_EC_CHARGE_RAMP_HW=y CONFIG_PLATFORM_EC_CHARGER_DISCHARGE_ON_AC=y CONFIG_PLATFORM_EC_CHARGER_DISCHARGE_ON_AC_CHARGER=y -CONFIG_PLATFORM_EC_CHARGER_ISL9238C=y CONFIG_PLATFORM_EC_CHARGER_MAINTAIN_VBAT=y CONFIG_PLATFORM_EC_CHARGER_OTG=y CONFIG_PLATFORM_EC_CHARGER_PSYS=y @@ -42,7 +57,6 @@ CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCELS=y CONFIG_PLATFORM_EC_CONSOLE_CMD_ACCEL_INFO=y CONFIG_PLATFORM_EC_CONSOLE_CMD_CHARGER_ADC_AMON_BMON=y CONFIG_PLATFORM_EC_CONSOLE_CMD_SYSINFO=y -CONFIG_PLATFORM_EC_HOSTCMD_REGULATOR=y CONFIG_PLATFORM_EC_HOST_COMMAND_STATUS=y # LED @@ -51,6 +65,8 @@ CONFIG_PLATFORM_EC_LED_ONOFF_STATES=y CONFIG_PLATFORM_EC_LED_ONOFF_STATES_BAT_LOW=10 # MKBP event mask +CONFIG_PLATFORM_EC_MKBP_EVENT=y +CONFIG_PLATFORM_EC_MKBP_INPUT_DEVICES=y CONFIG_PLATFORM_EC_MKBP_EVENT_WAKEUP_MASK=y CONFIG_PLATFORM_EC_MKBP_HOST_EVENT_WAKEUP_MASK=y CONFIG_PLATFORM_EC_MKBP_USE_GPIO=y @@ -85,7 +101,6 @@ CONFIG_PLATFORM_EC_USB_A_PORT_COUNT=1 # USB-C CONFIG_PLATFORM_EC_BC12_DETECT_PI3USB9201=y -CONFIG_PLATFORM_EC_BC12_DETECT_MT6360=y CONFIG_PLATFORM_EC_BC12_SINGLE_DRIVER=n CONFIG_PLATFORM_EC_SMBUS_PEC=y CONFIG_PLATFORM_EC_USBC_PPC_DEDICATED_INT=y diff --git a/zephyr/projects/corsola/krabby/pwm.dts b/zephyr/projects/corsola/pwm_krabby.dts index f86448cc8e..40eb8f5048 100644 --- a/zephyr/projects/corsola/krabby/pwm.dts +++ b/zephyr/projects/corsola/pwm_krabby.dts @@ -7,26 +7,23 @@ named-pwms { compatible = "named-pwms"; /* NOTE: &pwm number needs same with channel number */ - led1: led1 { + led1: ec_led1_odl { #pwm-cells = <0>; pwms = <&pwm0 PWM_CHANNEL_0 PWM_POLARITY_INVERTED>; - label = "LED1"; /* * If we need pwm output in ITE chip power saving * mode, then we should set frequency <=324Hz. */ frequency = <324>; }; - led2: led2 { + led2: ec_led2_odl { #pwm-cells = <0>; pwms = <&pwm1 PWM_CHANNEL_1 PWM_POLARITY_INVERTED>; - label = "LED2"; frequency = <324>; }; - led3: led3 { + led3: ec_led3_odl { #pwm-cells = <0>; pwms = <&pwm2 PWM_CHANNEL_2 PWM_POLARITY_INVERTED>; - label = "LED3"; frequency = <324>; }; }; diff --git a/zephyr/projects/corsola/src/board_chipset.c b/zephyr/projects/corsola/src/board_chipset.c new file mode 100644 index 0000000000..7e06a49792 --- /dev/null +++ b/zephyr/projects/corsola/src/board_chipset.c @@ -0,0 +1,24 @@ +/* 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. + */ + +/* Corsola baseboard-chipset specific configuration */ + +#include "common.h" +#include "gpio.h" +#include "hooks.h" + +/* Called on AP S3 -> S0 transition */ +static void board_chipset_resume(void) +{ + gpio_set_level(GPIO_EC_BL_EN_OD, 1); +} +DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_chipset_resume, HOOK_PRIO_DEFAULT); + +/* Called on AP S0 -> S3 transition */ +static void board_chipset_suspend(void) +{ + gpio_set_level(GPIO_EC_BL_EN_OD, 0); +} +DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_chipset_suspend, HOOK_PRIO_DEFAULT); diff --git a/zephyr/projects/corsola/src/hibernate.c b/zephyr/projects/corsola/src/hibernate.c new file mode 100644 index 0000000000..c3752358bf --- /dev/null +++ b/zephyr/projects/corsola/src/hibernate.c @@ -0,0 +1,21 @@ +/* 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. + */ + +#include "charger.h" +#include "driver/charger/isl923x_public.h" +#include "gpio.h" +#include "system.h" + +/* Corsola board specific hibernate implementation */ +__override void board_hibernate_late(void) +{ + if (IS_ENABLED(CONFIG_CHARGER_ISL9238C)) + isl9238c_hibernate(CHARGER_SOLO); + + gpio_set_level(GPIO_EN_ULP, 1); + + /* should not reach here */ + __builtin_unreachable(); +} diff --git a/zephyr/projects/corsola/src/krabby/battery.c b/zephyr/projects/corsola/src/krabby/battery.c new file mode 100644 index 0000000000..f07c38e1b8 --- /dev/null +++ b/zephyr/projects/corsola/src/krabby/battery.c @@ -0,0 +1,47 @@ +/* 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. + */ + +#include "battery.h" +#include "battery_fuel_gauge.h" +#include "battery_smart.h" +#include "charge_manager.h" +#include "chipset.h" +#include "gpio.h" +#include "hooks.h" +#include "system.h" +#include "usb_pd.h" + +const struct board_batt_params board_battery_info[] = { + [BATTERY_C235] = { + .fuel_gauge = { + .manuf_name = "AS3GWRc3KA", + .device_name = "C235-41", + .ship_mode = { + .reg_addr = 0x0, + .reg_data = { 0x10, 0x10 }, + }, + .fet = { + .reg_addr = 0x99, + .reg_mask = 0x0c, + .disconnect_val = 0x0c, + } + }, + .batt_info = { + .voltage_max = 8800, + .voltage_normal = 7700, + .voltage_min = 6000, + .precharge_current = 256, + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 60, + }, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(board_battery_info) == BATTERY_TYPE_COUNT); + +const enum battery_type DEFAULT_BATTERY_TYPE = BATTERY_C235; diff --git a/zephyr/projects/corsola/src/krabby/hooks.c b/zephyr/projects/corsola/src/krabby/hooks.c new file mode 100644 index 0000000000..cea6667650 --- /dev/null +++ b/zephyr/projects/corsola/src/krabby/hooks.c @@ -0,0 +1,19 @@ +/* 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. + */ + +#include "gpio.h" +#include "hooks.h" + +static void board_suspend(void) +{ + gpio_set_level(GPIO_EN_5V_USM, 0); +} +DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, board_suspend, HOOK_PRIO_DEFAULT); + +static void board_resume(void) +{ + gpio_set_level(GPIO_EN_5V_USM, 1); +} +DECLARE_HOOK(HOOK_CHIPSET_RESUME, board_resume, HOOK_PRIO_DEFAULT); diff --git a/zephyr/projects/corsola/krabby/src/i2c.c b/zephyr/projects/corsola/src/krabby/i2c.c index 12f626847c..12f626847c 100644 --- a/zephyr/projects/corsola/krabby/src/i2c.c +++ b/zephyr/projects/corsola/src/krabby/i2c.c diff --git a/zephyr/projects/corsola/src/krabby/led.c b/zephyr/projects/corsola/src/krabby/led.c new file mode 100644 index 0000000000..d07ec46004 --- /dev/null +++ b/zephyr/projects/corsola/src/krabby/led.c @@ -0,0 +1,91 @@ +/* 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. + */ + +#include "ec_commands.h" +#include "gpio.h" +#include "led_common.h" +#include "led_onoff_states.h" +#include "chipset.h" + +__override const int led_charge_lvl_1 = 5; +__override const int led_charge_lvl_2 = 95; + +__override struct led_descriptor + led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = { + [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, + [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, + [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} }, + [STATE_DISCHARGE_S0] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_DISCHARGE_S0_BAT_LOW] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC}, + {LED_OFF, 3 * LED_ONE_SEC} }, + [STATE_DISCHARGE_S3] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_BATTERY_ERROR] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC}, + {LED_OFF, 1 * LED_ONE_SEC} }, + [STATE_FACTORY_TEST] = {{EC_LED_COLOR_WHITE, 2 * LED_ONE_SEC}, + {EC_LED_COLOR_AMBER, 2 * 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_WHITE, LED_INDEFINITE} }, + [PWR_LED_STATE_SUSPEND_AC] = {{EC_LED_COLOR_WHITE, 1 * LED_ONE_SEC}, + {LED_OFF, 3 * LED_ONE_SEC} }, + [PWR_LED_STATE_SUSPEND_NO_AC] = {{EC_LED_COLOR_WHITE, 1 * LED_ONE_SEC}, + {LED_OFF, 3 * LED_ONE_SEC} }, + [PWR_LED_STATE_OFF] = {{LED_OFF, LED_INDEFINITE} }, +}; + + +const enum ec_led_id supported_led_ids[] = { + EC_LED_ID_BATTERY_LED, + EC_LED_ID_POWER_LED, +}; + +const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); + +__override void led_set_color_battery(enum ec_led_colors color) +{ +} + +__override void led_set_color_power(enum ec_led_colors color) +{ +} + +void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) +{ +} + +int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) +{ + if (led_id == EC_LED_ID_BATTERY_LED) { + if (brightness[EC_LED_COLOR_AMBER] != 0) + led_set_color_battery(EC_LED_COLOR_AMBER); + else if (brightness[EC_LED_COLOR_WHITE] != 0) + led_set_color_battery(EC_LED_COLOR_WHITE); + else + led_set_color_battery(LED_OFF); + } else if (led_id == EC_LED_ID_POWER_LED) { + if (brightness[EC_LED_COLOR_WHITE] != 0) + led_set_color_power(EC_LED_COLOR_WHITE); + else + led_set_color_power(LED_OFF); + } + + return EC_SUCCESS; +} + +__override enum led_states board_led_get_state(enum led_states desired_state) +{ + if (desired_state == STATE_BATTERY_ERROR) { + if (chipset_in_state(CHIPSET_STATE_ON)) + return desired_state; + else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) + return STATE_DISCHARGE_S3; + else + return STATE_DISCHARGE_S5; + } + return desired_state; +} diff --git a/zephyr/projects/corsola/src/krabby/usb_pd_policy.c b/zephyr/projects/corsola/src/krabby/usb_pd_policy.c new file mode 100644 index 0000000000..8d28364664 --- /dev/null +++ b/zephyr/projects/corsola/src/krabby/usb_pd_policy.c @@ -0,0 +1,89 @@ +/* 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. + */ + +#include "adc.h" +#include "charge_manager.h" +#include "chipset.h" +#include "usb_charge.h" +#include "usb_pd.h" +#include "usbc_ppc.h" + +int pd_snk_is_vbus_provided(int port) +{ + static atomic_t vbus_prev[CONFIG_USB_PD_PORT_MAX_COUNT]; + int vbus; + + /* + * (b:181203590#comment20) TODO(yllin): use + * PD_VSINK_DISCONNECT_PD for non-5V case. + */ + vbus = adc_read_channel(board_get_vbus_adc(port)) >= + PD_V_SINK_DISCONNECT_MAX; + +#ifdef CONFIG_USB_CHARGER + /* + * There's no PPC to inform VBUS change for usb_charger, so inform + * the usb_charger now. + */ + if (!!(vbus_prev[port] != vbus)) + usb_charger_vbus_change(port, vbus); + + if (vbus) + atomic_or(&vbus_prev[port], 1); + else + atomic_clear(&vbus_prev[port]); +#endif + return vbus; +} + +void pd_power_supply_reset(int port) +{ + int prev_en; + + prev_en = ppc_is_sourcing_vbus(port); + + /* Disable VBUS. */ + ppc_vbus_source_enable(port, 0); + + /* Enable discharge if we were previously sourcing 5V */ + if (prev_en) + pd_set_vbus_discharge(port, 1); + + /* Notify host of power info change. */ + pd_send_host_event(PD_EVENT_POWER_CHANGE); +} + +int pd_check_vconn_swap(int port) +{ + /* Allow Vconn swap if AP is on. */ + return chipset_in_state(CHIPSET_STATE_SUSPEND | CHIPSET_STATE_ON); +} + +int pd_set_power_supply_ready(int port) +{ + int rv; + + /* Disable charging. */ + rv = ppc_vbus_sink_enable(port, 0); + if (rv) + return rv; + + pd_set_vbus_discharge(port, 0); + + /* Provide Vbus. */ + rv = ppc_vbus_source_enable(port, 1); + if (rv) + return rv; + + /* Notify host of power info change. */ + pd_send_host_event(PD_EVENT_POWER_CHANGE); + + return EC_SUCCESS; +} + +int board_vbus_source_enabled(int port) +{ + return ppc_is_sourcing_vbus(port); +} diff --git a/zephyr/projects/corsola/src/krabby/usbc_config.c b/zephyr/projects/corsola/src/krabby/usbc_config.c new file mode 100644 index 0000000000..578881a8ba --- /dev/null +++ b/zephyr/projects/corsola/src/krabby/usbc_config.c @@ -0,0 +1,296 @@ +/* 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. + */ + +/* Krabby board-specific USB-C configuration */ + +#include "adc.h" +#include "baseboard_usbc_config.h" +#include "bc12/pi3usb9201_public.h" +#include "charge_manager.h" +#include "charger.h" +#include "console.h" +#include "driver/tcpm/it83xx_pd.h" +#include "driver/usb_mux/ps8743.h" +#include "hooks.h" +#include "ppc/syv682x_public.h" +#include "usb_mux/it5205_public.h" +#include "usbc_ppc.h" + +#include "variant_db_detection.h" + +#define CPRINTSUSB(format, args...) cprints(CC_USBCHARGE, format, ## args) +#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) + +/* charger */ +const struct charger_config_t chg_chips[] = { + { + .i2c_port = I2C_PORT_CHARGER, + .i2c_addr_flags = 0, + .drv = NULL, + }, +}; + +const struct pi3usb9201_config_t + pi3usb9201_bc12_chips[CONFIG_USB_PD_PORT_MAX_COUNT] = { + /* [0]: unused */ + [1] = { + .i2c_port = I2C_PORT_PPC1, + .i2c_addr_flags = PI3USB9201_I2C_ADDR_3_FLAGS, + } +}; +/* PPC */ +struct ppc_config_t ppc_chips[CONFIG_USB_PD_PORT_MAX_COUNT] = { + { + .i2c_port = I2C_PORT_PPC0, + .i2c_addr_flags = SYV682X_ADDR0_FLAGS, + .drv = &syv682x_drv, + .frs_en = GPIO_USB_C0_PPC_FRSINFO, + }, + { + .i2c_port = I2C_PORT_PPC1, + .i2c_addr_flags = SYV682X_ADDR0_FLAGS, + .drv = &syv682x_drv, + .frs_en = GPIO_USB_C1_FRS_EN, + }, +}; +unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips); + +struct bc12_config bc12_ports[CONFIG_USB_PD_PORT_MAX_COUNT] = { + { .drv = NULL }, + { .drv = &pi3usb9201_drv }, +}; + +void bc12_interrupt(enum gpio_signal signal) +{ + task_set_event(TASK_ID_USB_CHG_P1, USB_CHG_EVENT_BC12); +} + + +static void board_sub_bc12_init(void) +{ + if (corsola_get_db_type() == CORSOLA_DB_TYPEC) + gpio_enable_interrupt(GPIO_USB_C1_BC12_CHARGER_INT_ODL); + else + /* If this is not a Type-C subboard, disable the task. */ + task_disable_task(TASK_ID_USB_CHG_P1); +} +/* Must be done after I2C and subboard */ +DECLARE_HOOK(HOOK_INIT, board_sub_bc12_init, HOOK_PRIO_INIT_I2C + 1); + +static void board_usbc_init(void) +{ + gpio_enable_interrupt(GPIO_USB_C0_PPC_BC12_INT_ODL); +} +DECLARE_HOOK(HOOK_INIT, board_usbc_init, HOOK_PRIO_DEFAULT-1); + +/* TCPC */ +const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_MAX_COUNT] = { + { + .bus_type = EC_BUS_TYPE_EMBEDDED, + /* TCPC is embedded within EC so no i2c config needed */ + .drv = &it8xxx2_tcpm_drv, + /* Alert is active-low, push-pull */ + .flags = 0, + }, + { + .bus_type = EC_BUS_TYPE_EMBEDDED, + /* TCPC is embedded within EC so no i2c config needed */ + .drv = &it8xxx2_tcpm_drv, + /* Alert is active-low, push-pull */ + .flags = 0, + }, +}; + +void board_usb_mux_init(void) +{ + if (corsola_get_db_type() == CORSOLA_DB_TYPEC) { + ps8743_tune_usb_eq(&usb_muxes[1], + PS8743_USB_EQ_TX_12_8_DB, + PS8743_USB_EQ_RX_12_8_DB); + ps8743_write(&usb_muxes[1], + PS8743_REG_HS_DET_THRESHOLD, + PS8743_USB_HS_THRESH_NEG_10); + } +} +DECLARE_HOOK(HOOK_INIT, board_usb_mux_init, HOOK_PRIO_INIT_I2C + 1); + +void ppc_interrupt(enum gpio_signal signal) +{ + if (signal == GPIO_USB_C1_PPC_INT_ODL) + syv682x_interrupt(1); +} + +int ppc_get_alert_status(int port) +{ + if (port == 0) + return gpio_get_level(GPIO_USB_C0_PPC_BC12_INT_ODL) == 0; + if (port == 1 && corsola_get_db_type() == CORSOLA_DB_TYPEC) + return gpio_get_level(GPIO_USB_C1_PPC_INT_ODL) == 0; + + return 0; +} + +const struct cc_para_t *board_get_cc_tuning_parameter(enum usbpd_port port) +{ + const static struct cc_para_t + cc_parameter[CONFIG_USB_PD_ITE_ACTIVE_PORT_COUNT] = { + { + .rising_time = IT83XX_TX_PRE_DRIVING_TIME_1_UNIT, + .falling_time = IT83XX_TX_PRE_DRIVING_TIME_2_UNIT, + }, + { + .rising_time = IT83XX_TX_PRE_DRIVING_TIME_1_UNIT, + .falling_time = IT83XX_TX_PRE_DRIVING_TIME_2_UNIT, + }, + }; + + return &cc_parameter[port]; +} + +void board_overcurrent_event(int port, int is_overcurrented) +{ + /* TODO: check correct operation for Corsola */ +} + +uint16_t tcpc_get_alert_status(void) +{ + /* + * C0 & C1: TCPC is embedded in the EC and processes interrupts in the + * chip code (it83xx/intc.c) + */ + return 0; +} + +void board_reset_pd_mcu(void) +{ + /* + * C0 & C1: TCPC is embedded in the EC and processes interrupts in the + * chip code (it83xx/intc.c) + */ +} + +int board_set_active_charge_port(int port) +{ + int i; + int is_valid_port = (port >= 0 && port < board_get_usb_pd_port_count()); + + if (!is_valid_port && port != CHARGE_PORT_NONE) + return EC_ERROR_INVAL; + + if (port == CHARGE_PORT_NONE) { + CPRINTS("Disabling all charger ports"); + + /* Disable all ports. */ + for (i = 0; i < ppc_cnt; i++) { + /* + * Do not return early if one fails otherwise we can + * get into a boot loop assertion failure. + */ + if (ppc_vbus_sink_enable(i, 0)) + CPRINTS("Disabling C%d as sink failed.", i); + } + + return EC_SUCCESS; + } + + /* Check if the port is sourcing VBUS. */ + if (ppc_is_sourcing_vbus(port)) { + CPRINTS("Skip enable C%d", port); + return EC_ERROR_INVAL; + } + + CPRINTS("New charge port: C%d", port); + + /* + * Turn off the other ports' sink path FETs, before enabling the + * requested charge port. + */ + for (i = 0; i < ppc_cnt; i++) { + if (i == port) + continue; + + if (ppc_vbus_sink_enable(i, 0)) + CPRINTS("C%d: sink path disable failed.", i); + } + + /* Enable requested charge port. */ + if (ppc_vbus_sink_enable(port, 1)) { + CPRINTS("C%d: sink path enable failed.", port); + return EC_ERROR_UNKNOWN; + } + + return EC_SUCCESS; +} + +const struct usb_mux usbc0_virtual_mux = { + .usb_port = 0, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, +}; + +const struct usb_mux usbc1_virtual_mux = { + .usb_port = 1, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, +}; + +static int board_ps8743_mux_set(const struct usb_mux *me, + mux_state_t mux_state) +{ + int rv = EC_SUCCESS; + int reg = 0; + + rv = ps8743_read(me, PS8743_REG_MODE, ®); + if (rv) + return rv; + + /* Disable FLIP pin, enable I2C control. */ + reg |= PS8743_MODE_FLIP_REG_CONTROL; + /* Disable CE_USB pin, enable I2C control. */ + reg |= PS8743_MODE_USB_REG_CONTROL; + /* Disable CE_DP pin, enable I2C control. */ + reg |= PS8743_MODE_DP_REG_CONTROL; + + /* + * DP specific config + * + * Enable/Disable IN_HPD on the DB. + */ + gpio_set_level(GPIO_USB_C1_DP_IN_HPD, + mux_state & USB_PD_MUX_DP_ENABLED); + + return ps8743_write(me, PS8743_REG_MODE, reg); +} + +const struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_MAX_COUNT] = { + { + .usb_port = 0, + .i2c_port = I2C_PORT_USB_MUX0, + .i2c_addr_flags = IT5205_I2C_ADDR1_FLAGS, + .driver = &it5205_usb_mux_driver, + .next_mux = &usbc0_virtual_mux, + }, + { + .usb_port = 1, + .i2c_port = I2C_PORT_USB_MUX1, + .i2c_addr_flags = PS8743_I2C_ADDR0_FLAG, + .driver = &ps8743_usb_mux_driver, + .next_mux = &usbc1_virtual_mux, + .board_set = &board_ps8743_mux_set, + }, +}; + +#ifdef CONFIG_USB_PD_VBUS_MEASURE_ADC_EACH_PORT +enum adc_channel board_get_vbus_adc(int port) +{ + if (port == 0) + return ADC_VBUS_C0; + if (port == 1) + return ADC_VBUS_C1; + CPRINTSUSB("Unknown vbus adc port id: %d", port); + return ADC_VBUS_C0; +} +#endif /* CONFIG_USB_PD_VBUS_MEASURE_ADC_EACH_PORT */ diff --git a/zephyr/projects/corsola/src/regulator.c b/zephyr/projects/corsola/src/regulator.c new file mode 100644 index 0000000000..35670bda82 --- /dev/null +++ b/zephyr/projects/corsola/src/regulator.c @@ -0,0 +1,46 @@ +/* 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. + */ + +#include "common.h" +#include "bc12/mt6360_public.h" + +/* SD Card */ +int board_regulator_get_info(uint32_t index, char *name, + uint16_t *num_voltages, uint16_t *voltages_mv) +{ + enum mt6360_regulator_id id = index; + + return mt6360_regulator_get_info(id, name, num_voltages, + voltages_mv); +} + +int board_regulator_enable(uint32_t index, uint8_t enable) +{ + enum mt6360_regulator_id id = index; + + return mt6360_regulator_enable(id, enable); +} + +int board_regulator_is_enabled(uint32_t index, uint8_t *enabled) +{ + enum mt6360_regulator_id id = index; + + return mt6360_regulator_is_enabled(id, enabled); +} + +int board_regulator_set_voltage(uint32_t index, uint32_t min_mv, + uint32_t max_mv) +{ + enum mt6360_regulator_id id = index; + + return mt6360_regulator_set_voltage(id, min_mv, max_mv); +} + +int board_regulator_get_voltage(uint32_t index, uint32_t *voltage_mv) +{ + enum mt6360_regulator_id id = index; + + return mt6360_regulator_get_voltage(id, voltage_mv); +} diff --git a/zephyr/projects/corsola/src/usb_pd_policy.c b/zephyr/projects/corsola/src/usb_pd_policy.c new file mode 100644 index 0000000000..54322811a2 --- /dev/null +++ b/zephyr/projects/corsola/src/usb_pd_policy.c @@ -0,0 +1,152 @@ +/* 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. + */ + +#include "atomic.h" +#include "chipset.h" +#include "timer.h" +#include "usb_dp_alt_mode.h" +#include "usb_mux.h" +#include "usb_pd.h" +#include "usbc_ppc.h" + +#if CONFIG_USB_PD_3A_PORTS != 1 +#error Corsola reference must have at least one 3.0 A port +#endif + +#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) + +int svdm_get_hpd_gpio(int port) +{ + /* HPD is low active, inverse the result */ + return !gpio_get_level(GPIO_EC_AP_DP_HPD_ODL); +} + +void svdm_set_hpd_gpio(int port, int en) +{ + /* + * HPD is low active, inverse the en + * TODO: C0&C1 shares the same HPD, implement FCFS policy. + */ + gpio_set_level(GPIO_EC_AP_DP_HPD_ODL, !en); +} + +/** + * Is the port fine to be muxed its DisplayPort lines? + * + * Only one port can be muxed to DisplayPort at a time. + * + * @param port Port number of TCPC. + * @return 1 is fine; 0 is bad as other port is already muxed; + */ +static int is_dp_muxable(int port) +{ + int i; + + for (i = 0; i < board_get_usb_pd_port_count(); i++) { + if (i != port) { + if (usb_mux_get(i) & USB_PD_MUX_DP_ENABLED) + return 0; + } + } + + return 1; +} + +__override int svdm_dp_attention(int port, uint32_t *payload) +{ + int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]); + int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]); +#ifdef CONFIG_USB_PD_DP_HPD_GPIO + int cur_lvl = svdm_get_hpd_gpio(port); +#endif /* CONFIG_USB_PD_DP_HPD_GPIO */ + mux_state_t mux_state; + + dp_status[port] = payload[1]; + + if (!is_dp_muxable(port)) { + /* TODO(waihong): Info user? */ + CPRINTS("p%d: The other port is already muxed.", port); + return 0; /* nak */ + } + + if (lvl) + gpio_set_level_verbose(CC_USBPD, GPIO_DP_AUX_PATH_SEL, port); + + if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) && + (irq || lvl)) + /* + * Wake up the AP. IRQ or level high indicates a DP sink is now + * present. + */ + if (IS_ENABLED(CONFIG_MKBP_EVENT)) + pd_notify_dp_alt_mode_entry(port); + + /* Its initial DP status message prior to config */ + if (!(dp_flags[port] & DP_FLAGS_DP_ON)) { + if (lvl) + dp_flags[port] |= DP_FLAGS_HPD_HI_PENDING; + return 1; + } + +#ifdef CONFIG_USB_PD_DP_HPD_GPIO + if (irq && !lvl) { + /* + * IRQ can only be generated when the level is high, because + * the IRQ is signaled by a short low pulse from the high level. + */ + CPRINTF("ERR:HPD:IRQ&LOW\n"); + return 0; /* nak */ + } + + if (irq && cur_lvl) { + uint64_t now = get_time().val; + /* wait for the minimum spacing between IRQ_HPD if needed */ + if (now < svdm_hpd_deadline[port]) + usleep(svdm_hpd_deadline[port] - now); + + /* generate IRQ_HPD pulse */ + svdm_set_hpd_gpio(port, 0); + /* + * b/171172053#comment14: since the HPD_DSTREAM_DEBOUNCE_IRQ is + * very short (500us), we can use udelay instead of usleep for + * more stable pulse period. + */ + udelay(HPD_DSTREAM_DEBOUNCE_IRQ); + svdm_set_hpd_gpio(port, 1); + } else { + svdm_set_hpd_gpio(port, lvl); + } + + /* set the minimum time delay (2ms) for the next HPD IRQ */ + svdm_hpd_deadline[port] = get_time().val + HPD_USTREAM_DEBOUNCE_LVL; +#endif /* CONFIG_USB_PD_DP_HPD_GPIO */ + + mux_state = (lvl ? USB_PD_MUX_HPD_LVL : USB_PD_MUX_HPD_LVL_DEASSERTED) | + (irq ? USB_PD_MUX_HPD_IRQ : USB_PD_MUX_HPD_IRQ_DEASSERTED); + usb_mux_hpd_update(port, mux_state); + +#ifdef USB_PD_PORT_TCPC_MST + if (port == USB_PD_PORT_TCPC_MST) + baseboard_mst_enable_control(port, lvl); +#endif + + /* ack */ + return 1; +} + +__override void svdm_exit_dp_mode(int port) +{ +#ifdef CONFIG_USB_PD_DP_HPD_GPIO + svdm_set_hpd_gpio(port, 0); +#endif /* CONFIG_USB_PD_DP_HPD_GPIO */ + usb_mux_hpd_update(port, USB_PD_MUX_HPD_LVL_DEASSERTED | + USB_PD_MUX_HPD_IRQ_DEASSERTED); + +#ifdef USB_PD_PORT_TCPC_MST + if (port == USB_PD_PORT_TCPC_MST) + baseboard_mst_enable_control(port, 0); +#endif +} diff --git a/zephyr/projects/corsola/src/usbc_config.c b/zephyr/projects/corsola/src/usbc_config.c new file mode 100644 index 0000000000..c4917b252d --- /dev/null +++ b/zephyr/projects/corsola/src/usbc_config.c @@ -0,0 +1,135 @@ +/* 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. + */ + +/* Corsola baseboard-specific USB-C configuration */ + +#include "adc.h" +#include "baseboard_usbc_config.h" +#include "button.h" +#include "charger.h" +#include "charge_state_v2.h" +#include "console.h" +#include "ec_commands.h" +#include "extpower.h" +#include "gpio.h" +#include "hooks.h" +#include "i2c.h" +#include "lid_switch.h" +#include "task.h" +#include "ppc/syv682x_public.h" +#include "power.h" +#include "power_button.h" +#include "spi.h" +#include "switch.h" +#include "tablet_mode.h" +#include "uart.h" +#include "usb_charge.h" +#include "usb_mux.h" +#include "usb_pd_tcpm.h" +#include "usbc_ppc.h" + +#include "variant_db_detection.h" + +#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) + +/* Baseboard */ +static void baseboard_init(void) +{ + gpio_enable_interrupt(GPIO_AP_XHCI_INIT_DONE); +} +DECLARE_HOOK(HOOK_INIT, baseboard_init, HOOK_PRIO_DEFAULT-1); + +static void board_tcpc_init(void) +{ + /* C1: GPIO_USB_C1_PPC_INT_ODL & HDMI: GPIO_PS185_EC_DP_HPD */ + gpio_enable_interrupt(GPIO_X_EC_GPIO2); + + /* If this is not a Type-C subboard, disable the task. */ + if (corsola_get_db_type() != CORSOLA_DB_TYPEC) + task_disable_task(TASK_ID_PD_C1); +} +/* Must be done after I2C and subboard */ +DECLARE_HOOK(HOOK_INIT, board_tcpc_init, HOOK_PRIO_INIT_I2C + 1); + +__override uint8_t board_get_usb_pd_port_count(void) +{ + if (corsola_get_db_type() == CORSOLA_DB_TYPEC) + return CONFIG_USB_PD_PORT_MAX_COUNT; + else + return CONFIG_USB_PD_PORT_MAX_COUNT - 1; +} + +/* USB-A */ +const int usb_port_enable[] = { + GPIO_EN_PP5000_USB_A0_VBUS, +}; +BUILD_ASSERT(ARRAY_SIZE(usb_port_enable) == USB_PORT_COUNT); + +void usb_a0_interrupt(enum gpio_signal signal) +{ + enum usb_charge_mode mode = gpio_get_level(signal) ? + USB_CHARGE_MODE_ENABLED : USB_CHARGE_MODE_DISABLED; + + for (int i = 0; i < USB_PORT_COUNT; i++) + usb_charge_set_mode(i, mode, USB_ALLOW_SUSPEND_CHARGE); +} + +void board_set_charge_limit(int port, int supplier, int charge_ma, + int max_ma, int charge_mv) +{ + charge_set_input_current_limit( + MAX(charge_ma, CONFIG_CHARGER_INPUT_CURRENT), charge_mv); +} + +void board_pd_vconn_ctrl(int port, enum usbpd_cc_pin cc_pin, int enabled) +{ + /* + * We ignore the cc_pin and PPC vconn because polarity and PPC vconn + * should already be set correctly in the PPC driver via the pd + * state machine. + */ +} + +/** + * Handle PS185 HPD changing state. + */ +int debounced_hpd; + +static void ps185_hdmi_hpd_deferred(void) +{ + const int new_hpd = gpio_get_level(GPIO_PS185_EC_DP_HPD); + + /* HPD status not changed, probably a glitch, just return. */ + if (debounced_hpd == new_hpd) + return; + + debounced_hpd = new_hpd; + + gpio_set_level(GPIO_EC_AP_DP_HPD_ODL, !debounced_hpd); + CPRINTS(debounced_hpd ? "HDMI plug" : "HDMI unplug"); +} +DECLARE_DEFERRED(ps185_hdmi_hpd_deferred); + +#define PS185_HPD_DEBOUCE 250 + +static void hdmi_hpd_interrupt(enum gpio_signal signal) +{ + hook_call_deferred(&ps185_hdmi_hpd_deferred_data, PS185_HPD_DEBOUCE); +} + +/* HDMI/TYPE-C function shared subboard interrupt */ +void x_ec_interrupt(enum gpio_signal signal) +{ + int sub = corsola_get_db_type(); + + if (sub == CORSOLA_DB_TYPEC) + /* C1: PPC interrupt */ + ppc_interrupt(signal); + else if (sub == CORSOLA_DB_HDMI) + hdmi_hpd_interrupt(signal); + else + CPRINTS("Undetected subboard interrupt."); +} diff --git a/zephyr/projects/corsola/src/variant_db_detection.c b/zephyr/projects/corsola/src/variant_db_detection.c new file mode 100644 index 0000000000..340d54a196 --- /dev/null +++ b/zephyr/projects/corsola/src/variant_db_detection.c @@ -0,0 +1,65 @@ +/* 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. + */ + +/* Corsola daughter board detection */ + +#include "console.h" +#include "gpio.h" +#include "hooks.h" + +#include "variant_db_detection.h" + +#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ## args) +#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ## args) + +static void corsola_db_config(enum corsola_db_type type) +{ + switch (type) { + case CORSOLA_DB_HDMI: + /* EC_X_GPIO1 */ + gpio_set_flags(GPIO_EN_HDMI_PWR, GPIO_OUT_HIGH); + /* X_EC_GPIO2 */ + gpio_set_flags(GPIO_PS185_EC_DP_HPD, GPIO_INT_BOTH); + /* EC_X_GPIO3 */ + gpio_set_flags(GPIO_PS185_PWRDN_ODL, GPIO_ODR_HIGH); + return; + case CORSOLA_DB_TYPEC: + /* EC_X_GPIO1 */ + gpio_set_flags(GPIO_USB_C1_FRS_EN, GPIO_OUT_LOW); + /* X_EC_GPIO2 */ + gpio_set_flags(GPIO_USB_C1_PPC_INT_ODL, + GPIO_INT_BOTH | GPIO_PULL_UP); + /* EC_X_GPIO3 */ + gpio_set_flags(GPIO_USB_C1_DP_IN_HPD, GPIO_OUT_LOW); + return; + default: + break; + + } +} + +enum corsola_db_type corsola_get_db_type(void) +{ + static enum corsola_db_type db = CORSOLA_DB_NONE; + + if (db != CORSOLA_DB_NONE) + return db; + + if (!gpio_get_level(GPIO_HDMI_PRSNT_ODL)) + db = CORSOLA_DB_HDMI; + else + db = CORSOLA_DB_TYPEC; + + corsola_db_config(db); + + CPRINTS("Detect %s DB", db == CORSOLA_DB_HDMI ? "HDMI" : "TYPEC"); + return db; +} + +static void corsola_db_init(void) +{ + corsola_get_db_type(); +} +DECLARE_HOOK(HOOK_INIT, corsola_db_init, HOOK_PRIO_INIT_I2C - 1); |