Skip to contentSkip to conversation

hwmon: (f75375s) Fix writes to the pwm* attribute for the F75387

PATCH In review Nikolaus Schulz 2 participants 3 messages Feb 22, 2012 – Feb 23, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/6 hwmon: (f75375s) Fix writes to the pwm* attribute for the F75387

For the F75387, the register holding the current PWM duty cycle value is r/o; changing it requires writing to the fan expect register instead.

---
 drivers/hwmon/f75375s.c |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)
drivers/hwmon/f75375s.c +21 -6
index 5dae122..fc6444d 100644
@@ -308,8 +308,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
 		return err;
 
 	mutex_lock(&data->update_lock);
+	/* TODO: Improve representation in the register cache for the F75387 */
 	data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
-	f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr), data->pwm[nr]);
+	if (data->kind = f75387)
+		f75375_write16(client, F75375_REG_FAN_EXP(nr),
+				data->pwm[nr]);
+	else
+		f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
+				data->pwm[nr]);
 	mutex_unlock(&data->update_lock);
 	return count;
 }
@@ -373,9 +379,14 @@ static int set_pwm_enable_direct(struct i2c_client *client, int nr, int val)
 
 	f75375_write8(client, F75375_REG_FAN_TIMER, fanmode);
 	data->pwm_enable[nr] = val;
-	if (val = 0)
-		f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
-				data->pwm[nr]);
+	if (val = 0) {
+		if (data->kind = f75387)
+			f75375_write16(client, F75375_REG_FAN_EXP(nr),
+					data->pwm[nr]);
+		else
+			f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
+					data->pwm[nr]);
+	}
 	return 0;
 }
 
@@ -759,8 +770,12 @@ static void f75375_init(struct i2c_client *client, struct f75375_data *data,
 	set_pwm_enable_direct(client, 1, f75375s_pdata->pwm_enable[1]);
 	for (nr = 0; nr < 2; nr++) {
 		data->pwm[nr] = SENSORS_LIMIT(f75375s_pdata->pwm[nr], 0, 255);
-		f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
-			data->pwm[nr]);
+		if (data->kind = f75387)
+			f75375_write16(client, F75375_REG_FAN_EXP(nr),
+					data->pwm[nr]);
+		else
+			f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
+					data->pwm[nr]);
 	}
 
 }
Signature · 7 lines
1.7.9.1


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw
Quoted 13 lines · Nikolaus Schulz

For the F75387, the register holding the current PWM duty cycle value is r/o; changing it requires writing to the fan expect register instead.

---
 drivers/hwmon/f75375s.c |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)
drivers/hwmon/f75375s.c +0 -0
index 5dae122..fc6444d 100644

drivers/hwmon/f75375s.c static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, · line 311

Quoted 4 lines
drivers/hwmon/f75375s.c +1 -0
@@ -308,8 +308,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
 		return err;
 
 	mutex_lock(&data->update_lock);
+	/* TODO: Improve representation in the register cache for the F75387 */

Is this comment needed ? If not, I would prefer not to add it as comment in a bug fix at this point in the release cycle.

drivers/hwmon/f75375s.c static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, · line 318

Quoted 8 lines
drivers/hwmon/f75375s.c +6 -1
 	data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
-	f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr), data->pwm[nr]);
+	if (data->kind = f75387)
+		f75375_write16(client, F75375_REG_FAN_EXP(nr),
+				data->pwm[nr]);
+	else
+		f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
+				data->pwm[nr]);

This is three times the same code. Can you move it into a separate function ?

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw
In reply to Nikolaus Schulz
Quoted 16 lines · Guenter Roeck
Quoted 15 lines · Nikolaus Schulz

For the F75387, the register holding the current PWM duty cycle value is r/o; changing it requires writing to the fan expect register instead.

---
 drivers/hwmon/f75375s.c |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)
drivers/hwmon/f75375s.c +0 -0
index 5dae122..fc6444d 100644
@@ -308,8 +308,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
 		return err;
 
Quoted 5 lines

drivers/hwmon/f75375s.c static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, · line 311

Quoted 2 lines
drivers/hwmon/f75375s.c +1 -0
 	mutex_lock(&data->update_lock);
+	/* TODO: Improve representation in the register cache for the F75387 */

Is this comment needed ? If not, I would prefer not to add it as comment in a bug fix at this point in the release cycle.

Yeah, in fact didn't feel good about that myself. :) I'll drop that.

Quoted 10 lines

drivers/hwmon/f75375s.c static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, · line 318

Quoted 8 lines
drivers/hwmon/f75375s.c +6 -1
 	data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
-	f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr), data->pwm[nr]);
+	if (data->kind = f75387)
+		f75375_write16(client, F75375_REG_FAN_EXP(nr),
+				data->pwm[nr]);
+	else
+		f75375_write8(client, F75375_REG_FAN_PWM_DUTY(nr),
+				data->pwm[nr]);

This is three times the same code. Can you move it into a separate function ?

Right, I thought that making this a function involves passing so many variables around that it's not worth it, but it's indeed cleaner.

I'll post an updated patch. Thanks for the review!

Nikolaus

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors