2020-02-05 19:12:17

by Prashant Malani

[permalink] [raw]
Subject: [PATCH v2 08/17] extcon: cros_ec: Use cros_ec_cmd()

Replace cros_ec_pd_command() with cros_ec_cmd() which does the same
thing, but is defined in a common location in platform/chrome and
exposed for other modules to use.

Signed-off-by: Prashant Malani <[email protected]>
---

Changes in v2:
- Updated to use new function name and parameter list.

drivers/extcon/extcon-usbc-cros-ec.c | 61 ++++------------------------
1 file changed, 8 insertions(+), 53 deletions(-)

diff --git a/drivers/extcon/extcon-usbc-cros-ec.c b/drivers/extcon/extcon-usbc-cros-ec.c
index 5290cc2d19d953..2939cedca04798 100644
--- a/drivers/extcon/extcon-usbc-cros-ec.c
+++ b/drivers/extcon/extcon-usbc-cros-ec.c
@@ -45,49 +45,6 @@ enum usb_data_roles {
DR_DEVICE,
};

-/**
- * cros_ec_pd_command() - Send a command to the EC.
- * @info: pointer to struct cros_ec_extcon_info
- * @command: EC command
- * @version: EC command version
- * @outdata: EC command output data
- * @outsize: Size of outdata
- * @indata: EC command input data
- * @insize: Size of indata
- *
- * Return: 0 on success, <0 on failure.
- */
-static int cros_ec_pd_command(struct cros_ec_extcon_info *info,
- unsigned int command,
- unsigned int version,
- 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(info->ec, msg);
- if (ret >= 0 && insize)
- memcpy(indata, msg->data, insize);
-
- kfree(msg);
- return ret;
-}
-
/**
* cros_ec_usb_get_power_type() - Get power type info about PD device attached
* to given port.
@@ -102,8 +59,8 @@ static int cros_ec_usb_get_power_type(struct cros_ec_extcon_info *info)
int ret;

req.port = info->port_id;
- ret = cros_ec_pd_command(info, EC_CMD_USB_PD_POWER_INFO, 0,
- &req, sizeof(req), &resp, sizeof(resp));
+ ret = cros_ec_cmd(info->ec, 0, EC_CMD_USB_PD_POWER_INFO, &req,
+ sizeof(req), &resp, sizeof(resp), NULL);
if (ret < 0)
return ret;

@@ -123,9 +80,8 @@ static int cros_ec_usb_get_pd_mux_state(struct cros_ec_extcon_info *info)
int ret;

req.port = info->port_id;
- ret = cros_ec_pd_command(info, EC_CMD_USB_PD_MUX_INFO, 0,
- &req, sizeof(req),
- &resp, sizeof(resp));
+ ret = cros_ec_cmd(info->ec, 0, EC_CMD_USB_PD_MUX_INFO, &req,
+ sizeof(req), &resp, sizeof(resp), NULL);
if (ret < 0)
return ret;

@@ -152,9 +108,8 @@ static int cros_ec_usb_get_role(struct cros_ec_extcon_info *info,
pd_control.role = USB_PD_CTRL_ROLE_NO_CHANGE;
pd_control.mux = USB_PD_CTRL_MUX_NO_CHANGE;
pd_control.swap = USB_PD_CTRL_SWAP_NONE;
- ret = cros_ec_pd_command(info, EC_CMD_USB_PD_CONTROL, 1,
- &pd_control, sizeof(pd_control),
- &resp, sizeof(resp));
+ ret = cros_ec_cmd(info->ec, 1, EC_CMD_USB_PD_CONTROL, &pd_control,
+ sizeof(pd_control), &resp, sizeof(resp), NULL);
if (ret < 0)
return ret;

@@ -177,8 +132,8 @@ static int cros_ec_pd_get_num_ports(struct cros_ec_extcon_info *info)
struct ec_response_usb_pd_ports resp;
int ret;

- ret = cros_ec_pd_command(info, EC_CMD_USB_PD_PORTS,
- 0, NULL, 0, &resp, sizeof(resp));
+ ret = cros_ec_cmd(info->ec, 0, EC_CMD_USB_PD_PORTS, NULL, 0, &resp,
+ sizeof(resp), NULL);
if (ret < 0)
return ret;

--
2.25.0.341.g760bfbb309-goog