summaryrefslogtreecommitdiff
path: root/zephyr/program/corsola/src/variant_db_detection.c
diff options
context:
space:
mode:
authorYH Lin <yueherngl@google.com>2022-11-30 21:45:30 +0000
committerYH Lin <yueherngl@google.com>2022-11-30 21:45:30 +0000
commit184d13e77614be3be5374d3fef9d1edf66ec8687 (patch)
treed0c89ae8814c2ba35c238c6c0644ec6b1602c63a /zephyr/program/corsola/src/variant_db_detection.c
parent19d4d68ffa8b6910d716ab5e1953c41b58614a57 (diff)
parentaa40b859b3a73e5a205bc561c1a29eff38485461 (diff)
downloadchrome-ec-184d13e77614be3be5374d3fef9d1edf66ec8687.tar.gz
Merge remote-tracking branch cros/main into factory-brya-14909.124.B-main
Generated by: util/update_release_branch.py --baseboard brya --relevant_paths_file baseboard/brya/relevant-paths.txt factory-brya-14909.124.B-main Relevant changes: git log --oneline 19d4d68ffa..aa40b859b3 -- baseboard/brya board/agah board/anahera board/banshee board/brya board/crota board/felwinter board/gimble board/kano board/mithrax board/osiris board/primus board/redrix board/taeko board/taniks board/vell board/volmar driver/bc12/pi3usb9201_public.* driver/charger/bq25710.* driver/ppc/nx20p348x.* driver/ppc/syv682x_public.* driver/retimer/bb_retimer_public.* driver/tcpm/nct38xx.* driver/tcpm/ps8xxx_public.* driver/tcpm/tcpci.* include/power/alderlake* include/intel_x86.h power/alderlake* power/intel_x86.c util/getversion.sh e6da633c38 driver: Sort header files 234a87ae2d tcpci: Add FRS enable to driver structure a56be59ccd tcpm_header: add test for tcpm_dump_registers 57b3256963 Rename CONFIG_CHARGER_INPUT_CURRENT to _CHARGER_DEFAULT_CURRENT_LIMIT e420c8ff9a marasov: Modify TypeC and TypeA configuration. 43b53e0045 Add default implementation of board_set_charge_limit b75dc90677 Add CONFIG_CHARGER_MIN_INPUT_CURRENT_LIMIT f1b563c350 baseboard: Sort header files 7d01b1e58d driver/retimer/ps8818.h: Add I2C ADDR FLAGS 0x30, 0x58, 0x70 ec31407993 Add CONFIG_CHARGER_INPUT_CURRENT_DERATE_PCT 8f89f69a5b crota: disable lid angle sensor for clamshell BRANCH=None BUG=b:260630630 b:163093572 b:259002141 b:255184961 b:259354679 BUG=b:247100970 b:254328661 TEST=`emerge-brya chromeos-ec` Force-Relevant-Builds: all Change-Id: I0ecfa0e6af68631283c7a9e8f1afb9d827176c62 Signed-off-by: YH Lin <yueherngl@google.com>
Diffstat (limited to 'zephyr/program/corsola/src/variant_db_detection.c')
-rw-r--r--zephyr/program/corsola/src/variant_db_detection.c210
1 files changed, 210 insertions, 0 deletions
diff --git a/zephyr/program/corsola/src/variant_db_detection.c b/zephyr/program/corsola/src/variant_db_detection.c
new file mode 100644
index 0000000000..9ade144513
--- /dev/null
+++ b/zephyr/program/corsola/src/variant_db_detection.c
@@ -0,0 +1,210 @@
+/* Copyright 2021 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Corsola daughter board detection */
+#include "baseboard_usbc_config.h"
+#include "console.h"
+#include "cros_cbi.h"
+#include "gpio/gpio_int.h"
+#include "hooks.h"
+#include "usb_mux.h"
+#include "variant_db_detection.h"
+
+#include <zephyr/drivers/gpio.h>
+
+#define CPRINTS(format, args...) cprints(CC_SYSTEM, format, ##args)
+#define CPRINTF(format, args...) cprintf(CC_SYSTEM, format, ##args)
+
+#ifdef TEST_BUILD
+uint32_t dp_status[CONFIG_USB_PD_PORT_MAX_COUNT];
+#endif
+
+static void corsola_db_config(enum corsola_db_type type)
+{
+ switch (type) {
+ case CORSOLA_DB_HDMI:
+ /* EC_X_GPIO1 */
+ gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_en_hdmi_pwr),
+ GPIO_OUTPUT_HIGH);
+ /* X_EC_GPIO2 */
+ gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_ps185_ec_dp_hpd),
+ GPIO_INPUT);
+ gpio_enable_dt_interrupt(
+ GPIO_INT_FROM_NODELABEL(int_x_ec_gpio2));
+ /* EC_X_GPIO3 */
+ gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_ps185_pwrdn_odl),
+ GPIO_OUTPUT_HIGH | GPIO_OPEN_DRAIN);
+ return;
+ case CORSOLA_DB_TYPEC:
+ /* EC_X_GPIO1 */
+ gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_frs_en),
+ GPIO_OUTPUT_LOW);
+ /* X_EC_GPIO2 */
+ gpio_pin_configure_dt(
+ GPIO_DT_FROM_ALIAS(gpio_usb_c1_ppc_int_odl),
+ GPIO_INPUT | GPIO_PULL_UP);
+ gpio_enable_dt_interrupt(
+ GPIO_INT_FROM_NODELABEL(int_x_ec_gpio2));
+ /* EC_X_GPIO3 */
+ gpio_pin_configure_dt(GPIO_DT_FROM_ALIAS(gpio_usb_c1_dp_in_hpd),
+ GPIO_OUTPUT_LOW);
+ return;
+ case CORSOLA_DB_NONE:
+ /* Set floating pins as input with PU to prevent leakage */
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_ec_x_gpio1),
+ GPIO_INPUT | GPIO_PULL_UP);
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_x_ec_gpio2),
+ GPIO_INPUT | GPIO_PULL_UP);
+ gpio_pin_configure_dt(GPIO_DT_FROM_NODELABEL(gpio_ec_x_gpio3),
+ GPIO_INPUT | GPIO_PULL_UP);
+ return;
+ default:
+ break;
+ }
+}
+
+enum corsola_db_type corsola_get_db_type(void)
+{
+#if DT_NODE_EXISTS(DT_NODELABEL(db_config))
+ int ret;
+ uint32_t val;
+#endif
+ static enum corsola_db_type db = CORSOLA_DB_UNINIT;
+
+ if (db != CORSOLA_DB_UNINIT) {
+ return db;
+ }
+
+ if (!gpio_pin_get_dt(GPIO_DT_FROM_NODELABEL(gpio_hdmi_prsnt_odl))) {
+ db = CORSOLA_DB_HDMI;
+ } else {
+ db = CORSOLA_DB_TYPEC;
+ }
+
+/* Detect for no sub board case by FW_CONFIG */
+#if DT_NODE_EXISTS(DT_NODELABEL(db_config))
+ ret = cros_cbi_get_fw_config(DB, &val);
+ if (ret != 0) {
+ CPRINTS("Error retrieving CBI FW_CONFIG field %d", DB);
+ } else if (val == DB_NONE) {
+ db = CORSOLA_DB_NONE;
+ }
+#endif
+
+ corsola_db_config(db);
+
+ switch (db) {
+ case CORSOLA_DB_NONE:
+ CPRINTS("Detect %s DB", "NONE");
+ break;
+ case CORSOLA_DB_TYPEC:
+ CPRINTS("Detect %s DB", "TYPEC");
+ break;
+ case CORSOLA_DB_HDMI:
+ CPRINTS("Detect %s DB", "HDMI");
+ break;
+ default:
+ CPRINTS("DB UNINIT");
+ break;
+ }
+
+ return db;
+}
+
+static void corsola_db_init(void)
+{
+ corsola_get_db_type();
+}
+DECLARE_HOOK(HOOK_INIT, corsola_db_init, HOOK_PRIO_PRE_I2C);
+
+/**
+ * Handle PS185 HPD changing state.
+ */
+void ps185_hdmi_hpd_mux_set(void)
+{
+ const int hpd =
+ gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_ps185_ec_dp_hpd));
+
+ if (!corsola_is_dp_muxable(USBC_PORT_C1)) {
+ return;
+ }
+
+ if (hpd && !(usb_mux_get(USBC_PORT_C1) & USB_PD_MUX_DP_ENABLED)) {
+ dp_status[USBC_PORT_C1] =
+ VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */
+ 0, /* HPD level ... not applicable */
+ 0, /* exit DP? ... no */
+ 0, /* usb mode? ... no */
+ 0, /* multi-function ... no */
+ 1, /* DP enabled ... yes */
+ 0, /* power low? ... no */
+ (!!DP_FLAGS_DP_ON));
+ /* update C1 virtual mux */
+ usb_mux_set(USBC_PORT_C1, USB_PD_MUX_DP_ENABLED,
+ USB_SWITCH_DISCONNECT,
+ 0 /* polarity, don't care */);
+ CPRINTS("HDMI plug");
+ }
+}
+
+static void ps185_hdmi_hpd_deferred(void)
+{
+ const int hpd =
+ gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_ps185_ec_dp_hpd));
+
+ if (!hpd && (usb_mux_get(USBC_PORT_C1) & USB_PD_MUX_DP_ENABLED)) {
+ dp_status[USBC_PORT_C1] =
+ VDO_DP_STATUS(0, /* HPD IRQ ... not applicable */
+ 0, /* HPD level ... not applicable */
+ 0, /* exit DP? ... no */
+ 0, /* usb mode? ... no */
+ 0, /* multi-function ... no */
+ 0, /* DP enabled ... no */
+ 0, /* power low? ... no */
+ (!DP_FLAGS_DP_ON));
+ usb_mux_set(USBC_PORT_C1, USB_PD_MUX_NONE,
+ USB_SWITCH_DISCONNECT,
+ 0 /* polarity, don't care */);
+ CPRINTS("HDMI unplug");
+
+ return;
+ }
+
+ ps185_hdmi_hpd_mux_set();
+}
+DECLARE_DEFERRED(ps185_hdmi_hpd_deferred);
+
+#define HPD_SINK_ABSENCE_DEBOUNCE (2 * MSEC)
+
+void hdmi_hpd_interrupt(enum gpio_signal signal)
+{
+ const int hpd =
+ gpio_pin_get_dt(GPIO_DT_FROM_ALIAS(gpio_ps185_ec_dp_hpd));
+
+ if (!hpd) {
+ hook_call_deferred(&ps185_hdmi_hpd_deferred_data,
+ HPD_SINK_ABSENCE_DEBOUNCE);
+ } else {
+ hook_call_deferred(&ps185_hdmi_hpd_deferred_data, -1);
+ }
+
+ /* C0 DP is muxed, we should not send HPD to the AP */
+ if (!corsola_is_dp_muxable(USBC_PORT_C1)) {
+ if (hpd) {
+ CPRINTS("C0 port is already muxed.");
+ }
+ return;
+ }
+
+ if (hpd && !(usb_mux_get(USBC_PORT_C1) & USB_PD_MUX_DP_ENABLED)) {
+ /* set dp_aux_path_sel first, and configure the usb_mux in the
+ * deferred hook to prevent from dead locking.
+ */
+ gpio_pin_set_dt(GPIO_DT_FROM_NODELABEL(dp_aux_path_sel), hpd);
+ hook_call_deferred(&ps185_hdmi_hpd_deferred_data, 0);
+ }
+
+ svdm_set_hpd_gpio(USBC_PORT_C1, hpd);
+}