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
4 changes: 2 additions & 2 deletions drivers/usb/typec/tipd/cd321x-pm-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,8 @@ static void cd321x_dp_send_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, cd321x_dp_send(hpd, irq, false), CD321X_DP_SEND);
KUNIT_EXPECT_EQ(test, cd321x_dp_send(irq, hpd, false), CD321X_DP_SEND);
KUNIT_EXPECT_EQ(test, cd321x_dp_send(hpd, 0, false), CD321X_DP_SEND);
/* An HPD pulse is sent once, as an edge if the route holds IRQ_HPD. */
KUNIT_EXPECT_EQ(test, cd321x_dp_send(hpd, irq, true), CD321X_DP_SEND);
/* A coalesced HPD drop/rise replays HPD low first, then high. */
KUNIT_EXPECT_EQ(test, cd321x_dp_send(hpd, hpd, true), CD321X_DP_SEND_EDGE);
KUNIT_EXPECT_EQ(test, cd321x_dp_send(irq, irq, true), CD321X_DP_SEND_EDGE);
}

Expand Down
11 changes: 5 additions & 6 deletions drivers/usb/typec/tipd/cd321x-pm.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,24 +377,23 @@ static inline bool cd321x_display_taken(int ret)
enum cd321x_dp_send {
CD321X_DP_SEND_NONE, /* the display route holds this status */
CD321X_DP_SEND, /* send the status */
CD321X_DP_SEND_EDGE, /* send it without IRQ_HPD first, then with it */
CD321X_DP_SEND_EDGE, /* send HPD low first, then the status */
};

/*
* What a DP alt mode update with DP status @status sends to the display
* route, which holds @applied for the same pin assignment and configuration.
* The route drops a status equal to the one it holds, and so does this: an
* IRQ_HPD that the partner's last status still carries is not a new request.
* @pulse is a new request: the sink dropped HPD and raised it again since the
* last update (@status has IRQ_HPD set for it). When the route holds IRQ_HPD
* already, the request is sent as an edge, so that the route sees it.
* @pulse means the sink dropped HPD and raised it again since the last update:
* replay HPD low first so the display route tears down and retrains the link
* anew, matching an uncoalesced HPD drop.
*/
static inline enum cd321x_dp_send cd321x_dp_send(u32 applied, u32 status,
bool pulse)
{
if (pulse)
return applied & DP_STATUS_IRQ_HPD ? CD321X_DP_SEND_EDGE :
CD321X_DP_SEND;
return CD321X_DP_SEND_EDGE;
return applied == status ? CD321X_DP_SEND_NONE : CD321X_DP_SEND;
}

Expand Down
37 changes: 18 additions & 19 deletions drivers/usb/typec/tipd/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,25 +916,26 @@ static int cd321x_typec_update_mode(struct tps6598x *tps,

/*
* The sink dropped HPD and raised it again within the debounce
* window, as a monitor does after losing the link. The coalesced
* state looks unchanged, so the display side would never hear of
* it: report the pulse as IRQ_HPD. A port with a displayport
* reference reports the pulse out of band instead, as a
* disconnect and a connect (see cd321x_update_work()).
* window, as a monitor does after losing the link or waking
* from standby. Replay HPD low first so the display route
* disconnects and retrains the link anew, matching an
* uncoalesced HPD drop. A port with a displayport reference
* reports the pulse out of band instead, as a disconnect and
* a connect (see cd321x_update_work()).
*/
hpd_pulse = !tps->h17_display &&
!(IS_REACHABLE(CONFIG_DRM) && cd321x->connector_fwnode) &&
cd321x->state_valid &&
cd321x->state.alt == cd321x->port_altmode_dp &&
(st->data_status_changed & CD321X_DATA_STATUS_HPD_LEVEL) &&
(dp_data.status & DP_STATUS_HPD_STATE) &&
(cd321x->dp_status & DP_STATUS_HPD_STATE);
if (hpd_pulse)
dp_data.status |= DP_STATUS_IRQ_HPD;

if (cd321x->state_valid && cd321x->state.alt == cd321x->port_altmode_dp &&
cd321x->state.mode == mode && cd321x->dp_conf == dp_data.conf)
send = cd321x_dp_send(cd321x->dp_status, dp_data.status, hpd_pulse);
else
send = CD321X_DP_SEND;
send = hpd_pulse ? CD321X_DP_SEND_EDGE : CD321X_DP_SEND;
if (send == CD321X_DP_SEND_NONE)
return 0;

Expand All @@ -946,7 +947,8 @@ static int cd321x_typec_update_mode(struct tps6598x *tps,
goto out;
if (send == CD321X_DP_SEND_EDGE) {
struct typec_displayport_data edge = {
.status = dp_data.status & ~DP_STATUS_IRQ_HPD,
.status = dp_data.status &
~(DP_STATUS_HPD_STATE | DP_STATUS_IRQ_HPD),
.conf = dp_data.conf,
};

Expand Down Expand Up @@ -1358,6 +1360,8 @@ static void cd321x_update_work(struct work_struct *work)
cd321x->state = old_state;
goto retry;
}
cd321x->dp_status = 0;
cd321x->dp_conf = 0;
cd321x->display_route_active = false;
}

Expand Down Expand Up @@ -3004,7 +3008,6 @@ static bool cd321x_display_gate_pending(struct tps6598x *tps)
static int
cd321x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode)
{
struct fwnode_handle *connector_fwnode;
struct cd321x *cd321x = container_of(tps, struct cd321x, tps);
bool tbt_late;
int ret;
Expand All @@ -3025,12 +3028,9 @@ cd321x_register_port(struct tps6598x *tps, struct fwnode_handle *fwnode)
goto err_unregister_altmodes;
}

if (fwnode_property_present(fwnode, "displayport"))
connector_fwnode = fwnode_find_reference(fwnode, "displayport", 0);
else
connector_fwnode = fwnode_handle_get(fwnode);
if (!IS_ERR_OR_NULL(connector_fwnode))
cd321x->connector_fwnode = connector_fwnode;
cd321x->connector_fwnode = fwnode_find_reference(fwnode, "displayport", 0);
if (IS_ERR(cd321x->connector_fwnode))
cd321x->connector_fwnode = NULL;

cd321x->tbt_switch = cd321x_tbt_switch_get(tps->dev, fwnode, &tbt_late);
if (IS_ERR(cd321x->tbt_switch)) {
Expand Down Expand Up @@ -4047,6 +4047,8 @@ int tipd_init(struct tps6598x *tps)
return -EPROBE_DEFER;

dev_dbg(tps->dev, "Type-C probe start\n");
tps->h17_display = of_machine_is_compatible("apple,t8140") ||
of_machine_is_compatible("apple,t8142");
tps->reset = devm_gpiod_get_optional(tps->dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(tps->reset))
return dev_err_probe(tps->dev, PTR_ERR(tps->reset),
Expand Down Expand Up @@ -4383,9 +4385,6 @@ int tipd_resume(struct tps6598x *tps)
{
int ret;

tps->h17_display = of_machine_is_compatible("apple,t8140") ||
of_machine_is_compatible("apple,t8142");

ret = tps6598x_check_mode(tps);
if (ret < 0)
return ret;
Expand Down
2 changes: 0 additions & 2 deletions tools/testing/selftests/drivers/gpu/apple-dcp/pm.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,6 @@ def function(text, name):
static struct fwnode_handle *fwnode_find_reference(struct fwnode_handle *f,const char *s,int n) {
(void)f;(void)s;(void)n;connector.refs++;return &connector;
}
static bool fwnode_property_present(struct fwnode_handle *f,const char *s) { (void)f;(void)s;return true; }
static struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *f) { assert(!"connector is a displayport reference");return f; }
static void __attribute__((unused)) fwnode_handle_put(struct fwnode_handle *f) {
if(f){assert(f->refs>0);f->refs--;}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def probe(root):
unit = quiesce.make_unit(root)
unit = unit.replace(block(unit, 'int main('), block(unit, 'int main(').replace('int main(', 'int __attribute__((unused)) prior_main(', 1), 1)
unit = unit.replace('struct tipd_data {', 'struct fwnode_handle;\nstruct tipd_data { unsigned irq_mask1; int (*init)(struct tps6598x *); int (*switch_power_state)(struct tps6598x *, int); int (*register_port)(struct tps6598x *, struct fwnode_handle *); bool (*read_data_status)(struct tps6598x *); bool (*read_power_status)(struct tps6598x *); int (*connect)(struct tps6598x *,u32); void (*ready)(struct tps6598x *); void *irq_handler;')
unit = unit.replace('struct tps6598x {', 'struct tps6598x { bool dbma_at_probe,wakeup; u32 status; bool (*sleep_event)(struct tps6598x *);')
unit = unit.replace('struct tps6598x {', 'struct tps6598x { bool dbma_at_probe,wakeup,h17_display; u32 status; bool (*sleep_event)(struct tps6598x *);')
helpers = r"""
#undef dev_err
#define dev_err(...) ((void)0)
Expand Down
Loading