Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / platform / x86 / intel-wmi-thunderbolt.c
blobc2257bd06f1863d848fc384b2ac5577294bef8f5
1 /*
2 * WMI Thunderbolt driver
4 * Copyright (C) 2017 Dell Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/acpi.h>
19 #include <linux/device.h>
20 #include <linux/fs.h>
21 #include <linux/kernel.h>
22 #include <linux/module.h>
23 #include <linux/string.h>
24 #include <linux/sysfs.h>
25 #include <linux/types.h>
26 #include <linux/wmi.h>
28 #define INTEL_WMI_THUNDERBOLT_GUID "86CCFD48-205E-4A77-9C48-2021CBEDE341"
30 static ssize_t force_power_store(struct device *dev,
31 struct device_attribute *attr,
32 const char *buf, size_t count)
34 struct acpi_buffer input;
35 acpi_status status;
36 u8 mode;
38 input.length = sizeof(u8);
39 input.pointer = &mode;
40 mode = hex_to_bin(buf[0]);
41 if (mode == 0 || mode == 1) {
42 status = wmi_evaluate_method(INTEL_WMI_THUNDERBOLT_GUID, 0, 1,
43 &input, NULL);
44 if (ACPI_FAILURE(status))
45 return -ENODEV;
46 } else {
47 return -EINVAL;
49 return count;
52 static DEVICE_ATTR_WO(force_power);
54 static struct attribute *tbt_attrs[] = {
55 &dev_attr_force_power.attr,
56 NULL
59 static const struct attribute_group tbt_attribute_group = {
60 .attrs = tbt_attrs,
63 static int intel_wmi_thunderbolt_probe(struct wmi_device *wdev)
65 int ret;
67 ret = sysfs_create_group(&wdev->dev.kobj, &tbt_attribute_group);
68 kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE);
69 return ret;
72 static int intel_wmi_thunderbolt_remove(struct wmi_device *wdev)
74 sysfs_remove_group(&wdev->dev.kobj, &tbt_attribute_group);
75 kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE);
76 return 0;
79 static const struct wmi_device_id intel_wmi_thunderbolt_id_table[] = {
80 { .guid_string = INTEL_WMI_THUNDERBOLT_GUID },
81 { },
84 static struct wmi_driver intel_wmi_thunderbolt_driver = {
85 .driver = {
86 .name = "intel-wmi-thunderbolt",
88 .probe = intel_wmi_thunderbolt_probe,
89 .remove = intel_wmi_thunderbolt_remove,
90 .id_table = intel_wmi_thunderbolt_id_table,
93 module_wmi_driver(intel_wmi_thunderbolt_driver);
95 MODULE_ALIAS("wmi:" INTEL_WMI_THUNDERBOLT_GUID);
96 MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
97 MODULE_DESCRIPTION("Intel WMI Thunderbolt force power driver");
98 MODULE_LICENSE("GPL");