Files
OpenCellular/include/usbc_ppc.h
Aseda Aboagye 02e4c2ea9a ppc: sn5s330: Add interrupt handler.
Right now, the only events that are unmasked by default are overcurrent
conditions on PP1.  This commit adds a simple interrupt handler and
introduces a board specific callback when the overcurrent status changes
on a port.  This way, a board can take whatever action it desires with
the notification.

BUG=b:69139844
BRANCH=None
TEST=Flash zoombini with SN5S330 stuffed.  Verify that board boots okay.
TEST=With some extra code to setup the interrupt handler, attempt to
exceed the current limit set, verify that interrupt handler is called.
Reduce the current pulled to under the current limit, verify that the
condition is no longer present.

CQ-DEPEND=CL:797937

Change-Id: Id3321c5703f9608da895be0ed5841f2fb76e734e
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/797936
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-12-12 01:05:25 -08:00

134 lines
3.4 KiB
C

/* Copyright 2017 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 __CROS_EC_USBC_PPC_H
#define __CROS_EC_USBC_PPC_H
#include "common.h"
/* Common APIs for USB Type-C Power Path Controllers (PPC) */
struct ppc_drv {
/**
* Initialize the PPC.
*
* @param port: The Type-C port number.
* @return EC_SUCCESS when init was successful, error otherwise.
*/
int (*init)(int port);
/**
* Is the port sourcing Vbus?
*
* @param port: The Type-C port number.
* @return 1 if sourcing Vbus, 0 if not.
*/
int (*is_sourcing_vbus)(int port);
/**
* Turn on/off the charge path FET, such that current flows into the
* system.
*
* @param port: The Type-C port number.
* @param enable: 1: Turn on the FET, 0: turn off the FET.
* @return EC_SUCCESS on success, error otherwise.
*/
int (*vbus_sink_enable)(int port, int enable);
/**
* Turn on/off the source path FET, such that current flows from the
* system.
*
* @param port: The Type-C port number.
* @param enable: 1: Turn on the FET, 0: turn off the FET.
* @return EC_SUCCESS on success, error otherwise.
*/
int (*vbus_source_enable)(int port, int enable);
#ifdef CONFIG_CMD_PPC_DUMP
/**
* Perform a register dump of the PPC.
*
* @param port: The Type-C port number.
* @return EC_SUCCESS on success, error otherwise.
*/
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 {
int i2c_port;
int i2c_addr;
const struct ppc_drv *drv;
};
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?
*
* @param port: The Type-C port number.
* @return 1 if sourcing Vbus, 0 if not.
*/
int ppc_is_sourcing_vbus(int port);
/**
* Turn on/off the charge path FET, such that current flows into the
* system.
*
* @param port: The Type-C port number.
* @param enable: 1: Turn on the FET, 0: turn off the FET.
* @return EC_SUCCESS on success, error otherwise.
*/
int ppc_vbus_sink_enable(int port, int enable);
/**
* Turn on/off the source path FET, such that current flows from the
* system.
*
* @param port: The Type-C port number.
* @param enable: 1: Turn on the FET, 0: turn off the FET.
* @return EC_SUCCESS on success, error otherwise.
*/
int ppc_vbus_source_enable(int port, int enable);
/**
* Board specific callback when a port overcurrents.
*
* @param port: The Type-C port which overcurrented.
*/
void board_overcurrent_event(int port);
#endif /* !defined(__CROS_EC_USBC_PPC_H) */