Pull hwmon fixes from Guenter Roeck: "Fix word size register read and write operations in ina2xx driver, and initialize uninitialized structure elements in twl4030-madc-hwmon driver." * tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (ina2xx) Fix word size register read and write operations hwmon: (twl4030-madc-hwmon) Initialize uninitialized structure elements
Unified · Split
| @@ -69,22 +69,6 @@ struct ina2xx_data { · 68 unmodified lines | ||
| 69 | 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 | 72 | static struct ina2xx_data *ina2xx_update_device(struct device *dev) |
| 89 | 73 | { |
| 90 | 74 | 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 | ||
| 102 | 86 | |
| 103 | 87 | /* Read all registers */ |
| 104 | 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 | 90 | if (rv < 0) { |
| 107 | 91 | ret = ERR_PTR(rv); |
| 108 | 92 | goto abort; |
| @@ -279,22 +263,26 @@ static int ina2xx_probe(struct i2c_client *client, · 170 unmodified lines | ||
| 279 | 263 | switch (data->kind) { |
| 280 | 264 | case ina219: |
| 281 | 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 | 269 | /* set current LSB to 1mA, shunt is in uOhms */ |
| 285 | 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 | 273 | dev_info(&client->dev, |
| 288 | 274 | "power monitor INA219 (Rshunt = %li uOhm)\n", shunt); |
| 289 | 275 | data->registers = INA219_REGISTERS; |
| 290 | 276 | break; |
| 291 | 277 | case ina226: |
| 292 | 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 | 282 | /* set current LSB to 1mA, shunt is in uOhms */ |
| 296 | 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 | 286 | dev_info(&client->dev, |
| 299 | 287 | "power monitor INA226 (Rshunt = %li uOhm)\n", shunt); |
| 300 | 288 | data->registers = INA226_REGISTERS; |
| @@ -44,12 +44,13 @@ static ssize_t madc_read(struct device *dev, · 43 unmodified lines | ||
| 44 | 44 | struct device_attribute *devattr, char *buf) |
| 45 | 45 | { |
| 46 | 46 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); |
| 47 | − struct twl4030_madc_request req; | |
| 47 | + struct twl4030_madc_request req = { | |
| 48 | + .channels = 1 << attr->index, | |
| 49 | + .method = TWL4030_MADC_SW2, | |
| 50 | + .type = TWL4030_MADC_WAIT, | |
| 51 | + }; | |
| 48 | 52 | long val; |
| 49 | 53 | |
| 50 | − req.channels = (1 << attr->index); | |
| 51 | − req.method = TWL4030_MADC_SW2; | |
| 52 | − req.func_cb = NULL; | |
| 53 | 54 | val = twl4030_madc_conversion(&req); |
| 54 | 55 | if (val < 0) |
| 55 | 56 | return val; |