Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions drivers/phy/apple/atc.c
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,9 @@ struct atcphy_cio_sleep {
* it when the PHY is brought back up after a power-off
* @host_active: dwc3 has selected host mode on the USB3 PHY; a fixed-hub port
* then routes the PIPE itself on later Type-C mode changes
* @dwc3_running: dwc3 is out of the reset this PHY provides, in either role; follows
* the reset controller's assert/deassert only, not the register (the
* sleep hibernation steps toggle DWC3_RESET_N within one controller run)
* @usb3_port_off: The SuperSpeed root port of a fixed-hub controller was powered
* off for a PIPE or lane change and is not powered on again yet
* @usb3_port_work: Retries the power-on of @usb3_port_off after a USB failure
Expand Down Expand Up @@ -912,6 +915,7 @@ struct apple_atcphy {
bool fixed_usb2;
enum atcphy_mode typec_mode;
bool host_active;
bool dwc3_running;
/*
* The controller sleeps in place for this system sleep, the SuperSpeed side is checked
* against the mux after it, and the controller is in hibernation now.
Expand Down Expand Up @@ -5246,6 +5250,7 @@ static void _atcphy_dwc3_reset_assert(struct apple_atcphy *atcphy)
{
lockdep_assert_held(&atcphy->lock);

atcphy->dwc3_running = false;
clear32(atcphy->regs.pipehandler + PIPEHANDLER_AON_GEN, PIPEHANDLER_AON_GEN_DWC3_RESET_N);
set32(atcphy->regs.pipehandler + PIPEHANDLER_AON_GEN,
PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN);
Expand Down Expand Up @@ -5296,6 +5301,7 @@ static int atcphy_dwc3_reset_deassert(struct reset_controller_dev *rcdev, unsign
clear32(atcphy->regs.pipehandler + PIPEHANDLER_AON_GEN,
PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN);
set32(atcphy->regs.pipehandler + PIPEHANDLER_AON_GEN, PIPEHANDLER_AON_GEN_DWC3_RESET_N);
atcphy->dwc3_running = true;

return 0;
}
Expand Down Expand Up @@ -7848,12 +7854,14 @@ static int atcphy_suspend(struct device *dev)
return 0;
}
/*
* An active one survives suspend-to-idle while a host runs on it: DWC3
* then keeps the power domain on across system sleep, so the link stays
* as it is. Without a host, or in a deeper sleep state, it is lost.
* An active one survives suspend-to-idle while DWC3 runs on it, as a
* host or as a device: the glue then keeps the controller, and with it
* the power domain this PHY shares, on across system sleep, so the link
* stays as it is. With the controller in reset, or in a deeper sleep
* state, it is lost.
*/
if (atcphy->t8132_common_owned &&
(!atcphy->host_active || pm_suspend_target_state != PM_SUSPEND_TO_IDLE))
(!atcphy->dwc3_running || pm_suspend_target_state != PM_SUSPEND_TO_IDLE))
return -EBUSY;
/* Do not admit a new epoch after this check and before resume. */
atcphy->t8132_suspended = true;
Expand Down
18 changes: 12 additions & 6 deletions tools/asahi/atc-usb3-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def block(source, marker):
enum atcphy_pipehandler_state pipe_state;
enum atcphy_mode typec_mode;
bool pipe_pending, t8103_dummy_pending, t8103_usb3_retry, t8103_usb3_workaround, mode_dirty, usb_off_pending;
bool host_active, usb3_port_off, dp_only, ss_tunables, fixed_usb2, t8140_dp_tunables, dp_tunables;
bool host_active, dwc3_running, usb3_port_off, dp_only, ss_tunables, fixed_usb2, t8140_dp_tunables, dp_tunables;
/* T8132 ownership is tested without entering its lane-setup backend. */
bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt;
struct { void *usb3_dp; } tunables;
Expand Down Expand Up @@ -382,16 +382,16 @@ def block(source, marker):
static void reset_release_retries_before_writes(void) {
setup_legacy_usb3();unlock_ret=-ETIMEDOUT;assert(atcphy_park_live_t8103_pipehandler(&p)==-ETIMEDOUT);
u32 aon=BIT(14)|PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN;writel(aon,memory+PIPEHANDLER_AON_GEN);
assert(atcphy_dwc3_reset_deassert(&p.rcdev,0)==-ETIMEDOUT);assert(readl(memory+PIPEHANDLER_AON_GEN)==aon);
unlock_ret=0;assert(!atcphy_dwc3_reset_deassert(&p.rcdev,0));assert(!p.t8103_dummy_pending&&p.t8103_usb3_retry);
assert(atcphy_dwc3_reset_deassert(&p.rcdev,0)==-ETIMEDOUT);assert(readl(memory+PIPEHANDLER_AON_GEN)==aon&&!p.dwc3_running);
unlock_ret=0;assert(!atcphy_dwc3_reset_deassert(&p.rcdev,0));assert(!p.t8103_dummy_pending&&p.t8103_usb3_retry&&p.dwc3_running);
assert(readl(memory+PIPEHANDLER_AON_GEN)==((aon&~PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN)|PIPEHANDLER_AON_GEN_DWC3_RESET_N));
assert(!atcphy_usb3_set_mode(&phy,PHY_MODE_USB_HOST,0));assert(!p.t8103_usb3_retry&&p.pipe_state==ATCPHY_PIPEHANDLER_STATE_USB3);
}
static void reset_assert_failure_and_stop(void) {
setup_legacy_usb3();unlock_ret=-ETIMEDOUT;assert(atcphy_park_live_t8103_pipehandler(&p)==-ETIMEDOUT);
u32 aon=BIT(14)|PIPEHANDLER_AON_GEN_DWC3_RESET_N;writel(aon,memory+PIPEHANDLER_AON_GEN);
assert(atcphy_dwc3_reset_assert(&p.rcdev,0)==-ETIMEDOUT);assert(readl(memory+PIPEHANDLER_AON_GEN)==aon&&!usb2_power_off_calls);
unlock_ret=0;assert(!atcphy_dwc3_reset_assert(&p.rcdev,0));assert(!p.t8103_dummy_pending&&!p.t8103_usb3_retry&&usb2_power_off_calls==1);
u32 aon=BIT(14)|PIPEHANDLER_AON_GEN_DWC3_RESET_N;writel(aon,memory+PIPEHANDLER_AON_GEN);p.dwc3_running=true;
assert(atcphy_dwc3_reset_assert(&p.rcdev,0)==-ETIMEDOUT);assert(readl(memory+PIPEHANDLER_AON_GEN)==aon&&!usb2_power_off_calls&&p.dwc3_running);
unlock_ret=0;assert(!atcphy_dwc3_reset_assert(&p.rcdev,0));assert(!p.t8103_dummy_pending&&!p.t8103_usb3_retry&&usb2_power_off_calls==1&&!p.dwc3_running);
}
static void power_off_preserves_dp_and_finishes_pending(void) {
setup_legacy_usb3();unlock_ret=-ETIMEDOUT;assert(atcphy_park_live_t8103_pipehandler(&p)==-ETIMEDOUT);p.mode=APPLE_ATCPHY_MODE_USB3_DP;
Expand Down Expand Up @@ -866,6 +866,12 @@ def harness(source):
'clear32(atcphy->regs.pipehandler + PIPEHANDLER_AON_GEN, '
'PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN);\n'
'\tif (atcphy->t8103_dummy_pending) {'),
'reset-release-not-running': ('atcphy_dwc3_reset_deassert',
'atcphy->dwc3_running = true;',
'(void)0;'),
'reset-assert-keeps-running': ('void _atcphy_dwc3_reset_assert',
'atcphy->dwc3_running = false;',
'(void)0;'),
'reset-no-retry-clear': ('atcphy_dwc3_reset_assert',
'atcphy->t8103_usb3_retry = false;',
'(void)0;'),
Expand Down
27 changes: 22 additions & 5 deletions tools/testing/selftests/drivers/apple/atc-t8132-usb3.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def main():
struct apple_atcphy {
const struct atcphy_hw *hw;
struct device *dev;
bool t8132_ss, t8132_common_owned, t8132_suspended, t8132_failed, host_active;
bool t8132_ss, t8132_common_owned, t8132_suspended, t8132_failed, host_active, dwc3_running;
bool ss_tunables, mode_dirty, pipe_pending, swap_lanes;
bool cio_tunables, t8132_dp_alt, fixed_usb2, hibernated, pd_was_off, idle_rpm;
bool t8103_dummy_pending, t8103_usb3_workaround;
Expand Down Expand Up @@ -327,14 +327,23 @@ def main():
assert(!atcphy_configure_t8132(&a,APPLE_ATCPHY_MODE_USB3));
assert(atcphy_suspend(&dev)==-EBUSY && !a.t8132_suspended);
/* A running host keeps the epoch through suspend-to-idle only (cda0923e3d56). */
a.host_active=true; pm_suspend_target_state=PM_SUSPEND_MEM;
a.host_active=a.dwc3_running=true; pm_suspend_target_state=PM_SUSPEND_MEM;
assert(atcphy_suspend(&dev)==-EBUSY && !a.t8132_suspended);
pm_suspend_target_state=PM_SUSPEND_TO_IDLE;
unsigned kept=writes;
assert(!atcphy_suspend(&dev) && a.t8132_suspended && a.t8132_common_owned);
assert(atcphy_configure_t8132(&a,APPLE_ATCPHY_MODE_USB3)==-EBUSY && writes==kept);
assert(!atcphy_resume(&dev) && !a.t8132_suspended && a.t8132_common_owned);
a.host_active=false; pm_suspend_target_state=0;
/* So does a running device: the glue keeps the shared domain on for either role. */
a.host_active=false; pm_suspend_target_state=PM_SUSPEND_MEM;
assert(atcphy_suspend(&dev)==-EBUSY && !a.t8132_suspended);
pm_suspend_target_state=PM_SUSPEND_TO_IDLE; kept=writes;
assert(!atcphy_suspend(&dev) && a.t8132_suspended && a.t8132_common_owned && writes==kept);
assert(!atcphy_resume(&dev) && !a.t8132_suspended && a.t8132_common_owned);
/* A controller held in reset has nothing keeping the domain on. */
a.dwc3_running=false;
assert(atcphy_suspend(&dev)==-EBUSY && !a.t8132_suspended);
pm_suspend_target_state=0;
assert(atcphy_suspend(&dev)==-EBUSY && !a.t8132_suspended);
assert(!atcphy_configure_t8132(&a,APPLE_ATCPHY_MODE_OFF));
assert(!a.t8132_common_owned && !a.mode_dirty && !atcphy_suspend(&dev));
Expand Down Expand Up @@ -420,9 +429,17 @@ def main():
'''
run(Path(directory), "dwc3-t8132", role_program)
permissive = program.replace(
"(!atcphy->host_active || pm_suspend_target_state != PM_SUSPEND_TO_IDLE)", "false", 1)
"(!atcphy->dwc3_running || pm_suspend_target_state != PM_SUSPEND_TO_IDLE)", "false", 1)
assert permissive != program
run(Path(directory), "suspend-deep-negative-control", permissive, expect_failure=True)
host_only = program.replace(
"(!atcphy->dwc3_running || pm_suspend_target_state", "(!atcphy->host_active || pm_suspend_target_state", 1)
assert host_only != program
run(Path(directory), "suspend-host-only-negative-control", host_only, expect_failure=True)
no_reset = program.replace(
"(!atcphy->dwc3_running || pm_suspend_target_state", "(!atcphy->t8132_ss || pm_suspend_target_state", 1)
assert no_reset != program
run(Path(directory), "suspend-reset-negative-control", no_reset, expect_failure=True)
permissive = program.replace(
"if (atcphy->mode_dirty)\n\t\treturn -EBUSY;", "if (false)\n\t\treturn -EBUSY;", 1)
assert permissive != program
Expand Down Expand Up @@ -673,7 +690,7 @@ def main():
struct atcphy_hw { int gen; };
struct apple_atcphy {
const struct atcphy_hw *hw;struct device *dev;int lock,pipe_state;
bool t8132_ss,t8132_suspended,t8132_common_owned,t8132_failed,host_active,pipe_pending;
bool t8132_ss,t8132_suspended,t8132_common_owned,t8132_failed,host_active,dwc3_running,pipe_pending;
};
#define APPLE_ATCPHY_MODE_OFF 0
static struct apple_atcphy atc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct apple_atcphy {
bool aux, pll;
unsigned int pairs, rate;
} dp_t8122;
bool fixed_usb2, host_active, mode_dirty, ss_tunables, dp_tunables,
bool fixed_usb2, host_active, dwc3_running, mode_dirty, ss_tunables, dp_tunables,
aux_power_requested;
unsigned int dp_owned_pmas, dp_idle_pmas;
unsigned int dp_usb_context_valid, dp_usb_context_dirty;
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/drivers/gpu/apple-dcp/phy.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def function(source, name):
struct reset_controller_dev rcdev;
void *dev;
int lock, dp_link_rate;
bool fixed_usb2, host_active, swap_lanes, ss_tunables, dp_tunables;
bool fixed_usb2, host_active, dwc3_running, swap_lanes, ss_tunables, dp_tunables;
bool aux_power_requested, mode_dirty, dp_spread_spectrum, dp_presets_valid[5];
u32 dp_presets[5][16];
unsigned int dp_idle_pmas, dp_owned_pmas;
Expand Down Expand Up @@ -1948,7 +1948,7 @@ def function(name):
struct { unsigned char *core, *pipehandler; } regs;
void *dev;
int lock;
bool fixed_usb2, host_active, ss_tunables, dp_tunables, mode_dirty;
bool fixed_usb2, host_active, dwc3_running, ss_tunables, dp_tunables, mode_dirty;
unsigned int dp_owned_pmas, dp_idle_pmas;
unsigned int dp_usb_context_valid, dp_usb_context_dirty;
u32 dp_usb_context[2][27];
Expand Down Expand Up @@ -2348,7 +2348,7 @@ def function(source, name):
struct { unsigned char *core, *lpdptx, *lioa; } regs;
void *dev;
int lock, dp_link_rate;
bool fixed_usb2, host_active, swap_lanes, ss_tunables, dp_tunables;
bool fixed_usb2, host_active, dwc3_running, swap_lanes, ss_tunables, dp_tunables;
bool aux_power_requested, mode_dirty, dp_spread_spectrum, dp_presets_valid[5];
u32 dp_presets[5][16];
unsigned int dp_idle_pmas, dp_owned_pmas;
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/drivers/gpu/apple-dcp/quiesce.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def make_unit(source, parent=False, reference=None):
void *dev; int lock;
const struct atcphy_hw *hw;
struct { void *usb2phy; } regs;
bool fixed_usb2,host_active,mode_dirty,pipe_pending,usb_off_pending,ss_tunables,dp_tunables,cio_tunables,t8132_dp_alt;
bool fixed_usb2,host_active,dwc3_running,mode_dirty,pipe_pending,usb_off_pending,ss_tunables,dp_tunables,cio_tunables,t8132_dp_alt;
bool usb3_port_off,park_owed,dp_only,pd_was_off;
bool t8103_dummy_pending,t8103_usb3_retry,t8103_usb3_workaround;
enum atcphy_mode mode,typec_mode;
Expand Down
Loading