Changeset 3140

Show
Ignore:
Timestamp:
10/29/05 23:04:11 (8 years ago)
Author:
khali
Message:

Code cleanups, backported from Linux 2.6.

Files:
1 modified

Legend:

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

    r3139 r3140  
    3939#include <linux/kernel.h> 
    4040#include <linux/stddef.h> 
    41 #include <linux/sched.h> 
    4241#include <linux/ioport.h> 
    4342#include <linux/i2c.h> 
     
    5453static unsigned short vt596_smba; 
    5554#define SMBHSTSTS       (vt596_smba + 0) 
    56 #define SMBHSLVSTS      (vt596_smba + 1) 
    5755#define SMBHSTCNT       (vt596_smba + 2) 
    5856#define SMBHSTCMD       (vt596_smba + 3) 
     
    6159#define SMBHSTDAT1      (vt596_smba + 6) 
    6260#define SMBBLKDAT       (vt596_smba + 7) 
    63 #define SMBSLVCNT       (vt596_smba + 8) 
    64 #define SMBSHDWCMD      (vt596_smba + 9) 
    65 #define SMBSLVEVT       (vt596_smba + 0xA) 
    66 #define SMBSLVDAT       (vt596_smba + 0xC) 
    6761 
    6862/* PCI Address Constants */ 
     
    7165   We try to select the better one */ 
    7266 
    73 static unsigned short smb_cf_hstcfg = 0xD2; 
    74  
    75 #define SMBHSTCFG       (smb_cf_hstcfg) 
    76 #define SMBSLVC         (smb_cf_hstcfg + 1) 
    77 #define SMBSHDW1        (smb_cf_hstcfg + 2) 
    78 #define SMBSHDW2        (smb_cf_hstcfg + 3) 
    79 #define SMBREV          (smb_cf_hstcfg + 4) 
     67static unsigned short SMBHSTCFG = 0xD2; 
    8068 
    8169/* Other settings */ 
    8270#define MAX_TIMEOUT     500 
    83 #define ENABLE_INT9     0 
    8471 
    8572/* VT82C596 constants */ 
     
    10794 
    10895 
     96static struct pci_driver vt596_driver; 
    10997static struct i2c_adapter vt596_adapter; 
    11098 
     
    112100static unsigned int vt596_features; 
    113101 
    114 /* Another internally used function */ 
     102/* Return -1 on error, 0 on success */ 
    115103static int vt596_transaction(void) 
    116104{ 
     
    132120                if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 
    133121                        dev_dbg(&vt596_adapter, "Failed! (0x%02x)\n", temp); 
    134  
    135122                        return -1; 
    136123                } else { 
    137                         dev_dbg(&vt596_adapter, "Successfull!\n"); 
     124                        dev_dbg(&vt596_adapter, "Successful!\n"); 
    138125                } 
    139126        } 
    140127 
    141         /* start the transaction by setting bit 6 */ 
    142         outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); 
    143  
    144         /* We will always wait for a fraction of a second! 
    145            I don't know if VIA needs this, Intel did  */ 
     128        /* Start the transaction by setting bit 6 */ 
     129        outb_p(inb(SMBHSTCNT) | 0x40, SMBHSTCNT); 
     130 
     131        /* We will always wait for a fraction of a second */ 
    146132        do { 
    147133                i2c_delay(1); 
     
    152138        if (timeout >= MAX_TIMEOUT) { 
    153139                result = -1; 
    154                 dev_dbg(&vt596_adapter, "SMBus Timeout!\n"); 
     140                dev_err(&vt596_adapter, "SMBus Timeout!\n"); 
    155141        } 
    156142 
    157143        if (temp & 0x10) { 
    158144                result = -1; 
    159                 dev_dbg(&vt596_adapter, "Error: Failed bus transaction\n"); 
     145                dev_err(&vt596_adapter, "Transaction failed (0x%02x)\n", 
     146                        inb_p(SMBHSTCNT) & 0x3C); 
    160147        } 
    161148 
    162149        if (temp & 0x08) { 
    163150                result = -1; 
    164                 dev_info(&vt596_adapter, "Bus collision! SMBus may be " 
    165                         "locked until next hard\nreset. (sorry!)\n"); 
    166                 /* Clock stops and slave is stuck in mid-transmission */ 
     151                dev_err(&vt596_adapter, "SMBus collision!\n"); 
    167152        } 
    168153 
    169154        if (temp & 0x04) { 
     155                int size = inb_p(SMBHSTCNT) & 0x3C; 
     156                int read = inb_p(SMBHSTADD) & 0x01; 
    170157                result = -1; 
    171                 dev_dbg(&vt596_adapter, "Error: no response!\n"); 
    172         } 
    173  
    174         if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 
     158                /* The quick and receive byte command are used to probe 
     159                   for chips, so errors are expected, and we don't 
     160                   want to frighten the user. */ 
     161                if (!((size == VT596_QUICK && !read) || 
     162                      (size == VT596_BYTE && read))) 
     163                        dev_err(&vt596_adapter, "Transaction error!\n"); 
     164        } 
     165 
     166        /* Resetting status register */ 
     167        if (temp & 0x1F) 
    175168                outb_p(temp, SMBHSTSTS); 
    176                 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 
    177                         dev_warn(&vt596_adapter, "Failed reset at end " 
    178                                  "of transaction (%02x)\n", temp); 
    179                 } 
    180         } 
    181169 
    182170        dev_dbg(&vt596_adapter, "Transaction (post): CNT=%02x, CMD=%02x, " 
     
    188176} 
    189177 
    190 /* Return -1 on error. */ 
     178/* Return -1 on error, 0 on success */ 
    191179static s32 vt596_access(struct i2c_adapter *adap, u16 addr, 
    192180                unsigned short flags, char read_write, u8 command, 
    193181                int size, union i2c_smbus_data *data) 
    194182{ 
    195         int i, len; 
     183        int i; 
    196184 
    197185        switch (size) { 
    198186        case I2C_SMBUS_QUICK: 
    199                 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
    200                        SMBHSTADD); 
    201187                size = VT596_QUICK; 
    202188                break; 
    203189        case I2C_SMBUS_BYTE: 
    204                 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
    205                        SMBHSTADD); 
    206190                if (read_write == I2C_SMBUS_WRITE) 
    207191                        outb_p(command, SMBHSTCMD); 
     
    209193                break; 
    210194        case I2C_SMBUS_BYTE_DATA: 
    211                 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
    212                        SMBHSTADD); 
    213195                outb_p(command, SMBHSTCMD); 
    214196                if (read_write == I2C_SMBUS_WRITE) 
     
    217199                break; 
    218200        case I2C_SMBUS_WORD_DATA: 
    219                 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
    220                        SMBHSTADD); 
    221201                outb_p(command, SMBHSTCMD); 
    222202                if (read_write == I2C_SMBUS_WRITE) { 
     
    228208        case I2C_SMBUS_I2C_BLOCK_DATA: 
    229209                if (!(vt596_features & FEATURE_I2CBLOCK)) 
    230                         return -1; 
     210                        goto exit_unsupported; 
    231211                if (read_write == I2C_SMBUS_READ) 
    232212                        outb_p(I2C_SMBUS_BLOCK_MAX, SMBHSTDAT0); 
    233213                /* Fall through */ 
    234214        case I2C_SMBUS_BLOCK_DATA: 
    235                 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
    236                        SMBHSTADD); 
    237215                outb_p(command, SMBHSTCMD); 
    238216                if (read_write == I2C_SMBUS_WRITE) { 
    239                         len = data->block[0]; 
    240                         if (len < 0) 
    241                                 len = 0; 
     217                        u8 len = data->block[0]; 
    242218                        if (len > I2C_SMBUS_BLOCK_MAX) 
    243219                                len = I2C_SMBUS_BLOCK_MAX; 
    244220                        outb_p(len, SMBHSTDAT0); 
    245                         i = inb_p(SMBHSTCNT);   /* Reset SMBBLKDAT */ 
     221                        inb_p(SMBHSTCNT);       /* Reset SMBBLKDAT */ 
    246222                        for (i = 1; i <= len; i++) 
    247223                                outb_p(data->block[i], SMBBLKDAT); 
     
    251227                break; 
    252228        default: 
    253                 dev_warn(&vt596_adapter, "Unsupported transaction %d\n", size); 
    254                 return -1; 
    255         } 
    256  
    257         outb_p((size & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT); 
     229                goto exit_unsupported; 
     230        } 
     231 
     232        outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD); 
     233        outb_p((size & 0x3C), SMBHSTCNT); 
    258234 
    259235        if (vt596_transaction()) /* Error in transaction */ 
     
    265241        switch (size) { 
    266242        case VT596_BYTE: 
    267                 /* Where is the result put? I assume here it is in 
    268                  * SMBHSTDAT0 but it might just as well be in the 
    269                  * SMBHSTCMD. No clue in the docs 
    270                  */ 
    271                 data->byte = inb_p(SMBHSTDAT0); 
    272                 break; 
    273243        case VT596_BYTE_DATA: 
    274244                data->byte = inb_p(SMBHSTDAT0); 
     
    282252                if (data->block[0] > I2C_SMBUS_BLOCK_MAX) 
    283253                        data->block[0] = I2C_SMBUS_BLOCK_MAX; 
    284                 i = inb_p(SMBHSTCNT);   /* Reset SMBBLKDAT */ 
     254                inb_p(SMBHSTCNT);       /* Reset SMBBLKDAT */ 
    285255                for (i = 1; i <= data->block[0]; i++) 
    286256                        data->block[i] = inb_p(SMBBLKDAT); 
     
    288258        } 
    289259        return 0; 
     260 
     261exit_unsupported: 
     262        dev_warn(&vt596_adapter, "Unsupported command invoked! (0x%02x)\n", 
     263                 size); 
     264        return -1; 
    290265} 
    291266 
     
    325300        .id             = I2C_ALGO_SMBUS | I2C_HW_SMBUS_VIA2, 
    326301        .algo           = &smbus_algorithm, 
    327         .name           = "unset", 
    328302        .inc_use        = vt596_inc, 
    329303        .dec_use        = vt596_dec, 
     
    344318 
    345319        if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) || 
    346             !(vt596_smba & 0x1)) { 
     320            !(vt596_smba & 0x0001)) { 
    347321                /* try 2nd address and config reg. for 596 */ 
    348322                if (id->device == PCI_DEVICE_ID_VIA_82C596_3 && 
    349323                    !pci_read_config_word(pdev, SMBBA2, &vt596_smba) && 
    350                     (vt596_smba & 0x1)) { 
    351                         smb_cf_hstcfg = 0x84; 
     324                    (vt596_smba & 0x0001)) { 
     325                        SMBHSTCFG = 0x84; 
    352326                } else { 
    353327                        /* no matches at all */ 
     
    367341 
    368342found: 
    369         if (!request_region(vt596_smba, 8, "viapro-smbus")) { 
     343        if (!request_region(vt596_smba, 8, vt596_driver.name)) { 
    370344                dev_err(pdev, "SMBus region 0x%x already in use!\n", 
    371345                        vt596_smba); 
     
    382356                dev_warn(pdev, "WARNING: SMBus interface set to new " 
    383357                         "address 0x%04x!\n", vt596_smba); 
    384         } else if ((temp & 1) == 0) { 
     358        } else if (!(temp & 0x01)) { 
    385359                if (force) { 
    386360                        /* NOTE: This assumes I/O space and other allocations 
     
    390364                         * this. 
    391365                         */ 
    392                         pci_write_config_byte(pdev, SMBHSTCFG, temp | 1); 
     366                        pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01); 
    393367                        dev_info(pdev, "Enabling SMBus device\n"); 
    394368                } else { 
     
    400374        } 
    401375 
    402         if ((temp & 0x0E) == 8) 
    403                 dev_dbg(pdev, "using Interrupt 9 for SMBus.\n"); 
    404         else if ((temp & 0x0E) == 0) 
    405                 dev_dbg(pdev, "using Interrupt SMI# for SMBus.\n"); 
    406         else 
    407                 dev_dbg(pdev, "Illegal Interrupt configuration " 
    408                         "(or code out of date)!\n"); 
    409  
    410         pci_read_config_byte(pdev, SMBREV, &temp); 
    411         dev_dbg(pdev, "SMBREV = 0x%X\n", temp); 
    412376        dev_dbg(pdev, "VT596_smba = 0x%X\n", vt596_smba); 
    413377