Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
43 changes: 9 additions & 34 deletions drivers/phy/apple/atc-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,39 +1740,14 @@ static void atcphy_test_t6030_restore_dp_mode_fail(struct kunit *test)
KUNIT_EXPECT_FALSE(test, atcphy->pd_state_forgotten);
}

static void atcphy_test_t8103_usb3_machine_scope(struct kunit *test)
{
static const struct {
const char *compatible;
bool enabled;
} cases[] = {
{ "apple,t8103", true },
{ "apple,t6000", false },
{ "apple,t6001", false },
{ "apple,t6002", false },
{ "apple,t8112", false },
{ "apple,t6020", false },
{ "apple,t6021", false },
{ "apple,t6022", false },
{ "apple,t8122", false },
{ "apple,t6030", false },
{ "apple,t6031", false },
{ "apple,t6034", false },
{ "apple,t8140", false },
{ "apple,t8142", false },
};
struct property compatible = { .name = "compatible" };
struct device_node root = { .properties = &compatible };

for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {
compatible.value = (void *)cases[i].compatible;
compatible.length = strlen(cases[i].compatible) + 1;
/* M2 and Pro/Max PHYs select this same fallback hardware row. */
KUNIT_EXPECT_EQ(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8103, &root),
cases[i].enabled);
KUNIT_EXPECT_FALSE(test,
atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8122, &root));
}
/* The handoff follows the PIPE handler generation, whatever the machine. */
static void atcphy_test_t8103_usb3_generation_scope(struct kunit *test)
{
KUNIT_EXPECT_TRUE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8103));
KUNIT_EXPECT_FALSE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8122));
KUNIT_EXPECT_FALSE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8132));
KUNIT_EXPECT_FALSE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8140));
KUNIT_EXPECT_FALSE(test, atcphy_has_t8103_usb3_workaround(&atcphy_hw_t8142));
}

static const struct atcphy_hw *atcphy_test_match_hw(struct kunit *test,
Expand Down Expand Up @@ -1863,7 +1838,7 @@ static void atcphy_test_idle_power_off_dt(struct kunit *test)
}

static struct kunit_case atcphy_mux_test_cases[] = {
KUNIT_CASE(atcphy_test_t8103_usb3_machine_scope),
KUNIT_CASE(atcphy_test_t8103_usb3_generation_scope),
KUNIT_CASE(atcphy_test_idle_power_off_dt),
KUNIT_CASE(atcphy_test_target_mode),
KUNIT_CASE(atcphy_test_target_mode_fixed_hub),
Expand Down
58 changes: 39 additions & 19 deletions drivers/phy/apple/atc.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,13 @@ enum atcphy_lane_mode {
#define PIPEHANDLER_NATIVE_POWER_DOWN GENMASK(3, 0)

#define PIPEHANDLER_LOCK_ACK_TIMEOUT_US 1000
/*
* A live USB3 PIPE: the controller ACKs the lock only once it has let go of
* the PIPE, which a running link can take several ms to do. The old handoff
* asked up to ten times, 1 ms each with 5-10 ms between; this window covers
* the same span with the request held.
*/
#define PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US (100 * USEC_PER_MSEC)

/* USB2 PHY regs */
#define USB2PHY_USBCTL 0x00
Expand Down Expand Up @@ -939,7 +946,7 @@ struct atcphy_cio_sleep {
* @pipe_state: Backend the PIPE mux ("pipehandler") is routed to
* @t8103_dummy_pending: A live T8103-generation handoff still needs its unlock ACK
* @t8103_usb3_retry: USB3 routing owed after a deferred role or parked lane change
* @t8103_usb3_workaround: Base M1 admission for the USB3 handoff workaround
* @t8103_usb3_workaround: The T8103-generation USB3 handoff, see atcphy_has_t8103_usb3_workaround()
* @pd_nb: Power domain notifier, registered with restore_after_pd_off
* @pd_was_off: The power domain was switched off since the state was last
* brought back; set from the notifier, cleared under @lock
Expand Down Expand Up @@ -1626,8 +1633,10 @@ static int atcphy_pipehandler_lock_timeout(struct apple_atcphy *atcphy, u32 time
set32(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ, PIPEHANDLER_LOCK_EN);
}

/* Step coarser over a long window: the ACK is the only signal to wait for. */
ret = readl_poll_timeout(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_ACK, reg,
reg & PIPEHANDLER_LOCK_EN, 10, timeout);
reg & PIPEHANDLER_LOCK_EN,
timeout > 10 * USEC_PER_MSEC ? 100 : 10, timeout);
/*
* A controller that still drives the PIPE can take longer than this to
* let go. What that means is the caller's to decide: a best-effort lock
Expand Down Expand Up @@ -1658,20 +1667,27 @@ static int atcphy_pipehandler_lock(struct apple_atcphy *atcphy)
6000 : PIPEHANDLER_LOCK_ACK_TIMEOUT_US);
}

/* Retry only a live legacy PIPE: USB4 and stopped parking cannot clock the ACK. */
/*
* Lock a live USB3 PIPE: the running controller clocks the ACK, and gives it
* once it has let go of the PIPE. One request, held, and the ACK polled for the
* whole live window, rather than dropping and asking again. USB4 and stopped
* parking cannot clock the ACK and do not come here.
*/
static int atcphy_pipehandler_lock_live(struct apple_atcphy *atcphy)
{
unsigned int attempts = atcphy->t8103_usb3_workaround ? 10 : 1;
int ret;
u32 aon;

for (unsigned int attempt = 0; attempt < attempts; attempt++) {
ret = atcphy_pipehandler_lock(atcphy);
if (!ret)
return 0;
if (attempt + 1 < attempts)
usleep_range(5000, 10000);
}
return ret;
/* The tests stand in for the controller that acknowledges the lock. */
if (IS_ENABLED(CONFIG_PHY_APPLE_ATC_KUNIT_TEST))
KUNIT_STATIC_STUB_REDIRECT(atcphy_pipehandler_lock_live, atcphy);

/* A controller held in reset or clamped clocks nothing: no ACK can come. */
aon = readl(atcphy->regs.pipehandler + PIPEHANDLER_AON_GEN);
if (!(aon & PIPEHANDLER_AON_GEN_DWC3_RESET_N) ||
(aon & PIPEHANDLER_AON_GEN_DWC3_FORCE_CLAMP_EN))
return -ETIMEDOUT;

return atcphy_pipehandler_lock_timeout(atcphy, PIPEHANDLER_LOCK_LIVE_ACK_TIMEOUT_US);
}

static int atcphy_pipehandler_unlock(struct apple_atcphy *atcphy)
Expand Down Expand Up @@ -9071,12 +9087,16 @@ static bool atcphy_probe_pd_notifier(struct apple_atcphy *atcphy)
return !ret;
}

/* The T8103 PHY compatible is also a fallback on unqualified M1/M2 variants. */
static bool atcphy_has_t8103_usb3_workaround(const struct atcphy_hw *hw,
const struct device_node *root)
/*
* The USB3 handoff of the T8103-generation PIPE handler: a live PIPE is parked
* on the dummy backend under a held lock before a lane change, host BIST is
* skipped, and an early dwc3 role routes USB3 once Type-C asks for it. It is a
* property of that PIPE handler, so every PHY of the generation takes it: the
* apple,t8103-atcphy fallback of T8103, T600x, T8112 and T602x.
*/
static bool atcphy_has_t8103_usb3_workaround(const struct atcphy_hw *hw)
{
return hw->gen == ATCPHY_GENERATION_T8103 &&
of_device_is_compatible(root, "apple,t8103");
return hw->gen == ATCPHY_GENERATION_T8103;
}

/*
Expand Down Expand Up @@ -9176,7 +9196,7 @@ static int atcphy_probe(struct platform_device *pdev)
atcphy->hw = of_device_get_match_data(&pdev->dev);
if (!atcphy->hw)
return -EINVAL;
atcphy->t8103_usb3_workaround = atcphy_has_t8103_usb3_workaround(atcphy->hw, of_root);
atcphy->t8103_usb3_workaround = atcphy_has_t8103_usb3_workaround(atcphy->hw);

atcphy->dev = dev;
atcphy->np = dev->of_node;
Expand Down
Loading
Loading