Linux Audio

Check our new training course

Loading...
v4.6
  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
 21
 22#include <linux/ctype.h>
 23#include <linux/delay.h>
 24#include <linux/device.h>
 25#include <linux/fs.h>
 26#include <linux/kobject.h>
 27#include <linux/mfd/cros_ec.h>
 28#include <linux/mfd/cros_ec_commands.h>
 29#include <linux/module.h>
 
 
 30#include <linux/platform_device.h>
 31#include <linux/printk.h>
 32#include <linux/slab.h>
 33#include <linux/stat.h>
 34#include <linux/types.h>
 35#include <linux/uaccess.h>
 36
 37#include "cros_ec_dev.h"
 38
 39/* Accessor functions */
 40
 41static ssize_t show_ec_reboot(struct device *dev,
 42			      struct device_attribute *attr, char *buf)
 43{
 44	int count = 0;
 45
 46	count += scnprintf(buf + count, PAGE_SIZE - count,
 47			   "ro|rw|cancel|cold|disable-jump|hibernate");
 48	count += scnprintf(buf + count, PAGE_SIZE - count,
 49			   " [at-shutdown]\n");
 50	return count;
 51}
 52
 53static ssize_t store_ec_reboot(struct device *dev,
 54			       struct device_attribute *attr,
 55			       const char *buf, size_t count)
 56{
 57	static const struct {
 58		const char * const str;
 59		uint8_t cmd;
 60		uint8_t flags;
 61	} words[] = {
 62		{"cancel",       EC_REBOOT_CANCEL, 0},
 63		{"ro",           EC_REBOOT_JUMP_RO, 0},
 64		{"rw",           EC_REBOOT_JUMP_RW, 0},
 
 65		{"cold",         EC_REBOOT_COLD, 0},
 66		{"disable-jump", EC_REBOOT_DISABLE_JUMP, 0},
 67		{"hibernate",    EC_REBOOT_HIBERNATE, 0},
 68		{"at-shutdown",  -1, EC_REBOOT_FLAG_ON_AP_SHUTDOWN},
 69	};
 70	struct cros_ec_command *msg;
 71	struct ec_params_reboot_ec *param;
 72	int got_cmd = 0, offset = 0;
 73	int i;
 74	int ret;
 75	struct cros_ec_dev *ec = container_of(dev,
 76					      struct cros_ec_dev, class_dev);
 77
 78	msg = kmalloc(sizeof(*msg) + sizeof(*param), GFP_KERNEL);
 79	if (!msg)
 80		return -ENOMEM;
 81
 82	param = (struct ec_params_reboot_ec *)msg->data;
 83
 84	param->flags = 0;
 85	while (1) {
 86		/* Find word to start scanning */
 87		while (buf[offset] && isspace(buf[offset]))
 88			offset++;
 89		if (!buf[offset])
 90			break;
 91
 92		for (i = 0; i < ARRAY_SIZE(words); i++) {
 93			if (!strncasecmp(words[i].str, buf+offset,
 94					 strlen(words[i].str))) {
 95				if (words[i].flags) {
 96					param->flags |= words[i].flags;
 97				} else {
 98					param->cmd = words[i].cmd;
 99					got_cmd = 1;
100				}
101				break;
102			}
103		}
104
105		/* On to the next word, if any */
106		while (buf[offset] && !isspace(buf[offset]))
107			offset++;
108	}
109
110	if (!got_cmd) {
111		count = -EINVAL;
112		goto exit;
113	}
114
115	msg->version = 0;
116	msg->command = EC_CMD_REBOOT_EC + ec->cmd_offset;
117	msg->outsize = sizeof(*param);
118	msg->insize = 0;
119	ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
120	if (ret < 0) {
121		count = ret;
122		goto exit;
123	}
124	if (msg->result != EC_RES_SUCCESS) {
125		dev_dbg(ec->dev, "EC result %d\n", msg->result);
126		count = -EINVAL;
127	}
128exit:
129	kfree(msg);
130	return count;
131}
132
133static ssize_t show_ec_version(struct device *dev,
134			       struct device_attribute *attr, char *buf)
135{
136	static const char * const image_names[] = {"unknown", "RO", "RW"};
137	struct ec_response_get_version *r_ver;
138	struct ec_response_get_chip_info *r_chip;
139	struct ec_response_board_version *r_board;
140	struct cros_ec_command *msg;
141	int ret;
142	int count = 0;
143	struct cros_ec_dev *ec = container_of(dev,
144					      struct cros_ec_dev, class_dev);
145
146	msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
147	if (!msg)
148		return -ENOMEM;
149
150	/* Get versions. RW may change. */
151	msg->version = 0;
152	msg->command = EC_CMD_GET_VERSION + ec->cmd_offset;
153	msg->insize = sizeof(*r_ver);
154	msg->outsize = 0;
155	ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
156	if (ret < 0) {
157		count = ret;
158		goto exit;
159	}
160	if (msg->result != EC_RES_SUCCESS) {
161		count = scnprintf(buf, PAGE_SIZE,
162				  "ERROR: EC returned %d\n", msg->result);
163		goto exit;
164	}
165
166	r_ver = (struct ec_response_get_version *)msg->data;
167	/* Strings should be null-terminated, but let's be sure. */
168	r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0';
169	r_ver->version_string_rw[sizeof(r_ver->version_string_rw) - 1] = '\0';
170	count += scnprintf(buf + count, PAGE_SIZE - count,
171			   "RO version:    %s\n", r_ver->version_string_ro);
172	count += scnprintf(buf + count, PAGE_SIZE - count,
173			   "RW version:    %s\n", r_ver->version_string_rw);
174	count += scnprintf(buf + count, PAGE_SIZE - count,
175			   "Firmware copy: %s\n",
176			   (r_ver->current_image < ARRAY_SIZE(image_names) ?
177			    image_names[r_ver->current_image] : "?"));
178
179	/* Get build info. */
180	msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset;
181	msg->insize = EC_HOST_PARAM_SIZE;
182	ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
183	if (ret < 0)
184		count += scnprintf(buf + count, PAGE_SIZE - count,
185				   "Build info:    XFER ERROR %d\n", ret);
186	else if (msg->result != EC_RES_SUCCESS)
187		count += scnprintf(buf + count, PAGE_SIZE - count,
188				   "Build info:    EC error %d\n", msg->result);
189	else {
190		msg->data[sizeof(msg->data) - 1] = '\0';
 
191		count += scnprintf(buf + count, PAGE_SIZE - count,
192				   "Build info:    %s\n", msg->data);
193	}
194
195	/* Get chip info. */
196	msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset;
197	msg->insize = sizeof(*r_chip);
198	ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
199	if (ret < 0)
200		count += scnprintf(buf + count, PAGE_SIZE - count,
201				   "Chip info:     XFER ERROR %d\n", ret);
202	else if (msg->result != EC_RES_SUCCESS)
203		count += scnprintf(buf + count, PAGE_SIZE - count,
204				   "Chip info:     EC error %d\n", msg->result);
205	else {
 
206		r_chip = (struct ec_response_get_chip_info *)msg->data;
207
208		r_chip->vendor[sizeof(r_chip->vendor) - 1] = '\0';
209		r_chip->name[sizeof(r_chip->name) - 1] = '\0';
210		r_chip->revision[sizeof(r_chip->revision) - 1] = '\0';
211		count += scnprintf(buf + count, PAGE_SIZE - count,
212				   "Chip vendor:   %s\n", r_chip->vendor);
213		count += scnprintf(buf + count, PAGE_SIZE - count,
214				   "Chip name:     %s\n", r_chip->name);
215		count += scnprintf(buf + count, PAGE_SIZE - count,
216				   "Chip revision: %s\n", r_chip->revision);
217	}
218
219	/* Get board version */
220	msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset;
221	msg->insize = sizeof(*r_board);
222	ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
223	if (ret < 0)
224		count += scnprintf(buf + count, PAGE_SIZE - count,
225				   "Board version: XFER ERROR %d\n", ret);
226	else if (msg->result != EC_RES_SUCCESS)
227		count += scnprintf(buf + count, PAGE_SIZE - count,
228				   "Board version: EC error %d\n", msg->result);
229	else {
 
230		r_board = (struct ec_response_board_version *)msg->data;
231
232		count += scnprintf(buf + count, PAGE_SIZE - count,
233				   "Board version: %d\n",
234				   r_board->board_version);
235	}
236
237exit:
238	kfree(msg);
239	return count;
240}
241
242static ssize_t show_ec_flashinfo(struct device *dev,
243				 struct device_attribute *attr, char *buf)
244{
245	struct ec_response_flash_info *resp;
246	struct cros_ec_command *msg;
247	int ret;
248	struct cros_ec_dev *ec = container_of(dev,
249					      struct cros_ec_dev, class_dev);
250
251	msg = kmalloc(sizeof(*msg) + sizeof(*resp), GFP_KERNEL);
252	if (!msg)
253		return -ENOMEM;
254
255	/* The flash info shouldn't ever change, but ask each time anyway. */
256	msg->version = 0;
257	msg->command = EC_CMD_FLASH_INFO + ec->cmd_offset;
258	msg->insize = sizeof(*resp);
259	msg->outsize = 0;
260	ret = cros_ec_cmd_xfer(ec->ec_dev, msg);
261	if (ret < 0)
262		goto exit;
263	if (msg->result != EC_RES_SUCCESS) {
264		ret = scnprintf(buf, PAGE_SIZE,
265				"ERROR: EC returned %d\n", msg->result);
266		goto exit;
267	}
268
269	resp = (struct ec_response_flash_info *)msg->data;
270
271	ret = scnprintf(buf, PAGE_SIZE,
272			"FlashSize %d\nWriteSize %d\n"
273			"EraseSize %d\nProtectSize %d\n",
274			resp->flash_size, resp->write_block_size,
275			resp->erase_block_size, resp->protect_block_size);
276exit:
277	kfree(msg);
278	return ret;
279}
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281/* Module initialization */
282
283static DEVICE_ATTR(reboot, S_IWUSR | S_IRUGO, show_ec_reboot, store_ec_reboot);
284static DEVICE_ATTR(version, S_IRUGO, show_ec_version, NULL);
285static DEVICE_ATTR(flashinfo, S_IRUGO, show_ec_flashinfo, NULL);
 
286
287static struct attribute *__ec_attrs[] = {
 
288	&dev_attr_reboot.attr,
289	&dev_attr_version.attr,
290	&dev_attr_flashinfo.attr,
291	NULL,
292};
293
294struct attribute_group cros_ec_attr_group = {
 
 
 
 
 
 
 
 
 
 
 
 
295	.attrs = __ec_attrs,
 
296};
297
v6.2
  1// SPDX-License-Identifier: GPL-2.0+
  2// Expose the ChromeOS EC through sysfs
  3//
  4// Copyright (C) 2014 Google, Inc.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  5
  6#include <linux/ctype.h>
  7#include <linux/delay.h>
  8#include <linux/device.h>
  9#include <linux/fs.h>
 10#include <linux/kobject.h>
 
 
 11#include <linux/module.h>
 12#include <linux/platform_data/cros_ec_commands.h>
 13#include <linux/platform_data/cros_ec_proto.h>
 14#include <linux/platform_device.h>
 15#include <linux/printk.h>
 16#include <linux/slab.h>
 17#include <linux/stat.h>
 18#include <linux/types.h>
 19#include <linux/uaccess.h>
 20
 21#define DRV_NAME "cros-ec-sysfs"
 22
 23/* Accessor functions */
 24
 25static ssize_t reboot_show(struct device *dev,
 26			   struct device_attribute *attr, char *buf)
 27{
 28	int count = 0;
 29
 30	count += scnprintf(buf + count, PAGE_SIZE - count,
 31			   "ro|rw|cancel|cold|disable-jump|hibernate|cold-ap-off");
 32	count += scnprintf(buf + count, PAGE_SIZE - count,
 33			   " [at-shutdown]\n");
 34	return count;
 35}
 36
 37static ssize_t reboot_store(struct device *dev,
 38			    struct device_attribute *attr,
 39			    const char *buf, size_t count)
 40{
 41	static const struct {
 42		const char * const str;
 43		uint8_t cmd;
 44		uint8_t flags;
 45	} words[] = {
 46		{"cancel",       EC_REBOOT_CANCEL, 0},
 47		{"ro",           EC_REBOOT_JUMP_RO, 0},
 48		{"rw",           EC_REBOOT_JUMP_RW, 0},
 49		{"cold-ap-off",  EC_REBOOT_COLD_AP_OFF, 0},
 50		{"cold",         EC_REBOOT_COLD, 0},
 51		{"disable-jump", EC_REBOOT_DISABLE_JUMP, 0},
 52		{"hibernate",    EC_REBOOT_HIBERNATE, 0},
 53		{"at-shutdown",  -1, EC_REBOOT_FLAG_ON_AP_SHUTDOWN},
 54	};
 55	struct cros_ec_command *msg;
 56	struct ec_params_reboot_ec *param;
 57	int got_cmd = 0, offset = 0;
 58	int i;
 59	int ret;
 60	struct cros_ec_dev *ec = to_cros_ec_dev(dev);
 
 61
 62	msg = kmalloc(sizeof(*msg) + sizeof(*param), GFP_KERNEL);
 63	if (!msg)
 64		return -ENOMEM;
 65
 66	param = (struct ec_params_reboot_ec *)msg->data;
 67
 68	param->flags = 0;
 69	while (1) {
 70		/* Find word to start scanning */
 71		while (buf[offset] && isspace(buf[offset]))
 72			offset++;
 73		if (!buf[offset])
 74			break;
 75
 76		for (i = 0; i < ARRAY_SIZE(words); i++) {
 77			if (!strncasecmp(words[i].str, buf+offset,
 78					 strlen(words[i].str))) {
 79				if (words[i].flags) {
 80					param->flags |= words[i].flags;
 81				} else {
 82					param->cmd = words[i].cmd;
 83					got_cmd = 1;
 84				}
 85				break;
 86			}
 87		}
 88
 89		/* On to the next word, if any */
 90		while (buf[offset] && !isspace(buf[offset]))
 91			offset++;
 92	}
 93
 94	if (!got_cmd) {
 95		count = -EINVAL;
 96		goto exit;
 97	}
 98
 99	msg->version = 0;
100	msg->command = EC_CMD_REBOOT_EC + ec->cmd_offset;
101	msg->outsize = sizeof(*param);
102	msg->insize = 0;
103	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
104	if (ret < 0)
105		count = ret;
 
 
 
 
 
 
106exit:
107	kfree(msg);
108	return count;
109}
110
111static ssize_t version_show(struct device *dev,
112			    struct device_attribute *attr, char *buf)
113{
114	static const char * const image_names[] = {"unknown", "RO", "RW"};
115	struct ec_response_get_version *r_ver;
116	struct ec_response_get_chip_info *r_chip;
117	struct ec_response_board_version *r_board;
118	struct cros_ec_command *msg;
119	int ret;
120	int count = 0;
121	struct cros_ec_dev *ec = to_cros_ec_dev(dev);
 
122
123	msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
124	if (!msg)
125		return -ENOMEM;
126
127	/* Get versions. RW may change. */
128	msg->version = 0;
129	msg->command = EC_CMD_GET_VERSION + ec->cmd_offset;
130	msg->insize = sizeof(*r_ver);
131	msg->outsize = 0;
132	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
133	if (ret < 0) {
134		count = ret;
135		goto exit;
136	}
 
 
 
 
 
 
137	r_ver = (struct ec_response_get_version *)msg->data;
138	/* Strings should be null-terminated, but let's be sure. */
139	r_ver->version_string_ro[sizeof(r_ver->version_string_ro) - 1] = '\0';
140	r_ver->version_string_rw[sizeof(r_ver->version_string_rw) - 1] = '\0';
141	count += scnprintf(buf + count, PAGE_SIZE - count,
142			   "RO version:    %s\n", r_ver->version_string_ro);
143	count += scnprintf(buf + count, PAGE_SIZE - count,
144			   "RW version:    %s\n", r_ver->version_string_rw);
145	count += scnprintf(buf + count, PAGE_SIZE - count,
146			   "Firmware copy: %s\n",
147			   (r_ver->current_image < ARRAY_SIZE(image_names) ?
148			    image_names[r_ver->current_image] : "?"));
149
150	/* Get build info. */
151	msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset;
152	msg->insize = EC_HOST_PARAM_SIZE;
153	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
154	if (ret < 0) {
 
 
 
155		count += scnprintf(buf + count, PAGE_SIZE - count,
156				   "Build info:    XFER / EC ERROR %d / %d\n",
157				   ret, msg->result);
158	} else {
159		msg->data[EC_HOST_PARAM_SIZE - 1] = '\0';
160		count += scnprintf(buf + count, PAGE_SIZE - count,
161				   "Build info:    %s\n", msg->data);
162	}
163
164	/* Get chip info. */
165	msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset;
166	msg->insize = sizeof(*r_chip);
167	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
168	if (ret < 0) {
 
 
 
169		count += scnprintf(buf + count, PAGE_SIZE - count,
170				   "Chip info:     XFER / EC ERROR %d / %d\n",
171				   ret, msg->result);
172	} else {
173		r_chip = (struct ec_response_get_chip_info *)msg->data;
174
175		r_chip->vendor[sizeof(r_chip->vendor) - 1] = '\0';
176		r_chip->name[sizeof(r_chip->name) - 1] = '\0';
177		r_chip->revision[sizeof(r_chip->revision) - 1] = '\0';
178		count += scnprintf(buf + count, PAGE_SIZE - count,
179				   "Chip vendor:   %s\n", r_chip->vendor);
180		count += scnprintf(buf + count, PAGE_SIZE - count,
181				   "Chip name:     %s\n", r_chip->name);
182		count += scnprintf(buf + count, PAGE_SIZE - count,
183				   "Chip revision: %s\n", r_chip->revision);
184	}
185
186	/* Get board version */
187	msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset;
188	msg->insize = sizeof(*r_board);
189	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
190	if (ret < 0) {
 
 
 
191		count += scnprintf(buf + count, PAGE_SIZE - count,
192				   "Board version: XFER / EC ERROR %d / %d\n",
193				   ret, msg->result);
194	} else {
195		r_board = (struct ec_response_board_version *)msg->data;
196
197		count += scnprintf(buf + count, PAGE_SIZE - count,
198				   "Board version: %d\n",
199				   r_board->board_version);
200	}
201
202exit:
203	kfree(msg);
204	return count;
205}
206
207static ssize_t flashinfo_show(struct device *dev,
208			      struct device_attribute *attr, char *buf)
209{
210	struct ec_response_flash_info *resp;
211	struct cros_ec_command *msg;
212	int ret;
213	struct cros_ec_dev *ec = to_cros_ec_dev(dev);
 
214
215	msg = kmalloc(sizeof(*msg) + sizeof(*resp), GFP_KERNEL);
216	if (!msg)
217		return -ENOMEM;
218
219	/* The flash info shouldn't ever change, but ask each time anyway. */
220	msg->version = 0;
221	msg->command = EC_CMD_FLASH_INFO + ec->cmd_offset;
222	msg->insize = sizeof(*resp);
223	msg->outsize = 0;
224	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
225	if (ret < 0)
226		goto exit;
 
 
 
 
 
227
228	resp = (struct ec_response_flash_info *)msg->data;
229
230	ret = scnprintf(buf, PAGE_SIZE,
231			"FlashSize %d\nWriteSize %d\n"
232			"EraseSize %d\nProtectSize %d\n",
233			resp->flash_size, resp->write_block_size,
234			resp->erase_block_size, resp->protect_block_size);
235exit:
236	kfree(msg);
237	return ret;
238}
239
240/* Keyboard wake angle control */
241static ssize_t kb_wake_angle_show(struct device *dev,
242				  struct device_attribute *attr, char *buf)
243{
244	struct cros_ec_dev *ec = to_cros_ec_dev(dev);
245	struct ec_response_motion_sense *resp;
246	struct ec_params_motion_sense *param;
247	struct cros_ec_command *msg;
248	int ret;
249
250	msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
251	if (!msg)
252		return -ENOMEM;
253
254	param = (struct ec_params_motion_sense *)msg->data;
255	msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
256	msg->version = 2;
257	param->cmd = MOTIONSENSE_CMD_KB_WAKE_ANGLE;
258	param->kb_wake_angle.data = EC_MOTION_SENSE_NO_VALUE;
259	msg->outsize = sizeof(*param);
260	msg->insize = sizeof(*resp);
261
262	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
263	if (ret < 0)
264		goto exit;
265
266	resp = (struct ec_response_motion_sense *)msg->data;
267	ret = scnprintf(buf, PAGE_SIZE, "%d\n", resp->kb_wake_angle.ret);
268exit:
269	kfree(msg);
270	return ret;
271}
272
273static ssize_t kb_wake_angle_store(struct device *dev,
274				   struct device_attribute *attr,
275				   const char *buf, size_t count)
276{
277	struct cros_ec_dev *ec = to_cros_ec_dev(dev);
278	struct ec_params_motion_sense *param;
279	struct cros_ec_command *msg;
280	u16 angle;
281	int ret;
282
283	ret = kstrtou16(buf, 0, &angle);
284	if (ret)
285		return ret;
286
287	msg = kmalloc(sizeof(*msg) + EC_HOST_PARAM_SIZE, GFP_KERNEL);
288	if (!msg)
289		return -ENOMEM;
290
291	param = (struct ec_params_motion_sense *)msg->data;
292	msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
293	msg->version = 2;
294	param->cmd = MOTIONSENSE_CMD_KB_WAKE_ANGLE;
295	param->kb_wake_angle.data = angle;
296	msg->outsize = sizeof(*param);
297	msg->insize = sizeof(struct ec_response_motion_sense);
298
299	ret = cros_ec_cmd_xfer_status(ec->ec_dev, msg);
300	kfree(msg);
301	if (ret < 0)
302		return ret;
303	return count;
304}
305
306/* Module initialization */
307
308static DEVICE_ATTR_RW(reboot);
309static DEVICE_ATTR_RO(version);
310static DEVICE_ATTR_RO(flashinfo);
311static DEVICE_ATTR_RW(kb_wake_angle);
312
313static struct attribute *__ec_attrs[] = {
314	&dev_attr_kb_wake_angle.attr,
315	&dev_attr_reboot.attr,
316	&dev_attr_version.attr,
317	&dev_attr_flashinfo.attr,
318	NULL,
319};
320
321static umode_t cros_ec_ctrl_visible(struct kobject *kobj,
322				    struct attribute *a, int n)
323{
324	struct device *dev = kobj_to_dev(kobj);
325	struct cros_ec_dev *ec = to_cros_ec_dev(dev);
326
327	if (a == &dev_attr_kb_wake_angle.attr && !ec->has_kb_wake_angle)
328		return 0;
329
330	return a->mode;
331}
332
333static const struct attribute_group cros_ec_attr_group = {
334	.attrs = __ec_attrs,
335	.is_visible = cros_ec_ctrl_visible,
336};
337
338static int cros_ec_sysfs_probe(struct platform_device *pd)
339{
340	struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
341	struct device *dev = &pd->dev;
342	int ret;
343
344	ret = sysfs_create_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group);
345	if (ret < 0)
346		dev_err(dev, "failed to create attributes. err=%d\n", ret);
347
348	return ret;
349}
350
351static int cros_ec_sysfs_remove(struct platform_device *pd)
352{
353	struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent);
354
355	sysfs_remove_group(&ec_dev->class_dev.kobj, &cros_ec_attr_group);
356
357	return 0;
358}
359
360static struct platform_driver cros_ec_sysfs_driver = {
361	.driver = {
362		.name = DRV_NAME,
363	},
364	.probe = cros_ec_sysfs_probe,
365	.remove = cros_ec_sysfs_remove,
366};
367
368module_platform_driver(cros_ec_sysfs_driver);
369
370MODULE_LICENSE("GPL");
371MODULE_DESCRIPTION("Expose the ChromeOS EC through sysfs");
372MODULE_ALIAS("platform:" DRV_NAME);