Skip to content

Commit fb75686

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_ec_typec: Use cros_ec_command()
Re-use the existing cros_ec_command() instead of relying on a duplicate version. Signed-off-by: Prashant Malani <[email protected]> Signed-off-by: Enric Balletbo i Serra <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4f14063 commit fb75686

File tree

1 file changed

+19
-50
lines changed

1 file changed

+19
-50
lines changed

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 19 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -379,37 +379,6 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
379379
return ret;
380380
}
381381

382-
static int cros_typec_ec_command(struct cros_typec_data *typec,
383-
unsigned int version,
384-
unsigned int command,
385-
void *outdata,
386-
unsigned int outsize,
387-
void *indata,
388-
unsigned int insize)
389-
{
390-
struct cros_ec_command *msg;
391-
int ret;
392-
393-
msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL);
394-
if (!msg)
395-
return -ENOMEM;
396-
397-
msg->version = version;
398-
msg->command = command;
399-
msg->outsize = outsize;
400-
msg->insize = insize;
401-
402-
if (outsize)
403-
memcpy(msg->data, outdata, outsize);
404-
405-
ret = cros_ec_cmd_xfer_status(typec->ec, msg);
406-
if (ret >= 0 && insize)
407-
memcpy(indata, msg->data, insize);
408-
409-
kfree(msg);
410-
return ret;
411-
}
412-
413382
static int cros_typec_usb_safe_state(struct cros_typec_port *port)
414383
{
415384
port->state.mode = TYPEC_STATE_SAFE;
@@ -596,8 +565,8 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
596565
/* Sending Acknowledgment to EC */
597566
mux_ack.port = port_num;
598567

599-
if (cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_MUX_ACK, &mux_ack,
600-
sizeof(mux_ack), NULL, 0) < 0)
568+
if (cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_MUX_ACK, &mux_ack,
569+
sizeof(mux_ack), NULL, 0) < 0)
601570
dev_warn(typec->dev,
602571
"Failed to send Mux ACK to EC for port: %d\n",
603572
port_num);
@@ -668,8 +637,8 @@ static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num,
668637
.port = port_num,
669638
};
670639

671-
return cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_MUX_INFO, &req,
672-
sizeof(req), resp, sizeof(*resp));
640+
return cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, &req,
641+
sizeof(req), resp, sizeof(*resp));
673642
}
674643

675644
/*
@@ -776,8 +745,8 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
776745
int ret = 0;
777746

778747
memset(disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
779-
ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
780-
disc, EC_PROTO2_MAX_RESPONSE_SIZE);
748+
ret = cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
749+
disc, EC_PROTO2_MAX_RESPONSE_SIZE);
781750
if (ret < 0) {
782751
dev_err(typec->dev, "Failed to get SOP' discovery data for port: %d\n", port_num);
783752
goto sop_prime_disc_exit;
@@ -859,8 +828,8 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu
859828
typec_partner_set_pd_revision(port->partner, pd_revision);
860829

861830
memset(sop_disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
862-
ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
863-
sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
831+
ret = cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
832+
sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
864833
if (ret < 0) {
865834
dev_err(typec->dev, "Failed to get SOP discovery data for port: %d\n", port_num);
866835
goto disc_exit;
@@ -892,8 +861,8 @@ static int cros_typec_send_clear_event(struct cros_typec_data *typec, int port_n
892861
.clear_events_mask = events_mask,
893862
};
894863

895-
return cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_CONTROL, &req,
896-
sizeof(req), NULL, 0);
864+
return cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_CONTROL, &req,
865+
sizeof(req), NULL, 0);
897866
}
898867

899868
static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num)
@@ -904,8 +873,8 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
904873
};
905874
int ret;
906875

907-
ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_STATUS, &req, sizeof(req),
908-
&resp, sizeof(resp));
876+
ret = cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_STATUS, &req, sizeof(req),
877+
&resp, sizeof(resp));
909878
if (ret < 0) {
910879
dev_warn(typec->dev, "EC_CMD_TYPEC_STATUS failed for port: %d\n", port_num);
911880
return;
@@ -983,9 +952,9 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
983952
req.mux = USB_PD_CTRL_MUX_NO_CHANGE;
984953
req.swap = USB_PD_CTRL_SWAP_NONE;
985954

986-
ret = cros_typec_ec_command(typec, typec->pd_ctrl_ver,
987-
EC_CMD_USB_PD_CONTROL, &req, sizeof(req),
988-
&resp, sizeof(resp));
955+
ret = cros_ec_command(typec->ec, typec->pd_ctrl_ver,
956+
EC_CMD_USB_PD_CONTROL, &req, sizeof(req),
957+
&resp, sizeof(resp));
989958
if (ret < 0)
990959
return ret;
991960

@@ -1035,8 +1004,8 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
10351004

10361005
/* We're interested in the PD control command version. */
10371006
req_v1.cmd = EC_CMD_USB_PD_CONTROL;
1038-
ret = cros_typec_ec_command(typec, 1, EC_CMD_GET_CMD_VERSIONS,
1039-
&req_v1, sizeof(req_v1), &resp,
1007+
ret = cros_ec_command(typec->ec, 1, EC_CMD_GET_CMD_VERSIONS,
1008+
&req_v1, sizeof(req_v1), &resp,
10401009
sizeof(resp));
10411010
if (ret < 0)
10421011
return ret;
@@ -1119,8 +1088,8 @@ static int cros_typec_probe(struct platform_device *pdev)
11191088
typec->typec_cmd_supported = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD);
11201089
typec->needs_mux_ack = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK);
11211090

1122-
ret = cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_PORTS, NULL, 0,
1123-
&resp, sizeof(resp));
1091+
ret = cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_PORTS, NULL, 0,
1092+
&resp, sizeof(resp));
11241093
if (ret < 0)
11251094
return ret;
11261095

0 commit comments

Comments
 (0)