thmc50: individual alarm and fault files
PATCH 1/1 thmc50: individual alarm and fault files
From: Krzysztof Helt <[email protected]>
This patch adds individual alarm and fault files to the thmc50 driver. These sysfs entries are required for a new libsensors library.
----------------------------------------------------
Najważniejsze koncertowe wydarzenie tego lata! METAL HAMMER FESTIVAL TOOL, Chris Cornell, Dir en Grey, Coma i inni
12.08.2007 - Katowice, Spodek. Start: godz.: 15:00
http://klik.wp.pl/?adr=http%3A%2F%2Fadv.reklama.wp.pl%2Fas%2Fmetalhammer.html&sid=1246
From: Krzysztof Helt <[email protected]>
This patch adds individual alarm and fault files to the thmc50 driver. These sysfs entries are required for a new libsensors library.
---
drivers/hwmon/thmc50.c +47 -1
@@ -46,6 +46,11 @@ I2C_CLIENT_MODULE_PARM(adm1022_temp3, "L#define THMC50_REG_COMPANY_ID 0x3E#define THMC50_REG_DIE_CODE 0x3F#define THMC50_REG_ANALOG_OUT 0x19 +/* +* We use mirror status register for reading alarms +* so ACPI can use the primary status register. +*/ +#define THMC50_REG_INTR_MIRROR 0x4Cconst static u8 THMC50_REG_TEMP [] = {0x27 ,0x26 ,0x20 };const static u8 THMC50_REG_TEMP_MIN [] = {0x3A ,0x38 ,0x2C };
@@ -69,6 +74,7 @@ struct thmc50_data {s8 temp_max[3 ];s8 temp_min[3 ];u8 analog_out; +u8 alarms; };static int thmc50_attach_adapter (struct i2c_adapter *adapter);
@@ -180,13 +186,46 @@ static ssize_t set_temp_max(struct devicreturn count; } +static ssize_t show_alarm (struct device *dev,struct device_attribute *attr, +char *buf) +{ +int index =to_sensor_dev_attr (attr)->index; +struct thmc50_data *data =thmc50_update_device (dev); +int alarm = data->alarms; + +if (index ==1 ) + alarm >>=5 ; +else if (index ==2 ) + alarm >>=1 ; + +return sprintf (buf,"%u\n" , alarm &1 ); +} + +static ssize_t show_fault (struct device *dev,struct device_attribute *attr, +char *buf) +{ +int index =to_sensor_dev_attr (attr)->index; +struct thmc50_data *data =thmc50_update_device (dev); +int fault = data->alarms >>2 ; + +if (index ==1 ) + fault >>=5 ; + +return sprintf (buf,"%u\n" , fault &1 ); +} +#define temp_reg (offset) \ static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp, \ NULL, offset - 1); \ static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ show_temp_min, set_temp_min, offset - 1); \ static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ - show_temp_max, set_temp_max, offset - 1); + show_temp_max, set_temp_max, offset - 1); \ +static SENSOR_DEVICE_ATTR(temp##offset##_alarm, S_IRUGO, \ + show_alarm, NULL, offset - 1); + +static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_fault, NULL, 1); +static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_fault, NULL, 2);temp_reg (1 );temp_reg (2 );
@@ -200,9 +239,12 @@ static struct attribute *thmc50_attribut &sensor_dev_attr_temp1_max.dev_attr.attr, &sensor_dev_attr_temp1_min.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr, + &sensor_dev_attr_temp1_alarm.dev_attr.attr, &sensor_dev_attr_temp2_max.dev_attr.attr, &sensor_dev_attr_temp2_min.dev_attr.attr, &sensor_dev_attr_temp2_input.dev_attr.attr, + &sensor_dev_attr_temp2_alarm.dev_attr.attr, + &sensor_dev_attr_temp2_fault.dev_attr.attr, &sensor_dev_attr_pwm1.dev_attr.attr, &sensor_dev_attr_pwm1_mode.dev_attr.attr,NULL
@@ -217,6 +259,8 @@ static struct attribute *adm1022_attribu &sensor_dev_attr_temp3_max.dev_attr.attr, &sensor_dev_attr_temp3_min.dev_attr.attr, &sensor_dev_attr_temp3_input.dev_attr.attr, + &sensor_dev_attr_temp3_alarm.dev_attr.attr, + &sensor_dev_attr_temp3_fault.dev_attr.attr, NULL };
@@ -414,6 +458,8 @@ static struct thmc50_data *thmc50_update } data->analog_out =i2c_smbus_read_byte_data (client,THMC50_REG_ANALOG_OUT ); + data->alarms = +i2c_smbus_read_byte_data (client,THMC50_REG_INTR_MIRROR ); data->last_updated = jiffies; data->valid =1 ; }
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Hi Krzysztof,
Quoted 7 lines · Krzysztof Helt
From: Krzysztof Helt <[email protected]>
This patch adds individual alarm and fault files to the thmc50 driver. These sysfs entries are required for a new libsensors library.
Signed-off-by Krzysztof Helt <[email protected]>
Thank for working on this. Your patch works, but it's not very efficient. You could pass the bit shift value directly in index for each alarm and fault file, rather than computing it again each time. Then you could have a single callback for alarms and faults. Please see the lm90 driver for an example of this implementation.
Thanks,
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors