1818#define CPRINTS (format , args ...) cprints(CC_THERMAL, format, ## args)
1919
2020static 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+
89100static 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+
130152int 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+
269291void read_peci_over_espi_gettemp (void )
270292{
271293 int rv ;
@@ -288,4 +310,3 @@ void read_peci_over_espi_gettemp(void)
288310 }
289311}
290312DECLARE_HOOK (HOOK_SECOND , read_peci_over_espi_gettemp , HOOK_PRIO_DEFAULT );
291- */
0 commit comments