aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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