Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 199054
b: refs/heads/master
c: 38806bd
h: refs/heads/master
v: v3
  • Loading branch information
Jean Delvare committed May 27, 2010
1 parent e8ab49a commit 966bf05
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8d4dee98b10050db9c32a449e460a2f69bb558ec
refs/heads/master: 38806bda6b7c8473c47a967a514260c1a1c32c2e
38 changes: 28 additions & 10 deletions trunk/drivers/hwmon/tmp102.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
struct tmp102 {
struct device *hwmon_dev;
struct mutex lock;
u16 config_orig;
unsigned long last_update;
int temp[3];
};
Expand Down Expand Up @@ -177,43 +178,52 @@ static int __devinit tmp102_probe(struct i2c_client *client,
}
i2c_set_clientdata(client, tmp102);

status = tmp102_read_reg(client, TMP102_CONF_REG);
if (status < 0) {
dev_err(&client->dev, "error reading config register\n");
goto fail_free;
}
tmp102->config_orig = status;
status = tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONFIG);
if (status < 0) {
dev_err(&client->dev, "error writing config register\n");
goto fail0;
goto fail_restore_config;
}
status = tmp102_read_reg(client, TMP102_CONF_REG);
if (status < 0) {
dev_err(&client->dev, "error reading config register\n");
goto fail0;
goto fail_restore_config;
}
status &= ~TMP102_CONFIG_RD_ONLY;
if (status != TMP102_CONFIG) {
dev_err(&client->dev, "config settings did not stick\n");
status = -ENODEV;
goto fail0;
goto fail_restore_config;
}
tmp102->last_update = jiffies - HZ;
mutex_init(&tmp102->lock);

status = sysfs_create_group(&client->dev.kobj, &tmp102_attr_group);
if (status) {
dev_dbg(&client->dev, "could not create sysfs files\n");
goto fail0;
goto fail_restore_config;
}
tmp102->hwmon_dev = hwmon_device_register(&client->dev);
if (IS_ERR(tmp102->hwmon_dev)) {
dev_dbg(&client->dev, "unable to register hwmon device\n");
status = PTR_ERR(tmp102->hwmon_dev);
goto fail1;
goto fail_remove_sysfs;
}

dev_info(&client->dev, "initialized\n");

return 0;
fail1:

fail_remove_sysfs:
sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group);
fail0:
fail_restore_config:
tmp102_write_reg(client, TMP102_CONF_REG, tmp102->config_orig);
fail_free:
i2c_set_clientdata(client, NULL);
kfree(tmp102);

Expand All @@ -224,11 +234,19 @@ static int __devexit tmp102_remove(struct i2c_client *client)
{
struct tmp102 *tmp102 = i2c_get_clientdata(client);

/* shutdown the chip */
tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONF_SD);

hwmon_device_unregister(tmp102->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group);

/* Stop monitoring if device was stopped originally */
if (tmp102->config_orig & TMP102_CONF_SD) {
int config;

config = tmp102_read_reg(client, TMP102_CONF_REG);
if (config >= 0)
tmp102_write_reg(client, TMP102_CONF_REG,
config | TMP102_CONF_SD);
}

i2c_set_clientdata(client, NULL);
kfree(tmp102);

Expand Down

0 comments on commit 966bf05

Please sign in to comment.