summaryrefslogtreecommitdiffstats
path: root/drivers/platform/x86/intel/wmi/thunderbolt.c
blob: e2ad3f46f3569f97d883cb21735b6b571d87ffdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: GPL-2.0
/*
 * WMI Thunderbolt driver
 *
 * Copyright (C) 2017 Dell Inc. All Rights Reserved.
 */

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/acpi.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/string.h>
#include <linux/sysfs.h>
#include <linux/types.h>
#include <linux/wmi.h>

#define INTEL_WMI_THUNDERBOLT_GUID "86CCFD48-205E-4A77-9C48-2021CBEDE341"

static ssize_t force_power_store(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t count)
{
	struct acpi_buffer input;
	acpi_status status;
	u8 mode;

	input.length = sizeof(u8);
	input.pointer = &mode;
	mode = hex_to_bin(buf[0]);
	dev_dbg(dev, "force_power: storing %#x\n", mode);
	if (mode == 0 || mode == 1) {
		status = wmidev_evaluate_method(to_wmi_device(dev), 0, 1, &input, NULL);
		if (ACPI_FAILURE(status)) {
			dev_dbg(dev, "force_power: failed to evaluate ACPI method\n");
			return -ENODEV;
		}
	} else {
		dev_dbg(dev, "force_power: unsupported mode\n");
		return -EINVAL;
	}
	return count;
}

static DEVICE_ATTR_WO(force_power);

static struct attribute *tbt_attrs[] = {
	&dev_attr_force_power.attr,
	NULL
};
ATTRIBUTE_GROUPS(tbt);

static const struct wmi_device_id intel_wmi_thunderbolt_id_table[] = {
	{ .guid_string = INTEL_WMI_THUNDERBOLT_GUID },
	{ },
};

static struct wmi_driver intel_wmi_thunderbolt_driver = {
	.driver = {
		.name = "intel-wmi-thunderbolt",
		.dev_groups = tbt_groups,
	},
	.id_table = intel_wmi_thunderbolt_id_table,
};

module_wmi_driver(intel_wmi_thunderbolt_driver);

MODULE_DEVICE_TABLE(wmi, intel_wmi_thunderbolt_id_table);
MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
MODULE_DESCRIPTION("Intel WMI Thunderbolt force power driver");
MODULE_LICENSE("GPL v2");