diff --git a/src/board/system76/common/acpi.c b/src/board/system76/common/acpi.c index ac8dbe368..08ed4f366 100644 --- a/src/board/system76/common/acpi.c +++ b/src/board/system76/common/acpi.c @@ -162,14 +162,14 @@ uint8_t acpi_read(uint8_t addr) { ACPI_8(0xCC, sci_extra); - ACPI_8(0xCE, fan1_pwm_actual); - ACPI_16(0xD0, fan1_rpm); + ACPI_8(0xCE, fan1_info.pwm_actual); + ACPI_16(0xD0, fan1_info.rpm); #if CONFIG_HAVE_DGPU ACPI_8(0xCD, dgpu_temp); #endif // CONFIG_HAVE_DGPU #ifdef FAN2_PWM - ACPI_8(0xCF, fan2_pwm_actual); - ACPI_16(0xD2, fan2_rpm); + ACPI_8(0xCF, fan2_info.pwm_actual); + ACPI_16(0xD2, fan2_info.rpm); #endif // FAN2_PWM #if HAVE_LED_AIRPLANE_N diff --git a/src/board/system76/common/fan.c b/src/board/system76/common/fan.c index 531cdc464..1a07f10d5 100644 --- a/src/board/system76/common/fan.c +++ b/src/board/system76/common/fan.c @@ -10,13 +10,19 @@ bool fan_max = false; -uint8_t fan1_pwm_actual = 0; -uint8_t fan1_pwm_target = 0; -uint16_t fan1_rpm = 0; +struct FanInfo fan1_info = { + .pwm_actual = 0, + .pwm_target = 0, + .rpm = 0, +}; -uint8_t fan2_pwm_actual = 0; -uint8_t fan2_pwm_target = 0; -uint16_t fan2_rpm = 0; +#ifdef FAN2_PWM +struct FanInfo fan2_info = { + .pwm_actual = 0, + .pwm_target = 0, + .rpm = 0, +}; +#endif #define TACH_FREQ (CONFIG_CLOCK_FREQ_KHZ * 1000UL) @@ -87,58 +93,58 @@ void fan_event(void) { // change instead of ramping to provide the desired effects. // Set FAN1 duty - fan1_pwm_target = fan_duty(&FAN1, sys_temp); + fan1_info.pwm_target = fan_duty(&FAN1, sys_temp); if (fan_max) { - fan1_pwm_target = CTR0; - fan1_pwm_actual = CTR0; + fan1_info.pwm_target = CTR0; + fan1_info.pwm_actual = CTR0; } else if (power_state != POWER_STATE_S0) { - fan1_pwm_target = 0; - fan1_pwm_actual = 0; - } else if (fan1_pwm_actual < fan1_pwm_target) { - if (fan1_pwm_actual < CTR0) { - fan1_pwm_actual++; - if (fan1_pwm_actual < FAN1.pwm_min) { - fan1_pwm_actual = FAN1.pwm_min; + fan1_info.pwm_target = 0; + fan1_info.pwm_actual = 0; + } else if (fan1_info.pwm_actual < fan1_info.pwm_target) { + if (fan1_info.pwm_actual < CTR0) { + fan1_info.pwm_actual++; + if (fan1_info.pwm_actual < FAN1.pwm_min) { + fan1_info.pwm_actual = FAN1.pwm_min; } } - } else if (fan1_pwm_actual > fan1_pwm_target) { - if (fan1_pwm_actual > 0) { - fan1_pwm_actual--; - if (fan1_pwm_actual < FAN1.pwm_min) { - fan1_pwm_actual = 0; + } else if (fan1_info.pwm_actual > fan1_info.pwm_target) { + if (fan1_info.pwm_actual > 0) { + fan1_info.pwm_actual--; + if (fan1_info.pwm_actual < FAN1.pwm_min) { + fan1_info.pwm_actual = 0; } } } - TRACE("FAN1 duty=%d\n", fan1_pwm_actual); - FAN1_PWM = fan1_pwm_actual; - fan1_rpm = fan_get_tach0_rpm(); + TRACE("FAN1 duty=%d\n", fan1_info.pwm_actual); + FAN1_PWM = fan1_info.pwm_actual; + fan1_info.rpm = fan_get_tach0_rpm(); #ifdef FAN2_PWM // set FAN2 duty - fan2_pwm_target = fan_duty(&FAN2, sys_temp); + fan2_info.pwm_target = fan_duty(&FAN2, sys_temp); if (fan_max) { - fan2_pwm_target = CTR0; - fan2_pwm_actual = CTR0; + fan2_info.pwm_target = CTR0; + fan2_info.pwm_actual = CTR0; } else if (power_state != POWER_STATE_S0) { - fan2_pwm_target = 0; - fan2_pwm_actual = 0; - } else if (fan2_pwm_actual < fan2_pwm_target) { - if (fan2_pwm_actual < CTR0) { - fan2_pwm_actual++; - if (fan2_pwm_actual < FAN2.pwm_min) { - fan2_pwm_actual = FAN2.pwm_min; + fan2_info.pwm_target = 0; + fan2_info.pwm_actual = 0; + } else if (fan2_info.pwm_actual < fan2_info.pwm_target) { + if (fan2_info.pwm_actual < CTR0) { + fan2_info.pwm_actual++; + if (fan2_info.pwm_actual < FAN2.pwm_min) { + fan2_info.pwm_actual = FAN2.pwm_min; } } - } else if (fan2_pwm_actual > fan2_pwm_target) { - if (fan2_pwm_actual > 0) { - fan2_pwm_actual--; - if (fan2_pwm_actual < FAN2.pwm_min) { - fan2_pwm_actual = 0; + } else if (fan2_info.pwm_actual > fan2_info.pwm_target) { + if (fan2_info.pwm_actual > 0) { + fan2_info.pwm_actual--; + if (fan2_info.pwm_actual < FAN2.pwm_min) { + fan2_info.pwm_actual = 0; } } } - TRACE("FAN2 duty=%d\n", fan2_pwm_actual); - FAN2_PWM = fan2_pwm_actual; - fan2_rpm = fan_get_tach1_rpm(); + TRACE("FAN2 duty=%d\n", fan2_info.pwm_actual); + FAN2_PWM = fan2_info.pwm_actual; + fan2_info.rpm = fan_get_tach1_rpm(); #endif } diff --git a/src/board/system76/common/include/board/fan.h b/src/board/system76/common/include/board/fan.h index 9906577c0..b56473c71 100644 --- a/src/board/system76/common/include/board/fan.h +++ b/src/board/system76/common/include/board/fan.h @@ -21,20 +21,22 @@ struct Fan { const uint8_t pwm_min; }; +struct FanInfo { + uint8_t pwm_actual; + uint8_t pwm_target; + uint16_t rpm; +}; + extern const struct Fan __code FAN1; +extern struct FanInfo fan1_info; + #ifdef FAN2_PWM extern const struct Fan __code FAN2; +extern struct FanInfo fan2_info; #endif extern bool fan_max; -extern uint8_t fan1_pwm_actual; -extern uint8_t fan1_pwm_target; -extern uint16_t fan1_rpm; -extern uint8_t fan2_pwm_actual; -extern uint8_t fan2_pwm_target; -extern uint16_t fan2_rpm; - void fan_reset(void); void fan_event(void); diff --git a/src/board/system76/common/smfi.c b/src/board/system76/common/smfi.c index 225675aa8..ce635ddf6 100644 --- a/src/board/system76/common/smfi.c +++ b/src/board/system76/common/smfi.c @@ -126,11 +126,11 @@ static enum Result cmd_print(void) { static enum Result cmd_fan_get(void) { switch (smfi_cmd[SMFI_CMD_DATA]) { case 1: - smfi_cmd[SMFI_CMD_DATA + 1] = fan1_pwm_actual; + smfi_cmd[SMFI_CMD_DATA + 1] = fan1_info.pwm_actual; return RES_OK; #ifdef FAN2_PWM case 2: - smfi_cmd[SMFI_CMD_DATA + 1] = fan2_pwm_actual; + smfi_cmd[SMFI_CMD_DATA + 1] = fan2_info.pwm_actual; return RES_OK; #endif } @@ -143,12 +143,12 @@ static enum Result cmd_fan_set(void) { switch (smfi_cmd[SMFI_CMD_DATA]) { case 1: // Set duty cycle of FAN1 - fan1_pwm_target = smfi_cmd[SMFI_CMD_DATA + 1]; + fan1_info.pwm_target = smfi_cmd[SMFI_CMD_DATA + 1]; return RES_OK; #ifdef FAN2_PWM case 2: // Set duty cycle of FAN2 - fan2_pwm_target = smfi_cmd[SMFI_CMD_DATA + 1]; + fan2_info.pwm_target = smfi_cmd[SMFI_CMD_DATA + 1]; return RES_OK; #endif }