Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7530279imu; Tue, 22 Jan 2019 07:28:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN6cONB7r/NCAKW9hyITBevQWhj8MWG+Z17arYiF7IcPoSZqtwNS7iKFyMyNkFoP0Oc668/X X-Received: by 2002:a63:151f:: with SMTP id v31mr31831440pgl.34.1548170911703; Tue, 22 Jan 2019 07:28:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548170911; cv=none; d=google.com; s=arc-20160816; b=kXBJ8FatqgJsP0Nihuo7rp9QkjE4csYmIN1+4zpjiOj6N2Q0A9Y5HVCOkUctJOFJk8 qZZCTgdsMkkQMnKlyGicGXLE247M2G/rQizVFsPEvtwpFLWXuULsv2qm8yFivtvE2N15 35sb1fYT2TcLRtOzZp/Q6Fn4lkszAmWuTljn/FkS0vJfpoMzvWMD8rKnUW+zxa5MTUK/ BxaWtZdlxPgQHxcAjOl+3VeRWjf6nvy4DviEQnTQtOZb/uP6Ox/kVLluKTtA8B3ZcDN8 QJNA7ebSkB3GBpT5c6y0OFkaqTyCyOwC0qhgX7sknZ6x0aOfYmNOuDZ/T6ugucs9YpKN CsKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Ji37CWdDOCHmNeK85MzVTCmguGJDIIO9lJ5bDy4pIys=; b=JaVGqE3JK3igfLtE8Tg4hF2ua/aNhyvQckBKuGcAJ48qO+49fZ/eUtg8WBEdbIO/aZ QXxBNi5wZATFVaVw9Bx4jsISV4tSVhhGOP/yngBXfwTHv6WPG5lWS4QPYRrbq3qG72YO 9/stONuvoQKeQdQkMXQYKRwqYtZAEGwGSJzdJGc84zBIFSrsXYZWOFggFI+li7hNgfJh mtIEs9GdUWjiCQmdmWLipI1zSoSzy7pHhPHt8cE2+7oqFwvnOqcwbkFHDlfC0gpaRtAt 1vNep6CyDIuxtLoj9gHByVUMI7++X9Figjv2tTSpv0Aff9RLL/AJ4JC0LcX1WEJfygMr AzDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cHI2EPPL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w185si15396527pfw.122.2019.01.22.07.28.15; Tue, 22 Jan 2019 07:28:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cHI2EPPL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729957AbfAVP0V (ORCPT + 99 others); Tue, 22 Jan 2019 10:26:21 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:46348 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729908AbfAVP0T (ORCPT ); Tue, 22 Jan 2019 10:26:19 -0500 Received: by mail-qk1-f194.google.com with SMTP id q1so14399160qkf.13; Tue, 22 Jan 2019 07:26:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ji37CWdDOCHmNeK85MzVTCmguGJDIIO9lJ5bDy4pIys=; b=cHI2EPPLnRXOx0B6RXuXIgmMeQFpyesIcDZWcryea/++abq4OMzFdgJGCSUBjJDoQK z1E2M8d44cQ28eWYJ38mq8bw4E8fqmy01UTXOSZxZVKQIfEjEf7hBIqb/nHd6LSrkOXg n50avVj2V0Y1DVh5Sw5cm0bBe5+M2Dw3PTn2yXKgdiOpVBN5b1JTCktlVJdN2j7AF6Zd IXr8E1KILnD1iLz5VKPVCUABmiAfXd7UZB5uEDoNqv5CL5QtRkkrEKDcQxdkIHIAIE1g XaWHw+Q/MY7qgx604FI6WURQqnsHUv2A4NCfCVhKnqsw/O0djHr9LYGavSTMd2Qs4ABS cPcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ji37CWdDOCHmNeK85MzVTCmguGJDIIO9lJ5bDy4pIys=; b=D+KHHXO5/Z4sG1iUqrnDZ8nxsw8ebEMDdxzfhgHXi+IKgb3gJnAudlnZB2p2iPXcB8 BUPrOn8CeOO5sS4wktgMdnWNVb1QQMFq6x8LM0WdbsHMU1hK76DwQo0g1hAfLrC+qv7T d6R+bqqkMblrcKR5b9cPGVvooPCP3qbOQAkhvjbZ+VFtnCZYcvlKJBKJERbtPmdhtXLd ZkbcZ0zN9mQBjj3TT8QfPHShJRYe+k6Lq7/VzbutEWvDZGbG5meglLDp3cVpRvoiLRGH tVSiNuzhbaen+soTXBKaMXHTX80NGt6+/8hF9jsPrInU7O6P+2mhVTMIavKG/VzFLtM+ vLtQ== X-Gm-Message-State: AJcUukclpBTtR2KLBitUIlQGFvCLRIDSprnDUPXqt9pZYemw9MO0CKW5 ELGhUYPq7/6Gfi0Syg8ytfpdLgo/Q3CSK5SJuhI= X-Received: by 2002:a37:cf9b:: with SMTP id v27mr28020588qkl.160.1548170777589; Tue, 22 Jan 2019 07:26:17 -0800 (PST) MIME-Version: 1.0 References: <20190119001422.48186-1-ncrews@chromium.org> In-Reply-To: <20190119001422.48186-1-ncrews@chromium.org> From: Enric Balletbo Serra Date: Tue, 22 Jan 2019 16:26:06 +0100 Message-ID: Subject: Re: [PATCH v3 0/9] platform/chrome: rtc: Add support for Wilco EC To: Nick Crews Cc: linux-kernel , Guenter Roeck , Simon Glass , Daniel Kurtz , dlaurie@chromium.org, linux-rtc@vger.kernel.org, Enric Balletbo i Serra , Alessandro Zummo , Benson Leung , Nick Crews , Duncan Laurie , Alexandre Belloni Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Nick, Missatge de Nick Crews del dia ds., 19 de gen. 2019 a les 1:17: > > > 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 which can write/read arbitrary > bytes to/from the eSPI bus. > > We attempted to adhere to the sysfs principles of "one piece of data per > attribute" as much as possible, and mostly succeded. However, with the > wilco_ec/adv_power.h attributes, which deal with scheduling power usage, > we found it most elegant to bundle setting event times for an entire day > into a single attribute, so at most you are using attributes formatted > as "%d %d %d %d %d %d". With the telemetry attribute, we had to use a > binary attribute, instead of the preferable human-readable ascii, in > order to keep secure the information which is proprietary to the > enterprise service provider. This opaque binary data will be read and > sent using a proprietary daemon running on the OS. > I reviewed some patches of these series and I think that some of them are already close to be accepted, however, I still have several doubts regarding the bunch of sysfs attributes/properties. It is clear for me that some of them (like the version ones) fit into the sysfs, but I have several doubts with the power and telemetry attributes, looks to me that we're abusing of the sysfs interface. I am wondering if wouldn't be better use a simple ioctl functions that reads and writes to a chardev (/dev/wilco_ec). Did you think on that possibility? What people think? Thanks, Enric > 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 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 > - 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 > - 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 > - 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 > - 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 license boiler plate > - rm "wilco_ec_rtc -" prefix in docstring > - Make rtc driver its own module within the drivers/rtc/ directory > - Register a rtc device from core.c that is picked up by this driver > - rm "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): > platform/chrome: 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: Add sysfs attributes > platform/chrome: rtc: Add RTC driver > 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 | 33 ++ > drivers/platform/chrome/wilco_ec/Makefile | 6 + > drivers/platform/chrome/wilco_ec/adv_power.c | 544 ++++++++++++++++++ > drivers/platform/chrome/wilco_ec/adv_power.h | 183 ++++++ > drivers/platform/chrome/wilco_ec/core.c | 154 +++++ > drivers/platform/chrome/wilco_ec/debugfs.c | 218 +++++++ > 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 | 189 ++++++ > 27 files changed, 3509 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 > > -- > 2.20.1.321.g9e740568ce-goog >