Files
OpenCellular/include/charge_state_v2.h
Mary Ruthven cb4a76e802 i2c: get battery information from charge state
ARM systems currently use SBS kernel driver which talks to the battery
through I2C passthu in the EC. Instead when asking for battery
information try getting it from the charge state machine first, and
then try the battery if charge state does not have the information.
This reduces latency by cutting out the battery response time.

BUG=chromium:484841
BRANCH=none
TEST=check that power_supply_info works properly on Jerry

Change-Id: If4da15ccabe412adc31fc94b189089ebb3e9265c
Signed-off-by: Mary Ruthven <mruthven@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/307905
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Alec Berg <alecaberg@chromium.org>
2015-10-27 11:52:34 -07:00

88 lines
2.4 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.
*/
#include "battery.h"
#include "battery_smart.h"
#include "charger.h"
#include "timer.h"
#ifndef __CROS_EC_CHARGE_STATE_V2_H
#define __CROS_EC_CHARGE_STATE_V2_H
#if defined(CONFIG_I2C_VIRTUAL_BATTERY) && defined(CONFIG_BATTERY_SMART)
#define VIRTUAL_BATTERY_ADDR BATTERY_ADDR
#endif
/*
* The values exported by charge_get_state() and charge_get_flags() are used
* only to control the LEDs (with one not-quite-correct exception). For V2
* we use a different set of states internally.
*/
enum charge_state_v2 {
ST_IDLE = 0,
ST_DISCHARGE,
ST_CHARGE,
ST_PRECHARGE,
NUM_STATES_V2
};
struct charge_state_data {
timestamp_t ts;
int ac;
int batt_is_charging;
struct charger_params chg;
struct batt_params batt;
enum charge_state_v2 state;
int requested_voltage;
int requested_current;
int desired_input_current;
};
/*
* Optional customization.
*
* On input, the struct reflects the default behavior. The function can make
* changes to the state, requested_voltage, or requested_current.
*
* Return value:
* >0 Desired time in usec for this poll period.
* 0 Use the default poll period (which varies with the state).
* <0 An error occurred. The poll time will be shorter than usual. Too
* many errors in a row may trigger some corrective action.
*/
int charger_profile_override(struct charge_state_data *);
/*
* Access to custom profile params through host commands.
* What this does is up to the implementation.
*/
enum ec_status charger_profile_override_get_param(uint32_t param,
uint32_t *value);
enum ec_status charger_profile_override_set_param(uint32_t param,
uint32_t value);
/**
* Set the charge input current limit. This value is stored and sent every
* time AC is applied.
*
* @param ma New input current limit in mA
* @return EC_SUCCESS or error
*/
int charge_set_input_current_limit(int ma);
/**
* Get value of battery parameter from charge state.
*
* @param batt_param battery parameter
* @param dest Destination buffer for data
* @param read_len Number of bytes to write to buffer
* @return EC_SUCCESS if successful, non-zero if error.
*
*/
int virtual_battery_read(uint8_t batt_param, uint8_t *dest, int read_len);
#endif /* __CROS_EC_CHARGE_STATE_V2_H */