drivers/platform/chrome/cros_ec_sysfs.c

Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_sysfs.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/chrome/cros_ec_sysfs.c
Extension
.c
Size
12290 bytes
Lines
442
Domain
Driver Families
Bucket
drivers/platform
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

strlen(words[i].str))) {
				if (words[i].flags) {
					param->flags |= words[i].flags;
				} else {
					param->cmd = words[i].cmd;
					got_cmd = 1;
				}
				break;
			}
		}

		/* On to the next word, if any */
		while (buf[offset] && !isspace(buf[offset]))
			offset++;
	}

	if (!got_cmd) {
		count = -EINVAL;
		goto exit;
	}

	msg->version = 0;
	msg->command = EC_CMD_REBOOT_EC + ec->cmd_offset;
	msg->outsize = sizeof(*param);
	msg->insize = 0;
	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
	if (ret < 0)
		count = ret;
exit:
	kfree(msg);
	return count;
}

static ssize_t version_show(struct device *dev,
			    struct device_attribute *attr, char *buf)
{
	static const char * const image_names[] = {"unknown", "RO", "RW"};
	struct ec_response_get_version *r_ver;
	struct ec_response_get_chip_info *r_chip;
	struct ec_response_board_version *r_board;
	struct cros_ec_command *msg;
	int ret;
	int count = 0;
	struct cros_ec_dev *ec = to_cros_ec_dev(dev);

	msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
	if (!msg)
		return -ENOMEM;

	/* Get versions. RW may change. */
	msg->version = 0;
	msg->command = EC_CMD_GET_VERSION + ec->cmd_offset;
	msg->insize = sizeof(*r_ver);
	msg->outsize = 0;
	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
	if (ret < 0) {
		count = ret;
		goto exit;
	}
	r_ver = (struct ec_response_get_version *)msg->data;
	/* Strings should be null-terminated, but let's be sure. */
	r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0';
	r_ver->version_string_rw[sizeof(r_ver->version_string_rw) - 1] = '\0';
	count += sysfs_emit_at(buf, count, "RO version:    %s\n", r_ver->version_string_ro);
	count += sysfs_emit_at(buf, count, "RW version:    %s\n", r_ver->version_string_rw);
	count += sysfs_emit_at(buf, count, "Firmware copy: %s\n",
			   (r_ver->current_image < ARRAY_SIZE(image_names) ?
			    image_names[r_ver->current_image] : "?"));

	/* Get build info. */
	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 < 0) {
		count += sysfs_emit_at(buf, count,
				   "Build info:    XFER / EC ERROR %d / %d\n",
				   ret, msg->result);
	} else {
		msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
		count += sysfs_emit_at(buf, count, "Build info:    %s\n", msg->data);
	}

	/* Get chip info. */
	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 < 0) {
		count += sysfs_emit_at(buf, count,
				   "Chip info:     XFER / EC ERROR %d / %d\n",
				   ret, msg->result);

Annotation

Implementation Notes