treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / platform / x86 / intel-wmi-thunderbolt.c
blob974c22a7ff61ee4c124f4255bfc053bb892afb0a
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * WMI Thunderbolt driver
5 * Copyright (C) 2017 Dell Inc. All Rights Reserved.
6 */
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/acpi.h>
11 #include <linux/device.h>
12 #include <linux/fs.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>
20 #define INTEL_WMI_THUNDERBOLT_GUID "86CCFD48-205E-4A77-9C48-2021CBEDE341"
22 static ssize_t force_power_store(struct device *dev,
23 struct device_attribute *attr,
24 const char *buf, size_t count)
26 struct acpi_buffer input;
27 acpi_status status;
28 u8 mode;
30 input.length = sizeof(u8);
31 input.pointer = &mode;
32 mode = hex_to_bin(buf[0]);
33 dev_dbg(dev, "force_power: storing %#x\n", mode);
34 if (mode == 0 || mode == 1) {
35 status = wmi_evaluate_method(INTEL_WMI_THUNDERBOLT_GUID, 0, 1,
36 &input, NULL);
37 if (ACPI_FAILURE(status)) {
38 dev_dbg(dev, "force_power: failed to evaluate ACPI method\n");
39 return -ENODEV;
41 } else {
42 dev_dbg(dev, "force_power: unsupported mode\n");
43 return -EINVAL;
45 return count;
48 static DEVICE_ATTR_WO(force_power);
50 static struct attribute *tbt_attrs[] = {
51 &dev_attr_force_power.attr,
52 NULL
55 static const struct attribute_group tbt_attribute_group = {
56 .attrs = tbt_attrs,
59 static int intel_wmi_thunderbolt_probe(struct wmi_device *wdev,
60 const void *context)
62 int ret;
64 ret = sysfs_create_group(&wdev->dev.kobj, &tbt_attribute_group);
65 kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE);
66 return ret;
69 static int intel_wmi_thunderbolt_remove(struct wmi_device *wdev)
71 sysfs_remove_group(&wdev->dev.kobj, &tbt_attribute_group);
72 kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE);
73 return 0;
76 static const struct wmi_device_id intel_wmi_thunderbolt_id_table[] = {
77 { .guid_string = INTEL_WMI_THUNDERBOLT_GUID },
78 { },
81 static struct wmi_driver intel_wmi_thunderbolt_driver = {
82 .driver = {
83 .name = "intel-wmi-thunderbolt",
85 .probe = intel_wmi_thunderbolt_probe,
86 .remove = intel_wmi_thunderbolt_remove,
87 .id_table = intel_wmi_thunderbolt_id_table,
90 module_wmi_driver(intel_wmi_thunderbolt_driver);
92 MODULE_DEVICE_TABLE(wmi, intel_wmi_thunderbolt_id_table);
93 MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
94 MODULE_DESCRIPTION("Intel WMI Thunderbolt force power driver");
95 MODULE_LICENSE("GPL v2");