mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 18:51:56 -04:00
Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging
* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging: (23 commits) hwmon: Remove the deprecated adt7473 driver hwmon: Fix off-by-one kind values hwmon: (tmp421) Fix temperature conversions hwmon: (tmp421) Restore missing inputs hwmon: Driver for Andigilog aSC7621 family monitoring chips hwmon: (adt7411) Improve locking hwmon: Add driver for ADT7411 voltage and temperature sensor hwmon: (w83793) Add watchdog functionality hwmon: (g760a) Make rpm_from_cnt static hwmon: (it87) Validate auto pwm settings hwmon: (it87) Add support for old automatic fan speed control hwmon: (it87) Drop dead web links in documentation hwmon: (it87) Add an entry in MAINTAINERS hwmon: (it87) Use strict_strtol instead of simple_strtol hwmon: (it87) Fix many checkpatch errors and warnings hwmon: (it87) Add support for beep on alarm hwmon: (it87) Create vid attributes by group hwmon: (it87) Refactor attributes creation and removal hwmon: (it87) Expose the PWM/temperature mappings hwmon: (it87) Display fan outputs in automatic mode as such ...
This commit is contained in:
commit
dff6d1c5ef
19 changed files with 3335 additions and 1579 deletions
|
|
@ -170,6 +170,16 @@ config SENSORS_ADM9240
|
|||
This driver can also be built as a module. If so, the module
|
||||
will be called adm9240.
|
||||
|
||||
config SENSORS_ADT7411
|
||||
tristate "Analog Devices ADT7411"
|
||||
depends on I2C && EXPERIMENTAL
|
||||
help
|
||||
If you say yes here you get support for the Analog Devices
|
||||
ADT7411 voltage and temperature monitoring chip.
|
||||
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called adt7411.
|
||||
|
||||
config SENSORS_ADT7462
|
||||
tristate "Analog Devices ADT7462"
|
||||
depends on I2C && EXPERIMENTAL
|
||||
|
|
@ -190,20 +200,6 @@ config SENSORS_ADT7470
|
|||
This driver can also be built as a module. If so, the module
|
||||
will be called adt7470.
|
||||
|
||||
config SENSORS_ADT7473
|
||||
tristate "Analog Devices ADT7473 (DEPRECATED)"
|
||||
depends on I2C && EXPERIMENTAL
|
||||
select SENSORS_ADT7475
|
||||
help
|
||||
If you say yes here you get support for the Analog Devices
|
||||
ADT7473 temperature monitoring chips.
|
||||
|
||||
This driver is deprecated, you should use the adt7475 driver
|
||||
instead.
|
||||
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called adt7473.
|
||||
|
||||
config SENSORS_ADT7475
|
||||
tristate "Analog Devices ADT7473, ADT7475, ADT7476 and ADT7490"
|
||||
depends on I2C && EXPERIMENTAL
|
||||
|
|
@ -216,6 +212,19 @@ config SENSORS_ADT7475
|
|||
This driver can also be build as a module. If so, the module
|
||||
will be called adt7475.
|
||||
|
||||
config SENSORS_ASC7621
|
||||
tristate "Andigilog aSC7621"
|
||||
depends on HWMON && I2C
|
||||
help
|
||||
If you say yes here you get support for the aSC7621
|
||||
family of SMBus sensors chip found on most Intel X48, X38, 975,
|
||||
965 and 945 desktop boards. Currently supported chips:
|
||||
aSC7621
|
||||
aSC7621a
|
||||
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called asc7621.
|
||||
|
||||
config SENSORS_K8TEMP
|
||||
tristate "AMD Athlon64/FX or Opteron temperature sensor"
|
||||
depends on X86 && PCI && EXPERIMENTAL
|
||||
|
|
@ -563,9 +572,10 @@ config SENSORS_LM90
|
|||
depends on I2C
|
||||
help
|
||||
If you say yes here you get support for National Semiconductor LM90,
|
||||
LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, and Maxim
|
||||
LM86, LM89 and LM99, Analog Devices ADM1032 and ADT7461, Maxim
|
||||
MAX6646, MAX6647, MAX6648, MAX6649, MAX6657, MAX6658, MAX6659,
|
||||
MAX6680, MAX6681 and MAX6692 sensor chips.
|
||||
MAX6680, MAX6681 and MAX6692, and Winbond/Nuvoton W83L771AWG/ASG
|
||||
sensor chips.
|
||||
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called lm90.
|
||||
|
|
@ -909,7 +919,8 @@ config SENSORS_W83793
|
|||
select HWMON_VID
|
||||
help
|
||||
If you say yes here you get support for the Winbond W83793
|
||||
hardware monitoring chip.
|
||||
hardware monitoring chip, including support for the integrated
|
||||
watchdog.
|
||||
|
||||
This driver can also be built as a module. If so, the module
|
||||
will be called w83793.
|
||||
|
|
|
|||
|
|
@ -29,12 +29,13 @@ obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o
|
|||
obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
|
||||
obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
|
||||
obj-$(CONFIG_SENSORS_ADS7828) += ads7828.o
|
||||
obj-$(CONFIG_SENSORS_ADT7411) += adt7411.o
|
||||
obj-$(CONFIG_SENSORS_ADT7462) += adt7462.o
|
||||
obj-$(CONFIG_SENSORS_ADT7470) += adt7470.o
|
||||
obj-$(CONFIG_SENSORS_ADT7473) += adt7473.o
|
||||
obj-$(CONFIG_SENSORS_ADT7475) += adt7475.o
|
||||
obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
|
||||
obj-$(CONFIG_SENSORS_AMS) += ams/
|
||||
obj-$(CONFIG_SENSORS_ASC7621) += asc7621.o
|
||||
obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
|
||||
obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o
|
||||
obj-$(CONFIG_SENSORS_DME1737) += dme1737.o
|
||||
|
|
|
|||
366
drivers/hwmon/adt7411.c
Normal file
366
drivers/hwmon/adt7411.c
Normal file
|
|
@ -0,0 +1,366 @@
|
|||
/*
|
||||
* Driver for the ADT7411 (I2C/SPI 8 channel 10 bit ADC & temperature-sensor)
|
||||
*
|
||||
* Copyright (C) 2008, 2010 Pengutronix
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* TODO: SPI, support for external temperature sensor
|
||||
* use power-down mode for suspend?, interrupt handling?
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/jiffies.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/hwmon.h>
|
||||
#include <linux/hwmon-sysfs.h>
|
||||
|
||||
#define ADT7411_REG_INT_TEMP_VDD_LSB 0x03
|
||||
#define ADT7411_REG_EXT_TEMP_AIN14_LSB 0x04
|
||||
#define ADT7411_REG_VDD_MSB 0x06
|
||||
#define ADT7411_REG_INT_TEMP_MSB 0x07
|
||||
#define ADT7411_REG_EXT_TEMP_AIN1_MSB 0x08
|
||||
|
||||
#define ADT7411_REG_CFG1 0x18
|
||||
#define ADT7411_CFG1_START_MONITOR (1 << 0)
|
||||
|
||||
#define ADT7411_REG_CFG2 0x19
|
||||
#define ADT7411_CFG2_DISABLE_AVG (1 << 5)
|
||||
|
||||
#define ADT7411_REG_CFG3 0x1a
|
||||
#define ADT7411_CFG3_ADC_CLK_225 (1 << 0)
|
||||
#define ADT7411_CFG3_REF_VDD (1 << 4)
|
||||
|
||||
#define ADT7411_REG_DEVICE_ID 0x4d
|
||||
#define ADT7411_REG_MANUFACTURER_ID 0x4e
|
||||
|
||||
#define ADT7411_DEVICE_ID 0x2
|
||||
#define ADT7411_MANUFACTURER_ID 0x41
|
||||
|
||||
static const unsigned short normal_i2c[] = { 0x48, 0x4a, 0x4b, I2C_CLIENT_END };
|
||||
|
||||
struct adt7411_data {
|
||||
struct mutex device_lock; /* for "atomic" device accesses */
|
||||
struct mutex update_lock;
|
||||
unsigned long next_update;
|
||||
int vref_cached;
|
||||
struct device *hwmon_dev;
|
||||
};
|
||||
|
||||
/*
|
||||
* When reading a register containing (up to 4) lsb, all associated
|
||||
* msb-registers get locked by the hardware. After _one_ of those msb is read,
|
||||
* _all_ are unlocked. In order to use this locking correctly, reading lsb/msb
|
||||
* is protected here with a mutex, too.
|
||||
*/
|
||||
static int adt7411_read_10_bit(struct i2c_client *client, u8 lsb_reg,
|
||||
u8 msb_reg, u8 lsb_shift)
|
||||
{
|
||||
struct adt7411_data *data = i2c_get_clientdata(client);
|
||||
int val, tmp;
|
||||
|
||||
mutex_lock(&data->device_lock);
|
||||
|
||||
val = i2c_smbus_read_byte_data(client, lsb_reg);
|
||||
if (val < 0)
|
||||
goto exit_unlock;
|
||||
|
||||
tmp = (val >> lsb_shift) & 3;
|
||||
val = i2c_smbus_read_byte_data(client, msb_reg);
|
||||
|
||||
if (val >= 0)
|
||||
val = (val << 2) | tmp;
|
||||
|
||||
exit_unlock:
|
||||
mutex_unlock(&data->device_lock);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static int adt7411_modify_bit(struct i2c_client *client, u8 reg, u8 bit,
|
||||
bool flag)
|
||||
{
|
||||
struct adt7411_data *data = i2c_get_clientdata(client);
|
||||
int ret, val;
|
||||
|
||||
mutex_lock(&data->device_lock);
|
||||
|
||||
ret = i2c_smbus_read_byte_data(client, reg);
|
||||
if (ret < 0)
|
||||
goto exit_unlock;
|
||||
|
||||
if (flag)
|
||||
val = ret | bit;
|
||||
else
|
||||
val = ret & ~bit;
|
||||
|
||||
ret = i2c_smbus_write_byte_data(client, reg, val);
|
||||
|
||||
exit_unlock:
|
||||
mutex_unlock(&data->device_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t adt7411_show_vdd(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
int ret = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB,
|
||||
ADT7411_REG_VDD_MSB, 2);
|
||||
|
||||
return ret < 0 ? ret : sprintf(buf, "%u\n", ret * 7000 / 1024);
|
||||
}
|
||||
|
||||
static ssize_t adt7411_show_temp(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
int val = adt7411_read_10_bit(client, ADT7411_REG_INT_TEMP_VDD_LSB,
|
||||
ADT7411_REG_INT_TEMP_MSB, 0);
|
||||
|
||||
if (val < 0)
|
||||
return val;
|
||||
|
||||
val = val & 0x200 ? val - 0x400 : val; /* 10 bit signed */
|
||||
|
||||
return sprintf(buf, "%d\n", val * 250);
|
||||
}
|
||||
|
||||
static ssize_t adt7411_show_input(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
int nr = to_sensor_dev_attr(attr)->index;
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct adt7411_data *data = i2c_get_clientdata(client);
|
||||
int val;
|
||||
u8 lsb_reg, lsb_shift;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
if (time_after_eq(jiffies, data->next_update)) {
|
||||
val = i2c_smbus_read_byte_data(client, ADT7411_REG_CFG3);
|
||||
if (val < 0)
|
||||
goto exit_unlock;
|
||||
|
||||
if (val & ADT7411_CFG3_REF_VDD) {
|
||||
val = adt7411_read_10_bit(client,
|
||||
ADT7411_REG_INT_TEMP_VDD_LSB,
|
||||
ADT7411_REG_VDD_MSB, 2);
|
||||
if (val < 0)
|
||||
goto exit_unlock;
|
||||
|
||||
data->vref_cached = val * 7000 / 1024;
|
||||
} else {
|
||||
data->vref_cached = 2250;
|
||||
}
|
||||
|
||||
data->next_update = jiffies + HZ;
|
||||
}
|
||||
|
||||
lsb_reg = ADT7411_REG_EXT_TEMP_AIN14_LSB + (nr >> 2);
|
||||
lsb_shift = 2 * (nr & 0x03);
|
||||
val = adt7411_read_10_bit(client, lsb_reg,
|
||||
ADT7411_REG_EXT_TEMP_AIN1_MSB + nr, lsb_shift);
|
||||
if (val < 0)
|
||||
goto exit_unlock;
|
||||
|
||||
val = sprintf(buf, "%u\n", val * data->vref_cached / 1024);
|
||||
exit_unlock:
|
||||
mutex_unlock(&data->update_lock);
|
||||
return val;
|
||||
}
|
||||
|
||||
static ssize_t adt7411_show_bit(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
{
|
||||
struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(attr);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
int ret = i2c_smbus_read_byte_data(client, attr2->index);
|
||||
|
||||
return ret < 0 ? ret : sprintf(buf, "%u\n", !!(ret & attr2->nr));
|
||||
}
|
||||
|
||||
static ssize_t adt7411_set_bit(struct device *dev,
|
||||
struct device_attribute *attr, const char *buf,
|
||||
size_t count)
|
||||
{
|
||||
struct sensor_device_attribute_2 *s_attr2 = to_sensor_dev_attr_2(attr);
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct adt7411_data *data = i2c_get_clientdata(client);
|
||||
int ret;
|
||||
unsigned long flag;
|
||||
|
||||
ret = strict_strtoul(buf, 0, &flag);
|
||||
if (ret || flag > 1)
|
||||
return -EINVAL;
|
||||
|
||||
ret = adt7411_modify_bit(client, s_attr2->index, s_attr2->nr, flag);
|
||||
|
||||
/* force update */
|
||||
mutex_lock(&data->update_lock);
|
||||
data->next_update = jiffies;
|
||||
mutex_unlock(&data->update_lock);
|
||||
|
||||
return ret < 0 ? ret : count;
|
||||
}
|
||||
|
||||
#define ADT7411_BIT_ATTR(__name, __reg, __bit) \
|
||||
SENSOR_DEVICE_ATTR_2(__name, S_IRUGO | S_IWUSR, adt7411_show_bit, \
|
||||
adt7411_set_bit, __bit, __reg)
|
||||
|
||||
static DEVICE_ATTR(temp1_input, S_IRUGO, adt7411_show_temp, NULL);
|
||||
static DEVICE_ATTR(in0_input, S_IRUGO, adt7411_show_vdd, NULL);
|
||||
static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, adt7411_show_input, NULL, 0);
|
||||
static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, adt7411_show_input, NULL, 1);
|
||||
static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, adt7411_show_input, NULL, 2);
|
||||
static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, adt7411_show_input, NULL, 3);
|
||||
static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, adt7411_show_input, NULL, 4);
|
||||
static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, adt7411_show_input, NULL, 5);
|
||||
static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, adt7411_show_input, NULL, 6);
|
||||
static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, adt7411_show_input, NULL, 7);
|
||||
static ADT7411_BIT_ATTR(no_average, ADT7411_REG_CFG2, ADT7411_CFG2_DISABLE_AVG);
|
||||
static ADT7411_BIT_ATTR(fast_sampling, ADT7411_REG_CFG3, ADT7411_CFG3_ADC_CLK_225);
|
||||
static ADT7411_BIT_ATTR(adc_ref_vdd, ADT7411_REG_CFG3, ADT7411_CFG3_REF_VDD);
|
||||
|
||||
static struct attribute *adt7411_attrs[] = {
|
||||
&dev_attr_temp1_input.attr,
|
||||
&dev_attr_in0_input.attr,
|
||||
&sensor_dev_attr_in1_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in2_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in3_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in4_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in5_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in6_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in7_input.dev_attr.attr,
|
||||
&sensor_dev_attr_in8_input.dev_attr.attr,
|
||||
&sensor_dev_attr_no_average.dev_attr.attr,
|
||||
&sensor_dev_attr_fast_sampling.dev_attr.attr,
|
||||
&sensor_dev_attr_adc_ref_vdd.dev_attr.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static const struct attribute_group adt7411_attr_grp = {
|
||||
.attrs = adt7411_attrs,
|
||||
};
|
||||
|
||||
static int adt7411_detect(struct i2c_client *client,
|
||||
struct i2c_board_info *info)
|
||||
{
|
||||
int val;
|
||||
|
||||
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||
return -ENODEV;
|
||||
|
||||
val = i2c_smbus_read_byte_data(client, ADT7411_REG_MANUFACTURER_ID);
|
||||
if (val < 0 || val != ADT7411_MANUFACTURER_ID) {
|
||||
dev_dbg(&client->dev, "Wrong manufacturer ID. Got %d, "
|
||||
"expected %d\n", val, ADT7411_MANUFACTURER_ID);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
val = i2c_smbus_read_byte_data(client, ADT7411_REG_DEVICE_ID);
|
||||
if (val < 0 || val != ADT7411_DEVICE_ID) {
|
||||
dev_dbg(&client->dev, "Wrong device ID. Got %d, "
|
||||
"expected %d\n", val, ADT7411_DEVICE_ID);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
strlcpy(info->type, "adt7411", I2C_NAME_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __devinit adt7411_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
struct adt7411_data *data;
|
||||
int ret;
|
||||
|
||||
data = kzalloc(sizeof(*data), GFP_KERNEL);
|
||||
if (!data)
|
||||
return -ENOMEM;
|
||||
|
||||
i2c_set_clientdata(client, data);
|
||||
mutex_init(&data->device_lock);
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
ret = adt7411_modify_bit(client, ADT7411_REG_CFG1,
|
||||
ADT7411_CFG1_START_MONITOR, 1);
|
||||
if (ret < 0)
|
||||
goto exit_free;
|
||||
|
||||
/* force update on first occasion */
|
||||
data->next_update = jiffies;
|
||||
|
||||
ret = sysfs_create_group(&client->dev.kobj, &adt7411_attr_grp);
|
||||
if (ret)
|
||||
goto exit_free;
|
||||
|
||||
data->hwmon_dev = hwmon_device_register(&client->dev);
|
||||
if (IS_ERR(data->hwmon_dev)) {
|
||||
ret = PTR_ERR(data->hwmon_dev);
|
||||
goto exit_remove;
|
||||
}
|
||||
|
||||
dev_info(&client->dev, "successfully registered\n");
|
||||
|
||||
return 0;
|
||||
|
||||
exit_remove:
|
||||
sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
|
||||
exit_free:
|
||||
i2c_set_clientdata(client, NULL);
|
||||
kfree(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __devexit adt7411_remove(struct i2c_client *client)
|
||||
{
|
||||
struct adt7411_data *data = i2c_get_clientdata(client);
|
||||
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
sysfs_remove_group(&client->dev.kobj, &adt7411_attr_grp);
|
||||
i2c_set_clientdata(client, NULL);
|
||||
kfree(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct i2c_device_id adt7411_id[] = {
|
||||
{ "adt7411", 0 },
|
||||
{ }
|
||||
};
|
||||
|
||||
static struct i2c_driver adt7411_driver = {
|
||||
.driver = {
|
||||
.name = "adt7411",
|
||||
},
|
||||
.probe = adt7411_probe,
|
||||
.remove = __devexit_p(adt7411_remove),
|
||||
.id_table = adt7411_id,
|
||||
.detect = adt7411_detect,
|
||||
.address_list = normal_i2c,
|
||||
.class = I2C_CLASS_HWMON,
|
||||
};
|
||||
|
||||
static int __init sensors_adt7411_init(void)
|
||||
{
|
||||
return i2c_add_driver(&adt7411_driver);
|
||||
}
|
||||
module_init(sensors_adt7411_init)
|
||||
|
||||
static void __exit sensors_adt7411_exit(void)
|
||||
{
|
||||
i2c_del_driver(&adt7411_driver);
|
||||
}
|
||||
module_exit(sensors_adt7411_exit)
|
||||
|
||||
MODULE_AUTHOR("Sascha Hauer <[email protected]> and "
|
||||
"Wolfram Sang <[email protected]>");
|
||||
MODULE_DESCRIPTION("ADT7411 driver");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
File diff suppressed because it is too large
Load diff
1255
drivers/hwmon/asc7621.c
Normal file
1255
drivers/hwmon/asc7621.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -267,7 +267,7 @@ struct fschmd_data {
|
|||
struct list_head list; /* member of the watchdog_data_list */
|
||||
struct kref kref;
|
||||
struct miscdevice watchdog_miscdev;
|
||||
int kind;
|
||||
enum chips kind;
|
||||
unsigned long watchdog_is_open;
|
||||
char watchdog_expect_close;
|
||||
char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
|
||||
|
|
@ -325,8 +325,7 @@ static ssize_t show_in_value(struct device *dev,
|
|||
int index = to_sensor_dev_attr(devattr)->index;
|
||||
struct fschmd_data *data = fschmd_update_device(dev);
|
||||
|
||||
/* fscher / fschrc - 1 as data->kind is an array index, not a chips */
|
||||
if (data->kind == (fscher - 1) || data->kind >= (fschrc - 1))
|
||||
if (data->kind == fscher || data->kind >= fschrc)
|
||||
return sprintf(buf, "%d\n", (data->volt[index] * dmi_vref *
|
||||
dmi_mult[index]) / 255 + dmi_offset[index]);
|
||||
else
|
||||
|
|
@ -492,7 +491,7 @@ static ssize_t show_pwm_auto_point1_pwm(struct device *dev,
|
|||
int val = data->fan_min[index];
|
||||
|
||||
/* 0 = allow turning off (except on the syl), 1-255 = 50-100% */
|
||||
if (val || data->kind == fscsyl - 1)
|
||||
if (val || data->kind == fscsyl)
|
||||
val = val / 2 + 128;
|
||||
|
||||
return sprintf(buf, "%d\n", val);
|
||||
|
|
@ -506,7 +505,7 @@ static ssize_t store_pwm_auto_point1_pwm(struct device *dev,
|
|||
unsigned long v = simple_strtoul(buf, NULL, 10);
|
||||
|
||||
/* reg: 0 = allow turning off (except on the syl), 1-255 = 50-100% */
|
||||
if (v || data->kind == fscsyl - 1) {
|
||||
if (v || data->kind == fscsyl) {
|
||||
v = SENSORS_LIMIT(v, 128, 255);
|
||||
v = (v - 128) * 2 + 1;
|
||||
}
|
||||
|
|
@ -1037,7 +1036,7 @@ static int fschmd_detect(struct i2c_client *client,
|
|||
else
|
||||
return -ENODEV;
|
||||
|
||||
strlcpy(info->type, fschmd_id[kind - 1].name, I2C_NAME_SIZE);
|
||||
strlcpy(info->type, fschmd_id[kind].name, I2C_NAME_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1065,6 +1064,7 @@ static int fschmd_probe(struct i2c_client *client,
|
|||
(where the client is found through a data ptr instead of the
|
||||
otherway around) */
|
||||
data->client = client;
|
||||
data->kind = kind;
|
||||
|
||||
if (kind == fscpos) {
|
||||
/* The Poseidon has hardwired temp limits, fill these
|
||||
|
|
@ -1085,9 +1085,6 @@ static int fschmd_probe(struct i2c_client *client,
|
|||
}
|
||||
}
|
||||
|
||||
/* i2c kind goes from 1-6, we want from 0-5 to address arrays */
|
||||
data->kind = kind - 1;
|
||||
|
||||
/* Read in some never changing registers */
|
||||
data->revision = i2c_smbus_read_byte_data(client, FSCHMD_REG_REVISION);
|
||||
data->global_control = i2c_smbus_read_byte_data(client,
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ struct g760a_data {
|
|||
#define PWM_FROM_CNT(cnt) (0xff-(cnt))
|
||||
#define PWM_TO_CNT(pwm) (0xff-(pwm))
|
||||
|
||||
unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div)
|
||||
static inline unsigned int rpm_from_cnt(u8 val, u32 clk, u16 div)
|
||||
{
|
||||
return ((val == 0x00) ? 0 : ((clk*30)/(val*div)));
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* lm90.c - Part of lm_sensors, Linux kernel modules for hardware
|
||||
* monitoring
|
||||
* Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org>
|
||||
* Copyright (C) 2003-2010 Jean Delvare <khali@linux-fr.org>
|
||||
*
|
||||
* Based on the lm83 driver. The LM90 is a sensor chip made by National
|
||||
* Semiconductor. It reports up to two temperatures (its own plus up to
|
||||
|
|
@ -93,7 +93,8 @@
|
|||
static const unsigned short normal_i2c[] = {
|
||||
0x18, 0x19, 0x1a, 0x29, 0x2a, 0x2b, 0x4c, 0x4d, 0x4e, I2C_CLIENT_END };
|
||||
|
||||
enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646 };
|
||||
enum chips { lm90, adm1032, lm99, lm86, max6657, adt7461, max6680, max6646,
|
||||
w83l771 };
|
||||
|
||||
/*
|
||||
* The LM90 registers
|
||||
|
|
@ -151,6 +152,7 @@ static int lm90_detect(struct i2c_client *client, struct i2c_board_info *info);
|
|||
static int lm90_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id);
|
||||
static void lm90_init_client(struct i2c_client *client);
|
||||
static void lm90_alert(struct i2c_client *client, unsigned int flag);
|
||||
static int lm90_remove(struct i2c_client *client);
|
||||
static struct lm90_data *lm90_update_device(struct device *dev);
|
||||
|
||||
|
|
@ -173,6 +175,7 @@ static const struct i2c_device_id lm90_id[] = {
|
|||
{ "max6659", max6657 },
|
||||
{ "max6680", max6680 },
|
||||
{ "max6681", max6680 },
|
||||
{ "w83l771", w83l771 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, lm90_id);
|
||||
|
|
@ -184,6 +187,7 @@ static struct i2c_driver lm90_driver = {
|
|||
},
|
||||
.probe = lm90_probe,
|
||||
.remove = lm90_remove,
|
||||
.alert = lm90_alert,
|
||||
.id_table = lm90_id,
|
||||
.detect = lm90_detect,
|
||||
.address_list = normal_i2c,
|
||||
|
|
@ -201,6 +205,9 @@ struct lm90_data {
|
|||
int kind;
|
||||
int flags;
|
||||
|
||||
u8 config_orig; /* Original configuration register value */
|
||||
u8 alert_alarms; /* Which alarm bits trigger ALERT# */
|
||||
|
||||
/* registers values */
|
||||
s8 temp8[4]; /* 0: local low limit
|
||||
1: local high limit
|
||||
|
|
@ -758,6 +765,14 @@ static int lm90_detect(struct i2c_client *new_client,
|
|||
&& reg_convrate <= 0x07) {
|
||||
name = "max6646";
|
||||
}
|
||||
} else
|
||||
if (address == 0x4C
|
||||
&& man_id == 0x5C) { /* Winbond/Nuvoton */
|
||||
if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */
|
||||
&& (reg_config1 & 0x2A) == 0x00
|
||||
&& reg_convrate <= 0x08) {
|
||||
name = "w83l771";
|
||||
}
|
||||
}
|
||||
|
||||
if (!name) { /* identification failed */
|
||||
|
|
@ -794,6 +809,19 @@ static int lm90_probe(struct i2c_client *new_client,
|
|||
new_client->flags &= ~I2C_CLIENT_PEC;
|
||||
}
|
||||
|
||||
/* Different devices have different alarm bits triggering the
|
||||
* ALERT# output */
|
||||
switch (data->kind) {
|
||||
case lm90:
|
||||
case lm99:
|
||||
case lm86:
|
||||
data->alert_alarms = 0x7b;
|
||||
break;
|
||||
default:
|
||||
data->alert_alarms = 0x7c;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Initialize the LM90 chip */
|
||||
lm90_init_client(new_client);
|
||||
|
||||
|
|
@ -830,7 +858,7 @@ exit:
|
|||
|
||||
static void lm90_init_client(struct i2c_client *client)
|
||||
{
|
||||
u8 config, config_orig;
|
||||
u8 config;
|
||||
struct lm90_data *data = i2c_get_clientdata(client);
|
||||
|
||||
/*
|
||||
|
|
@ -842,7 +870,7 @@ static void lm90_init_client(struct i2c_client *client)
|
|||
dev_warn(&client->dev, "Initialization failed!\n");
|
||||
return;
|
||||
}
|
||||
config_orig = config;
|
||||
data->config_orig = config;
|
||||
|
||||
/* Check Temperature Range Select */
|
||||
if (data->kind == adt7461) {
|
||||
|
|
@ -860,7 +888,7 @@ static void lm90_init_client(struct i2c_client *client)
|
|||
}
|
||||
|
||||
config &= 0xBF; /* run */
|
||||
if (config != config_orig) /* Only write if changed */
|
||||
if (config != data->config_orig) /* Only write if changed */
|
||||
i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
|
||||
}
|
||||
|
||||
|
|
@ -875,10 +903,46 @@ static int lm90_remove(struct i2c_client *client)
|
|||
device_remove_file(&client->dev,
|
||||
&sensor_dev_attr_temp2_offset.dev_attr);
|
||||
|
||||
/* Restore initial configuration */
|
||||
i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
|
||||
data->config_orig);
|
||||
|
||||
kfree(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void lm90_alert(struct i2c_client *client, unsigned int flag)
|
||||
{
|
||||
struct lm90_data *data = i2c_get_clientdata(client);
|
||||
u8 config, alarms;
|
||||
|
||||
lm90_read_reg(client, LM90_REG_R_STATUS, &alarms);
|
||||
if ((alarms & 0x7f) == 0) {
|
||||
dev_info(&client->dev, "Everything OK\n");
|
||||
} else {
|
||||
if (alarms & 0x61)
|
||||
dev_warn(&client->dev,
|
||||
"temp%d out of range, please check!\n", 1);
|
||||
if (alarms & 0x1a)
|
||||
dev_warn(&client->dev,
|
||||
"temp%d out of range, please check!\n", 2);
|
||||
if (alarms & 0x04)
|
||||
dev_warn(&client->dev,
|
||||
"temp%d diode open, please check!\n", 2);
|
||||
|
||||
/* Disable ALERT# output, because these chips don't implement
|
||||
SMBus alert correctly; they should only hold the alert line
|
||||
low briefly. */
|
||||
if ((data->kind == adm1032 || data->kind == adt7461)
|
||||
&& (alarms & data->alert_alarms)) {
|
||||
dev_dbg(&client->dev, "Disabling ALERT#\n");
|
||||
lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
|
||||
i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1,
|
||||
config | 0x80);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
|
||||
{
|
||||
int err;
|
||||
|
|
@ -966,6 +1030,21 @@ static struct lm90_data *lm90_update_device(struct device *dev)
|
|||
}
|
||||
lm90_read_reg(client, LM90_REG_R_STATUS, &data->alarms);
|
||||
|
||||
/* Re-enable ALERT# output if it was originally enabled and
|
||||
* relevant alarms are all clear */
|
||||
if ((data->config_orig & 0x80) == 0
|
||||
&& (data->alarms & data->alert_alarms) == 0) {
|
||||
u8 config;
|
||||
|
||||
lm90_read_reg(client, LM90_REG_R_CONFIG1, &config);
|
||||
if (config & 0x80) {
|
||||
dev_dbg(&client->dev, "Re-enabling ALERT#\n");
|
||||
i2c_smbus_write_byte_data(client,
|
||||
LM90_REG_W_CONFIG1,
|
||||
config & ~0x80);
|
||||
}
|
||||
}
|
||||
|
||||
data->last_updated = jiffies;
|
||||
data->valid = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ struct tmp401_data {
|
|||
struct mutex update_lock;
|
||||
char valid; /* zero until following fields are valid */
|
||||
unsigned long last_updated; /* in jiffies */
|
||||
int kind;
|
||||
enum chips kind;
|
||||
|
||||
/* register values */
|
||||
u8 status;
|
||||
|
|
@ -524,7 +524,7 @@ static int tmp401_detect(struct i2c_client *client,
|
|||
if (reg > 15)
|
||||
return -ENODEV;
|
||||
|
||||
strlcpy(info->type, tmp401_id[kind - 1].name, I2C_NAME_SIZE);
|
||||
strlcpy(info->type, tmp401_id[kind].name, I2C_NAME_SIZE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -572,8 +572,7 @@ static int tmp401_probe(struct i2c_client *client,
|
|||
goto exit_remove;
|
||||
}
|
||||
|
||||
dev_info(&client->dev, "Detected TI %s chip\n",
|
||||
names[data->kind - 1]);
|
||||
dev_info(&client->dev, "Detected TI %s chip\n", names[data->kind]);
|
||||
|
||||
return 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -61,9 +61,9 @@ static const u8 TMP421_TEMP_LSB[4] = { 0x10, 0x11, 0x12, 0x13 };
|
|||
#define TMP423_DEVICE_ID 0x23
|
||||
|
||||
static const struct i2c_device_id tmp421_id[] = {
|
||||
{ "tmp421", tmp421 },
|
||||
{ "tmp422", tmp422 },
|
||||
{ "tmp423", tmp423 },
|
||||
{ "tmp421", 2 },
|
||||
{ "tmp422", 3 },
|
||||
{ "tmp423", 4 },
|
||||
{ }
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, tmp421_id);
|
||||
|
|
@ -73,21 +73,23 @@ struct tmp421_data {
|
|||
struct mutex update_lock;
|
||||
char valid;
|
||||
unsigned long last_updated;
|
||||
int kind;
|
||||
int channels;
|
||||
u8 config;
|
||||
s16 temp[4];
|
||||
};
|
||||
|
||||
static int temp_from_s16(s16 reg)
|
||||
{
|
||||
int temp = reg;
|
||||
/* Mask out status bits */
|
||||
int temp = reg & ~0xf;
|
||||
|
||||
return (temp * 1000 + 128) / 256;
|
||||
}
|
||||
|
||||
static int temp_from_u16(u16 reg)
|
||||
{
|
||||
int temp = reg;
|
||||
/* Mask out status bits */
|
||||
int temp = reg & ~0xf;
|
||||
|
||||
/* Add offset for extended temperature range. */
|
||||
temp -= 64 * 256;
|
||||
|
|
@ -107,7 +109,7 @@ static struct tmp421_data *tmp421_update_device(struct device *dev)
|
|||
data->config = i2c_smbus_read_byte_data(client,
|
||||
TMP421_CONFIG_REG_1);
|
||||
|
||||
for (i = 0; i <= data->kind; i++) {
|
||||
for (i = 0; i < data->channels; i++) {
|
||||
data->temp[i] = i2c_smbus_read_byte_data(client,
|
||||
TMP421_TEMP_MSB[i]) << 8;
|
||||
data->temp[i] |= i2c_smbus_read_byte_data(client,
|
||||
|
|
@ -166,7 +168,7 @@ static mode_t tmp421_is_visible(struct kobject *kobj, struct attribute *a,
|
|||
devattr = container_of(a, struct device_attribute, attr);
|
||||
index = to_sensor_dev_attr(devattr)->index;
|
||||
|
||||
if (data->kind > index)
|
||||
if (index < data->channels)
|
||||
return a->mode;
|
||||
|
||||
return 0;
|
||||
|
|
@ -252,9 +254,9 @@ static int tmp421_detect(struct i2c_client *client,
|
|||
return -ENODEV;
|
||||
}
|
||||
|
||||
strlcpy(info->type, tmp421_id[kind - 1].name, I2C_NAME_SIZE);
|
||||
strlcpy(info->type, tmp421_id[kind].name, I2C_NAME_SIZE);
|
||||
dev_info(&adapter->dev, "Detected TI %s chip at 0x%02x\n",
|
||||
names[kind - 1], client->addr);
|
||||
names[kind], client->addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -271,7 +273,7 @@ static int tmp421_probe(struct i2c_client *client,
|
|||
|
||||
i2c_set_clientdata(client, data);
|
||||
mutex_init(&data->update_lock);
|
||||
data->kind = id->driver_data;
|
||||
data->channels = id->driver_data;
|
||||
|
||||
err = tmp421_init_client(client);
|
||||
if (err)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
Copyright (C) 2006 Winbond Electronics Corp.
|
||||
Yuan Mu
|
||||
Rudolf Marek <r.marek@assembler.cz>
|
||||
Copyright (C) 2009-2010 Sven Anders <anders@anduras.de>, ANDURAS AG.
|
||||
Watchdog driver part
|
||||
(Based partially on fschmd driver,
|
||||
Copyright 2007-2008 by Hans de Goede)
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
|
@ -35,6 +39,16 @@
|
|||
#include <linux/hwmon-sysfs.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/watchdog.h>
|
||||
#include <linux/miscdevice.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/kref.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/reboot.h>
|
||||
|
||||
/* Default values */
|
||||
#define WATCHDOG_TIMEOUT 2 /* 2 minute default timeout */
|
||||
|
||||
/* Addresses to scan */
|
||||
static const unsigned short normal_i2c[] = { 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
|
|
@ -51,6 +65,18 @@ static int reset;
|
|||
module_param(reset, bool, 0);
|
||||
MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
|
||||
|
||||
static int timeout = WATCHDOG_TIMEOUT; /* default timeout in minutes */
|
||||
module_param(timeout, int, 0);
|
||||
MODULE_PARM_DESC(timeout,
|
||||
"Watchdog timeout in minutes. 2<= timeout <=255 (default="
|
||||
__MODULE_STRING(WATCHDOG_TIMEOUT) ")");
|
||||
|
||||
static int nowayout = WATCHDOG_NOWAYOUT;
|
||||
module_param(nowayout, int, 0);
|
||||
MODULE_PARM_DESC(nowayout,
|
||||
"Watchdog cannot be stopped once started (default="
|
||||
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
||||
|
||||
/*
|
||||
Address 0x00, 0x0d, 0x0e, 0x0f in all three banks are reserved
|
||||
as ID, Bank Select registers
|
||||
|
|
@ -72,6 +98,11 @@ MODULE_PARM_DESC(reset, "Set to 1 to reset chip, not recommended");
|
|||
#define W83793_REG_VID_LATCHB 0x08
|
||||
#define W83793_REG_VID_CTRL 0x59
|
||||
|
||||
#define W83793_REG_WDT_LOCK 0x01
|
||||
#define W83793_REG_WDT_ENABLE 0x02
|
||||
#define W83793_REG_WDT_STATUS 0x03
|
||||
#define W83793_REG_WDT_TIMEOUT 0x04
|
||||
|
||||
static u16 W83793_REG_TEMP_MODE[2] = { 0x5e, 0x5f };
|
||||
|
||||
#define TEMP_READ 0
|
||||
|
|
@ -223,8 +254,37 @@ struct w83793_data {
|
|||
u8 tolerance[3]; /* Temp tolerance(Smart Fan I/II) */
|
||||
u8 sf2_pwm[6][7]; /* Smart FanII: Fan duty cycle */
|
||||
u8 sf2_temp[6][7]; /* Smart FanII: Temp level point */
|
||||
|
||||
/* watchdog */
|
||||
struct i2c_client *client;
|
||||
struct mutex watchdog_lock;
|
||||
struct list_head list; /* member of the watchdog_data_list */
|
||||
struct kref kref;
|
||||
struct miscdevice watchdog_miscdev;
|
||||
unsigned long watchdog_is_open;
|
||||
char watchdog_expect_close;
|
||||
char watchdog_name[10]; /* must be unique to avoid sysfs conflict */
|
||||
unsigned int watchdog_caused_reboot;
|
||||
int watchdog_timeout; /* watchdog timeout in minutes */
|
||||
};
|
||||
|
||||
/* Somewhat ugly :( global data pointer list with all devices, so that
|
||||
we can find our device data as when using misc_register. There is no
|
||||
other method to get to one's device data from the open file-op and
|
||||
for usage in the reboot notifier callback. */
|
||||
static LIST_HEAD(watchdog_data_list);
|
||||
|
||||
/* Note this lock not only protect list access, but also data.kref access */
|
||||
static DEFINE_MUTEX(watchdog_data_mutex);
|
||||
|
||||
/* Release our data struct when we're detached from the i2c client *and* all
|
||||
references to our watchdog device are released */
|
||||
static void w83793_release_resources(struct kref *ref)
|
||||
{
|
||||
struct w83793_data *data = container_of(ref, struct w83793_data, kref);
|
||||
kfree(data);
|
||||
}
|
||||
|
||||
static u8 w83793_read_value(struct i2c_client *client, u16 reg);
|
||||
static int w83793_write_value(struct i2c_client *client, u16 reg, u8 value);
|
||||
static int w83793_probe(struct i2c_client *client,
|
||||
|
|
@ -1063,14 +1123,349 @@ static void w83793_init_client(struct i2c_client *client)
|
|||
/* Start monitoring */
|
||||
w83793_write_value(client, W83793_REG_CONFIG,
|
||||
w83793_read_value(client, W83793_REG_CONFIG) | 0x01);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Watchdog routines
|
||||
*/
|
||||
|
||||
static int watchdog_set_timeout(struct w83793_data *data, int timeout)
|
||||
{
|
||||
int ret, mtimeout;
|
||||
|
||||
mtimeout = DIV_ROUND_UP(timeout, 60);
|
||||
|
||||
if (mtimeout > 255)
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&data->watchdog_lock);
|
||||
if (!data->client) {
|
||||
ret = -ENODEV;
|
||||
goto leave;
|
||||
}
|
||||
|
||||
data->watchdog_timeout = mtimeout;
|
||||
|
||||
/* Set Timeout value (in Minutes) */
|
||||
w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
|
||||
data->watchdog_timeout);
|
||||
|
||||
ret = mtimeout * 60;
|
||||
|
||||
leave:
|
||||
mutex_unlock(&data->watchdog_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int watchdog_get_timeout(struct w83793_data *data)
|
||||
{
|
||||
int timeout;
|
||||
|
||||
mutex_lock(&data->watchdog_lock);
|
||||
timeout = data->watchdog_timeout * 60;
|
||||
mutex_unlock(&data->watchdog_lock);
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
static int watchdog_trigger(struct w83793_data *data)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&data->watchdog_lock);
|
||||
if (!data->client) {
|
||||
ret = -ENODEV;
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Set Timeout value (in Minutes) */
|
||||
w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
|
||||
data->watchdog_timeout);
|
||||
|
||||
leave:
|
||||
mutex_unlock(&data->watchdog_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int watchdog_enable(struct w83793_data *data)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&data->watchdog_lock);
|
||||
if (!data->client) {
|
||||
ret = -ENODEV;
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Set initial timeout */
|
||||
w83793_write_value(data->client, W83793_REG_WDT_TIMEOUT,
|
||||
data->watchdog_timeout);
|
||||
|
||||
/* Enable Soft Watchdog */
|
||||
w83793_write_value(data->client, W83793_REG_WDT_LOCK, 0x55);
|
||||
|
||||
leave:
|
||||
mutex_unlock(&data->watchdog_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int watchdog_disable(struct w83793_data *data)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
mutex_lock(&data->watchdog_lock);
|
||||
if (!data->client) {
|
||||
ret = -ENODEV;
|
||||
goto leave;
|
||||
}
|
||||
|
||||
/* Disable Soft Watchdog */
|
||||
w83793_write_value(data->client, W83793_REG_WDT_LOCK, 0xAA);
|
||||
|
||||
leave:
|
||||
mutex_unlock(&data->watchdog_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int watchdog_open(struct inode *inode, struct file *filp)
|
||||
{
|
||||
struct w83793_data *pos, *data = NULL;
|
||||
int watchdog_is_open;
|
||||
|
||||
/* We get called from drivers/char/misc.c with misc_mtx hold, and we
|
||||
call misc_register() from w83793_probe() with watchdog_data_mutex
|
||||
hold, as misc_register() takes the misc_mtx lock, this is a possible
|
||||
deadlock, so we use mutex_trylock here. */
|
||||
if (!mutex_trylock(&watchdog_data_mutex))
|
||||
return -ERESTARTSYS;
|
||||
list_for_each_entry(pos, &watchdog_data_list, list) {
|
||||
if (pos->watchdog_miscdev.minor == iminor(inode)) {
|
||||
data = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check, if device is already open */
|
||||
watchdog_is_open = test_and_set_bit(0, &data->watchdog_is_open);
|
||||
|
||||
/* Increase data reference counter (if not already done).
|
||||
Note we can never not have found data, so we don't check for this */
|
||||
if (!watchdog_is_open)
|
||||
kref_get(&data->kref);
|
||||
|
||||
mutex_unlock(&watchdog_data_mutex);
|
||||
|
||||
/* Check, if device is already open and possibly issue error */
|
||||
if (watchdog_is_open)
|
||||
return -EBUSY;
|
||||
|
||||
/* Enable Soft Watchdog */
|
||||
watchdog_enable(data);
|
||||
|
||||
/* Store pointer to data into filp's private data */
|
||||
filp->private_data = data;
|
||||
|
||||
return nonseekable_open(inode, filp);
|
||||
}
|
||||
|
||||
static int watchdog_close(struct inode *inode, struct file *filp)
|
||||
{
|
||||
struct w83793_data *data = filp->private_data;
|
||||
|
||||
if (data->watchdog_expect_close) {
|
||||
watchdog_disable(data);
|
||||
data->watchdog_expect_close = 0;
|
||||
} else {
|
||||
watchdog_trigger(data);
|
||||
dev_crit(&data->client->dev,
|
||||
"unexpected close, not stopping watchdog!\n");
|
||||
}
|
||||
|
||||
clear_bit(0, &data->watchdog_is_open);
|
||||
|
||||
/* Decrease data reference counter */
|
||||
mutex_lock(&watchdog_data_mutex);
|
||||
kref_put(&data->kref, w83793_release_resources);
|
||||
mutex_unlock(&watchdog_data_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t watchdog_write(struct file *filp, const char __user *buf,
|
||||
size_t count, loff_t *offset)
|
||||
{
|
||||
size_t ret;
|
||||
struct w83793_data *data = filp->private_data;
|
||||
|
||||
if (count) {
|
||||
if (!nowayout) {
|
||||
size_t i;
|
||||
|
||||
/* Clear it in case it was set with a previous write */
|
||||
data->watchdog_expect_close = 0;
|
||||
|
||||
for (i = 0; i != count; i++) {
|
||||
char c;
|
||||
if (get_user(c, buf + i))
|
||||
return -EFAULT;
|
||||
if (c == 'V')
|
||||
data->watchdog_expect_close = 1;
|
||||
}
|
||||
}
|
||||
ret = watchdog_trigger(data);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static int watchdog_ioctl(struct inode *inode, struct file *filp,
|
||||
unsigned int cmd, unsigned long arg)
|
||||
{
|
||||
static struct watchdog_info ident = {
|
||||
.options = WDIOF_KEEPALIVEPING |
|
||||
WDIOF_SETTIMEOUT |
|
||||
WDIOF_CARDRESET,
|
||||
.identity = "w83793 watchdog"
|
||||
};
|
||||
|
||||
int val, ret = 0;
|
||||
struct w83793_data *data = filp->private_data;
|
||||
|
||||
switch (cmd) {
|
||||
case WDIOC_GETSUPPORT:
|
||||
if (!nowayout)
|
||||
ident.options |= WDIOF_MAGICCLOSE;
|
||||
if (copy_to_user((void __user *)arg, &ident, sizeof(ident)))
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
|
||||
case WDIOC_GETSTATUS:
|
||||
val = data->watchdog_caused_reboot ? WDIOF_CARDRESET : 0;
|
||||
ret = put_user(val, (int __user *)arg);
|
||||
break;
|
||||
|
||||
case WDIOC_GETBOOTSTATUS:
|
||||
ret = put_user(0, (int __user *)arg);
|
||||
break;
|
||||
|
||||
case WDIOC_KEEPALIVE:
|
||||
ret = watchdog_trigger(data);
|
||||
break;
|
||||
|
||||
case WDIOC_GETTIMEOUT:
|
||||
val = watchdog_get_timeout(data);
|
||||
ret = put_user(val, (int __user *)arg);
|
||||
break;
|
||||
|
||||
case WDIOC_SETTIMEOUT:
|
||||
if (get_user(val, (int __user *)arg)) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
ret = watchdog_set_timeout(data, val);
|
||||
if (ret > 0)
|
||||
ret = put_user(ret, (int __user *)arg);
|
||||
break;
|
||||
|
||||
case WDIOC_SETOPTIONS:
|
||||
if (get_user(val, (int __user *)arg)) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
if (val & WDIOS_DISABLECARD)
|
||||
ret = watchdog_disable(data);
|
||||
else if (val & WDIOS_ENABLECARD)
|
||||
ret = watchdog_enable(data);
|
||||
else
|
||||
ret = -EINVAL;
|
||||
|
||||
break;
|
||||
default:
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const struct file_operations watchdog_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.llseek = no_llseek,
|
||||
.open = watchdog_open,
|
||||
.release = watchdog_close,
|
||||
.write = watchdog_write,
|
||||
.ioctl = watchdog_ioctl,
|
||||
};
|
||||
|
||||
/*
|
||||
* Notifier for system down
|
||||
*/
|
||||
|
||||
static int watchdog_notify_sys(struct notifier_block *this, unsigned long code,
|
||||
void *unused)
|
||||
{
|
||||
struct w83793_data *data = NULL;
|
||||
|
||||
if (code == SYS_DOWN || code == SYS_HALT) {
|
||||
|
||||
/* Disable each registered watchdog */
|
||||
mutex_lock(&watchdog_data_mutex);
|
||||
list_for_each_entry(data, &watchdog_data_list, list) {
|
||||
if (data->watchdog_miscdev.minor)
|
||||
watchdog_disable(data);
|
||||
}
|
||||
mutex_unlock(&watchdog_data_mutex);
|
||||
}
|
||||
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* The WDT needs to learn about soft shutdowns in order to
|
||||
* turn the timebomb registers off.
|
||||
*/
|
||||
|
||||
static struct notifier_block watchdog_notifier = {
|
||||
.notifier_call = watchdog_notify_sys,
|
||||
};
|
||||
|
||||
/*
|
||||
* Init / remove routines
|
||||
*/
|
||||
|
||||
static int w83793_remove(struct i2c_client *client)
|
||||
{
|
||||
struct w83793_data *data = i2c_get_clientdata(client);
|
||||
struct device *dev = &client->dev;
|
||||
int i;
|
||||
int i, tmp;
|
||||
|
||||
/* Unregister the watchdog (if registered) */
|
||||
if (data->watchdog_miscdev.minor) {
|
||||
misc_deregister(&data->watchdog_miscdev);
|
||||
|
||||
if (data->watchdog_is_open) {
|
||||
dev_warn(&client->dev,
|
||||
"i2c client detached with watchdog open! "
|
||||
"Stopping watchdog.\n");
|
||||
watchdog_disable(data);
|
||||
}
|
||||
|
||||
mutex_lock(&watchdog_data_mutex);
|
||||
list_del(&data->list);
|
||||
mutex_unlock(&watchdog_data_mutex);
|
||||
|
||||
/* Tell the watchdog code the client is gone */
|
||||
mutex_lock(&data->watchdog_lock);
|
||||
data->client = NULL;
|
||||
mutex_unlock(&data->watchdog_lock);
|
||||
}
|
||||
|
||||
/* Reset Configuration Register to Disable Watch Dog Registers */
|
||||
tmp = w83793_read_value(client, W83793_REG_CONFIG);
|
||||
w83793_write_value(client, W83793_REG_CONFIG, tmp & ~0x04);
|
||||
|
||||
unregister_reboot_notifier(&watchdog_notifier);
|
||||
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
|
||||
|
|
@ -1099,7 +1494,10 @@ static int w83793_remove(struct i2c_client *client)
|
|||
if (data->lm75[1] != NULL)
|
||||
i2c_unregister_device(data->lm75[1]);
|
||||
|
||||
kfree(data);
|
||||
/* Decrease data reference counter */
|
||||
mutex_lock(&watchdog_data_mutex);
|
||||
kref_put(&data->kref, w83793_release_resources);
|
||||
mutex_unlock(&watchdog_data_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1203,6 +1601,7 @@ static int w83793_probe(struct i2c_client *client,
|
|||
const struct i2c_device_id *id)
|
||||
{
|
||||
struct device *dev = &client->dev;
|
||||
const int watchdog_minors[] = { WATCHDOG_MINOR, 212, 213, 214, 215 };
|
||||
struct w83793_data *data;
|
||||
int i, tmp, val, err;
|
||||
int files_fan = ARRAY_SIZE(w83793_left_fan) / 7;
|
||||
|
|
@ -1218,6 +1617,14 @@ static int w83793_probe(struct i2c_client *client,
|
|||
i2c_set_clientdata(client, data);
|
||||
data->bank = i2c_smbus_read_byte_data(client, W83793_REG_BANKSEL);
|
||||
mutex_init(&data->update_lock);
|
||||
mutex_init(&data->watchdog_lock);
|
||||
INIT_LIST_HEAD(&data->list);
|
||||
kref_init(&data->kref);
|
||||
|
||||
/* Store client pointer in our data struct for watchdog usage
|
||||
(where the client is found through a data ptr instead of the
|
||||
otherway around) */
|
||||
data->client = client;
|
||||
|
||||
err = w83793_detect_subclients(client);
|
||||
if (err)
|
||||
|
|
@ -1380,8 +1787,77 @@ static int w83793_probe(struct i2c_client *client,
|
|||
goto exit_remove;
|
||||
}
|
||||
|
||||
/* Watchdog initialization */
|
||||
|
||||
/* Register boot notifier */
|
||||
err = register_reboot_notifier(&watchdog_notifier);
|
||||
if (err != 0) {
|
||||
dev_err(&client->dev,
|
||||
"cannot register reboot notifier (err=%d)\n", err);
|
||||
goto exit_devunreg;
|
||||
}
|
||||
|
||||
/* Enable Watchdog registers.
|
||||
Set Configuration Register to Enable Watch Dog Registers
|
||||
(Bit 2) = XXXX, X1XX. */
|
||||
tmp = w83793_read_value(client, W83793_REG_CONFIG);
|
||||
w83793_write_value(client, W83793_REG_CONFIG, tmp | 0x04);
|
||||
|
||||
/* Set the default watchdog timeout */
|
||||
data->watchdog_timeout = timeout;
|
||||
|
||||
/* Check, if last reboot was caused by watchdog */
|
||||
data->watchdog_caused_reboot =
|
||||
w83793_read_value(data->client, W83793_REG_WDT_STATUS) & 0x01;
|
||||
|
||||
/* Disable Soft Watchdog during initialiation */
|
||||
watchdog_disable(data);
|
||||
|
||||
/* We take the data_mutex lock early so that watchdog_open() cannot
|
||||
run when misc_register() has completed, but we've not yet added
|
||||
our data to the watchdog_data_list (and set the default timeout) */
|
||||
mutex_lock(&watchdog_data_mutex);
|
||||
for (i = 0; i < ARRAY_SIZE(watchdog_minors); i++) {
|
||||
/* Register our watchdog part */
|
||||
snprintf(data->watchdog_name, sizeof(data->watchdog_name),
|
||||
"watchdog%c", (i == 0) ? '\0' : ('0' + i));
|
||||
data->watchdog_miscdev.name = data->watchdog_name;
|
||||
data->watchdog_miscdev.fops = &watchdog_fops;
|
||||
data->watchdog_miscdev.minor = watchdog_minors[i];
|
||||
|
||||
err = misc_register(&data->watchdog_miscdev);
|
||||
if (err == -EBUSY)
|
||||
continue;
|
||||
if (err) {
|
||||
data->watchdog_miscdev.minor = 0;
|
||||
dev_err(&client->dev,
|
||||
"Registering watchdog chardev: %d\n", err);
|
||||
break;
|
||||
}
|
||||
|
||||
list_add(&data->list, &watchdog_data_list);
|
||||
|
||||
dev_info(&client->dev,
|
||||
"Registered watchdog chardev major 10, minor: %d\n",
|
||||
watchdog_minors[i]);
|
||||
break;
|
||||
}
|
||||
if (i == ARRAY_SIZE(watchdog_minors)) {
|
||||
data->watchdog_miscdev.minor = 0;
|
||||
dev_warn(&client->dev, "Couldn't register watchdog chardev "
|
||||
"(due to no free minor)\n");
|
||||
}
|
||||
|
||||
mutex_unlock(&watchdog_data_mutex);
|
||||
|
||||
return 0;
|
||||
|
||||
/* Unregister hwmon device */
|
||||
|
||||
exit_devunreg:
|
||||
|
||||
hwmon_device_unregister(data->hwmon_dev);
|
||||
|
||||
/* Unregister sysfs hooks */
|
||||
|
||||
exit_remove:
|
||||
|
|
@ -1628,7 +2104,7 @@ static void __exit sensors_w83793_exit(void)
|
|||
i2c_del_driver(&w83793_driver);
|
||||
}
|
||||
|
||||
MODULE_AUTHOR("Yuan Mu");
|
||||
MODULE_AUTHOR("Yuan Mu, Sven Anders");
|
||||
MODULE_DESCRIPTION("w83793 driver");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue