Changeset 64

Show
Ignore:
Timestamp:
12/10/98 17:20:03 (10 years ago)
Author:
frodo
Message:

Fixed a byte swapping bug in both the LM75 and the GL518SM drivers.

Strangly enough, both these devices use a high byte, low byte order for
word-sized reads and writes. The SMBus documentation specifies the
reverse (low, high) order, though. If all devices use the high,low order,
we should change this in smbus.c.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/trunk/TODO

    r55 r64  
    22 
    33* Check whether the FAN count divisors in the lm78 module are correct 
    4   (probably not!) 
     4  (probably not!); correct gl518sm changed-fan_div_but_did_not_update_fans 
    55* Wouldn't it be better to display all natural voltages for the LM78 chip, 
    66  and do *all* conversions through a user program? 
  • lm-sensors/trunk/kernel/chips/gl518sm.c

    r63 r64  
    133133static void gl518_inc_use (struct i2c_client *client); 
    134134static void gl518_dec_use (struct i2c_client *client); 
     135static u16 swap_bytes(u16 val); 
    135136static int gl518_read_value(struct i2c_client *client, u8 reg); 
    136137static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); 
     
    363364} 
    364365 
    365 /* Registers 0x07 to 0x0c are word-sized, others are byte-sized */ 
     366u16 swap_bytes(u16 val) 
     367
     368  return (val >> 8) | (val << 8); 
     369
     370 
     371/* Registers 0x07 to 0x0c are word-sized, others are byte-sized  
     372   GL518 uses a high-byte first convention, which is exactly opposite to 
     373   the usual practice. */ 
    366374int gl518_read_value(struct i2c_client *client, u8 reg) 
    367375{ 
    368376  if ((reg >= 0x07) && (reg <= 0x0c))  
    369     return smbus_read_word_data(client->adapter,client->addr,reg); 
     377    return swap_bytes(smbus_read_word_data(client->adapter,client->addr,reg)); 
    370378  else 
    371379    return smbus_read_byte_data(client->adapter,client->addr,reg); 
    372380} 
    373381 
     382/* Registers 0x07 to 0x0c are word-sized, others are byte-sized  
     383   GL518 uses a high-byte first convention, which is exactly opposite to 
     384   the usual practice. */ 
    374385int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) 
    375386{ 
    376387  if ((reg >= 0x07) && (reg <= 0x0c))  
    377     return smbus_write_word_data(client->adapter,client->addr,reg,value); 
     388    return smbus_write_word_data(client->adapter,client->addr,reg, 
     389                                 swap_bytes(value)); 
    378390  else 
    379391    return smbus_write_byte_data(client->adapter,client->addr,reg,value); 
  • lm-sensors/trunk/kernel/chips/lm75.c

    r53 r64  
    243243 
    244244/* All registers are word-sized, except for the configuration register. 
    245    For some reason, we must swap the low and high byte, but only on  
    246    reading words?!? */ 
     245   LM75 uses a high-byte first convention, which is exactly opposite to 
     246   the usual practice. */ 
    247247int lm75_read_value(struct i2c_client *client, u8 reg) 
    248248{ 
     
    253253} 
    254254 
    255 /* No swapping needed here! */ 
     255/* All registers are word-sized, except for the configuration register. 
     256   LM75 uses a high-byte first convention, which is exactly opposite to 
     257   the usual practice. */ 
    256258int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) 
    257259{ 
     
    259261    return smbus_write_byte_data(client->adapter,client->addr,reg,value); 
    260262  else 
    261     return smbus_write_word_data(client->adapter,client->addr,reg,value); 
     263    return smbus_write_word_data(client->adapter,client->addr,reg, 
     264           swap_bytes(value)); 
    262265} 
    263266 
  • lm-sensors/trunk/src/gl518sm.c

    r63 r64  
    133133static void gl518_inc_use (struct i2c_client *client); 
    134134static void gl518_dec_use (struct i2c_client *client); 
     135static u16 swap_bytes(u16 val); 
    135136static int gl518_read_value(struct i2c_client *client, u8 reg); 
    136137static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); 
     
    363364} 
    364365 
    365 /* Registers 0x07 to 0x0c are word-sized, others are byte-sized */ 
     366u16 swap_bytes(u16 val) 
     367
     368  return (val >> 8) | (val << 8); 
     369
     370 
     371/* Registers 0x07 to 0x0c are word-sized, others are byte-sized  
     372   GL518 uses a high-byte first convention, which is exactly opposite to 
     373   the usual practice. */ 
    366374int gl518_read_value(struct i2c_client *client, u8 reg) 
    367375{ 
    368376  if ((reg >= 0x07) && (reg <= 0x0c))  
    369     return smbus_read_word_data(client->adapter,client->addr,reg); 
     377    return swap_bytes(smbus_read_word_data(client->adapter,client->addr,reg)); 
    370378  else 
    371379    return smbus_read_byte_data(client->adapter,client->addr,reg); 
    372380} 
    373381 
     382/* Registers 0x07 to 0x0c are word-sized, others are byte-sized  
     383   GL518 uses a high-byte first convention, which is exactly opposite to 
     384   the usual practice. */ 
    374385int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) 
    375386{ 
    376387  if ((reg >= 0x07) && (reg <= 0x0c))  
    377     return smbus_write_word_data(client->adapter,client->addr,reg,value); 
     388    return smbus_write_word_data(client->adapter,client->addr,reg, 
     389                                 swap_bytes(value)); 
    378390  else 
    379391    return smbus_write_byte_data(client->adapter,client->addr,reg,value); 
  • lm-sensors/trunk/src/lm75.c

    r53 r64  
    243243 
    244244/* All registers are word-sized, except for the configuration register. 
    245    For some reason, we must swap the low and high byte, but only on  
    246    reading words?!? */ 
     245   LM75 uses a high-byte first convention, which is exactly opposite to 
     246   the usual practice. */ 
    247247int lm75_read_value(struct i2c_client *client, u8 reg) 
    248248{ 
     
    253253} 
    254254 
    255 /* No swapping needed here! */ 
     255/* All registers are word-sized, except for the configuration register. 
     256   LM75 uses a high-byte first convention, which is exactly opposite to 
     257   the usual practice. */ 
    256258int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) 
    257259{ 
     
    259261    return smbus_write_byte_data(client->adapter,client->addr,reg,value); 
    260262  else 
    261     return smbus_write_word_data(client->adapter,client->addr,reg,value); 
     263    return smbus_write_word_data(client->adapter,client->addr,reg, 
     264           swap_bytes(value)); 
    262265} 
    263266