From cbf518d36e89b1304aa839e23c64c391373e2493 Mon Sep 17 00:00:00 2001 From: Frodo Looijaard Date: Wed, 2 Dec 1998 17:25:53 +0000 Subject: [PATCH] Fixes to make code compile with 2.1 kernels Everything now compiles cleanly (except for warnings in kernel header files) against 2.1.122. As I do not run 2.1 kernels, loading them could not be tested. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@22 7894878c-1315-0410-8ee3-d5d059ff63e0 --- TODO | 6 ++++- i2c/bit-mb.c | 5 ++-- kernel/busses/i2c-piix4.c | 3 +++ kernel/compat.h | 11 +++----- kernel/i2c-proc.c | 54 +++++++++++++++++---------------------- kernel/include/compat.h | 11 +++----- kernel/smbus.c | 1 + src/compat.h | 11 +++----- src/i2c-proc.c | 54 +++++++++++++++++---------------------- src/piix4.c | 3 +++ src/smbus.c | 1 + 11 files changed, 73 insertions(+), 87 deletions(-) diff --git a/TODO b/TODO index 128896ea..1ef52e6d 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,8 @@ Many, many things. Most notably: -* 2.1 kernel tests; at this moment, only 2.0 compiles have been tried. +* Change the i2c modules to keep the namespace clean (EXPORT_SYMBOL does not + work for us; many static declarations need to be added; better ask Simon + Vogl first) * Make it SMP-safe: there are no spinlocks yet. They are needed at many places, probably (everywhere where global vars are accessed). * Extend sensors.c with a file /proc/sys/dev/sensors/chips, which lists @@ -10,6 +12,8 @@ Many, many things. Most notably: * Write piix4_* in piix4.c * Make lm78.c detect 'double hits', (same chip connected to both SMBus and ISA). +* Better lm78 detection; insmod-time paramters to set addresses (difficult, + because of all i2c busses!). * Check whether some lm78 functionality is chip-generic and can be moved to sensors.c. * Rename i2c-proc.c to i2c-user.c, and extend it with /dev entries; diff --git a/i2c/bit-mb.c b/i2c/bit-mb.c index 661596fb..ae39eaa4 100644 --- a/i2c/bit-mb.c +++ b/i2c/bit-mb.c @@ -27,8 +27,7 @@ #include #include -/* When exactly was the new pci interface introduced? */ -#if LINUX_VERSION_CODE < 0x020100 +#if LINUX_VERSION_CODE < 0x020136 /* 2.1.54 */ #include #endif @@ -128,7 +127,7 @@ static void bit_mb_exit(void) } /* When exactly was the new pci interface introduced? */ -#if LINUX_VERSION_CODE >= 0x020100 +#if LINUX_VERSION_CODE >= 0x020136 /* 2.1.54 */ static u32 find_i2c(void) { diff --git a/kernel/busses/i2c-piix4.c b/kernel/busses/i2c-piix4.c index a5932ead..1716fe8b 100644 --- a/kernel/busses/i2c-piix4.c +++ b/kernel/busses/i2c-piix4.c @@ -17,8 +17,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* Note: New PCI (non-BIOS) interface introduced in 2.1.54! */ + #include #include +#include #include "smbus.h" #include "version.h" diff --git a/kernel/compat.h b/kernel/compat.h index e3adedba..8bae94d8 100644 --- a/kernel/compat.h +++ b/kernel/compat.h @@ -37,18 +37,15 @@ #endif #endif /* def MODULE */ -/* copy_from/to_usr is called memcpy_from/to_fs in 2.0 kernels; perhaps in - some early 2.1 kernels too? */ +/* copy_from/to_usr is called memcpy_from/to_fs in 2.0 kernels + get_user was redefined in 2.1 kernels to use two arguments, and returns + an error code */ #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) #define copy_from_user memcpy_fromfs #define copy_to_user memcpy_tofs -#endif - -/* get_user was redefined in 2.1 kernels to use two arguments, and returns - an error code */ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) #define get_user_data(to,from) ((to) = get_user(from),0) #else +#include #define get_user_data(to,from) get_user(to,from) #endif diff --git a/kernel/i2c-proc.c b/kernel/i2c-proc.c index 1094f3f0..bce69a5b 100644 --- a/kernel/i2c-proc.c +++ b/kernel/i2c-proc.c @@ -40,31 +40,18 @@ static int i2cproc_command(struct i2c_client *client, unsigned int cmd, void *arg); static void i2cproc_inc_use(struct i2c_client *client); static void i2cproc_dec_use(struct i2c_client *client); -static int i2cproc_bus_read(struct inode * inode, struct file * file,char * buf, - int count); - -/* To implement the dynamic /proc/bus/i2c-? files, we need our own - implementation of the read hook */ -static struct file_operations i2cproc_operations = { - NULL, - i2cproc_bus_read, -}; - -static struct inode_operations i2cproc_inode_operations = { - &i2cproc_operations -}; - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) -static int i2proc_bus_read(char *buf, char **start, off_t offset, int len, +static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, + loff_t *ppos); +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof , void *private); -ssize_t array_read(struct file * file, char * buf,size_t count, loff_t *ppos); #else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ -int i2cproc_bus_read(struct inode * inode, struct file * file,char * buf, - int count); +static int i2cproc_bus_read(struct inode * inode, struct file * file, + char * buf, int count); static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int unused); @@ -100,6 +87,18 @@ static struct proc_dir_entry *i2cproc_proc_entries[I2C_ADAP_MAX]; #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ +/* To implement the dynamic /proc/bus/i2c-? files, we need our own + implementation of the read hook */ +static struct file_operations i2cproc_operations = { + NULL, + i2cproc_bus_read, +}; + +static struct inode_operations i2cproc_inode_operations = { + &i2cproc_operations +}; + + /* Used by init/cleanup */ static int i2cproc_initialized; @@ -202,10 +201,7 @@ int i2cproc_cleanup(void) } if (i2cproc_initialized >= 1) { #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) - if ((res = remove_proc_entry("i2c",proc_bus))) { - printk("i2c-proc.o: could not delete /proc/bus/i2c, module not removed."); - return res; - } + remove_proc_entry("i2c",proc_bus); i2cproc_initialized -= 2; #else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ if (i2cproc_initialized >= 2) { @@ -252,7 +248,8 @@ int read_bus_i2c(char *buf, char **start, off_t offset, int len, int unused) /* This function generates the output for /proc/bus/i2c-? */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) -ssize_t i2cproc_read(struct file * file, char * buf,size_t count, loff_t *ppos) +ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, + loff_t *ppos) { struct inode * inode = file->f_dentry->d_inode; #else (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) @@ -290,7 +287,7 @@ int i2cproc_bus_read(struct inode * inode, struct file * file,char * buf, len = len - file->f_pos; if (len < 0) len = 0; - memcpy_tofs(buf,kbuf+file->f_pos,len); + copy_to_user (buf,kbuf+file->f_pos,len); file->f_pos += len; kfree(kbuf); return len; @@ -346,8 +343,7 @@ int i2cproc_attach_adapter(struct i2c_adapter *adapter) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) proc_entry = create_proc_entry(name,0,proc_bus); - if (! proc_entry) - else { + if (! proc_entry) { printk("i2c-proc.o: Could not create /proc/bus/%s\n",name); kfree(client); return -ENOENT; @@ -398,11 +394,7 @@ int i2cproc_detach_client(struct i2c_client *client) if (client->adapter == i2cproc_adapters[i]) { #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) sprintf(name,"i2c-%d",i); - if ((res = remove_proc_entry(name,proc_bus))) { - printk("i2c-proc.o: Deregistration of /proc entry failed, " - "client not detached.\n"); - return res; - } + remove_proc_entry(name,proc_bus); #else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ if ((res = proc_unregister(&proc_bus_dir, i2cproc_proc_entries[i]->low_ino))) { diff --git a/kernel/include/compat.h b/kernel/include/compat.h index e3adedba..8bae94d8 100644 --- a/kernel/include/compat.h +++ b/kernel/include/compat.h @@ -37,18 +37,15 @@ #endif #endif /* def MODULE */ -/* copy_from/to_usr is called memcpy_from/to_fs in 2.0 kernels; perhaps in - some early 2.1 kernels too? */ +/* copy_from/to_usr is called memcpy_from/to_fs in 2.0 kernels + get_user was redefined in 2.1 kernels to use two arguments, and returns + an error code */ #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) #define copy_from_user memcpy_fromfs #define copy_to_user memcpy_tofs -#endif - -/* get_user was redefined in 2.1 kernels to use two arguments, and returns - an error code */ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) #define get_user_data(to,from) ((to) = get_user(from),0) #else +#include #define get_user_data(to,from) get_user(to,from) #endif diff --git a/kernel/smbus.c b/kernel/smbus.c index ea22d809..405104d2 100644 --- a/kernel/smbus.c +++ b/kernel/smbus.c @@ -19,6 +19,7 @@ #include #include +#include #include "i2c.h" #ifdef SPINLOCK diff --git a/src/compat.h b/src/compat.h index e3adedba..8bae94d8 100644 --- a/src/compat.h +++ b/src/compat.h @@ -37,18 +37,15 @@ #endif #endif /* def MODULE */ -/* copy_from/to_usr is called memcpy_from/to_fs in 2.0 kernels; perhaps in - some early 2.1 kernels too? */ +/* copy_from/to_usr is called memcpy_from/to_fs in 2.0 kernels + get_user was redefined in 2.1 kernels to use two arguments, and returns + an error code */ #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) #define copy_from_user memcpy_fromfs #define copy_to_user memcpy_tofs -#endif - -/* get_user was redefined in 2.1 kernels to use two arguments, and returns - an error code */ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) #define get_user_data(to,from) ((to) = get_user(from),0) #else +#include #define get_user_data(to,from) get_user(to,from) #endif diff --git a/src/i2c-proc.c b/src/i2c-proc.c index 1094f3f0..bce69a5b 100644 --- a/src/i2c-proc.c +++ b/src/i2c-proc.c @@ -40,31 +40,18 @@ static int i2cproc_command(struct i2c_client *client, unsigned int cmd, void *arg); static void i2cproc_inc_use(struct i2c_client *client); static void i2cproc_dec_use(struct i2c_client *client); -static int i2cproc_bus_read(struct inode * inode, struct file * file,char * buf, - int count); - -/* To implement the dynamic /proc/bus/i2c-? files, we need our own - implementation of the read hook */ -static struct file_operations i2cproc_operations = { - NULL, - i2cproc_bus_read, -}; - -static struct inode_operations i2cproc_inode_operations = { - &i2cproc_operations -}; - #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) -static int i2proc_bus_read(char *buf, char **start, off_t offset, int len, +static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, + loff_t *ppos); +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof , void *private); -ssize_t array_read(struct file * file, char * buf,size_t count, loff_t *ppos); #else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ -int i2cproc_bus_read(struct inode * inode, struct file * file,char * buf, - int count); +static int i2cproc_bus_read(struct inode * inode, struct file * file, + char * buf, int count); static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int unused); @@ -100,6 +87,18 @@ static struct proc_dir_entry *i2cproc_proc_entries[I2C_ADAP_MAX]; #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ +/* To implement the dynamic /proc/bus/i2c-? files, we need our own + implementation of the read hook */ +static struct file_operations i2cproc_operations = { + NULL, + i2cproc_bus_read, +}; + +static struct inode_operations i2cproc_inode_operations = { + &i2cproc_operations +}; + + /* Used by init/cleanup */ static int i2cproc_initialized; @@ -202,10 +201,7 @@ int i2cproc_cleanup(void) } if (i2cproc_initialized >= 1) { #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) - if ((res = remove_proc_entry("i2c",proc_bus))) { - printk("i2c-proc.o: could not delete /proc/bus/i2c, module not removed."); - return res; - } + remove_proc_entry("i2c",proc_bus); i2cproc_initialized -= 2; #else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ if (i2cproc_initialized >= 2) { @@ -252,7 +248,8 @@ int read_bus_i2c(char *buf, char **start, off_t offset, int len, int unused) /* This function generates the output for /proc/bus/i2c-? */ #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) -ssize_t i2cproc_read(struct file * file, char * buf,size_t count, loff_t *ppos) +ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, + loff_t *ppos) { struct inode * inode = file->f_dentry->d_inode; #else (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) @@ -290,7 +287,7 @@ int i2cproc_bus_read(struct inode * inode, struct file * file,char * buf, len = len - file->f_pos; if (len < 0) len = 0; - memcpy_tofs(buf,kbuf+file->f_pos,len); + copy_to_user (buf,kbuf+file->f_pos,len); file->f_pos += len; kfree(kbuf); return len; @@ -346,8 +343,7 @@ int i2cproc_attach_adapter(struct i2c_adapter *adapter) #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) proc_entry = create_proc_entry(name,0,proc_bus); - if (! proc_entry) - else { + if (! proc_entry) { printk("i2c-proc.o: Could not create /proc/bus/%s\n",name); kfree(client); return -ENOENT; @@ -398,11 +394,7 @@ int i2cproc_detach_client(struct i2c_client *client) if (client->adapter == i2cproc_adapters[i]) { #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) sprintf(name,"i2c-%d",i); - if ((res = remove_proc_entry(name,proc_bus))) { - printk("i2c-proc.o: Deregistration of /proc entry failed, " - "client not detached.\n"); - return res; - } + remove_proc_entry(name,proc_bus); #else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ if ((res = proc_unregister(&proc_bus_dir, i2cproc_proc_entries[i]->low_ino))) { diff --git a/src/piix4.c b/src/piix4.c index a5932ead..1716fe8b 100644 --- a/src/piix4.c +++ b/src/piix4.c @@ -17,8 +17,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* Note: New PCI (non-BIOS) interface introduced in 2.1.54! */ + #include #include +#include #include "smbus.h" #include "version.h" diff --git a/src/smbus.c b/src/smbus.c index ea22d809..405104d2 100644 --- a/src/smbus.c +++ b/src/smbus.c @@ -19,6 +19,7 @@ #include #include +#include #include "i2c.h" #ifdef SPINLOCK