Commit 1210d1e6 authored by Nick Crews's avatar Nick Crews Committed by Enric Balletbo i Serra

platform/chrome: wilco_ec: Add telemetry char device interface

The Wilco Embedded Controller is able to send telemetry data
which is useful for enterprise applications. A daemon running on
the OS sends a command to the EC via a write() to a char device,
and can read the response with a read(). The write() request is
verified by the driver to ensure that it is performing only one
of the whitelisted commands, and that no extraneous data is
being transmitted to the EC. The response is passed directly
back to the reader with no modification.

The character device will appear as /dev/wilco_telemN, where N
is some small non-negative integer, starting with 0. Only one
process may have the file descriptor open at a time. The calling
userspace program needs to keep the device file descriptor open
between the calls to write() and read() in order to preserve the
response. Up to 32 bytes will be available for reading.

For testing purposes, try requesting the EC's firmware build
date, by sending the WILCO_EC_TELEM_GET_VERSION command with
argument index=3. i.e. write [0x38, 0x00, 0x03]
to the device node. An ASCII string of the build date is
returned.
Signed-off-by: default avatarNick Crews <ncrews@chromium.org>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
parent f7b0bc5e
......@@ -27,3 +27,10 @@ config WILCO_EC_EVENTS
(such as power state changes) to userspace. The EC sends the events
over ACPI, and a driver queues up the events to be read by a
userspace daemon from /dev/wilco_event using read() and poll().
config WILCO_EC_TELEMETRY
tristate "Enable querying telemetry data from EC"
depends on WILCO_EC
help
If you say Y here, you get support to query EC telemetry data from
/dev/wilco_telem0 using write() and then read().
......@@ -6,3 +6,5 @@ wilco_ec_debugfs-objs := debugfs.o
obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.o
wilco_ec_events-objs := event.o
obj-$(CONFIG_WILCO_EC_EVENTS) += wilco_ec_events.o
wilco_ec_telem-objs := telemetry.o
obj-$(CONFIG_WILCO_EC_TELEMETRY) += wilco_ec_telem.o
......@@ -93,8 +93,20 @@ static int wilco_ec_probe(struct platform_device *pdev)
goto unregister_rtc;
}
/* Register child device that will be found by the telemetry driver. */
ec->telem_pdev = platform_device_register_data(dev, "wilco_telem",
PLATFORM_DEVID_AUTO,
ec, sizeof(*ec));
if (IS_ERR(ec->telem_pdev)) {
dev_err(dev, "Failed to create telemetry platform device\n");
ret = PTR_ERR(ec->telem_pdev);
goto remove_sysfs;
}
return 0;
remove_sysfs:
wilco_ec_remove_sysfs(ec);
unregister_rtc:
platform_device_unregister(ec->rtc_pdev);
unregister_debugfs:
......@@ -109,6 +121,7 @@ static int wilco_ec_remove(struct platform_device *pdev)
struct wilco_ec_device *ec = platform_get_drvdata(pdev);
wilco_ec_remove_sysfs(ec);
platform_device_unregister(ec->telem_pdev);
platform_device_unregister(ec->rtc_pdev);
if (ec->debugfs_pdev)
platform_device_unregister(ec->debugfs_pdev);
......
......@@ -16,7 +16,7 @@
#define DRV_NAME "wilco-ec-debugfs"
/* The 256 raw bytes will take up more space when represented as a hex string */
/* The raw bytes will take up more space when represented as a hex string */
#define FORMATTED_BUFFER_SIZE (EC_MAILBOX_DATA_SIZE * 4)
struct wilco_ec_debugfs {
......
This diff is collapsed.
......@@ -29,6 +29,7 @@
* @data_size: Size of the data buffer used for EC communication.
* @debugfs_pdev: The child platform_device used by the debugfs sub-driver.
* @rtc_pdev: The child platform_device used by the RTC sub-driver.
* @telem_pdev: The child platform_device used by the telemetry sub-driver.
*/
struct wilco_ec_device {
struct device *dev;
......@@ -40,6 +41,7 @@ struct wilco_ec_device {
size_t data_size;
struct platform_device *debugfs_pdev;
struct platform_device *rtc_pdev;
struct platform_device *telem_pdev;
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment