From c190b15d98a44a104b90630dec6f2659fed5bcf4 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 19 Dec 2008 00:37:40 +0000 Subject: Openmoko 2.6.28 kernel readiness 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 --- src/accelerometers.c | 33 +++++++++++++++++++++++++-------- 1 file 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; -- cgit v1.2.3