mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-27 18:25:05 +00:00
kevin: set accurate current limit on USB load switch
When sourcing current on the type-C port, set the OCP limit on the VBUS load switch according to current dynamic capability. (3.0A when only one port is a power source, 1.5A else) Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=gru BUG=chrome-os-partner:56110 TEST=manual: connect Caroline to Kevin with Twinkie in between, ask Caroline to sink current through the UI. without anything else connected on Kevin, see 3A flowing when measuring with Twinkie ('tw vbus'), plug a dangling C-to-A receptacle dongle on the other Kevin port and see 1.5A flowing through Twinkie. Force the input current limit on Caroline to 3.0A and see Kevin cutting VBUS. Change-Id: Ib879b1ed720b20aa702c5f3643948ba0575d1193 Reviewed-on: https://chromium-review.googlesource.com/403869 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
34066e92a9
commit
cf7ff32b92
@@ -51,6 +51,11 @@ void pd_transition_voltage(int idx)
|
||||
/* No-operation: we are always 5V */
|
||||
}
|
||||
|
||||
int board_vbus_source_enabled(int port)
|
||||
{
|
||||
return gpio_get_level(port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN);
|
||||
}
|
||||
|
||||
int pd_set_power_supply_ready(int port)
|
||||
{
|
||||
/* Ensure we're not charging from this port */
|
||||
|
||||
@@ -220,8 +220,7 @@ int board_set_active_charge_port(int charge_port)
|
||||
switch (charge_port) {
|
||||
case 0: case 1:
|
||||
/* Don't charge from a source port */
|
||||
if (gpio_get_level(charge_port == 0 ?
|
||||
GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN))
|
||||
if (board_vbus_source_enabled(charge_port))
|
||||
return -1;
|
||||
|
||||
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
|
||||
@@ -261,8 +260,8 @@ void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
|
||||
int extpower_is_present(void)
|
||||
{
|
||||
int port;
|
||||
int p0_src = gpio_get_level(GPIO_USB_C0_5V_EN);
|
||||
int p1_src = gpio_get_level(GPIO_USB_C1_5V_EN);
|
||||
int p0_src = board_vbus_source_enabled(0);
|
||||
int p1_src = board_vbus_source_enabled(1);
|
||||
|
||||
/*
|
||||
* The charger will indicate VBUS presence if we're sourcing 5V,
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "util.h"
|
||||
#include "usb_mux.h"
|
||||
#include "usb_pd.h"
|
||||
#include "usb_pd_tcpm.h"
|
||||
|
||||
#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
|
||||
#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
|
||||
@@ -51,6 +52,31 @@ void pd_transition_voltage(int idx)
|
||||
/* No-operation: we are always 5V */
|
||||
}
|
||||
|
||||
static uint8_t vbus_en[CONFIG_USB_PD_PORT_COUNT];
|
||||
static uint8_t vbus_rp[CONFIG_USB_PD_PORT_COUNT] = {TYPEC_RP_1A5, TYPEC_RP_1A5};
|
||||
|
||||
int board_vbus_source_enabled(int port)
|
||||
{
|
||||
return vbus_en[port];
|
||||
}
|
||||
|
||||
static void board_vbus_update_source_current(int port)
|
||||
{
|
||||
enum gpio_signal gpio = port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN;
|
||||
int flags = (vbus_rp[port] == TYPEC_RP_1A5 && vbus_en[port]) ?
|
||||
(GPIO_INPUT | GPIO_PULL_UP) : GPIO_OUTPUT;
|
||||
|
||||
/*
|
||||
* Driving USB_Cx_5V_EN high, actually put a 16.5k resistance
|
||||
* (2x 33k in parallel) on the NX5P3290 load switch ILIM pin,
|
||||
* setting a minimum OCP current of 3186 mA.
|
||||
* Putting an internal pull-up on USB_Cx_5V_EN, effectively put a 33k
|
||||
* resistor on ILIM, setting a minimum OCP current of 1505 mA.
|
||||
*/
|
||||
gpio_set_level(gpio, vbus_en[port]);
|
||||
gpio_set_flags(gpio, flags);
|
||||
}
|
||||
|
||||
int pd_set_power_supply_ready(int port)
|
||||
{
|
||||
/* Ensure we're not charging from this port */
|
||||
@@ -59,10 +85,10 @@ int pd_set_power_supply_ready(int port)
|
||||
/* Ensure we advertise the proper available current quota */
|
||||
charge_manager_source_port(port, 1);
|
||||
|
||||
/* Provide VBUS */
|
||||
gpio_set_level(port ? GPIO_USB_C1_5V_EN :
|
||||
GPIO_USB_C0_5V_EN, 1);
|
||||
pd_set_vbus_discharge(port, 0);
|
||||
/* Provide VBUS */
|
||||
vbus_en[port] = 1;
|
||||
board_vbus_update_source_current(port);
|
||||
|
||||
/* notify host of power info change */
|
||||
pd_send_host_event(PD_EVENT_POWER_CHANGE);
|
||||
@@ -72,13 +98,12 @@ int pd_set_power_supply_ready(int port)
|
||||
|
||||
void pd_power_supply_reset(int port)
|
||||
{
|
||||
enum gpio_signal gpio;
|
||||
int prev_en;
|
||||
|
||||
gpio = port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN;
|
||||
prev_en = gpio_get_level(gpio);
|
||||
prev_en = vbus_en[port];
|
||||
/* Disable VBUS */
|
||||
gpio_set_level(gpio, 0);
|
||||
vbus_en[port] = 0;
|
||||
board_vbus_update_source_current(port);
|
||||
/* Enable discharge if we were previously sourcing 5V */
|
||||
if (prev_en)
|
||||
pd_set_vbus_discharge(port, 1);
|
||||
@@ -114,6 +139,14 @@ void typec_set_input_current_limit(int port, uint32_t max_ma,
|
||||
#endif
|
||||
}
|
||||
|
||||
void typec_set_source_current_limit(int port, int rp)
|
||||
{
|
||||
vbus_rp[port] = rp;
|
||||
|
||||
/* change the GPIO driving the load switch if needed */
|
||||
board_vbus_update_source_current(port);
|
||||
}
|
||||
|
||||
int pd_board_checks(void)
|
||||
{
|
||||
return EC_SUCCESS;
|
||||
|
||||
@@ -51,6 +51,11 @@ void pd_transition_voltage(int idx)
|
||||
/* No-operation: we are always 5V */
|
||||
}
|
||||
|
||||
int board_vbus_source_enabled(int port)
|
||||
{
|
||||
return gpio_get_level(port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN);
|
||||
}
|
||||
|
||||
int pd_set_power_supply_ready(int port)
|
||||
{
|
||||
/* Ensure we're not charging from this port */
|
||||
|
||||
@@ -51,6 +51,11 @@ void pd_transition_voltage(int idx)
|
||||
/* No-operation: we are always 5V */
|
||||
}
|
||||
|
||||
int board_vbus_source_enabled(int port)
|
||||
{
|
||||
return gpio_get_level(port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN);
|
||||
}
|
||||
|
||||
int pd_set_power_supply_ready(int port)
|
||||
{
|
||||
/* Ensure we're not charging from this port */
|
||||
|
||||
@@ -51,6 +51,11 @@ void pd_transition_voltage(int idx)
|
||||
/* No-operation: we are always 5V */
|
||||
}
|
||||
|
||||
int board_vbus_source_enabled(int port)
|
||||
{
|
||||
return gpio_get_level(port ? GPIO_USB_C1_5V_EN : GPIO_USB_C0_5V_EN);
|
||||
}
|
||||
|
||||
int pd_set_power_supply_ready(int port)
|
||||
{
|
||||
/* Ensure we're not charging from this port */
|
||||
|
||||
@@ -939,6 +939,7 @@ void charge_manager_source_port(int port, int enable)
|
||||
charge_manager_save_log(p);
|
||||
#endif
|
||||
|
||||
typec_set_source_current_limit(p, rp);
|
||||
tcpm_select_rp_value(p, rp);
|
||||
pd_update_contract(p);
|
||||
}
|
||||
|
||||
@@ -968,8 +968,7 @@ void pd_set_vbus_discharge(int port, int enable)
|
||||
static struct mutex discharge_lock[CONFIG_USB_PD_PORT_COUNT];
|
||||
|
||||
mutex_lock(&discharge_lock[port]);
|
||||
enable &= !gpio_get_level(port ? GPIO_USB_C1_5V_EN :
|
||||
GPIO_USB_C0_5V_EN);
|
||||
enable &= !board_vbus_source_enabled(port);
|
||||
#ifdef CONFIG_USB_PD_DISCHARGE_GPIO
|
||||
gpio_set_level(port ? GPIO_USB_C1_DISCHARGE :
|
||||
GPIO_USB_C0_DISCHARGE, enable);
|
||||
|
||||
@@ -120,4 +120,12 @@ int board_set_active_charge_port(int charge_port);
|
||||
*/
|
||||
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma);
|
||||
|
||||
/*
|
||||
* Get whether the port is sourcing power on VBUS.
|
||||
*
|
||||
* @param port PD port.
|
||||
* @return VBUS power state.
|
||||
*/
|
||||
int board_vbus_source_enabled(int port);
|
||||
|
||||
#endif /* __CROS_EC_CHARGE_MANAGER_H */
|
||||
|
||||
@@ -1001,6 +1001,14 @@ void pd_update_contract(int port);
|
||||
void typec_set_input_current_limit(int port, uint32_t max_ma,
|
||||
uint32_t supply_voltage);
|
||||
|
||||
/**
|
||||
* Set the type-C current limit when sourcing current..
|
||||
*
|
||||
* @param port USB-C port number
|
||||
* @param rp One of enum tcpc_rp_value (eg TYPEC_RP_3A0) defining the limit.
|
||||
*/
|
||||
void typec_set_source_current_limit(int port, int rp);
|
||||
|
||||
/**
|
||||
* Verify board specific health status : current, voltages...
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user