platform/chrome: rtc: Add support for Wilco EC
v4 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), adding a debugfs interface for sending/receiving raw byte sequesnces to the EC, 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 via debugfs which can write/read arbitrary bytes to/from the eSPI bus.
The entry point of the driver is wilco_ec/core.c,
which is responsible for several tasks:
- Initialize the register interface that is used by wilco_ec_mailbox()
- Create a platform device which is picked up by the debugfs driver
- Create a platform device which is picked up by the RTC driver
- Initialize the sysfs entries
- Set up event handling
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.
The RTC driver is exposed as a standard RTC 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 v4:
- add #define DRV_NAME
- remove redundant Kconfig nesting
- changed my email to @chromium.org
- Add better explanation of what core.c does
- Change debugfs driver to be a separate module
- Change me email to @chromium.org from @google.com
- Change CONFIG_WILCO_EC_SYSFS_RAW to CONFIG_WILCO_EC_DEBUGFS
- Change me email to @chromium.org from @google.com
- Move "Add RTC driver" before "Add sysfs attributes" so that it could get accepted earlier, since it is less contentious
- Move "Add RTC driver" before "Add sysfs attributes" so that it could get accepted earlier, since it is less contentious
Changes in v3:
- Change <= to >= in mec_in_range()
- Add " - EC_HOST_CMD_REGION0" to offset arg for io_bytes_mec()
- remove unused ret in probe()
- Add newline spacer in probe()
- rm unnecessary res in get_resource()
- s/8bit/8-bit
- rm first sleep when sending command to EC
- Move the attribute to the debugfs system
- Move the implementation to debugfs.c
- Improve the raw hex parsing
- Encapsulate global variables in one object
- Add safety check when passing less than 3 bytes
- Move documentation to debugfs-wilco-ec
- rm #define for driver name
- Don't compute weekday when reading from RTC.
Still set weekday when writing, as RTC needs this
to control advanced power scheduling
- rm check for invalid month data
- Set range_min and range_max on rtc_device
- explicitly define toplevel_groups from the start,
so adding telem later makes sense
- Break version attribute into individual attributes
- rm unused WILCO_EC_ATTR_RW macro
- Moved some #defines from legacy.h to legacy.c
- change err check from "if (ret < 0)" to "if (ret)"
- Now bubble up error codes from within sysfs_init()
- Add comment that PID means Property ID
- rm some useless references to internal docs from documentation
- add err check on returned data size
- add check on read request offset and size
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
- Remove COMPILE_TEST from Kconfig because inb()/outb() won't work on anything but X86
- Add myself as module author
- Tweak mailbox()
- Add sysfs documentation
- rm duplicate EC_MAILBOX_DATA_SIZE defs
- Make docstrings follow kernel style
- Fix tags in commit msg
- Move Kconfig to subdirectory
- 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
- 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 when init()ing sysfs
- rm "wilco_ec_event -" prefix from docstring
- rm license boiler plate
- Add sysfs directory documentation
- Fix cosmetics
- events are init()ed before subdrivers now
- 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
- make format strings in read() and store() functions static
Duncan Laurie (6):
cros_ec: Remove cros_ec dependency in lpc_mec platform/chrome: Add new driver for Wilco EC platform/chrome: Add support for raw commands in debugfs platform/chrome: rtc: Add RTC driver platform/chrome: Add sysfs attributes 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
Documentation/ABI/testing/debugfs-wilco-ec | 23 + .../ABI/testing/sysfs-platform-wilco-ec | 196 +++++++ 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 | 47 +- drivers/platform/chrome/wilco_ec/Kconfig | 20 + drivers/platform/chrome/wilco_ec/Makefile | 8 + 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 | 164 ++++++ drivers/platform/chrome/wilco_ec/debugfs.c | 226 ++++++++ drivers/platform/chrome/wilco_ec/event.c | 347 +++++++++++ drivers/platform/chrome/wilco_ec/legacy.c | 103 ++++ drivers/platform/chrome/wilco_ec/legacy.h | 79 +++ drivers/platform/chrome/wilco_ec/mailbox.c | 236 ++++++++ drivers/platform/chrome/wilco_ec/properties.c | 344 +++++++++++ drivers/platform/chrome/wilco_ec/properties.h | 180 ++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 245 ++++++++ drivers/platform/chrome/wilco_ec/telemetry.c | 73 +++ 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 | 177 ++++++ include/linux/platform_data/wilco-ec.h | 186 ++++++ 27 files changed, 3513 insertions(+), 60 deletions(-) create mode 100644 Documentation/ABI/testing/debugfs-wilco-ec create mode 100644 Documentation/ABI/testing/sysfs-platform-wilco-ec 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/debugfs.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.321.g9e740568ce-goog
PATCH v4 1/9 cros_ec: 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 v4: None
Changes in v3:
- Change <= to >= in mec_in_range()
- Add " - EC_HOST_CMD_REGION0" to offset arg for io_bytes_mec()
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 | 47 +++++++------------- 3 files changed, 83 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 +16 -31
67 lines not on this page · raw message
Signature · 1 line
2.20.1.321.g9e740568ce-goog
PATCH v4 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 v4:
- add #define DRV_NAME
- remove redundant Kconfig nesting
- changed my email to @chromium.org
- Add better explanation of what core.c does
Changes in v3:
- remove unused ret in probe()
- Add newline spacer in probe()
- rm unnecessary res in get_resource()
- s/8bit/8-bit
- rm first sleep when sending command to EC
Changes in v2:
- Remove COMPILE_TEST from Kconfig because inb()/outb() won't work on anything but X86
- Add myself as module author
- Tweak mailbox()
drivers/platform/chrome/Kconfig | 4 +- drivers/platform/chrome/Makefile | 2 + drivers/platform/chrome/wilco_ec/Kconfig | 11 + drivers/platform/chrome/wilco_ec/Makefile | 4 + drivers/platform/chrome/wilco_ec/core.c | 106 +++++++++ drivers/platform/chrome/wilco_ec/mailbox.c | 236 +++++++++++++++++++++ include/linux/platform_data/wilco-ec.h | 138 ++++++++++++ 7 files changed, 500 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 +11 -0
@@ -0,0 +1,11 @@ +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.
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 +106 -0
106 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/mailbox.c new file +236 -0
236 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.321.g9e740568ce-goog
PATCH v4 3/9 platform/chrome: Add support for raw commands in debugfs
In reply to Nick CrewsFrom: Duncan Laurie <[email protected]>
Add a debugfs 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.
Turn the keyboard global mic mute led on
Quoted 1 line
echo 00 f2 01 76 06 00 00 01 01 >
/sys/kernel/debug/wilco_ec/raw
Turn the keyboard global mic mute led off
Quoted 1 line
echo 00 f2 01 76 06 00 00 01 00 >
/sys/kernel/debug/wilco_ec/raw
Get the EC firmware build date
First send the request command
Quoted 1 line
echo 00 f0 38 00 03 00 > raw
Then read the result. "12/21/18" is in the middle of the response
Quoted 1 line
cat raw
00 31 32 2f 32 31 2f 31 38 00 00 0f 01 00 01 00 .12/21/18.......
---
Changes in v4:
- Change debugfs driver to be a separate module
- Change me email to @chromium.org from @google.com
- Change CONFIG_WILCO_EC_SYSFS_RAW to CONFIG_WILCO_EC_DEBUGFS
Changes in v3:
- Move the attribute to the debugfs system
- Move the implementation to debugfs.c
- Improve the raw hex parsing
- Encapsulate global variables in one object
- Add safety check when passing less than 3 bytes
- Move documentation to debugfs-wilco-ec
Changes in v2:
- Add sysfs documentation
- rm duplicate EC_MAILBOX_DATA_SIZE defs
- Make docstrings follow kernel style
- Fix tags in commit msg
- Move Kconfig to subdirectory
- Reading raw now includes ASCII translation
Documentation/ABI/testing/debugfs-wilco-ec | 23 +++ drivers/platform/chrome/wilco_ec/Kconfig | 9 + drivers/platform/chrome/wilco_ec/Makefile | 2 + drivers/platform/chrome/wilco_ec/core.c | 20 ++ drivers/platform/chrome/wilco_ec/debugfs.c | 226 +++++++++++++++++++++ 5 files changed, 280 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-wilco-ec create mode 100644 drivers/platform/chrome/wilco_ec/debugfs.c
Documentation/ABI/testing/debugfs-wilco-ec new file +23 -0
@@ -0,0 +1,23 @@ +What: /sys/kernel/debug/wilco_ec/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... + + At least three bytes are required, for the msg type and command, + with additional bytes optional for additional data.
drivers/platform/chrome/wilco_ec/Kconfig +9 -0
@@ -9,3 +9,12 @@ config WILCO_EC To compile this driver as a module, choose M here: the module will be called wilco_ec. + +config WILCO_EC_DEBUGFS + tristate "Enable raw access to EC via debugfs" + depends on WILCO_EC + help + If you say Y here, you get support for sending raw commands to + the Wilco EC via debugfs. 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.
drivers/platform/chrome/wilco_ec/Makefile +2 -0
@@ -2,3 +2,5 @@ wilco_ec-objs := core.o mailbox.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o +wilco_ec_debugfs-objs := debugfs.o +obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.o
drivers/platform/chrome/wilco_ec/core.c +20 -0
@@ -44,6 +44,8 @@ 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 );if (!ec)
@@ -71,7 +73,25 @@ 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 ); +/* +* Register a debugfs platform device that will get picked up by the +* debugfs driver. This platform device will get freed when its parent +* device dev is unregistered. +*/ + child_pdev =platform_device_register_data (dev,"wilco-ec-debugfs" , +PLATFORM_DEVID_AUTO , +NULL ,0 ); +if (IS_ERR (child_pdev)) { +dev_err (dev,"Failed to create debugfs platform device\n" ); + ret =PTR_ERR (child_pdev); + goto destroy_mec; + } +return 0 ; + +destroy_mec: +cros_ec_lpc_mec_destroy (); +return ret; }static int wilco_ec_remove (struct platform_device *pdev)
drivers/platform/chrome/wilco_ec/debugfs.c new file +226 -0
226 lines not on this page · raw message
Signature · 1 line
2.20.1.321.g9e740568ce-goog
Re: [PATCH v4 3/9] platform/chrome: Add support for raw commands in debugfs
Hi Nick,
Missatge de Nick Crews <[email protected]> del dia dc., 23 de gen. 2019 a les 19:38:
Quoted 11 lines
From: Duncan Laurie <[email protected]>
Add a debugfs 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.
Turn the keyboard global mic mute led on
Quoted 1 line
echo 00 f2 01 76 06 00 00 01 01 >
/sys/kernel/debug/wilco_ec/rawTurn the keyboard global mic mute led off
Quoted 1 line
echo 00 f2 01 76 06 00 00 01 00 >
/sys/kernel/debug/wilco_ec/raw
That won't be a real example, right? Would be better remove it?
Quoted 117 lines
Get the EC firmware build date
First send the request commandQuoted 1 line
echo 00 f0 38 00 03 00 > raw
Then read the result. "12/21/18" is in the middle of the response
Quoted 1 line
cat raw
00 31 32 2f 32 31 2f 31 38 00 00 0f 01 00 01 00 .12/21/18.......
Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Nick Crews <[email protected]>---
Changes in v4:
- Change debugfs driver to be a separate module
- Change me email to @chromium.org from @google.com
- ChangeCONFIG_WILCO_EC_SYSFS_RAWtoCONFIG_WILCO_EC_DEBUGFSChanges in v3:
- Move the attribute to the debugfs system
- Move the implementation todebugfs.c
- Improve the raw hex parsing
- Encapsulate global variables in one object
- Add safety check when passing less than 3 bytes
- Move documentation to debugfs-wilco-ecChanges in v2:
- Add sysfs documentation
- rm duplicateEC_MAILBOX_DATA_SIZEdefs
- Make docstrings follow kernel style
- Fix tags in commit msg
- MoveKconfigto subdirectory
- Reading raw now includes ASCII translationDocumentation/ABI/testing/debugfs-wilco-ec | 23 +++ drivers/platform/chrome/wilco_ec/Kconfig | 9 + drivers/platform/chrome/wilco_ec/Makefile | 2 + drivers/platform/chrome/wilco_ec/core.c | 20 ++ drivers/platform/chrome/wilco_ec/debugfs.c | 226 +++++++++++++++++++++ 5 files changed, 280 insertions(+) create mode 100644 Documentation/ABI/testing/debugfs-wilco-ec create mode 100644 drivers/platform/chrome/wilco_ec/debugfs.cDocumentation/ABI/testing/debugfs-wilco-ec new file +23
-0@@ -0,0 +1,23 @@ +What: /sys/kernel/debug/wilco_ec/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... + + At least three bytes are required, for the msg type and command, + with additional bytes optional for additional data.drivers/platform/chrome/wilco_ec/Kconfig +9
-0@@ -9,3 +9,12 @@ config WILCO_EC To compile this driver as a module, choose M here: the module will be called wilco_ec. + +config WILCO_EC_DEBUGFS + tristate "Enable raw access to EC via debugfs" + depends on WILCO_EC + help + If you say Y here, you get support for sending raw commands to + the Wilco EC via debugfs. 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.drivers/platform/chrome/wilco_ec/Makefile +2
-0@@ -2,3 +2,5 @@ wilco_ec-objs := core.o mailbox.o obj-$(CONFIG_WILCO_EC) += wilco_ec.o +wilco_ec_debugfs-objs := debugfs.o +obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.odrivers/platform/chrome/wilco_ec/core.c +4
-0@@ -44,6 +44,8 @@ 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 );if (!ec)@@ -71,7 +73,25 @@ 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 ); +/* +* Register a debugfs platform device that will get picked up by the
drivers/platform/chrome/wilco_ec/core.c static int wilco_ec_probe(struct platform_device *pdev) · line 87
Quoted 10 lines
drivers/platform/chrome/wilco_ec/core.c +10
-0+* debugfs driver. This platform device will get freed when its parent +* device dev is unregistered. +*/ + child_pdev =platform_device_register_data (dev,"wilco-ec-debugfs" , +PLATFORM_DEVID_AUTO , +NULL ,0 ); +if (IS_ERR (child_pdev)) { +dev_err (dev,"Failed to create debugfs platform device\n" ); + ret =PTR_ERR (child_pdev); + goto destroy_mec;
I don't think makes sense destroy the wilco-ec if for some reason the debugfs interface driver fails (unlikely). Your driver should have the same behaviour without depending on the debugfs part ...
drivers/platform/chrome/wilco_ec/core.c static int wilco_ec_probe(struct platform_device *pdev) · line 94
Quoted 7 lines
drivers/platform/chrome/wilco_ec/core.c +6
-0+ } +return 0 ; + +destroy_mec: +cros_ec_lpc_mec_destroy (); +return ret;
... and then you can remove this error cleanup for now.
Quoted 58 lines
drivers/platform/chrome/wilco_ec/core.c +0
-0}static int wilco_ec_remove (struct platform_device *pdev)drivers/platform/chrome/wilco_ec/debugfs.c new file +49
-0@@ -0,0 +1,226 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* debugfs attributes for Wilco EC +* +* Copyright 2019 Google LLC +* +* There is only one attribute used for debugging, called raw. +* You can write a hexadecimal sentence to raw, and that series of bytes +* will be sent to the EC. Then, you can read the bytes of response +* by reading from raw. +*/ + +#include <linux/ctype.h> +#include <linux/debugfs.h> +#include <linux/fs.h> +#include <linux/module.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/platform_device.h> + +#define DRV_NAME "wilco-ec-debugfs" + +/* The 256 raw bytes will take up more space when represented as a hex string */ +#define FORMATTED_BUFFER_SIZE (EC_MAILBOX_DATA_SIZE_EXTENDED * 4) + +struct wilco_ec_debugfs { +struct wilco_ec_device *ec; +struct dentry *dir; +size_t response_size; +u8 raw_data[EC_MAILBOX_DATA_SIZE_EXTENDED ]; +u8 formatted_data[FORMATTED_BUFFER_SIZE ]; +}; + +static struct wilco_ec_debugfs *debug_info; + +/** +* parse_hex_sentence() - Convert a ascii hex representation into byte array +* @in: Input buffer of ascii +* @isize: Length of input buffer +* @out: Output buffer +* @osize: Length of output buffer, e.g. max number of bytes to parse +* +* An valid input is a series of ascii hexadecimal numbers, separated by spaces. +* An example valid input is +* " 00 f2 0 000076 6 0 ff" +* +* If an individual "word" within the hex sentence is longer than MAX_WORD_SIZE, +* then the sentence is illegal, and parsing will fail. +* +* Return: Number of bytes parsed, or negative error code on failure
drivers/platform/chrome/wilco_ec/debugfs.c line 59
Quoted 10 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +10
-0+*/ +static int parse_hex_sentence (const char *in,int isize,u8 *out,int osize) +{ +int n_parsed =0 ; +int word_start =0 ; +int word_end; +int word_len; +/* Temp buffer for holding a "word" of chars that represents one byte */ +const static int MAX_WORD_SIZE =16 ; +char tmp[MAX_WORD_SIZE +1 ];
spaces around +
[my first filter is run checkpatch.pl --strict :) ]
Quoted 80 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +80
-0+u8 byte; + +while (word_start < isize && n_parsed < osize) { +/* Find the start of the next word */ +while (word_start < isize &&isspace (in[word_start])) + word_start++; +/* reached the end of the input before next word? */ +if (word_start >= isize) +break ; + +/* Find the end of this word */ + word_end = word_start; +while (word_end < isize && !isspace (in[word_end])) + word_end++; + +/* Copy to a tmp NULL terminated string */ + word_len = word_end - word_start; +if (word_len >MAX_WORD_SIZE ) +return -EINVAL ; +memcpy (tmp, in + word_start, word_len); + tmp[word_len] ='\0' ; + +/* +* Convert from hex string, place in output. If fails to parse, +* just return -EINVAL because specific error code is only +* relevant for this one word, returning it would be confusing. +*/ +if (kstrtou8 (tmp,16 , &byte)) +return -EINVAL ; + out[n_parsed++] = byte; + + word_start = word_end; + } +return n_parsed; +} + +/* The message type takes up two bytes and the command takes a byte */ +#define CMDS_AND_DATA_SIZE ((EC_MAILBOX_DATA_SIZE) + 3) + +static ssize_t raw_write (struct file *file,const char __user *user_buf, +size_t count,loff_t *ppos) +{ +char *buf = debug_info->formatted_data; +struct wilco_ec_message msg; +u8 request_data[CMDS_AND_DATA_SIZE ]; +ssize_t kcount; +int ret; + +if (count >FORMATTED_BUFFER_SIZE ) +return -EINVAL ; + + kcount =simple_write_to_buffer (buf,FORMATTED_BUFFER_SIZE , ppos, + user_buf, count); +if (kcount <0 ) +return kcount; + + ret =parse_hex_sentence (buf, kcount, request_data,CMDS_AND_DATA_SIZE ); +if (ret <0 ) +return ret; +/* Need at least three bytes for type and command */ +if (ret <3 ) +return -EINVAL ; + +/* Clear response data buffer */ +memset (debug_info->raw_data,'\0' ,EC_MAILBOX_DATA_SIZE_EXTENDED ); + + msg.type = request_data[0 ] <<8 | request_data[1 ]; + msg.flags =WILCO_EC_FLAG_RAW ; + msg.command = request_data[2 ]; + msg.request_data = ret >3 ? request_data +3 :NULL ; + msg.request_size = ret -3 ; + msg.response_data = debug_info->raw_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 ; + } +
drivers/platform/chrome/wilco_ec/debugfs.c line 149
Quoted 10 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +10
-0+ ret =wilco_ec_mailbox (debug_info->ec, &msg); +if (ret <0 ) +return ret; + debug_info->response_size = ret; + +return count; +} + +/** +* wilco_ec_raw_show() - Show result from previous call to raw_store()
If you want to have the function documentation (see comment below)
s/wilco_ec_raw_show/wilco_ec_raw_read/
and
s/raw_store/wilco_ec_raw_write/
drivers/platform/chrome/wilco_ec/debugfs.c line 153
Quoted 4 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +4
-0+* @dev: Device representing the EC +* @attr: The attribute in question +* @buf: Output buffer to be filled +*
Note that the documentation doesn't match with current function. You can either, fix the documentation and also document wilco_ec_raw_write or just remove that documentation. For me it is clear what read/write means, It might make sense for the examples, but it is also documented in the debugfs-wilco-ec file (sometimes duplicating the info is a source of mismatches).
drivers/platform/chrome/wilco_ec/debugfs.c line 165
Quoted 12 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +12
-0+* 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 +*/ +static ssize_t raw_read (struct file *file,char __user *user_buf,size_t count, +loff_t *ppos)
s/raw_read/wilco_ec_raw_read/
Quoted 9 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +9
-0+{ +int fmt_len =0 ; + +if (debug_info->response_size) { + fmt_len =hex_dump_to_buffer (debug_info->raw_data, + debug_info->response_size, +16 ,1 , debug_info->formatted_data, +FORMATTED_BUFFER_SIZE , true); +/* Only return response the first time it is read */
drivers/platform/chrome/wilco_ec/debugfs.c line 184
Quoted 10 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +10
-0+ debug_info->response_size =0 ; + } + +return simple_read_from_buffer (user_buf, count, ppos, + debug_info->formatted_data, fmt_len); +} + +static const struct file_operations fops_raw = { + .owner =THIS_MODULE , + .read = raw_read,
s/raw_read/wilco_ec_raw_read/
drivers/platform/chrome/wilco_ec/debugfs.c line 185
Quoted 1 line
drivers/platform/chrome/wilco_ec/debugfs.c new file +1
-0+ .write = raw_write,
s/raw_write/wilco_ec_raw_write/
drivers/platform/chrome/wilco_ec/debugfs.c line 194
Quoted 9 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +9
-0+ .llseek = no_llseek, +}; + +static int wilco_ec_debugfs_probe (struct platform_device *pdev) +{ +/* +* Ignore all errors, if there's a problem then we're already on fire: +* www.mail-archive.com/[email protected]/msg1906997.html +*/
I'd prefer if you remove this comment, as is not really true (see below) and likely this will end on a broken link in the future.
drivers/platform/chrome/wilco_ec/debugfs.c line 197
Quoted 3 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +3
-0+struct wilco_ec_device *ec =dev_get_drvdata (pdev->dev.parent); + + debug_info =devm_kzalloc (&pdev->dev,sizeof (*debug_info),GFP_KERNEL );
Oh, you should check the return value of devm_kzalloc, which would cause a NULL pointer dereference in a OOM situation. It's only for the debugfs calls that you should not have to check the error.
drivers/platform/chrome/wilco_ec/debugfs.c line 207
Quoted 10 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +10
-0+ debug_info->ec = ec; + debug_info->dir =debugfs_create_dir ("wilco_ec" ,NULL ); +debugfs_create_file ("raw" ,0644 , debug_info->dir,NULL , &fops_raw); + +return 0 ; +} + +static int wilco_ec_debugfs_remove (struct platform_device *pdev) +{ +if (debug_info)
It is possible to have debug_info not allocated at this point? I think that now you can remove this check
Quoted 20 lines
drivers/platform/chrome/wilco_ec/debugfs.c new file +19
-1+debugfs_remove_recursive (debug_info->dir); + +return 0 ; +} + +static struct platform_driver wilco_ec_debugfs_driver = { + .driver = { + .name =DRV_NAME , + }, + .probe = wilco_ec_debugfs_probe, + .remove = wilco_ec_debugfs_remove, +}; + +module_platform_driver (wilco_ec_debugfs_driver); + +MODULE_ALIAS ("platform:" DRV_NAME ); +MODULE_AUTHOR ("Nick Crews <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Wilco EC debugfs driver" ); --
Quoted 2 lines
2.20.1.321.g9e740568ce-goog
After solving these comments I think you can add my
Acked-for-chrome-platform-by: Enric Balletbo i Serra <[email protected]>
Thanks,
Enric
PATCH v4 4/9 platform/chrome: rtc: Add RTC driver
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 v4:
- Change me email to @chromium.org from @google.com
- Move "Add RTC driver" before "Add sysfs attributes" so that it could get accepted earlier, since it is less contentious
Changes in v3:
- rm #define for driver name
- Don't compute weekday when reading from RTC. Still set weekday when writing, as RTC needs this to control advanced power scheduling
- rm check for invalid month data
- Set range_min and range_max on rtc_device
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
drivers/platform/chrome/wilco_ec/core.c | 14 ++ drivers/rtc/Kconfig | 11 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-wilco-ec.c | 177 ++++++++++++++++++++++++ 4 files changed, 203 insertions(+) create mode 100644 drivers/rtc/rtc-wilco-ec.c
drivers/platform/chrome/wilco_ec/core.c +14 -0
@@ -87,6 +87,20 @@ static int wilco_ec_probe(struct platform_device *pdev) goto destroy_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 destroy_mec; + } +return 0 ; destroy_mec:
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 +177 -0
177 lines not on this page · raw message
Signature · 1 line
2.20.1.321.g9e740568ce-goog
Re: [PATCH v4 4/9] platform/chrome: rtc: Add RTC driver
Quoted 12 lines · Nick Crews
From: 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 fromcore.c, as opposed tocore.cregistering the driver callbacks directly.Quoted 1 line
hwclock --show --rtc
/dev/rtc1
Quoted 8 lines
2007-12-31 16:01:20.460959-08:00Quoted 2 lines
hwclock --systohc --rtc
/dev/rtc1
hwclock --show --rtc/dev/rtc12018-11-29 17:08:00.780793-08:00Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Nick Crews <[email protected]>
Quoted 271 lines
---
Changes in v4:
- Change me email to @chromium.org from @google.com
- Move "Add RTC driver" before "Add sysfs attributes" so that it could get accepted earlier, since it is less contentiousChanges in v3:
- rm #define for driver name
- Don't compute weekday when reading from RTC. Still set weekday when writing, as RTC needs this to control advanced power scheduling
- rm check for invalid month data
- Setrange_minandrange_maxonrtc_deviceChanges in v2:
- rm license boiler plate
- rm "wilco_ec_rtc-" prefix in docstring
- Make rtc driver its own module within thedrivers/rtc/directory
- Register a rtc device fromcore.cthat is picked up by this driverdrivers/platform/chrome/wilco_ec/core.c | 14 ++ drivers/rtc/Kconfig | 11 ++ drivers/rtc/Makefile | 1 + drivers/rtc/rtc-wilco-ec.c | 177 ++++++++++++++++++++++++ 4 files changed, 203 insertions(+) create mode 100644 drivers/rtc/rtc-wilco-ec.cdrivers/platform/chrome/wilco_ec/core.c +14
-0@@ -87,6 +87,20 @@ static int wilco_ec_probe(struct platform_device *pdev) goto destroy_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 destroy_mec; + } +return 0 ; destroy_mec: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_CLASSdrivers/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.odrivers/rtc/rtc-wilco-ec.c new file +177
-0@@ -0,0 +1,177 @@ +// 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> +#include <linux/platform_device.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/rtc.h> +#include <linux/timekeeping.h> + +#define EC_COMMAND_CMOS 0x7c +#define EC_CMOS_TOD_WRITE 0x02 +#define EC_CMOS_TOD_READ 0x08 + +/** +* struct ec_rtc_read - Format of RTC returned by EC. +* @second: Second value (0..59) +* @minute: Minute value (0..59) +* @hour: Hour value (0..23) +* @day: Day value (1..31) +* @month: Month value (1..12) +* @year: Year value (full year % 100) +* @century: Century value (full year / 100) +* +* All values are presented in binary (not BCD). +*/ +struct ec_rtc_read { +u8 second; +u8 minute; +u8 hour; +u8 day; +u8 month; +u8 year; +u8 century; +} __packed; + +/** +* struct ec_rtc_write - Format of RTC sent to the EC. +* @param: EC_CMOS_TOD_WRITE +* @century: Century value (full year / 100) +* @year: Year value (full year % 100) +* @month: Month value (1..12) +* @day: Day value (1..31) +* @hour: Hour value (0..23) +* @minute: Minute value (0..59) +* @second: Second value (0..59) +* @weekday: Day of the week (0=Saturday) +* +* All values are presented in BCD. +*/ +struct ec_rtc_write { +u8 param; +u8 century; +u8 year; +u8 month; +u8 day; +u8 hour; +u8 minute; +u8 second; +u8 weekday; +} __packed; + +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), + }; +int ret; + + ret =wilco_ec_mailbox (ec, &msg); +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; + tm->tm_mon = rtc.month -1 ; + tm->tm_year = rtc.year + (rtc.century *100 ) -1900 ; + tm->tm_yday =rtc_year_days (tm->tm_mday, tm->tm_mon, tm->tm_year); + +/* Don't compute day of week, we don't need it. */ + tm->tm_wday =-1 ; + +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, + .request_size =sizeof (rtc), + }; +int year = tm->tm_year +1900 ; +/* +* Convert from 0=Sunday to 0=Saturday for the EC +* We DO need to set weekday because the EC controls battery charging +* schedules that depend on the day of the week. +*/ +int wday = tm->tm_wday ==6 ?0 : tm->tm_wday +1 ; +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) +{ +struct rtc_device *rtc; + + rtc =devm_rtc_allocate_device (&pdev->dev); +if (IS_ERR (rtc)) +return PTR_ERR (rtc); + + rtc->ops = &wilco_ec_rtc_ops; +/* EC only supports this century */ + rtc->range_min =RTC_TIMESTAMP_BEGIN_2000 ; + rtc->range_max =RTC_TIMESTAMP_END_2099 ; + rtc->owner =THIS_MODULE ; + +return rtc_register_device (rtc); +} + +static struct platform_driver wilco_ec_rtc_driver = { + .driver = { + .name ="rtc-wilco-ec" , + }, + .probe = wilco_ec_rtc_probe, +}; + +module_platform_driver (wilco_ec_rtc_driver); + +MODULE_ALIAS ("platform:rtc-wilco-ec" ); +MODULE_AUTHOR ("Nick Crews <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("Wilco EC RTC driver" );Signature · 1 line
2.20.1.321.g9e740568ce-goog
Signature · 3 lines
Alexandre Belloni, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v4 5/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 v4:
- Move "Add RTC driver" before "Add sysfs attributes" so that it could get accepted earlier, since it is less contentious
Changes in v3:
- explicitly define toplevel_groups from the start, so adding telem later makes sense
- Break version attribute into individual attributes
- rm unused WILCO_EC_ATTR_RW macro
- Moved some #defines from legacy.h to legacy.c
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 when init()ing sysfs
.../ABI/testing/sysfs-platform-wilco-ec | 42 +++++++ drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/core.c | 12 ++ drivers/platform/chrome/wilco_ec/legacy.c | 103 ++++++++++++++++++ drivers/platform/chrome/wilco_ec/legacy.h | 79 ++++++++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 79 ++++++++++++++ include/linux/platform_data/wilco-ec.h | 14 +++ 7 files changed, 330 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-wilco-ec 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-wilco-ec new file +42 -0
@@ -0,0 +1,42 @@ +What: /sys/bus/platform/devices/GOOG000C\:00/version_label +Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller firmware version label. + Output will a version string be similar to the example below: + 95.00.06 + +What: /sys/bus/platform/devices/GOOG000C\:00/version_svn_revision +Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller SVN revision. + Output will a version string be similar to the example below: + 5960a.06 + +What: /sys/bus/platform/devices/GOOG000C\:00/version_model_number +Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller model number. + Output will a version string be similar to the example below: + 08;8 + +What: /sys/bus/platform/devices/GOOG000C\:00/version_build_date +Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller firmware build date. + Output will a MM/DD/YY string. + +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. + + Input should be parseable by kstrtobool().
drivers/platform/chrome/wilco_ec/Makefile +1 -1
@@ -1,6 +1,6 @@ # 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 wilco_ec_debugfs-objs := debugfs.o obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.o
drivers/platform/chrome/wilco_ec/core.c +12 -0
@@ -101,6 +101,13 @@ static int wilco_ec_probe(struct platform_device *pdev) goto destroy_mec; } +/* Create sysfs attributes for userspace interaction */ + ret =wilco_ec_sysfs_init (ec); +if (ret) { +dev_err (dev,"Failed to create sysfs attributes\n" ); + goto destroy_mec; + } +return 0 ; destroy_mec:
@@ -110,6 +117,11 @@ static int wilco_ec_probe(struct platform_device *pdev)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 +103 -0
103 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/legacy.h new file +79 -0
79 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/sysfs.c new file +79 -0
79 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.321.g9e740568ce-goog
Re: [PATCH v4 5/9] platform/chrome: Add sysfs attributes
Hi Nick,
Missatge de Nick Crews <[email protected]> del dia dc., 23 de gen. 2019 a les 19:38:
Quoted 7 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 6 lines
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
Note that example is not correct with the new attributes.
Quoted 44 lines
Signed-off-by Duncan Laurie <[email protected]>Signed-off-by Nick Crews <[email protected]>---
Changes in v4:
- Move "Add RTC driver" before "Add sysfs attributes" so that it could get accepted earlier, since it is less contentiousChanges in v3:
- explicitly definetoplevel_groupsfrom the start, so adding telem later makes sense
- Break version attribute into individual attributes
- rm unusedWILCO_EC_ATTR_RWmacro
- Moved some #defines fromlegacy.htolegacy.cChanges 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 when init()ing sysfs.../ABI/testing/sysfs-platform-wilco-ec | 42 +++++++ drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/core.c | 12 ++ drivers/platform/chrome/wilco_ec/legacy.c | 103 ++++++++++++++++++ drivers/platform/chrome/wilco_ec/legacy.h | 79 ++++++++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 79 ++++++++++++++ include/linux/platform_data/wilco-ec.h | 14 +++ 7 files changed, 330 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/sysfs-platform-wilco-ec 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-wilco-ec new file +0
-0
Documentation/ABI/testing/sysfs-platform-wilco-ec line 9
Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-wilco-ec new file +9
-0@@ -0,0 +1,42 @@ +What: /sys/bus/platform/devices/GOOG000C\:00/version_label +Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller firmware version label. + Output will a version string be similar to the example below: + 95.00.06 + +What: /sys/bus/platform/devices/GOOG000C\:00/version_svn_revision
nit: don't know why but svn always reminds me to subversion ... I see that you always add the prefix version_, I assume this is to maintain in some way the old directory structure but we cleaned a lot the number of sysfs attributes, so makes sense always add the prefix version_? On some cases looks weird to me. Why not just 'revision' it's short an clear.
Documentation/ABI/testing/sysfs-platform-wilco-ec line 17
Quoted 8 lines
Documentation/ABI/testing/sysfs-platform-wilco-ec new file +8
-0+Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller SVN revision. + Output will a version string be similar to the example below: + 5960a.06 + +What: /sys/bus/platform/devices/GOOG000C\:00/version_model_number
nit: model_number?
Documentation/ABI/testing/sysfs-platform-wilco-ec line 23
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-wilco-ec new file +6
-0+Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller model number. + Output will a version string be similar to the example below: + 08;8
Which format is this? DD/MM?
Documentation/ABI/testing/sysfs-platform-wilco-ec line 25
Quoted 2 lines
Documentation/ABI/testing/sysfs-platform-wilco-ec new file +2
-0+ +What: /sys/bus/platform/devices/GOOG000C\:00/version_build_date
nit: build_date?
Documentation/ABI/testing/sysfs-platform-wilco-ec line 31
Quoted 6 lines
Documentation/ABI/testing/sysfs-platform-wilco-ec new file +6
-0+Date: January 2019 +KernelVersion: 4.19 +Description: + Display Wilco Embedded Controller firmware build date. + Output will a MM/DD/YY string. +
Should match with the above example
Documentation/ABI/testing/sysfs-platform-wilco-ec line 32
Quoted 1 line
Documentation/ABI/testing/sysfs-platform-wilco-ec new file +1
-0+What: /sys/bus/platform/devices/GOOG000C\:00/stealth_mode
I guess that this should go on a separate patch for now, please.
Documentation/ABI/testing/sysfs-platform-wilco-ec line 41
Quoted 9 lines
Documentation/ABI/testing/sysfs-platform-wilco-ec new file +9
-0+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. +
I understand correctly that's a power management feature? What's the use case from userspace point of view?
Quoted 254 lines
Documentation/ABI/testing/sysfs-platform-wilco-ec new file +1
-0+ Input should be parseable by kstrtobool().drivers/platform/chrome/wilco_ec/Makefile +1
-1@@ -1,6 +1,6 @@ # 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 wilco_ec_debugfs-objs := debugfs.o obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.odrivers/platform/chrome/wilco_ec/core.c +12
-0@@ -101,6 +101,13 @@ static int wilco_ec_probe(struct platform_device *pdev) goto destroy_mec; } +/* Create sysfs attributes for userspace interaction */ + ret =wilco_ec_sysfs_init (ec); +if (ret) { +dev_err (dev,"Failed to create sysfs attributes\n" ); + goto destroy_mec; + } +return 0 ; destroy_mec:@@ -110,6 +117,11 @@ static int wilco_ec_probe(struct platform_device *pdev)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 +103
-0@@ -0,0 +1,103 @@ +// 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" + +#define EC_COMMAND_EC_INFO 0x38 +#define EC_INFO_SIZE 9 +#define EC_COMMAND_STEALTH_MODE 0xfc + +#define VERSION_INDEX_LABEL 0 +#define VERSION_INDEX_SVN_REVISION 1 +#define VERSION_INDEX_MODEL_NUMBER 2 +#define VERSION_INDEX_BUILD_DATE 3 + +static ssize_t get_info (struct device *dev,char *buf,u8 index) +{ +struct wilco_ec_device *ec =dev_get_drvdata (dev); +char result[EC_INFO_SIZE ]; +struct wilco_ec_message msg = { + .type =WILCO_EC_MSG_LEGACY , + .command =EC_COMMAND_EC_INFO , + .request_data = &index, + .request_size =sizeof (index), + .response_data = result, + .response_size =EC_INFO_SIZE , + }; +int ret; + + ret =wilco_ec_mailbox (ec, &msg); +if (ret <0 ) +return ret; +if (ret !=EC_INFO_SIZE ) +return -EBADMSG ; + +return scnprintf (buf,PAGE_SIZE ,"%s\n" , result); +} + +ssize_t wilco_ec_version_label_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return get_info (dev, buf,VERSION_INDEX_LABEL ); +} + +ssize_t wilco_ec_version_svn_revision_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return get_info (dev, buf,VERSION_INDEX_SVN_REVISION ); +} + +ssize_t wilco_ec_version_model_number_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return get_info (dev, buf,VERSION_INDEX_MODEL_NUMBER ); +} + +ssize_t wilco_ec_version_build_date_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +return get_info (dev, buf,VERSION_INDEX_BUILD_DATE ); +} + +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 +79
-0@@ -0,0 +1,79 @@ +/* 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> + +/** +* wilco_ec_version_label_show() - Display Wilco EC version label +* @dev: The device underlying the struct wilco_ec_device +* @attr: The attribute being read from +* @buf: Output buffer to fill with the result +* +* Output will a version string be similar to the example below: +* 95.00.06 +*/ +ssize_t wilco_ec_version_label_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +/** +* wilco_ec_version_svn_revision_show() - Display Wilco EC SVN revision +* @dev: The device underlying the struct wilco_ec_device +* @attr: The attribute being read from +* @buf: Output buffer to fill with the result +* +* Output will a version string be similar to the example below: +* 5960a.06 +*/ +ssize_t wilco_ec_version_svn_revision_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +/** +* wilco_ec_version_model_number_show() - Display Wilco EC model number +* @dev: The device underlying the struct wilco_ec_device +* @attr: The attribute being read from +* @buf: Output buffer to fill with the result +* +* Output will a version string be similar to the example below: +* 08;8 +*/ +ssize_t wilco_ec_version_model_number_show (struct device *dev, +struct device_attribute *attr, +char *buf); + +/** +* wilco_ec_version_build_date_show() - Display Wilco EC firmware build date +* @dev: The device underlying the struct wilco_ec_device +* @attr: The attribute being read from +* @buf: Output buffer to fill with the result +* +* Output will a MM/DD/YY string. +*/ +ssize_t wilco_ec_version_build_date_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 +11
-0@@ -0,0 +1,79 @@ +// 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. +*/ +
drivers/platform/chrome/wilco_ec/sysfs.c line 21
Quoted 10 lines
drivers/platform/chrome/wilco_ec/sysfs.c new file +10
-0+#include <linux/ctype.h> +#include <linux/platform_data/wilco-ec.h> +#include <linux/platform_device.h> +#include <linux/sysfs.h> + +#include "legacy.h" + +#define WILCO_EC_ATTR_RO (_name) \ +__ATTR(_name, 0444, wilco_ec_##_name##_show, NULL) +
This is only to add the wilco_ec_ prefix to the attributes, I'd prefer you use the standard ATTR_ attibutes and just name the attributes without the wilco_ec_ prefix.
drivers/platform/chrome/wilco_ec/sysfs.c line 24
Quoted 3 lines
drivers/platform/chrome/wilco_ec/sysfs.c new file +3
-0+#define WILCO_EC_ATTR_WO (_name) \ +__ATTR(_name, 0200, NULL, wilco_ec_##_name##_store) +
ditto
Quoted 79 lines
drivers/platform/chrome/wilco_ec/sysfs.c new file +55
-0+/* Make top-level attributes, which will live inside GOOG000C:00/ */ +static struct device_attribute stealth_attr =WILCO_EC_ATTR_WO (stealth_mode); +static struct device_attribute version_label_attr = +WILCO_EC_ATTR_RO (version_label); +static struct device_attribute version_svn_revision_attr = +WILCO_EC_ATTR_RO (version_svn_revision); +static struct device_attribute version_model_number_attr = +WILCO_EC_ATTR_RO (version_model_number); +static struct device_attribute version_build_date_attr = +WILCO_EC_ATTR_RO (version_build_date); +static struct attribute *wilco_ec_toplevel_attrs[] = { + &version_label_attr.attr, + &version_svn_revision_attr.attr, + &version_model_number_attr.attr, + &version_build_date_attr.attr, + &stealth_attr.attr, +NULL +}; +static const struct attribute_group wilco_ec_toplevel_group = { + .attrs = wilco_ec_toplevel_attrs, +}; +static const struct attribute_group *wilco_ec_toplevel_groups[] = { + &wilco_ec_toplevel_group, +NULL , +}; + +/** +* 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. +*/ +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 ; + +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.321.g9e740568ce-goog
Regards,
Enric
PATCH v4 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 v4: None
Changes in v3:
- change err check from "if (ret < 0)" to "if (ret)"
Changes in v2:
- rm "wilco_ec_event -" prefix from docstring
- rm license boiler plate
- Add sysfs directory documentation
- Fix cosmetics
- events are init()ed before subdrivers now
drivers/platform/chrome/wilco_ec/Makefile | 3 +- drivers/platform/chrome/wilco_ec/core.c | 12 + drivers/platform/chrome/wilco_ec/event.c | 347 ++++++++++++++++++++++ include/linux/platform_data/wilco-ec.h | 34 +++ 4 files changed, 395 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/chrome/wilco_ec/event.c
drivers/platform/chrome/wilco_ec/Makefile +2 -1
@@ -1,6 +1,7 @@ # 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 wilco_ec_debugfs-objs := debugfs.o obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.o
drivers/platform/chrome/wilco_ec/core.c +12 -0
@@ -108,8 +108,17 @@ static int wilco_ec_probe(struct platform_device *pdev) goto destroy_mec; } +/* Prepare to handle events */ + ret =wilco_ec_event_init (ec); +if (ret) { +dev_err (dev,"Failed to setup event handling\n" ); + goto remove_sysfs; + } +return 0 ; +remove_sysfs: +wilco_ec_sysfs_remove (ec); destroy_mec:cros_ec_lpc_mec_destroy ();return ret;
@@ -119,6 +128,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.321.g9e740568ce-goog
Re: [PATCH v4 6/9] platform/chrome: Add event handling
Hi Nick, Duncan,
Quoted 8 lines · Nick Crews
From: 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.
Quoted 7 lines
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.
I thought we agreed that brightness keys will be routed through normal keyboard interface, not separate input device?
Looking at the driver more, I do not see why it needs to be toed to EC, this seems to be a straightforward ACPI driver that should bind to and ACPI device by its HID, since the only thing it does is installing ACPI notify handler and shuffling the events over to userspace.
I do not think we want to use a binary attribute for this, as it does not support polling well and in general is not well suitable for pumping data to userspace. I'd recommend char misc device for that.
What kind of events will be delivered over this interface?
Thanks.
Signature · 1 line
Dmitry
PATCH v4 7/9 platform/chrome: Add EC properties
In reply to Nick CrewsFrom: Nick Crews <[email protected]>
A 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 v4: None
Changes in v3:
- Now bubble up error codes from within sysfs_init()
- Add comment that PID means Property ID
Changes in v2:
- rm license boiler plate
- rm "wilco_ec_properties -" prefix from docstring
- Add documentation
.../ABI/testing/sysfs-platform-wilco-ec | 66 ++++ drivers/platform/chrome/wilco_ec/Makefile | 2 +- drivers/platform/chrome/wilco_ec/properties.c | 344 ++++++++++++++++++ drivers/platform/chrome/wilco_ec/properties.h | 180 +++++++++ drivers/platform/chrome/wilco_ec/sysfs.c | 59 ++- drivers/platform/chrome/wilco_ec/util.h | 38 ++ 6 files changed, 686 insertions(+), 3 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-wilco-ec +66 -0
@@ -40,3 +40,69 @@ Description: In addition Wireless devices are turned off. Input should be parseable by kstrtobool(). + +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. + + Input should be parseable by kstrtobool(). + Output will be either "0\n" or "1\n". + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/fn_lock +Date: January 2019 +KernelVersion: 4.19 +Description: + Fn Toggle - main feature enable/disable setting. + + Input should be parseable by kstrtobool(). + Output will be either "0\n" or "1\n". + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/nic +Date: January 2019 +KernelVersion: 4.19 +Description: + Enable NIC (network interface card) on the dock. + + Input should be parseable by kstrtobool(). + Output will be either "0\n" or "1\n". + +What: /sys/bus/platform/devices/GOOG000C\:00/properties/ext_usb_port_en +Date: January 2019 +KernelVersion: 4.19 +Description: + External USB port enable. + + Input should be parseable by kstrtobool(). + Output will be either "0\n" or "1\n". + +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. + + Input should be parseable by kstrtobool(). + Output will be either "0\n" or "1\n". + +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. + + Input should be parseable by kstrtobool(). + Output will be either "0\n" or "1\n".
drivers/platform/chrome/wilco_ec/Makefile +1 -1
@@ -1,7 +1,7 @@ # 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 wilco_ec_debugfs-objs := debugfs.o obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.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 +180 -0
180 lines not on this page · raw message
drivers/platform/chrome/wilco_ec/sysfs.c +57 -2
90 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.321.g9e740568ce-goog
Re: [PATCH v4 7/9] platform/chrome: Add EC properties
Quoted 21 lines · Nick Crews
From: Nick Crews <[email protected]>
A 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.
Quoted 5 lines
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.
We have proper interfaces for many of the options below (i.e. mic mute led can be expressed via LED subsystem and controlled via /sys/class/led/...), wlan is should be controlled by rfkil if we decide to go that road, etc.
Thanks.
Signature · 1 line
Dmitry
PATCH v4 8/9 platform/chrome: Add peakshift and adv_batt_charging
In reply to Nick CrewsFrom: Nick Crews <[email protected]>
Create "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 v4: None
Changes in v3:
- rm some useless references to internal docs from documentation
Changes in v2:
- rm license boiler plate
- rm "wilco_ec_adv_power - " prefix from docstring
- Add documentation
- make format strings in read() and store() functions static
.../ABI/testing/sysfs-platform-wilco-ec | 88 +++ 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 | 104 ++++ 5 files changed, 920 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-wilco-ec +88 -0
@@ -106,3 +106,91 @@ Description: Input should be parseable by kstrtobool(). Output will be either "0\n" or "1\n". + +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. + + Input should be parseable by kstrtobool(). + Output will be either "0\n" or "1\n". + +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]. + + Input should be parseable to range [15,50] by kstrtou8(). + Output will be two-digit ascii number in range [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. + + 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. + + Input should be parseable by kstrtobool(). + Output will be either "0\n" or "1\n". + +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 +1 -1
@@ -1,7 +1,7 @@ # 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 wilco_ec_debugfs-objs := debugfs.o obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.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 +104 -0
131 lines not on this page · raw message
Signature · 1 line
2.20.1.321.g9e740568ce-goog
PATCH v4 9/9 platform/chrome: Add binary telemetry attributes
In reply to Nick CrewsFrom: Nick Crews <[email protected]>
The Wilco Embedded Controller is able to send telemetry data which is useful for enterprise applications. A daemon running on the OS sends a command (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 v4: None
Changes in v3:
- add err check on returned data size
- add check on read request offset and size
Changes in v2: None
drivers/platform/chrome/wilco_ec/Makefile | 3 +- drivers/platform/chrome/wilco_ec/sysfs.c | 7 ++ drivers/platform/chrome/wilco_ec/telemetry.c | 73 ++++++++++++++++++++ drivers/platform/chrome/wilco_ec/telemetry.h | 41 +++++++++++ 4 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/chrome/wilco_ec/telemetry.c create mode 100644 drivers/platform/chrome/wilco_ec/telemetry.h
drivers/platform/chrome/wilco_ec/Makefile +2 -1
@@ -1,7 +1,8 @@ # 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 wilco_ec_debugfs-objs := debugfs.o obj-$(CONFIG_WILCO_EC_DEBUGFS) += wilco_ec_debugfs.o
drivers/platform/chrome/wilco_ec/sysfs.c +7 -0
@@ -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)
@@ -42,8 +43,14 @@ static struct attribute *wilco_ec_toplevel_attrs[] = { &stealth_attr.attr,NULL }; +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,
drivers/platform/chrome/wilco_ec/telemetry.c new file +73 -0
73 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.321.g9e740568ce-goog