Changeset 40

Show
Ignore:
Timestamp:
12/06/98 16:21:29 (14 years ago)
Author:
frodo
Message:

LM75 data correctly readable now!

* Changed test in lm75 setup code to 'read/write returns < 0' instead of

(old) 'read/write returns 0xff'. Nowadays, we can see the difference
between an error and a 0xff result, after all.

* Introduced constants used by PIIX4 for transaction types. These are

*not* the same as those in smbus.h.

* Some small code optimalizations in piix4.o.

Location:
lm-sensors/trunk
Files:
4 modified

Legend:

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

    r39 r40  
    6262#define MAX_TIMEOUT 500 
    6363#define  ENABLE_INT9 0 
     64 
     65/* PIIX4 constants */ 
     66#define PIIX4_QUICK      0x00 
     67#define PIIX4_BYTE       0x04 
     68#define PIIX4_BYTE_DATA  0x08 
     69#define PIIX4_WORD_DATA  0x0C 
     70#define PIIX4_BLOCK_DATA 0x14 
     71 
    6472 
    6573static int piix4_init(void); 
     
    205213  int timeout=0; 
    206214 
     215#ifdef DEBUG 
     216  printk("piix4.o: Transaction: CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " 
     217         "DAT1=%02x\n", 
     218         inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), 
     219         inb_p(SMBHSTDAT1)); 
     220#endif 
     221 
    207222  /* Make sure the SMBus host is ready to start transmitting */ 
    208223  if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 
    209224#ifdef DEBUG 
    210     printk("piix4.o: SMBus busy (%02x). Resetting... ",temp); 
     225    printk("piix4.o: SMBus busy (%02x). Resetting... \n",temp); 
    211226#endif 
    212227    outb_p(temp, SMBHSTSTS); 
     
    226241  outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);  
    227242 
    228   /* Wait for a fraction of a second! (See PIIX4 docs errata) */ 
    229   piix4_do_pause(1); 
    230  
    231   /* Poll Host_busy bit */ 
    232   temp=inb_p(SMBHSTSTS) & 0x01; 
    233   while (temp & (timeout++ < MAX_TIMEOUT)) { 
    234     /* Wait for a while and try again*/ 
     243  /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ 
     244  do { 
    235245    piix4_do_pause(1); 
    236     temp = inb_p(SMBHSTSTS) & 0x01; 
    237   } 
     246    temp=inb_p(SMBHSTSTS); 
     247  } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); 
    238248 
    239249  /* If the SMBus is still busy, we give up */ 
     
    245255  } 
    246256 
    247   temp = inb_p(SMBHSTSTS); 
    248  
    249   if (temp  & 0x10) { 
     257  if (temp & 0x10) { 
    250258    result = -1; 
    251259#ifdef DEBUG 
     
    285293  int i,len; 
    286294 
    287   outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 
    288  
    289295  switch(size) { 
     296    case SMBUS_PROC_CALL: 
     297      printk("piix4.o: SMBUS_PROC_CALL not supported!\n"); 
     298      return -1; 
    290299    case SMBUS_QUICK: 
    291300      outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); 
     301      size = PIIX4_QUICK; 
    292302      break; 
    293303    case SMBUS_BYTE: 
     
    295305      if (read_write == SMBUS_WRITE) 
    296306        outb_p(command, SMBHSTCMD); 
     307      size = PIIX4_BYTE; 
    297308      break; 
    298309    case SMBUS_BYTE_DATA: 
     
    301312      if (read_write == SMBUS_WRITE) 
    302313        outb_p(data->byte,SMBHSTDAT0); 
     314      size = PIIX4_BYTE_DATA; 
    303315      break; 
    304316    case SMBUS_WORD_DATA: 
     
    309321        outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1); 
    310322      } 
     323      size = PIIX4_WORD_DATA; 
    311324      break; 
    312325    case SMBUS_BLOCK_DATA: 
     
    323336        for (i = 1; i <= len; i ++) 
    324337          outb_p(data->block[i],SMBBLKDAT); 
    325         break; 
    326338      } 
    327   } 
     339      size = PIIX4_BLOCK_DATA; 
     340      break; 
     341  } 
     342 
     343  outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 
    328344 
    329345  if (piix4_transaction()) /* Error in transaction */  
    330346    return -1;  
    331347   
    332  
    333   if ((read_write == SMBUS_WRITE) || (size == SMBUS_QUICK)) 
     348  if ((read_write == SMBUS_WRITE) || (size == PIIX4_QUICK)) 
    334349    return 0; 
    335350   
    336351 
    337352  switch(size) { 
    338     case SMBUS_BYTE: /* Where is the result put? I assume here it is in 
     353    case PIIX4_BYTE: /* Where is the result put? I assume here it is in 
    339354                        SMBHSTDAT0 but it might just as well be in the 
    340355                        SMBHSTCMD. No clue in the docs */ 
     
    342357      data->byte = inb_p(SMBHSTDAT0); 
    343358      break; 
    344     case SMBUS_BYTE_DATA: 
     359    case PIIX4_BYTE_DATA: 
    345360      data->byte = inb_p(SMBHSTDAT0); 
    346361      break; 
    347     case SMBUS_WORD_DATA: 
     362    case PIIX4_WORD_DATA: 
    348363      data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 
    349364      break; 
    350     case SMBUS_BLOCK_DATA: 
     365    case PIIX4_BLOCK_DATA: 
    351366      data->block[0] = inb_p(SMBHSTDAT0); 
    352367      i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 
  • lm-sensors/trunk/kernel/chips/lm75.c

    r39 r40  
    123123       adapter, and check whether they are used here */ 
    124124     
    125     if (smbus_read_byte_data(adapter,address,LM75_REG_CONF) == 0xff) 
     125    if (smbus_read_byte_data(adapter,address,LM75_REG_CONF) < 0) 
    126126      continue; 
    127127 
     
    168168      goto ERROR3; 
    169169    data->sysctl_id = err; 
     170    err = 0; 
    170171 
    171172    /* Initialize the LM75 chip */ 
  • lm-sensors/trunk/src/lm75.c

    r39 r40  
    123123       adapter, and check whether they are used here */ 
    124124     
    125     if (smbus_read_byte_data(adapter,address,LM75_REG_CONF) == 0xff) 
     125    if (smbus_read_byte_data(adapter,address,LM75_REG_CONF) < 0) 
    126126      continue; 
    127127 
     
    168168      goto ERROR3; 
    169169    data->sysctl_id = err; 
     170    err = 0; 
    170171 
    171172    /* Initialize the LM75 chip */ 
  • lm-sensors/trunk/src/piix4.c

    r39 r40  
    6262#define MAX_TIMEOUT 500 
    6363#define  ENABLE_INT9 0 
     64 
     65/* PIIX4 constants */ 
     66#define PIIX4_QUICK      0x00 
     67#define PIIX4_BYTE       0x04 
     68#define PIIX4_BYTE_DATA  0x08 
     69#define PIIX4_WORD_DATA  0x0C 
     70#define PIIX4_BLOCK_DATA 0x14 
     71 
    6472 
    6573static int piix4_init(void); 
     
    205213  int timeout=0; 
    206214 
     215#ifdef DEBUG 
     216  printk("piix4.o: Transaction: CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " 
     217         "DAT1=%02x\n", 
     218         inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), 
     219         inb_p(SMBHSTDAT1)); 
     220#endif 
     221 
    207222  /* Make sure the SMBus host is ready to start transmitting */ 
    208223  if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 
    209224#ifdef DEBUG 
    210     printk("piix4.o: SMBus busy (%02x). Resetting... ",temp); 
     225    printk("piix4.o: SMBus busy (%02x). Resetting... \n",temp); 
    211226#endif 
    212227    outb_p(temp, SMBHSTSTS); 
     
    226241  outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);  
    227242 
    228   /* Wait for a fraction of a second! (See PIIX4 docs errata) */ 
    229   piix4_do_pause(1); 
    230  
    231   /* Poll Host_busy bit */ 
    232   temp=inb_p(SMBHSTSTS) & 0x01; 
    233   while (temp & (timeout++ < MAX_TIMEOUT)) { 
    234     /* Wait for a while and try again*/ 
     243  /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ 
     244  do { 
    235245    piix4_do_pause(1); 
    236     temp = inb_p(SMBHSTSTS) & 0x01; 
    237   } 
     246    temp=inb_p(SMBHSTSTS); 
     247  } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); 
    238248 
    239249  /* If the SMBus is still busy, we give up */ 
     
    245255  } 
    246256 
    247   temp = inb_p(SMBHSTSTS); 
    248  
    249   if (temp  & 0x10) { 
     257  if (temp & 0x10) { 
    250258    result = -1; 
    251259#ifdef DEBUG 
     
    285293  int i,len; 
    286294 
    287   outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 
    288  
    289295  switch(size) { 
     296    case SMBUS_PROC_CALL: 
     297      printk("piix4.o: SMBUS_PROC_CALL not supported!\n"); 
     298      return -1; 
    290299    case SMBUS_QUICK: 
    291300      outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); 
     301      size = PIIX4_QUICK; 
    292302      break; 
    293303    case SMBUS_BYTE: 
     
    295305      if (read_write == SMBUS_WRITE) 
    296306        outb_p(command, SMBHSTCMD); 
     307      size = PIIX4_BYTE; 
    297308      break; 
    298309    case SMBUS_BYTE_DATA: 
     
    301312      if (read_write == SMBUS_WRITE) 
    302313        outb_p(data->byte,SMBHSTDAT0); 
     314      size = PIIX4_BYTE_DATA; 
    303315      break; 
    304316    case SMBUS_WORD_DATA: 
     
    309321        outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1); 
    310322      } 
     323      size = PIIX4_WORD_DATA; 
    311324      break; 
    312325    case SMBUS_BLOCK_DATA: 
     
    323336        for (i = 1; i <= len; i ++) 
    324337          outb_p(data->block[i],SMBBLKDAT); 
    325         break; 
    326338      } 
    327   } 
     339      size = PIIX4_BLOCK_DATA; 
     340      break; 
     341  } 
     342 
     343  outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 
    328344 
    329345  if (piix4_transaction()) /* Error in transaction */  
    330346    return -1;  
    331347   
    332  
    333   if ((read_write == SMBUS_WRITE) || (size == SMBUS_QUICK)) 
     348  if ((read_write == SMBUS_WRITE) || (size == PIIX4_QUICK)) 
    334349    return 0; 
    335350   
    336351 
    337352  switch(size) { 
    338     case SMBUS_BYTE: /* Where is the result put? I assume here it is in 
     353    case PIIX4_BYTE: /* Where is the result put? I assume here it is in 
    339354                        SMBHSTDAT0 but it might just as well be in the 
    340355                        SMBHSTCMD. No clue in the docs */ 
     
    342357      data->byte = inb_p(SMBHSTDAT0); 
    343358      break; 
    344     case SMBUS_BYTE_DATA: 
     359    case PIIX4_BYTE_DATA: 
    345360      data->byte = inb_p(SMBHSTDAT0); 
    346361      break; 
    347     case SMBUS_WORD_DATA: 
     362    case PIIX4_WORD_DATA: 
    348363      data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 
    349364      break; 
    350     case SMBUS_BLOCK_DATA: 
     365    case PIIX4_BLOCK_DATA: 
    351366      data->block[0] = inb_p(SMBHSTDAT0); 
    352367      i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */