Show
Ignore:
Timestamp:
01/17/03 02:19:52 (10 years ago)
Author:
kmalkki
Message:

(Kyösti) some cleanups for 2.4+

Module refcounting using .owner, removing of inc/dec_use.
These require (yet unreleased) i2c 2.8.0+.

Named initializers everywhere. Unified namespace.

Cleanup for 2.5, remove EXPORT_NO_SYMBOLS, declare everything
static. Apply initcalls.

PCI device registration changes for busses started, replicating
from i2c-amd*. While everything does compile, nothing really
works. Well, maybe i2c-amd* ported back from 2.5 tree.

After updating your work directory, run

> cvs diff -u -r LAST-PRE-2-8-I2C > lm-2.8-patches-1

BEWARE: I have not even insmoded any of these yet.

To compile, you need i2c from cvs too.
For 2.4 kernel :

> cvs co -r lk2-4 i2c

For 2.5 kernel :

> cvs co i2c

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/kernel/busses/i2c-i801.c

    r1490 r1698  
    5252#include "version.h" 
    5353 
    54 #ifdef MODULE_LICENSE 
    5554MODULE_LICENSE("GPL"); 
    56 #endif 
    5755 
    5856#ifdef I2C_FUNC_SMBUS_BLOCK_DATA_PEC 
     
    128126                 "EXTREMELY DANGEROUS!"); 
    129127 
    130 #ifdef MODULE 
    131 static 
    132 #else 
    133 extern 
    134 #endif 
    135 int __init i2c_i801_init(void); 
    136 static int __init i801_cleanup(void); 
    137 static int i801_setup(void); 
    138 static s32 i801_access(struct i2c_adapter *adap, u16 addr, 
    139                        unsigned short flags, char read_write, 
    140                        u8 command, int size, union i2c_smbus_data *data); 
     128 
     129 
     130 
     131 
    141132static void i801_do_pause(unsigned int amount); 
    142133static int i801_transaction(void); 
    143134static int i801_block_transaction(union i2c_smbus_data *data, 
    144135                                  char read_write, int command); 
    145 static void i801_inc(struct i2c_adapter *adapter); 
    146 static void i801_dec(struct i2c_adapter *adapter); 
    147 static u32 i801_func(struct i2c_adapter *adapter); 
    148  
    149 #ifdef MODULE 
    150 extern int init_module(void); 
    151 extern int cleanup_module(void); 
    152 #endif                          /* MODULE */ 
    153  
    154 static struct i2c_algorithm smbus_algorithm = { 
    155         /* name */ "Non-I2C SMBus adapter", 
    156         /* id */ I2C_ALGO_SMBUS, 
    157         /* master_xfer */ NULL, 
    158         /* smbus_xfer */ i801_access, 
    159         /* slave_send */ NULL, 
    160         /* slave_rcv */ NULL, 
    161         /* algo_control */ NULL, 
    162         /* functionality */ i801_func, 
    163 }; 
    164  
    165 static struct i2c_adapter i801_adapter = { 
    166         "unset", 
    167         I2C_ALGO_SMBUS | I2C_HW_SMBUS_I801, 
    168         &smbus_algorithm, 
    169         NULL, 
    170         i801_inc, 
    171         i801_dec, 
    172         NULL, 
    173         NULL, 
    174 }; 
    175  
    176 static int __initdata i801_initialized; 
     136 
     137 
     138 
     139 
    177140static unsigned short i801_smba = 0; 
    178141static struct pci_dev *I801_dev = NULL; 
     
    671634} 
    672635 
    673 void i801_inc(struct i2c_adapter *adapter) 
    674 { 
    675         MOD_INC_USE_COUNT; 
    676 } 
    677  
    678 void i801_dec(struct i2c_adapter *adapter) 
    679 { 
    680         MOD_DEC_USE_COUNT; 
    681 } 
    682636 
    683637u32 i801_func(struct i2c_adapter *adapter) 
     
    694648} 
    695649 
    696 int __init i2c_i801_init(void) 
    697 { 
    698         int res; 
    699         printk(KERN_INFO "i2c-i801.o version %s (%s)\n", LM_VERSION, LM_DATE); 
    700 #ifdef DEBUG 
    701 /* PE- It might be good to make this a permanent part of the code! */ 
    702         if (i801_initialized) { 
    703                 printk 
    704                     (KERN_DEBUG "i2c-i801.o: Oops, i801_init called a second time!\n"); 
    705                 return -EBUSY; 
    706         } 
    707 #endif 
    708         i801_initialized = 0; 
    709         if ((res = i801_setup())) { 
     650static struct i2c_algorithm smbus_algorithm = { 
     651        .name           = "Non-I2C SMBus adapter", 
     652        .id             = I2C_ALGO_SMBUS, 
     653        .smbus_xfer     = i801_access, 
     654        .functionality  = i801_func, 
     655}; 
     656 
     657static struct i2c_adapter i801_adapter = { 
     658        .owner          = THIS_MODULE, 
     659        .name           = "unset", 
     660        .id             = I2C_ALGO_SMBUS | I2C_HW_SMBUS_I801, 
     661        .algo           = &smbus_algorithm, 
     662}; 
     663 
     664 
     665 
     666static struct pci_device_id i801_ids[] __devinitdata = { 
     667        { 0, } 
     668}; 
     669 
     670static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id *id) 
     671{ 
     672 
     673        if (i801_setup()) { 
    710674                printk 
    711675                    (KERN_WARNING "i2c-i801.o: I801 not detected, module not inserted.\n"); 
    712                 i801_cleanup(); 
    713                 return res; 
    714         } 
    715         i801_initialized++; 
     676                return -ENODEV; 
     677        } 
     678 
    716679        sprintf(i801_adapter.name, "SMBus I801 adapter at %04x", 
    717680                i801_smba); 
    718         if ((res = i2c_add_adapter(&i801_adapter))) { 
    719                 printk 
    720                     (KERN_ERR "i2c-i801.o: Adapter registration failed, module not inserted.\n"); 
    721                 i801_cleanup(); 
    722                 return res; 
    723         } 
    724         i801_initialized++; 
    725         printk(KERN_INFO "i2c-i801.o: I801 bus detected and initialized\n"); 
    726         return 0; 
    727 } 
    728  
    729 int __init i801_cleanup(void) 
    730 { 
    731         int res; 
    732         if (i801_initialized >= 2) { 
    733                 if ((res = i2c_del_adapter(&i801_adapter))) { 
    734                         printk 
    735                             (KERN_ERR "i2c-i801.o: i2c_del_adapter failed, module not removed\n"); 
    736                         return res; 
    737                 } else 
    738                         i801_initialized--; 
    739         } 
    740         if (i801_initialized >= 1) { 
    741                 release_region(i801_smba, (isich4 ? 16 : 8)); 
    742                 i801_initialized--; 
    743         } 
    744         return 0; 
    745 } 
    746  
    747 EXPORT_NO_SYMBOLS; 
    748  
    749 #ifdef MODULE 
     681        i2c_add_adapter(&i801_adapter); 
     682} 
     683 
     684static void __devexit i801_remove(struct pci_dev *dev) 
     685{ 
     686        i2c_del_adapter(&i801_adapter); 
     687} 
     688 
     689static struct pci_driver i801_driver = { 
     690        .name           = "i801 smbus", 
     691        .id_table       = i801_ids, 
     692        .probe          = i801_probe, 
     693        .remove         = __devexit_p(i801_remove), 
     694}; 
     695 
     696static int __init i2c_i801_init(void) 
     697{ 
     698        printk(KERN_INFO "i2c-i801.o version %s (%s)\n", LM_VERSION, LM_DATE); 
     699        return pci_module_init(&i801_driver); 
     700} 
     701 
     702 
     703static void __exit i2c_i801_exit(void) 
     704{ 
     705        pci_unregister_driver(&i801_driver); 
     706        release_region(i801_smba, (isich4 ? 16 : 8)); 
     707} 
     708 
     709 
    750710 
    751711MODULE_AUTHOR 
     
    753713MODULE_DESCRIPTION("I801 SMBus driver"); 
    754714 
    755 int init_module(void) 
    756 { 
    757         return i2c_i801_init(); 
    758 } 
    759  
    760 int cleanup_module(void) 
    761 { 
    762         return i801_cleanup(); 
    763 } 
    764  
    765 #endif                          /* MODULE */ 
     715module_init(i2c_i801_init); 
     716module_exit(i2c_i801_exit);