GoboLinux Downloads Documentation Community Recipes Screenshots

GoboLinux Recipe & Package Search Tool

71 versions of Linux.

ProgramAgeSizeByWWWSummary
Linux 4.13.2-r1 760  88794 Luca...
The Linux Kernel.
Linux 4.9.16-r3 931  100651 Luca...
The Linux Kernel.
Linux 4.9.4-r5 987  99374 Luca...
The Linux Kernel.
Linux 4.8.2-r2 1053  89394 Luca...
The Linux Kernel.
Linux 4.7.4-r1 1123  82767 Luca...
The Linux Kernel.
Linux 4.7.0-r4 1178  82585 Luca...
The Linux Kernel.
Linux 3.13.3-r1 2058  252629 Luca...
The Linux Kernel.
Linux 3.12.6-r1 2118  238949 Luca...
The Linux Kernel.
Linux 3.9.4-r2 2313  70048 Luca...
The Linux Kernel.
Linux 3.7.1-r2 2486  67579 Luca...
The Linux Kernel.
Linux 3.5.0-r1 2637  124391 Luca...
The Linux Kernel.
Linux 3.4.4-r1 2637  124348 Luca...
The Linux Kernel.
Linux 3.3.6-r1 2637  124410 Luca...
The Linux Kernel.
Linux 3.2.12-r2 2765  124345 Luca...
The Linux Kernel.
Linux 3.2.7-r1 2795  123550 Mich...
The Linux Kernel.
Linux 3.1.1-r1 2900  122907 Mich...
The Linux Kernel.
Linux 3.0.4-r4 2961  122754 Luca...
The Linux Kernel.
Linux 2.6.36.3-r1 3184  116087 Diog...
The Linux Kernel.
Linux 2.6.32.3-r1 3562  117990 Luca...
The Linux Kernel.
Linux 2.6.32-r1 3603  117751 Luca...
The Linux Kernel.
Linux 2.6.31.6-r3 3608  126499 Luca...
The Linux Kernel.
Linux 2.6.30.5-r1 3687  166102 Jona...
The Linux Kernel.
Linux 2.6.29.1-r1 3830  117500 Luca...
The Linux Kernel.
Linux 2.6.28.7-r1 3886  115518 Giam...
The Linux Kernel.
Linux 2.6.28.1-r1 3886  115487 Giam...
The Linux Kernel.
Linux 2.6.28-r1 3886  116681 Mich...
The Linux Kernel.
Linux 2.6.27.8-r1 3886  134160 Giam...
The Linux Kernel.
Linux 2.6.27.4-r3 3886  149529 Luca...
The Linux Kernel.
Linux 2.6.25.17-r1 3886  172834 Giam...
The Linux Kernel.
Linux 2.6.25.16-r1 3886  166500 Giam...
The Linux Kernel.
Linux 2.6.25.10-r2 3886  165320 Giam...
The Linux Kernel.
Linux 2.6.25.7-r1 3886  157294 Giam...
The Linux Kernel.
Linux 2.6.25.4-r1 3886  133017 Hopp...
The Linux Kernel.
Linux 2.6.25-r1 3886  133216 Luca...
The Linux Kernel.
Linux 2.6.24.4-r5 3886  150733
The Linux Kernel.
view entry at GitHub | download recipe.bz2 file
01-gobohide.patch
02-unionfs-2.3.2_for_2.6.24.4.patch
03-squashfs-3.3-cvs_20080310.patch
04-squashfs-3.3-cvs_20080310-fix.patch
04-thinkpad-acpi-0.19-20080107_v2.6.24.patch
05-applesmc-case-led.patch
06-applesmc_int.patch
07-applesmc-macbook2.patch
08-applesmc-retry-when-accessing-keys.patch
09-appletouch-add-macbook3-trackpad.patch
10-appletouch.patch
11-appletouch-new.patch
12-sigmatel_audio_display_all_controls_when_subsystem_id_is_wrong.patch
13-sigmatel_audio_fix_macbook_v2.patch
14-appletouch-2.6.24_rc8.patch
15-macbook3rd-2.6.24_rc8.patch
16-usbhid-macbook3_1-quirks.patch
17-applesmc_led_unregister.patch
18-vm_splice_fix.patch
Recipe
Resources/BuildInformation
Resources/Dependencies
Resources/Description
Resources/NewDependencies
i686/Recipe
i686/dot-config
ppc/Recipe
ppc/dot-config
Add interrupt support for the accelerometer. A message is printed in dmesg when an \
interrupt occurs, but no further handling is done.

From: Nicolas Boichat <nicolas@boichat.ch>


---

 drivers/hwmon/applesmc.c |  320 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 297 insertions(+), 23 deletions(-)

diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
index 3b09cdb..8f75b57 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -39,14 +39,20 @@
 #include <linux/leds.h>
 #include <linux/hwmon.h>
 #include <linux/workqueue.h>
+#include <linux/interrupt.h>
 
 /* data port used by Apple SMC */
 #define APPLESMC_DATA_PORT	0x300
 /* command/status port used by Apple SMC */
 #define APPLESMC_CMD_PORT	0x304
+/* status port used by Apple SMC to get which interrupt type just happened */
+#define APPLESMC_INT_PORT	0x31f
 
 #define APPLESMC_NR_PORTS	32 /* 0x300-0x31f */
 
+/* Defined in ACPI DSDT table, should we read it from there? */
+#define APPLESMC_IRQ		6
+
 #define APPLESMC_MAX_DATA_LENGTH 32
 
 #define APPLESMC_STATUS_MASK	0x0f
@@ -57,6 +63,8 @@
 
 #define KEY_COUNT_KEY		"#KEY" /* r-o ui32 */
 
+#define INTERRUPT_OK_KEY	"NTOK" /* w-o ui8 */
+
 #define LIGHT_SENSOR_LEFT_KEY	"ALV0" /* r-o {alv (6 bytes) */
 #define LIGHT_SENSOR_RIGHT_KEY	"ALV1" /* r-o {alv (6 bytes) */
 #define BACKLIGHT_KEY		"LKSB" /* w-o {lkb (2 bytes) */
@@ -68,6 +76,19 @@
 #define MOTION_SENSOR_Z_KEY	"MO_Z" /* r-o sp78 (2 bytes) */
 #define MOTION_SENSOR_KEY	"MOCN" /* r/w ui16 */
 
+/*
+ * Interrupt controls.
+ * If the norm of the position (sqrt(MO_X^2+MO_Y^2+MO_Z^2)) is smaller than
+ * MOLT (free fall), or bigger than MOHT (high acceleration) for longer than the
+ * value of MOLD (or MOHD), SMC will trigger an interrupt.
+ */
+#define MOTION_LOW_NORM			"MOLT" /* r/w sp78 (2 bytes) */
+#define MOTION_HIGH_NORM		"MOHT" /* r/w sp78 (2 bytes) */
+#define MOTION_LOW_NORM_INTERVAL	"MOLD" /* r/w ui8 */
+#define MOTION_HIGH_NORM_INTERVAL	"MOHD" /* r/w ui8 */
+
+#define MSDW_KEY		"MSDW" /* r/w flag (1 byte) */
+
 #define FANS_COUNT		"FNum" /* r-o ui8 */
 #define FANS_MANUAL		"FS! " /* r-w ui16 */
 #define FAN_ACTUAL_SPEED	"F0Ac" /* r-o fpe2 (2 bytes) */
@@ -385,12 +406,83 @@ static int applesmc_read_motion_sensor(int index, s16* value)
 }
 
 /*
+ * applesmc_init_check_key_value - checks if a given key contains the bytes in
+ * buffer, if not, writes these bytes.
+ * In case of failure retry every INIT_WAIT_MSECS msec, and timeout if it
+ * waited more than INIT_TIMEOUT_MSECS in total.
+ * Returns zero on success or a negative error on failure. Callers must
+ * hold applesmc_lock.
+ */
+static int applesmc_init_check_key_value(const char *key, u8 *buffer, u8 len)
+{
+	int total, ret, i, compare;
+	u8 rdbuffer[APPLESMC_MAX_DATA_LENGTH];
+
+	if (len > APPLESMC_MAX_DATA_LENGTH) {
+		printk(KERN_ERR "applesmc_init_check_key_value: cannot "
+					"read/write more than %d bytes",
+					APPLESMC_MAX_DATA_LENGTH);
+		return -EINVAL;
+	}
+
+	for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
+		ret = applesmc_read_key(key, rdbuffer, len);
+		if (!ret) {
+			compare = 1;
+			for (i = 0; i < len; i++) {
+				if (rdbuffer[i] != buffer[i]) {
+					compare = 0;
+					break;
+				}
+			}
+
+			if (compare) {
+				return 0;
+			}
+		}
+		ret = applesmc_write_key(key, buffer, len);
+		msleep(INIT_WAIT_MSECS);
+	}
+
+	if (ret)
+		return ret;
+	else
+		return -EIO;
+}
+
+irqreturn_t applesmc_irq_handler(int irq, void *dev_id)
+{
+	u8 int_type = inb(APPLESMC_INT_PORT);
+
+	switch (int_type) {
+	case 0x60:
+		printk(KERN_INFO "applesmc: received a free fall interrupt\n");
+		break;
+	case 0x6f:
+		printk(KERN_INFO
+			"applesmc: received a high acceleration interrupt\n");
+		break;
+	case 0x80:
+		printk(KERN_INFO "applesmc: received a shock interrupt\n");
+		break;
+	default:
+		printk(KERN_INFO
+			"applesmc: received an unknown interrupt %x\n",
+			int_type);
+	}
+
+	return IRQ_HANDLED;
+}
+
+/*
  * applesmc_device_init - initialize the accelerometer.  Returns zero on success
  * and negative error code on failure.  Can sleep.
  */
 static int applesmc_device_init(void)
 {
-	int total, ret = -ENXIO;
+	int total;
+	int ret = -ENXIO;
+	int ret1, ret2;
 	u8 buffer[2];
 
 	if (!applesmc_accelerometer)
@@ -398,32 +490,79 @@ static int applesmc_device_init(void)
 
 	mutex_lock(&applesmc_lock);
 
+	/* Accept interrupts */
+	buffer[0] = 0x01;
 	for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
-		if (debug)
-			printk(KERN_DEBUG "applesmc try %d\n", total);
-		if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) &&
-				(buffer[0] != 0x00 || buffer[1] != 0x00)) {
-			if (total == INIT_TIMEOUT_MSECS) {
-				printk(KERN_DEBUG "applesmc: device has"
-						" already been initialized"
-						" (0x%02x, 0x%02x).\n",
-						buffer[0], buffer[1]);
-			} else {
-				printk(KERN_DEBUG "applesmc: device"
-						" successfully initialized"
-						" (0x%02x, 0x%02x).\n",
-						buffer[0], buffer[1]);
-			}
-			ret = 0;
-			goto out;
-		}
-		buffer[0] = 0xe0;
-		buffer[1] = 0x00;
-		applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2);
+		ret1 = applesmc_write_key(INTERRUPT_OK_KEY, buffer, 1);
+		msleep(INIT_WAIT_MSECS);
+
+		if (!ret1)
+			break;
+	}
+	if (ret1)
+		printk(KERN_WARNING "applesmc: Cannot set NTOK key, "
+					"will not receive interrupts.\n");
+
+	/* Setup interrupt controls. */
+	buffer[0] = 20; /* 20 msecs */
+	ret1 = applesmc_init_check_key_value(MOTION_LOW_NORM_INTERVAL,
+								buffer, 1);
+
+	buffer[0] = 20; /* 20 msecs */
+	ret2 = applesmc_init_check_key_value(MOTION_HIGH_NORM_INTERVAL,
+								buffer, 1);
+
+	if (ret1 || ret2) {
+		printk(KERN_WARNING "applesmc: Cannot set motion sensor "
+					"interrupt interval, might not receive "
+					"some interrupts.");
+	}
+
+	buffer[0] = 0x00;
+	buffer[1] = 0x60;
+	ret1 = applesmc_init_check_key_value(MOTION_LOW_NORM, buffer, 2);
+
+	buffer[0] = 0x01;
+	buffer[1] = 0xc0;
+	ret2 = applesmc_init_check_key_value(MOTION_HIGH_NORM, buffer, 2);
+
+	if (ret1 || ret2) {
+		printk(KERN_WARNING "applesmc: Cannot set motion sensor "
+				"min/max norm parameters, "
+				"might not receive some interrupts.");
+	}
+
+	/* Mysterious key. */
+	buffer[0] = 0x01;
+	for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
+		ret1 = applesmc_write_key(MSDW_KEY, buffer, 1);
 		msleep(INIT_WAIT_MSECS);
+
+		if (!ret1)
+			break;
+	}
+	if (ret1)
+		printk(KERN_WARNING "applesmc: Cannot set MSDW key\n");
+
+	/* Initialize the device. */
+	buffer[0] = 0xe0;
+	buffer[1] = 0xf8;
+	if (applesmc_init_check_key_value(MOTION_SENSOR_KEY, buffer, 2)) {
+		printk(KERN_WARNING "applesmc: failed to init "
+							"the accelerometer\n");
+		goto out;
 	}
 
-	printk(KERN_WARNING "applesmc: failed to init the device\n");
+	ret1 = request_irq(APPLESMC_IRQ, applesmc_irq_handler, IRQF_DISABLED,
+						"applesmc_irq_handler", NULL);
+
+	if (ret1) {
+		printk(KERN_WARNING "applesmc: cannot setup irq handler\n");
+	}
+
+	printk(KERN_DEBUG "applesmc: accelerometer "
+						"successfully initialized.\n");
+	ret = 0;
 
 out:
 	mutex_unlock(&applesmc_lock);
@@ -468,9 +607,16 @@ static int applesmc_resume(struct platform_device *dev)
 	return applesmc_device_init();
 }
 
+static int applesmc_remove(struct platform_device *dev)
+{
+	free_irq(APPLESMC_IRQ, NULL);
+	return 0;
+}
+
 static struct platform_driver applesmc_driver = {
 	.probe = applesmc_probe,
 	.resume = applesmc_resume,
+	.remove = applesmc_remove,
 	.driver	= {
 		.name = "applesmc",
 		.owner = THIS_MODULE,
@@ -932,6 +1078,122 @@ static ssize_t applesmc_key_at_index_store(struct device *dev,
 	return count;
 }
 
+static ssize_t applesmc_accelerometer_show(struct device *dev,
+				struct device_attribute *attr, char *sysfsbuf)
+{
+	int ret;
+	unsigned int value = 0;
+	u8 buffer[2];
+	char *key;
+	int length;
+	struct sensor_device_attribute_2 *sensor_attr =
+						to_sensor_dev_attr_2(attr);
+
+	switch (sensor_attr->index) {
+	case 0:
+		key = MOTION_LOW_NORM_INTERVAL;
+		length = 1;
+		break;
+	case 1:
+		key = MOTION_HIGH_NORM_INTERVAL;
+		length = 1;
+		break;
+	case 2:
+		key = MOTION_LOW_NORM;
+		length = 2;
+		break;
+	case 3:
+		key = MOTION_HIGH_NORM;
+		length = 2;
+		break;
+	default:
+		printk(KERN_ERR
+			"Invalid index for applesmc_accelerometer_show");
+		return -EINVAL;
+	}
+
+	mutex_lock(&applesmc_lock);
+
+	ret = applesmc_read_key(key, buffer, length);
+	if (length == 2)
+		value = ((unsigned int)buffer[0] << 8) | buffer[1];
+	else if (length == 1)
+		value = buffer[0];
+	else {
+		printk("Invalid length for applesmc_param_show");
+		ret = -EINVAL;
+	}
+
+	mutex_unlock(&applesmc_lock);
+	if (ret)
+		return ret;
+	else
+		return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", value);
+}
+
+static ssize_t applesmc_accelerometer_store(struct device *dev,
+					struct device_attribute *attr,
+					const char *sysfsbuf, size_t count)
+{
+	int ret;
+	u32 value;
+	u8 buffer[2];
+	char *key;
+	int length;
+	struct sensor_device_attribute_2 *sensor_attr =
+						to_sensor_dev_attr_2(attr);
+
+	switch (sensor_attr->index) {
+	case 0:
+		key = MOTION_LOW_NORM_INTERVAL;
+		length = 1;
+		break;
+	case 1:
+		key = MOTION_HIGH_NORM_INTERVAL;
+		length = 1;
+		break;
+	case 2:
+		key = MOTION_LOW_NORM;
+		length = 2;
+		break;
+	case 3:
+		key = MOTION_HIGH_NORM;
+		length = 2;
+		break;
+	default:
+		printk("Invalid index for applesmc_accelerometer_show");
+		return -EINVAL;
+	}
+
+	value = simple_strtoul(sysfsbuf, NULL, 10);
+
+	if (length == 2) {
+		if (value > 0xffff)
+			return -EINVAL;
+
+		buffer[0] = (value >> 8) & 0xff;
+		buffer[1] = value & 0xff;
+	} else if (length == 1) {
+		if (value > 0xff)
+			return -EINVAL;
+
+		buffer[0] = value & 0xff;
+	} else {
+		printk("Invalid length for applesmc_param_store");
+		return -EINVAL;
+	}
+
+	mutex_lock(&applesmc_lock);
+
+	ret = applesmc_write_key(key, buffer, length);
+
+	mutex_unlock(&applesmc_lock);
+
+	if (ret)
+		return ret;
+	else
+		return count;
+}
 static struct led_classdev applesmc_backlight = {
 	.name			= "smc:kbd_backlight",
 	.default_trigger	= "nand-disk",
@@ -943,10 +1205,22 @@ static DEVICE_ATTR(name, 0444, applesmc_name_show, NULL);
 static DEVICE_ATTR(position, 0444, applesmc_position_show, NULL);
 static DEVICE_ATTR(calibrate, 0644,
 			applesmc_calibrate_show, applesmc_calibrate_store);
+static SENSOR_DEVICE_ATTR(low_norm_trigger_interval, 0644,
+		applesmc_accelerometer_show, applesmc_accelerometer_store, 0);
+static SENSOR_DEVICE_ATTR(high_norm_trigger_interval, 0644,
+		applesmc_accelerometer_show, applesmc_accelerometer_store, 1);
+static SENSOR_DEVICE_ATTR(low_norm_trigger, 0644,
+		applesmc_accelerometer_show, applesmc_accelerometer_store, 2);
+static SENSOR_DEVICE_ATTR(high_norm_trigger, 0644,
+		applesmc_accelerometer_show, applesmc_accelerometer_store, 3);
 
 static struct attribute *accelerometer_attributes[] = {
 	&dev_attr_position.attr,
 	&dev_attr_calibrate.attr,
+	&sensor_dev_attr_low_norm_trigger.dev_attr.attr,
+	&sensor_dev_attr_high_norm_trigger.dev_attr.attr,
+	&sensor_dev_attr_low_norm_trigger_interval.dev_attr.attr,
+	&sensor_dev_attr_high_norm_trigger_interval.dev_attr.attr,
 	NULL
 };
 
Linux 2.6.24.3-r5 3886  150221 Luca...
The Linux Kernel.
Linux 2.6.24.2-r3 3886  146488 Giam...
The Linux Kernel.
Linux 2.6.24.1-r1 3886  146454 Giam...
The Linux Kernel.
Linux 2.6.24-r1 3886  146428 Luca...
The Linux Kernel.
Linux 2.6.23.8-r4 3886  155842 Luca...
The Linux Kernel.
Linux 2.6.22.7-r4 3886  114727 Luca...
The Linux Kernel.
Linux 2.6.22.1-r1 3886  121391 Luca...
The Linux Kernel.
Linux 2.6.21.1-r3 3886  118854 Luca...
The Linux Kernel.
Linux 2.6.20.7-r1 3886  117945 Luca...
The Linux Kernel.
Linux 2.6.20.4-r3 3886  151150 Luca...
The Linux Kernel.
Linux 2.6.20-r1 3886  106429 Luca...
The Linux Kernel.
Linux 2.6.18.3-r2 3886  111124 Luca...
The Linux Kernel.
Linux 2.6.17.11-r1 3886  164053 Luca...
The Linux Kernel.
Linux 2.6.17.3-r1 3886  165067 Luca...
The Linux Kernel.
Linux 2.6.16.20-r1 3886  133625 Luca...
The Linux Kernel.
Linux 2.6.16.14-r1 3886  168270 Luca...
The Linux Kernel.
Linux 2.6.15.5-r1 3886  224686 Jona...
The Linux Kernel.
Linux 2.6.15.2-r1 3886  177165 Carl...
The Linux Kernel.
Linux 2.6.15.1-r1 3886  149219 Jona...
The Linux Kernel.
Linux 2.6.15-r1 3886  149214 Luca...
The Linux Kernel.
Linux 2.6.14.4-r1 3886  150166 Jona...
The Linux Kernel.
Linux 2.6.14.3-r1 3886  150060 Jona...
The Linux Kernel.
Linux 2.6.14.2-r1 3886  149791 Carl...
The Linux Kernel.
Linux 2.6.13.4-r1 3886  149559 Luca...
The Linux Kernel.
Linux 2.6.13.2-r1 3886  56611 Jona...
The Linux Kernel.
Linux 2.6.13.1-r1 3886  56378 Luca...
The Linux Kernel.
Linux 2.6.12.2-r1 3886  50355 Luca...
The Linux Kernel.
Linux 2.6.11.9-r1 3886  98969 Luca...
The Linux Kernel.
Linux 2.6.11.8-r1 3886  109424 Jona...
The Linux Kernel.
Linux 2.6.11-r1 3886  99032 Luca...
The Linux Kernel.
Linux 2.6.10-r1 3886  65969 Luca...
The Linux Kernel.
Linux 2.6.9-r1 3886  278461 Luca...
The Linux Kernel.
Linux 2.6.8.1-r1 3886  35576 Luca...
The Linux Kernel.
Linux 2.6.7-r1 3886  22610 Luca...
The Linux Kernel.
Linux 2.6.6-r1 3886  21958 Luca...
The Linux Kernel.
Linux 2.4.26-r1 3886  22359 Luca...
The Linux Kernel.