* [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations
@ 2012-09-11 16:34 Guenter Roeck
2012-09-12 8:24 ` Jean Delvare
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Guenter Roeck @ 2012-09-11 16:34 UTC (permalink / raw)
To: lm-sensors
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.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
Candidate for 3.6 and -stable.
drivers/hwmon/ina2xx.c | 30 +++++++++---------------------
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c
index 7f3f4a3..6021482 100644
--- a/drivers/hwmon/ina2xx.c
+++ b/drivers/hwmon/ina2xx.c
@@ -69,22 +69,6 @@ struct ina2xx_data {
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)
{
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 */
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) {
ret = ERR_PTR(rv);
goto abort;
@@ -279,22 +263,26 @@ static int ina2xx_probe(struct i2c_client *client,
switch (data->kind) {
case ina219:
/* 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 */
/* (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,
"power monitor INA219 (Rshunt = %li uOhm)\n", shunt);
data->registers = INA219_REGISTERS;
break;
case ina226:
/* 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 */
/* (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,
"power monitor INA226 (Rshunt = %li uOhm)\n", shunt);
data->registers = INA226_REGISTERS;
--
1.7.9.7
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations
2012-09-11 16:34 [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations Guenter Roeck
@ 2012-09-12 8:24 ` Jean Delvare
2012-09-12 13:41 ` Guenter Roeck
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2012-09-12 8:24 UTC (permalink / raw)
To: lm-sensors
On Tue, 11 Sep 2012 09:34:17 -0700, Guenter Roeck wrote:
> 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.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> Candidate for 3.6 and -stable.
Agreed, down to 3.2 (when i2c_smbus_read/write_word_swapped were
introduced.) If anyone needs the fix for a kernel older than this, it
will have to be implemented differently.
Acked-by: Jean Delvare <khali@linux-fr.org>
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations
2012-09-11 16:34 [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations Guenter Roeck
2012-09-12 8:24 ` Jean Delvare
@ 2012-09-12 13:41 ` Guenter Roeck
2012-09-12 13:49 ` Jean Delvare
2012-09-12 14:02 ` Guenter Roeck
3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2012-09-12 13:41 UTC (permalink / raw)
To: lm-sensors
On Wed, Sep 12, 2012 at 10:24:41AM +0200, Jean Delvare wrote:
> On Tue, 11 Sep 2012 09:34:17 -0700, Guenter Roeck wrote:
> > 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.
> >
> > Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> > ---
> > Candidate for 3.6 and -stable.
>
> Agreed, down to 3.2 (when i2c_smbus_read/write_word_swapped were
> introduced.) If anyone needs the fix for a kernel older than this, it
> will have to be implemented differently.
>
Fortunately, that driver was only introduced in 3.5 (and I didn't realize the
be16 problem when reviewing it ;).
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations
2012-09-11 16:34 [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations Guenter Roeck
2012-09-12 8:24 ` Jean Delvare
2012-09-12 13:41 ` Guenter Roeck
@ 2012-09-12 13:49 ` Jean Delvare
2012-09-12 14:02 ` Guenter Roeck
3 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2012-09-12 13:49 UTC (permalink / raw)
To: lm-sensors
On Wed, 12 Sep 2012 06:41:19 -0700, Guenter Roeck wrote:
> On Wed, Sep 12, 2012 at 10:24:41AM +0200, Jean Delvare wrote:
> > Agreed, down to 3.2 (when i2c_smbus_read/write_word_swapped were
> > introduced.) If anyone needs the fix for a kernel older than this, it
> > will have to be implemented differently.
> >
> Fortunately, that driver was only introduced in 3.5 (and I didn't realize the
> be16 problem when reviewing it ;).
Doh, my bad, I was looking at the max1111 driver history :/ Doing too
many things at once...
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations
2012-09-11 16:34 [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations Guenter Roeck
` (2 preceding siblings ...)
2012-09-12 13:49 ` Jean Delvare
@ 2012-09-12 14:02 ` Guenter Roeck
3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2012-09-12 14:02 UTC (permalink / raw)
To: lm-sensors
On Wed, Sep 12, 2012 at 03:49:23PM +0200, Jean Delvare wrote:
> On Wed, 12 Sep 2012 06:41:19 -0700, Guenter Roeck wrote:
> > On Wed, Sep 12, 2012 at 10:24:41AM +0200, Jean Delvare wrote:
> > > Agreed, down to 3.2 (when i2c_smbus_read/write_word_swapped were
> > > introduced.) If anyone needs the fix for a kernel older than this, it
> > > will have to be implemented differently.
> > >
> > Fortunately, that driver was only introduced in 3.5 (and I didn't realize the
> > be16 problem when reviewing it ;).
>
> Doh, my bad, I was looking at the max1111 driver history :/ Doing too
> many things at once...
>
Glad to hear that this doens't just happen to me :)
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-09-12 14:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-11 16:34 [lm-sensors] [PATCH 3/5] hwmon: (ina2xx) Fix word size register read and write operations Guenter Roeck
2012-09-12 8:24 ` Jean Delvare
2012-09-12 13:41 ` Guenter Roeck
2012-09-12 13:49 ` Jean Delvare
2012-09-12 14:02 ` Guenter Roeck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.