diff options
Diffstat (limited to 'common/i2c_trace.c')
-rw-r--r-- | common/i2c_trace.c | 68 |
1 files changed, 27 insertions, 41 deletions
diff --git a/common/i2c_trace.c b/common/i2c_trace.c index af65d85210..c7207698b7 100644 --- a/common/i2c_trace.c +++ b/common/i2c_trace.c @@ -1,4 +1,4 @@ -/* Copyright 2019 The Chromium OS Authors. All rights reserved. +/* Copyright 2019 The ChromiumOS Authors * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ @@ -11,8 +11,8 @@ #include "util.h" #define CPUTS(outstr) cputs(CC_I2C, outstr) -#define CPRINTS(format, args...) cprints(CC_I2C, format, ## args) -#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args) +#define CPRINTS(format, args...) cprints(CC_I2C, format, ##args) +#define CPRINTF(format, args...) cprintf(CC_I2C, format, ##args) struct i2c_trace_range { bool enabled; @@ -23,18 +23,17 @@ struct i2c_trace_range { static struct i2c_trace_range trace_entries[8]; -void i2c_trace_notify(int port, uint16_t addr_flags, - const uint8_t *out_data, size_t out_size, - const uint8_t *in_data, size_t in_size, int ret) +void i2c_trace_notify(int port, uint16_t addr_flags, const uint8_t *out_data, + size_t out_size, const uint8_t *in_data, size_t in_size, + int ret) { size_t i; uint16_t addr = I2C_STRIP_FLAGS(addr_flags); for (i = 0; i < ARRAY_SIZE(trace_entries); i++) - if (trace_entries[i].enabled - && trace_entries[i].port == port - && trace_entries[i].addr_lo <= addr - && trace_entries[i].addr_hi >= addr) + if (trace_entries[i].enabled && trace_entries[i].port == port && + trace_entries[i].addr_lo <= addr && + trace_entries[i].addr_hi >= addr) goto trace_enabled; return; @@ -66,19 +65,16 @@ static int command_i2ctrace_list(void) for (i = 0; i < ARRAY_SIZE(trace_entries); i++) { if (trace_entries[i].enabled) { i2c_port = get_i2c_port(trace_entries[i].port); - ccprintf("%-2zd %d %-8s 0x%X", - i, - trace_entries[i].port, + ccprintf("%-2zd %d %-8s 0x%X", i, trace_entries[i].port, #ifndef CONFIG_ZEPHYR i2c_port->name, #else "", #endif /* CONFIG_ZEPHYR */ trace_entries[i].addr_lo); - if (trace_entries[i].addr_hi - != trace_entries[i].addr_lo) - ccprintf(" to 0x%X", - trace_entries[i].addr_hi); + if (trace_entries[i].addr_hi != + trace_entries[i].addr_lo) + ccprintf(" to 0x%X", trace_entries[i].addr_hi); ccprintf("\n"); } } @@ -95,8 +91,7 @@ static int command_i2ctrace_disable(size_t id) return EC_SUCCESS; } -static int command_i2ctrace_enable(int port, int addr_lo, - int addr_hi) +static int command_i2ctrace_enable(int port, int addr_lo, int addr_hi) { struct i2c_trace_range *t; struct i2c_trace_range *new_entry = NULL; @@ -111,41 +106,34 @@ static int command_i2ctrace_enable(int port, int addr_lo, * Scan thru existing entries to see if there is one we can * extend instead of making a new entry */ - for (t = trace_entries; - t < trace_entries + ARRAY_SIZE(trace_entries); + for (t = trace_entries; t < trace_entries + ARRAY_SIZE(trace_entries); t++) { if (t->enabled && t->port == port) { /* Subset of existing range, do nothing */ - if (t->addr_lo <= addr_lo && - t->addr_hi >= addr_hi) + if (t->addr_lo <= addr_lo && t->addr_hi >= addr_hi) return EC_SUCCESS; /* Extends exising range on both directions, replace */ - if (t->addr_lo >= addr_lo && - t->addr_hi <= addr_hi) { + if (t->addr_lo >= addr_lo && t->addr_hi <= addr_hi) { t->enabled = 0; - return command_i2ctrace_enable( - port, addr_lo, addr_hi); + return command_i2ctrace_enable(port, addr_lo, + addr_hi); } /* Extends existing range below */ if (t->addr_lo - 1 <= addr_hi && t->addr_hi >= addr_hi) { t->enabled = 0; - return command_i2ctrace_enable( - port, - addr_lo, - t->addr_hi); + return command_i2ctrace_enable(port, addr_lo, + t->addr_hi); } /* Extends existing range above */ if (t->addr_lo <= addr_lo && t->addr_hi + 1 >= addr_lo) { t->enabled = 0; - return command_i2ctrace_enable( - port, - t->addr_lo, - addr_hi); + return command_i2ctrace_enable(port, t->addr_lo, + addr_hi); } } else if (!t->enabled && !new_entry) { new_entry = t; @@ -165,8 +153,7 @@ static int command_i2ctrace_enable(int port, int addr_lo, return EC_ERROR_MEMORY_ALLOCATION; } - -static int command_i2ctrace(int argc, char **argv) +static int command_i2ctrace(int argc, const char **argv) { int id_or_port; int address_low; @@ -204,14 +191,13 @@ static int command_i2ctrace(int argc, char **argv) return EC_ERROR_PARAM_COUNT; } - return command_i2ctrace_enable( - id_or_port, address_low, address_high); + return command_i2ctrace_enable(id_or_port, address_low, + address_high); } return EC_ERROR_PARAM1; } -DECLARE_CONSOLE_COMMAND(i2ctrace, - command_i2ctrace, +DECLARE_CONSOLE_COMMAND(i2ctrace, command_i2ctrace, "[list | disable <id> | enable <port> <address> | " "enable <port> <address-low> <address-high>]", "Trace I2C transactions"); |