mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 02:20:48 +00:00
kevin: Add battery and charger support
Add support for bd99955 charger and battery. BUG=chrome-os-partner:51722 TEST=Verify kevin charges at 3A input current when zinger is inserted, and verify battery actually charges. BRANCH=None Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: Iccd8185585fe39440681f5830cf58acafe6291b8 Reviewed-on: https://chromium-review.googlesource.com/335538 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
55bd1930f1
commit
e2deea3649
82
board/kevin/battery.c
Normal file
82
board/kevin/battery.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/* Copyright 2016 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.
|
||||
*
|
||||
* Battery pack vendor provided charging profile
|
||||
*/
|
||||
|
||||
#include "battery.h"
|
||||
#include "battery_smart.h"
|
||||
#include "charge_state.h"
|
||||
#include "console.h"
|
||||
#include "ec_commands.h"
|
||||
#include "util.h"
|
||||
|
||||
/* Shutdown mode parameter to write to manufacturer access register */
|
||||
#define SB_SHUTDOWN_DATA 0x0010
|
||||
|
||||
/* Battery info for proto - copied from celes */
|
||||
/* TODO: Update once real battery is available */
|
||||
static const struct battery_info info = {
|
||||
.voltage_max = 8700,
|
||||
.voltage_normal = 7600,
|
||||
.voltage_min = 6000,
|
||||
.precharge_current = 150,
|
||||
.start_charging_min_c = 0,
|
||||
.start_charging_max_c = 45,
|
||||
.charging_min_c = 0,
|
||||
.charging_max_c = 60,
|
||||
.discharging_min_c = -20,
|
||||
.discharging_max_c = 60,
|
||||
};
|
||||
|
||||
const struct battery_info *battery_get_info(void)
|
||||
{
|
||||
return &info;
|
||||
}
|
||||
|
||||
int board_cut_off_battery(void)
|
||||
{
|
||||
int rv;
|
||||
|
||||
/* Ship mode command must be sent twice to take effect */
|
||||
rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
|
||||
if (rv != EC_SUCCESS)
|
||||
return EC_RES_ERROR;
|
||||
|
||||
rv = sb_write(SB_MANUFACTURER_ACCESS, SB_SHUTDOWN_DATA);
|
||||
return rv ? EC_RES_ERROR : EC_RES_SUCCESS;
|
||||
}
|
||||
|
||||
int charger_profile_override(struct charge_state_data *curr)
|
||||
{
|
||||
const struct battery_info *batt_info;
|
||||
/* battery temp in 0.1 deg C */
|
||||
int bat_temp_c = curr->batt.temperature - 2731;
|
||||
|
||||
batt_info = battery_get_info();
|
||||
/* Don't charge if outside of allowable temperature range */
|
||||
if (bat_temp_c >= batt_info->charging_max_c * 10 ||
|
||||
bat_temp_c < batt_info->charging_min_c * 10) {
|
||||
curr->requested_current = 0;
|
||||
curr->requested_voltage = 0;
|
||||
curr->batt.flags &= ~BATT_FLAG_WANT_CHARGE;
|
||||
curr->state = ST_IDLE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Customs options controllable by host command. */
|
||||
#define PARAM_FASTCHARGE (CS_PARAM_CUSTOM_PROFILE_MIN + 0)
|
||||
|
||||
enum ec_status charger_profile_override_get_param(uint32_t param,
|
||||
uint32_t *value)
|
||||
{
|
||||
return EC_RES_INVALID_PARAM;
|
||||
}
|
||||
|
||||
enum ec_status charger_profile_override_set_param(uint32_t param,
|
||||
uint32_t value)
|
||||
{
|
||||
return EC_RES_INVALID_PARAM;
|
||||
}
|
||||
@@ -7,10 +7,17 @@
|
||||
#include "adc_chip.h"
|
||||
#include "backlight.h"
|
||||
#include "button.h"
|
||||
#include "charge_manager.h"
|
||||
#include "charge_state.h"
|
||||
#include "charger.h"
|
||||
#include "chipset.h"
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "driver/charger/bd99955.h"
|
||||
#include "driver/tcpm/fusb302.h"
|
||||
#include "extpower.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
#include "host_command.h"
|
||||
#include "i2c.h"
|
||||
#include "keyboard_scan.h"
|
||||
@@ -24,9 +31,13 @@
|
||||
#include "switch.h"
|
||||
#include "timer.h"
|
||||
#include "thermal.h"
|
||||
#include "usb_charge.h"
|
||||
#include "usb_pd_tcpm.h"
|
||||
#include "util.h"
|
||||
|
||||
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
|
||||
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
|
||||
|
||||
static void tcpc_alert_event(enum gpio_signal signal)
|
||||
{
|
||||
/* Exchange status with TCPCs */
|
||||
@@ -123,18 +134,67 @@ uint16_t tcpc_get_alert_status(void)
|
||||
|
||||
int board_set_active_charge_port(int charge_port)
|
||||
{
|
||||
/* TODO: Select proper charge port through BD99955 regs. */
|
||||
ASSERT(charge_port != 1);
|
||||
return EC_SUCCESS;
|
||||
enum bd99955_charge_port bd99955_port;
|
||||
|
||||
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;
|
||||
break;
|
||||
case CHARGE_PORT_NONE:
|
||||
bd99955_port = BD99955_CHARGE_PORT_NONE;
|
||||
break;
|
||||
default:
|
||||
panic("Invalid charge port\n");
|
||||
break;
|
||||
}
|
||||
|
||||
return bd99955_select_input_port(bd99955_port);
|
||||
}
|
||||
|
||||
void board_set_charge_limit(int charge_ma)
|
||||
{
|
||||
/* TODO: Add support for BD99955 charger. */
|
||||
charge_set_input_current_limit(MAX(charge_ma,
|
||||
CONFIG_CHARGER_INPUT_CURRENT));
|
||||
}
|
||||
|
||||
int extpower_is_present(void)
|
||||
{
|
||||
/* TODO: Add support for BD99955 charger. */
|
||||
return 1;
|
||||
return bd99955_extpower_is_present();
|
||||
}
|
||||
|
||||
static void board_init(void)
|
||||
{
|
||||
struct charge_port_info charge_none;
|
||||
int i;
|
||||
|
||||
/* Initialize all pericom charge suppliers to 0 */
|
||||
charge_none.voltage = USB_CHARGER_VOLTAGE_MV;
|
||||
charge_none.current = 0;
|
||||
/* TODO: Implement BC1.2 + VBUS detection */
|
||||
for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) {
|
||||
charge_manager_update_charge(CHARGE_SUPPLIER_PROPRIETARY,
|
||||
i,
|
||||
&charge_none);
|
||||
charge_manager_update_charge(CHARGE_SUPPLIER_BC12_CDP,
|
||||
i,
|
||||
&charge_none);
|
||||
charge_manager_update_charge(CHARGE_SUPPLIER_BC12_DCP,
|
||||
i,
|
||||
&charge_none);
|
||||
charge_manager_update_charge(CHARGE_SUPPLIER_BC12_SDP,
|
||||
i,
|
||||
&charge_none);
|
||||
charge_manager_update_charge(CHARGE_SUPPLIER_OTHER,
|
||||
i,
|
||||
&charge_none);
|
||||
charge_manager_update_charge(CHARGE_SUPPLIER_VBUS,
|
||||
i,
|
||||
&charge_none);
|
||||
}
|
||||
}
|
||||
DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT);
|
||||
|
||||
@@ -30,6 +30,11 @@
|
||||
#define CONFIG_SPI_FLASH_W25X40
|
||||
#define CONFIG_VBOOT_HASH
|
||||
|
||||
#define CONFIG_CHARGER
|
||||
#define CONFIG_CHARGER_BD99955
|
||||
#define CONFIG_CHARGER_INPUT_CURRENT 512
|
||||
#define CONFIG_CHARGER_V2
|
||||
|
||||
/* USB PD config */
|
||||
#define CONFIG_CHARGE_MANAGER
|
||||
#define CONFIG_USB_POWER_DELIVERY
|
||||
@@ -45,8 +50,9 @@
|
||||
/* TODO: Enable TRY_SRC */
|
||||
#undef CONFIG_USB_PD_TRY_SRC
|
||||
|
||||
#define CONFIG_BATTERY_SMART
|
||||
#define CONFIG_BATTERY_CUT_OFF
|
||||
#define CONFIG_BATTERY_PRESENT_GPIO GPIO_EC_BATT_PRES_L
|
||||
#define CONFIG_BATTERY_SMART
|
||||
|
||||
/* TODO: Allow higher voltage charging */
|
||||
#define PD_OPERATING_POWER_MW 15000
|
||||
@@ -81,6 +87,9 @@
|
||||
#undef CONFIG_PSTORE
|
||||
#undef CONFIG_LOW_POWER_IDLE /* Deep Sleep Support */
|
||||
|
||||
#undef DEFERRABLE_MAX_COUNT
|
||||
#define DEFERRABLE_MAX_COUNT 9
|
||||
|
||||
#define I2C_PORT_TCPC0 NPCX_I2C_PORT0_0
|
||||
#define I2C_PORT_TCPC1 NPCX_I2C_PORT0_1
|
||||
#define I2C_PORT_CHARGER NPCX_I2C_PORT2
|
||||
|
||||
@@ -10,5 +10,6 @@
|
||||
CHIP:=npcx
|
||||
CHIP_VARIANT:=npcx5m5g
|
||||
|
||||
board-y=board.o
|
||||
board-y=battery.o
|
||||
board-y+=board.o
|
||||
board-y+=usb_pd_policy.o
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
#define CONFIG_TASK_LIST \
|
||||
TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \
|
||||
TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \
|
||||
TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \
|
||||
TASK_NOTEST(PDCMD, pd_command_task, NULL, TASK_STACK_SIZE) \
|
||||
TASK_ALWAYS(HOSTCMD, host_command_task, NULL, TASK_STACK_SIZE) \
|
||||
|
||||
@@ -23,8 +23,8 @@ GPIO_INT(VOLUME_DOWN_L, PIN(8, 3), GPIO_INT_BOTH | GPIO_INPUT | GPIO_PULL_UP,
|
||||
button_interrupt)
|
||||
GPIO_INT(POWER_BUTTON_L, PIN(0, 4), GPIO_INT_BOTH | GPIO_INPUT,
|
||||
power_button_interrupt)
|
||||
GPIO_INT(LID_OPEN, PIN(9, 7), GPIO_INT_BOTH | GPIO_INPUT | GPIO_SEL_1P8V,
|
||||
lid_interrupt)
|
||||
GPIO_INT(LID_OPEN, PIN(9, 7),
|
||||
GPIO_INT_BOTH | GPIO_INPUT | GPIO_SEL_1P8V, lid_interrupt)
|
||||
|
||||
/* TODO: Add power sequencing interrupt pins */
|
||||
|
||||
@@ -98,7 +98,7 @@ GPIO(USB_DP_HPD, PIN(6, 6), GPIO_OUT_LOW)
|
||||
GPIO(CHARGER_RESET_L, PIN(0, 1), GPIO_OUT_HIGH | GPIO_OPEN_DRAIN)
|
||||
GPIO(CR50_RESET_L, PIN(0, 2), GPIO_OUT_HIGH | GPIO_OPEN_DRAIN)
|
||||
GPIO(CHARGER_INT_L, PIN(3, 3), GPIO_INPUT)
|
||||
GPIO(EC_BATT_PRES_L, PIN(3, 4), GPIO_INPUT | GPIO_PULL_UP)
|
||||
GPIO(EC_BATT_PRES_L, PIN(3, 4), GPIO_INPUT)
|
||||
GPIO(LID_360_L, PIN(3, 6), GPIO_INPUT | GPIO_SEL_1P8V)
|
||||
GPIO(BASE_SIXAXIS_INT_L, PIN(4, 0), GPIO_INPUT | GPIO_SEL_1P8V)
|
||||
GPIO(CCD_MODE, PIN(6, 3), GPIO_INPUT)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "charge_manager.h"
|
||||
#include "common.h"
|
||||
#include "console.h"
|
||||
#include "driver/charger/bd99955.h"
|
||||
#include "gpio.h"
|
||||
#include "hooks.h"
|
||||
#include "host_command.h"
|
||||
@@ -50,11 +51,11 @@ void pd_transition_voltage(int idx)
|
||||
int pd_set_power_supply_ready(int port)
|
||||
{
|
||||
/* Disable charging */
|
||||
/* TODO: Add support for BD99955 */
|
||||
bd99955_select_input_port(BD99955_CHARGE_PORT_NONE);
|
||||
|
||||
/* Provide VBUS */
|
||||
gpio_set_level(port ? GPIO_C1_VOUT_EN_L :
|
||||
GPIO_C0_VOUT_EN_L, 1);
|
||||
GPIO_C0_VOUT_EN_L, 0);
|
||||
|
||||
/* notify host of power info change */
|
||||
pd_send_host_event(PD_EVENT_POWER_CHANGE);
|
||||
@@ -66,7 +67,7 @@ void pd_power_supply_reset(int port)
|
||||
{
|
||||
/* Disable VBUS */
|
||||
gpio_set_level(port ? GPIO_C1_VOUT_EN_L :
|
||||
GPIO_C0_VOUT_EN_L, 0);
|
||||
GPIO_C0_VOUT_EN_L, 1);
|
||||
|
||||
/* notify host of power info change */
|
||||
pd_send_host_event(PD_EVENT_POWER_CHANGE);
|
||||
|
||||
Reference in New Issue
Block a user