dgpu: Split out getting temp to a function
Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
		
				
					committed by
					
						 Tim Crawford
						Tim Crawford
					
				
			
			
				
	
			
			
			
						parent
						
							80cfa91b9f
						
					
				
				
					commit
					8f88c0c7aa
				
			| @@ -59,23 +59,33 @@ void dgpu_init(void) { | |||||||
|     i2c_reset(&I2C_DGPU, true); |     i2c_reset(&I2C_DGPU, true); | ||||||
| } | } | ||||||
|  |  | ||||||
| uint8_t dgpu_get_fan_duty(void) { | bool dgpu_get_temp(int16_t *const data) { | ||||||
|     uint8_t duty; |     if (gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) { | ||||||
|     if (power_state == POWER_STATE_S0 && gpio_get(&DGPU_PWR_EN) && !gpio_get(&GC6_FB_EN)) { |  | ||||||
|         // Use I2CS if in S0 state |  | ||||||
|         int8_t rlts; |         int8_t rlts; | ||||||
|         int16_t res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1); |         int16_t res = i2c_get(&I2C_DGPU, 0x4F, 0x00, &rlts, 1); | ||||||
|         if (res == 1) { |         if (res == 1) { | ||||||
|             dgpu_temp = (int16_t)rlts; |             *data = (int16_t)rlts; | ||||||
|             duty = fan_duty(&FAN, dgpu_temp); |             return true; | ||||||
|         } else { |         } else { | ||||||
|             DEBUG("DGPU temp error: %d\n", res); |             DEBUG("DGPU temp error: %d\n", res); | ||||||
|             // Default to 50% if there is an error |             *data = 0; | ||||||
|             dgpu_temp = 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); |             duty = PWM_DUTY(50); | ||||||
|         } |         } | ||||||
|     } else { |     } else { | ||||||
|         // Turn fan off if not in S0 state or GPU power not on |  | ||||||
|         dgpu_temp = 0; |         dgpu_temp = 0; | ||||||
|         duty = PWM_DUTY(0); |         duty = PWM_DUTY(0); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ | |||||||
| #ifndef _BOARD_DGPU_H | #ifndef _BOARD_DGPU_H | ||||||
| #define _BOARD_DGPU_H | #define _BOARD_DGPU_H | ||||||
|  |  | ||||||
|  | #include <stdbool.h> | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
|  |  | ||||||
| #if CONFIG_HAVE_DGPU | #if CONFIG_HAVE_DGPU | ||||||
| @@ -10,12 +11,18 @@ | |||||||
| extern int16_t dgpu_temp; | extern int16_t dgpu_temp; | ||||||
|  |  | ||||||
| void dgpu_init(void); | void dgpu_init(void); | ||||||
|  | bool dgpu_get_temp(int16_t *const data); | ||||||
| uint8_t dgpu_get_fan_duty(void); | uint8_t dgpu_get_fan_duty(void); | ||||||
|  |  | ||||||
| #else | #else | ||||||
|  |  | ||||||
| static inline void dgpu_init(void) {} | static inline void dgpu_init(void) {} | ||||||
|  |  | ||||||
|  | static inline bool dgpu_get_temp(int16_t *const data) { | ||||||
|  |     *data = 0; | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  |  | ||||||
| static inline uint8_t dgpu_get_fan_duty(void) { | static inline uint8_t dgpu_get_fan_duty(void) { | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user