History

hwmon: (ina2xx) Fix word size register read and write operations

The driver uses be16_to_cpu and cpu_to_be16 to convert data in SMBus word operations from chip to host byte order. However, the data passed from and to the SMBus word API functions is in host byte order, not in chip byte order. Conversion should therefore use swab16 instead of be16 to change the byte order. Replace driver internal word conversion functions with SMBus API functions to solve the problem.

Guenter Roeck committed 14 years ago

Commit 080b98e1 parent 73d7c111 file · +9 −21Browse files

Unified · Split

drivers/hwmon/ina2xx.c+9−21
@@ -69,22 +69,6 @@ struct ina2xx_data { · 68 unmodified lines
6969 u16 regs[INA2XX_MAX_REGISTERS];
7070 };
7171
72−int ina2xx_read_word(struct i2c_client *client, int reg)
73−{
74− int val = i2c_smbus_read_word_data(client, reg);
75− if (unlikely(val < 0)) {
76− dev_dbg(&client->dev,
77− "Failed to read register: %d\n", reg);
78− return val;
79− }
80− return be16_to_cpu(val);
81−}
82−
83−void ina2xx_write_word(struct i2c_client *client, int reg, int data)
84−{
85− i2c_smbus_write_word_data(client, reg, cpu_to_be16(data));
86−}
87−
8872 static struct ina2xx_data *ina2xx_update_device(struct device *dev)
8973 {
9074 struct i2c_client *client = to_i2c_client(dev);
@@ -102,7 +86,7 @@ static struct ina2xx_data *ina2xx_update_device(struct device *dev) · 11 unmodified lines
10286
10387 /* Read all registers */
10488 for (i = 0; i < data->registers; i++) {
105− int rv = ina2xx_read_word(client, i);
89+ int rv = i2c_smbus_read_word_swapped(client, i);
10690 if (rv < 0) {
10791 ret = ERR_PTR(rv);
10892 goto abort;
@@ -279,22 +263,26 @@ static int ina2xx_probe(struct i2c_client *client, · 170 unmodified lines
279263 switch (data->kind) {
280264 case ina219:
281265 /* device configuration */
282− ina2xx_write_word(client, INA2XX_CONFIG, INA219_CONFIG_DEFAULT);
266+ i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
267+ INA219_CONFIG_DEFAULT);
283268
284269 /* set current LSB to 1mA, shunt is in uOhms */
285270 /* (equation 13 in datasheet) */
286− ina2xx_write_word(client, INA2XX_CALIBRATION, 40960000 / shunt);
271+ i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
272+ 40960000 / shunt);
287273 dev_info(&client->dev,
288274 "power monitor INA219 (Rshunt = %li uOhm)\n", shunt);
289275 data->registers = INA219_REGISTERS;
290276 break;
291277 case ina226:
292278 /* device configuration */
293− ina2xx_write_word(client, INA2XX_CONFIG, INA226_CONFIG_DEFAULT);
279+ i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
280+ INA226_CONFIG_DEFAULT);
294281
295282 /* set current LSB to 1mA, shunt is in uOhms */
296283 /* (equation 1 in datasheet)*/
297− ina2xx_write_word(client, INA2XX_CALIBRATION, 5120000 / shunt);
284+ i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
285+ 5120000 / shunt);
298286 dev_info(&client->dev,
299287 "power monitor INA226 (Rshunt = %li uOhm)\n", shunt);
300288 data->registers = INA226_REGISTERS;