/*
* Copyright (C) 2007-2009 Luca Tettamanti <kronos.it@gmail.com>
*
* This file is released under the GPLv2
* See COPYING in the top level directory of the kernel tree.
*/
#include <linux/kernel.h>
#include <linux/hwmon.h>
#include <linux/list.h>
#include <linux/module.h>
#include <acpi/acpi.h>
#include <acpi/acpixf.h>
#include <acpi/acpi_drivers.h>
#include <acpi/acpi_bus.h>
#define ATK_HID "ATK0110"
/* Minimum time between readings, enforced in order to avoid
* hogging the CPU.
*/
#define CACHE_TIME HZ
#define BOARD_ID "MBIF"
#define METHOD_ENUMERATE "GGRP"
#define METHOD_READ "GITM"
#define METHOD_WRITE "SITM"
#define METHOD_OLD_READ_TMP "RTMP"
#define METHOD_OLD_READ_VLT "RVLT"
#define METHOD_OLD_READ_FAN "RFAN"
#define METHOD_OLD_ENUM_TMP "TSIF"
#define METHOD_OLD_ENUM_VLT "VSIF"
#define METHOD_OLD_ENUM_FAN "FSIF"
#define ATK_MUX_HWMON 0x00000006ULL
#define ATK_MUX_MGMT 0x00000011ULL
#define ATK_CLASS_MASK 0xff000000ULL
#define ATK_CLASS_FREQ_CTL 0x03000000ULL
#define ATK_CLASS_FAN_CTL 0x04000000ULL
#define ATK_CLASS_HWMON 0x06000000ULL
#define ATK_CLASS_MGMT 0x11000000ULL
#define ATK_TYPE_MASK 0x00ff0000ULL
#define HWMON_TYPE_VOLT 0x00020000ULL
#define HWMON_TYPE_TEMP 0x00030000ULL
#define HWMON_TYPE_FAN 0x00040000ULL
#define ATK_ELEMENT_ID_MASK 0x0000ffffULL
#define ATK_EC_ID 0x11060004ULL
enum atk_pack_member {
HWMON_PACK_FLAGS,
HWMON_PACK_NAME,
HWMON_PACK_LIMIT1,
HWMON_PACK_LIMIT2,
HWMON_PACK_ENABLE
};
/* New package format */
#define _HWMON_NEW_PACK_SIZE 7
#define _HWMON_NEW_PACK_FLAGS 0
#define _HWMON_NEW_PACK_NAME 1
#define _HWMON_NEW_PACK_UNK1 2
#define _HWMON_NEW_PACK_UNK2 3
#define _HWMON_NEW_PACK_LIMIT1 4
#define _HWMON_NEW_PACK_LIMIT2 5
#define _HWMON_NEW_PACK_ENABLE 6
/* Old package format */
#define _HWMON_OLD_PACK_SIZE 5
#define _HWMON_OLD_PACK_FLAGS 0
#define _HWMON_OLD_PACK_NAME 1
#define _HWMON_OLD_PACK_LIMIT1 2
#define _HWMON_OLD_PACK_LIMIT2 3
#define _HWMON_OLD_PACK_ENABLE 4
struct atk_data {
struct device *hwmon_dev;
acpi_handle atk_handle;
struct acpi_device *acpi_dev;
bool old_interface;
/* old interface */
acpi_handle rtmp_handle;
acpi_handle rvlt_handle;
acpi_handle rfan_handle;
/* new inteface */
acpi_handle enumerate_handle;
acpi_handle read_handle;
acpi_handle write_handle;
bool disable_ec;
int voltage_count;
int temperature_count;
int fan_count;
struct list_head sensor_list;
};
typedef ssize_t (*sysfs_show_func)(struct device *dev,
struct device_attribute *attr, char *buf);
static const struct acpi_device_id atk_ids[] = {
{ATK_HID, 0},
{"", 0},
};
MODULE_DEVICE_TABLE(acpi, atk_ids);
#define ATTR_NAME_SIZE 16 /* Worst case is "tempN_input" */
struct atk_sensor_data {
struct list_head list;
struct atk_data *data;
struct device_attribute label_attr;
struct device_attribute input_attr;
struct device_attribute limit1_attr;
struct device_attribute limit2_attr;
char label_attr_name[ATTR_NAME_SIZE];
char input_attr_name[ATTR_NAME_SIZE];
char limit1_attr_name[ATTR_NAME_SIZE];
char limit2_attr_name[ATTR_NAME_SIZE];
u64 id;
u64 type;
u64 limit1;
u64 limit2;
u64 cached_value;
unsigned long last_updated; /* in jiffies */
bool is_valid;
char const *acpi_name;
};
/* Return buffer format:
* [0-3] "value" is valid flag
* [4-7] value
* [8- ] unknown stuff on newer mobos
*/
struct atk_acpi_ret_buffer {
u32 flags;
u32 value;
u8 data[];
};
/* Input buffer used for GITM and SITM methods */
struct atk_acpi_input_buf {
u32 id;
u32 param1;
u32 param2;
};
static int atk_add(struct acpi_device *device);
static int atk_remove