Commit 569be443 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

i2c-stub: Use a single array for byte and word operations

This mimics the behavior of actual SMBus chips better.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Cc: Mark M. Hoffman <mhoffman@lightlink.com>
parent b3af547e
...@@ -35,9 +35,6 @@ int chip_addr[10]: ...@@ -35,9 +35,6 @@ int chip_addr[10]:
CAVEATS: CAVEATS:
There are independent arrays for byte/data and word/data commands. Depending
on if/how a target driver mixes them, you'll need to be careful.
If your target driver polls some byte or word waiting for it to change, the If your target driver polls some byte or word waiting for it to change, the
stub could lock it up. Use i2cset to unlock it. stub could lock it up. Use i2cset to unlock it.
......
/* /*
i2c-stub.c - Part of lm_sensors, Linux kernel modules for hardware i2c-stub.c - I2C/SMBus chip emulator
monitoring
Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com> Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -37,8 +37,8 @@ MODULE_PARM_DESC(chip_addr, ...@@ -37,8 +37,8 @@ MODULE_PARM_DESC(chip_addr,
struct stub_chip { struct stub_chip {
u8 pointer; u8 pointer;
u8 bytes[256]; u16 words[256]; /* Byte operations use the LSB as per SMBus
u16 words[256]; specification */
}; };
static struct stub_chip *stub_chips; static struct stub_chip *stub_chips;
...@@ -75,7 +75,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, ...@@ -75,7 +75,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
"wrote 0x%02x.\n", "wrote 0x%02x.\n",
addr, command); addr, command);
} else { } else {
data->byte = chip->bytes[chip->pointer++]; data->byte = chip->words[chip->pointer++] & 0xff;
dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, " dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, "
"read 0x%02x.\n", "read 0x%02x.\n",
addr, data->byte); addr, data->byte);
...@@ -86,12 +86,13 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, ...@@ -86,12 +86,13 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
case I2C_SMBUS_BYTE_DATA: case I2C_SMBUS_BYTE_DATA:
if (read_write == I2C_SMBUS_WRITE) { if (read_write == I2C_SMBUS_WRITE) {
chip->bytes[command] = data->byte; chip->words[command] &= 0xff00;
chip->words[command] |= data->byte;
dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, "
"wrote 0x%02x at 0x%02x.\n", "wrote 0x%02x at 0x%02x.\n",
addr, data->byte, command); addr, data->byte, command);
} else { } else {
data->byte = chip->bytes[command]; data->byte = chip->words[command] & 0xff;
dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, "
"read 0x%02x at 0x%02x.\n", "read 0x%02x at 0x%02x.\n",
addr, data->byte, command); addr, data->byte, command);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment