| .. | .. |
|---|
| 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. |
|---|
| 21 | 5 | |
|---|
| 22 | 6 | #include <linux/ctype.h> |
|---|
| 23 | 7 | #include <linux/delay.h> |
|---|
| 24 | 8 | #include <linux/device.h> |
|---|
| 25 | 9 | #include <linux/fs.h> |
|---|
| 26 | 10 | #include <linux/kobject.h> |
|---|
| 27 | | -#include <linux/mfd/cros_ec.h> |
|---|
| 28 | | -#include <linux/mfd/cros_ec_commands.h> |
|---|
| 29 | 11 | #include <linux/module.h> |
|---|
| 12 | +#include <linux/platform_data/cros_ec_commands.h> |
|---|
| 13 | +#include <linux/platform_data/cros_ec_proto.h> |
|---|
| 30 | 14 | #include <linux/platform_device.h> |
|---|
| 31 | 15 | #include <linux/printk.h> |
|---|
| 32 | 16 | #include <linux/slab.h> |
|---|
| 33 | 17 | #include <linux/stat.h> |
|---|
| 34 | 18 | #include <linux/types.h> |
|---|
| 35 | 19 | #include <linux/uaccess.h> |
|---|
| 20 | + |
|---|
| 21 | +#define DRV_NAME "cros-ec-sysfs" |
|---|
| 36 | 22 | |
|---|
| 37 | 23 | /* Accessor functions */ |
|---|
| 38 | 24 | |
|---|
| .. | .. |
|---|
| 163 | 149 | /* Get build info. */ |
|---|
| 164 | 150 | msg->command = EC_CMD_GET_BUILD_INFO + ec->cmd_offset; |
|---|
| 165 | 151 | 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) { |
|---|
| 168 | 154 | 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 { |
|---|
| 174 | 158 | msg->data[EC_HOST_PARAM_SIZE - 1] = '\0'; |
|---|
| 175 | 159 | count += scnprintf(buf + count, PAGE_SIZE - count, |
|---|
| 176 | 160 | "Build info: %s\n", msg->data); |
|---|
| .. | .. |
|---|
| 179 | 163 | /* Get chip info. */ |
|---|
| 180 | 164 | msg->command = EC_CMD_GET_CHIP_INFO + ec->cmd_offset; |
|---|
| 181 | 165 | 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) { |
|---|
| 184 | 168 | 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 { |
|---|
| 190 | 172 | r_chip = (struct ec_response_get_chip_info *)msg->data; |
|---|
| 191 | 173 | |
|---|
| 192 | 174 | r_chip->vendor[sizeof(r_chip->vendor) - 1] = '\0'; |
|---|
| .. | .. |
|---|
| 203 | 185 | /* Get board version */ |
|---|
| 204 | 186 | msg->command = EC_CMD_GET_BOARD_VERSION + ec->cmd_offset; |
|---|
| 205 | 187 | 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) { |
|---|
| 208 | 190 | 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 { |
|---|
| 214 | 194 | r_board = (struct ec_response_board_version *)msg->data; |
|---|
| 215 | 195 | |
|---|
| 216 | 196 | count += scnprintf(buf + count, PAGE_SIZE - count, |
|---|
| .. | .. |
|---|
| 340 | 320 | static umode_t cros_ec_ctrl_visible(struct kobject *kobj, |
|---|
| 341 | 321 | struct attribute *a, int n) |
|---|
| 342 | 322 | { |
|---|
| 343 | | - struct device *dev = container_of(kobj, struct device, kobj); |
|---|
| 323 | + struct device *dev = kobj_to_dev(kobj); |
|---|
| 344 | 324 | struct cros_ec_dev *ec = to_cros_ec_dev(dev); |
|---|
| 345 | 325 | |
|---|
| 346 | 326 | if (a == &dev_attr_kb_wake_angle.attr && !ec->has_kb_wake_angle) |
|---|
| .. | .. |
|---|
| 349 | 329 | return a->mode; |
|---|
| 350 | 330 | } |
|---|
| 351 | 331 | |
|---|
| 352 | | -struct attribute_group cros_ec_attr_group = { |
|---|
| 332 | +static struct attribute_group cros_ec_attr_group = { |
|---|
| 353 | 333 | .attrs = __ec_attrs, |
|---|
| 354 | 334 | .is_visible = cros_ec_ctrl_visible, |
|---|
| 355 | 335 | }; |
|---|
| 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); |
|---|
| 357 | 368 | |
|---|
| 358 | 369 | 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); |
|---|