Changeset 1504

Show
Ignore:
Timestamp:
08/25/02 16:33:27 (11 years ago)
Author:
amalysh
Message:

(amalysh)
Fixed the typo in sis630_access
Changed sis630_transaction. Now it's 2x faster...

Files:
1 modified

Legend:

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

    r1497 r1504  
    1717    along with this program; if not, write to the Free Software 
    1818    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
     19*/ 
     20 
     21/* 
     22   Changes: 
     23   24.08.2002 
     24        Fixed the typo in sis630_access (Thanks to Mark M. Hoffman) 
     25        Changed sis630_transaction. Now it's 2x faster (Thanks to Mark M. Hoffman) 
    1926*/ 
    2027 
     
    97104                          union i2c_smbus_data *data); 
    98105static void sis630_do_pause(unsigned int amount); 
    99 static int sis630_transaction(void); 
     106static int sis630_transaction(int size); 
    100107static void sis630_inc(struct i2c_adapter *adapter); 
    101108static void sis630_dec(struct i2c_adapter *adapter); 
     
    145152} 
    146153 
    147 int sis630_transaction() { 
     154int sis630_transaction(int size) { 
    148155        int temp; 
    149156        int result = 0; 
     
    152159        /* 
    153160          Make sure the SMBus host is ready to start transmitting. 
    154           Datasheet say SMB_STS are sticky bits, but on my Laptop 
    155           (Clevo/Kapok 2202) SMBALT# (bit 7) cannot be cleared ??? 
    156161        */ 
    157         if ((temp = sis630_read(SMB_STS)) != 0x80) { 
     162        if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) { 
    158163#ifdef DEBUG 
    159164                printk(KERN_DEBUG "i2c-sis630.o: SMBus busy (%02x). " 
    160165                        "Resetting...\n",temp); 
    161166#endif 
    162                 sis630_write(SMB_STS, temp & 0xff); 
    163                 if ((temp = sis630_read(SMB_STS)) != 0x80) { 
     167                /* kill smbus transaction */ 
     168                sis630_write(SMBHOST_CNT, 0x02); 
     169 
     170                if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) { 
    164171#ifdef DEBUG 
    165172                        printk(KERN_DEBUG "i2c-sis630.o: Failed! (%02x)\n", 
     
    174181        } 
    175182 
    176         /* start the transaction by setting bit 4 */ 
    177         sis630_write(SMBHOST_CNT, sis630_read(SMBHOST_CNT) | 0x10); 
     183        /* disable timeout interrupt and set clock to 56KHz */ 
     184        sis630_write(SMB_CNT, 0x20); 
     185 
     186        /* clear all sticky bits */ 
     187        temp = sis630_read(SMB_STS); 
     188        sis630_write(SMB_STS, temp & 0x1e); 
     189 
     190        /* start the transaction by setting bit 4 and size */ 
     191        sis630_write(SMBHOST_CNT,0x10 | (size & 0x07)); 
    178192 
    179193        /* We will always wait for a fraction of a second! */ 
     
    181195                sis630_do_pause(1); 
    182196                temp = sis630_read(SMB_STS); 
    183         } while (!(temp & 0x08) && (timeout++ < MAX_TIMEOUT)); 
     197        } while (!(temp & 0x0e) && (timeout++ < MAX_TIMEOUT)); 
    184198 
    185199        /* If the SMBus is still busy, we give up */ 
     
    203217                printk(KERN_ERR "i2c-sis630.o: Bus collision! " 
    204218                        "SMBus may be locked until next hard reset (or not...)\n"); 
    205  
    206219                /* TBD: Datasheet say: 
    207220                   the software should clear this bit and restart SMBUS operation 
     
    209222        } 
    210223 
    211         if ((temp = sis630_read(SMB_STS)) != 0x80) { 
    212                 sis630_write(SMB_STS, temp & 0xff); 
    213         } 
    214  
    215         if ((temp = sis630_read(SMB_STS)) != 0x80) { 
    216 #ifdef DEBUG 
    217                 printk(KERN_DEBUG "i2c-sis630.o: Failed reset at end of " 
    218                         "transaction (%02x)\n",temp); 
    219 #endif 
    220         } 
     224        /* clear all status "sticky" bits */ 
     225        sis630_write(SMB_STS, temp); 
    221226 
    222227        return result; 
     
    270275 
    271276 
    272         sis630_write(SMBHOST_CNT,(size & 0x07)); 
    273  
    274         if (sis630_transaction()) 
     277        if (sis630_transaction(size)) 
    275278                return -1; 
    276279 
     
    281284 
    282285        switch(size) { 
    283                 case I2C_SMBUS_BYTE: 
    284                 case I2C_SMBUS_BYTE_DATA: 
     286                case SIS630_BYTE: 
     287                case SIS630_BYTE_DATA: 
    285288                        data->byte = sis630_read(SMB_BYTE); 
    286289                        break; 
    287                 case I2C_SMBUS_PROC_CALL: 
    288                 case I2C_SMBUS_WORD_DATA: 
     290                case SIS630_PCALL: 
     291                case SIS630_WORD_DATA: 
    289292                        data->word = sis630_read(SMB_BYTE) + (sis630_read(SMB_BYTE + 1) << 8); 
    290293                        break; 
     
    312315int sis630_setup(void) { 
    313316        unsigned char b; 
    314         int rc; 
    315317        struct pci_dev *sis630_dev = NULL; 
    316318 
     
    337339           in acpi io space and read acpi base addr 
    338340        */ 
    339         if ((rc = pci_read_config_byte(sis630_dev, SIS630_BIOS_CTL_REG, &b))) { 
     341        if (PCIBIOS_SUCCESSFUL != 
     342            pci_read_config_byte(sis630_dev, SIS630_BIOS_CTL_REG,&b)) { 
    340343                printk(KERN_ERR "i2c-sis630.o: Error: Can't read bios ctl reg\n"); 
    341                 return rc; 
    342         } 
     344                return -ENODEV; 
     345        } 
     346        /* if ACPI already anbled , do nothing */ 
    343347        if (!(b & 0x80) && 
    344             (rc = pci_write_config_byte(sis630_dev, SIS630_BIOS_CTL_REG, b | 0x80))) { 
     348            PCIBIOS_SUCCESSFUL != 
     349            pci_write_config_byte(sis630_dev,SIS630_BIOS_CTL_REG,b|0x80)) { 
    345350                printk(KERN_ERR "i2c-sis630.o: Error: Can't enable ACPI\n"); 
    346                 return rc; 
     351                return -ENODEV; 
    347352        } 
    348353        /* Determine the ACPI base address */ 
    349         if ((rc = pci_read_config_word(sis630_dev, SIS630_ACPI_BASE_REG,&acpi_base))) { 
     354        if (PCIBIOS_SUCCESSFUL != 
     355            pci_read_config_word(sis630_dev,SIS630_ACPI_BASE_REG,&acpi_base)) { 
    350356                printk(KERN_ERR "i2c-sis630.o: Error: Can't determine ACPI base address\n"); 
    351                 return rc; 
     357                return -ENODEV; 
    352358        } 
    353359 
     
    358364        /* Everything is happy, let's grab the memory and set things up. */ 
    359365        if (!request_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION, "sis630-smbus")){ 
    360  
    361366                printk(KERN_ERR "i2c-sis630.o: SMBus registers 0x%04x-0x%04x " 
    362367                        "already in use!\n",acpi_base + SMB_STS, acpi_base + SMB_SAA);