mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-14 08:36:39 +00:00
Occasionally the charge circuit on samus gets wedged and will not
charge. This change detects when the charge circuit has failed
and automatically recovers from it. It uses the BQ PROCHOT warning
to detect the failure by setting PROCHOT to trigger when the BQ
thinks input current is higher than the input current limit. When
the failure is detected, the EC disables charging and tells PD MCU
to disable CHARGE_EN, then a couple seconds later, it re-enables
charging.
This CL also adds more communication between EC and PD for the EC
to be able to set the charge state for the PD. Valid charge states
are: No charging allowed, 5V charging only, and max charging. The
EC uses this as such:
- When the EC gets AC present interrupt, it sets off a deferred
function to change charge state to max charging after some delay
to give time for the charge circuit to settle down.
- When the EC gets AC disconnect interrupt, it disables charging
briefly, enables learn mode, and then sets 5V charging allowed.
This allows for the same starting conditions in the charge circuit
for every AC attach.
- When the EC detects a wedged charge circuit, it disables charging
and waits a few seconds before re-enabling 5V only charging.
Additionally, this change moves the charging cutoff in S3/S5/G3 when
the battery is full to the EC. With the added control for the EC
to set the PD charging state, it is more convenient for the EC to
manage cutting off charging when battery is full.
BUG=chrome-os-partner:36081
BRANCH=samus
TEST=test the basics:
- connect/disconnect zinger a bunch of times
- connect and disconnect two zingers in different order
- connect two zingers and charge override between the two
test the automatic charge wedge recover:
- wedge the charge circuit by setting charger voltage under battery
voltage: "charger voltage 7000"
- wait a few seconds for the system to recover and check it is charging
with "battery" command
test full battery charge cutoff:
- added console command to change battery soc in board/samus/extpower.c:
static int cmd_battfake(int argc, char **argv)
{
char *e;
battery_soc = strtoi(argv[1], &e, 10);
batt_soc_change();
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(battfake, cmd_battfake, "", "", NULL);
- in S0, tested "battfake 100" does not disable charging.
- in G3, tested "battfake 100" disables charging and "battfake 99"
re-enables charging.
- set "battfake 100" and tested transitioning to S0 enables charging and
transitioning to S5 disables charging.
- attached two chargers and used charge override to select active port.
then toggled "battfake 100" to "battfake 99" back and forth and verified
charge override port is still the same.
test third-party 12V charger:
- plug in a bunch of times and make sure we stay at 5V for 500ms and then
transition to 12V
test with no battery:
- tested five different units with no battery and just zinger. 3/5 boot,
while the other 2 don't. But, the 2 that don't boot without battery also
can't boot w/o battery when this CL is reverted, so I don't think this
change is causing the problem, I think there is an electrical limitation.
test with EVT zinger:
- EVT zingers (P2 - C2) negotiate very quickly after connection, which
can cause INA problems w/o this CL. Tested an EVT zinger with samus and
did a bunch of connections and disconnections and verified that we always
wait at 5V for 500ms and that we don't wedge the INA circuit on connect.
test backwards compatibility:
- test new PD with old EC and make sure we can charge with zinger.
(note that if the charge circuit wedges, we won't be able to unwedge it).
- test old PD with new EC and make sure we can charge with zinger.
Change-Id: I7703b7a2ab1209d7f559b265b03517e79c74b16a
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/245253
Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
253 lines
6.8 KiB
C
253 lines
6.8 KiB
C
/* Copyright (c) 2012 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.
|
|
*/
|
|
|
|
/* Host command module for Chrome EC */
|
|
|
|
#ifndef __CROS_EC_HOST_COMMAND_H
|
|
#define __CROS_EC_HOST_COMMAND_H
|
|
|
|
#include "common.h"
|
|
#include "ec_commands.h"
|
|
|
|
/* Args for host command handler */
|
|
struct host_cmd_handler_args {
|
|
/*
|
|
* The driver that receives the command sets up the send_response()
|
|
* handler. Once the command is processed this handler is called to
|
|
* send the response back to the host.
|
|
*/
|
|
void (*send_response)(struct host_cmd_handler_args *args);
|
|
uint16_t command; /* Command (e.g., EC_CMD_FLASH_GET_INFO) */
|
|
uint8_t version; /* Version of command (0-31) */
|
|
|
|
const void *params; /* Input parameters */
|
|
uint16_t params_size; /* Size of input parameters in bytes */
|
|
|
|
/*
|
|
* Pointer to output response data buffer. On input to the handler,
|
|
* points to a buffer of size response_max.
|
|
*/
|
|
void *response;
|
|
|
|
/* Maximum size of response buffer provided to command handler */
|
|
uint16_t response_max;
|
|
|
|
/*
|
|
* Size of data pointed to by response. Defaults to 0, so commands
|
|
* which do not produce response data do not need to set this.
|
|
*/
|
|
uint16_t response_size;
|
|
|
|
/*
|
|
* This is the result returned by command and therefore the status to
|
|
* be reported from the command execution to the host. The driver
|
|
* should set this to EC_RES_SUCCESS on receipt of a valid command.
|
|
* It is then passed back to the driver via send_response() when
|
|
* command execution is complete. The driver may still override this
|
|
* when sending the response back to the host if it detects an error
|
|
* in the response or in its own operation.
|
|
*/
|
|
enum ec_status result;
|
|
};
|
|
|
|
/* Args for host packet handler */
|
|
struct host_packet {
|
|
/*
|
|
* The driver that receives the command sets up the send_response()
|
|
* handler. Once the command is processed this handler is called to
|
|
* send the response back to the host.
|
|
*/
|
|
void (*send_response)(struct host_packet *pkt);
|
|
|
|
/* Input request data */
|
|
const void *request;
|
|
|
|
/*
|
|
* Input request temp buffer. If this is non-null, the data has not
|
|
* been copied from here into the request buffer yet. The host command
|
|
* handler should do so while verifying the command. The interface
|
|
* can't do it, because it doesn't know how much to copy.
|
|
*/
|
|
void *request_temp;
|
|
|
|
/*
|
|
* Maximum size of request the interface can handle, in bytes. The
|
|
* buffers pointed to by *request and *request_temp must be at least
|
|
* this big.
|
|
*/
|
|
uint16_t request_max;
|
|
|
|
/* Size of input request data, in bytes */
|
|
uint16_t request_size;
|
|
|
|
/* Pointer to output response data buffer */
|
|
void *response;
|
|
|
|
/* Maximum size of response buffer provided to command handler */
|
|
uint16_t response_max;
|
|
|
|
/* Size of output response data, in bytes */
|
|
uint16_t response_size;
|
|
|
|
/*
|
|
* Error from driver; if this is non-zero, host command handler will
|
|
* return a properly formatted error response packet rather than
|
|
* calling a command handler.
|
|
*/
|
|
enum ec_status driver_result;
|
|
};
|
|
|
|
/* Host command */
|
|
struct host_command {
|
|
/*
|
|
* Handler for the command. Args points to context for handler.
|
|
* Returns result status (EC_RES_*).
|
|
*/
|
|
int (*handler)(struct host_cmd_handler_args *args);
|
|
/* Command code */
|
|
int command;
|
|
/* Mask of supported versions */
|
|
int version_mask;
|
|
};
|
|
|
|
/**
|
|
* Return a pointer to the memory-mapped buffer.
|
|
*
|
|
* This buffer is EC_MEMMAP_SIZE bytes long, is writable at any time, and the
|
|
* host can read it at any time.
|
|
*
|
|
* @param offset Offset within the range to return
|
|
* @return pointer to the buffer at that offset
|
|
*/
|
|
uint8_t *host_get_memmap(int offset);
|
|
|
|
/**
|
|
* Process a host command and return its response
|
|
*
|
|
* @param args Command handler args
|
|
* @return resulting status
|
|
*/
|
|
enum ec_status host_command_process(struct host_cmd_handler_args *args);
|
|
|
|
/**
|
|
* Set one or more host event bits.
|
|
*
|
|
* @param mask Event bits to set (use EC_HOST_EVENT_MASK()).
|
|
*/
|
|
void host_set_events(uint32_t mask);
|
|
|
|
/**
|
|
* Set a single host event.
|
|
*
|
|
* @param event Event to set (EC_HOST_EVENT_*).
|
|
*/
|
|
static inline void host_set_single_event(int event)
|
|
{
|
|
host_set_events(EC_HOST_EVENT_MASK(event));
|
|
}
|
|
|
|
/**
|
|
* Clear one or more host event bits.
|
|
*
|
|
* @param mask Event bits to clear (use EC_HOST_EVENT_MASK()).
|
|
* Write 1 to a bit to clear it.
|
|
*/
|
|
void host_clear_events(uint32_t mask);
|
|
|
|
/**
|
|
* Return the raw event state.
|
|
*/
|
|
uint32_t host_get_events(void);
|
|
|
|
/**
|
|
* Send a response to the relevent driver for transmission
|
|
*
|
|
* Once command processing is complete, this is used to send a response
|
|
* back to the host.
|
|
*
|
|
* @param args Contains response to send
|
|
*/
|
|
void host_send_response(struct host_cmd_handler_args *args);
|
|
|
|
/**
|
|
* Called by host interface module when a command is received.
|
|
*/
|
|
void host_command_received(struct host_cmd_handler_args *args);
|
|
|
|
/**
|
|
* Return the expected host packet size given its header.
|
|
*
|
|
* Also does some sanity checking on the host request.
|
|
*
|
|
* @param r Host request header
|
|
* @return The expected packet size, or 0 if error.
|
|
*/
|
|
int host_request_expected_size(const struct ec_host_request *r);
|
|
|
|
/**
|
|
* Handle a received host packet.
|
|
*
|
|
* @param packet Host packet args
|
|
*/
|
|
void host_packet_receive(struct host_packet *pkt);
|
|
|
|
/* Register a host command handler */
|
|
#define DECLARE_HOST_COMMAND(command, routine, version_mask) \
|
|
const struct host_command __host_cmd_##command \
|
|
__attribute__((section(".rodata.hcmds"))) \
|
|
= {routine, command, version_mask}
|
|
|
|
|
|
/**
|
|
* Politely ask the CPU to enable/disable its own throttling.
|
|
*
|
|
* @param throttle Enable (!=0) or disable(0) throttling
|
|
*/
|
|
void host_throttle_cpu(int throttle);
|
|
|
|
|
|
/**
|
|
* Signal host command task to send status to PD MCU.
|
|
*
|
|
* @new_chg_state PD MCU charge state
|
|
*/
|
|
void host_command_pd_send_status(enum pd_charge_state new_chg_state);
|
|
|
|
/**
|
|
* Ask the PD MCU for its status, obtaining the current charge_port as a
|
|
* side-effect (-1 means none or don't know).
|
|
*
|
|
* @param charge_port If present, updated with the current charge port:
|
|
* -1 == none/unknown, 0 == left, 1 == right.
|
|
*/
|
|
void pd_exchange_status(int *charge_port);
|
|
|
|
|
|
/**
|
|
* Send host command to PD MCU.
|
|
*
|
|
* @param command Host command number
|
|
* @param version Version of host command
|
|
* @param outdata Pointer to buffer of out data
|
|
* @param outsize Size of buffer to out data
|
|
* @param indata Pointer to buffer to store response
|
|
* @param insize Size of buffer to store response
|
|
*/
|
|
int pd_host_command(int command, int version,
|
|
const void *outdata, int outsize,
|
|
void *indata, int insize);
|
|
|
|
|
|
/**
|
|
* EC: Get verify boot mode
|
|
* @return vboot_mode as the following:
|
|
* VBOOT_MODE_NORMAL - normal mode
|
|
* VBOOT_MODE_DEVELOPER - developer mode
|
|
* VBOOT_MODE_RECOVERY - recovery mode
|
|
*/
|
|
int host_get_vboot_mode(void);
|
|
|
|
#endif /* __CROS_EC_HOST_COMMAND_H */
|