Lines Matching +full:fan +full:- +full:0

27 #include <subdev/bios/fan.h>
32 nvkm_fan_update(struct nvkm_fan *fan, bool immediate, int target) in nvkm_fan_update() argument
34 struct nvkm_therm *therm = fan->parent; in nvkm_fan_update()
35 struct nvkm_subdev *subdev = &therm->subdev; in nvkm_fan_update()
36 struct nvkm_timer *tmr = subdev->device->timer; in nvkm_fan_update()
38 int ret = 0; in nvkm_fan_update()
41 /* update target fan speed, restricting to allowed range */ in nvkm_fan_update()
42 spin_lock_irqsave(&fan->lock, flags); in nvkm_fan_update()
43 if (target < 0) in nvkm_fan_update()
44 target = fan->percent; in nvkm_fan_update()
45 target = max_t(u8, target, fan->bios.min_duty); in nvkm_fan_update()
46 target = min_t(u8, target, fan->bios.max_duty); in nvkm_fan_update()
47 if (fan->percent != target) { in nvkm_fan_update()
48 nvkm_debug(subdev, "FAN target: %d\n", target); in nvkm_fan_update()
49 fan->percent = target; in nvkm_fan_update()
53 duty = fan->get(therm); in nvkm_fan_update()
55 spin_unlock_irqrestore(&fan->lock, flags); in nvkm_fan_update()
56 return 0; in nvkm_fan_update()
60 if (!immediate && duty >= 0) { in nvkm_fan_update()
63 * it is meant to bump the fan speed more incrementally in nvkm_fan_update()
68 duty = max(duty - 3, target); in nvkm_fan_update()
73 nvkm_debug(subdev, "FAN update: %d\n", duty); in nvkm_fan_update()
74 ret = fan->set(therm, duty); in nvkm_fan_update()
76 spin_unlock_irqrestore(&fan->lock, flags); in nvkm_fan_update()
80 /* fan speed updated, drop the fan lock before grabbing the in nvkm_fan_update()
81 * alarm-scheduling lock and risking a deadlock in nvkm_fan_update()
83 spin_unlock_irqrestore(&fan->lock, flags); in nvkm_fan_update()
85 /* schedule next fan update, if not at target speed already */ in nvkm_fan_update()
87 u16 bump_period = fan->bios.bump_period; in nvkm_fan_update()
88 u16 slow_down_period = fan->bios.slow_down_period; in nvkm_fan_update()
98 nvkm_timer_alarm(tmr, delay * 1000 * 1000, &fan->alarm); in nvkm_fan_update()
107 struct nvkm_fan *fan = container_of(alarm, struct nvkm_fan, alarm); in nvkm_fan_alarm() local
108 nvkm_fan_update(fan, false, -1); in nvkm_fan_alarm()
114 return therm->fan->get(therm); in nvkm_therm_fan_get()
120 return nvkm_fan_update(therm->fan, immediate, percent); in nvkm_therm_fan_set()
126 struct nvkm_device *device = therm->subdev.device; in nvkm_therm_fan_sense()
127 struct nvkm_timer *tmr = device->timer; in nvkm_therm_fan_sense()
128 struct nvkm_gpio *gpio = device->gpio; in nvkm_therm_fan_sense()
132 if (therm->func->fan_sense) in nvkm_therm_fan_sense()
133 return therm->func->fan_sense(therm); in nvkm_therm_fan_sense()
135 if (therm->fan->tach.func == DCB_GPIO_UNUSED) in nvkm_therm_fan_sense()
136 return -ENODEV; in nvkm_therm_fan_sense()
139 * When the fan spins, it changes the value of GPIO FAN_SENSE. in nvkm_therm_fan_sense()
140 * We get 4 changes (0 -> 1 -> 0 -> 1) per complete rotation. in nvkm_therm_fan_sense()
143 prev = nvkm_gpio_get(gpio, 0, therm->fan->tach.func, in nvkm_therm_fan_sense()
144 therm->fan->tach.line); in nvkm_therm_fan_sense()
145 cycles = 0; in nvkm_therm_fan_sense()
147 usleep_range(500, 1000); /* supports 0 < rpm < 7500 */ in nvkm_therm_fan_sense()
149 cur = nvkm_gpio_get(gpio, 0, therm->fan->tach.func, in nvkm_therm_fan_sense()
150 therm->fan->tach.line); in nvkm_therm_fan_sense()
157 } while (cycles < 5 && nvkm_timer_read(tmr) - start < 250000000); in nvkm_therm_fan_sense()
162 do_div(tach, (end - start)); in nvkm_therm_fan_sense()
165 return 0; in nvkm_therm_fan_sense()
177 if (therm->mode != NVKM_THERM_CTRL_MANUAL) in nvkm_therm_fan_user_set()
178 return -EINVAL; in nvkm_therm_fan_user_set()
186 therm->fan->bios.pwm_freq = 0; in nvkm_therm_fan_set_defaults()
187 therm->fan->bios.min_duty = 0; in nvkm_therm_fan_set_defaults()
188 therm->fan->bios.max_duty = 100; in nvkm_therm_fan_set_defaults()
189 therm->fan->bios.bump_period = 500; in nvkm_therm_fan_set_defaults()
190 therm->fan->bios.slow_down_period = 2000; in nvkm_therm_fan_set_defaults()
191 therm->fan->bios.linear_min_temp = 40; in nvkm_therm_fan_set_defaults()
192 therm->fan->bios.linear_max_temp = 85; in nvkm_therm_fan_set_defaults()
198 if (therm->fan->bios.min_duty > 100) in nvkm_therm_fan_safety_checks()
199 therm->fan->bios.min_duty = 100; in nvkm_therm_fan_safety_checks()
200 if (therm->fan->bios.max_duty > 100) in nvkm_therm_fan_safety_checks()
201 therm->fan->bios.max_duty = 100; in nvkm_therm_fan_safety_checks()
203 if (therm->fan->bios.min_duty > therm->fan->bios.max_duty) in nvkm_therm_fan_safety_checks()
204 therm->fan->bios.min_duty = therm->fan->bios.max_duty; in nvkm_therm_fan_safety_checks()
210 return 0; in nvkm_therm_fan_init()
216 struct nvkm_timer *tmr = therm->subdev.device->timer; in nvkm_therm_fan_fini()
218 nvkm_timer_alarm(tmr, 0, &therm->fan->alarm); in nvkm_therm_fan_fini()
219 return 0; in nvkm_therm_fan_fini()
225 struct nvkm_subdev *subdev = &therm->subdev; in nvkm_therm_fan_ctor()
226 struct nvkm_device *device = subdev->device; in nvkm_therm_fan_ctor()
227 struct nvkm_gpio *gpio = device->gpio; in nvkm_therm_fan_ctor()
228 struct nvkm_bios *bios = device->bios; in nvkm_therm_fan_ctor()
232 /* attempt to locate a drivable fan, and determine control method */ in nvkm_therm_fan_ctor()
233 ret = nvkm_gpio_find(gpio, 0, DCB_GPIO_FAN, 0xff, &func); in nvkm_therm_fan_ctor()
234 if (ret == 0) { in nvkm_therm_fan_ctor()
236 if (func.line != 16 && func.log[0] & DCB_GPIO_LOG_DIR_IN) { in nvkm_therm_fan_ctor()
238 ret = -EINVAL; in nvkm_therm_fan_ctor()
241 if (ret != 0) in nvkm_therm_fan_ctor()
246 /* no controllable fan found, create a dummy fan module */ in nvkm_therm_fan_ctor()
247 if (ret != 0) { in nvkm_therm_fan_ctor()
253 nvkm_debug(subdev, "FAN control: %s\n", therm->fan->type); in nvkm_therm_fan_ctor()
256 therm->fan->percent = nvkm_therm_fan_get(therm); in nvkm_therm_fan_ctor()
259 ret = nvkm_gpio_find(gpio, 0, DCB_GPIO_FAN_SENSE, 0xff, in nvkm_therm_fan_ctor()
260 &therm->fan->tach); in nvkm_therm_fan_ctor()
262 therm->fan->tach.func = DCB_GPIO_UNUSED; in nvkm_therm_fan_ctor()
264 /* initialise fan bump/slow update handling */ in nvkm_therm_fan_ctor()
265 therm->fan->parent = therm; in nvkm_therm_fan_ctor()
266 nvkm_alarm_init(&therm->fan->alarm, nvkm_fan_alarm); in nvkm_therm_fan_ctor()
267 spin_lock_init(&therm->fan->lock); in nvkm_therm_fan_ctor()
271 nvbios_perf_fan_parse(bios, &therm->fan->perf); in nvkm_therm_fan_ctor()
272 if (!nvbios_fan_parse(bios, &therm->fan->bios)) { in nvkm_therm_fan_ctor()
273 nvkm_debug(subdev, "parsing the fan table failed\n"); in nvkm_therm_fan_ctor()
274 if (nvbios_therm_fan_parse(bios, &therm->fan->bios)) in nvkm_therm_fan_ctor()
275 nvkm_error(subdev, "parsing both fan tables failed\n"); in nvkm_therm_fan_ctor()
278 return 0; in nvkm_therm_fan_ctor()