Changeset 1704

Show
Ignore:
Timestamp:
01/21/03 05:53:16 (10 years ago)
Author:
mmh
Message:

Removed some redundant pci_find_device calls.

Cleaned up kernel log messages.

Files:
1 modified

Legend:

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

    r1700 r1704  
    4747#include <linux/init.h> 
    4848 
    49 MODULE_LICENSE("GPL"); 
     49#define DRV_NAME "i2c-sis645" 
    5050 
    5151/* PCI identifiers */ 
     
    9090 
    9191/* base address register in PCI config space */ 
    92 #define BASE_IO_REG 0x04 
     92#define SIS645_BAR 0x04 
    9393 
    9494/* SiS645 SMBus registers */ 
     
    121121#define SIS645_BLOCK_DATA 0x05 
    122122 
    123 static int sis645_enable_smbus(struct pci_dev *dev); 
    124 static int sis645_build_dev(struct pci_dev **smbus_dev, 
    125                             struct pci_dev *bridge_dev); 
    126  
    127123static void sis645_do_pause(unsigned int amount); 
    128124static int sis645_transaction(int size); 
    129125 
    130  
     126static struct i2c_adapter sis645_adapter; 
    131127 
    132128static unsigned short sis645_smbus_base = 0; 
     
    146142/* Turns on SMBus device if it is not; return 0 iff successful 
    147143 */ 
    148 static int sis645_enable_smbus(struct pci_dev *dev) 
     144static int __devinit sis645_enable_smbus(struct pci_dev *dev) 
    149145{ 
    150146        u8 val = 0; 
     
    153149 
    154150#ifdef DEBUG 
    155         printk("i2c-sis645.o: Config byte was 0x%02x.\n", val); 
     151        printk(KERN_DEBUG DRV_NAME ": Config byte was 0x%02x.\n", val); 
    156152#endif 
    157153 
     
    162158        if (val & 0x10) { 
    163159#ifdef DEBUG 
    164                 printk("i2c-sis645.o: Error: Config byte stuck!\n"); 
     160                printk(KERN_DEBUG DRV_NAME ": Config byte stuck!\n"); 
    165161#endif 
    166162                return -1; 
     
    172168/* Builds the basic pci_dev for SiS645 SMBus 
    173169 */ 
    174 static int sis645_build_dev(struct pci_dev **smbus_dev, 
     170static int __devinit sis645_build_dev(struct pci_dev **smbus_dev, 
    175171                            struct pci_dev *bridge_dev) 
    176172{ 
     
    191187        ret = pci_read_config_word(&temp_dev, PCI_VENDOR_ID, &vid); 
    192188        if (ret || PCI_VENDOR_ID_SI != vid) { 
    193                 printk("i2c-sis645.o: Couldn't find SMBus device!\n"); 
     189                printk(KERN_ERR DRV_NAME ": Couldn't find SMBus device!\n"); 
    194190                return ret; 
    195191        } 
     
    198194        ret = pci_read_config_word(&temp_dev, PCI_DEVICE_ID, &did); 
    199195        if (ret || PCI_DEVICE_ID_SI_SMBUS != did) { 
    200                 printk("i2c-sis645.o: Couldn't find SMBus device!\n"); 
     196                printk(KERN_ERR DRV_NAME ": Couldn't find SMBus device!\n"); 
    201197                return ret; 
    202198        } 
     
    206202        *smbus_dev = kmalloc(sizeof(**smbus_dev), GFP_ATOMIC); 
    207203        if (NULL == *smbus_dev) { 
    208                 printk("i2c-sis645.o: Error: Out of memory!\n"); 
     204                printk(KERN_ERR DRV_NAME ": Out of memory!\n"); 
    209205                return -ENOMEM; 
    210206        } 
     
    214210        ret = pci_setup_device(*smbus_dev); 
    215211        if (ret) { 
    216                 printk("i2c-sis645.o: pci_setup_device failed (0x%08x)\n",ret); 
     212                printk(KERN_ERR DRV_NAME ": pci_setup_device failed (0x%08x)\n",ret); 
    217213        } 
    218214        return ret; 
     
    223219/* Detect whether a SiS645 can be found, and initialize it, where necessary. 
    224220 */ 
    225 static int sis645_setup(void) 
    226 { 
    227         struct pci_dev *SIS645_ISA_dev; 
     221static int __devinit sis645_probe(struct pci_dev *dev, const struct pci_device_id *id) 
     222{ 
    228223        struct pci_dev *SIS645_SMBUS_dev; 
    229224        int ret; 
    230225        u16 ww = 0; 
    231226 
    232         if (pci_present() == 0) { 
    233                 printk("i2c-sis645.o: Error: No PCI-bus found!\n"); 
    234                 return -ENODEV; 
    235         } 
    236  
    237         if (SIS645_ISA_dev = pci_find_device(PCI_VENDOR_ID_SI, 
    238                         PCI_DEVICE_ID_SI_961, NULL)) { 
    239                 printk("i2c-sis645.o: Found SiS961 south bridge.\n"); 
    240         } 
    241  
    242         else if (SIS645_ISA_dev = pci_find_device(PCI_VENDOR_ID_SI, 
    243                         PCI_DEVICE_ID_SI_962, NULL)) { 
    244                 printk("i2c-sis645.o: Found SiS962 [MuTIOL Media IO].\n"); 
    245         } 
    246  
    247         else if (SIS645_ISA_dev = pci_find_device(PCI_VENDOR_ID_SI, 
    248                         PCI_DEVICE_ID_SI_503, NULL)) { 
    249                 printk("i2c-sis645.o: Found SiS south bridge in compatability mode(?)\n"); 
     227        if (sis645_smbus_base) { 
     228                printk(KERN_ERR DRV_NAME ": Only one device supported.\n"); 
     229                return -EBUSY; 
     230        } 
     231 
     232        switch (dev->device) { 
     233        case PCI_DEVICE_ID_SI_961: 
     234                printk(KERN_INFO DRV_NAME ": Found SiS961 south bridge.\n"); 
     235                break; 
     236 
     237        case PCI_DEVICE_ID_SI_962: 
     238                printk(KERN_INFO DRV_NAME ": Found SiS962 [MuTIOL Media IO].\n"); 
     239                break; 
     240 
     241        case PCI_DEVICE_ID_SI_503: 
     242                printk(KERN_INFO DRV_NAME ": Found SiS south bridge in compatability mode(?)\n"); 
    250243 
    251244                /* look for known compatible north bridges */ 
     
    260253                        && (NULL == pci_find_device(PCI_VENDOR_ID_SI, 
    261254                                PCI_DEVICE_ID_SI_735, NULL))) { 
    262                         printk("i2c-sis645.o: Error: Can't find suitable host bridge!\n"); 
     255                        printk(KERN_ERR DRV_NAME ": Can't find suitable host bridge!\n"); 
    263256                        return -ENODEV; 
    264257                } 
    265         } 
    266  
    267         else { 
    268                 printk("i2c-sis645.o: Error: Can't find suitable south bridge!\n"); 
     258                break ; 
     259 
     260        default: 
     261                printk(KERN_ERR DRV_NAME ": Can't find suitable south bridge!\n"); 
    269262                return -ENODEV; 
    270263        } 
     
    273266                        PCI_DEVICE_ID_SI_SMBUS, NULL))) { 
    274267 
    275                 printk("i2c-sis645.o: " 
     268                printk(KERN_INFO DRV_NAME ": " 
    276269                        "Attempting to enable SiS645 SMBus device\n"); 
    277270 
    278271#ifndef CONFIG_HOTPLUG 
    279                 printk("i2c-sis645.o: " 
     272                printk(KERN_INFO DRV_NAME ": " 
    280273                        "Requires kernel >= 2.4 with CONFIG_HOTPLUG, sorry!\n"); 
    281274                return -ENODEV; 
    282275 
    283276#else /* CONFIG_HOTPLUG */ 
    284                 if (ret = sis645_enable_smbus(SIS645_ISA_dev)) { 
     277                if (ret = sis645_enable_smbus(dev)) { 
    285278                        return ret; 
    286279                } 
    287280 
    288                 if (ret = sis645_build_dev(&SIS645_SMBUS_dev, SIS645_ISA_dev)) { 
     281                if (ret = sis645_build_dev(&SIS645_SMBUS_dev, dev)) { 
    289282                        return ret; 
    290283                } 
    291284 
    292285                if (ret = pci_enable_device(SIS645_SMBUS_dev)) { 
    293                         printk("i2c-sis645.o: Can't pci_enable SMBus device!" 
     286                        printk(KERN_ERR DRV_NAME ": Can't pci_enable SMBus device!" 
    294287                                " (0x%08x)\n", ret); 
    295288                        return ret; 
     
    304297        pci_read_config_word(SIS645_SMBUS_dev, PCI_CLASS_DEVICE, &ww); 
    305298        if (PCI_CLASS_SERIAL_SMBUS != ww) { 
    306                 printk("i2c-sis645.o: Error: Unsupported device class 0x%04x!\n", ww); 
     299                printk(KERN_ERR DRV_NAME ": Unsupported device class 0x%04x!\n", ww); 
    307300                return -ENODEV; 
    308301        } 
    309302 
    310303        /* get the IO base address */ 
    311         sis645_smbus_base = SIS645_SMBUS_dev->resource[BASE_IO_REG].start; 
     304        sis645_smbus_base = pci_resource_start(SIS645_SMBUS_dev, SIS645_BAR); 
    312305        if (!sis645_smbus_base) { 
    313                 printk("i2c-sis645.o: SiS645 SMBus base address not initialized!\n"); 
     306                printk(KERN_ERR DRV_NAME ": SiS645 SMBus base address not initialized!\n"); 
    314307                return -EINVAL; 
    315308        } 
    316         printk("i2c-sis645.o: SiS645 SMBus base address: 0x%04x\n", sis645_smbus_base); 
     309        printk(KERN_INFO DRV_NAME ": SiS645 SMBus base address: 0x%04x\n", sis645_smbus_base); 
    317310 
    318311        /* Everything is happy, let's grab the memory and set things up. */ 
    319312        if (!request_region(sis645_smbus_base, SIS645_SMB_IOREGION, "sis645-smbus")) { 
    320                 printk 
    321                     ("i2c-sis645.o: SMBus registers 0x%04x-0x%04x already in use!\n", 
     313                printk(KERN_ERR DRV_NAME ": SMBus registers 0x%04x-0x%04x already in use!\n", 
    322314                     sis645_smbus_base, sis645_smbus_base + SIS645_SMB_IOREGION - 1); 
    323315                return -EINVAL; 
    324316        } 
    325317 
     318        sprintf(sis645_adapter.name, "SMBus SiS645 adapter at 0x%04x", sis645_smbus_base); 
     319        i2c_add_adapter(&sis645_adapter); 
     320 
    326321        return(0); 
    327322} 
    328  
    329323 
    330324/* Internally used pause function */ 
     
    347341        if (((temp = sis645_read(SMB_CNT)) & 0x03) != 0x00) { 
    348342#ifdef DEBUG 
    349                 printk("i2c-sis645.o: SMBus busy (0x%02x). Resetting...\n", 
     343                printk(KERN_DEBUG DRV_NAME ": SMBus busy (0x%02x). Resetting...\n", 
    350344                                temp); 
    351345#endif 
     
    357351                if (((temp = sis645_read(SMB_CNT)) & 0x03) != 0x00) { 
    358352#ifdef DEBUG 
    359                         printk("i2c-sis645.o: Failed! (0x%02x)\n", temp); 
     353                        printk(KERN_DEBUG DRV_NAME ": Failed! (0x%02x)\n", temp); 
    360354#endif 
    361355                        return -1; 
    362356                } else { 
    363357#ifdef DEBUG 
    364                         printk("i2c-sis645.o: Successful!\n"); 
     358                        printk(KERN_DEBUG DRV_NAME ": Successful!\n"); 
    365359#endif 
    366360                } 
     
    385379        /* If the SMBus is still busy, we give up */ 
    386380        if (timeout >= MAX_TIMEOUT) { 
    387                 printk("i2c-sis645.o: SMBus Timeout! (0x%02x)\n",temp); 
     381                printk(KERN_DEBUG DRV_NAME ": SMBus Timeout! (0x%02x)\n",temp); 
    388382                result = -1; 
    389383        } 
     
    392386        if (temp & 0x02) { 
    393387#ifdef DEBUG 
    394                 printk("i2c-sis645.o: Error: Failed bus transaction!\n"); 
     388                printk(KERN_DEBUG DRV_NAME ": Failed bus transaction!\n"); 
    395389#endif 
    396390                result = -1; 
     
    400394        if (temp & 0x04) { 
    401395#ifdef DEBUG 
    402                 printk("i2c-sis645.o: Error: Bus collision!\n"); 
     396                printk(KERN_DEBUG DRV_NAME ": Bus collision!\n"); 
    403397#endif 
    404398                result = -1; 
     
    409403        if (temp = sis645_read(SMB_STS)) { 
    410404#ifdef DEBUG 
    411                 printk("i2c-sis645.o: Failed reset at end of transaction!" 
     405                printk(KERN_DEBUG DRV_NAME ": Failed reset at end of transaction!" 
    412406                                " (0x%02x)\n", temp); 
    413407#endif 
     
    457451        case I2C_SMBUS_BLOCK_DATA: 
    458452                /* TO DO: */ 
    459                 printk("sis645.o: SMBus block not implemented!\n"); 
     453                printk(KERN_INFO DRV_NAME ": SMBus block not implemented!\n"); 
    460454                return -1; 
    461455                break; 
    462456 
    463457        default: 
    464                 printk("sis645.o: unsupported I2C size\n"); 
     458                printk(KERN_INFO DRV_NAME ": Unsupported I2C size\n"); 
    465459                return -1; 
    466460                break; 
     
    523517}; 
    524518 
    525 static int __devinit sis645_probe(struct pci_dev *dev, const struct pci_device_id *id) 
    526 { 
    527  
    528         if (sis645_setup()) { 
    529                 printk ("i2c-sis645.o: SiS645 not detected, module not inserted.\n"); 
    530  
    531                 return -ENODEV; 
    532         } 
    533          
    534         sprintf(sis645_adapter.name, "SMBus SiS645 adapter at 0x%04x", sis645_smbus_base); 
    535         i2c_add_adapter(&sis645_adapter); 
    536 } 
    537  
    538519static void __devexit sis645_remove(struct pci_dev *dev) 
    539520{ 
     
    551532static int __init i2c_sis645_init(void) 
    552533{ 
    553         printk("i2c-sis645.o: version %s (%s)\n", LM_VERSION, LM_DATE); 
     534        printk(KERN_INFO DRV_NAME ".o version %s (%s)\n", LM_VERSION, LM_DATE); 
    554535        return pci_module_init(&sis645_driver); 
    555536} 
     
    566547MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); 
    567548MODULE_DESCRIPTION("SiS645 SMBus driver"); 
     549MODULE_LICENSE("GPL"); 
    568550 
    569551/* Register initialization functions using helper macros */