diff options
| -rw-r--r-- | drivers/hwmon/ina2xx.c | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index 7f3f4a385729..602148299f68 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c | |||
| @@ -69,22 +69,6 @@ struct ina2xx_data { | |||
| 69 | u16 regs[INA2XX_MAX_REGISTERS]; | 69 | u16 regs[INA2XX_MAX_REGISTERS]; |
| 70 | }; | 70 | }; |
| 71 | 71 | ||
| 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 | |||
| 88 | static struct ina2xx_data *ina2xx_update_device(struct device *dev) | 72 | static struct ina2xx_data *ina2xx_update_device(struct device *dev) |
| 89 | { | 73 | { |
| 90 | struct i2c_client *client = to_i2c_client(dev); | 74 | struct i2c_client *client = to_i2c_client(dev); |
| @@ -102,7 +86,7 @@ static struct ina2xx_data *ina2xx_update_device(struct device *dev) | |||
| 102 | 86 | ||
| 103 | /* Read all registers */ | 87 | /* Read all registers */ |
| 104 | for (i = 0; i < data->registers; i++) { | 88 | 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); |
| 106 | if (rv < 0) { | 90 | if (rv < 0) { |
| 107 | ret = ERR_PTR(rv); | 91 | ret = ERR_PTR(rv); |
| 108 | goto abort; | 92 | goto abort; |
| @@ -279,22 +263,26 @@ static int ina2xx_probe(struct i2c_client *client, | |||
| 279 | switch (data->kind) { | 263 | switch (data->kind) { |
| 280 | case ina219: | 264 | case ina219: |
| 281 | /* device configuration */ | 265 | /* 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); | ||
| 283 | 268 | ||
| 284 | /* set current LSB to 1mA, shunt is in uOhms */ | 269 | /* set current LSB to 1mA, shunt is in uOhms */ |
| 285 | /* (equation 13 in datasheet) */ | 270 | /* (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); | ||
| 287 | dev_info(&client->dev, | 273 | dev_info(&client->dev, |
| 288 | "power monitor INA219 (Rshunt = %li uOhm)\n", shunt); | 274 | "power monitor INA219 (Rshunt = %li uOhm)\n", shunt); |
| 289 | data->registers = INA219_REGISTERS; | 275 | data->registers = INA219_REGISTERS; |
| 290 | break; | 276 | break; |
| 291 | case ina226: | 277 | case ina226: |
| 292 | /* device configuration */ | 278 | /* 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); | ||
| 294 | 281 | ||
| 295 | /* set current LSB to 1mA, shunt is in uOhms */ | 282 | /* set current LSB to 1mA, shunt is in uOhms */ |
| 296 | /* (equation 1 in datasheet)*/ | 283 | /* (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); | ||
| 298 | dev_info(&client->dev, | 286 | dev_info(&client->dev, |
| 299 | "power monitor INA226 (Rshunt = %li uOhm)\n", shunt); | 287 | "power monitor INA226 (Rshunt = %li uOhm)\n", shunt); |
| 300 | data->registers = INA226_REGISTERS; | 288 | data->registers = INA226_REGISTERS; |
