Hi Nicolas,

here is another version of my patch which fixes the module loading delay
and contains conditionals which allow the module to be compiled for
kernels < 2.6.17. I don't know when the led subsystem was introduced so
I assumed kernel version 2.6.17. If you'd like to integrate the patch
feel free to do so.

And by the way: Do you have any SMC documentation?

Regards,

- Jan.

--- applesmc.c.orig	2006-10-17 19:10:07.000000000 +0200
+++ applesmc.c	2006-10-17 20:14:22.000000000 +0200
@@ -32,8 +32,12 @@
 #include <linux/module.h>
 #include <linux/timer.h>
 #include <linux/dmi.h>
+#include <linux/version.h>
 #include <asm/io.h>
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
 #include <linux/leds.h>
+#endif
 
 /* data port used by apple SMC */
 #define APPLESMC_DATA_PORT	0x300
@@ -65,6 +69,8 @@
 #define FAN_SAFE_SPEED          "F0Sf" //r-o length 2
 #define FAN_TARGET_SPEED        "F0Tg" //r-w length 2
 
+#define FAN_TEMP                "TC0D"
+
 #define INIT_TIMEOUT_MSECS	5000	/* wait up to 5s for device init ... */
 #define INIT_WAIT_MSECS		50	/* ... in 50ms increments */
 
@@ -222,6 +228,8 @@
 	int total, ret = -ENXIO;
 	u8 buffer[2];
 
+	if (!applesmc_accelerometer) return 0;
+
 	down(&applesmc_sem);
 
 	for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
@@ -390,6 +398,32 @@
 		return sprintf(buf, "(%d,%d)\n", left, right);
 }
 
+static ssize_t applesmc_show_fan_temp(struct device *dev, char *buf, char *key, int offset)
+{
+    int ret;
+    char newkey[5];
+    u8 buffer[2];
+    u8 temp;
+    
+    newkey[0] = key[0];
+    newkey[1] = key[1];
+    newkey[2] = '0' + offset;
+    newkey[3] = key[3];
+    newkey[4] = 0;
+
+    down(&applesmc_sem);
+
+    ret = applesmc_read_key(newkey, buffer, 2);
+    temp = (buffer[0] * 256 + buffer[1]) >> 8;
+
+    up(&applesmc_sem);
+
+    if (ret)
+	return ret;
+    else
+	return sprintf(buf, "%d\n", (int) temp);
+}
+
 static ssize_t applesmc_show_fan_speed(struct device *dev, char *buf,
 							char* key, int offset)
 {
@@ -519,6 +553,7 @@
 	return count;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
 static void applesmc_backlight_set(struct led_classdev *led_cdev,
 				enum led_brightness value)
 {
@@ -536,6 +571,7 @@
 	.default_trigger	= "nand-disk",
 	.brightness_set		= applesmc_backlight_set,
 };
+#endif
 
 static DEVICE_ATTR(position, 0444, applesmc_position_show, NULL);
 static DEVICE_ATTR(calibrate, 0644, applesmc_calibrate_show,applesmc_calibrate_store);
@@ -543,6 +579,11 @@
 static DEVICE_ATTR(light, 0444, applesmc_light_show, NULL);
 
 #define sysfs_fan_speeds_offset(offset) \
+static ssize_t show_fan_temp_##offset (struct device *dev, \
+				struct device_attribute *attr, char *buf) \
+{ \
+	return applesmc_show_fan_temp(dev, buf, FAN_TEMP, offset); \
+} \
 static ssize_t show_fan_actual_speed_##offset (struct device *dev, \
 				struct device_attribute *attr, char *buf) \
 { \
@@ -551,6 +592,9 @@
 static DEVICE_ATTR(fan##offset##_actual_speed, S_IRUGO, \
 					show_fan_actual_speed_##offset, NULL); \
 \
+static DEVICE_ATTR(fan##offset##_temp, S_IRUGO, \
+					show_fan_temp_##offset, NULL); \
+\
 static ssize_t show_fan_minimum_speed_##offset (struct device *dev, \
 				struct device_attribute *attr, char *buf) \
 { \
@@ -610,6 +654,7 @@
 
 #define device_create_file_fan(client, offset) \
 do { \
+sysfs_create_file(client, &dev_attr_fan##offset##_temp.attr); \
 sysfs_create_file(client, &dev_attr_fan##offset##_actual_speed.attr); \
 sysfs_create_file(client, &dev_attr_fan##offset##_minimum_speed.attr); \
 sysfs_create_file(client, &dev_attr_fan##offset##_maximum_speed.attr); \
@@ -800,10 +845,12 @@
 		if (ret)
 			goto out_accelerometer;
 
+		#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
 		/* register as a led device */
 		ret = led_classdev_register(&pdev->dev, &applesmc_backlight);
 		if (ret < 0)
 			goto out_accelerometer;
+		#endif
 	}
 
 	printk(KERN_INFO "applesmc: driver successfully loaded.\n");
@@ -825,8 +872,10 @@
 
 static void __exit applesmc_exit(void)
 {
+        #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
 	if (applesmc_light)
 		led_classdev_unregister(&applesmc_backlight);
+	#endif
 	if (applesmc_accelerometer)
 		applesmc_release_accelerometer();
 	platform_device_unregister(pdev);

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Mactel-linux-devel mailing list
Mactel-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mactel-linux-devel

Reply via email to