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/acpi.h> 11 #include <linux/device.h> 12 #include <linux/fs.h> 13 #include <linux/hex.h> 14 #include <linux/kernel.h> 15 #include <linux/module.h> 16 #include <linux/string.h> 17 #include <linux/sysfs.h> 18 #include <linux/types.h> 19 #include <linux/wmi.h> 20 21 #define INTEL_WMI_THUNDERBOLT_GUID "86CCFD48-205E-4A77-9C48-2021CBEDE341" 22 23 static ssize_t force_power_store(struct device *dev, 24 struct device_attribute *attr, 25 const char *buf, size_t count) 26 { 27 struct acpi_buffer input; 28 acpi_status status; 29 u8 mode; 30 31 input.length = sizeof(u8); 32 input.pointer = &mode; 33 mode = hex_to_bin(buf[0]); 34 dev_dbg(dev, "force_power: storing %#x\n", mode); 35 if (mode == 0 || mode == 1) { 36 status = wmidev_evaluate_method(to_wmi_device(dev), 0, 1, &input, NULL); 37 if (ACPI_FAILURE(status)) { 38 dev_dbg(dev, "force_power: failed to evaluate ACPI method\n"); 39 return -ENODEV; 40 } 41 } else { 42 dev_dbg(dev, "force_power: unsupported mode\n"); 43 return -EINVAL; 44 } 45 return count; 46 } 47 48 static DEVICE_ATTR_WO(force_power); 49 50 static struct attribute *tbt_attrs[] = { 51 &dev_attr_force_power.attr, 52 NULL 53 }; 54 ATTRIBUTE_GROUPS(tbt); 55 56 static const struct wmi_device_id intel_wmi_thunderbolt_id_table[] = { 57 { .guid_string = INTEL_WMI_THUNDERBOLT_GUID }, 58 { }, 59 }; 60 61 static struct wmi_driver intel_wmi_thunderbolt_driver = { 62 .driver = { 63 .name = "intel-wmi-thunderbolt", 64 .dev_groups = tbt_groups, 65 }, 66 .id_table = intel_wmi_thunderbolt_id_table, 67 .no_singleton = true, 68 }; 69 70 module_wmi_driver(intel_wmi_thunderbolt_driver); 71 72 MODULE_DEVICE_TABLE(wmi, intel_wmi_thunderbolt_id_table); 73 MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>"); 74 MODULE_DESCRIPTION("Intel WMI Thunderbolt force power driver"); 75 MODULE_LICENSE("GPL v2"); 76