Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acpi: Report RPM values instead of raw tachometer values #456

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/board/system76/common/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <board/kbled.h>
#include <board/lid.h>
#include <board/peci.h>
#include <common/macro.h>
#include <board/pwm.h>
#include <common/debug.h>
#include <ec/pwm.h>
#include <common/macro.h>

#ifndef HAVE_LED_AIRPLANE_N
#define HAVE_LED_AIRPLANE_N 1
Expand Down Expand Up @@ -162,13 +162,11 @@ uint8_t acpi_read(uint8_t addr) {
ACPI_8(0xCC, sci_extra);

ACPI_8(0xCE, DCR2);
ACPI_8(0xD0, F1TLRR);
ACPI_8(0xD1, F1TMRR);
ACPI_16(0xD0, pwm_tach0_rpm);
#if CONFIG_HAVE_DGPU
ACPI_8(0xCD, dgpu_temp);
ACPI_8(0xCF, DCR4);
ACPI_8(0xD2, F2TLRR);
ACPI_8(0xD3, F2TMRR);
ACPI_16(0xD2, pwm_tach1_rpm);
#endif // CONFIG_HAVE_DGPU

#if HAVE_LED_AIRPLANE_N
Expand Down
7 changes: 7 additions & 0 deletions src/board/system76/common/include/board/pwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

#include <ec/pwm.h>

// NOTE: These are used instead of the functions directly for ACPI to prevent
// double reads of the tachometer values.
extern int16_t pwm_tach0_rpm;
extern int16_t pwm_tach1_rpm;

void pwm_init(void);
int16_t pwm_get_tach0_rpm(void);
int16_t pwm_get_tach1_rpm(void);

#endif // _BOARD_PWM_H
5 changes: 5 additions & 0 deletions src/board/system76/common/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ void main(void) {

// Update fan speeds
fan_duty_set(peci_get_fan_duty(), dgpu_get_fan_duty());

// NOTE: These values are reported to ACPI. Update them at the
// same interval as the fan duties.
pwm_tach0_rpm = pwm_get_tach0_rpm();
pwm_tach1_rpm = pwm_get_tach1_rpm();
}

// Only run the following once per interval
Expand Down
30 changes: 30 additions & 0 deletions src/board/system76/common/pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
#include <board/pwm.h>
#include <common/macro.h>

#define TACH_FREQ (CONFIG_CLOCK_FREQ_KHZ * 1000UL)

// Fan Speed (RPM) = 60 / (1/fs sec * {FnTMRR, FnRLRR} * P)
// - n: 1 or 2
// - P: the numbers of square pulses per revolution
// - fs: sample rate (FreqEC / 128)
// - {FnTMRR, FnTLRR} = 0000h: Fan Speed is zero
#define TACH_TO_RPM(x) (60UL * TACH_FREQ / 128UL / 2UL / (x))

int16_t pwm_tach0_rpm = -1;
int16_t pwm_tach1_rpm = -1;

void pwm_init(void) {
// Set T0CHSEL to TACH0A and T1CHSEL to TACH1A
TSWCTLR = 0;
Expand Down Expand Up @@ -37,3 +49,21 @@ void pwm_init(void) {
// Enable PWM
ZTIER = BIT(1);
}

int16_t pwm_get_tach0_rpm(void) {
uint16_t rpm = (F1TMRR << 8) | F1TLRR;

if (rpm)
rpm = TACH_TO_RPM(rpm);

return rpm;
}

int16_t pwm_get_tach1_rpm(void) {
uint16_t rpm = (F2TMRR << 8) | F2TLRR;

if (rpm)
rpm = TACH_TO_RPM(rpm);

return rpm;
}