hwmon: Use i2c_smbus_{read,write}_word_swapped
Make use of the new i2c_smbus_{read,write}_word_swapped functions. This makes the driver code more compact and readable. It also ensures proper error handling. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Jonathan Cameron <jic23@cam.ac.uk> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com> Cc: Dirk Eibach <eibach@gdsys.de> Cc: "Mark M. Hoffman" <mhoffman@lightlink.com> Cc: Guillaume Ligneul <guillaume.ligneul@gmail.com>
这个提交包含在:
@@ -34,7 +34,7 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c,
|
||||
#define LM73_REG_CTRL 0x04
|
||||
#define LM73_REG_ID 0x07
|
||||
|
||||
#define LM73_ID 0x9001 /* or 0x190 after a swab16() */
|
||||
#define LM73_ID 0x9001 /* 0x0190, byte-swapped */
|
||||
#define DRVNAME "lm73"
|
||||
#define LM73_TEMP_MIN (-40)
|
||||
#define LM73_TEMP_MAX 150
|
||||
@@ -57,7 +57,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
|
||||
/* Write value */
|
||||
value = (short) SENSORS_LIMIT(temp/250, (LM73_TEMP_MIN*4),
|
||||
(LM73_TEMP_MAX*4)) << 5;
|
||||
i2c_smbus_write_word_data(client, attr->index, swab16(value));
|
||||
i2c_smbus_write_word_swapped(client, attr->index, value);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da,
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
/* use integer division instead of equivalent right shift to
|
||||
guarantee arithmetic shift and preserve the sign */
|
||||
int temp = ((s16) (swab16(i2c_smbus_read_word_data(client,
|
||||
attr->index)))*250) / 32;
|
||||
int temp = ((s16) (i2c_smbus_read_word_swapped(client,
|
||||
attr->index))*250) / 32;
|
||||
return sprintf(buf, "%d\n", temp);
|
||||
}
|
||||
|
||||
|
在新工单中引用
屏蔽一个用户