Skip to content

Commit

Permalink
Merge tag 'tag-chrome-platform-for-v5.10' 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:
   - Error code cleanup across cros-ec by Guenter
   - Remove cros_ec_cmd_xfer in favor of cros_ec_cmd_xfer_status

  cros_ec_typec:
   - Landed initial USB4 support in typec connector class driver for
     cros_ec
   - Role switch bugfix on disconnect, and reordering configuration
     steps

  cros_ec_lightbar:
   - Fix buffer outsize and result for get_lightbar_version

  misc:
   - Remove config MFD_CROS_EC, now that transition from MFD is complete
   - Enable KEY_LEFTMETA in new location on arm based cros-ec-keyboard
     keymap"

* tag 'tag-chrome-platform-for-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
  ARM: dts: cros-ec-keyboard: Add alternate keymap for KEY_LEFTMETA
  platform/chrome: Use kobj_to_dev() instead of container_of()
  platform/chrome: cros_ec_proto: Drop cros_ec_cmd_xfer()
  platform/chrome: cros_ec_proto: Update cros_ec_cmd_xfer() call-sites
  platform/chrome: Kconfig: Remove the transitional MFD_CROS_EC config
  platform/chrome: cros_ec_lightbar: Reduce ligthbar get version command
  platform/chrome: cros_ec_trace: Add fields to command traces
  platform/chrome: cros_ec_typec: Re-order connector configuration steps
  platform/chrome: cros_ec_typec: Avoid setting usb role twice during disconnect
  platform/chrome: cros_ec_typec: Send enum values to usb_role_switch_set_role()
  platform/chrome: cros_ec_typec: USB4 support
  pwm: cros-ec: Simplify EC error handling
  platform/chrome: cros_ec_proto: Convert EC error codes to Linux error codes
  platform/input: cros_ec: Replace -ENOTSUPP with -ENOPROTOOPT
  pwm: cros-ec: Accept more error codes from cros_ec_cmd_xfer_status
  platform/chrome: cros_ec_sysfs: Report range of error codes from EC
  cros_ec_lightbar: Accept more error codes from cros_ec_cmd_xfer_status
  iio: cros_ec: Accept -EOPNOTSUPP as 'not supported' error code
  • Loading branch information
torvalds committed Oct 23, 2020
2 parents 4a22709 + 3e98fd6 commit 090a7d0
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 115 deletions.
1 change: 1 addition & 0 deletions arch/arm/boot/dts/cros-ec-keyboard.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
MATRIX_KEY(0x02, 0x09, KEY_F8)
MATRIX_KEY(0x02, 0x0a, KEY_YEN)

MATRIX_KEY(0x03, 0x00, KEY_LEFTMETA)
MATRIX_KEY(0x03, 0x01, KEY_GRAVE)
MATRIX_KEY(0x03, 0x02, KEY_F2)
MATRIX_KEY(0x03, 0x03, KEY_5)
Expand Down
2 changes: 1 addition & 1 deletion drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static int cros_ec_sensors_read(struct iio_dev *indio_dev,
st->core.param.sensor_offset.flags = 0;

ret = cros_ec_motion_send_host_cmd(&st->core, 0);
if (ret == -EPROTO) {
if (ret == -EPROTO || ret == -EOPNOTSUPP) {
/* Reading calibscale is not supported on older EC. */
*val = 1;
*val2 = 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/input/keyboard/cros_ec_keyb.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ static int cros_ec_keyb_info(struct cros_ec_device *ec_dev,
params->event_type = event_type;

ret = cros_ec_cmd_xfer_status(ec_dev, msg);
if (ret == -ENOTSUPP) {
if (ret == -ENOPROTOOPT) {
/* With older ECs we just return 0 for everything */
memset(result, 0, result_size);
ret = 0;
Expand Down
10 changes: 0 additions & 10 deletions drivers/platform/chrome/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
# Platform support for Chrome OS hardware (Chromebooks and Chromeboxes)
#

config MFD_CROS_EC
tristate "Platform support for Chrome hardware (transitional)"
select CHROME_PLATFORMS
select CROS_EC
select MFD_CROS_EC_DEV
depends on X86 || ARM || ARM64 || COMPILE_TEST
help
This is a transitional Kconfig option and will be removed after
everyone enables the parts individually.

menuconfig CHROME_PLATFORMS
bool "Platform support for Chrome hardware"
depends on X86 || ARM || ARM64 || COMPILE_TEST
Expand Down
12 changes: 6 additions & 6 deletions drivers/platform/chrome/cros_ec_lightbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ static int get_lightbar_version(struct cros_ec_dev *ec,

param = (struct ec_params_lightbar *)msg->data;
param->cmd = LIGHTBAR_CMD_VERSION;
msg->outsize = sizeof(param->cmd);
msg->result = sizeof(resp->version);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) {
if (ret < 0 && ret != -EINVAL) {
ret = 0;
goto exit;
}
Expand Down Expand Up @@ -298,11 +300,9 @@ static ssize_t sequence_show(struct device *dev,
goto exit;

ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret == -EPROTO) {
ret = scnprintf(buf, PAGE_SIZE,
"ERROR: EC returned %d\n", msg->result);
goto exit;
} else if (ret < 0) {
if (ret < 0) {
ret = scnprintf(buf, PAGE_SIZE, "XFER / EC ERROR %d / %d\n",
ret, msg->result);
goto exit;
}

Expand Down
106 changes: 56 additions & 50 deletions drivers/platform/chrome/cros_ec_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,43 @@

#define EC_COMMAND_RETRIES 50

static const int cros_ec_error_map[] = {
[EC_RES_INVALID_COMMAND] = -EOPNOTSUPP,
[EC_RES_ERROR] = -EIO,
[EC_RES_INVALID_PARAM] = -EINVAL,
[EC_RES_ACCESS_DENIED] = -EACCES,
[EC_RES_INVALID_RESPONSE] = -EPROTO,
[EC_RES_INVALID_VERSION] = -ENOPROTOOPT,
[EC_RES_INVALID_CHECKSUM] = -EBADMSG,
[EC_RES_IN_PROGRESS] = -EINPROGRESS,
[EC_RES_UNAVAILABLE] = -ENODATA,
[EC_RES_TIMEOUT] = -ETIMEDOUT,
[EC_RES_OVERFLOW] = -EOVERFLOW,
[EC_RES_INVALID_HEADER] = -EBADR,
[EC_RES_REQUEST_TRUNCATED] = -EBADR,
[EC_RES_RESPONSE_TOO_BIG] = -EFBIG,
[EC_RES_BUS_ERROR] = -EFAULT,
[EC_RES_BUSY] = -EBUSY,
[EC_RES_INVALID_HEADER_VERSION] = -EBADMSG,
[EC_RES_INVALID_HEADER_CRC] = -EBADMSG,
[EC_RES_INVALID_DATA_CRC] = -EBADMSG,
[EC_RES_DUP_UNAVAILABLE] = -ENODATA,
};

static int cros_ec_map_error(uint32_t result)
{
int ret = 0;

if (result != EC_RES_SUCCESS) {
if (result < ARRAY_SIZE(cros_ec_error_map) && cros_ec_error_map[result])
ret = cros_ec_error_map[result];
else
ret = -EPROTO;
}

return ret;
}

static int prepare_packet(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
{
Expand Down Expand Up @@ -512,19 +549,22 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev)
EXPORT_SYMBOL(cros_ec_query_all);

/**
* cros_ec_cmd_xfer() - Send a command to the ChromeOS EC.
* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC.
* @ec_dev: EC device.
* @msg: Message to write.
*
* Call this to send a command to the ChromeOS EC. This should be used
* instead of calling the EC's cmd_xfer() callback directly.
* Call this to send a command to the ChromeOS EC. This should be used instead of calling the EC's
* cmd_xfer() callback directly. It returns success status only if both the command was transmitted
* successfully and the EC replied with success status.
*
* Return: 0 on success or negative error code.
* Return:
* >=0 - The number of bytes transferred
* <0 - Linux error code
*/
static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
{
int ret;
int ret, mapped;

mutex_lock(&ec_dev->lock);
if (ec_dev->proto_version == EC_PROTO_VERSION_UNKNOWN) {
Expand Down Expand Up @@ -561,42 +601,15 @@ static int cros_ec_cmd_xfer(struct cros_ec_device *ec_dev,
return -EMSGSIZE;
}
}

ret = send_command(ec_dev, msg);
mutex_unlock(&ec_dev->lock);

return ret;
}

/**
* cros_ec_cmd_xfer_status() - Send a command to the ChromeOS EC.
* @ec_dev: EC device.
* @msg: Message to write.
*
* This function is identical to cros_ec_cmd_xfer, except it returns success
* status only if both the command was transmitted successfully and the EC
* replied with success status. It's not necessary to check msg->result when
* using this function.
*
* Return:
* >=0 - The number of bytes transferred
* -ENOTSUPP - Operation not supported
* -EPROTO - Protocol error
*/
int cros_ec_cmd_xfer_status(struct cros_ec_device *ec_dev,
struct cros_ec_command *msg)
{
int ret;

ret = cros_ec_cmd_xfer(ec_dev, msg);
if (ret < 0) {
dev_err(ec_dev->dev, "Command xfer error (err:%d)\n", ret);
} else if (msg->result == EC_RES_INVALID_VERSION) {
dev_dbg(ec_dev->dev, "Command invalid version (err:%d)\n",
msg->result);
return -ENOTSUPP;
} else if (msg->result != EC_RES_SUCCESS) {
dev_dbg(ec_dev->dev, "Command result (err: %d)\n", msg->result);
return -EPROTO;
mapped = cros_ec_map_error(msg->result);
if (mapped) {
dev_dbg(ec_dev->dev, "Command result (err: %d [%d])\n",
msg->result, mapped);
ret = mapped;
}

return ret;
Expand All @@ -615,7 +628,7 @@ static int get_next_event_xfer(struct cros_ec_device *ec_dev,
msg->insize = size;
msg->outsize = 0;

ret = cros_ec_cmd_xfer(ec_dev, msg);
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
if (ret > 0) {
ec_dev->event_size = ret - 1;
ec_dev->event_data = *event;
Expand Down Expand Up @@ -659,7 +672,7 @@ static int get_keyboard_state_event(struct cros_ec_device *ec_dev)
msg->insize = sizeof(ec_dev->event_data.data);
msg->outsize = 0;

ec_dev->event_size = cros_ec_cmd_xfer(ec_dev, msg);
ec_dev->event_size = cros_ec_cmd_xfer_status(ec_dev, msg);
ec_dev->event_data.event_type = EC_MKBP_EVENT_KEY_MATRIX;
memcpy(&ec_dev->event_data.data, msg->data,
sizeof(ec_dev->event_data.data));
Expand Down Expand Up @@ -848,11 +861,9 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
params = (struct ec_params_motion_sense *)msg->data;
params->cmd = MOTIONSENSE_CMD_DUMP;

ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret < 0) {
sensor_count = ret;
} else if (msg->result != EC_RES_SUCCESS) {
sensor_count = -EPROTO;
} else {
resp = (struct ec_response_motion_sense *)msg->data;
sensor_count = resp->dump.sensor_count;
Expand All @@ -863,9 +874,7 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
* Check legacy mode: Let's find out if sensors are accessible
* via LPC interface.
*/
if (sensor_count == -EPROTO &&
ec->cmd_offset == 0 &&
ec_dev->cmd_readmem) {
if (sensor_count < 0 && ec->cmd_offset == 0 && ec_dev->cmd_readmem) {
ret = ec_dev->cmd_readmem(ec_dev, EC_MEMMAP_ACC_STATUS,
1, &status);
if (ret >= 0 &&
Expand All @@ -880,9 +889,6 @@ int cros_ec_get_sensor_count(struct cros_ec_dev *ec)
*/
sensor_count = 0;
}
} else if (sensor_count == -EPROTO) {
/* EC responded, but does not understand DUMP command. */
sensor_count = 0;
}
return sensor_count;
}
Expand Down
26 changes: 10 additions & 16 deletions drivers/platform/chrome/cros_ec_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,10 @@ static ssize_t version_show(struct device *dev,
msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset;
msg->insize = EC_HOST_PARAM_SIZE;
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret == -EPROTO) {
count += scnprintf(buf + count, PAGE_SIZE - count,
"Build info: EC error %d\n", msg->result);
} else if (ret < 0) {
if (ret < 0) {
count += scnprintf(buf + count, PAGE_SIZE - count,
"Build info: XFER ERROR %d\n", ret);
"Build info: XFER / EC ERROR %d / %d\n",
ret, msg->result);
} else {
msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
count += scnprintf(buf + count, PAGE_SIZE - count,
Expand All @@ -166,12 +164,10 @@ static ssize_t version_show(struct device *dev,
msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset;
msg->insize = sizeof(*r_chip);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret == -EPROTO) {
count += scnprintf(buf + count, PAGE_SIZE - count,
"Chip info: EC error %d\n", msg->result);
} else if (ret < 0) {
if (ret < 0) {
count += scnprintf(buf + count, PAGE_SIZE - count,
"Chip info: XFER ERROR %d\n", ret);
"Chip info: XFER / EC ERROR %d / %d\n",
ret, msg->result);
} else {
r_chip = (struct ec_response_get_chip_info *)msg->data;

Expand All @@ -190,12 +186,10 @@ static ssize_t version_show(struct device *dev,
msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset;
msg->insize = sizeof(*r_board);
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
if (ret == -EPROTO) {
count += scnprintf(buf + count, PAGE_SIZE - count,
"Board version: EC error %d\n", msg->result);
} else if (ret < 0) {
if (ret < 0) {
count += scnprintf(buf + count, PAGE_SIZE - count,
"Board version: XFER ERROR %d\n", ret);
"Board version: XFER / EC ERROR %d / %d\n",
ret, msg->result);
} else {
r_board = (struct ec_response_board_version *)msg->data;

Expand Down Expand Up @@ -326,7 +320,7 @@ static struct attribute *__ec_attrs[] = {
static umode_t cros_ec_ctrl_visible(struct kobject *kobj,
struct attribute *a, int n)
{
struct device *dev = container_of(kobj, struct device, kobj);
struct device *dev = kobj_to_dev(kobj);
struct cros_ec_dev *ec = to_cros_ec_dev(dev);

if (a == &dev_attr_kb_wake_angle.attr && !ec->has_kb_wake_angle)
Expand Down
27 changes: 21 additions & 6 deletions drivers/platform/chrome/cros_ec_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,49 @@ TRACE_EVENT(cros_ec_request_start,
TP_ARGS(cmd),
TP_STRUCT__entry(
__field(uint32_t, version)
__field(uint32_t, offset)
__field(uint32_t, command)
__field(uint32_t, outsize)
__field(uint32_t, insize)
),
TP_fast_assign(
__entry->version = cmd->version;
__entry->command = cmd->command;
__entry->offset = cmd->command / EC_CMD_PASSTHRU_OFFSET(1);
__entry->command = cmd->command % EC_CMD_PASSTHRU_OFFSET(1);
__entry->outsize = cmd->outsize;
__entry->insize = cmd->insize;
),
TP_printk("version: %u, command: %s", __entry->version,
__print_symbolic(__entry->command, EC_CMDS))
TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u",
__entry->version, __entry->offset,
__print_symbolic(__entry->command, EC_CMDS),
__entry->outsize, __entry->insize)
);

TRACE_EVENT(cros_ec_request_done,
TP_PROTO(struct cros_ec_command *cmd, int retval),
TP_ARGS(cmd, retval),
TP_STRUCT__entry(
__field(uint32_t, version)
__field(uint32_t, offset)
__field(uint32_t, command)
__field(uint32_t, outsize)
__field(uint32_t, insize)
__field(uint32_t, result)
__field(int, retval)
),
TP_fast_assign(
__entry->version = cmd->version;
__entry->command = cmd->command;
__entry->offset = cmd->command / EC_CMD_PASSTHRU_OFFSET(1);
__entry->command = cmd->command % EC_CMD_PASSTHRU_OFFSET(1);
__entry->outsize = cmd->outsize;
__entry->insize = cmd->insize;
__entry->result = cmd->result;
__entry->retval = retval;
),
TP_printk("version: %u, command: %s, ec result: %s, retval: %d",
__entry->version,
TP_printk("version: %u, offset: %d, command: %s, outsize: %u, insize: %u, ec result: %s, retval: %u",
__entry->version, __entry->offset,
__print_symbolic(__entry->command, EC_CMDS),
__entry->outsize, __entry->insize,
__print_symbolic(__entry->result, EC_RESULT),
__entry->retval)
);
Expand Down
Loading

0 comments on commit 090a7d0

Please sign in to comment.