From 0d44674274c1b6d9bd7c3de90312982883a6e3c1 Mon Sep 17 00:00:00 2001 From: Keith Short Date: Fri, 6 Mar 2020 09:50:58 -0700 Subject: i2c: Cleanup I2C tracing output The output of the I2C tracing is hard to parse, especially for reads to I2C registers. This change creates only a single I2C trace for each I2C transfer (instead of 2 entries), and labels the write and read parts of the I2C transaction clearly. Example output (TCPC device during disconnect): i2c: 1:0x20 wr 0x10 rd 0x01 0x00 i2c: 1:0x20 wr 0x10 0x01 0x00 i2c: 1:0x20 wr 0x1A rd 0x1A i2c: 1:0x20 wr 0x1D rd 0x10 i2c: 1:0x20 wr 0x1C rd 0x70 i2c: 1:0x20 wr 0x2F 0x21 i2c: 1:0x20 wr 0x1C 0x70 i2c: 1:0x20 wr 0x2F 0x00 i2c: 1:0x20 wr 0x1C rd 0x70 i2c: 1:0x20 wr 0x1C 0x60 BUG=none BRANCH=none TEST=make buildall TEST=Enable CONFIG_I2C_DEBUG and verify output. Signed-off-by: Keith Short Change-Id: I077196e70ae3abb6c462cf08a3f944b43fdcf82a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2091573 Reviewed-by: Jack Rosenthal Reviewed-by: Jett Rink --- common/i2c_trace.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'common/i2c_trace.c') diff --git a/common/i2c_trace.c b/common/i2c_trace.c index d25f89a00c..6645b9a303 100644 --- a/common/i2c_trace.c +++ b/common/i2c_trace.c @@ -24,14 +24,12 @@ struct i2c_trace_range { static struct i2c_trace_range trace_entries[8]; void i2c_trace_notify(int port, uint16_t slave_addr_flags, - int direction, const uint8_t *data, size_t size) + const uint8_t *out_data, size_t out_size, + const uint8_t *in_data, size_t in_size) { size_t i; uint16_t addr = I2C_GET_ADDR(slave_addr_flags); - if (size == 0) - return; - for (i = 0; i < ARRAY_SIZE(trace_entries); i++) if (trace_entries[i].enabled && trace_entries[i].port == port @@ -41,12 +39,17 @@ void i2c_trace_notify(int port, uint16_t slave_addr_flags, return; trace_enabled: - CPRINTF("i2c: %s %d:0x%X ", - direction ? "read" : "write", - port, - addr); - for (i = 0; i < size; i++) - CPRINTF("%02X ", data[i]); + CPRINTF("i2c: %d:0x%X ", port, addr); + if (out_size) { + CPRINTF("wr "); + for (i = 0; i < out_size; i++) + CPRINTF("0x%02X ", out_data[i]); + } + if (in_size) { + CPRINTF(" rd "); + for (i = 0; i < in_size; i++) + CPRINTF("0x%02X ", in_data[i]); + } CPRINTF("\n"); } -- cgit v1.2.1