reef: reject charge port on init till battery is initialized

Ported from patch below:
      Change-Id: If8fd84f82f5a7fb7ca3736031a161d90e5e77c12
      Reviewed-on: https://chromium-review.googlesource.com/349853

Also added CUSTOM_BATTERY_PRESENT check for battery not initialized

BUG=chrome-os-partner:55255
BRANCH=master
TEST="batterycutoff" command successful and boots fine
after plugging in AC to exit ship mode;make buildall -j

Change-Id: I928e17b7ae186d9be695f45540fd79b844f8e3ac
Signed-off-by: Divya Sasidharan <divya.s.sasidharan@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/360217
Commit-Ready: Divya S Sasidharan <divya.s.sasidharan@intel.com>
Tested-by: Divya S Sasidharan <divya.s.sasidharan@intel.com>
Reviewed-by: Vijay P Hiremath <vijay.p.hiremath@intel.com>
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Divya Sasidharan
2016-07-13 16:35:53 -07:00
committed by chrome-bot
parent 824f9fadc2
commit 27f6bf2762
4 changed files with 70 additions and 27 deletions

View File

@@ -10,6 +10,7 @@
#include "charge_state.h"
#include "console.h"
#include "ec_commands.h"
#include "gpio.h"
#include "i2c.h"
#include "util.h"
@@ -230,3 +231,32 @@ DECLARE_CONSOLE_COMMAND(fastcharge, command_fastcharge,
NULL);
#endif /* CONFIG_CHARGER_PROFILE_OVERRIDE */
#ifdef CONFIG_BATTERY_PRESENT_CUSTOM
/*
* Physical detection of battery.
*/
enum battery_present battery_is_present(void)
{
enum battery_present batt_pres;
int batt_status;
/* The GPIO is low when the battery is physically present */
batt_pres = gpio_get_level(GPIO_EC_BATT_PRES_L) ? BP_NO : BP_YES;
/*
* Make sure battery status is implemented, I2C transactions are
* success & the battery status is Initialized to find out if it
* is a working battery and it is not in the cut-off mode.
*
* FETs are turned off after Power Shutdown time.
* The device will wake up when a voltage is applied to PACK.
* Battery status will be inactive until it is initialized.
*/
if (batt_pres == BP_YES && !battery_status(&batt_status))
if (!(batt_status & STATUS_INITIALIZED))
batt_pres = BP_NO;
return batt_pres;
}
#endif

View File

@@ -268,6 +268,12 @@ const struct button_config buttons[CONFIG_BUTTON_COUNT] = {
30 * MSEC, 0},
};
static const enum bd99955_charge_port
pd_port_to_bd99955_port[CONFIG_USB_PD_PORT_COUNT] = {
[0] = BD99955_CHARGE_PORT_VBUS,
[1] = BD99955_CHARGE_PORT_VCC,
};
/* Called by APL power state machine when transitioning from G3 to S5 */
static void chipset_pre_init(void)
{
@@ -337,6 +343,23 @@ static void board_init(void)
/* PP3300 needs to be enabled before TCPC init hooks */
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_FIRST);
int pd_snk_is_vbus_provided(int port)
{
enum bd99955_charge_port bd99955_port;
switch (port) {
case 0:
case 1:
bd99955_port = pd_port_to_bd99955_port[port];
break;
default:
panic("Invalid charge port\n");
break;
}
return bd99955_is_vbus_provided(bd99955_port);
}
/**
* Set active charge port -- only one port can be active at a time.
*
@@ -348,6 +371,7 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_FIRST);
int board_set_active_charge_port(int charge_port)
{
enum bd99955_charge_port bd99955_port;
static int initialized;
/* charge port is a physical port */
int is_real_port = (charge_port >= 0 &&
@@ -360,15 +384,25 @@ int board_set_active_charge_port(int charge_port)
CPRINTF("Skip enable p%d", charge_port);
return EC_ERROR_INVAL;
}
/*
* Reject charge port disable if our battery is critical and we
* have yet to initialize a charge port - continue to charge using
* charger ROM / POR settings.
*/
if (!initialized &&
charge_port == CHARGE_PORT_NONE &&
charge_get_percent() < 2) {
CPRINTS("Battery critical, don't disable charging");
return -1;
}
CPRINTS("New chg p%d", charge_port);
switch (charge_port) {
case 0:
bd99955_port = BD99955_CHARGE_PORT_VBUS;
break;
case 1:
bd99955_port = BD99955_CHARGE_PORT_VCC;
bd99955_port = pd_port_to_bd99955_port[charge_port];
break;
case CHARGE_PORT_NONE:
bd99955_port = BD99955_CHARGE_PORT_NONE;
@@ -378,6 +412,8 @@ int board_set_active_charge_port(int charge_port)
break;
}
initialized = 1;
return bd99955_select_input_port(bd99955_port);
}

View File

@@ -16,7 +16,7 @@
/* Battery */
#define CONFIG_BATTERY_CUT_OFF
#define CONFIG_BATTERY_PRESENT_GPIO GPIO_EC_BATT_PRES_L
#define CONFIG_BATTERY_PRESENT_CUSTOM
#define CONFIG_BATTERY_SMART
/* Charger */

View File

@@ -106,29 +106,6 @@ void typec_set_input_current_limit(int port, uint32_t max_ma,
pd_send_host_event(PD_EVENT_POWER_CHANGE);
}
int pd_snk_is_vbus_provided(int port)
{
enum bd99955_charge_port bd99955_port;
/*
* TODO: Add a compile-time mapping to prevent
* duplication of this code.
*/
switch (port) {
case 0:
bd99955_port = BD99955_CHARGE_PORT_VBUS;
break;
case 1:
bd99955_port = BD99955_CHARGE_PORT_VCC;
break;
default:
panic("Invalid charge port\n");
break;
}
return bd99955_is_vbus_provided(bd99955_port);
}
int pd_board_checks(void)
{
return EC_SUCCESS;