Skip to content

Commit

Permalink
Merge tag 'tag-chrome-platform-for-v5.16' of git://git.kernel.org/pub…
Browse files Browse the repository at this point in the history
…/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
  • Loading branch information
torvalds committed Nov 10, 2021
2 parents 89fa0be + 297d34e commit d4efc0d
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 137 deletions.
14 changes: 11 additions & 3 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -4468,28 +4468,36 @@ F: drivers/input/touchscreen/chipone_icn8505.c

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

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

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

CHROMEOS EC USB TYPE-C DRIVER
M: Prashant Malani <[email protected]>
S: Maintained
F: drivers/platform/chrome/cros_ec_typec.c

CHROMEOS EC USB PD NOTIFY DRIVER
M: Prashant Malani <[email protected]>
S: Maintained
F: drivers/platform/chrome/cros_usbpd_notify.c
F: include/linux/platform_data/cros_usbpd_notify.h

CHRONTEL CH7322 CEC DRIVER
M: Joe Tessler <[email protected]>
L: [email protected]
Expand Down
3 changes: 1 addition & 2 deletions drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,7 @@ EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write);

static int __maybe_unused cros_ec_sensors_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct iio_dev *indio_dev = platform_get_drvdata(pdev);
struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
int ret = 0;

Expand Down
4 changes: 2 additions & 2 deletions drivers/mfd/cros_ec_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ static int ec_device_probe(struct platform_device *pdev)
ec->ec_dev = dev_get_drvdata(dev->parent);
ec->dev = dev;
ec->cmd_offset = ec_platform->cmd_offset;
ec->features[0] = -1U; /* Not cached yet */
ec->features[1] = -1U; /* Not cached yet */
ec->features.flags[0] = -1U; /* Not cached yet */
ec->features.flags[1] = -1U; /* Not cached yet */
device_initialize(&ec->class_dev);

for (i = 0; i < ARRAY_SIZE(cros_mcu_devices); i++) {
Expand Down
4 changes: 2 additions & 2 deletions drivers/platform/chrome/cros_ec_lpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static int cros_ec_pkt_xfer_lpc(struct cros_ec_device *ec,
cros_ec_lpc_ops.write(EC_LPC_ADDR_HOST_CMD, 1, &sum);

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

if (ec_response_timed_out()) {
dev_warn(ec->dev, "EC responsed timed out\n");
dev_warn(ec->dev, "EC response timed out\n");
ret = -EIO;
goto done;
}
Expand Down
79 changes: 58 additions & 21 deletions drivers/platform/chrome/cros_ec_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -808,38 +808,27 @@ EXPORT_SYMBOL(cros_ec_get_host_event);
*
* Call this function to test whether the ChromeOS EC supports a feature.
*
* Return: 1 if supported, 0 if not
* Return: true if supported, false if not (or if an error was encountered).
*/
int cros_ec_check_features(struct cros_ec_dev *ec, int feature)
bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)
{
struct cros_ec_command *msg;
struct ec_response_get_features *features = &ec->features;
int ret;

if (ec->features[0] == -1U && ec->features[1] == -1U) {
if (features->flags[0] == -1U && features->flags[1] == -1U) {
/* features bitmap not read yet */
msg = kzalloc(sizeof(*msg) + sizeof(ec->features), GFP_KERNEL);
if (!msg)
return -ENOMEM;

msg->command = EC_CMD_GET_FEATURES + ec->cmd_offset;
msg->insize = sizeof(ec->features);

ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
ret = cros_ec_command(ec->ec_dev, 0, EC_CMD_GET_FEATURES + ec->cmd_offset,
NULL, 0, features, sizeof(*features));
if (ret < 0) {
dev_warn(ec->dev, "cannot get EC features: %d/%d\n",
ret, msg->result);
memset(ec->features, 0, sizeof(ec->features));
} else {
memcpy(ec->features, msg->data, sizeof(ec->features));
dev_warn(ec->dev, "cannot get EC features: %d\n", ret);
memset(features, 0, sizeof(*features));
}

dev_dbg(ec->dev, "EC features %08x %08x\n",
ec->features[0], ec->features[1]);

kfree(msg);
features->flags[0], features->flags[1]);
}

return ec->features[feature / 32] & EC_FEATURE_MASK_0(feature);
return !!(features->flags[feature / 32] & EC_FEATURE_MASK_0(feature));
}
EXPORT_SYMBOL_GPL(cros_ec_check_features);

Expand Down Expand Up @@ -908,3 +897,51 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
return sensor_count;
}
EXPORT_SYMBOL_GPL(cros_ec_get_sensor_count);

/**
* cros_ec_command - Send a command to the EC.
*
* @ec_dev: EC device
* @version: EC command version
* @command: EC command
* @outdata: EC command output data
* @outsize: Size of outdata
* @indata: EC command input data
* @insize: Size of indata
*
* Return: >= 0 on success, negative error number on failure.
*/
int cros_ec_command(struct cros_ec_device *ec_dev,
unsigned int version,
int command,
void *outdata,
int outsize,
void *indata,
int insize)
{
struct cros_ec_command *msg;
int ret;

msg = kzalloc(sizeof(*msg) + max(insize, outsize), 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(ec_dev, msg);
if (ret < 0)
goto error;

if (insize)
memcpy(indata, msg->data, insize);
error:
kfree(msg);
return ret;
}
EXPORT_SYMBOL_GPL(cros_ec_command);
6 changes: 2 additions & 4 deletions drivers/platform/chrome/cros_ec_sensorhub.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ static int cros_ec_sensorhub_probe(struct platform_device *pdev)
*/
static int cros_ec_sensorhub_suspend(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct cros_ec_sensorhub *sensorhub = platform_get_drvdata(pdev);
struct cros_ec_sensorhub *sensorhub = dev_get_drvdata(dev);
struct cros_ec_dev *ec = sensorhub->ec;

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

static int cros_ec_sensorhub_resume(struct device *dev)
{
struct platform_device *pdev = to_platform_device(dev);
struct cros_ec_sensorhub *sensorhub = platform_get_drvdata(pdev);
struct cros_ec_sensorhub *sensorhub = dev_get_drvdata(dev);
struct cros_ec_dev *ec = sensorhub->ec;

if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO))
Expand Down
74 changes: 21 additions & 53 deletions drivers/platform/chrome/cros_ec_typec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -596,8 +565,8 @@ 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,
sizeof(mux_ack), NULL, 0) < 0)
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",
port_num);
Expand Down Expand Up @@ -668,8 +637,8 @@ 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,
sizeof(req), resp, sizeof(*resp));
return cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_MUX_INFO, &req,
sizeof(req), resp, sizeof(*resp));
}

/*
Expand Down Expand Up @@ -776,8 +745,8 @@ 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),
disc, EC_PROTO2_MAX_RESPONSE_SIZE);
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);
goto sop_prime_disc_exit;
Expand Down Expand Up @@ -859,8 +828,8 @@ 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),
sop_disc, EC_PROTO2_MAX_RESPONSE_SIZE);
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);
goto disc_exit;
Expand Down Expand Up @@ -892,8 +861,8 @@ 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,
sizeof(req), NULL, 0);
return cros_ec_command(typec->ec, 0, EC_CMD_TYPEC_CONTROL, &req,
sizeof(req), NULL, 0);
}

static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num)
Expand All @@ -904,8 +873,8 @@ 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),
&resp, sizeof(resp));
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);
return;
Expand Down Expand Up @@ -983,9 +952,9 @@ 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,
EC_CMD_USB_PD_CONTROL, &req, sizeof(req),
&resp, sizeof(resp));
ret = cros_ec_command(typec->ec, typec->pd_ctrl_ver,
EC_CMD_USB_PD_CONTROL, &req, sizeof(req),
&resp, sizeof(resp));
if (ret < 0)
return ret;

Expand Down Expand Up @@ -1035,8 +1004,8 @@ 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,
&req_v1, sizeof(req_v1), &resp,
ret = cros_ec_command(typec->ec, 1, EC_CMD_GET_CMD_VERSIONS,
&req_v1, sizeof(req_v1), &resp,
sizeof(resp));
if (ret < 0)
return ret;
Expand Down Expand Up @@ -1116,12 +1085,11 @@ static int cros_typec_probe(struct platform_device *pdev)
}

ec_dev = dev_get_drvdata(&typec->ec->ec->dev);
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);
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,
&resp, sizeof(resp));
ret = cros_ec_command(typec->ec, 0, EC_CMD_USB_PD_PORTS, NULL, 0,
&resp, sizeof(resp));
if (ret < 0)
return ret;

Expand Down
Loading

0 comments on commit d4efc0d

Please sign in to comment.