aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Peres <martin.peres@labri.fr>2012-09-01 21:20:45 -0400
committerBen Skeggs <bskeggs@redhat.com>2012-10-02 23:13:14 -0400
commitbf6546b4219d2b188529f3242efda4048f5b1b41 (patch)
tree36c1d3d3c3becdcda11bfdda002dde40b8b2f4aa
parentaa1b9b4836a8ab093ec06b0780553566a5430da7 (diff)
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>
-rw-r--r--drivers/gpu/drm/nouveau/core/subdev/therm/fan.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c b/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
index 9ad6e166dd75..b7339b52559e 100644
--- a/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
+++ b/drivers/gpu/drm/nouveau/core/subdev/therm/fan.c
@@ -105,30 +105,37 @@ nouveau_therm_fan_sense(struct nouveau_therm *therm)
105 struct nouveau_gpio *gpio = nouveau_gpio(therm); 105 struct nouveau_gpio *gpio = nouveau_gpio(therm);
106 struct dcb_gpio_func func; 106 struct dcb_gpio_func func;
107 u32 cycles, cur, prev; 107 u32 cycles, cur, prev;
108 u64 start; 108 u64 start, end, tach;
109 109
110 if (gpio->find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, &func)) 110 if (gpio->find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, &func))
111 return -ENODEV; 111 return -ENODEV;
112 112
113 /* Monitor the GPIO input 0x3b for 250ms. 113 /* Time a complete rotation and extrapolate to RPM:
114 * When the fan spins, it changes the value of GPIO FAN_SENSE. 114 * When the fan spins, it changes the value of GPIO FAN_SENSE.
115 * We get 4 changes (0 -> 1 -> 0 -> 1 -> [...]) per complete rotation. 115 * We get 4 changes (0 -> 1 -> 0 -> 1) per complete rotation.
116 */ 116 */
117 start = ptimer->read(ptimer); 117 start = ptimer->read(ptimer);
118 prev = gpio->get(gpio, 0, func.func, func.line); 118 prev = gpio->get(gpio, 0, func.func, func.line);
119 cycles = 0; 119 cycles = 0;
120 do { 120 do {
121 usleep_range(500, 1000); /* supports 0 < rpm < 7500 */
122
121 cur = gpio->get(gpio, 0, func.func, func.line); 123 cur = gpio->get(gpio, 0, func.func, func.line);
122 if (prev != cur) { 124 if (prev != cur) {
125 if (!start)
126 start = ptimer->read(ptimer);
123 cycles++; 127 cycles++;
124 prev = cur; 128 prev = cur;
125 } 129 }
126 130 } while (cycles < 5 && ptimer->read(ptimer) - start < 250000000);
127 usleep_range(500, 1000); /* supports 0 < rpm < 7500 */ 131 end = ptimer->read(ptimer);
128 } while (ptimer->read(ptimer) - start < 250000000); 132
129 133 if (cycles == 5) {
130 /* interpolate to get rpm */ 134 tach = (u64)60000000000;
131 return cycles / 4 * 4 * 60; 135 do_div(tach, (end - start));
136 return tach;
137 } else
138 return 0;
132} 139}
133 140
134static void 141static void