platform/chrome: rtc: Add support for Wilco EC
v2 cover platform/chrome: rtc: Add support for Wilco EC
There is a new chromebook that contains a different Embedded Controller (codename Wilco) than the rest of the chromebook series. Thus the kernel requires a different driver than the already existing and generalized cros_ec_* drivers. Specifically, this driver adds support for getting and setting the RTC on the EC, adding a binary sysfs attribute that receives ACPI events from the EC, adding a binary sysfs attribute to request telemetry data from the EC (useful for enterprise applications), and adding normal sysfs attributes to get/set various other properties on the EC. The core of the communication with the EC is implemented in wilco_ec/mailbox.c, using a simple byte-level protocol with a checksum, transmitted over an eSPI bus. For debugging purposes, a raw attribute is also provided which can write/read arbitrary bytes to/from the eSPI bus.
We attempted to adhere to the sysfs principles of "one piece of data per attribute" as much as possible, and mostly succeded. However, with the wilco_ec/adv_power.h attributes, which deal with scheduling power usage, we found it most elegant to bundle setting event times for an entire day into a single attribute, so at most you are using attributes formatted as "%d %d %d %d %d %d". With the telemetry attribute, we had to use a binary attribute, instead of the preferable human-readable ascii, in order to keep secure the information which is proprietary to the enterprise service provider. This opaque binary data will be read and sent using a proprietary daemon running on the OS. Finally, the "version" attribute returns a formatted result that looks something like:
Quoted 1 line
cat /sys/bus/platform/devices/GOOG000C\:00/version
Label : 95.00.06
SVN Revision : 5960a.06
Model Number : 08;8
Build Date : 11/29/18
The RTC driver is exposed as a standard RTC class driver with read/write functionality.
For event notification, the Wilco EC can return extended events that are not handled by standard ACPI objects. These events can include hotkeys which map to standard functions like brightness controls, or information about EC controlled features like the charger or battery. These events are triggered with an ACPI Notify(0x90) and the event data buffer is read through an ACPI method provided by the BIOS which reads the event buffer from EC RAM. These events are then processed, with hotkey events being sent to the input subsystem and other events put into a queue which can be read by a userspace daemon via a sysfs attribute.
The rest of the attributes are categorized as either "properties" or "legacy". "legacy" implies that the attribute existed on the EC before it was modified for ChromeOS, and "properties" implies that the attribute exposes functionality that was added to the EC specifically for ChromeOS. They are mostly boolean flags or percentages.
A full thread of the development of these patches can be found at
https://chromium-review.googlesource.com/c/1371034. This thread contains comments and revisions that could be helpful in understanding how the driver arrived at the state it is in now. The thread also contains some ChromeOS specific patches that actually enable the driver. If you want to test the patch yourself, you would have to install the ChromeOS SDK and cherry pick in these patches.
I also wrote some integration tests using the Tast testing framework that ChromeOS uses. It would require a full ChromeOS SDK to actually run the tests, but the source of the tests, written in Go, are useful for understanding what the desired behavior is. You can view the tests here:
https://chromium-review.googlesource.com/c/1372575
Thank you for your comments!
Changes in v2:
- Fixed kernel-doc comments
- Fixed include of linux/mfd/cros_ec_lpc_mec.h
- cros_ec_lpc_mec_in_range() returns -EINVAL on error
- Added parens around macro variables
- Removed COMPILE_TEST from Kconfig because inb()/outb() won't work on anything but X86
- Moved everything to wilco_ec/ subdirectory
- Moved header file to include/platform_data/
so could be used by future sub-drivers
- Tweaked mailbox()
- Removed duplicate EC_MAILBOX_DATA_SIZE defs
- Removed some error messages / converted to dbg()
- Remove license boiler plate
- Remove "wilco_ec_sysfs -" docstring prefix
- Fix accidental Makefile deletion
- Add documentation for sysfs entries
- Change "enable ? 0 : 1" to "!enable"
- No longer override error code from sysfs_init()
- Put attributes in the legacy file to begin with, don't move later
- Remove duplicate error messages in sysfs_init() and its caller
- Add sysfs documentation
- rm duplicate EC_MAILBOX_DATA_SIZE defs
- Make docstrings follow kernel style
- Fix tags in commit msg
- Reading raw now includes ASCII translation
- rm license boiler plate
- rm "wilco_ec_rtc -" prefix in docstring
- Make rtc driver its own module within the drivers/rtc/ directory
- Register a rtc device from core.c that is picked up by this driver
- rm unused rtc_sync() function
- rm "wilco_ec_event -" prefix from docstring
- rm license boiler plate
- Add sysfs directory documentation
- Fix cosmetics
- Remove duplicate error messages
- rm license boiler plate
- rm "wilco_ec_properties -" prefix from docstring
- Add documentation
- rm license boiler plate
- rm "wilco_ec_adv_power - " prefix from docstring
- Add documentation
- Made format strings in store() and read() functions static
- rm "wilco_ec_telemetry - " prefix from docstring
- rm license boiler plate
- Fix commit msg tag
Duncan Laurie (6):
platform/chrome: Remove cros_ec dependency in lpc_mec platform/chrome: Add new driver for Wilco EC platform/chrome: Add sysfs attributes platform/chrome: Add support for raw commands in sysfs platform/chrome: rtc: Add RTC driver for Wilco EC platform/chrome: Add event handling
Nick Crews (3):
platform/chrome: Add EC properties platform/chrome: Add peakshift and adv_batt_charging platform/chrome: Add binary telemetry attributes
.../ABI/testing/sysfs-platform-wilcoec | 176 ++++++ drivers/platform/chrome/Kconfig | 4 +- drivers/platform/chrome/Makefile | 2 + drivers/platform/chrome/cros_ec_lpc_mec.c | 52 +- drivers/platform/chrome/cros_ec_lpc_mec.h | 43 +- drivers/platform/chrome/cros_ec_lpc_reg.c | 43 +- drivers/platform/chrome/wilco_ec/Kconfig | 33 ++ drivers/platform/chrome/wilco_ec/Makefile | 6 + drivers/platform/chrome/wilco_ec/adv_power.c | 544 ++++++++++++++++++ drivers/platform/chrome/wilco_ec/adv_power.h | 183 ++++++ drivers/platform/chrome/wilco_ec/core.c | 144 +++++ drivers/platform/chrome/wilco_ec/event.c | 347 +++++++++++ drivers/platform/chrome/wilco_ec/legacy.c | 190 ++++++ drivers/platform/chrome/wilco_ec/legacy.h | 93 +++ drivers/platform/chrome/wilco_ec/mailbox.c | 237 ++++++++ drivers/platform/chrome/wilco_ec/properties.c | 344 +++++++++++ drivers/platform/chrome/wilco_ec/properties.h | 179 ++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 238 ++++++++ drivers/platform/chrome/wilco_ec/telemetry.c | 66 +++ drivers/platform/chrome/wilco_ec/telemetry.h | 41 ++ drivers/platform/chrome/wilco_ec/util.h | 38 ++ drivers/rtc/Kconfig | 11 + drivers/rtc/Makefile | 1 + drivers/rtc/rtc-wilco-ec.c | 178 ++++++ include/linux/platform_data/wilco-ec.h | 186 ++++++ 25 files changed, 3319 insertions(+), 60 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-wilcoec create mode 100644 drivers/platform/chrome/wilco_ec/Kconfig create mode 100644 drivers/platform/chrome/wilco_ec/Makefile create mode 100644 drivers/platform/chrome/wilco_ec/adv_power.c create mode 100644 drivers/platform/chrome/wilco_ec/adv_power.h create mode 100644 drivers/platform/chrome/wilco_ec/core.c create mode 100644 drivers/platform/chrome/wilco_ec/event.c create mode 100644 drivers/platform/chrome/wilco_ec/legacy.c create mode 100644 drivers/platform/chrome/wilco_ec/legacy.h create mode 100644 drivers/platform/chrome/wilco_ec/mailbox.c create mode 100644 drivers/platform/chrome/wilco_ec/properties.c create mode 100644 drivers/platform/chrome/wilco_ec/properties.h create mode 100644 drivers/platform/chrome/wilco_ec/sysfs.c create mode 100644 drivers/platform/chrome/wilco_ec/telemetry.c create mode 100644 drivers/platform/chrome/wilco_ec/telemetry.h create mode 100644 drivers/platform/chrome/wilco_ec/util.h create mode 100644 drivers/rtc/rtc-wilco-ec.c create mode 100644 include/linux/platform_data/wilco-ec.h
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH v2 1/9 platform/chrome: Remove cros_ec dependency in lpc_mec
From: Duncan Laurie <[email protected]>
In order to allow this code to be re-used, remove the dependency on the rest of the cros_ec code from the cros_ec_lpc_mec functions.
Instead of using a hardcoded register base address of 0x800 have this be passed in to cros_ec_lpc_mec_init(). The existing cros_ec use case now passes in the 0x800 base address this way.
There are some error checks that happen in cros_ec_lpc_mec_in_range() that probably shouldn't be there, as they are checking kernel-space callers and not user-space input. However, we'll just do the refactor in this patch, and in a future patch might remove this error checking and fix all the instances of code that calls this.
There's a similar problem in cros_ec_lpc_read_bytes(), where we return a checksum, but on error just return 0. This should probably be changed so that it returns int, but we don't want to have to mess with all the calling code for this fix. Maybe we'll come back through later and fix this.
---
Changes in v2:
- Fixed kernel-doc comments
- Fixed include of linux/mfd/cros_ec_lpc_mec.h
- cros_ec_lpc_mec_in_range() returns -EINVAL on error
- Added parens around macro variables
drivers/platform/chrome/cros_ec_lpc_mec.c | 52 +++++++++++++++++++---- drivers/platform/chrome/cros_ec_lpc_mec.h | 43 ++++++++++--------- drivers/platform/chrome/cros_ec_lpc_reg.c | 43 ++++++------------- 3 files changed, 79 insertions(+), 59 deletions(-)
drivers/platform/chrome/cros_ec_lpc_mec.c +43 -9
@@ -23,7 +23,6 @@#include <linux/delay.h> #include <linux/io.h> -#include <linux/mfd/cros_ec_commands.h> #include <linux/mutex.h> #include <linux/types.h>
@@ -34,6 +33,7 @@* EC mutex because memmap data may be accessed without it being held. */ static struct mutex io_mutex; +static u16 mec_emi_base, mec_emi_end;/* * cros_ec_lpc_mec_emi_write_address
@@ -46,10 +46,37 @@ static struct mutex io_mutex;static void cros_ec_lpc_mec_emi_write_address (u16 addr,enum cros_ec_lpc_mec_emi_access_mode access_type) { -/* Address relative to start of EMI range */ - addr -=MEC_EMI_RANGE_START ; -outb ((addr &0xfc ) | access_type,MEC_EMI_EC_ADDRESS_B0 ); -outb ((addr >>8 ) &0x7f ,MEC_EMI_EC_ADDRESS_B1 ); +outb ((addr &0xfc ) | access_type,MEC_EMI_EC_ADDRESS_B0 (mec_emi_base)); +outb ((addr >>8 ) &0x7f ,MEC_EMI_EC_ADDRESS_B1 (mec_emi_base)); +} + +/** +* cros_ec_lpc_mec_in_range() - Determine if addresses are in MEC EMI range. +* +* @offset: Address offset +* @length: Number of bytes to check +* +* Return: 1 if in range, 0 if not, and -EINVAL on failure +* such as the mec range not being initialized +*/ +int cros_ec_lpc_mec_in_range (unsigned int offset,unsigned int length) +{ +if (length ==0 ) +return -EINVAL ; + +if (WARN_ON (mec_emi_base ==0 || mec_emi_end ==0 )) +return -EINVAL ; + +if (offset >= mec_emi_base && offset < mec_emi_end) { +if (WARN_ON (offset + length -1 <= mec_emi_end)) +return -EINVAL ; +return 1 ; + } + +if (WARN_ON (offset + length > mec_emi_base && offset < mec_emi_end)) +return -EINVAL ; + +return 0 ; }/*
@@ -71,6 +98,11 @@ u8 cros_ec_lpc_io_bytes_mec(enum cros_ec_lpc_mec_io_type io_type,u8 sum =0 ;enum cros_ec_lpc_mec_emi_access_mode access, new_access; +/* Return checksum of 0 if window is not initialized */ +WARN_ON (mec_emi_base ==0 || mec_emi_end ==0 ); +if (mec_emi_base ==0 || mec_emi_end ==0 ) +return 0 ; +/* * Long access cannot be used on misaligned data since reading B0 loads * the data register and writing B3 flushes.
@@ -86,9 +118,9 @@ u8 cros_ec_lpc_io_bytes_mec(enum cros_ec_lpc_mec_io_type io_type,cros_ec_lpc_mec_emi_write_address (offset, access);/* Skip bytes in case of misaligned offset */ - io_addr =MEC_EMI_EC_DATA_B0 + (offset &0x3 ); + io_addr =MEC_EMI_EC_DATA_B0 (mec_emi_base) + (offset &0x3 );while (i < length) { -while (io_addr <=MEC_EMI_EC_DATA_B3 ) { +while (io_addr <=MEC_EMI_EC_DATA_B3 (mec_emi_base)) {if (io_type ==MEC_IO_READ ) buf[i] =inb (io_addr++);else
@@ -118,7 +150,7 @@ u8 cros_ec_lpc_io_bytes_mec(enum cros_ec_lpc_mec_io_type io_type, }/* Access [B0, B3] on each loop pass */ - io_addr =MEC_EMI_EC_DATA_B0 ; + io_addr =MEC_EMI_EC_DATA_B0 (mec_emi_base); } done:
@@ -128,9 +160,11 @@ u8 cros_ec_lpc_io_bytes_mec(enum cros_ec_lpc_mec_io_type io_type, }EXPORT_SYMBOL (cros_ec_lpc_io_bytes_mec); -void cros_ec_lpc_mec_init (void ) +void cros_ec_lpc_mec_init (unsigned int base,unsigned int end) {mutex_init (&io_mutex); + mec_emi_base = base; + mec_emi_end = end; }EXPORT_SYMBOL (cros_ec_lpc_mec_init);
drivers/platform/chrome/cros_ec_lpc_mec.h +24 -19
65 lines not on this page · raw message
drivers/platform/chrome/cros_ec_lpc_reg.c +12 -31
63 lines not on this page · raw message
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH v2 2/9 platform/chrome: Add new driver for Wilco EC
In reply to Nick CrewsFrom: Duncan Laurie <[email protected]>
This EC is an incompatible variant of the typical Chrome OS embedded controller. It uses the same low-level communication and a similar protocol with some significant differences. The EC firmware does not support the same mailbox commands so it is not registered as a cros_ec device type.
---
Changes in v2:
- Removed COMPILE_TEST from Kconfig because inb()/outb() won't work on anything but X86
- Moved everything to wilco_ec/ subdirectory
- Moved header file to include/platform_data/ so could be used by future sub-drivers
- Tweaked mailbox()
- Removed duplicate EC_MAILBOX_DATA_SIZE defs
- Removed some error messages / converted to dbg()
drivers/platform/chrome/Kconfig | 4 +- drivers/platform/chrome/Makefile | 2 + drivers/platform/chrome/wilco_ec/Kconfig | 24 +++ drivers/platform/chrome/wilco_ec/Makefile | 4 + drivers/platform/chrome/wilco_ec/core.c | 99 +++++++++ drivers/platform/chrome/wilco_ec/mailbox.c | 237 +++++++++++++++++++++ include/linux/platform_data/wilco-ec.h | 138 ++++++++++++ 7 files changed, 507 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/chrome/wilco_ec/Kconfig create mode 100644 drivers/platform/chrome/wilco_ec/Makefile create mode 100644 drivers/platform/chrome/wilco_ec/core.c create mode 100644 drivers/platform/chrome/wilco_ec/mailbox.c create mode 100644 include/linux/platform_data/wilco-ec.h
drivers/platform/chrome/Kconfig +3 -1
@@ -49,6 +49,8 @@ config CHROMEOS_TBMC To compile this driver as a module, choose M here: the module will be called chromeos_tbmc. +source "drivers/platform/chrome/wilco_ec/Kconfig" + config CROS_EC_CTL tristate
@@ -86,7 +88,7 @@ config CROS_EC_LPC config CROS_EC_LPC_MEC bool "ChromeOS Embedded Controller LPC Microchip EC (MEC) variant" - depends on CROS_EC_LPC + depends on CROS_EC_LPC || WILCO_EC default n help If you say Y here, a variant LPC protocol for the Microchip EC
drivers/platform/chrome/Makefile +2 -0
@@ -13,3 +13,5 @@ cros_ec_lpcs-$(CONFIG_CROS_EC_LPC_MEC) += cros_ec_lpc_mec.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o + +obj-$(CONFIG_WILCO_EC) += wilco_ec/
drivers/platform/chrome/wilco_ec/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +menuconfig WILCO_EC_PLATFORM + bool "Platform support for Wilco Embedded Controller hardware" + help + Say Y here to get to see options for platform support for + various Wilco EC features. This option alone does + not add any kernel code. + + If you say N, all options in this submenu will be skipped and disabled. + +if WILCO_EC_PLATFORM + +config WILCO_EC + tristate "ChromeOS Wilco Embedded Controller" + depends on ACPI && X86 + select CROS_EC_LPC_MEC + help + If you say Y here, you get support for talking to the ChromeOS + Wilco EC over an eSPI bus. This uses a simple byte-level protocol + with a checksum. + + To compile this driver as a module, choose M here: the + module will be called wilco_ec. + +endif # WILCO_EC_PLATFORM
drivers/platform/chrome/wilco_ec/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +wilco_ec-objs := core.o mailbox.o +obj-$(CONFIG_WILCO_EC) += wilco_ec.o
drivers/platform/chrome/wilco_ec/core.c new file +99 -0
99 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/mailbox.c new file +237 -0
237 lines not on this page · raw message
include/linux/platform_data/wilco-ec.h new file +138 -0
138 lines not on this page · raw message
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Re: [PATCH v2 2/9] platform/chrome: Add new driver for Wilco EC
Hi Nick,
The patch looks pretty good to me, just some minor comments below ...
Missatge de Nick Crews <[email protected]> del dia dl., 14 de gen. 2019 a les 23:05:
Quoted 131 lines
From: Duncan Laurie <[email protected]>
This EC is an incompatible variant of the typical Chrome OS embedded controller. It uses the same low-level communication and a similar protocol with some significant differences. The EC firmware does not support the same mailbox commands so it is not registered as a
cros_ecdevice type.Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Nick Crews <[email protected]>---
Changes in v2:
- RemovedCOMPILE_TESTfromKconfigbecause inb()/outb() won't work on anything but X86
- Moved everything to wilco_ec/ subdirectory
- Moved header file toinclude/platform_data/so could be used by future sub-drivers
- Tweakedmailbox()
- Removed duplicateEC_MAILBOX_DATA_SIZEdefs
- Removed some error messages / converted todbg()drivers/platform/chrome/Kconfig | 4 +- drivers/platform/chrome/Makefile | 2 + drivers/platform/chrome/wilco_ec/Kconfig | 24 +++ drivers/platform/chrome/wilco_ec/Makefile | 4 + drivers/platform/chrome/wilco_ec/core.c | 99 +++++++++ drivers/platform/chrome/wilco_ec/mailbox.c | 237 +++++++++++++++++++++ include/linux/platform_data/wilco-ec.h | 138 ++++++++++++ 7 files changed, 507 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/chrome/wilco_ec/Kconfig create mode 100644 drivers/platform/chrome/wilco_ec/Makefile create mode 100644 drivers/platform/chrome/wilco_ec/core.c create mode 100644 drivers/platform/chrome/wilco_ec/mailbox.c create mode 100644 include/linux/platform_data/wilco-ec.hdrivers/platform/chrome/Kconfig +3
-1@@ -49,6 +49,8 @@ config CHROMEOS_TBMC To compile this driver as a module, choose M here: the module will be called chromeos_tbmc. +source "drivers/platform/chrome/wilco_ec/Kconfig" + config CROS_EC_CTL tristate@@ -86,7 +88,7 @@ config CROS_EC_LPC config CROS_EC_LPC_MEC bool "ChromeOS Embedded Controller LPC Microchip EC (MEC) variant" - depends on CROS_EC_LPC + depends on CROS_EC_LPC || WILCO_EC default n help If you say Y here, a variant LPC protocol for the Microchip ECdrivers/platform/chrome/Makefile +2
-0@@ -13,3 +13,5 @@ cros_ec_lpcs-$(CONFIG_CROS_EC_LPC_MEC) += cros_ec_lpc_mec.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o + +obj-$(CONFIG_WILCO_EC) += wilco_ec/drivers/platform/chrome/wilco_ec/Kconfig new file +24
-0@@ -0,0 +1,24 @@ +menuconfig WILCO_EC_PLATFORM + bool "Platform support for Wilco Embedded Controller hardware" + help + Say Y here to get to see options for platform support for + various Wilco EC features. This option alone does + not add any kernel code. + + If you say N, all options in this submenu will be skipped and disabled. + +if WILCO_EC_PLATFORM + +config WILCO_EC + tristate "ChromeOS Wilco Embedded Controller" + depends on ACPI && X86 + select CROS_EC_LPC_MEC + help + If you say Y here, you get support for talking to the ChromeOS + Wilco EC over an eSPI bus. This uses a simple byte-level protocol + with a checksum. + + To compile this driver as a module, choose M here: the + module will be called wilco_ec. + +endif # WILCO_EC_PLATFORMdrivers/platform/chrome/wilco_ec/Makefile new file +4
-0@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +wilco_ec-objs := core.o mailbox.o +obj-$(CONFIG_WILCO_EC) += wilco_ec.odrivers/platform/chrome/wilco_ec/core.c new file +16
-0@@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Mailbox interface for Wilco Embedded Controller +* +* Copyright 2018 Google LLC +*/ + +#include <linux/acpi.h> +#include <linux/device.h> +#include <linux/ioport.h> +#include <linux/module.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/platform_device.h> + +#include "../cros_ec_lpc_mec.h" +
drivers/platform/chrome/wilco_ec/core.c line 26
Quoted 10 lines
drivers/platform/chrome/wilco_ec/core.c new file +10
-0+static struct resource *wilco_get_resource (struct platform_device *pdev, +int index) +{ +struct device *dev = &pdev->dev; +struct resource *res; + + res =platform_get_resource (pdev,IORESOURCE_IO , index); +if (!res) { +dev_dbg (dev,"couldn't find IO resource %d\n" , index); +return NULL ;
return res; ?
drivers/platform/chrome/wilco_ec/core.c line 33
Quoted 7 lines
drivers/platform/chrome/wilco_ec/core.c new file +7
-0+ } + +if (!devm_request_region (dev, res->start,resource_size (res), +dev_name (dev))) +return NULL ; + +return res;
return devm_request_region(dev, res->start,
resource_size(res),dev_name(dev))); ?
drivers/platform/chrome/wilco_ec/core.c line 40
Quoted 7 lines
drivers/platform/chrome/wilco_ec/core.c new file +7
-0+} + +static int wilco_ec_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct wilco_ec_device *ec; +int ret;
This variable is not used, you can remove it.
drivers/platform/chrome/wilco_ec/core.c line 44
Quoted 4 lines
drivers/platform/chrome/wilco_ec/core.c new file +4
-0+ + ec =devm_kzalloc (dev,sizeof (*ec),GFP_KERNEL ); +if (!ec) +return -ENOMEM ;
nit: I like to see a blank line here
Quoted 108 lines
drivers/platform/chrome/wilco_ec/core.c new file +55
-0+platform_set_drvdata (pdev, ec); + ec->dev = dev; +mutex_init (&ec->mailbox_lock); + +/* Largest data buffer size requirement is extended data response */ + ec->data_size =sizeof (struct wilco_ec_response ) + +EC_MAILBOX_DATA_SIZE_EXTENDED ; + ec->data_buffer =devm_kzalloc (dev, ec->data_size,GFP_KERNEL ); +if (!ec->data_buffer) +return -ENOMEM ; + +/* Prepare access to IO regions provided by ACPI */ + ec->io_data =wilco_get_resource (pdev,0 );/* Host Data */ + ec->io_command =wilco_get_resource (pdev,1 );/* Host Command */ + ec->io_packet =wilco_get_resource (pdev,2 );/* MEC EMI */ +if (!ec->io_data || !ec->io_command || !ec->io_packet) +return -ENODEV ; + +/* Initialize cros_ec register interface for communication */ +cros_ec_lpc_mec_init (ec->io_packet->start, + ec->io_packet->start +EC_MAILBOX_DATA_SIZE ); + +return 0 ; +} + +static int wilco_ec_remove (struct platform_device *pdev) +{ +/* Teardown cros_ec interface */ +cros_ec_lpc_mec_destroy (); + +return 0 ; +} + +static const struct acpi_device_id wilco_ec_acpi_device_ids[] = { + {"GOOG000C" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (acpi, wilco_ec_acpi_device_ids); + +static struct platform_driver wilco_ec_driver = { + .driver = { + .name ="wilco_ec" , + .acpi_match_table = wilco_ec_acpi_device_ids, + }, + .probe = wilco_ec_probe, + .remove = wilco_ec_remove, +}; + +module_platform_driver (wilco_ec_driver); + +MODULE_AUTHOR ("Nick Crews <[email protected]>" ); +MODULE_AUTHOR ("Duncan Laurie <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("ChromeOS Wilco Embedded Controller driver" ); +MODULE_ALIAS ("platform:wilco-ec" );drivers/platform/chrome/wilco_ec/mailbox.c new file +47
-0@@ -0,0 +1,237 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Mailbox interface for Wilco Embedded Controller +* +* Copyright 2018 Google LLC +* +* The Wilco EC is similar to a typical ChromeOS embedded controller. +* It uses the same MEC based low-level communication and a similar +* protocol, but with some important differences. The EC firmware does +* not support the same mailbox commands so it is not registered as a +* cros_ec device type. +* +* Most messages follow a standard format, but there are some exceptions +* and an interface is provided to do direct/raw transactions that do not +* make assumptions about byte placement. +*/ + +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/io.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/platform_device.h> + +#include "../cros_ec_lpc_mec.h" + +/* Version of mailbox interface */ +#define EC_MAILBOX_VERSION 0 + +/* Command to start mailbox transaction */ +#define EC_MAILBOX_START_COMMAND 0xda + +/* Version of EC protocol */ +#define EC_MAILBOX_PROTO_VERSION 3 + +/* Number of header bytes to be counted as data bytes */ +#define EC_MAILBOX_DATA_EXTRA 2 + +/* Maximum timeout */ +#define EC_MAILBOX_TIMEOUT HZ + +/* EC response flags */ +#define EC_CMDR_DATA BIT(0)/* Data ready for host to read */ +#define EC_CMDR_PENDING BIT(1)/* Write pending to EC */ +#define EC_CMDR_BUSY BIT(2)/* EC is busy processing a command */ +#define EC_CMDR_CMD BIT(3)/* Last host write was a command */ + +/**
drivers/platform/chrome/wilco_ec/mailbox.c line 57
Quoted 10 lines
drivers/platform/chrome/wilco_ec/mailbox.c new file +10
-0+* wilco_ec_response_timed_out() - Wait for EC response. +* @ec: EC device. +* +* Return: true if EC timed out, false if EC did not time out. +*/ +static bool wilco_ec_response_timed_out (struct wilco_ec_device *ec) +{ +unsigned long timeout = jiffies +EC_MAILBOX_TIMEOUT ; + +usleep_range (200 ,300 );
Is this sleep really needed here? The system will not respond in less than 200us? What happens if you just remove this line?
drivers/platform/chrome/wilco_ec/mailbox.c line 69
Quoted 12 lines
drivers/platform/chrome/wilco_ec/mailbox.c new file +12
-0+do { +if (!(inb (ec->io_command->start) & + (EC_CMDR_PENDING |EC_CMDR_BUSY ))) +return false; +usleep_range (100 ,200 ); + }while (time_before (jiffies, timeout)); + +return true; +} + +/** +* wilco_ec_checksum() - Compute 8bit checksum over data range.
nit: 8-bit, to be coherent with the documentation with the previous patch
drivers/platform/chrome/wilco_ec/mailbox.c line 73
Quoted 4 lines
drivers/platform/chrome/wilco_ec/mailbox.c new file +4
-0+* @data: Data to checksum. +* @size: Number of bytes to checksum. +* +* Return: 8bit checksum of provided data.
nit: 8-bit, to be coherent with the documentation with the previous patch
Quoted 309 lines
drivers/platform/chrome/wilco_ec/mailbox.c new file +164
-0+*/ +static u8 wilco_ec_checksum (const void *data,size_t size) +{ +u8 *data_bytes = (u8 *)data; +u8 checksum =0 ; +size_t i; + +for (i =0 ; i < size; i++) + checksum += data_bytes[i]; + +return checksum; +} + +/** +* wilco_ec_prepare() - Prepare the request structure for the EC. +* @msg: EC message with request information. +* @rq: EC request structure to fill. +*/ +static void wilco_ec_prepare (struct wilco_ec_message *msg, +struct wilco_ec_request *rq) +{ +memset (rq,0 ,sizeof (*rq)); + +/* Handle messages without trimming bytes from the request */ +if (msg->request_size && msg->flags &WILCO_EC_FLAG_RAW_REQUEST ) { + rq->reserved_raw = *(u8 *)msg->request_data; + msg->request_size--; +memmove (msg->request_data, msg->request_data +1 , + msg->request_size); + } + +/* Fill in request packet */ + rq->struct_version =EC_MAILBOX_PROTO_VERSION ; + rq->mailbox_id = msg->type; + rq->mailbox_version =EC_MAILBOX_VERSION ; + rq->data_size = msg->request_size +EC_MAILBOX_DATA_EXTRA ; + rq->command = msg->command; + +/* Checksum header and data */ + rq->checksum =wilco_ec_checksum (rq,sizeof (*rq)); + rq->checksum +=wilco_ec_checksum (msg->request_data, msg->request_size); + rq->checksum = -rq->checksum; +} + +/** +* wilco_ec_transfer() - Perform actual data transfer. +* @ec: EC device. +* @msg: EC message data for request and response. +* @rq: Filled in request structure +* +* Context: ec->mailbox_lock should be held while using this function. +* Return: number of bytes received or negative error code on failure. +*/ +int wilco_ec_transfer (struct wilco_ec_device *ec,struct wilco_ec_message *msg, +struct wilco_ec_request *rq) +{ +struct wilco_ec_response *rs; +u8 checksum; +u8 flag; +size_t size; + +/* Write request header, then data */ +cros_ec_lpc_io_bytes_mec (MEC_IO_WRITE ,0 ,sizeof (*rq), (u8 *)rq); +cros_ec_lpc_io_bytes_mec (MEC_IO_WRITE ,sizeof (*rq), msg->request_size, + msg->request_data); + +/* Start the command */ +outb (EC_MAILBOX_START_COMMAND , ec->io_command->start); + +/* Wait for it to complete */ +if (wilco_ec_response_timed_out (ec)) { +dev_dbg (ec->dev,"response timed out\n" ); +return -ETIMEDOUT ; + } + +/* For some commands (eg shutdown) the EC will not respond, that's OK */ +if (msg->flags &WILCO_EC_FLAG_NO_RESPONSE ) { +dev_dbg (ec->dev,"EC does not respond to this command\n" ); +return 0 ; + } + +/* Check result */ + flag =inb (ec->io_data->start); +if (flag) { +dev_dbg (ec->dev,"bad response: 0x%02x\n" , flag); +return -EIO ; + } + +if (msg->flags &WILCO_EC_FLAG_EXTENDED_DATA ) + size =EC_MAILBOX_DATA_SIZE_EXTENDED ; +else + size =EC_MAILBOX_DATA_SIZE ; + +/* Read back response */ + rs = ec->data_buffer; + checksum =cros_ec_lpc_io_bytes_mec (MEC_IO_READ ,0 , +sizeof (*rs) + size, (u8 *)rs); +if (checksum) { +dev_dbg (ec->dev,"bad packet checksum 0x%02x\n" , rs->checksum); +return -EBADMSG ; + } + +/* Check that the EC reported success */ + msg->result = rs->result; +if (msg->result) { +dev_dbg (ec->dev,"bad response: 0x%02x\n" , msg->result); +return -EBADMSG ; + } + +/* Check the returned data size, skipping the header */ +if (rs->data_size != size) { +dev_dbg (ec->dev,"unexpected packet size (%u != %zu)" , + rs->data_size, size); +return -EMSGSIZE ; + } + +/* Skip 1 response data byte unless specified */ + size = (msg->flags &WILCO_EC_FLAG_RAW_RESPONSE ) ?0 :1 ; +if ((ssize_t ) rs->data_size - size < msg->response_size) { +dev_dbg (ec->dev,"response data too short (%zd < %zu)" , + (ssize_t ) rs->data_size - size, msg->response_size); +return -EMSGSIZE ; + } + +/* Ignore response data bytes as requested */ +memcpy (msg->response_data, rs->data + size, msg->response_size); + +/* Return actual amount of data received */ +return msg->response_size; +} + +/** +* wilco_ec_mailbox() - Send EC request and receive EC response. +* @ec: EC device. +* @msg: EC message data for request and response. +* +* On entry msg->type, msg->flags, msg->command, msg->request_size, +* msg->response_size, and msg->request_data should all be filled in. +* +* On exit msg->result and msg->response_data will be filled. +* +* Return: number of bytes received or negative error code on failure. +*/ +int wilco_ec_mailbox (struct wilco_ec_device *ec,struct wilco_ec_message *msg) +{ +struct wilco_ec_request *rq; +int ret; + +dev_dbg (ec->dev,"cmd=%02x type=%04x flags=%02x rslen=%zu rqlen=%zu\n" , + msg->command, msg->type, msg->flags, msg->response_size, + msg->request_size); + +/* Prepare request packet */ + rq = ec->data_buffer; +wilco_ec_prepare (msg, rq); + +mutex_lock (&ec->mailbox_lock); + ret =wilco_ec_transfer (ec, msg, rq); +mutex_unlock (&ec->mailbox_lock); + +return ret; + +} +EXPORT_SYMBOL_GPL (wilco_ec_mailbox);include/linux/platform_data/wilco-ec.h new file +138
-1@@ -0,0 +1,138 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* ChromeOS Wilco Embedded Controller +* +* Copyright 2018 Google LLC +*/ + +#ifndef WILCO_EC_H +#define WILCO_EC_H + +#include <linux/device.h> +#include <linux/kernel.h> + +#define WILCO_EC_FLAG_NO_RESPONSE BIT(0)/* EC does not respond */ +#define WILCO_EC_FLAG_EXTENDED_DATA BIT(1)/* EC returns 256 data bytes */ +#define WILCO_EC_FLAG_RAW_REQUEST BIT(2)/* Do not trim request data */ +#define WILCO_EC_FLAG_RAW_RESPONSE BIT(3)/* Do not trim response data */ +#define WILCO_EC_FLAG_RAW (WILCO_EC_FLAG_RAW_REQUEST | \ + WILCO_EC_FLAG_RAW_RESPONSE) + +/* Normal commands have a maximum 32 bytes of data */ +#define EC_MAILBOX_DATA_SIZE 32 + +/* Extended commands have 256 bytes of response data */ +#define EC_MAILBOX_DATA_SIZE_EXTENDED 256 + +/** +* struct wilco_ec_device - Wilco Embedded Controller handle. +* @dev: Device handle. +* @mailbox_lock: Mutex to ensure one mailbox command at a time. +* @io_command: I/O port for mailbox command. Provided by ACPI. +* @io_data: I/O port for mailbox data. Provided by ACPI. +* @io_packet: I/O port for mailbox packet data. Provided by ACPI. +* @data_buffer: Buffer used for EC communication. The same buffer +* is used to hold the request and the response. +* @data_size: Size of the data buffer used for EC communication. +*/ +struct wilco_ec_device { +struct device *dev; +struct mutex mailbox_lock; +struct resource *io_command; +struct resource *io_data; +struct resource *io_packet; +void *data_buffer; +size_t data_size; +}; + +/** +* enum wilco_ec_msg_type - Message type to select a set of command codes. +* @WILCO_EC_MSG_LEGACY: Legacy EC messages for standard EC behavior. +* @WILCO_EC_MSG_PROPERTY: Get/Set/Sync EC controlled NVRAM property. +* @WILCO_EC_MSG_TELEMETRY: Telemetry data provided by the EC. +*/ +enum wilco_ec_msg_type { +WILCO_EC_MSG_LEGACY =0x00f0 , +WILCO_EC_MSG_PROPERTY =0x00f2 , +WILCO_EC_MSG_TELEMETRY =0x00f5 , +}; + +/** +* struct wilco_ec_message - Request and response message. +* @type: Mailbox message type. +* @flags: Message flags. +* @command: Mailbox command code. +* @result: Result code from the EC. Non-zero indicates an error. +* @request_size: Number of bytes to send to the EC. +* @request_data: Buffer containing the request data. +* @response_size: Number of bytes expected from the EC. +* This is 32 by default and 256 if the flag +* is set for %WILCO_EC_FLAG_EXTENDED_DATA +* @response_data: Buffer containing the response data, should be +* response_size bytes and allocated by caller. +*/ +struct wilco_ec_message { +enum wilco_ec_msg_type type; +u8 flags; +u8 command; +u8 result; +size_t request_size; +void *request_data; +size_t response_size; +void *response_data; +}; + +/** +* struct wilco_ec_request - Mailbox request message format. +* @struct_version: Should be %EC_MAILBOX_PROTO_VERSION +* @checksum: Sum of all bytes must be 0. +* @mailbox_id: Mailbox identifier, specifies the command set. +* @mailbox_version: Mailbox interface version %EC_MAILBOX_VERSION +* @reserved: Set to zero. +* @data_size: Length of request, data + last 2 bytes of the header. +* @command: Mailbox command code, unique for each mailbox_id set. +* @reserved_raw: Set to zero for most commands, but is used by +* some command types and for raw commands. +*/ +struct wilco_ec_request { +u8 struct_version; +u8 checksum; +u16 mailbox_id; +u8 mailbox_version; +u8 reserved; +u16 data_size; +u8 command; +u8 reserved_raw; +} __packed; + +/** +* struct wilco_ec_response - Mailbox response message format. +* @struct_version: Should be %EC_MAILBOX_PROTO_VERSION +* @checksum: Sum of all bytes must be 0. +* @result: Result code from the EC. Non-zero indicates an error. +* @data_size: Length of the response data buffer. +* @reserved: Set to zero. +* @mbox0: EC returned data at offset 0 is unused (always 0) so this byte +* is treated as part of the header instead of the data. +* @data: Response data buffer. Max size is %EC_MAILBOX_DATA_SIZE_EXTENDED. +*/ +struct wilco_ec_response { +u8 struct_version; +u8 checksum; +u16 result; +u16 data_size; +u8 reserved[2 ]; +u8 mbox0; +u8 data[0 ]; +} __packed; + +/** +* wilco_ec_mailbox() - Send request to the EC and receive the response. +* @ec: Wilco EC device. +* @msg: Wilco EC message. +* +* Return: Number of bytes received or negative error code on failure. +*/ +int wilco_ec_mailbox (struct wilco_ec_device *ec,struct wilco_ec_message *msg); + +#endif /* WILCO_EC_H */ --
Quoted 2 lines
2.20.1.97.g81188d93c3-goog
Thanks,
Enric
PATCH v2 3/9 platform/chrome: Add sysfs attributes
In reply to Nick CrewsFrom: Duncan Laurie <[email protected]>
Add some sample sysfs attributes for the Wilco EC that show how the mailbox interface works. "Legacy" attributes are those that existed in the EC before it was adapted to ChromeOS.
Quoted 1 line
cat /sys/bus/platform/devices/GOOG000C\:00/version
Label : 99.99.99
SVN Revision : 738ed.99
Model Number : 08;8
Build Date : 08/30/18
---
Changes in v2:
- Remove license boiler plate
- Remove "wilco_ec_sysfs -" docstring prefix
- Fix accidental Makefile deletion
- Add documentation for sysfs entries
- Change "enable ? 0 : 1" to "!enable"
- No longer override error code from sysfs_init()
- Put attributes in the legacy file to begin with, don't move later
- Remove duplicate error messages in sysfs_init() and its caller
.../ABI/testing/sysfs-platform-wilcoec | 26 ++++++ drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/core.c | 15 +++ drivers/platform/chrome/wilco_ec/legacy.c | 91 +++++++++++++++++++ drivers/platform/chrome/wilco_ec/legacy.h | 47 ++++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 66 ++++++++++++++ include/linux/platform_data/wilco-ec.h | 14 +++ 7 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-wilcoec create mode 100644 drivers/platform/chrome/wilco_ec/legacy.c create mode 100644 drivers/platform/chrome/wilco_ec/legacy.h create mode 100644 drivers/platform/chrome/wilco_ec/sysfs.c
Documentation/ABI/testing/sysfs-platform-wilcoec new file +26 -0
@@ -0,0 +1,26 @@ +What: /sys/bus/platform/devices/GOOG000C\:00/version +Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller version info + + Output will be similar to the example below: + Label : 95.00.06 + SVN Revision : 5960a.06 + Model Number : 08;8 + Build Date : 11/29/18 + + Although this contains multiple pieces of data in a single sysfs + attribute (inconsistent with normal sysfs conventions), + this format was chosen to be consistent with the version + attribute in /sys/class/chomeos/<device>/version + +What: /sys/bus/platform/devices/GOOG000C\:00/stealth_mode +Date: January 2019 +KernelVersion: 4.19 +Description: + Turn stealth_mode on or off on EC. Stealth mode means that the + various LEDs, the LCD backlight, and onboard speakers are turned + off and remain off even if activated from the off state. + External monitors connected to the system are not affected. + In addition Wireless devices are turned off.
drivers/platform/chrome/wilco_ec/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 -wilco_ec-objs := core.o mailbox.o +wilco_ec-objs := core.o mailbox.o sysfs.o legacy.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o
drivers/platform/chrome/wilco_ec/core.c +15 -0
@@ -64,11 +64,26 @@ static int wilco_ec_probe(struct platform_device *pdev)cros_ec_lpc_mec_init (ec->io_packet->start, ec->io_packet->start +EC_MAILBOX_DATA_SIZE ); +/* Create sysfs attributes for userspace interaction */ + ret =wilco_ec_sysfs_init (ec); +if (ret <0 ) { +dev_err (dev,"Failed to create sysfs attributes\n" ); + goto destroy_lpc_mec; + }return 0 ; + +destroy_lpc_mec: +cros_ec_lpc_mec_destroy (); +return ret; }static int wilco_ec_remove (struct platform_device *pdev) { +struct wilco_ec_device *ec =platform_get_drvdata (pdev); + +/* Remove sysfs attributes */ +wilco_ec_sysfs_remove (ec); +/* Teardown cros_ec interface */ cros_ec_lpc_mec_destroy ();
drivers/platform/chrome/wilco_ec/legacy.c new file +91 -0
91 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/legacy.h new file +47 -0
47 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/sysfs.c new file +66 -0
66 lines not on this page · raw message
include/linux/platform_data/wilco-ec.h +14 -0
@@ -135,4 +135,18 @@ struct wilco_ec_response {*/ int wilco_ec_mailbox (struct wilco_ec_device *ec,struct wilco_ec_message *msg); +/** +* wilco_ec_sysfs_init() - Create sysfs attributes. +* @ec: EC device. +* +* Return: 0 for success or negative error code on failure. +*/ +int wilco_ec_sysfs_init (struct wilco_ec_device *ec); + +/** +* wilco_ec_sysfs_remove() - Remove sysfs attributes. +* @ec: EC device. +*/ +void wilco_ec_sysfs_remove (struct wilco_ec_device *ec); +#endif /* WILCO_EC_H */
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Re: [PATCH v2 3/9] platform/chrome: Add sysfs attributes
Hi Nick,
Some few comments more ...
Missatge de Nick Crews <[email protected]> del dia dl., 14 de gen. 2019 a les 23:07:
Quoted 27 lines
From: Duncan Laurie <[email protected]>
Add some sample sysfs attributes for the Wilco EC that show how the mailbox interface works. "Legacy" attributes are those that existed in the EC before it was adapted to ChromeOS.
Quoted 1 line
cat /sys/bus/platform/devices/GOOG000C\:00/version
Label : 99.99.99
SVN Revision : 738ed.99
Model Number : 08;8
Build Date : 08/30/18Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Nick Crews <[email protected]>---
Changes in v2:
- Remove license boiler plate
- Remove "wilco_ec_sysfs-" docstring prefix
- Fix accidentalMakefiledeletion
- Add documentation for sysfs entries
- Change "enable ? 0 : 1" to "!enable"
- No longer override error code fromsysfs_init()
- Put attributes in the legacy file to begin with, don't move later
- Remove duplicate error messages insysfs_init()and its caller
Quoted 9 lines
.../ABI/testing/sysfs-platform-wilcoec | 26 ++++++ drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/core.c | 15 +++ drivers/platform/chrome/wilco_ec/legacy.c | 91 +++++++++++++++++++ drivers/platform/chrome/wilco_ec/legacy.h | 47 ++++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 66 ++++++++++++++ include/linux/platform_data/wilco-ec.h | 14 +++ 7 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-wilcoec
I'd like to rename this to sysfs-platform-wilco-ec (like cros-ec)
Documentation/ABI/testing/sysfs-platform-wilcoec line 3
Quoted 13 lines
create mode 100644 drivers/platform/chrome/wilco_ec/legacy.c create mode 100644 drivers/platform/chrome/wilco_ec/legacy.h create mode 100644 drivers/platform/chrome/wilco_ec/sysfs.cDocumentation/ABI/testing/sysfs-platform-wilcoec new file +3
-0@@ -0,0 +1,26 @@ +What: /sys/bus/platform/devices/GOOG000C\:00/version +Date: January 2019 +KernelVersion: 4.19
That will be probably 5.1
Quoted 4 lines
Documentation/ABI/testing/sysfs-platform-wilcoec new file +4
-0+Description: + Display Wilco Embedded Controller version info + + Output will be similar to the example below:
Documentation/ABI/testing/sysfs-platform-wilcoec line 17
Quoted 10 lines
Documentation/ABI/testing/sysfs-platform-wilcoec new file +10
-0+ Label : 95.00.06 + SVN Revision : 5960a.06 + Model Number : 08;8 + Build Date : 11/29/18 + + Although this contains multiple pieces of data in a single sysfs + attribute (inconsistent with normal sysfs conventions), + this format was chosen to be consistent with the version + attribute in /sys/class/chomeos/<device>/version +
I don't buy the reason to be inconsistent. I don't think you need to be consistent with something that is wrong and not following the conventions. Past errors should be fixed :)
I'd like to see here single values in single attributes, this will also be easier to parse from userspace point of view.
Documentation/ABI/testing/sysfs-platform-wilcoec line 26
Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-wilcoec new file +9
-0+What: /sys/bus/platform/devices/GOOG000C\:00/stealth_mode +Date: January 2019 +KernelVersion: 4.19 +Description: + Turn stealth_mode on or off on EC. Stealth mode means that the + various LEDs, the LCD backlight, and onboard speakers are turned + off and remain off even if activated from the off state. + External monitors connected to the system are not affected. + In addition Wireless devices are turned off.
Would be good to specify the valid values to write.
Quoted 214 lines
drivers/platform/chrome/wilco_ec/Makefile +1
-1@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 -wilco_ec-objs := core.o mailbox.o +wilco_ec-objs := core.o mailbox.o sysfs.o legacy.o obj-$(CONFIG_WILCO_EC) += wilco_ec.odrivers/platform/chrome/wilco_ec/core.c +15
-0@@ -64,11 +64,26 @@ static int wilco_ec_probe(struct platform_device *pdev)cros_ec_lpc_mec_init (ec->io_packet->start, ec->io_packet->start +EC_MAILBOX_DATA_SIZE ); +/* Create sysfs attributes for userspace interaction */ + ret =wilco_ec_sysfs_init (ec); +if (ret <0 ) { +dev_err (dev,"Failed to create sysfs attributes\n" ); + goto destroy_lpc_mec; + }return 0 ; + +destroy_lpc_mec: +cros_ec_lpc_mec_destroy (); +return ret; }static int wilco_ec_remove (struct platform_device *pdev) { +struct wilco_ec_device *ec =platform_get_drvdata (pdev); + +/* Remove sysfs attributes */ +wilco_ec_sysfs_remove (ec); +/* Teardown cros_ec interface */ cros_ec_lpc_mec_destroy ();drivers/platform/chrome/wilco_ec/legacy.c new file +91
-0@@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Legacy (non-Chrome-specific) sysfs attributes for Wilco EC +* +* Copyright 2018 Google LLC +*/ + +#include <linux/ctype.h> +#include <linux/device.h> +#include <linux/platform_data/wilco-ec.h> + +#include "legacy.h" + +struct ec_info { +u8 index; +const char *label; +}; + +static ssize_t wilco_ec_show_info (struct wilco_ec_device *ec,char *buf, +ssize_t count,struct ec_info *info) +{ +char result[EC_INFO_SIZE ]; +struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .command =EC_COMMAND_EC_INFO , + .request_data = &info->index, + .request_size =sizeof (info->index), + .response_data = result, + .response_size =EC_INFO_SIZE , + }; +int ret; + + ret =wilco_ec_mailbox (ec, &msg); +if (ret !=EC_INFO_SIZE ) +return scnprintf (buf + count,PAGE_SIZE - count, +"%-12s : ERROR %d\n" , info->label, ret); + +return scnprintf (buf + count,PAGE_SIZE - count, +"%-12s : %s\n" , info->label, result); +} + +ssize_t wilco_ec_version_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev); +struct ec_info wilco_ec_info[] = { + {0 ,"Label" }, + {1 ,"SVN Revision" }, + {2 ,"Model Number" }, + {3 ,"Build Date" }, + {0xff ,NULL }, + }; +struct ec_info *info = wilco_ec_info; +ssize_t c =0 ; + +for (info = wilco_ec_info; info->label; info++) + c +=wilco_ec_show_info (ec, buf, c, info); + +return c; +} + +ssize_t wilco_ec_stealth_mode_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev); +u8 param; +struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .command =EC_COMMAND_STEALTH_MODE , + .request_data = ¶m, + .request_size =sizeof (param), + }; +int ret; +bool enable; + + ret =kstrtobool (buf, &enable); +if (ret) { +dev_err (dev,"Unable to parse '%s' to bool" , buf); +return ret; + } + +/* Invert input parameter, EC expects 0=on and 1=off */ + param = !enable; + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; + +return count; +}drivers/platform/chrome/wilco_ec/legacy.h new file +47
-0@@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Legacy (non-Chrome-specific) sysfs attributes for Wilco EC +* +* Copyright 2018 Google LLC +*/ + +#ifndef WILCO_EC_LEGACY_H +#define WILCO_EC_LEGACY_H + +#include <linux/device.h> + +#define EC_COMMAND_EC_INFO 0x38 +#define EC_INFO_SIZE 9 +#define EC_COMMAND_STEALTH_MODE 0xfc + +/** +* wilco_ec_version_show() - Display Wilco Embedded Controller version info +* +* Output will be similar to the example below: +* Label : 95.00.06 +* SVN Revision : 5960a.06 +* Model Number : 08;8 +* Build Date : 11/29/18 +* +* Although this contains multiple pieces of data in a single sysfs attribute +* (inconsistent with normal sysfs conventions), this format was chosen to be +* consistent with the version attribute in ../cros_ec_sysfs.c +*/ +ssize_t wilco_ec_version_show (struct device *dev,struct device_attribute *attr, +char *buf); + +/** +* wilco_ec_stealth_mode_store() - Turn stealth_mode on or off on EC +* @dev: Device representing the EC +* @attr: The attribute in question +* @buf: Input buffer, should be parseable by kstrtobool(). Anything parsed to +* True means enable stealth mode (turn off screen, etc) +* @count: Number of bytes in input buffer +* +* Return: Number of bytes consumed from input, negative error code on failure +*/ +ssize_t wilco_ec_stealth_mode_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count); + +#endif /* WILCO_EC_LEGACY_H */ drivers/platform/chrome/wilco_ec/sysfs.c new file +17
-0@@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Sysfs attributes for Wilco Embedded Controller +* +* Copyright 2018 Google LLC +* +* The sysfs attributes appear under /sys/bus/platform/devices/GOOG000C\:00/ +* To actually learn what each attribute does, read the corresponding _show() or +* _store() function source. +*/ + +#include <linux/ctype.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/platform_device.h> +#include <linux/sysfs.h> + +#include "legacy.h"
drivers/platform/chrome/wilco_ec/sysfs.c line 27
Quoted 10 lines
drivers/platform/chrome/wilco_ec/sysfs.c new file +10
-0+ +#define WILCO_EC_ATTR_RO (_name) \ +__ATTR(_name, 0444, wilco_ec_##_name##_show, NULL) + +#define WILCO_EC_ATTR_WO (_name) \ +__ATTR(_name, 0200, NULL, wilco_ec_##_name##_store) + +#define WILCO_EC_ATTR_RW (_name) \ +__ATTR(_name, 0644, wilco_ec_##_name##_show, wilco_ec_##_name##_store) +
Why not use the already defined DEVICE_ATTR_* family instead?
Quoted 18 lines
drivers/platform/chrome/wilco_ec/sysfs.c new file +18
-0+/* Make top-level attributes, which will live inside GOOG000C:00/ */ +static struct device_attribute version_attr =WILCO_EC_ATTR_RO (version); +static struct device_attribute stealth_attr =WILCO_EC_ATTR_WO (stealth_mode); +static struct attribute *wilco_ec_toplevel_attrs[] = { + &version_attr.attr, + &stealth_attr.attr, +NULL +}; +ATTRIBUTE_GROUPS (wilco_ec_toplevel); + +/** +* wilco_ec_sysfs_init() - Initialize the sysfs directories and attributes +* @dev: The device representing the EC +* +* Creates the sysfs directory structure and populates it with all attributes. +* If there is a problem it will clean up the entire filesystem. +* +* Return 0 on success, -ENOMEM on failure creating directories or attibutes.
drivers/platform/chrome/wilco_ec/sysfs.c line 55
Quoted 10 lines
drivers/platform/chrome/wilco_ec/sysfs.c new file +10
-0+*/ +int wilco_ec_sysfs_init (struct wilco_ec_device *ec) +{ +struct device *dev = ec->dev; +int ret; + +/* add the top-level attributes */ + ret =sysfs_create_groups (&dev->kobj, wilco_ec_toplevel_groups); +if (ret) +return -ENOMEM ;
Do not overwrite the error, return ret;
Quoted 35 lines
drivers/platform/chrome/wilco_ec/sysfs.c new file +11
-0+ +return 0 ; +} + +void wilco_ec_sysfs_remove (struct wilco_ec_device *ec) +{ +struct device *dev = ec->dev; + +/* go upwards through the directory structure */ +sysfs_remove_groups (&dev->kobj, wilco_ec_toplevel_groups); +}include/linux/platform_data/wilco-ec.h +14
-1@@ -135,4 +135,18 @@ struct wilco_ec_response {*/ int wilco_ec_mailbox (struct wilco_ec_device *ec,struct wilco_ec_message *msg); +/** +* wilco_ec_sysfs_init() - Create sysfs attributes. +* @ec: EC device. +* +* Return: 0 for success or negative error code on failure. +*/ +int wilco_ec_sysfs_init (struct wilco_ec_device *ec); + +/** +* wilco_ec_sysfs_remove() - Remove sysfs attributes. +* @ec: EC device. +*/ +void wilco_ec_sysfs_remove (struct wilco_ec_device *ec); +#endif /* WILCO_EC_H */ --
Quoted 2 lines
2.20.1.97.g81188d93c3-goog
Thanks,
Enric
PATCH v2 4/9 platform/chrome: Add support for raw commands in sysfs
In reply to Nick CrewsFrom: Duncan Laurie <[email protected]>
Add a sysfs attribute that allows sending raw commands to the EC. This is useful for development and debug but should not be enabled in a production environment.
Quoted 2 lines
echo 00 f0 38 00 03 00 > /sys/bus/platform/devices/GOOG000C\:00/raw cat /sys/bus/platform/devices/GOOG000C\:00/raw
00 37 33 38 65 64 00...
---
Changes in v2:
- Add sysfs documentation
- rm duplicate EC_MAILBOX_DATA_SIZE defs
- Make docstrings follow kernel style
- Fix tags in commit msg
- Reading raw now includes ASCII translation
.../ABI/testing/sysfs-platform-wilcoec | 21 ++++ drivers/platform/chrome/wilco_ec/Kconfig | 9 ++ drivers/platform/chrome/wilco_ec/legacy.c | 99 +++++++++++++++++++ drivers/platform/chrome/wilco_ec/legacy.h | 46 +++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 6 ++ 5 files changed, 181 insertions(+)
Documentation/ABI/testing/sysfs-platform-wilcoec +21 -0
@@ -24,3 +24,24 @@ Description: off and remain off even if activated from the off state. External monitors connected to the system are not affected. In addition Wireless devices are turned off. + +What: /sys/bus/platform/devices/GOOG000C\:00/raw +Date: January 2019 +KernelVersion: 4.19 +Description: + Write and read raw mailbox commands to the EC. + + For writing: + Bytes 0-1 indicate the message type: + 00 F0 = Execute Legacy Command + 00 F2 = Read/Write NVRAM Property + Byte 2 provides the command code + Bytes 3+ consist of the data passed in the request + + Example: + // Request EC info type 3 (EC firmware build date) + $ echo 00 f0 38 00 03 00 > raw + // View the result. The decoded ASCII result "12/21/18" is + // included after the raw hex. + $ cat raw + 00 31 32 2f 32 31 2f 31 38 00 38 00 01 00 2f 00 .12/21/18.8...
drivers/platform/chrome/wilco_ec/Kconfig +9 -0
@@ -21,4 +21,13 @@ config WILCO_EC To compile this driver as a module, choose M here: the module will be called wilco_ec. +config WILCO_EC_SYSFS_RAW + bool "Enable raw access to EC via sysfs" + depends on WILCO_EC + help + If you say Y here, you get support for sending raw commands to + the Wilco EC via sysfs. These commands do not do any byte + manipulation and allow for testing arbitrary commands. This + interface is intended for debug only and is disabled by default. + endif # WILCO_EC_PLATFORM
drivers/platform/chrome/wilco_ec/legacy.c +99 -0
105 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/legacy.h +46 -0
52 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/sysfs.c +6 -0
@@ -28,9 +28,15 @@ __ATTR(_name, 0644, wilco_ec_##_name##_show, wilco_ec_##_name##_store)/* Make top-level attributes, which will live inside GOOG000C:00/ */ static struct device_attribute version_attr =WILCO_EC_ATTR_RO (version);static struct device_attribute stealth_attr =WILCO_EC_ATTR_WO (stealth_mode); +#ifdef CONFIG_WILCO_EC_SYSFS_RAW +static struct device_attribute raw_attr =WILCO_EC_ATTR_RW (raw); +#endif static struct attribute *wilco_ec_toplevel_attrs[] = { &version_attr.attr, &stealth_attr.attr, +#ifdef CONFIG_WILCO_EC_SYSFS_RAW + &raw_attr.attr, +#endifNULL };ATTRIBUTE_GROUPS (wilco_ec_toplevel);
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Re: [PATCH v2 4/9] platform/chrome: Add support for raw commands in sysfs
Hi Nick,
Missatge de Nick Crews <[email protected]> del dia dl., 14 de gen. 2019 a les 23:07:
Quoted 7 lines
From: Duncan Laurie <[email protected]>
Add a sysfs attribute that allows sending raw commands to the EC. This is useful for development and debug but should not be enabled in a production environment.
Shouldn't you use debugfs for all this stuff instead?
Quoted 259 lines
Quoted 2 lines
echo 00 f0 38 00 03 00 > /sys/bus/platform/devices/GOOG000C\:00/raw cat /sys/bus/platform/devices/GOOG000C\:00/raw
00 37 33 38 65 64 00...
Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Nick Crews <[email protected]>---
Changes in v2:
- Add sysfs documentation
- rm duplicateEC_MAILBOX_DATA_SIZEdefs
- Make docstrings follow kernel style
- Fix tags in commit msg
- Reading raw now includes ASCII translation.../ABI/testing/sysfs-platform-wilcoec | 21 ++++ drivers/platform/chrome/wilco_ec/Kconfig | 9 ++ drivers/platform/chrome/wilco_ec/legacy.c | 99 +++++++++++++++++++ drivers/platform/chrome/wilco_ec/legacy.h | 46 +++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 6 ++ 5 files changed, 181 insertions(+)Documentation/ABI/testing/sysfs-platform-wilcoec +21
-0@@ -24,3 +24,24 @@ Description: off and remain off even if activated from the off state. External monitors connected to the system are not affected. In addition Wireless devices are turned off. + +What: /sys/bus/platform/devices/GOOG000C\:00/raw +Date: January 2019 +KernelVersion: 4.19 +Description: + Write and read raw mailbox commands to the EC. + + For writing: + Bytes 0-1 indicate the message type: + 00 F0 = Execute Legacy Command + 00 F2 = Read/Write NVRAM Property + Byte 2 provides the command code + Bytes 3+ consist of the data passed in the request + + Example: + // Request EC info type 3 (EC firmware build date) + $ echo 00 f0 38 00 03 00 > raw + // View the result. The decoded ASCII result "12/21/18" is + // included after the raw hex. + $ cat raw + 00 31 32 2f 32 31 2f 31 38 00 38 00 01 00 2f 00 .12/21/18.8...drivers/platform/chrome/wilco_ec/Kconfig +9
-0@@ -21,4 +21,13 @@ config WILCO_EC To compile this driver as a module, choose M here: the module will be called wilco_ec. +config WILCO_EC_SYSFS_RAW + bool "Enable raw access to EC via sysfs" + depends on WILCO_EC + help + If you say Y here, you get support for sending raw commands to + the Wilco EC via sysfs. These commands do not do any byte + manipulation and allow for testing arbitrary commands. This + interface is intended for debug only and is disabled by default. + endif # WILCO_EC_PLATFORMdrivers/platform/chrome/wilco_ec/legacy.c +99
-0@@ -11,6 +11,105 @@#include "legacy.h" +#ifdef CONFIG_WILCO_EC_SYSFS_RAW + +/* Raw data buffer, large enough to hold extended responses */ +static size_t raw_response_size; +static u8 raw_response_data[EC_MAILBOX_DATA_SIZE_EXTENDED ]; + +ssize_t wilco_ec_raw_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev); +struct wilco_ec_message msg; +u8 raw_request_data[EC_MAILBOX_DATA_SIZE ]; +int in_offset =0 ; +int out_offset =0 ; +int ret; + +while (in_offset < count) { +char word_buf[EC_MAILBOX_DATA_SIZE ]; +u8 byte; +int start_offset = in_offset; +int end_offset; + +/* Find the start of the byte */ +while (buf[start_offset] &&isspace (buf[start_offset])) + start_offset++; +if (!buf[start_offset]) +break ; + +/* Find the start of the next byte, if any */ + end_offset = start_offset; +while (buf[end_offset] && !isspace (buf[end_offset])) + end_offset++; +if (start_offset > count || end_offset > count) +break ; +if (start_offset >EC_MAILBOX_DATA_SIZE || + end_offset >EC_MAILBOX_DATA_SIZE ) +break ; + +/* Copy to a new NULL terminated string */ +memcpy (word_buf, buf + start_offset, end_offset - start_offset); + word_buf[end_offset - start_offset] ='\0' ; + +/* Convert from hex string */ + ret =kstrtou8 (word_buf,16 , &byte); +if (ret) +break ; + +/* Fill this byte into the request buffer */ + raw_request_data[out_offset++] = byte; +if (out_offset >=EC_MAILBOX_DATA_SIZE ) +break ; + + in_offset = end_offset; + } +if (out_offset ==0 ) +return -EINVAL ; + +/* Clear response data buffer */ +memset (raw_response_data,'\0' ,EC_MAILBOX_DATA_SIZE_EXTENDED ); + + msg.type = raw_request_data[0 ] <<8 | raw_request_data[1 ]; + msg.flags =WILCO_EC_FLAG_RAW ; + msg.command = raw_request_data[2 ]; + msg.request_data = raw_request_data +3 ; + msg.request_size = out_offset -3 ; + msg.response_data = raw_response_data; + msg.response_size =EC_MAILBOX_DATA_SIZE ; + +/* Telemetry commands use extended response data */ +if (msg.type ==WILCO_EC_MSG_TELEMETRY ) { + msg.flags |=WILCO_EC_FLAG_EXTENDED_DATA ; + msg.response_size =EC_MAILBOX_DATA_SIZE_EXTENDED ; + } + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; + raw_response_size = ret; +return count; +} + +ssize_t wilco_ec_raw_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +ssize_t count =0 ; + +if (raw_response_size) { + count =hex_dump_to_buffer (raw_response_data, raw_response_size, +16 ,1 , buf,PAGE_SIZE , true); + +/* Only return response the first time it is read */ + raw_response_size =0 ; + } + +return count; +} + +#endif /* CONFIG_WILCO_EC_SYSFS_RAW */ +struct ec_info {u8 index;const char *label;drivers/platform/chrome/wilco_ec/legacy.h +46
-0@@ -14,6 +14,52 @@#define EC_INFO_SIZE 9#define EC_COMMAND_STEALTH_MODE 0xfc +#ifdef CONFIG_WILCO_EC_SYSFS_RAW + +/** +* wilco_ec_raw_store() - Write a raw command to EC, store result to view later +* @dev: Device representing the EC +* @attr: The attribute in question +* @buf: Input buffer, format explained below +* @count: Number of bytes in input buffer +* +* Bytes 0-1 indicate the message type: +* 00 F0 = Execute Legacy Command +* 00 F2 = Read/Write NVRAM Property +* Byte 2 provides the command code +* Bytes 3+ consist of the data passed in the request +* +* example: read the EC info type 3 (EC firmware build date): +* # echo 00 f0 38 00 03 00 > raw +* +* After calling this function, read the result by using raw_show() +* +* Return: Number of bytes consumed from input, negative error code on failure +*/ +ssize_t wilco_ec_raw_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count); + +/** +* wilco_ec_raw_show() - Show result from previous call to raw_store() +* @dev: Device representing the EC +* @attr: The attribute in question +* @buf: Output buffer to be filled +* +* Example usage: +* // Call raw_store(), read EC info type 3 (EC firmware build date) +* # echo 00 f0 38 00 03 00 > raw +* // Call this function, view the result. The decoded ASCII result +* // "12/21/18" is included after the raw hex. +* # cat raw +* 00 31 32 2f 32 31 2f 31 38 00 38 00 01 00 2f 00 .12/21/18.8.../. +* +* Return: Number of bytes written to output, negative error code on failure +*/ +ssize_t wilco_ec_raw_show (struct device *dev,struct device_attribute *attr, +char *buf); + +#endif /* CONFIG_WILCO_EC_SYSFS_RAW */ +/** * wilco_ec_version_show() - Display Wilco Embedded Controller version info * drivers/platform/chrome/wilco_ec/sysfs.c +6
-1@@ -28,9 +28,15 @@ __ATTR(_name, 0644, wilco_ec_##_name##_show, wilco_ec_##_name##_store)/* Make top-level attributes, which will live inside GOOG000C:00/ */ static struct device_attribute version_attr =WILCO_EC_ATTR_RO (version);static struct device_attribute stealth_attr =WILCO_EC_ATTR_WO (stealth_mode); +#ifdef CONFIG_WILCO_EC_SYSFS_RAW +static struct device_attribute raw_attr =WILCO_EC_ATTR_RW (raw); +#endif static struct attribute *wilco_ec_toplevel_attrs[] = { &version_attr.attr, &stealth_attr.attr, +#ifdef CONFIG_WILCO_EC_SYSFS_RAW + &raw_attr.attr, +#endifNULL };ATTRIBUTE_GROUPS (wilco_ec_toplevel); --2.20.1.97.g81188d93c3-goog
Re: [PATCH v2 4/9] platform/chrome: Add support for raw commands in sysfs
Hi Enric, thanks for the comments. I'll send out a new version soon, with this moved to debugfs.
Quoted 6 lines · Enric Balletbo Serra
Hi Nick,
Missatge de Nick Crews <[email protected]> del dia dl., 14 de gen. 2019 a les 23:07:
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
From: Duncan Laurie <[email protected]>
Add a sysfs attribute that allows sending raw commands to the EC. This is useful for development and debug but should not be enabled in a production environment.
Shouldn't you use debugfs for all this stuff instead?
Yes, I probably should. I've moved this all to there in the newest version.
Quoted 261 lines
Quoted 261 lines
Quoted 4 lines
echo 00 f0 38 00 03 00 > /sys/bus/platform/devices/GOOG000C\:00/raw cat /sys/bus/platform/devices/GOOG000C\:00/raw
00 37 33 38 65 64 00...
Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Nick Crews <[email protected]>---
Changes in v2:
- Add sysfs documentation
- rm duplicateEC_MAILBOX_DATA_SIZEdefs
- Make docstrings follow kernel style
- Fix tags in commit msg
- Reading raw now includes ASCII translation.../ABI/testing/sysfs-platform-wilcoec | 21 ++++ drivers/platform/chrome/wilco_ec/Kconfig | 9 ++ drivers/platform/chrome/wilco_ec/legacy.c | 99 +++++++++++++++++++ drivers/platform/chrome/wilco_ec/legacy.h | 46 +++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 6 ++ 5 files changed, 181 insertions(+)Documentation/ABI/testing/sysfs-platform-wilcoec +21
-0@@ -24,3 +24,24 @@ Description: off and remain off even if activated from the off state. External monitors connected to the system are not affected. In addition Wireless devices are turned off. + +What: /sys/bus/platform/devices/GOOG000C\:00/raw +Date: January 2019 +KernelVersion: 4.19 +Description: + Write and read raw mailbox commands to the EC. + + For writing: + Bytes 0-1 indicate the message type: + 00 F0 = Execute Legacy Command + 00 F2 = Read/Write NVRAM Property + Byte 2 provides the command code + Bytes 3+ consist of the data passed in the request + + Example: + // Request EC info type 3 (EC firmware build date) + $ echo 00 f0 38 00 03 00 > raw + // View the result. The decoded ASCII result "12/21/18" is + // included after the raw hex. + $ cat raw + 00 31 32 2f 32 31 2f 31 38 00 38 00 01 00 2f 00 .12/21/18.8...drivers/platform/chrome/wilco_ec/Kconfig +9
-0@@ -21,4 +21,13 @@ config WILCO_EC To compile this driver as a module, choose M here: the module will be called wilco_ec. +config WILCO_EC_SYSFS_RAW + bool "Enable raw access to EC via sysfs" + depends on WILCO_EC + help + If you say Y here, you get support for sending raw commands to + the Wilco EC via sysfs. These commands do not do any byte + manipulation and allow for testing arbitrary commands. This + interface is intended for debug only and is disabled by default. + endif # WILCO_EC_PLATFORMdrivers/platform/chrome/wilco_ec/legacy.c +99
-0@@ -11,6 +11,105 @@#include "legacy.h" +#ifdef CONFIG_WILCO_EC_SYSFS_RAW + +/* Raw data buffer, large enough to hold extended responses */ +static size_t raw_response_size; +static u8 raw_response_data[EC_MAILBOX_DATA_SIZE_EXTENDED ]; + +ssize_t wilco_ec_raw_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev); +struct wilco_ec_message msg; +u8 raw_request_data[EC_MAILBOX_DATA_SIZE ]; +int in_offset =0 ; +int out_offset =0 ; +int ret; + +while (in_offset < count) { +char word_buf[EC_MAILBOX_DATA_SIZE ]; +u8 byte; +int start_offset = in_offset; +int end_offset; + +/* Find the start of the byte */ +while (buf[start_offset] &&isspace (buf[start_offset])) + start_offset++; +if (!buf[start_offset]) +break ; + +/* Find the start of the next byte, if any */ + end_offset = start_offset; +while (buf[end_offset] && !isspace (buf[end_offset])) + end_offset++; +if (start_offset > count || end_offset > count) +break ; +if (start_offset >EC_MAILBOX_DATA_SIZE || + end_offset >EC_MAILBOX_DATA_SIZE ) +break ; + +/* Copy to a new NULL terminated string */ +memcpy (word_buf, buf + start_offset, end_offset - start_offset); + word_buf[end_offset - start_offset] ='\0' ; + +/* Convert from hex string */ + ret =kstrtou8 (word_buf,16 , &byte); +if (ret) +break ; + +/* Fill this byte into the request buffer */ + raw_request_data[out_offset++] = byte; +if (out_offset >=EC_MAILBOX_DATA_SIZE ) +break ; + + in_offset = end_offset; + } +if (out_offset ==0 ) +return -EINVAL ; + +/* Clear response data buffer */ +memset (raw_response_data,'\0' ,EC_MAILBOX_DATA_SIZE_EXTENDED ); + + msg.type = raw_request_data[0 ] <<8 | raw_request_data[1 ]; + msg.flags =WILCO_EC_FLAG_RAW ; + msg.command = raw_request_data[2 ]; + msg.request_data = raw_request_data +3 ; + msg.request_size = out_offset -3 ; + msg.response_data = raw_response_data; + msg.response_size =EC_MAILBOX_DATA_SIZE ; + +/* Telemetry commands use extended response data */ +if (msg.type ==WILCO_EC_MSG_TELEMETRY ) { + msg.flags |=WILCO_EC_FLAG_EXTENDED_DATA ; + msg.response_size =EC_MAILBOX_DATA_SIZE_EXTENDED ; + } + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; + raw_response_size = ret; +return count; +} + +ssize_t wilco_ec_raw_show (struct device *dev,struct device_attribute *attr, +char *buf) +{ +ssize_t count =0 ; + +if (raw_response_size) { + count =hex_dump_to_buffer (raw_response_data, raw_response_size, +16 ,1 , buf,PAGE_SIZE , true); + +/* Only return response the first time it is read */ + raw_response_size =0 ; + } + +return count; +} + +#endif /* CONFIG_WILCO_EC_SYSFS_RAW */ +struct ec_info {u8 index;const char *label;drivers/platform/chrome/wilco_ec/legacy.h +46
-0@@ -14,6 +14,52 @@#define EC_INFO_SIZE 9#define EC_COMMAND_STEALTH_MODE 0xfc +#ifdef CONFIG_WILCO_EC_SYSFS_RAW + +/** +* wilco_ec_raw_store() - Write a raw command to EC, store result to view later +* @dev: Device representing the EC +* @attr: The attribute in question +* @buf: Input buffer, format explained below +* @count: Number of bytes in input buffer +* +* Bytes 0-1 indicate the message type: +* 00 F0 = Execute Legacy Command +* 00 F2 = Read/Write NVRAM Property +* Byte 2 provides the command code +* Bytes 3+ consist of the data passed in the request +* +* example: read the EC info type 3 (EC firmware build date): +* # echo 00 f0 38 00 03 00 > raw +* +* After calling this function, read the result by using raw_show() +* +* Return: Number of bytes consumed from input, negative error code on failure +*/ +ssize_t wilco_ec_raw_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count); + +/** +* wilco_ec_raw_show() - Show result from previous call to raw_store() +* @dev: Device representing the EC +* @attr: The attribute in question +* @buf: Output buffer to be filled +* +* Example usage: +* // Call raw_store(), read EC info type 3 (EC firmware build date) +* # echo 00 f0 38 00 03 00 > raw +* // Call this function, view the result. The decoded ASCII result +* // "12/21/18" is included after the raw hex. +* # cat raw +* 00 31 32 2f 32 31 2f 31 38 00 38 00 01 00 2f 00 .12/21/18.8.../. +* +* Return: Number of bytes written to output, negative error code on failure +*/ +ssize_t wilco_ec_raw_show (struct device *dev,struct device_attribute *attr, +char *buf); + +#endif /* CONFIG_WILCO_EC_SYSFS_RAW */ +/** * wilco_ec_version_show() - Display Wilco Embedded Controller version info * drivers/platform/chrome/wilco_ec/sysfs.c +6
-1@@ -28,9 +28,15 @@ __ATTR(_name, 0644, wilco_ec_##_name##_show, wilco_ec_##_name##_store)/* Make top-level attributes, which will live inside GOOG000C:00/ */ static struct device_attribute version_attr =WILCO_EC_ATTR_RO (version);static struct device_attribute stealth_attr =WILCO_EC_ATTR_WO (stealth_mode); +#ifdef CONFIG_WILCO_EC_SYSFS_RAW +static struct device_attribute raw_attr =WILCO_EC_ATTR_RW (raw); +#endif static struct attribute *wilco_ec_toplevel_attrs[] = { &version_attr.attr, &stealth_attr.attr, +#ifdef CONFIG_WILCO_EC_SYSFS_RAW + &raw_attr.attr, +#endifNULL };ATTRIBUTE_GROUPS (wilco_ec_toplevel); --2.20.1.97.g81188d93c3-goog
PATCH v2 5/9 platform/chrome: rtc: Add RTC driver for Wilco EC
In reply to Nick CrewsFrom: Duncan Laurie <[email protected]>
This Embedded Controller has an internal RTC that is exposed as a standard RTC class driver with read/write functionality.
The driver is added to the drivers/rtc/ so that the maintainer of that directory will be able to comment on this change, as that maintainer is the expert on this system. In addition, the driver code is called indirectly after a corresponding device is registered from core.c, as opposed to core.c registering the driver callbacks directly.
Quoted 1 line
hwclock --show --rtc
/dev/rtc1
2007-12-31 16:01:20.460959-08:00
Quoted 2 lines
hwclock --systohc --rtc
/dev/rtc1
hwclock --show --rtc/dev/rtc1
2018-11-29 17:08:00.780793-08:00
---
Changes in v2:
- rm license boiler plate
- rm "wilco_ec_rtc -" prefix in docstring
- Make rtc driver its own module within the drivers/rtc/ directory
- Register a rtc device from core.c that is picked up by this driver
- rm unused rtc_sync() function
drivers/platform/chrome/wilco_ec/core.c | 18 +++ drivers/rtc/Kconfig | 11 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-wilco-ec.c | 178 ++++++++++++++++++++++++ 4 files changed, 208 insertions(+) create mode 100644 drivers/rtc/rtc-wilco-ec.c
drivers/platform/chrome/wilco_ec/core.c +18 -0
@@ -37,6 +37,7 @@ static int wilco_ec_probe(struct platform_device *pdev) {struct device *dev = &pdev->dev;struct wilco_ec_device *ec; +struct platform_device *child_pdev;int ret; ec =devm_kzalloc (dev,sizeof (*ec),GFP_KERNEL );
@@ -70,8 +71,25 @@ static int wilco_ec_probe(struct platform_device *pdev)dev_err (dev,"Failed to create sysfs attributes\n" ); goto destroy_lpc_mec; } + +/* +* Register a RTC platform device that will get picked up by the RTC +* subsystem. This platform device will get freed when its parent device +* dev is unregistered. +*/ + child_pdev =platform_device_register_data (dev,"rtc-wilco-ec" , +PLATFORM_DEVID_AUTO , +NULL ,0 ); +if (IS_ERR (child_pdev)) { +dev_err (dev,"Failed to create RTC platform device\n" ); + ret =PTR_ERR (child_pdev); + goto remove_sysfs; + } +return 0 ; +remove_sysfs: +wilco_ec_sysfs_remove (ec); destroy_lpc_mec:cros_ec_lpc_mec_destroy ();return ret;
drivers/rtc/Kconfig +11 -0
@@ -1814,4 +1814,15 @@ config RTC_DRV_GOLDFISH Goldfish is a code name for the virtual platform developed by Google for Android emulation. +config RTC_DRV_WILCO_EC + tristate "Wilco EC RTC" + depends on WILCO_EC + default m + help + If you say yes here, you get read/write support for the Real Time + Clock on the Wilco Embedded Controller (Wilco is a kind of Chromebook) + + This can also be built as a module. If so, the module will + be named "rtc_wilco_ec". + endif # RTC_CLASS
drivers/rtc/Makefile +1 -0
@@ -172,6 +172,7 @@ obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o obj-$(CONFIG_RTC_DRV_VRTC) += rtc-mrst.o obj-$(CONFIG_RTC_DRV_VT8500) += rtc-vt8500.o +obj-$(CONFIG_RTC_DRV_WILCO_EC) += rtc-wilco-ec.o obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
drivers/rtc/rtc-wilco-ec.c new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
2.20.1.97.g81188d93c3-goog
Alexandre Belloni
maintainerRe: [PATCH v2 5/9] platform/chrome: rtc: Add RTC driver for Wilco EC
Hello,
Quoted 16 lines · Nick Crews
drivers/rtc/rtc-wilco-ec.c new file +10
-0@@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* RTC interface for Wilco Embedded Controller with R/W abilities +* +* Copyright 2018 Google LLC +* +* The corresponding platform device is typically registered in +* drivers/platform/chrome/wilco_ec/core.c +*/ +
drivers/rtc/rtc-wilco-ec.c line 20
Quoted 10 lines
drivers/rtc/rtc-wilco-ec.c new file +10
-0+#include <linux/bcd.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/rtc.h> +#include <linux/timekeeping.h> + +#define DRV_NAME "rtc-wilco-ec"
Please get rid of that define.
Quoted 19 lines
drivers/rtc/rtc-wilco-ec.c new file +19
-0+int wilco_ec_rtc_read (struct device *dev,struct rtc_time *tm) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev->parent); +u8 param =EC_CMOS_TOD_READ ; +struct ec_rtc_read rtc; +struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .flags =WILCO_EC_FLAG_RAW_RESPONSE , + .command =EC_COMMAND_CMOS , + .request_data = ¶m, + .request_size =sizeof (param), + .response_data = &rtc, + .response_size =sizeof (rtc), + }; +struct rtc_time calc_tm; +unsigned long time; +int ret; + + ret =wilco_ec_mailbox (ec, &msg);
drivers/rtc/rtc-wilco-ec.c line 102
Quoted 10 lines
drivers/rtc/rtc-wilco-ec.c new file +10
-0+if (ret <0 ) +return ret; + + tm->tm_sec = rtc.second; + tm->tm_min = rtc.minute; + tm->tm_hour = rtc.hour; + tm->tm_mday = rtc.day; +/* +* The RTC stores the month value as 1-12 but the kernel expects 0-11, +* so ensure invalid/zero month value from RTC is not converted to -1.
I'm pretty sure this is not necessary and will certainly make the core think the date is valid when it has obviously been corrupted.
drivers/rtc/rtc-wilco-ec.c line 111
Quoted 9 lines
drivers/rtc/rtc-wilco-ec.c new file +9
-0+*/ + tm->tm_mon = rtc.month ? rtc.month -1 :0 ; + tm->tm_year = rtc.year + (rtc.century *100 ) -1900 ; + tm->tm_yday =rtc_year_days (tm->tm_mday, tm->tm_mon, tm->tm_year); + +/* Compute day of week */ +rtc_tm_to_time (tm, &time); +rtc_time_to_tm (time, &calc_tm); + tm->tm_wday = calc_tm.tm_wday;
Do you really need an accurate wday? There are no userspace applications that I know of that care and converting back and forth is quite expensive.
Quoted 8 lines
drivers/rtc/rtc-wilco-ec.c new file +8
-0+ +return 0 ; +} + +int wilco_ec_rtc_write (struct device *dev,struct rtc_time *tm) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev->parent); +struct ec_rtc_write rtc;
drivers/rtc/rtc-wilco-ec.c line 129
Quoted 10 lines
drivers/rtc/rtc-wilco-ec.c new file +10
-0+struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .flags =WILCO_EC_FLAG_RAW_RESPONSE , + .command =EC_COMMAND_CMOS , + .request_data = &rtc, + .request_size =sizeof (rtc), + }; +int year = tm->tm_year +1900 ; +/* Convert from 0=Sunday to 0=Saturday for the EC */ +int wday = tm->tm_wday ==6 ?0 : tm->tm_wday +1 ;
I'm not sure how useful it is to set an accurate wday when the RTC is not able to give it back.
Quoted 20 lines
drivers/rtc/rtc-wilco-ec.c new file +20
-0+int ret; + + rtc.param =EC_CMOS_TOD_WRITE ; + rtc.century =bin2bcd (year /100 ); + rtc.year =bin2bcd (year %100 ); + rtc.month =bin2bcd (tm->tm_mon +1 ); + rtc.day =bin2bcd (tm->tm_mday); + rtc.hour =bin2bcd (tm->tm_hour); + rtc.minute =bin2bcd (tm->tm_min); + rtc.second =bin2bcd (tm->tm_sec); + rtc.weekday =bin2bcd (wday); + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; + +return 0 ; +} + +static const struct rtc_class_ops wilco_ec_rtc_ops = {
drivers/rtc/rtc-wilco-ec.c line 159
Quoted 10 lines
drivers/rtc/rtc-wilco-ec.c new file +10
-0+ .read_time = wilco_ec_rtc_read, + .set_time = wilco_ec_rtc_write, +}; + +static int wilco_ec_rtc_probe (struct platform_device *pdev) +{ +struct rtc_device *rtc =devm_rtc_device_register (&pdev->dev, +DRV_NAME , + &wilco_ec_rtc_ops, +THIS_MODULE );
Please use devm_rtc_allocate_device() and set rtc->range_min and rtc->range_max before registering with rtc_register_device().
Quoted 22 lines
drivers/rtc/rtc-wilco-ec.c new file +19
-0+if (IS_ERR (rtc)) +return PTR_ERR (rtc); + +return 0 ; +} + +static struct platform_driver wilco_ec_rtc_driver = { + .driver = { + .name =DRV_NAME , + }, + .probe = wilco_ec_rtc_probe, +}; + +module_platform_driver (wilco_ec_rtc_driver); + +MODULE_ALIAS ("platform:" DRV_NAME ); +MODULE_AUTHOR ("Nick Crews <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Wilco EC RTC driver" );Signature · 1 line
2.20.1.97.g81188d93c3-goog
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v2 5/9] platform/chrome: rtc: Add RTC driver for Wilco EC
Thanks for the comments Alexandre, I've responded to your comments inline. I'll send out a new version of the patch in a bit
Quoted 24 lines · On Mon, Jan 14, 2019 at 3:26 PM -700 Alexandre Belloni wrote:
Hello,
Quoted 20 lines · Nick Crews
drivers/rtc/rtc-wilco-ec.c new file +14
-0@@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* RTC interface for Wilco Embedded Controller with R/W abilities +* +* Copyright 2018 Google LLC +* +* The corresponding platform device is typically registered in +* drivers/platform/chrome/wilco_ec/core.c +*/ + +#include <linux/bcd.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/module.h>
Quoted 8 lines
drivers/rtc/rtc-wilco-ec.c line 20
Quoted 6 lines
drivers/rtc/rtc-wilco-ec.c new file +6
-0+#include <linux/platform_device.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/rtc.h> +#include <linux/timekeeping.h> + +#define DRV_NAME "rtc-wilco-ec"Please get rid of that define.
Done in the new patch.
Quoted 25 lines
Quoted 25 lines
drivers/rtc/rtc-wilco-ec.c new file +24
-0+int wilco_ec_rtc_read (struct device *dev,struct rtc_time *tm) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev->parent); +u8 param =EC_CMOS_TOD_READ ; +struct ec_rtc_read rtc; +struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .flags =WILCO_EC_FLAG_RAW_RESPONSE , + .command =EC_COMMAND_CMOS , + .request_data = ¶m, + .request_size =sizeof (param), + .response_data = &rtc, + .response_size =sizeof (rtc), + }; +struct rtc_time calc_tm; +unsigned long time; +int ret; + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; + + tm->tm_sec = rtc.second; + tm->tm_min = rtc.minute;
Quoted 8 lines
drivers/rtc/rtc-wilco-ec.c line 102
Quoted 5 lines
drivers/rtc/rtc-wilco-ec.c new file +5
-0+ tm->tm_hour = rtc.hour; + tm->tm_mday = rtc.day; +/* +* The RTC stores the month value as 1-12 but the kernel expects 0-11, +* so ensure invalid/zero month value from RTC is not converted to -1. I'm pretty sure this is not necessary and will certainly make the core think the date is valid when it has obviously been corrupted.
OK, I'll get rid of the safety check and just do rtc.month -1.
Quoted 11 lines
drivers/rtc/rtc-wilco-ec.c line 111
Quoted 10 lines
drivers/rtc/rtc-wilco-ec.c new file +9
-0+*/ + tm->tm_mon = rtc.month ? rtc.month -1 :0 ; + tm->tm_year = rtc.year + (rtc.century *100 ) -1900 ; + tm->tm_yday =rtc_year_days (tm->tm_mday, tm->tm_mon, tm->tm_year); + +/* Compute day of week */ +rtc_tm_to_time (tm, &time); +rtc_time_to_tm (time, &calc_tm); + tm->tm_wday = calc_tm.tm_wday;
Quoted 4 lines
Do you really need an accurate wday? There are no userspace applications that I know of that care and converting back and forth is quite expensive.
We probably don't, this RTC should only get used for very specific purposes, and any userspace programs should be using a different RTC.
Quoted 13 lines
Quoted 13 lines
drivers/rtc/rtc-wilco-ec.c new file +13
-0+ +return 0 ; +} + +int wilco_ec_rtc_write (struct device *dev,struct rtc_time *tm) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev->parent); +struct ec_rtc_write rtc; +struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .flags =WILCO_EC_FLAG_RAW_RESPONSE , + .command =EC_COMMAND_CMOS , + .request_data = &rtc,
Quoted 9 lines
drivers/rtc/rtc-wilco-ec.c line 129
Quoted 5 lines
drivers/rtc/rtc-wilco-ec.c new file +5
-0+ .request_size = sizeof(rtc), + }; +int year = tm->tm_year +1900 ; +/* Convert from 0=Sunday to 0=Saturday for the EC */ +int wday = tm->tm_wday ==6 ?0 : tm->tm_wday +1 ;I'm not sure how useful it is to set an accurate wday when the RTC is not able to give it back.
This is actually needed. The RTC on the EC controls battery charging schedules and thus needs to know the day of the week, and this is the way to do this.
Quoted 25 lines
Quoted 25 lines
drivers/rtc/rtc-wilco-ec.c new file +25
-0+int ret; + + rtc.param =EC_CMOS_TOD_WRITE ; + rtc.century =bin2bcd (year /100 ); + rtc.year =bin2bcd (year %100 ); + rtc.month =bin2bcd (tm->tm_mon +1 ); + rtc.day =bin2bcd (tm->tm_mday); + rtc.hour =bin2bcd (tm->tm_hour); + rtc.minute =bin2bcd (tm->tm_min); + rtc.second =bin2bcd (tm->tm_sec); + rtc.weekday =bin2bcd (wday); + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; + +return 0 ; +} + +static const struct rtc_class_ops wilco_ec_rtc_ops = { + .read_time = wilco_ec_rtc_read, + .set_time = wilco_ec_rtc_write, +}; + +static int wilco_ec_rtc_probe (struct platform_device *pdev)
Quoted 9 lines
drivers/rtc/rtc-wilco-ec.c line 159
Quoted 5 lines
drivers/rtc/rtc-wilco-ec.c new file +5
-0+{ +struct rtc_device *rtc =devm_rtc_device_register (&pdev->dev, +DRV_NAME , + &wilco_ec_rtc_ops, +THIS_MODULE );Please use
devm_rtc_allocate_device()and setrtc->range_minandrtc->range_maxbefore registering withrtc_register_device().
Thanks, will do this.
Quoted 19 lines
Quoted 19 lines
drivers/rtc/rtc-wilco-ec.c new file +19
-0+if (IS_ERR (rtc)) +return PTR_ERR (rtc); + +return 0 ; +} + +static struct platform_driver wilco_ec_rtc_driver = { + .driver = { + .name =DRV_NAME , + }, + .probe = wilco_ec_rtc_probe, +}; + +module_platform_driver (wilco_ec_rtc_driver); + +MODULE_ALIAS ("platform:" DRV_NAME ); +MODULE_AUTHOR ("Nick Crews <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Wilco EC RTC driver" );
Quoted 8 lines
Quoted 3 lines
--
2.20.1.97.g81188d93c3-goog--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Nick Crews
[email protected]
Re: [PATCH v2 5/9] platform/chrome: rtc: Add RTC driver for Wilco EC
In reply to Alexandre BelloniHi Alexandre, thanks for taking the time to review this. I've responded to your comments inline below. I'll send out a new version of this patch soon.
Quoted 24 lines · Alexandre Belloni
Hello,
Quoted 20 lines · Nick Crews
drivers/rtc/rtc-wilco-ec.c new file +14
-0@@ -0,0 +1,178 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* RTC interface for Wilco Embedded Controller with R/W abilities +* +* Copyright 2018 Google LLC +* +* The corresponding platform device is typically registered in +* drivers/platform/chrome/wilco_ec/core.c +*/ + +#include <linux/bcd.h> +#include <linux/err.h> +#include <linux/kernel.h> +#include <linux/module.h>
Quoted 9 lines
drivers/rtc/rtc-wilco-ec.c line 20
Quoted 6 lines
drivers/rtc/rtc-wilco-ec.c new file +6
-0+#include <linux/platform_device.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/rtc.h> +#include <linux/timekeeping.h> + +#define DRV_NAME "rtc-wilco-ec"Please get rid of that define.
Done.
Quoted 24 lines
Quoted 24 lines
drivers/rtc/rtc-wilco-ec.c new file +24
-0+int wilco_ec_rtc_read (struct device *dev,struct rtc_time *tm) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev->parent); +u8 param =EC_CMOS_TOD_READ ; +struct ec_rtc_read rtc; +struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .flags =WILCO_EC_FLAG_RAW_RESPONSE , + .command =EC_COMMAND_CMOS , + .request_data = ¶m, + .request_size =sizeof (param), + .response_data = &rtc, + .response_size =sizeof (rtc), + }; +struct rtc_time calc_tm; +unsigned long time; +int ret; + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; + + tm->tm_sec = rtc.second; + tm->tm_min = rtc.minute;
Quoted 8 lines
drivers/rtc/rtc-wilco-ec.c line 102
Quoted 5 lines
drivers/rtc/rtc-wilco-ec.c new file +5
-0+ tm->tm_hour = rtc.hour; + tm->tm_mday = rtc.day; +/* +* The RTC stores the month value as 1-12 but the kernel expects 0-11, +* so ensure invalid/zero month value from RTC is not converted to -1. I'm pretty sure this is not necessary and will certainly make the core think the date is valid when it has obviously been corrupted.
Done, I'll just use rtc.month - 1 always.
Quoted 11 lines
drivers/rtc/rtc-wilco-ec.c line 111
Quoted 10 lines
drivers/rtc/rtc-wilco-ec.c new file +9
-0+*/ + tm->tm_mon = rtc.month ? rtc.month -1 :0 ; + tm->tm_year = rtc.year + (rtc.century *100 ) -1900 ; + tm->tm_yday =rtc_year_days (tm->tm_mday, tm->tm_mon, tm->tm_year); + +/* Compute day of week */ +rtc_tm_to_time (tm, &time); +rtc_time_to_tm (time, &calc_tm); + tm->tm_wday = calc_tm.tm_wday;
Quoted 3 lines
Do you really need an accurate wday? There are no userspace applications that I know of that care and converting back and forth is quite expensive.
No, I'm not sure we do need this. Removing it.
Quoted 14 lines
Quoted 14 lines
drivers/rtc/rtc-wilco-ec.c new file +13
-0+ +return 0 ; +} + +int wilco_ec_rtc_write (struct device *dev,struct rtc_time *tm) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev->parent); +struct ec_rtc_write rtc; +struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .flags =WILCO_EC_FLAG_RAW_RESPONSE , + .command =EC_COMMAND_CMOS , + .request_data = &rtc,
Quoted 8 lines
drivers/rtc/rtc-wilco-ec.c line 129
Quoted 5 lines
drivers/rtc/rtc-wilco-ec.c new file +5
-0+ .request_size = sizeof(rtc), + }; +int year = tm->tm_year +1900 ; +/* Convert from 0=Sunday to 0=Saturday for the EC */ +int wday = tm->tm_wday ==6 ?0 : tm->tm_wday +1 ;I'm not sure how useful it is to set an accurate wday when the RTC is not able to give it back.
This is actually needed. The RTC controls battery charging schedule, which varies by the day of the week, and it requires this to be set.
Quoted 26 lines
Quoted 26 lines
drivers/rtc/rtc-wilco-ec.c new file +25
-0+int ret; + + rtc.param =EC_CMOS_TOD_WRITE ; + rtc.century =bin2bcd (year /100 ); + rtc.year =bin2bcd (year %100 ); + rtc.month =bin2bcd (tm->tm_mon +1 ); + rtc.day =bin2bcd (tm->tm_mday); + rtc.hour =bin2bcd (tm->tm_hour); + rtc.minute =bin2bcd (tm->tm_min); + rtc.second =bin2bcd (tm->tm_sec); + rtc.weekday =bin2bcd (wday); + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; + +return 0 ; +} + +static const struct rtc_class_ops wilco_ec_rtc_ops = { + .read_time = wilco_ec_rtc_read, + .set_time = wilco_ec_rtc_write, +}; + +static int wilco_ec_rtc_probe (struct platform_device *pdev)
Quoted 8 lines
drivers/rtc/rtc-wilco-ec.c line 159
Quoted 5 lines
drivers/rtc/rtc-wilco-ec.c new file +5
-0+{ +struct rtc_device *rtc =devm_rtc_device_register (&pdev->dev, +DRV_NAME , + &wilco_ec_rtc_ops, +THIS_MODULE );Please use
devm_rtc_allocate_device()and setrtc->range_minandrtc->range_maxbefore registering withrtc_register_device().
Done.
Quoted 20 lines
Quoted 20 lines
drivers/rtc/rtc-wilco-ec.c new file +19
-0+if (IS_ERR (rtc)) +return PTR_ERR (rtc); + +return 0 ; +} + +static struct platform_driver wilco_ec_rtc_driver = { + .driver = { + .name =DRV_NAME , + }, + .probe = wilco_ec_rtc_probe, +}; + +module_platform_driver (wilco_ec_rtc_driver); + +MODULE_ALIAS ("platform:" DRV_NAME ); +MODULE_AUTHOR ("Nick Crews <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Wilco EC RTC driver" );
Quoted 8 lines
Quoted 3 lines
--
2.20.1.97.g81188d93c3-goog--
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Cheers,
Nick Crews
PATCH v2 6/9 platform/chrome: Add event handling
In reply to Nick CrewsFrom: Duncan Laurie <[email protected]>
The Wilco Embedded Controller can return extended events that are not handled by standard ACPI objects. These events can include hotkeys which map to standard functions like brightness controls, or information about EC controlled features like the charger or battery.
These events are triggered with an ACPI Notify(0x90) and the event data buffer is read through an ACPI method provided by the BIOS which reads the event buffer from EC RAM.
These events are then processed, with hotkey events being sent to the input subsystem and other events put into a queue which can be read by a userspace daemon via a sysfs attribute.
Quoted 1 line
evtest
/dev/input/event6
Input driver version is 1.0.1
Input device ID: bus 0x19 vendor 0x0 product 0x0 version 0x0 Input device name: "Wilco EC hotkeys"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 224 (KEY_BRIGHTNESSDOWN)
Event code 225 (KEY_BRIGHTNESSUP)
Event code 240 (KEY_UNKNOWN)
Event type 4 (EV_MSC)
Event code 4 (MSC_SCAN)
Properties:
Testing ... (interrupt to exit)
Event: type 4 (EV_MSC), code 4 (MSC_SCAN), value 57
Event: type 1 (EV_KEY), code 224 (KEY_BRIGHTNESSDOWN), value 1
Event: -------------- SYN_REPORT ------------
Event: type 1 (EV_KEY), code 224 (KEY_BRIGHTNESSDOWN), value 0
Event: -------------- SYN_REPORT ------------
Event: type 4 (EV_MSC), code 4 (MSC_SCAN), value 58
Event: type 1 (EV_KEY), code 225 (KEY_BRIGHTNESSUP), value 1
Event: -------------- SYN_REPORT ------------
Event: type 1 (EV_KEY), code 225 (KEY_BRIGHTNESSUP), value 0
Event: -------------- SYN_REPORT ------------
---
Changes in v2:
- rm "wilco_ec_event -" prefix from docstring
- rm license boiler plate
- Add sysfs directory documentation
- Fix cosmetics
- Remove duplicate error messages
drivers/platform/chrome/wilco_ec/Makefile | 3 +- drivers/platform/chrome/wilco_ec/core.c | 14 +- drivers/platform/chrome/wilco_ec/event.c | 347 ++++++++++++++++++++++ include/linux/platform_data/wilco-ec.h | 34 +++ 4 files changed, 396 insertions(+), 2 deletions(-) create mode 100644 drivers/platform/chrome/wilco_ec/event.c
drivers/platform/chrome/wilco_ec/Makefile +2 -1
@@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -wilco_ec-objs := core.o mailbox.o sysfs.o legacy.o +wilco_ec-objs := core.o mailbox.o sysfs.o legacy.o \ + event.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o
drivers/platform/chrome/wilco_ec/core.c +13 -1
@@ -72,6 +72,13 @@ static int wilco_ec_probe(struct platform_device *pdev) goto destroy_lpc_mec; } +/* Prepare to handle events */ + ret =wilco_ec_event_init (ec); +if (ret <0 ) { +dev_err (dev,"Failed to setup event handling\n" ); + goto remove_sysfs; + } +/* * Register a RTC platform device that will get picked up by the RTC * subsystem. This platform device will get freed when its parent device
@@ -83,11 +90,13 @@ static int wilco_ec_probe(struct platform_device *pdev)if (IS_ERR (child_pdev)) {dev_err (dev,"Failed to create RTC platform device\n" ); ret =PTR_ERR (child_pdev); - goto remove_sysfs; + goto remove_events; }return 0 ; +remove_events: +wilco_ec_event_remove (ec); remove_sysfs:wilco_ec_sysfs_remove (ec); destroy_lpc_mec:
@@ -99,6 +108,9 @@ static int wilco_ec_remove(struct platform_device *pdev) {struct wilco_ec_device *ec =platform_get_drvdata (pdev); +/* Stop handling EC events */ +wilco_ec_event_remove (ec); +/* Remove sysfs attributes */ wilco_ec_sysfs_remove (ec);
drivers/platform/chrome/wilco_ec/event.c new file +347 -0
347 lines not on this page · raw message
include/linux/platform_data/wilco-ec.h +34 -0
@@ -9,7 +9,9 @@#define WILCO_EC_H #include <linux/device.h> +#include <linux/input.h> #include <linux/kernel.h> +#include <linux/list.h> #define WILCO_EC_FLAG_NO_RESPONSE BIT(0)/* EC does not respond */ #define WILCO_EC_FLAG_EXTENDED_DATA BIT(1)/* EC returns 256 data bytes */
@@ -24,6 +26,22 @@/* Extended commands have 256 bytes of response data */ #define EC_MAILBOX_DATA_SIZE_EXTENDED 256 +/** +* struct wilco_ec_event - EC extended events. +* @lock: Mutex to guard the list of events. +* @list: Queue of EC events to be provided to userspace. +* @attr: Sysfs attribute for userspace to read events. +* @count: Count of events in the queue. +* @input: Input device for hotkey events. +*/ +struct wilco_ec_event { +struct mutex lock; +struct list_head list; +struct bin_attribute attr; +size_t count; +struct input_dev *input; +}; +/** * struct wilco_ec_device - Wilco Embedded Controller handle. * @dev: Device handle.
@@ -34,6 +52,7 @@* @data_buffer: Buffer used for EC communication. The same buffer * is used to hold the request and the response. * @data_size: Size of the data buffer used for EC communication. +* @event: EC extended event handler. */ struct wilco_ec_device {struct device *dev;
@@ -43,6 +62,7 @@ struct wilco_ec_device {struct resource *io_packet;void *data_buffer;size_t data_size; +struct wilco_ec_event event; };/**
@@ -149,4 +169,18 @@ int wilco_ec_sysfs_init(struct wilco_ec_device *ec);*/ void wilco_ec_sysfs_remove (struct wilco_ec_device *ec); +/** +* wilco_ec_event_init() - Prepare to handle EC events. +* @ec: EC device. +* +* Return: 0 for success or negative error code on failure. +*/ +int wilco_ec_event_init (struct wilco_ec_device *ec); + +/** +* wilco_ec_event_remove() - Remove EC event handler. +* @ec: EC device. +*/ +void wilco_ec_event_remove (struct wilco_ec_device *ec); +#endif /* WILCO_EC_H */
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH v2 7/9 platform/chrome: Add EC properties
In reply to Nick CrewsA Property is typically a data item that is stored to NVRAM. Each of these data items has an index associated with it known as the Property ID (PID). The Property ID is used by the system BIOS (and EC) to refer to the Property. Properties may have variable lengths. Many features are implemented primarily by EC Firmware with system BIOS just supporting user configuration via BIOS SETUP and/or SMBIOS changes. In order to implement many of these types of features the user configuration information is saved to and retrieved from the EC. The EC stores this configuration information to NVRAM and then can use it while the system BIOS is not running or during early boot. Although this is a typical scenario there may be other reasons to store information in the EC NVRAM instead of the System NVRAM. Most of the property services do not have a valid failure condition, so this field can be ignored. For items that are write once, a failure is returned when a second write is attempted.
Add a get and set interface for EC properties. properties live within the "properties" directory. Most of the added properties are boolean, but this also provides the interface for non-boolean properties, which will be used late for scheduling power routines.
The wilco_ec_sysfs_util.h stuff will be used for
future attributes as well.
Quoted 2 lines
cd /sys/bus/platform/devices/GOOG000C\:00/
echo 0 > properties/global_mic_mute_led
[mic mute led on keyboard turns off]
Quoted 1 line
cat
0
Quoted 1 line
echo 1 > properties/global_mic_mute_led
[mic mute led on keyboard turns on]
Quoted 1 line
cat properties/global_mic_mute_led
1
Quoted 1 line
cat properties/wireless_sw_wlan
cat: wireless_sw_wlan: Permission denied
[Good, that is supposed to be write-only]
Quoted 1 line
echo 0 > properties/wireless_sw_wlan
---
Changes in v2:
- rm license boiler plate
- rm "wilco_ec_properties -" prefix from docstring
- Add documentation
.../ABI/testing/sysfs-platform-wilcoec | 48 +++ drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/properties.c | 344 ++++++++++++++++++ drivers/platform/chrome/wilco_ec/properties.h | 179 +++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 55 ++- drivers/platform/chrome/wilco_ec/util.h | 38 ++ 6 files changed, 664 insertions(+), 2 deletions(-) create mode 100644 drivers/platform/chrome/wilco_ec/properties.c create mode 100644 drivers/platform/chrome/wilco_ec/properties.h create mode 100644 drivers/platform/chrome/wilco_ec/util.h
Documentation/ABI/testing/sysfs-platform-wilcoec +48 -0
@@ -45,3 +45,51 @@ Description: // included after the raw hex. $ cat raw 00 31 32 2f 32 31 2f 31 38 00 38 00 01 00 2f 00 .12/21/18.8... + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/global_mic_mute_led +Date: January 2019 +KernelVersion: 4.19 +Description: + Read/write the microphone mute led on the keyboard on and off. + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/fn_lock +Date: January 2019 +KernelVersion: 4.19 +Description: + Fn Toggle - main feature enable/disable setting. + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/nic +Date: January 2019 +KernelVersion: 4.19 +Description: + Enable NIC (network interface card) on the dock. + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/ext_usb_port_en +Date: January 2019 +KernelVersion: 4.19 +Description: + External USB port enable. + +What: /sys/bus/platform/devices/GOOG000C\:00/wireless_sw_wlan +Date: January 2019 +KernelVersion: 4.19 +Description: + Wireless switch - WLAN. + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/auto_boot_on_trinity_dock_attach +Date: January 2019 +KernelVersion: 4.19 +Description: + Enable wake when dock is attached to the system. + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/ich_azalia_en +Date: January 2019 +KernelVersion: 4.19 +Description: + Enable Audio in the Dock. + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/sign_of_life_kbbl +Date: January 2019 +KernelVersion: 4.19 +Description: + Enable early Keyboard BackLight at boot.
drivers/platform/chrome/wilco_ec/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 wilco_ec-objs := core.o mailbox.o sysfs.o legacy.o \ - event.o + event.o properties.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o
drivers/platform/chrome/wilco_ec/properties.c new file +344 -0
344 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/properties.h new file +179 -0
179 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/sysfs.c +54 -1
80 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/util.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* wilco_ec_sysfs_util - helpers for sysfs attributes of Wilco EC +* +* Copyright (C) 2018 Google LLC +*/ + +#ifndef WILCO_EC_SYSFS_UTIL_H +#define WILCO_EC_SYSFS_UTIL_H + +#include <linux/kobject.h> +#include <linux/device.h> +#include <linux/string.h> + +/** +* device_from_kobject() - Get EC device from subdirectory's kobject. +* @kobj: kobject associated with a subdirectory +* +* When we place attributes within directories within the sysfs filesystem, +* at each callback we get a reference to the kobject representing the directory +* that that attribute is in. Somehow we need to get a pointer to the EC device. +* This goes up the directory structure a number of levels until reaching the +* top level for the EC device, and then finds the device from the root kobject. +* +* Example: for attribute GOOG000C:00/properties/peakshift/sunday, +* we would go up two levels, from peakshift to properties and then from +* properties to GOOG000C:00 +* +* Return: a pointer to the device struct representing the EC. +*/ +static inline struct device *device_from_kobject (struct kobject *kobj) +{ +while (strcmp (kobj->name,"GOOG000C:00" ) !=0 ) + kobj = kobj->parent; + return container_of(kobj, struct device, kobj); +} + +#endif
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH v2 8/9 platform/chrome: Add peakshift and adv_batt_charging
In reply to Nick CrewsCreate "peakshift" and "advanced_battery_charging" directories within the "properties" directory, and create the relevant attributes within these. These properties have to do with configuring some of the advanced power management options that prolong battery health and reduce energy use at peak hours of the day.
Scheduling events uses a 24 hour clock, and only supports time intervals of 15 minutes. For example, to set advanced_battery_charging to start at 4:15pm and to last for 6 hours and 45 minutes, you would use the argument "16 15 6 45".
Quoted 3 lines
cd /sys/bus/platform/devices/GOOG000C\:00 cat properties/peakshift/peakshift_battery_threshold 015
[means 15 percent]
Quoted 1 line
cat properties/peakshift/peakshift_monday
16 00 20 30 00 00
[starts at 4:00 pm, ends at 8:30, charging resumes at midnight]
Quoted 1 line
echo "16 00 20 31 00 00" > properties/peakshift/peakshift_monday
-bash: echo: write error: Invalid argument
Quoted 1 line
dmesg | tail -n1
[40.34534] wilco_ec GOOG00C:00: minutes must be at the quarter hour
Quoted 2 lines
echo "16 0 20 45 0 0" > properties/peakshift/peakshift_monday cat properties/peakshift/peakshift_monday
16 00 20 45 00 00
---
Changes in v2:
- rm license boiler plate
- rm "wilco_ec_adv_power - " prefix from docstring
- Add documentation
- Made format strings in store() and read() functions static
.../ABI/testing/sysfs-platform-wilcoec | 75 +++ drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/adv_power.c | 544 ++++++++++++++++++ drivers/platform/chrome/wilco_ec/adv_power.h | 183 ++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 100 ++++ 5 files changed, 903 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/chrome/wilco_ec/adv_power.c create mode 100644 drivers/platform/chrome/wilco_ec/adv_power.h
Documentation/ABI/testing/sysfs-platform-wilcoec +75 -0
@@ -93,3 +93,78 @@ Date: January 2019 KernelVersion: 4.19 Description: Enable early Keyboard BackLight at boot. + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/peakshift/<day of week> +Date: January 2019 +KernelVersion: 4.19 +Description: + For each weekday a start and end time to run in Peak Shift mode + can be set. During these times the system will run from the + battery even if the AC is attached as long as the battery stays + above the threshold specified. After the end time specified the + system will run from AC if attached but will not charge the + battery. The system will again function normally using AC and + recharging the battery after the specified Charge Start time. + + The input buffer must have the format "start_hr start_min end_hr + end_min charge_start_hr charge_start_min" The hour fields must + be in the range [0-23], and the minutes must be one of (0, 15, + 30, 45). The string must be parseable by sscanf() using the + format string "%d %d %d %d %d %d". An example valid input is + "6 15 009 45 23 0", which corresponds to 6:15, 9:45, and 23:00 + + The output buffer will be filled with the format "start_hr + start_min end_hr end_min charge_start_hr charge_start_min" The + hour fields will be in the range [0-23], and the minutes will be + one of (0, 15, 30, 45). Each number will be zero padded to two + characters. An example output is "06 15 09 45 23 00", which + corresponds to 6:15, 9:45, and 23:00 + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/peakshift/enable +Date: January 2019 +KernelVersion: 4.19 +Description: + Enable/disable the peakshift power management policy + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/peakshift/battery_threshold +Date: January 2019 +KernelVersion: 4.19 +Description: + Read/write the battery percentage threshold for which the + peakshift policy is used. The valid range is [15, 50]. + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/advanced_battery_charging/<day of week> +Date: January 2019 +KernelVersion: 4.19 +Description: + Advanced Charging Mode allows the user to maximize the battery + health. In Advanced Charging Mode the system will use standard + charging algorithm and other techniques during non-work hours to + maximize battery health. During work hours, an express charge is + used. This express charge allows the battery to be charged + faster; therefore, the battery is at full charge sooner. For + each day the time in which the system will be most heavily used + is specified by the start time and the duration. Please read the + Common UEFI BIOS Behavioral Specification and BatMan 2 BIOS_EC + Specification for more details about this feature. + + The input buffer must have the format "start_hr start_min + duration_hr duration_min" The hour fields must be in the range + [0-23], and the minutes must be one of (0, 15, 30, 45). The + string must be parseable by sscanf() using the format string + "%d %d %d %d %d %d". An example valid input is "0006 15 23 45", + which corresponds to a start time of 6:15 and a duration of + 23:45. + + The output buffer will be filled with the format "start_hr + start_min duration_hr duration_min" The hour fields will be in + the range [0-23], and the minutes will be one of (0, 15, 30, + 45). Each number will be zero padded to two characters. An + example output is "06 15 23 45", which corresponds to a start + time of 6:15 and a duration of 23:45 + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/advanced_battery_charging/enable +Date: January 2019 +KernelVersion: 4.19 +Description: + Enable/disable the Advanced Battery Charging policy
drivers/platform/chrome/wilco_ec/Makefile +1 -1
@@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 wilco_ec-objs := core.o mailbox.o sysfs.o legacy.o \ - event.o properties.o + event.o properties.o adv_power.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o
drivers/platform/chrome/wilco_ec/adv_power.c new file +544 -0
544 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/adv_power.h new file +183 -0
183 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/sysfs.c +100 -0
127 lines not on this page · raw message
Signature · 1 line
2.20.1.97.g81188d93c3-goog
PATCH v2 9/9 platform/chrome: Add binary telemetry attributes
In reply to Nick CrewsThe Wilco Embedded Controller is able to send telemetry data which is useful for enterprise applications. A daemon running on the OS sends a command (possibly with args) to the EC via this sysfs interface, and the EC responds over the sysfs interface with the response. Both the request and the response are in an opaque binary format so that information which is proprietary to the enterprise service provider is secure.
At this point, the Wilco EC does not implement this telemetry functionality, so any request using the WILCO_EC_MSG_TELEMETRY command returns an error. This is just an initial change for comments, until the EC code is implemented.
---
Changes in v2:
- rm "wilco_ec_telemetry - " prefix from docstring
- rm license boiler plate
- Fix commit msg tag
.../ABI/testing/sysfs-platform-wilcoec | 6 ++ drivers/platform/chrome/wilco_ec/Makefile | 3 +- drivers/platform/chrome/wilco_ec/sysfs.c | 15 ++++- drivers/platform/chrome/wilco_ec/telemetry.c | 66 +++++++++++++++++++ drivers/platform/chrome/wilco_ec/telemetry.h | 41 ++++++++++++ 5 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 drivers/platform/chrome/wilco_ec/telemetry.c create mode 100644 drivers/platform/chrome/wilco_ec/telemetry.h
Documentation/ABI/testing/sysfs-platform-wilcoec +6 -0
@@ -168,3 +168,9 @@ Date: January 2019 KernelVersion: 4.19 Description: Enable/disable the Advanced Battery Charging policy + +What: /sys/bus/platform/devices/GOOG000C\:00/telemetry +Date: January 2019 +KernelVersion: 4.19 +Description: + Send and receive opaque binary telemetry data to/from the EC.
drivers/platform/chrome/wilco_ec/Makefile +2 -1
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 wilco_ec-objs := core.o mailbox.o sysfs.o legacy.o \ - event.o properties.o adv_power.o + event.o properties.o adv_power.o \ + telemetry.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o
drivers/platform/chrome/wilco_ec/sysfs.c +14 -1
@@ -17,6 +17,7 @@#include "legacy.h" #include "properties.h" #include "adv_power.h" +#include "telemetry.h" #define WILCO_EC_ATTR_RO (_name) \ __ATTR(_name, 0444, wilco_ec_##_name##_show, NULL)
@@ -41,7 +42,19 @@ static struct attribute *wilco_ec_toplevel_attrs[] = {#endif NULL }; -ATTRIBUTE_GROUPS (wilco_ec_toplevel); +static struct bin_attribute telem_attr =TELEMETRY_BIN_ATTR (telemetry); +static struct bin_attribute *telem_attrs[] = { + &telem_attr, +NULL +}; +static const struct attribute_group wilco_ec_toplevel_group = { + .attrs = wilco_ec_toplevel_attrs, + .bin_attrs = telem_attrs, +}; +static const struct attribute_group *wilco_ec_toplevel_groups[] = { + &wilco_ec_toplevel_group, +NULL , +};/* Make property attributes, which will live inside GOOG000C:00/properties/ */ BOOLEAN_PROPERTY_RW_ATTRIBUTE(OP_SET, bool_prop_attr_global_mic_mute_led,
drivers/platform/chrome/wilco_ec/telemetry.c new file +66 -0
66 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/telemetry.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
2.20.1.97.g81188d93c3-goog