Skip to content

Commit 4e459f7

Browse files
committed
workaround hang issue with PD 0.0.1E
Signed-off-by: Kieran Levin <ktl@frame.work>
1 parent 65bb7f0 commit 4e459f7

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

zephyr/program/lotus/include/cypress_pd_common.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
(0x1010 + ((x) * 0x1000))
8686
#define CCG_CURRENT_RDO_REG(x) \
8787
(0x1014 + ((x) * 0x1000))
88+
#define CCG_ALT_MODE_CMD_REG(x) \
89+
(0x101C + ((x) * 0x1000))
90+
#define CCG_APP_HW_CMD_REG(x) \
91+
(0x1020 + ((x) * 0x1000))
8892
#define CCG_EVENT_MASK_REG(x) \
8993
(0x1024 + ((x) * 0x1000))
9094
#define CCG_VDM_EC_CONTROL_REG(x) \
@@ -95,6 +99,10 @@
9599
(0x1032 + ((x) * 0x1000))
96100
#define CCG_PORT_INTR_STATUS_REG(x) \
97101
(0x1034 + ((x) * 0x1000))
102+
#define CCG_PORT_HOST_CAP_REG(x) \
103+
(0x105C + ((x) * 0x1000))
104+
#define CCG_ALT_MODE_MASK_REG(x) \
105+
(0x1060 + ((x) * 0x1000))
98106
#define SELECT_SINK_PDO_EPR_MASK(x) \
99107
(0x1065 + ((x) * 0x1000))
100108
#define CCG_SINK_PPS_AVS_CTRL_REG(x) \
@@ -289,6 +297,7 @@ enum ccg_usermux_configuration {
289297
CCG_PD_USER_MUX_CONFIG_ISOLATE = 0,
290298
CCG_PD_USER_MUX_CONFIG_SAFE,
291299
CCG_PD_USER_MUX_CONFIG_SS_ONLY,
300+
CCG_PD_USER_MUX_CONFIG_DEINIT = 0x09,
292301
CCG_PD_USER_MUX_CONFIG_DEBUG_ACCESSORY = 0x0A
293302
};
294303

@@ -475,7 +484,7 @@ struct pd_chip_ucsi_info_t {
475484

476485
int cypd_write_reg8(int controller, int reg, int data);
477486

478-
int cypd_write_reg_block(int controller, int reg, void *data, int len);
487+
int cypd_write_reg_block(int controller, int reg, const void *data, int len);
479488

480489
int cypd_read_reg_block(int controller, int reg, void *data, int len);
481490

@@ -550,4 +559,6 @@ int cypd_get_ac_power(void);
550559
*/
551560
void force_disable_epr_mode(void);
552561

562+
void cypd_port_reset(void);
563+
553564
#endif /* __CROS_EC_CYPRESS_PD_COMMON_H */

zephyr/program/lotus/src/board_host_command.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ static enum ec_status enter_non_acpi_mode(struct host_cmd_handler_args *args)
173173

174174
update_apu_ready(1);
175175

176+
cypd_port_reset();
177+
176178
/**
177179
* Even though the protocol returns EC_SUCCESS,
178180
* the system still does not update the power limit.

zephyr/program/lotus/src/cypress_pd_common.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void cypd_update_port_state(int controller, int port);
9595
static void cypd_pdo_reset_deferred(void);
9696
static void cypd_set_prepare_pdo(int controller, int port);
9797

98-
int cypd_write_reg_block(int controller, int reg, void *data, int len)
98+
int cypd_write_reg_block(int controller, int reg, const void *data, int len)
9999
{
100100
int rv;
101101
uint16_t i2c_port = pd_chip_config[controller].i2c_port;
@@ -1262,43 +1262,33 @@ static void port_to_safe_mode(int port)
12621262
CPRINTS("P%d: Safe", port);
12631263

12641264
}
1265-
1266-
enum power_state pd_prev_power_state = POWER_G3;
1265+
bool apu_not_initialized;
12671266
void update_system_power_state(int controller)
12681267
{
12691268
enum power_state ps = power_get_state();
1270-
12711269
switch (ps) {
12721270
case POWER_G3:
12731271
case POWER_S5G3:
1274-
pd_prev_power_state = POWER_G3;
12751272
cypd_set_power_state(CCG_POWERSTATE_G3, controller);
1273+
apu_not_initialized = true;
12761274
break;
12771275
case POWER_S5:
12781276
case POWER_S3S5:
12791277
case POWER_S4S5:
1280-
pd_prev_power_state = POWER_S5;
12811278
cypd_set_power_state(CCG_POWERSTATE_S5, controller);
1279+
apu_not_initialized = true;
12821280
break;
12831281
case POWER_S3:
12841282
case POWER_S4S3:
12851283
case POWER_S5S3:
12861284
case POWER_S0S3:
12871285
case POWER_S0ixS3: /* S0ix -> S3 */
12881286
cypd_set_power_state(CCG_POWERSTATE_S3, controller);
1289-
if (pd_prev_power_state < POWER_S3) {
1290-
perform_error_recovery(controller);
1291-
pd_prev_power_state = ps;
1292-
}
12931287
break;
12941288
case POWER_S0:
12951289
case POWER_S3S0:
12961290
case POWER_S0ixS0: /* S0ix -> S0 */
12971291
cypd_set_power_state(CCG_POWERSTATE_S0, controller);
1298-
if (pd_prev_power_state < POWER_S3) {
1299-
perform_error_recovery(controller);
1300-
pd_prev_power_state = ps;
1301-
}
13021292
break;
13031293
case POWER_S0ix:
13041294
case POWER_S3S0ix: /* S3 -> S0ix */
@@ -1317,6 +1307,16 @@ void cypd_set_power_active(void)
13171307
task_set_event(TASK_ID_CYPD, CCG_EVT_S_CHANGE);
13181308
}
13191309

1310+
void cypd_port_reset(void)
1311+
{
1312+
if (apu_not_initialized) {
1313+
task_set_event(TASK_ID_CYPD, CCG_EVT_PLT_RESET);
1314+
apu_not_initialized = false;
1315+
}
1316+
}
1317+
1318+
1319+
13201320
#define CYPD_SETUP_CMDS_LEN 2
13211321
static int cypd_setup(int controller)
13221322
{
@@ -1421,6 +1421,7 @@ static void cypd_handle_state(int controller)
14211421
cypd_update_power_status(controller);
14221422

14231423
update_system_power_state(controller);
1424+
14241425
cypd_setup(controller);
14251426

14261427
/* After initial complete, update the type-c port state */
@@ -1853,6 +1854,10 @@ void cypd_interrupt_handler_task(void *p)
18531854
if (evt & CCG_EVT_UPDATE_PWRSTAT)
18541855
cypd_update_power_status(2);
18551856

1857+
if (evt & CCG_EVT_PLT_RESET) {
1858+
perform_error_recovery(2);
1859+
}
1860+
18561861

18571862
if (evt & (CCG_EVT_INT_CTRL_0 | CCG_EVT_INT_CTRL_1 |
18581863
CCG_EVT_STATE_CTRL_0 | CCG_EVT_STATE_CTRL_1)) {

0 commit comments

Comments
 (0)