Re: [PATCH 13/40] hwmon: (lm90) Support multiple temperature resolutions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 5/26/22 00:12, Slawomir Stepien wrote:
On maj 25, 2022 06:57, Guenter Roeck wrote:
(...)
@@ -1477,36 +1332,36 @@ static int lm90_temp_write(struct device *dev, u32 attr, int channel, long val)
switch (attr) {
  	case hwmon_temp_min:
-		if (channel == 0)
-			err = lm90_set_temp8(data,
-					      lm90_temp_min_index[channel],
-					      val);
-		else
-			err = lm90_set_temp11(data,
-					      lm90_temp_min_index[channel],
-					      val);
+		err = lm90_set_temp(data, lm90_temp_min_index[channel],
+				    channel, val);
  		break;
  	case hwmon_temp_max:
-		if (channel == 0)
-			err = lm90_set_temp8(data,
-					     lm90_temp_max_index[channel],
-					     val);
-		else
-			err = lm90_set_temp11(data,
-					      lm90_temp_max_index[channel],
-					      val);
+		err = lm90_set_temp(data, lm90_temp_max_index[channel],
+				    channel, val);
  		break;
  	case hwmon_temp_crit:
-		err = lm90_set_temp8(data, lm90_temp_crit_index[channel], val);
+		err = lm90_set_temp(data, lm90_temp_crit_index[channel],
+				    channel, val);
  		break;
  	case hwmon_temp_crit_hyst:
  		err = lm90_set_temphyst(data, val);
  		break;
  	case hwmon_temp_emergency:
-		err = lm90_set_temp8(data, lm90_temp_emerg_index[channel], val);
+		err = lm90_set_temp(data, lm90_temp_emerg_index[channel],
+				    channel, val);
  		break;
  	case hwmon_temp_offset:
-		err = lm90_set_temp11(data, REMOTE_OFFSET, val);
+		val = lm90_temp_to_reg(0, val,
+				       lm90_temp_get_resolution(data, REMOTE_OFFSET));
+		data->temp[REMOTE_OFFSET] = val;

I do not understand why you do this val assignment here, before doing real i2c write. That write
might fail and then we have "incorrect" value in data->temp.


No special reason. I'll move the assignment to the end of the case statement.

Guenter

+		err = i2c_smbus_write_byte_data(data->client,
+						LM90_REG_REMOTE_OFFSH,
+						val >> 8);
+		if (err)
+			break;
+		err = i2c_smbus_write_byte_data(data->client,
+						LM90_REG_REMOTE_OFFSL,
+						val & 0xff);
  		break;
  	default:
  		err = -EOPNOTSUPP;
@@ -2035,6 +1890,7 @@ static int lm90_probe(struct i2c_client *client)
  	 * ALERT# output
  	 */
  	data->alert_alarms = lm90_params[data->kind].alert_alarms;
+	data->resolution = lm90_params[data->kind].resolution ? : 11;
/* Set chip capabilities */
  	data->flags = lm90_params[data->kind].flags;





[Index of Archives]     [LM Sensors]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux