Skip to content

Fwk lotus azalea 19573 #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: fwk-lotus-azalea-19573
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions common/charge_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ static void battery_sustainer_disable(void)
battery_sustainer_set(-1, -1);
}

test_export_static bool battery_sustainer_enabled(void)
//test_export_static bool battery_sustainer_enabled(void)
bool battery_sustainer_enabled(void)
{
return sustain_soc.lower != -1 && sustain_soc.upper != -1;
}
Expand Down Expand Up @@ -594,6 +595,9 @@ int set_chg_ctrl_mode(enum ec_charge_control_mode mode)
int current, voltage;
int rv;

CPRINTS("%s: Trying to switch control mode from %s to %s", __func__,
mode_text[local_state.chg_ctl_mode],
mode_text[mode]);
current = local_state.manual_current;
voltage = local_state.manual_voltage;

Expand All @@ -620,8 +624,10 @@ int set_chg_ctrl_mode(enum ec_charge_control_mode mode)

if (IS_ENABLED(CONFIG_CHARGER_DISCHARGE_ON_AC)) {
rv = charger_discharge_on_ac(discharge_on_ac);
if (rv != EC_SUCCESS)
if (rv != EC_SUCCESS) {
CPRINTS("%s: Returning due to failure of charger_discharge_on_ac() rv=%d", __func__, rv);
return rv;
}
}

/* Commit all atomically */
Expand Down Expand Up @@ -946,7 +952,8 @@ sustain_switch_mode(enum ec_charge_control_mode mode)
* We come here only if the soc is already above the
* upper limit at the time the sustainer started.
*/
new_mode = CHARGE_CONTROL_DISCHARGE;
//new_mode = CHARGE_CONTROL_DISCHARGE;
new_mode = CHARGE_CONTROL_IDLE;
} else if (sustain_soc.upper == soc) {
/*
* We've been charging and finally reached the upper.
Expand All @@ -972,7 +979,8 @@ sustain_switch_mode(enum ec_charge_control_mode mode)
* This can happen only if sustainer is restarted with
* decreased upper limit. Let's discharge to the upper.
*/
new_mode = CHARGE_CONTROL_DISCHARGE;
//new_mode = CHARGE_CONTROL_DISCHARGE;
new_mode = CHARGE_CONTROL_IDLE;
break;
case CHARGE_CONTROL_DISCHARGE:
/* Discharging actively. */
Expand Down Expand Up @@ -1015,9 +1023,10 @@ static void sustain_battery_soc(void)
return;

rv = set_chg_ctrl_mode(new_mode);
CPRINTS("%s: %s control mode to %s", __func__,
CPRINTS("%s: %s control mode to %s, rv=%d", __func__,
rv == EC_SUCCESS ? "Switched" : "Failed to switch",
mode_text[new_mode]);
mode_text[new_mode],
rv);
}

static void current_limit_battery_soc(void)
Expand Down Expand Up @@ -1279,7 +1288,11 @@ static void process_ac_change(const int chgnum)
prev_ac = curr.ac;
} else {
/* Some things are only meaningful on AC */
set_chg_ctrl_mode(CHARGE_CONTROL_NORMAL);
int rv = set_chg_ctrl_mode(CHARGE_CONTROL_NORMAL);
CPRINTS("%s: %s control mode to %s, rv=%d", __func__,
rv == EC_SUCCESS ? "Switched" : "Failed to switch",
mode_text[CHARGE_CONTROL_NORMAL],
rv);
battery_seems_dead = 0;
prev_ac = curr.ac;

Expand Down Expand Up @@ -2156,13 +2169,13 @@ charge_command_charge_control(struct host_cmd_handler_args *args)
* components are updated to v3.
*/
if (sustain_soc.lower < sustain_soc.upper)
sustain_soc.flags =
EC_CHARGE_CONTROL_FLAG_NO_IDLE;
sustain_soc.flags = 0;
//EC_CHARGE_CONTROL_FLAG_NO_IDLE;
} else {
sustain_soc.flags = p->flags;
}
} else {
battery_sustainer_disable();
//battery_sustainer_disable();
}
} else if (p->cmd == EC_CHARGE_CONTROL_CMD_GET) {
r->mode = get_chg_ctrl_mode();
Expand All @@ -2177,6 +2190,10 @@ charge_command_charge_control(struct host_cmd_handler_args *args)
}

rv = set_chg_ctrl_mode(p->mode);
CPRINTS("%s: %s control mode to %s, rv=%d", __func__,
rv == EC_SUCCESS ? "Switched" : "Failed to switch",
mode_text[p->mode],
rv);
if (rv != EC_SUCCESS)
return EC_RES_ERROR;

Expand Down Expand Up @@ -2421,6 +2438,10 @@ static int command_chgstate(int argc, const char **argv)
return EC_ERROR_PARAM2;
rv = set_chg_ctrl_mode(val ? CHARGE_CONTROL_IDLE :
CHARGE_CONTROL_NORMAL);
CPRINTS("%s: %s control mode to %s, rv=%d", __func__,
rv == EC_SUCCESS ? "Switched" : "Failed to switch",
mode_text[val ? CHARGE_CONTROL_IDLE : CHARGE_CONTROL_NORMAL],
rv);
if (rv)
return rv;
} else if (!strcasecmp(argv[1], "discharge")) {
Expand All @@ -2430,6 +2451,10 @@ static int command_chgstate(int argc, const char **argv)
return EC_ERROR_PARAM2;
rv = set_chg_ctrl_mode(val ? CHARGE_CONTROL_DISCHARGE :
CHARGE_CONTROL_NORMAL);
CPRINTS("%s: %s control mode to %s, rv=%d", __func__,
rv == EC_SUCCESS ? "Switched" : "Failed to switch",
mode_text[val ? CHARGE_CONTROL_DISCHARGE : CHARGE_CONTROL_NORMAL],
rv);
if (rv)
return rv;
} else if (IS_ENABLED(CONFIG_CHARGE_DEBUG) &&
Expand Down
36 changes: 36 additions & 0 deletions common/console_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "uart.h"
#include "usb_console.h"
#include "util.h"
#include "host_command.h"

#ifdef CONFIG_CONSOLE_CHANNEL
/* Default to all channels active */
Expand Down Expand Up @@ -203,4 +204,39 @@ static int command_ch(int argc, const char **argv)
DECLARE_SAFE_CONSOLE_COMMAND(chan, command_ch,
"[ save | restore | <mask> | <name> ]",
"Save, restore, get or set console channel mask");

static enum ec_status host_command_chan(struct host_cmd_handler_args *args)
{
struct ec_response_chan_info *r = args->response;
struct ec_params_chan_set const *set = args->params;
if (r && args->params_size == 0) {
r->version = 1;
r->chan_debug_value = channel_mask;
int index = 0;
for (int i = 0; i < CC_CHANNEL_COUNT; i++) {
for (int n = 0; n < strnlen(channel_names[i], 32); n++) {
r->names[index] = channel_names[i][n];
index++;
if (index >= (sizeof(r->names) - 2)) {
break;
}
}
r->names[index] = 0;
index++;
if (index >= (sizeof(r->names) - 1)) {
break;
}
}
args->response_size = sizeof(*r);
return EC_RES_SUCCESS;
} else if (args->params_size > 0) {
channel_mask = set->chan_debug_value;
return EC_RES_SUCCESS;
}
return EC_RES_INVALID_PARAM;
}

DECLARE_HOST_COMMAND(EC_CMD_CHAN, host_command_chan,
EC_VER_MASK(0));

#endif /* CONFIG_CONSOLE_CHANNEL */
67 changes: 52 additions & 15 deletions common/port80.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "task.h"
#include "timer.h"
#include "util.h"
#include "watchdog.h"

#define CPRINTF(format, args...) cprintf(CC_PORT80, format, ##args)

Expand All @@ -24,7 +25,14 @@ typedef uint32_t port80_code_t;
#else
typedef uint16_t port80_code_t;
#endif
static port80_code_t history[CONFIG_PORT80_HISTORY_LEN];
struct port80_s {
port80_code_t port80_code;
//uint16_t counter;
//uint8_t source;
//uint8_t pad1;
};

static struct port80_s history[CONFIG_PORT80_HISTORY_LEN];
static int writes; /* Number of port 80 writes so far */
static uint16_t last_boot; /* Last code from previous boot */
static int scroll;
Expand All @@ -43,9 +51,9 @@ DECLARE_DEFERRED(port80_dump_buffer);
static int ddr_initialized_fail;
static int has_port_80_data;

int port_80_last(void)
uint32_t port_80_last(void)
{
return (uint16_t)history[(writes-1) % ARRAY_SIZE(history)];
return (uint32_t)history[(writes-1) % ARRAY_SIZE(history)].port80_code;
}

int amd_ddr_initialized_check(void)
Expand All @@ -59,14 +67,31 @@ DECLARE_DEFERRED(port_80_read_customized);
void port_80_read_customized(int index)
{
if (has_port_80_data) {
CPRINTF("PORT80: %04X\n", (history[(writes-1) % ARRAY_SIZE(history)] & 0xFFFF));
CPRINTF("PORT80: %08x:%08x\n",
writes - 1,
history[(writes-1) % ARRAY_SIZE(history)].port80_code);
//CPRINTF("PORT80: %04X:%02X:%08X\n",
// history[(writes-1) % ARRAY_SIZE(history)].counter,
// history[(writes-1) % ARRAY_SIZE(history)].source,
// history[(writes-1) % ARRAY_SIZE(history)].port80_code);
has_port_80_data = 0;
}
}
#endif
static int port_80_debug_counter1 = 0;
static int port_80_debug_counter2 = 0;

void port_80_write(int data)
void port_80_write(uint8_t source, uint32_t data)
{
port_80_debug_counter1++;
port_80_debug_counter2++;
if (port_80_debug_counter1 != 1) {
CPRINTF("port_80_write re-entry detected counter1=%d\n", port_80_debug_counter1);
}
if (port_80_debug_counter2 == 0x1000) {
CPRINTF("port_80_write trace detected counter2=%d\n", port_80_debug_counter2);
}

#ifndef CONFIG_CUSTOMIZED_DESIGN
char ts_str[PRINTF_TIMESTAMP_BUF_SIZE];

Expand Down Expand Up @@ -107,7 +132,7 @@ void port_80_write(int data)
/* Save current port80 code if system is resetting */
if (data == PORT_80_EVENT_RESET && writes) {
port80_code_t prev =
history[(writes - 1) % ARRAY_SIZE(history)];
history[(writes - 1) % ARRAY_SIZE(history)].port80_code;

/*
* last_boot only reports 8-bit codes.
Expand All @@ -117,16 +142,19 @@ void port_80_write(int data)
last_boot = prev;
}

history[writes % ARRAY_SIZE(history)] = data;
history[writes % ARRAY_SIZE(history)].port80_code = data;
//history[writes % ARRAY_SIZE(history)].counter = (uint16_t) writes & 0xffff;
//history[writes % ARRAY_SIZE(history)].source = source;
writes++;
port_80_debug_counter1--;
}

static void port80_dump_buffer(void)
{
int printed = 0;
int i;
int head, tail;
int last_e = 0;
uint32_t last_e = 0;

/*
* Print the port 80 writes so far, clipped to the length of our
Expand All @@ -142,9 +170,12 @@ static void port80_dump_buffer(void)
else
tail = 0;

ccprintf("writes: 0x%x\n", writes);
ccputs("Port 80 writes:");
for (i = tail; i < head; i++) {
int e = history[i % ARRAY_SIZE(history)];
uint32_t e = history[i % ARRAY_SIZE(history)].port80_code;
//uint16_t counter = history[i % ARRAY_SIZE(history)].counter;
//uint16_t source = history[i % ARRAY_SIZE(history)].source;
switch (e) {
case PORT_80_EVENT_RESUME:
ccprintf("\n(S3->S0)");
Expand All @@ -155,11 +186,15 @@ static void port80_dump_buffer(void)
printed = 0;
break;
default:
if (!(printed++ % 20)) {
if (!(printed % 0x80)) {
watchdog_reload();
}
if (!(printed++ % 0x08)) {
ccputs("\n ");
cflush();
}
ccprintf(" %02x", e);
ccprintf(" %08x:%08x", i, e);
//ccprintf(" %04x:%02x:%08x", counter, source, e);
last_e = e;
}
}
Expand Down Expand Up @@ -236,12 +271,12 @@ static enum ec_status port80_command_read(struct host_cmd_handler_args *args)
return EC_RES_INVALID_PARAM;

for (i = 0; i < entries; i++) {
uint16_t e =
history[(i + offset) % ARRAY_SIZE(history)];
uint32_t e =
history[(i + offset) % ARRAY_SIZE(history)].port80_code;
rsp->data.codes[i] = e;
}

args->response_size = entries * sizeof(uint16_t);
args->response_size = entries * sizeof(uint32_t);
return EC_RES_SUCCESS;
}

Expand All @@ -250,9 +285,11 @@ static enum ec_status port80_command_read(struct host_cmd_handler_args *args)
DECLARE_HOST_COMMAND(EC_CMD_PORT80_READ, port80_command_read,
EC_VER_MASK(0) | EC_VER_MASK(1));

#define PORT80_FROM_LOG_RESUME 2

static void port80_log_resume(void)
{
/* Store port 80 event so we know where resume happened */
port_80_write(PORT_80_EVENT_RESUME);
port_80_write(PORT80_FROM_LOG_RESUME, PORT_80_EVENT_RESUME);
}
DECLARE_HOOK(HOOK_CHIPSET_RESUME, port80_log_resume, HOOK_PRIO_DEFAULT);
1 change: 1 addition & 0 deletions driver/battery/smart.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ void battery_get_params(struct batt_params *batt)
* will be preserved.
*/
memcpy(&batt_new, batt, sizeof(*batt));
// This clears all the BAD flags.
batt_new.flags &= ~BATT_FLAG_VOLATILE;

if (sb_read(SB_TEMPERATURE, &batt_new.temperature) &&
Expand Down
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3678,7 +3678,7 @@
#undef CONFIG_POLLING_UART

/* Define length of history buffer for port80 messages. */
#define CONFIG_PORT80_HISTORY_LEN 128
#define CONFIG_PORT80_HISTORY_LEN 4096

/*
* Enable/Disable printing of port80 messages in interrupt context. By default,
Expand Down
1 change: 1 addition & 0 deletions include/ec_cmd_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ _CROS_EC_CV_F_P(EC_CMD_SWITCH_ENABLE_WIRELESS, 0, switch_enable_wireless,
switch_enable_wireless_v0);
_CROS_EC_C1_F_PF_RF(EC_CMD_SWITCH_ENABLE_WIRELESS, switch_enable_wireless);
_CROS_EC_C0_F_RF(EC_CMD_SYSINFO, sysinfo);
_CROS_EC_C0_F_RF(EC_CMD_CHAN, chan);
_CROS_EC_C0_F_PF_RF(EC_CMD_TEMP_SENSOR_GET_INFO, temp_sensor_get_info);
_CROS_EC_C0_F_PF_RF(EC_CMD_TEST_PROTOCOL, test_protocol);
_CROS_EC_C0_F(EC_CMD_THERMAL_AUTO_FAN_CTRL, thermal_auto_fan_ctrl);
Expand Down
Loading