Skip to content

Commit

Permalink
hwmon: (tmp102) Fix suspend and resume functions
Browse files Browse the repository at this point in the history
Suspend and resume functions shouldn't overwrite the configuration
register. They should only alter the one bit they have to touch.

Also don't assume that register reads and writes always succeed.
Handle errors properly, shall they happen.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Steven King <sfking@fdwdc.com>
  • Loading branch information
Jean Delvare committed May 27, 2010
1 parent cff37c9 commit 8d4dee9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions drivers/hwmon/tmp102.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,27 @@ static int __devexit tmp102_remove(struct i2c_client *client)
static int tmp102_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
int config;

tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONF_SD);
config = tmp102_read_reg(client, TMP102_CONF_REG);
if (config < 0)
return config;

return 0;
config |= TMP102_CONF_SD;
return tmp102_write_reg(client, TMP102_CONF_REG, config);
}

static int tmp102_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
int config;

tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONFIG);
config = tmp102_read_reg(client, TMP102_CONF_REG);
if (config < 0)
return config;

return 0;
config &= ~TMP102_CONF_SD;
return tmp102_write_reg(client, TMP102_CONF_REG, config);
}

static const struct dev_pm_ops tmp102_dev_pm_ops = {
Expand Down

0 comments on commit 8d4dee9

Please sign in to comment.