Skip to content

Commit

Permalink
Fix false alarm when writing convrate on max6658 (sonic-net#82)
Browse files Browse the repository at this point in the history
* 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
byu343 authored and lguohan committed Jul 11, 2019
1 parent 415b368 commit d03f616
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
96 changes: 96 additions & 0 deletions patch/driver-hwmon-max6658-fix-write-convrate.patch
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)
1 change: 1 addition & 0 deletions patch/series
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ kernel-add-kexec-reboot-string.patch
driver-hwmon-max6620.patch
driver-hwmon-max6620-fix-rpm-calc.patch
driver-hwmon-max6620-update.patch
driver-hwmon-max6658-fix-write-convrate.patch
driver-hwmon-pmbus-dni_dps460.patch
driver-hwmon-pmbus-dni_dps460-update-pmbus-core.patch
driver-hwmon-pmbus-dps1900.patch
Expand Down

0 comments on commit d03f616

Please sign in to comment.