xref: /linux/drivers/platform/x86/intel/wmi/thunderbolt.c (revision 1fd1dc41724319406b0aff221a352a400b0ddfc5)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * WMI Thunderbolt driver
4  *
5  * Copyright (C) 2017 Dell Inc. All Rights Reserved.
6  */
7 
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9 
10 #include <linux/device.h>
11 #include <linux/fs.h>
12 #include <linux/hex.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/string.h>
16 #include <linux/sysfs.h>
17 #include <linux/types.h>
18 #include <linux/wmi.h>
19 
20 #define INTEL_WMI_THUNDERBOLT_GUID "86CCFD48-205E-4A77-9C48-2021CBEDE341"
21 
22 static ssize_t force_power_store(struct device *dev,
23 				 struct device_attribute *attr,
24 				 const char *buf, size_t count)
25 {
26 	struct wmi_buffer buffer;
27 	int ret;
28 	u8 mode;
29 
30 	buffer.length = sizeof(mode);
31 	buffer.data = &mode;
32 
33 	mode = hex_to_bin(buf[0]);
34 	if (mode > 1)
35 		return -EINVAL;
36 
37 	ret = wmidev_invoke_method(to_wmi_device(dev), 0, 1, &buffer, NULL);
38 	if (ret < 0)
39 		return ret;
40 
41 	return count;
42 }
43 
44 static DEVICE_ATTR_WO(force_power);
45 
46 static struct attribute *tbt_attrs[] = {
47 	&dev_attr_force_power.attr,
48 	NULL
49 };
50 ATTRIBUTE_GROUPS(tbt);
51 
52 static const struct wmi_device_id intel_wmi_thunderbolt_id_table[] = {
53 	{ .guid_string = INTEL_WMI_THUNDERBOLT_GUID },
54 	{ },
55 };
56 
57 static struct wmi_driver intel_wmi_thunderbolt_driver = {
58 	.driver = {
59 		.name = "intel-wmi-thunderbolt",
60 		.dev_groups = tbt_groups,
61 	},
62 	.id_table = intel_wmi_thunderbolt_id_table,
63 	.no_singleton = true,
64 };
65 
66 module_wmi_driver(intel_wmi_thunderbolt_driver);
67 
68 MODULE_DEVICE_TABLE(wmi, intel_wmi_thunderbolt_id_table);
69 MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
70 MODULE_DESCRIPTION("Intel WMI Thunderbolt force power driver");
71 MODULE_LICENSE("GPL v2");
72