All of lore.kernel.org
 help / color / mirror / Atom feed
* [lm-sensors] [PATCH] thmc50: individual alarm and fault files
@ 2007-08-04 11:56 Krzysztof Helt
  2007-08-12 18:40 ` Jean Delvare
  0 siblings, 1 reply; 2+ messages in thread
From: Krzysztof Helt @ 2007-08-04 11:56 UTC (permalink / raw)
  To: lm-sensors

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

From: Krzysztof Helt <krzysztof.h1@wp.pl>

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 <krzysztof.h1@wp.pl>



----------------------------------------------------
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

[-- Attachment #2: thmc50-individual-alarms.diff --]
[-- Type: application/octet-stream, Size: 3683 bytes --]

From: Krzysztof Helt <krzysztof.h1@wp.pl>

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 <krzysztof.h1@wp.pl>

---

diff -urp linux-2.6.23.old/drivers/hwmon/thmc50.c linux-2.6.23/drivers/hwmon/thmc50.c
--- linux-2.6.23.old/drivers/hwmon/thmc50.c	2007-08-02 10:21:00.000000000 +0200
+++ linux-2.6.23/drivers/hwmon/thmc50.c	2007-08-03 20:46:33.000000000 +0200
@@ -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			0x4C
 
 const 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 devic
 	return 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;
 	}

[-- Attachment #3: Type: text/plain, Size: 153 bytes --]

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [lm-sensors] [PATCH] thmc50: individual alarm and fault files
  2007-08-04 11:56 [lm-sensors] [PATCH] thmc50: individual alarm and fault files Krzysztof Helt
@ 2007-08-12 18:40 ` Jean Delvare
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Delvare @ 2007-08-12 18:40 UTC (permalink / raw)
  To: lm-sensors

Hi Krzysztof,

On Sat, 04 Aug 2007 13:56:31 +0200, Krzysztof Helt wrote:
> From: Krzysztof Helt <krzysztof.h1@wp.pl>
> 
> 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 <krzysztof.h1@wp.pl>

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,
-- 
Jean Delvare

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-12 18:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-04 11:56 [lm-sensors] [PATCH] thmc50: individual alarm and fault files Krzysztof Helt
2007-08-12 18:40 ` Jean Delvare

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.