Lines Matching +full:min +full:- +full:rpm

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
56 #define FCU_RPM_FAIL 0x0b /* fans states in bits 0<1-6>7 */
65 #define FCU_PWM_RPM(x) 0x31 + (x) * 2 /* Get RPM. */
78 int rpm; member
89 /* We can read the PWM and the RPM from a PWM controlled fan.
106 static int fcu_fan_set_rpm(struct fcu_fan *fan, int rpm);
110 int *rpm);
155 return (-1); in fcu_write()
183 return (-1); in fcu_read_1()
205 sc->sc_dev = dev; in fcu_probe()
206 sc->sc_addr = iicbus_get_addr(dev); in fcu_probe()
220 sc->enum_hook.ich_func = fcu_start; in fcu_attach()
221 sc->enum_hook.ich_arg = dev; in fcu_attach()
226 * the master. The openpic on mac-io is controlling the htpic. in fcu_attach()
227 * This one gets attached after the mac-io probing and then the in fcu_attach()
231 if (config_intrhook_establish(&sc->enum_hook) != 0) in fcu_attach()
248 fcu_write(sc->sc_dev, sc->sc_addr, 0xe, buf, 1); in fcu_start()
249 fcu_write(sc->sc_dev, sc->sc_addr, 0x2e, buf, 1); in fcu_start()
250 fcu_read_1(sc->sc_dev, sc->sc_addr, 0, buf); in fcu_start()
253 device_printf(dev, "FCU initialized, RPM shift: %d\n", in fcu_start()
260 config_intrhook_disestablish(&sc->enum_hook); in fcu_start()
265 fcu_fan_set_rpm(struct fcu_fan *fan, int rpm) in fcu_fan_set_rpm() argument
271 sc = device_get_softc(fan->dev); in fcu_fan_set_rpm()
274 rpm = max(fan->fan.min_rpm, rpm); in fcu_fan_set_rpm()
275 rpm = min(fan->fan.max_rpm, rpm); in fcu_fan_set_rpm()
277 if (fan->type == FCU_FAN_RPM) { in fcu_fan_set_rpm()
278 reg = FCU_RPM_SET(fan->id); in fcu_fan_set_rpm()
279 fan->setpoint = rpm; in fcu_fan_set_rpm()
281 device_printf(fan->dev, "Unknown fan type: %d\n", fan->type); in fcu_fan_set_rpm()
285 buf[0] = rpm >> (8 - fcu_rpm_shift); in fcu_fan_set_rpm()
286 buf[1] = rpm << fcu_rpm_shift; in fcu_fan_set_rpm()
288 if (fcu_write(sc->sc_dev, sc->sc_addr, reg, buf, 2) < 0) in fcu_fan_set_rpm()
301 int rpm; in fcu_fan_get_rpm() local
303 sc = device_get_softc(fan->dev); in fcu_fan_get_rpm()
305 if (fan->type == FCU_FAN_RPM) { in fcu_fan_get_rpm()
308 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, &avail) < 0) in fcu_fan_get_rpm()
309 return (-1); in fcu_fan_get_rpm()
310 if ((avail & (1 << fan->id)) == 0) { in fcu_fan_get_rpm()
311 device_printf(fan->dev, in fcu_fan_get_rpm()
312 "RPM Fan not available ID: %d\n", fan->id); in fcu_fan_get_rpm()
313 return (-1); in fcu_fan_get_rpm()
317 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, &fail) < 0) in fcu_fan_get_rpm()
318 return (-1); in fcu_fan_get_rpm()
319 if ((fail & (1 << fan->id)) != 0) { in fcu_fan_get_rpm()
320 device_printf(fan->dev, in fcu_fan_get_rpm()
321 "RPM Fan failed ID: %d\n", fan->id); in fcu_fan_get_rpm()
322 return (-1); in fcu_fan_get_rpm()
326 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, &active) < 0) in fcu_fan_get_rpm()
327 return (-1); in fcu_fan_get_rpm()
328 if ((active & (1 << fan->id)) == 0) { in fcu_fan_get_rpm()
329 device_printf(fan->dev, "RPM Fan not active ID: %d\n", in fcu_fan_get_rpm()
330 fan->id); in fcu_fan_get_rpm()
331 return (-1); in fcu_fan_get_rpm()
333 reg = FCU_RPM_READ(fan->id); in fcu_fan_get_rpm()
336 device_printf(fan->dev, "Unknown fan type: %d\n", fan->type); in fcu_fan_get_rpm()
337 return (-1); in fcu_fan_get_rpm()
340 /* It seems that we can read the fans rpm. */ in fcu_fan_get_rpm()
341 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, buff) < 0) in fcu_fan_get_rpm()
342 return (-1); in fcu_fan_get_rpm()
344 rpm = (buff[0] << (8 - fcu_rpm_shift)) | buff[1] >> fcu_rpm_shift; in fcu_fan_get_rpm()
346 return (rpm); in fcu_fan_get_rpm()
356 sc = device_get_softc(fan->dev); in fcu_fan_set_pwm()
359 pwm = max(fan->fan.min_rpm, pwm); in fcu_fan_set_pwm()
360 pwm = min(fan->fan.max_rpm, pwm); in fcu_fan_set_pwm()
362 if (fan->type == FCU_FAN_PWM) { in fcu_fan_set_pwm()
363 reg = FCU_PWM_SGET(fan->id); in fcu_fan_set_pwm()
368 fan->setpoint = pwm; in fcu_fan_set_pwm()
370 device_printf(fan->dev, "Unknown fan type: %d\n", fan->type); in fcu_fan_set_pwm()
376 if (fcu_write(sc->sc_dev, sc->sc_addr, reg, buf, 1) < 0) in fcu_fan_set_pwm()
382 fcu_fan_get_pwm(device_t dev, struct fcu_fan *fan, int *pwm, int *rpm) in fcu_fan_get_pwm() argument
391 if (fan->type == FCU_FAN_PWM) { in fcu_fan_get_pwm()
394 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, &avail) < 0) in fcu_fan_get_pwm()
395 return (-1); in fcu_fan_get_pwm()
396 if ((avail & (1 << fan->id)) == 0) { in fcu_fan_get_pwm()
398 fan->id); in fcu_fan_get_pwm()
399 return (-1); in fcu_fan_get_pwm()
403 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, &fail) < 0) in fcu_fan_get_pwm()
404 return (-1); in fcu_fan_get_pwm()
405 if ((fail & (1 << fan->id)) != 0) { in fcu_fan_get_pwm()
406 device_printf(dev, "PWM Fan failed ID: %d\n", fan->id); in fcu_fan_get_pwm()
407 return (-1); in fcu_fan_get_pwm()
411 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, &active) < 0) in fcu_fan_get_pwm()
412 return (-1); in fcu_fan_get_pwm()
413 if ((active & (1 << fan->id)) == 0) { in fcu_fan_get_pwm()
415 fan->id); in fcu_fan_get_pwm()
416 return (-1); in fcu_fan_get_pwm()
418 reg = FCU_PWM_SGET(fan->id); in fcu_fan_get_pwm()
420 device_printf(dev, "Unknown fan type: %d\n", fan->type); in fcu_fan_get_pwm()
425 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, buf) < 0) in fcu_fan_get_pwm()
426 return (-1); in fcu_fan_get_pwm()
430 /* Now read the rpm. */ in fcu_fan_get_pwm()
431 reg = FCU_PWM_RPM(fan->id); in fcu_fan_get_pwm()
432 if (fcu_read_1(sc->sc_dev, sc->sc_addr, reg, buf) < 0) in fcu_fan_get_pwm()
433 return (-1); in fcu_fan_get_pwm()
435 *rpm = (buf[0] << (8 - fcu_rpm_shift)) | buf[1] >> fcu_rpm_shift; in fcu_fan_get_pwm()
442 * and we have allocated memory for sc->sc_fans, we fill in the properties.
459 prop_len = OF_getprop(child, "hwctrl-location", location, in fcu_fill_fan_prop()
462 if (sc->sc_fans != NULL) { in fcu_fill_fan_prop()
463 strcpy(sc->sc_fans[i].fan.name, location + len); in fcu_fill_fan_prop()
469 if (sc->sc_fans == NULL) in fcu_fill_fan_prop()
476 prop_len = OF_getprop(child, "hwctrl-type", type, sizeof(type)); in fcu_fill_fan_prop()
478 if (strcmp(type + len, "fan-rpm") == 0) in fcu_fill_fan_prop()
479 sc->sc_fans[i].type = FCU_FAN_RPM; in fcu_fill_fan_prop()
481 sc->sc_fans[i].type = FCU_FAN_PWM; in fcu_fill_fan_prop()
488 prop_len = OF_getprop(child, "hwctrl-id", id, sizeof(id)); in fcu_fill_fan_prop()
490 sc->sc_fans[j].id = ((id[j] >> 8) & 0x0f) % 8; in fcu_fill_fan_prop()
493 prop_len = OF_getprop(child, "hwctrl-zone", id, sizeof(id)); in fcu_fill_fan_prop()
495 sc->sc_fans[j].fan.zone = id[j]; in fcu_fill_fan_prop()
499 sc->sc_fans[j].dev = sc->sc_dev; in fcu_fill_fan_prop()
500 if (sc->sc_fans[j].type == FCU_FAN_RPM) { in fcu_fill_fan_prop()
501 sc->sc_fans[j].fan.min_rpm = 4800 >> fcu_rpm_shift; in fcu_fill_fan_prop()
502 sc->sc_fans[j].fan.max_rpm = 56000 >> fcu_rpm_shift; in fcu_fill_fan_prop()
503 sc->sc_fans[j].setpoint = in fcu_fill_fan_prop()
504 fcu_fan_get_rpm(&sc->sc_fans[j]); in fcu_fill_fan_prop()
505 sc->sc_fans[j].fan.read = in fcu_fill_fan_prop()
507 sc->sc_fans[j].fan.set = in fcu_fill_fan_prop()
510 sc->sc_fans[j].fan.min_rpm = 30; /* Percent */ in fcu_fill_fan_prop()
511 sc->sc_fans[j].fan.max_rpm = 100; in fcu_fill_fan_prop()
512 sc->sc_fans[j].fan.read = NULL; in fcu_fill_fan_prop()
513 sc->sc_fans[j].fan.set = in fcu_fill_fan_prop()
516 sc->sc_fans[j].fan.default_rpm = sc->sc_fans[j].fan.max_rpm; in fcu_fill_fan_prop()
528 int rpm = 0, pwm = 0, error = 0; in fcu_fanrpm_sysctl() local
532 fan = &sc->sc_fans[arg2 & 0x00ff]; in fcu_fanrpm_sysctl()
533 if (fan->type == FCU_FAN_RPM) { in fcu_fanrpm_sysctl()
534 rpm = fcu_fan_get_rpm(fan); in fcu_fanrpm_sysctl()
535 if (rpm < 0) in fcu_fanrpm_sysctl()
537 error = sysctl_handle_int(oidp, &rpm, 0, req); in fcu_fanrpm_sysctl()
539 error = fcu_fan_get_pwm(fcu, fan, &pwm, &rpm); in fcu_fanrpm_sysctl()
548 error = sysctl_handle_int(oidp, &rpm, 0, req); in fcu_fanrpm_sysctl()
556 /* We can only read the RPM from a PWM controlled fan, so return. */ in fcu_fanrpm_sysctl()
560 if (error || !req->newptr) in fcu_fanrpm_sysctl()
563 if (fan->type == FCU_FAN_RPM) in fcu_fanrpm_sysctl()
564 return (fcu_fan_set_rpm(fan, rpm)); in fcu_fanrpm_sysctl()
580 sc->sc_nfans = 0; in fcu_attach_fans()
583 sc->sc_nfans = fcu_fill_fan_prop(dev); in fcu_attach_fans()
585 device_printf(dev, "%d fans detected!\n", sc->sc_nfans); in fcu_attach_fans()
587 if (sc->sc_nfans == 0) { in fcu_attach_fans()
592 sc->sc_fans = malloc(sc->sc_nfans * sizeof(struct fcu_fan), M_FCU, in fcu_attach_fans()
601 sc->sc_nfans = fcu_fill_fan_prop(dev); in fcu_attach_fans()
604 for (i = 0; i < sc->sc_nfans; i++) in fcu_attach_fans()
605 pmac_thermal_fan_register(&sc->sc_fans[i].fan); in fcu_attach_fans()
608 for (i = 0; i < sc->sc_nfans; i++) { in fcu_attach_fans()
609 for (j = 0; j < strlen(sc->sc_fans[i].fan.name); j++) { in fcu_attach_fans()
610 sysctl_name[j] = tolower(sc->sc_fans[i].fan.name[j]); in fcu_attach_fans()
616 if (sc->sc_fans[i].type == FCU_FAN_RPM) { in fcu_attach_fans()
622 &(sc->sc_fans[i].fan.min_rpm), 0, in fcu_attach_fans()
623 "Minimum allowed RPM"); in fcu_attach_fans()
626 &(sc->sc_fans[i].fan.max_rpm), 0, in fcu_attach_fans()
627 "Maximum allowed RPM"); in fcu_attach_fans()
630 "rpm", CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, in fcu_attach_fans()
631 dev, i, fcu_fanrpm_sysctl, "I", "Fan RPM"); in fcu_attach_fans()
633 fcu_fan_get_pwm(dev, &sc->sc_fans[i], in fcu_attach_fans()
634 &sc->sc_fans[i].setpoint, in fcu_attach_fans()
635 &sc->sc_fans[i].rpm); in fcu_attach_fans()
642 &(sc->sc_fans[i].fan.min_rpm), 0, in fcu_attach_fans()
646 &(sc->sc_fans[i].fan.max_rpm), 0, in fcu_attach_fans()
656 "rpm", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_NEEDGIANT, in fcu_attach_fans()
658 "Fan RPM"); in fcu_attach_fans()
662 /* Dump fan location, type & RPM. */ in fcu_attach_fans()
665 for (i = 0; i < sc->sc_nfans; i++) { in fcu_attach_fans()
667 "RPM: %d\n", sc->sc_fans[i].fan.name, in fcu_attach_fans()
668 sc->sc_fans[i].type, sc->sc_fans[i].id, in fcu_attach_fans()
669 (sc->sc_fans[i].type == FCU_FAN_RPM) ? in fcu_attach_fans()
670 sc->sc_fans[i].setpoint : in fcu_attach_fans()
671 sc->sc_fans[i].rpm ); in fcu_attach_fans()