* stub for driver testing (was Re: lm87 ported to Linux 2.6)
@ 2005-05-19 6:25 Mark M. Hoffman
2005-05-19 6:25 ` Greg KH
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Mark M. Hoffman @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Hi Jean:
(CCs trimmed on purpose)
* Jean Delvare <khali@linux-fr.org> [2004-08-23 21:52:06 +0200]:
> This first patch is untested beyond compilation, as I don't own a LM87
> myself. This is why I rely on you for testing. The more testers there
Attached is a quick hack that makes this (testing a driver for h/w you
don't own) a little easier. It would be even more useful if it wrote to
a file instead of spamming all those printks - I'll do that if people
want it.
You'll probably need to pass force_foo parameters to the chip driver to
get it to attach. Also be warned: if the driver has any polling loops
which wait for some byte/data to change, this bus stub could lock it up.
Stuff like this probably isn't appropriate for kernel.org (Greg?)
Maybe it belongs in a new directory in the sensors CVS?
Regards,
--
Mark M. Hoffman
mhoffman@lightlink.com
-------------- next part --------------
# Handy out-of-kernel Makefile by Gerd Knorr / LWN.net
#
ifneq ($(KERNELRELEASE),)
obj-m := i2c-stub.o
else
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
endif
-------------- next part --------------
/*
i2c-stub.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (c) 2004 Mark M. Hoffman <mhoffman@lightlink.com>
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define DEBUG 1
#include <linux/config.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/i2c.h>
static u8 stub_bytes[256];
static u16 stub_words[256];
/* Return -1 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)
{
s32 ret;
switch (size) {
case I2C_SMBUS_QUICK:
dev_dbg(&adap->dev, "smbus quick - addr 0x%02x\n", addr);
ret = 0;
break;
case I2C_SMBUS_BYTE_DATA:
if (read_write = I2C_SMBUS_WRITE) {
stub_bytes[command] = data->byte;
dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, "
"wrote 0x%02x at 0x%02x.\n",
addr, data->byte, command);
} else {
data->byte = stub_bytes[command];
dev_dbg(&adap->dev, "smbus byte data - addr 0x%02x, "
"read 0x%02x at 0x%02x.\n",
addr, data->byte, command);
}
ret = 0;
break;
case I2C_SMBUS_WORD_DATA:
if (read_write = I2C_SMBUS_WRITE) {
stub_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);
} else {
data->word = stub_words[command];
dev_dbg(&adap->dev, "smbus word data - addr 0x%02x, "
"read 0x%04x at 0x%02x.\n",
addr, data->word, command);
}
ret = 0;
break;
default:
dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n");
ret = -1;
break;
} /* switch (size) */
return ret;
}
static u32 stub_func(struct i2c_adapter *adapter)
{
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE_DATA |
I2C_FUNC_SMBUS_WORD_DATA;
}
static struct i2c_algorithm smbus_algorithm = {
.name = "Non-I2C SMBus adapter",
.id = I2C_ALGO_SMBUS,
.functionality = stub_func,
.smbus_xfer = stub_xfer,
};
static struct i2c_adapter stub_adapter = {
.owner = THIS_MODULE,
.class = I2C_CLASS_HWMON,
.algo = &smbus_algorithm,
.name = "SMBus stub driver",
};
static int __init i2c_stub_init(void)
{
printk(KERN_INFO "i2c-stub loaded\n");
return i2c_add_adapter(&stub_adapter);
}
static void __exit i2c_stub_exit(void)
{
i2c_del_adapter(&stub_adapter);
}
MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
MODULE_DESCRIPTION("I2C stub driver");
MODULE_LICENSE("GPL");
module_init(i2c_stub_init);
module_exit(i2c_stub_exit);
^ permalink raw reply [flat|nested] 5+ messages in thread* stub for driver testing (was Re: lm87 ported to Linux 2.6)
2005-05-19 6:25 stub for driver testing (was Re: lm87 ported to Linux 2.6) Mark M. Hoffman
@ 2005-05-19 6:25 ` Greg KH
2005-05-19 6:25 ` Jean Delvare
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
On Mon, Aug 23, 2004 at 11:42:44PM -0400, Mark M. Hoffman wrote:
> Hi Jean:
>
> (CCs trimmed on purpose)
>
> * Jean Delvare <khali@linux-fr.org> [2004-08-23 21:52:06 +0200]:
> > This first patch is untested beyond compilation, as I don't own a LM87
> > myself. This is why I rely on you for testing. The more testers there
>
> Attached is a quick hack that makes this (testing a driver for h/w you
> don't own) a little easier. It would be even more useful if it wrote to
> a file instead of spamming all those printks - I'll do that if people
> want it.
>
> You'll probably need to pass force_foo parameters to the chip driver to
> get it to attach. Also be warned: if the driver has any polling loops
> which wait for some byte/data to change, this bus stub could lock it up.
>
> Stuff like this probably isn't appropriate for kernel.org (Greg?)
Why not? It looks useful to me. Care to send me a patch adding this to
the main kernel tree?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread* stub for driver testing (was Re: lm87 ported to Linux 2.6)
2005-05-19 6:25 stub for driver testing (was Re: lm87 ported to Linux 2.6) Mark M. Hoffman
2005-05-19 6:25 ` Greg KH
@ 2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Mark M. Hoffman
2005-05-19 6:25 ` Jean Delvare
3 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
> I'll make it impossible to build this driver into the kernel... it's
> only useful as a module anyway.
I can't see any technical reason why it couldn't be used into the kernel. But
I don't see why one would want to do that either. So all in all I agree with
you ;)
> Would it be appropriate to mark it experimental as well?
Yes, but not because it's for testing purposes. For that, a clear help text
stating, among other details, "If unsure, say N.", is what you want. The
experimental tag refers to the code stability, not the driver goal.
> > I think that this driver would be even more useful if it was possible to
> > "load" a register map into it. (...)
>
> Um, i2cset works fine for this.
Ah, correct. For some reason (maybe I'm somewhat stupid, or it was too early
in the morning) I missed that. One more reason to go on providing a way to get
rid of the 5 second delay in i2cset like I did recently for isaset and isadump.
> BTW: note how there are independent arrays for data/byte and
> data/word commands. Depending on if/how a chip driver mixes them,
> you'll need to be careful.
Yeah, I noticed that. The LM87 doesn't use words so I guess it should cause no
trouble to me - this time at least.
Thanks.
--
Jean "Khali" Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* stub for driver testing (was Re: lm87 ported to Linux 2.6)
2005-05-19 6:25 stub for driver testing (was Re: lm87 ported to Linux 2.6) Mark M. Hoffman
2005-05-19 6:25 ` Greg KH
2005-05-19 6:25 ` Jean Delvare
@ 2005-05-19 6:25 ` Mark M. Hoffman
2005-05-19 6:25 ` Jean Delvare
3 siblings, 0 replies; 5+ messages in thread
From: Mark M. Hoffman @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
Jean, Greg:
* Jean Delvare <khali@linux-fr.org> [2004-08-25 10:17:18 +0100]:
> > > Stuff like this probably isn't appropriate for kernel.org (Greg?)
> >
> > Why not? It looks useful to me. Care to send me a patch adding
> > this to the main kernel tree?
Later today, sure.
> I agree it sounds very useful for testing, and the driver isn't that big. Just
> make in clear in the help text that the regular guy doesn't need this.
I'll make it impossible to build this driver into the kernel... it's only
useful as a module anyway. Would it be appropriate to mark it experimental
as well?
> I think that this driver would be even more useful if it was possible to
> "load" a register map into it. I guess it should be possible to have a sysfs
> interface, much like we have for the eeprom driver, but writable. That way we
> could test almost anything in the driver, including the
> detection/identification step, and possibly even simulate temperature changes
> and the like. Testing would look like:
> 1* Load i2c-stub.
> 2* Write (binary) register map.
> 3* Load chip driver.
> 4* Test the driver and possibly change registers values on the fly (dd or some
> perl should do).
>
> An alternative interface file could be one to which we'd write "address value"
> pairs. I don't know which is easier to implement or more convenient. Thoughts?
Um, i2cset works fine for this.
BTW: note how there are independent arrays for data/byte and data/word commands.
Depending on if/how a chip driver mixes them, you'll need to be careful.
Regards,
--
Mark M. Hoffman
mhoffman@lightlink.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* stub for driver testing (was Re: lm87 ported to Linux 2.6)
2005-05-19 6:25 stub for driver testing (was Re: lm87 ported to Linux 2.6) Mark M. Hoffman
` (2 preceding siblings ...)
2005-05-19 6:25 ` Mark M. Hoffman
@ 2005-05-19 6:25 ` Jean Delvare
3 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2005-05-19 6:25 UTC (permalink / raw)
To: lm-sensors
> > Stuff like this probably isn't appropriate for kernel.org (Greg?)
>
> Why not? It looks useful to me. Care to send me a patch adding
> this to the main kernel tree?
I agree it sounds very useful for testing, and the driver isn't that big. Just
make in clear in the help text that the regular guy doesn't need this.
I think that this driver would be even more useful if it was possible to
"load" a register map into it. I guess it should be possible to have a sysfs
interface, much like we have for the eeprom driver, but writable. That way we
could test almost anything in the driver, including the
detection/identification step, and possibly even simulate temperature changes
and the like. Testing would look like:
1* Load i2c-stub.
2* Write (binary) register map.
3* Load chip driver.
4* Test the driver and possibly change registers values on the fly (dd or some
perl should do).
An alternative interface file could be one to which we'd write "address value"
pairs. I don't know which is easier to implement or more convenient. Thoughts?
Note that I've not been able to test the driver yet, will do as time permits.
Thanks.
--
Jean "Khali" Delvare
http://khali.linux-fr.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2005-05-19 6:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-19 6:25 stub for driver testing (was Re: lm87 ported to Linux 2.6) Mark M. Hoffman
2005-05-19 6:25 ` Greg KH
2005-05-19 6:25 ` Jean Delvare
2005-05-19 6:25 ` Mark M. Hoffman
2005-05-19 6:25 ` Jean Delvare
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.