Skip to content

Commit

Permalink
Merge "Changes to touchscreen driver to enhance logging" into ics
Browse files Browse the repository at this point in the history
  • Loading branch information
dalingrin authored and Gerrit Code Review committed Apr 7, 2012
2 parents 9110793 + 037a5a8 commit 664f08e
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 96 deletions.
5 changes: 5 additions & 0 deletions liblights/lights.c
Expand Up @@ -45,6 +45,8 @@ char const *const LED_FILE = "/dev/lm8502";

#define TS_SOCKET_LOCATION "/dev/socket/tsdriver"

#define TS_SOCKET_DEBUG 1

/* LED engine programs */
static const uint16_t notif_led_program_pulse[] = {
0x9c0f, 0x9c8f, 0xe004, 0x4000, 0x047f, 0x4c00, 0x057f, 0x4c00,
Expand All @@ -69,6 +71,9 @@ void send_ts_socket(char *send_data) {
strcpy(unaddr.sun_path, TS_SOCKET_LOCATION);
len = strlen(unaddr.sun_path) + sizeof(unaddr.sun_family);
if (connect(ts_fd, (struct sockaddr *)&unaddr, len) >= 0) {
#if TS_SOCKET_DEBUG
LOGD("Send ts socket %i byte(s): '%s'\n", sizeof(*send_data), send_data);
#endif
send(ts_fd, send_data, sizeof(*send_data), 0);
}
close(ts_fd);
Expand Down
6 changes: 5 additions & 1 deletion touchscreen_drv/Android.mk
Expand Up @@ -12,6 +12,8 @@ LOCAL_SRC_FILES:= \
LOCAL_CFLAGS:= -g -c -W -Wall -O2 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp -funsafe-math-optimizations -D_POSIX_SOURCE -I/home/green/touchpad/hp_tenderloin_kernel/include
LOCAL_MODULE:=ts_srv
LOCAL_MODULE_TAGS:= eng
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_EXECUTABLE)


Expand All @@ -24,4 +26,6 @@ LOCAL_SRC_FILES:= \
LOCAL_CFLAGS:= -g -c -W -Wall -O2 -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp -funsafe-math-optimizations -D_POSIX_SOURCE -I/home/green/touchpad/hp_tenderloin_kernel/include
LOCAL_MODULE:=ts_srv_set
LOCAL_MODULE_TAGS:= eng
include $(BUILD_EXECUTABLE)
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
include $(BUILD_EXECUTABLE)
44 changes: 24 additions & 20 deletions touchscreen_drv/digitizer.c
Expand Up @@ -22,6 +22,8 @@
*
*/

#define LOG_TAG "ts_power"
#include <cutils/log.h>
#include <stdio.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
Expand All @@ -40,40 +42,42 @@ void touchscreen_power(int enable)
__u8 i2c_buf[16];
int rc;

LOGI("touchscreen_power: enable=%d, ts_state=%d", enable, ts_state);

if (enable && !ts_state) {
int retry_count = 0;
try_again:
/* Set reset so the chip immediatelly sees it */
lseek(xres_fd, 0, SEEK_SET);
rc = write(xres_fd, "1", 1);
if (rc != 1)
printf("TSpower, failed set xres");
LOGE("TSpower, failed set xres");

/* Then power on */
lseek(vdd_fd, 0, SEEK_SET);
rc = write(vdd_fd, "1", 1);
if (rc != 1)
printf("TSpower, failed to enable vdd");
LOGE("TSpower, failed to enable vdd");

/* Sleep some more for the voltage to stabilize */
usleep(50000);

lseek(wake_fd, 0, SEEK_SET);
rc = write(wake_fd, "1", 1);
if (rc != 1)
printf("TSpower, failed to assert wake");
LOGE("TSpower, failed to assert wake");

lseek(xres_fd, 0, SEEK_SET);
rc = write(xres_fd, "0", 1);
if (rc != 1)
printf("TSpower, failed to reset xres");
LOGE("TSpower, failed to reset xres");

usleep(50000);

lseek(wake_fd, 0, SEEK_SET);
rc = write(wake_fd, "0", 1);
if (rc != 1)
printf("TSpower, failed to deassert wake");
LOGE("TSpower, failed to deassert wake");

usleep(50000);

Expand All @@ -88,14 +92,14 @@ void touchscreen_power(int enable)
i2c_buf[0] = 0x08; i2c_buf[1] = 0;
rc = ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
if (rc != 1)
printf("TSPower, ioctl1 failed %d errno %d\n", rc, errno);
LOGE("TSPower, ioctl1 failed %d errno %d\n", rc, errno);
/* Ok, so the TS failed to wake, we need to retry a few times
* before totally giving up */
if ((rc != 1) && (retry_count++ < MAX_DIGITIZER_RETRY)) {
lseek(vdd_fd, 0, SEEK_SET);
rc = write(vdd_fd, "0", 1);
usleep(10000);
printf("TS wakeup retry #%d\n", retry_count);
LOGE("TS wakeup retry #%d\n", retry_count);
goto try_again;
}

Expand All @@ -104,44 +108,44 @@ void touchscreen_power(int enable)
i2c_buf[3] = 0x0C; i2c_buf[4] = 0x0D; i2c_buf[5] = 0x0A;
rc = ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
if (rc != 1)
printf("TSPower, ioctl2 failed %d errno %d\n", rc, errno);
LOGE("TSPower, ioctl2 failed %d errno %d\n", rc, errno);

i2c_msg.len = 2;
i2c_buf[0] = 0x30; i2c_buf[1] = 0x0F;
rc = ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
if (rc != 1)
printf("TSPower, ioctl3 failed %d errno %d\n", rc, errno);
LOGE("TSPower, ioctl3 failed %d errno %d\n", rc, errno);

i2c_buf[0] = 0x40; i2c_buf[1] = 0x02;
rc = ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
if (rc != 1)
printf("TSPower, ioctl4 failed %d errno %d\n", rc, errno);
LOGE("TSPower, ioctl4 failed %d errno %d\n", rc, errno);

i2c_buf[0] = 0x41; i2c_buf[1] = 0x10;
rc = ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
if (rc != 1)
printf("TSPower, ioctl5 failed %d errno %d\n", rc, errno);
LOGE("TSPower, ioctl5 failed %d errno %d\n", rc, errno);

i2c_buf[0] = 0x0A; i2c_buf[1] = 0x04;
rc = ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
if (rc != 1)
printf("TSPower, ioctl6 failed %d errno %d\n", rc, errno);
LOGE("TSPower, ioctl6 failed %d errno %d\n", rc, errno);

i2c_buf[0] = 0x08; i2c_buf[1] = 0x03;
rc = ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
if (rc != 1)
printf("TSPower, ioctl7 failed %d errno %d\n", rc, errno);
LOGE("TSPower, ioctl7 failed %d errno %d\n", rc, errno);

lseek(wake_fd, 0, SEEK_SET);
rc = write(wake_fd, "1", 1);
if (rc != 1)
printf("TSpower, failed to assert wake again");
LOGE("TSpower, failed to assert wake again");
ts_state = 1;
} else if (ts_state) {
lseek(vdd_fd, 0, SEEK_SET);
rc = write(vdd_fd, "0", 1);
if (rc != 1)
printf("TSpower, failed to disable vdd");
LOGE("TSpower, failed to disable vdd");

/* Weird, but on 4G touchpads even after vdd is off there is still
* stream of data from ctp that only disappears after we reset the
Expand All @@ -162,15 +166,15 @@ void init_digitizer_fd(void) {
/* TS file descriptors. Ignore errors. */
vdd_fd = open("/sys/devices/platform/cy8ctma395/vdd", O_WRONLY);
if (vdd_fd < 0)
printf("TScontrol: Cannot open vdd - %d", errno);
LOGE("TScontrol: Cannot open vdd - %d", errno);
xres_fd = open("/sys/devices/platform/cy8ctma395/xres", O_WRONLY);
if (xres_fd < 0)
printf("TScontrol: Cannot open xres - %d", errno);
LOGE("TScontrol: Cannot open xres - %d", errno);
wake_fd = open("/sys/user_hw/pins/ctp/wake/level", O_WRONLY);
if (wake_fd < 0)
printf("TScontrol: Cannot open wake - %d", errno);
LOGE("TScontrol: Cannot open wake - %d", errno);
i2c_fd = open("/dev/i2c-5", O_RDWR);
if (i2c_fd < 0)
printf("TScontrol: Cannot open i2c dev - %d", errno);
LOGE("TScontrol: Cannot open i2c dev - %d", errno);

}
}

0 comments on commit 664f08e

Please sign in to comment.