History

Merge tag 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging

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

Linus Torvalds committed 14 years ago

Commit 1c23ce72 parents dd383af 080b98e2 files · +14 −25Browse files

Unified · Split

2 files
  1. drivers/hwmon/ina2xx.c +9 −21
  2. drivers/hwmon/twl4030-madc-hwmon.c +5 −4
drivers/hwmon/ina2xx.c+9−21
@@ -69,22 +69,6 @@ struct ina2xx_data { · 68 unmodified lines
69 u16 regs[INA2XX_MAX_REGISTERS];69 u16 regs[INA2XX_MAX_REGISTERS];
70};70};
71 71
72int 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
83void 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
88static struct ina2xx_data *ina2xx_update_device(struct device *dev)72static 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) · 11 unmodified lines
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, · 170 unmodified lines
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;
drivers/hwmon/twl4030-madc-hwmon.c+5−4
@@ -44,12 +44,13 @@ static ssize_t madc_read(struct device *dev, · 43 unmodified lines
44 struct device_attribute *devattr, char *buf)44 struct device_attribute *devattr, char *buf)
45{45{
46 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);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 long val;52 long val;
49 53
50 req.channels = (1 << attr->index);
51 req.method = TWL4030_MADC_SW2;
52 req.func_cb = NULL;
53 val = twl4030_madc_conversion(&req);54 val = twl4030_madc_conversion(&req);
54 if (val < 0)55 if (val < 0)
55 return val;56 return val;