diff --git a/kernel/Module.mk b/kernel/Module.mk index bc0bf97d..174372c3 100644 --- a/kernel/Module.mk +++ b/kernel/Module.mk @@ -23,7 +23,7 @@ MODULE_DIR := src # Regrettably, even 'simply expanded variables' will not put their currently # defined value verbatim into the command-list of rules... SRCTARGETS := $(MODULE_DIR)/smbus.o $(MODULE_DIR)/piix4.o $(MODULE_DIR)/isa.o \ - $(MODULE_DIR)/lm78.o + $(MODULE_DIR)/lm78.o $(MODULE_DIR)/i2c-bus.o # Include all dependency files INCLUDEFILES += $(SRCTARGETS:.o=.d) diff --git a/kernel/busses/i2c-isa.c b/kernel/busses/i2c-isa.c index 8ea0b52c..061acb45 100644 --- a/kernel/busses/i2c-isa.c +++ b/kernel/busses/i2c-isa.c @@ -75,7 +75,7 @@ static int isa_initialized; int isa_master_xfer (struct isa_adapter *adap, struct i2c_msg msgs[], int num) { - printk("isa_master_xfer called for adapter `%s' " + printk("isa.o: isa_master_xfer called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -84,7 +84,7 @@ int isa_master_xfer (struct isa_adapter *adap, struct i2c_msg msgs[], /* Algorithm slave_send call-back implementation. Can't do that... */ int isa_slave_send (struct isa_adapter *adap, char *data, int len) { - printk("isa_slave_send called for adapter `%s' " + printk("isa.o: isa_slave_send called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -93,7 +93,7 @@ int isa_slave_send (struct isa_adapter *adap, char *data, int len) /* Algorithm slave_recv call-back implementation. Can't do that... */ int isa_slave_recv (struct isa_adapter *adap, char *data, int len) { - printk("isa_slave_recv called for adapter `%s' " + printk("isa.o: isa_slave_recv called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -131,7 +131,7 @@ int isa_init(void) #endif isa_initialized = 0; if ((res = isa_add_algorithm(&isa_algorithm))) { - printk("isa.o: Algorithm registration failed, module isa.o not inserted\n"); + printk("isa.o: Algorithm registration failed, module not inserted.\n"); isa_cleanup(); return res; } @@ -141,12 +141,12 @@ int isa_init(void) isa_adapter.algo = &isa_algorithm; if ((res = isa_add_adapter(&isa_adapter))) { printk("isa.o: Adapter registration failed, " - "module isa.o is not inserted\n"); + "module isa.o is not inserted\n."); isa_cleanup(); return res; } isa_initialized++; - printk("isa.o: ISA bus access for i2c modules initialized\n"); + printk("isa.o: ISA bus access for i2c modules initialized.\n"); return 0; } @@ -156,7 +156,7 @@ int isa_cleanup(void) if (isa_initialized >= 2) { if ((res = isa_del_adapter(&isa_adapter))) { - printk("isa.o: isa_del_adapter failed, module not removed\n"); + printk("isa.o: Adapter deregistration failed, module not removed.\n"); return res; } else isa_initialized--; @@ -164,7 +164,7 @@ int isa_cleanup(void) if (isa_initialized >= 1) { if ((res = isa_del_algorithm(&isa_algorithm))) { - printk("isa.o: isa_del_algorithm failed, module not removed\n"); + printk("isa.o: Algorithm deregistration failed, module not removed.\n"); return res; } else isa_initialized--; diff --git a/kernel/busses/i2c-piix4.c b/kernel/busses/i2c-piix4.c index 52bcd0b4..a5932ead 100644 --- a/kernel/busses/i2c-piix4.c +++ b/kernel/busses/i2c-piix4.c @@ -65,7 +65,7 @@ int piix4_init(void) #endif piix4_initialized = 0; if ((res = piix4_setup())) { - printk("piix4.o: PIIX4 not detected, module not inserted\n"); + printk("piix4.o: PIIX4 not detected, module not inserted.\n"); piix4_cleanup(); return res; } @@ -75,7 +75,7 @@ int piix4_init(void) piix4_adapter.algo = &smbus_algorithm; piix4_adapter.smbus_access = &piix4_access; if ((res = smbus_add_adapter(&piix4_adapter))) { - printk("piix4.o: smbus_add_adapter failed, module not inserted\n"); + printk("piix4.o: Adapter registration failed, module not inserted.\n"); piix4_cleanup(); return res; } diff --git a/kernel/compat.h b/kernel/compat.h new file mode 100644 index 00000000..c6b5049e --- /dev/null +++ b/kernel/compat.h @@ -0,0 +1,40 @@ +/* + compar.h - A Linux module for reading sensor data. + Copyright (c) 1998 Frodo Looijaard + + 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. +*/ + +#ifndef SENSORS_COMPAT_H +#define SENSORS_COMPAT_H + +/* This useful macro is not defined in the 2.0 kernels */ + +#include +#ifndef KERNEL_VERSION +#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c)) +#endif + +#ifdef MODULE +#include +#ifndef MODULE_AUTHOR +#define MODULE_AUTHOR(whatever) +#endif +#ifndef MODULE_DESCRIPTION +#define MODULE_DESCRIPTION(whatever) +#endif +#endif /* def MODULE */ + +#endif /* SENSORS_COMPAT_H */ diff --git a/kernel/include/compat.h b/kernel/include/compat.h new file mode 100644 index 00000000..c6b5049e --- /dev/null +++ b/kernel/include/compat.h @@ -0,0 +1,40 @@ +/* + compar.h - A Linux module for reading sensor data. + Copyright (c) 1998 Frodo Looijaard + + 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. +*/ + +#ifndef SENSORS_COMPAT_H +#define SENSORS_COMPAT_H + +/* This useful macro is not defined in the 2.0 kernels */ + +#include +#ifndef KERNEL_VERSION +#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c)) +#endif + +#ifdef MODULE +#include +#ifndef MODULE_AUTHOR +#define MODULE_AUTHOR(whatever) +#endif +#ifndef MODULE_DESCRIPTION +#define MODULE_DESCRIPTION(whatever) +#endif +#endif /* def MODULE */ + +#endif /* SENSORS_COMPAT_H */ diff --git a/kernel/smbus.c b/kernel/smbus.c index 8494caf1..ea22d809 100644 --- a/kernel/smbus.c +++ b/kernel/smbus.c @@ -114,7 +114,7 @@ s32 smbus_access_i2c(struct i2c_adapter * adapter, u8 addr, char read_write, int smbus_master_xfer (struct smbus_adapter *adap, struct i2c_msg msgs[], int num) { - printk("smbus_master_xfer called for adapter `%s' " + printk("smbus.o: smbus_master_xfer called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -123,7 +123,7 @@ int smbus_master_xfer (struct smbus_adapter *adap, struct i2c_msg msgs[], /* Algorithm slave_send call-back implementation. Can't do that... */ int smbus_slave_send (struct smbus_adapter *adap, char *data, int len) { - printk("smbus_slave_send called for adapter `%s' " + printk("smbus.o: smbus_slave_send called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -132,7 +132,7 @@ int smbus_slave_send (struct smbus_adapter *adap, char *data, int len) /* Algorithm slave_recv call-back implementation. Can't do that... */ int smbus_slave_recv (struct smbus_adapter *adap, char *data, int len) { - printk("smbus_slave_recv called for adapter `%s' " + printk("smbus.o: smbus_slave_recv called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -163,7 +163,7 @@ int smbus_init(void) int res; printk("smbus.o version %s (%s)\n",LM_VERSION,LM_DATE); if ((res = smbus_add_algorithm(&smbus_algorithm))) - printk("Module smbus.o not inserted!\n"); + printk("smbus.o: Algorithm registration failed, module not inserted.\n"); else printk("smbus.o initialized\n"); return res; @@ -173,7 +173,7 @@ int smbus_cleanup(void) { int res; if ((res = smbus_del_algorithm(&smbus_algorithm))) - printk("Module smbus.o could not be removed cleanly!\n"); + printk("smbus.o: Algorithm deregistration failed, module not removed\n"); return res; } diff --git a/src/Module.mk b/src/Module.mk index bc0bf97d..174372c3 100644 --- a/src/Module.mk +++ b/src/Module.mk @@ -23,7 +23,7 @@ MODULE_DIR := src # Regrettably, even 'simply expanded variables' will not put their currently # defined value verbatim into the command-list of rules... SRCTARGETS := $(MODULE_DIR)/smbus.o $(MODULE_DIR)/piix4.o $(MODULE_DIR)/isa.o \ - $(MODULE_DIR)/lm78.o + $(MODULE_DIR)/lm78.o $(MODULE_DIR)/i2c-bus.o # Include all dependency files INCLUDEFILES += $(SRCTARGETS:.o=.d) diff --git a/src/compat.h b/src/compat.h new file mode 100644 index 00000000..c6b5049e --- /dev/null +++ b/src/compat.h @@ -0,0 +1,40 @@ +/* + compar.h - A Linux module for reading sensor data. + Copyright (c) 1998 Frodo Looijaard + + 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. +*/ + +#ifndef SENSORS_COMPAT_H +#define SENSORS_COMPAT_H + +/* This useful macro is not defined in the 2.0 kernels */ + +#include +#ifndef KERNEL_VERSION +#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c)) +#endif + +#ifdef MODULE +#include +#ifndef MODULE_AUTHOR +#define MODULE_AUTHOR(whatever) +#endif +#ifndef MODULE_DESCRIPTION +#define MODULE_DESCRIPTION(whatever) +#endif +#endif /* def MODULE */ + +#endif /* SENSORS_COMPAT_H */ diff --git a/src/i2c-bus.c b/src/i2c-bus.c new file mode 100644 index 00000000..8499b151 --- /dev/null +++ b/src/i2c-bus.c @@ -0,0 +1,178 @@ +/* + i2c-bus.c - A Linux module for reading sensor data. + Copyright (c) 1998 Frodo Looijaard + + 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. +*/ + +#include +#include + +#include "version.h" +#include "compat.h" + +#ifdef MODULE +extern int init_module(void); +extern int cleanup_module(void); +#endif /* MODULE */o + +static int i2cbus_init(void); +static int i2cbus_cleanup(void); + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)) + +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, + int *eof , void *private); + +static struct proc_dir_entry *proc_bus_i2c; + +#else /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)) */ + +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, + int unused); + +static struct proc_dir_entry proc_bus_dir = + { + /* low_ino */ 0, /* Set by proc_register_dynamic */ + /* namelen */ 3, + /* name */ "bus", + /* mode */ S_IRUGO | S_IXUGO | S_IFDIR, + /* nlink */ 1, /* Corrected by proc_register[_dynamic] */ + /* uid */ 0, + /* gid */ 0, + /* size */ 0, + /* ops */ &proc_dir_inode_operations, + }; + +static struct proc_dir_entry proc_bus_i2c_dir = + { + /* low_ino */ 0, /* Set by proc_register_dynamic */ + /* namelen */ 3, + /* name */ "i2c", + /* mode */ S_IRUGO | S_IFREG, + /* nlink */ 1, + /* uid */ 0, + /* gid */ 0, + /* size */ 0, + /* ops */ NULL, + /* get_info */ &read_bus_i2c + }; + +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)) */ + +static int i2cbus_initialized; + +int i2cbus_init(void) +{ + int res; + + printk("i2c-bus.o version %s (%s)\n",LM_VERSION,LM_DATE); + i2cbus_initialized = 0; + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)) + if (! proc_bus) { + printk("i2c-bus.o: /proc/bus/ does not exist, module not inserted.\n"); + i2cbus_cleanup(); + return -ENOENT; + } + proc_bus_i2c = create_proc_entry("i2c",0,proc_bus); + if (proc_bus_i2c) + proc_bus_i2c->read_proc = &read_bus_i2c; + else { + printk("i2c-bus.o: Could not create /proc/bus/i2c, module not inserted.\n"); + i2cbus_cleanup(); + return -ENOENT; + } + i2cbus_initialized += 2; +#else + /* In Linux 2.0.x, there is no /proc/bus! But I hope no other module + introduced it, or we are fucked. */ + if ((res = proc_register_dynamic(&proc_root, &proc_bus_dir))) { + printk("i2c-bus.o: Could not create /proc/bus/, module not inserted.\n"); + i2cbus_cleanup(); + return res; + } + i2cbus_initialized ++; + if ((res = proc_register_dynamic(&proc_bus_dir, &proc_bus_i2c_dir))) { + printk("i2c-bus.o: Could not create /proc/bus/i2c, module not inserted.\n"); + i2cbus_cleanup(); + return res; + } + i2cbus_initialized ++; +#endif + return 0; +} + +int i2cbus_cleanup(void) +{ + int res; + + if (i2cbus_initialized >= 1) { +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)) + if ((res = remove_proc_entry("i2c",proc_bus))) { + printk("i2c-bus.o: could not delete /proc/bus/i2c, module not removed."); + return res; + } + i2cbus_initialized -= 2; +#else + if (i2cbus_initialized >= 2) { + if ((res = proc_unregister(&proc_bus_dir,proc_bus_i2c_dir.low_ino))) { + printk("i2c-bus.o: could not delete /proc/bus/i2c, " + "module not removed."); + return res; + } + i2cbus_initialized --; + } + if ((res = proc_unregister(&proc_root,proc_bus_dir.low_ino))) { + printk("i2c-bus.o: could not delete /proc/bus/, " + "module not removed."); + return res; + } + i2cbus_initialized --; +#endif + } + return 0; +} + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)) +int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, + void *private) +#else +int read_bus_i2c(char *buf, char **start, off_t offset, int len, int unused) +#endif +{ + len = 0; + len += sprintf(buf,"A very nice test, indeed\n"); + return len; +} + + +#ifdef MODULE + +MODULE_AUTHOR("Frodo Looijaard "); +MODULE_DESCRIPTION("I2C /proc/bus entries driver"); + +int init_module(void) +{ + return i2cbus_init(); +} + +int cleanup_module(void) +{ + return i2cbus_cleanup(); +} + +#endif /* MODULE */ + diff --git a/src/isa.c b/src/isa.c index 8ea0b52c..061acb45 100644 --- a/src/isa.c +++ b/src/isa.c @@ -75,7 +75,7 @@ static int isa_initialized; int isa_master_xfer (struct isa_adapter *adap, struct i2c_msg msgs[], int num) { - printk("isa_master_xfer called for adapter `%s' " + printk("isa.o: isa_master_xfer called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -84,7 +84,7 @@ int isa_master_xfer (struct isa_adapter *adap, struct i2c_msg msgs[], /* Algorithm slave_send call-back implementation. Can't do that... */ int isa_slave_send (struct isa_adapter *adap, char *data, int len) { - printk("isa_slave_send called for adapter `%s' " + printk("isa.o: isa_slave_send called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -93,7 +93,7 @@ int isa_slave_send (struct isa_adapter *adap, char *data, int len) /* Algorithm slave_recv call-back implementation. Can't do that... */ int isa_slave_recv (struct isa_adapter *adap, char *data, int len) { - printk("isa_slave_recv called for adapter `%s' " + printk("isa.o: isa_slave_recv called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -131,7 +131,7 @@ int isa_init(void) #endif isa_initialized = 0; if ((res = isa_add_algorithm(&isa_algorithm))) { - printk("isa.o: Algorithm registration failed, module isa.o not inserted\n"); + printk("isa.o: Algorithm registration failed, module not inserted.\n"); isa_cleanup(); return res; } @@ -141,12 +141,12 @@ int isa_init(void) isa_adapter.algo = &isa_algorithm; if ((res = isa_add_adapter(&isa_adapter))) { printk("isa.o: Adapter registration failed, " - "module isa.o is not inserted\n"); + "module isa.o is not inserted\n."); isa_cleanup(); return res; } isa_initialized++; - printk("isa.o: ISA bus access for i2c modules initialized\n"); + printk("isa.o: ISA bus access for i2c modules initialized.\n"); return 0; } @@ -156,7 +156,7 @@ int isa_cleanup(void) if (isa_initialized >= 2) { if ((res = isa_del_adapter(&isa_adapter))) { - printk("isa.o: isa_del_adapter failed, module not removed\n"); + printk("isa.o: Adapter deregistration failed, module not removed.\n"); return res; } else isa_initialized--; @@ -164,7 +164,7 @@ int isa_cleanup(void) if (isa_initialized >= 1) { if ((res = isa_del_algorithm(&isa_algorithm))) { - printk("isa.o: isa_del_algorithm failed, module not removed\n"); + printk("isa.o: Algorithm deregistration failed, module not removed.\n"); return res; } else isa_initialized--; diff --git a/src/piix4.c b/src/piix4.c index 52bcd0b4..a5932ead 100644 --- a/src/piix4.c +++ b/src/piix4.c @@ -65,7 +65,7 @@ int piix4_init(void) #endif piix4_initialized = 0; if ((res = piix4_setup())) { - printk("piix4.o: PIIX4 not detected, module not inserted\n"); + printk("piix4.o: PIIX4 not detected, module not inserted.\n"); piix4_cleanup(); return res; } @@ -75,7 +75,7 @@ int piix4_init(void) piix4_adapter.algo = &smbus_algorithm; piix4_adapter.smbus_access = &piix4_access; if ((res = smbus_add_adapter(&piix4_adapter))) { - printk("piix4.o: smbus_add_adapter failed, module not inserted\n"); + printk("piix4.o: Adapter registration failed, module not inserted.\n"); piix4_cleanup(); return res; } diff --git a/src/smbus.c b/src/smbus.c index 8494caf1..ea22d809 100644 --- a/src/smbus.c +++ b/src/smbus.c @@ -114,7 +114,7 @@ s32 smbus_access_i2c(struct i2c_adapter * adapter, u8 addr, char read_write, int smbus_master_xfer (struct smbus_adapter *adap, struct i2c_msg msgs[], int num) { - printk("smbus_master_xfer called for adapter `%s' " + printk("smbus.o: smbus_master_xfer called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -123,7 +123,7 @@ int smbus_master_xfer (struct smbus_adapter *adap, struct i2c_msg msgs[], /* Algorithm slave_send call-back implementation. Can't do that... */ int smbus_slave_send (struct smbus_adapter *adap, char *data, int len) { - printk("smbus_slave_send called for adapter `%s' " + printk("smbus.o: smbus_slave_send called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -132,7 +132,7 @@ int smbus_slave_send (struct smbus_adapter *adap, char *data, int len) /* Algorithm slave_recv call-back implementation. Can't do that... */ int smbus_slave_recv (struct smbus_adapter *adap, char *data, int len) { - printk("smbus_slave_recv called for adapter `%s' " + printk("smbus.o: smbus_slave_recv called for adapter `%s' " "(no i2c level access possible!)\n", adap->name); return 0; @@ -163,7 +163,7 @@ int smbus_init(void) int res; printk("smbus.o version %s (%s)\n",LM_VERSION,LM_DATE); if ((res = smbus_add_algorithm(&smbus_algorithm))) - printk("Module smbus.o not inserted!\n"); + printk("smbus.o: Algorithm registration failed, module not inserted.\n"); else printk("smbus.o initialized\n"); return res; @@ -173,7 +173,7 @@ int smbus_cleanup(void) { int res; if ((res = smbus_del_algorithm(&smbus_algorithm))) - printk("Module smbus.o could not be removed cleanly!\n"); + printk("smbus.o: Algorithm deregistration failed, module not removed\n"); return res; } diff --git a/version.h b/version.h index 0c7e1b29..d0e375fb 100644 --- a/version.h +++ b/version.h @@ -1,2 +1,2 @@ -#define LM_DATE "19981122" -#define LM_VERSION "2.0.0pre1" +#define LM_DATE "19981127" +#define LM_VERSION "2.0.0pre2"