Files
OpenCellular/include/charge_manager.h
Shawn Nematbakhsh b8f73a451d charge_manager: Add module for managing battery charge limits
charge_manager is intended to manage charge limits from various tasks
(typically PD charge tasks and USB / BC 1.2 charge tasks). These tasks
can update the charge limit of a port by calling charge_manager_update
(thread-safe function). If the charge limit has changed,
charge_manager_refresh will be queued as a deferred task, which will
select the "best" charge port and set the proper charge limit.

In order to use charge_manager, a board needs to do the following:

1. Declare PD_PORT_COUNT in usb_pd_config.h
2. Implement board_set_charge_limit
3. Implement board_set_active_charge_port
4. Call charge_manager_update whenever the available charge on a port changes.

BUG=chrome-os-partner:31361
TEST=Manual on samus_pd, with subsequent commit. Insert and remove
various chargers, check console to verify PD charger always has priority
and correct current limit is set based upon 'best' charger.
BRANCH=samus

Change-Id: Iede120b69e0b46ed329bcf9b7e07c39ba5e9f77b
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/222723
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2014-10-15 18:22:44 +00:00

39 lines
1.0 KiB
C

/* Copyright (c) 2014 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 __CHARGE_MANAGER_H
#define __CHARGE_MANAGER_H
/* Charge port that indicates no active port */
#define CHARGE_PORT_NONE -1
/* Initial charge state */
#define CHARGE_CURRENT_UNINITIALIZED -1
#define CHARGE_VOLTAGE_UNINITIALIZED -1
#define POWER(charge_port) ((charge_port.current) * (charge_port.voltage))
/* Charge suppliers, sorted by priority */
enum charge_supplier {
CHARGE_SUPPLIER_NONE = -1,
/* Highest priority supplier first */
CHARGE_SUPPLIER_PD = 0,
CHARGE_SUPPLIER_TYPEC = 1,
CHARGE_SUPPLIER_BC12 = 2,
CHARGE_SUPPLIER_COUNT
};
/* Charge tasks report available current and voltage */
struct charge_port_info {
int current;
int voltage;
};
/* Called by charging tasks to update their available charge */
void charge_manager_update(enum charge_supplier supplier,
int charge_port,
struct charge_port_info *charge);
#endif /* __CHARGE_MANAGER_H */