asus-wmi-sensors/asus-wmi-sensors.c

675 lines
17 KiB
C
Raw Normal View History

2018-12-11 23:11:53 +00:00
// SPDX-License-Identifier: GPL-2.0+
/*
* Asus WMI sensors HWMON driver
*
* Copyright (C) 2018-2019 Ed Brindley <kernel@maidavale.org>
2018-12-11 23:11:53 +00:00
*/
#define PLATFORM_DRIVER
2018-12-11 23:11:53 +00:00
#include <linux/dmi.h>
2018-11-25 23:48:36 +00:00
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
2018-11-30 18:04:10 +00:00
#include <linux/init.h>
#include <linux/jiffies.h>
2018-11-30 18:04:10 +00:00
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_device.h>
2018-11-25 23:48:36 +00:00
#include <linux/wmi.h>
MODULE_AUTHOR("Ed Brindley <kernel@maidavale.org>");
MODULE_DESCRIPTION("Asus WMI Sensors Driver");
MODULE_LICENSE("GPL");
2019-02-03 15:20:23 +00:00
MODULE_VERSION("3");
2018-11-25 23:48:36 +00:00
#define ASUS_HW_GUID "466747A0-70EC-11DE-8A39-0800200C9A66"
2019-01-08 14:44:38 +00:00
#define CROSSHAIR_6 "CROSSHAIR VI HERO"
#define CROSSHAIR_6_WIFI "ROG CROSSHAIR VI HERO (WI-FI AC)"
#define CROSSHAIR_6_EXTREME "ROG CROSSHAIR VI EXTREME"
2018-12-11 23:11:53 +00:00
#define CROSSHAIR_7 "ROG CROSSHAIR VII HERO"
#define CROSSHAIR_7_WIFI "ROG CROSSHAIR VII HERO (WI-FI)"
#define ZENITH_EXTREME "ROG ZENITH EXTREME"
#define ZENITH_EXTREME_ALPHA "ROG ZENITH EXTREME ALPHA"
#define PRIME_X470_PRO "PRIME X470-PRO"
2019-06-11 21:57:12 +00:00
#define PRIME_X399_A "PRIME X399-A"
2019-07-06 09:32:05 +00:00
#define STRIX_X399_E "ROG STRIX X399-E GAMING"
#define STRIX_B450_E "ROG STRIX B450-E GAMING"
#define STRIX_B450_F "ROG STRIX B450-F GAMING"
2019-07-17 08:26:46 +00:00
#define STRIX_B450_I "ROG STRIX B450-I GAMING"
2019-07-20 09:46:55 +00:00
#define STRIX_X470_I "ROG STRIX X470-I GAMING"
#define STRIX_X470_F "ROG STRIX X470-F GAMING"
2018-12-11 23:11:53 +00:00
2018-11-30 18:04:10 +00:00
#define METHODID_SENSOR_GET_VALUE 0x52574543
#define METHODID_SENSOR_UPDATE_BUFFER 0x51574543
#define METHODID_SENSOR_GET_INFO 0x50574543
#define METHODID_SENSOR_GET_NUMBER 0x50574572
#define METHODID_SENSOR_GET_BUFFER_ADDRESS 0x50574573
#define METHODID_SENSOR_GET_VERSION 0x50574574
2018-11-25 23:48:36 +00:00
#define ASUS_WMI_MAX_STR_SIZE 32
#define HWMON_MAX 9
2018-11-25 23:48:36 +00:00
enum asus_wmi_sensor_class {
VOLTAGE = 0x0,
TEMPERATURE_C = 0x1,
FAN_RPM = 0x2,
CURRENT = 0x3,
WATER_FLOW = 0x4,
2019-02-03 15:23:34 +00:00
//BOOL = 0x5 //TODO
2018-11-25 23:48:36 +00:00
};
enum asus_wmi_location {
CPU = 0x0,
CPU_SOC = 0x1,
DRAM = 0x2,
MOTHERBOARD = 0x3,
CHIPSET = 0x4,
AUX = 0x5,
VRM = 0x6,
COOLER = 0x7
};
enum asus_wmi_type {
SIGNED_INT = 0x0,
UNSIGNED_INT = 0x1,
2019-02-03 15:23:34 +00:00
//BOOL = 0x2, //TODO
2019-02-03 15:20:23 +00:00
SCALED = 0x3,
};
enum asus_wmi_source {
SIO = 0x1,
EC = 0x2
};
2018-11-25 23:48:36 +00:00
static enum hwmon_sensor_types asus_data_types[] = {
[VOLTAGE] = hwmon_in,
[TEMPERATURE_C] = hwmon_temp,
[FAN_RPM] = hwmon_fan,
[CURRENT] = hwmon_curr,
[WATER_FLOW] = hwmon_fan,
};
static u32 hwmon_attributes[] = {
[hwmon_chip] = HWMON_C_REGISTER_TZ,
[hwmon_temp] = HWMON_T_INPUT | HWMON_T_LABEL,
[hwmon_in] = HWMON_I_INPUT | HWMON_I_LABEL,
[hwmon_curr] = HWMON_C_INPUT | HWMON_C_LABEL,
[hwmon_fan] = HWMON_F_INPUT | HWMON_F_LABEL,
};
struct asus_wmi_sensor_info {
u32 id;
int data_type; // asus_wmi_sensor_class e.g. voltage, temp etc
int location; // asus_wmi_location
2018-11-25 23:48:36 +00:00
char name[ASUS_WMI_MAX_STR_SIZE];
int source; // asus_wmi_source
int type; // asus_wmi_type signed, unsigned etc
u32 cached_value;
2018-11-25 23:48:36 +00:00
};
struct asus_wmi_sensors {
#ifdef PLATFORM_DRIVER
struct platform_driver platform_driver;
struct platform_device *platform_device;
#else
2018-12-11 23:11:53 +00:00
struct wmi_driver wmi_driver;
struct wmi_device *wmi_device;
#endif
2018-11-25 23:48:36 +00:00
2018-11-30 18:04:10 +00:00
u8 buffer;
unsigned long source_last_updated[3]; /* in jiffies */
u8 sensor_count;
2018-11-30 18:04:10 +00:00
struct mutex lock;
const struct asus_wmi_sensor_info **info[HWMON_MAX];
struct asus_wmi_sensor_info **info_by_id;
2018-11-25 23:48:36 +00:00
};
2018-11-30 18:04:10 +00:00
/*
* Universal method for calling WMI method
* @method_id:
* @args:
* @output:
*/
2018-11-25 23:48:36 +00:00
static int asus_wmi_call_method(u32 method_id, u32 *args, struct acpi_buffer *output)
{
struct acpi_buffer input = {(acpi_size) sizeof(*args), args };
acpi_status status;
status = wmi_evaluate_method(ASUS_HW_GUID,
0,
method_id,
&input, output);
if (ACPI_FAILURE(status)) {
return -EIO;
}
return 0;
}
/*
* Gets the version of the ASUS sensors interface implemented
*/
2018-11-25 23:48:36 +00:00
static int get_version(u32 *version)
{
u32 args[] = {0, 0, 0};
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
2018-11-30 18:04:10 +00:00
int status = asus_wmi_call_method(METHODID_SENSOR_GET_VERSION, args, &output);
2018-11-25 23:48:36 +00:00
if (!status) {
union acpi_object *obj = (union acpi_object *)output.pointer;
if (obj && obj->type == ACPI_TYPE_INTEGER) {
*version = obj->integer.value;
}
}
return status;
}
/*
* Gets the number of sensor items
*/
2018-11-25 23:48:36 +00:00
static int get_item_count(u32 *count)
{
u32 args[] = {0, 0, 0};
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
2018-11-30 18:04:10 +00:00
int status = asus_wmi_call_method(METHODID_SENSOR_GET_NUMBER, args, &output);
2018-11-25 23:48:36 +00:00
if (!status) {
union acpi_object *obj = (union acpi_object *)output.pointer;
if (obj && obj->type == ACPI_TYPE_INTEGER) {
*count = obj->integer.value;
}
}
return status;
}
/*
* For a given sensor item returns details e.g. type (voltage/temperature/fan speed etc), bank etc
*/
2018-11-25 23:48:36 +00:00
static int info(int index, struct asus_wmi_sensor_info *s)
{
u32 args[] = {index, 0};
union acpi_object name_obj, data_type_obj, location_obj, source_obj, type_obj;
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
union acpi_object *obj;
2018-11-30 18:04:10 +00:00
int status = asus_wmi_call_method(METHODID_SENSOR_GET_INFO, args, &output);
2018-11-25 23:48:36 +00:00
if (!status) {
s->id = index;
obj = (union acpi_object *)output.pointer;
if (obj && obj->type == ACPI_TYPE_PACKAGE) {
if(obj->package.count != 5) {
return 1;
}
name_obj = obj->package.elements[0];
if (name_obj.type != ACPI_TYPE_STRING) {
return 1;
}
strncpy(s->name, name_obj.string.pointer, sizeof s->name - 1);
data_type_obj = obj->package.elements[1];
if (data_type_obj.type != ACPI_TYPE_INTEGER) {
return 1;
}
s->data_type = data_type_obj.integer.value;
location_obj = obj->package.elements[2];
if (location_obj.type != ACPI_TYPE_INTEGER) {
return 1;
}
s->location = location_obj.integer.value;
source_obj = obj->package.elements[3];
if (source_obj.type != ACPI_TYPE_INTEGER) {
return 1;
}
s->source = source_obj.integer.value;
type_obj = obj->package.elements[4];
if (type_obj.type != ACPI_TYPE_INTEGER) {
return 1;
}
s->type = type_obj.integer.value;
}
}
return status;
}
2018-11-30 18:04:10 +00:00
static int update_buffer(u8 source)
2018-11-25 23:48:36 +00:00
{
u32 args[] = {source, 0};
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
2018-11-30 18:04:10 +00:00
return asus_wmi_call_method(METHODID_SENSOR_UPDATE_BUFFER, args, &output);
2018-11-25 23:48:36 +00:00
}
2018-11-30 18:04:10 +00:00
static int get_sensor_value(u8 index, u32 *value)
2018-11-25 23:48:36 +00:00
{
u32 args[] = {index, 0};
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
2018-11-30 18:04:10 +00:00
int status = asus_wmi_call_method(METHODID_SENSOR_GET_VALUE, args, &output);
2018-11-25 23:48:36 +00:00
if (!status) {
union acpi_object *obj = (union acpi_object *)output.pointer;
if (obj && obj->type == ACPI_TYPE_INTEGER) {
*value = obj->integer.value;
}
}
return status;
}
static void update_values_for_source(u8 source, struct asus_wmi_sensors *asus_wmi_sensors) {
int ret = 0;
int value = 0;
int i;
struct asus_wmi_sensor_info *sensor;
for (i = 0; i < asus_wmi_sensors->sensor_count;i++) {
sensor = asus_wmi_sensors->info_by_id[i];
2019-02-03 15:20:23 +00:00
if(sensor && sensor->source == source) {
ret = get_sensor_value(sensor->id, &value);
if (!ret) {
sensor->cached_value = value;
}
}
}
}
static int scale_sensor_value(u32 value, int data_type) {
switch (data_type) {
case VOLTAGE:
return DIV_ROUND_CLOSEST(value, 1000);
case TEMPERATURE_C:
return value * 1000;
case CURRENT:
return value * 1000;
}
return value; // FAN_RPM and WATER_FLOW don't need scaling
}
static int get_cached_value_or_update(const struct asus_wmi_sensor_info *sensor, struct asus_wmi_sensors *asus_wmi_sensors, u32 *value) {
int ret;
if (time_after(jiffies, asus_wmi_sensors->source_last_updated[sensor->source] + HZ)) {
ret = update_buffer(sensor->source);
if (ret) {
pr_err("update_buffer failure\n");
return -EIO;
}
asus_wmi_sensors->buffer = sensor->source;
update_values_for_source(sensor->source, asus_wmi_sensors);
asus_wmi_sensors->source_last_updated[sensor->source] = jiffies;
}
2019-01-13 16:38:42 +00:00
*value = sensor->cached_value;
return 0;
}
2018-11-30 18:04:10 +00:00
/*
* Now follow the functions that implement the hwmon interface
*/
2018-11-25 23:48:36 +00:00
static int asus_wmi_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
int ret;
u32 value = 0;
const struct asus_wmi_sensor_info *sensor;
struct asus_wmi_sensors *asus_wmi_sensors = dev_get_drvdata(dev);
sensor = *(asus_wmi_sensors->info[type] + channel);
2018-11-30 18:04:10 +00:00
mutex_lock(&asus_wmi_sensors->lock);
2018-11-25 23:48:36 +00:00
ret = get_cached_value_or_update(sensor, asus_wmi_sensors, &value);
2018-11-30 18:04:10 +00:00
mutex_unlock(&asus_wmi_sensors->lock);
if (!ret) {
*val = scale_sensor_value(value, sensor->data_type);
2018-11-30 18:04:10 +00:00
}
2018-11-25 23:48:36 +00:00
return ret;
}
static int
asus_wmi_hwmon_read_string(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, const char **str)
{
const struct asus_wmi_sensor_info *sensor;
struct asus_wmi_sensors *asus_wmi_sensors = dev_get_drvdata(dev);
sensor = *(asus_wmi_sensors->info[type] + channel);
*str = sensor->name;
return 0;
}
static umode_t
asus_wmi_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,
u32 attr, int channel)
{
const struct asus_wmi_sensor_info *sensor;
const struct asus_wmi_sensors *asus_wmi_sensors = drvdata;
sensor = *(asus_wmi_sensors->info[type] + channel);
if (sensor && sensor->name)
return S_IRUGO;
return 0;
}
static int asus_wmi_hwmon_add_chan_info(struct hwmon_channel_info *asus_wmi_hwmon_chan,
struct device *dev, int num,
enum hwmon_sensor_types type, u32 config)
{
int i;
u32 *cfg = devm_kcalloc(dev, num + 1, sizeof(*cfg), GFP_KERNEL);
if (!cfg)
return -ENOMEM;
asus_wmi_hwmon_chan->type = type;
asus_wmi_hwmon_chan->config = cfg;
for (i = 0; i < num; i++, cfg++)
*cfg = config;
return 0;
}
static const struct hwmon_ops asus_wmi_hwmon_ops = {
.is_visible = asus_wmi_hwmon_is_visible,
.read = asus_wmi_hwmon_read,
.read_string = asus_wmi_hwmon_read_string,
};
static struct hwmon_chip_info asus_wmi_chip_info = {
.ops = &asus_wmi_hwmon_ops,
.info = NULL,
};
2018-11-30 18:04:10 +00:00
static int configure_sensor_setup(struct asus_wmi_sensors *asus_wmi_sensors)
2018-11-25 23:48:36 +00:00
{
int err;
int i, idx;
int nr_count[HWMON_MAX] = {0}, nr_types = 0;
2018-11-25 23:48:36 +00:00
u32 nr_sensors = 0;
struct device *hwdev;
#ifdef PLATFORM_DRIVER
struct device *dev = &asus_wmi_sensors->platform_device->dev;
#else
struct device *dev = &asus_wmi_sensors->wmi_device->dev;
#endif
2018-11-25 23:48:36 +00:00
struct hwmon_channel_info *asus_wmi_hwmon_chan;
struct asus_wmi_sensor_info *temp_sensor;
enum hwmon_sensor_types type;
const struct hwmon_channel_info **ptr_asus_wmi_ci;
const struct hwmon_chip_info *chip_info;
2018-11-30 18:04:10 +00:00
asus_wmi_sensors->buffer = -1;
mutex_init(&asus_wmi_sensors->lock);
2018-11-25 23:48:36 +00:00
temp_sensor = devm_kcalloc(dev, 1, sizeof(*temp_sensor), GFP_KERNEL);
if (!temp_sensor) {
2018-11-30 18:04:10 +00:00
pr_err("Alloc fail\n");
2018-11-25 23:48:36 +00:00
return -ENOMEM;
}
get_item_count(&nr_sensors);
asus_wmi_sensors->sensor_count = nr_sensors;
2018-12-11 23:11:53 +00:00
pr_debug("sensor count %u\n", nr_sensors);
2018-11-25 23:48:36 +00:00
for (i = 0; i < nr_sensors; i++) {
err = info(i, temp_sensor);
if (err)
return -EINVAL;
switch (temp_sensor->data_type) {
case TEMPERATURE_C:
case VOLTAGE:
case CURRENT:
case FAN_RPM:
case WATER_FLOW:
type = asus_data_types[temp_sensor->data_type];
if (!nr_count[type])
nr_types++;
nr_count[type]++;
break;
}
}
if (nr_count[hwmon_temp])
nr_count[hwmon_chip]++, nr_types++;
asus_wmi_hwmon_chan = devm_kcalloc(dev, nr_types, sizeof(*asus_wmi_hwmon_chan),
GFP_KERNEL);
if (!asus_wmi_hwmon_chan)
return -ENOMEM;
ptr_asus_wmi_ci = devm_kcalloc(dev, nr_types + 1, sizeof(*ptr_asus_wmi_ci),
GFP_KERNEL);
if (!ptr_asus_wmi_ci)
return -ENOMEM;
asus_wmi_chip_info.info = ptr_asus_wmi_ci;
chip_info = &asus_wmi_chip_info;
asus_wmi_sensors->info_by_id =
devm_kcalloc(dev, nr_sensors, sizeof(*asus_wmi_sensors->info_by_id), GFP_KERNEL);
2019-02-03 15:20:23 +00:00
if (!asus_wmi_sensors->info_by_id)
return -ENOMEM;
for (type = 0; type < HWMON_MAX; type++) {
2018-11-25 23:48:36 +00:00
if (!nr_count[type])
continue;
asus_wmi_hwmon_add_chan_info(asus_wmi_hwmon_chan, dev, nr_count[type],
type, hwmon_attributes[type]);
*ptr_asus_wmi_ci++ = asus_wmi_hwmon_chan++;
asus_wmi_sensors->info[type] =
devm_kcalloc(dev, nr_count[type], sizeof(*asus_wmi_sensors->info), GFP_KERNEL);
if (!asus_wmi_sensors->info[type])
return -ENOMEM;
}
for (i = nr_sensors - 1; i >= 0 ; i--) {
temp_sensor = devm_kzalloc(dev, sizeof(*temp_sensor), GFP_KERNEL);
if (!temp_sensor) {
2018-12-20 00:10:23 +00:00
pr_err("asuswmisensors: Alloc fail\n");
2018-11-25 23:48:36 +00:00
return -ENOMEM;
}
err = info(i, temp_sensor);
if (err) {
2018-12-20 00:10:23 +00:00
pr_err("asuswmisensors: sensor error\n");
2018-11-25 23:48:36 +00:00
continue;
}
2018-12-20 00:10:23 +00:00
pr_debug("asuswmisensors: setting sensor info\n");
2018-11-25 23:48:36 +00:00
switch (temp_sensor->data_type) {
case TEMPERATURE_C:
case VOLTAGE:
case CURRENT:
case FAN_RPM:
case WATER_FLOW:
type = asus_data_types[temp_sensor->data_type];
idx = --nr_count[type];
*(asus_wmi_sensors->info[type] + idx) = temp_sensor;
asus_wmi_sensors->info_by_id[i] = temp_sensor;
2018-11-25 23:48:36 +00:00
break;
}
}
hwdev = devm_hwmon_device_register_with_info(dev, "asuswmisensors",
2018-11-25 23:48:36 +00:00
asus_wmi_sensors, chip_info,
NULL);
return PTR_ERR_OR_ZERO(hwdev);
}
2018-12-11 23:11:53 +00:00
static int is_board_supported(void) {
2018-12-20 00:10:23 +00:00
const char *board_vendor, *board_name, *bios_version;
2018-11-30 18:04:10 +00:00
u32 version = 0;
2018-12-11 23:11:53 +00:00
board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
board_name = dmi_get_system_info(DMI_BOARD_NAME);
2018-12-20 00:10:23 +00:00
bios_version = dmi_get_system_info(DMI_BIOS_VERSION);
2018-11-30 18:04:10 +00:00
if(get_version(&version)) {
2018-12-20 00:10:23 +00:00
pr_err("asuswmisensors: Error getting version\n");
2018-11-30 18:04:10 +00:00
return -ENODEV;
}
2018-12-20 00:10:23 +00:00
if (board_vendor && board_name && bios_version) {
pr_info("asuswmisensors: Vendor: %s Board: %s BIOS version: %s WMI version: %u", board_vendor, board_name, bios_version, version);
2018-11-30 18:04:10 +00:00
2018-12-11 23:11:53 +00:00
if (version >= 3 || (version >= 2 && (
strcmp(board_name, CROSSHAIR_7_WIFI) == 0 ||
strcmp(board_name, CROSSHAIR_7) == 0 ||
strcmp(board_name, CROSSHAIR_6_WIFI) == 0 ||
2018-12-16 18:51:53 +00:00
strcmp(board_name, CROSSHAIR_6) == 0 ||
2019-01-08 14:44:38 +00:00
strcmp(board_name, CROSSHAIR_6_EXTREME) == 0 ||
strcmp(board_name, ZENITH_EXTREME) == 0 ||
strcmp(board_name, ZENITH_EXTREME_ALPHA) == 0 ||
2019-06-11 21:57:12 +00:00
strcmp(board_name, PRIME_X399_A) == 0 ||
2019-07-06 09:32:05 +00:00
strcmp(board_name, PRIME_X470_PRO) == 0 ||
strcmp(board_name, STRIX_X399_E) == 0 ||
strcmp(board_name, STRIX_B450_E) == 0 ||
strcmp(board_name, STRIX_B450_F) == 0 ||
2019-07-20 09:46:55 +00:00
strcmp(board_name, STRIX_B450_I) == 0 ||
strcmp(board_name, STRIX_X470_I) == 0 ||
strcmp(board_name, STRIX_X470_F) == 0))) {
2018-11-30 18:04:10 +00:00
2018-12-20 00:10:23 +00:00
pr_info("asuswmisensors: Supported board");
2018-12-11 23:11:53 +00:00
return 0;
}
}
2018-12-20 00:10:23 +00:00
pr_info("asuswmisensors: Unsupported board");
2018-12-11 23:11:53 +00:00
return -ENODEV;
2018-11-30 18:04:10 +00:00
}
#ifndef PLATFORM_DRIVER
2018-12-11 23:11:53 +00:00
static int asus_wmi_sensors_probe(struct wmi_device *wdev)
2018-11-30 18:04:10 +00:00
{
2018-12-11 23:11:53 +00:00
struct device *dev = &wdev->dev;
2018-11-30 18:04:10 +00:00
struct asus_wmi_sensors *asus_wmi_sensors;
2018-12-20 00:18:56 +00:00
pr_info("asuswmisensors: WMI GUID matched - probing");
2018-12-11 23:11:53 +00:00
if (is_board_supported()) {
return -ENODEV;
}
2018-11-30 18:04:10 +00:00
2018-12-11 23:11:53 +00:00
asus_wmi_sensors = devm_kzalloc(dev, sizeof(struct asus_wmi_sensors), GFP_KERNEL);
2018-11-30 18:04:10 +00:00
if (!asus_wmi_sensors)
return -ENOMEM;
2018-12-11 23:11:53 +00:00
asus_wmi_sensors->wmi_device = wdev;
2018-11-30 18:04:10 +00:00
2018-12-11 23:11:53 +00:00
dev_set_drvdata(dev, asus_wmi_sensors);
2018-11-30 18:04:10 +00:00
return configure_sensor_setup(asus_wmi_sensors);
}
2018-12-11 23:11:53 +00:00
static int asus_wmi_sensors_remove(struct wmi_device *wdev)
2018-11-30 18:04:10 +00:00
{
2018-12-11 23:11:53 +00:00
struct asus_wmi_sensors *asus;
asus = dev_get_drvdata(&wdev->dev);
return 0;
2018-11-30 18:04:10 +00:00
}
2018-12-11 23:11:53 +00:00
static const struct wmi_device_id asus_wmi_sensors_id_table[] = {
{ .guid_string = ASUS_HW_GUID },
{ },
};
static struct wmi_driver asus_wmi_sensors = {
.driver = {
.name = "asus-wmi-sensors",
},
.probe = asus_wmi_sensors_probe,
.remove = asus_wmi_sensors_remove,
.id_table = asus_wmi_sensors_id_table,
};
module_wmi_driver(asus_wmi_sensors);
#endif
#ifdef PLATFORM_DRIVER
static struct platform_device *asus_wmi_sensors_platform_device;
static int asus_wmi_probe(struct platform_device *pdev)
{
if (!wmi_has_guid(ASUS_HW_GUID)) {
2019-01-08 22:33:22 +00:00
pr_info("asuswmisensors: ASUSHW GUID not found\n");
return -ENODEV;
}
if (is_board_supported()) {
return -ENODEV;
}
pr_info("asuswmisensors: ASUS WMI sensors driver loaded\n");
return 0;
}
static struct platform_driver asus_wmi_sensors_platform_driver = {
.driver = {
.name = "asus-wmi-sensors",
},
.probe = asus_wmi_probe
};
static int __init asus_wmi_init(void)
{
struct asus_wmi_sensors *asus_wmi_sensors;
asus_wmi_sensors_platform_device = platform_create_bundle(&asus_wmi_sensors_platform_driver,
asus_wmi_probe,
NULL, 0, NULL, 0);
if (IS_ERR(asus_wmi_sensors_platform_device))
return PTR_ERR(asus_wmi_sensors_platform_device);
asus_wmi_sensors = devm_kzalloc(&asus_wmi_sensors_platform_device->dev, sizeof(struct asus_wmi_sensors), GFP_KERNEL);
if (!asus_wmi_sensors)
return -ENOMEM;
asus_wmi_sensors->platform_device = asus_wmi_sensors_platform_device;
asus_wmi_sensors->platform_driver = asus_wmi_sensors_platform_driver;
platform_set_drvdata(asus_wmi_sensors->platform_device, asus_wmi_sensors);
return configure_sensor_setup(asus_wmi_sensors);
}
static void __exit asus_wmi_exit(void)
{
platform_device_unregister(asus_wmi_sensors_platform_device);
platform_driver_unregister(&asus_wmi_sensors_platform_driver);
}
module_init(asus_wmi_init);
module_exit(asus_wmi_exit);
2019-01-08 14:44:38 +00:00
#endif