Skip to content

Commit 168e48e

Browse files
committed
[modify] switch Legacy or ESPI PECI
when Legacy PECI is read 3 times pass will force at Legacy PECI, but when to read 10 times fail will switch to ESPI PECI. Signed-off-by: Leo_Tsai <LeoCX_Tsai@compal.com>
1 parent f6f5f6c commit 168e48e

3 files changed

Lines changed: 44 additions & 22 deletions

File tree

board/hx30/board.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ const struct temp_sensor_t temp_sensors[] = {
998998
[TEMP_SENSOR_PECI] = {
999999
.name = "PECI",
10001000
.type = TEMP_SENSOR_TYPE_CPU,
1001-
.read = peci_temp_sensor_get_val,
1001+
.read = peci_over_espi_temp_sensor_get_val,
10021002
.idx = 0,
10031003
},
10041004
#endif /* CONFIG_PECI */

board/hx30/peci_customization.c

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#define CPRINTS(format, args...) cprints(CC_THERMAL, format, ## args)
1919

2020
static int peci_temp;
21+
static int peci_select_count;
22+
static int peci_select_flags;
2123

2224
/*****************************************************************************/
2325
/* Internal functions */
@@ -74,18 +76,27 @@ int peci_Wr_Pkg_Config(uint8_t index, uint16_t parameter, uint32_t data, int wle
7476
for (clen = 4; clen < wlen - 1; clen++)
7577
out[clen] = ((data >> ((clen - 4) * 8)) & 0xFF);
7678

77-
/* if (board_get_version() >= BOARD_VERSION_7)
78-
espi_oob_peci_transaction(&peci);
79-
else {
80-
DVT1 is HW PECI pin
81-
*/
82-
rv = peci_transaction(&peci);
79+
80+
if (peci_select_count < 10 || peci_select_flags) {
81+
rv = peci_transaction(&peci);
82+
83+
if (rv != 0)
84+
peci_select_count++;
85+
else if (!peci_select_flags) {
86+
CPRINTS("FORCE GPIO PECI!");
87+
peci_select_count = 0;
88+
peci_select_flags = 1;
89+
}
90+
} else {
91+
rv = espi_oob_peci_transaction(&peci);
92+
}
93+
8394
if (rv)
8495
return rv;
85-
/*}*/
96+
8697
return EC_SUCCESS;
8798
}
88-
/*
99+
89100
static int peci_over_espi_get_cpu_temp(int *cpu_temp)
90101
{
91102
int rv;
@@ -101,32 +112,43 @@ static int peci_over_espi_get_cpu_temp(int *cpu_temp)
101112
.timeout_us = PECI_GET_TEMP_TIMEOUT_US,
102113
};
103114

104-
rv = espi_oob_peci_transaction(&peci);
115+
if (peci_select_count < 10 || peci_select_flags) {
116+
rv = peci_transaction(&peci);
117+
118+
if (rv != 0)
119+
peci_select_count++;
120+
else if (!peci_select_flags && peci_select_count > 3) {
121+
CPRINTS("FORCE GPIO PECI!");
122+
peci_select_count = 0;
123+
peci_select_flags = 1;
124+
}
125+
} else {
126+
rv = espi_oob_peci_transaction(&peci);
105127

106-
if (rv == EC_ERROR_TIMEOUT) {
107-
CPRINTS("ESPI GET VALUE TIMEOUT!");
108-
espi_oob_retry_receive_date(r_buf);
128+
if (rv == EC_ERROR_TIMEOUT) {
129+
CPRINTS("ESPI GET VALUE TIMEOUT!");
130+
espi_oob_retry_receive_date(r_buf);
131+
}
109132
}
110133

111134
if (rv)
112135
return rv;
113136

114-
115-
Get relative raw data of temperature.
137+
/* Get relative raw data of temperature. */
116138
*cpu_temp = (r_buf[1] << 8) | r_buf[0];
117139

118-
Convert relative raw data to degrees C.
140+
/* Convert relative raw data to degrees C. */
119141
*cpu_temp = ((*cpu_temp ^ 0xFFFF) + 1) >> 6;
120142

121143
if (*cpu_temp >= CONFIG_PECI_TJMAX)
122144
return EC_ERROR_INVAL;
123145

124-
temperature in K
146+
/* temperature in K */
125147
*cpu_temp = CONFIG_PECI_TJMAX - *cpu_temp + 273;
126148

127149
return EC_SUCCESS;
128150
}
129-
*/
151+
130152
int check_system_power(void)
131153
{
132154
uint8_t host_power_state = *host_get_customer_memmap(EC_EMEMAP_ER1_POWER_STATE);
@@ -265,7 +287,7 @@ int peci_over_espi_temp_sensor_get_val(int idx, int *temp_ptr)
265287
return EC_SUCCESS;
266288
}
267289

268-
/*
290+
269291
void read_peci_over_espi_gettemp(void)
270292
{
271293
int rv;
@@ -288,4 +310,3 @@ void read_peci_over_espi_gettemp(void)
288310
}
289311
}
290312
DECLARE_HOOK(HOOK_SECOND, read_peci_over_espi_gettemp, HOOK_PRIO_DEFAULT);
291-
*/

chip/mchp/peci.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ DECLARE_HOOK(HOOK_INIT, peci_init, HOOK_PRIO_DEFAULT);
346346
int peci_transaction(struct peci_data *peci)
347347
{
348348
struct peci_params_t peci_params;
349+
uint8_t rv;
349350
int index;
350351
int dlen;
351352
uint8_t aw_FCS_calc;
@@ -381,11 +382,11 @@ int peci_transaction(struct peci_data *peci)
381382
peci_params.cmd_fifo[peci_params.cmd_length - 1] = aw_FCS_calc;
382383
}
383384

384-
peci_trans(&peci_params);
385+
rv = peci_trans(&peci_params);
385386

386387
/* TODO: check error message, if no error, pass the data fifo to *in*/
387388
for (dlen = 0; dlen < peci_params.read_length; dlen++)
388389
peci->r_buf[dlen] = peci_params.data_fifo[dlen];
389390

390-
return PECI_STATUS_NO_ERR;
391+
return rv;
391392
}

0 commit comments

Comments
 (0)