forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 072de836f53be56a70cecf70b43ae43b7ce17376
kernel/drivers/platform/chrome/cros_ec_sysfs.c
....@@ -1,38 +1,24 @@
1
-/*
2
- * cros_ec_sysfs - expose the Chrome OS EC through sysfs
3
- *
4
- * Copyright (C) 2014 Google, Inc.
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU General Public License
17
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
- */
19
-
20
-#define pr_fmt(fmt) "cros_ec_sysfs: " fmt
1
+// SPDX-License-Identifier: GPL-2.0+
2
+// Expose the ChromeOS EC through sysfs
3
+//
4
+// Copyright (C) 2014 Google, Inc.
215
226 #include <linux/ctype.h>
237 #include <linux/delay.h>
248 #include <linux/device.h>
259 #include <linux/fs.h>
2610 #include <linux/kobject.h>
27
-#include <linux/mfd/cros_ec.h>
28
-#include <linux/mfd/cros_ec_commands.h>
2911 #include <linux/module.h>
12
+#include <linux/platform_data/cros_ec_commands.h>
13
+#include <linux/platform_data/cros_ec_proto.h>
3014 #include <linux/platform_device.h>
3115 #include <linux/printk.h>
3216 #include <linux/slab.h>
3317 #include <linux/stat.h>
3418 #include <linux/types.h>
3519 #include <linux/uaccess.h>
20
+
21
+#define DRV_NAME "cros-ec-sysfs"
3622
3723 /* Accessor functions */
3824
....@@ -163,14 +149,12 @@
163149 /* Get build info. */
164150 msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset;
165151 msg->insize = EC_HOST_PARAM_SIZE;
166
- ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
167
- if (ret < 0)
152
+ ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
153
+ if (ret < 0) {
168154 count += scnprintf(buf + count, PAGE_SIZE - count,
169
- "Build info: XFER ERROR %d\n", ret);
170
- else if (msg->result != EC_RES_SUCCESS)
171
- count += scnprintf(buf + count, PAGE_SIZE - count,
172
- "Build info: EC error %d\n", msg->result);
173
- else {
155
+ "Build info: XFER / EC ERROR %d / %d\n",
156
+ ret, msg->result);
157
+ } else {
174158 msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
175159 count += scnprintf(buf + count, PAGE_SIZE - count,
176160 "Build info: %s\n", msg->data);
....@@ -179,14 +163,12 @@
179163 /* Get chip info. */
180164 msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset;
181165 msg->insize = sizeof(*r_chip);
182
- ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
183
- if (ret < 0)
166
+ ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
167
+ if (ret < 0) {
184168 count += scnprintf(buf + count, PAGE_SIZE - count,
185
- "Chip info: XFER ERROR %d\n", ret);
186
- else if (msg->result != EC_RES_SUCCESS)
187
- count += scnprintf(buf + count, PAGE_SIZE - count,
188
- "Chip info: EC error %d\n", msg->result);
189
- else {
169
+ "Chip info: XFER / EC ERROR %d / %d\n",
170
+ ret, msg->result);
171
+ } else {
190172 r_chip = (struct ec_response_get_chip_info *)msg->data;
191173
192174 r_chip->vendor[sizeof(r_chip->vendor) - 1] = '\0';
....@@ -203,14 +185,12 @@
203185 /* Get board version */
204186 msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset;
205187 msg->insize = sizeof(*r_board);
206
- ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
207
- if (ret < 0)
188
+ ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
189
+ if (ret < 0) {
208190 count += scnprintf(buf + count, PAGE_SIZE - count,
209
- "Board version: XFER ERROR %d\n", ret);
210
- else if (msg->result != EC_RES_SUCCESS)
211
- count += scnprintf(buf + count, PAGE_SIZE - count,
212
- "Board version: EC error %d\n", msg->result);
213
- else {
191
+ "Board version: XFER / EC ERROR %d / %d\n",
192
+ ret, msg->result);
193
+ } else {
214194 r_board = (struct ec_response_board_version *)msg->data;
215195
216196 count += scnprintf(buf + count, PAGE_SIZE - count,
....@@ -340,7 +320,7 @@
340320 static umode_t cros_ec_ctrl_visible(struct kobject *kobj,
341321 struct attribute *a, int n)
342322 {
343
- struct device *dev = container_of(kobj, struct device, kobj);
323
+ struct device *dev = kobj_to_dev(kobj);
344324 struct cros_ec_dev *ec = to_cros_ec_dev(dev);
345325
346326 if (a == &dev_attr_kb_wake_angle.attr && !ec->has_kb_wake_angle)
....@@ -349,11 +329,43 @@
349329 return a->mode;
350330 }
351331
352
-struct attribute_group cros_ec_attr_group = {
332
+static struct attribute_group cros_ec_attr_group = {
353333 .attrs = __ec_attrs,
354334 .is_visible = cros_ec_ctrl_visible,
355335 };
356
-EXPORT_SYMBOL(cros_ec_attr_group);
336
+
337
+static int cros_ec_sysfs_probe(struct platform_device *pd)
338
+{
339
+ struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
340
+ struct device *dev = &pd->dev;
341
+ int ret;
342
+
343
+ ret = sysfs_create_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group);
344
+ if (ret < 0)
345
+ dev_err(dev, "failed to create attributes. err=%d\n", ret);
346
+
347
+ return ret;
348
+}
349
+
350
+static int cros_ec_sysfs_remove(struct platform_device *pd)
351
+{
352
+ struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
353
+
354
+ sysfs_remove_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group);
355
+
356
+ return 0;
357
+}
358
+
359
+static struct platform_driver cros_ec_sysfs_driver = {
360
+ .driver = {
361
+ .name = DRV_NAME,
362
+ },
363
+ .probe = cros_ec_sysfs_probe,
364
+ .remove = cros_ec_sysfs_remove,
365
+};
366
+
367
+module_platform_driver(cros_ec_sysfs_driver);
357368
358369 MODULE_LICENSE("GPL");
359
-MODULE_DESCRIPTION("ChromeOS EC control driver");
370
+MODULE_DESCRIPTION("Expose the ChromeOS EC through sysfs");
371
+MODULE_ALIAS("platform:" DRV_NAME);