summaryrefslogtreecommitdiff
path: root/board/glkrvp/chg_usb_pd.c
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2017-11-07 23:09:57 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-11-10 09:16:35 -0800
commitcab93b613b1c47fa01b140b507ddb08f9d48b415 (patch)
tree454cf82388a64c6556893c0e24d7c6d5a632fb5a /board/glkrvp/chg_usb_pd.c
parente64f9b258acb5e3bb3457a26e8c1450b75fab243 (diff)
downloadchrome-ec-cab93b613b1c47fa01b140b507ddb08f9d48b415.tar.gz
glkrvp: Allow system to boot using DC Jack
There are two Type-C ports and a DC Jack on GLKRVP. Added code to allow system to boot from DC Jack also. This helps to boot the device without Type-C connector during early stage of software development. BUG=b:69005234 BRANCH=glkrvp TEST=GLKRVP can boot to OS without battery and DC Jack attached. Also VBATA is set to battery voltage max. When DC-Jack is present Type-C port is not enabled and vice-versa. Change-Id: I0fe5631c40490c56fba6ed5f3ad7ba7f5248460a Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/757874 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'board/glkrvp/chg_usb_pd.c')
-rw-r--r--board/glkrvp/chg_usb_pd.c86
1 files changed, 76 insertions, 10 deletions
diff --git a/board/glkrvp/chg_usb_pd.c b/board/glkrvp/chg_usb_pd.c
index 097b7ee1be..da37894a1a 100644
--- a/board/glkrvp/chg_usb_pd.c
+++ b/board/glkrvp/chg_usb_pd.c
@@ -24,6 +24,12 @@
#define PTN5110_EXT_GPIO_EN_SNK1 (1 << 4)
#define PTN5110_EXT_GPIO_IILIM_5V_VBUS_L (1 << 3)
+enum glkrvp_charge_ports {
+ TYPE_C_PORT_0,
+ TYPE_C_PORT_1,
+ DC_JACK_PORT_0,
+};
+
const struct tcpc_config_t tcpc_config[CONFIG_USB_PD_PORT_COUNT] = {
{NPCX_I2C_PORT0_1, 0xA0, &tcpci_tcpm_drv, TCPC_ALERT_ACTIVE_LOW},
{NPCX_I2C_PORT0_1, 0xA4, &tcpci_tcpm_drv, TCPC_ALERT_ACTIVE_LOW},
@@ -129,11 +135,54 @@ void board_reset_pd_mcu(void)
/* TODO: Add reset logic */
}
+static inline int board_dc_jack_present(void)
+{
+ return !gpio_get_level(GPIO_DC_JACK_PRESENT_L);
+}
+
+static void board_dc_jack_handle(void)
+{
+ struct charge_port_info charge_dc_jack;
+
+ /* System is booted from DC Jack */
+ if (board_dc_jack_present()) {
+ charge_dc_jack.current = (PD_MAX_POWER_MW * 1000) /
+ DC_JACK_MAX_VOLTAGE_MV;
+ charge_dc_jack.voltage = DC_JACK_MAX_VOLTAGE_MV;
+ } else {
+ charge_dc_jack.current = 0;
+ charge_dc_jack.voltage = USB_CHARGER_VOLTAGE_MV;
+ }
+
+ charge_manager_update_charge(CHARGE_SUPPLIER_DEDICATED,
+ DC_JACK_PORT_0, &charge_dc_jack);
+}
+DECLARE_HOOK(HOOK_AC_CHANGE, board_dc_jack_handle, HOOK_PRIO_FIRST);
+
+static void board_charge_init(void)
+{
+ int port, supplier;
+ struct charge_port_info charge_init = {
+ .current = 0,
+ .voltage = USB_CHARGER_VOLTAGE_MV,
+ };
+
+ /* Initialize all charge suppliers to seed the charge manager */
+ for (port = 0; port < CHARGE_PORT_COUNT; port++) {
+ for (supplier = 0; supplier < CHARGE_SUPPLIER_COUNT; supplier++)
+ charge_manager_update_charge(supplier, port,
+ &charge_init);
+ }
+
+ board_dc_jack_handle();
+}
+DECLARE_HOOK(HOOK_INIT, board_charge_init, HOOK_PRIO_DEFAULT);
+
int board_set_active_charge_port(int port)
{
/* charge port is a realy physical port */
int is_real_port = (port >= 0 &&
- port < CONFIG_USB_PD_PORT_COUNT);
+ port < CHARGE_PORT_COUNT);
/* check if we are source vbus on that port */
int source = board_charger_port_is_sourcing_vbus(port);
@@ -142,16 +191,33 @@ int board_set_active_charge_port(int port)
return EC_ERROR_INVAL;
}
- CPRINTS("New chg p%d", port);
+ /*
+ * Do not enable Type-C port if the DC Jack is present.
+ * When the Type-C is active port, hardware circuit will
+ * block DC jack from enabling +VADP_OUT.
+ */
+ if (port != DC_JACK_PORT_0 && board_dc_jack_present()) {
+ CPRINTS("DC Jack present, Skip enable p%d", port);
+ return EC_ERROR_INVAL;
+ }
- if (port != CHARGE_PORT_NONE) {
- /* Make sure non-charging port is disabled */
- board_charging_enable(port, 1);
- board_charging_enable(!port, 0);
- } else {
- /* Disable both ports */
- board_charging_enable(0, 0);
- board_charging_enable(1, 0);
+ /* Make sure non-charging port is disabled */
+ switch (port) {
+ case TYPE_C_PORT_0:
+ board_charging_enable(TYPE_C_PORT_1, 0);
+ board_charging_enable(TYPE_C_PORT_0, 1);
+ break;
+ case TYPE_C_PORT_1:
+ board_charging_enable(TYPE_C_PORT_0, 0);
+ board_charging_enable(TYPE_C_PORT_1, 1);
+ break;
+ case DC_JACK_PORT_0:
+ case CHARGE_PORT_NONE:
+ default:
+ /* Disable both Type-C ports */
+ board_charging_enable(TYPE_C_PORT_0, 0);
+ board_charging_enable(TYPE_C_PORT_1, 0);
+ break;
}
return EC_SUCCESS;