Skip to content

Commit f54c013

Browse files
author
Prashant Malani
committed
platform/chrome: cros_typec_vdm: Add Attention support
Add support to retrieve VDM attention messages and forward them to the appropriate alt mode driver. Signed-off-by: Prashant Malani <[email protected]> Reviewed-by: Benson Leung <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4b1936c commit f54c013

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,14 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
10151015
if (ret < 0)
10161016
dev_warn(typec->dev, "Failed VDM Reply event clear, port: %d\n", port_num);
10171017
}
1018+
1019+
if (resp.events & PD_STATUS_EVENT_VDM_ATTENTION) {
1020+
cros_typec_handle_vdm_attention(typec, port_num);
1021+
ret = cros_typec_send_clear_event(typec, port_num, PD_STATUS_EVENT_VDM_ATTENTION);
1022+
if (ret < 0)
1023+
dev_warn(typec->dev, "Failed VDM Attenetion event clear, port: %d\n",
1024+
port_num);
1025+
}
10181026
}
10191027

10201028
static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)

drivers/platform/chrome/cros_typec_vdm.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,46 @@
1313
#include "cros_ec_typec.h"
1414
#include "cros_typec_vdm.h"
1515

16+
/*
17+
* Retrieves pending VDM attention messages from the EC and forwards them to the altmode driver
18+
* based on SVID.
19+
*/
20+
void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num)
21+
{
22+
struct ec_response_typec_vdm_response resp;
23+
struct ec_params_typec_vdm_response req = {
24+
.port = port_num,
25+
};
26+
struct typec_altmode *amode;
27+
u16 svid;
28+
u32 hdr;
29+
int ret;
30+
31+
do {
32+
ret = cros_ec_cmd(typec->ec, 0, EC_CMD_TYPEC_VDM_RESPONSE, &req,
33+
sizeof(req), &resp, sizeof(resp));
34+
if (ret < 0) {
35+
dev_warn(typec->dev, "Failed VDM response fetch, port: %d\n", port_num);
36+
return;
37+
}
38+
39+
hdr = resp.vdm_response[0];
40+
svid = PD_VDO_VID(hdr);
41+
dev_dbg(typec->dev, "Received VDM Attention header: %x, port: %d\n", hdr, port_num);
42+
43+
amode = typec_match_altmode(typec->ports[port_num]->port_altmode,
44+
CROS_EC_ALTMODE_MAX, svid, PD_VDO_OPOS(hdr));
45+
if (!amode) {
46+
dev_err(typec->dev,
47+
"Received VDM for unregistered altmode (SVID:%x), port: %d\n",
48+
svid, port_num);
49+
return;
50+
}
51+
52+
typec_altmode_attention(amode, resp.vdm_attention[1]);
53+
} while (resp.vdm_attention_left);
54+
}
55+
1656
/*
1757
* Retrieves a VDM response from the EC and forwards it to the altmode driver based on SVID.
1858
*/

drivers/platform/chrome/cros_typec_vdm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
extern struct typec_altmode_ops port_amode_ops;
99

10+
void cros_typec_handle_vdm_attention(struct cros_typec_data *typec, int port_num);
1011
void cros_typec_handle_vdm_response(struct cros_typec_data *typec, int port_num);
1112

1213
#endif /* __CROS_TYPEC_VDM__ */

0 commit comments

Comments
 (0)