Files
OpenCellular/include/charge_state_v2.h
Alec Berg 283fe98939 samus: ryu: fix charge state machine init of input current
Currently charge state machine resets input current limit to default
every time AC is connected. Problem is by the time charge state machine
gets around to setting input current, it could have already been set
by successful PD negotiation, and this ends up overriding that value.
This fix has the state machine store desired input current limit, as
determined from PD negotation or any other place, and send last desired
input current limit on AC connect.

BUG=chrome-os-partner:24461
BRANCH=none
TEST=load on samus, test toggling between "pd 0 dev 5" and "pd 0 dev 20",
and test plugging and unplugging zinger numerous times, and verify charger
command always gives the expected input current limit based on PD
negotiation.

Change-Id: I18d8acc9e2085739e783c9c70c682d46bcce7fdb
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/211639
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
2014-08-12 05:11:39 +00:00

72 lines
1.9 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 "charger.h"
#include "timer.h"
#ifndef __CROS_EC_CHARGE_STATE_V2_H
#define __CROS_EC_CHARGE_STATE_V2_H
/*
* 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;
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);
#endif /* __CROS_EC_CHARGE_STATE_V2_H */