Commit ae236e57 authored by Oleg Drokin's avatar Oleg Drokin
Browse files

Move touchscreen power control to libsensors.

Also change permissions on relevant sys and dev entries to system, so that
we can access them not as root.
parent a1c55bd0
......@@ -65,6 +65,12 @@ on init
mkdir /mnt/emmc 0000 system system
symlink /mnt/emmc /emmc
# For TS control
chown system system /sys/devices/platform/cy8ctma395/vdd
chown system system /sys/devices/platform/cy8ctma395/xres
chown system system /sys/user_hw/pins/ctp/wake/level
chown system system /dev/i2c-5
on boot
mkdir /data/misc/wifi 0770 system wifi
mkdir /data/misc/wifi/sockets 0770 system wifi
......
......@@ -28,6 +28,11 @@
#include <cutils/atomic.h>
#include <cutils/log.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include "nusensors.h"
#include "lsm303dlh_acc.h"
#include "lsm303dlh_mag.h"
......@@ -122,6 +127,11 @@ LOGD("sensor activation called: handle=%d, enabled=%d***************************
int result = write(mWritePipeFd, &wakeMessage, 1);
LOGE_IF(result<0, "error sending wake message (%s)", strerror(errno));
}
/* TS power magic hack, ts power tracks that of accelerometer */
if (handle == ID_A)
touchscreen_power(enabled);
return err;
}
......@@ -184,6 +194,9 @@ static int poll__close(struct hw_device_t *dev)
if (ctx) {
delete ctx;
}
touchscreen_power(0);
return 0;
}
......@@ -205,6 +218,77 @@ static int poll__poll(struct sensors_poll_device_t *dev,
return ctx->pollEvents(data, count);
}
/** TS power stuff */
static int vdd_fd, xres_fd, wake_fd, i2c_fd;
void touchscreen_power(int enable)
{
struct i2c_rdwr_ioctl_data i2c_ioctl_data;
struct i2c_msg i2c_msg;
__u8 i2c_buf[16];
if (enable) {
lseek(vdd_fd, 0, SEEK_SET);
write(vdd_fd, "1", 1);
lseek(wake_fd, 0, SEEK_SET);
write(wake_fd, "1", 1);
lseek(xres_fd, 0, SEEK_SET);
write(xres_fd, "1", 1);
lseek(xres_fd, 0, SEEK_SET);
write(xres_fd, "0", 1);
usleep(50000);
lseek(wake_fd, 0, SEEK_SET);
write(wake_fd, "0", 1);
usleep(50000);
i2c_ioctl_data.nmsgs = 1;
i2c_ioctl_data.msgs = &i2c_msg;
i2c_msg.addr = 0x67;
i2c_msg.flags = 0;
i2c_msg.buf = i2c_buf;
i2c_msg.len = 2;
i2c_buf[0] = 0x08; i2c_buf[1] = 0;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_msg.len = 6;
i2c_buf[0] = 0x31; i2c_buf[1] = 0x01; i2c_buf[2] = 0x08;
i2c_buf[3] = 0x0C; i2c_buf[4] = 0x0D; i2c_buf[5] = 0x0A;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_msg.len = 2;
i2c_buf[0] = 0x30; i2c_buf[1] = 0x0F;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_buf[0] = 0x40; i2c_buf[1] = 0x02;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_buf[0] = 0x41; i2c_buf[1] = 0x10;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_buf[0] = 0x0A; i2c_buf[1] = 0x04;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_buf[0] = 0x08; i2c_buf[1] = 0x03;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
lseek(wake_fd, 0, SEEK_SET);
write(wake_fd, "1", 1);
} else {
lseek(vdd_fd, 0, SEEK_SET);
write(vdd_fd, "0", 1);
/* XXX, should be correllated with LIFTOFF_TIMEOUT in ts driver */
usleep(80000);
}
}
/*****************************************************************************/
int init_nusensors(hw_module_t const* module, hw_device_t** device)
......@@ -224,5 +308,15 @@ int init_nusensors(hw_module_t const* module, hw_device_t** device)
*device = &dev->device.common;
status = 0;
/* TS file descriptors. Ignore errors. */
vdd_fd = open("/sys/devices/platform/cy8ctma395/vdd", O_WRONLY);
LOGE_IF(vdd_fd < 0, "TScontrol: Cannot open vdd - %d", errno);
xres_fd = open("/sys/devices/platform/cy8ctma395/xres", O_WRONLY);
LOGE_IF(xres_fd < 0, "TScontrol: Cannot open xres - %d", errno);
wake_fd = open("/sys/user_hw/pins/ctp/wake/level", O_WRONLY);
LOGE_IF(wake_fd < 0, "TScontrol: Cannot open wake - %d", errno);
i2c_fd = open("/dev/i2c-5", O_RDWR);
LOGE_IF(i2c_fd < 0, "TScontrol: Cannot open i2c dev - %d", errno);
return status;
}
......@@ -32,6 +32,7 @@ __BEGIN_DECLS
/*****************************************************************************/
int init_nusensors(hw_module_t const* module, hw_device_t** device);
void touchscreen_power(int enable);
/*****************************************************************************/
......
......@@ -29,8 +29,6 @@
#include <linux/input.h>
#include <linux/uinput.h>
#include <linux/hsuart.h>
#include <linux/i2c.h>
#include <linux/i2c-dev.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/time.h>
......@@ -478,11 +476,8 @@ void open_uinput()
int main(int argc, char** argv)
{
struct hsuart_mode uart_mode;
struct i2c_rdwr_ioctl_data i2c_ioctl_data;
struct i2c_msg i2c_msg;
int uart_fd, vdd_fd, xres_fd, wake_fd, i2c_fd, nbytes, i;
int uart_fd, nbytes, i;
char recv_buf[RECV_BUF_SIZE];
char i2c_buf[16];
fd_set fdset;
struct timeval seltmout;
......@@ -499,67 +494,8 @@ int main(int argc, char** argv)
uart_mode.speed = 0x3D0900;
ioctl(uart_fd, HSUART_IOCTL_SET_UARTMODE,&uart_mode);
vdd_fd = open("/sys/devices/platform/cy8ctma395/vdd", O_WRONLY);
xres_fd = open("/sys/devices/platform/cy8ctma395/xres", O_WRONLY);
wake_fd = open("/sys/user_hw/pins/ctp/wake/level", O_WRONLY);
i2c_fd = open("/dev/i2c-5", O_RDWR);
lseek(vdd_fd, 0, SEEK_SET);
write(vdd_fd, "1", 1);
lseek(wake_fd, 0, SEEK_SET);
write(wake_fd, "1", 1);
lseek(xres_fd, 0, SEEK_SET);
write(xres_fd, "1", 1);
lseek(xres_fd, 0, SEEK_SET);
write(xres_fd, "0", 1);
usleep(50000);
ioctl(uart_fd, HSUART_IOCTL_FLUSH, 0x9);
lseek(wake_fd, 0, SEEK_SET);
write(wake_fd, "0", 1);
usleep(50000);
i2c_ioctl_data.nmsgs = 1;
i2c_ioctl_data.msgs = &i2c_msg;
i2c_msg.addr = 0x67;
i2c_msg.flags = 0;
i2c_msg.buf = i2c_buf;
i2c_msg.len = 2;
i2c_buf[0] = 0x08; i2c_buf[1] = 0;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_msg.len = 6;
i2c_buf[0] = 0x31; i2c_buf[1] = 0x01; i2c_buf[2] = 0x08;
i2c_buf[3] = 0x0C; i2c_buf[4] = 0x0D; i2c_buf[5] = 0x0A;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_msg.len = 2;
i2c_buf[0] = 0x30; i2c_buf[1] = 0x0F;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_buf[0] = 0x40; i2c_buf[1] = 0x02;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_buf[0] = 0x41; i2c_buf[1] = 0x10;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_buf[0] = 0x0A; i2c_buf[1] = 0x04;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
i2c_buf[0] = 0x08; i2c_buf[1] = 0x03;
ioctl(i2c_fd,I2C_RDWR,&i2c_ioctl_data);
lseek(wake_fd, 0, SEEK_SET);
write(wake_fd, "1", 1);
while(1)
{
// usleep(50000);
......@@ -590,6 +526,10 @@ int main(int argc, char** argv)
FD_ZERO(&fdset);
FD_SET(uart_fd, &fdset);
/* Flush uart - for the powermanagement stuff */
ioctl(uart_fd, HSUART_IOCTL_FLUSH, 0x9);
/* Now enter indefinite sleep iuntil input appears */
select(uart_fd+1, &fdset, NULL, NULL, NULL);
/* In case we were wrongly woken up check the event
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment