forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/drivers/platform/chrome/cros_ec_vbc.c
....@@ -1,34 +1,23 @@
1
-/*
2
- * cros_ec_vbc - Expose the vboot context nvram to userspace
3
- *
4
- * Copyright (C) 2015 Collabora Ltd.
5
- *
6
- * based on vendor driver,
7
- *
8
- * Copyright (C) 2012 The Chromium OS Authors
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- */
1
+// SPDX-License-Identifier: GPL-2.0+
2
+// Expose the vboot context nvram to userspace
3
+//
4
+// Copyright (C) 2012 Google, Inc.
5
+// Copyright (C) 2015 Collabora Ltd.
206
217 #include <linux/of.h>
228 #include <linux/platform_device.h>
23
-#include <linux/mfd/cros_ec.h>
24
-#include <linux/mfd/cros_ec_commands.h>
9
+#include <linux/module.h>
10
+#include <linux/platform_data/cros_ec_commands.h>
11
+#include <linux/platform_data/cros_ec_proto.h>
2512 #include <linux/slab.h>
13
+
14
+#define DRV_NAME "cros-ec-vbc"
2615
2716 static ssize_t vboot_context_read(struct file *filp, struct kobject *kobj,
2817 struct bin_attribute *att, char *buf,
2918 loff_t pos, size_t count)
3019 {
31
- struct device *dev = container_of(kobj, struct device, kobj);
20
+ struct device *dev = kobj_to_dev(kobj);
3221 struct cros_ec_dev *ec = to_cros_ec_dev(dev);
3322 struct cros_ec_device *ecdev = ec->ec_dev;
3423 struct ec_params_vbnvcontext *params;
....@@ -51,7 +40,7 @@
5140 msg->outsize = para_sz;
5241 msg->insize = resp_sz;
5342
54
- err = cros_ec_cmd_xfer(ecdev, msg);
43
+ err = cros_ec_cmd_xfer_status(ecdev, msg);
5544 if (err < 0) {
5645 dev_err(dev, "Error sending read request: %d\n", err);
5746 kfree(msg);
....@@ -68,7 +57,7 @@
6857 struct bin_attribute *attr, char *buf,
6958 loff_t pos, size_t count)
7059 {
71
- struct device *dev = container_of(kobj, struct device, kobj);
60
+ struct device *dev = kobj_to_dev(kobj);
7261 struct cros_ec_dev *ec = to_cros_ec_dev(dev);
7362 struct cros_ec_device *ecdev = ec->ec_dev;
7463 struct ec_params_vbnvcontext *params;
....@@ -94,7 +83,7 @@
9483 msg->outsize = para_sz;
9584 msg->insize = 0;
9685
97
- err = cros_ec_cmd_xfer(ecdev, msg);
86
+ err = cros_ec_cmd_xfer_status(ecdev, msg);
9887 if (err < 0) {
9988 dev_err(dev, "Error sending write request: %d\n", err);
10089 kfree(msg);
....@@ -105,21 +94,6 @@
10594 return data_sz;
10695 }
10796
108
-static umode_t cros_ec_vbc_is_visible(struct kobject *kobj,
109
- struct bin_attribute *a, int n)
110
-{
111
- struct device *dev = container_of(kobj, struct device, kobj);
112
- struct cros_ec_dev *ec = to_cros_ec_dev(dev);
113
- struct device_node *np = ec->ec_dev->dev->of_node;
114
-
115
- if (IS_ENABLED(CONFIG_OF) && np) {
116
- if (of_property_read_bool(np, "google,has-vbc-nvram"))
117
- return a->attr.mode;
118
- }
119
-
120
- return 0;
121
-}
122
-
12397 static BIN_ATTR_RW(vboot_context, 16);
12498
12599 static struct bin_attribute *cros_ec_vbc_bin_attrs[] = {
....@@ -127,9 +101,46 @@
127101 NULL
128102 };
129103
130
-struct attribute_group cros_ec_vbc_attr_group = {
104
+static struct attribute_group cros_ec_vbc_attr_group = {
131105 .name = "vbc",
132106 .bin_attrs = cros_ec_vbc_bin_attrs,
133
- .is_bin_visible = cros_ec_vbc_is_visible,
134107 };
135
-EXPORT_SYMBOL(cros_ec_vbc_attr_group);
108
+
109
+static int cros_ec_vbc_probe(struct platform_device *pd)
110
+{
111
+ struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
112
+ struct device *dev = &pd->dev;
113
+ int ret;
114
+
115
+ ret = sysfs_create_group(&ec_dev->class_dev.kobj,
116
+ &cros_ec_vbc_attr_group);
117
+ if (ret < 0)
118
+ dev_err(dev, "failed to create %s attributes. err=%d\n",
119
+ cros_ec_vbc_attr_group.name, ret);
120
+
121
+ return ret;
122
+}
123
+
124
+static int cros_ec_vbc_remove(struct platform_device *pd)
125
+{
126
+ struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
127
+
128
+ sysfs_remove_group(&ec_dev->class_dev.kobj,
129
+ &cros_ec_vbc_attr_group);
130
+
131
+ return 0;
132
+}
133
+
134
+static struct platform_driver cros_ec_vbc_driver = {
135
+ .driver = {
136
+ .name = DRV_NAME,
137
+ },
138
+ .probe = cros_ec_vbc_probe,
139
+ .remove = cros_ec_vbc_remove,
140
+};
141
+
142
+module_platform_driver(cros_ec_vbc_driver);
143
+
144
+MODULE_LICENSE("GPL");
145
+MODULE_DESCRIPTION("Expose the vboot context nvram to userspace");
146
+MODULE_ALIAS("platform:" DRV_NAME);