^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * WMI Thunderbolt driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2017 Dell Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/sysfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/wmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define INTEL_WMI_THUNDERBOLT_GUID "86CCFD48-205E-4A77-9C48-2021CBEDE341"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static ssize_t force_power_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct acpi_buffer input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) input.length = sizeof(u8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) input.pointer = &mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) mode = hex_to_bin(buf[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) dev_dbg(dev, "force_power: storing %#x\n", mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) if (mode == 0 || mode == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) status = wmi_evaluate_method(INTEL_WMI_THUNDERBOLT_GUID, 0, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) &input, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) dev_dbg(dev, "force_power: failed to evaluate ACPI method\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) dev_dbg(dev, "force_power: unsupported mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static DEVICE_ATTR_WO(force_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static struct attribute *tbt_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) &dev_attr_force_power.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static const struct attribute_group tbt_attribute_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .attrs = tbt_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static int intel_wmi_thunderbolt_probe(struct wmi_device *wdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) const void *context)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ret = sysfs_create_group(&wdev->dev.kobj, &tbt_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static int intel_wmi_thunderbolt_remove(struct wmi_device *wdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) sysfs_remove_group(&wdev->dev.kobj, &tbt_attribute_group);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static const struct wmi_device_id intel_wmi_thunderbolt_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) { .guid_string = INTEL_WMI_THUNDERBOLT_GUID },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static struct wmi_driver intel_wmi_thunderbolt_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .name = "intel-wmi-thunderbolt",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .probe = intel_wmi_thunderbolt_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .remove = intel_wmi_thunderbolt_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .id_table = intel_wmi_thunderbolt_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) module_wmi_driver(intel_wmi_thunderbolt_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) MODULE_DEVICE_TABLE(wmi, intel_wmi_thunderbolt_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) MODULE_DESCRIPTION("Intel WMI Thunderbolt force power driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) MODULE_LICENSE("GPL v2");