i2c cleanups
Subsystems (3)
PATCH 1/1 i2c cleanups
Hi Marcelo,
I will be sending 4 patches to you, based on linux-2.4.24-pre1. They contain cleanups for the i2c subsystem code, ported from LM Sensors' i2c CVS repository [1].
Details about what the patch do will be found with each patch.
Thanks.
[1] http://www2.lm-sensors.nu/~lm78/cvs/browse.cgi/i2c
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups (1/4)
This patch does some trivial changes to a few i2c drivers. The changes are only white space and comment changes, and line reordering. There are also two simple changes to i2c-id.h to keep it in line with the ones in our repository and Linux 2.6.0-test11.
These changes should make subsequent patches more readable.
Please apply.
drivers/i2c/i2c-core.c +2 -1
@@ -1427,9 +1427,10 @@#ifdef MODULE MODULE_AUTHOR ("Simon G. Vogl <[email protected]>" );MODULE_DESCRIPTION ("I2C-Bus main module" ); +MODULE_LICENSE ("GPL" ); +MODULE_PARM (i2c_debug,"i" );MODULE_PARM_DESC (i2c_debug,"debug level" ); -MODULE_LICENSE ("GPL" );int init_module (void ) {
drivers/i2c/i2c-dev.c +4 -4
@@ -159,9 +159,9 @@struct i2c_client *client = (struct i2c_client *)file->private_data; -if (count >8192 ) +if (count >8192 ) count =8192 ; - +/* copy user space data to kernel space. */ tmp =kmalloc (count,GFP_KERNEL );if (tmp==NULL )
@@ -190,9 +190,9 @@struct inode *inode = file->f_dentry->d_inode;#endif /* DEBUG */ -if (count >8192 ) +if (count >8192 ) count =8192 ; - +/* copy user space data to kernel space. */ tmp =kmalloc (count,GFP_KERNEL );if (tmp==NULL )
drivers/i2c/i2c-elv.c +0 -1
@@ -202,7 +202,6 @@MODULE_DESCRIPTION ("I2C-Bus adapter routines for ELV parallel port adapter" );MODULE_LICENSE ("GPL" ); -MODULE_PARM (base,"i" );int init_module (void )
drivers/media/video/saa7110.c +1 -1
@@ -404,7 +404,7 @@ {"saa7110" ,/* name */ -I2C_DRIVERID_VIDEODECODER ,/* in i2c.h */ +I2C_DRIVERID_VIDEODECODER ,/* in i2c-old.h */ I2C_SAA7110 ,I2C_SAA7110 +1 ,/* Addr range */ saa7110_attach,
include/linux/i2c-id.h +2 -2
@@ -90,7 +90,7 @@#define I2C_DRIVERID_DRP3510 43/* ADR decoder (Astra Radio) */ #define I2C_DRIVERID_SP5055 44/* Satellite tuner */ #define I2C_DRIVERID_STV0030 45/* Multipurpose switch */ -#define I2C_DRIVERID_ADV717X 48/* video encoder */ +#define I2C_DRIVERID_ADV7175 48/* ADV 7175/7176 video encoder */ #define I2C_DRIVERID_MAX1617 56/* temp sensor */ #define I2C_DRIVERID_SAA7191 57/* video decoder */ #define I2C_DRIVERID_INDYCAM 58/* SGI IndyCam */
@@ -213,7 +213,7 @@#define I2C_HW_SMBUS_AMD756 0x05#define I2C_HW_SMBUS_SIS5595 0x06#define I2C_HW_SMBUS_ALI1535 0x07 -#define I2C_HW_SMBUS_W9968CF 0x08 +#define I2C_HW_SMBUS_W9968CF 0x0d/* --- ISA pseudo-adapter */ #define I2C_HW_ISA 0x00
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups (2/4)
In reply to Jean DelvareThis patch updates the i2c documentation files to what we have in our repository. There are various fixes, and a more complete protocol summary.
Please apply.
Documentation/i2c/dev-interface +1 -1
@@ -87,7 +87,7 @@ ioctl(file,I2C_TENBIT,long select) Selects ten bit addresses if select not equals 0, selects normal 7 bit - addresses if select equals 0. + addresses if select equals 0. Default 0. ioctl(file,I2C_FUNCS,unsigned long *funcs) Gets the adapter functionality and puts it in *funcs.
Documentation/i2c/i2c-protocol +3 -4
@@ -52,10 +52,10 @@ We have found some I2C devices that needs the following modifications: Flag I2C_M_NOSTART: - In a combined transaction, no 'S Addr' is generated at some point. - For example, setting I2C_M_NOSTART on the second partial message + In a combined transaction, no 'S Addr Wr/Rd [A]' is generated at some + point. For example, setting I2C_M_NOSTART on the second partial message generates something like: - S Addr Rd [A] [Data] NA Wr [A] Data [A] P + S Addr Rd [A] [Data] NA Data [A] P If you set the I2C_M_NOSTART variable for the first partial message, we do not generate Addr, but we do generate the startbit S. This will probably confuse all other clients on your bus, so don't try this.
@@ -65,4 +65,3 @@ need to emit an Rd instead of a Wr, or vice versa, you set this flag. For example: S Addr Rd [A] Data [A] Data [A] ... [A] Data [A] P -
Documentation/i2c/smbus-protocol +93 -4
125 lines not on this page · raw message
Documentation/i2c/summary +5 -5
@@ -4,7 +4,7 @@ ============= I2C (pronounce: I squared C) is a protocol developed by Philips. It is a -slow two-wire protocol (10-100 kHz), but it suffices for many types of +slow two-wire protocol (10-400 kHz), but it suffices for many types of devices. SMBus (System Management Bus) is a subset of the I2C protocol. Many
@@ -43,15 +43,15 @@ Included Bus Drivers ==================== -Note that not only stable drivers are patched into the kernel by 'mkpatch'. +Note that only stable drivers are patched into the kernel by 'mkpatch'. Base modules ------------ -i2c-core: The basic I2C code, including the /proc interface -i2c-dev: The /dev interface -i2c-proc: The /proc interface for device (client) drivers +i2c-core: The basic I2C code, including the /proc/bus/i2c* interface +i2c-dev: The /dev/i2c-* interface +i2c-proc: The /proc/sys/dev/sensors interface for device (client) drivers Algorithm drivers -----------------
Documentation/i2c/writing-clients +3 -3
@@ -365,7 +328,7 @@ The detect client function is called by i2c_probe or i2c_detect. The `kind' parameter contains 0 if this call is due to a `force' -parameter, and 0 otherwise (for i2c_detect, it contains 0 if +parameter, and -1 otherwise (for i2c_detect, it contains 0 if this call is due to the generic `force' parameter, and the chip type number if it is due to a specific `force' parameter).
@@ -448,9 +411,9 @@ /* Note that we reserve some space for foo_data too. If you don't need it, remove it. We do it here to help to lessen memory fragmentation. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client)) + + if (! (new_client = kmalloc(sizeof(struct i2c_client) + sizeof(struct foo_data), - GFP_KERNEL)) { + GFP_KERNEL))) { err = -ENOMEM; goto ERROR0; }
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups (3/4)
In reply to Jean DelvareThis patch fixes many (122) printk calls missing their KERN_* constant. There also are some other trivial fixes that were passing by (indentation changes and string changes).
Please apply.
drivers/i2c/i2c-algo-bit.c +22 -22
@@ -123,7 +123,7 @@if (current->need_resched)schedule (); } -DEBSTAT (printk ("needed %ld jiffies\n" , jiffies-start)); +DEBSTAT (printk (KERN_DEBUG "needed %ld jiffies\n" , jiffies-start));#ifdef SLO_IO SLO_IO#endif
@@ -179,12 +179,12 @@struct i2c_algo_bit_data *adap = i2c_adap->algo_data;/* assert: scl is low */ -DEB2 (printk (" i2c_outb:%2.2X\n" ,c&0xff )); +DEB2 (printk (KERN_DEBUG " i2c_outb:%2.2X\n" ,c&0xff ));for ( i=7 ; i>=0 ; i-- ) { sb = c & (1 << i );setsda (adap,sb);udelay (adap->udelay); -DEBPROTO (printk ("%d" ,sb!=0 )); +DEBPROTO (printk (KERN_DEBUG "%d" ,sb!=0 ));if (sclhi (adap)<0 ) {/* timed out */ sdahi (adap);/* we don't want to block the net */ return -ETIMEDOUT ;
@@ -201,10 +201,10 @@ };/* read ack: SDA should be pulled down by slave */ ack=getsda (adap);/* ack: sda is pulled low ->success. */ -DEB2 (printk (" i2c_outb: getsda() = 0x%2.2x\n" , ~ack )); +DEB2 (printk (KERN_DEBUG " i2c_outb: getsda() = 0x%2.2x\n" , ~ack )); -DEBPROTO (printk ("[%2.2x]" ,c&0xff ) ); - DEBPROTO(if (0==ack){ printk(" A ");} else printk(" NA ") ); +DEBPROTO (printk (KERN_DEBUG "[%2.2x]" ,c&0xff ) ); + DEBPROTO(if (0==ack){ printk(KERN_DEBUG " A ");} else printk(KERN_DEBUG " NA ") );scllo (adap);return 0 ==ack;/* return 1 if device acked */ /* assert: scl is low (sda undef) */
@@ -220,7 +220,7 @@struct i2c_algo_bit_data *adap = i2c_adap->algo_data;/* assert: scl is low */ -DEB2 (printk ("i2c_inb.\n" )); +DEB2 (printk (KERN_DEBUG "i2c_inb.\n" ));sdahi (adap);for (i=0 ;i<8 ;i++) {
@@ -233,7 +233,7 @@scllo (adap); }/* assert: scl is low */ -DEBPROTO (printk (" %2.2x" , indata &0xff )); +DEBPROTO (printk (KERN_DEBUG " 0x%02x" , indata &0xff ));return (int ) (indata &0xff ); }
@@ -341,7 +341,7 @@i2c_start (adap);udelay (adap->udelay); } - DEB2(if (i) printk("i2c-algo-bit.o: needed %d retries for %d\n", + DEB2(if (i) printk(KERN_DEBUG "i2c-algo-bit.o: needed %d retries for %d\n", i,addr));return ret; }
@@ -356,7 +356,7 @@while (count >0 ) { c = *temp; -DEB2 (printk ("i2c-algo-bit.o: %s i2c_write: writing %2.2X\n" , +DEB2 (printk (KERN_DEBUG "i2c-algo-bit.o: %s sendbytes: writing %2.2X\n" , i2c_adap->name, c&0xff )); retval =i2c_outb (i2c_adap,c);if (retval>0 ) {
@@ -364,7 +364,7 @@ temp++; wrcount++; }else {/* arbitration or no acknowledge */ -printk ("i2c-algo-bit.o: %s i2c_write: error - bailout.\n" , +printk (KERN_ERR "i2c-algo-bit.o: %s sendbytes: error - bailout.\n" , i2c_adap->name);i2c_stop (adap);return (retval<0 )? retval : -EFAULT ;
@@ -392,7 +392,7 @@ *temp = inval; rdcount++; }else {/* read timed out */ -printk ("i2c-algo-bit.o: i2c_read: i2c_inb timed out.\n" ); +printk (KERN_ERR "i2c-algo-bit.o: readbytes: i2c_inb timed out.\n" );break ; }
@@ -405,7 +405,7 @@ }if (sclhi (adap)<0 ) {/* timeout */ sdahi (adap); -printk ("i2c-algo-bit.o: i2c_read: Timeout at ack\n" ); +printk (KERN_ERR "i2c-algo-bit.o: readbytes: Timeout at ack\n" );return -ETIMEDOUT ; };scllo (adap);
@@ -435,18 +435,18 @@if ( (flags &I2C_M_TEN ) ) {/* a ten bit address */ addr =0xf0 | (( msg->addr >>7 ) &0x03 ); -DEB2 (printk ("addr0: %d\n" ,addr)); +DEB2 (printk (KERN_DEBUG "addr0: %d\n" ,addr));/* try extended address code...*/ ret =try_address (i2c_adap, addr, retries);if (ret!=1 ) { -printk ("died at extended address code.\n" ); +printk (KERN_ERR "died at extended address code.\n" );return -EREMOTEIO ; }/* the remaining 8 bit address */ ret =i2c_outb (i2c_adap,msg->addr &0x7f );if (ret !=1 ) {/* the chip did not ack / xmission error occurred */ -printk ("died at 2nd address code.\n" ); +printk (KERN_ERR "died at 2nd address code.\n" );return -EREMOTEIO ; }if ( flags &I2C_M_RD ) {
@@ -455,7 +455,7 @@ addr |=0x01 ; ret =try_address (i2c_adap, addr, retries);if (ret!=1 ) { -printk ("died at extended address code.\n" ); +printk (KERN_ERR "died at extended address code.\n" );return -EREMOTEIO ; } }
@@ -490,22 +490,22 @@ } ret =bit_doAddress (i2c_adap,pmsg,i2c_adap->retries);if (ret !=0 ) { -DEB2 (printk ("i2c-algo-bit.o: NAK from device adr %#2x msg #%d\n" - ,msgs[i].addr,i)); +DEB2 (printk (KERN_DEBUG "i2c-algo-bit.o: NAK from device addr %2.2x msg #%d\n" , + msgs[i].addr,i));return (ret<0 ) ? ret : -EREMOTEIO ; } }if (pmsg->flags &I2C_M_RD ) {/* read bytes into buffer*/ ret =readbytes (i2c_adap,pmsg->buf,pmsg->len); -DEB2 (printk ("i2c-algo-bit.o: read %d bytes.\n" ,ret)); +DEB2 (printk (KERN_DEBUG "i2c-algo-bit.o: read %d bytes.\n" ,ret));if (ret < pmsg->len ) {return (ret<0 )? ret : -EREMOTEIO ; } }else {/* write bytes from buffer */ ret =sendbytes (i2c_adap,pmsg->buf,pmsg->len); -DEB2 (printk ("i2c-algo-bit.o: wrote %d bytes.\n" ,ret)); +DEB2 (printk (KERN_DEBUG "i2c-algo-bit.o: wrote %d bytes.\n" ,ret));if (ret < pmsg->len ) {return (ret<0 ) ? ret : -EREMOTEIO ; }
@@ -555,7 +555,7 @@return -ENODEV ; } -DEB2 (printk ("i2c-algo-bit.o: hw routines for %s registered.\n" , +DEB2 (printk (KERN_DEBUG "i2c-algo-bit.o: hw routines for %s registered.\n" , adap->name));/* register new adapter to i2c module... */
drivers/i2c/i2c-algo-pcf.c +28 -28
207 lines not on this page · raw message
drivers/i2c/i2c-core.c +38 -38
284 lines not on this page · raw message
drivers/i2c/i2c-dev.c +16 -16
@@ -168,7 +168,7 @@return -ENOMEM ;#ifdef DEBUG -printk ("i2c-dev.o: i2c-%d reading %d bytes.\n" ,MINOR (inode->i_rdev), +printk (KERN_DEBUG "i2c-dev.o: i2c-%d reading %d bytes.\n" ,MINOR (inode->i_rdev), count);#endif
@@ -203,7 +203,7 @@ }#ifdef DEBUG -printk ("i2c-dev.o: i2c-%d writing %d bytes.\n" ,MINOR (inode->i_rdev), +printk (KERN_DEBUG "i2c-dev.o: i2c-%d writing %d bytes.\n" ,MINOR (inode->i_rdev), count);#endif ret =i2c_master_send (client,tmp,count);
@@ -224,7 +224,7 @@unsigned long funcs;#ifdef DEBUG -printk ("i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n" , +printk (KERN_DEBUG "i2c-dev.o: i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n" ,MINOR (inode->i_rdev),cmd, arg);#endif /* DEBUG */
@@ -346,7 +346,7 @@ (data_arg.size != I2C_SMBUS_BLOCK_DATA) && (data_arg.size != I2C_SMBUS_I2C_BLOCK_DATA)) {#ifdef DEBUG -printk ("i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n" , +printk (KERN_DEBUG "i2c-dev.o: size out of range (%x) in ioctl I2C_SMBUS.\n" , data_arg.size);#endif return -EINVAL ;
@@ -356,7 +356,7 @@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" , +printk (KERN_DEBUG "i2c-dev.o: read_write out of range (%x) in ioctl I2C_SMBUS.\n" , data_arg.read_write);#endif return -EINVAL ;
@@ -376,7 +376,7 @@if (data_arg.data ==NULL ) {#ifdef DEBUG -printk ("i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n" ); +printk (KERN_DEBUG "i2c-dev.o: data is NULL pointer in ioctl I2C_SMBUS.\n" );#endif return -EINVAL ; }
@@ -418,7 +418,7 @@if ((minor >=I2CDEV_ADAPS_MAX ) || ! (i2cdev_adaps[minor])) {#ifdef DEBUG -printk ("i2c-dev.o: Trying to open unattached adapter i2c-%d\n" , +printk (KERN_DEBUG "i2c-dev.o: Trying to open unattached adapter i2c-%d\n" , minor);#endif return -ENODEV ;
@@ -439,7 +439,7 @@#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */ #ifdef DEBUG -printk ("i2c-dev.o: opened i2c-%d\n" ,minor); +printk (KERN_DEBUG "i2c-dev.o: opened i2c-%d\n" ,minor);#endif return 0 ; }
@@ -450,7 +450,7 @@kfree (file->private_data); file->private_data=NULL ;#ifdef DEBUG -printk ("i2c-dev.o: Closed: i2c-%d\n" , minor); +printk (KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n" , minor);#endif #if LINUX_KERNEL_VERSION <KERNEL_VERSION (2 ,4 ,0 )MOD_DEC_USE_COUNT ;
@@ -471,11 +471,11 @@char name[8 ];if ((i =i2c_adapter_id (adap)) <0 ) { -printk ("i2c-dev.o: Unknown adapter ?!?\n" ); +printk (KERN_DEBUG "i2c-dev.o: Unknown adapter ?!?\n" );return -ENODEV ; }if (i >=I2CDEV_ADAPS_MAX ) { -printk ("i2c-dev.o: Adapter number too large?!? (%d)\n" ,i); +printk (KERN_DEBUG "i2c-dev.o: Adapter number too large?!? (%d)\n" ,i);return -ENODEV ; }
@@ -488,7 +488,7 @@S_IFCHR |S_IRUSR |S_IWUSR , &i2cdev_fops, NULL);#endif -printk ("i2c-dev.o: Registered '%s' as minor %d\n" ,adap->name,i); +printk (KERN_DEBUG "i2c-dev.o: Registered '%s' as minor %d\n" ,adap->name,i); }else {/* This is actually a detach_adapter call! */ #ifdef CONFIG_DEVFS_FS
@@ -496,7 +496,7 @@#endif i2cdev_adaps[i] =NULL ;#ifdef DEBUG -printk ("i2c-dev.o: Adapter unregistered: %s\n" ,adap->name); +printk (KERN_DEBUG "i2c-dev.o: Adapter unregistered: %s\n" ,adap->name);#endif }
@@ -518,7 +518,7 @@ {int res; -printk ("i2c-dev.o: i2c /dev entries driver module\n" ); +printk (KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n" ,I2C_VERSION ,I2C_DATE ); i2cdev_initialized =0 ;#ifdef CONFIG_DEVFS_FS
@@ -526,7 +526,7 @@#else if (register_chrdev (I2C_MAJOR ,"i2c" ,&i2cdev_fops)) {#endif -printk ("i2c-dev.o: unable to get major %d for i2c bus\n" , +printk (KERN_ERR "i2c-dev.o: unable to get major %d for i2c bus\n" ,I2C_MAJOR );return -EIO ; }
@@ -536,7 +536,7 @@ i2cdev_initialized ++;if ((res =i2c_add_driver (&i2cdev_driver))) { -printk ("i2c-dev.o: Driver registration failed, module not inserted.\n" ); +printk (KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n" );i2cdev_cleanup ();return res; }
drivers/i2c/i2c-elektor.c +11 -9
@@ -78,7 +78,7 @@ val |=I2C_PCF_ENI ; } -DEB3 (printk ("i2c-elektor.o: Write 0x%X 0x%02X\n" , address, val &255 )); +DEB3 (printk (KERN_DEBUG "i2c-elektor.o: Write 0x%X 0x%02X\n" , address, val &255 ));switch (mmapped) {case 0 :/* regular I/O */
@@ -99,7 +99,7 @@int address = ctl ? (base +1 ) : base;int val = mmapped ?readb (address) :inb (address); -DEB3 (printk ("i2c-elektor.o: Read 0x%X 0x%02X\n" , address, val)); +DEB3 (printk (KERN_DEBUG "i2c-elektor.o: Read 0x%X 0x%02X\n" , address, val));return (val); }
@@ -142,7 +142,9 @@ {if (!mmapped) {if (check_region (base,2 ) <0 ) { -printk ("i2c-elektor.o: requested I/O region (0x%X:2) is in use.\n" , base); +printk (KERN_ERR +"i2c-elektor.o: requested I/O region (0x%X:2) " +"is in use.\n" , base);return -ENODEV ; }else {request_region (base,2 ,"i2c (isa bus adapter)" );
@@ -150,7 +152,7 @@ }if (irq >0 ) {if (request_irq (irq, pcf_isa_handler,0 ,"PCF8584" ,0 ) <0 ) { -printk ("i2c-elektor.o: Request irq%d failed\n" , irq); +printk (KERN_ERR "i2c-elektor.o: Request irq%d failed\n" , irq); irq =0 ; }else enable_irq (irq);
@@ -238,7 +240,7 @@/* yeap, we've found cypress, let's check config */ if (!pci_read_config_byte (cy693_dev,0x47 , &config)) { -DEB3 (printk ("i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n" , config)); +DEB3 (printk (KERN_DEBUG "i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n" , config));/* UP2000 board has this register set to 0xe1, but the most significant bit as seems can be
@@ -260,7 +262,7 @@8.25 MHz (PCI/4) clock (this can be read from cypress) */ clock =I2C_PCF_CLK |I2C_PCF_TRNS90 ; -printk ("i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n" ); +printk (KERN_INFO "i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n" ); } } }
@@ -269,11 +271,11 @@/* sanity checks for mmapped I/O */ if (mmapped && base <0xc8000 ) { -printk ("i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n" , base); +printk (KERN_ERR "i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n" , base);return -ENODEV ; } -printk ("i2c-elektor.o: i2c pcf8584-isa adapter module\n" ); +printk (KERN_INFO "i2c-elektor.o: i2c pcf8584-isa adapter module version %s (%s)\n" ,I2C_VERSION ,I2C_DATE );if (base ==0 ) { base =DEFAULT_BASE ;
@@ -289,7 +291,7 @@return -ENODEV ; } -printk ("i2c-elektor.o: found device at %#x.\n" , base); +printk (KERN_DEBUG "i2c-elektor.o: found device at %#x.\n" , base);return 0 ; }
drivers/i2c/i2c-elv.c +4 -4
@@ -95,14 +95,14 @@ }else {/* test for ELV adap. */ if (inb (base+1 ) &0x80 ) {/* BUSY should be high */ -DEBINIT (printk ("i2c-elv.o: Busy was low.\n" )); +DEBINIT (printk (KERN_DEBUG "i2c-elv.o: Busy was low.\n" ));return -ENODEV ; }else {outb (0x0c ,base+2 );/* SLCT auf low */ udelay (400 );if ( !(inb (base+1 ) &&0x10 ) ) {outb (0x04 ,base+2 ); -DEBINIT (printk ("i2c-elv.o: Select was high.\n" )); +DEBINIT (printk (KERN_DEBUG "i2c-elv.o: Select was high.\n" ));return -ENODEV ; } }
@@ -170,7 +170,7 @@int __init i2c_bitelv_init (void ) { -printk ("i2c-elv.o: i2c ELV parallel port adapter module\n" ); +printk (KERN_INFO "i2c-elv.o: i2c ELV parallel port adapter module version %s (%s)\n" ,I2C_VERSION ,I2C_DATE );if (base==0 ) {/* probe some values */ base=DEFAULT_BASE ;
@@ -190,7 +190,7 @@return -ENODEV ; } } -printk ("i2c-elv.o: found device at %#x.\n" ,base); +printk (KERN_DEBUG "i2c-elv.o: found device at %#x.\n" ,base);return 0 ; }
drivers/i2c/i2c-philips-par.c +5 -5
@@ -190,18 +190,18 @@struct i2c_par *adapter =kmalloc (sizeof (struct i2c_par ),GFP_KERNEL );if (!adapter) { -printk ("i2c-philips-par: Unable to malloc.\n" ); +printk (KERN_ERR "i2c-philips-par: Unable to malloc.\n" );return ; } -printk ("i2c-philips-par.o: attaching to %s\n" , port->name); +printk (KERN_DEBUG "i2c-philips-par.o: attaching to %s\n" , port->name); adapter->pdev =parport_register_device (port,"i2c-philips-par" ,NULL ,NULL ,NULL ,PARPORT_FLAG_EXCL ,NULL );if (!adapter->pdev) { -printk ("i2c-philips-par: Unable to register with parport.\n" ); +printk (KERN_ERR "i2c-philips-par: Unable to register with parport.\n" );return ; }
@@ -218,7 +218,7 @@if (i2c_bit_add_bus (&adapter->adapter) <0 ) { -printk ("i2c-philips-par: Unable to register with I2C.\n" ); +printk (KERN_ERR "i2c-philips-par: Unable to register with I2C.\n" );parport_unregister_device (adapter->pdev);kfree (adapter);return ;/* No good */
@@ -264,7 +264,7 @@#if LINUX_VERSION_CODE <KERNEL_VERSION (2 ,3 ,4 )struct parport *port;#endif -printk ("i2c-philips-par.o: i2c Philips parallel port adapter module\n" ); +printk (KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n" ,I2C_VERSION ,I2C_DATE );#if LINUX_VERSION_CODE >=KERNEL_VERSION (2 ,3 ,4 )parport_register_driver (&i2c_driver);
drivers/i2c/i2c-proc.c +10 -14
@@ -38,10 +38,6 @@#include <linux/init.h> -/* FIXME need i2c versioning */ -#define LM_DATE "20010825" -#define LM_VERSION "2.6.1" -#ifndef THIS_MODULE #define THIS_MODULE NULL#endif
@@ -684,7 +680,7 @@ && (addr == this_force->force[j + 1])) {#ifdef DEBUG printk - ("i2c-proc.o: found force parameter for adapter %d, addr %04x\n" , + (KERN_DEBUG "i2c-proc.o: found force parameter for adapter %d, addr %04x\n" , adapter_id, addr);#endif if (
@@ -714,7 +710,7 @@ && (addr == address_data->ignore[i + 1])) {#ifdef DEBUG printk - ("i2c-proc.o: found ignore parameter for adapter %d, " + (KERN_DEBUG "i2c-proc.o: found ignore parameter for adapter %d, " "addr %04x\n" , adapter_id, addr);#endif found =1 ;
@@ -734,7 +730,7 @@ && (addr <= address_data->ignore_range[i + 2])) {#ifdef DEBUG printk - ("i2c-proc.o: found ignore_range parameter for adapter %d, " + (KERN_DEBUG "i2c-proc.o: found ignore_range parameter for adapter %d, " "addr %04x\n" , adapter_id, addr);#endif found =1 ;
@@ -753,7 +749,7 @@if (addr == address_data->normal_isa[i]) {#ifdef DEBUG printk - ("i2c-proc.o: found normal isa entry for adapter %d, " + (KERN_DEBUG "i2c-proc.o: found normal isa entry for adapter %d, " "addr %04x\n" , adapter_id, addr);#endif
@@ -775,7 +771,7 @@ 0)) {#ifdef DEBUG printk - ("i2c-proc.o: found normal isa_range entry for adapter %d, " + (KERN_DEBUG "i2c-proc.o: found normal isa_range entry for adapter %d, " "addr %04x" , adapter_id, addr);#endif found =1 ;
@@ -789,7 +785,7 @@ found =1 ;#ifdef DEBUG printk - ("i2c-proc.o: found normal i2c entry for adapter %d, " + (KERN_DEBUG "i2c-proc.o: found normal i2c entry for adapter %d, " "addr %02x" , adapter_id, addr);#endif }
@@ -805,7 +801,7 @@ {#ifdef DEBUG printk - ("i2c-proc.o: found normal i2c_range entry for adapter %d, " + (KERN_DEBUG "i2c-proc.o: found normal i2c_range entry for adapter %d, " "addr %04x\n" , adapter_id, addr);#endif found =1 ;
@@ -822,7 +818,7 @@ && (addr == address_data->probe[i + 1])) {#ifdef DEBUG printk - ("i2c-proc.o: found probe parameter for adapter %d, " + (KERN_DEBUG "i2c-proc.o: found probe parameter for adapter %d, " "addr %04x\n" , adapter_id, addr);#endif found =1 ;
@@ -841,7 +837,7 @@ found =1 ;#ifdef DEBUG printk - ("i2c-proc.o: found probe_range parameter for adapter %d, " + (KERN_DEBUG "i2c-proc.o: found probe_range parameter for adapter %d, " "addr %04x\n" , adapter_id, addr);#endif }
@@ -862,7 +858,7 @@int __init sensors_init (void ) { -printk ("i2c-proc.o version %s (%s)\n" ,LM_VERSION ,LM_DATE ); +printk (KERN_INFO "i2c-proc.o version %s (%s)\n" ,I2C_VERSION ,I2C_DATE ); i2c_initialized =0 ; if (! (i2c_proc_header =
drivers/i2c/i2c-velleman.c +2 -2
@@ -160,7 +160,7 @@int __init i2c_bitvelle_init (void ) { -printk ("i2c-velleman.o: i2c Velleman K8000 adapter module\n" ); +printk (KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n" ,I2C_VERSION ,I2C_DATE );if (base==0 ) {/* probe some values */ base=DEFAULT_BASE ;
@@ -180,7 +180,7 @@return -ENODEV ; } } -printk ("i2c-velleman.o: found device at %#x.\n" ,base); +printk (KERN_DEBUG "i2c-velleman.o: found device at %#x.\n" ,base);return 0 ; }
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups (4/4)
In reply to Jean DelvareThis small patch fixes the pcmcia sa1100 driver including the i2c.h header, while it doesn't make any use of it. I found that while working on my various i2c patches.
Please apply.
drivers/pcmcia/sa1100_stork.c renamed from drivers/pcmcia/sa1100_stork.c.orig +0 -1
@@ -24,7 +24,6 @@#include <linux/init.h> #include <linux/kernel.h> #include <linux/sched.h> -#include <linux/i2c.h> #include <asm/hardware.h> #include <asm/irq.h>
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups
In reply to Jean DelvareThe 4 patches were accepted, you can see them in 2.4.23-bk13. A first battle we won :) but the war is far from being over.
From 246kB for the patch that was required to update Linux 2.4.23 to i2c 2.8.2, the patch size is reduced to 215kB with 2.4.23-bk13. If we leave apart the new drivers, which I don't plan to submit, the remaining size is 129k. This basically means that I've only done one fifth of the job so far. I will sumbit another wave of patches as soon as possible.
There's something I would need help with. The main reason why we are submitting patches is the change in the way module references are counted. Sooner or later I'll have to submit a patch for that point. I read on this list that the new method might not be correct though. I don't want to submit a buggy patch this late in Linux 2.4's life, but on the other hand I don't have the knowledge nor time to solve the problem, if there is one. So I would like someone to review that part of our code, to tell me if this is correct or not and why, and to commit the required changes to our i2c CVS repository, if needed.
Ky?sti, you seem to understand the problem rather well, so I was hoping you could help me here. MDS and Greg also would probably be able to help. Guys, please work it out if you can. And remember that time is against us, since a structure change won't be accepted after 2.4.24 is released (it's not even sure it will be accepted *before*...)
If anyone else wants to help, this is very welcome too, of course ;)
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 7 lines · Ky?sti M?lkki
For kernel 2.6: kobjects. This is the essentials of driver-model and sysfs allowing a tree-like topology of devices and drivers. Reference a device on the bus, and its driver and parent device are also referenced. In turn, this would obsolete .owner if driver-model gets more thoroughly implemented during 2.7 cycle. I have some compiling and running code for that, will post for review on holidays.
No, kobjects have _nothing_ to do with module references. In fact, that's the headache of module reference counts in a nutshell, kobject, properly reference count the data structures, but the module reference count is needed to properly protect the code itself from going away.
For files that users open within sysfs, kobjects now properly increment the module reference count. But for other modules that grab structures from your module, you need to make sure the module reference counting is correct.
Or just disable CONFIG_MODULE_UNLOAD, and not worry about it at all :)
thanks,
greg k-h
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 3 lines
For kernel 2.2 : MOD_INC/DEC_USE_COUNT and necessary callbacks in the i2c structs. I _think_ there was some race condition of calling rmmod to release the module and another process half-way to
MOD_INC_COUNT.
I read about that.
Quoted 7 lines
For kernel 2.4 : Replace
MOD_INC_COUNTwithtry_inc_mod_count(), this may fail if the module in question is about to be removed from kernel. The callback ini2c_adapterandi2c_driveris void (*inc_use)() so the choice of exporting .owner=THIS_MODULE to i2c-core as was already done in 2.5 tree seemed like the correct choice. This is the essential question whether the cleanup is just an api change or a real bugfix.
This is an API change, that replaces a small bug (the race condition) with a big one (module reference counting is plain dead broken, as you and I underline below).
I can't see any call to with try_inc_mod_count() in our sources. Is it supposed to be automatically called as soon as you use the .owner=THIS_MODULE trick?
Quoted 6 lines
A problem I see there is procfs allowing only one module reference per opened file. In terms of i2c architecture, we need to hold both adapter and driver modules in place. Currently neither is done and I think it will oops if you enter a directory under
/proc/sys/dev/sensorsand rmmod either of the two hw interface modules.
Yes, I could oops the kernel doing so. Went to the proc/dev/sys/sensors/somechip directory, removed the chip driver, the directory was still there and empty. Moved away, removed the bus driver, moved back to the proc/.../somechip directory, *oops*.
As a comparison, doing the same with the older module count method (i2c and lm_sensors 2.7.0), removing the chip module while standing in its directory wouldn't be possible. OTOH, removing the bus driver module would be possible, resulting in the proc/.../somechip going empty but not being deleted of course. Moving out of the proc tree would let me remove the chip driver. There must be a bug somewhere though since i2c-proc now has a refcount of 1 instead of 0 so that I can't remove it anymore. But at least there is no oops.
So the new code can be seen as a regression when compared with the old one, and I won't possibly send this to Marcelo until it is fixed.
Quoted 1 line
The
fill_inodefrom days of 2.2.x does not seem either.
What do you mean?
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 2 lines
correct. see Ticket #331.
I don't see this as a big problem though.
I am not refering to the race condition that existed with the old method. This was due to the general design of modules in Linux 2.2 if I understood it correctly. There's nothing we could do about it.
The real problem is that the move to 2.4 method with .owner=THIS_MODULE, which was supposed to fix that, was not done correctly and that accessing the /proc interface doesn't lock the modules at all, so it's very easy to get the kernel to oops. Of course we can tell the users not to do it, and I'm sure almost none of our users ever experienced the problem, still that's not acceptable to submit such a change for inclusion into the Linux 2.4 kernel.
I'd like to remind everyone that I'm currently trying to get i2c 2.8.2 into the 2.4.24 kernel only because of this structure change. If it turns our that the structure change isn't going to make it into 2.4 anyway, then I'm wasting my time and Marcelo's too.
Quoted 2 lines
Unfortunately, most of this is over my head so don't expect me to contribute much to a review of Khali's patch.
It's far over my head too. But there must be someone who decided we would change to the new referening style. Ky?sti I suppose? If nobody here is able to propose an acceptable solution to fix the problem, we'll have to undo all the changes and come back to the old reference counting mechanism as it exists in the Linux 2.4 kernel, so that we ensure the compatibility with existing i2c drivers again.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 9 lines
Related links to refcount discussion:
[OKS] Module removal
http://www.ussg.iu.edu/hypermail/linux/kernel/0207.0/index.html#86
Module Refcount & Stuff mini-FAQ
http://www.ussg.iu.edu/hypermail/linux/kernel/0211.2/0697.html
I read it all (really). Very interesting indeed, but that looks much like work-in-progess discussions between kernel core developers.
How do we solve our problem?
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 5 lines
Quoted 3 lines
This is an API change, that replaces a small bug (the race condition) with a big one (module reference counting is plain dead broken, as you and I underline below).
These are two independent issues.
I don't think you call label them as independant. They are different, but related issues. The problem is that I cannot send a patch to Marcelo that fixes a small bug and adds a big one. That the two bugs are "independant" doesn't matter.
Quoted 4 lines
For some time, I have not reviewed video4linux, or other i2c drivers. They really should call i2c_use/release_client before referencing the client structure or using the
client->driver->command()method for inter-module calls.
Other i2c drivers (in Linux 2.4 world) still use the i2c interface as of 2.6.1. This is precisely why the recent structure change is causing so much trouble.
We'd better have our own drivers handle references correctly before ever thinking of merging the change into Linux 2.4 and fixing all other i2c drivers.
Quoted 10 lines
Strange that you found any difference, in either case it will call
unregister_sysctl_tablewith a busy table. Somewhere deep in procfs this fails, but we go ahead and free the table anyway ini2c_deregister_entry.Solution: Prevent chip detach while sysctl table is busy, means reference counting both the bus and the chip modules. This needs an API change on the user side: Move ... sensors/somechip-0-2d to sensors/bus-0/somechip-2d. That way bus module is referenced on the path.
Do you seriously think we should do that? This sounds like a very big change for a near-end-of-life kernel tree. OK, I think I understand this would be the only way to have references handled correctly. But for now we don't handle them at all. What about handling chip drivers counts correctly and forget about bus drivers counts? That's the way things were done with the old method (up to i2c 2.7.0) so I would feel less uncomfortable sending such a patch to Marcelo, since there would be no regression anymore, and still the race condition fixed.
Also, I confirm that I would possibly obtain a segfault using 2.7.0 if I remove a bus driver while in some /proc/.../somechip directory, move elsewhere, remove the chip driver and come back. I guess this was expected.
Ky?sti, what would it take to restore correct module reference counting on chip drivers? Does it require to update only i2c-core and i2c-proc, or would we have to update all drivers? Please help me with this. This is required in order to have any serious patch sent to Marcelo, and you're the one of us all understanding all these things at best, it seems.
Quoted 3 lines
Does not seem _correct_ either. A call to
i2c_fill_inodeincrements only i2c-proc module reference. It was already counted as soon as you entered/proc/sys/dev/sensors/.
Is it something that should be fixed, or that already was, or neither?
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 11 lines · On 12/17/03 16:50 Ky?sti M?lkki wrote:
Long story short, as I recall it.
For kernel 2.4 : Replace
MOD_INC_COUNTwithtry_inc_mod_count(), this may fail if the module in question is about to be removed from kernel. The callback ini2c_adapterandi2c_driveris void (*inc_use)() so the choice of exporting .owner=THIS_MODULE to i2c-core as was already done in 2.5 tree seemed like the correct choice. This is the essential question whether the cleanup is just an api change or a real bugfix.
Quoted 7 lines
A problem I see there is procfs allowing only one module reference per opened file. In terms of i2c architecture, we need to hold both adapter and driver modules in place. Currently neither is done and I think it will oops if you enter a directory under
/proc/sys/dev/sensorsand rmmod either of the two hw interface modules. Thefill_inodefrom days of 2.2.x does not seem either.
correct. see Ticket #331.
I don't see this as a big problem though.
Unfortunately, most of this is over my head so don't expect me to contribute much to a review of Khali's patch.
mds
PATCH 1/1 i2c cleanups
In reply to Jean DelvareLong story short, as I recall it.
For kernel 2.2 : MOD_INC/DEC_USE_COUNT and necessary callbacks in the i2c structs. I _think_ there was some race condition of calling rmmod to release the module and another process half-way to MOD_INC_COUNT.
For kernel 2.4 : Replace MOD_INC_COUNT with try_inc_mod_count(), this may fail if the module in question is about to be removed from kernel. The callback in i2c_adapter and i2c_driver is void (*inc_use)() so the choice of exporting .owner=THIS_MODULE to i2c-core as was already done in 2.5 tree seemed like the correct choice. This is the essential question whether the cleanup is just an api change or a real bugfix.
A problem I see there is procfs allowing only one module reference per opened file. In terms of i2c architecture, we need to hold both adapter and driver modules in place. Currently neither is done and I think it will oops if you enter a directory under /proc/sys/dev/sensors and rmmod either of the two hw interface modules. The fill_inode from days of 2.2.x does not seem either.
For kernel 2.6: kobjects. This is the essentials of driver-model and sysfs allowing a tree-like topology of devices and drivers. Reference a device on the bus, and its driver and parent device are also referenced. In turn, this would obsolete .owner if driver-model gets more thoroughly implemented during 2.7 cycle. I have some compiling and running code for that, will post for review on holidays.
Maybe someone can pop more details right off their stack.
Signature · 1 line
Ky?sti M?lkki <[email protected]>
PATCH 1/1 i2c cleanups
In reply to Jean DelvareRelated links to refcount discussion:
[OKS] Module removal
http://www.ussg.iu.edu/hypermail/linux/kernel/0207.0/index.html#86
Module Refcount & Stuff mini-FAQ
http://www.ussg.iu.edu/hypermail/linux/kernel/0211.2/0697.html
Signature · 1 line
Ky?sti M?lkki <[email protected]>
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 3 lines · Jean Delvare
This is an API change, that replaces a small bug (the race condition) with a big one (module reference counting is plain dead broken, as you and I underline below).
These are two independent issues.
Seems i2c-proc, i2c_register_entry is "fixed,debugged,fixed,merged and still broken". The .owner is a direct replacement of passing controlling_mod (THIS_MODULE from chip driver).
Quoted 3 lines
I can't see any call to with
try_inc_mod_count()in our sources. Is it supposed to be automatically called as soon as you use the .owner=THIS_MODULE trick?
When you open a file in procfs, yes. For some time, I have not reviewed video4linux, or other i2c drivers. They really should call i2c_use/release_client before referencing the client structure or using the client->driver->command() method for inter-module calls.
Quoted 12 lines
Quoted 6 lines
A problem I see there is procfs allowing only one module reference per opened file. In terms of i2c architecture, we need to hold both adapter and driver modules in place. Currently neither is done and I think it will oops if you enter a directory under
/proc/sys/dev/sensorsand rmmod either of the two hw interface modules.Yes, I could oops the kernel doing so. Went to the proc/dev/sys/sensors/somechip directory, removed the chip driver, the directory was still there and empty. Moved away, removed the bus driver, moved back to the proc/.../somechip directory, *oops*.
Quoted 8 lines
As a comparison, doing the same with the older module count method (i2c and
lm_sensors2.7.0), removing the chip module while standing in its directory wouldn't be possible. OTOH, removing the bus driver module would be possible, resulting in the proc/.../somechip going empty but not being deleted of course. Moving out of the proc tree would let me remove the chip driver. There must be a bug somewhere though since i2c-proc now has a refcount of 1 instead of 0 so that I can't remove it anymore. But at least there is no oops.
Strange that you found any difference, in either case it will call unregister_sysctl_table with a busy table. Somewhere deep in procfs this fails, but we go ahead and free the table anyway in i2c_deregister_entry.
Solution: Prevent chip detach while sysctl table is busy, means reference counting both the bus and the chip modules. This needs an API change on the user side: Move ... sensors/somechip-0-2d to sensors/bus-0/somechip-2d. That way bus module is referenced on the path.
Quoted 3 lines
Quoted 1 line
The
fill_inodefrom days of 2.2.x does not seem either.What do you mean?
Does not seem _correct_ either. A call to i2c_fill_inode increments only i2c-proc module reference. It was already counted as soon as you entered /proc/sys/dev/sensors/.
Signature · 1 line
Ky?sti M?lkki <[email protected]>
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 7 lines
Quoted 6 lines
Solution: Prevent chip detach while sysctl table is busy, means reference counting both the bus and the chip modules. This needs an API change on the user side: Move ... sensors/somechip-0-2d to sensors/bus-0/somechip-2d. That way bus module is referenced on the path.
Quoted 8 lines
Do you seriously think we should do that? This sounds like a very big change for a near-end-of-life kernel tree. OK, I think I understand this would be the only way to have references handled correctly. But for now we don't handle them at all. What about handling chip drivers counts correctly and forget about bus drivers counts? That's the way things were done with the old method (up to i2c 2.7.0) so I would feel less uncomfortable sending such a patch to Marcelo, since there would be no regression anymore, and still the race condition fixed.
Let's start by fixing the chip count.
Quoted 6 lines
Ky?sti, what would it take to restore correct module reference counting on chip drivers? Does it require to update only i2c-core and i2c-proc, or would we have to update all drivers? Please help me with this. This is required in order to have any serious patch sent to Marcelo, and you're the one of us all understanding all these things at best, it seems.
If we only get .owner in adapter and driver structure, I can keep the changes within i2c-core and i2c-proc. Did you have a collection of video4linux drivers, with i2c dependency, easily available ? Seems i2c drivers in kernel tree 2.4.23 drivers/media/video handle reference counting internally; They get reference as soon as the client is attached to adapter. One has to rmmod bus before chip.
Quoted 5 lines
Quoted 3 lines
Does not seem _correct_ either. A call to
i2c_fill_inodeincrements only i2c-proc module reference. It was already counted as soon as you entered/proc/sys/dev/sensors/.Is it something that should be fixed, or that already was, or neither?
Kernel 2.2 stuff. I was mistaken, there is i2c_fill_inode and i2c_dir_fill_inode and the latter does handle chip reference, but not the adapter. Ironically, for kernels 2.2 it would be easy to fix.
I will prepare a set of incremental patches from the CVS with minimal changes, with compatible API. Binary compatibility not maintained.
Signature · 1 line
Ky?sti M?lkki <[email protected]>
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 6 lines
Jean, here is something to start with. Tested to apply cleanly over 2.4.23 after your set of 4 patches.
Patch -km-1 :
Remove code for
KERNEL_VERSIONtests.
Great. This was on my TODO list. I think I'll tweak it a bit, to remove version.h includes which aren't necessary anymore (I guess) and merge empty lines where it applies. Also, this patch might conflict with the one I wrote on posted to the list yesterday (which cleans modules init/exit handling). But basically you got it, this is something I wanted to send to Marcelo.
Quoted 4 lines
Patch -km-2 :
This has .owner and .inc/dec_use for reference counting. Also, C99 initializers and initcalls are imported from i2c CVS head.
What are initcalls.
Quoted 1 line
No new drivers, SMBus commands or driver ID's.
Good point.
Quoted 2 lines
This is about 1/4 of changes needed to bring 2.4.24 in-sync with i2c 2.8.2.
Sure this is an important part, this is even the reason why all these started.
But there's a problem. As discussed on the list the last few days, i2c as of CVS head does not handle module reference counting correctly. So we cannot possibly send this patch to Marcelo before this issue is fixed. Since you seem to know how to fix it, please commit the necessary changes to CVS head (I don't think it is a good idea to branch the CVS, it's just not worth it). I do well understand that, even with the fix, the reference counting will be broken, but at least it won't be worse than in the previous implementation (that is, moving into /proc/.../somechip/ increases the chip use count, but not the bus use count). This is required before we can send any inc/dec-to-owner patch to Marcelo.
Quoted 2 lines
At least i2c-proc is not yet in sync with 2.8.0, so sensor chips will not build.
This was expected. They don't build either as of now anyway ;)
Quoted 3 lines
I probably forgot some tiny parts elsewhere too but seems you were working on similar cleanups so maybe this is some assistance.
Your help is very appreciated, since there is much much work to do and we are runnign out of time.
Quoted 1 line
We cannot get 200kB+ patches through anyway.
Yes, that's the idea (and I don't consider it a problem, since this ensures that what we are sending is valid and doesn't bring any regression into the kernel tree).
Quoted 4 lines
I'll prepare some more patches today. Driver ID's, SMBus commands, and i2c-proc. The in-file revision tag $id has not been in sync with CVS files for ages and I plan to unexpand them with a separate patch.
IDs is an easy and independant patch, I should be able to go with it if you don't.
New SMBus commands are not to be commited for now, if ever. They are new
functionalities, I doubt Marcelo will want them into Linux 2.4.
The i2c-proc patches (and anything related to the core or spread over all drivers) are what is more important, both because it might need to be done before other minor changes, and because I don't understand it too well, so that's where your help will be really precious.
Thanks a lot for providing assistance in backporting CVS to Linux 2.4. Keep in mind that all changes have to be as sliced as possible if we want them accepted.
I will be submitting a new wave of patches to Marcelo rather soon, which should include (list is not definitive):
- init/exit cleanups (me)
- compatibility cleanups (you)
- velleman doc (me)
- algo debug stuff removal (me)
I'll let you know as soon as I'm working on other patches so that we can merge our efforts efficiently.
Thanks again.
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 1 line
Forget about -km-2 and -km-6. I will post them in smaller parts.
Never received -km-6, so I can forget about it very easily ;) What about -km-4?
As for -km-2, don't forget that there is no real use splitting patches if parts cannot be applied independantly. And I repeat myself, please first fix module reference counting in CVS before posting any patch related to this point. Again, we cannot send anything to Marcelo with regression in it.
Quoted 7 lines
Patch -km-7 : Drop 2.2 code.
Patch -km-8 : User progs don't include kernel files. Patch -km-9 : Message block size.
Patch -km-10 : RemoveSLO_IOin algo-bit. Patch -km-11 : Bus scan removal, bit & pcf. Patch -km-12 : Add new IDs.
Patch -km-13 : Unused code, whitespace.
Great. I already have patches for 10 and 11 (more complete since it also handles drivers that are not in our CVS repository). I will take a look at your patches in a while, as time permits.
Quoted 1 line
Yes, christmas got cancelled ;)
;) You know, we merely depend on Marcelo for having our patches applied. I don't plan to submit anything new until he approved (or disapproved) the previous wave of patches. This of course doesn't prevent us from working on new patches, but there's no need skipping Christmas if you don't want to. Unless you, like I, don't enjoy these days too much and were after some kind of excuse for missing them ;)
Signature · 2 lines
Jean Delvare http://www.ensicaen.ismra.fr/~delvare/
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 2 lines · Ky?sti M?lkki
I will prepare a set of incremental patches from the CVS with minimal changes, with compatible API. Binary compatibility not maintained.
Jean, here is something to start with. Tested to apply cleanly over 2.4.23 after your set of 4 patches.
Patch -km-1 :
Remove code for KERNEL_VERSION tests.
Patch -km-2 :
This has .owner and .inc/dec_use for reference counting. Also, C99 initializers and initcalls are imported from i2c CVS head. No new drivers, SMBus commands or driver ID's. This is about 1/4 of changes needed to bring 2.4.24 in-sync with i2c 2.8.2.
At least i2c-proc is not yet in sync with 2.8.0, so sensor chips will not build. I probably forgot some tiny parts elsewhere too but seems you were working on similar cleanups so maybe this is some assistance. We cannot get 200kB+ patches through anyway.
I'll prepare some more patches today. Driver ID's, SMBus commands, and i2c-proc. The in-file revision tag $id has not been in sync with CVS files for ages and I plan to unexpand them with a separate patch.
Signature · 1,928 lines
Ky?sti M?lkki <[email protected]> -------------- next part -------------- diff -ur lk-i2c-km-1/Documentation/i2c/writing-clients lk-i2c-km-2/Documentation/i2c/writing-clients --- lk-i2c-km-1/Documentation/i2c/writing-clients 2003-12-22 19:41:53.000000000 +0200 +++ lk-i2c-km-2/Documentation/i2c/writing-clients 2003-12-22 22:09:34.000000000 +0200 @@ -24,16 +24,14 @@ routines, a client structure specific information like the actual I2C address. - struct i2c_driver foo_driver - { - /* name */ "Foo version 2.3 and later driver", - /* id */ I2C_DRIVERID_FOO, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &foo_attach_adapter, - /* detach_client */ &foo_detach_client, - /* command */ &foo_command, /* May be NULL */ - /* inc_use */ &foo_inc_use, /* May be NULL */ - /* dec_use */ &foo_dec_use /* May be NULL */ + static struct i2c_driver foo_driver = { + .owner = THIS_MODULE, + .name = "Foo version 2.3 driver", + .id = I2C_DRIVERID_FOO, /* usually from i2c-id.h */ + .flags = I2C_DF_NOTIFY, + .attach_adapter = &foo_attach_adapter, + .detach_client = &foo_detach_client, + .command = &foo_command /* may be NULL */ } The name can be chosen freely, and may be upto 40 characters long. Please diff -ur lk-i2c-km-1/drivers/i2c/i2c-algo-bit.c lk-i2c-km-2/drivers/i2c/i2c-algo-bit.c --- lk-i2c-km-1/drivers/i2c/i2c-algo-bit.c 2003-12-22 19:41:53.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-algo-bit.c 2003-12-22 22:59:46.000000000 +0200 @@ -18,25 +18,22 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* ------------------------------------------------------------------------- */ -/* With some changes from Ky?sti M?lkki <[email protected]> and even - Frodo Looijaard <[email protected]> */ +/* With some changes from Frodo Looijaard <[email protected]>, Ky?sti M?lkki + <[email protected]> and Jean Delvare <[email protected]> */ -/* $Id: i2c-algo-bit.c,v 1.30 2001/07/29 02:44:25 mds Exp $ */ +/* $Id: i2c-algo-bit.c,v 1.46 2003/11/01 16:20:01 khali Exp $ */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/slab.h> -#include <linux/version.h> #include <linux/init.h> -#include <asm/uaccess.h> -#include <linux/ioport.h> #include <linux/errno.h> #include <linux/sched.h> - #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> + /* ----- global defines ----------------------------------------------- */ #define DEB(x) if (i2c_debug>=1) x; #define DEB2(x) if (i2c_debug>=2) x; @@ -531,14 +528,11 @@ /* -----exported algorithm data: ------------------------------------- */ static struct i2c_algorithm i2c_bit_algo = { - "Bit-shift algorithm", - I2C_ALGO_BIT, - bit_xfer, - NULL, - NULL, /* slave_xmit */ - NULL, /* slave_recv */ - algo_control, /* ioctl */ - bit_func, /* functionality */ + .owner = THIS_MODULE, + .name = "Bit-shift algorithm", + .id = I2C_ALGO_BIT, + .master_xfer = bit_xfer, + .functionality = bit_func, }; /* @@ -583,42 +577,19 @@ printk("\n"); } -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif i2c_add_adapter(adap); - return 0; } int i2c_bit_del_bus(struct i2c_adapter *adap) { - int res; - - if ((res = i2c_del_adapter(adap)) < 0) - return res; - - DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name)); - -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif - return 0; -} - -int __init i2c_algo_bit_init (void) -{ - printk(KERN_INFO "i2c-algo-bit.o: i2c bit algorithm module\n"); - return 0; + return i2c_del_adapter(adap); } - - EXPORT_SYMBOL(i2c_bit_add_bus); EXPORT_SYMBOL(i2c_bit_del_bus); -#ifdef MODULE MODULE_AUTHOR("Simon G. Vogl <[email protected]>"); MODULE_DESCRIPTION("I2C-Bus bit-banging algorithm"); MODULE_LICENSE("GPL"); @@ -630,14 +601,4 @@ MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus"); MODULE_PARM_DESC(i2c_debug, - "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol"); - -int init_module(void) -{ - return i2c_algo_bit_init(); -} - -void cleanup_module(void) -{ -} -#endif + "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol"); diff -ur lk-i2c-km-1/drivers/i2c/i2c-algo-pcf.c lk-i2c-km-2/drivers/i2c/i2c-algo-pcf.c --- lk-i2c-km-1/drivers/i2c/i2c-algo-pcf.c 2003-12-22 19:41:53.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-algo-pcf.c 2003-12-22 23:22:21.000000000 +0200 @@ -31,13 +31,8 @@ #include <linux/module.h> #include <linux/delay.h> #include <linux/slab.h> -#include <linux/version.h> #include <linux/init.h> -#include <asm/uaccess.h> -#include <linux/ioport.h> #include <linux/errno.h> -#include <linux/sched.h> - #include <linux/i2c.h> #include <linux/i2c-algo-pcf.h> #include "i2c-pcf8584.h" @@ -443,14 +438,11 @@ /* -----exported algorithm data: ------------------------------------- */ static struct i2c_algorithm pcf_algo = { - "PCF8584 algorithm", - I2C_ALGO_PCF, - pcf_xfer, - NULL, - NULL, /* slave_xmit */ - NULL, /* slave_recv */ - algo_control, /* ioctl */ - pcf_func, /* functionality */ + .owner = THIS_MODULE, + .name = "PCF8584 algorithm", + .id = I2C_ALGO_PCF, + .master_xfer = pcf_xfer, + .functionality = pcf_func, }; /* @@ -476,10 +468,6 @@ return i; } -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif - i2c_add_adapter(adap); /* scan bus */ @@ -511,28 +499,12 @@ int i2c_pcf_del_bus(struct i2c_adapter *adap) { - int res; - if ((res = i2c_del_adapter(adap)) < 0) - return res; - DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name)); - -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif - return 0; -} - -int __init i2c_algo_pcf_init (void) -{ - printk("i2c-algo-pcf.o: i2c pcf8584 algorithm module\n"); - return 0; + return i2c_del_adapter(adap); } - EXPORT_SYMBOL(i2c_pcf_add_bus); EXPORT_SYMBOL(i2c_pcf_del_bus); -#ifdef MODULE MODULE_AUTHOR("Hans Berglund <[email protected]>"); MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm"); MODULE_LICENSE("GPL"); @@ -543,14 +515,3 @@ MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus"); MODULE_PARM_DESC(i2c_debug, "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol"); - - -int init_module(void) -{ - return i2c_algo_pcf_init(); -} - -void cleanup_module(void) -{ -} -#endif diff -ur lk-i2c-km-1/drivers/i2c/i2c-core.c lk-i2c-km-2/drivers/i2c/i2c-core.c --- lk-i2c-km-1/drivers/i2c/i2c-core.c 2003-12-22 20:06:47.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-core.c 2003-12-22 23:43:33.000000000 +0200 @@ -18,24 +18,18 @@ /* ------------------------------------------------------------------------- */ /* With some changes from Ky?sti M?lkki <[email protected]>. - All SMBus-related things are written by Frodo Looijaard <[email protected]> */ + All SMBus-related things are written by Frodo Looijaard <[email protected]> + SMBus 2.0 support by Mark Studebaker <[email protected]> */ -/* $Id: i2c-core.c,v 1.64 2001/08/13 01:35:56 mds Exp $ */ +/* i2c-core.c,v 1.91.2.2 2003/01/21 10:00:19 kmalkki Exp */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/slab.h> #include <linux/proc_fs.h> -#include <linux/config.h> - -#include <linux/i2c.h> - -/* ----- compatibility stuff ----------------------------------------------- */ - -#include <linux/version.h> #include <linux/init.h> - +#include <linux/i2c.h> #include <asm/uaccess.h> /* ----- global defines ---------------------------------------------------- */ @@ -78,7 +72,7 @@ #ifdef CONFIG_PROC_FS static int i2cproc_init(void); -static int i2cproc_cleanup(void); +static void i2cproc_cleanup(void); static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, @@ -464,21 +458,27 @@ void i2c_inc_use_client(struct i2c_client *client) { - - if (client->driver->inc_use != NULL) + if (client->driver->owner) + __MOD_INC_USE_COUNT(client->driver->owner); + else if (client->driver->inc_use != NULL) client->driver->inc_use(client); - if (client->adapter->inc_use != NULL) + if (client->adapter->owner) + __MOD_INC_USE_COUNT(client->adapter->owner); + else if (client->adapter->inc_use != NULL) client->adapter->inc_use(client->adapter); } void i2c_dec_use_client(struct i2c_client *client) { - - if (client->driver->dec_use != NULL) + if (client->driver->owner) + __MOD_DEC_USE_COUNT(client->driver->owner); + else if (client->driver->dec_use != NULL) client->driver->dec_use(client); - if (client->adapter->dec_use != NULL) + if (client->adapter->owner) + __MOD_DEC_USE_COUNT(client->adapter->owner); + else if (client->adapter->dec_use != NULL) client->adapter->dec_use(client->adapter); } @@ -591,9 +591,8 @@ #ifdef CONFIG_PROC_FS - /* This function generates the output for /proc/bus/i2c */ -int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, +static int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, void *private) { int i; @@ -682,7 +681,7 @@ return -ENOENT; } -int i2cproc_init(void) +static int __init i2cproc_init(void) { struct proc_dir_entry *proc_bus_i2c; @@ -706,7 +705,7 @@ return 0; } -int i2cproc_cleanup(void) +static void __exit i2cproc_cleanup(void) { if (i2cproc_initialized >= 1) { @@ -1243,116 +1242,20 @@ return 0; } -#ifndef MODULE -#ifdef CONFIG_I2C_CHARDEV - extern int i2c_dev_init(void); -#endif -#ifdef CONFIG_I2C_ALGOBIT - extern int i2c_algo_bit_init(void); -#endif -#ifdef CONFIG_I2C_PHILIPSPAR - extern int i2c_bitlp_init(void); -#endif -#ifdef CONFIG_I2C_ELV - extern int i2c_bitelv_init(void); -#endif -#ifdef CONFIG_I2C_VELLEMAN - extern int i2c_bitvelle_init(void); -#endif -#ifdef CONFIG_I2C_BITVIA - extern int i2c_bitvia_init(void); -#endif - -#ifdef CONFIG_I2C_ALGOPCF - extern int i2c_algo_pcf_init(void); -#endif -#ifdef CONFIG_I2C_ELEKTOR - extern int i2c_pcfisa_init(void); -#endif - -#ifdef CONFIG_I2C_ALGO8XX - extern int i2c_algo_8xx_init(void); -#endif -#ifdef CONFIG_I2C_RPXLITE - extern int i2c_rpx_init(void); -#endif - -#ifdef CONFIG_I2C_ALGO_SIBYTE - extern int i2c_algo_sibyte_init(void); - extern int i2c_sibyte_init(void); -#endif -#ifdef CONFIG_I2C_MAX1617 - extern int i2c_max1617_init(void); -#endif - -#ifdef CONFIG_I2C_PROC - extern int sensors_init(void); +static void __exit i2c_exit(void) +{ +#ifdef CONFIG_PROC_FS + i2cproc_cleanup(); #endif +} -/* This is needed for automatic patch generation: sensors code starts here */ -/* This is needed for automatic patch generation: sensors code ends here */ - +/* leave this in for now simply to make patching easier so we don't have + to remove the call in drivers/char/mem.c */ int __init i2c_init_all(void) { - /* --------------------- global ----- */ - i2c_init(); - -#ifdef CONFIG_I2C_CHARDEV - i2c_dev_init(); -#endif - /* --------------------- bit -------- */ -#ifdef CONFIG_I2C_ALGOBIT - i2c_algo_bit_init(); -#endif -#ifdef CONFIG_I2C_PHILIPSPAR - i2c_bitlp_init(); -#endif -#ifdef CONFIG_I2C_ELV - i2c_bitelv_init(); -#endif -#ifdef CONFIG_I2C_VELLEMAN - i2c_bitvelle_init(); -#endif - - /* --------------------- pcf -------- */ -#ifdef CONFIG_I2C_ALGOPCF - i2c_algo_pcf_init(); -#endif -#ifdef CONFIG_I2C_ELEKTOR - i2c_pcfisa_init(); -#endif - - /* --------------------- 8xx -------- */ -#ifdef CONFIG_I2C_ALGO8XX - i2c_algo_8xx_init(); -#endif -#ifdef CONFIG_I2C_RPXLITE - i2c_rpx_init(); -#endif - - /* --------------------- SiByte -------- */ -#ifdef CONFIG_I2C_ALGO_SIBYTE - i2c_algo_sibyte_init(); - i2c_sibyte_init(); -#endif -#ifdef CONFIG_I2C_MAX1617 - i2c_max1617_init(); -#endif - - /* -------------- proc interface ---- */ -#ifdef CONFIG_I2C_PROC - sensors_init(); -#endif -/* This is needed for automatic patch generation: sensors code starts here */ -/* This is needed for automatic patch generation: sensors code ends here */ - return 0; } -#endif - - - EXPORT_SYMBOL(i2c_add_adapter); EXPORT_SYMBOL(i2c_del_adapter); EXPORT_SYMBOL(i2c_add_driver); @@ -1389,7 +1292,6 @@ EXPORT_SYMBOL(i2c_get_functionality); EXPORT_SYMBOL(i2c_check_functionality); -#ifdef MODULE MODULE_AUTHOR("Simon G. Vogl <[email protected]>"); MODULE_DESCRIPTION("I2C-Bus main module"); MODULE_LICENSE("GPL"); @@ -1397,13 +1299,5 @@ MODULE_PARM(i2c_debug, "i"); MODULE_PARM_DESC(i2c_debug,"debug level"); -int init_module(void) -{ - return i2c_init(); -} - -void cleanup_module(void) -{ - i2cproc_cleanup(); -} -#endif +module_init(i2c_init); +module_exit(i2c_exit); diff -ur lk-i2c-km-1/drivers/i2c/i2c-dev.c lk-i2c-km-2/drivers/i2c/i2c-dev.c --- lk-i2c-km-1/drivers/i2c/i2c-dev.c 2003-12-22 20:06:47.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-dev.c 2003-12-23 01:09:19.000000000 +0200 @@ -28,33 +28,24 @@ /* The devfs code is contributed by Philipp Matthias Hahn <[email protected]> */ -/* $Id: i2c-dev.c,v 1.40 2001/08/25 01:28:01 mds Exp $ */ +/* $Id: i2c-dev.c,v 1.56 2003/11/22 14:57:48 khali Exp $ */ -#include <linux/config.h> #include <linux/kernel.h> #include <linux/module.h> #include <linux/fs.h> #include <linux/slab.h> -#include <linux/version.h> #include <linux/smp_lock.h> #ifdef CONFIG_DEVFS_FS #include <linux/devfs_fs_kernel.h> #endif - - -/* If you want debugging uncomment: */ -/* #define DEBUG */ - #include <linux/init.h> -#include <asm/uaccess.h> - #include <linux/i2c.h> #include <linux/i2c-dev.h> +#include <asm/uaccess.h> + +/* If you want debugging uncomment: */ +/* #define DEBUG */ -#ifdef MODULE -extern int init_module(void); -extern int cleanup_module(void); -#endif /* def MODULE */ /* struct file_operations changed too often in the 2.1 series for nice code */ @@ -74,22 +65,16 @@ static int i2cdev_command(struct i2c_client *client, unsigned int cmd, void *arg); -#ifdef MODULE -static -#else -extern -#endif - int __init i2c_dev_init(void); -static int i2cdev_cleanup(void); +static void i2c_dev_exit(void); static struct file_operations i2cdev_fops = { - owner: THIS_MODULE, - llseek: no_llseek, - read: i2cdev_read, - write: i2cdev_write, - ioctl: i2cdev_ioctl, - open: i2cdev_open, - release: i2cdev_release, + .owner = THIS_MODULE, + .llseek = no_llseek, + .read = i2cdev_read, + .write = i2cdev_write, + .ioctl = i2cdev_ioctl, + .open = i2cdev_open, + .release = i2cdev_release, }; #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX @@ -100,24 +85,20 @@ #endif 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, */ + .owner = THIS_MODULE, /* not really used */ + .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, }; 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, + .addr = -1, + .driver = &i2cdev_driver, }; static int i2cdev_initialized; @@ -480,7 +461,7 @@ return -1; } -int __init i2c_dev_init(void) +static int __init i2c_dev_init(void) { int res; @@ -503,14 +484,14 @@ if ((res = i2c_add_driver(&i2cdev_driver))) { printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n"); - i2cdev_cleanup(); + i2c_dev_exit(); return res; } i2cdev_initialized ++; return 0; } -int i2cdev_cleanup(void) +static void __exit i2c_dev_exit(void) { int res; @@ -541,21 +522,9 @@ EXPORT_NO_SYMBOLS; -#ifdef MODULE - MODULE_AUTHOR("Frodo Looijaard <[email protected]> and Simon G. Vogl <[email protected]>"); MODULE_DESCRIPTION("I2C /dev entries driver"); MODULE_LICENSE("GPL"); -int init_module(void) -{ - return i2c_dev_init(); -} - -int cleanup_module(void) -{ - return i2cdev_cleanup(); -} - -#endif /* def MODULE */ - +module_init(i2c_dev_init); +module_exit(i2c_dev_exit); diff -ur lk-i2c-km-1/drivers/i2c/i2c-elektor.c lk-i2c-km-2/drivers/i2c/i2c-elektor.c --- lk-i2c-km-1/drivers/i2c/i2c-elektor.c 2003-12-22 20:06:47.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-elektor.c 2003-12-23 00:11:48.000000000 +0200 @@ -30,14 +30,14 @@ #include <linux/module.h> #include <linux/delay.h> #include <linux/slab.h> -#include <linux/version.h> #include <linux/init.h> +#include <linux/interrupt.h> #include <linux/pci.h> -#include <asm/irq.h> -#include <asm/io.h> - +#include <linux/wait.h> #include <linux/i2c.h> #include <linux/i2c-algo-pcf.h> +#include <asm/io.h> +#include <asm/irq.h> #include <linux/i2c-elektor.h> #include "i2c-pcf8584.h" @@ -157,70 +157,29 @@ } -static void __exit pcf_isa_exit(void) -{ - if (irq > 0) { - disable_irq(irq); - free_irq(irq, 0); - } - if (!mmapped) { - release_region(base , 2); - } -} - - -static int pcf_isa_reg(struct i2c_client *client) -{ - return 0; -} - - -static int pcf_isa_unreg(struct i2c_client *client) -{ - return 0; -} - -static void pcf_isa_inc_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif -} - -static void pcf_isa_dec_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif -} - - /* ------------------------------------------------------------------------ * Encapsulate the above functions in the correct operations structure. * This is only done when more than one hardware adapter is supported. */ static struct i2c_algo_pcf_data pcf_isa_data = { - NULL, - pcf_isa_setbyte, - pcf_isa_getbyte, - pcf_isa_getown, - pcf_isa_getclock, - pcf_isa_waitforpin, - 10, 10, 100, /* waits, timeout */ + .setpcf = pcf_isa_setbyte, + .getpcf = pcf_isa_getbyte, + .getown = pcf_isa_getown, + .getclock = pcf_isa_getclock, + .waitforpin = pcf_isa_waitforpin, + .udelay = 10, + .mdelay = 10, + .timeout = HZ, }; static struct i2c_adapter pcf_isa_ops = { - "PCF8584 ISA adapter", - I2C_HW_P_ELEK, - NULL, - &pcf_isa_data, - pcf_isa_inc_use, - pcf_isa_dec_use, - pcf_isa_reg, - pcf_isa_unreg, + .owner = THIS_MODULE, + .name = "PCF8584 ISA adapter", + .id = I2C_HW_P_ELEK, + .algo_data = &pcf_isa_data, }; -int __init i2c_pcfisa_init(void) +static int __init i2c_pcfisa_init(void) { #ifdef __alpha__ /* check to see we have memory mapped PCF8584 connected to the @@ -291,9 +250,20 @@ } +static void __exit pcf_isa_exit(void) +{ + if (irq > 0) { + disable_irq(irq); + free_irq(irq, 0); + } + + if (!mmapped) { + release_region(base , 2); + } +} + EXPORT_NO_SYMBOLS; -#ifdef MODULE MODULE_AUTHOR("Hans Berglund <[email protected]>"); MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter"); MODULE_LICENSE("GPL"); @@ -305,15 +275,5 @@ MODULE_PARM(mmapped, "i"); MODULE_PARM(i2c_debug, "i"); -int init_module(void) -{ - return i2c_pcfisa_init(); -} - -void cleanup_module(void) -{ - i2c_pcf_del_bus(&pcf_isa_ops); - pcf_isa_exit(); -} - -#endif +module_init(i2c_pcfisa_init); +module_exit(i2c_pcfisa_exit); diff -ur lk-i2c-km-1/drivers/i2c/i2c-elv.c lk-i2c-km-2/drivers/i2c/i2c-elv.c --- lk-i2c-km-1/drivers/i2c/i2c-elv.c 2003-12-22 19:41:53.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-elv.c 2003-12-23 00:12:06.000000000 +0200 @@ -21,22 +21,18 @@ /* With some changes from Ky?sti M?lkki <[email protected]> and even Frodo Looijaard <[email protected]> */ -/* $Id: i2c-elv.c,v 1.17 2001/07/29 02:44:25 mds Exp $ */ +/* $Id: i2c-elv.c,v 1.28 2003/07/25 07:56:42 khali Exp $ */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/delay.h> #include <linux/slab.h> -#include <linux/version.h> #include <linux/init.h> - -#include <asm/uaccess.h> - #include <linux/ioport.h> -#include <asm/io.h> #include <linux/errno.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> +#include <asm/io.h> #define DEFAULT_BASE 0x378 static int base=0; @@ -115,60 +111,28 @@ return 0; } -static void __exit bit_elv_exit(void) -{ - release_region( base , (base = 0x3bc)? 3 : 8 ); -} - -static int bit_elv_reg(struct i2c_client *client) -{ - return 0; -} - -static int bit_elv_unreg(struct i2c_client *client) -{ - return 0; -} - -static void bit_elv_inc_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif -} - -static void bit_elv_dec_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif -} - /* ------------------------------------------------------------------------ * Encapsulate the above functions in the correct operations structure. * This is only done when more than one hardware adapter is supported. */ static struct i2c_algo_bit_data bit_elv_data = { - NULL, - bit_elv_setsda, - bit_elv_setscl, - bit_elv_getsda, - bit_elv_getscl, - 80, 80, 100, /* waits, timeout */ + .setsda = bit_elv_setsda, + .setscl = bit_elv_setscl, + .getsda = bit_elv_getsda, + .getscl = bit_elv_getscl, + .udelay = 80, + .mdelay = 80, + .timeout = HZ }; static struct i2c_adapter bit_elv_ops = { - "ELV Parallel port adaptor", - I2C_HW_B_ELV, - NULL, - &bit_elv_data, - bit_elv_inc_use, - bit_elv_dec_use, - bit_elv_reg, - bit_elv_unreg, + .owner = THIS_MODULE, + .name = "ELV Parallel port adaptor", + .id = I2C_HW_B_ELV, + .algo_data = &bit_elv_data, }; -int __init i2c_bitelv_init(void) +static int __init i2c_bitelv_init(void) { printk(KERN_INFO "i2c-elv.o: i2c ELV parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE); if (base=0) { @@ -194,25 +158,19 @@ return 0; } +static void __exit i2c_bitelv_exit(void) +{ + i2c_bit_del_bus(&bit_elv_ops); + release_region(base , (base = 0x3bc) ? 3 : 8); +} EXPORT_NO_SYMBOLS; -#ifdef MODULE MODULE_AUTHOR("Simon G. Vogl <[email protected]>"); MODULE_DESCRIPTION("I2C-Bus adapter routines for ELV parallel port adapter"); MODULE_LICENSE("GPL"); MODULE_PARM(base, "i"); -int init_module(void) -{ - return i2c_bitelv_init(); -} - -void cleanup_module(void) -{ - i2c_bit_del_bus(&bit_elv_ops); - bit_elv_exit(); -} - -#endif +module_init(i2c_bitelv_init); +module_exit(i2c_bitelv_exit); diff -ur lk-i2c-km-1/drivers/i2c/i2c-philips-par.c lk-i2c-km-2/drivers/i2c/i2c-philips-par.c --- lk-i2c-km-1/drivers/i2c/i2c-philips-par.c 2003-12-22 20:06:47.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-philips-par.c 2003-12-23 00:12:24.000000000 +0200 @@ -21,7 +21,7 @@ /* With some changes from Ky?sti M?lkki <[email protected]> and even Frodo Looijaard <[email protected]> */ -/* $Id: i2c-philips-par.c,v 1.18 2000/07/06 19:21:49 frodo Exp $ */ +/* $Id: i2c-philips-par.c,v 1.31 2003/07/25 08:44:13 khali Exp $ */ #include <linux/kernel.h> #include <linux/ioport.h> @@ -29,14 +29,10 @@ #include <linux/init.h> #include <linux/stddef.h> #include <linux/parport.h> - +#include <linux/slab.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> -#ifndef __exit -#define __exit __init -#endif - static int type; struct i2c_par @@ -130,25 +126,6 @@ PARPORT_STATUS_BUSY) ? 0 : 1; } -static int bit_lp_reg(struct i2c_client *client) -{ - return 0; -} - -static int bit_lp_unreg(struct i2c_client *client) -{ - return 0; -} - -static void bit_lp_inc_use(struct i2c_adapter *adap) -{ - MOD_INC_USE_COUNT; -} - -static void bit_lp_dec_use(struct i2c_adapter *adap) -{ - MOD_DEC_USE_COUNT; -} /* ------------------------------------------------------------------------ * Encapsulate the above functions in the correct operations structure. @@ -156,33 +133,28 @@ */ static struct i2c_algo_bit_data bit_lp_data = { - NULL, - bit_lp_setsda, - bit_lp_setscl, - bit_lp_getsda, - bit_lp_getscl, - 80, 80, 100, /* waits, timeout */ + .setsda = bit_lp_setsda, + .setscl = bit_lp_setscl, + .getsda = bit_lp_getsda, + .getscl = bit_lp_getscl, + .udelay = 80, + .mdelay = 80, + .timeout = HZ }; static struct i2c_algo_bit_data bit_lp_data2 = { - NULL, - bit_lp_setsda2, - bit_lp_setscl2, - bit_lp_getsda2, - NULL, - 80, 80, 100, /* waits, timeout */ + .setsda = bit_lp_setsda2, + .setscl = bit_lp_setscl2, + .getsda = bit_lp_getsda2, + .udelay = 80, + .mdelay = 80, + .timeout = HZ }; static struct i2c_adapter bit_lp_ops = { - "Philips Parallel port adapter", - I2C_HW_B_LP, - NULL, - NULL, - bit_lp_inc_use, - bit_lp_dec_use, - bit_lp_reg, - - bit_lp_unreg, + .owner = THIS_MODULE, + .name = "Philips Parallel port adapter", + .id = I2C_HW_B_LP, }; static void i2c_parport_attach (struct parport *port) @@ -257,15 +229,16 @@ NULL }; -int __init i2c_bitlp_init(void) +static int __init i2c_bitlp_init(void) { - printk(KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE); + printk(KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE); parport_register_driver(&i2c_driver); + return 0; } -void __exit i2c_bitlp_exit(void) +static void __exit i2c_bitlp_exit(void) { parport_unregister_driver(&i2c_driver); } @@ -278,14 +251,5 @@ MODULE_PARM(type, "i"); -#ifdef MODULE -int init_module(void) -{ - return i2c_bitlp_init(); -} - -void cleanup_module(void) -{ - i2c_bitlp_exit(); -} -#endif +module_init(i2c_bitlp_init); +module_exit(i2c_bitlp_exit); diff -ur lk-i2c-km-1/drivers/i2c/i2c-proc.c lk-i2c-km-2/drivers/i2c/i2c-proc.c --- lk-i2c-km-1/drivers/i2c/i2c-proc.c 2003-12-22 20:06:47.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-proc.c 2003-12-22 21:09:37.000000000 +0200 @@ -23,20 +23,17 @@ This driver puts entries in /proc/sys/dev/sensors for each I2C device */ -#include <linux/version.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/ctype.h> #include <linux/sysctl.h> #include <linux/proc_fs.h> +#include <linux/init.h> #include <linux/ioport.h> -#include <asm/uaccess.h> - #include <linux/i2c.h> #include <linux/i2c-proc.h> - -#include <linux/init.h> +#include <asm/uaccess.h> #ifndef THIS_MODULE #define THIS_MODULE NULL @@ -56,8 +53,6 @@ void *newval, size_t newlen, void **context); -int __init sensors_init(void); - #define SENSORS_ENTRY_MAX 20 static struct ctl_table_header *i2c_entries[SENSORS_ENTRY_MAX]; @@ -847,7 +842,7 @@ return 0; } -int __init sensors_init(void) +static int __init i2c_proc_init(void) { printk(KERN_INFO "i2c-proc.o version %s (%s)\n", I2C_VERSION, I2C_DATE); i2c_initialized = 0; @@ -859,34 +854,20 @@ return 0; } +static void __exit i2c_proc_exit(void) +{ + unregister_sysctl_table(i2c_proc_header); +} + +EXPORT_SYMBOL(i2c_register_entry); EXPORT_SYMBOL(i2c_deregister_entry); -EXPORT_SYMBOL(i2c_detect); EXPORT_SYMBOL(i2c_proc_real); -EXPORT_SYMBOL(i2c_register_entry); EXPORT_SYMBOL(i2c_sysctl_real); - -#ifdef MODULE +EXPORT_SYMBOL(i2c_detect); MODULE_AUTHOR("Frodo Looijaard <[email protected]>"); MODULE_DESCRIPTION("i2c-proc driver"); MODULE_LICENSE("GPL"); -int i2c_cleanup(void) -{ - if (i2c_initialized >= 1) { - unregister_sysctl_table(i2c_proc_header); - i2c_initialized--; - } - return 0; -} - -int init_module(void) -{ - return sensors_init(); -} - -int cleanup_module(void) -{ - return i2c_cleanup(); -} -#endif /* MODULE */ +module_init(i2c_proc_init); +module_exit(i2c_proc_exit); diff -ur lk-i2c-km-1/drivers/i2c/i2c-velleman.c lk-i2c-km-2/drivers/i2c/i2c-velleman.c --- lk-i2c-km-1/drivers/i2c/i2c-velleman.c 2003-12-22 19:41:53.000000000 +0200 +++ lk-i2c-km-2/drivers/i2c/i2c-velleman.c 2003-12-23 00:12:39.000000000 +0200 @@ -18,18 +18,18 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* ------------------------------------------------------------------------- */ -/* $Id: i2c-velleman.c,v 1.19 2000/01/24 02:06:33 mds Exp $ */ +/* $Id: i2c-velleman.c,v 1.31 2003/07/25 08:44:13 khali Exp $ */ #include <linux/kernel.h> #include <linux/ioport.h> #include <linux/module.h> #include <linux/init.h> -#include <linux/string.h> /* for 2.0 kernels to get NULL */ -#include <asm/errno.h> /* for 2.0 kernels to get ENODEV */ -#include <asm/io.h> - +#include <linux/errno.h> +#include <linux/delay.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> +#include <asm/io.h> +#include <asm/param.h> /* for HZ */ /* ----- global defines ----------------------------------------------- */ #define DEB(x) /* should be reasonable open, close &c. */ @@ -90,75 +90,38 @@ static int bit_velle_init(void) { - if (check_region(base,(base = 0x3bc)? 3 : 8) < 0 ) { - DEBE(printk("i2c-velleman.o: Port %#x already in use.\n", - base)); + if (!request_region(base, (base = 0x3bc) ? 3 : 8, + "i2c (Vellemann adapter)")) return -ENODEV; - } else { - request_region(base, (base = 0x3bc)? 3 : 8, - "i2c (Vellemann adapter)"); - bit_velle_setsda((void*)base,1); - bit_velle_setscl((void*)base,1); - } - return 0; -} -static void __exit bit_velle_exit(void) -{ - release_region( base , (base = 0x3bc)? 3 : 8 ); -} - - -static int bit_velle_reg(struct i2c_client *client) -{ - return 0; -} - -static int bit_velle_unreg(struct i2c_client *client) -{ + bit_velle_setsda((void*)base,1); + bit_velle_setscl((void*)base,1); return 0; } -static void bit_velle_inc_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif -} - -static void bit_velle_dec_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif -} - /* ------------------------------------------------------------------------ * Encapsulate the above functions in the correct operations structure. * This is only done when more than one hardware adapter is supported. */ static struct i2c_algo_bit_data bit_velle_data = { - NULL, - bit_velle_setsda, - bit_velle_setscl, - bit_velle_getsda, - bit_velle_getscl, - 10, 10, 100, /* waits, timeout */ + .setsda = bit_velle_setsda, + .setscl = bit_velle_setscl, + .getsda = bit_velle_getsda, + .getscl = bit_velle_getscl, + .udelay = 10, + .mdelay = 10, + .timeout = HZ }; static struct i2c_adapter bit_velle_ops = { - "Velleman K8000", - I2C_HW_B_VELLE, - NULL, - &bit_velle_data, - bit_velle_inc_use, - bit_velle_dec_use, - bit_velle_reg, - bit_velle_unreg, + .owner = THIS_MODULE, + .name = "Velleman K8000", + .id = I2C_HW_B_VELLE, + .algo_data = &bit_velle_data, }; -int __init i2c_bitvelle_init(void) +static int __init i2c_bitvelle_init(void) { printk(KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE); if (base=0) { @@ -184,24 +147,19 @@ return 0; } +static void __exit i2c_bitvelle_exit(void) +{ + i2c_bit_del_bus(&bit_velle_ops); + release_region(base, (base = 0x3bc) ? 3 : 8); +} + EXPORT_NO_SYMBOLS; -#ifdef MODULE MODULE_AUTHOR("Simon G. Vogl <[email protected]>"); MODULE_DESCRIPTION("I2C-Bus adapter routines for Velleman K8000 adapter"); MODULE_LICENSE("GPL"); MODULE_PARM(base, "i"); -int init_module(void) -{ - return i2c_bitvelle_init(); -} - -void cleanup_module(void) -{ - i2c_bit_del_bus(&bit_velle_ops); - bit_velle_exit(); -} - -#endif +module_init(i2c_bitvelle_init); +module_exit(i2c_bitvelle_exit); diff -ur lk-i2c-km-1/drivers/media/video/saa7110.c lk-i2c-km-2/drivers/media/video/saa7110.c --- lk-i2c-km-1/drivers/media/video/saa7110.c 2003-12-22 19:41:53.000000000 +0200 +++ lk-i2c-km-2/drivers/media/video/saa7110.c 2003-12-22 21:14:26.000000000 +0200 @@ -404,7 +404,7 @@ { "saa7110", /* name */ - I2C_DRIVERID_VIDEODECODER, /* in i2c-old.h */ + I2C_DRIVERID_VIDEODECODER, /* in i2c.h */ I2C_SAA7110, I2C_SAA7110+1, /* Addr range */ saa7110_attach, diff -ur lk-i2c-km-1/include/linux/i2c-algo-bit.h lk-i2c-km-2/include/linux/i2c-algo-bit.h --- lk-i2c-km-1/include/linux/i2c-algo-bit.h 2003-11-25 21:47:32.000000000 +0200 +++ lk-i2c-km-2/include/linux/i2c-algo-bit.h 2003-12-22 20:46:16.000000000 +0200 @@ -21,12 +21,10 @@ /* With some changes from Ky?sti M?lkki <[email protected]> and even Frodo Looijaard <[email protected]> */ -/* $Id: i2c-algo-bit.h,v 1.7 1999/12/21 23:45:58 frodo Exp $ */ +/* $Id: i2c-algo-bit.h,v 1.11 2003/07/25 07:56:42 khali Exp $ */ -#ifndef I2C_ALGO_BIT_H -#define I2C_ALGO_BIT_H 1 - -#include <linux/i2c.h> +#ifndef _LINUX_I2C_ALGO_BIT_H +#define _LINUX_I2C_ALGO_BIT_H /* --- Defines for bit-adapters --------------------------------------- */ /* @@ -42,9 +40,10 @@ int (*getscl) (void *data); /* local settings */ - int udelay; - int mdelay; - int timeout; + int udelay; /* half-clock-cycle time in microsecs */ + /* i.e. clock is (500 / udelay) KHz */ + int mdelay; /* in millisecs, unused */ + int timeout; /* in jiffies */ }; #define I2C_BIT_ADAP_MAX 16 @@ -52,4 +51,4 @@ int i2c_bit_add_bus(struct i2c_adapter *); int i2c_bit_del_bus(struct i2c_adapter *); -#endif /* I2C_ALGO_BIT_H */ +#endif /* _LINUX_I2C_ALGO_BIT_H */ diff -ur lk-i2c-km-1/include/linux/i2c-algo-pcf.h lk-i2c-km-2/include/linux/i2c-algo-pcf.h --- lk-i2c-km-1/include/linux/i2c-algo-pcf.h 2000-12-11 23:22:34.000000000 +0200 +++ lk-i2c-km-2/include/linux/i2c-algo-pcf.h 2003-12-22 20:50:15.000000000 +0200 @@ -22,13 +22,12 @@ /* With some changes from Ky?sti M?lkki <[email protected]> and even Frodo Looijaard <[email protected]> */ -/* $Id: i2c-algo-pcf.h,v 1.7 2000/02/27 23:02:45 frodo Exp $ */ +/* $Id: i2c-algo-pcf.h,v 1.9 2003/07/25 07:56:42 khali Exp $ */ -#ifndef I2C_ALGO_PCF_H -#define I2C_ALGO_PCF_H 1 +#ifndef _LINUX_I2C_ALGO_PCF_H +#define _LINUX_I2C_ALGO_PCF_H -/* --- Defines for pcf-adapters --------------------------------------- */ -#include <linux/i2c.h> +#include <linux/i2c-pcf8584.h> struct i2c_algo_pcf_data { void *data; /* private data for lolevel routines */ @@ -49,4 +48,4 @@ int i2c_pcf_add_bus(struct i2c_adapter *); int i2c_pcf_del_bus(struct i2c_adapter *); -#endif /* I2C_ALGO_PCF_H */ +#endif /* _LINUX_I2C_ALGO_PCF_H */ diff -ur lk-i2c-km-1/include/linux/i2c-dev.h lk-i2c-km-2/include/linux/i2c-dev.h --- lk-i2c-km-1/include/linux/i2c-dev.h 2003-11-25 21:47:29.000000000 +0200 +++ lk-i2c-km-2/include/linux/i2c-dev.h 2003-12-23 00:41:47.000000000 +0200 @@ -19,14 +19,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: i2c-dev.h,v 1.9 2001/08/15 03:04:58 mds Exp $ */ - -#ifndef I2C_DEV_H -#define I2C_DEV_H +/* $Id: i2c-dev.h,v 1.14 2003/07/25 07:56:42 khali Exp $ */ +#ifndef _LINUX_I2C_DEV_H +#define _LINUX_I2C_DEV_H #include <linux/types.h> -#include <linux/i2c.h> /* Some IOCTL commands are defined in <linux/i2c.h> */ /* Note: 10-bit addresses are NOT supported! */ diff -ur lk-i2c-km-1/include/linux/i2c-id.h lk-i2c-km-2/include/linux/i2c-id.h --- lk-i2c-km-1/include/linux/i2c-id.h 2003-12-22 19:42:42.000000000 +0200 +++ lk-i2c-km-2/include/linux/i2c-id.h 2003-12-22 20:50:13.000000000 +0200 @@ -20,10 +20,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* ------------------------------------------------------------------------- */ -/* $Id: i2c-id.h,v 1.35 2001/08/12 17:22:20 mds Exp $ */ +/* $Id: i2c-id.h,v 1.84 2003/11/22 14:58:51 khali Exp $ */ + +#ifndef LINUX_I2C_ID_H +#define LINUX_I2C_ID_H -#ifndef I2C_ID_H -#define I2C_ID_H /* * This file is part of the i2c-bus package and contains the identifier * values for drivers, adapters and other folk populating these serial diff -ur lk-i2c-km-1/include/linux/i2c-proc.h lk-i2c-km-2/include/linux/i2c-proc.h --- lk-i2c-km-1/include/linux/i2c-proc.h 2003-11-25 21:47:36.000000000 +0200 +++ lk-i2c-km-2/include/linux/i2c-proc.h 2003-12-22 22:09:37.000000000 +0200 @@ -1,6 +1,7 @@ /* - sensors.h - Part of lm_sensors, Linux kernel modules for hardware - monitoring + i2c-proc.h - Part of the i2c package + was originally sensors.h - Part of lm_sensors, Linux kernel modules + for hardware monitoring Copyright (c) 1998, 1999 Frodo Looijaard <[email protected]> This program is free software; you can redistribute it and/or modify @@ -18,14 +19,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#ifndef SENSORS_SENSORS_H -#define SENSORS_SENSORS_H +#ifndef _LINUX_I2C_PROC_H +#define _LINUX_I2C_PROC_H -#ifdef __KERNEL__ - -/* Next two must be included before sysctl.h can be included, in 2.0 kernels */ -#include <linux/types.h> -#include <linux/fs.h> #include <linux/sysctl.h> /* The type of callback functions used in sensors_{proc,sysctl}_real */ @@ -362,7 +358,7 @@ /* This macro is used to scale user-input to sensible values in almost all chip drivers. */ -extern inline int SENSORS_LIMIT(long value, long low, long high) +static inline int SENSORS_LIMIT(long value, long low, long high) { if (value < low) return low; @@ -372,8 +368,6 @@ return value; } -#endif /* def __KERNEL__ */ - /* The maximum length of the prefix */ #define SENSORS_PREFIX_MAX 20 @@ -392,5 +386,5 @@ char name[SENSORS_PREFIX_MAX + 13]; }; -#endif /* def SENSORS_SENSORS_H */ +#endif /* def _LINUX_I2C_PROC_H */ diff -ur lk-i2c-km-1/include/linux/i2c.h lk-i2c-km-2/include/linux/i2c.h --- lk-i2c-km-1/include/linux/i2c.h 2003-12-22 20:06:47.000000000 +0200 +++ lk-i2c-km-2/include/linux/i2c.h 2003-12-23 00:41:41.000000000 +0200 @@ -23,39 +23,28 @@ /* With some changes from Ky?sti M?lkki <[email protected]> and Frodo Looijaard <[email protected]> */ -/* $Id: i2c.h,v 1.46 2001/08/31 00:04:07 phil Exp $ */ +/* $Id: i2c.h,v 1.72 2003/10/05 23:54:10 phil Exp $ */ -#ifndef I2C_H -#define I2C_H +#ifndef _LINUX_I2C_H +#define _LINUX_I2C_H -#define I2C_DATE "20010830" -#define I2C_VERSION "2.6.1" +#define I2C_DATE "20031005" +#define I2C_VERSION "2.8.1" -#include <linux/i2c-id.h> /* id values of adapters et. al. */ +#include <linux/module.h> #include <linux/types.h> - - -struct i2c_msg; - - -#ifdef __KERNEL__ - -/* --- Includes and compatibility declarations ------------------------ */ - -#include <linux/version.h> - -#include <asm/page.h> /* for 2.2.xx */ +#include <linux/errno.h> +#include <linux/sched.h> #include <asm/semaphore.h> -#include <linux/config.h> +#include <linux/i2c-id.h> /* --- General options ------------------------------------------------ */ -#define I2C_ALGO_MAX 4 /* control memory consumption */ -#define I2C_ADAP_MAX 16 +#define I2C_ADAP_MAX 16 /* control memory consumption */ #define I2C_DRIVER_MAX 16 #define I2C_CLIENT_MAX 32 -#define I2C_DUMMY_MAX 4 +struct i2c_msg; struct i2c_algorithm; struct i2c_adapter; struct i2c_client; @@ -63,7 +52,6 @@ struct i2c_client_address_data; union i2c_smbus_data; - /* * The master routines are the ones normally used to transmit data to devices * on a bus (or read from them). Apart from two basic transfer functions to @@ -128,6 +116,7 @@ */ struct i2c_driver { + struct module *owner; char name[32]; int id; unsigned int flags; /* div., see below */ @@ -195,6 +184,7 @@ * to name two of the most common. */ struct i2c_algorithm { + struct module *owner; /* future use --km */ char name[32]; /* textual description */ unsigned int id; @@ -219,12 +209,12 @@ u32 (*functionality) (struct i2c_adapter *); }; - /* * i2c_adapter is the structure used to identify a physical i2c bus along * with the access algorithms necessary to access it. */ struct i2c_adapter { + struct module *owner; char name[32]; /* some useful name to identify the adapter */ unsigned int id;/* = is algo->id | hwdep.struct->id, */ /* for registered values see below */ @@ -362,8 +352,6 @@ /* Return 1 if adapter supports everything we need, 0 if not. */ extern int i2c_check_functionality (struct i2c_adapter *adap, u32 func); -#endif /* __KERNEL__ */ - /* * I2C Message - used for pure i2c transaction, also from /dev interface */ @@ -476,16 +464,6 @@ #define I2C_MAJOR 89 /* Device major number */ -#ifdef __KERNEL__ - -# ifndef NULL -# define NULL ( (void *) 0 ) -# endif - -# ifndef ENODEV -# include <asm/errno.h> -# endif - /* These defines are used for probing i2c client addresses */ /* Default fill of many variables */ #define I2C_CLIENT_DEFAULTS {I2C_CLIENT_END, I2C_CLIENT_END, I2C_CLIENT_END, \ @@ -547,5 +525,11 @@ #define i2c_is_isa_adapter(adapptr) \ ((adapptr)->algo->id = I2C_ALGO_ISA) -#endif /* def __KERNEL__ */ -#endif /* I2C_H */ +/* Tiny delay function used by the i2c bus drivers */ +static inline void i2c_delay(signed long timeout) +{ + set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(timeout); +} + +#endif /* _LINUX_I2C_H */ -------------- next part -------------- diff -ur lk-2.4.23-i2c-khali/drivers/i2c/i2c-core.c lk-2.4.23-i2c-km/drivers/i2c/i2c-core.c --- lk-2.4.23-i2c-khali/drivers/i2c/i2c-core.c 2003-12-22 16:05:44.000000000 +0200 +++ lk-2.4.23-i2c-km/drivers/i2c/i2c-core.c 2003-12-22 18:35:10.000000000 +0200 @@ -36,10 +36,6 @@ #include <linux/version.h> #include <linux/init.h> -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) -#define init_MUTEX(s) do { *(s) = MUTEX; } while(0) -#endif - #include <asm/uaccess.h> /* ----- global defines ---------------------------------------------------- */ @@ -84,9 +80,6 @@ static int i2cproc_init(void); static int i2cproc_cleanup(void); -#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)) */ static ssize_t i2cproc_bus_read(struct file * file, char * buf,size_t count, loff_t *ppos); @@ -99,11 +92,6 @@ read: i2cproc_bus_read, }; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,3,48)) -static struct inode_operations i2cproc_inode_operations = { - &i2cproc_operations -}; -#endif static int i2cproc_initialized = 0; @@ -164,16 +152,8 @@ goto ERROR1; } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,48)) proc_entry->proc_fops = &i2cproc_operations; -#else - proc_entry->ops = &i2cproc_inode_operations; -#endif -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) proc_entry->owner = THIS_MODULE; -#else - proc_entry->fill_inode = &monitor_bus_i2c; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,58)) */ adap->inode = proc_entry->low_ino; } @@ -611,17 +591,6 @@ #ifdef CONFIG_PROC_FS -#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; -} -#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,3,37)) */ /* This function generates the output for /proc/bus/i2c */ int read_bus_i2c(char *buf, char **start, off_t offset, int len, int *eof, @@ -732,11 +701,7 @@ return -ENOENT; } proc_bus_i2c->read_proc = &read_bus_i2c; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) proc_bus_i2c->owner = THIS_MODULE; -#else - proc_bus_i2c->fill_inode = &monitor_bus_i2c; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */ i2cproc_initialized += 2; return 0; } diff -ur lk-2.4.23-i2c-khali/drivers/i2c/i2c-dev.c lk-2.4.23-i2c-km/drivers/i2c/i2c-dev.c --- lk-2.4.23-i2c-khali/drivers/i2c/i2c-dev.c 2003-12-22 16:05:44.000000000 +0200 +++ lk-2.4.23-i2c-km/drivers/i2c/i2c-dev.c 2003-12-22 18:35:10.000000000 +0200 @@ -36,9 +36,7 @@ #include <linux/fs.h> #include <linux/slab.h> #include <linux/version.h> -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) #include <linux/smp_lock.h> -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */ #ifdef CONFIG_DEVFS_FS #include <linux/devfs_fs_kernel.h> #endif @@ -60,9 +58,6 @@ /* struct file_operations changed too often in the 2.1 series for nice code */ -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9) -static loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin); -#endif 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, @@ -88,14 +83,8 @@ static int i2cdev_cleanup(void); static struct file_operations i2cdev_fops = { -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) owner: THIS_MODULE, -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */ -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9) - llseek: i2cdev_lseek, -#else llseek: no_llseek, -#endif read: i2cdev_read, write: i2cdev_write, ioctl: i2cdev_ioctl, @@ -133,20 +122,6 @@ static int i2cdev_initialized; -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,9) -/* Note that the lseek function is called llseek in 2.1 kernels. But things - are complicated enough as is. */ -loff_t i2cdev_lseek (struct file *file, loff_t offset, int origin) -{ -#ifdef DEBUG - 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; -} -#endif - static ssize_t i2cdev_read (struct file *file, char *buf, size_t count, loff_t *offset) { @@ -434,9 +409,6 @@ if (i2cdev_adaps[minor]->inc_use) i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]); -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) - MOD_INC_USE_COUNT; -#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */ #ifdef DEBUG printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor); @@ -452,16 +424,10 @@ #ifdef DEBUG printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor); #endif -#if LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) - MOD_DEC_USE_COUNT; -#else /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */ lock_kernel(); -#endif /* LINUX_KERNEL_VERSION < KERNEL_VERSION(2,4,0) */ if (i2cdev_adaps[minor]->dec_use) i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]); -#if LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) unlock_kernel(); -#endif /* LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,4,0) */ return 0; } diff -ur lk-2.4.23-i2c-khali/drivers/i2c/i2c-elektor.c lk-2.4.23-i2c-km/drivers/i2c/i2c-elektor.c --- lk-2.4.23-i2c-khali/drivers/i2c/i2c-elektor.c 2003-12-22 16:05:44.000000000 +0200 +++ lk-2.4.23-i2c-km/drivers/i2c/i2c-elektor.c 2003-12-22 18:35:10.000000000 +0200 @@ -55,11 +55,7 @@ in some functions, called from the algo-pcf module. Sometimes it's need to be rewriten - but for now just remove this for simpler reading */ -#if (LINUX_VERSION_CODE < 0x020301) -static struct wait_queue *pcf_wait = NULL; -#else static wait_queue_head_t pcf_wait; -#endif static int pcf_pending; /* ----- global defines ----------------------------------------------- */ @@ -281,9 +277,7 @@ base = DEFAULT_BASE; } -#if (LINUX_VERSION_CODE >= 0x020301) init_waitqueue_head(&pcf_wait); -#endif if (pcf_isa_init() = 0) { if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) return -ENODEV; diff -ur lk-2.4.23-i2c-khali/drivers/i2c/i2c-philips-par.c lk-2.4.23-i2c-km/drivers/i2c/i2c-philips-par.c --- lk-2.4.23-i2c-khali/drivers/i2c/i2c-philips-par.c 2003-12-22 16:05:44.000000000 +0200 +++ lk-2.4.23-i2c-km/drivers/i2c/i2c-philips-par.c 2003-12-22 18:39:06.000000000 +0200 @@ -250,41 +250,24 @@ } -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4) static struct parport_driver i2c_driver = { "i2c-philips-par", i2c_parport_attach, i2c_parport_detach, NULL }; -#endif int __init i2c_bitlp_init(void) { -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,4) - struct parport *port; -#endif - printk(KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE); + printk(KERN_INFO "i2c-philips-par.o: i2c Philips parallel port adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4) parport_register_driver(&i2c_driver); -#else - for (port = parport_enumerate(); port; port=port->next) - i2c_parport_attach(port); -#endif - return 0; } void __exit i2c_bitlp_exit(void) { -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,4) parport_unregister_driver(&i2c_driver); -#else - struct parport *port; - for (port = parport_enumerate(); port; port=port->next) - i2c_parport_detach(port); -#endif } EXPORT_NO_SYMBOLS; diff -ur lk-2.4.23-i2c-khali/drivers/i2c/i2c-proc.c lk-2.4.23-i2c-km/drivers/i2c/i2c-proc.c --- lk-2.4.23-i2c-khali/drivers/i2c/i2c-proc.c 2003-12-22 16:05:44.000000000 +0200 +++ lk-2.4.23-i2c-km/drivers/i2c/i2c-proc.c 2003-12-22 18:35:10.000000000 +0200 @@ -63,10 +63,6 @@ static struct i2c_client *i2c_clients[SENSORS_ENTRY_MAX]; static unsigned short i2c_inodes[SENSORS_ENTRY_MAX]; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) -static void i2c_fill_inode(struct inode *inode, int fill); -static void i2c_dir_fill_inode(struct inode *inode, int fill); -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) */ static ctl_table sysctl_table[] = { {CTL_DEV, "dev", NULL, 0, 0555}, @@ -196,12 +192,7 @@ #endif /* DEBUG */ i2c_inodes[id - 256] new_header->ctl_table->child->child->de->low_ino; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) new_header->ctl_table->child->child->de->owner = controlling_mod; -#else - new_header->ctl_table->child->child->de->fill_inode - &i2c_dir_fill_inode; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */ return id; } @@ -863,12 +854,7 @@ if (! (i2c_proc_header register_sysctl_table(i2c_proc, 0))) return -ENOMEM; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) i2c_proc_header->ctl_table->child->de->owner = THIS_MODULE; -#else - i2c_proc_header->ctl_table->child->de->fill_inode - &i2c_fill_inode; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */ i2c_initialized++; return 0; } diff -ur lk-2.4.23-i2c-khali/include/linux/i2c.h lk-2.4.23-i2c-km/include/linux/i2c.h --- lk-2.4.23-i2c-khali/include/linux/i2c.h 2003-11-25 21:47:24.000000000 +0200 +++ lk-2.4.23-i2c-km/include/linux/i2c.h 2003-12-22 18:12:12.000000000 +0200 @@ -43,16 +43,9 @@ /* --- Includes and compatibility declarations ------------------------ */ #include <linux/version.h> -#ifndef KERNEL_VERSION -#define KERNEL_VERSION(a,b,c) (((a) << 16) | ((b) << 8) | (c)) -#endif #include <asm/page.h> /* for 2.2.xx */ -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,25) -#include <linux/sched.h> -#else #include <asm/semaphore.h> -#endif #include <linux/config.h> /* --- General options ------------------------------------------------ */ @@ -226,9 +219,6 @@ u32 (*functionality) (struct i2c_adapter *); }; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29) -struct proc_dir_entry; -#endif /* * i2c_adapter is the structure used to identify a physical i2c bus along @@ -267,9 +257,6 @@ #ifdef CONFIG_PROC_FS /* No need to set this when you initialize the adapter */ int inode; -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,1,29) - struct proc_dir_entry *proc_entry; -#endif #endif /* def CONFIG_PROC_FS */ };
PATCH 1/1 i2c cleanups
In reply to Jean DelvarePatch -km-3 :
Replace use of ADAP_LOCK and DRV_LOCK with down(&core_lists). In many cases we need both, some return path forgot UNLOCK, and locks were claimed in varying order and sometimes not at all.
Replace use of I2C_LOCK with down(&adapter->bus).
Remove unused adapter, driver and client counts.
Signature · 558 lines
Ky?sti M?lkki <[email protected]> -------------- next part -------------- diff -ur lk-i2c-km-2/drivers/i2c/i2c-core.c lk-i2c-km-3/drivers/i2c/i2c-core.c --- lk-i2c-km-2/drivers/i2c/i2c-core.c 2003-12-22 23:43:33.000000000 +0200 +++ lk-i2c-km-3/drivers/i2c/i2c-core.c 2003-12-23 12:36:43.000000000 +0200 @@ -34,32 +34,14 @@ /* ----- global defines ---------------------------------------------------- */ -/* exclusive access to the bus */ -#define I2C_LOCK(adap) down(&adap->lock) -#define I2C_UNLOCK(adap) up(&adap->lock) - -#define ADAP_LOCK() down(&adap_lock) -#define ADAP_UNLOCK() up(&adap_lock) - -#define DRV_LOCK() down(&driver_lock) -#define DRV_UNLOCK() up(&driver_lock) - #define DEB(x) if (i2c_debug>=1) x; #define DEB2(x) if (i2c_debug>=2) x; /* ----- global variables -------------------------------------------------- */ -/**** lock for writing to global variables: the adapter & driver list */ -struct semaphore adap_lock; -struct semaphore driver_lock; - -/**** adapter list */ +DECLARE_MUTEX(core_lists); static struct i2c_adapter *adapters[I2C_ADAP_MAX]; -static int adap_count; - -/**** drivers list */ static struct i2c_driver *drivers[I2C_DRIVER_MAX]; -static int driver_count; /**** debug level */ static int i2c_debug=1; @@ -111,7 +93,7 @@ { int i,j,res; - ADAP_LOCK(); + down(&core_lists); for (i = 0; i < I2C_ADAP_MAX; i++) if (NULL = adapters[i]) break; @@ -124,12 +106,10 @@ } adapters[i] = adap; - adap_count++; - ADAP_UNLOCK(); /* init data types */ - init_MUTEX(&adap->lock); - + init_MUTEX(&adap->bus); + init_MUTEX(&adap->list); #ifdef CONFIG_PROC_FS if (i2cproc_initialized) { @@ -154,36 +134,25 @@ #endif /* def CONFIG_PROC_FS */ /* inform drivers of new adapters */ - DRV_LOCK(); for (j=0;j<I2C_DRIVER_MAX;j++) if (drivers[j]!=NULL && (drivers[j]->flags&(I2C_DF_NOTIFY|I2C_DF_DUMMY))) /* We ignore the return code; if it fails, too bad */ drivers[j]->attach_adapter(adap); - DRV_UNLOCK(); DEB(printk(KERN_DEBUG "i2c-core.o: adapter %s registered as adapter %d.\n", adap->name,i)); - - return 0; - - -ERROR1: - ADAP_LOCK(); - adapters[i] = NULL; - adap_count--; -ERROR0: - ADAP_UNLOCK(); + ERROR0: + up(&core_lists); return res; } int i2c_del_adapter(struct i2c_adapter *adap) { - int i,j,res; - - ADAP_LOCK(); + int i,j, res=0; + down(&core_lists); for (i = 0; i < I2C_ADAP_MAX; i++) if (adap = adapters[i]) break; @@ -199,17 +168,14 @@ * *detach* it! Of course, each dummy driver should know about * this or hell will break loose... */ - DRV_LOCK(); for (j = 0; j < I2C_DRIVER_MAX; j++) if (drivers[j] && (drivers[j]->flags & I2C_DF_DUMMY)) if ((res = drivers[j]->attach_adapter(adap))) { printk(KERN_WARNING "i2c-core.o: can't detach adapter %s " "while detaching driver %s: driver not " "detached!",adap->name,drivers[j]->name); - goto ERROR1; + goto ERROR0; } - DRV_UNLOCK(); - /* detach any active clients. This must be done first, because * it can fail; in which case we give upp. */ @@ -237,17 +203,9 @@ #endif /* def CONFIG_PROC_FS */ adapters[i] = NULL; - adap_count--; - - ADAP_UNLOCK(); - DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name)); - return 0; - -ERROR0: - ADAP_UNLOCK(); - return res; -ERROR1: - DRV_UNLOCK(); + DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name)); + ERROR0: + up(&core_lists); return res; } @@ -261,7 +219,8 @@ int i2c_add_driver(struct i2c_driver *driver) { int i; - DRV_LOCK(); + + down(&core_lists); for (i = 0; i < I2C_DRIVER_MAX; i++) if (NULL = drivers[i]) break; @@ -270,19 +229,12 @@ " i2c-core.o: register_driver(%s) " "- enlarge I2C_DRIVER_MAX.\n", driver->name); - DRV_UNLOCK(); + up(&core_lists); return -ENOMEM; } - - drivers[i] = driver; - driver_count++; - - DRV_UNLOCK(); /* driver was successfully added */ - + drivers[i] = driver; DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name)); - ADAP_LOCK(); - /* now look for instances of driver on our adapters */ if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) { @@ -291,15 +243,15 @@ /* Ignore errors */ driver->attach_adapter(adapters[i]); } - ADAP_UNLOCK(); + up(&core_lists); return 0; } int i2c_del_driver(struct i2c_driver *driver) { - int i,j,k,res; + int i,j,k,res = 0; - DRV_LOCK(); + down(&core_lists); for (i = 0; i < I2C_DRIVER_MAX; i++) if (driver = drivers[i]) break; @@ -307,7 +259,7 @@ printk(KERN_WARNING " i2c-core.o: unregister_driver: " "[%s] not found\n", driver->name); - DRV_UNLOCK(); + up(&core_lists); return -ENODEV; } /* Have a look at each adapter, if clients of this driver are still @@ -319,7 +271,6 @@ * invalid operation might (will!) result, when using stale client * pointers. */ - ADAP_LOCK(); /* should be moved inside the if statement... */ for (k=0;k<I2C_ADAP_MAX;k++) { struct i2c_adapter *adap = adapters[k]; if (adap = NULL) /* skip empty entries. */ @@ -338,8 +289,7 @@ "not be detached properly; driver " "not unloaded!",driver->name, adap->name); - ADAP_UNLOCK(); - return res; + goto ERROR0; } } else { for (j=0;j<I2C_CLIENT_MAX;j++) { @@ -362,31 +312,41 @@ driver->name, client->addr, adap->name); - ADAP_UNLOCK(); - return res; + goto ERROR0; } } } } } - ADAP_UNLOCK(); drivers[i] = NULL; - driver_count--; - DRV_UNLOCK(); - DEB(printk(KERN_DEBUG "i2c-core.o: driver unregistered: %s\n",driver->name)); - return 0; + + ERROR0: + up(&core_lists); + return res; } -int i2c_check_addr (struct i2c_adapter *adapter, int addr) +static 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 i2c_check_addr (struct i2c_adapter *adapter, int addr) +{ + int rval; + + down(&adapter->list); + rval = __i2c_check_addr(adapter, addr); + up(&adapter->list); + + return rval; +} + int i2c_attach_client(struct i2c_client *client) { struct i2c_adapter *adapter = client->adapter; @@ -395,6 +355,7 @@ if (i2c_check_addr(client->adapter,client->addr)) return -EBUSY; + down(&adapter->list); for (i = 0; i < I2C_CLIENT_MAX; i++) if (NULL = adapter->clients[i]) break; @@ -402,11 +363,11 @@ printk(KERN_WARNING " i2c-core.o: attach_client(%s) - enlarge I2C_CLIENT_MAX.\n", client->name); + up(&adapter->list); return -ENOMEM; } - adapter->clients[i] = client; - adapter->client_count++; + up(&adapter->list); if (adapter->client_register) if (adapter->client_register(client)) @@ -428,16 +389,6 @@ struct i2c_adapter *adapter = client->adapter; int i,res; - for (i = 0; i < I2C_CLIENT_MAX; i++) - if (client = adapter->clients[i]) - break; - if (I2C_CLIENT_MAX = i) { - printk(KERN_WARNING " i2c-core.o: unregister_client " - "[%s] not found\n", - client->name); - return -ENODEV; - } - if( (client->flags & I2C_CLIENT_ALLOW_USE) && (client->usage_count>0)) return -EBUSY; @@ -449,8 +400,19 @@ return res; } + down(&adapter->list); + for (i = 0; i < I2C_CLIENT_MAX; i++) + if (client = adapter->clients[i]) + break; + if (I2C_CLIENT_MAX = i) { + printk(KERN_WARNING " i2c-core.o: unregister_client " + "[%s] not found\n", + client->name); + up(&adapter->list); + return -ENODEV; + } adapter->clients[i] = NULL; - adapter->client_count--; + up(&adapter->list); DEB(printk(KERN_DEBUG "i2c-core.o: client [%s] unregistered.\n",client->name)); return 0; @@ -482,6 +444,7 @@ client->adapter->dec_use(client->adapter); } +#if 0 /* just forget about this for now --km */ struct i2c_client *i2c_get_client(int driver_id, int adapter_id, struct i2c_client *prev) { @@ -548,6 +511,7 @@ return 0; } +#endif int i2c_use_client(struct i2c_client *client) { @@ -598,6 +562,7 @@ int i; int nr = 0; /* Note that it is safe to write a `little' beyond len. Yes, really. */ + down(&core_lists); for (i = 0; (i < I2C_ADAP_MAX) && (nr < len); i++) if (adapters[i]) { nr += sprintf(buf+nr, "i2c-%d\t", i); @@ -614,6 +579,7 @@ adapters[i]->name, adapters[i]->algo->name); } + up(&core_lists); return nr; } @@ -624,61 +590,77 @@ struct inode * inode = file->f_dentry->d_inode; char *kbuf; struct i2c_client *client; + struct i2c_adapter *adap; int i,j,k,order_nr,len=0; size_t len_total; int order[I2C_CLIENT_MAX]; +#define OUTPUT_LENGTH_PER_LINE 70 - if (count > 4000) - return -EINVAL; len_total = file->f_pos + count; - /* Too bad if this gets longer (unlikely) */ - if (len_total > 4000) - len_total = 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; - /* Order will hold the indexes of the clients - sorted by address */ - order_nr=0; - for (j = 0; j < I2C_CLIENT_MAX; j++) { - if ((client = adapters[i]->clients[j]) && - (client->driver->id != I2C_DRIVERID_I2CDEV)) { - for(k = order_nr; - (k > 0) && - adapters[i]->clients[order[k-1]]-> - addr > client->addr; - k--) - order[k] = order[k-1]; - order[k] = j; - order_nr++; - } - } + if (len_total > (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE) ) + /* adjust to maximum file size */ + len_total = (I2C_CLIENT_MAX * OUTPUT_LENGTH_PER_LINE); + + down(&core_lists); + /* adap = file->private_data; ?? --km */ + for (i = 0; i < I2C_ADAP_MAX; i++) { + adap = adapters[i]; + if (adap && (adap->inode = inode->i_ino)) + break; + } + if ( I2C_ADAP_MAX = i ) { + up(&core_lists); + return -ENOENT; + } + + /* We need a bit of slack in the kernel buffer; this makes the + sprintf safe. */ + if (! (kbuf = kmalloc(len_total + + OUTPUT_LENGTH_PER_LINE, + GFP_KERNEL))) + return -ENOMEM; + + /* Order will hold the indexes of the clients + sorted by address */ + order_nr=0; + down(&adap->list); + for (j = 0; j < I2C_CLIENT_MAX; j++) { + if ((client = adap->clients[j]) && + (client->driver->id != I2C_DRIVERID_I2CDEV)) { + for(k = order_nr; + (k > 0) && + adap->clients[order[k-1]]-> + addr > client->addr; + k--) + order[k] = order[k-1]; + order[k] = j; + order_nr++; + } + } - for (j = 0; (j < order_nr) && (len < len_total); j++) { - client = adapters[i]->clients[order[j]]; - len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n", - client->addr, - client->name, - client->driver->name); - } - len = len - file->f_pos; - if (len > count) - len = count; - 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; + for (j = 0; (j < order_nr) && (len < len_total); j++) { + client = adap->clients[order[j]]; + len += sprintf(kbuf+len,"%02x\t%-32s\t%-32s\n", + client->addr, + client->name, + client->driver->name); + } + up(&adap->list); + up(&core_lists); + + len = len - file->f_pos; + if (len > count) + len = count; + 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; } static int __init i2cproc_init(void) @@ -731,9 +713,9 @@ DEB2(printk(KERN_DEBUG "i2c-core.o: master_xfer: %s with %d msgs.\n", adap->name,num)); - I2C_LOCK(adap); + down(&adap->bus); ret = adap->algo->master_xfer(adap,msgs,num); - I2C_UNLOCK(adap); + up(&adap->bus); return ret; } else { @@ -758,9 +740,9 @@ DEB2(printk(KERN_DEBUG "i2c-core.o: master_send: writing %d bytes on %s.\n", count,client->adapter->name)); - I2C_LOCK(adap); + down(&adap->bus); ret = adap->algo->master_xfer(adap,&msg,1); - I2C_UNLOCK(adap); + up(&adap->bus); /* if everything went ok (i.e. 1 msg transmitted), return #bytes * transmitted, else error code. @@ -788,9 +770,9 @@ DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: reading %d bytes on %s.\n", count,client->adapter->name)); - I2C_LOCK(adap); + down(&adap->bus); ret = adap->algo->master_xfer(adap,&msg,1); - I2C_UNLOCK(adap); + up(&adap->bus); DEB2(printk(KERN_DEBUG "i2c-core.o: master_recv: return:%d (count:%d, addr:0x%02x)\n", ret, count, client->addr)); @@ -1231,12 +1213,7 @@ printk(KERN_INFO "i2c-core.o: i2c core module version %s (%s)\n", I2C_VERSION, I2C_DATE); memset(adapters,0,sizeof(adapters)); memset(drivers,0,sizeof(drivers)); - adap_count=0; - driver_count=0; - init_MUTEX(&adap_lock); - init_MUTEX(&driver_lock); - i2cproc_init(); return 0; Only in lk-i2c-km-3/drivers/i2c: i2c-core.c~ diff -ur lk-i2c-km-2/include/linux/i2c.h lk-i2c-km-3/include/linux/i2c.h --- lk-i2c-km-2/include/linux/i2c.h 2003-12-23 00:41:41.000000000 +0200 +++ lk-i2c-km-3/include/linux/i2c.h 2003-12-23 12:33:15.000000000 +0200 @@ -235,11 +235,11 @@ /* and can be set via the i2c_ioctl call */ /* data fields that are valid for all devices */ - struct semaphore lock; + struct semaphore bus; + struct semaphore list; unsigned int flags;/* flags specifying div. data */ struct i2c_client *clients[I2C_CLIENT_MAX]; - int client_count; int timeout; int retries; Only in lk-i2c-km-3/include/linux: i2c.h~
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 95 lines · Jean Delvare
Quoted 6 lines
Jean, here is something to start with. Tested to apply cleanly over 2.4.23 after your set of 4 patches.
Patch -km-1 :
Remove code for
KERNEL_VERSIONtests.Great. This was on my TODO list. I think I'll tweak it a bit, to remove
version.hincludes which aren't necessary anymore (I guess) and merge empty lines where it applies. Also, this patch might conflict with the one I wrote on posted to the list yesterday (which cleans modules init/exit handling). But basically you got it, this is something I wanted to send to Marcelo.Quoted 4 lines
Patch -km-2 :
This has .owner and .inc/dec_use for reference counting. Also, C99 initializers and initcalls are imported from i2c CVS head.
What are initcalls.
Quoted 1 line
No new drivers, SMBus commands or driver ID's.
Good point.
Quoted 2 lines
This is about 1/4 of changes needed to bring 2.4.24 in-sync with i2c 2.8.2.
Sure this is an important part, this is even the reason why all these started.
But there's a problem. As discussed on the list the last few days, i2c as of CVS head does not handle module reference counting correctly. So we cannot possibly send this patch to Marcelo before this issue is fixed. Since you seem to know how to fix it, please commit the necessary changes to CVS head (I don't think it is a good idea to branch the CVS, it's just not worth it). I do well understand that, even with the fix, the reference counting will be broken, but at least it won't be worse than in the previous implementation (that is, moving into
/proc/.../somechip/increases the chip use count, but not the bus use count). This is required before we can send any inc/dec-to-owner patch to Marcelo.Quoted 2 lines
At least i2c-proc is not yet in sync with 2.8.0, so sensor chips will not build.
This was expected. They don't build either as of now anyway ;)
Quoted 3 lines
I probably forgot some tiny parts elsewhere too but seems you were working on similar cleanups so maybe this is some assistance.
Your help is very appreciated, since there is much much work to do and we are runnign out of time.
Quoted 1 line
We cannot get 200kB+ patches through anyway.
Yes, that's the idea (and I don't consider it a problem, since this ensures that what we are sending is valid and doesn't bring any regression into the kernel tree).
Quoted 4 lines
I'll prepare some more patches today. Driver ID's, SMBus commands, and i2c-proc. The in-file revision tag $id has not been in sync with CVS files for ages and I plan to unexpand them with a separate patch.
IDs is an easy and independant patch, I should be able to go with it if you don't.
New SMBus commands are not to be commited for now, if ever. They are new
functionalities, I doubt Marcelo will want them into Linux 2.4.The i2c-proc patches (and anything related to the core or spread over all drivers) are what is more important, both because it might need to be done before other minor changes, and because I don't understand it too well, so that's where your help will be really precious.
Thanks a lot for providing assistance in backporting CVS to Linux 2.4. Keep in mind that all changes have to be as sliced as possible if we want them accepted.
I will be submitting a new wave of patches to Marcelo rather soon, which should include (list is not definitive):
- init/exit cleanups (me)
- compatibility cleanups (you)
- velleman doc (me)
- algo debug stuff removal (me)I'll let you know as soon as I'm working on other patches so that we can merge our efforts efficiently.
Thanks again.
Signature · 1 line
Ky?sti M?lkki <[email protected]> +358 50 462 8786
PATCH 1/1 i2c cleanups
In reply to Jean DelvareThis time, with the message ;)
Patch -km-4:
Clean /proc/bus/i2c initialization.
Patch -km-5:
Forgot one use I2C_LOCK earlier in -km-3.
Signature · 227 lines
Ky?sti M?lkki <[email protected]> -------------- next part -------------- diff -ur lk-i2c-km-4/drivers/i2c/i2c-core.c lk-i2c-km-5/drivers/i2c/i2c-core.c --- lk-i2c-km-4/drivers/i2c/i2c-core.c 2003-12-23 14:16:38.000000000 +0200 +++ lk-i2c-km-5/drivers/i2c/i2c-core.c 2003-12-23 14:57:49.000000000 +0200 @@ -1155,20 +1155,22 @@ } -s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, +s32 i2c_smbus_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, char read_write, u8 command, int size, union i2c_smbus_data * data) { s32 res; - flags = flags & I2C_M_TEN; - if (adapter->algo->smbus_xfer) { - I2C_LOCK(adapter); - res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write, + + flags &= I2C_M_TEN; + if (adap->algo->smbus_xfer) { + down(&adap->bus); + res = adap->algo->smbus_xfer(adap,addr,flags,read_write, command,size,data); - I2C_UNLOCK(adapter); + up(&adap->bus); } else - res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, + res = i2c_smbus_xfer_emulated(adap,addr,flags,read_write, command,size,data); + return res; } -------------- next part -------------- diff -ur lk-i2c-km-3/drivers/i2c/i2c-core.c lk-i2c-km-4/drivers/i2c/i2c-core.c --- lk-i2c-km-3/drivers/i2c/i2c-core.c 2003-12-23 14:45:22.000000000 +0200 +++ lk-i2c-km-4/drivers/i2c/i2c-core.c 2003-12-23 14:16:38.000000000 +0200 @@ -52,11 +52,6 @@ */ #ifdef CONFIG_PROC_FS - -static int i2cproc_init(void); -static void i2cproc_cleanup(void); - - 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, @@ -65,16 +60,11 @@ /* To implement the dynamic /proc/bus/i2c-? files, we need our own implementation of the read hook */ static struct file_operations i2cproc_operations = { - read: i2cproc_bus_read, + .read = i2cproc_bus_read, }; - -static int i2cproc_initialized = 0; - -#else /* undef CONFIG_PROC_FS */ - -#define i2cproc_init() 0 -#define i2cproc_cleanup() 0 +static int i2cproc_register(struct i2c_adapter *adap, int bus); +static void i2cproc_remove(int bus); #endif /* CONFIG_PROC_FS */ @@ -91,7 +81,7 @@ */ int i2c_add_adapter(struct i2c_adapter *adap) { - int i,j,res; + int i,j,res = 0; down(&core_lists); for (i = 0; i < I2C_ADAP_MAX; i++) @@ -104,34 +94,18 @@ res = -ENOMEM; goto ERROR0; } + +#ifdef CONFIG_PROC_FS + res = i2cproc_register(adap, i); + if (res<0) + goto ERROR0; +#endif /* def CONFIG_PROC_FS */ adapters[i] = adap; /* init data types */ init_MUTEX(&adap->bus); init_MUTEX(&adap->list); -#ifdef CONFIG_PROC_FS - - if (i2cproc_initialized) { - char name[8]; - struct proc_dir_entry *proc_entry; - - sprintf(name,"i2c-%d", i); - - proc_entry = create_proc_entry(name,0,proc_bus); - if (! proc_entry) { - printk("i2c-core.o: Could not create /proc/bus/%s\n", - name); - res = -ENOENT; - goto ERROR1; - } - - proc_entry->proc_fops = &i2cproc_operations; - proc_entry->owner = THIS_MODULE; - adap->inode = proc_entry->low_ino; - } - -#endif /* def CONFIG_PROC_FS */ /* inform drivers of new adapters */ for (j=0;j<I2C_DRIVER_MAX;j++) @@ -194,16 +168,13 @@ goto ERROR0; } } + #ifdef CONFIG_PROC_FS - if (i2cproc_initialized) { - char name[8]; - sprintf(name,"i2c-%d", i); - remove_proc_entry(name,proc_bus); - } + i2cproc_remove(i); #endif /* def CONFIG_PROC_FS */ adapters[i] = NULL; - DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name)); + DEB(printk(KERN_DEBUG "i2c-core.o: adapter unregistered: %s\n",adap->name)); ERROR0: up(&core_lists); return res; @@ -663,41 +634,52 @@ return len; } -static int __init i2cproc_init(void) +static int i2cproc_register(struct i2c_adapter *adap, int bus) { + char name[8]; + struct proc_dir_entry *proc_entry; - struct proc_dir_entry *proc_bus_i2c; + sprintf(name,"i2c-%d", bus); + proc_entry = create_proc_entry(name,0,proc_bus); + if (! proc_entry) { + printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/%s\n", + name); + return -ENOENT; + } + + proc_entry->proc_fops = &i2cproc_operations; + proc_entry->owner = adap->owner; + adap->inode = proc_entry->low_ino; + return 0; +} - i2cproc_initialized = 0; +static void i2cproc_remove(int bus) +{ + char name[8]; + sprintf(name,"i2c-%d", bus); + remove_proc_entry(name, proc_bus); +} + +static int __init i2cproc_init(void) +{ + struct proc_dir_entry *proc_bus_i2c; - if (! proc_bus) { - printk("i2c-core.o: /proc/bus/ does not exist"); - i2cproc_cleanup(); - return -ENOENT; - } proc_bus_i2c = create_proc_entry("i2c",0,proc_bus); if (!proc_bus_i2c) { printk(KERN_ERR "i2c-core.o: Could not create /proc/bus/i2c"); - i2cproc_cleanup(); return -ENOENT; } + proc_bus_i2c->read_proc = &read_bus_i2c; proc_bus_i2c->owner = THIS_MODULE; - i2cproc_initialized += 2; return 0; } static void __exit i2cproc_cleanup(void) { - - if (i2cproc_initialized >= 1) { - remove_proc_entry("i2c",proc_bus); - i2cproc_initialized -= 2; - } - return 0; + remove_proc_entry("i2c",proc_bus); } - #endif /* def CONFIG_PROC_FS */ /* ---------------------------------------------------- @@ -1214,9 +1196,12 @@ memset(adapters,0,sizeof(adapters)); memset(drivers,0,sizeof(drivers)); - i2cproc_init(); - +#ifdef CONFIG_PROC_FS + return i2cproc_init(); +#else return 0; +#endif + } static void __exit i2c_exit(void) Only in lk-i2c-km-3/drivers/i2c: i2c-core.c.orig
PATCH 1/1 i2c cleanups
In reply to Jean DelvareForget about -km-2 and -km-6. I will post them in smaller parts.
Patch -km-7 : Drop 2.2 code.
Patch -km-8 : User progs don't include kernel files. Patch -km-9 : Message block size.
Patch -km-10 : Remove SLO_IO in algo-bit. Patch -km-11 : Bus scan removal, bit & pcf. Patch -km-12 : Add new IDs.
Patch -km-13 : Unused code, whitespace.
Yes, christmas got cancelled ;)
Signature · 625 lines
Ky?sti M?lkki <[email protected]> -------------- next part -------------- Only in lk-i2c-km-7/drivers/i2c: i2c-dev.c.orig diff -ur lk-i2c-km-6/drivers/i2c/i2c-proc.c lk-i2c-km-7/drivers/i2c/i2c-proc.c --- lk-i2c-km-6/drivers/i2c/i2c-proc.c 2003-12-22 21:09:37.000000000 +0200 +++ lk-i2c-km-7/drivers/i2c/i2c-proc.c 2003-12-25 11:38:16.000000000 +0200 @@ -209,48 +209,6 @@ } } -/* Monitor access for /proc/sys/dev/sensors; make unloading i2c-proc.o - impossible if some process still uses it or some file in it */ -void i2c_fill_inode(struct inode *inode, int fill) -{ - if (fill) - MOD_INC_USE_COUNT; - else - MOD_DEC_USE_COUNT; -} - -/* Monitor access for /proc/sys/dev/sensors/ directories; make unloading - the corresponding module impossible if some process still uses it or - some file in it */ -void i2c_dir_fill_inode(struct inode *inode, int fill) -{ - int i; - struct i2c_client *client; - -#ifdef DEBUG - if (!inode) { - printk("i2c-proc.o: Warning: inode NULL in fill_inode()\n"); - return; - } -#endif /* def DEBUG */ - - for (i = 0; i < SENSORS_ENTRY_MAX; i++) - if (i2c_clients[i] - && (i2c_inodes[i] = inode->i_ino)) break; -#ifdef DEBUG - if (i = SENSORS_ENTRY_MAX) { - printk - ("i2c-proc.o: Warning: inode (%ld) not found in fill_inode()\n", - inode->i_ino); - return; - } -#endif /* def DEBUG */ - client = i2c_clients[i]; - if (fill) - client->driver->inc_use(client); - else - client->driver->dec_use(client); -} int i2c_proc_chips(ctl_table * ctl, int write, struct file *filp, void *buffer, size_t * lenp) Only in lk-i2c-km-7/drivers/i2c: i2c-proc.c~ -------------- next part -------------- Only in lk-i2c-km-7/drivers/i2c: i2c-dev.c.orig Only in lk-i2c-km-7/drivers/i2c: i2c-proc.c~ diff -ur lk-i2c-km-7/include/linux/i2c-dev.h lk-i2c-km-8/include/linux/i2c-dev.h --- lk-i2c-km-7/include/linux/i2c-dev.h 2003-12-23 00:41:47.000000000 +0200 +++ lk-i2c-km-8/include/linux/i2c-dev.h 2003-12-25 12:19:20.000000000 +0200 @@ -43,137 +43,4 @@ __u32 nmsgs; /* number of i2c_msgs */ }; -#ifndef __KERNEL__ - -#include <sys/ioctl.h> - -static inline __s32 i2c_smbus_access(int file, char read_write, __u8 command, - int size, union i2c_smbus_data *data) -{ - struct i2c_smbus_ioctl_data args; - - args.read_write = read_write; - args.command = command; - args.size = size; - args.data = data; - return ioctl(file,I2C_SMBUS,&args); -} - - -static inline __s32 i2c_smbus_write_quick(int file, __u8 value) -{ - return i2c_smbus_access(file,value,0,I2C_SMBUS_QUICK,NULL); -} - -static inline __s32 i2c_smbus_read_byte(int file) -{ - union i2c_smbus_data data; - if (i2c_smbus_access(file,I2C_SMBUS_READ,0,I2C_SMBUS_BYTE,&data)) - return -1; - else - return 0x0FF & data.byte; -} - -static inline __s32 i2c_smbus_write_byte(int file, __u8 value) -{ - return i2c_smbus_access(file,I2C_SMBUS_WRITE,value, - I2C_SMBUS_BYTE,NULL); -} - -static inline __s32 i2c_smbus_read_byte_data(int file, __u8 command) -{ - union i2c_smbus_data data; - if (i2c_smbus_access(file,I2C_SMBUS_READ,command, - I2C_SMBUS_BYTE_DATA,&data)) - return -1; - else - return 0x0FF & data.byte; -} - -static inline __s32 i2c_smbus_write_byte_data(int file, __u8 command, - __u8 value) -{ - union i2c_smbus_data data; - data.byte = value; - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command, - I2C_SMBUS_BYTE_DATA, &data); -} - -static inline __s32 i2c_smbus_read_word_data(int file, __u8 command) -{ - union i2c_smbus_data data; - if (i2c_smbus_access(file,I2C_SMBUS_READ,command, - I2C_SMBUS_WORD_DATA,&data)) - return -1; - else - return 0x0FFFF & data.word; -} - -static inline __s32 i2c_smbus_write_word_data(int file, __u8 command, - __u16 value) -{ - union i2c_smbus_data data; - data.word = value; - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command, - I2C_SMBUS_WORD_DATA, &data); -} - -static inline __s32 i2c_smbus_process_call(int file, __u8 command, __u16 value) -{ - union i2c_smbus_data data; - data.word = value; - if (i2c_smbus_access(file,I2C_SMBUS_WRITE,command, - I2C_SMBUS_PROC_CALL,&data)) - return -1; - else - return 0x0FFFF & data.word; -} - - -/* Returns the number of read bytes */ -static inline __s32 i2c_smbus_read_block_data(int file, __u8 command, - __u8 *values) -{ - union i2c_smbus_data data; - int i; - if (i2c_smbus_access(file,I2C_SMBUS_READ,command, - I2C_SMBUS_BLOCK_DATA,&data)) - return -1; - else { - for (i = 1; i <= data.block[0]; i++) - values[i-1] = data.block[i]; - return data.block[0]; - } -} - -static inline __s32 i2c_smbus_write_block_data(int file, __u8 command, - __u8 length, __u8 *values) -{ - union i2c_smbus_data data; - int i; - if (length > 32) - length = 32; - for (i = 1; i <= length; i++) - data.block[i] = values[i-1]; - data.block[0] = length; - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command, - I2C_SMBUS_BLOCK_DATA, &data); -} - -static inline __s32 i2c_smbus_write_i2c_block_data(int file, __u8 command, - __u8 length, __u8 *values) -{ - union i2c_smbus_data data; - int i; - if (length > 32) - length = 32; - for (i = 1; i <= length; i++) - data.block[i] = values[i-1]; - data.block[0] = length; - return i2c_smbus_access(file,I2C_SMBUS_WRITE,command, - I2C_SMBUS_I2C_BLOCK_DATA, &data); -} - -#endif /* ndef __KERNEL__ */ - -#endif +#endif /* _LINUX_I2C_DEV_H */ Only in lk-i2c-km-8/include/linux: i2c-dev.h~ -------------- next part -------------- diff -ur lk-i2c-km-8/drivers/i2c/i2c-core.c lk-i2c-km-9/drivers/i2c/i2c-core.c --- lk-i2c-km-8/drivers/i2c/i2c-core.c 2003-12-25 14:34:50.000000000 +0200 +++ lk-i2c-km-9/drivers/i2c/i2c-core.c 2003-12-25 14:36:41.000000000 +0200 @@ -1029,8 +1029,8 @@ { union i2c_smbus_data data; int i; - if (length > 32) - length = 32; + if (length > I2C_SMBUS_BLOCK_MAX) + length = I2C_SMBUS_BLOCK_MAX; for (i = 1; i <= length; i++) data.block[i] = values[i-1]; data.block[0] = length; @@ -1044,8 +1044,8 @@ { union i2c_smbus_data data; int i; - if (length > 32) - length = 32; + if (length > I2C_SMBUS_I2C_BLOCK_MAX) + length = I2C_SMBUS_I2C_BLOCK_MAX; for (i = 1; i <= length; i++) data.block[i] = values[i-1]; data.block[0] = length; @@ -1119,7 +1119,7 @@ return -1; } else { msg[0].len = data->block[0] + 2; - if (msg[0].len > 34) { + if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { printk(KERN_ERR "i2c-core.o: smbus_access called with " "invalid block write size (%d)\n", msg[0].len); Only in lk-i2c-km-9/drivers/i2c: i2c-core.c~ diff -ur lk-i2c-km-8/include/linux/i2c.h lk-i2c-km-9/include/linux/i2c.h --- lk-i2c-km-8/include/linux/i2c.h 2003-12-25 14:34:50.000000000 +0200 +++ lk-i2c-km-9/include/linux/i2c.h 2003-12-25 14:37:56.000000000 +0200 @@ -405,10 +405,11 @@ /* * Data for SMBus Messages */ +#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */ union i2c_smbus_data { __u8 byte; __u16 word; - __u8 block[33]; /* block[0] is used for length */ + __u8 block[I2C_SMBUS_BLOCK_MAX + 1]; /* block[0] is used for length */ }; /* smbus_access read or write markers */ Only in lk-i2c-km-9/include/linux: i2c.h~ -------------- next part -------------- diff -ur lk-i2c-km-9/drivers/i2c/i2c-algo-bit.c lk-i2c-km-10/drivers/i2c/i2c-algo-bit.c --- lk-i2c-km-9/drivers/i2c/i2c-algo-bit.c 2003-12-25 14:59:06.000000000 +0200 +++ lk-i2c-km-10/drivers/i2c/i2c-algo-bit.c 2003-12-25 14:58:35.000000000 +0200 @@ -41,22 +41,9 @@ #define DEBPROTO(x) if (i2c_debug>=9) { x; } /* debug the protocol by showing transferred bits */ -/* debugging - slow down transfer to have a look at the data .. */ -/* I use this with two leds&resistors, each one connected to sda,scl */ -/* respectively. This makes sure that the algorithm works. Some chips */ -/* might not like this, as they have an internal timeout of some mils */ -/* -#define SLO_IO jif=jiffies;while(time_before_eq(jiffies, jif+i2c_table[minor].veryslow))\ - if (need_resched) schedule(); -*/ - /* ----- global variables --------------------------------------------- */ -#ifdef SLO_IO - int jif; -#endif - /* module parameters: */ static int i2c_debug; @@ -86,9 +73,6 @@ { setscl(adap,0); udelay(adap->udelay); -#ifdef SLO_IO - SLO_IO -#endif } /* @@ -121,9 +105,6 @@ schedule(); } DEBSTAT(printk(KERN_DEBUG "needed %ld jiffies\n", jiffies-start)); -#ifdef SLO_IO - SLO_IO -#endif return 0; } Only in lk-i2c-km-10/drivers/i2c: i2c-algo-bit.c~ -------------- next part -------------- diff -ur lk-i2c-km-10/drivers/i2c/i2c-algo-bit.c lk-i2c-km-11/drivers/i2c/i2c-algo-bit.c --- lk-i2c-km-10/drivers/i2c/i2c-algo-bit.c 2003-12-25 14:58:35.000000000 +0200 +++ lk-i2c-km-11/drivers/i2c/i2c-algo-bit.c 2003-12-25 15:03:09.000000000 +0200 @@ -48,7 +48,6 @@ */ static int i2c_debug; static int bit_test; /* see if the line-setting functions work */ -static int bit_scan; /* have a look at what's hanging 'round */ /* --- setting states on the bus with the right timing: --------------- */ @@ -521,7 +520,6 @@ */ int i2c_bit_add_bus(struct i2c_adapter *adap) { - int i; struct i2c_algo_bit_data *bit_adap = adap->algo_data; if (bit_test) { @@ -541,23 +539,6 @@ adap->timeout = 100; /* default values, should */ adap->retries = 3; /* be replaced by defines */ - /* scan bus */ - if (bit_scan) { - int ack; - printk(KERN_INFO " i2c-algo-bit.o: scanning bus %s.\n", - adap->name); - for (i = 0x00; i < 0xff; i+=2) { - i2c_start(bit_adap); - ack = i2c_outb(adap,i); - i2c_stop(bit_adap); - if (ack>0) { - printk("(%02x)",i>>1); - } else - printk("."); - } - printk("\n"); - } - i2c_add_adapter(adap); return 0; } @@ -576,10 +557,8 @@ MODULE_LICENSE("GPL"); MODULE_PARM(bit_test, "i"); -MODULE_PARM(bit_scan, "i"); MODULE_PARM(i2c_debug,"i"); MODULE_PARM_DESC(bit_test, "Test the lines of the bus to see if it is stuck"); -MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus"); MODULE_PARM_DESC(i2c_debug, "debug level - 0 off; 1 normal; 2,3 more verbose; 9 bit-protocol"); diff -ur lk-i2c-km-10/drivers/i2c/i2c-algo-pcf.c lk-i2c-km-11/drivers/i2c/i2c-algo-pcf.c --- lk-i2c-km-10/drivers/i2c/i2c-algo-pcf.c 2003-12-22 23:22:21.000000000 +0200 +++ lk-i2c-km-11/drivers/i2c/i2c-algo-pcf.c 2003-12-25 15:03:03.000000000 +0200 @@ -48,7 +48,6 @@ /* module parameters: */ static int i2c_debug=0; -static int pcf_scan=0; /* have a look at what's hanging 'round */ /* --- setting states on the bus with the right timing: --------------- */ @@ -469,30 +468,6 @@ } i2c_add_adapter(adap); - - /* scan bus */ - if (pcf_scan) { - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s.\n", - adap->name); - for (i = 0x00; i < 0xff; i+=2) { - if (wait_for_bb(pcf_adap)) { - printk(KERN_INFO " i2c-algo-pcf.o: scanning bus %s - TIMEOUTed.\n", - adap->name); - break; - } - i2c_outb(pcf_adap, i); - i2c_start(pcf_adap); - if ((wait_for_pin(pcf_adap, &status) >= 0) && - ((status & I2C_PCF_LRB) = 0)) { - printk("(%02x)",i>>1); - } else { - printk("."); - } - i2c_stop(pcf_adap); - udelay(pcf_adap->udelay); - } - printk("\n"); - } return 0; } @@ -509,9 +484,6 @@ MODULE_DESCRIPTION("I2C-Bus PCF8584 algorithm"); MODULE_LICENSE("GPL"); -MODULE_PARM(pcf_scan, "i"); MODULE_PARM(i2c_debug,"i"); - -MODULE_PARM_DESC(pcf_scan, "Scan for active chips on the bus"); MODULE_PARM_DESC(i2c_debug, "debug level - 0 off; 1 normal; 2,3 more verbose; 9 pcf-protocol"); -------------- next part -------------- diff -ur lk-i2c-km-11/include/linux/i2c-id.h lk-i2c-km-12/include/linux/i2c-id.h --- lk-i2c-km-11/include/linux/i2c-id.h 2003-12-22 20:50:13.000000000 +0200 +++ lk-i2c-km-12/include/linux/i2c-id.h 2003-12-25 15:13:18.000000000 +0200 @@ -91,7 +91,23 @@ #define I2C_DRIVERID_DRP3510 43 /* ADR decoder (Astra Radio) */ #define I2C_DRIVERID_SP5055 44 /* Satellite tuner */ #define I2C_DRIVERID_STV0030 45 /* Multipurpose switch */ +#define I2C_DRIVERID_SAA7108 46 /* video decoder, image scaler */ +#define I2C_DRIVERID_DS1307 47 /* DS1307 real time clock */ #define I2C_DRIVERID_ADV7175 48 /* ADV 7175/7176 video encoder */ +#define I2C_DRIVERID_ZR36067 49 /* Zoran 36067 video encoder */ +#define I2C_DRIVERID_ZR36120 50 /* Zoran 36120 video encoder */ +#define I2C_DRIVERID_24LC32A 51 /* Microchip 24LC32A 32k EEPROM */ +#define I2C_DRIVERID_STM41T00 52 /* real time clock */ +#define I2C_DRIVERID_UDA1342 53 /* UDA1342 audio codec */ +#define I2C_DRIVERID_ADV7170 54 /* video encoder */ +#define I2C_DRIVERID_RADEON 55 /* I2C bus on Radeon boards */ +#define I2C_DRIVERID_MAX1617 56 /* temp sensor */ +#define I2C_DRIVERID_SAA7191 57 /* video encoder */ +#define I2C_DRIVERID_INDYCAM 58 /* SGI IndyCam */ +#define I2C_DRIVERID_BT832 59 /* CMOS camera video processor */ +#define I2C_DRIVERID_TDA9887 60 /* TDA988x IF-PLL demodulator */ + + #define I2C_DRIVERID_EXP0 0xF0 /* experimental use id's */ #define I2C_DRIVERID_EXP1 0xF1 @@ -100,6 +116,8 @@ #define I2C_DRIVERID_I2CDEV 900 #define I2C_DRIVERID_I2CPROC 901 +#define I2C_DRIVERID_ARP 902 /* SMBus ARP Client */ +#define I2C_DRIVERID_ALERT 903 /* SMBus Alert Responder Client */ /* IDs -- Use DRIVERIDs 1000-1999 for sensors. These were originally in sensors.h in the lm_sensors package */ @@ -129,6 +147,25 @@ #define I2C_DRIVERID_ADM1024 1025 #define I2C_DRIVERID_IT87 1026 #define I2C_DRIVERID_CH700X 1027 /* single driver for CH7003-7009 digital pc to tv encoders */ +#define I2C_DRIVERID_FSCPOS 1028 +#define I2C_DRIVERID_FSCSCY 1029 +#define I2C_DRIVERID_PCF8591 1030 +#define I2C_DRIVERID_SMSC47M1 1031 +#define I2C_DRIVERID_VT1211 1032 +#define I2C_DRIVERID_LM92 1033 +#define I2C_DRIVERID_VT8231 1034 +#define I2C_DRIVERID_SMARTBATT 1035 +#define I2C_DRIVERID_BMCSENSORS 1036 +#define I2C_DRIVERID_FS451 1037 +#define I2C_DRIVERID_W83627HF 1038 +#define I2C_DRIVERID_LM85 1039 +#define I2C_DRIVERID_LM83 1040 +#define I2C_DRIVERID_SAA1064 1041 +#define I2C_DRIVERID_LM90 1042 +#define I2C_DRIVERID_ASB100 1043 +#define I2C_DRIVERID_MAX6650 1044 +#define I2C_DRIVERID_XEONTEMP 1045 +#define I2C_DRIVERID_FSCHER 1046 /* * ---- Adapter types ---------------------------------------------------- @@ -145,10 +182,21 @@ #define I2C_ALGO_ISA 0x050000 /* lm_sensors ISA pseudo-adapter */ #define I2C_ALGO_SAA7146 0x060000 /* SAA 7146 video decoder bus */ #define I2C_ALGO_ACB 0x070000 /* ACCESS.bus algorithm */ - +#define I2C_ALGO_IIC 0x080000 /* ITE IIC bus */ +#define I2C_ALGO_SAA7134 0x090000 +#define I2C_ALGO_MPC824X 0x0a0000 /* Motorola 8240 / 8245 */ +#define I2C_ALGO_IPMI 0x0b0000 /* IPMI dummy adapter */ +#define I2C_ALGO_IPMB 0x0c0000 /* IPMB adapter */ +#define I2C_ALGO_MPC107 0x0d0000 #define I2C_ALGO_EC 0x100000 /* ACPI embedded controller */ #define I2C_ALGO_MPC8XX 0x110000 /* MPC8xx PowerPC I2C algorithm */ +#define I2C_ALGO_OCP 0x120000 /* IBM or otherwise On-chip I2C algorithm */ +#define I2C_ALGO_BITHS 0x130000 /* enhanced bit style adapters */ +#define I2C_ALGO_OCP_IOP3XX 0x140000 /* XSCALE IOP3XX On-chip I2C alg */ +#define I2C_ALGO_SIBYTE 0x150000 /* Broadcom SiByte SOCs */ +#define I2C_ALGO_SGI 0x160000 /* SGI algorithm */ +#define I2C_ALGO_USB 0x170000 /* USB algorithm */ #define I2C_ALGO_EXP 0x800000 /* experimental */ @@ -176,21 +224,46 @@ #define I2C_HW_B_I810 0x0a /* Intel I810 */ #define I2C_HW_B_VOO 0x0b /* 3dfx Voodoo 3 / Banshee */ #define I2C_HW_B_PPORT 0x0c /* Primitive parallel port adapter */ +#define I2C_HW_B_SAVG 0x0d /* Savage 4 */ +#define I2C_HW_B_SCX200 0x0e /* Nat'l Semi SCx200 I2C */ #define I2C_HW_B_RIVA 0x10 /* Riva based graphics cards */ #define I2C_HW_B_IOC 0x11 /* IOC bit-wiggling */ #define I2C_HW_B_TSUNA 0x12 /* DEC Tsunami chipset */ +#define I2C_HW_B_FRODO 0x13 /* 2d3D, Inc. SA-1110 Development Board */ +#define I2C_HW_B_OMAHA 0x14 /* Omaha I2C interface (ARM) */ +#define I2C_HW_B_GUIDE 0x15 /* Guide bit-basher */ +#define I2C_HW_B_IXP2000 0x16 /* GPIO on IXP2000 systems */ +#define I2C_HW_B_IXP425 0x17 /* GPIO on IXP425 systems */ +#define I2C_HW_B_S3VIA 0x18 /* S3Via ProSavage adapter */ +#define I2C_HW_B_ZR36067 0x19 /* Zoran-36057/36067 based boards */ +#define I2C_HW_B_PCILYNX 0x20 /* TI PCILynx I2C adapter */ /* --- PCF 8584 based algorithms */ #define I2C_HW_P_LP 0x00 /* Parallel port interface */ #define I2C_HW_P_ISA 0x01 /* generic ISA Bus inteface card */ #define I2C_HW_P_ELEK 0x02 /* Elektor ISA Bus inteface card */ +/* --- USB based adapters */ +#define I2C_HW_USB_USBVISION 0x00 + /* --- ACPI Embedded controller algorithms */ #define I2C_HW_ACPI_EC 0x00 +/* --- MPC824x PowerPC adapters */ +#define I2C_HW_MPC824X 0x00 /* Motorola 8240 / 8245 */ + /* --- MPC8xx PowerPC adapters */ #define I2C_HW_MPC8XX_EPON 0x00 /* Eponymous MPC8xx I2C adapter */ +/* --- ITE based algorithms */ +#define I2C_HW_I_IIC 0x00 /* controller on the ITE */ + +/* --- PowerPC on-chip adapters */ +#define I2C_HW_OCP 0x00 /* IBM on-chip I2C adapter */ + +/* --- XSCALE on-chip adapters */ +#define I2C_HW_IOP321 0x00 + /* --- SMBus only adapters */ #define I2C_HW_SMBUS_PIIX4 0x00 #define I2C_HW_SMBUS_ALI15X3 0x01 @@ -200,9 +273,23 @@ #define I2C_HW_SMBUS_AMD756 0x05 #define I2C_HW_SMBUS_SIS5595 0x06 #define I2C_HW_SMBUS_ALI1535 0x07 +#define I2C_HW_SMBUS_SIS630 0x08 +#define I2C_HW_SMBUS_SIS645 0x09 +#define I2C_HW_SMBUS_AMD8111 0x0a +#define I2C_HW_SMBUS_SCX200 0x0b +#define I2C_HW_SMBUS_NFORCE2 0x0c #define I2C_HW_SMBUS_W9968CF 0x0d /* --- ISA pseudo-adapter */ #define I2C_HW_ISA 0x00 -#endif /* I2C_ID_H */ +/* --- IPMI pseudo-adapter */ +#define I2C_HW_IPMI 0x00 + +/* --- IPMB adapter */ +#define I2C_HW_IPMB 0x00 + +/* --- MCP107 adapter */ +#define I2C_HW_MPC107 0x00 + +#endif /* LINUX_I2C_ID_H */ Only in lk-i2c-km-12/include/linux: i2c-id.h~ -------------- next part -------------- diff -ur lk-i2c-km-12/drivers/i2c/i2c-algo-bit.c lk-i2c-km-13/drivers/i2c/i2c-algo-bit.c --- lk-i2c-km-12/drivers/i2c/i2c-algo-bit.c 2003-12-25 15:11:02.000000000 +0200 +++ lk-i2c-km-13/drivers/i2c/i2c-algo-bit.c 2003-12-25 15:41:06.000000000 +0200 @@ -492,12 +492,6 @@ return num; } -static int algo_control(struct i2c_adapter *adapter, - unsigned int cmd, unsigned long arg) -{ - return 0; -} - static u32 bit_func(struct i2c_adapter *adap) { return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | diff -ur lk-i2c-km-12/drivers/i2c/i2c-algo-pcf.c lk-i2c-km-13/drivers/i2c/i2c-algo-pcf.c --- lk-i2c-km-12/drivers/i2c/i2c-algo-pcf.c 2003-12-25 15:11:02.000000000 +0200 +++ lk-i2c-km-13/drivers/i2c/i2c-algo-pcf.c 2003-12-25 15:37:56.000000000 +0200 @@ -422,12 +422,6 @@ return (i); } -static int algo_control(struct i2c_adapter *adapter, - unsigned int cmd, unsigned long arg) -{ - return 0; -} - static u32 pcf_func(struct i2c_adapter *adap) { return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR | @@ -449,7 +443,7 @@ */ int i2c_pcf_add_bus(struct i2c_adapter *adap) { - int i, status; + int i; struct i2c_algo_pcf_data *pcf_adap = adap->algo_data; DEB2(printk(KERN_DEBUG "i2c-algo-pcf.o: hw routines for %s registered.\n", diff -ur lk-i2c-km-12/drivers/i2c/i2c-core.c lk-i2c-km-13/drivers/i2c/i2c-core.c --- lk-i2c-km-12/drivers/i2c/i2c-core.c 2003-12-25 14:39:23.000000000 +0200 +++ lk-i2c-km-13/drivers/i2c/i2c-core.c 2003-12-25 15:19:51.000000000 +0200 @@ -277,8 +277,8 @@ "unregistering driver " "`%s', the client at " "address %02x of " - "adapter `%s' could not" - "be detached; driver" + "adapter `%s' could not " + "be detached; driver " "not unloaded!", driver->name, client->addr,
PATCH 1/1 i2c cleanups
In reply to Jean DelvareQuoted 4 lines · Jean Delvare
Quoted 1 line
Forget about -km-2 and -km-6. I will post them in smaller parts.
Never received -km-6, so I can forget about it very easily ;) What about -km-4?
Go ahead with -km-4 if you like.
Quoted 5 lines
As for -km-2, don't forget that there is no real use splitting patches if parts cannot be applied independantly. And I repeat myself, please first fix module reference counting in CVS before posting any patch related to this point. Again, we cannot send anything to Marcelo with regression in it.
Module reference counting patches.
Patch -km-24: Add .owner reference counting. Patch -km-23: Inits with .owner and without .inc/dec_use Patch -km-26: Unused code and whitespace.
Patch -km-13: Unused code and whitespace. (yes, here)
There is one more (yet unwritten) patch for this set coming up. It will replace (deprecated) __MOD_INC_USE_COUNT with try_inc_mod_count.
The broken part in CVS refcounting is i2c_register_entry, and I'll either fix it or take the one from 2.4 tree. The question with i2c_register_entry is whether to pass controlling_mod which is equal to client->driver->owner. Latest sensors don't pass it, any other users for i2c-proc ?
Once I have this all finished I will commit on CVS head.
Signature · 626 lines
Ky?sti M?lkki <[email protected]> -------------- next part -------------- diff -ur lk-i2c-km-23/drivers/i2c/i2c-core.c lk-i2c-km-24/drivers/i2c/i2c-core.c --- lk-i2c-km-23/drivers/i2c/i2c-core.c 2003-12-27 23:05:29.000000000 +0200 +++ lk-i2c-km-24/drivers/i2c/i2c-core.c 2003-12-27 23:13:21.000000000 +0200 @@ -397,21 +397,27 @@ void i2c_inc_use_client(struct i2c_client *client) { - - if (client->driver->inc_use != NULL) + if (client->driver->owner) + __MOD_INC_USE_COUNT(client->driver->owner); + else if (client->driver->inc_use != NULL) client->driver->inc_use(client); - if (client->adapter->inc_use != NULL) + if (client->adapter->owner) + __MOD_INC_USE_COUNT(client->adapter->owner); + else if (client->adapter->inc_use != NULL) client->adapter->inc_use(client->adapter); } void i2c_dec_use_client(struct i2c_client *client) { - - if (client->driver->dec_use != NULL) + if (client->driver->owner) + __MOD_DEC_USE_COUNT(client->driver->owner); + else if (client->driver->dec_use != NULL) client->driver->dec_use(client); - if (client->adapter->dec_use != NULL) + if (client->adapter->owner) + __MOD_DEC_USE_COUNT(client->adapter->owner); + else if (client->adapter->dec_use != NULL) client->adapter->dec_use(client->adapter); } diff -ur lk-i2c-km-23/drivers/i2c/i2c-dev.c lk-i2c-km-24/drivers/i2c/i2c-dev.c --- lk-i2c-km-23/drivers/i2c/i2c-dev.c 2003-12-27 23:14:41.000000000 +0200 +++ lk-i2c-km-24/drivers/i2c/i2c-dev.c 2003-12-27 23:13:20.000000000 +0200 @@ -391,11 +391,11 @@ if(! (client = kmalloc(sizeof(struct i2c_client),GFP_KERNEL))) return -ENOMEM; memcpy(client,&i2cdev_client_template,sizeof(struct i2c_client)); + + /* registered with adapter, passed as client to user */ client->adapter = i2cdev_adaps[minor]; file->private_data = client; - - if (i2cdev_adaps[minor]->inc_use) - i2cdev_adaps[minor]->inc_use(i2cdev_adaps[minor]); + i2c_inc_use_client(client); #ifdef DEBUG printk(KERN_DEBUG "i2c-dev.o: opened i2c-%d\n",minor); @@ -405,16 +405,20 @@ static int i2cdev_release (struct inode *inode, struct file *file) { - unsigned int minor = MINOR(inode->i_rdev); - kfree(file->private_data); - file->private_data=NULL; + struct i2c_client *client; #ifdef DEBUG - printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor); + unsigned int minor = MINOR(inode->i_rdev); #endif + + client = file->private_data; + file->private_data = NULL; lock_kernel(); - if (i2cdev_adaps[minor]->dec_use) - i2cdev_adaps[minor]->dec_use(i2cdev_adaps[minor]); + i2c_dec_use_client(client); unlock_kernel(); + kfree(client); +#ifdef DEBUG + printk(KERN_DEBUG "i2c-dev.o: Closed: i2c-%d\n", minor); +#endif return 0; } Only in lk-i2c-km-23/drivers/i2c: i2c-dev.c.orig Only in lk-i2c-km-23/drivers/i2c: i2c-dev.c~ diff -ur lk-i2c-km-23/include/linux/i2c.h lk-i2c-km-24/include/linux/i2c.h --- lk-i2c-km-23/include/linux/i2c.h 2003-12-27 23:05:29.000000000 +0200 +++ lk-i2c-km-24/include/linux/i2c.h 2003-12-27 23:13:45.000000000 +0200 @@ -128,6 +128,7 @@ */ struct i2c_driver { + struct module *owner; char name[32]; int id; unsigned int flags; /* div., see below */ @@ -195,6 +196,7 @@ * to name two of the most common. */ struct i2c_algorithm { + struct module *owner; /* future use --km */ char name[32]; /* textual description */ unsigned int id; @@ -219,12 +221,12 @@ u32 (*functionality) (struct i2c_adapter *); }; - /* * i2c_adapter is the structure used to identify a physical i2c bus along * with the access algorithms necessary to access it. */ struct i2c_adapter { + struct module *owner; char name[32]; /* some useful name to identify the adapter */ unsigned int id;/* = is algo->id | hwdep.struct->id, */ /* for registered values see below */ -------------- next part -------------- diff -ur lk-i2c-km-22/Documentation/i2c/writing-clients lk-i2c-km-23/Documentation/i2c/writing-clients --- lk-i2c-km-22/Documentation/i2c/writing-clients 2003-12-27 23:05:18.000000000 +0200 +++ lk-i2c-km-23/Documentation/i2c/writing-clients 2003-12-27 23:05:48.000000000 +0200 @@ -24,16 +24,14 @@ routines, a client structure specific information like the actual I2C address. - struct i2c_driver foo_driver - { - /* name */ "Foo version 2.3 and later driver", - /* id */ I2C_DRIVERID_FOO, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &foo_attach_adapter, - /* detach_client */ &foo_detach_client, - /* command */ &foo_command, /* May be NULL */ - /* inc_use */ &foo_inc_use, /* May be NULL */ - /* dec_use */ &foo_dec_use /* May be NULL */ + static struct i2c_driver foo_driver = { + .owner = THIS_MODULE, + .name = "Foo version 2.3 driver", + .id = I2C_DRIVERID_FOO, /* usually from i2c-id.h */ + .flags = I2C_DF_NOTIFY, + .attach_adapter = &foo_attach_adapter, + .detach_client = &foo_detach_client, + .command = &foo_command /* may be NULL */ } The name can be chosen freely, and may be upto 40 characters long. Please diff -ur lk-i2c-km-22/drivers/i2c/i2c-algo-bit.c lk-i2c-km-23/drivers/i2c/i2c-algo-bit.c --- lk-i2c-km-22/drivers/i2c/i2c-algo-bit.c 2003-12-27 23:05:18.000000000 +0200 +++ lk-i2c-km-23/drivers/i2c/i2c-algo-bit.c 2003-12-27 23:05:48.000000000 +0200 @@ -523,14 +523,11 @@ /* -----exported algorithm data: ------------------------------------- */ static struct i2c_algorithm i2c_bit_algo = { - "Bit-shift algorithm", - I2C_ALGO_BIT, - bit_xfer, - NULL, - NULL, /* slave_xmit */ - NULL, /* slave_recv */ - algo_control, /* ioctl */ - bit_func, /* functionality */ + .owner = THIS_MODULE, + .name = "Bit-shift algorithm", + .id = I2C_ALGO_BIT, + .master_xfer = bit_xfer, + .functionality = bit_func, }; /* diff -ur lk-i2c-km-22/drivers/i2c/i2c-algo-pcf.c lk-i2c-km-23/drivers/i2c/i2c-algo-pcf.c --- lk-i2c-km-22/drivers/i2c/i2c-algo-pcf.c 2003-12-27 23:05:18.000000000 +0200 +++ lk-i2c-km-23/drivers/i2c/i2c-algo-pcf.c 2003-12-27 23:05:48.000000000 +0200 @@ -435,14 +435,11 @@ /* -----exported algorithm data: ------------------------------------- */ static struct i2c_algorithm pcf_algo = { - "PCF8584 algorithm", - I2C_ALGO_PCF, - pcf_xfer, - NULL, - NULL, /* slave_xmit */ - NULL, /* slave_recv */ - algo_control, /* ioctl */ - pcf_func, /* functionality */ + .owner = THIS_MODULE, + .name = "PCF8584 algorithm", + .id = I2C_ALGO_PCF, + .master_xfer = pcf_xfer, + .functionality = pcf_func, }; /* diff -ur lk-i2c-km-22/drivers/i2c/i2c-dev.c lk-i2c-km-23/drivers/i2c/i2c-dev.c --- lk-i2c-km-22/drivers/i2c/i2c-dev.c 2003-12-27 23:05:18.000000000 +0200 +++ lk-i2c-km-23/drivers/i2c/i2c-dev.c 2003-12-27 23:09:52.000000000 +0200 @@ -76,13 +76,13 @@ static struct file_operations i2cdev_fops = { - owner: THIS_MODULE, - llseek: no_llseek, - read: i2cdev_read, - write: i2cdev_write, - ioctl: i2cdev_ioctl, - open: i2cdev_open, - release: i2cdev_release, + .owner = THIS_MODULE, + .llseek = no_llseek, + .read = i2cdev_read, + .write = i2cdev_write, + .ioctl = i2cdev_ioctl, + .open = i2cdev_open, + .release = i2cdev_release, }; #define I2CDEV_ADAPS_MAX I2C_ADAP_MAX @@ -93,24 +93,20 @@ #endif 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, */ + .owner = THIS_MODULE, /* not really used */ + .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, }; 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, + .addr = -1, + .driver = &i2cdev_driver, }; static ssize_t i2cdev_read (struct file *file, char *buf, size_t count, Only in lk-i2c-km-23/drivers/i2c: i2c-dev.c~ diff -ur lk-i2c-km-22/drivers/i2c/i2c-elektor.c lk-i2c-km-23/drivers/i2c/i2c-elektor.c --- lk-i2c-km-22/drivers/i2c/i2c-elektor.c 2003-12-27 23:05:18.000000000 +0200 +++ lk-i2c-km-23/drivers/i2c/i2c-elektor.c 2003-12-27 23:05:48.000000000 +0200 @@ -200,24 +200,21 @@ * This is only done when more than one hardware adapter is supported. */ static struct i2c_algo_pcf_data pcf_isa_data = { - NULL, - pcf_isa_setbyte, - pcf_isa_getbyte, - pcf_isa_getown, - pcf_isa_getclock, - pcf_isa_waitforpin, - 10, 10, 100, /* waits, timeout */ + .setpcf = pcf_isa_setbyte, + .getpcf = pcf_isa_getbyte, + .getown = pcf_isa_getown, + .getclock = pcf_isa_getclock, + .waitforpin = pcf_isa_waitforpin, + .udelay = 10, + .mdelay = 10, + .timeout = HZ, }; static struct i2c_adapter pcf_isa_ops = { - "PCF8584 ISA adapter", - I2C_HW_P_ELEK, - NULL, - &pcf_isa_data, - pcf_isa_inc_use, - pcf_isa_dec_use, - pcf_isa_reg, - pcf_isa_unreg, + .owner = THIS_MODULE, + .name = "PCF8584 ISA adapter", + .id = I2C_HW_P_ELEK, + .algo_data = &pcf_isa_data, }; int __init i2c_pcfisa_init(void) diff -ur lk-i2c-km-22/drivers/i2c/i2c-elv.c lk-i2c-km-23/drivers/i2c/i2c-elv.c --- lk-i2c-km-22/drivers/i2c/i2c-elv.c 2003-12-27 23:05:18.000000000 +0200 +++ lk-i2c-km-23/drivers/i2c/i2c-elv.c 2003-12-27 23:05:48.000000000 +0200 @@ -151,23 +151,20 @@ * This is only done when more than one hardware adapter is supported. */ static struct i2c_algo_bit_data bit_elv_data = { - NULL, - bit_elv_setsda, - bit_elv_setscl, - bit_elv_getsda, - bit_elv_getscl, - 80, 80, 100, /* waits, timeout */ + .setsda = bit_elv_setsda, + .setscl = bit_elv_setscl, + .getsda = bit_elv_getsda, + .getscl = bit_elv_getscl, + .udelay = 80, + .mdelay = 80, + .timeout = HZ }; static struct i2c_adapter bit_elv_ops = { - "ELV Parallel port adaptor", - I2C_HW_B_ELV, - NULL, - &bit_elv_data, - bit_elv_inc_use, - bit_elv_dec_use, - bit_elv_reg, - bit_elv_unreg, + .owner = THIS_MODULE, + .name = "ELV Parallel port adaptor", + .id = I2C_HW_B_ELV, + .algo_data = &bit_elv_data, }; int __init i2c_bitelv_init(void) diff -ur lk-i2c-km-22/drivers/i2c/i2c-philips-par.c lk-i2c-km-23/drivers/i2c/i2c-philips-par.c --- lk-i2c-km-22/drivers/i2c/i2c-philips-par.c 2003-12-27 23:05:18.000000000 +0200 +++ lk-i2c-km-23/drivers/i2c/i2c-philips-par.c 2003-12-27 23:05:48.000000000 +0200 @@ -156,33 +156,28 @@ */ static struct i2c_algo_bit_data bit_lp_data = { - NULL, - bit_lp_setsda, - bit_lp_setscl, - bit_lp_getsda, - bit_lp_getscl, - 80, 80, 100, /* waits, timeout */ + .setsda = bit_lp_setsda, + .setscl = bit_lp_setscl, + .getsda = bit_lp_getsda, + .getscl = bit_lp_getscl, + .udelay = 80, + .mdelay = 80, + .timeout = HZ }; static struct i2c_algo_bit_data bit_lp_data2 = { - NULL, - bit_lp_setsda2, - bit_lp_setscl2, - bit_lp_getsda2, - NULL, - 80, 80, 100, /* waits, timeout */ + .setsda = bit_lp_setsda2, + .setscl = bit_lp_setscl2, + .getsda = bit_lp_getsda2, + .udelay = 80, + .mdelay = 80, + .timeout = HZ }; static struct i2c_adapter bit_lp_ops = { - "Philips Parallel port adapter", - I2C_HW_B_LP, - NULL, - NULL, - bit_lp_inc_use, - bit_lp_dec_use, - bit_lp_reg, - - bit_lp_unreg, + .owner = THIS_MODULE, + .name = "Philips Parallel port adapter", + .id = I2C_HW_B_LP, }; static void i2c_parport_attach (struct parport *port) diff -ur lk-i2c-km-22/drivers/i2c/i2c-velleman.c lk-i2c-km-23/drivers/i2c/i2c-velleman.c --- lk-i2c-km-22/drivers/i2c/i2c-velleman.c 2003-12-27 23:05:18.000000000 +0200 +++ lk-i2c-km-23/drivers/i2c/i2c-velleman.c 2003-12-27 23:05:48.000000000 +0200 @@ -139,23 +139,20 @@ */ static struct i2c_algo_bit_data bit_velle_data = { - NULL, - bit_velle_setsda, - bit_velle_setscl, - bit_velle_getsda, - bit_velle_getscl, - 10, 10, 100, /* waits, timeout */ + .setsda = bit_velle_setsda, + .setscl = bit_velle_setscl, + .getsda = bit_velle_getsda, + .getscl = bit_velle_getscl, + .udelay = 10, + .mdelay = 10, + .timeout = HZ }; static struct i2c_adapter bit_velle_ops = { - "Velleman K8000", - I2C_HW_B_VELLE, - NULL, - &bit_velle_data, - bit_velle_inc_use, - bit_velle_dec_use, - bit_velle_reg, - bit_velle_unreg, + .owner = THIS_MODULE, + .name = "Velleman K8000", + .id = I2C_HW_B_VELLE, + .algo_data = &bit_velle_data, }; int __init i2c_bitvelle_init(void) -------------- next part -------------- diff -ur lk-i2c-km-25/drivers/i2c/i2c-algo-bit.c lk-i2c-km-26/drivers/i2c/i2c-algo-bit.c --- lk-i2c-km-25/drivers/i2c/i2c-algo-bit.c 2003-12-27 23:05:48.000000000 +0200 +++ lk-i2c-km-26/drivers/i2c/i2c-algo-bit.c 2003-12-27 23:30:33.000000000 +0200 @@ -554,9 +554,6 @@ adap->timeout = 100; /* default values, should */ adap->retries = 3; /* be replaced by defines */ -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif i2c_add_adapter(adap); return 0; @@ -572,9 +569,6 @@ DEB2(printk("i2c-algo-bit.o: adapter unregistered: %s\n",adap->name)); -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif return 0; } Only in lk-i2c-km-26/drivers/i2c: i2c-algo-bit.c~ diff -ur lk-i2c-km-25/drivers/i2c/i2c-algo-pcf.c lk-i2c-km-26/drivers/i2c/i2c-algo-pcf.c --- lk-i2c-km-25/drivers/i2c/i2c-algo-pcf.c 2003-12-27 23:05:48.000000000 +0200 +++ lk-i2c-km-26/drivers/i2c/i2c-algo-pcf.c 2003-12-27 23:33:48.000000000 +0200 @@ -465,10 +465,6 @@ return i; } -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif - i2c_add_adapter(adap); return 0; } @@ -481,9 +477,6 @@ return res; DEB2(printk("i2c-algo-pcf.o: adapter unregistered: %s\n",adap->name)); -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif return 0; } Only in lk-i2c-km-26/drivers/i2c: i2c-algo-pcf.c~ diff -ur lk-i2c-km-25/drivers/i2c/i2c-elektor.c lk-i2c-km-26/drivers/i2c/i2c-elektor.c --- lk-i2c-km-25/drivers/i2c/i2c-elektor.c 2003-12-27 23:05:48.000000000 +0200 +++ lk-i2c-km-26/drivers/i2c/i2c-elektor.c 2003-12-27 23:31:21.000000000 +0200 @@ -156,45 +156,6 @@ return 0; } - -static void __exit pcf_isa_exit(void) -{ - if (irq > 0) { - disable_irq(irq); - free_irq(irq, 0); - } - if (!mmapped) { - release_region(base , 2); - } -} - - -static int pcf_isa_reg(struct i2c_client *client) -{ - return 0; -} - - -static int pcf_isa_unreg(struct i2c_client *client) -{ - return 0; -} - -static void pcf_isa_inc_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif -} - -static void pcf_isa_dec_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif -} - - /* ------------------------------------------------------------------------ * Encapsulate the above functions in the correct operations structure. * This is only done when more than one hardware adapter is supported. Only in lk-i2c-km-26/drivers/i2c: i2c-elektor.c~ diff -ur lk-i2c-km-25/drivers/i2c/i2c-elv.c lk-i2c-km-26/drivers/i2c/i2c-elv.c --- lk-i2c-km-25/drivers/i2c/i2c-elv.c 2003-12-27 23:05:48.000000000 +0200 +++ lk-i2c-km-26/drivers/i2c/i2c-elv.c 2003-12-27 23:30:04.000000000 +0200 @@ -122,30 +122,6 @@ release_region( base , (base = 0x3bc)? 3 : 8 ); } -static int bit_elv_reg(struct i2c_client *client) -{ - return 0; -} - -static int bit_elv_unreg(struct i2c_client *client) -{ - return 0; -} - -static void bit_elv_inc_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif -} - -static void bit_elv_dec_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif -} - /* ------------------------------------------------------------------------ * Encapsulate the above functions in the correct operations structure. * This is only done when more than one hardware adapter is supported. Only in lk-i2c-km-26/drivers/i2c: i2c-elv.c~ diff -ur lk-i2c-km-25/drivers/i2c/i2c-philips-par.c lk-i2c-km-26/drivers/i2c/i2c-philips-par.c --- lk-i2c-km-25/drivers/i2c/i2c-philips-par.c 2003-12-27 23:05:48.000000000 +0200 +++ lk-i2c-km-26/drivers/i2c/i2c-philips-par.c 2003-12-27 23:32:01.000000000 +0200 @@ -130,26 +130,6 @@ PARPORT_STATUS_BUSY) ? 0 : 1; } -static int bit_lp_reg(struct i2c_client *client) -{ - return 0; -} - -static int bit_lp_unreg(struct i2c_client *client) -{ - return 0; -} - -static void bit_lp_inc_use(struct i2c_adapter *adap) -{ - MOD_INC_USE_COUNT; -} - -static void bit_lp_dec_use(struct i2c_adapter *adap) -{ - MOD_DEC_USE_COUNT; -} - /* ------------------------------------------------------------------------ * Encapsulate the above functions in the correct operations structure. * This is only done when more than one hardware adapter is supported. Only in lk-i2c-km-26/drivers/i2c: i2c-philips-par.c~ diff -ur lk-i2c-km-25/drivers/i2c/i2c-velleman.c lk-i2c-km-26/drivers/i2c/i2c-velleman.c --- lk-i2c-km-25/drivers/i2c/i2c-velleman.c 2003-12-27 23:05:48.000000000 +0200 +++ lk-i2c-km-26/drivers/i2c/i2c-velleman.c 2003-12-27 23:32:47.000000000 +0200 @@ -108,31 +108,6 @@ release_region( base , (base = 0x3bc)? 3 : 8 ); } - -static int bit_velle_reg(struct i2c_client *client) -{ - return 0; -} - -static int bit_velle_unreg(struct i2c_client *client) -{ - return 0; -} - -static void bit_velle_inc_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_INC_USE_COUNT; -#endif -} - -static void bit_velle_dec_use(struct i2c_adapter *adap) -{ -#ifdef MODULE - MOD_DEC_USE_COUNT; -#endif -} - /* ------------------------------------------------------------------------ * Encapsulate the above functions in the correct operations structure. * This is only done when more than one hardware adapter is supported. Only in lk-i2c-km-26/drivers/i2c: i2c-velleman.c~