1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2019 Google LLC
5 * Sysfs properties to view and modify EC-controlled features on Wilco devices.
6 * The entries will appear under /sys/bus/platform/devices/GOOG000C:00/
8 * See Documentation/ABI/testing/sysfs-platform-wilco-ec for more information.
11 #include <linux/platform_data/wilco-ec.h>
12 #include <linux/sysfs.h>
14 #define CMD_KB_CMOS 0x7C
15 #define SUB_CMD_KB_CMOS_AUTO_ON 0x03
17 struct boot_on_ac_request {
18 u8 cmd; /* Always CMD_KB_CMOS */
20 u8 sub_cmd; /* Always SUB_CMD_KB_CMOS_AUTO_ON */
22 u8 val; /* Either 0 or 1 */
26 #define CMD_EC_INFO 0x38
31 CMD_GET_EC_BUILD_DATE = 3,
34 struct get_ec_info_req {
35 u8 cmd; /* Always CMD_EC_INFO */
37 u8 op; /* One of enum get_ec_info_op */
40 struct get_ec_info_resp {
42 char value[9]; /* __nonstring: might not be null terminated */
45 static ssize_t boot_on_ac_store(struct device *dev,
46 struct device_attribute *attr,
47 const char *buf, size_t count)
49 struct wilco_ec_device *ec = dev_get_drvdata(dev);
50 struct boot_on_ac_request rq;
51 struct wilco_ec_message msg;
55 ret = kstrtou8(buf, 10, &val);
61 memset(&rq, 0, sizeof(rq));
63 rq.sub_cmd = SUB_CMD_KB_CMOS_AUTO_ON;
66 memset(&msg, 0, sizeof(msg));
67 msg.type = WILCO_EC_MSG_LEGACY;
68 msg.request_data = &rq;
69 msg.request_size = sizeof(rq);
70 ret = wilco_ec_mailbox(ec, &msg);
77 static DEVICE_ATTR_WO(boot_on_ac);
79 static ssize_t get_info(struct device *dev, char *buf, enum get_ec_info_op op)
81 struct wilco_ec_device *ec = dev_get_drvdata(dev);
82 struct get_ec_info_req req = { .cmd = CMD_EC_INFO, .op = op };
83 struct get_ec_info_resp resp;
86 struct wilco_ec_message msg = {
87 .type = WILCO_EC_MSG_LEGACY,
89 .request_size = sizeof(req),
90 .response_data = &resp,
91 .response_size = sizeof(resp),
94 ret = wilco_ec_mailbox(ec, &msg);
98 return scnprintf(buf, PAGE_SIZE, "%.*s\n", (int)sizeof(resp.value),
102 static ssize_t version_show(struct device *dev, struct device_attribute *attr,
105 return get_info(dev, buf, CMD_GET_EC_LABEL);
108 static DEVICE_ATTR_RO(version);
110 static ssize_t build_revision_show(struct device *dev,
111 struct device_attribute *attr, char *buf)
113 return get_info(dev, buf, CMD_GET_EC_REV);
116 static DEVICE_ATTR_RO(build_revision);
118 static ssize_t build_date_show(struct device *dev,
119 struct device_attribute *attr, char *buf)
121 return get_info(dev, buf, CMD_GET_EC_BUILD_DATE);
124 static DEVICE_ATTR_RO(build_date);
126 static ssize_t model_number_show(struct device *dev,
127 struct device_attribute *attr, char *buf)
129 return get_info(dev, buf, CMD_GET_EC_MODEL);
132 static DEVICE_ATTR_RO(model_number);
135 static struct attribute *wilco_dev_attrs[] = {
136 &dev_attr_boot_on_ac.attr,
137 &dev_attr_build_date.attr,
138 &dev_attr_build_revision.attr,
139 &dev_attr_model_number.attr,
140 &dev_attr_version.attr,
144 static struct attribute_group wilco_dev_attr_group = {
145 .attrs = wilco_dev_attrs,
148 int wilco_ec_add_sysfs(struct wilco_ec_device *ec)
150 return sysfs_create_group(&ec->dev->kobj, &wilco_dev_attr_group);
153 void wilco_ec_remove_sysfs(struct wilco_ec_device *ec)
155 sysfs_remove_group(&ec->dev->kobj, &wilco_dev_attr_group);