acpi_gic: Add helper for platform gicc
[coreboot2.git] / src / superio / ite / common / env_ctrl.h
blob8a461aa3f287fdfa89ac7e14d8742518d5ed682d
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #ifndef SUPERIO_ITE_ENV_CTRL_H
4 #define SUPERIO_ITE_ENV_CTRL_H
6 #include "env_ctrl_chip.h"
8 #if CONFIG(SUPERIO_ITE_ENV_CTRL_8BIT_PWM)
9 #define ITE_EC_FAN_MAX_PWM 0xff
10 #define ITE_EC_FAN_PWM_DEFAULT_CLOCK ITE_EC_FAN_PWM_CLOCK_6MHZ
11 #else
12 #define ITE_EC_FAN_MAX_PWM 0x7f
13 #define ITE_EC_FAN_PWM_DEFAULT_CLOCK ITE_EC_FAN_PWM_CLOCK_3MHZ
14 #endif
16 #define ITE_EC_CONFIGURATION 0x00
17 #define ITE_EC_CONFIGURATION_START (1 << 0)
19 #define ITE_EC_INTERFACE_SELECT 0x0a
20 #define ITE_EC_INTERFACE_PSEUDO_EOC (1 << 7)
21 #define ITE_EC_INTERFACE_SMB_ENABLE (1 << 6)
22 #define ITE_EC_INTERFACE_SEL_DISABLE (0 << 4)
23 #define ITE_EC_INTERFACE_SEL_SST_SLAVE (1 << 4)
24 #define ITE_EC_INTERFACE_SEL_PECI (2 << 4)
25 #define ITE_EC_INTERFACE_SEL_SST_HOST (3 << 4)
26 #define ITE_EC_INTERFACE_CLOCK_32MHZ (0 << 3)
27 #define ITE_EC_INTERFACE_CLOCK_24MHZ (1 << 3)
28 #define ITE_EC_INTERFACE_SPEED_TOLERANCE (1 << 2)
29 #define ITE_EC_INTERFACE_PECI_AWFCS (1 << 0)
31 #define ITE_EC_FAN_PWM_SMOOTHING_FREQ 0x0b
32 #define ITE_EC_FAN_PWM_SMOOTHING_MASK (3 << 6)
33 #define ITE_EC_FAN_PWM_SMOOTHING_1KHZ (0 << 6)
34 #define ITE_EC_FAN_PWM_SMOOTHING_256HZ (1 << 6)
35 #define ITE_EC_FAN_PWM_SMOOTHING_64HZ (2 << 6)
36 #define ITE_EC_FAN_PWM_SMOOTHING_16HZ (3 << 6)
37 /* ITE IT8786E PWM_SMOOTHING_FREQ */
38 #define ITE_EC_FAN_ALT_PWM_SMOOTHING_16HZ (1 << 6)
39 #define ITE_EC_FAN_ALT_PWM_SMOOTHING_8HZ (2 << 6)
40 #define ITE_EC_FAN_ALT_PWM_SMOOTHING_4HZ (3 << 6)
41 #define ITE_EC_FAN_CTL5_SEL(FAN_CTLx) ((((FAN_CTLx)-1) & 3) << 2)
42 #define ITE_EC_FAN_CTL5_SEL_NONE (3 << 2)
43 #define ITE_EC_FAN_CTL4_SEL(FAN_CTLx) (((FAN_CTLx)-1) & 3)
44 #define ITE_EC_FAN_CTL4_SEL_NONE (3 << 0)
46 #define ITE_EC_FAN_TAC_COUNTER_ENABLE 0x0c
47 #define ITE_EC_FAN_TAC_16BIT_ENABLE(x) (1 << ((x)-1))
49 #define ITE_EC_FAN_SEC_CTL 0x0c
50 #define ITE_EC_FAN_SEC_CTL_TAC_EN(x) (1 << (x))
52 #define ITE_EC_FAN_TAC_LIMIT(x) \
53 (((x) > 3 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
54 ? (0x84 + ((x)-4) * 2) \
55 : (0x10 + ((x)-1)) \
57 #define ITE_EC_FAN_TAC_EXT_LIMIT(x) \
58 (((x) > 3 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
59 ? (0x85 + ((x)-4) * 2) \
60 : (0x1b + ((x)-1)) \
63 #define ITE_EC_FAN_TAC_CNTRL 0x0c
64 #define ITE_EC_TMPIN3_ENHANCED_INT_MODE (1 << 7)
65 #define ITE_EC_TMPIN2_ENHANCED_INT_MODE (1 << 6)
66 #define ITE_EC_FAN_TAC5_EN (1 << 5)
67 #define ITE_EC_FAN_TAC4_EN (1 << 4)
68 #define ITE_EC_TMPIN1_ENHANCED_INT_MODE (1 << 3)
69 #define ITE_EC_AMDTSI_ERR_EN (1 << 0)
71 #define ITE_EC_FAN_MAIN_CTL 0x13
72 #define ITE_EC_FAN_MAIN_CTL_TAC_EN(x) (1 << ((x)+3))
73 #define ITE_EC_FAN_MAIN_CTL_COLL_FULL_SPEED (1 << 3)
74 #define ITE_EC_FAN_MAIN_CTL_SMART(x) (1 << ((x)-1))
75 #define ITE_EC_FAN_CTL_MODE 0x14
76 #define ITE_EC_FAN_CTL_POLARITY_HIGH (1 << 7)
77 #define ITE_EC_FAN_PWM_CLOCK_MASK (7 << 4)
78 #define ITE_EC_FAN_PWM_CLOCK_48MHZ (0 << 4)
79 #define ITE_EC_FAN_PWM_CLOCK_24MHZ (1 << 4)
80 #define ITE_EC_FAN_PWM_CLOCK_12MHZ (2 << 4)
81 #define ITE_EC_FAN_PWM_CLOCK_8MHZ (3 << 4)
82 #define ITE_EC_FAN_PWM_CLOCK_6MHZ (4 << 4)
83 #define ITE_EC_FAN_PWM_CLOCK_3MHZ (5 << 4)
84 #define ITE_EC_FAN_PWM_CLOCK_1_5MHZ (6 << 4)
85 #define ITE_EC_FAN_PWM_CLOCK_51KHZ (7 << 4)
86 #define ITE_EC_FAN_PWM_MIN_DUTY_20 (1 << 3)
87 #define ITE_EC_FAN_CTL_ON(x) (1 << ((x)-1))
89 #define ITE_EC_FAN_CTL_PWM_CONTROL(x) \
90 (((x) > 3 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
91 ? (0x1e + ((x)-4)) \
92 : (0x15 + ((x)-1)) \
94 #define ITE_EC_FAN_PWM_CLSD_LOOP (1 << 2)
96 #if CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)
97 #define ITE_EC_FAN_CTL_TEMPIN_MASK (7 << 3)
98 #define ITE_EC_FAN_CTL_TEMPIN(x) ((((x)-1) & 7) << 3)
99 #else
100 #define ITE_EC_FAN_CTL_TEMPIN_MASK (3 << 0)
101 #define ITE_EC_FAN_CTL_TEMPIN(x) (((x)-1) & 3)
102 #endif
104 #define ITE_EC_FAN_CTL_PWM_MODE_SOFTWARE (0 << 7)
105 #define ITE_EC_FAN_CTL_PWM_MODE_AUTOMATIC (1 << 7)
106 #define ITE_EC_FAN_CTL_PWM_DUTY_MASK (ITE_EC_FAN_MAX_PWM << 0)
107 #define ITE_EC_FAN_CTL_PWM_DUTY(p) \
108 ({ \
109 const unsigned int _p = p; \
110 (_p >= 100) \
111 ? ITE_EC_FAN_MAX_PWM \
112 : (_p * ITE_EC_FAN_MAX_PWM) / 100; \
114 #define ITE_EC_FAN_CTL_PWM_RPM(p) \
115 ({ \
116 const unsigned int _p = p; \
117 (_p >= 4080) \
118 ? 0xFF \
119 : (_p / 16); \
122 #define ITE_EC_HIGH_TEMP_LIMIT(x) (0x40 + ((x-1) * 2))
123 #define ITE_EC_LOW_TEMP_LIMIT(x) (0x41 + ((x-1) * 2))
125 #define ITE_EC_ADC_VOLTAGE_CHANNEL_ENABLE 0x50
126 #define ITE_EC_ADC_TEMP_CHANNEL_ENABLE 0x51
127 #define ITE_EC_ADC_TEMP_EXT_REPORTS_TO_MASK (3 << 6)
128 #define ITE_EC_ADC_TEMP_EXT_REPORTS_TO(x) (((x) & 3) << 6)
129 #define ITE_EC_ADC_TEMP_RESISTOR_MODE(x) (1 << ((x)+2))
130 #define ITE_EC_ADC_TEMP_DIODE_MODE(x) (1 << ((x)-1))
131 #define ITE_EC_ADC_TEMP_EXTRA_CHANNEL_ENABLE 0x55
132 #define ITE_EC_ADC_TEMP_EXTRA_TMPIN3_EXT (1 << 7)
134 /* Matches length of ITE_EC_TMPIN_CNT */
135 static const u8 ITE_EC_TEMP_ADJUST[] = { 0x56, 0x57, 0x59 };
137 #define ITE_EC_BEEP_ENABLE 0x5C
138 #define ITE_EC_TEMP_ADJUST_WRITE_ENABLE (1 << 7)
139 #define ITE_EC_ADC_CLOCK_1MHZ (6 << 4)
140 #define ITE_EC_ADC_CLOCK_2MHZ (7 << 4)
141 #define ITE_EC_ADC_CLOCK_24MHZ (5 << 4)
142 #define ITE_EC_ADC_CLOCK_31KHZ (4 << 4)
143 #define ITE_EC_ADC_CLOCK_62KHZ (3 << 4)
144 #define ITE_EC_ADC_CLOCK_125KHZ (2 << 4)
145 #define ITE_EC_ADC_CLOCK_250KHZ (1 << 4)
146 #define ITE_EC_ADC_CLOCK_500KHZ (0 << 4)
147 #define ITE_EC_BEEP_ON_TMP_LIMIT (1 << 2)
148 #define ITE_EC_BEEP_ON_VIN_LIMIT (1 << 1)
149 #define ITE_EC_BEEP_ON_FAN_LIMIT (1 << 0)
150 #define ITE_EC_BEEP_FREQ_DIV_OF_FAN 0x5D
151 #define ITE_EC_BEEP_FREQ_DIV_OF_VIN 0x5E
152 #define ITE_EC_BEEP_FREQ_DIV_OF_TMPIN 0x5F
153 #define ITE_EC_BEEP_TONE_DIVISOR(x) (((x) & 0x0f) << 4)
154 #define ITE_EC_BEEP_FREQ_DIVISOR(x) (((x) & 0x0f) << 0)
156 #define ITE_EC_FAN_CTL_TEMP_LIMIT_OFF(x) \
157 (((x) == 5 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
158 ? (0xa0) \
159 : (0x60 + ((x)-1) * 8) \
161 #define ITE_EC_FAN_CTL_TEMP_LIMIT_START(x) \
162 (((x) == 5 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
163 ? (0xa1) \
164 : (0x61 + ((x)-1) * 8) \
166 #define ITE_EC_FAN_CTL_TEMP_LIMIT_FULL(x) \
167 (((x) == 5 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
168 ? (0xa2) \
169 : (0x62 + ((x)-1) * 8) \
171 #define ITE_EC_FAN_CTL_PWM_START(x) \
172 (((x) == 5 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
173 ? (0xa3) \
174 : (0x63 + ((x)-1) * 8) \
176 #define ITE_EC_FAN_CTL_PWM_AUTO(x) \
177 (((x) == 5 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
178 ? (0xa4) \
179 : (0x64 + ((x)-1) * 8) \
181 #define ITE_EC_FAN_CTL_DELTA_TEMP(x) \
182 (((x) == 5 && CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS)) \
183 ? (0xa5) \
184 : (0x65 + ((x)-1) * 8) \
187 /* Common for ITE_EC_FAN_CTL_PWM_START */
188 #define ITE_EC_FAN_CTL_PWM_SLOPE_BIT6(s) (((s) & 0x40) << 1)
189 #define ITE_EC_FAN_CTL_PWM_START_DUTY(p) ITE_EC_FAN_CTL_PWM_DUTY(p)
190 #define ITE_EC_FAN_CTL_PWM_START_RPM(p) ITE_EC_FAN_CTL_PWM_RPM(p)
192 /* Common for ITE_EC_FAN_CTL_PWM_AUTO */
193 #define ITE_EC_FAN_CTL_AUTO_SMOOTHING_EN (1 << 7)
194 #define ITE_EC_FAN_CTL_PWM_SLOPE_LOWER(s) ((s) & 0x3f)
196 /* Common for ITE_EC_FAN_CTL_DELTA_TEMP */
197 #define ITE_EC_FAN_CTL_DELTA_TEMP_INTRVL(c) ((c) & 0x1f)
198 #define ITE_EC_FAN_CTL_FULL_AT_THRML_LMT(x) (((x) & 0x1) << 6)
199 #define ITE_EC_FAN_CTL_TARGET_ZONE(x) (0x66 + ((x)-1) * 8)
200 #define ITE_EC_FAN_CTL_TARGET_ZONE_MASK 0x0f
202 #define ITE_EC_FAN_VEC_CTL_LIMIT_START(x) (0x90 + (x) * 4)
203 #define ITE_EC_FAN_VEC_CTL_SLOPE(x) (0x91 + (x) * 4)
204 #define ITE_EC_FAN_VEC_CTL_DELTA(x) (0x92 + (x) * 4)
205 #define ITE_EC_FAN_VEC_CTL_RANGE(x) (0x93 + (x) * 4)
207 #define ITE_EC_FAN_VEC_CTL_SLOPE_TMPIN0(x) (((x) & 0x1) << 7)
208 #define ITE_EC_FAN_VEC_CTL_DELTA_TMPIN1(x) (((x) & 0x2) << 6)
209 #define ITE_EC_FAN_VEC_CTL_DELTA_TEMP_INTRVL(c) ITE_EC_FAN_CTL_DELTA_TEMP_INTRVL(c)
210 #define ITE_EC_FAN_VEC_CTL_DELTA_FANOUT(x) (((x) & 0x3) << 5)
211 #define ITE_EC_FAN_VEC_CTL_RANGE_SLOPESIGN(x) (((x) & 0x1) << 7)
213 #define ITE_EC_EXTEMP_STATUS 0x88
214 #define ITE_EC_EXTEMP_STATUS_HOST_BUSY (1 << 0)
215 #define ITE_EC_EXTEMP_ADDRESS 0x89
216 #define ITE_EC_EXTEMP_WRITE_LENGTH 0x8a
217 #define ITE_EC_EXTEMP_READ_LENGTH 0x8b
218 #define ITE_EC_EXTEMP_COMMAND 0x8c
219 #define ITE_EC_EXTEMP_WRITE_DATA_2 0x8d
220 #define ITE_EC_EXTEMP_CONTROL 0x8e
221 #define ITE_EC_EXTEMP_CTRL_AUTO_32HZ (0 << 6)
222 #define ITE_EC_EXTEMP_CTRL_AUTO_16HZ (1 << 6)
223 #define ITE_EC_EXTEMP_CTRL_AUTO_8HZ (2 << 6)
224 #define ITE_EC_EXTEMP_CTRL_AUTO_4HZ (3 << 6)
225 #define ITE_EC_EXTEMP_CTRL_AUTO_START (1 << 5)
226 #define ITE_EC_EXTEMP_CTRL_AUTO_ABORT (1 << 4)
227 #define ITE_EC_EXTEMP_CTRL_AUTO_TWO_DOMAIN (1 << 3)
228 #define ITE_EC_EXTEMP_CTRL_CONTENTION (1 << 2)
229 #define ITE_EC_EXTEMP_CTRL_SST_IDLE_HIGH (1 << 1)
230 #define ITE_EC_EXTEMP_CTRL_START (1 << 0)
232 /* Standard PECI GetTemp */
233 #define PECI_CLIENT_ADDRESS 0x30
234 #define PECI_GETTEMP_COMMAND 0x01
235 #define PECI_GETTEMP_WRITE_LENGTH 0x01
236 #define PECI_GETTEMP_READ_LENGTH 0x02
238 void ite_ec_init(u16 base, const struct ite_ec_config *conf);
240 #endif /* SUPERIO_ITE_ENV_CTRL_H */