Skip to content

Commit 7101c83

Browse files
Prashant MalaniEnric Balletbo i Serra
authored andcommitted
platform/chrome: cros_usbpd_notify: Move ec_command()
cros_ec_command() can be used by other modules too. So, move it to a common location and export it. This patch does not introduce any functional changes. 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 67ea023 commit 7101c83

File tree

3 files changed

+48
-44
lines changed

3 files changed

+48
-44
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,3 +910,48 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
910910
return sensor_count;
911911
}
912912
EXPORT_SYMBOL_GPL(cros_ec_get_sensor_count);
913+
914+
/**
915+
* cros_ec_command - Send a command to the EC.
916+
*
917+
* @ec_dev: EC device
918+
* @command: EC command
919+
* @outdata: EC command output data
920+
* @outsize: Size of outdata
921+
* @indata: EC command input data
922+
* @insize: Size of indata
923+
*
924+
* Return: >= 0 on success, negative error number on failure.
925+
*/
926+
int cros_ec_command(struct cros_ec_device *ec_dev,
927+
int command,
928+
uint8_t *outdata,
929+
int outsize,
930+
uint8_t *indata,
931+
int insize)
932+
{
933+
struct cros_ec_command *msg;
934+
int ret;
935+
936+
msg = kzalloc(sizeof(*msg) + max(insize, outsize), GFP_KERNEL);
937+
if (!msg)
938+
return -ENOMEM;
939+
940+
msg->command = command;
941+
msg->outsize = outsize;
942+
msg->insize = insize;
943+
944+
if (outsize)
945+
memcpy(msg->data, outdata, outsize);
946+
947+
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
948+
if (ret < 0)
949+
goto error;
950+
951+
if (insize)
952+
memcpy(indata, msg->data, insize);
953+
error:
954+
kfree(msg);
955+
return ret;
956+
}
957+
EXPORT_SYMBOL_GPL(cros_ec_command);

drivers/platform/chrome/cros_usbpd_notify.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,50 +53,6 @@ void cros_usbpd_unregister_notify(struct notifier_block *nb)
5353
}
5454
EXPORT_SYMBOL_GPL(cros_usbpd_unregister_notify);
5555

56-
/**
57-
* cros_ec_command - Send a command to the EC.
58-
*
59-
* @ec_dev: EC device
60-
* @command: EC command
61-
* @outdata: EC command output data
62-
* @outsize: Size of outdata
63-
* @indata: EC command input data
64-
* @insize: Size of indata
65-
*
66-
* Return: >= 0 on success, negative error number on failure.
67-
*/
68-
static int cros_ec_command(struct cros_ec_device *ec_dev,
69-
int command,
70-
uint8_t *outdata,
71-
int outsize,
72-
uint8_t *indata,
73-
int insize)
74-
{
75-
struct cros_ec_command *msg;
76-
int ret;
77-
78-
msg = kzalloc(sizeof(*msg) + max(insize, outsize), GFP_KERNEL);
79-
if (!msg)
80-
return -ENOMEM;
81-
82-
msg->command = command;
83-
msg->outsize = outsize;
84-
msg->insize = insize;
85-
86-
if (outsize)
87-
memcpy(msg->data, outdata, outsize);
88-
89-
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
90-
if (ret < 0)
91-
goto error;
92-
93-
if (insize)
94-
memcpy(indata, msg->data, insize);
95-
error:
96-
kfree(msg);
97-
return ret;
98-
}
99-
10056
static void cros_usbpd_get_event_and_notify(struct device *dev,
10157
struct cros_ec_device *ec_dev)
10258
{

include/linux/platform_data/cros_ec_proto.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ bool cros_ec_check_features(struct cros_ec_dev *ec, int feature);
231231

232232
int cros_ec_get_sensor_count(struct cros_ec_dev *ec);
233233

234+
int cros_ec_command(struct cros_ec_device *ec_dev, int command, uint8_t *outdata, int outsize,
235+
uint8_t *indata, int insize);
236+
234237
/**
235238
* cros_ec_get_time_ns() - Return time in ns.
236239
*

0 commit comments

Comments
 (0)