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

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
85 int rpm; member
88 /* We can read the PWM and the RPM from a PWM controlled fan.
276 sc->sc_cmd_phys = segs[0].ds_addr; in smu_phys_callback()
288 mtx_init(&sc->sc_mtx, "smu", NULL, MTX_DEF); in smu_attach()
289 sc->sc_cur_cmd = NULL; in smu_attach()
290 sc->sc_doorbellirqid = -1; in smu_attach()
292 sc->sc_u3 = 0; in smu_attach()
293 if (OF_finddevice("/u3") != -1) in smu_attach()
294 sc->sc_u3 = 1; in smu_attach()
302 NULL, &(sc->sc_dmatag)); in smu_attach()
303 sc->sc_bt = &bs_le_tag; in smu_attach()
304 bus_space_map(sc->sc_bt, SMU_MAILBOX, 4, 0, &sc->sc_mailbox); in smu_attach()
310 bus_dmamem_alloc(sc->sc_dmatag, (void **)&sc->sc_cmd, BUS_DMA_WAITOK | in smu_attach()
311 BUS_DMA_ZERO, &sc->sc_cmd_dmamap); in smu_attach()
312 bus_dmamap_load(sc->sc_dmatag, sc->sc_cmd_dmamap, in smu_attach()
313 sc->sc_cmd, PAGE_SIZE, smu_phys_callback, sc, 0); in smu_attach()
314 STAILQ_INIT(&sc->sc_cmdq); in smu_attach()
326 /* Some SMUs have RPM and PWM controlled fans which do not sit in smu_attach()
342 if (strncmp(name, "smu-i2c-control", 15) == 0) in smu_attach()
353 sc->sc_cpu_diode_scale = (data[4] << 8) + data[5]; in smu_attach()
354 sc->sc_cpu_diode_offset = (data[6] << 8) + data[7]; in smu_attach()
357 sc->sc_cpu_volt_scale = (data[4] << 8) + data[5]; in smu_attach()
358 sc->sc_cpu_volt_offset = (data[6] << 8) + data[7]; in smu_attach()
359 sc->sc_cpu_curr_scale = (data[8] << 8) + data[9]; in smu_attach()
360 sc->sc_cpu_curr_offset = (data[10] << 8) + data[11]; in smu_attach()
363 sc->sc_slots_pow_scale = (data[4] << 8) + data[5]; in smu_attach()
364 sc->sc_slots_pow_offset = (data[6] << 8) + data[7]; in smu_attach()
369 sc->sc_leddev = led_create(smu_set_sleepled, dev, "sleepled"); in smu_attach()
383 sc->sc_doorbellirqid = 0; in smu_attach()
384 sc->sc_doorbellirq = bus_alloc_resource_any(smu_doorbell, SYS_RES_IRQ, in smu_attach()
385 &sc->sc_doorbellirqid, RF_ACTIVE); in smu_attach()
386 bus_setup_intr(smu_doorbell, sc->sc_doorbellirq, in smu_attach()
388 &sc->sc_doorbellirqcookie); in smu_attach()
389 powerpc_config_intr(rman_get_start(sc->sc_doorbellirq), in smu_attach()
421 mtx_assert(&sc->sc_mtx, MA_OWNED); in smu_send_cmd()
423 if (sc->sc_u3) in smu_send_cmd()
426 sc->sc_cur_cmd = cmd; in smu_send_cmd()
429 sc->sc_cmd->cmd = cmd->cmd; in smu_send_cmd()
430 sc->sc_cmd->len = cmd->len; in smu_send_cmd()
431 memcpy(sc->sc_cmd->data, cmd->data, sizeof(cmd->data)); in smu_send_cmd()
432 bus_dmamap_sync(sc->sc_dmatag, sc->sc_cmd_dmamap, BUS_DMASYNC_PREWRITE); in smu_send_cmd()
433 bus_space_write_4(sc->sc_bt, sc->sc_mailbox, 0, sc->sc_cmd_phys); in smu_send_cmd()
435 /* Flush the cacheline it is in -- SMU bypasses the cache */ in smu_send_cmd()
436 __asm __volatile("sync; dcbf 0,%0; sync" :: "r"(sc->sc_cmd): "memory"); in smu_send_cmd()
456 mtx_lock(&sc->sc_mtx); in smu_doorbell_intr()
458 if (sc->sc_cur_cmd == NULL) /* spurious */ in smu_doorbell_intr()
462 __asm __volatile("dcbf 0,%0; sync" :: "r"(sc->sc_cmd) : "memory"); in smu_doorbell_intr()
464 bus_dmamap_sync(sc->sc_dmatag, sc->sc_cmd_dmamap, BUS_DMASYNC_POSTREAD); in smu_doorbell_intr()
466 sc->sc_cur_cmd->cmd = sc->sc_cmd->cmd; in smu_doorbell_intr()
467 sc->sc_cur_cmd->len = sc->sc_cmd->len; in smu_doorbell_intr()
468 memcpy(sc->sc_cur_cmd->data, sc->sc_cmd->data, in smu_doorbell_intr()
469 sizeof(sc->sc_cmd->data)); in smu_doorbell_intr()
470 wakeup(sc->sc_cur_cmd); in smu_doorbell_intr()
471 sc->sc_cur_cmd = NULL; in smu_doorbell_intr()
472 if (sc->sc_u3) in smu_doorbell_intr()
477 if (STAILQ_FIRST(&sc->sc_cmdq) != NULL) { in smu_doorbell_intr()
478 sc->sc_cur_cmd = STAILQ_FIRST(&sc->sc_cmdq); in smu_doorbell_intr()
479 STAILQ_REMOVE_HEAD(&sc->sc_cmdq, cmd_q); in smu_doorbell_intr()
480 smu_send_cmd(smu, sc->sc_cur_cmd); in smu_doorbell_intr()
483 mtx_unlock(&sc->sc_mtx); in smu_doorbell_intr()
494 cmd_code = cmd->cmd; in smu_run_cmd()
496 mtx_lock(&sc->sc_mtx); in smu_run_cmd()
497 if (sc->sc_cur_cmd != NULL) { in smu_run_cmd()
498 STAILQ_INSERT_TAIL(&sc->sc_cmdq, cmd, cmd_q); in smu_run_cmd()
501 mtx_unlock(&sc->sc_mtx); in smu_run_cmd()
506 if (sc->sc_doorbellirqid < 0) { in smu_run_cmd()
511 } while (sc->sc_cur_cmd != NULL); in smu_run_cmd()
519 mtx_lock(&sc->sc_mtx); in smu_run_cmd()
520 if (cmd->cmd == cmd_code) { /* Never processed */ in smu_run_cmd()
522 if (sc->sc_cur_cmd == cmd) in smu_run_cmd()
523 sc->sc_cur_cmd = NULL; in smu_run_cmd()
525 STAILQ_REMOVE(&sc->sc_cmdq, cmd, smu_cmd, in smu_run_cmd()
527 mtx_unlock(&sc->sc_mtx); in smu_run_cmd()
531 mtx_unlock(&sc->sc_mtx); in smu_run_cmd()
536 if (cmd->cmd == ((~cmd_code) & 0xff)) in smu_run_cmd()
600 if (level->rel_set[0].freq == 10000 /* max */) in smu_cpufreq_pre_change()
609 if (level->rel_set[0].freq < 10000 /* max */) in smu_cpufreq_post_change()
638 if (strcmp(name, "smu-doorbell") != 0) in doorbell_probe()
660 device_t smu = fan->dev; in smu_fan_check_old_style()
665 if (sc->old_style_fans != -1) in smu_fan_check_old_style()
666 return (sc->old_style_fans); in smu_fan_check_old_style()
677 cmd.data[1] = fan->reg; in smu_fan_check_old_style()
683 sc->old_style_fans = (error != 0); in smu_fan_check_old_style()
685 return (sc->old_style_fans); in smu_fan_check_old_style()
689 smu_fan_set_rpm(struct smu_fan *fan, int rpm) in smu_fan_set_rpm() argument
691 device_t smu = fan->dev; in smu_fan_set_rpm()
699 rpm = max(fan->fan.min_rpm, rpm); in smu_fan_set_rpm()
700 rpm = min(fan->fan.max_rpm, rpm); in smu_fan_set_rpm()
704 if (!fan->old_style) { in smu_fan_set_rpm()
707 cmd.data[1] = fan->reg; in smu_fan_set_rpm()
708 cmd.data[2] = (rpm >> 8) & 0xff; in smu_fan_set_rpm()
709 cmd.data[3] = rpm & 0xff; in smu_fan_set_rpm()
713 fan->old_style = 1; in smu_fan_set_rpm()
716 cmd.data[0] = 0x00; /* RPM fan. */ in smu_fan_set_rpm()
717 cmd.data[1] = 1 << fan->reg; in smu_fan_set_rpm()
718 cmd.data[2 + 2*fan->reg] = (rpm >> 8) & 0xff; in smu_fan_set_rpm()
719 cmd.data[3 + 2*fan->reg] = rpm & 0xff; in smu_fan_set_rpm()
724 fan->setpoint = rpm; in smu_fan_set_rpm()
732 device_t smu = fan->dev; in smu_fan_read_rpm()
734 int rpm, error; in smu_fan_read_rpm() local
738 if (!fan->old_style) { in smu_fan_read_rpm()
742 cmd.data[1] = fan->reg; in smu_fan_read_rpm()
746 fan->old_style = 1; in smu_fan_read_rpm()
748 rpm = (cmd.data[0] << 8) | cmd.data[1]; in smu_fan_read_rpm()
751 if (fan->old_style) { in smu_fan_read_rpm()
760 rpm = (cmd.data[fan->reg*2+1] << 8) | cmd.data[fan->reg*2+2]; in smu_fan_read_rpm()
763 return (rpm); in smu_fan_read_rpm()
768 device_t smu = fan->dev; in smu_fan_set_pwm()
776 pwm = max(fan->fan.min_rpm, pwm); in smu_fan_set_pwm()
777 pwm = min(fan->fan.max_rpm, pwm); in smu_fan_set_pwm()
785 if (!fan->old_style) { in smu_fan_set_pwm()
788 cmd.data[1] = fan->reg; in smu_fan_set_pwm()
794 fan->old_style = 1; in smu_fan_set_pwm()
797 if (fan->old_style) { in smu_fan_set_pwm()
800 cmd.data[1] = 1 << fan->reg; in smu_fan_set_pwm()
801 cmd.data[2 + 2*fan->reg] = (pwm >> 8) & 0xff; in smu_fan_set_pwm()
802 cmd.data[3 + 2*fan->reg] = pwm & 0xff; in smu_fan_set_pwm()
807 fan->setpoint = pwm; in smu_fan_set_pwm()
813 smu_fan_read_pwm(struct smu_fan *fan, int *pwm, int *rpm) in smu_fan_read_pwm() argument
815 device_t smu = fan->dev; in smu_fan_read_pwm()
819 if (!fan->old_style) { in smu_fan_read_pwm()
823 cmd.data[1] = fan->reg; in smu_fan_read_pwm()
827 fan->old_style = 1; in smu_fan_read_pwm()
829 *rpm = (cmd.data[0] << 8) | cmd.data[1]; in smu_fan_read_pwm()
832 if (fan->old_style) { in smu_fan_read_pwm()
841 *rpm = (cmd.data[fan->reg*2+1] << 8) | cmd.data[fan->reg*2+2]; in smu_fan_read_pwm()
843 if (fan->old_style) { in smu_fan_read_pwm()
847 cmd.data[1] = 1 << fan->reg; in smu_fan_read_pwm()
853 *pwm = cmd.data[fan->reg*2+2]; in smu_fan_read_pwm()
864 int pwm = 0, rpm, error = 0; in smu_fanrpm_sysctl() local
868 fan = &sc->sc_fans[arg2 & 0xff]; in smu_fanrpm_sysctl()
870 if (fan->type == SMU_FAN_RPM) { in smu_fanrpm_sysctl()
871 rpm = smu_fan_read_rpm(fan); in smu_fanrpm_sysctl()
872 if (rpm < 0) in smu_fanrpm_sysctl()
873 return (rpm); in smu_fanrpm_sysctl()
875 error = sysctl_handle_int(oidp, &rpm, 0, req); in smu_fanrpm_sysctl()
877 error = smu_fan_read_pwm(fan, &pwm, &rpm); in smu_fanrpm_sysctl()
886 error = sysctl_handle_int(oidp, &rpm, 0, req); in smu_fanrpm_sysctl()
893 /* We can only read the RPM from a PWM controlled fan, so return. */ in smu_fanrpm_sysctl()
897 if (error || !req->newptr) in smu_fanrpm_sysctl()
900 sc->sc_lastuserchange = time_uptime; in smu_fanrpm_sysctl()
902 if (fan->type == SMU_FAN_RPM) in smu_fanrpm_sysctl()
903 return (smu_fan_set_rpm(fan, rpm)); in smu_fanrpm_sysctl()
916 fan = &sc->sc_fans[id]; in smu_fill_fan_prop()
919 /* We have either RPM or PWM controlled fans. */ in smu_fill_fan_prop()
920 if (strcmp(type, "fan-rpm-control") == 0) in smu_fill_fan_prop()
921 fan->type = SMU_FAN_RPM; in smu_fill_fan_prop()
923 fan->type = SMU_FAN_PWM; in smu_fill_fan_prop()
925 fan->dev = dev; in smu_fill_fan_prop()
926 fan->old_style = 0; in smu_fill_fan_prop()
927 OF_getprop(child, "reg", &fan->reg, in smu_fill_fan_prop()
929 OF_getprop(child, "min-value", &fan->fan.min_rpm, in smu_fill_fan_prop()
931 OF_getprop(child, "max-value", &fan->fan.max_rpm, in smu_fill_fan_prop()
933 OF_getprop(child, "zone", &fan->fan.zone, in smu_fill_fan_prop()
936 if (OF_getprop(child, "unmanaged-value", in smu_fill_fan_prop()
937 &fan->fan.default_rpm, in smu_fill_fan_prop()
939 fan->fan.default_rpm = fan->fan.max_rpm; in smu_fill_fan_prop()
941 OF_getprop(child, "location", fan->fan.name, in smu_fill_fan_prop()
942 sizeof(fan->fan.name)); in smu_fill_fan_prop()
944 if (fan->type == SMU_FAN_RPM) in smu_fill_fan_prop()
945 fan->setpoint = smu_fan_read_rpm(fan); in smu_fill_fan_prop()
947 smu_fan_read_pwm(fan, &fan->setpoint, &fan->rpm); in smu_fill_fan_prop()
968 if (strncmp(name, "rpm-fans", 9) == 0 || in smu_count_fans()
969 strncmp(name, "pwm-fans", 9) == 0 || in smu_count_fans()
975 if (sc->sc_fans != NULL) { in smu_count_fans()
977 nfans - 1); in smu_count_fans()
1001 sc->sc_nfans = smu_count_fans(dev); in smu_attach_fans()
1002 if (sc->sc_nfans == 0) in smu_attach_fans()
1006 sc->sc_fans = malloc(sc->sc_nfans * sizeof(struct smu_fan), M_SMU, in smu_attach_fans()
1013 for (i = 0; i < sc->sc_nfans; i++) in smu_attach_fans()
1014 pmac_thermal_fan_register(&sc->sc_fans[i].fan); in smu_attach_fans()
1022 for (i = 0; i < sc->sc_nfans; i++) { in smu_attach_fans()
1023 fan = &sc->sc_fans[i]; in smu_attach_fans()
1024 for (j = 0; j < strlen(fan->fan.name); j++) { in smu_attach_fans()
1025 sysctl_name[j] = tolower(fan->fan.name[j]); in smu_attach_fans()
1030 if (fan->type == SMU_FAN_RPM) { in smu_attach_fans()
1037 &fan->fan.min_rpm, 0, in smu_attach_fans()
1038 "Minimum allowed RPM"); in smu_attach_fans()
1041 &fan->fan.max_rpm, 0, in smu_attach_fans()
1042 "Maximum allowed RPM"); in smu_attach_fans()
1044 "rpm",CTLTYPE_INT | CTLFLAG_RW | in smu_attach_fans()
1046 smu_fanrpm_sysctl, "I", "Fan RPM"); in smu_attach_fans()
1048 fan->fan.read = (int (*)(struct pmac_fan *))smu_fan_read_rpm; in smu_attach_fans()
1049 fan->fan.set = (int (*)(struct pmac_fan *, int))smu_fan_set_rpm; in smu_attach_fans()
1058 &fan->fan.min_rpm, 0, in smu_attach_fans()
1062 &fan->fan.max_rpm, 0, in smu_attach_fans()
1070 "rpm",CTLTYPE_INT | CTLFLAG_RD | in smu_attach_fans()
1073 smu_fanrpm_sysctl, "I", "Fan RPM"); in smu_attach_fans()
1074 fan->fan.read = NULL; in smu_attach_fans()
1075 fan->fan.set = (int (*)(struct pmac_fan *, int))smu_fan_set_pwm; in smu_attach_fans()
1079 fan->fan.name, fan->type); in smu_attach_fans()
1086 device_t smu = sens->dev; in smu_sensor_read()
1094 cmd.data[0] = sens->reg; in smu_sensor_read()
1099 return (-1); in smu_sensor_read()
1104 switch (sens->type) { in smu_sensor_read()
1106 value *= sc->sc_cpu_diode_scale; in smu_sensor_read()
1108 value += ((int64_t)sc->sc_cpu_diode_offset) << 9; in smu_sensor_read()
1115 value *= sc->sc_cpu_volt_scale; in smu_sensor_read()
1116 value += sc->sc_cpu_volt_offset; in smu_sensor_read()
1125 value *= sc->sc_cpu_curr_scale; in smu_sensor_read()
1126 value += sc->sc_cpu_curr_offset; in smu_sensor_read()
1135 value *= sc->sc_slots_pow_scale; in smu_sensor_read()
1136 value += sc->sc_slots_pow_offset; in smu_sensor_read()
1159 sens = &sc->sc_sensors[arg2]; in smu_sensor_sysctl()
1182 sc->sc_nsensors = 0; in smu_attach_sensors()
1185 sc->sc_nsensors++; in smu_attach_sensors()
1187 if (sc->sc_nsensors == 0) { in smu_attach_sensors()
1192 sc->sc_sensors = malloc(sc->sc_nsensors * sizeof(struct smu_sensor), in smu_attach_sensors()
1195 sens = sc->sc_sensors; in smu_attach_sensors()
1196 sc->sc_nsensors = 0; in smu_attach_sensors()
1207 sens->dev = dev; in smu_attach_sensors()
1210 if (strcmp(type, "current-sensor") == 0) { in smu_attach_sensors()
1211 sens->type = SMU_CURRENT_SENSOR; in smu_attach_sensors()
1213 } else if (strcmp(type, "temp-sensor") == 0) { in smu_attach_sensors()
1214 sens->type = SMU_TEMP_SENSOR; in smu_attach_sensors()
1216 } else if (strcmp(type, "voltage-sensor") == 0) { in smu_attach_sensors()
1217 sens->type = SMU_VOLTAGE_SENSOR; in smu_attach_sensors()
1219 } else if (strcmp(type, "power-sensor") == 0) { in smu_attach_sensors()
1220 sens->type = SMU_POWER_SENSOR; in smu_attach_sensors()
1226 OF_getprop(child, "reg", &sens->reg, sizeof(cell_t)); in smu_attach_sensors()
1227 OF_getprop(child, "zone", &sens->therm.zone, sizeof(int)); in smu_attach_sensors()
1228 OF_getprop(child, "location", sens->therm.name, in smu_attach_sensors()
1229 sizeof(sens->therm.name)); in smu_attach_sensors()
1231 for (i = 0; i < strlen(sens->therm.name); i++) { in smu_attach_sensors()
1232 sysctl_name[i] = tolower(sens->therm.name[i]); in smu_attach_sensors()
1238 sprintf(sysctl_desc,"%s (%s)", sens->therm.name, units); in smu_attach_sensors()
1242 dev, sc->sc_nsensors, smu_sensor_sysctl, in smu_attach_sensors()
1243 (sens->type == SMU_TEMP_SENSOR) ? "IK" : "I", sysctl_desc); in smu_attach_sensors()
1245 if (sens->type == SMU_TEMP_SENSOR) { in smu_attach_sensors()
1247 sens->therm.target_temp = 500 + 2731; /* 50 C */ in smu_attach_sensors()
1248 sens->therm.max_temp = 900 + 2731; /* 90 C */ in smu_attach_sensors()
1250 sens->therm.read = in smu_attach_sensors()
1252 pmac_thermal_sensor_register(&sens->therm); in smu_attach_sensors()
1256 sc->sc_nsensors++; in smu_attach_sensors()
1296 if (error || !req->newptr) in smu_server_mode()
1349 ct.min = bcd2bin(cmd.data[1]); in smu_gettime()
1372 cmd.data[2] = bin2bcd(ct.min); in smu_settime()
1377 cmd.data[7] = bin2bcd(ct.year - 2000); in smu_settime()
1429 if (strcmp(name, "i2c-bus") != 0 && strcmp(name, "i2c") != 0) in smu_attach_i2c()
1442 dinfo->obd_name); in smu_attach_i2c()
1460 if (strcmp(name, "i2c-bus") == 0 || strcmp(name, "i2c") == 0) { in smuiic_probe()
1472 mtx_init(&sc->sc_mtx, "smuiic", NULL, MTX_DEF); in smuiic_attach()
1473 sc->sc_iic_inuse = 0; in smuiic_attach()
1476 OF_getprop(ofw_bus_get_node(dev), "reg", &sc->sc_busno, in smuiic_attach()
1477 sizeof(sc->sc_busno)); in smuiic_attach()
1493 mtx_lock(&sc->sc_mtx); in smuiic_transfer()
1494 while (sc->sc_iic_inuse) in smuiic_transfer()
1495 mtx_sleep(sc, &sc->sc_mtx, 0, "smuiic", 100); in smuiic_transfer()
1497 sc->sc_iic_inuse = 1; in smuiic_transfer()
1502 cmd.data[0] = sc->sc_busno; in smuiic_transfer()
1516 cmd.data[3] = min(msgs[i].len, 3); in smuiic_transfer()
1517 memcpy(&cmd.data[4], msgs[i].buf, min(msgs[i].len, 3)); in smuiic_transfer()
1537 mtx_unlock(&sc->sc_mtx); in smuiic_transfer()
1539 mtx_lock(&sc->sc_mtx); in smuiic_transfer()
1547 mtx_unlock(&sc->sc_mtx); in smuiic_transfer()
1549 mtx_lock(&sc->sc_mtx); in smuiic_transfer()
1554 mtx_sleep(sc, &sc->sc_mtx, 0, "smuiic", 10); in smuiic_transfer()
1563 msgs[i].len = cmd.len - 1; in smuiic_transfer()
1567 sc->sc_iic_inuse = 0; in smuiic_transfer()
1568 mtx_unlock(&sc->sc_mtx); in smuiic_transfer()