blob: 105d6da8cff37f43678cb35e8dfbcbbfef9eb516 [file] [log] [blame]
Felix Held3f3eca92020-01-23 17:12:32 +01001/* SPDX-License-Identifier: GPL-2.0-or-later */
Nico Hubere34e1782016-09-29 12:33:01 +02002
Nico Hubere34e1782016-09-29 12:33:01 +02003#include <console/console.h>
4#include <delay.h>
Elyes HAOUAS2329a252019-05-15 22:11:18 +02005#include <stddef.h>
Felix Held166b55c2019-10-07 18:10:30 +02006#include <superio/hwm5_conf.h>
Nico Hubere34e1782016-09-29 12:33:01 +02007
8#include "env_ctrl.h"
9#include "env_ctrl_chip.h"
10
Nico Hubere34e1782016-09-29 12:33:01 +020011static void extemp_force_idle_status(const u16 base)
12{
13 u8 reg;
14 int retries = 10;
15
16 /* Wait up to 10ms for non-busy state. */
17 while (retries > 0) {
Felix Held166b55c2019-10-07 18:10:30 +020018 reg = pnp_read_hwm5_index(base, ITE_EC_EXTEMP_STATUS);
Nico Hubere34e1782016-09-29 12:33:01 +020019
20 if ((reg & ITE_EC_EXTEMP_STATUS_HOST_BUSY) == 0x0)
21 break;
22
23 retries--;
24
25 mdelay(1);
26 }
27
28 if (retries == 0 && (reg & ITE_EC_EXTEMP_STATUS_HOST_BUSY) == 0x1) {
29 /*
30 * SIO is busy due to unfinished peci transaction.
31 * Re-configure Register 0x8E to terminate processes.
32 */
Felix Held166b55c2019-10-07 18:10:30 +020033 pnp_write_hwm5_index(base, ITE_EC_EXTEMP_CONTROL,
34 ITE_EC_EXTEMP_CTRL_AUTO_4HZ | ITE_EC_EXTEMP_CTRL_AUTO_START);
Nico Hubere34e1782016-09-29 12:33:01 +020035 }
36}
37
38/*
Vagiz Trakhanov177f7732017-10-17 18:04:55 +000039 * Setup PECI interface
Nico Hubere34e1782016-09-29 12:33:01 +020040 */
Vagiz Trakhanov177f7732017-10-17 18:04:55 +000041static void enable_peci(const u16 base)
Nico Hubere34e1782016-09-29 12:33:01 +020042{
Nico Hubere34e1782016-09-29 12:33:01 +020043 /* Enable PECI interface */
Felix Held166b55c2019-10-07 18:10:30 +020044 pnp_write_hwm5_index(base, ITE_EC_INTERFACE_SELECT,
45 ITE_EC_INTERFACE_SEL_PECI | ITE_EC_INTERFACE_SPEED_TOLERANCE);
Nico Hubere34e1782016-09-29 12:33:01 +020046
47 /* Setup External Temperature using PECI GetTemp */
Felix Held166b55c2019-10-07 18:10:30 +020048 pnp_write_hwm5_index(base, ITE_EC_EXTEMP_ADDRESS, PECI_CLIENT_ADDRESS);
49 pnp_write_hwm5_index(base, ITE_EC_EXTEMP_COMMAND, PECI_GETTEMP_COMMAND);
50 pnp_write_hwm5_index(base, ITE_EC_EXTEMP_WRITE_LENGTH, PECI_GETTEMP_WRITE_LENGTH);
51 pnp_write_hwm5_index(base, ITE_EC_EXTEMP_READ_LENGTH, PECI_GETTEMP_READ_LENGTH);
52 pnp_write_hwm5_index(base, ITE_EC_EXTEMP_CONTROL,
53 ITE_EC_EXTEMP_CTRL_AUTO_4HZ | ITE_EC_EXTEMP_CTRL_AUTO_START);
Nico Hubere34e1782016-09-29 12:33:01 +020054}
55
56/*
Vagiz Trakhanov177f7732017-10-17 18:04:55 +000057 * Set up External Temperature to read via PECI or thermal diode/resistor
Nico Hubere34e1782016-09-29 12:33:01 +020058 * into TMPINx register
59 */
Samuel Holland901bdb32017-06-06 20:40:27 -050060static void enable_tmpin(const u16 base, const u8 tmpin,
Vagiz Trakhanov17c57712017-09-28 14:21:54 +000061 const struct ite_ec_thermal_config *const conf)
Nico Hubere34e1782016-09-29 12:33:01 +020062{
63 u8 reg;
Michael Büchler370b8b62020-06-01 20:51:58 +020064 u8 reg_extra;
Nico Hubere34e1782016-09-29 12:33:01 +020065
Felix Held166b55c2019-10-07 18:10:30 +020066 reg = pnp_read_hwm5_index(base, ITE_EC_ADC_TEMP_CHANNEL_ENABLE);
Michael Büchler370b8b62020-06-01 20:51:58 +020067 reg_extra = pnp_read_hwm5_index(base, ITE_EC_ADC_TEMP_EXTRA_CHANNEL_ENABLE);
Nico Hubere34e1782016-09-29 12:33:01 +020068
Vagiz Trakhanov17c57712017-09-28 14:21:54 +000069 switch (conf->mode) {
Joel Linn82ff48c2024-03-26 18:19:15 +010070 case THERMAL_MODE_DISABLED:
71 return;
Vagiz Trakhanov177f7732017-10-17 18:04:55 +000072 case THERMAL_PECI:
Michael Büchler370b8b62020-06-01 20:51:58 +020073 /* Some chips can set any TMPIN as the target for PECI readings
74 while others can only read to TMPIN3. In the latter case a
75 different register is used for enabling it. */
76 if (CONFIG(SUPERIO_ITE_ENV_CTRL_EXT_ANY_TMPIN)) {
77 /* IT8721F is an exception, it cannot use TMPIN2 for PECI. */
78 if (CONFIG(SUPERIO_ITE_IT8721F) && tmpin == 2) {
79 printk(BIOS_WARNING,
80 "PECI to TMPIN2 not supported on IT8721F\n");
81 return;
82 }
Joel Linn82ff48c2024-03-26 18:19:15 +010083 u8 reg_new = (reg & ~ITE_EC_ADC_TEMP_EXT_REPORTS_TO_MASK)
84 | ITE_EC_ADC_TEMP_EXT_REPORTS_TO(tmpin);
85 /* Registers stick on reboot and resume,
86 don't warn for correct reg values */
87 if (reg & ITE_EC_ADC_TEMP_EXT_REPORTS_TO_MASK && reg != reg_new) {
Michael Büchler370b8b62020-06-01 20:51:58 +020088 printk(BIOS_WARNING,
Joel Linn82ff48c2024-03-26 18:19:15 +010089 "PECI specified for another TMPIN, overwriting\n");
Michael Büchler370b8b62020-06-01 20:51:58 +020090 }
Joel Linn82ff48c2024-03-26 18:19:15 +010091 reg = reg_new;
Michael Büchler370b8b62020-06-01 20:51:58 +020092 } else if (tmpin == 3) {
93 reg_extra |= ITE_EC_ADC_TEMP_EXTRA_TMPIN3_EXT;
94 pnp_write_hwm5_index(base, ITE_EC_ADC_TEMP_EXTRA_CHANNEL_ENABLE,
95 reg_extra);
96 } else {
97 printk(BIOS_WARNING, "PECI to TMPIN%d not supported on this Super I/O",
98 tmpin);
Vagiz Trakhanov177f7732017-10-17 18:04:55 +000099 return;
100 }
101 enable_peci(base);
Michael Büchler370b8b62020-06-01 20:51:58 +0200102
Vagiz Trakhanov177f7732017-10-17 18:04:55 +0000103 break;
Nico Hubere34e1782016-09-29 12:33:01 +0200104 case THERMAL_DIODE:
105 reg |= ITE_EC_ADC_TEMP_DIODE_MODE(tmpin);
106 break;
107 case THERMAL_RESISTOR:
108 reg |= ITE_EC_ADC_TEMP_RESISTOR_MODE(tmpin);
109 break;
110 default:
Elyes HAOUAS12eef082020-03-30 16:45:35 +0200111 printk(BIOS_WARNING, "Unsupported thermal mode 0x%x on TMPIN%d\n",
Vagiz Trakhanov17c57712017-09-28 14:21:54 +0000112 conf->mode, tmpin);
Nico Hubere34e1782016-09-29 12:33:01 +0200113 return;
114 }
115
Felix Held166b55c2019-10-07 18:10:30 +0200116 pnp_write_hwm5_index(base, ITE_EC_ADC_TEMP_CHANNEL_ENABLE, reg);
Nico Hubere34e1782016-09-29 12:33:01 +0200117
Vagiz Trakhanov17c57712017-09-28 14:21:54 +0000118 /* Set temperature offsets */
119 if (conf->mode != THERMAL_RESISTOR) {
Felix Held166b55c2019-10-07 18:10:30 +0200120 reg = pnp_read_hwm5_index(base, ITE_EC_BEEP_ENABLE);
Vagiz Trakhanov17c57712017-09-28 14:21:54 +0000121 reg |= ITE_EC_TEMP_ADJUST_WRITE_ENABLE;
Felix Held166b55c2019-10-07 18:10:30 +0200122 pnp_write_hwm5_index(base, ITE_EC_BEEP_ENABLE, reg);
123 pnp_write_hwm5_index(base, ITE_EC_TEMP_ADJUST[tmpin-1], conf->offset);
Vagiz Trakhanov17c57712017-09-28 14:21:54 +0000124 }
125
Vagiz Trakhanovcc9c0cb2017-09-28 14:25:59 +0000126 /* Set temperature limits */
127 u8 max = conf->max;
Felix Held166b55c2019-10-07 18:10:30 +0200128 pnp_write_hwm5_index(base, ITE_EC_HIGH_TEMP_LIMIT(tmpin), max ? max : 127);
129 pnp_write_hwm5_index(base, ITE_EC_LOW_TEMP_LIMIT(tmpin), conf->min);
Vagiz Trakhanovcc9c0cb2017-09-28 14:25:59 +0000130
Nico Hubere34e1782016-09-29 12:33:01 +0200131 /* Enable the startup of monitoring operation */
Felix Held166b55c2019-10-07 18:10:30 +0200132 reg = pnp_read_hwm5_index(base, ITE_EC_CONFIGURATION);
Nico Hubere34e1782016-09-29 12:33:01 +0200133 reg |= ITE_EC_CONFIGURATION_START;
Felix Held166b55c2019-10-07 18:10:30 +0200134 pnp_write_hwm5_index(base, ITE_EC_CONFIGURATION, reg);
Nico Hubere34e1782016-09-29 12:33:01 +0200135}
136
137static void fan_smartconfig(const u16 base, const u8 fan,
138 const enum ite_ec_fan_mode mode,
139 const struct ite_ec_fan_smartconfig *const conf)
140{
141 u8 pwm_ctrl;
142 u8 pwm_start = 0;
143 u8 pwm_auto = 0;
Michael Büchlere693b1d2020-06-01 23:22:10 +0200144 u8 delta_temp;
Nico Hubere34e1782016-09-29 12:33:01 +0200145
146 if (mode == FAN_SMART_SOFTWARE) {
147 pwm_ctrl = ITE_EC_FAN_CTL_PWM_MODE_SOFTWARE;
148
149 /* 50% duty cycle by default */
150 const u8 duty = conf->pwm_start ? conf->pwm_start : 50;
Julius Wernercd49cce2019-03-05 16:53:33 -0800151 if (CONFIG(SUPERIO_ITE_ENV_CTRL_8BIT_PWM))
Nico Hubere34e1782016-09-29 12:33:01 +0200152 pwm_start = ITE_EC_FAN_CTL_PWM_DUTY(duty);
153 else
154 pwm_ctrl |= ITE_EC_FAN_CTL_PWM_DUTY(duty);
155 } else {
156 pwm_ctrl = ITE_EC_FAN_CTL_PWM_MODE_AUTOMATIC;
157 pwm_ctrl |= ITE_EC_FAN_CTL_TEMPIN(conf->tmpin);
158
Matt DeVillier67f80fb2020-08-12 10:29:11 -0500159 if (conf->clsd_loop) {
160 pwm_ctrl |= ITE_EC_FAN_PWM_CLSD_LOOP;
161 pwm_start = ITE_EC_FAN_CTL_PWM_START_RPM(conf->rpm_start);
Michał Żygowskidcfff372018-12-31 10:45:19 +0100162 pwm_auto = ITE_EC_FAN_CTL_PWM_SLOPE_LOWER(conf->slope);
Matt DeVillier67f80fb2020-08-12 10:29:11 -0500163 } else {
164 pwm_start = ITE_EC_FAN_CTL_PWM_START_DUTY(conf->pwm_start);
165
166 if (CONFIG(SUPERIO_ITE_ENV_CTRL_7BIT_SLOPE_REG)) {
167 pwm_auto = conf->slope & 0x7f;
168 } else {
169 pwm_start |= ITE_EC_FAN_CTL_PWM_SLOPE_BIT6(conf->slope);
170 pwm_auto = ITE_EC_FAN_CTL_PWM_SLOPE_LOWER(conf->slope);
171 }
Michał Żygowskidcfff372018-12-31 10:45:19 +0100172 }
173
Arthur Heymanse68947d2016-11-26 14:43:18 +0100174 if (conf->smoothing)
175 pwm_auto |= ITE_EC_FAN_CTL_AUTO_SMOOTHING_EN;
Nico Hubere34e1782016-09-29 12:33:01 +0200176
Felix Held166b55c2019-10-07 18:10:30 +0200177 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_TEMP_LIMIT_OFF(fan), conf->tmp_off);
178 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_TEMP_LIMIT_START(fan),
179 conf->tmp_start);
Nico Hubere34e1782016-09-29 12:33:01 +0200180 /* Full speed above 127°C by default */
Felix Held166b55c2019-10-07 18:10:30 +0200181 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_TEMP_LIMIT_FULL(fan),
182 conf->tmp_full ? conf->tmp_full : 127);
Michael Büchlere693b1d2020-06-01 23:22:10 +0200183
184 delta_temp = ITE_EC_FAN_CTL_DELTA_TEMP_INTRVL(conf->tmp_delta);
Joel Linnf7e45672024-03-29 14:03:44 +0100185 if (!CONFIG(SUPERIO_ITE_ENV_CTRL_NO_FULLSPEED_SETTING))
186 delta_temp |= ITE_EC_FAN_CTL_FULL_AT_THRML_LMT(conf->full_lmt);
Felix Held166b55c2019-10-07 18:10:30 +0200187 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_DELTA_TEMP(fan),
Michael Büchlere693b1d2020-06-01 23:22:10 +0200188 delta_temp);
Nico Hubere34e1782016-09-29 12:33:01 +0200189 }
190
Felix Held166b55c2019-10-07 18:10:30 +0200191 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_PWM_CONTROL(fan), pwm_ctrl);
192 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_PWM_START(fan), pwm_start);
193 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_PWM_AUTO(fan), pwm_auto);
Nico Hubere34e1782016-09-29 12:33:01 +0200194}
195
196static void enable_fan(const u16 base, const u8 fan,
197 const struct ite_ec_fan_config *const conf)
198{
199 u8 reg;
200
Krystian Hebel97445f22019-02-26 11:19:58 +0100201 if (conf->mode == FAN_IGNORE ||
Julius Wernercd49cce2019-03-05 16:53:33 -0800202 (CONFIG(SUPERIO_ITE_ENV_CTRL_NO_ONOFF) &&
Krystian Hebel97445f22019-02-26 11:19:58 +0100203 conf->mode <= FAN_MODE_OFF))
Nico Hubere34e1782016-09-29 12:33:01 +0200204 return;
205
206 /* FAN_CTL2 might have its own frequency setting */
Julius Wernercd49cce2019-03-05 16:53:33 -0800207 if (CONFIG(SUPERIO_ITE_ENV_CTRL_PWM_FREQ2) && fan == 2) {
Felix Held166b55c2019-10-07 18:10:30 +0200208 reg = pnp_read_hwm5_index(base, ITE_EC_ADC_TEMP_EXTRA_CHANNEL_ENABLE);
Nico Hubere34e1782016-09-29 12:33:01 +0200209 reg &= ~ITE_EC_FAN_PWM_CLOCK_MASK;
210 reg |= ITE_EC_FAN_PWM_DEFAULT_CLOCK;
Felix Held166b55c2019-10-07 18:10:30 +0200211 pnp_write_hwm5_index(base, ITE_EC_ADC_TEMP_EXTRA_CHANNEL_ENABLE, reg);
Nico Hubere34e1782016-09-29 12:33:01 +0200212 }
213
214 if (conf->mode >= FAN_SMART_SOFTWARE) {
215 fan_smartconfig(base, fan, conf->mode, &conf->smart);
216 } else {
Felix Held166b55c2019-10-07 18:10:30 +0200217 reg = pnp_read_hwm5_index(base, ITE_EC_FAN_CTL_MODE);
Nico Hubere34e1782016-09-29 12:33:01 +0200218 if (conf->mode == FAN_MODE_ON)
219 reg |= ITE_EC_FAN_CTL_ON(fan);
220 else
221 reg &= ~ITE_EC_FAN_CTL_ON(fan);
Felix Held166b55c2019-10-07 18:10:30 +0200222 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_MODE, reg);
Nico Hubere34e1782016-09-29 12:33:01 +0200223 }
224
Elyes HAOUAS12eef082020-03-30 16:45:35 +0200225 if (CONFIG(SUPERIO_ITE_ENV_CTRL_FAN16_CONFIG) && conf->mode >= FAN_MODE_ON) {
Felix Held166b55c2019-10-07 18:10:30 +0200226 reg = pnp_read_hwm5_index(base, ITE_EC_FAN_TAC_COUNTER_ENABLE);
Nico Hubere34e1782016-09-29 12:33:01 +0200227 reg |= ITE_EC_FAN_TAC_16BIT_ENABLE(fan);
Felix Held166b55c2019-10-07 18:10:30 +0200228 pnp_write_hwm5_index(base, ITE_EC_FAN_TAC_COUNTER_ENABLE, reg);
Nico Hubere34e1782016-09-29 12:33:01 +0200229 }
230
Julius Wernercd49cce2019-03-05 16:53:33 -0800231 if (CONFIG(SUPERIO_ITE_ENV_CTRL_5FANS) && fan > 3) {
Felix Held166b55c2019-10-07 18:10:30 +0200232 reg = pnp_read_hwm5_index(base, ITE_EC_FAN_SEC_CTL);
Krystian Hebel97445f22019-02-26 11:19:58 +0100233 if (conf->mode >= FAN_MODE_ON)
234 reg |= ITE_EC_FAN_SEC_CTL_TAC_EN(fan);
235 else
236 reg &= ~ITE_EC_FAN_SEC_CTL_TAC_EN(fan);
Felix Held166b55c2019-10-07 18:10:30 +0200237 pnp_write_hwm5_index(base, ITE_EC_FAN_SEC_CTL, reg);
Krystian Hebel97445f22019-02-26 11:19:58 +0100238 } else {
Felix Held166b55c2019-10-07 18:10:30 +0200239 reg = pnp_read_hwm5_index(base, ITE_EC_FAN_MAIN_CTL);
Krystian Hebel97445f22019-02-26 11:19:58 +0100240 if (conf->mode >= FAN_MODE_ON)
241 reg |= ITE_EC_FAN_MAIN_CTL_TAC_EN(fan);
242 else
243 reg &= ~ITE_EC_FAN_MAIN_CTL_TAC_EN(fan);
244
245 /* Some ITEs have SmartGuardian always enabled */
Julius Wernercd49cce2019-03-05 16:53:33 -0800246 if (!CONFIG(SUPERIO_ITE_ENV_CTRL_NO_ONOFF)) {
Krystian Hebel97445f22019-02-26 11:19:58 +0100247 if (conf->mode >= FAN_SMART_SOFTWARE)
248 reg |= ITE_EC_FAN_MAIN_CTL_SMART(fan);
249 else
250 reg &= ~ITE_EC_FAN_MAIN_CTL_SMART(fan);
251 }
Felix Held166b55c2019-10-07 18:10:30 +0200252 pnp_write_hwm5_index(base, ITE_EC_FAN_MAIN_CTL, reg);
Krystian Hebel97445f22019-02-26 11:19:58 +0100253 }
Nico Hubere34e1782016-09-29 12:33:01 +0200254}
255
Joel Linn9905d1f2024-03-26 18:33:38 +0100256static void enable_fan_vector(const u16 base, const u8 fan_vector,
257 const struct ite_ec_fan_vector_config *const conf)
258{
259 u8 reg;
260
261 u8 start = conf->tmp_start;
262 if (!start) {
263 /* When tmp_start is not configured we would set the
264 * register to it's default of 0xFF here, which would
265 * effectively disable the vector functionality of the
266 * SuperIO altogether since that temperature will never
267 * be reached. We can therefore return here and don't
268 * need to set any other registers.
269 */
270 return;
271 }
272 pnp_write_hwm5_index(base, ITE_EC_FAN_VEC_CTL_LIMIT_START(fan_vector), start);
273
274 const s8 slope = conf->slope;
275 const bool slope_neg = slope < 0;
276 if (slope <= -128)
277 reg = 127;
278 else if (slope_neg)
279 reg = -slope;
280 else
281 reg = slope;
282 reg |= ITE_EC_FAN_VEC_CTL_SLOPE_TMPIN0(conf->tmpin);
283 pnp_write_hwm5_index(base, ITE_EC_FAN_VEC_CTL_SLOPE(fan_vector), reg);
284
285 reg = ITE_EC_FAN_VEC_CTL_DELTA_TEMP_INTRVL(conf->tmp_delta);
286 reg |= ITE_EC_FAN_VEC_CTL_DELTA_FANOUT(conf->fanout);
287 reg |= ITE_EC_FAN_VEC_CTL_DELTA_TMPIN1(conf->tmpin);
288 pnp_write_hwm5_index(base, ITE_EC_FAN_VEC_CTL_DELTA(fan_vector), reg);
289
290 if (CONFIG(SUPERIO_ITE_ENV_CTRL_FAN_VECTOR_RANGED)) {
291 reg = conf->tmp_range & 0x7f;
292 reg |= ITE_EC_FAN_VEC_CTL_RANGE_SLOPESIGN(slope_neg);
293 pnp_write_hwm5_index(base, ITE_EC_FAN_VEC_CTL_RANGE(fan_vector), reg);
294 } else if (slope_neg) {
295 printk(BIOS_WARNING, "Unsupported negative slope on fan vector control\n");
296 }
297}
298
Vagiz Trakhanov41aa5ec2017-10-23 13:17:44 +0000299static void enable_beeps(const u16 base, const struct ite_ec_config *const conf)
300{
301 u8 reg = 0;
302 u8 freq = ITE_EC_BEEP_TONE_DIVISOR(10) | ITE_EC_BEEP_FREQ_DIVISOR(10);
303
304 if (conf->tmpin_beep) {
305 reg |= ITE_EC_BEEP_ON_TMP_LIMIT;
Felix Held166b55c2019-10-07 18:10:30 +0200306 pnp_write_hwm5_index(base, ITE_EC_BEEP_FREQ_DIV_OF_TMPIN, freq);
Vagiz Trakhanov41aa5ec2017-10-23 13:17:44 +0000307 }
308 if (conf->fan_beep) {
309 reg |= ITE_EC_BEEP_ON_FAN_LIMIT;
Felix Held166b55c2019-10-07 18:10:30 +0200310 pnp_write_hwm5_index(base, ITE_EC_BEEP_FREQ_DIV_OF_FAN, freq);
Vagiz Trakhanov41aa5ec2017-10-23 13:17:44 +0000311 }
312 if (conf->vin_beep) {
313 reg |= ITE_EC_BEEP_ON_VIN_LIMIT;
Felix Held166b55c2019-10-07 18:10:30 +0200314 pnp_write_hwm5_index(base, ITE_EC_BEEP_FREQ_DIV_OF_VIN, freq);
Vagiz Trakhanov41aa5ec2017-10-23 13:17:44 +0000315 }
316
317 if (reg) {
Felix Held166b55c2019-10-07 18:10:30 +0200318 reg |= pnp_read_hwm5_index(base, ITE_EC_BEEP_ENABLE);
319 pnp_write_hwm5_index(base, ITE_EC_BEEP_ENABLE, reg);
Vagiz Trakhanov41aa5ec2017-10-23 13:17:44 +0000320 }
321}
322
Nico Hubere34e1782016-09-29 12:33:01 +0200323void ite_ec_init(const u16 base, const struct ite_ec_config *const conf)
324{
325 size_t i;
326
327 /* Configure 23.43kHz PWM active high output */
Felix Held166b55c2019-10-07 18:10:30 +0200328 u8 fan_ctl = pnp_read_hwm5_index(base, ITE_EC_FAN_CTL_MODE);
Nico Hubere34e1782016-09-29 12:33:01 +0200329 fan_ctl &= ~ITE_EC_FAN_PWM_CLOCK_MASK;
330 fan_ctl |= ITE_EC_FAN_PWM_DEFAULT_CLOCK;
331 fan_ctl |= ITE_EC_FAN_CTL_POLARITY_HIGH;
Felix Held166b55c2019-10-07 18:10:30 +0200332 pnp_write_hwm5_index(base, ITE_EC_FAN_CTL_MODE, fan_ctl);
Nico Hubere34e1782016-09-29 12:33:01 +0200333
Nico Hubere34e1782016-09-29 12:33:01 +0200334 /* Enable HWM if configured */
335 for (i = 0; i < ITE_EC_TMPIN_CNT; ++i)
Vagiz Trakhanov17c57712017-09-28 14:21:54 +0000336 enable_tmpin(base, i + 1, &conf->tmpin[i]);
Nico Hubere34e1782016-09-29 12:33:01 +0200337
Michał Żygowskidcfff372018-12-31 10:45:19 +0100338 /* Enable External Sensor SMBus Host if configured */
339 if (conf->smbus_en) {
Felix Held166b55c2019-10-07 18:10:30 +0200340 pnp_write_hwm5_index(base, ITE_EC_INTERFACE_SELECT,
341 pnp_read_hwm5_index(base, ITE_EC_INTERFACE_SELECT) |
Michał Żygowskidcfff372018-12-31 10:45:19 +0100342 ITE_EC_INTERFACE_SMB_ENABLE);
343 }
344
Michael Büchlera8152722020-08-02 15:38:10 +0200345 /* Set SST/PECI Host Controller Clock to either 24 MHz or internal 32 MHz */
346 if (conf->smbus_24mhz) {
347 pnp_write_hwm5_index(base, ITE_EC_INTERFACE_SELECT,
348 pnp_read_hwm5_index(base, ITE_EC_INTERFACE_SELECT) |
349 ITE_EC_INTERFACE_CLOCK_24MHZ);
350 }
351
Nico Hubere34e1782016-09-29 12:33:01 +0200352 /* Enable reading of voltage pins */
Felix Held166b55c2019-10-07 18:10:30 +0200353 pnp_write_hwm5_index(base, ITE_EC_ADC_VOLTAGE_CHANNEL_ENABLE, conf->vin_mask);
Nico Hubere34e1782016-09-29 12:33:01 +0200354
355 /* Enable FANx if configured */
356 for (i = 0; i < ITE_EC_FAN_CNT; ++i)
357 enable_fan(base, i + 1, &conf->fan[i]);
358
Joel Linn9905d1f2024-03-26 18:33:38 +0100359 if (CONFIG(SUPERIO_ITE_ENV_CTRL_FAN_VECTOR)) {
360 /* Enable Special FAN Vector X if configured */
361 for (i = 0; i < ITE_EC_FAN_VECTOR_CNT; ++i)
362 enable_fan_vector(base, i, &conf->fan_vector[i]);
363 }
364
Vagiz Trakhanov41aa5ec2017-10-23 13:17:44 +0000365 /* Enable beeps if configured */
366 enable_beeps(base, conf);
367
Nico Hubere34e1782016-09-29 12:33:01 +0200368 /*
369 * System may get wrong temperature data when SIO is in
370 * busy state. Therefore, check the status and terminate
371 * processes if needed.
372 */
Vagiz Trakhanov177f7732017-10-17 18:04:55 +0000373 for (i = 0; i < ITE_EC_TMPIN_CNT; ++i)
374 if (conf->tmpin[i].mode == THERMAL_PECI)
375 extemp_force_idle_status(base);
Nico Hubere34e1782016-09-29 12:33:01 +0200376}