Skip to content

Commit

Permalink
dgpu: Split out getting temp to a function
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Crawford <tcrawford@system76.com>
  • Loading branch information
crawfxrd committed Jun 26, 2024
1 parent 5b0766a commit ce80393
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/board/system76/common/dgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,33 @@ void dgpu_init(void) {
i2c_reset(&I2C_DGPU, true);
}

uint8_t dgpu_get_fan_duty(void) {
uint8_t duty;
if (power_state == POWER_STATE_S0 && gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) {
// Use I2CS if in S0 state
bool dgpu_get_temp(int16_t *const data) {
if (gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) {
int8_t rlts;
int16_t res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1);
if (res == 1) {
dgpu_temp = (int16_t)rlts;
duty = fan_duty(&FAN, dgpu_temp);
*data = (int16_t)rlts;
return true;
} else {
DEBUG("DGPU temp error: %d\n", res);
// Default to 50% if there is an error
dgpu_temp = 0;
*data = 0;
return false;
}
}

*data = 0;
return true;
}

uint8_t dgpu_get_fan_duty(void) {
uint8_t duty;
if (power_state == POWER_STATE_S0) {
if (dgpu_get_temp(&dgpu_temp)) {
duty = fan_duty(&FAN, dgpu_temp);
} else {
duty = PWM_DUTY(50);
}
} else {
// Turn fan off if not in S0 state or GPU power not on
dgpu_temp = 0;
duty = PWM_DUTY(0);
}
Expand All @@ -100,6 +110,11 @@ uint8_t dgpu_get_fan_duty(void) {

void dgpu_init(void) {}

bool dgpu_get_temp(int16_t *const data) {
*data = 0;
return true;
}

uint8_t dgpu_get_fan_duty(void) {
return PWM_DUTY(0);
}
Expand Down
2 changes: 2 additions & 0 deletions src/board/system76/common/include/board/dgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef _BOARD_DGPU_H
#define _BOARD_DGPU_H

#include <stdbool.h>
#include <stdint.h>

#ifndef HAVE_DGPU
Expand All @@ -14,6 +15,7 @@ extern int16_t dgpu_temp;
#endif // HAVE_DGPU

void dgpu_init(void);
bool dgpu_get_temp(int16_t *const data);
uint8_t dgpu_get_fan_duty(void);

#endif // _BOARD_DGPU_H

0 comments on commit ce80393

Please sign in to comment.