Skip to content

Commit

Permalink
Merge tag 'tag-chrome-platform-for-v5.2' of ssh://gitolite.kernel.org…
Browse files Browse the repository at this point in the history
…/pub/scm/linux/kernel/git/chrome-platform/linux

Pull chrome platform updates from Benson Leung:
 "CrOS EC:
   - Add EC host command support using rpmsg
   - Add new CrOS USB PD logging driver
   - Transfer spi messages at high priority
   - Add support to trace CrOS EC commands
   - Minor fixes and cleanups in protocol and debugfs

  Wilco EC:
   - Standardize Wilco EC mailbox interface
   - Add h1_gpio status to debugfs"

* tag 'tag-chrome-platform-for-v5.2' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux:
  platform/chrome: cros_ec_proto: Add trace event to trace EC commands
  platform/chrome: cros_ec_debugfs: Use cros_ec_cmd_xfer_status helper
  platform/chrome: cros_ec: Add EC host command support using rpmsg
  platform/chrome: wilco_ec: Add h1_gpio status to debugfs
  platform/chrome: wilco_ec: Standardize mailbox interface
  platform/chrome: cros_ec_proto: check for NULL transfer function
  platform/chrome: Add CrOS USB PD logging driver
  platform/chrome: cros_ec_spi: Transfer messages at high priority
  platform/chrome: cros_ec_debugfs: no need to check return value of debugfs_create functions
  platform/chrome: cros_ec_debugfs: Remove dev_warn when console log is not supported
  • Loading branch information
torvalds committed May 12, 2019
2 parents 8148c17 + 58a2109 commit 4778236
Show file tree
Hide file tree
Showing 14 changed files with 984 additions and 183 deletions.
45 changes: 34 additions & 11 deletions Documentation/ABI/testing/debugfs-wilco-ec
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
What: /sys/kernel/debug/wilco_ec/h1_gpio
Date: April 2019
KernelVersion: 5.2
Description:
As part of Chrome OS's FAFT (Fully Automated Firmware Testing)
tests, we need to ensure that the H1 chip is properly setting
some GPIO lines. The h1_gpio attribute exposes the state
of the lines:
- ENTRY_TO_FACT_MODE in BIT(0)
- SPI_CHROME_SEL in BIT(1)

Output will formatted with "0x%02x\n".

What: /sys/kernel/debug/wilco_ec/raw
Date: January 2019
KernelVersion: 5.1
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
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.

At least three bytes are required, for the msg type and command,
with additional bytes optional for additional data.
For writing, bytes 0-1 indicate the message type, one of enum
wilco_ec_msg_type. Byte 2+ consist of the data passed in the
request, starting at MBOX[0]

At least three bytes are required for writing, two for the type
and at least a single byte of data. Only the first
EC_MAILBOX_DATA_SIZE bytes of MBOX will be used.

Example:
// Request EC info type 3 (EC firmware build date)
$ echo 00 f0 38 00 03 00 > raw
// Corresponds with sending type 0x00f0 with
// MBOX = [38, 00, 03, 00]
$ echo 00 f0 38 00 03 00 > /sys/kernel/debug/wilco_ec/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...
// Corresponds with MBOX = [00, 00, 31, 32, 2f, 32, 31, 38, ...]
$ cat /sys/kernel/debug/wilco_ec/raw
00 00 31 32 2f 32 31 2f 31 38 00 38 00 01 00 2f 00 ..12/21/18.8...

Note that the first 32 bytes of the received MBOX[] will be
printed, even if some of the data is junk. It is up to you to
know how many of the first bytes of data are the actual
response.
24 changes: 24 additions & 0 deletions drivers/platform/chrome/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ config CROS_EC_I2C
a checksum. Failing accesses will be retried three times to
improve reliability.

config CROS_EC_RPMSG
tristate "ChromeOS Embedded Controller (rpmsg)"
depends on MFD_CROS_EC && RPMSG && OF
help
If you say Y here, you get support for talking to the ChromeOS EC
through rpmsg. This uses a simple byte-level protocol with a
checksum. Also since there's no addition EC-to-host interrupt, this
use a byte in message to distinguish host event from host command.

To compile this driver as a module, choose M here: the
module will be called cros_ec_rpmsg.

config CROS_EC_SPI
tristate "ChromeOS Embedded Controller (SPI)"
depends on MFD_CROS_EC && SPI
Expand Down Expand Up @@ -152,6 +164,18 @@ config CROS_EC_SYSFS
To compile this driver as a module, choose M here: the
module will be called cros_ec_sysfs.

config CROS_USBPD_LOGGER
tristate "Logging driver for USB PD charger"
depends on CHARGER_CROS_USBPD
default y
select RTC_LIB
help
This option enables support for logging event data for the USB PD charger
available in the Embedded Controller on ChromeOS systems.

To compile this driver as a module, choose M here: the
module will be called cros_usbpd_logger.

source "drivers/platform/chrome/wilco_ec/Kconfig"

endif # CHROMEOS_PLATFORMS
7 changes: 6 additions & 1 deletion drivers/platform/chrome/Makefile
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# SPDX-License-Identifier: GPL-2.0

# tell define_trace.h where to find the cros ec trace header
CFLAGS_cros_ec_trace.o:= -I$(src)

obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o
obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o
obj-$(CONFIG_CHROMEOS_TBMC) += chromeos_tbmc.o
obj-$(CONFIG_CROS_EC_I2C) += cros_ec_i2c.o
obj-$(CONFIG_CROS_EC_RPMSG) += cros_ec_rpmsg.o
obj-$(CONFIG_CROS_EC_SPI) += cros_ec_spi.o
cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_reg.o
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_EC_PROTO) += cros_ec_proto.o cros_ec_trace.o
obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o
obj-$(CONFIG_CROS_EC_LIGHTBAR) += cros_ec_lightbar.o
obj-$(CONFIG_CROS_EC_VBC) += cros_ec_vbc.o
obj-$(CONFIG_CROS_EC_DEBUGFS) += cros_ec_debugfs.o
obj-$(CONFIG_CROS_EC_SYSFS) += cros_ec_sysfs.o
obj-$(CONFIG_CROS_USBPD_LOGGER) += cros_usbpd_logger.o

obj-$(CONFIG_WILCO_EC) += wilco_ec/
74 changes: 19 additions & 55 deletions drivers/platform/chrome/cros_ec_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,9 @@ static void cros_ec_console_log_work(struct work_struct *__work)
int buf_space;
int ret;

ret = cros_ec_cmd_xfer(ec->ec_dev, &snapshot_msg);
if (ret < 0) {
dev_err(ec->dev, "EC communication failed\n");
goto resched;
}
if (snapshot_msg.result != EC_RES_SUCCESS) {
dev_err(ec->dev, "EC failed to snapshot the console log\n");
ret = cros_ec_cmd_xfer_status(ec->ec_dev, &snapshot_msg);
if (ret < 0)
goto resched;
}

/* Loop until we have read everything, or there's an error. */
mutex_lock(&debug_info->log_mutex);
Expand All @@ -95,16 +89,10 @@ static void cros_ec_console_log_work(struct work_struct *__work)

memset(read_params, '\0', sizeof(*read_params));
read_params->subcmd = CONSOLE_READ_RECENT;
ret = cros_ec_cmd_xfer(ec->ec_dev, debug_info->read_msg);
if (ret < 0) {
dev_err(ec->dev, "EC communication failed\n");
break;
}
if (debug_info->read_msg->result != EC_RES_SUCCESS) {
dev_err(ec->dev,
"EC failed to read the console log\n");
ret = cros_ec_cmd_xfer_status(ec->ec_dev,
debug_info->read_msg);
if (ret < 0)
break;
}

/* If the buffer is empty, we're done here. */
if (ret == 0 || ec_buffer[0] == '\0')
Expand Down Expand Up @@ -290,9 +278,8 @@ static int ec_read_version_supported(struct cros_ec_dev *ec)
params->cmd = EC_CMD_CONSOLE_READ;
response = (struct ec_response_get_cmd_versions *)msg->data;

ret = cros_ec_cmd_xfer(ec->ec_dev, msg) >= 0 &&
msg->result == EC_RES_SUCCESS &&
(response->version_mask & EC_VER_MASK(1));
ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg) >= 0 &&
response->version_mask & EC_VER_MASK(1);

kfree(msg);

Expand All @@ -306,11 +293,12 @@ static int cros_ec_create_console_log(struct cros_ec_debugfs *debug_info)
int read_params_size;
int read_response_size;

if (!ec_read_version_supported(ec)) {
dev_warn(ec->dev,
"device does not support reading the console log\n");
/*
* If the console log feature is not supported return silently and
* don't create the console_log entry.
*/
if (!ec_read_version_supported(ec))
return 0;
}

buf = devm_kzalloc(ec->dev, LOG_SIZE, GFP_KERNEL);
if (!buf)
Expand All @@ -336,12 +324,8 @@ static int cros_ec_create_console_log(struct cros_ec_debugfs *debug_info)
mutex_init(&debug_info->log_mutex);
init_waitqueue_head(&debug_info->log_wq);

if (!debugfs_create_file("console_log",
S_IFREG | 0444,
debug_info->dir,
debug_info,
&cros_ec_console_log_fops))
return -ENOMEM;
debugfs_create_file("console_log", S_IFREG | 0444, debug_info->dir,
debug_info, &cros_ec_console_log_fops);

INIT_DELAYED_WORK(&debug_info->log_poll_work,
cros_ec_console_log_work);
Expand Down Expand Up @@ -375,9 +359,8 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
msg->command = EC_CMD_GET_PANIC_INFO;
msg->insize = insize;

ret = cros_ec_cmd_xfer(ec_dev, msg);
ret = cros_ec_cmd_xfer_status(ec_dev, msg);
if (ret < 0) {
dev_warn(debug_info->ec->dev, "Cannot read panicinfo.\n");
ret = 0;
goto free;
}
Expand All @@ -389,13 +372,8 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
debug_info->panicinfo_blob.data = msg->data;
debug_info->panicinfo_blob.size = ret;

if (!debugfs_create_blob("panicinfo",
S_IFREG | 0444,
debug_info->dir,
&debug_info->panicinfo_blob)) {
ret = -ENOMEM;
goto free;
}
debugfs_create_blob("panicinfo", S_IFREG | 0444, debug_info->dir,
&debug_info->panicinfo_blob);

return 0;

Expand All @@ -404,15 +382,6 @@ static int cros_ec_create_panicinfo(struct cros_ec_debugfs *debug_info)
return ret;
}

static int cros_ec_create_pdinfo(struct cros_ec_debugfs *debug_info)
{
if (!debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info,
&cros_ec_pdinfo_fops))
return -ENOMEM;

return 0;
}

static int cros_ec_debugfs_probe(struct platform_device *pd)
{
struct cros_ec_dev *ec = dev_get_drvdata(pd->dev.parent);
Expand All @@ -427,8 +396,6 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)

debug_info->ec = ec;
debug_info->dir = debugfs_create_dir(name, NULL);
if (!debug_info->dir)
return -ENOMEM;

ret = cros_ec_create_panicinfo(debug_info);
if (ret)
Expand All @@ -438,18 +405,15 @@ static int cros_ec_debugfs_probe(struct platform_device *pd)
if (ret)
goto remove_debugfs;

ret = cros_ec_create_pdinfo(debug_info);
if (ret)
goto remove_log;
debugfs_create_file("pdinfo", 0444, debug_info->dir, debug_info,
&cros_ec_pdinfo_fops);

ec->debug_info = debug_info;

dev_set_drvdata(&pd->dev, ec);

return 0;

remove_log:
cros_ec_cleanup_console_log(debug_info);
remove_debugfs:
debugfs_remove_recursive(debug_info->dir);
return ret;
Expand Down
15 changes: 15 additions & 0 deletions drivers/platform/chrome/cros_ec_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <linux/slab.h>
#include <asm/unaligned.h>

#include "cros_ec_trace.h"

#define EC_COMMAND_RETRIES 50

static int prepare_packet(struct cros_ec_device *ec_dev,
Expand Down Expand Up @@ -51,11 +53,24 @@ static int send_command(struct cros_ec_device *ec_dev,
int ret;
int (*xfer_fxn)(struct cros_ec_device *ec, struct cros_ec_command *msg);

trace_cros_ec_cmd(msg);

if (ec_dev->proto_version > 2)
xfer_fxn = ec_dev->pkt_xfer;
else
xfer_fxn = ec_dev->cmd_xfer;

if (!xfer_fxn) {
/*
* This error can happen if a communication error happened and
* the EC is trying to use protocol v2, on an underlying
* communication mechanism that does not support v2.
*/
dev_err_once(ec_dev->dev,
"missing EC transfer API, cannot send command\n");
return -EIO;
}

ret = (*xfer_fxn)(ec_dev, msg);
if (msg->result == EC_RES_IN_PROGRESS) {
int i;
Expand Down
Loading

0 comments on commit 4778236

Please sign in to comment.