diff options
author | Ralf Baechle <ralf@linux-mips.org> | 2000-02-18 22:06:10 +0000 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2000-02-18 22:06:10 +0000 |
commit | aba4e552a2f2c1492441acbccedd8e0a4c53f916 (patch) | |
tree | 23921efb2b4af590160f034a89ff3da2ecca6e47 /drivers/i2c | |
parent | 9e17e1aa1cf1cb497d2f67147a51831888affcf3 (diff) |
Merge with Linux 2.3.43.
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/Config.in | 22 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 612 | ||||
-rw-r--r-- | drivers/i2c/i2c-dev.c | 605 | ||||
-rw-r--r-- | drivers/i2c/i2c-elektor.c | 213 | ||||
-rw-r--r-- | drivers/i2c/i2c-pcf8584.h | 38 |
5 files changed, 587 insertions, 903 deletions
diff --git a/drivers/i2c/Config.in b/drivers/i2c/Config.in index ba533aac0..9050f3528 100644 --- a/drivers/i2c/Config.in +++ b/drivers/i2c/Config.in @@ -8,22 +8,22 @@ tristate 'I2C support' CONFIG_I2C if [ "$CONFIG_I2C" != "n" ]; then - dep_tristate 'I2C bit-banging interfaces' CONFIG_I2C_ALGOBIT $CONFIG_I2C - if [ "$CONFIG_I2C_ALGOBIT" != "n" ]; then - dep_tristate ' Philips style parallel port adapter' CONFIG_I2C_PHILIPSPAR $CONFIG_I2C_ALGOBIT - dep_tristate ' ELV adapter' CONFIG_I2C_ELV $CONFIG_I2C_ALGOBIT - dep_tristate ' Velleman K9000 adapter' CONFIG_I2C_VELLEMAN $CONFIG_I2C_ALGOBIT - fi + dep_tristate 'I2C bit-banging interfaces' CONFIG_I2C_ALGOBIT $CONFIG_I2C + if [ "$CONFIG_I2C_ALGOBIT" != "n" ]; then + dep_tristate ' Philips style parallel port adapter' CONFIG_I2C_PHILIPSPAR $CONFIG_I2C_ALGOBIT + dep_tristate ' ELV adapter' CONFIG_I2C_ELV $CONFIG_I2C_ALGOBIT + dep_tristate ' Velleman K9000 adapter' CONFIG_I2C_VELLEMAN $CONFIG_I2C_ALGOBIT + fi - dep_tristate 'I2C PCF 8584 interfaces' CONFIG_I2C_ALGOPCF $CONFIG_I2C - if [ "$CONFIG_I2C_ALGOPCF" != "n" ]; then - dep_tristate ' Elektor ISA card' CONFIG_I2C_ELEKTOR $CONFIG_I2C_ALGOPCF - fi + dep_tristate 'I2C PCF 8584 interfaces' CONFIG_I2C_ALGOPCF $CONFIG_I2C + if [ "$CONFIG_I2C_ALGOPCF" != "n" ]; then + dep_tristate ' Elektor ISA card' CONFIG_I2C_ELEKTOR $CONFIG_I2C_ALGOPCF + fi # This is needed for automatic patch generation: sensors code starts here # This is needed for automatic patch generation: sensors code ends here - dep_tristate 'I2C device interface' CONFIG_I2C_CHARDEV $CONFIG_I2C + dep_tristate 'I2C device interface' CONFIG_I2C_CHARDEV $CONFIG_I2C fi endmenu diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 3d88b6c39..e74337f5b 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -20,7 +20,7 @@ /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> */ -/* $Id: i2c-core.c,v 1.44 1999/12/21 23:45:58 frodo Exp $ */ +/* $Id: i2c-core.c,v 1.48 2000/01/24 21:41:19 frodo Exp $ */ #include <linux/module.h> #include <linux/kernel.h> @@ -33,37 +33,14 @@ /* ----- compatibility stuff ----------------------------------------------- */ -/* 2.0.0 kernel compatibility */ -#if LINUX_VERSION_CODE < 0x020100 -#define MODULE_AUTHOR(noone) -#define MODULE_DESCRIPTION(none) -#define MODULE_PARM(no,param) -#define MODULE_PARM_DESC(no,description) -#define EXPORT_SYMBOL(noexport) -#define EXPORT_NO_SYMBOLS -#endif - #include <linux/version.h> -#ifndef KERNEL_VERSION -#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c)) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,53) #include <linux/init.h> -#else -#define __init -#endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) #define init_MUTEX(s) do { *(s) = MUTEX; } while(0) #endif -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) -#define copy_from_user memcpy_fromfs -#define copy_to_user memcpy_tofs -#else #include <asm/uaccess.h> -#endif /* ----- global defines ---------------------------------------------------- */ @@ -83,8 +60,8 @@ /* ----- global variables -------------------------------------------------- */ /**** lock for writing to global variables: the adapter & driver list */ -struct semaphore adap_lock; -struct semaphore driver_lock; +struct semaphore adap_lock; +struct semaphore driver_lock; /**** adapter list */ static struct i2c_adapter *adapters[I2C_ADAP_MAX]; @@ -104,73 +81,29 @@ static void i2c_dummy_client(struct i2c_client *client); *---------------------------------------------------- */ -/* Note that quite some things changed within the 2.1 kernel series. - Some things below are somewhat difficult to read because of this. */ - #ifdef CONFIG_PROC_FS static int i2cproc_init(void); static int i2cproc_cleanup(void); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) && \ - (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27)) +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27)) static void monitor_bus_i2c(struct inode *inode, int fill); #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) - 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); -#else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ - -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); - -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 */ 2, /* Corrected by proc_register[_dynamic] */ - /* uid */ 0, - /* gid */ 0, - /* size */ 0, -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,0,36)) - /* ops */ &proc_dir_inode_operations, -#endif - }; - -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,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, + NULL, + i2cproc_bus_read, }; static struct inode_operations i2cproc_inode_operations = { - &i2cproc_operations + &i2cproc_operations }; static int i2cproc_initialized = 0; @@ -183,7 +116,7 @@ static int i2cproc_initialized = 0; #endif /* CONFIG_PROC_FS */ -/* --------------------------------------------------- +/* --------------------------------------------------- * registering functions * --------------------------------------------------- */ @@ -222,55 +155,21 @@ int i2c_add_adapter(struct i2c_adapter *adap) if (i2cproc_initialized) { char name[8]; struct proc_dir_entry *proc_entry; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) - int res; -#endif sprintf(name,"i2c-%d", i); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) proc_entry = create_proc_entry(name,0,proc_bus); if (! proc_entry) { printk("i2c-core.o: Could not create /proc/bus/%s\n", - name); + name); return -ENOENT; - } + } proc_entry->ops = &i2cproc_inode_operations; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) proc_entry->owner = THIS_MODULE; -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) +#else proc_entry->fill_inode = &monitor_bus_i2c; #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */ -#else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ - adap->proc_entry = NULL; - if (!(proc_entry = kmalloc(sizeof(struct proc_dir_entry)+ - strlen(name)+1, GFP_KERNEL))) { - printk("i2c-core.o: Out of memory!\n"); - return -ENOMEM; - } - memset(proc_entry,0,sizeof(struct proc_dir_entry)); - proc_entry->namelen = strlen(name); - proc_entry->name = (char *) (proc_entry + 1); - proc_entry->mode = S_IRUGO | S_IFREG; - proc_entry->nlink = 1; - proc_entry->ops = &i2cproc_inode_operations; - - /* Nasty stuff to keep GCC satisfied */ - { - char *procname; - (const char *) procname = proc_entry->name; - strcpy (procname,name); - } - - if ((res = proc_register_dynamic(&proc_bus_dir, proc_entry))) { - printk("i2c-core.o: Could not create %s.\n",name); - kfree(proc_entry); - return res; - } - - adap->proc_entry = proc_entry; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ - adap->inode = proc_entry->low_ino; } @@ -283,7 +182,8 @@ int i2c_add_adapter(struct i2c_adapter *adap) drivers[j]->attach_adapter(adap); DRV_UNLOCK(); - DEB(printk("i2c-core.o: adapter %s registered as adapter %d.\n",adap->name,i)); + DEB(printk("i2c-core.o: adapter %s registered as adapter %d.\n", + adap->name,i)); return 0; } @@ -306,23 +206,9 @@ int i2c_del_adapter(struct i2c_adapter *adap) i2c_dummy_adapter(adap); /* actually i2c_dummy->del_adapter */ #ifdef CONFIG_PROC_FS if (i2cproc_initialized) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) char name[8]; sprintf(name,"i2c-%d", i); remove_proc_entry(name,proc_bus); -#else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ - int res; - if (adapters[i]->proc_entry) { - if ((res = proc_unregister(&proc_bus_dir, - adapters[i]->proc_entry->low_ino))) { - printk("i2c-core.o: Deregistration of /proc " - "entry failed\n"); - ADAP_UNLOCK(); - return res; - } - kfree(adapters[i]->proc_entry); - } -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ } #endif /* def CONFIG_PROC_FS */ @@ -344,7 +230,7 @@ int i2c_del_adapter(struct i2c_adapter *adap) ADAP_UNLOCK(); DEB(printk("i2c-core.o: adapter unregistered: %s\n",adap->name)); - return 0; + return 0; } @@ -384,7 +270,8 @@ int i2c_add_driver(struct i2c_driver *driver) driver->attach_adapter(adapters[i]); for (j=0; j<I2C_CLIENT_MAX; j++) if (adapters[i]->clients[j]) - driver->detach_client(adapters[i]->clients[j]); + driver->detach_client( + adapters[i]->clients[j]); } } ADAP_UNLOCK(); @@ -418,7 +305,7 @@ int i2c_del_driver(struct i2c_driver *driver) } /* Have a look at each adapter, if clients of this driver are still * attached. If so, detach them to be able to kill the driver - * afterwards. + * afterwards. */ DEB2(printk("i2c-core.o: unregister_driver - looking for clients.\n")); /* removing clients does not depend on the notify flag, else @@ -453,11 +340,11 @@ int i2c_del_driver(struct i2c_driver *driver) int i2c_check_addr (struct i2c_adapter *adapter, int addr) { - int i; - for (i = 0; i < I2C_CLIENT_MAX ; i++) - if (adapter->clients[i] && (adapter->clients[i]->addr == addr)) - return -EBUSY; - return 0; + int i; + for (i = 0; i < I2C_CLIENT_MAX ; i++) + if (adapter->clients[i] && (adapter->clients[i]->addr == addr)) + return -EBUSY; + return 0; } int i2c_attach_client(struct i2c_client *client) @@ -465,8 +352,8 @@ int i2c_attach_client(struct i2c_client *client) struct i2c_adapter *adapter = client->adapter; int i; - if (i2c_check_addr(client->adapter,client->addr)) - return -EBUSY; + if (i2c_check_addr(client->adapter,client->addr)) + return -EBUSY; for (i = 0; i < I2C_CLIENT_MAX; i++) if (NULL == adapter->clients[i]) @@ -513,7 +400,7 @@ int i2c_detach_client(struct i2c_client *client) i2c_dummy_client(client); DEB(printk("i2c-core.o: client [%s] unregistered.\n",client->name)); - return 0; + return 0; } void i2c_inc_use_client(struct i2c_client *client) @@ -543,26 +430,21 @@ void i2c_dec_use_client(struct i2c_client *client) #ifdef CONFIG_PROC_FS -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) && \ - (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27)) +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,27)) /* Monitor access to /proc/bus/i2c*; make unloading i2c-proc impossible if some process still uses it or some file in it */ void monitor_bus_i2c(struct inode *inode, int fill) { - if (fill) - MOD_INC_USE_COUNT; - else - MOD_DEC_USE_COUNT; + if (fill) + MOD_INC_USE_COUNT; + else + MOD_DEC_USE_COUNT; } -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */ +#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,37)) */ /* This function generates the output for /proc/bus/i2c */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, void *private) -#else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ -int read_bus_i2c(char *buf, char **start, off_t offset, int len, int unused) -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ { int i; int nr = 0; @@ -571,7 +453,7 @@ int read_bus_i2c(char *buf, char **start, off_t offset, int len, int unused) if (adapters[i]) { nr += sprintf(buf+nr, "i2c-%d\t", i); if (adapters[i]->algo->smbus_xfer) { - if (adapters[i]->algo->master_xfer) + if (adapters[i]->algo->master_xfer) nr += sprintf(buf+nr,"smbus/i2c"); else nr += sprintf(buf+nr,"smbus "); @@ -587,62 +469,55 @@ 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_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)) -int i2cproc_bus_read(struct inode * inode, struct file * file,char * buf, - int count) -{ -#endif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) - char *kbuf; - struct i2c_client *client; - int i,j,len=0; - - if (count < 0) - return -EINVAL; - if (count > 4000) - count = 4000; - for (i = 0; i < I2C_ADAP_MAX; i++) - if (adapters[i]->inode == inode->i_ino) { - /* We need a bit of slack in the kernel buffer; this makes the - sprintf safe. */ - if (! (kbuf = kmalloc(count + 80,GFP_KERNEL))) - return -ENOMEM; - for (j = 0; j < I2C_CLIENT_MAX; j++) - if ((client = adapters[i]->clients[j])) - /* Filter out dummy clients */ - if (client->driver->id != I2C_DRIVERID_I2CDEV) - len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n", - client->addr, - client->name,client->driver->name); - if (file->f_pos+len > count) - len = count - file->f_pos; - len = len - file->f_pos; - if (len < 0) - len = 0; - copy_to_user (buf,kbuf+file->f_pos,len); - file->f_pos += len; - kfree(kbuf); - return len; - } - return -ENOENT; + struct inode * inode = file->f_dentry->d_inode; + char *kbuf; + struct i2c_client *client; + int i,j,len=0; + + if (count < 0) + return -EINVAL; + if (count > 4000) + count = 4000; + for (i = 0; i < I2C_ADAP_MAX; i++) + if (adapters[i]->inode == inode->i_ino) { + /* We need a bit of slack in the kernel buffer; this makes the + sprintf safe. */ + if (! (kbuf = kmalloc(count + 80,GFP_KERNEL))) + return -ENOMEM; + for (j = 0; j < I2C_CLIENT_MAX; j++) + if ((client = adapters[i]->clients[j])) + /* Filter out dummy clients */ + if (client->driver->id != I2C_DRIVERID_I2CDEV) + len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n", + client->addr, + client->name,client->driver->name); + if (file->f_pos+len > count) + len = count - file->f_pos; + len = len - file->f_pos; + if (len < 0) + len = 0; + if (copy_to_user (buf,kbuf+file->f_pos, + len)) { + kfree(kbuf); + return -EFAULT; + } + file->f_pos += len; + kfree(kbuf); + return len; + } + return -ENOENT; } int i2cproc_init(void) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) struct proc_dir_entry *proc_bus_i2c; -#else - int res; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ i2cproc_initialized = 0; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) if (! proc_bus) { printk("i2c-core.o: /proc/bus/ does not exist"); i2cproc_cleanup(); @@ -657,29 +532,10 @@ int i2cproc_init(void) proc_bus_i2c->read_proc = &read_bus_i2c; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) proc_bus_i2c->owner = THIS_MODULE; -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) +#else proc_bus_i2c->fill_inode = &monitor_bus_i2c; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */ i2cproc_initialized += 2; -#else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ - /* In Linux 2.0.x, there is no /proc/bus! But I hope no other module - introduced it, or we are fucked. And 2.0.35 and earlier does not - export proc_dir_inode_operations, so we grab it from proc_net, - which also uses it. Not nice. */ - proc_bus_dir.ops = proc_net.ops; - if ((res = proc_register_dynamic(&proc_root, &proc_bus_dir))) { - printk("i2c-core.o: Could not create /proc/bus/"); - i2cproc_cleanup(); - return res; - } - i2cproc_initialized ++; - if ((res = proc_register_dynamic(&proc_bus_dir, &proc_bus_i2c_dir))) { - printk("i2c-core.o: Could not create /proc/bus/i2c\n"); - i2cproc_cleanup(); - return res; - } - i2cproc_initialized ++; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ return 0; } @@ -687,27 +543,8 @@ int i2cproc_cleanup(void) { if (i2cproc_initialized >= 1) { -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) remove_proc_entry("i2c",proc_bus); i2cproc_initialized -= 2; -#else /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29)) */ - int res; - if (i2cproc_initialized >= 2) { - if ((res = proc_unregister(&proc_bus_dir, - proc_bus_i2c_dir.low_ino))) { - printk("i2c-core.o: could not delete " - "/proc/bus/i2c, module not removed."); - return res; - } - i2cproc_initialized --; - } - if ((res = proc_unregister(&proc_root,proc_bus_dir.low_ino))) { - printk("i2c-core.o: could not delete /proc/bus/, " - "module not removed."); - return res; - } - i2cproc_initialized --; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,29)) */ } return 0; } @@ -715,7 +552,7 @@ int i2cproc_cleanup(void) #endif /* def CONFIG_PROC_FS */ -/* --------------------------------------------------- +/* --------------------------------------------------- * dummy driver notification * --------------------------------------------------- */ @@ -724,16 +561,16 @@ static void i2c_dummy_adapter(struct i2c_adapter *adap) { int i; for (i=0; i<I2C_DRIVER_MAX; i++) - if (drivers[i] && (drivers[i]->flags & I2C_DF_DUMMY)) - drivers[i]->attach_adapter(adap); + if (drivers[i] && (drivers[i]->flags & I2C_DF_DUMMY)) + drivers[i]->attach_adapter(adap); } static void i2c_dummy_client(struct i2c_client *client) { int i; for (i=0; i<I2C_DRIVER_MAX; i++) - if (drivers[i] && (drivers[i]->flags & I2C_DF_DUMMY)) - drivers[i]->detach_client(client); + if (drivers[i] && (drivers[i]->flags & I2C_DF_DUMMY)) + drivers[i]->detach_client(client); } @@ -747,7 +584,8 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg msgs[],int num) int ret; if (adap->algo->master_xfer) { - DEB2(printk("i2c-core.o: master_xfer: %s with %d msgs.\n",adap->name,num)); + DEB2(printk("i2c-core.o: master_xfer: %s with %d msgs.\n", + adap->name,num)); I2C_LOCK(adap); ret = adap->algo->master_xfer(adap,msgs,num); @@ -756,7 +594,7 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg msgs[],int num) return ret; } else { printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n", - adap->id); + adap->id); return -ENOSYS; } } @@ -786,7 +624,7 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count) return (ret == 1 )? count : ret; } else { printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n", - client->adapter->id); + client->adapter->id); return -ENOSYS; } } @@ -819,7 +657,7 @@ int i2c_master_recv(struct i2c_client *client, char *buf ,int count) return (ret == 1 )? count : ret; } else { printk("i2c-core.o: I2C adapter %04x: I2C level transfers not supported\n", - client->adapter->id); + client->adapter->id); return -ENOSYS; } } @@ -855,128 +693,124 @@ int i2c_probe(struct i2c_adapter *adapter, struct i2c_client_address_data *address_data, i2c_client_found_addr_proc *found_proc) { - int addr,i,found,err; - int adap_id = i2c_adapter_id(adapter); - - /* Forget it if we can't probe using SMBUS_QUICK */ - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK)) - return -1; - - for (addr = 0x00; - addr <= 0x7f; - addr++) { - - /* Skip if already in use */ - if (i2c_check_addr(adapter,addr)) - continue; - - /* If it is in one of the force entries, we don't do any detection - at all */ - found = 0; - - for (i = 0; - !found && (address_data->force[i] != I2C_CLIENT_END); - i += 3) { - if (((adap_id == address_data->force[i]) || - (address_data->force[i] == ANY_I2C_BUS)) && - (addr == address_data->force[i+1])) { - DEB2(printk("i2c-core.o: found force parameter for adapter %d, addr %04x\n", - adap_id,addr)); - if ((err = found_proc(adapter,addr,0,0))) - return err; - found = 1; - } - } - if (found) - continue; - - /* If this address is in one of the ignores, we can forget about it - right now */ - for (i = 0; - !found && (address_data->ignore[i] != I2C_CLIENT_END); - i += 2) { - if (((adap_id == address_data->ignore[i]) || - ((address_data->ignore[i] == ANY_I2C_BUS))) && - (addr == address_data->ignore[i+1])) { - DEB2(printk("i2c-core.o: found ignore parameter for adapter %d, " - "addr %04x\n", adap_id ,addr)); - found = 1; - } - } - for (i = 0; - !found && (address_data->ignore_range[i] != I2C_CLIENT_END); - i += 3) { - if (((adap_id == address_data->ignore_range[i]) || - ((address_data->ignore_range[i]==ANY_I2C_BUS))) && - (addr >= address_data->ignore_range[i+1]) && - (addr <= address_data->ignore_range[i+2])) { - DEB2(printk("i2c-core.o: found ignore_range parameter for adapter %d, " - "addr %04x\n", adap_id,addr)); - found = 1; - } - } - if (found) - continue; - - /* Now, we will do a detection, but only if it is in the normal or - probe entries */ - for (i = 0; - !found && (address_data->normal_i2c[i] != I2C_CLIENT_END); - i += 1) { - if (addr == address_data->normal_i2c[i]) { - found = 1; - DEB2(printk("i2c-core.o: found normal i2c entry for adapter %d, " - "addr %02x", adap_id,addr)); - } - } - - for (i = 0; - !found && (address_data->normal_i2c_range[i] != I2C_CLIENT_END); - i += 2) { - if ((addr >= address_data->normal_i2c_range[i]) && - (addr <= address_data->normal_i2c_range[i+1])) { - found = 1; - DEB2(printk("i2c-core.o: found normal i2c_range entry for adapter %d, " - "addr %04x\n", adap_id,addr)); - } - } - - for (i = 0; - !found && (address_data->probe[i] != I2C_CLIENT_END); - i += 2) { - if (((adap_id == address_data->probe[i]) || - ((address_data->probe[i] == ANY_I2C_BUS))) && - (addr == address_data->probe[i+1])) { - found = 1; - DEB2(printk("i2c-core.o: found probe parameter for adapter %d, " - "addr %04x\n", adap_id,addr)); - } - } - for (i = 0; - !found && (address_data->probe_range[i] != I2C_CLIENT_END); - i += 3) { - if (((adap_id == address_data->probe_range[i]) || - (address_data->probe_range[i] == ANY_I2C_BUS)) && - (addr >= address_data->probe_range[i+1]) && - (addr <= address_data->probe_range[i+2])) { - found = 1; - DEB2(printk("i2c-core.o: found probe_range parameter for adapter %d, " - "addr %04x\n", adap_id,addr)); - } - } - if (!found) - continue; - - /* OK, so we really should examine this address. First check - whether there is some client here at all! */ - if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0) - if ((err = found_proc(adapter,addr,0,-1))) - return err; - } - return 0; + int addr,i,found,err; + int adap_id = i2c_adapter_id(adapter); + + /* Forget it if we can't probe using SMBUS_QUICK */ + if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK)) + return -1; + + for (addr = 0x00; addr <= 0x7f; addr++) { + + /* Skip if already in use */ + if (i2c_check_addr(adapter,addr)) + continue; + + /* If it is in one of the force entries, we don't do any detection + at all */ + found = 0; + + for (i = 0; !found && (address_data->force[i] != I2C_CLIENT_END); i += 3) { + if (((adap_id == address_data->force[i]) || + (address_data->force[i] == ANY_I2C_BUS)) && + (addr == address_data->force[i+1])) { + DEB2(printk("i2c-core.o: found force parameter for adapter %d, addr %04x\n", + adap_id,addr)); + if ((err = found_proc(adapter,addr,0,0))) + return err; + found = 1; + } + } + if (found) + continue; + + /* If this address is in one of the ignores, we can forget about + it right now */ + for (i = 0; + !found && (address_data->ignore[i] != I2C_CLIENT_END); + i += 2) { + if (((adap_id == address_data->ignore[i]) || + ((address_data->ignore[i] == ANY_I2C_BUS))) && + (addr == address_data->ignore[i+1])) { + DEB2(printk("i2c-core.o: found ignore parameter for adapter %d, " + "addr %04x\n", adap_id ,addr)); + found = 1; + } + } + for (i = 0; + !found && (address_data->ignore_range[i] != I2C_CLIENT_END); + i += 3) { + if (((adap_id == address_data->ignore_range[i]) || + ((address_data->ignore_range[i]==ANY_I2C_BUS))) && + (addr >= address_data->ignore_range[i+1]) && + (addr <= address_data->ignore_range[i+2])) { + DEB2(printk("i2c-core.o: found ignore_range parameter for adapter %d, " + "addr %04x\n", adap_id,addr)); + found = 1; + } + } + if (found) + continue; + + /* Now, we will do a detection, but only if it is in the normal or + probe entries */ + for (i = 0; + !found && (address_data->normal_i2c[i] != I2C_CLIENT_END); + i += 1) { + if (addr == address_data->normal_i2c[i]) { + found = 1; + DEB2(printk("i2c-core.o: found normal i2c entry for adapter %d, " + "addr %02x", adap_id,addr)); + } + } + + for (i = 0; + !found && (address_data->normal_i2c_range[i] != I2C_CLIENT_END); + i += 2) { + if ((addr >= address_data->normal_i2c_range[i]) && + (addr <= address_data->normal_i2c_range[i+1])) { + found = 1; + DEB2(printk("i2c-core.o: found normal i2c_range entry for adapter %d, " + "addr %04x\n", adap_id,addr)); + } + } + + for (i = 0; + !found && (address_data->probe[i] != I2C_CLIENT_END); + i += 2) { + if (((adap_id == address_data->probe[i]) || + ((address_data->probe[i] == ANY_I2C_BUS))) && + (addr == address_data->probe[i+1])) { + found = 1; + DEB2(printk("i2c-core.o: found probe parameter for adapter %d, " + "addr %04x\n", adap_id,addr)); + } + } + for (i = 0; + !found && (address_data->probe_range[i] != I2C_CLIENT_END); + i += 3) { + if (((adap_id == address_data->probe_range[i]) || + (address_data->probe_range[i] == ANY_I2C_BUS)) && + (addr >= address_data->probe_range[i+1]) && + (addr <= address_data->probe_range[i+2])) { + found = 1; + DEB2(printk("i2c-core.o: found probe_range parameter for adapter %d, " + "addr %04x\n", adap_id,addr)); + } + } + if (!found) + continue; + + /* OK, so we really should examine this address. First check + whether there is some client here at all! */ + if (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0) + if ((err = found_proc(adapter,addr,0,-1))) + return err; + } + return 0; } -/* +++ frodo +/* * return id number for a specific adapter */ int i2c_adapter_id(struct i2c_adapter *adap) @@ -993,14 +827,14 @@ int i2c_adapter_id(struct i2c_adapter *adap) extern s32 i2c_smbus_write_quick(struct i2c_client * client, u8 value) { return i2c_smbus_xfer(client->adapter,client->addr,client->flags, - value,0,I2C_SMBUS_QUICK,NULL); + value,0,I2C_SMBUS_QUICK,NULL); } extern s32 i2c_smbus_read_byte(struct i2c_client * client) { union i2c_smbus_data data; if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data)) + I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data)) return -1; else return 0x0FF & data.byte; @@ -1009,26 +843,26 @@ extern s32 i2c_smbus_read_byte(struct i2c_client * client) extern s32 i2c_smbus_write_byte(struct i2c_client * client, u8 value) { return i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL); + I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,NULL); } extern s32 i2c_smbus_read_byte_data(struct i2c_client * client, u8 command) { union i2c_smbus_data data; if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data)) + I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data)) return -1; else return 0x0FF & data.byte; } -extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, - u8 command, u8 value) +extern s32 i2c_smbus_write_byte_data(struct i2c_client * client, u8 command, + u8 value) { union i2c_smbus_data data; data.byte = value; return i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_WRITE,command, + I2C_SMBUS_WRITE,command, I2C_SMBUS_BYTE_DATA,&data); } @@ -1036,7 +870,7 @@ extern s32 i2c_smbus_read_word_data(struct i2c_client * client, u8 command) { union i2c_smbus_data data; if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data)) + I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data)) return -1; else return 0x0FFFF & data.word; @@ -1048,8 +882,8 @@ extern s32 i2c_smbus_write_word_data(struct i2c_client * client, union i2c_smbus_data data; data.word = value; return i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_WRITE,command, - I2C_SMBUS_WORD_DATA,&data); + I2C_SMBUS_WRITE,command, + I2C_SMBUS_WORD_DATA,&data); } extern s32 i2c_smbus_process_call(struct i2c_client * client, @@ -1058,8 +892,8 @@ extern s32 i2c_smbus_process_call(struct i2c_client * client, union i2c_smbus_data data; data.word = value; if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_WRITE,command, - I2C_SMBUS_PROC_CALL, &data)) + I2C_SMBUS_WRITE,command, + I2C_SMBUS_PROC_CALL, &data)) return -1; else return 0x0FFFF & data.word; @@ -1072,7 +906,7 @@ extern s32 i2c_smbus_read_block_data(struct i2c_client * client, union i2c_smbus_data data; int i; if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_READ,command, + I2C_SMBUS_READ,command, I2C_SMBUS_BLOCK_DATA,&data)) return -1; else { @@ -1093,7 +927,7 @@ extern s32 i2c_smbus_write_block_data(struct i2c_client * client, data.block[i] = values[i-1]; data.block[0] = length; return i2c_smbus_xfer(client->adapter,client->addr,client->flags, - I2C_SMBUS_WRITE,command, + I2C_SMBUS_WRITE,command, I2C_SMBUS_BLOCK_DATA,&data); } @@ -1177,7 +1011,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, size); return -1; } - + if (i2c_transfer(adapter, msg, num) < 0) return -1; @@ -1193,8 +1027,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr, case I2C_SMBUS_PROC_CALL: data->word = msgbuf1[0] | (msgbuf1[1] << 8); break; - } - return 0; + } + return 0; } @@ -1203,7 +1037,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, union i2c_smbus_data * data) { s32 res; - flags = flags & I2C_M_TEN; + flags = flags & I2C_M_TEN; if (adapter->algo->smbus_xfer) { I2C_LOCK(adapter); res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write, @@ -1211,7 +1045,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, I2C_UNLOCK(adapter); } else res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, - command,size,data); + command,size,data); return res; } @@ -1220,22 +1054,22 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, backward compatibility. */ u32 i2c_get_functionality (struct i2c_adapter *adap) { - if (adap->algo->functionality) - return adap->algo->functionality(adap); - else - return 0xffffffff; + if (adap->algo->functionality) + return adap->algo->functionality(adap); + else + return 0xffffffff; } int i2c_check_functionality (struct i2c_adapter *adap, u32 func) { - u32 adap_func = i2c_get_functionality (adap); - return (func & adap_func) == func; + u32 adap_func = i2c_get_functionality (adap); + return (func & adap_func) == func; } static int __init i2c_init(void) { - printk("i2c-core.o: i2c core module\n"); + printk("i2c-core.o: i2c core module\n"); memset(adapters,0,sizeof(adapters)); memset(drivers,0,sizeof(drivers)); adap_count=0; diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 088d730fc..c2c51bef4 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -23,7 +23,7 @@ But I have used so much of his original code and ideas that it seems only fair to recognize him as co-author -- Frodo */ -/* $Id: i2c-dev.c,v 1.18 1999/12/21 23:45:58 frodo Exp $ */ +/* $Id: i2c-dev.c,v 1.25 2000/01/26 14:14:20 frodo Exp $ */ #include <linux/kernel.h> #include <linux/module.h> @@ -34,34 +34,8 @@ /* If you want debugging uncomment: */ /* #define DEBUG */ -#ifndef KERNEL_VERSION -#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c)) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,51) #include <linux/init.h> -#else -#define __init -#endif - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,1,4)) -#define copy_from_user memcpy_fromfs -#define copy_to_user memcpy_tofs -#define get_user_data(to,from) ((to) = get_user(from),0) -#else #include <asm/uaccess.h> -#define get_user_data(to,from) get_user(to,from) -#endif - -/* 2.0.0 kernel compatibility */ -#if LINUX_VERSION_CODE < 0x020100 -#define MODULE_AUTHOR(noone) -#define MODULE_DESCRIPTION(none) -#define MODULE_PARM(no,param) -#define MODULE_PARM_DESC(no,description) -#define EXPORT_SYMBOL(noexport) -#define EXPORT_NO_SYMBOLS -#endif #include <linux/i2c.h> #include <linux/i2c-dev.h> @@ -73,45 +47,18 @@ extern int cleanup_module(void); /* struct file_operations changed too often in the 2.1 series for nice code */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) static loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin); -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,56)) -static long long i2cdev_lseek (struct file *file, long long offset, int origin); -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)) -static long long i2cdev_llseek (struct inode *inode, struct file *file, - long long offset, int origin); -#else -static int i2cdev_lseek (struct inode *inode, struct file *file, off_t offset, - int origin); -#endif -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) static ssize_t i2cdev_read (struct file *file, char *buf, size_t count, loff_t *offset); static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count, loff_t *offset); -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)) -static long i2cdev_read (struct inode *inode, struct file *file, char *buf, - unsigned long count); -static long i2cdev_write (struct inode *inode, struct file *file, - const char *buf, unsigned long offset); -#else -static int i2cdev_read(struct inode *inode, struct file *file, char *buf, - int count); -static int i2cdev_write(struct inode *inode, struct file *file, - const char *buf, int count); -#endif static int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg); static int i2cdev_open (struct inode *inode, struct file *file); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,31)) static int i2cdev_release (struct inode *inode, struct file *file); -#else -static void i2cdev_release (struct inode *inode, struct file *file); -#endif - static int i2cdev_attach_adapter(struct i2c_adapter *adap); static int i2cdev_detach_client(struct i2c_client *client); @@ -127,413 +74,349 @@ extern static int i2cdev_cleanup(void); static struct file_operations i2cdev_fops = { - i2cdev_lseek, - i2cdev_read, - i2cdev_write, - NULL, /* i2cdev_readdir */ - NULL, /* i2cdev_select */ - i2cdev_ioctl, - NULL, /* i2cdev_mmap */ - i2cdev_open, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,118) - NULL, /* i2cdev_flush */ -#endif - i2cdev_release, + i2cdev_lseek, + i2cdev_read, + i2cdev_write, + NULL, /* i2cdev_readdir */ + NULL, /* i2cdev_select */ + i2cdev_ioctl, + NULL, /* i2cdev_mmap */ + i2cdev_open, + NULL, /* i2cdev_flush */ + i2cdev_release, }; #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX static struct i2c_adapter *i2cdev_adaps[I2CDEV_ADAPS_MAX]; static struct i2c_driver i2cdev_driver = { - /* name */ "i2c-dev dummy driver", - /* id */ I2C_DRIVERID_I2CDEV, - /* flags */ I2C_DF_DUMMY, - /* attach_adapter */ i2cdev_attach_adapter, - /* detach_client */ i2cdev_detach_client, - /* command */ i2cdev_command, - /* inc_use */ NULL, - /* dec_use */ NULL, + /* name */ "i2c-dev dummy driver", + /* id */ I2C_DRIVERID_I2CDEV, + /* flags */ I2C_DF_DUMMY, + /* attach_adapter */ i2cdev_attach_adapter, + /* detach_client */ i2cdev_detach_client, + /* command */ i2cdev_command, + /* inc_use */ NULL, + /* dec_use */ NULL, }; static struct i2c_client i2cdev_client_template = { - /* name */ "I2C /dev entry", - /* id */ 1, - /* flags */ 0, - /* addr */ -1, - /* adapter */ NULL, - /* driver */ &i2cdev_driver, - /* data */ NULL + /* name */ "I2C /dev entry", + /* id */ 1, + /* flags */ 0, + /* addr */ -1, + /* adapter */ NULL, + /* driver */ &i2cdev_driver, + /* data */ NULL }; static int i2cdev_initialized; /* Note that the lseek function is called llseek in 2.1 kernels. But things are complicated enough as is. */ -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin) -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,56)) -long long i2cdev_lseek (struct file *file, long long offset, int origin) -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)) -long long i2cdev_llseek (struct inode *inode, struct file *file, - long long offset, int origin) -#else -int i2cdev_lseek (struct inode *inode, struct file *file, off_t offset, - int origin) -#endif { #ifdef DEBUG -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,56)) - struct inode *inode = file->f_dentry->d_inode; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ - printk("i2c-dev,o: i2c-%d lseek to %ld bytes relative to %d.\n", - MINOR(inode->i_rdev),(long) offset,origin); + struct inode *inode = file->f_dentry->d_inode; + printk("i2c-dev,o: i2c-%d lseek to %ld bytes relative to %d.\n", + MINOR(inode->i_rdev),(long) offset,origin); #endif /* DEBUG */ - return -ESPIPE; + return -ESPIPE; } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) static ssize_t i2cdev_read (struct file *file, char *buf, size_t count, loff_t *offset) -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)) -static long i2cdev_read (struct inode *inode, struct file *file, char *buf, - unsigned long count) -#else -static int i2cdev_read(struct inode *inode, struct file *file, char *buf, - int count) -#endif { - char *tmp; - int ret; + char *tmp; + int ret; #ifdef DEBUG -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) - struct inode *inode = file->f_dentry->d_inode; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ + struct inode *inode = file->f_dentry->d_inode; #endif /* DEBUG */ - struct i2c_client *client = (struct i2c_client *)file->private_data; + struct i2c_client *client = (struct i2c_client *)file->private_data; - /* copy user space data to kernel space. */ - tmp = kmalloc(count,GFP_KERNEL); - if (tmp==NULL) - return -ENOMEM; + /* copy user space data to kernel space. */ + tmp = kmalloc(count,GFP_KERNEL); + if (tmp==NULL) + return -ENOMEM; #ifdef DEBUG - printk("i2c-dev,o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev),count); + printk("i2c-dev,o: i2c-%d reading %d bytes.\n",MINOR(inode->i_rdev), + count); #endif - ret = i2c_master_recv(client,tmp,count); - copy_to_user(buf,tmp,count); - kfree(tmp); - return ret; + ret = i2c_master_recv(client,tmp,count); + if (! ret) + ret = copy_to_user(buf,tmp,count)?-EFAULT:0; + kfree(tmp); + return ret; } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) static ssize_t i2cdev_write (struct file *file, const char *buf, size_t count, loff_t *offset) -#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)) -static long i2cdev_write (struct inode *inode, struct file *file, - const char *buf, unsigned long offset) -#else -static int i2cdev_write(struct inode *inode, struct file *file, - const char *buf, int count) -#endif { - int ret; - char *tmp; - struct i2c_client *client = (struct i2c_client *)file->private_data; + int ret; + char *tmp; + struct i2c_client *client = (struct i2c_client *)file->private_data; #ifdef DEBUG -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) - struct inode *inode = file->f_dentry->d_inode; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,70)) */ + struct inode *inode = file->f_dentry->d_inode; #endif /* DEBUG */ - /* copy user space data to kernel space. */ - tmp = kmalloc(count,GFP_KERNEL); - if (tmp==NULL) - return -ENOMEM; - copy_from_user(tmp,buf,count); + /* copy user space data to kernel space. */ + tmp = kmalloc(count,GFP_KERNEL); + if (tmp==NULL) + return -ENOMEM; + if (copy_from_user(tmp,buf,count)) { + kfree(tmp); + return -EFAULT; + } #ifdef DEBUG - printk("i2c-dev,o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev),count); + printk("i2c-dev,o: i2c-%d writing %d bytes.\n",MINOR(inode->i_rdev), + count); #endif - ret = i2c_master_send(client,tmp,count); - kfree(tmp); - return ret; + ret = i2c_master_send(client,tmp,count); + kfree(tmp); + return ret; } int i2cdev_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { - struct i2c_client *client = (struct i2c_client *)file->private_data; - struct i2c_smbus_ioctl_data data_arg; - union i2c_smbus_data temp; - int ver,datasize,res; - unsigned long funcs; + struct i2c_client *client = (struct i2c_client *)file->private_data; + struct i2c_smbus_ioctl_data data_arg; + union i2c_smbus_data temp; + int datasize,res; + unsigned long funcs; #ifdef DEBUG - printk("i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n", - MINOR(inode->i_rdev),cmd, arg); + printk("i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n", + MINOR(inode->i_rdev),cmd, arg); #endif /* DEBUG */ - switch ( cmd ) { - case I2C_SLAVE: - case I2C_SLAVE_FORCE: - if ((arg > 0x3ff) || (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) - return -EINVAL; - if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) - return -EBUSY; - client->addr = arg; - return 0; - case I2C_TENBIT: - if (arg) - client->flags |= I2C_M_TEN; - else - client->flags &= ~I2C_M_TEN; - return 0; - case I2C_FUNCS: - if (! arg) { -#ifdef DEBUG - printk("i2c-dev.o: NULL argument pointer in ioctl I2C_SMBUS.\n"); -#endif - return -EINVAL; - } - if (verify_area(VERIFY_WRITE,(unsigned long *) arg, - sizeof(unsigned long))) { + switch ( cmd ) { + case I2C_SLAVE: + case I2C_SLAVE_FORCE: + if ((arg > 0x3ff) || + (((client->flags & I2C_M_TEN) == 0) && arg > 0x7f)) + return -EINVAL; + if ((cmd == I2C_SLAVE) && i2c_check_addr(client->adapter,arg)) + return -EBUSY; + client->addr = arg; + return 0; + case I2C_TENBIT: + if (arg) + client->flags |= I2C_M_TEN; + else + client->flags &= ~I2C_M_TEN; + return 0; + case I2C_FUNCS: + funcs = i2c_get_functionality(client->adapter); + return (copy_to_user((unsigned long *)arg,&funcs, + sizeof(unsigned long)))?-EFAULT:0; + case I2C_SMBUS: + copy_from_user_ret(&data_arg, + (struct i2c_smbus_ioctl_data *) arg, + sizeof(struct i2c_smbus_ioctl_data), + -EFAULT); + if ((data_arg.size != I2C_SMBUS_BYTE) && + (data_arg.size != I2C_SMBUS_QUICK) && + (data_arg.size != I2C_SMBUS_BYTE_DATA) && + (data_arg.size != I2C_SMBUS_WORD_DATA) && + (data_arg.size != I2C_SMBUS_PROC_CALL) && + (data_arg.size != I2C_SMBUS_BLOCK_DATA)) { #ifdef DEBUG - printk("i2c-dev.o: invalid argument pointer (%ld) " - "in IOCTL I2C_SMBUS.\n", arg); + printk("i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n", + data_arg.size); #endif - return -EINVAL; - } - - funcs = i2c_get_functionality(client->adapter); - copy_to_user((unsigned long *)arg,&funcs,sizeof(unsigned long)); - return 0; - case I2C_SMBUS: - if (! arg) { + return -EINVAL; + } + /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1, + so the check is valid if size==I2C_SMBUS_QUICK too. */ + if ((data_arg.read_write != I2C_SMBUS_READ) && + (data_arg.read_write != I2C_SMBUS_WRITE)) { #ifdef DEBUG - printk("i2c-dev.o: NULL argument pointer in ioctl I2C_SMBUS.\n"); + printk("i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n", + data_arg.read_write); #endif - return -EINVAL; - } - if (verify_area(VERIFY_READ,(struct i2c_smbus_ioctl_data *) arg, - sizeof(struct i2c_smbus_ioctl_data))) { + return -EINVAL; + } + + /* Note that command values are always valid! */ + + if ((data_arg.size == I2C_SMBUS_QUICK) || + ((data_arg.size == I2C_SMBUS_BYTE) && + (data_arg.read_write == I2C_SMBUS_WRITE))) + /* These are special: we do not use data */ + return i2c_smbus_xfer(client->adapter, client->addr, + client->flags, + data_arg.read_write, + data_arg.command, + data_arg.size, NULL); + + if (data_arg.data == NULL) { #ifdef DEBUG - printk("i2c-dev.o: invalid argument pointer (%ld) " - "in IOCTL I2C_SMBUS.\n", arg); + printk("i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n"); #endif - return -EINVAL; - } - copy_from_user(&data_arg,(struct i2c_smbus_ioctl_data *) arg, - sizeof(struct i2c_smbus_ioctl_data)); - if ((data_arg.size != I2C_SMBUS_BYTE) && - (data_arg.size != I2C_SMBUS_QUICK) && - (data_arg.size != I2C_SMBUS_BYTE_DATA) && - (data_arg.size != I2C_SMBUS_WORD_DATA) && - (data_arg.size != I2C_SMBUS_PROC_CALL) && - (data_arg.size != I2C_SMBUS_BLOCK_DATA)) { -#ifdef DEBUG - printk("i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n", - data_arg.size); -#endif - return -EINVAL; - } - /* Note that I2C_SMBUS_READ and I2C_SMBUS_WRITE are 0 and 1, - so the check is valid if size==I2C_SMBUS_QUICK too. */ - if ((data_arg.read_write != I2C_SMBUS_READ) && - (data_arg.read_write != I2C_SMBUS_WRITE)) { -#ifdef DEBUG - printk("i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n", - data_arg.read_write); -#endif - return -EINVAL; - } - - /* Note that command values are always valid! */ - - if ((data_arg.size == I2C_SMBUS_QUICK) || - ((data_arg.size == I2C_SMBUS_BYTE) && - (data_arg.read_write == I2C_SMBUS_WRITE))) - /* These are special: we do not use data */ - return i2c_smbus_xfer(client->adapter, client->addr, client->flags, - data_arg.read_write, data_arg.command, - data_arg.size, NULL); - - if (data_arg.data == NULL) { -#ifdef DEBUG - printk("i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n"); -#endif - return -EINVAL; - } - - /* This seems unlogical but it is not: if the user wants to read a - value, we must write that value to user memory! */ - ver = ((data_arg.read_write == I2C_SMBUS_WRITE) && - (data_arg.size != I2C_SMBUS_PROC_CALL))?VERIFY_READ:VERIFY_WRITE; - - if ((data_arg.size == I2C_SMBUS_BYTE_DATA) || (data_arg.size == I2C_SMBUS_BYTE)) - datasize = sizeof(data_arg.data->byte); - else if ((data_arg.size == I2C_SMBUS_WORD_DATA) || - (data_arg.size == I2C_SMBUS_PROC_CALL)) - datasize = sizeof(data_arg.data->word); - else /* size == I2C_SMBUS_BLOCK_DATA */ - datasize = sizeof(data_arg.data->block); - - if (verify_area(ver,data_arg.data,datasize)) { -#ifdef DEBUG - printk("i2c-dev.o: invalid pointer data (%p) in ioctl I2C_SMBUS.\n", - data_arg.data); -#endif - return -EINVAL; - } - - if ((data_arg.size == I2C_SMBUS_PROC_CALL) || - (data_arg.read_write == I2C_SMBUS_WRITE)) - copy_from_user(&temp,data_arg.data,datasize); - res = i2c_smbus_xfer(client->adapter,client->addr,client->flags, - data_arg.read_write, - data_arg.command,data_arg.size,&temp); - if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || - (data_arg.read_write == I2C_SMBUS_READ))) - copy_to_user(data_arg.data,&temp,datasize); - return res; - - default: - return i2c_control(client,cmd,arg); - } - return 0; + return -EINVAL; + } + + if ((data_arg.size == I2C_SMBUS_BYTE_DATA) || + (data_arg.size == I2C_SMBUS_BYTE)) + datasize = sizeof(data_arg.data->byte); + else if ((data_arg.size == I2C_SMBUS_WORD_DATA) || + (data_arg.size == I2C_SMBUS_PROC_CALL)) + datasize = sizeof(data_arg.data->word); + else /* size == I2C_SMBUS_BLOCK_DATA */ + datasize = sizeof(data_arg.data->block); + + if ((data_arg.size == I2C_SMBUS_PROC_CALL) || + (data_arg.read_write == I2C_SMBUS_WRITE)) + copy_from_user_ret(&temp,data_arg.data,datasize, + -EFAULT); + res = i2c_smbus_xfer(client->adapter,client->addr,client->flags, + data_arg.read_write, + data_arg.command,data_arg.size,&temp); + if (! res && ((data_arg.size == I2C_SMBUS_PROC_CALL) || + (data_arg.read_write == I2C_SMBUS_READ))) + copy_to_user_ret(data_arg.data,&temp,datasize,-EFAULT); + return res; + + default: + return i2c_control(client,cmd,arg); + } + return 0; } int i2cdev_open (struct inode *inode, struct file *file) { - unsigned int minor = MINOR(inode->i_rdev); - struct i2c_client *client; + unsigned int minor = MINOR(inode->i_rdev); + struct i2c_client *client; - if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) { + if ((minor >= I2CDEV_ADAPS_MAX) || ! (i2cdev_adaps[minor])) { #ifdef DEBUG - printk("i2c-dev.o: Trying to open unattached adapter i2c-%d\n",minor); + printk("i2c-dev.o: Trying to open unattached adapter i2c-%d\n", + minor); #endif - return -ENODEV; - } + return -ENODEV; + } - /* Note that we here allocate a client for later use, but we will *not* - register this client! Yes, this is safe. No, it is not very clean. */ - if(! (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL))) - return -ENOMEM; - memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client)); - client->adapter = i2cdev_adaps[minor]; - file->private_data = client; + /* Note that we here allocate a client for later use, but we will *not* + register this client! Yes, this is safe. No, it is not very clean. */ + if(! (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL))) + return -ENOMEM; + memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client)); + client->adapter = i2cdev_adaps[minor]; + file->private_data = client; - i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]); - MOD_INC_USE_COUNT; + if (i2cdev_adaps[minor]->inc_use) + i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]); + MOD_INC_USE_COUNT; #ifdef DEBUG - printk("i2c-dev.o: opened i2c-%d\n",minor); + printk("i2c-dev.o: opened i2c-%d\n",minor); #endif - return 0; + return 0; } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,31)) static int i2cdev_release (struct inode *inode, struct file *file) -#else -static void i2cdev_release (struct inode *inode, struct file *file) -#endif { - unsigned int minor = MINOR(inode->i_rdev); - kfree(file->private_data); - file->private_data=NULL; + unsigned int minor = MINOR(inode->i_rdev); + kfree(file->private_data); + file->private_data=NULL; #ifdef DEBUG - printk("i2c-dev.o: Closed: i2c-%d\n", minor); -#endif - MOD_DEC_USE_COUNT; - i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,31)) - return 0; + printk("i2c-dev.o: Closed: i2c-%d\n", minor); #endif + MOD_DEC_USE_COUNT; + if (i2cdev_adaps[minor]->dec_use) + i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]); + return 0; } int i2cdev_attach_adapter(struct i2c_adapter *adap) { - int i; - - if ((i = i2c_adapter_id(adap)) < 0) { - printk("i2c-dev.o: Unknown adapter ?!?\n"); - return -ENODEV; - } - if (i >= I2CDEV_ADAPS_MAX) { - printk("i2c-dev.o: Adapter number too large?!? (%d)\n",i); - return -ENODEV; - } - - if (! i2cdev_adaps[i]) { - i2cdev_adaps[i] = adap; - printk("i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i); - } else { - i2cdev_adaps[i] = NULL; + int i; + + if ((i = i2c_adapter_id(adap)) < 0) { + printk("i2c-dev.o: Unknown adapter ?!?\n"); + return -ENODEV; + } + if (i >= I2CDEV_ADAPS_MAX) { + printk("i2c-dev.o: Adapter number too large?!? (%d)\n",i); + return -ENODEV; + } + + if (! i2cdev_adaps[i]) { + i2cdev_adaps[i] = adap; + printk("i2c-dev.o: Registered '%s' as minor %d\n",adap->name,i); + } else { + i2cdev_adaps[i] = NULL; #ifdef DEBUG - printk("i2c-dev.o: Adapter unregistered: %s\n",adap->name); + printk("i2c-dev.o: Adapter unregistered: %s\n",adap->name); #endif - } + } - return 0; + return 0; } int i2cdev_detach_client(struct i2c_client *client) { - return 0; + return 0; } static int i2cdev_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return -1; + return -1; } int __init i2c_dev_init(void) { - int res; - - printk("i2c-dev.o: i2c /dev entries driver module\n"); - - i2cdev_initialized = 0; - if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) { - printk("i2c-dev.o: unable to get major %d for i2c bus\n",I2C_MAJOR); - return -EIO; - } - i2cdev_initialized ++; - - if ((res = i2c_add_driver(&i2cdev_driver))) { - printk("i2c-dev.o: Driver registration failed, module not inserted.\n"); - i2cdev_cleanup(); - return res; - } - i2cdev_initialized ++; - return 0; + int res; + + printk("i2c-dev.o: i2c /dev entries driver module\n"); + + i2cdev_initialized = 0; + if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) { + printk("i2c-dev.o: unable to get major %d for i2c bus\n", + I2C_MAJOR); + return -EIO; + } + i2cdev_initialized ++; + + if ((res = i2c_add_driver(&i2cdev_driver))) { + printk("i2c-dev.o: Driver registration failed, module not inserted.\n"); + i2cdev_cleanup(); + return res; + } + i2cdev_initialized ++; + return 0; } int i2cdev_cleanup(void) { - int res; - - if (i2cdev_initialized >= 2) { - if ((res = i2c_del_driver(&i2cdev_driver))) { - printk("i2c-dev.o: Driver deregistration failed, " - "module not removed.\n"); - return res; - } - i2cdev_initialized ++; - } - - if (i2cdev_initialized >= 1) { - if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) { - printk("i2c-dev.o: unable to release major %d for i2c bus\n",I2C_MAJOR); - return res; - } - i2cdev_initialized --; - } - return 0; + int res; + + if (i2cdev_initialized >= 2) { + if ((res = i2c_del_driver(&i2cdev_driver))) { + printk("i2c-dev.o: Driver deregistration failed, " + "module not removed.\n"); + return res; + } + i2cdev_initialized ++; + } + + if (i2cdev_initialized >= 1) { + if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) { + printk("i2c-dev.o: unable to release major %d for i2c bus\n", + I2C_MAJOR); + return res; + } + i2cdev_initialized --; + } + return 0; } EXPORT_NO_SYMBOLS; @@ -545,12 +428,12 @@ MODULE_DESCRIPTION("I2C /dev entries driver"); int init_module(void) { - return i2c_dev_init(); + return i2c_dev_init(); } int cleanup_module(void) { - return i2cdev_cleanup(); + return i2cdev_cleanup(); } #endif /* def MODULE */ diff --git a/drivers/i2c/i2c-elektor.c b/drivers/i2c/i2c-elektor.c index fb965df0f..ad7b9d41c 100644 --- a/drivers/i2c/i2c-elektor.c +++ b/drivers/i2c/i2c-elektor.c @@ -22,7 +22,7 @@ /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even Frodo Looijaard <frodol@dds.nl> */ -/* $Id: i2c-elektor.c,v 1.13 1999/12/21 23:45:58 frodo Exp $ */ +/* $Id: i2c-elektor.c,v 1.16 2000/01/24 02:06:33 mds Exp $ */ #include <linux/kernel.h> #include <linux/ioport.h> @@ -30,24 +30,10 @@ #include <linux/delay.h> #include <linux/malloc.h> #include <linux/version.h> -#if LINUX_VERSION_CODE >= 0x020135 #include <linux/init.h> -#else -#define __init -#endif #include <asm/irq.h> #include <asm/io.h> -/* 2.0.0 kernel compatibility */ -#if LINUX_VERSION_CODE < 0x020100 -#define MODULE_AUTHOR(noone) -#define MODULE_DESCRIPTION(none) -#define MODULE_PARM(no,param) -#define MODULE_PARM_DESC(no,description) -#define EXPORT_SYMBOL(noexport) -#define EXPORT_NO_SYMBOLS -#endif - #include <linux/i2c.h> #include <linux/i2c-algo-pcf.h> #include <linux/i2c-elektor.h> @@ -87,56 +73,48 @@ static int pcf_pending; static void pcf_isa_setbyte(void *data, int ctl, int val) { - if (ctl) { - if (gpi.pi_irq > 0) { - DEB3(printk("i2c-elektor.o: Write control 0x%x\n", val|I2C_PCF_ENI)); - outb(val | I2C_PCF_ENI, CTRL); - } else { - DEB3(printk("i2c-elektor.o: Write control 0x%x\n", val)); - outb(val, CTRL); - } - } else { - DEB3(printk("i2c-elektor.o: Write data 0x%x\n", val)); - outb(val, DATA); - } + if (ctl) { + if (gpi.pi_irq > 0) { + DEB3(printk("i2c-elektor.o: Write control 0x%x\n", + val|I2C_PCF_ENI)); + outb(val | I2C_PCF_ENI, CTRL); + } else { + DEB3(printk("i2c-elektor.o: Write control 0x%x\n", val)); + outb(val, CTRL); + } + } else { + DEB3(printk("i2c-elektor.o: Write data 0x%x\n", val)); + outb(val, DATA); + } } static int pcf_isa_getbyte(void *data, int ctl) { - int val; - - if (ctl) { - val = inb(CTRL); - DEB3(printk("i2c-elektor.o: Read control 0x%x\n", val)); - } else { - val = inb(DATA); - DEB3(printk("i2c-elektor.o: Read data 0x%x\n", val)); - } - return (val); + int val; + + if (ctl) { + val = inb(CTRL); + DEB3(printk("i2c-elektor.o: Read control 0x%x\n", val)); + } else { + val = inb(DATA); + DEB3(printk("i2c-elektor.o: Read data 0x%x\n", val)); + } + return (val); } static int pcf_isa_getown(void *data) { - return (gpi.pi_own); + return (gpi.pi_own); } static int pcf_isa_getclock(void *data) { - return (gpi.pi_clock); + return (gpi.pi_clock); } -#if LINUX_VERSION_CODE < 0x02017f -static void schedule_timeout(int j) -{ - current->state = TASK_INTERRUPTIBLE; - current->timeout = jiffies + j; - schedule(); -} -#endif - #if 0 static void pcf_isa_sleep(unsigned long timeout) { @@ -147,64 +125,53 @@ static void pcf_isa_sleep(unsigned long timeout) static void pcf_isa_waitforpin(void) { - int timeout = 2; - - if (gpi.pi_irq > 0) { - cli(); - if (pcf_pending == 0) { -#if LINUX_VERSION_CODE < 0x02017f - current->timeout = jiffies + timeout * HZ; - interruptible_sleep_on(&pcf_wait); -#else - interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ ); -#endif - } - else - pcf_pending = 0; - sti(); -#if LINUX_VERSION_CODE < 0x02017f - current->timeout = 0; -#endif - } - else { - udelay(100); - } + int timeout = 2; + + if (gpi.pi_irq > 0) { + cli(); + if (pcf_pending == 0) { + interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ ); + } else + pcf_pending = 0; + sti(); + } else { + udelay(100); + } } static void pcf_isa_handler(int this_irq, void *dev_id, struct pt_regs *regs) { - - pcf_pending = 1; - wake_up_interruptible(&pcf_wait); + pcf_pending = 1; + wake_up_interruptible(&pcf_wait); } static int pcf_isa_init(void) { - if (check_region(gpi.pi_base, 2) < 0 ) { - return -ENODEV; - } else { - request_region(gpi.pi_base, 2, "i2c (isa bus adapter)"); - } - if (gpi.pi_irq > 0) { - if (request_irq(gpi.pi_irq, pcf_isa_handler, 0, "PCF8584", 0) < 0) { - printk("i2c-elektor.o: Request irq%d failed\n", gpi.pi_irq); - gpi.pi_irq = 0; - } - else - enable_irq(gpi.pi_irq); - } - return 0; + if (check_region(gpi.pi_base, 2) < 0 ) { + return -ENODEV; + } else { + request_region(gpi.pi_base, 2, "i2c (isa bus adapter)"); + } + if (gpi.pi_irq > 0) { + if (request_irq(gpi.pi_irq, pcf_isa_handler, 0, "PCF8584", 0) + < 0) { + printk("i2c-elektor.o: Request irq%d failed\n", gpi.pi_irq); + gpi.pi_irq = 0; + } else + enable_irq(gpi.pi_irq); + } + return 0; } static void pcf_isa_exit(void) { - if (gpi.pi_irq > 0) { - disable_irq(gpi.pi_irq); - free_irq(gpi.pi_irq, 0); - } - release_region(gpi.pi_base , 2); + if (gpi.pi_irq > 0) { + disable_irq(gpi.pi_irq); + free_irq(gpi.pi_irq, 0); + } + release_region(gpi.pi_base , 2); } @@ -222,14 +189,14 @@ static int pcf_isa_unreg(struct i2c_client *client) static void pcf_isa_inc_use(struct i2c_adapter *adap) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } static void pcf_isa_dec_use(struct i2c_adapter *adap) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } @@ -262,41 +229,41 @@ static struct i2c_adapter pcf_isa_ops = { int __init i2c_pcfisa_init(void) { - struct i2c_pcf_isa *pisa = &gpi; + struct i2c_pcf_isa *pisa = &gpi; - printk("i2c-elektor.o: i2c pcf8584-isa adapter module\n"); - if (base == 0) - pisa->pi_base = DEFAULT_BASE; - else - pisa->pi_base = base; + printk("i2c-elektor.o: i2c pcf8584-isa adapter module\n"); + if (base == 0) + pisa->pi_base = DEFAULT_BASE; + else + pisa->pi_base = base; - if (irq == 0) - pisa->pi_irq = DEFAULT_IRQ; - else - pisa->pi_irq = irq; + if (irq == 0) + pisa->pi_irq = DEFAULT_IRQ; + else + pisa->pi_irq = irq; - if (clock == 0) - pisa->pi_clock = DEFAULT_CLOCK; - else - pisa->pi_clock = clock; + if (clock == 0) + pisa->pi_clock = DEFAULT_CLOCK; + else + pisa->pi_clock = clock; - if (own == 0) - pisa->pi_own = DEFAULT_OWN; - else - pisa->pi_own = own; + if (own == 0) + pisa->pi_own = DEFAULT_OWN; + else + pisa->pi_own = own; - pcf_isa_data.data = (void *)pisa; + pcf_isa_data.data = (void *)pisa; #if (LINUX_VERSION_CODE >= 0x020301) - init_waitqueue_head(&pcf_wait); + init_waitqueue_head(&pcf_wait); #endif - if (pcf_isa_init() == 0) { - if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) - return -ENODEV; - } else { - return -ENODEV; - } - printk("i2c-elektor.o: found device at %#x.\n", pisa->pi_base); - return 0; + if (pcf_isa_init() == 0) { + if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) + return -ENODEV; + } else { + return -ENODEV; + } + printk("i2c-elektor.o: found device at %#x.\n", pisa->pi_base); + return 0; } @@ -313,7 +280,7 @@ MODULE_PARM(own, "i"); int init_module(void) { - return i2c_pcfisa_init(); + return i2c_pcfisa_init(); } void cleanup_module(void) diff --git a/drivers/i2c/i2c-pcf8584.h b/drivers/i2c/i2c-pcf8584.h index 7dabbd9a9..9f0874012 100644 --- a/drivers/i2c/i2c-pcf8584.h +++ b/drivers/i2c/i2c-pcf8584.h @@ -21,20 +21,20 @@ /* With some changes from Frodo Looijaard <frodol@dds.nl> */ -/* $Id: i2c-pcf8584.h,v 1.2 1999/12/21 23:45:58 frodo Exp $ */ +/* $Id: i2c-pcf8584.h,v 1.3 2000/01/18 23:54:07 frodo Exp $ */ #ifndef I2C_PCF8584_H #define I2C_PCF8584_H 1 /* ----- Control register bits ---------------------------------------- */ -#define I2C_PCF_PIN 0x80 -#define I2C_PCF_ESO 0x40 -#define I2C_PCF_ES1 0x20 -#define I2C_PCF_ES2 0x10 -#define I2C_PCF_ENI 0x08 -#define I2C_PCF_STA 0x04 -#define I2C_PCF_STO 0x02 -#define I2C_PCF_ACK 0x01 +#define I2C_PCF_PIN 0x80 +#define I2C_PCF_ESO 0x40 +#define I2C_PCF_ES1 0x20 +#define I2C_PCF_ES2 0x10 +#define I2C_PCF_ENI 0x08 +#define I2C_PCF_STA 0x04 +#define I2C_PCF_STO 0x02 +#define I2C_PCF_ACK 0x01 #define I2C_PCF_START (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STA | I2C_PCF_ACK) #define I2C_PCF_STOP (I2C_PCF_PIN | I2C_PCF_ESO | I2C_PCF_STO | I2C_PCF_ACK) @@ -45,7 +45,7 @@ /*#define I2C_PCF_PIN 0x80 as above*/ #define I2C_PCF_INI 0x40 /* 1 if not initialized */ -#define I2C_PCF_STS 0x20 +#define I2C_PCF_STS 0x20 #define I2C_PCF_BER 0x10 #define I2C_PCF_AD0 0x08 #define I2C_PCF_LRB 0x08 @@ -54,17 +54,17 @@ #define I2C_PCF_BB 0x01 /* ----- Chip clock frequencies --------------------------------------- */ -#define I2C_PCF_CLK3 0x00 -#define I2C_PCF_CLK443 0x10 -#define I2C_PCF_CLK6 0x14 -#define I2C_PCF_CLK8 0x18 -#define I2C_PCF_CLK12 0x1c +#define I2C_PCF_CLK3 0x00 +#define I2C_PCF_CLK443 0x10 +#define I2C_PCF_CLK6 0x14 +#define I2C_PCF_CLK 0x18 +#define I2C_PCF_CLK12 0x1c /* ----- transmission frequencies ------------------------------------- */ -#define I2C_PCF_TRNS90 0x00 /* 90 kHz */ -#define I2C_PCF_TRNS45 0x01 /* 45 kHz */ -#define I2C_PCF_TRNS11 0x02 /* 11 kHz */ -#define I2C_PCF_TRNS15 0x03 /* 1.5 kHz */ +#define I2C_PCF_TRNS90 0x00 /* 90 kHz */ +#define I2C_PCF_TRNS45 0x01 /* 45 kHz */ +#define I2C_PCF_TRNS11 0x02 /* 11 kHz */ +#define I2C_PCF_TRNS15 0x03 /* 1.5 kHz */ /* ----- Access to internal registers according to ES1,ES2 ------------ */ |