From b9931b370ed1c0e8f0c01260296d0b09b45ab3ce Mon Sep 17 00:00:00 2001 From: codeworkx Date: Wed, 27 Jul 2011 04:28:59 +0200 Subject: [PATCH] vibrator: attempt to fix a deep sleep issue needs change in kernel driver --- vibrator/tspdrv.c | 54 +++++++++++++++++++++++++++++------------------ vibrator/tspdrv.h | 6 +++--- 2 files changed, 37 insertions(+), 23 deletions(-) diff --git a/vibrator/tspdrv.c b/vibrator/tspdrv.c index 38ae1d3..37abd59 100644 --- a/vibrator/tspdrv.c +++ b/vibrator/tspdrv.c @@ -33,32 +33,34 @@ int sendit(int timeout_ms) tspd = open(TSPDRV_DEVICE, O_RDWR); if(tspd < 0) { - LOGE("failed on opening /dev/tspdrv"); + LOGE("failed on opening /dev/tspdrv\n"); } else { - LOGV("opened device /dev/tspdrv"); + LOGV("opened device /dev/tspdrv\n"); } /* send tspdrv magic number */ tspret = ioctl(tspd, TSPDRV_MAGIC_NUMBER); if(tspret != 0) { - LOGE("TSPDRV_MAGIC_NUMBER error"); + LOGE("TSPDRV_MAGIC_NUMBER error\n"); } else { - LOGV("sent TSPDRV_MAGIC_NUMBER"); + LOGV("TSPDRV_MAGIC_NUMBER success\n"); } /* get number of actuators */ actuators = ioctl(tspd, TSPDRV_GET_NUM_ACTUATORS); - if(actuators < 0) { - LOGE("TSPDRV_GET_NUM_ACTUATORS error, no actuators available"); + if(actuators < 1) { + LOGE("TSPDRV_GET_NUM_ACTUATORS error, no actuators available\n"); } else { - LOGV("TSPDRV_GET_NUM_ACTUATORS success, actuators = %d", actuators); + LOGV("TSPDRV_GET_NUM_ACTUATORS success, actuators = %d\n", actuators); - /* enable tspdrv amp */ - tspret = ioctl(tspd, TSPDRV_ENABLE_AMP, actuators); - if(tspret != 0) { - LOGE("failed on enabling AMP"); - } else { - LOGV("enabled AMP"); + if(timeout_ms > 0) { + /* enable tspdrv amp */ + tspret = ioctl(tspd, TSPDRV_ENABLE_AMP, actuators); + if(tspret != 0) { + LOGE("TSPDRV_ENABLE_AMP error\n"); + } else { + LOGV("TSPDRV_ENABLE_AMP success\n"); + } } } @@ -66,20 +68,32 @@ int sendit(int timeout_ms) if(fd < 0) return errno; + LOGV("timeout_ms: %d\n", timeout_ms); nwr = sprintf(value, "%d\n", timeout_ms); ret = write(fd, value, nwr); - close(fd); + if(timeout_ms == 0) { + /* stop tspdrv kernel timer */ + tspret = ioctl(tspd, TSPDRV_STOP_KERNEL_TIMER); + if(tspret != 0) { + LOGE("TSPDRV_STOP_KERNEL_TIMER error\n"); + } else { + LOGV("TSPDRV_STOP_KERNEL_TIMER success\n"); + } - /* stop tspdrv kernel timer */ - tspret = ioctl(tspd, TSPDRV_STOP_KERNEL_TIMER); - if(tspret != 0) { - LOGE("failed on stopping kernel timer"); - } else { - LOGV("stopped kernel timer"); + /* disable tspdrv amp */ + if(actuators >= 1) { + tspret = ioctl(tspd, TSPDRV_DISABLE_AMP, actuators); + if(tspret != 0) { + LOGE("TSPDRV_DISABLE_AMP error\n"); + } else { + LOGV("TSPDRV_DISABLE_AMP success\n"); + } + } } close(tspd); + close(fd); return (ret == nwr) ? 0 : -1; } diff --git a/vibrator/tspdrv.h b/vibrator/tspdrv.h index 29fdb47..8f08085 100644 --- a/vibrator/tspdrv.h +++ b/vibrator/tspdrv.h @@ -18,13 +18,13 @@ #ifndef __TSPDRV_H #define __TSPDRV_H __FILE__ -#define THE_DEVICE "/sys/class/timed_output/vibrator/enable" +#define THE_DEVICE "/sys/class/timed_output/vibrator/enable" #define TSPDRV_DEVICE "/dev/tspdrv" #define TSPDRV_MAGIC_NUMBER 0x494D4D52 -#define TSPDRV_STOP_KERNEL_TIMER _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 1) +#define TSPDRV_STOP_KERNEL_TIMER _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 1) #define TSPDRV_ENABLE_AMP _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 3) #define TSPDRV_DISABLE_AMP _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 4) -#define TSPDRV_GET_NUM_ACTUATORS _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 5) +#define TSPDRV_GET_NUM_ACTUATORS _IO(TSPDRV_MAGIC_NUMBER & 0xFF, 5) #endif /* __TSPDRV_H */