Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d2cac802 authored by Ben Hutchings's avatar Ben Hutchings Committed by Jean Delvare
Browse files

hwmon: (lm87) Restore original configuration register on removal



This means that if we have to start the monitor when probed, we also
stop it on removal.

Signed-off-by: default avatarBen Hutchings <bhutchings@solarflare.com>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 49ae6cc8
Loading
Loading
Loading
Loading
+7 −5
Original line number Original line Diff line number Diff line
@@ -199,6 +199,7 @@ struct lm87_data {
	unsigned long last_updated; /* In jiffies */
	unsigned long last_updated; /* In jiffies */


	u8 channel;		/* register value */
	u8 channel;		/* register value */
	u8 config;		/* original register value */


	u8 in[8];		/* register value */
	u8 in[8];		/* register value */
	u8 in_max[8];		/* register value */
	u8 in_max[8];		/* register value */
@@ -832,6 +833,7 @@ exit_remove:
	sysfs_remove_group(&new_client->dev.kobj, &lm87_group);
	sysfs_remove_group(&new_client->dev.kobj, &lm87_group);
	sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt);
	sysfs_remove_group(&new_client->dev.kobj, &lm87_group_opt);
exit_free:
exit_free:
	lm87_write_value(new_client, LM87_REG_CONFIG, data->config);
	kfree(data);
	kfree(data);
exit:
exit:
	return err;
	return err;
@@ -840,12 +842,11 @@ exit:
static void lm87_init_client(struct i2c_client *client)
static void lm87_init_client(struct i2c_client *client)
{
{
	struct lm87_data *data = i2c_get_clientdata(client);
	struct lm87_data *data = i2c_get_clientdata(client);
	u8 config;


	data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
	data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
	data->config = lm87_read_value(client, LM87_REG_CONFIG) & 0x6F;


	config = lm87_read_value(client, LM87_REG_CONFIG);
	if (!(data->config & 0x01)) {
	if (!(config & 0x01)) {
		int i;
		int i;


		/* Limits are left uninitialized after power-up */
		/* Limits are left uninitialized after power-up */
@@ -869,9 +870,9 @@ static void lm87_init_client(struct i2c_client *client)
	}
	}


	/* Make sure Start is set and INT#_Clear is clear */
	/* Make sure Start is set and INT#_Clear is clear */
	if ((config & 0x09) != 0x01)
	if ((data->config & 0x09) != 0x01)
		lm87_write_value(client, LM87_REG_CONFIG,
		lm87_write_value(client, LM87_REG_CONFIG,
				 (config & 0x77) | 0x01);
				 (data->config & 0x77) | 0x01);
}
}


static int lm87_remove(struct i2c_client *client)
static int lm87_remove(struct i2c_client *client)
@@ -882,6 +883,7 @@ static int lm87_remove(struct i2c_client *client)
	sysfs_remove_group(&client->dev.kobj, &lm87_group);
	sysfs_remove_group(&client->dev.kobj, &lm87_group);
	sysfs_remove_group(&client->dev.kobj, &lm87_group_opt);
	sysfs_remove_group(&client->dev.kobj, &lm87_group_opt);


	lm87_write_value(client, LM87_REG_CONFIG, data->config);
	kfree(data);
	kfree(data);
	return 0;
	return 0;
}
}