Skip to contentSkip to conversation

hwmon: (w83627hf) Add support for suspend

PATCH Superseded Jean Delvare 2 participants 4 messages Oct 23, 2012 – Oct 26, 2012 Hardware monitoring

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (w83627hf) Add support for suspend

On suspend some register values are lost, most notably the Value RAM areas but also other limits. Restore them on resume. On top of that, some fixups are needed to work around BIOS bugs, in particular when the BIOS omits running the same initialization sequence on resume that it does after boot. In that case we have to carry initialization over suspend.

---
 drivers/hwmon/w83627hf.c |   75 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)
drivers/hwmon/w83627hf.c +74 -1
@@ -5,7 +5,7 @@
  *			      Philip Edelbrock <[email protected]>,
  *			      and Mark Studebaker <[email protected]>
  * Ported to 2.6 by Bernhard C. Schrenk <[email protected]>
- * Copyright (c) 2007  Jean Delvare <[email protected]>
+ * Copyright (c) 2007 - 1012  Jean Delvare <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -389,6 +389,12 @@ struct w83627hf_data {
 				 */
 	u8 vrm;
 	u8 vrm_ovt;		/* Register value, 627THF/637HF/687THF only */
+
+#ifdef CONFIG_PM
+	/* Remember extra register values over suspend/resume */
+	u8 scfg1;
+	u8 scfg2;
+#endif
 };
 
 
@@ -401,10 +407,77 @@ static void w83627hf_update_fan_div(stru
 static struct w83627hf_data *w83627hf_update_device(struct device *dev);
 static void w83627hf_init_device(struct platform_device *pdev);
 
+#ifdef CONFIG_PM
+static int w83627hf_suspend(struct device *dev)
+{
+	struct w83627hf_data *data = w83627hf_update_device(dev);
+
+	mutex_lock(&data->update_lock);
+	data->scfg1 = w83627hf_read_value(data, W83781D_REG_SCFG1);
+	data->scfg2 = w83627hf_read_value(data, W83781D_REG_SCFG2);
+	mutex_unlock(&data->update_lock);
+
+	return 0;
+}
+
+static int w83627hf_resume(struct device *dev)
+{
+	struct w83627hf_data *data = dev_get_drvdata(dev);
+	int i, num_temps = (data->type = w83697hf) ? 2 : 3;
+
+	/* Restore limits */
+	mutex_lock(&data->update_lock);
+	for (i = 0; i <= 8; i++) {
+		/* skip missing sensors */
+		if (((data->type = w83697hf) && (i = 1)) ||
+		    ((data->type != w83627hf && data->type != w83697hf)
+		    && (i = 5 || i = 6)))
+			continue;
+		w83627hf_write_value(data, W83781D_REG_IN_MAX(i),
+				     data->in_max[i]);
+		w83627hf_write_value(data, W83781D_REG_IN_MIN(i),
+				     data->in_min[i]);
+	}
+	for (i = 0; i <= 2; i++)
+		w83627hf_write_value(data, W83627HF_REG_FAN_MIN(i),
+				     data->fan_min[i]);
+	for (i = 0; i < num_temps; i++) {
+		w83627hf_write_value(data, w83627hf_reg_temp_over[i],
+				     data->temp_max[i]);
+		w83627hf_write_value(data, w83627hf_reg_temp_hyst[i],
+				     data->temp_max_hyst[i]);
+	}
+
+	/* Fixup BIOS bugs */
+	if (data->type = w83627thf || data->type = w83637hf ||
+	    data->type = w83687thf)
+		w83627hf_write_value(data, W83627THF_REG_VRM_OVT_CFG,
+				     data->vrm_ovt);
+	w83627hf_write_value(data, W83781D_REG_SCFG1, data->scfg1);
+	w83627hf_write_value(data, W83781D_REG_SCFG2, data->scfg2);
+
+	/* Force re-reading all values */
+	data->valid = 0;
+	mutex_unlock(&data->update_lock);
+
+	return 0;
+}
+
+static const struct dev_pm_ops w83627hf_dev_pm_ops = {
+	.suspend = w83627hf_suspend,
+	.resume = w83627hf_resume,
+};
+
+#define W83627HF_DEV_PM_OPS	(&w83627hf_dev_pm_ops)
+#else
+#define W83627HF_DEV_PM_OPS	NULL
+#endif /* CONFIG_PM */
+
 static struct platform_driver w83627hf_driver = {
 	.driver = {
 		.owner	= THIS_MODULE,
 		.name	= DRVNAME,
+		.pm	= W83627HF_DEV_PM_OPS,
 	},
 	.probe		= w83627hf_probe,
 	.remove		= __devexit_p(w83627hf_remove),
Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Jean Delvare

On suspend some register values are lost, most notably the Value RAM areas but also other limits. Restore them on resume. On top of that, some fixups are needed to work around BIOS bugs, in particular when the BIOS omits running the same initialization sequence on resume that it does after boot. In that case we have to carry initialization over suspend.

Does the BIOS bug apply to all BIOSes, or just to some, or does it not matter ?

I have a system with w83627hf - want me to test the code with it ?

Code itself looks good afaics, so

Thanks,
Guenter

Quoted 111 lines
---
 drivers/hwmon/w83627hf.c |   75 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 74 insertions(+), 1 deletion(-)
drivers/hwmon/w83627hf.c +74 -1
@@ -5,7 +5,7 @@
  *			      Philip Edelbrock <[email protected]>,
  *			      and Mark Studebaker <[email protected]>
  * Ported to 2.6 by Bernhard C. Schrenk <[email protected]>
- * Copyright (c) 2007  Jean Delvare <[email protected]>
+ * Copyright (c) 2007 - 1012  Jean Delvare <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -389,6 +389,12 @@ struct w83627hf_data {
 				 */
 	u8 vrm;
 	u8 vrm_ovt;		/* Register value, 627THF/637HF/687THF only */
+
+#ifdef CONFIG_PM
+	/* Remember extra register values over suspend/resume */
+	u8 scfg1;
+	u8 scfg2;
+#endif
 };
 
 
@@ -401,10 +407,77 @@ static void w83627hf_update_fan_div(stru
 static struct w83627hf_data *w83627hf_update_device(struct device *dev);
 static void w83627hf_init_device(struct platform_device *pdev);
 
+#ifdef CONFIG_PM
+static int w83627hf_suspend(struct device *dev)
+{
+	struct w83627hf_data *data = w83627hf_update_device(dev);
+
+	mutex_lock(&data->update_lock);
+	data->scfg1 = w83627hf_read_value(data, W83781D_REG_SCFG1);
+	data->scfg2 = w83627hf_read_value(data, W83781D_REG_SCFG2);
+	mutex_unlock(&data->update_lock);
+
+	return 0;
+}
+
+static int w83627hf_resume(struct device *dev)
+{
+	struct w83627hf_data *data = dev_get_drvdata(dev);
+	int i, num_temps = (data->type = w83697hf) ? 2 : 3;
+
+	/* Restore limits */
+	mutex_lock(&data->update_lock);
+	for (i = 0; i <= 8; i++) {
+		/* skip missing sensors */
+		if (((data->type = w83697hf) && (i = 1)) ||
+		    ((data->type != w83627hf && data->type != w83697hf)
+		    && (i = 5 || i = 6)))
+			continue;
+		w83627hf_write_value(data, W83781D_REG_IN_MAX(i),
+				     data->in_max[i]);
+		w83627hf_write_value(data, W83781D_REG_IN_MIN(i),
+				     data->in_min[i]);
+	}
+	for (i = 0; i <= 2; i++)
+		w83627hf_write_value(data, W83627HF_REG_FAN_MIN(i),
+				     data->fan_min[i]);
+	for (i = 0; i < num_temps; i++) {
+		w83627hf_write_value(data, w83627hf_reg_temp_over[i],
+				     data->temp_max[i]);
+		w83627hf_write_value(data, w83627hf_reg_temp_hyst[i],
+				     data->temp_max_hyst[i]);
+	}
+
+	/* Fixup BIOS bugs */
+	if (data->type = w83627thf || data->type = w83637hf ||
+	    data->type = w83687thf)
+		w83627hf_write_value(data, W83627THF_REG_VRM_OVT_CFG,
+				     data->vrm_ovt);
+	w83627hf_write_value(data, W83781D_REG_SCFG1, data->scfg1);
+	w83627hf_write_value(data, W83781D_REG_SCFG2, data->scfg2);
+
+	/* Force re-reading all values */
+	data->valid = 0;
+	mutex_unlock(&data->update_lock);
+
+	return 0;
+}
+
+static const struct dev_pm_ops w83627hf_dev_pm_ops = {
+	.suspend = w83627hf_suspend,
+	.resume = w83627hf_resume,
+};
+
+#define W83627HF_DEV_PM_OPS	(&w83627hf_dev_pm_ops)
+#else
+#define W83627HF_DEV_PM_OPS	NULL
+#endif /* CONFIG_PM */
+
 static struct platform_driver w83627hf_driver = {
 	.driver = {
 		.owner	= THIS_MODULE,
 		.name	= DRVNAME,
+		.pm	= W83627HF_DEV_PM_OPS,
 	},
 	.probe		= w83627hf_probe,
 	.remove		= __devexit_p(w83627hf_remove),
Signature · 2 lines
-- 
Jean Delvare

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

#2 lore raw
In reply to Jean Delvare
Quoted 11 lines · Guenter Roeck
Quoted 8 lines · Jean Delvare

On suspend some register values are lost, most notably the Value RAM areas but also other limits. Restore them on resume. On top of that, some fixups are needed to work around BIOS bugs, in particular when the BIOS omits running the same initialization sequence on resume that it does after boot. In that case we have to carry initialization over suspend.

Does the BIOS bug apply to all BIOSes, or just to some, or does it not matter ?

At least mine. But there is no downside on other systems, reading and writing two extra registers over the LPC bus is pretty cheap. And I would be very surprised if other BIOSes out there don't need the same anyway.

Quoted 1 line

I have a system with w83627hf - want me to test the code with it ?

Would be great, yes. Dumping the registers before and after suspend would be a good way to ensure it worked fine.

Quoted 3 lines

Code itself looks good afaics, so

Thanks for the review.

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
maintainer
#3 lore raw
In reply to Jean Delvare
Quoted 18 lines · Jean Delvare
Quoted 11 lines · Guenter Roeck
Quoted 8 lines · Jean Delvare

On suspend some register values are lost, most notably the Value RAM areas but also other limits. Restore them on resume. On top of that, some fixups are needed to work around BIOS bugs, in particular when the BIOS omits running the same initialization sequence on resume that it does after boot. In that case we have to carry initialization over suspend.

Does the BIOS bug apply to all BIOSes, or just to some, or does it not matter ?

At least mine. But there is no downside on other systems, reading and writing two extra registers over the LPC bus is pretty cheap. And I would be very surprised if other BIOSes out there don't need the same anyway.

Quoted 5 lines
Quoted 1 line

I have a system with w83627hf - want me to test the code with it ?

Would be great, yes. Dumping the registers before and after suspend would be a good way to ensure it worked fine.

Guenter

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