2 * Copyright (C) 2012 Google, Inc
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Expose the ChromeOS EC firmware information.
22 #include <linux/module.h>
23 #include <linux/mfd/chromeos_ec.h>
24 #include <linux/mfd/chromeos_ec_commands.h>
25 #include <linux/platform_device.h>
26 #include <linux/chromeos_platform.h>
28 static ssize_t ec_fw_version_show(struct device *dev,
29 struct device_attribute *attr, char *buf)
31 struct chromeos_ec_device *ec = dev_get_drvdata(dev);
32 struct ec_response_get_version info;
33 const char * const copy_name[] = {"?", "RO", "RW"};
36 ret = ec->command_recv(ec, EC_CMD_GET_VERSION, &info,
37 sizeof(struct ec_response_get_version));
41 if (info.current_image > EC_IMAGE_RW)
42 info.current_image = EC_IMAGE_UNKNOWN;
44 return scnprintf(buf, PAGE_SIZE, "Current: %s\nRO: %s\nRW: %s\n",
45 copy_name[info.current_image], info.version_string_ro,
46 info.version_string_rw);
49 static ssize_t ec_build_info_show(struct device *dev,
50 struct device_attribute *attr, char *buf)
52 struct chromeos_ec_device *ec = dev_get_drvdata(dev);
53 char info[EC_HOST_PARAM_SIZE];
56 ret = ec->command_recv(ec, EC_CMD_GET_BUILD_INFO, info, sizeof(info));
60 return scnprintf(buf, PAGE_SIZE, "%s\n", info);
63 static ssize_t ec_chip_info_show(struct device *dev,
64 struct device_attribute *attr, char *buf)
66 struct chromeos_ec_device *ec = dev_get_drvdata(dev);
67 struct ec_response_get_chip_info info;
70 ret = ec->command_recv(ec, EC_CMD_GET_CHIP_INFO, &info,
71 sizeof(struct ec_response_get_chip_info));
75 return scnprintf(buf, PAGE_SIZE, "%s %s %s\n",
76 info.vendor, info.name, info.revision);
79 static ssize_t ec_dev_usb_store(struct device *dev,
80 struct device_attribute *attr,
81 const char *buf, size_t count)
84 err = chromeos_set_dev_usb();
90 static DEVICE_ATTR(fw_version, S_IRUGO, ec_fw_version_show, NULL);
91 static DEVICE_ATTR(build_info, S_IRUGO, ec_build_info_show, NULL);
92 static DEVICE_ATTR(chip_info, S_IRUGO, ec_chip_info_show, NULL);
93 static DEVICE_ATTR(dev_usb, S_IWUGO, NULL, ec_dev_usb_store);
95 static struct attribute *ec_fw_attrs[] = {
96 &dev_attr_fw_version.attr,
97 &dev_attr_build_info.attr,
98 &dev_attr_chip_info.attr,
102 static const struct attribute_group ec_fw_attr_group = {
103 .attrs = ec_fw_attrs,
106 static int __devinit ec_fw_probe(struct platform_device *pdev)
108 struct chromeos_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
109 struct device *dev = ec->dev;
112 err = sysfs_create_group(&dev->kobj, &ec_fw_attr_group);
114 dev_warn(dev, "error creating sysfs entries.\n");
118 dev_dbg(dev, "Chrome EC Firmware Information\n");
123 static int __devexit ec_fw_remove(struct platform_device *pdev)
125 struct chromeos_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
127 sysfs_remove_group(&ec->dev->kobj, &ec_fw_attr_group);
132 static struct platform_driver ec_fw_driver = {
133 .probe = ec_fw_probe,
134 .remove = __devexit_p(ec_fw_remove),
136 .name = "cros_ec-fw",
140 module_platform_driver(ec_fw_driver);
142 MODULE_LICENSE("GPL");
143 MODULE_DESCRIPTION("ChromeOS EC firmware");
144 MODULE_ALIAS("platform:cros_ec-fw");