2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-31 06:15:15 +00:00

Start of i2c-bus, a module for displaying i2c bus information in /proc

Nothing much here yet, except some code to create /proc/bus/i2c. Should work
for kernels 2.0 and 2.1 (please test).

Other notable things:
  printk statements in all modules made to have to same 'look'.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@15 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Frodo Looijaard
1998-11-27 00:26:51 +00:00
parent 4d0ef54c3c
commit c26eff1184
13 changed files with 332 additions and 34 deletions

View File

@@ -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)

View File

@@ -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--;

View File

@@ -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;
}

40
kernel/compat.h Normal file
View File

@@ -0,0 +1,40 @@
/*
compar.h - A Linux module for reading sensor data.
Copyright (c) 1998 Frodo Looijaard <frodol@dds.nl>
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 <linux/version.h>
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
#endif
#ifdef MODULE
#include <linux/module.h>
#ifndef MODULE_AUTHOR
#define MODULE_AUTHOR(whatever)
#endif
#ifndef MODULE_DESCRIPTION
#define MODULE_DESCRIPTION(whatever)
#endif
#endif /* def MODULE */
#endif /* SENSORS_COMPAT_H */

40
kernel/include/compat.h Normal file
View File

@@ -0,0 +1,40 @@
/*
compar.h - A Linux module for reading sensor data.
Copyright (c) 1998 Frodo Looijaard <frodol@dds.nl>
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 <linux/version.h>
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
#endif
#ifdef MODULE
#include <linux/module.h>
#ifndef MODULE_AUTHOR
#define MODULE_AUTHOR(whatever)
#endif
#ifndef MODULE_DESCRIPTION
#define MODULE_DESCRIPTION(whatever)
#endif
#endif /* def MODULE */
#endif /* SENSORS_COMPAT_H */

View File

@@ -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;
}

View File

@@ -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)

40
src/compat.h Normal file
View File

@@ -0,0 +1,40 @@
/*
compar.h - A Linux module for reading sensor data.
Copyright (c) 1998 Frodo Looijaard <frodol@dds.nl>
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 <linux/version.h>
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c))
#endif
#ifdef MODULE
#include <linux/module.h>
#ifndef MODULE_AUTHOR
#define MODULE_AUTHOR(whatever)
#endif
#ifndef MODULE_DESCRIPTION
#define MODULE_DESCRIPTION(whatever)
#endif
#endif /* def MODULE */
#endif /* SENSORS_COMPAT_H */

178
src/i2c-bus.c Normal file
View File

@@ -0,0 +1,178 @@
/*
i2c-bus.c - A Linux module for reading sensor data.
Copyright (c) 1998 Frodo Looijaard <frodol@dds.nl>
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 <linux/module.h>
#include <linux/proc_fs.h>
#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 <frodol@dds.nl>");
MODULE_DESCRIPTION("I2C /proc/bus entries driver");
int init_module(void)
{
return i2cbus_init();
}
int cleanup_module(void)
{
return i2cbus_cleanup();
}
#endif /* MODULE */

View File

@@ -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--;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -1,2 +1,2 @@
#define LM_DATE "19981122"
#define LM_VERSION "2.0.0pre1"
#define LM_DATE "19981127"
#define LM_VERSION "2.0.0pre2"