forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix false alarm when writing convrate on max6658 (#82)
* Fix false alarm when writing convrate on max6658 We found that the max6658 sometimes issues a false alarm when its convrate is changed, with the current hwmon driver. This workaround will fix it by stopping the conversion before setting the convrate. * Avoid affecting other kinds by the change to max6658
- Loading branch information
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c | ||
index 841f2428..d3e1cc2e 100644 | ||
--- a/drivers/hwmon/lm90.c | ||
+++ b/drivers/hwmon/lm90.c | ||
@@ -486,6 +486,33 @@ static inline int lm90_select_remote_channel(struct i2c_client *client, | ||
return 0; | ||
} | ||
|
||
+static int max6657_write_convrate(struct i2c_client *client, int val) | ||
+{ | ||
+ int err_c = 0; | ||
+ int err; | ||
+ int config_orig, config_stop; | ||
+ | ||
+ /* Save config and stop conversion*/ | ||
+ config_orig = lm90_read_reg(client, LM90_REG_R_CONFIG1); | ||
+ if (config_orig < 0) | ||
+ return config_orig; | ||
+ config_stop = config_orig | 0x40; | ||
+ if (config_orig != config_stop) { | ||
+ err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config_stop); | ||
+ if (err < 0) | ||
+ return err; | ||
+ } | ||
+ | ||
+ /* Set conv rate */ | ||
+ err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, val); | ||
+ | ||
+ /* Revert change to config */ | ||
+ if (config_orig != config_stop) | ||
+ err_c = i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config_orig); | ||
+ | ||
+ return err < 0 ? err : err_c; | ||
+} | ||
+ | ||
/* | ||
* Set conversion rate. | ||
* client->update_lock must be held when calling this function (unless we are | ||
@@ -506,7 +533,11 @@ static int lm90_set_convrate(struct i2c_client *client, struct lm90_data *data, | ||
if (interval >= update_interval * 3 / 4) | ||
break; | ||
|
||
- err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, i); | ||
+ if (data->kind == max6657) | ||
+ err = max6657_write_convrate(client, i); | ||
+ else | ||
+ err = i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, i); | ||
+ | ||
data->update_interval = DIV_ROUND_CLOSEST(update_interval, 64); | ||
return err; | ||
} | ||
@@ -1512,8 +1543,11 @@ static void lm90_restore_conf(void *_data) | ||
struct i2c_client *client = data->client; | ||
|
||
/* Restore initial configuration */ | ||
- i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, | ||
- data->convrate_orig); | ||
+ if (data->kind == max6657) | ||
+ max6657_write_convrate(client, data->convrate_orig); | ||
+ else | ||
+ i2c_smbus_write_byte_data(client, LM90_REG_W_CONVRATE, | ||
+ data->convrate_orig); | ||
i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, | ||
data->config_orig); | ||
} | ||
@@ -1521,6 +1555,7 @@ static void lm90_restore_conf(void *_data) | ||
static int lm90_init_client(struct i2c_client *client, struct lm90_data *data) | ||
{ | ||
int config, convrate; | ||
+ int err; | ||
|
||
convrate = lm90_read_reg(client, LM90_REG_R_CONVRATE); | ||
if (convrate < 0) | ||
@@ -1530,12 +1565,21 @@ static int lm90_init_client(struct i2c_client *client, struct lm90_data *data) | ||
/* | ||
* Start the conversions. | ||
*/ | ||
- lm90_set_convrate(client, data, 500); /* 500ms; 2Hz conversion rate */ | ||
+ /* 500ms; 2Hz conversion rate */ | ||
+ if (data->kind != max6657) | ||
+ lm90_set_convrate(client, data, 500); | ||
+ | ||
config = lm90_read_reg(client, LM90_REG_R_CONFIG1); | ||
if (config < 0) | ||
return config; | ||
data->config_orig = config; | ||
|
||
+ if (data->kind == max6657) { | ||
+ err = lm90_set_convrate(client, data, 500); | ||
+ if (err < 0) | ||
+ return err; | ||
+ } | ||
+ | ||
/* Check Temperature Range Select */ | ||
if (data->kind == adt7461 || data->kind == tmp451) { | ||
if (config & 0x04) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters