aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw27@cam.ac.uk>2008-12-19 00:37:40 +0000
committerThomas White <taw27@cam.ac.uk>2008-12-19 00:37:40 +0000
commitc190b15d98a44a104b90630dec6f2659fed5bcf4 (patch)
treec9f5bd3a5b5471c78879a20c7364e52dc93a7fcb
parent365c155ee09c2573b6931e8816dc6fe61a441d5f (diff)
Openmoko 2.6.28 kernel readinessopenmoocow-0.3
This makes the accelerometer threshold-setting code check the new (2.6.28+) kernel sysfs paths for the threshold values, as well as the old versions. Signed-off-by: Thomas White <taw27@cam.ac.uk>
-rw-r--r--src/accelerometers.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/accelerometers.c b/src/accelerometers.c
index e965b2f..e11d4c0 100644
--- a/src/accelerometers.c
+++ b/src/accelerometers.c
@@ -53,17 +53,34 @@ struct input_event {
#define REL_Y (0x01)
#define REL_Z (0x02)
+/* Try to open the threshold sysfs file for Freerunner's accelerometers.
+ * Try methods for both old and new kernels */
+static FILE *accelerometer_freerunner_open_threshold(const char *mode)
+{
+ FILE *fh;
+
+ /* Try 2.6.24 method */
+ fh = fopen("/sys/devices/platform/lis302dl.2/threshold", mode);
+ if ( fh != NULL ) {
+ return fh;
+ }
+
+ /* Try 2.6.28+ method */
+ fh = fopen("/sys/class/i2c-adapter/i2c-0/0-0073/lis302dl.2/threshold", mode);
+ if ( fh != NULL ) {
+ return fh;
+ }
+
+ return NULL;
+}
+
static void accelerometer_freerunner_try_threshold(AccelHandle *accel)
{
FILE *fh;
int rval;
/* Save the old threshold */
- fh = fopen("/sys/devices/platform/lis302dl.2/threshold", "r");
- if ( fh == NULL ) {
- fprintf(stderr, "Failed to disable accelerometer threshold.\n");
- return;
- }
+ fh = accelerometer_freerunner_open_threshold("r");
rval = fscanf(fh, "%i", &accel->old_threshold);
if ( rval != 1 ) {
/* Failed */
@@ -74,7 +91,7 @@ static void accelerometer_freerunner_try_threshold(AccelHandle *accel)
fclose(fh);
/* Set the threshold to zero */
- fh = fopen("/sys/devices/platform/lis302dl.2/threshold", "w");
+ fh = accelerometer_freerunner_open_threshold("w");
if ( fh == NULL ) {
fprintf(stderr, "Failed to disable accelerometer threshold.\n");
return;
@@ -94,7 +111,7 @@ static void accelerometer_freerunner_try_restore_threshold(AccelHandle *accel)
printf("Not restoring threshold.\n");
}
- fh = fopen("/sys/devices/platform/lis302dl.2/threshold", "r");
+ fh = accelerometer_freerunner_open_threshold("r");
if ( fh == NULL ) {
fprintf(stderr, "Failed to restore accelerometer threshold.\n");
return;
@@ -112,7 +129,7 @@ static void accelerometer_freerunner_try_restore_threshold(AccelHandle *accel)
}
/* Set it back to the old value */
- fh = fopen("/sys/devices/platform/lis302dl.2/threshold", "w");
+ fh = accelerometer_freerunner_open_threshold("w");
if ( fh == NULL ) {
fprintf(stderr, "Failed to restore accelerometer threshold.\n");
return;