mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-29 15:43:59 +08:00
840d9f131f
There is a bit of mess between cros-ec mfd includes and platform includes. For example, we have a linux/mfd/cros_ec.h include that exports the interface implemented in platform/chrome/cros_ec_proto.c. Or we have a linux/mfd/cros_ec_commands.h file that is non related to the multifunction device (in the sense that is not exporting any function of the mfd device). This causes crossed includes between mfd and platform/chrome subsystems and makes the code difficult to read, apart from creating 'curious' situations where a platform/chrome driver includes a linux/mfd/cros_ec.h file just to get the exported functions that are implemented in another platform/chrome driver. In order to have a better separation on what the cros-ec multifunction driver does and what the cros-ec core provides move and rework the affected includes doing: - Move cros_ec_commands.h to include/linux/platform_data/cros_ec_commands.h - Get rid of the parts that are implemented in the platform/chrome/cros_ec_proto.c driver from include/linux/mfd/cros_ec.h to a new file include/linux/platform_data/cros_ec_proto.h - Update all the drivers with the new includes, so - Drivers that only need to know about the protocol include - linux/platform_data/cros_ec_proto.h - linux/platform_data/cros_ec_commands.h - Drivers that need to know about the cros-ec mfd device also include - linux/mfd/cros_ec.h Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Mark Brown <broonie@kernel.org> Acked-by: Wolfram Sang <wsa@the-dreams.de> Acked-by: Neil Armstrong <narmstrong@baylibre.com> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> Acked-by: Chanwoo Choi <cw00.choi@samsung.com> Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Tested-by: Gwendal Grignou <gwendal@chromium.org> Series changes: 3 - Fix dereferencing pointer to incomplete type 'struct cros_ec_dev' (lkp) Signed-off-by: Lee Jones <lee.jones@linaro.org>
148 lines
3.7 KiB
C
148 lines
3.7 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
// Expose the vboot context nvram to userspace
|
|
//
|
|
// Copyright (C) 2012 Google, Inc.
|
|
// Copyright (C) 2015 Collabora Ltd.
|
|
|
|
#include <linux/of.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/mfd/cros_ec.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_data/cros_ec_commands.h>
|
|
#include <linux/platform_data/cros_ec_proto.h>
|
|
#include <linux/slab.h>
|
|
|
|
#define DRV_NAME "cros-ec-vbc"
|
|
|
|
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 = to_cros_ec_dev(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 = to_cros_ec_dev(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 BIN_ATTR_RW(vboot_context, 16);
|
|
|
|
static struct bin_attribute *cros_ec_vbc_bin_attrs[] = {
|
|
&bin_attr_vboot_context,
|
|
NULL
|
|
};
|
|
|
|
static struct attribute_group cros_ec_vbc_attr_group = {
|
|
.name = "vbc",
|
|
.bin_attrs = cros_ec_vbc_bin_attrs,
|
|
};
|
|
|
|
static int cros_ec_vbc_probe(struct platform_device *pd)
|
|
{
|
|
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
|
|
struct device *dev = &pd->dev;
|
|
int ret;
|
|
|
|
ret = sysfs_create_group(&ec_dev->class_dev.kobj,
|
|
&cros_ec_vbc_attr_group);
|
|
if (ret < 0)
|
|
dev_err(dev, "failed to create %s attributes. err=%d\n",
|
|
cros_ec_vbc_attr_group.name, ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int cros_ec_vbc_remove(struct platform_device *pd)
|
|
{
|
|
struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
|
|
|
|
sysfs_remove_group(&ec_dev->class_dev.kobj,
|
|
&cros_ec_vbc_attr_group);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver cros_ec_vbc_driver = {
|
|
.driver = {
|
|
.name = DRV_NAME,
|
|
},
|
|
.probe = cros_ec_vbc_probe,
|
|
.remove = cros_ec_vbc_remove,
|
|
};
|
|
|
|
module_platform_driver(cros_ec_vbc_driver);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("Expose the vboot context nvram to userspace");
|
|
MODULE_ALIAS("platform:" DRV_NAME);
|