2018-09-26 18:27:40 +03:00
// SPDX-License-Identifier: GPL-2.0
2017-09-08 18:23:11 +03:00
/*
* 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 ] ) ;
2018-09-26 19:10:58 +03:00
dev_dbg ( dev , " force_power: storing %#x \n " , mode ) ;
2017-09-08 18:23:11 +03:00
if ( mode = = 0 | | mode = = 1 ) {
status = wmi_evaluate_method ( INTEL_WMI_THUNDERBOLT_GUID , 0 , 1 ,
& input , NULL ) ;
2018-09-26 19:10:58 +03:00
if ( ACPI_FAILURE ( status ) ) {
dev_dbg ( dev , " force_power: failed to evaluate ACPI method \n " ) ;
2017-09-08 18:23:11 +03:00
return - ENODEV ;
2018-09-26 19:10:58 +03:00
}
2017-09-08 18:23:11 +03:00
} else {
2018-09-26 19:10:58 +03:00
dev_dbg ( dev , " force_power: unsupported mode \n " ) ;
2017-09-14 09:41:55 +03:00
return - EINVAL ;
2017-09-08 18:23:11 +03:00
}
return count ;
}
static DEVICE_ATTR_WO ( force_power ) ;
static struct attribute * tbt_attrs [ ] = {
& dev_attr_force_power . attr ,
NULL
} ;
static const struct attribute_group tbt_attribute_group = {
. attrs = tbt_attrs ,
} ;
2019-05-27 19:21:30 +03:00
static int intel_wmi_thunderbolt_probe ( struct wmi_device * wdev ,
const void * context )
2017-09-08 18:23:11 +03:00
{
int ret ;
ret = sysfs_create_group ( & wdev - > dev . kobj , & tbt_attribute_group ) ;
kobject_uevent ( & wdev - > dev . kobj , KOBJ_CHANGE ) ;
return ret ;
}
static int intel_wmi_thunderbolt_remove ( struct wmi_device * wdev )
{
sysfs_remove_group ( & wdev - > dev . kobj , & tbt_attribute_group ) ;
kobject_uevent ( & wdev - > dev . kobj , KOBJ_CHANGE ) ;
return 0 ;
}
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 " ,
} ,
. probe = intel_wmi_thunderbolt_probe ,
. remove = intel_wmi_thunderbolt_remove ,
. id_table = intel_wmi_thunderbolt_id_table ,
} ;
module_wmi_driver ( intel_wmi_thunderbolt_driver ) ;
2019-02-19 22:59:55 +03:00
MODULE_DEVICE_TABLE ( wmi , intel_wmi_thunderbolt_id_table ) ;
2017-09-08 18:23:11 +03:00
MODULE_AUTHOR ( " Mario Limonciello <mario.limonciello@dell.com> " ) ;
MODULE_DESCRIPTION ( " Intel WMI Thunderbolt force power driver " ) ;
2018-09-26 18:27:40 +03:00
MODULE_LICENSE ( " GPL v2 " ) ;