Commit fb75686b authored by Prashant Malani's avatar Prashant Malani Committed by Enric Balletbo i Serra
Browse files

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: default avatarPrashant Malani <pmalani@chromium.org>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
Link: https://lore.kernel.org/r/20210930022403.3358070-6-pmalani@chromium.org
parent 4f140639
Loading
Loading
Loading
Loading
+19 −50
Original line number Diff line number Diff line
@@ -379,37 +379,6 @@ static int cros_typec_init_ports(struct cros_typec_data *typec)
	return ret;
}

static int cros_typec_ec_command(struct cros_typec_data *typec,
				 unsigned int version,
				 unsigned int command,
				 void *outdata,
				 unsigned int outsize,
				 void *indata,
				 unsigned int insize)
{
	struct cros_ec_command *msg;
	int ret;

	msg = kzalloc(sizeof(*msg) + max(outsize, insize), GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	msg->version = version;
	msg->command = command;
	msg->outsize = outsize;
	msg->insize = insize;

	if (outsize)
		memcpy(msg->data, outdata, outsize);

	ret = cros_ec_cmd_xfer_status(typec->ec, msg);
	if (ret >= 0 && insize)
		memcpy(indata, msg->data, insize);

	kfree(msg);
	return ret;
}

static int cros_typec_usb_safe_state(struct cros_typec_port *port)
{
	port->state.mode = TYPEC_STATE_SAFE;
@@ -596,7 +565,7 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num,
	/* Sending Acknowledgment to EC */
	mux_ack.port = port_num;

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

	return cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_MUX_INFO, &req,
	return cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, &req,
			       sizeof(req), resp, sizeof(*resp));
}

@@ -776,7 +745,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p
	int ret = 0;

	memset(disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
	ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
	ret = cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
			      disc, EC_PROTO2_MAX_RESPONSE_SIZE);
	if (ret < 0) {
		dev_err(typec->dev, "Failed to get SOP' discovery data for port: %d\n", port_num);
@@ -859,7 +828,7 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu
	typec_partner_set_pd_revision(port->partner, pd_revision);

	memset(sop_disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE);
	ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
	ret = cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req),
			      sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
	if (ret < 0) {
		dev_err(typec->dev, "Failed to get SOP discovery data for port: %d\n", port_num);
@@ -892,7 +861,7 @@ static int cros_typec_send_clear_event(struct cros_typec_data *typec, int port_n
		.clear_events_mask = events_mask,
	};

	return cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_CONTROL, &req,
	return cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_CONTROL, &req,
			       sizeof(req), NULL, 0);
}

@@ -904,7 +873,7 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num
	};
	int ret;

	ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_STATUS, &req, sizeof(req),
	ret = cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_STATUS, &req, sizeof(req),
			      &resp, sizeof(resp));
	if (ret < 0) {
		dev_warn(typec->dev, "EC_CMD_TYPEC_STATUS failed for port: %d\n", port_num);
@@ -983,7 +952,7 @@ static int cros_typec_port_update(struct cros_typec_data *typec, int port_num)
	req.mux = USB_PD_CTRL_MUX_NO_CHANGE;
	req.swap = USB_PD_CTRL_SWAP_NONE;

	ret = cros_typec_ec_command(typec, typec->pd_ctrl_ver,
	ret = cros_ec_command(typec->ec, typec->pd_ctrl_ver,
			      EC_CMD_USB_PD_CONTROL, &req, sizeof(req),
			      &resp, sizeof(resp));
	if (ret < 0)
@@ -1035,7 +1004,7 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)

	/* We're interested in the PD control command version. */
	req_v1.cmd = EC_CMD_USB_PD_CONTROL;
	ret = cros_typec_ec_command(typec, 1, EC_CMD_GET_CMD_VERSIONS,
	ret = cros_ec_command(typec->ec, 1, EC_CMD_GET_CMD_VERSIONS,
			      &req_v1, sizeof(req_v1), &resp,
				    sizeof(resp));
	if (ret < 0)
@@ -1119,7 +1088,7 @@ static int cros_typec_probe(struct platform_device *pdev)
	typec->typec_cmd_supported = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD);
	typec->needs_mux_ack = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK);

	ret = cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_PORTS, NULL, 0,
	ret = cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_PORTS, NULL, 0,
			      &resp, sizeof(resp));
	if (ret < 0)
		return ret;