Browse Source

thermal: rcar_gen3_thermal: add suspend and resume support

To restore operation it's easiest to reinitialise all TSCs. In order to
do this the current trip window needs to be stored in the TSC structure
so that it can be restored upon resume.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Niklas Söderlund 8 năm trước cách đây
mục cha
commit
75f78d6d9e
1 tập tin đã thay đổi với 35 bổ sung0 xóa
  1. 35 0
      drivers/thermal/rcar_gen3_thermal.c

+ 35 - 0
drivers/thermal/rcar_gen3_thermal.c

@@ -82,6 +82,8 @@ struct rcar_gen3_thermal_tsc {
 	void __iomem *base;
 	void __iomem *base;
 	struct thermal_zone_device *zone;
 	struct thermal_zone_device *zone;
 	struct equation_coefs coef;
 	struct equation_coefs coef;
+	int low;
+	int high;
 };
 };
 
 
 struct rcar_gen3_thermal_priv {
 struct rcar_gen3_thermal_priv {
@@ -217,6 +219,9 @@ static int rcar_gen3_thermal_set_trips(void *devdata, int low, int high)
 	rcar_gen3_thermal_write(tsc, REG_GEN3_IRQTEMP2,
 	rcar_gen3_thermal_write(tsc, REG_GEN3_IRQTEMP2,
 				rcar_gen3_thermal_mcelsius_to_temp(tsc, high));
 				rcar_gen3_thermal_mcelsius_to_temp(tsc, high));
 
 
+	tsc->low = low;
+	tsc->high = high;
+
 	return 0;
 	return 0;
 }
 }
 
 
@@ -454,9 +459,39 @@ error_unregister:
 	return ret;
 	return ret;
 }
 }
 
 
+static int __maybe_unused rcar_gen3_thermal_suspend(struct device *dev)
+{
+	struct rcar_gen3_thermal_priv *priv = dev_get_drvdata(dev);
+
+	rcar_thermal_irq_set(priv, false);
+
+	return 0;
+}
+
+static int __maybe_unused rcar_gen3_thermal_resume(struct device *dev)
+{
+	struct rcar_gen3_thermal_priv *priv = dev_get_drvdata(dev);
+	unsigned int i;
+
+	for (i = 0; i < priv->num_tscs; i++) {
+		struct rcar_gen3_thermal_tsc *tsc = priv->tscs[i];
+
+		priv->data->thermal_init(tsc);
+		rcar_gen3_thermal_set_trips(tsc, tsc->low, tsc->high);
+	}
+
+	rcar_thermal_irq_set(priv, true);
+
+	return 0;
+}
+
+static SIMPLE_DEV_PM_OPS(rcar_gen3_thermal_pm_ops, rcar_gen3_thermal_suspend,
+			 rcar_gen3_thermal_resume);
+
 static struct platform_driver rcar_gen3_thermal_driver = {
 static struct platform_driver rcar_gen3_thermal_driver = {
 	.driver	= {
 	.driver	= {
 		.name	= "rcar_gen3_thermal",
 		.name	= "rcar_gen3_thermal",
+		.pm = &rcar_gen3_thermal_pm_ops,
 		.of_match_table = rcar_gen3_thermal_dt_ids,
 		.of_match_table = rcar_gen3_thermal_dt_ids,
 	},
 	},
 	.probe		= rcar_gen3_thermal_probe,
 	.probe		= rcar_gen3_thermal_probe,