mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 10:31:02 +00:00
sn5s330: Add support for Vbus detection.
The SN5S330 has support for detecting when Vbus is present on a port. This commit simply adds an API to query the PPC. BUG=None BRANCH=None TEST=`make -j buildall`. TEST=Flash a board with the SN5S330, with some extra code, verify that Vbus can be detected with this API. Change-Id: I45bf7ff24bcdc447efe12932f51f8094108e29d5 Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/791502 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
0dd7716c4f
commit
eff4baf03f
@@ -42,6 +42,16 @@ int ppc_vbus_source_enable(int port, int enable)
|
||||
return ppc_chips[port].drv->vbus_source_enable(port, enable);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
|
||||
int ppc_is_vbus_present(int port, int *vbus_present)
|
||||
{
|
||||
if (port >= ppc_cnt)
|
||||
return EC_ERROR_INVAL;
|
||||
|
||||
return ppc_chips[port].drv->is_vbus_present(port, vbus_present);
|
||||
}
|
||||
#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
|
||||
|
||||
static void ppc_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -122,14 +122,12 @@ static int sn5s330_is_pp_fet_enabled(uint8_t port, enum sn5s330_pp_idx pp,
|
||||
int status;
|
||||
int regval;
|
||||
|
||||
if (pp == SN5S330_PP1) {
|
||||
if (pp == SN5S330_PP1)
|
||||
pp_bit = SN5S330_PP1_EN;
|
||||
} else if (pp == SN5S330_PP2) {
|
||||
else if (pp == SN5S330_PP2)
|
||||
pp_bit = SN5S330_PP2_EN;
|
||||
} else {
|
||||
CPRINTF("bad PP idx(%d)!", pp);
|
||||
else
|
||||
return EC_ERROR_INVAL;
|
||||
}
|
||||
|
||||
status = get_func_set3(port, ®val);
|
||||
if (status)
|
||||
@@ -415,6 +413,20 @@ static int sn5s330_init(int port)
|
||||
return EC_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
|
||||
static int sn5s330_is_vbus_present(int port, int *vbus_present)
|
||||
{
|
||||
int regval;
|
||||
int rv;
|
||||
|
||||
rv = read_reg(port, SN5S330_INT_STATUS_REG3, ®val);
|
||||
if (!rv)
|
||||
*vbus_present = !!(regval & SN5S330_VBUS_GOOD);
|
||||
|
||||
return rv;
|
||||
}
|
||||
#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
|
||||
|
||||
static int sn5s330_is_sourcing_vbus(int port)
|
||||
{
|
||||
int is_sourcing_vbus = 0;
|
||||
@@ -448,4 +460,7 @@ const struct ppc_drv sn5s330_drv = {
|
||||
#ifdef CONFIG_CMD_PPC_DUMP
|
||||
.reg_dump = &sn5s330_dump,
|
||||
#endif /* defined(CONFIG_CMD_PPC_DUMP) */
|
||||
#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
|
||||
.is_vbus_present = &sn5s330_is_vbus_present,
|
||||
#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
|
||||
};
|
||||
|
||||
@@ -100,6 +100,9 @@ enum sn5s330_pp_idx {
|
||||
#define SN5S330_PP2_CONFIG (1 << 2)
|
||||
#define SN5S330_OVP_EN_CC (1 << 4)
|
||||
|
||||
/* INT_STATUS_REG3 */
|
||||
#define SN5S330_VBUS_GOOD (1 << 0)
|
||||
|
||||
/* INT_STATUS_REG4 */
|
||||
#define SN5S330_DIG_RES (1 << 0)
|
||||
#define SN5S330_DB_BOOT (1 << 1)
|
||||
|
||||
@@ -2641,6 +2641,7 @@
|
||||
* - Some TCPCs can detect and report the presence of VBUS.
|
||||
* - In some configurations, charger ICs can report the presence of VBUS.
|
||||
* - On some boards, dedicated VBUS interrupt pins are available.
|
||||
* - Some power path controllers (PPC) can report the presence of VBUS.
|
||||
*
|
||||
* Exactly one of these should be defined for all boards that run the PD
|
||||
* state machine.
|
||||
@@ -2648,6 +2649,7 @@
|
||||
#undef CONFIG_USB_PD_VBUS_DETECT_TCPC
|
||||
#undef CONFIG_USB_PD_VBUS_DETECT_CHARGER
|
||||
#undef CONFIG_USB_PD_VBUS_DETECT_GPIO
|
||||
#undef CONFIG_USB_PD_VBUS_DETECT_PPC
|
||||
#undef CONFIG_USB_PD_VBUS_DETECT_NONE
|
||||
|
||||
|
||||
|
||||
@@ -56,6 +56,24 @@ struct ppc_drv {
|
||||
*/
|
||||
int (*reg_dump)(int port);
|
||||
#endif /* defined(CONFIG_CMD_PPC_DUMP) */
|
||||
|
||||
#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
|
||||
/*
|
||||
* TODO(aaboagye): In order for VBUS detection to work properly for our
|
||||
* system, we need to enable VBUS interrupts and send the appropriate
|
||||
* notifications.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Determine if VBUS is present or not.
|
||||
*
|
||||
* @param port: The Type-C port number.
|
||||
* @param vbus_present: 1: VBUS is present. 0: VBUS is not present.
|
||||
* @return EC_SUCCESS if able to determine VBUS status, otherwise an
|
||||
* error.
|
||||
*/
|
||||
int (*is_vbus_present)(int port, int *vbus_present);
|
||||
#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
|
||||
};
|
||||
|
||||
struct ppc_config_t {
|
||||
@@ -67,6 +85,16 @@ struct ppc_config_t {
|
||||
extern const struct ppc_config_t ppc_chips[];
|
||||
extern const unsigned int ppc_cnt;
|
||||
|
||||
/**
|
||||
* Determine if VBUS is present or not.
|
||||
*
|
||||
* @param port: The Type-C port number.
|
||||
* @param vbus_present: 1: VBUS is present. 0: VBUS is not present.
|
||||
* @return EC_SUCCESS if able to determine VBUS status, otherwise an
|
||||
* error.
|
||||
*/
|
||||
int ppc_is_vbus_present(int port, int *vbus_present);
|
||||
|
||||
/**
|
||||
* Is the port sourcing Vbus?
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user