linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
To: Zhang Rui <rui.zhang@intel.com>, Eduardo Valentin <edubezval@gmail.com>
Cc: Amit kucheria <amit.kucheria@linaro.org>,
	Eric Anholt <eric@anholt.net>,
	Stefan Wahren <stefan.wahren@i2se.com>,
	Markus Mayer <mmayer@broadcom.com>,
	bcm-kernel-feedback-list@broadcom.com,
	Heiko Stuebner <heiko@sntech.de>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Keerthy <j-keerthy@ti.com>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	Jun Nie <jun.nie@linaro.org>, Baoyou Xie <baoyou.xie@linaro.org>,
	Shawn Guo <shawnguo@kernel.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	b.zolnierkie@samsung.com
Subject: [PATCH v2 01/17] thermal: add thermal_zone_set_mode() helper
Date: Wed, 17 Oct 2018 17:52:27 +0200	[thread overview]
Message-ID: <1539791563-5959-2-git-send-email-b.zolnierkie@samsung.com> (raw)
In-Reply-To: <1539791563-5959-1-git-send-email-b.zolnierkie@samsung.com>

In order to remove the code duplication and prepare for further
changes:

* Add thermal_zone_set_mode() helper. Then update core code and
  drivers to use it.

There should be no functional changes caused by this patch.

Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
---
 drivers/thermal/hisi_thermal.c     | 14 ++------------
 drivers/thermal/of-thermal.c       |  3 ++-
 drivers/thermal/rockchip_thermal.c | 26 +++++++++-----------------
 drivers/thermal/thermal_helpers.c  | 14 ++++++++++++++
 drivers/thermal/thermal_sysfs.c    |  8 +++++---
 include/linux/thermal.h            |  5 +++++
 6 files changed, 37 insertions(+), 33 deletions(-)

diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c
index 761d055..b3f8d9f 100644
--- a/drivers/thermal/hisi_thermal.c
+++ b/drivers/thermal/hisi_thermal.c
@@ -515,15 +515,6 @@ static int hisi_thermal_register_sensor(struct platform_device *pdev,
 };
 MODULE_DEVICE_TABLE(of, of_hisi_thermal_match);
 
-static void hisi_thermal_toggle_sensor(struct hisi_thermal_sensor *sensor,
-				       bool on)
-{
-	struct thermal_zone_device *tzd = sensor->tzd;
-
-	tzd->ops->set_mode(tzd,
-		on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
-}
-
 static int hisi_thermal_probe(struct platform_device *pdev)
 {
 	struct hisi_thermal_data *data;
@@ -571,7 +562,7 @@ static int hisi_thermal_probe(struct platform_device *pdev)
 		}
 	}
 
-	hisi_thermal_toggle_sensor(&data->sensor, true);
+	thermal_zone_set_mode((&data->sensor)->tzd, THERMAL_DEVICE_ENABLED);
 
 	return 0;
 }
@@ -579,9 +570,8 @@ static int hisi_thermal_probe(struct platform_device *pdev)
 static int hisi_thermal_remove(struct platform_device *pdev)
 {
 	struct hisi_thermal_data *data = platform_get_drvdata(pdev);
-	struct hisi_thermal_sensor *sensor = &data->sensor;
 
-	hisi_thermal_toggle_sensor(sensor, false);
+	thermal_zone_set_mode((&data->sensor)->tzd, THERMAL_DEVICE_DISABLED);
 
 	data->disable_sensor(data);
 
diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
index 4f28165..118910c 100644
--- a/drivers/thermal/of-thermal.c
+++ b/drivers/thermal/of-thermal.c
@@ -496,7 +496,8 @@ struct thermal_zone_device *
 			tzd = thermal_zone_of_add_sensor(child, sensor_np,
 							 data, ops);
 			if (!IS_ERR(tzd))
-				tzd->ops->set_mode(tzd, THERMAL_DEVICE_ENABLED);
+				thermal_zone_set_mode(tzd,
+						      THERMAL_DEVICE_ENABLED);
 
 			of_node_put(sensor_specs.np);
 			of_node_put(child);
diff --git a/drivers/thermal/rockchip_thermal.c b/drivers/thermal/rockchip_thermal.c
index f36375d..2edd44c 100644
--- a/drivers/thermal/rockchip_thermal.c
+++ b/drivers/thermal/rockchip_thermal.c
@@ -1022,15 +1022,6 @@ static void rk_tsadcv2_tshut_mode(int chn, void __iomem *regs,
 };
 MODULE_DEVICE_TABLE(of, of_rockchip_thermal_match);
 
-static void
-rockchip_thermal_toggle_sensor(struct rockchip_thermal_sensor *sensor, bool on)
-{
-	struct thermal_zone_device *tzd = sensor->tzd;
-
-	tzd->ops->set_mode(tzd,
-		on ? THERMAL_DEVICE_ENABLED : THERMAL_DEVICE_DISABLED);
-}
-
 static irqreturn_t rockchip_thermal_alarm_irq_thread(int irq, void *dev)
 {
 	struct rockchip_thermal_data *thermal = dev;
@@ -1292,7 +1283,8 @@ static int rockchip_thermal_probe(struct platform_device *pdev)
 	thermal->chip->control(thermal->regs, true);
 
 	for (i = 0; i < thermal->chip->chn_num; i++)
-		rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
+		thermal_zone_set_mode((&thermal->sensors[i])->tzd,
+				      THERMAL_DEVICE_ENABLED);
 
 	platform_set_drvdata(pdev, thermal);
 
@@ -1311,11 +1303,9 @@ static int rockchip_thermal_remove(struct platform_device *pdev)
 	struct rockchip_thermal_data *thermal = platform_get_drvdata(pdev);
 	int i;
 
-	for (i = 0; i < thermal->chip->chn_num; i++) {
-		struct rockchip_thermal_sensor *sensor = &thermal->sensors[i];
-
-		rockchip_thermal_toggle_sensor(sensor, false);
-	}
+	for (i = 0; i < thermal->chip->chn_num; i++)
+		thermal_zone_set_mode((&thermal->sensors[i])->tzd,
+				      THERMAL_DEVICE_DISABLED);
 
 	thermal->chip->control(thermal->regs, false);
 
@@ -1332,7 +1322,8 @@ static int __maybe_unused rockchip_thermal_suspend(struct device *dev)
 	int i;
 
 	for (i = 0; i < thermal->chip->chn_num; i++)
-		rockchip_thermal_toggle_sensor(&thermal->sensors[i], false);
+		thermal_zone_set_mode((&thermal->sensors[i])->tzd,
+				      THERMAL_DEVICE_DISABLED);
 
 	thermal->chip->control(thermal->regs, false);
 
@@ -1383,7 +1374,8 @@ static int __maybe_unused rockchip_thermal_resume(struct device *dev)
 	thermal->chip->control(thermal->regs, true);
 
 	for (i = 0; i < thermal->chip->chn_num; i++)
-		rockchip_thermal_toggle_sensor(&thermal->sensors[i], true);
+		thermal_zone_set_mode((&thermal->sensors[i])->tzd,
+				      THERMAL_DEVICE_ENABLED);
 
 	pinctrl_pm_select_default_state(dev);
 
diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index 2ba756a..b18cee2 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -224,3 +224,17 @@ int thermal_zone_get_offset(struct thermal_zone_device *tz)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(thermal_zone_get_offset);
+
+/**
+ * thermal_zone_set_mode() - sets mode of thermal zone device
+ * @tz: a valid pointer to a struct thermal_zone_device
+ * @mode: mode to be set
+ *
+ * Return: On success returns 0, an error code otherwise.
+ */
+int thermal_zone_set_mode(struct thermal_zone_device *tz,
+			  enum thermal_device_mode mode)
+{
+	return tz->ops->set_mode(tz, mode);
+}
+EXPORT_SYMBOL_GPL(thermal_zone_set_mode);
diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c
index 2241cea..2e9e762 100644
--- a/drivers/thermal/thermal_sysfs.c
+++ b/drivers/thermal/thermal_sysfs.c
@@ -69,17 +69,19 @@
 {
 	struct thermal_zone_device *tz = to_thermal_zone(dev);
 	int result;
+	enum thermal_device_mode mode;
 
 	if (!tz->ops->set_mode)
 		return -EPERM;
 
 	if (!strncmp(buf, "enabled", sizeof("enabled") - 1))
-		result = tz->ops->set_mode(tz, THERMAL_DEVICE_ENABLED);
+		mode = THERMAL_DEVICE_ENABLED;
 	else if (!strncmp(buf, "disabled", sizeof("disabled") - 1))
-		result = tz->ops->set_mode(tz, THERMAL_DEVICE_DISABLED);
+		mode = THERMAL_DEVICE_DISABLED;
 	else
-		result = -EINVAL;
+		return -EINVAL;
 
+	result = thermal_zone_set_mode(tz, mode);
 	if (result)
 		return result;
 
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 5f4705f..9d21fd1 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -452,6 +452,8 @@ struct thermal_cooling_device *
 int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp);
 int thermal_zone_get_slope(struct thermal_zone_device *tz);
 int thermal_zone_get_offset(struct thermal_zone_device *tz);
+int thermal_zone_set_mode(struct thermal_zone_device *tz,
+			  enum thermal_device_mode mode);
 
 int get_tz_trend(struct thermal_zone_device *, int);
 struct thermal_instance *get_thermal_instance(struct thermal_zone_device *,
@@ -518,6 +520,9 @@ static inline int thermal_zone_get_slope(
 static inline int thermal_zone_get_offset(
 		struct thermal_zone_device *tz)
 { return -ENODEV; }
+static inline int thermal_zone_set_mode(
+		struct thermal_zone_device *tz, enum thermal_device_mode mode)
+{ return -ENODEV; }
 static inline int get_tz_trend(struct thermal_zone_device *tz, int trip)
 { return -ENODEV; }
 static inline struct thermal_instance *
-- 
1.9.1


  parent reply	other threads:[~2018-10-17 15:53 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20181017155314epcas2p4a5aa24978b36354a2ccb2f9b0fb6f0f6@epcas2p4.samsung.com>
2018-10-17 15:52 ` [PATCH v2 00/17] thermal: enable+check sensor after its setup is finished Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155320epcas2p439b713149d94aa485b3c2ffba063ea03@epcas2p4.samsung.com>
2018-10-17 15:52     ` Bartlomiej Zolnierkiewicz [this message]
2018-11-06  8:11       ` [PATCH v2 01/17] thermal: add thermal_zone_set_mode() helper Zhang Rui
2018-11-06 16:11         ` Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155326epcas2p21d8b703f27fe54561a0f741fa7920dce@epcas2p2.samsung.com>
2018-10-17 15:52     ` [PATCH v2 02/17] thermal: add thermal_zone_device_check() helper Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155332epcas2p499ac9d53678d82a9984b3533e723a0dd@epcas2p4.samsung.com>
2018-10-17 15:52     ` [PATCH v2 03/17] thermal: separate sensor enable and check operations Bartlomiej Zolnierkiewicz
2018-10-26 12:11       ` Amit Kucheria
     [not found]   ` <CGME20181017155338epcas1p3a22cd0b22e757c3e51eb72ccee545478@epcas1p3.samsung.com>
2018-10-17 15:52     ` [PATCH v2 04/17] thermal: separate sensor registration and enable+check operations Bartlomiej Zolnierkiewicz
2018-10-31 12:40       ` Amit Kucheria
     [not found]   ` <CGME20181017155345epcas1p18dee37b9a46f2bf0b68aa3ded43f2717@epcas1p1.samsung.com>
2018-10-17 15:52     ` [PATCH v2 05/17] thermal: bcm2835: enable+check sensor after its setup is finished Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155351epcas1p171637911ef29cdec96dda648cfac51a5@epcas1p1.samsung.com>
2018-10-17 15:52     ` [PATCH v2 06/17] thermal: brcmstb: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155357epcas1p3900b1d3522c636fdee27ab9928c076e1@epcas1p3.samsung.com>
2018-10-17 15:52     ` [PATCH v2 07/17] thermal: hisi_thermal: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155403epcas2p1ed9777e96c6b2c77c2c5b67466be9843@epcas2p1.samsung.com>
2018-10-17 15:52     ` [PATCH v2 08/17] thermal: qcom: tsens: " Bartlomiej Zolnierkiewicz
2018-10-26 12:11       ` Amit Kucheria
2018-10-26 12:39         ` Amit Kucheria
     [not found]   ` <CGME20181017155409epcas2p41b5770668abdb4af99646841a3dd24ec@epcas2p4.samsung.com>
2018-10-17 15:52     ` [PATCH v2 09/17] thermal: qoriq: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155416epcas2p32f63571e9c06cd1aba2b40bcf23de8e1@epcas2p3.samsung.com>
2018-10-17 15:52     ` [PATCH v2 10/17] thermal: rcar_gen3_thermal: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155422epcas1p1644d897c62ceb36b57d33ecd4e3bc81c@epcas1p1.samsung.com>
2018-10-17 15:52     ` [PATCH v2 11/17] thermal: rockchip_thermal: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155428epcas2p1aca0b5e7b30b89db7be7026dfa740fc6@epcas2p1.samsung.com>
2018-10-17 15:52     ` [PATCH v2 12/17] thermal: exynos: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155434epcas1p33a6de1fda3c69cc966f954796a95a935@epcas1p3.samsung.com>
2018-10-17 15:52     ` [PATCH v2 13/17] thermal: tegra: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155440epcas1p12c33048a8c1c083496d1a8996591d884@epcas1p1.samsung.com>
2018-10-17 15:52     ` [PATCH v2 14/17] thermal: ti-soc-thermal: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155447epcas2p2db761f6575de357b65eb5e39b709fead@epcas2p2.samsung.com>
2018-10-17 15:52     ` [PATCH v2 15/17] thermal: uniphier: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155453epcas1p3be6976375c18583bcbebc7ff7853ae50@epcas1p3.samsung.com>
2018-10-17 15:52     ` [PATCH v2 16/17] thermal: zx2967: " Bartlomiej Zolnierkiewicz
     [not found]   ` <CGME20181017155459epcas1p470bd73f433cdbb0f7a11aa8d46212e4e@epcas1p4.samsung.com>
2018-10-17 15:52     ` [PATCH v2 17/17] thermal: warn on attempts to read temperature on disabled sensors Bartlomiej Zolnierkiewicz
     [not found]   ` <1541387097.2124.9.camel@intel.com>
2018-11-05 16:35     ` [PATCH v2 00/17] thermal: enable+check sensor after its setup is finished Bartlomiej Zolnierkiewicz
2018-11-06  0:46       ` Eduardo Valentin
2018-11-06  7:34       ` Zhang Rui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1539791563-5959-2-git-send-email-b.zolnierkie@samsung.com \
    --to=b.zolnierkie@samsung.com \
    --cc=amit.kucheria@linaro.org \
    --cc=baoyou.xie@linaro.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=edubezval@gmail.com \
    --cc=eric@anholt.net \
    --cc=heiko@sntech.de \
    --cc=j-keerthy@ti.com \
    --cc=jonathanh@nvidia.com \
    --cc=jun.nie@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mmayer@broadcom.com \
    --cc=rui.zhang@intel.com \
    --cc=shawnguo@kernel.org \
    --cc=stefan.wahren@i2se.com \
    --cc=thierry.reding@gmail.com \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).