All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] i2c errors while updating sensors
@ 2011-12-23 14:44 Frans Meulenbroeks
  2011-12-23 16:23 ` Guenter Roeck
  2012-01-02 11:00 ` Frans Meulenbroeks
  0 siblings, 2 replies; 3+ messages in thread
From: Frans Meulenbroeks @ 2011-12-23 14:44 UTC (permalink / raw)
  To: lm-sensors


[-- Attachment #1.1: Type: text/plain, Size: 2258 bytes --]

I was peeking at lm75/lm80 i2c error message handing.

The problem I am facing is that I am using lm75 for temperature monitoring
and lm80 for temperature and fan tacho monitoring.
This is an embedded (powerpc) system using a 2.6.38 kernel, and accessing
the sensors through the sysfs interface.

The customer wants to be able to detect if someone accidently disconnects
the fan (or the monitoring chip dies).
I know i2c is not hot pluggable, but would have expected to be able to
detect this error condition

However, from peeking at the sources, it seems I am not.


lm75.c says (function lm75_update_device)
        for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
            int status;

            status = lm75_read_value(client, LM75_REG_TEMP[i]);
            if (status < 0)
                dev_dbg(&client->dev, "reg %d, err %d\n",
                        LM75_REG_TEMP[i], status);
            else
                data->temp[i] = status;
        }
        data->last_updated = jiffies;
        data->valid = 1;
So there is an error message if dbg is on, but a user will still get the
old data as temp[i] is not updated.

Wouldn't it be nice to e.g. add a (bool) attribute data-valid or or so and
drop that to 0 on a read fail (or maybe 3 subsequent read fails)?
Or is there a better way do detect such a problem in user space (e.g. by
putting an "error" value in the var)

I've also peeked at lm80.c
Here the situation seems to be a little bit worse.
E.g. I see:

static int lm80_read_value(struct i2c_client *client, u8 reg)
{
    return i2c_smbus_read_byte_data(client, reg);
}

...

        data->temp =
            (lm80_read_value(client, LM80_REG_TEMP) << 8) |
            (lm80_read_value(client, LM80_REG_RES) & 0xf0);

but i2c_smbus_read_byte_data may return a negative value upon error.
To me it seems this is not going to return a sensible value in case the
read fails (and also not e.g. something like -1)

Is this desired? Should this be fixed? Or is there a better way to do so?
If needed, I can have a stab at the code to fix it, but in that case I
would appreciate some guidance in the direction of the preferred solution
(so my work is not rejected because it was felt a faulty solution).

Best regards & seasons greetings,
Frans

[-- Attachment #1.2: Type: text/html, Size: 2504 bytes --]

[-- Attachment #2: Type: text/plain, Size: 153 bytes --]

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-01-02 11:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-23 14:44 [lm-sensors] i2c errors while updating sensors Frans Meulenbroeks
2011-12-23 16:23 ` Guenter Roeck
2012-01-02 11:00 ` Frans Meulenbroeks

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.