Fix word size register read and write operations in ina2xx driver, and
initialize uninitialized structure elements in twl4030-madc-hwmon driver. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAABAgAGBQJQUqtMAAoJEMsfJm/On5mBMQsP/jH4HzFWMVHg14M5PSrGy9me P77+ldlO09SnvmA2qdMZSNfBXrh5bjq6VoPNR5vdX9PB2jdJ0HOdKvyUG9D2eXQD jGJAYGk24HrjrGi6FeVD7pP7NGwQRyyVRM1Vmm+n/M781SD66gJPCMO+qC6391ma oytVuejT6TVajZtXfWZuKp1GQ2x3lb21hfhrDbnSB3AibYilXSqktx4AjmG+IDRb SsNPI+WLu4mNJQMTYFVrrRs2b6PLYDw1ODuIQIoB3lyKEJVOE6mUw2EQXEnzaybb F03Ujktgn81/7kvPQK1Qovq97TuwrY0mxDRwg/5brUZo9nNxeMqTMt9IXesDCokf euzVUWM+kZ7FLIokl5GwuZt309tVxQozr0aE6JKOi+CPkcT4VskBfC8DfNJ2wqnR tUTzFiCa/wo2cr3/iqf6o5sR7eRJBN5lF9RLW14K+2MvotwEDOZ3R/9EtEEL1MSP bdGQ1p4swYQxu8O8FFLVVWbPUl4/c0l/dW0yiEpQl/hdHpP2G/DV3pSBLMyrOzGu elpm2lFzC+aKG7lm08IpxHzBKXOZZ7Lp3s9FN3koOcAWD/hGlS6jNOPCFpMdlVg0 uFeMO/lgveuvcTD5llBa9d+yWzCNYPHuqx1kBbiNyZ3sisdwCmuldgISuKPcp7wb BQ5Xc6sv7Jg3tDbP12d+ =gYp1 -----END PGP SIGNATURE----- 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
This commit is contained in:
commit
1c23ce720d
@ -69,22 +69,6 @@ struct ina2xx_data {
|
|||||||
u16 regs[INA2XX_MAX_REGISTERS];
|
u16 regs[INA2XX_MAX_REGISTERS];
|
||||||
};
|
};
|
||||||
|
|
||||||
int ina2xx_read_word(struct i2c_client *client, int reg)
|
|
||||||
{
|
|
||||||
int val = i2c_smbus_read_word_data(client, reg);
|
|
||||||
if (unlikely(val < 0)) {
|
|
||||||
dev_dbg(&client->dev,
|
|
||||||
"Failed to read register: %d\n", reg);
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
return be16_to_cpu(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ina2xx_write_word(struct i2c_client *client, int reg, int data)
|
|
||||||
{
|
|
||||||
i2c_smbus_write_word_data(client, reg, cpu_to_be16(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct ina2xx_data *ina2xx_update_device(struct device *dev)
|
static struct ina2xx_data *ina2xx_update_device(struct device *dev)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = to_i2c_client(dev);
|
struct i2c_client *client = to_i2c_client(dev);
|
||||||
@ -102,7 +86,7 @@ static struct ina2xx_data *ina2xx_update_device(struct device *dev)
|
|||||||
|
|
||||||
/* Read all registers */
|
/* Read all registers */
|
||||||
for (i = 0; i < data->registers; i++) {
|
for (i = 0; i < data->registers; i++) {
|
||||||
int rv = ina2xx_read_word(client, i);
|
int rv = i2c_smbus_read_word_swapped(client, i);
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
ret = ERR_PTR(rv);
|
ret = ERR_PTR(rv);
|
||||||
goto abort;
|
goto abort;
|
||||||
@ -279,22 +263,26 @@ static int ina2xx_probe(struct i2c_client *client,
|
|||||||
switch (data->kind) {
|
switch (data->kind) {
|
||||||
case ina219:
|
case ina219:
|
||||||
/* device configuration */
|
/* device configuration */
|
||||||
ina2xx_write_word(client, INA2XX_CONFIG, INA219_CONFIG_DEFAULT);
|
i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
|
||||||
|
INA219_CONFIG_DEFAULT);
|
||||||
|
|
||||||
/* set current LSB to 1mA, shunt is in uOhms */
|
/* set current LSB to 1mA, shunt is in uOhms */
|
||||||
/* (equation 13 in datasheet) */
|
/* (equation 13 in datasheet) */
|
||||||
ina2xx_write_word(client, INA2XX_CALIBRATION, 40960000 / shunt);
|
i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
|
||||||
|
40960000 / shunt);
|
||||||
dev_info(&client->dev,
|
dev_info(&client->dev,
|
||||||
"power monitor INA219 (Rshunt = %li uOhm)\n", shunt);
|
"power monitor INA219 (Rshunt = %li uOhm)\n", shunt);
|
||||||
data->registers = INA219_REGISTERS;
|
data->registers = INA219_REGISTERS;
|
||||||
break;
|
break;
|
||||||
case ina226:
|
case ina226:
|
||||||
/* device configuration */
|
/* device configuration */
|
||||||
ina2xx_write_word(client, INA2XX_CONFIG, INA226_CONFIG_DEFAULT);
|
i2c_smbus_write_word_swapped(client, INA2XX_CONFIG,
|
||||||
|
INA226_CONFIG_DEFAULT);
|
||||||
|
|
||||||
/* set current LSB to 1mA, shunt is in uOhms */
|
/* set current LSB to 1mA, shunt is in uOhms */
|
||||||
/* (equation 1 in datasheet)*/
|
/* (equation 1 in datasheet)*/
|
||||||
ina2xx_write_word(client, INA2XX_CALIBRATION, 5120000 / shunt);
|
i2c_smbus_write_word_swapped(client, INA2XX_CALIBRATION,
|
||||||
|
5120000 / shunt);
|
||||||
dev_info(&client->dev,
|
dev_info(&client->dev,
|
||||||
"power monitor INA226 (Rshunt = %li uOhm)\n", shunt);
|
"power monitor INA226 (Rshunt = %li uOhm)\n", shunt);
|
||||||
data->registers = INA226_REGISTERS;
|
data->registers = INA226_REGISTERS;
|
||||||
|
@ -44,12 +44,13 @@ static ssize_t madc_read(struct device *dev,
|
|||||||
struct device_attribute *devattr, char *buf)
|
struct device_attribute *devattr, char *buf)
|
||||||
{
|
{
|
||||||
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
|
||||||
struct twl4030_madc_request req;
|
struct twl4030_madc_request req = {
|
||||||
|
.channels = 1 << attr->index,
|
||||||
|
.method = TWL4030_MADC_SW2,
|
||||||
|
.type = TWL4030_MADC_WAIT,
|
||||||
|
};
|
||||||
long val;
|
long val;
|
||||||
|
|
||||||
req.channels = (1 << attr->index);
|
|
||||||
req.method = TWL4030_MADC_SW2;
|
|
||||||
req.func_cb = NULL;
|
|
||||||
val = twl4030_madc_conversion(&req);
|
val = twl4030_madc_conversion(&req);
|
||||||
if (val < 0)
|
if (val < 0)
|
||||||
return val;
|
return val;
|
||||||
|
Loading…
Reference in New Issue
Block a user