Changeset 1698

Show
Ignore:
Timestamp:
01/17/03 02:19:52 (6 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:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/trunk/kernel/busses/dmi_scan.c

    r1661 r1698  
    230230} 
    231231 
    232 #ifdef MODULE 
    233232MODULE_DESCRIPTION("SM BIOS DMI Scanner"); 
    234 #ifdef MODULE_LICENSE 
    235233MODULE_LICENSE("GPL"); 
    236 #endif 
    237234EXPORT_SYMBOL(dmi_ident); 
    238235EXPORT_SYMBOL(dmi_scan_mach); 
    239 int init_module(void) 
    240 { 
    241         return 0; 
    242 } 
    243  
    244 int cleanup_module(void) 
    245 { 
    246         return 0; 
    247 } 
    248  
    249 #endif 
  • lm-sensors/trunk/kernel/busses/i2c-ali1535.c

    r1572 r1698  
    6767#include <linux/init.h> 
    6868 
    69 #ifdef MODULE_LICENSE 
    7069MODULE_LICENSE("GPL"); 
    71 #endif 
    7270 
    7371#ifndef DECLARE_MUTEX 
     
    145143#define ALI1535_SMBIO_EN        0x04    /* SMB I/O Space enable        */ 
    146144 
    147 #ifdef MODULE 
    148 static 
    149 #else 
    150 extern 
    151 #endif 
    152 int __init i2c_ali1535_init(void); 
    153 static int __init ali1535_cleanup(void); 
    154 static int ali1535_setup(void); 
    155 static s32 ali1535_access(struct i2c_adapter *adap, u16 addr, 
    156                           unsigned short flags, char read_write, 
    157                           u8 command, int size, 
    158                           union i2c_smbus_data *data); 
    159145static void ali1535_do_pause(unsigned int amount); 
    160146static int ali1535_transaction(void); 
    161 static void ali1535_inc(struct i2c_adapter *adapter); 
    162 static void ali1535_dec(struct i2c_adapter *adapter); 
    163 static u32 ali1535_func(struct i2c_adapter *adapter); 
    164  
    165 #ifdef MODULE 
    166 extern int init_module(void); 
    167 extern int cleanup_module(void); 
    168 #endif                          /* MODULE */ 
    169  
    170 static struct i2c_algorithm smbus_algorithm = { 
    171         /* name */ "Non-i2c SMBus adapter", 
    172         /* id */ I2C_ALGO_SMBUS, 
    173         /* master_xfer */ NULL,  
    174         /* smbus_access */ ali1535_access, 
    175         /* slave_send */ NULL, 
    176         /* slave_rcv */ NULL, 
    177         /* algo_control */ NULL, 
    178         /* functionality */ ali1535_func, 
    179 }; 
    180  
    181 static struct i2c_adapter ali1535_adapter = { 
    182         "unset", 
    183         I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI1535, 
    184         &smbus_algorithm, 
    185         NULL, 
    186         ali1535_inc, 
    187         ali1535_dec, 
    188         NULL, 
    189         NULL, 
    190 }; 
    191  
    192 static int __initdata ali1535_initialized; 
     147 
    193148static unsigned short ali1535_smba = 0; 
    194149DECLARE_MUTEX(i2c_ali1535_sem); 
     
    592547} 
    593548 
    594 void ali1535_inc(struct i2c_adapter *adapter) 
    595 { 
    596         MOD_INC_USE_COUNT; 
    597 } 
    598  
    599 void ali1535_dec(struct i2c_adapter *adapter) 
    600 { 
    601  
    602         MOD_DEC_USE_COUNT; 
    603 } 
    604549 
    605550u32 ali1535_func(struct i2c_adapter *adapter) 
     
    610555} 
    611556 
    612 int __init i2c_ali1535_init(void) 
    613 
    614         int res; 
    615         printk("i2c-ali1535.o version %s (%s)\n", LM_VERSION, LM_DATE); 
    616 #ifdef DEBUG 
    617 /* PE- It might be good to make this a permanent part of the code! */ 
    618         if (ali1535_initialized) { 
    619                 printk 
    620                     ("i2c-ali1535.o: Oops, ali1535_init called a second time!\n"); 
    621                 return -EBUSY; 
    622         } 
    623 #endif 
    624         ali1535_initialized = 0; 
    625         if ((res = ali1535_setup())) { 
     557static struct i2c_algorithm smbus_algorithm = { 
     558        .name           = "Non-i2c SMBus adapter", 
     559        .id             = I2C_ALGO_SMBUS, 
     560        .smbus_xfer     = ali1535_access, 
     561        .functionality  = ali1535_func, 
     562}; 
     563 
     564static struct i2c_adapter ali1535_adapter = { 
     565        .owner          = THIS_MODULE, 
     566        .name           = "unset", 
     567        .id             = I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI1535, 
     568        .algo           = &smbus_algorithm, 
     569}; 
     570 
     571 
     572static struct pci_device_id ali1535_ids[] __devinitdata = { 
     573        { 0, } 
     574}; 
     575 
     576static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_id *id) 
     577
     578        if (ali1535_setup()) { 
    626579                printk 
    627580                    ("i2c-ali1535.o: ALI1535 not detected, module not inserted.\n"); 
    628                 ali1535_cleanup(); 
    629                 return res; 
    630         } 
    631         ali1535_initialized++; 
     581                return -ENODEV; 
     582        } 
     583 
    632584        sprintf(ali1535_adapter.name, "SMBus ALI1535 adapter at %04x", 
    633585                ali1535_smba); 
    634         if ((res = i2c_add_adapter(&ali1535_adapter))) { 
    635                 printk 
    636                     ("i2c-ali1535.o: Adapter registration failed, module not inserted.\n"); 
    637                 ali1535_cleanup(); 
    638                 return res; 
    639         } 
    640         ali1535_initialized++; 
    641         printk 
    642             ("i2c-ali1535.o: ALI1535 SMBus Controller detected and initialized\n"); 
    643         return 0; 
    644 
    645  
    646 int __init ali1535_cleanup(void) 
    647 
    648         int res; 
    649         if (ali1535_initialized >= 2) { 
    650                 if ((res = i2c_del_adapter(&ali1535_adapter))) { 
    651                         printk 
    652                             ("i2c-ali1535.o: i2c_del_adapter failed, module not removed\n"); 
    653                         return res; 
    654                 } else 
    655                         ali1535_initialized--; 
    656         } 
    657         if (ali1535_initialized >= 1) { 
    658                 release_region(ali1535_smba, ALI1535_SMB_IOSIZE); 
    659                 ali1535_initialized--; 
    660         } 
    661         return 0; 
     586        i2c_add_adapter(&ali1535_adapter); 
     587
     588 
     589static void __devexit ali1535_remove(struct pci_dev *dev) 
     590
     591        i2c_del_adapter(&ali1535_adapter); 
     592
     593 
     594 
     595static struct pci_driver ali1535_driver = { 
     596        .name           = "ali1535 smbus", 
     597        .id_table       = ali1535_ids, 
     598        .probe          = ali1535_probe, 
     599        .remove         = __devexit_p(ali1535_remove), 
     600}; 
     601 
     602static int __init i2c_ali1535_init(void) 
     603
     604        printk("i2c-ali1535.o version %s (%s)\n", LM_VERSION, LM_DATE); 
     605        return pci_module_init(&ali1535_driver); 
     606
     607 
     608 
     609static void __exit i2c_ali1535_exit(void) 
     610
     611        pci_unregister_driver(&ali1535_driver); 
     612        release_region(ali1535_smba, ALI1535_SMB_IOSIZE); 
    662613} 
    663614 
     
    666617EXPORT_SYMBOL(ali1535_access); 
    667618EXPORT_SYMBOL(i2c_ali1535_sem); 
    668 #else 
    669 EXPORT_NO_SYMBOLS; 
    670619#endif 
    671  
    672 #ifdef MODULE 
    673620 
    674621MODULE_AUTHOR 
     
    677624MODULE_DESCRIPTION("ALI1535 SMBus driver"); 
    678625 
    679 int init_module(void) 
    680 
    681         return i2c_ali1535_init(); 
    682 
    683  
    684 int cleanup_module(void) 
    685 
    686         return ali1535_cleanup(); 
    687 
    688  
    689 #endif                          /* MODULE */ 
    690  
     626module_init(i2c_ali1535_init); 
     627module_exit(i2c_ali1535_exit); 
     628 
  • lm-sensors/trunk/kernel/busses/i2c-ali15x3.c

    r1388 r1698  
    7373#include <linux/init.h> 
    7474 
    75 #ifdef MODULE_LICENSE 
    7675MODULE_LICENSE("GPL"); 
    77 #endif 
    7876 
    7977/* ALI15X3 SMBus address offsets */ 
     
    136134                 "Initialize the base address of the i2c controller"); 
    137135 
    138 #ifdef MODULE 
    139 static 
    140 #else 
    141 extern 
    142 #endif 
    143 int __init i2c_ali15x3_init(void); 
    144 static int __init ali15x3_cleanup(void); 
    145 static int ali15x3_setup(void); 
    146 static s32 ali15x3_access(struct i2c_adapter *adap, u16 addr, 
    147                           unsigned short flags, char read_write, 
    148                           u8 command, int size, 
    149                           union i2c_smbus_data *data); 
     136 
    150137static void ali15x3_do_pause(unsigned int amount); 
    151138static int ali15x3_transaction(void); 
    152 static void ali15x3_inc(struct i2c_adapter *adapter); 
    153 static void ali15x3_dec(struct i2c_adapter *adapter); 
    154 static u32 ali15x3_func(struct i2c_adapter *adapter); 
    155  
    156 #ifdef MODULE 
    157 extern int init_module(void); 
    158 extern int cleanup_module(void); 
    159 #endif                          /* MODULE */ 
    160  
    161 static struct i2c_algorithm smbus_algorithm = { 
    162         /* name */ "Non-I2C SMBus adapter", 
    163         /* id */ I2C_ALGO_SMBUS, 
    164         /* master_xfer */ NULL, 
    165         /* smbus_access */ ali15x3_access, 
    166         /* slave_send */ NULL, 
    167         /* slave_rcv */ NULL, 
    168         /* algo_control */ NULL, 
    169         /* functionality */ ali15x3_func, 
    170 }; 
    171  
    172 static struct i2c_adapter ali15x3_adapter = { 
    173         "unset", 
    174         I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3, 
    175         &smbus_algorithm, 
    176         NULL, 
    177         ali15x3_inc, 
    178         ali15x3_dec, 
    179         NULL, 
    180         NULL, 
    181 }; 
    182  
    183 static int __initdata ali15x3_initialized; 
     139 
    184140static unsigned short ali15x3_smba = 0; 
    185141static int locked=0; 
     
    559515} 
    560516 
    561 void ali15x3_inc(struct i2c_adapter *adapter) 
    562 { 
    563         MOD_INC_USE_COUNT; 
    564 } 
    565  
    566 void ali15x3_dec(struct i2c_adapter *adapter) 
    567 { 
    568  
    569         MOD_DEC_USE_COUNT; 
    570 } 
    571517 
    572518u32 ali15x3_func(struct i2c_adapter *adapter) 
     
    577523} 
    578524 
    579 int __init i2c_ali15x3_init(void) 
    580 
    581         int res; 
    582         printk("i2c-ali15x3.o version %s (%s)\n", LM_VERSION, LM_DATE); 
    583 #ifdef DEBUG 
    584 /* PE- It might be good to make this a permanent part of the code! */ 
    585         if (ali15x3_initialized) { 
    586                 printk 
    587                     ("i2c-ali15x3.o: Oops, ali15x3_init called a second time!\n"); 
    588                 return -EBUSY; 
    589         } 
    590 #endif 
    591         ali15x3_initialized = 0; 
    592         if ((res = ali15x3_setup())) { 
     525static struct i2c_algorithm smbus_algorithm = { 
     526        .name           = "Non-I2C SMBus adapter", 
     527        .id             = I2C_ALGO_SMBUS, 
     528        .smbus_xfer     = ali15x3_access, 
     529        .functionality  = ali15x3_func, 
     530}; 
     531 
     532static struct i2c_adapter ali15x3_adapter = { 
     533        .owner          = THIS_MODULE, 
     534        .name           = "unset", 
     535        .id             = I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3, 
     536        .algo           = &smbus_algorithm, 
     537}; 
     538 
     539 
     540 
     541static struct pci_device_id ali15x3_ids[] __devinitdata = { 
     542        { 0, } 
     543}; 
     544 
     545static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_id *id) 
     546
     547        if (ali15x3_setup()) { 
    593548                printk 
    594549                    ("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n"); 
    595                 ali15x3_cleanup(); 
    596                 return res
    597         } 
    598         ali15x3_initialized++; 
     550 
     551                return -ENODEV
     552        } 
     553 
    599554        sprintf(ali15x3_adapter.name, "SMBus ALI15X3 adapter at %04x", 
    600555                ali15x3_smba); 
    601         if ((res = i2c_add_adapter(&ali15x3_adapter))) { 
    602                 printk 
    603                     ("i2c-ali15x3.o: Adapter registration failed, module not inserted.\n"); 
    604                 ali15x3_cleanup(); 
    605                 return res; 
    606         } 
    607         ali15x3_initialized++; 
    608         printk 
    609             ("i2c-ali15x3.o: ALI15X3 SMBus Controller detected and initialized\n"); 
    610         return 0; 
    611 
    612  
    613 int __init ali15x3_cleanup(void) 
    614 
    615         int res; 
    616         if (ali15x3_initialized >= 2) { 
    617                 if ((res = i2c_del_adapter(&ali15x3_adapter))) { 
    618                         printk 
    619                             ("i2c-ali15x3.o: i2c_del_adapter failed, module not removed\n"); 
    620                         return res; 
    621                 } else 
    622                         ali15x3_initialized--; 
    623         } 
    624         if (ali15x3_initialized >= 1) { 
    625                 release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE); 
    626                 ali15x3_initialized--; 
    627         } 
    628         return 0; 
    629 
    630  
    631 EXPORT_NO_SYMBOLS; 
    632  
    633 #ifdef MODULE 
     556        i2c_add_adapter(&ali15x3_adapter); 
     557
     558 
     559static void __devexit ali15x3_remove(struct pci_dev *dev) 
     560
     561        i2c_del_adapter(&ali15x3_adapter); 
     562
     563 
     564static struct pci_driver ali15x3_driver = { 
     565        .name           = "ali15x3 smbus", 
     566        .id_table       = ali15x3_ids, 
     567        .probe          = ali15x3_probe, 
     568        .remove         = __devexit_p(ali15x3_remove), 
     569}; 
     570 
     571static int __init i2c_ali15x3_init(void) 
     572
     573        printk("i2c-ali15x3.o version %s (%s)\n", LM_VERSION, LM_DATE); 
     574        return pci_module_init(&ali15x3_driver); 
     575
     576 
     577 
     578static void __exit i2c_ali15x3_exit(void) 
     579
     580        pci_unregister_driver(&ali15x3_driver); 
     581        release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE); 
     582
     583 
     584 
    634585 
    635586MODULE_AUTHOR 
     
    637588MODULE_DESCRIPTION("ALI15X3 SMBus driver"); 
    638589 
    639 int init_module(void) 
    640 
    641         return i2c_ali15x3_init(); 
    642 
    643  
    644 int cleanup_module(void) 
    645 
    646         return ali15x3_cleanup(); 
    647 
    648  
    649 #endif                          /* MODULE */ 
     590module_init(i2c_ali15x3_init); 
     591module_exit(i2c_ali15x3_exit); 
  • lm-sensors/trunk/kernel/busses/i2c-amd756.c

    r1694 r1698  
    204204 
    205205/* Return -1 on error. */ 
     206 
    206207static s32 amd756_access(struct i2c_adapter * adap, u16 addr, 
    207208                  unsigned short flags, char read_write, 
     
    298299} 
    299300 
    300 void amd756_inc(struct i2c_adapter *adapter) 
    301 { 
    302         MOD_INC_USE_COUNT; 
    303 } 
    304  
    305 void amd756_dec(struct i2c_adapter *adapter) 
    306 { 
    307  
    308         MOD_DEC_USE_COUNT; 
    309 } 
    310  
    311301static u32 amd756_func(struct i2c_adapter *adapter) 
    312302{ 
     
    324314 
    325315static struct i2c_adapter amd756_adapter = { 
     316        .owner          = THIS_MODULE, 
    326317        .name           = "unset", 
    327318        .id             = I2C_ALGO_SMBUS | I2C_HW_SMBUS_AMD756, 
    328319        .algo           = &smbus_algorithm, 
    329         .inc_use        = amd756_inc, 
    330         .dec_use        = amd756_dec, 
    331320}; 
    332321 
     
    406395} 
    407396 
     397 
    408398static void __devexit amd756_remove(struct pci_dev *dev) 
    409399{ 
    410400        i2c_del_adapter(&amd756_adapter); 
    411         release_region(amd756_ioport, SMB_IOSIZE); 
    412401} 
    413402 
     
    419408}; 
    420409 
    421 static int __init amd756_init(void) 
     410static int __init i2c_amd756_init(void) 
    422411{ 
    423412        printk(KERN_INFO "i2c-amd756.o version %s (%s)\n", LM_VERSION, LM_DATE); 
     
    425414} 
    426415 
    427 static void __exit amd756_exit(void) 
     416 
     417static void __exit i2c_amd756_exit(void) 
    428418{ 
    429419        pci_unregister_driver(&amd756_driver); 
     420        release_region(amd756_ioport, SMB_IOSIZE); 
    430421} 
    431422 
     
    434425MODULE_LICENSE("GPL"); 
    435426 
    436 module_init(amd756_init) 
    437 module_exit(amd756_exit) 
     427module_init(i2c_amd756_init) 
     428module_exit(i2c_amd756_exit) 
  • lm-sensors/trunk/kernel/busses/i2c-amd8111.c

    r1693 r1698  
    321321} 
    322322 
    323 void amd8111_inc(struct i2c_adapter *adapter) 
    324 { 
    325         MOD_INC_USE_COUNT; 
    326 } 
    327  
    328 void amd8111_dec(struct i2c_adapter *adapter) 
    329 { 
    330         MOD_DEC_USE_COUNT; 
    331 } 
    332323 
    333324u32 amd8111_func(struct i2c_adapter *adapter) 
     
    346337}; 
    347338 
     339 
     340static struct pci_device_id amd8111_ids[] __devinitdata = { 
     341        { 0x1022, 0x746a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 
     342        { 0, } 
     343}; 
     344 
    348345static int __devinit amd8111_probe(struct pci_dev *dev, const struct pci_device_id *id) 
    349346{ 
    350347        struct amd_smbus *smbus; 
     348        int error; 
    351349 
    352350        if (~pci_resource_flags(dev, 0) & IORESOURCE_IO) 
     
    367365        } 
    368366 
     367        smbus->adapter.owner = THIS_MODULE; 
    369368        sprintf(smbus->adapter.name, "SMBus2 AMD8111 adapter at %04x", smbus->base); 
    370369        smbus->adapter.id = I2C_ALGO_SMBUS | I2C_HW_SMBUS_AMD8111; 
    371370        smbus->adapter.algo = &smbus_algorithm; 
    372371        smbus->adapter.algo_data = smbus; 
    373         smbus->adapter.inc_use = amd8111_inc; 
    374         smbus->adapter.dec_use = amd8111_dec; 
    375  
    376         if (i2c_add_adapter(&smbus->adapter)) { 
     372 
     373        error = i2c_add_adapter(&smbus->adapter); 
     374        if (error) { 
    377375                printk(KERN_WARNING "i2c-amd8111.c: Failed to register adapter.\n"); 
    378376                release_region(smbus->base, smbus->size); 
     
    387385} 
    388386 
     387 
    389388static void __devexit amd8111_remove(struct pci_dev *dev) 
    390389{ 
    391390        struct amd_smbus *smbus = (void*) pci_get_drvdata(dev); 
    392         if (i2c_del_adapter(&smbus->adapter)) { 
    393                 printk(KERN_WARNING "i2c-amd8111.c: Failed to unregister adapter.\n"); 
    394                 return; 
    395         } 
     391        i2c_del_adapter(&smbus->adapter); 
    396392        release_region(smbus->base, smbus->size); 
    397393        kfree(smbus); 
    398394} 
    399395 
    400 static struct pci_device_id amd8111_id_table[] __devinitdata = 
    401 {{ 0x1022, 0x746a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 
    402  { 0 }}; 
    403  
    404  
    405396static struct pci_driver amd8111_driver = { 
    406         .name = "amd8111 smbus 2.0", 
    407         .id_table = amd8111_id_table
    408         .probe = amd8111_probe, 
    409         .remove = __devexit_p(amd8111_remove), 
     397        .name          = "amd8111 smbus 2.0", 
     398        .id_table      = amd8111_ids
     399        .probe         = amd8111_probe, 
     400        .remove                = __devexit_p(amd8111_remove), 
    410401}; 
    411402 
    412 int __init amd8111_init(void) 
     403static int __init i2c_amd8111_init(void) 
    413404{ 
    414405        printk(KERN_INFO "i2c-amd8111.o version %s (%s)\n", LM_VERSION, LM_DATE); 
     
    416407} 
    417408 
    418 void __exit amd8111_exit(void) 
     409 
     410static void __exit i2c_amd8111_exit(void) 
    419411{ 
    420412        pci_unregister_driver(&amd8111_driver); 
    421413} 
    422414 
    423 module_init(amd8111_init); 
    424 module_exit(amd8111_exit); 
     415module_init(i2c_amd8111_init); 
     416module_exit(i2c_amd8111_exit); 
  • lm-sensors/trunk/kernel/busses/i2c-hydra.c

    r1427 r1698  
    3636#include <linux/init.h> 
    3737 
    38 #ifdef MODULE_LICENSE 
    3938MODULE_LICENSE("GPL"); 
    40 #endif 
    4139 
    42 /* PCI device */ 
    43 #define VENDOR          PCI_VENDOR_ID_APPLE 
    44 #define DEVICE          PCI_DEVICE_ID_APPLE_HYDRA 
    4540 
    4641#define HYDRA_CACHE_PD  0x00000030 
     
    105100} 
    106101 
    107 static void bit_hydra_inc(struct i2c_adapter *adap) 
    108 { 
    109         MOD_INC_USE_COUNT; 
    110 } 
    111  
    112 static void bit_hydra_dec(struct i2c_adapter *adap) 
    113 { 
    114         MOD_DEC_USE_COUNT; 
    115 } 
    116  
    117102/* ------------------------------------------------------------------------ */ 
    118103 
    119104static struct i2c_algo_bit_data bit_hydra_data = { 
    120         NULL, 
    121         bit_hydra_setsda, 
    122         bit_hydra_setscl, 
    123         bit_hydra_getsda, 
    124         bit_hydra_getscl, 
    125         5, 5, 100,              /*waits, timeout */ 
     105        .setsda         = bit_hydra_setsda, 
     106        .setscl         = bit_hydra_setscl, 
     107        .getsda         = bit_hydra_getsda, 
     108        .getscl         = bit_hydra_getscl, 
     109        .udelay         = 5, 
     110        .mdelay         = 5, 
     111        .timeout        = HZ 
    126112}; 
    127113 
    128114static struct i2c_adapter bit_hydra_ops = { 
    129         "Hydra i2c", 
    130         I2C_HW_B_HYDRA, 
    131         NULL, 
    132         &bit_hydra_data, 
    133         bit_hydra_inc, 
    134         bit_hydra_dec, 
    135         NULL, 
    136         NULL, 
     115        .owner          = THIS_MODULE, 
     116        .name           = "Hydra i2c", 
     117        .id             = I2C_HW_B_HYDRA, 
     118        .algo_data              = &bit_hydra_data, 
    137119}; 
    138120 
    139121 
    140 static int find_hydra(void) 
     122/* PCI device */ 
     123#define VENDOR          PCI_VENDOR_ID_APPLE 
     124#define DEVICE          PCI_DEVICE_ID_APPLE_HYDRA 
     125 
     126static struct pci_device_id hydra_ids[] __devinitdata = { 
     127        { 0, } 
     128}; 
     129 
     130static int __devinit hydra_probe(struct pci_dev *dev, const struct pci_device_id *id) 
    141131{ 
    142         struct pci_dev *dev; 
    143132        unsigned int base_addr; 
    144133 
    145         if (!pci_present()) 
    146                 return -ENODEV; 
    147  
    148         dev = pci_find_device(VENDOR, DEVICE, NULL); 
    149         if (!dev) { 
    150                 printk("Hydra not found\n"); 
    151                 return -ENODEV; 
    152         } 
    153  
    154 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13) 
    155134        base_addr = dev->resource[0].start; 
    156 #else 
    157         base_addr = dev->base_address[0]; 
    158 #endif 
    159135        hydra_base = (unsigned long) ioremap(base_addr, 0x100); 
    160136 
    161         return 0; 
     137        pdregw(0);              /* clear SCLK_OE and SDAT_OE */ 
     138        return i2c_bit_add_bus(&bit_hydra_ops); 
    162139} 
    163140 
    164 #ifdef MODULE 
    165 static 
    166 #else 
    167 extern 
    168 #endif 
    169 int __init i2c_hydra_init(void) 
     141static void __devexit hydra_remove(struct pci_dev *dev) 
    170142{ 
    171         if (find_hydra() < 0) { 
    172                 printk("Error while reading PCI configuration\n"); 
    173                 return -ENODEV; 
    174         } 
    175  
    176         pdregw(0);              /* clear SCLK_OE and SDAT_OE */ 
    177  
    178         if (i2c_bit_add_bus(&bit_hydra_ops) == 0) { 
    179                 printk("Hydra i2c: Module succesfully loaded\n"); 
    180                 return 0; 
    181         } else { 
    182                 iounmap((void *) hydra_base); 
    183                 printk 
    184                     ("Hydra i2c: Algo-bit error, couldn't register bus\n"); 
    185                 return -ENODEV; 
    186         } 
     143        pdregw(0);      /* clear SCLK_OE and SDAT_OE */ 
     144        i2c_bit_del_bus(&bit_hydra_ops); 
    187145} 
    188146 
    189 EXPORT_NO_SYMBOLS; 
    190147 
    191 #ifdef MODULE 
     148static struct pci_driver hydra_driver = { 
     149        .name           = "hydra smbus", 
     150        .id_table       = hydra_ids, 
     151        .probe          = hydra_probe, 
     152        .remove         = __devexit_p(hydra_remove), 
     153}; 
     154 
     155static int __init i2c_hydra_init(void) 
     156
     157        return pci_module_init(&hydra_driver); 
     158
     159 
     160 
     161static void __exit i2c_hydra_exit(void) 
     162
     163        pci_unregister_driver(&hydra_driver); 
     164        iounmap((void *) hydra_base); 
     165
     166 
     167 
     168 
    192169MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>"); 
    193170MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O"); 
    194171 
    195 int init_module(void) 
    196 
    197         return i2c_hydra_init(); 
    198 
     172module_init(i2c_hydra_init); 
     173module_exit(i2c_hydra_exit); 
    199174 
    200 void cleanup_module(void) 
    201 { 
    202         i2c_bit_del_bus(&bit_hydra_ops); 
    203         if (hydra_base) { 
    204                 pdregw(0);      /* clear SCLK_OE and SDAT_OE */ 
    205                 iounmap((void *) hydra_base); 
    206         } 
    207 } 
    208 #endif 
  • 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_ada