forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the i2c-stub driver to drivers/i2c, to match the Kconfig entry. This is less confusing that way. I also fixed all checkpatch warnings and errors. Signed-off-by: Jean Delvare <[email protected]> Cc: Peter Huewe <[email protected]>
- Loading branch information
Jean Delvare
authored and
Jean Delvare
committed
Oct 28, 2012
1 parent
e657e07
commit 31d178b
Showing
3 changed files
with
33 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
i2c-stub.c - I2C/SMBus chip emulator | ||
Copyright (c) 2004 Mark M. Hoffman <[email protected]> | ||
Copyright (C) 2007 Jean Delvare <[email protected]> | ||
Copyright (C) 2007, 2012 Jean Delvare <[email protected]> | ||
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 | ||
|
@@ -51,8 +51,8 @@ struct stub_chip { | |
static struct stub_chip *stub_chips; | ||
|
||
/* Return negative errno on error. */ | ||
static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, | ||
char read_write, u8 command, int size, union i2c_smbus_data * data) | ||
static s32 stub_xfer(struct i2c_adapter *adap, u16 addr, unsigned short flags, | ||
char read_write, u8 command, int size, union i2c_smbus_data *data) | ||
{ | ||
s32 ret; | ||
int i, len; | ||
|
@@ -78,14 +78,14 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, | |
case I2C_SMBUS_BYTE: | ||
if (read_write == I2C_SMBUS_WRITE) { | ||
chip->pointer = command; | ||
dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, " | ||
"wrote 0x%02x.\n", | ||
addr, command); | ||
dev_dbg(&adap->dev, | ||
"smbus byte - addr 0x%02x, wrote 0x%02x.\n", | ||
addr, command); | ||
} else { | ||
data->byte = chip->words[chip->pointer++] & 0xff; | ||
dev_dbg(&adap->dev, "smbus byte - addr 0x%02x, " | ||
"read 0x%02x.\n", | ||
addr, data->byte); | ||
dev_dbg(&adap->dev, | ||
"smbus byte - addr 0x%02x, read 0x%02x.\n", | ||
addr, data->byte); | ||
} | ||
|
||
ret = 0; | ||
|
@@ -95,14 +95,14 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, | |
if (read_write == I2C_SMBUS_WRITE) { | ||
chip->words[command] &= 0xff00; | ||
chip->words[command] |= data->byte; | ||
dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " | ||
"wrote 0x%02x at 0x%02x.\n", | ||
addr, data->byte, command); | ||
dev_dbg(&adap->dev, | ||
"smbus byte data - addr 0x%02x, wrote 0x%02x at 0x%02x.\n", | ||
addr, data->byte, command); | ||
} else { | ||
data->byte = chip->words[command] & 0xff; | ||
dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, " | ||
"read 0x%02x at 0x%02x.\n", | ||
addr, data->byte, command); | ||
dev_dbg(&adap->dev, | ||
"smbus byte data - addr 0x%02x, read 0x%02x at 0x%02x.\n", | ||
addr, data->byte, command); | ||
} | ||
chip->pointer = command + 1; | ||
|
||
|
@@ -112,14 +112,14 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, | |
case I2C_SMBUS_WORD_DATA: | ||
if (read_write == I2C_SMBUS_WRITE) { | ||
chip->words[command] = data->word; | ||
dev_dbg(&adap->dev, "smbus word data - addr 0x%02x, " | ||
"wrote 0x%04x at 0x%02x.\n", | ||
addr, data->word, command); | ||
dev_dbg(&adap->dev, | ||
"smbus word data - addr 0x%02x, wrote 0x%04x at 0x%02x.\n", | ||
addr, data->word, command); | ||
} else { | ||
data->word = chip->words[command]; | ||
dev_dbg(&adap->dev, "smbus word data - addr 0x%02x, " | ||
"read 0x%04x at 0x%02x.\n", | ||
addr, data->word, command); | ||
dev_dbg(&adap->dev, | ||
"smbus word data - addr 0x%02x, read 0x%04x at 0x%02x.\n", | ||
addr, data->word, command); | ||
} | ||
|
||
ret = 0; | ||
|
@@ -132,17 +132,17 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, | |
chip->words[command + i] &= 0xff00; | ||
chip->words[command + i] |= data->block[1 + i]; | ||
} | ||
dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, " | ||
"wrote %d bytes at 0x%02x.\n", | ||
addr, len, command); | ||
dev_dbg(&adap->dev, | ||
"i2c block data - addr 0x%02x, wrote %d bytes at 0x%02x.\n", | ||
addr, len, command); | ||
} else { | ||
for (i = 0; i < len; i++) { | ||
data->block[1 + i] = | ||
chip->words[command + i] & 0xff; | ||
} | ||
dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, " | ||
"read %d bytes at 0x%02x.\n", | ||
addr, len, command); | ||
dev_dbg(&adap->dev, | ||
"i2c block data - addr 0x%02x, read %d bytes at 0x%02x.\n", | ||
addr, len, command); | ||
} | ||
|
||
ret = 0; | ||
|
@@ -179,25 +179,24 @@ static int __init i2c_stub_init(void) | |
int i, ret; | ||
|
||
if (!chip_addr[0]) { | ||
printk(KERN_ERR "i2c-stub: Please specify a chip address\n"); | ||
pr_err("i2c-stub: Please specify a chip address\n"); | ||
return -ENODEV; | ||
} | ||
|
||
for (i = 0; i < MAX_CHIPS && chip_addr[i]; i++) { | ||
if (chip_addr[i] < 0x03 || chip_addr[i] > 0x77) { | ||
printk(KERN_ERR "i2c-stub: Invalid chip address " | ||
"0x%02x\n", chip_addr[i]); | ||
pr_err("i2c-stub: Invalid chip address 0x%02x\n", | ||
chip_addr[i]); | ||
return -EINVAL; | ||
} | ||
|
||
printk(KERN_INFO "i2c-stub: Virtual chip at 0x%02x\n", | ||
chip_addr[i]); | ||
pr_info("i2c-stub: Virtual chip at 0x%02x\n", chip_addr[i]); | ||
} | ||
|
||
/* Allocate memory for all chips at once */ | ||
stub_chips = kzalloc(i * sizeof(struct stub_chip), GFP_KERNEL); | ||
if (!stub_chips) { | ||
printk(KERN_ERR "i2c-stub: Out of memory\n"); | ||
pr_err("i2c-stub: Out of memory\n"); | ||
return -ENOMEM; | ||
} | ||
|
||
|
@@ -219,4 +218,3 @@ MODULE_LICENSE("GPL"); | |
|
||
module_init(i2c_stub_init); | ||
module_exit(i2c_stub_exit); | ||
|