Changeset 707

Show
Ignore:
Timestamp:
01/24/00 21:37:01 (9 years ago)
Author:
frodo
Message:

`indent -kr -i8' on all kernel sources

Files:

Legend:

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

    r705 r707  
    8787 
    8888/* PCI Address Constants */ 
    89 #define SMBCOM    0x004  
     89#define SMBCOM    0x004 
    9090#define SMBBA     0x014 
    9191#define SMBATPC   0x05B         /* used to unlock xxxBA registers */ 
     
    119119 
    120120/* ALI15X3 status register bits */ 
    121 #define ALI15X3_STS_IDLE        0x04           
    122 #define ALI15X3_STS_BUSY        0x08           
    123 #define ALI15X3_STS_DONE        0x10           
     121#define ALI15X3_STS_IDLE        0x04 
     122#define ALI15X3_STS_BUSY        0x08 
     123#define ALI15X3_STS_DONE        0x10 
    124124#define ALI15X3_STS_DEV         0x20    /* device error */ 
    125125#define ALI15X3_STS_COLL        0x40    /* collision or no response */ 
     
    133133extern 
    134134#endif 
    135        int __init i2c_ali15x3_init(void); 
     135int __init i2c_ali15x3_init(void); 
    136136static int __init ali15x3_cleanup(void); 
    137137static int ali15x3_setup(void); 
    138 static s32 ali15x3_access(struct i2c_adapter *adap, u16 addr,  
    139                           unsigned short flags,char read_write, 
    140                           u8 command, int size, union i2c_smbus_data * data); 
    141 static void ali15x3_do_pause( unsigned int amount ); 
     138static s32 ali15x3_access(struct i2c_adapter *adap, u16 addr, 
     139                          unsigned short flags, char read_write, 
     140                          u8 command, int size, 
     141                          union i2c_smbus_data *data); 
     142static void ali15x3_do_pause(unsigned int amount); 
    142143static int ali15x3_transaction(void); 
    143144static void ali15x3_inc(struct i2c_adapter *adapter); 
     
    148149extern int init_module(void); 
    149150extern int cleanup_module(void); 
    150 #endif /* MODULE */ 
     151#endif                         /* MODULE */ 
    151152 
    152153static struct i2c_algorithm smbus_algorithm = { 
    153   /* name */           "Non-I2C SMBus adapter", 
    154   /* id */             I2C_ALGO_SMBUS, 
    155   /* master_xfer */    NULL, 
    156   /* smbus_access */    ali15x3_access, 
    157   /* slave_send */     NULL, 
    158   /* slave_rcv */      NULL, 
    159   /* algo_control */   NULL, 
    160   /* functionality */  ali15x3_func, 
     154       /* name */ "Non-I2C SMBus adapter", 
     155       /* id */ I2C_ALGO_SMBUS, 
     156       /* master_xfer */ NULL, 
     157       /* smbus_access */ ali15x3_access, 
     158       /* slave_send */ NULL, 
     159       /* slave_rcv */ NULL, 
     160       /* algo_control */ NULL, 
     161       /* functionality */ ali15x3_func, 
    161162}; 
    162163 
    163164static struct i2c_adapter ali15x3_adapter = { 
    164   "unset", 
    165   I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3, 
    166   &smbus_algorithm, 
    167   NULL, 
    168   ali15x3_inc, 
    169   ali15x3_dec, 
    170   NULL, 
    171   NULL, 
     165       "unset", 
     166       I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3, 
     167       &smbus_algorithm, 
     168       NULL, 
     169       ali15x3_inc, 
     170       ali15x3_dec, 
     171       NULL, 
     172       NULL, 
    172173}; 
    173174 
     
    182183int ali15x3_setup(void) 
    183184{ 
    184   int error_return=0; 
    185   unsigned char temp; 
    186  
    187   struct pci_dev *ALI15X3_dev; 
    188  
    189   /* First check whether we can access PCI at all */ 
    190   if (pci_present() == 0) { 
    191     printk("i2c-ali15x3.o: Error: No PCI-bus found!\n"); 
    192     error_return=-ENODEV; 
    193     goto END; 
    194  
    195  
    196   /* Look for the ALI15X3, M7101 device */ 
    197   ALI15X3_dev = NULL; 
    198   ALI15X3_dev = pci_find_device(PCI_VENDOR_ID_AL,  
    199                                 PCI_DEVICE_ID_AL_M7101, ALI15X3_dev); 
    200   if(ALI15X3_dev == NULL) { 
    201     printk("i2c-ali15x3.o: Error: Can't detect ali15x3!\n"); 
    202     error_return=-ENODEV; 
    203     goto END; 
    204   }  
     185       int error_return = 0; 
     186       unsigned char temp; 
     187 
     188       struct pci_dev *ALI15X3_dev; 
     189 
     190       /* First check whether we can access PCI at all */ 
     191       if (pci_present() == 0) { 
     192               printk("i2c-ali15x3.o: Error: No PCI-bus found!\n"); 
     193               error_return = -ENODEV; 
     194               goto END; 
     195       
     196 
     197       /* Look for the ALI15X3, M7101 device */ 
     198       ALI15X3_dev = NULL; 
     199        ALI15X3_dev = pci_find_device(PCI_VENDOR_ID_AL, 
     200                                     PCI_DEVICE_ID_AL_M7101, ALI15X3_dev); 
     201       if (ALI15X3_dev == NULL) { 
     202               printk("i2c-ali15x3.o: Error: Can't detect ali15x3!\n"); 
     203               error_return = -ENODEV; 
     204               goto END; 
     205        } 
    205206 
    206207/* Check the following things: 
     
    215216   are zero unless you clear the lock bits. 
    216217*/ 
    217   pci_read_config_byte(ALI15X3_dev, SMBATPC, &temp); 
    218   if(temp & ALI15X3_LOCK) 
    219   {    
    220     temp &= ~ALI15X3_LOCK; 
    221     pci_write_config_byte(ALI15X3_dev, SMBATPC, temp); 
    222   } 
     218        pci_read_config_byte(ALI15X3_dev, SMBATPC, &temp); 
     219        if (temp & ALI15X3_LOCK) { 
     220                temp &= ~ALI15X3_LOCK; 
     221                pci_write_config_byte(ALI15X3_dev, SMBATPC, temp); 
     222        } 
    223223 
    224224/* Determine the address of the SMBus area */ 
    225   pci_read_config_word(ALI15X3_dev, SMBBA,&ali15x3_smba); 
    226   ali15x3_smba &= (0xffff & ~ (ALI15X3_SMB_IOSIZE - 1)); 
    227   if(ali15x3_smba == 0) { 
    228     printk("i2c-ali15x3.o: ALI15X3_smb region uninitialized - upgrade BIOS?\n"); 
    229     error_return=-ENODEV; 
    230   } 
    231  
    232   if(error_return == -ENODEV) 
    233     goto END; 
    234  
    235   if (check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE)) { 
    236     printk("i2c-ali15x3.o: ALI15X3_smb region 0x%x already in use!\n", ali15x3_smba); 
    237     error_return=-ENODEV; 
    238   } 
    239  
    240   if(error_return == -ENODEV) 
    241     goto END; 
     225        pci_read_config_word(ALI15X3_dev, SMBBA, &ali15x3_smba); 
     226        ali15x3_smba &= (0xffff & ~(ALI15X3_SMB_IOSIZE - 1)); 
     227        if (ali15x3_smba == 0) { 
     228                printk 
     229                    ("i2c-ali15x3.o: ALI15X3_smb region uninitialized - upgrade BIOS?\n"); 
     230                error_return = -ENODEV; 
     231        } 
     232 
     233        if (error_return == -ENODEV) 
     234                goto END; 
     235 
     236        if (check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE)) { 
     237                printk 
     238                    ("i2c-ali15x3.o: ALI15X3_smb region 0x%x already in use!\n", 
     239                     ali15x3_smba); 
     240                error_return = -ENODEV; 
     241        } 
     242 
     243        if (error_return == -ENODEV) 
     244                goto END; 
    242245 
    243246/* check if whole device is enabled */ 
    244     pci_read_config_byte(ALI15X3_dev, SMBCOM, &temp); 
    245   if ((temp & 1) == 0) { 
    246     printk("SMBUS: Error: SMB device not enabled - upgrade BIOS?\n");      
    247     error_return=-ENODEV; 
    248     goto END; 
    249   } 
     247        pci_read_config_byte(ALI15X3_dev, SMBCOM, &temp); 
     248        if ((temp & 1) == 0) { 
     249                printk 
     250                    ("SMBUS: Error: SMB device not enabled - upgrade BIOS?\n"); 
     251                error_return = -ENODEV; 
     252                goto END; 
     253        } 
    250254 
    251255/* Is SMB Host controller enabled? */ 
    252   pci_read_config_byte(ALI15X3_dev, SMBHSTCFG, &temp); 
     256       pci_read_config_byte(ALI15X3_dev, SMBHSTCFG, &temp); 
    253257#ifdef FORCE_ALI15X3_ENABLE 
    254258/* This should never need to be done. 
     
    257261   things after enabling this. :') Check for Bios updates before 
    258262   resorting to this.  */ 
    259   if ((temp & 1) == 0) { 
    260     pci_write_config_byte(ALI15X3_dev, SMBHSTCFG, temp | 1); 
    261     printk("i2c-ali15x3.o: WARNING: ALI15X3 SMBus interface has been FORCEFULLY " 
    262            "ENABLED!!\n"); 
    263   } 
    264 #else /* FORCE_ALI15X3_ENABLE */ 
    265   if ((temp & 1) == 0) { 
    266     printk("SMBUS: Error: Host SMBus controller not enabled - upgrade BIOS?\n");      
    267     error_return=-ENODEV; 
    268     goto END; 
    269   } 
    270 #endif /* FORCE_ALI15X3_ENABLE */ 
     263        if ((temp & 1) == 0) { 
     264                pci_write_config_byte(ALI15X3_dev, SMBHSTCFG, temp | 1); 
     265                printk 
     266                    ("i2c-ali15x3.o: WARNING: ALI15X3 SMBus interface has been FORCEFULLY " 
     267                     "ENABLED!!\n"); 
     268        } 
     269#else                           /* FORCE_ALI15X3_ENABLE */ 
     270        if ((temp & 1) == 0) { 
     271                printk 
     272                    ("SMBUS: Error: Host SMBus controller not enabled - upgrade BIOS?\n"); 
     273                error_return = -ENODEV; 
     274                goto END; 
     275        } 
     276#endif                          /* FORCE_ALI15X3_ENABLE */ 
    271277 
    272278/* set SMB clock to 74KHz as recommended in data sheet */ 
    273   pci_write_config_byte(ALI15X3_dev, SMBCLK, 0x20); 
    274  
    275   /* Everything is happy, let's grab the memory and set things up. */ 
    276   request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb");        
     279       pci_write_config_byte(ALI15X3_dev, SMBCLK, 0x20); 
     280 
     281       /* Everything is happy, let's grab the memory and set things up. */ 
     282        request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb"); 
    277283 
    278284#ifdef DEBUG 
     
    284290     printk("i2c-ali15x3.o: ALI15X3 using Interrupt 9 for SMBus.\n"); 
    285291*/ 
    286   pci_read_config_byte(ALI15X3_dev, SMBREV, &temp); 
    287   printk("i2c-ali15x3.o: SMBREV = 0x%X\n",temp); 
    288   printk("i2c-ali15x3.o: ALI15X3_smba = 0x%X\n",ali15x3_smba); 
    289 #endif /* DEBUG */ 
    290  
    291 END: 
    292   return error_return; 
     292       pci_read_config_byte(ALI15X3_dev, SMBREV, &temp); 
     293       printk("i2c-ali15x3.o: SMBREV = 0x%X\n", temp); 
     294       printk("i2c-ali15x3.o: ALI15X3_smba = 0x%X\n", ali15x3_smba); 
     295#endif                         /* DEBUG */ 
     296 
     297      END: 
     298       return error_return; 
    293299} 
    294300 
    295301 
    296302/* Internally used pause function */ 
    297 void ali15x3_do_pause( unsigned int amount
    298 { 
    299       current->state = TASK_INTERRUPTIBLE; 
    300       schedule_timeout(amount); 
     303void ali15x3_do_pause(unsigned int amount
     304{ 
     305       current->state = TASK_INTERRUPTIBLE; 
     306       schedule_timeout(amount); 
    301307} 
    302308 
    303309/* Another internally used function */ 
    304 int ali15x3_transaction(void)  
    305 
    306   int temp; 
    307   int result=0; 
    308   int timeout=0; 
    309  
    310 #ifdef DEBUG 
    311   printk("i2c-ali15x3.o: Transaction (pre): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " 
    312          "DAT1=%02x\n", 
    313          inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), 
    314          inb_p(SMBHSTDAT1)); 
     310int ali15x3_transaction(void) 
     311
     312        int temp; 
     313        int result = 0; 
     314        int timeout = 0; 
     315 
     316#ifdef DEBUG 
     317        printk 
     318            ("i2c-ali15x3.o: Transaction (pre): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " 
     319             "DAT1=%02x\n", inb_p(SMBHSTSTS), inb_p(SMBHSTCNT), 
     320             inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 
     321             inb_p(SMBHSTDAT1)); 
    315322#endif 
    316323 
    317   /* get status */ 
    318   temp = inb_p(SMBHSTSTS); 
    319  
    320   /* Make sure the SMBus host is ready to start transmitting */ 
    321   /* Check the busy bit first */ 
    322   if (temp & ALI15X3_STS_BUSY) { 
     324       /* get status */ 
     325       temp = inb_p(SMBHSTSTS); 
     326 
     327       /* Make sure the SMBus host is ready to start transmitting */ 
     328       /* Check the busy bit first */ 
     329       if (temp & ALI15X3_STS_BUSY) { 
    323330/* 
    324331   If the host controller is still busy, it may have timed out in the previous transaction, 
     
    342349    if (temp & ALI15X3_STS_BUSY) { 
    343350*/ 
    344    
     351 
    345352/* 
    346353   Try resetting entire SMB bus, including other devices - 
     
    349356   If that's the case you are stuck. 
    350357*/ 
    351        printk("i2c-ali15x3.o: Resetting entire SMB Bus to clear busy condition (%02x)\n",temp); 
    352        outb_p(ALI15X3_T_OUT, SMBHSTCNT); 
    353        temp = inb_p(SMBHSTSTS); 
    354      } 
     358                printk 
     359                    ("i2c-ali15x3.o: Resetting entire SMB Bus to clear busy condition (%02x)\n", 
     360                     temp); 
     361                outb_p(ALI15X3_T_OUT, SMBHSTCNT); 
     362                temp = inb_p(SMBHSTSTS); 
     363        } 
    355364/* 
    356365  } 
    357366*/ 
    358367 
    359   /* now check the error bits and the busy bit */ 
    360   if (temp & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) { 
    361     /* do a clear-on-write */ 
    362     outb_p(0xFF, SMBHSTSTS); 
    363     if ((temp = inb_p(SMBHSTSTS)) & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) { 
    364       /* this is probably going to be correctable only by a power reset 
    365          as one of the bits now appears to be stuck */ 
    366       /* This may be a bus or device with electrical problems. */ 
    367       printk("i2c-ali15x3.o: SMBus reset failed! (0x%02x) - controller or device on bus is probably hung\n",temp); 
    368       return -1; 
    369     } 
    370   } else { 
    371     /* check and clear done bit */ 
    372     if (temp & ALI15X3_STS_DONE) { 
    373       outb_p(temp, SMBHSTSTS); 
    374     } 
    375   } 
    376  
    377   /* start the transaction by writing anything to the start register */ 
    378   outb_p(0xFF, SMBHSTSTART);  
    379  
    380   /* We will always wait for a fraction of a second! */ 
    381   timeout = 0; 
    382   do { 
    383     ali15x3_do_pause(1); 
    384     temp=inb_p(SMBHSTSTS); 
    385   } while ((!(temp & (ALI15X3_STS_ERR | ALI15X3_STS_DONE))) && (timeout++ < MAX_TIMEOUT)); 
    386  
    387   /* If the SMBus is still busy, we give up */ 
    388   if (timeout >= MAX_TIMEOUT) { 
    389     result = -1; 
    390     printk("i2c-ali15x3.o: SMBus Timeout!\n");  
    391   } 
    392  
    393   if (temp & ALI15X3_STS_TERM) { 
    394     result = -1; 
    395 #ifdef DEBUG 
    396     printk("i2c-ali15x3.o: Error: Failed bus transaction\n"); 
     368        /* now check the error bits and the busy bit */ 
     369        if (temp & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) { 
     370                /* do a clear-on-write */ 
     371                outb_p(0xFF, SMBHSTSTS); 
     372                if ((temp = inb_p(SMBHSTSTS)) & 
     373                    (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) { 
     374                        /* this is probably going to be correctable only by a power reset 
     375                           as one of the bits now appears to be stuck */ 
     376                        /* This may be a bus or device with electrical problems. */ 
     377                        printk 
     378                            ("i2c-ali15x3.o: SMBus reset failed! (0x%02x) - controller or device on bus is probably hung\n", 
     379                             temp); 
     380                        return -1; 
     381                } 
     382        } else { 
     383                /* check and clear done bit */ 
     384                if (temp & ALI15X3_STS_DONE) { 
     385                        outb_p(temp, SMBHSTSTS); 
     386                } 
     387        } 
     388 
     389        /* start the transaction by writing anything to the start register */ 
     390        outb_p(0xFF, SMBHSTSTART); 
     391 
     392        /* We will always wait for a fraction of a second! */ 
     393        timeout = 0; 
     394        do { 
     395                ali15x3_do_pause(1); 
     396                temp = inb_p(SMBHSTSTS); 
     397        } while ((!(temp & (ALI15X3_STS_ERR | ALI15X3_STS_DONE))) 
     398                 && (timeout++ < MAX_TIMEOUT)); 
     399 
     400        /* If the SMBus is still busy, we give up */ 
     401        if (timeout >= MAX_TIMEOUT) { 
     402                result = -1; 
     403                printk("i2c-ali15x3.o: SMBus Timeout!\n"); 
     404        } 
     405 
     406        if (temp & ALI15X3_STS_TERM) { 
     407                result = -1; 
     408#ifdef DEBUG 
     409                printk("i2c-ali15x3.o: Error: Failed bus transaction\n"); 
    397410#endif 
    398  
     411       
    399412 
    400413/* 
     
    404417  This means that bus collisions go unreported. 
    405418*/ 
    406   if (temp & ALI15X3_STS_COLL) { 
    407     result = -1; 
    408 #ifdef DEBUG 
    409     printk("i2c-ali15x3.o: Error: no response or bus collision ADD=%02x\n", inb_p(SMBHSTADD)); 
     419        if (temp & ALI15X3_STS_COLL) { 
     420                result = -1; 
     421#ifdef DEBUG 
     422                printk 
     423                    ("i2c-ali15x3.o: Error: no response or bus collision ADD=%02x\n", 
     424                     inb_p(SMBHSTADD)); 
    410425#endif 
    411  
     426       
    412427 
    413428/* haven't ever seen this */ 
    414   if (temp & ALI15X3_STS_DEV) { 
    415     result = -1; 
    416     printk("i2c-ali15x3.o: Error: device error\n"); 
    417  
    418  
    419 #ifdef DEBUG 
    420   printk("i2c-ali15x3.o: Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, " 
    421          "DAT0=%02x, DAT1=%02x\n"
    422          inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), 
    423          inb_p(SMBHSTDAT1)); 
     429       if (temp & ALI15X3_STS_DEV) { 
     430               result = -1; 
     431               printk("i2c-ali15x3.o: Error: device error\n"); 
     432       
     433#ifdef DEBUG 
     434        printk 
     435           ("i2c-ali15x3.o: Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, " 
     436            "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTSTS), inb_p(SMBHSTCNT)
     437            inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 
     438            inb_p(SMBHSTDAT1)); 
    424439#endif 
    425   return result; 
     440       return result; 
    426441} 
    427442 
    428443/* Return -1 on error. See smbus.h for more information */ 
    429 s32 ali15x3_access(struct i2c_adapter *adap, u16 addr, unsigned short flags
    430                    char read_write, u8 command, int size,  
    431                   union i2c_smbus_data * data) 
    432 { 
    433   int i,len; 
    434   int temp; 
    435   int timeout; 
     444s32 ali15x3_access(struct i2c_adapter * adap, u16 addr
     445                   unsigned short flags, char read_write, u8 command, 
     446                  int size, union i2c_smbus_data * data) 
     447{ 
     448       int i, len; 
     449       int temp; 
     450       int timeout; 
    436451 
    437452/* clear all the bits (clear-on-write) */ 
    438   outb_p(0xFF, SMBHSTSTS);  
     453        outb_p(0xFF, SMBHSTSTS); 
    439454/* make sure SMBus is idle */ 
    440   temp = inb_p(SMBHSTSTS); 
    441   for(timeout = 0; (timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE); timeout++) 
    442   { 
    443     ali15x3_do_pause(1); 
    444     temp=inb_p(SMBHSTSTS); 
    445   } 
    446   if (timeout >= MAX_TIMEOUT) { 
    447     printk("i2c-ali15x3.o: Idle wait Timeout! STS=0x%02x\n", temp);  
    448   } 
    449  
    450   switch(size) { 
    451     case I2C_SMBUS_PROC_CALL: 
    452       printk("i2c-ali15x3.o: I2C_SMBUS_PROC_CALL not supported!\n"); 
    453       return -1; 
    454     case I2C_SMBUS_QUICK: 
    455       outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); 
    456       size = ALI15X3_QUICK; 
    457       break; 
    458     case I2C_SMBUS_BYTE: 
    459       outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); 
    460       if (read_write == I2C_SMBUS_WRITE) 
    461         outb_p(command, SMBHSTCMD); 
    462       size = ALI15X3_BYTE; 
    463       break; 
    464     case I2C_SMBUS_BYTE_DATA: 
    465       outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); 
    466       outb_p(command, SMBHSTCMD); 
    467       if (read_write == I2C_SMBUS_WRITE) 
    468         outb_p(data->byte,SMBHSTDAT0); 
    469       size = ALI15X3_BYTE_DATA; 
    470       break; 
    471     case I2C_SMBUS_WORD_DATA: 
    472       outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); 
    473       outb_p(command, SMBHSTCMD); 
    474       if (read_write == I2C_SMBUS_WRITE) { 
    475         outb_p(data->word & 0xff,SMBHSTDAT0); 
    476         outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1); 
    477       } 
    478       size = ALI15X3_WORD_DATA; 
    479       break; 
    480     case I2C_SMBUS_BLOCK_DATA: 
    481       outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); 
    482       outb_p(command, SMBHSTCMD); 
    483       if (read_write == I2C_SMBUS_WRITE) { 
    484         len = data->block[0]; 
    485         if (len < 0) { 
    486           len = 0; 
    487           data->block[0] = len; 
    488         }        
    489         if (len > 32) { 
    490           len = 32; 
    491           data->block[0] = len; 
    492         }        
    493         outb_p(len,SMBHSTDAT0); 
    494         outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */ 
    495         for (i = 1; i <= len; i++) 
    496           outb_p(data->block[i],SMBBLKDAT); 
    497       } 
    498       size = ALI15X3_BLOCK_DATA; 
    499       break; 
    500   } 
    501  
    502   outb_p(size, SMBHSTCNT);      /* output command */ 
    503  
    504   if (ali15x3_transaction()) /* Error in transaction */  
    505     return -1;  
    506    
    507   if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK)) 
    508     return 0; 
    509    
    510  
    511   switch(size) { 
    512     case ALI15X3_BYTE: /* Result put in SMBHSTDAT0 */ 
    513       data->byte = inb_p(SMBHSTDAT0); 
    514       break; 
    515     case ALI15X3_BYTE_DATA: 
    516       data->byte = inb_p(SMBHSTDAT0); 
    517       break; 
    518     case ALI15X3_WORD_DATA: 
    519       data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 
    520       break; 
    521     case ALI15X3_BLOCK_DATA: 
    522       len = inb_p(SMBHSTDAT0); 
    523       if(len > 32)       
    524         len = 32; 
    525       data->block[0] = len; 
    526       outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */ 
    527       for (i = 1; i <= data->block[0]; i++) { 
    528         data->block[i] = inb_p(SMBBLKDAT); 
    529 #ifdef DEBUG 
    530         printk("i2c-ali15x3.o: Blk: len=%d, i=%d, data=%02x\n", len, i, data->block[i]); 
    531 #endif DEBUG 
    532       } 
    533       break; 
    534   } 
    535   return 0; 
     455        temp = inb_p(SMBHSTSTS); 
     456        for (timeout = 0; 
     457             (timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE); 
     458             timeout++) { 
     459                ali15x3_do_pause(1); 
     460                temp = inb_p(SMBHSTSTS); 
     461        } 
     462        if (timeout >= MAX_TIMEOUT) { 
     463                printk("i2c-ali15x3.o: Idle wait Timeout! STS=0x%02x\n", 
     464                       temp); 
     465        } 
     466 
     467        switch (size) { 
     468        case I2C_SMBUS_PROC_CALL: 
     469                printk 
     470                    ("i2c-ali15x3.o: I2C_SMBUS_PROC_CALL not supported!\n"); 
     471                return -1; 
     472        case I2C_SMBUS_QUICK: 
     473                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
     474                       SMBHSTADD); 
     475                size = ALI15X3_QUICK; 
     476                break; 
     477        case I2C_SMBUS_BYTE: 
     478                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
     479                       SMBHSTADD); 
     480                if (read_write == I2C_SMBUS_WRITE) 
     481                        outb_p(command, SMBHSTCMD); 
     482                size = ALI15X3_BYTE; 
     483                break; 
     484        case I2C_SMBUS_BYTE_DATA: 
     485                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
     486                       SMBHSTADD); 
     487                outb_p(command, SMBHSTCMD); 
     488                if (read_write == I2C_SMBUS_WRITE) 
     489                        outb_p(data->byte, SMBHSTDAT0); 
     490                size = ALI15X3_BYTE_DATA; 
     491                break; 
     492        case I2C_SMBUS_WORD_DATA: 
     493                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
     494                       SMBHSTADD); 
     495                outb_p(command, SMBHSTCMD); 
     496                if (read_write == I2C_SMBUS_WRITE) { 
     497                        outb_p(data->word & 0xff, SMBHSTDAT0); 
     498                        outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); 
     499                } 
     500                size = ALI15X3_WORD_DATA; 
     501                break; 
     502        case I2C_SMBUS_BLOCK_DATA: 
     503                outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 
     504                       SMBHSTADD); 
     505                outb_p(command, SMBHSTCMD); 
     506                if (read_write == I2C_SMBUS_WRITE) { 
     507                        len = data->block[0]; 
     508                        if (len < 0) { 
     509                                len = 0; 
     510                                data->block[0] = len; 
     511                        } 
     512                        if (len > 32) { 
     513                                len = 32; 
     514                                data->block[0] = len; 
     515                        } 
     516                        outb_p(len, SMBHSTDAT0); 
     517                        outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT);        /* Reset SMBBLKDAT */ 
     518                        for (i = 1; i <= len; i++) 
     519                                outb_p(data->block[i], SMBBLKDAT); 
     520                } 
     521                size = ALI15X3_BLOCK_DATA; 
     522                break; 
     523        } 
     524 
     525        outb_p(size, SMBHSTCNT);        /* output command */ 
     526 
     527        if (ali15x3_transaction())      /* Error in transaction */ 
     528                return -1; 
     529 
     530        if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK)) 
     531                return 0; 
     532 
     533 
     534        switch (size) { 
     535        case ALI15X3_BYTE:      /* Result put in SMBHSTDAT0 */ 
     536                data->byte = inb_p(SMBHSTDAT0); 
     537                break; 
     538        case ALI15X3_BYTE_DATA: 
     539                data->byte = inb_p(SMBHSTDAT0); 
     540                break; 
     541        case ALI15X3_WORD_DATA: 
     542                data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 
     543                break; 
     544        case ALI15X3_BLOCK_DATA: 
     545                len = inb_p(SMBHSTDAT0); 
     546                if (len > 32) 
     547                        len = 32; 
     548                data->block[0] = len; 
     549                outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT);        /* Reset SMBBLKDAT */ 
     550                for (i = 1; i <= data->block[0]; i++) { 
     551                        data->block[i] = inb_p(SMBBLKDAT); 
     552#ifdef DEBUG 
     553                        printk 
     554                            ("i2c-ali15x3.o: Blk: len=%d, i=%d, data=%02x\n", 
     555                             len, i, data->block[i]); 
     556#endif  /* DEBUG */ 
     557                } 
     558                break; 
     559        } 
     560        return 0; 
    536561} 
    537562 
     
    550575{ 
    551576        return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 
    552                I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 
    553                I2C_FUNC_SMBUS_BLOCK_DATA; 
     577           I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 
     578           I2C_FUNC_SMBUS_BLOCK_DATA; 
    554579} 
    555580 
    556581int __init i2c_ali15x3_init(void) 
    557582{ 
    558   int res; 
    559   printk("ali15x3.o version %s (%s)\n",LM_VERSION,LM_DATE); 
     583       int res; 
     584       printk("ali15x3.o version %s (%s)\n", LM_VERSION, LM_DATE); 
    560585#ifdef DEBUG 
    561586/* PE- It might be good to make this a permanent part of the code! */ 
    562   if (ali15x3_initialized) { 
    563     printk("i2c-ali15x3.o: Oops, ali15x3_init called a second time!\n"); 
    564     return -EBUSY; 
    565   } 
     587        if (ali15x3_initialized) { 
     588                printk 
     589                    ("i2c-ali15x3.o: Oops, ali15x3_init called a second time!\n"); 
     590                return -EBUSY; 
     591        } 
    566592#endif 
    567   ali15x3_initialized = 0; 
    568   if ((res = ali15x3_setup())) { 
    569     printk("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n"); 
    570     ali15x3_cleanup(); 
    571     return res; 
    572   } 
    573   ali15x3_initialized ++; 
    574   sprintf(ali15x3_adapter.name,"SMBus ALI15X3 adapter at %04x",ali15x3_smba); 
    575   if ((res = i2c_add_adapter(&ali15x3_adapter))) { 
    576     printk("i2c-ali15x3.o: Adapter registration failed, module not inserted.\n"); 
    577     ali15x3_cleanup(); 
    578     return res; 
    579   } 
    580   ali15x3_initialized++; 
    581   printk("i2c-ali15x3.o: ALI15X3 SMBus Controller detected and initialized\n"); 
    582   return 0; 
     593        ali15x3_initialized = 0; 
     594        if ((res = ali15x3_setup())) { 
     595                printk 
     596                    ("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n"); 
     597                ali15x3_cleanup(); 
     598                return res; 
     599        } 
     600        ali15x3_initialized++; 
     601        sprintf(ali15x3_adapter.name, "SMBus ALI15X3 adapter at %04x", 
     602                ali15x3_smba); 
     603        if ((res = i2c_add_adapter(&ali15x3_adapter))) { 
     604                printk 
     605                    ("i2c-ali15x3.o: Adapter registration failed, module not inserted.\n"); 
     606                ali15x3_cleanup(); 
     607                return res; 
     608        } 
     609        ali15x3_initialized++; 
     610        printk 
     611            ("i2c-ali15x3.o: ALI15X3 SMBus Controller detected and initialized\n"); 
     612        return 0; 
    583613} 
    584614 
    585615int __init ali15x3_cleanup(void) 
    586616{ 
    587   int res; 
    588   if (ali15x3_initialized >= 2) 
    589 
    590     if ((res = i2c_del_adapter(&ali15x3_adapter))) { 
    591       printk("i2c-ali15x3.o: i2c_del_adapter failed, module not removed\n"); 
    592       return res; 
    593     } else 
    594       ali15x3_initialized--; 
    595  
    596   if (ali15x3_initialized >= 1) { 
    597     release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE); 
    598     ali15x3_initialized--; 
    599  
    600   return 0; 
     617       int res; 
     618        if (ali15x3_initialized >= 2) { 
     619               if ((res = i2c_del_adapter(&ali15x3_adapter)))
     620                        printk 
     621                           ("i2c-ali15x3.o: i2c_del_adapter failed, module not removed\n"); 
     622                       return res; 
     623               } else 
     624                       ali15x3_initialized--; 
     625       
     626       if (ali15x3_initialized >= 1) { 
     627               release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE); 
     628               ali15x3_initialized--; 
     629       
     630       return 0; 
    601631} 
    602632 
     
    605635#ifdef MODULE 
    606636 
    607 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker <mdsxyz123@yahoo.com>"); 
     637MODULE_AUTHOR 
     638    ("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker <mdsxyz123@yahoo.com>"); 
    608639MODULE_DESCRIPTION("ALI15X3 SMBus driver"); 
    609640 
    610641int init_module(void) 
    611642{ 
    612   return i2c_ali15x3_init(); 
     643       return i2c_ali15x3_init(); 
    613644} 
    614645 
    615646int cleanup_module(void) 
    616647{ 
    617   return ali15x3_cleanup(); 
    618 } 
    619  
    620 #endif /* MODULE */ 
     648       return ali15x3_cleanup(); 
     649} 
     650 
     651#endif                         /* MODULE */ 
  • lm-sensors/trunk/kernel/busses/i2c-amd756.c

    r705 r707  
    5555 
    5656/* address of I/O space */ 
    57 #define SMBBA     0x058 /* mh */ 
     57#define SMBBA     0x058                /* mh */ 
    5858 
    5959/* general configuration */ 
    60 #define SMBGCFG   0x041 /* mh */ 
     60#define SMBGCFG   0x041                /* mh */ 
    6161 
    6262/* silicon revision code */ 
     
    8181extern 
    8282#endif 
    83        int __init i2c_amd756_init(void); 
     83int __init i2c_amd756_init(void); 
    8484static int __init amd756_cleanup(void); 
    8585static int amd756_setup(void); 
    86 static s32 amd756_access(struct i2c_adapter *adap, u16 addr,  
    87                         unsigned short flags, char read_write, 
    88                         u8 command, int size, union i2c_smbus_data * data); 
    89 static void amd756_do_pause( unsigned int amount ); 
     86static s32 amd756_access(struct i2c_adapter *adap, u16 addr, 
     87                        unsigned short flags, char read_write, 
     88                        u8 command, int size, union i2c_smbus_data *data); 
     89static void amd756_do_pause(unsigned int amount); 
    9090static int amd756_transaction(void); 
    9191static void amd756_inc(struct i2c_adapter *adapter); 
     
    9696extern int init_module(void); 
    9797extern int cleanup_module(void); 
    98 #endif /* MODULE */ 
     98#endif                         /* MODULE */ 
    9999 
    100100static struct i2c_algorithm smbus_algorithm = { 
    101   /* name */           "Non-I2C SMBus adapter", 
    102   /* id */             I2C_ALGO_SMBUS, 
    103   /* master_xfer */    NULL, 
    104   /* smbus_access */    amd756_access, 
    105   /* slave_send */     NULL, 
    106   /* slave_rcv */      NULL, 
    107   /* algo_control */   NULL, 
    108   /* functionality */  amd756_func, 
     101       /* name */ "Non-I2C SMBus adapter", 
     102       /* id */ I2C_ALGO_SMBUS, 
     103       /* master_xfer */ NULL, 
     104       /* smbus_access */ amd756_access, 
     105       /* slave_send */ NULL, 
     106       /* slave_rcv */ NULL, 
     107       /* algo_control */ NULL, 
     108       /* functionality */ amd756_func, 
    109109}; 
    110110 
    111111static struct i2c_adapter amd756_adapter = { 
    112   "unset", 
    113   I2C_ALGO_SMBUS | I2C_HW_SMBUS_AMD756, 
    114   &smbus_algorithm, 
    115   NULL, 
    116   amd756_inc, 
    117   amd756_dec, 
    118   NULL, 
    119   NULL, 
     112       "unset", 
     113       I2C_ALGO_SMBUS | I2C_HW_SMBUS_AMD756, 
     114       &smbus_algorithm, 
     115       NULL, 
     116       amd756_inc, 
     117       amd756_dec, 
     118       NULL, 
     119       NULL, 
    120120}; 
    121121 
     
    132132int amd756_setup(void) 
    133133{ 
    134   int error_return=0; 
    135   unsigned char temp; 
    136  
    137   struct pci_dev *AMD756_dev; 
    138  
    139   /* First check whether we can access PCI at all */ 
    140   if (pci_present() == 0) { 
    141     printk("i2c-amd756.o: Error: No PCI-bus found!\n"); 
    142     error_return=-ENODEV; 
    143     goto END; 
    144   } 
    145  
    146   /* Look for the AMD756, function 3 */ 
    147   /* Note: we keep on searching until we have found 'function 3' */ 
    148   AMD756_dev = NULL; 
    149   do 
    150     AMD756_dev = pci_find_device(PCI_VENDOR_ID_AMD,  
    151                                 PCI_DEVICE_ID_AMD_756, AMD756_dev); 
    152   while (AMD756_dev && (PCI_FUNC(AMD756_dev->devfn) != 3)); 
    153   if(AMD756_dev == NULL) { 
    154     printk("i2c-amd756.o: Error: Can't detect AMD756, function 3!\n"); 
    155     error_return=-ENODEV; 
    156     goto END; 
    157   }  
     134        int error_return = 0; 
     135        unsigned char temp; 
     136 
     137        struct pci_dev *AMD756_dev; 
     138 
     139        /* First check whether we can access PCI at all */ 
     140        if (pci_present() == 0) { 
     141                printk("i2c-amd756.o: Error: No PCI-bus found!\n"); 
     142                error_return = -ENODEV; 
     143                goto END; 
     144        } 
     145 
     146        /* Look for the AMD756, function 3 */ 
     147        /* Note: we keep on searching until we have found 'function 3' */ 
     148        AMD756_dev = NULL; 
     149        do 
     150                AMD756_dev = pci_find_device(PCI_VENDOR_ID_AMD, 
     151                                             PCI_DEVICE_ID_AMD_756, 
     152                                             AMD756_dev); 
     153        while (AMD756_dev && (PCI_FUNC(AMD756_dev->devfn) != 3)); 
     154        if (AMD756_dev == NULL) { 
     155                printk 
     156                    ("i2c-amd756.o: Error: Can't detect AMD756, function 3!\n"); 
     157                error_return = -ENODEV; 
     158                goto END; 
     159        } 
    158160 
    159161/* Determine the address of the SMBus areas */ 
    160162 
    161   /* Technically it is a dword but... */ 
    162   pci_read_config_word(AMD756_dev, SMBBA, &amd756_smba); 
    163   amd756_smba &= 0xfff0; 
    164  
    165   if (check_region(amd756_smba, 8)) { 
    166     printk("i2c-amd756.o: AMD756_smb region 0x%x already in use!\n", amd756_smba); 
    167     error_return=-ENODEV; 
    168     goto END; 
    169   } 
    170  
    171   pci_read_config_byte(AMD756_dev, SMBGCFG, &temp); 
    172  
    173   if ((temp & 128) == 0) { 
    174     printk("SMBUS: Error: Host SMBus controller I/O not enabled!\n");      
    175     error_return=-ENODEV; 
    176     goto END; 
    177   } 
    178  
    179   /* Everything is happy, let's grab the memory and set things up. */ 
    180   request_region(amd756_smba, 8, "amd756-smbus");        
    181  
    182 #ifdef DEBUG 
    183   /* 
    184   if ((temp & 0x0E) == 8) 
    185      printk("i2c-amd756.o: AMD756 using Interrupt 9 for SMBus.\n"); 
    186   else if ((temp & 0x0E) == 0) 
    187      printk("i2c-amd756.o: AMD756 using Interrupt SMI# for SMBus.\n"); 
    188   else  
    189      printk("i2c-amd756.o: AMD756: Illegal Interrupt configuration (or code out " 
    190             "of date)!\n"); 
    191