From f70f276a2e910c69d11b038a7df3de9d08f10b8b Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Wed, 19 Aug 2015 13:19:54 +0200 Subject: Revert "platform/chrome: Don't make CHROME_PLATFORMS depends on X86 || ARM" This reverts commit d12bbcd3ea44 ("platform/chrome: Don't make CHROME_PLATFORMS depends on X86 || ARM") since it was found to not be the correct fix for the MFD_CROS_EC config unmet direct dependencies warning. The correct solution was to add the needed dependencies to the MFD_CROS_EC symbol. Besides the revert, this patch extends the CHROME_PLATFORMS symbol dependencies and adds || COMPILE_TEST to allow drivers to have build coverage on other architectures. Suggested-by: Geert Uytterhoeven Signed-off-by: Javier Martinez Canillas Signed-off-by: Olof Johansson --- drivers/platform/chrome/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 3271cd1abe7c..21f4ea6c6c21 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -4,6 +4,7 @@ menuconfig CHROME_PLATFORMS bool "Platform support for Chrome hardware" + depends on X86 || ARM || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for various Chromebooks and Chromeboxes. This option alone does -- cgit v1.2.3-59-g8ed1b From 75529a9d427500f1b7deb3d0dec5c8d0a61fee02 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Wed, 19 Aug 2015 13:19:55 +0200 Subject: platform/chrome: Make depends on MFD_CROS_EC instead CROS_EC_PROTO The ChromeOS EC LPC and chardev drivers depend on CROS_EC_PROTO but MFD_CROS_EC select CROS_EC_PROTO instead. Mixing select and depends on is bad practice as it may lead to circular Kconfig dependencies. Since the platform devices that are matched with these drivers are registered by the ChromeOS EC mfd driver, they really depend on MFD_CROS_EC. And because this config option selects CROS_EC_PROTO, that dependency is met as well. So make the drivers to depend on MFD_CROS_EC instead of CROS_EC_PROTO. Signed-off-by: Javier Martinez Canillas Signed-off-by: Olof Johansson --- drivers/platform/chrome/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index 21f4ea6c6c21..fde1129501f5 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -40,7 +40,7 @@ config CHROMEOS_PSTORE config CROS_EC_CHARDEV tristate "Chrome OS Embedded Controller userspace device interface" - depends on CROS_EC_PROTO + depends on MFD_CROS_EC ---help--- This driver adds support to talk with the ChromeOS EC from userspace. @@ -49,7 +49,7 @@ config CROS_EC_CHARDEV config CROS_EC_LPC tristate "ChromeOS Embedded Controller (LPC)" - depends on MFD_CROS_EC && CROS_EC_PROTO && (X86 || COMPILE_TEST) + depends on MFD_CROS_EC && (X86 || COMPILE_TEST) help If you say Y here, you get support for talking to the ChromeOS EC over an LPC bus. This uses a simple byte-level protocol with a -- cgit v1.2.3-59-g8ed1b From fbf40727c781a3b8562e76a86cd08a111414d1c7 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 22 Jun 2015 08:27:18 +0200 Subject: platform/chrome: cros_ec_lpc - Use existing function to check EC result Commit 6db07b633658 ("mfd: cros_ec: Check result code from EC messages") added a common cros_ec_check_result() function that can be used to check the ec_msg->result for errors and warns about them. Use the existing function instead of duplicating same check in the driver. Signed-off-by: Javier Martinez Canillas Reviewed-by: Gwendal Grignou Tested-by: Gwendal Grignou Signed-off-by: Olof Johansson --- drivers/platform/chrome/cros_ec_lpc.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index bdd77ce45f05..ca7cdc6eef0b 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -166,19 +166,9 @@ static int cros_ec_cmd_xfer_lpc(struct cros_ec_device *ec, /* Check result */ msg->result = inb(EC_LPC_ADDR_HOST_DATA); - - switch (msg->result) { - case EC_RES_SUCCESS: - break; - case EC_RES_IN_PROGRESS: - ret = -EAGAIN; - dev_dbg(ec->dev, "command 0x%02x in progress\n", - msg->command); + ret = cros_ec_check_result(ec, msg); + if (ret) goto done; - default: - dev_dbg(ec->dev, "command 0x%02x returned %d\n", - msg->command, msg->result); - } /* Read back args */ args.flags = inb(EC_LPC_ADDR_HOST_ARGS); -- cgit v1.2.3-59-g8ed1b From 85bba84ead5cec41add1cbdb2978e572add10deb Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 22 Jun 2015 08:27:19 +0200 Subject: platform/chrome: cros_ec_lpc - Add support for Google Pixel 2 Since the verion of ACPI in Google BIOS does not enumerate the devices in the LPC bus, the cros_ec_lpc driver resorts to DMI data to check if a system is supported by the driver and autoload if built as a module. Add information about the Google Pixel 2 to the DMI device table. Signed-off-by: Javier Martinez Canillas Signed-off-by: Olof Johansson --- drivers/platform/chrome/cros_ec_lpc.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers') diff --git a/drivers/platform/chrome/cros_ec_lpc.c b/drivers/platform/chrome/cros_ec_lpc.c index ca7cdc6eef0b..f9a245465fd0 100644 --- a/drivers/platform/chrome/cros_ec_lpc.c +++ b/drivers/platform/chrome/cros_ec_lpc.c @@ -319,6 +319,13 @@ static struct dmi_system_id cros_ec_lpc_dmi_table[] __initdata = { DMI_MATCH(DMI_PRODUCT_NAME, "Link"), }, }, + { + /* x86-samus, the Chromebook Pixel 2. */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "GOOGLE"), + DMI_MATCH(DMI_PRODUCT_NAME, "Samus"), + }, + }, { /* x86-peppy, the Acer C720 Chromebook. */ .matches = { -- cgit v1.2.3-59-g8ed1b From afbf8ec7c4f90ddd3ee8655c591983fb9d399f43 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 22 Jun 2015 08:27:20 +0200 Subject: platform/chrome: cros_ec_dev - Add a platform device ID table If the cros_ec_dev driver is built as a module, modalias information is not filled so the module is not autoloaded. Add a platform device table and use the MODULE_DEVICE_TABLE() macro to export that information in the module so user-space can match the modalias uevent and autoload it. Signed-off-by: Javier Martinez Canillas Signed-off-by: Olof Johansson --- drivers/platform/chrome/cros_ec_dev.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers') diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c index e8fcdc237029..2f4099820480 100644 --- a/drivers/platform/chrome/cros_ec_dev.c +++ b/drivers/platform/chrome/cros_ec_dev.c @@ -287,6 +287,12 @@ static int ec_device_remove(struct platform_device *pdev) return 0; } +static const struct platform_device_id cros_ec_id[] = { + { "cros-ec-ctl", 0 }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(platform, cros_ec_id); + static struct platform_driver cros_ec_dev_driver = { .driver = { .name = "cros-ec-ctl", -- cgit v1.2.3-59-g8ed1b From 23ecee32b91cf732226bd7a3ee9fa7a9127645ab Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Wed, 1 Jul 2015 12:46:42 +0200 Subject: platform/chrome: Enable Chrome platforms on 64-bit ARM With Chrome running on 64-bit ARM devices, add ARM64 to the list of supported architectures. Signed-off-by: Thierry Reding [olof; Fixed up due to addition of COMPILE_TEST] Signed-off-by: Olof Johansson --- drivers/platform/chrome/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kconfig index fde1129501f5..d03df4a60d05 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -4,7 +4,7 @@ menuconfig CHROME_PLATFORMS bool "Platform support for Chrome hardware" - depends on X86 || ARM || COMPILE_TEST + depends on X86 || ARM || ARM64 || COMPILE_TEST ---help--- Say Y here to get to see options for platform support for various Chromebooks and Chromeboxes. This option alone does -- cgit v1.2.3-59-g8ed1b From 88dfb8b43d557ee9b1c1ffd2c8d275dd479a66d4 Mon Sep 17 00:00:00 2001 From: Christian Engelmayer Date: Sat, 18 Jul 2015 19:30:33 +0200 Subject: platform/chrome: cros_ec: Fix leak in sequence_store() The allocated cros_ec_command message structure is not freed in function sequence_store(). Make sure that 'msg' is freed in all exit paths. Detected by Coverity CID 1309667. Signed-off-by: Christian Engelmayer Signed-off-by: Olof Johansson --- drivers/platform/chrome/cros_ec_lightbar.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c index 144e09df9b84..fc30a991b738 100644 --- a/drivers/platform/chrome/cros_ec_lightbar.c +++ b/drivers/platform/chrome/cros_ec_lightbar.c @@ -352,10 +352,6 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr, struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev, class_dev); - msg = alloc_lightbar_cmd_msg(ec); - if (!msg) - return -ENOMEM; - for (len = 0; len < count; len++) if (!isalnum(buf[len])) break; @@ -370,21 +366,30 @@ static ssize_t sequence_store(struct device *dev, struct device_attribute *attr, return ret; } + msg = alloc_lightbar_cmd_msg(ec); + if (!msg) + return -ENOMEM; + param = (struct ec_params_lightbar *)msg->data; param->cmd = LIGHTBAR_CMD_SEQ; param->seq.num = num; ret = lb_throttle(); if (ret) - return ret; + goto exit; ret = cros_ec_cmd_xfer(ec->ec_dev, msg); if (ret < 0) - return ret; + goto exit; - if (msg->result != EC_RES_SUCCESS) - return -EINVAL; + if (msg->result != EC_RES_SUCCESS) { + ret = -EINVAL; + goto exit; + } - return count; + ret = count; +exit: + kfree(msg); + return ret; } /* Module initialization */ -- cgit v1.2.3-59-g8ed1b From f14ae099bdad32414ad968909973bfade9b37967 Mon Sep 17 00:00:00 2001 From: Christian Engelmayer Date: Sun, 19 Jul 2015 21:43:02 +0200 Subject: platform/chrome: cros_ec: Fix possible leak in led_rgb_store() Function led_rgb_store() contains some direct returns in error cases that leak the already allocated cros_ec_command message structure. Make sure that 'msg' is freed in all exit paths. Detected by Coverity CID 1309666. Signed-off-by: Christian Engelmayer Signed-off-by: Olof Johansson --- drivers/platform/chrome/cros_ec_lightbar.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/platform/chrome/cros_ec_lightbar.c b/drivers/platform/chrome/cros_ec_lightbar.c index fc30a991b738..ff7640575c75 100644 --- a/drivers/platform/chrome/cros_ec_lightbar.c +++ b/drivers/platform/chrome/cros_ec_lightbar.c @@ -252,7 +252,7 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr, ret = sscanf(buf, "%i", &val[i++]); if (ret == 0) - return -EINVAL; + goto exit; if (i == 4) { param = (struct ec_params_lightbar *)msg->data; @@ -268,17 +268,15 @@ static ssize_t led_rgb_store(struct device *dev, struct device_attribute *attr, if ((j++ % 4) == 0) { ret = lb_throttle(); if (ret) - return ret; + goto exit; } ret = cros_ec_cmd_xfer(ec->ec_dev, msg); if (ret < 0) goto exit; - if (msg->result != EC_RES_SUCCESS) { - ret = -EINVAL; + if (msg->result != EC_RES_SUCCESS) goto exit; - } i = 0; ok = 1; -- cgit v1.2.3-59-g8ed1b From 18800fc7a04e7df8a345e7ef4fc3064368276f83 Mon Sep 17 00:00:00 2001 From: Emilio López Date: Mon, 21 Sep 2015 10:38:22 -0300 Subject: platform/chrome: Support reading/writing the vboot context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some EC implementations include a small nvram space used to store verified boot context data. This patch offers a way to expose this data to userspace. Reviewed-by: Javier Martinez Canillas Signed-off-by: Emilio López Signed-off-by: Olof Johansson --- drivers/platform/chrome/Makefile | 3 +- drivers/platform/chrome/cros_ec_dev.c | 1 + drivers/platform/chrome/cros_ec_vbc.c | 137 ++++++++++++++++++++++++++++++++++ include/linux/mfd/cros_ec.h | 1 + 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 drivers/platform/chrome/cros_ec_vbc.c (limited to 'drivers') diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Makefile index 4a11b010f5d8..bc498bda8211 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -1,7 +1,8 @@ obj-$(CONFIG_CHROMEOS_LAPTOP) += chromeos_laptop.o obj-$(CONFIG_CHROMEOS_PSTORE) += chromeos_pstore.o -cros_ec_devs-objs := cros_ec_dev.o cros_ec_sysfs.o cros_ec_lightbar.o +cros_ec_devs-objs := cros_ec_dev.o cros_ec_sysfs.o \ + cros_ec_lightbar.o cros_ec_vbc.o obj-$(CONFIG_CROS_EC_CHARDEV) += cros_ec_devs.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpc.o obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o diff --git a/drivers/platform/chrome/cros_ec_dev.c b/drivers/platform/chrome/cros_ec_dev.c index 2f4099820480..d45cd254ed1c 100644 --- a/drivers/platform/chrome/cros_ec_dev.c +++ b/drivers/platform/chrome/cros_ec_dev.c @@ -32,6 +32,7 @@ static int ec_major; static const struct attribute_group *cros_ec_groups[] = { &cros_ec_attr_group, &cros_ec_lightbar_attr_group, + &cros_ec_vbc_attr_group, NULL, }; diff --git a/drivers/platform/chrome/cros_ec_vbc.c b/drivers/platform/chrome/cros_ec_vbc.c new file mode 100644 index 000000000000..564a0d08c8bf --- /dev/null +++ b/drivers/platform/chrome/cros_ec_vbc.c @@ -0,0 +1,137 @@ +/* + * cros_ec_vbc - Expose the vboot context nvram to userspace + * + * Copyright (C) 2015 Collabora Ltd. + * + * based on vendor driver, + * + * Copyright (C) 2012 The Chromium OS Authors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include + +static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *att, char *buf, + loff_t pos, size_t count) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev, + class_dev); + struct cros_ec_device *ecdev = ec->ec_dev; + struct ec_params_vbnvcontext *params; + struct cros_ec_command *msg; + int err; + const size_t para_sz = sizeof(params->op); + const size_t resp_sz = sizeof(struct ec_response_vbnvcontext); + const size_t payload = max(para_sz, resp_sz); + + msg = kmalloc(sizeof(*msg) + payload, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + /* NB: we only kmalloc()ated enough space for the op field */ + params = (struct ec_params_vbnvcontext *)msg->data; + params->op = EC_VBNV_CONTEXT_OP_READ; + + msg->version = EC_VER_VBNV_CONTEXT; + msg->command = EC_CMD_VBNV_CONTEXT; + msg->outsize = para_sz; + msg->insize = resp_sz; + + err = cros_ec_cmd_xfer(ecdev, msg); + if (err < 0) { + dev_err(dev, "Error sending read request: %d\n", err); + kfree(msg); + return err; + } + + memcpy(buf, msg->data, resp_sz); + + kfree(msg); + return resp_sz; +} + +static ssize_t vboot_context_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, char *buf, + loff_t pos, size_t count) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev, + class_dev); + struct cros_ec_device *ecdev = ec->ec_dev; + struct ec_params_vbnvcontext *params; + struct cros_ec_command *msg; + int err; + const size_t para_sz = sizeof(*params); + const size_t data_sz = sizeof(params->block); + + /* Only write full values */ + if (count != data_sz) + return -EINVAL; + + msg = kmalloc(sizeof(*msg) + para_sz, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + params = (struct ec_params_vbnvcontext *)msg->data; + params->op = EC_VBNV_CONTEXT_OP_WRITE; + memcpy(params->block, buf, data_sz); + + msg->version = EC_VER_VBNV_CONTEXT; + msg->command = EC_CMD_VBNV_CONTEXT; + msg->outsize = para_sz; + msg->insize = 0; + + err = cros_ec_cmd_xfer(ecdev, msg); + if (err < 0) { + dev_err(dev, "Error sending write request: %d\n", err); + kfree(msg); + return err; + } + + kfree(msg); + return data_sz; +} + +static umode_t cros_ec_vbc_is_visible(struct kobject *kobj, + struct bin_attribute *a, int n) +{ + struct device *dev = container_of(kobj, struct device, kobj); + struct cros_ec_dev *ec = container_of(dev, struct cros_ec_dev, + class_dev); + struct device_node *np = ec->ec_dev->dev->of_node; + + if (IS_ENABLED(CONFIG_OF) && np) { + if (of_property_read_bool(np, "google,has-vbc-nvram")) + return a->attr.mode; + } + + return 0; +} + +static BIN_ATTR_RW(vboot_context, 16); + +static struct bin_attribute *cros_ec_vbc_bin_attrs[] = { + &bin_attr_vboot_context, + NULL +}; + +struct attribute_group cros_ec_vbc_attr_group = { + .name = "vbc", + .bin_attrs = cros_ec_vbc_bin_attrs, + .is_bin_visible = cros_ec_vbc_is_visible, +}; diff --git a/include/linux/mfd/cros_ec.h b/include/linux/mfd/cros_ec.h index da72671a42fa..494682ce4bf3 100644 --- a/include/linux/mfd/cros_ec.h +++ b/include/linux/mfd/cros_ec.h @@ -255,5 +255,6 @@ int cros_ec_query_all(struct cros_ec_device *ec_dev); /* sysfs stuff */ extern struct attribute_group cros_ec_attr_group; extern struct attribute_group cros_ec_lightbar_attr_group; +extern struct attribute_group cros_ec_vbc_attr_group; #endif /* __LINUX_MFD_CROS_EC_H */ -- cgit v1.2.3-59-g8ed1b From ebaf31c46cce0dc8a6ed690b5456b295aa7586a6 Mon Sep 17 00:00:00 2001 From: Jarkko Nikula Date: Tue, 3 Nov 2015 13:09:00 +0200 Subject: platform/chrome: Fix i2c-designware adapter name Commit d80d134182ba ("i2c: designware: Move common probe code into i2c_dw_probe()") caused the I2C adapter lookup code here to fail for PCI enumerated i2c-designware because commit changed the adapter name but didn't update it here. Fix the I2C adapter lookup by using the "Synopsys DesignWare I2C adapter" name. Reported-by: Jeremiah Mahler Fixes: d80d134182ba ("i2c: designware: Move common probe code into i2c_dw_probe()") Signed-off-by: Jarkko Nikula Tested-by: Jeremiah Mahler Signed-off-by: Olof Johansson --- drivers/platform/chrome/chromeos_laptop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c index 02072749fff3..2b441e9ae593 100644 --- a/drivers/platform/chrome/chromeos_laptop.c +++ b/drivers/platform/chrome/chromeos_laptop.c @@ -47,8 +47,8 @@ static const char *i2c_adapter_names[] = { "SMBus I801 adapter", "i915 gmbus vga", "i915 gmbus panel", - "i2c-designware-pci", - "i2c-designware-pci", + "Synopsys DesignWare I2C adapter", + "Synopsys DesignWare I2C adapter", }; /* Keep this enum consistent with i2c_adapter_names */ -- cgit v1.2.3-59-g8ed1b