Andy Shevchenko | a8694ee | 2018-09-26 18:27:40 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mario Limonciello | ce6a900 | 2017-09-08 10:23:11 -0500 | [diff] [blame] | 2 | /* |
| 3 | * WMI Thunderbolt driver |
| 4 | * |
| 5 | * Copyright (C) 2017 Dell Inc. All Rights Reserved. |
Mario Limonciello | ce6a900 | 2017-09-08 10:23:11 -0500 | [diff] [blame] | 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/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 acpi_buffer input; |
| 27 | acpi_status status; |
| 28 | u8 mode; |
| 29 | |
| 30 | input.length = sizeof(u8); |
| 31 | input.pointer = &mode; |
| 32 | mode = hex_to_bin(buf[0]); |
Mario Limonciello | 7eccb5e | 2018-09-26 11:10:58 -0500 | [diff] [blame] | 33 | dev_dbg(dev, "force_power: storing %#x\n", mode); |
Mario Limonciello | ce6a900 | 2017-09-08 10:23:11 -0500 | [diff] [blame] | 34 | if (mode == 0 || mode == 1) { |
| 35 | status = wmi_evaluate_method(INTEL_WMI_THUNDERBOLT_GUID, 0, 1, |
| 36 | &input, NULL); |
Mario Limonciello | 7eccb5e | 2018-09-26 11:10:58 -0500 | [diff] [blame] | 37 | if (ACPI_FAILURE(status)) { |
| 38 | dev_dbg(dev, "force_power: failed to evaluate ACPI method\n"); |
Mario Limonciello | ce6a900 | 2017-09-08 10:23:11 -0500 | [diff] [blame] | 39 | return -ENODEV; |
Mario Limonciello | 7eccb5e | 2018-09-26 11:10:58 -0500 | [diff] [blame] | 40 | } |
Mario Limonciello | ce6a900 | 2017-09-08 10:23:11 -0500 | [diff] [blame] | 41 | } else { |
Mario Limonciello | 7eccb5e | 2018-09-26 11:10:58 -0500 | [diff] [blame] | 42 | dev_dbg(dev, "force_power: unsupported mode\n"); |
Mario Limonciello | 12933ea | 2017-09-14 01:41:55 -0500 | [diff] [blame] | 43 | return -EINVAL; |
Mario Limonciello | ce6a900 | 2017-09-08 10:23:11 -0500 | [diff] [blame] | 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 | |
| 55 | static const struct attribute_group tbt_attribute_group = { |
| 56 | .attrs = tbt_attrs, |
| 57 | }; |
| 58 | |
| 59 | static int intel_wmi_thunderbolt_probe(struct wmi_device *wdev) |
| 60 | { |
| 61 | int ret; |
| 62 | |
| 63 | ret = sysfs_create_group(&wdev->dev.kobj, &tbt_attribute_group); |
| 64 | kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE); |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | static int intel_wmi_thunderbolt_remove(struct wmi_device *wdev) |
| 69 | { |
| 70 | sysfs_remove_group(&wdev->dev.kobj, &tbt_attribute_group); |
| 71 | kobject_uevent(&wdev->dev.kobj, KOBJ_CHANGE); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static const struct wmi_device_id intel_wmi_thunderbolt_id_table[] = { |
| 76 | { .guid_string = INTEL_WMI_THUNDERBOLT_GUID }, |
| 77 | { }, |
| 78 | }; |
| 79 | |
| 80 | static struct wmi_driver intel_wmi_thunderbolt_driver = { |
| 81 | .driver = { |
| 82 | .name = "intel-wmi-thunderbolt", |
| 83 | }, |
| 84 | .probe = intel_wmi_thunderbolt_probe, |
| 85 | .remove = intel_wmi_thunderbolt_remove, |
| 86 | .id_table = intel_wmi_thunderbolt_id_table, |
| 87 | }; |
| 88 | |
| 89 | module_wmi_driver(intel_wmi_thunderbolt_driver); |
| 90 | |
Mattias Jacobsson | 73814602 | 2019-02-19 20:59:55 +0100 | [diff] [blame] | 91 | MODULE_DEVICE_TABLE(wmi, intel_wmi_thunderbolt_id_table); |
Mario Limonciello | ce6a900 | 2017-09-08 10:23:11 -0500 | [diff] [blame] | 92 | MODULE_AUTHOR("Mario Limonciello <mario.limonciello@dell.com>"); |
| 93 | MODULE_DESCRIPTION("Intel WMI Thunderbolt force power driver"); |
Andy Shevchenko | a8694ee | 2018-09-26 18:27:40 +0300 | [diff] [blame] | 94 | MODULE_LICENSE("GPL v2"); |