Skip to content

Commit f1faa89

Browse files
Josh-Tsaiamstan
authored andcommitted
fwk: cypd: check the RDO mismatch flags
If the type-c device operating current is lower than maximum operating power in the RDO, the capability mismatch flag will be set. This change reads the contract information after the negotiation is completed. If the capability mismatch flag is set, call the event to check if the board allows changing the PDO or not. BRANCH=fwk-dogwood-27111 BUG=https://app.clickup.com/t/86etza0y1 TEST=Connect the device which will set the mismatch flag, and check the EC log prints "RDO Mismatch, may provide more power for this device" Signed-off-by: Josh Tsai <Josh_Tsai@compal.com>
1 parent f98dca3 commit f1faa89

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

zephyr/program/framework/include/cypress_pd_common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ enum pd_task_evt {
295295
CCG_EVT_PDO_C1P1 = BIT(22),
296296
CCG_EVT_PERFORM_ERROR_RECOVERY = BIT(23),
297297
CCG_EVT_PDO_RESET = BIT(24),
298+
CCG_EVT_RDO_MISMATCH = BIT(25),
298299
};
299300

300301
/************************************************
@@ -519,6 +520,7 @@ struct pd_port_current_state_t {
519520
int voltage;
520521
int current;
521522
int ac_port;
523+
bool rdo_mismatch;
522524
enum ccg_c_state c_state; /* What device is attached on the other side */
523525
uint8_t pd_state;
524526
uint8_t cc;
@@ -813,6 +815,12 @@ int cypd_get_ac_power(void);
813815
*/
814816
int cypd_get_active_port_voltage(void);
815817

818+
/**
819+
* Board can override the logic to allow PD chips to change
820+
* the source PDO from 5V/1.5A to 5V/3A
821+
*/
822+
__override_proto bool cypd_allow_increase_rdo_profile(void);
823+
816824
/**
817825
* Safety level LEVEL_TYPEC_1_5A trigger, modify sink 3A port to 1.5A
818826
*

zephyr/program/framework/src/cypress_pd_common.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ static void clear_port_state(int controller, int port)
998998
pd_port_states[port_idx].c_state = 0;
999999
pd_port_states[port_idx].current = 0;
10001000
pd_port_states[port_idx].voltage = 0;
1001+
pd_port_states[port_idx].rdo_mismatch = false;
10011002
}
10021003

10031004
void cypd_update_port_state(int controller, int port)
@@ -1470,6 +1471,11 @@ int cypd_get_active_port_voltage(void)
14701471
return pd_port_states[prev_charge_port].voltage;
14711472
}
14721473

1474+
__overridable bool cypd_allow_increase_rdo_profile(void)
1475+
{
1476+
return false;
1477+
}
1478+
14731479
/*****************************************************************************/
14741480
/* Interrupt handler */
14751481

@@ -1702,7 +1708,20 @@ void cypd_port_int(int controller, int port)
17021708
case CCG_RESPONSE_PD_CONTRACT_NEGOTIATION_COMPLETE:
17031709
CPRINTS("CYPD_RESPONSE_PD_CONTRACT_NEGOTIATION_COMPLETE %d", port_idx);
17041710
cypd_update_port_state(controller, port);
1705-
cypd_set_prepare_pdo(controller, port);
1711+
1712+
/* Read the contract information if we are the source */
1713+
int pd_port = ((controller << 2) + port);
1714+
1715+
if (pd_port_states[pd_port].pd_state == PD_ROLE_SOURCE) {
1716+
i2c_read_offset16_block(i2c_port, addr_flags,
1717+
CCG_READ_DATA_MEMORY_REG(port, 0), data2, MIN(response_len, 32));
1718+
1719+
if (data2[0] & BIT(1)) {
1720+
CPRINTS("RDO Mismatch, may provide more power for this device");
1721+
pd_port_states[pd_port].rdo_mismatch = true;
1722+
task_set_event(TASK_ID_CYPD, CCG_EVT_RDO_MISMATCH);
1723+
}
1724+
}
17061725
#ifdef CONFIG_PD_CCG8_EPR
17071726
/* make sure enter EPR mode only process in S0 state */
17081727
if (chipset_in_state(CHIPSET_STATE_ON))
@@ -1713,7 +1732,6 @@ void cypd_port_int(int controller, int port)
17131732
case CCG_RESPONSE_PORT_CONNECT:
17141733
CPRINTS("CYPD_RESPONSE_PORT_CONNECT %d", port_idx);
17151734
record_ucsi_connector_change_event(controller, port);
1716-
cypd_set_typec_profile(controller, port);
17171735
cypd_update_port_state(controller, port);
17181736
break;
17191737
case CCG_RESPONSE_SOURCE_CAP_MSG_RX:
@@ -1933,6 +1951,17 @@ void cypd_interrupt_handler_task(void *p)
19331951
task_wait_event_mask(TASK_EVENT_TIMER, 10);
19341952
}
19351953

1954+
if (evt & CCG_EVT_RDO_MISMATCH) {
1955+
if (cypd_allow_increase_rdo_profile()) {
1956+
for (i = 0; i < PD_PORT_COUNT; i++) {
1957+
if (pd_port_states[i].rdo_mismatch)
1958+
cypd_select_pdo(PORT_TO_CONTROLLER(i),
1959+
PORT_TO_CONTROLLER_PORT(i),
1960+
CCG_PD_CMD_SET_TYPEC_3A);
1961+
}
1962+
}
1963+
}
1964+
19361965
if (evt & CCG_EVT_DPALT_DISABLE) {
19371966
poweroff_dp_check();
19381967
}

0 commit comments

Comments
 (0)