All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau: Add fine-grain temperature reporting
@ 2020-08-12 20:49 ` Jeremy Cline
  0 siblings, 0 replies; 38+ messages in thread
From: Jeremy Cline @ 2020-08-12 20:49 UTC (permalink / raw)
  To: Ben Skeggs
  Cc: David Airlie, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW, Daniel Vetter

Commit d32656373857 ("drm/nouveau/therm/gp100: initial implementation of
new gp1xx temperature sensor") added support for reading finer-grain
temperatures, but continued to report temperatures in 1 degree Celsius
increments via nvkm_therm_temp_get().

Rather than altering nvkm_therm_temp_get() to report finer-grain
temperatures, which would be inconvenient for other users of the
function, a second interface has been added to line up with hwmon's
native unit of temperature.

Signed-off-by: Jeremy Cline <jcline-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
 .../drm/nouveau/include/nvkm/subdev/therm.h   | 18 +++++++++++++
 drivers/gpu/drm/nouveau/nouveau_hwmon.c       |  4 +--
 .../gpu/drm/nouveau/nvkm/subdev/therm/base.c  | 16 ++++++++++++
 .../gpu/drm/nouveau/nvkm/subdev/therm/gp100.c | 25 +++++++++++++++++--
 .../gpu/drm/nouveau/nvkm/subdev/therm/priv.h  |  1 +
 5 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h
index 62c34f98c930..7b9928dd001c 100644
--- a/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h
+++ b/drivers/gpu/drm/nouveau/include/nvkm/subdev/therm.h
@@ -100,6 +100,24 @@ struct nvkm_therm {
 };
 
 int nvkm_therm_temp_get(struct nvkm_therm *);
+
+/**
+ * nvkm_therm_temp_millidegree_get() - get the temperature in millidegrees
+ * @therm: The thermal device to read from.
+ *
+ * This interface reports temperatures in units of millidegree Celsius to
+ * align with the hwmon API. Some cards may only be capable of reporting in
+ * units of Celsius, and those that report finer grain temperatures may not be
+ * capable of millidegree Celsius accuracy,
+ *
+ * For cases where millidegree temperature is too fine-grain, the
+ * nvkm_therm_temp_get() interface reports temperatures in one degree Celsius
+ * increments.
+ *
+ * Return: The temperature in millidegrees Celsius, or -ENODEV if temperature
+ *         reporting is not supported.
+ */
+int nvkm_therm_temp_millidegree_get(struct nvkm_therm *therm);
 int nvkm_therm_fan_sense(struct nvkm_therm *);
 int nvkm_therm_cstate(struct nvkm_therm *, int, int);
 void nvkm_therm_clkgate_init(struct nvkm_therm *,
diff --git a/drivers/gpu/drm/nouveau/nouveau_hwmon.c b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
index 1c3104d20571..e96355f93ce5 100644
--- a/drivers/gpu/drm/nouveau/nouveau_hwmon.c
+++ b/drivers/gpu/drm/nouveau/nouveau_hwmon.c
@@ -428,8 +428,8 @@ nouveau_temp_read(struct device *dev, u32 attr, int channel, long *val)
 	case hwmon_temp_input:
 		if (drm_dev->switch_power_state != DRM_SWITCH_POWER_ON)
 			return -EINVAL;
-		ret = nvkm_therm_temp_get(therm);
-		*val = ret < 0 ? ret : (ret * 1000);
+		ret = nvkm_therm_temp_millidegree_get(therm);
+		*val = ret;
 		break;
 	case hwmon_temp_max:
 		*val = therm->attr_get(therm, NVKM_THERM_ATTR_THRS_DOWN_CLK)
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
index 4a4d1e224126..e655b32c78b8 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/base.c
@@ -34,6 +34,22 @@ nvkm_therm_temp_get(struct nvkm_therm *therm)
 	return -ENODEV;
 }
 
+int
+nvkm_therm_temp_millidegree_get(struct nvkm_therm *therm)
+{
+	int ret = -ENODEV;
+
+	if (therm->func->temp_millidegree_get)
+		return therm->func->temp_millidegree_get(therm);
+
+	if (therm->func->temp_get) {
+		ret = therm->func->temp_get(therm);
+		if (ret > 0)
+			ret *= 1000;
+	}
+	return ret;
+}
+
 static int
 nvkm_therm_update_trip(struct nvkm_therm *therm)
 {
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gp100.c b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gp100.c
index 9f0dea3f61dc..4c3c2895a3cb 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gp100.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/gp100.c
@@ -24,7 +24,7 @@
 #include "priv.h"
 
 static int
-gp100_temp_get(struct nvkm_therm *therm)
+gp100_temp_get_raw(struct nvkm_therm *therm)
 {
 	struct nvkm_device *device = therm->subdev.device;
 	struct nvkm_subdev *subdev = &therm->subdev;
@@ -37,14 +37,35 @@ gp100_temp_get(struct nvkm_therm *therm)
 
 	/* device valid */
 	if (tsensor & 0x20000000)
-		return (inttemp >> 8);
+		return inttemp;
 	else
 		return -ENODEV;
 }
 
+static int
+gp100_temp_millidegree_get(struct nvkm_therm *therm)
+{
+	int raw_temp = gp100_temp_get_raw(therm);
+
+	if (raw_temp < 0)
+		return raw_temp;
+	return raw_temp * 1000 >> 8;
+}
+
+static int
+gp100_temp_get(struct nvkm_therm *therm)
+{
+	int raw_temp = gp100_temp_get_raw(therm);
+
+	if (raw_temp < 0)
+		return raw_temp;
+	return raw_temp >> 8;
+}
+
 static const struct nvkm_therm_func
 gp100_therm = {
 	.temp_get = gp100_temp_get,
+	.temp_millidegree_get = gp100_temp_millidegree_get,
 	.program_alarms = nvkm_therm_program_alarms_polling,
 };
 
diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
index 21659daf1864..a53068b4f0b9 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/therm/priv.h
@@ -92,6 +92,7 @@ struct nvkm_therm_func {
 	int (*pwm_clock)(struct nvkm_therm *, int line);
 
 	int (*temp_get)(struct nvkm_therm *);
+	int (*temp_millidegree_get)(struct nvkm_therm *therm);
 
 	int (*fan_sense)(struct nvkm_therm *);
 
-- 
2.26.2

^ permalink raw reply related	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2020-09-17 14:26 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-12 20:49 [PATCH] drm/nouveau: Add fine-grain temperature reporting Jeremy Cline
2020-08-12 20:49 ` Jeremy Cline
2020-08-12 20:49 ` Jeremy Cline
     [not found] ` <20200812204952.1921587-1-jcline-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2020-08-13 12:43   ` Karol Herbst
2020-08-13 12:43     ` Karol Herbst
2020-08-13 12:43     ` Karol Herbst
2020-09-09  4:05   ` Ben Skeggs
2020-09-09  4:05     ` [Nouveau] " Ben Skeggs
2020-09-09  4:05     ` Ben Skeggs
     [not found]     ` <CACAvsv71oxCYB1+LCAUHD5v_NGAP-DpxPY_dPz53iw2=91KAJg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-09-09  8:22       ` Karol Herbst
2020-09-09  8:22         ` [Nouveau] " Karol Herbst
2020-09-09  8:22         ` Karol Herbst
     [not found]         ` <CACO55tvv6REmNzZZyyRSJyRT5z-xEf38+tk9cDnft63DX5JQUw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-09-09 14:07           ` Jeremy Cline
2020-09-09 14:07             ` [Nouveau] " Jeremy Cline
2020-09-09 14:07             ` Jeremy Cline
2020-09-10  4:23             ` Ben Skeggs
2020-09-10  4:23               ` Ben Skeggs
2020-09-16 19:47   ` [PATCH v2 0/2] " Jeremy Cline
2020-09-16 19:47     ` Jeremy Cline
2020-09-16 19:47     ` Jeremy Cline
     [not found]     ` <20200916194711.999602-1-jcline-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2020-09-16 19:47       ` [PATCH v2 1/2] drm/nouveau: return temperatures in temp_get() via parameter Jeremy Cline
2020-09-16 19:47         ` Jeremy Cline
2020-09-16 19:47         ` Jeremy Cline
     [not found]         ` <20200916194711.999602-2-jcline-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2020-09-16 20:01           ` Karol Herbst
2020-09-16 20:01             ` Karol Herbst
2020-09-16 20:01             ` Karol Herbst
     [not found]             ` <CACO55tueUdL0Jp15keCUpFzBuSM8gimkth7VUZxhnaijHOXKxw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-09-16 20:03               ` Karol Herbst
2020-09-16 20:03                 ` Karol Herbst
2020-09-16 20:03                 ` Karol Herbst
     [not found]                 ` <CACO55tuKO61iQQEmrFwct2NDxgbgqMYBnrvtXaDQRu95dZfk6A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-09-17 14:11                   ` Jeremy Cline
2020-09-17 14:11                     ` Jeremy Cline
2020-09-17 14:11                     ` Jeremy Cline
     [not found]                     ` <20200917141113.GA750296-PmJJM/U+xkPZ+VzJOa5vwg@public.gmane.org>
2020-09-17 14:23                       ` Karol Herbst
2020-09-17 14:23                         ` Karol Herbst
2020-09-17 14:23                         ` Karol Herbst
2020-09-16 19:47       ` [PATCH v2 2/2] drm/nouveau: Add fine-grain temperature reporting Jeremy Cline
2020-09-16 19:47         ` Jeremy Cline
2020-09-16 19:47         ` Jeremy Cline

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.