瀏覽代碼

drm/nouveau/fan: rewrite the fan tachometer driver to get more precision, faster

The previous driver waited for 250ms to accumulate data. This version times a
complete fan rotation and extrapolates to RPM.

The fan rotational speed should now be read in less than 250ms (worst case)
and usually in less 50ms.

Signed-off-by: Martin Peres <martin.peres@labri.fr>
Reviewed-by: Ben Skeggs <bskeggs@redhat.com>
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Martin Peres 12 年之前
父節點
當前提交
bf6546b421
共有 1 個文件被更改,包括 16 次插入9 次删除
  1. 16 9
      drivers/gpu/drm/nouveau/core/subdev/therm/fan.c

+ 16 - 9
drivers/gpu/drm/nouveau/core/subdev/therm/fan.c

@@ -105,30 +105,37 @@ nouveau_therm_fan_sense(struct nouveau_therm *therm)
 	struct nouveau_gpio *gpio = nouveau_gpio(therm);
 	struct nouveau_gpio *gpio = nouveau_gpio(therm);
 	struct dcb_gpio_func func;
 	struct dcb_gpio_func func;
 	u32 cycles, cur, prev;
 	u32 cycles, cur, prev;
-	u64 start;
+	u64 start, end, tach;
 
 
 	if (gpio->find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, &func))
 	if (gpio->find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, &func))
 		return -ENODEV;
 		return -ENODEV;
 
 
-	/* Monitor the GPIO input 0x3b for 250ms.
+	/* Time a complete rotation and extrapolate to RPM:
 	 * When the fan spins, it changes the value of GPIO FAN_SENSE.
 	 * When the fan spins, it changes the value of GPIO FAN_SENSE.
-	 * We get 4 changes (0 -> 1 -> 0 -> 1 -> [...]) per complete rotation.
+	 * We get 4 changes (0 -> 1 -> 0 -> 1) per complete rotation.
 	 */
 	 */
 	start = ptimer->read(ptimer);
 	start = ptimer->read(ptimer);
 	prev = gpio->get(gpio, 0, func.func, func.line);
 	prev = gpio->get(gpio, 0, func.func, func.line);
 	cycles = 0;
 	cycles = 0;
 	do {
 	do {
+		usleep_range(500, 1000); /* supports 0 < rpm < 7500 */
+
 		cur = gpio->get(gpio, 0, func.func, func.line);
 		cur = gpio->get(gpio, 0, func.func, func.line);
 		if (prev != cur) {
 		if (prev != cur) {
+			if (!start)
+				start = ptimer->read(ptimer);
 			cycles++;
 			cycles++;
 			prev = cur;
 			prev = cur;
 		}
 		}
-
-		usleep_range(500, 1000); /* supports 0 < rpm < 7500 */
-	} while (ptimer->read(ptimer) - start < 250000000);
-
-	/* interpolate to get rpm */
-	return cycles / 4 * 4 * 60;
+	} while (cycles < 5 && ptimer->read(ptimer) - start < 250000000);
+	end = ptimer->read(ptimer);
+
+	if (cycles == 5) {
+		tach = (u64)60000000000;
+		do_div(tach, (end - start));
+		return tach;
+	} else
+		return 0;
 }
 }
 
 
 static void
 static void