From 680ed1f632897b3ec493156863b05115f28102ef Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Tue, 25 Dec 2018 04:43:21 -0600 Subject: ec/chromeec: fix LPC read/write for MEC devices Commit 8cf8aa2 [ec/google/chromeec: Use common MEC interface] changed the return mechanism for the checksum on reads/writes for MEC devices, but incorrectly handled the passed-in csum parameter by not dereferencing. This led to the returned csum value always being zero, which causes all EC commands with non- NULL data_in to fail with a checksum error. Fix this by storing the returned checksum in a temp variable, and only assigning to csum when the pointer isn't NULL; Test: build/boot google/chell, verify EC hello command succeeds, keyboard backlight turned on at boot. Change-Id: I7122c3fdc5a19f87f12975ee448728cf29948436 Signed-off-by: Matt DeVillier Reviewed-on: https://review.coreboot.org/c/30444 Tested-by: build bot (Jenkins) Reviewed-by: Arthur Heymans --- src/ec/google/chromeec/ec_lpc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/ec/google') diff --git a/src/ec/google/chromeec/ec_lpc.c b/src/ec/google/chromeec/ec_lpc.c index c8665c9e82..61005d3e3b 100644 --- a/src/ec/google/chromeec/ec_lpc.c +++ b/src/ec/google/chromeec/ec_lpc.c @@ -41,9 +41,11 @@ static void read_bytes(u16 port, unsigned int length, u8 *dest, u8 *csum) #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC_MEC) /* Access desired range though EMI interface */ if (port >= MEC_EMI_RANGE_START && port <= MEC_EMI_RANGE_END) { - csum += mec_io_bytes(MEC_IO_READ, MEC_EMI_BASE, + u8 ret = mec_io_bytes(MEC_IO_READ, MEC_EMI_BASE, port - MEC_EMI_RANGE_START, dest, length); + if (csum) + *csum += ret; return; } #endif @@ -78,9 +80,11 @@ static void write_bytes(u16 port, unsigned int length, u8 *msg, u8 *csum) #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC_MEC) /* Access desired range though EMI interface */ if (port >= MEC_EMI_RANGE_START && port <= MEC_EMI_RANGE_END) { - csum += mec_io_bytes(MEC_IO_WRITE, MEC_EMI_BASE, + u8 ret = mec_io_bytes(MEC_IO_WRITE, MEC_EMI_BASE, port - MEC_EMI_RANGE_START, msg, length); + if (csum) + *csum += ret; return; } #endif -- cgit v1.2.3