Skip to content

CCG8: after a jump into an EC image which starts with the AP off, the USB-C ports stop detecting chargers, because the image tells the running PD controllers G3 #105

Open

Description

@mitar

On a Laptop 13 Pro with the AMD Ryzen AI 300 Series mainboard, EC lilac-4.0.2-fdbf549, the USB-C ports stop detecting chargers after a jump into an image which starts with the AP off: framework_tool --reboot-ec reboot followed by framework_tool --reboot-ec jump-rw, or a jump after the EC restarted from a crash (for example the one in #104). A charger or a dock plugged in afterwards is not detected and the laptop cannot charge. The state survives AP reboots, further EC resets and framework_tool --pd-reset, and only an EC hibernate (30 s off on battery), which powers the PD controllers off, ends it. A partner which stays attached can keep working: after one such jump the HDMI Expansion Card, which was attached throughout, stayed. The crash restart itself left the ports working in my tests; it is the jump which follows.

Cause: when the jumped-to image starts with the AP off and the power button task idle, the chipset stays in G3, and cypd_handle_state() in CCG_STATE_APP_SETUP calls update_system_power_state(), which sends CCG_POWERSTATE_G3 (CCG_SYS_PWR_STATE = 0x05) to both controllers. After a sysjump the controllers have kept running with their ports up, and after this G3 they do not detect chargers any more, also when the EC later sends S0 (0x00) and runs perform_error_recovery().

Whether the image powers the AP on at once depends on set_initial_pwrbtn_state() in power_button_x86.c: reset flags equal to EC_RESET_FLAG_HARD, HIBERNATE without AC, or the AC attach option power it on (PB init-on after updating firmware, PB init power on, PB init AC attach on), and the chipset goes from G3 to S5 before the controllers are set up, so G3 is never sent. Otherwise it logs PB idle. After a jump the reset flags include SYSJUMP besides the cause of the last EC reset, so after --reboot-ec reboot (HARD | SYSJUMP) or after a crash restart (SOFT | SYSJUMP) the image logs PB idle and sends G3, while after a power-on start (POWER_ON | HIBERNATE without AC) it powers the AP on and does not.

Evidence (EC console of an instrumented build of 4.0.2, which logs the system power state written to each controller as DIAG; the code is otherwise Framework's):

A jump on battery after a power-on start, the ports keep working:

[0.152300 PB init power on]
[0.155300 power state 0 = G3, in 0x0001]
[0.161000 power state 6 = G3->S5, in 0x0001]
[0.168900 DIAG C0 update power state 6 prev 0]
[0.196700 DIAG C1 update power state 6 prev 0]
...
[0.419000 DIAG C0 sys power state 0x00 rv 0]
[0.420700 DIAG C1 sys power state 0x00 rv 0]

A jump on battery after framework_tool --reboot-ec reboot (reset flags Hard), a charger plugged in afterwards is not detected:

[0.152900 PB idle]
[0.155300 power state 0 = G3, in 0x0001]
[0.165700 DIAG C0 update power state 0 prev 0]
[0.167700 DIAG C0 sys power state 0x05 rv 0]
[0.188400 DIAG C1 update power state 0 prev 0]
[0.190400 DIAG C1 sys power state 0x05 rv 0]
...
[3.233100 DIAG C0 sys power state 0x00 rv 0]
[3.237900 DIAG C1 sys power state 0x00 rv 0]
[3.239700 DIAG C0 error recovery port 0]

The same sequence with a build which does not send G3 at the start of the image: no 0x05, and chargers on the right and on the left side charge. Since then I jumped into such a build after --reboot-ec reboot more than ten times, on battery and with a charger or a dock attached, and a charger or the dock connected afterwards was detected each time I tried.

In the dead state the controllers answer over I2C and their configuration reads the same as when they work: CCG_PDPORT_ENABLE_REG 0x03, CCG_SYS_PWR_STATE 0x00, event masks 0x2fffff, no pending interrupts. Only the port status differs: with a 100 W charger attached to port 0 of controller 0, CCG_TYPE_C_STATUS_REG(0) reads 0x00 and CCG_PD_STATUS_REG(0) 0x00014036, the same as an empty port, against 0x89 and 0x00259c76 once it works.

As far as I can see in the code, a cold start from hibernate with AC attached and the AP off also sends G3 during setup, and the ports work there, so the controllers accept G3 right after they power up. cypd_ccg6.c never sends G3 at all: it tells CCG6 controllers S5 for G3.

Proposed fix (commit on my branch): at the start of an image, send G3 only after a power-on reset of the EC which was not followed by a sysjump, when the controllers have just powered up as well, and otherwise only once the AP enters G3. In cypd_ccg8.c:

/* Whether the AP has been out of G3 since this EC image started. */
static bool ap_left_g3;

static bool pd_controllers_started_with_ec(void)
{
	return (system_get_reset_flags() & EC_RESET_FLAG_POWER_ON) &&
	       !system_jumped_to_this_image();
}
...
	if (ps != POWER_G3 && ps != POWER_S5G3)
		ap_left_g3 = true;

	switch (ps) {
	case POWER_G3:
	case POWER_S5G3:
		pd_prev_power_state = POWER_G3;
		if (ap_left_g3 || pd_controllers_started_with_ec())
			cypd_set_power_state(CCG_POWERSTATE_G3, controller);
		break;

An alternative is to tell such controllers S5 instead of G3, as the CCG6 code does. In the jumps where I tried it, chargers on both sides and the dock kept working as well. One difference: told nothing, the controllers do not report "AMD Crossbar is ready" (response 0x38) at the next power-on, while told S5 or G3 they do, which makes the EC run perform_error_recovery() once more. I saw no difference in function between the two.

The HDMI Expansion Card can also disappear after jumps for a different reason, see #106.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions