summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTing Shen <phoenixshen@google.com>2022-09-14 18:07:22 +0800
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-20 04:54:18 +0000
commit82f49ef34c349d4b6ddd71d75019fa2636f4537f (patch)
tree568202948b2d5213abe9372b77ffaa4a57901e71
parent4320ea6d5964354611aafa8f8343246e4a297100 (diff)
downloadchrome-ec-82f49ef34c349d4b6ddd71d75019fa2636f4537f.tar.gz
zephyr: emul_rt9490: fix incorrect multibyte IO implementation
When performing multibyte IO, the `reg` parameter means the first byte of this IO operation, it won't increase during consecutive read/write operations. The actual byte to access is offsetted by the `bytes` parameter. BUG=none TEST=pass all tests BRANCH=none Signed-off-by: Ting Shen <phoenixshen@google.com> Change-Id: I15c046fcfb8dbcc05f260bd929da32b7d86a3c90 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3896554 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Commit-Queue: Ting Shen <phoenixshen@chromium.org> Tested-by: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Eric Yilun Lin <yllin@google.com>
-rw-r--r--zephyr/emul/emul_rt9490.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/zephyr/emul/emul_rt9490.c b/zephyr/emul/emul_rt9490.c
index 5c0e7bf8b9..dbc2500e90 100644
--- a/zephyr/emul/emul_rt9490.c
+++ b/zephyr/emul/emul_rt9490.c
@@ -48,11 +48,12 @@ static int rt9490_emul_read(const struct emul *emul, int reg, uint8_t *val,
{
struct rt9490_data *data = emul->data;
uint8_t *regs = data->regs;
+ int pos = reg + bytes;
- if (!IN_RANGE(reg, 0, RT9490_REG_MAX)) {
+ if (!IN_RANGE(pos, 0, RT9490_REG_MAX)) {
return -1;
}
- *val = regs[reg];
+ *val = regs[pos];
return 0;
}
@@ -62,11 +63,12 @@ static int rt9490_emul_write(const struct emul *emul, int reg, uint8_t val,
{
struct rt9490_data *data = emul->data;
uint8_t *regs = data->regs;
+ int pos = reg + bytes - 1;
- if (!IN_RANGE(reg, 0, RT9490_REG_MAX) || !IN_RANGE(val, 0, UINT8_MAX)) {
+ if (!IN_RANGE(pos, 0, RT9490_REG_MAX) || !IN_RANGE(val, 0, UINT8_MAX)) {
return -1;
}
- regs[reg] = val;
+ regs[pos] = val;
return 0;
}