Skip to content
Merged
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
1 change: 1 addition & 0 deletions arch/arm64/boot/dts/apple/t6041-j575c-atc3.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
apple,event-irq-in-sleep;
/* Retimer set up before Linux keeps SuperSpeed down until replugged. */
apple,reset-inherited-usb2-connection;
apple,debug-lock-key = "575J";

typec3: connector {
compatible = "usb-c-connector";
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/boot/dts/apple/t6041-j575c.dts
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@
apple,event-irq-in-sleep;
/* Retimer set up before Linux keeps SuperSpeed down until replugged. */
apple,reset-inherited-usb2-connection;
apple,debug-lock-key = "575J";

typec1: connector {
compatible = "usb-c-connector";
Expand Down Expand Up @@ -1481,6 +1482,7 @@
apple,event-irq-in-sleep;
/* Retimer set up before Linux keeps SuperSpeed down until replugged. */
apple,reset-inherited-usb2-connection;
apple,debug-lock-key = "575J";

typec2: connector {
compatible = "usb-c-connector";
Expand Down
73 changes: 39 additions & 34 deletions drivers/usb/typec/tipd/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3581,25 +3581,38 @@ static int cd321x_remove(struct tps6598x *tps)
}

/*
* Boards whose inherited boot connection must be renegotiated. The port
* controller key is the reversed target identifier.
* An SN201202x takes "DISC" unlocked with the key its DT gives it (apple,debug-lock-key, the board
* number reversed).
*/
static int tipd_replug_key(struct tps6598x *tps, u8 key[4])
{
const char *s;

if (!device_is_compatible(tps->dev, "apple,sn201202x") ||
device_property_read_string(tps->dev, "apple,debug-lock-key", &s) || strlen(s) != 4)
return -EOPNOTSUPP;
memcpy(key, s, 4);
return 0;
}

/*
* A connection that was up before Linux keeps state from the boot chain: a USB2 repeater
* connection on the J716c boot port, or on the J575c a Type-C retimer set up before the host PHY
* ran, so SuperSpeed stays in RxDetect until the partner is replugged. The controller reports
* nothing that tells such a connection apart from one that trains, so every one is renegotiated.
*
* J716c: the boot port keeps a USB2 repeater connection.
* J575c: a connection that was up before Linux keeps its Type-C retimer set up
* from before the host PHY ran, so SuperSpeed stays in RxDetect until the
* partner is replugged. Every such connection is renegotiated: the controller
* reports nothing that tells it apart from one whose SuperSpeed side trains.
* A failure leaves the port as it was (USB2 only) instead of failing the probe.
* The renegotiation's DISC takes the controller unlocked with the board's LOCK key, the board
* number reversed. A port whose DT gives it (apple,debug-lock-key) is left as it was if the
* renegotiation fails. The J716c's DT does not give it yet: its key is here, and a failure there
* fails the probe.
*/
struct cd321x_inherited_board {
const char *compatible;
u8 key[4];
bool best_effort;
};

static const struct cd321x_inherited_board cd321x_inherited_boards[] = {
{ .compatible = "apple,j716c", .key = { '6', '1', '7', 'J' } },
{ .compatible = "apple,j575c", .key = { '5', '7', '5', 'J' }, .best_effort = true },
};

static const struct cd321x_inherited_board *cd321x_inherited_board(void)
Expand All @@ -3612,8 +3625,7 @@ static const struct cd321x_inherited_board *cd321x_inherited_board(void)
return NULL;
}

static int __cd321x_reset_inherited_connection(struct tps6598x *tps,
const struct cd321x_inherited_board *board,
static int __cd321x_reset_inherited_connection(struct tps6598x *tps, const u8 key[4],
u32 *status)
{
static const u8 locked[4];
Expand All @@ -3626,8 +3638,7 @@ static int __cd321x_reset_inherited_connection(struct tps6598x *tps,
return 0;

/* All suppliers are available, but no USB or router session has started. */
ret = tps6598x_exec_cmd(tps, "LOCK", sizeof(board->key), board->key, sizeof(result),
&result);
ret = tps6598x_exec_cmd(tps, "LOCK", 4, key, sizeof(result), &result);
if (ret)
return ret;
if (result) {
Expand Down Expand Up @@ -3670,19 +3681,28 @@ static int __cd321x_reset_inherited_connection(struct tps6598x *tps,
static int cd321x_reset_inherited_connection(struct tps6598x *tps, u32 *status)
{
const struct cd321x_inherited_board *board;
bool best_effort = true;
u8 key[4];
int ret;

if (!device_property_read_bool(tps->dev, "apple,reset-inherited-usb2-connection") ||
!device_is_compatible(tps->dev, "apple,sn201202x") ||
tps->dbma_at_probe || !(*status & TPS_STATUS_PLUG_PRESENT) ||
!TPS_STATUS_TO_TYPEC_DATAROLE(*status))
return 0;
board = cd321x_inherited_board();
if (!board)
return 0;
if (tipd_replug_key(tps, key)) {
board = cd321x_inherited_board();
if (!board) {
dev_warn(tps->dev,
"inherited connection not reinitialized: no apple,debug-lock-key\n");
return 0;
}
memcpy(key, board->key, sizeof(key));
best_effort = false;
}

ret = __cd321x_reset_inherited_connection(tps, board, status);
if (!ret || !board->best_effort)
ret = __cd321x_reset_inherited_connection(tps, key, status);
if (!ret || !best_effort)
return ret;

dev_warn(tps->dev, "inherited connection not reinitialized: %d\n", ret);
Expand Down Expand Up @@ -3719,21 +3739,6 @@ static void tipd_port_list_del(struct tps6598x *tps)
cancel_work_sync(&tps->replug_work);
}

/*
* An SN201202x takes "DISC" unlocked with the key its DT gives it (apple,debug-lock-key, the board
* number reversed).
*/
static int tipd_replug_key(struct tps6598x *tps, u8 key[4])
{
const char *s;

if (!device_is_compatible(tps->dev, "apple,sn201202x") ||
device_property_read_string(tps->dev, "apple,debug-lock-key", &s) || strlen(s) != 4)
return -EOPNOTSUPP;
memcpy(key, s, 4);
return 0;
}

bool tipd_replug_supported(struct tps6598x *tps)
{
u8 key[4];
Expand Down
Loading