aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-01-27 12:14:45 -0500
committerJean Delvare <khali@hyperion.delvare>2008-01-27 12:14:45 -0500
commit569be443e3c1329fc6725988004f5d8a32fe3be5 (patch)
tree694ce140e127777cdc1bc66d2359233dd1d2f307 /drivers/i2c/busses
parentb3af547e197fa3ca648d148dd8d36befe989e5a0 (diff)
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>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/i2c-stub.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 84df29da1ddc..c2a9f8c94f5e 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -1,8 +1,8 @@
1/* 1/*
2 i2c-stub.c - Part of lm_sensors, Linux kernel modules for hardware 2 i2c-stub.c - I2C/SMBus chip emulator
3 monitoring
4 3
5 Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com> 4 Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
5 Copyright (C) 2007 Jean Delvare <khali@linux-fr.org>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
@@ -37,8 +37,8 @@ MODULE_PARM_DESC(chip_addr,
37 37
38struct stub_chip { 38struct stub_chip {
39 u8 pointer; 39 u8 pointer;
40 u8 bytes[256]; 40 u16 words[256]; /* Byte operations use the LSB as per SMBus
41 u16 words[256]; 41 specification */
42}; 42};
43 43
44static struct stub_chip *stub_chips; 44static struct stub_chip *stub_chips;
@@ -75,7 +75,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
75 "wrote 0x%02x.\n", 75 "wrote 0x%02x.\n",
76 addr, command); 76 addr, command);
77 } else { 77 } else {
78 data->byte = chip->bytes[chip->pointer++]; 78 data->byte = chip->words[chip->pointer++] & 0xff;
79 dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, " 79 dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, "
80 "read 0x%02x.\n", 80 "read 0x%02x.\n",
81 addr, data->byte); 81 addr, data->byte);
@@ -86,12 +86,13 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
86 86
87 case I2C_SMBUS_BYTE_DATA: 87 case I2C_SMBUS_BYTE_DATA:
88 if (read_write == I2C_SMBUS_WRITE) { 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 dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " 91 dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, "
91 "wrote 0x%02x at 0x%02x.\n", 92 "wrote 0x%02x at 0x%02x.\n",
92 addr, data->byte, command); 93 addr, data->byte, command);
93 } else { 94 } else {
94 data->byte = chip->bytes[command]; 95 data->byte = chip->words[command] & 0xff;
95 dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " 96 dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, "
96 "read 0x%02x at 0x%02x.\n", 97 "read 0x%02x at 0x%02x.\n",
97 addr, data->byte, command); 98 addr, data->byte, command);