Skip to content
Closed
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
10 changes: 10 additions & 0 deletions Documentation/devicetree/bindings/phy/apple,t6040-atcphy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ properties:
$ref: "#/$defs/apple,tunable"
description: USB2 host tunables, applied to the bank0 region.

apple,tunable-usb2-default:
$ref: "#/$defs/apple,tunable"
description:
USB2 default tunables, applied to the bank0 region before the device
tunables when the port runs as a USB device.

apple,tunable-usb2-device:
$ref: "#/$defs/apple,tunable"
description: USB2 device tunables, applied to the bank0 region.

required:
- compatible
- reg
Expand Down
50 changes: 50 additions & 0 deletions drivers/phy/apple/atc-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,54 @@ static void atcphy_test_target_mode_t8132(struct kunit *test)
KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_OFF);
}

/* T8132 has no SuperSpeed device mode: a device role keeps the lanes on USB2. */
static void atcphy_test_t8132_device_role_usb2(struct kunit *test)
{
struct typec_altmode dp = { .svid = USB_TYPEC_DP_SID };
struct typec_mux_state state = { .mode = TYPEC_STATE_USB };
struct apple_atcphy *atcphy = atcphy_test_alloc_dev(test, false);

atcphy->hw = &atcphy_hw_t8132;
atcphy->t8132_ss = true;
atcphy->ss_tunables = true;
KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB3);
atcphy->usb2_device = true;
KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB2);
state.alt = &dp;
state.mode = TYPEC_DP_STATE_D;
KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_USB2);
KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP),
APPLE_ATCPHY_MODE_USB2);
atcphy->t8132_dp_alt = true;
KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_USB3_DP),
APPLE_ATCPHY_MODE_DP);
KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_DP),
APPLE_ATCPHY_MODE_DP);
KUNIT_EXPECT_EQ(test, atcphy_usb2_device_mode(atcphy, APPLE_ATCPHY_MODE_OFF),
APPLE_ATCPHY_MODE_OFF);
state.alt = NULL;
state.mode = TYPEC_STATE_SAFE;
KUNIT_EXPECT_EQ(test, atcphy_typec_target_mode(atcphy, &state), APPLE_ATCPHY_MODE_OFF);
}

/* .validate tells dwc3-apple whether the USB3 PHY can carry a SuperSpeed device. */
static void atcphy_test_usb3_validate_device(struct kunit *test)
{
struct apple_atcphy *atcphy = atcphy_test_alloc_dev(test, false);
struct phy *phy = kunit_kzalloc(test, sizeof(*phy), GFP_KERNEL);

KUNIT_ASSERT_NOT_NULL(test, phy);
dev_set_drvdata(&phy->dev, atcphy);
atcphy->hw = &atcphy_hw_t8132;
KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_USB_HOST, 0, NULL), 0);
KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_USB_DEVICE, 0, NULL), -EOPNOTSUPP);
atcphy->hw = &atcphy_hw_t8122;
KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_USB_DEVICE, 0, NULL), 0);
atcphy->hw = &atcphy_hw_t8103;
KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_USB_DEVICE, 0, NULL), 0);
KUNIT_EXPECT_EQ(test, atcphy_usb3_validate(phy, PHY_MODE_DP, 0, NULL), -EOPNOTSUPP);
}

static void atcphy_test_noop_same_mode(struct kunit *test)
{
struct apple_atcphy *atcphy = atcphy_test_alloc(test, true);
Expand Down Expand Up @@ -1391,6 +1439,8 @@ static struct kunit_case atcphy_mux_test_cases[] = {
KUNIT_CASE(atcphy_test_target_mode),
KUNIT_CASE(atcphy_test_target_mode_fixed_hub),
KUNIT_CASE(atcphy_test_target_mode_t8132),
KUNIT_CASE(atcphy_test_t8132_device_role_usb2),
KUNIT_CASE(atcphy_test_usb3_validate_device),
KUNIT_CASE(atcphy_test_noop_same_mode),
KUNIT_CASE(atcphy_test_noop_needs_work),
KUNIT_CASE(atcphy_test_usb3_port_ready),
Expand Down
84 changes: 80 additions & 4 deletions drivers/phy/apple/atc.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,10 @@ struct apple_atcphy;
* can also drop while the system runs, see atcphy_rpm_get().
* Only for PHYs without DisplayPort, whose phy ops and tunnel
* calls take no runtime PM reference
* @no_ss_device: No SuperSpeed device mode. .validate refuses PHY_MODE_USB_DEVICE
* on the USB3 PHY, so that the controller sets itself up as a
* high-speed device, and a device role keeps the lanes off USB3
* (usb2_device in struct apple_atcphy)
*/
struct atcphy_hw {
void (*configure_post_tunable)(struct apple_atcphy *, enum atcphy_mode);
Expand All @@ -725,6 +729,7 @@ struct atcphy_hw {
bool clear_boot_hold;
bool restore_after_pd_off;
bool idle_power_off;
bool no_ss_device;
};

enum atcphy_t8132_bank {
Expand Down Expand Up @@ -881,6 +886,12 @@ struct apple_atcphy {
const struct atcphy_hw *hw;
/* T8132 keeps USB2 support when its optional SuperSpeed banks are absent. */
bool t8132_ss;
/*
* No SuperSpeed device mode (hw->no_ss_device): while the controller
* holds the device role, the lanes run the USB2 mode the partner's USB3
* mode would otherwise take. Cleared by the host role and the safe state.
*/
bool usb2_device;
/* Only this driver's admitted common-power epoch may be stopped. */
bool t8132_common_owned;
/* A touched failure has no qualified partial rollback or retry. */
Expand Down Expand Up @@ -3620,6 +3631,21 @@ static bool atcphy_t8132_dp_on(const struct apple_atcphy *atcphy)
return atcphy->hw->gen == ATCPHY_GENERATION_T8132 && atcphy->t8132_dp_alt;
}

/*
* The mode a port without SuperSpeed device mode runs in while its controller
* is a USB device: the same lanes without SuperSpeed. USB2 stays on its own
* wires next to four-lane DisplayPort.
*/
static enum atcphy_mode atcphy_usb2_device_mode(const struct apple_atcphy *atcphy,
enum atcphy_mode mode)
{
if (mode == APPLE_ATCPHY_MODE_USB3)
return APPLE_ATCPHY_MODE_USB2;
if (mode == APPLE_ATCPHY_MODE_USB3_DP)
return atcphy_t8132_dp_on(atcphy) ? APPLE_ATCPHY_MODE_DP : APPLE_ATCPHY_MODE_USB2;
return mode;
}

/*
* The T8132 lane start differs from the T8122 one: both blocks start at swing
* 0 / pre-emphasis 0, the RX block's VREF filter is held until both DTVREG
Expand Down Expand Up @@ -4612,9 +4638,17 @@ static int atcphy_rpm_usb2_set_mode(struct phy *phy, enum phy_mode mode, int sub
return ret;
}

/* Both roles: atcphy_usb2_set_mode() sets or clears the host signature. */
static int atcphy_usb2_validate(struct phy *phy, enum phy_mode mode, int submode,
union phy_configure_opts *opts)
{
return mode == PHY_MODE_USB_HOST || mode == PHY_MODE_USB_DEVICE ? 0 : -EOPNOTSUPP;
}

static const struct phy_ops apple_atc_usb2_phy_ops = {
.owner = THIS_MODULE,
.init = atcphy_rpm_usb2_init,
.validate = atcphy_usb2_validate,
.set_mode = atcphy_rpm_usb2_set_mode,
};

Expand Down Expand Up @@ -4714,6 +4748,8 @@ static int atcphy_usb3_route(struct apple_atcphy *atcphy, bool host)
return atcphy_configure_pipehandler(atcphy, host);
}

static int atcphy_mux_switch(struct apple_atcphy *atcphy, enum atcphy_mode target_mode);

static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode)
{
struct apple_atcphy *atcphy = phy_get_drvdata(phy);
Expand All @@ -4725,10 +4761,26 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode
if (atcphy->usb_off_pending)
return -EBUSY;

if (atcphy->t8132_ss &&
(atcphy->mode == APPLE_ATCPHY_MODE_USB3 || atcphy->mode == APPLE_ATCPHY_MODE_USB3_DP) &&
mode == PHY_MODE_USB_DEVICE)
return -EOPNOTSUPP;
if (atcphy->hw->no_ss_device && mode == PHY_MODE_USB_DEVICE) {
enum atcphy_mode usb2 = atcphy_usb2_device_mode(atcphy, atcphy->mode);

/*
* No SuperSpeed device mode: serve the device role on USB2, as
* the port did without its USB3 calibration, instead of failing
* the role. Later mux updates keep USB2 (usb2_device). Without
* the T8132 SuperSpeed banks the lanes never leave USB2.
*/
atcphy->usb2_device = true;
if (usb2 != atcphy->mode) {
dev_info(atcphy->dev, "USB device role: no SuperSpeed device mode, using USB2\n");
ret = atcphy_mux_switch(atcphy, usb2);
if (ret)
return ret;
}
} else if (mode == PHY_MODE_USB_HOST) {
/* The lanes regain USB3 with the next mux update (a data role swap). */
atcphy->usb2_device = false;
}

switch (mode) {
case PHY_MODE_USB_HOST:
Expand Down Expand Up @@ -4810,8 +4862,26 @@ static int atcphy_rpm_usb3_set_mode(struct phy *phy, enum phy_mode mode, int sub
return ret;
}

/*
* Both roles, except a device role on a PHY without SuperSpeed device mode:
* atcphy_usb3_set_mode() serves that one on USB2, and the controller must run
* as a high-speed device.
*/
static int atcphy_usb3_validate(struct phy *phy, enum phy_mode mode, int submode,
union phy_configure_opts *opts)
{
struct apple_atcphy *atcphy = phy_get_drvdata(phy);

if (mode == PHY_MODE_USB_HOST)
return 0;
if (mode == PHY_MODE_USB_DEVICE)
return atcphy->hw->no_ss_device ? -EOPNOTSUPP : 0;
return -EOPNOTSUPP;
}

static const struct phy_ops apple_atc_usb3_phy_ops = {
.owner = THIS_MODULE,
.validate = atcphy_usb3_validate,
.exit = atcphy_usb3_exit,
.power_off = atcphy_rpm_usb3_power_off,
.set_mode = atcphy_rpm_usb3_set_mode,
Expand Down Expand Up @@ -5787,6 +5857,8 @@ static enum atcphy_mode atcphy_typec_target_mode(struct apple_atcphy *atcphy,
target_mode = usb_mode;
}
}
if (atcphy->usb2_device)
target_mode = atcphy_usb2_device_mode(atcphy, target_mode);

/*
* T8142 runs DisplayPort only with the boot loader's LIOA and common
Expand Down Expand Up @@ -5910,6 +5982,9 @@ static int atcphy_mux_switch(struct apple_atcphy *atcphy, enum atcphy_mode targe
int ret;

lockdep_assert_held(&atcphy->lock);
/* The partner is gone: the next one starts without the device-role USB2 limit. */
if (target_mode == APPLE_ATCPHY_MODE_OFF)
atcphy->usb2_device = false;
if (atcphy->t8103_dummy_pending) {
ret = atcphy_park_live_t8103_pipehandler(atcphy);
if (ret)
Expand Down Expand Up @@ -7947,6 +8022,7 @@ static const struct atcphy_hw atcphy_hw_t8122 = {
static const struct atcphy_hw atcphy_hw_t8132 = {
.gen = ATCPHY_GENERATION_T8132,
.usb2_only = true,
.no_ss_device = true,
.usb2phy_sig_host = USB2PHY_SIG_HOST_T8132,
.pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8103,
.pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8103,
Expand Down
Loading
Loading