All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org, sensors@stimpy.netroedge.com
Subject: Re: [PATCH] I2C update for 2.6.9
Date: Tue, 19 Oct 2004 17:18:23 -0700	[thread overview]
Message-ID: <10982315032767@kroah.com> (raw)
In-Reply-To: <10982315034183@kroah.com>

ChangeSet 1.1832.73.3, 2004/09/08 12:34:34-07:00, mhoffman@lightlink.com

[PATCH] I2C/SMBus stub for driver testing

* Greg KH <greg@kroah.com> [2004-08-24 16:44:32 -0700]:
> > > Why not?  It looks useful to me.  Care to send me a patch adding
> > > this to the main kernel tree?

* Mark M. Hoffman <mhoffman@lightlink.com> [2004-08-25 10:25:02 -0400]:
> Later today, sure.

Well here it is, one day later because I really didn't want to do this
with printk.  I spent some time looking around and relayfs seems like
a good fit.  Do you think relayfs will ever get merged?  Meanwhile...

* * * * *

This patch, applied to 2.6.9-rc1, adds an I2C/SMBus test stub that is useful
for developing sensors drivers.

Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>


 Documentation/i2c/i2c-stub    |   33 +++++++++++
 drivers/i2c/busses/Kconfig    |   13 ++++
 drivers/i2c/busses/Makefile   |    1 
 drivers/i2c/busses/i2c-stub.c |  125 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 172 insertions(+)


diff -Nru a/Documentation/i2c/i2c-stub b/Documentation/i2c/i2c-stub
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/Documentation/i2c/i2c-stub	2004-10-19 16:55:52 -07:00
@@ -0,0 +1,33 @@
+MODULE: i2c-stub
+
+DESCRIPTION:
+
+This module is a very simple fake I2C/SMBus driver.  It implements three
+types of SMBus commands: write quick, (r/w) byte data, and (r/w) word data.
+
+No hardware is needed nor associated with this module.  It will accept write
+quick commands to all addresses; it will respond to the other commands (also
+to all addresses) by reading from or writing to an array in memory.  It will
+also spam the kernel logs for every command it handles.
+
+The typical use-case is like this:
+	1. load this module
+	2. use i2cset (from lm_sensors project) to pre-load some data
+	3. load the target sensors chip driver module
+	4. observe its behavior in the kernel log
+
+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
+stub could lock it up.  Use i2cset to unlock it.
+
+If the hardware for your driver has banked registers (e.g. Winbond sensors
+chips) this module will not work well - although it could be extended to
+support that pretty easily.
+
+If you spam it hard enough, printk can be lossy.  This module really wants
+something like relayfs.
+
diff -Nru a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
--- a/drivers/i2c/busses/Kconfig	2004-10-19 16:55:52 -07:00
+++ b/drivers/i2c/busses/Kconfig	2004-10-19 16:55:52 -07:00
@@ -376,6 +376,19 @@
 	  This driver can also be built as a module.  If so, the module
 	  will be called i2c-sis96x.
 
+config I2C_STUB
+	tristate "I2C/SMBus Test Stub"
+	depends on I2C && EXPERIMENTAL && 'm'
+	default 'n'
+	help
+	  This module may be useful to developers of SMBus client drivers,
+	  especially for certain kinds of sensor chips.
+
+	  If you do build this module, be sure to read the notes and warnings
+	  in Documentation/i2c/i2c-stub.
+
+	  If you don't know what to do here, definitely say N.
+
 config I2C_VIA
 	tristate "VIA 82C586B"
 	depends on I2C && PCI && EXPERIMENTAL
diff -Nru a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
--- a/drivers/i2c/busses/Makefile	2004-10-19 16:55:52 -07:00
+++ b/drivers/i2c/busses/Makefile	2004-10-19 16:55:52 -07:00
@@ -30,6 +30,7 @@
 obj-$(CONFIG_I2C_SIS5595)	+= i2c-sis5595.o
 obj-$(CONFIG_I2C_SIS630)	+= i2c-sis630.o
 obj-$(CONFIG_I2C_SIS96X)	+= i2c-sis96x.o
+obj-$(CONFIG_I2C_STUB)		+= i2c-stub.o
 obj-$(CONFIG_I2C_VIA)		+= i2c-via.o
 obj-$(CONFIG_I2C_VIAPRO)	+= i2c-viapro.o
 obj-$(CONFIG_I2C_VOODOO3)	+= i2c-voodoo3.o
diff -Nru a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
--- /dev/null	Wed Dec 31 16:00:00 196900
+++ b/drivers/i2c/busses/i2c-stub.c	2004-10-19 16:55:52 -07:00
@@ -0,0 +1,125 @@
+/*
+    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);
+


  reply	other threads:[~2004-10-20  0:42 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-20  0:16 [BK PATCH] I2C update for 2.6.9 Greg KH
2005-05-19  6:25 ` Greg KH
2004-10-20  0:18 ` [PATCH] " Greg KH
2004-10-20  0:18   ` Greg KH
2004-10-20  0:18     ` Greg KH [this message]
2004-10-20  0:18       ` Greg KH
2004-10-20  0:18         ` Greg KH
2004-10-20  0:18           ` Greg KH
2004-10-20  0:18             ` Greg KH
2004-10-20  0:18               ` Greg KH
2004-10-20  0:18                 ` Greg KH
2005-05-19  6:25                   ` Greg KH
2004-10-20  0:18                   ` Greg KH
2004-10-20  0:18                     ` Greg KH
2004-10-20  0:18                       ` Greg KH
2004-10-20  0:18                         ` Greg KH
2004-10-20  0:18                           ` Greg KH
2004-10-20  0:18                             ` Greg KH
2004-10-20  0:18                               ` Greg KH
2004-10-20  0:18                                 ` Greg KH
2004-10-20  0:18                                   ` Greg KH
2004-10-20  0:18                                     ` Greg KH
2004-10-20  0:18                                       ` Greg KH
2004-10-20  0:18                                         ` Greg KH
2004-10-20  0:18                                           ` Greg KH
2004-10-20  0:18                                             ` Greg KH
2004-10-20  0:18                                               ` Greg KH
2004-10-20  0:18                                                 ` Greg KH
2004-10-20  0:18                                                   ` Greg KH
2004-10-20  0:18                                                     ` Greg KH
2005-05-19  6:25                                                       ` Greg KH
2004-10-20  0:18                                                       ` Greg KH
2004-10-20  0:18                                                         ` Greg KH
2004-10-20  0:18                                                           ` Greg KH
2004-10-20  0:18                                                             ` Greg KH
2004-10-20  0:18                                                               ` Greg KH
2004-10-20  5:21                                                   ` Eugene Surovegin
2005-05-19  6:25                                                     ` Eugene Surovegin
2004-10-20  6:26                                                     ` [PATCH] fix recently introduced race in IBM PPC4xx I2C driver Eugene Surovegin
2005-05-19  6:25                                                       ` Eugene Surovegin
2004-10-22 19:55                                                       ` Greg KH
2005-05-19  6:25                                                         ` Greg KH
2004-10-25 18:29                                               ` [PATCH] I2C update for 2.6.9 Bill Davidsen
2005-05-19  6:25                                                 ` Bill Davidsen
2004-10-25 20:54                                                 ` Jean Delvare
2005-05-19  6:25                                                   ` Jean Delvare
2004-10-26 21:03                                                   ` Bill Davidsen
2005-05-19  6:25                                                     ` Bill Davidsen
2004-10-20 15:57 ` [BK PATCH] " Jean Delvare
2005-05-19  6:25   ` Jean Delvare
2004-10-20 16:40   ` Lee Revell
2005-05-19  6:25     ` Lee Revell
2004-10-22 21:34 ` Jean Delvare
2005-05-19  6:25   ` Jean Delvare

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10982315032767@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sensors@stimpy.netroedge.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.