xref: /aosp_15_r20/external/coreboot/src/mainboard/amd/pademelon/fan_init.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <bootstate.h>
4 #include <superio/fintek/common/fan_control.h>
5 #include <amdblocks/lpc.h>
6 #include <device/pci_ops.h>
7 #include <soc/pci_devs.h>
8 
9 #define CPU_FAN		1
10 #define SYSTEM_FAN	2
11 
12 /* Boundaries in celsius, sections in percent */
13 static u8 cpu_boudaries[FINTEK_BOUNDARIES_SIZE] = {
14 	80,
15 	65,
16 	50,
17 	35
18 };
19 
20 static u8 system_boudaries[FINTEK_BOUNDARIES_SIZE] = {
21 	70,
22 	55,
23 	40,
24 	25
25 };
26 
27 static u8 cpu_section[FINTEK_SECTIONS_SIZE] = {
28 	100,
29 	85,
30 	70,
31 	55,
32 	40
33 };
34 
35 static u8 system_section[FINTEK_SECTIONS_SIZE] = {
36 	100,
37 	85,
38 	70,
39 	55,
40 	40
41 };
42 
43 struct fintek_fan cpu_fan = {
44 	CPU_FAN,
45 	IGNORE_SENSOR,
46 	TEMP_SENSOR_DEFAULT,
47 	FAN_TEMP_TSI,
48 	FAN_TYPE_PWM_PUSH_PULL,
49 	FAN_MODE_DEFAULT,
50 	FAN_PWM_FREQ_23500,
51 	FAN_UP_RATE_10HZ,
52 	FAN_DOWN_RATE_10HZ,
53 	FAN_FOLLOW_INTERPOLATION,
54 	cpu_boudaries,
55 	cpu_section
56 };
57 
58 struct fintek_fan system_fan = {
59 	SYSTEM_FAN,
60 	EXTERNAL_SENSOR2,
61 	TEMP_SENSOR_BJT,
62 	FAN_TEMP_EXTERNAL_2,
63 	FAN_TYPE_DAC_POWER,
64 	FAN_MODE_DEFAULT,
65 	FAN_PWM_FREQ_23500,
66 	FAN_UP_RATE_10HZ,
67 	FAN_DOWN_RATE_10HZ,
68 	FAN_FOLLOW_INTERPOLATION,
69 	system_boudaries,
70 	system_section
71 };
72 
init_fan_control(void * unused)73 static void init_fan_control(void *unused)
74 {
75 	/* Open a LPC IO access to 0x0220-0x0227 */
76 	pci_or_config32(SOC_LPC_DEV, LPC_IO_PORT_DECODE_ENABLE, DECODE_ENABLE_SERIAL_PORT2);
77 
78 	set_fan(&cpu_fan);
79 	set_fan(&system_fan);
80 }
81 
82 BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, init_fan_control, NULL);
83