Skip to content

Commit d4efc0d

Browse files
committed
Merge tag 'tag-chrome-platform-for-v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux
Pull chrome platform updates from Benson Leung: "cros_ec_typec: - Clean up use of cros_ec_check_features cros_ec_*: - Rename and move cros_ec_pd_command to cros_ec_command, and make changes to cros_ec_typec and cros_ec_proto to use the new common command, reducing duplication. sensorhub: - simplify getting .driver_data in cros_ec_sensors_core and cros_ec_sensorhub misc: - Maintainership change. Enric Balletbo i Serra has moved on from Collabora, so removing him from chrome/platform maintainers. Thanks for all of your hard work maintaining this, Enric, and best of luck to you in your new role! - Add Prashant Malani as driver maintainer for cros_ec_typec.c and cros_usbpd_notify. He was already principal contributor of these drivers" * tag 'tag-chrome-platform-for-v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux: platform/chrome: cros_ec_proto: Use ec_command for check_features platform/chrome: cros_ec_proto: Use EC struct for features MAINTAINERS: Chrome: Drop Enric Balletbo i Serra platform/chrome: cros_ec_typec: Use cros_ec_command() platform/chrome: cros_ec_proto: Add version for ec_command platform/chrome: cros_ec_proto: Make data pointers void platform/chrome: cros_usbpd_notify: Move ec_command() platform/chrome: cros_usbpd_notify: Rename cros_ec_pd_command() platform/chrome: cros_ec: Fix spelling mistake "responsed" -> "response" platform/chrome: cros_ec_sensorhub: simplify getting .driver_data iio: common: cros_ec_sensors: simplify getting .driver_data platform/chrome: cros-ec-typec: Cleanup use of check_features platform/chrome: cros_ec_proto: Fix check_features ret val MAINTAINERS: Add Prashant's maintainership of cros_ec drivers
2 parents 89fa0be + 297d34e commit d4efc0d

File tree

9 files changed

+104
-137
lines changed

9 files changed

+104
-137
lines changed

MAINTAINERS

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,28 +4468,36 @@ F: drivers/input/touchscreen/chipone_icn8505.c
44684468

44694469
CHROME HARDWARE PLATFORM SUPPORT
44704470
M: Benson Leung <[email protected]>
4471-
M: Enric Balletbo i Serra <[email protected]>
44724471
S: Maintained
44734472
T: git git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git
44744473
F: drivers/platform/chrome/
44754474

44764475
CHROMEOS EC CODEC DRIVER
44774476
M: Cheng-Yi Chiang <[email protected]>
4478-
R: Enric Balletbo i Serra <[email protected]>
44794477
R: Guenter Roeck <[email protected]>
44804478
S: Maintained
44814479
F: Documentation/devicetree/bindings/sound/google,cros-ec-codec.yaml
44824480
F: sound/soc/codecs/cros_ec_codec.*
44834481

44844482
CHROMEOS EC SUBDRIVERS
44854483
M: Benson Leung <[email protected]>
4486-
M: Enric Balletbo i Serra <[email protected]>
44874484
R: Guenter Roeck <[email protected]>
44884485
S: Maintained
44894486
F: drivers/power/supply/cros_usbpd-charger.c
44904487
N: cros_ec
44914488
N: cros-ec
44924489

4490+
CHROMEOS EC USB TYPE-C DRIVER
4491+
M: Prashant Malani <[email protected]>
4492+
S: Maintained
4493+
F: drivers/platform/chrome/cros_ec_typec.c
4494+
4495+
CHROMEOS EC USB PD NOTIFY DRIVER
4496+
M: Prashant Malani <[email protected]>
4497+
S: Maintained
4498+
F: drivers/platform/chrome/cros_usbpd_notify.c
4499+
F: include/linux/platform_data/cros_usbpd_notify.h
4500+
44934501
CHRONTEL CH7322 CEC DRIVER
44944502
M: Joe Tessler <[email protected]>
44954503

drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,7 @@ EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);
831831

832832
static int __maybe_unused cros_ec_sensors_resume(struct device *dev)
833833
{
834-
struct platform_device *pdev = to_platform_device(dev);
835-
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
834+
struct iio_dev *indio_dev = dev_get_drvdata(dev);
836835
struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
837836
int ret = 0;
838837

drivers/mfd/cros_ec_dev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ static int ec_device_probe(struct platform_device *pdev)
146146
ec->ec_dev = dev_get_drvdata(dev->parent);
147147
ec->dev = dev;
148148
ec->cmd_offset = ec_platform->cmd_offset;
149-
ec->features[0] = -1U; /* Not cached yet */
150-
ec->features[1] = -1U; /* Not cached yet */
149+
ec->features.flags[0] = -1U; /* Not cached yet */
150+
ec->features.flags[1] = -1U; /* Not cached yet */
151151
device_initialize(&ec->class_dev);
152152

153153
for (i = 0; i < ARRAY_SIZE(cros_mcu_devices); i++) {

drivers/platform/chrome/cros_ec_lpc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
156156
cros_ec_lpc_ops.write(EC_LPC_ADDR_HOST_CMD, 1, &sum);
157157

158158
if (ec_response_timed_out()) {
159-
dev_warn(ec->dev, "EC responsed timed out\n");
159+
dev_warn(ec->dev, "EC response timed out\n");
160160
ret = -EIO;
161161
goto done;
162162
}
@@ -238,7 +238,7 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec,
238238
cros_ec_lpc_ops.write(EC_LPC_ADDR_HOST_CMD, 1, &sum);
239239

240240
if (ec_response_timed_out()) {
241-
dev_warn(ec->dev, "EC responsed timed out\n");
241+
dev_warn(ec->dev, "EC response timed out\n");
242242
ret = -EIO;
243243
goto done;
244244
}

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -808,38 +808,27 @@ EXPORT_SYMBOL(cros_ec_get_host_event);
808808
*
809809
* Call this function to test whether the ChromeOS EC supports a feature.
810810
*
811-
* Return: 1 if supported, 0 if not
811+
* Return: true if supported, false if not (or if an error was encountered).
812812
*/
813-
int cros_ec_check_features(struct cros_ec_dev *ec, int feature)
813+
bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)
814814
{
815-
struct cros_ec_command *msg;
815+
struct ec_response_get_features *features = &ec->features;
816816
int ret;
817817

818-
if (ec->features[0] == -1U && ec->features[1] == -1U) {
818+
if (features->flags[0] == -1U && features->flags[1] == -1U) {
819819
/* features bitmap not read yet */
820-
msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);
821-
if (!msg)
822-
return -ENOMEM;
823-
824-
msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
825-
msg->insize = sizeof(ec->features);
826-
827-
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
820+
ret = cros_ec_command(ec->ec_dev, 0, EC_CMD_GET_FEATURES + ec->cmd_offset,
821+
NULL, 0, features, sizeof(*features));
828822
if (ret < 0) {
829-
dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
830-
ret, msg->result);
831-
memset(ec->features, 0, sizeof(ec->features));
832-
} else {
833-
memcpy(ec->features, msg->data, sizeof(ec->features));
823+
dev_warn(ec->dev, "cannot get EC features: %d\n", ret);
824+
memset(features, 0, sizeof(*features));
834825
}
835826

836827
dev_dbg(ec->dev, "EC features %08x %08x\n",
837-
ec->features[0], ec->features[1]);
838-
839-
kfree(msg);
828+
features->flags[0], features->flags[1]);
840829
}
841830

842-
return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature);
831+
return !!(features->flags[feature / 32] & EC_FEATURE_MASK_0(feature));
843832
}
844833
EXPORT_SYMBOL_GPL(cros_ec_check_features);
845834

@@ -908,3 +897,51 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
908897
return sensor_count;
909898
}
910899
EXPORT_SYMBOL_GPL(cros_ec_get_sensor_count);
900+
901+
/**
902+
* cros_ec_command - Send a command to the EC.
903+
*
904+
* @ec_dev: EC device
905+
* @version: EC command version
906+
* @command: EC command
907+
* @outdata: EC command output data
908+
* @outsize: Size of outdata
909+
* @indata: EC command input data
910+
* @insize: Size of indata
911+
*
912+
* Return: >= 0 on success, negative error number on failure.
913+
*/
914+
int cros_ec_command(struct cros_ec_device *ec_dev,
915+
unsigned int version,
916+
int command,
917+
void *outdata,
918+
int outsize,
919+
void *indata,
920+
int insize)
921+
{
922+
struct cros_ec_command *msg;
923+
int ret;
924+
925+
msg = kzalloc(sizeof(*msg) + max(insize, outsize), GFP_KERNEL);
926+
if (!msg)
927+
return -ENOMEM;
928+
929+
msg->version = version;
930+
msg->command = command;
931+
msg->outsize = outsize;
932+
msg->insize = insize;
933+
934+
if (outsize)
935+
memcpy(msg->data, outdata, outsize);
936+
937+
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
938+
if (ret < 0)
939+
goto error;
940+
941+
if (insize)
942+
memcpy(indata, msg->data, insize);
943+
error:
944+
kfree(msg);
945+
return ret;
946+
}
947+
EXPORT_SYMBOL_GPL(cros_ec_command);

drivers/platform/chrome/cros_ec_sensorhub.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev)
224224
*/
225225
static int cros_ec_sensorhub_suspend(struct device *dev)
226226
{
227-
struct platform_device *pdev = to_platform_device(dev);
228-
struct cros_ec_sensorhub *sensorhub = platform_get_drvdata(pdev);
227+
struct cros_ec_sensorhub *sensorhub = dev_get_drvdata(dev);
229228
struct cros_ec_dev *ec = sensorhub->ec;
230229

231230
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO))
@@ -235,8 +234,7 @@ static int cros_ec_sensorhub_suspend(struct device *dev)
235234

236235
static int cros_ec_sensorhub_resume(struct device *dev)
237236
{
238-
struct platform_device *pdev = to_platform_device(dev);
239-
struct cros_ec_sensorhub *sensorhub = platform_get_drvdata(pdev);
237+
struct cros_ec_sensorhub *sensorhub = dev_get_drvdata(dev);
240238
struct cros_ec_dev *ec = sensorhub->ec;
241239

242240
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO))

drivers/platform/chrome/cros_ec_typec.c

Lines changed: 21 additions & 53 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;
@@ -1116,12 +1085,11 @@ static int cros_typec_probe(struct platform_device *pdev)
11161085
}
11171086

11181087
ec_dev = dev_get_drvdata(&typec->ec->ec->dev);
1119-
typec->typec_cmd_supported = !!cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD);
1120-
typec->needs_mux_ack = !!cros_ec_check_features(ec_dev,
1121-
EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK);
1088+
typec->typec_cmd_supported = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_CMD);
1089+
typec->needs_mux_ack = cros_ec_check_features(ec_dev, EC_FEATURE_TYPEC_MUX_REQUIRE_AP_ACK);
11221090

1123-
ret = cros_typec_ec_command(typec, 0, EC_CMD_USB_PD_PORTS, NULL, 0,
1124-
&resp, sizeof(resp));
1091+
ret = cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_PORTS, NULL, 0,
1092+
&resp, sizeof(resp));
11251093
if (ret < 0)
11261094
return ret;
11271095

0 commit comments

Comments
 (0)