Commit 569be443e3c1329fc6725988004f5d8a32fe3be5
Committed by
Jean Delvare
1 parent
b3af547e19
Exists in
master
and in
7 other branches
i2c-stub: Use a single array for byte and word operations
This mimics the behavior of actual SMBus chips better. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Mark M. Hoffman <mhoffman@lightlink.com>
Showing 2 changed files with 8 additions and 10 deletions Side-by-side Diff
Documentation/i2c/i2c-stub
... | ... | @@ -35,9 +35,6 @@ |
35 | 35 | |
36 | 36 | CAVEATS: |
37 | 37 | |
38 | -There are independent arrays for byte/data and word/data commands. Depending | |
39 | -on if/how a target driver mixes them, you'll need to be careful. | |
40 | - | |
41 | 38 | If your target driver polls some byte or word waiting for it to change, the |
42 | 39 | stub could lock it up. Use i2cset to unlock it. |
43 | 40 |
drivers/i2c/busses/i2c-stub.c
1 | 1 | /* |
2 | - i2c-stub.c - Part of lm_sensors, Linux kernel modules for hardware | |
3 | - monitoring | |
2 | + i2c-stub.c - I2C/SMBus chip emulator | |
4 | 3 | |
5 | 4 | Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com> |
5 | + Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> | |
6 | 6 | |
7 | 7 | This program is free software; you can redistribute it and/or modify |
8 | 8 | it under the terms of the GNU General Public License as published by |
... | ... | @@ -37,8 +37,8 @@ |
37 | 37 | |
38 | 38 | struct stub_chip { |
39 | 39 | u8 pointer; |
40 | - u8 bytes[256]; | |
41 | - u16 words[256]; | |
40 | + u16 words[256]; /* Byte operations use the LSB as per SMBus | |
41 | + specification */ | |
42 | 42 | }; |
43 | 43 | |
44 | 44 | static struct stub_chip *stub_chips; |
... | ... | @@ -75,7 +75,7 @@ |
75 | 75 | "wrote 0x%02x.\n", |
76 | 76 | addr, command); |
77 | 77 | } else { |
78 | - data->byte = chip->bytes[chip->pointer++]; | |
78 | + data->byte = chip->words[chip->pointer++] & 0xff; | |
79 | 79 | dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, " |
80 | 80 | "read 0x%02x.\n", |
81 | 81 | addr, data->byte); |
82 | 82 | |
... | ... | @@ -86,12 +86,13 @@ |
86 | 86 | |
87 | 87 | case I2C_SMBUS_BYTE_DATA: |
88 | 88 | if (read_write == I2C_SMBUS_WRITE) { |
89 | - chip->bytes[command] = data->byte; | |
89 | + chip->words[command] &= 0xff00; | |
90 | + chip->words[command] |= data->byte; | |
90 | 91 | dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " |
91 | 92 | "wrote 0x%02x at 0x%02x.\n", |
92 | 93 | addr, data->byte, command); |
93 | 94 | } else { |
94 | - data->byte = chip->bytes[command]; | |
95 | + data->byte = chip->words[command] & 0xff; | |
95 | 96 | dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " |
96 | 97 | "read 0x%02x at 0x%02x.\n", |
97 | 98 | addr, data->byte, command); |