From 06d89b033065d9c96f4a6e53129b22b912fae224 Mon Sep 17 00:00:00 2001 From: Parth Malkan Date: Tue, 10 Aug 2021 21:54:59 +0000 Subject: SSFC: Framework to support two charger sources Many platforms have requirements to support more than one charge source (eg. pirika). It can't be supported by just enabling two different CONFIGS as that can lead to conflicts. Eg.USD_PD_VBUS_DETECT_TCPC vs USB_PD_VBUS_DETECT_DISCHARGE. This change provides a framework that supports two different charger sources in the same build. Please see the CL for relevant logs. BRANCH=None BUG=b:194375840 TEST=make -j buildall Signed-off-by: Parth Malkan Change-Id: I309cc5930233983e615d90a4290fc749abf7aa2d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3088232 Reviewed-by: Aseda Aboagye --- include/config.h | 7 ++++ include/usb_pd_flags.h | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 include/usb_pd_flags.h (limited to 'include') diff --git a/include/config.h b/include/config.h index f74c9f82c9..5c0975c713 100644 --- a/include/config.h +++ b/include/config.h @@ -4235,6 +4235,13 @@ */ #undef CONFIG_USB_PD_DEBUG_LEVEL +/* + * Define if this board is using runtime flags instead of build time configs + * to control USB PD properties. + */ +#define CONFIG_USB_PD_FLAGS +#undef CONFIG_USB_PD_RUNTIME_FLAGS + /* * Define if this board can enable VBUS discharge (eg. through a GPIO-controlled * discharge circuit, or through port controller registers) to discharge VBUS diff --git a/include/usb_pd_flags.h b/include/usb_pd_flags.h new file mode 100644 index 0000000000..71932de885 --- /dev/null +++ b/include/usb_pd_flags.h @@ -0,0 +1,88 @@ +/* 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. + */ + +/* + * Contains USB PD flags definition and accessors + */ +#ifndef __CROS_EC_USB_PD_FLAGS_H +#define __CROS_EC_USB_PD_FLAGS_H + +#include "stdint.h" + +/* + * USB PD VBUS detect (0-2) + */ +enum usb_pd_vbus_detect { + USB_PD_VBUS_DETECT_NONE = 0, + USB_PD_VBUS_DETECT_TCPC = 1, + USB_PD_VBUS_DETECT_GPIO = 2, + USB_PD_VBUS_DETECT_PPC = 3, + USB_PD_VBUS_DETECT_CHARGER = 4 +}; + +/* + * USB PD DISCHARGE (Bits 3-4) + */ +enum usb_pd_discharge { + USB_PD_DISCHARGE_NONE = 0, + USB_PD_DISCHARGE_TCPC = 1, + USB_PD_DISCHARGE_GPIO = 2, + USB_PD_DISCHARGE_PPC = 3 +}; + +/* + * USB PD Charger OTG (Bit 5) + */ +enum usb_pd_charger_otg { + USB_PD_CHARGER_OTG_DISABLED = 0, + USB_PD_CHARGER_OTG_ENABLED = 1 +}; + +union usb_pd_runtime_flags { + struct { + enum usb_pd_vbus_detect vbus_detect : 3; + enum usb_pd_discharge discharge : 2; + enum usb_pd_charger_otg charger_otg : 1; + uint32_t reserved : 26; + }; + uint32_t raw_value; +}; + +/** + * Set VBUS detect type from USB_PD_FLAGS. + */ +void set_usb_pd_vbus_detect(enum usb_pd_vbus_detect vbus_detect); + +/** + * Get VBUS detect type from USB_PD_FLAGS. + * + * @return the VBUS detect type. + */ +enum usb_pd_vbus_detect get_usb_pd_vbus_detect(void); + +/** + * Set USB PD discharge type from USB_PD_FLAGS. + */ +void set_usb_pd_discharge(enum usb_pd_discharge discharge); + +/** + * Get USB PD discharge type from USB_PD_FLAGS. + * + * @return the USB PD discharge type. + */ +enum usb_pd_discharge get_usb_pd_discharge(void); + +/** + * Set USB PD charger OTG from USB_PD_FLAGS. + */ +void set_usb_pd_charger_otg(enum usb_pd_charger_otg charger_otg); + +/** + * Get USB PD charger OTG from USB_PD_FLAGS. + * + * @return the USB PD charger OTG. + */ +enum usb_pd_charger_otg get_usb_pd_charger_otg(void); +#endif /* __CROS_EC_USB_PD_FLAGS_H */ -- cgit v1.2.1