static void check_mem_data(struct i2c_client *client) { u8 read_buf[4] = {0}; msleep(30); gsl_ts_read(client,0xb0, read_buf, sizeof(read_buf)); if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a) { //printk("#########check mem read 0xb0 = %x %x %x %x #########\n", //read_buf[3], read_buf[2], read_buf[1], read_buf[0]); gsl_sw_init(client); } }
static irqreturn_t gsl_ts_irq(int irq, void *arg) { int rc; struct gsl_ts_data *ts = (struct gsl_ts_data *) arg; struct i2c_client *client = ts->client; struct device *dev = &client->dev; u8 status[4] = { 0, 0, 0, 0 }; u8 event[GSL_PACKET_SIZE]; dev_dbg(&client->dev, "%s: IRQ received\n", __func__); if (ts->state == GSL_TS_SHUTDOWN) { dev_warn(&client->dev, "%s: device supended, not handling interrupt\n", __func__); return IRQ_HANDLED; } rc = gsl_ts_read(client, GSL_STATUS_REG, status, sizeof(status)); if (rc < 0) { dev_err(dev, "%s: error reading chip status\n", __func__); return IRQ_HANDLED; } if (status[0] == GSL_STATUS_FW) { /* TODO: Send firmware here instead of during init */ dev_info(dev, "%s: device waiting for firmware\n", __func__); } else if (status[0] == GSL_STATUS_TOUCH) { dev_vdbg(dev, "%s: touch event\n", __func__); rc = gsl_ts_read(client, GSL_DATA_REG, event, sizeof(event)); if (rc < 0) { dev_err(dev, "%s: touch data read failed\n", __func__); return IRQ_HANDLED; } if (event[0] == 0xff) { dev_warn(dev, "%s: ignoring invalid touch record (0xff)\n", __func__); return IRQ_HANDLED; } rc = gsl_ts_read(client, GSL_TOUCH_STATUS_REG, status, sizeof(status)); if (rc < 0) { dev_err(dev, "%s: reading touch status register failed\n", __func__); return IRQ_HANDLED; } if ((status[0] | status[1] | status[2] | status[3]) == 0) { gsl_ts_mt_event(ts, event); } else { dev_warn(dev, "%s: device seems to be stuck, resetting\n", __func__); rc = gsl_ts_reset_chip(ts->client); if (rc < 0) { dev_err(dev, "%s: reset_chip failed\n", __func__); return IRQ_HANDLED; } rc = gsl_ts_startup_chip(ts->client); if (rc < 0) { dev_err(dev, "%s: startup_chip failed\n", __func__); return IRQ_HANDLED; } } } else { dev_warn(&client->dev, "%s: IRQ received, unknown status 0x%02x\n", __func__, status[0]); } return IRQ_HANDLED; }
void read_coords(struct i2c_client *cliente) { u8 buffer[10]; int retval; static enum read_status cstatus=RS_idle; static int old_x=0; static int old_y=0; static int old_dist=0; static int old_startx=0; static int old_starty=0; static char old_touches=0; static time_t old_time=0; static suseconds_t old_ms=0; struct timeval now; int x1=0; int y1=0; int x2=0; int y2=0; int xm=0; int ym=0; int dist=0; int time_passed=0; retval=gsl_ts_read(cliente, GSL_DATA_REG, buffer, 1); if (retval<=0) { printf("error reading number of touches: %d\n",retval); return; } gettimeofday(&now,NULL); u8 touches=buffer[0]<=3 ? buffer[0] : 3; if (touches==0) { old_time = now.tv_sec; old_ms = now.tv_usec/1000; old_touches=0; } else { time_passed=(int)(((1000*now.tv_sec)+(now.tv_usec/1000))-((old_time*1000)+old_ms)); retval=gsl_ts_read(cliente,0x84,buffer,4); x1=(((unsigned int)buffer[0])+256*((unsigned int)buffer[1]))&0x0FFF; y1=(((unsigned int)buffer[2])+256*((unsigned int)buffer[3]))&0x0FFF; if (old_touches==0) { old_startx=x1; old_starty=y1; old_x=xm; old_y=ym; old_touches=touches; } if (cliente->invert_x) { x1=cliente->resx-x1-1; } if (cliente->invert_y) { y1=cliente->resy-y1-1; } if (touches>1) { retval=gsl_ts_read(cliente,0x88,buffer,4); x2=(((unsigned int)buffer[0])+256*((unsigned int)buffer[1]))&0x0FFF; y2=(((unsigned int)buffer[2])+256*((unsigned int)buffer[3]))&0x0FFF; if (cliente->invert_x) { x2=cliente->resx-x2-1; } if (cliente->invert_y) { y2=cliente->resy-y2-1; } xm=(x1+x2)/2; ym=(y1+y2)/2; int xt,yt; xt = (x1>x2) ? x1-x2 : x2-x1; yt = (y1>y2) ? y1-y2 : y2-y1; dist=xt*xt+yt*yt; } else { x2=x1; y2=y1; xm=x1; ym=y1; dist=0; } } switch(cstatus) { case RS_idle: if (touches==1) { old_x=x1; old_y=y1; move_to(cliente,old_x,old_y); cstatus=RS_one_A; return; } if (touches==2) { old_x=xm; old_y=ym; old_dist=dist; move_to(cliente,old_x,old_y); cstatus=RS_two_A; return; } if (touches==3) { cstatus=RS_three_A; menu_ctrl(cliente); return; } break; case RS_one_A: if (touches==3) { cstatus=RS_three_A; menu_ctrl(cliente); return; } if (touches==2) { old_x=xm; old_y=ym; old_dist=dist; move_to(cliente,old_x,old_y); cstatus=RS_two_A; return; } if (touches==0) { move_to(cliente,old_x,old_y); click(cliente,1); click(cliente,0); cstatus=RS_idle; return; } if (touches==1) { if (cliente->new_scroll) { int d; d=(old_x-xm)/X_THRESHOLD; if (d!=0) { scrollh(cliente,d); old_x=xm; cstatus=RS_one_B; } d=(ym-old_y)/Y_THRESHOLD; if (d!=0) { scroll(cliente,d); old_y=ym; cstatus=RS_one_B; } if ((cstatus==RS_one_A)&&(time_passed>1000)) { move_to(cliente,old_x+SINGLE_CLICK_OFFSET,old_y+SINGLE_CLICK_OFFSET); click(cliente,1); old_x=x1; old_y=x2; cstatus=RS_one_C; } } else { if ((old_x!=x1)||(old_y!=y1)) { move_to(cliente,old_x,old_y); click(cliente,1); old_x=x1; old_y=x2; cstatus=RS_one_B; } } return; } break; case RS_one_B: if (touches==1) { if ((old_x!=x1)||(old_y!=y1)) { if (cliente->new_scroll) { int d; d=(old_x-xm)/X_THRESHOLD; if (d!=0) { scrollh(cliente,d); old_x=xm; } d=(ym-old_y)/Y_THRESHOLD; if (d!=0) { scroll(cliente,d); old_y=ym; } } else { move_to(cliente,old_x,old_y); old_x=x1; old_y=y1; } } return; } if (touches==0) { click(cliente,0); cstatus=RS_idle; return; } break; case RS_one_C: if (touches==1) { move_to(cliente,old_x+SINGLE_CLICK_OFFSET,old_y+SINGLE_CLICK_OFFSET); old_x=x1; old_y=y1; return; } if (touches==0) { click(cliente,0); cstatus=RS_idle; return; } break; case RS_two_A: if (touches==3) { cstatus=RS_three_A; menu_ctrl(cliente); return; } if (touches==1) { old_x=x1; old_y=y1; move_to(cliente,old_x,old_y); cstatus=RS_right_A; return; } case RS_two_B: if (touches==2) { int d; if (!cliente->new_scroll) { d=(old_x-xm)/X_THRESHOLD; if (d!=0) { cstatus=RS_two_B; scrollh(cliente,d); old_x=xm; } d=(ym-old_y)/Y_THRESHOLD; if (d!=0) { cstatus=RS_two_B; scroll(cliente,d); old_y=ym; } } d=(dist-old_dist)/Z_THRESHOLD; if (d!=0) { if (d>0) { zoom(cliente,(int)(sqrt(d))); } else { zoom(cliente,-((int)(sqrt(-d)))); } old_dist=dist; cstatus=RS_two_B; } } if (touches==0) { cstatus=RS_idle; } break; case RS_right_A: if (touches==0) { cstatus=RS_idle; return; } if ((x1!=old_x)||(y1!=old_y)) { old_x=x1; old_y=y1; move_to(cliente,old_x,old_y); } if (touches==2) { click_r(cliente,1); cstatus=RS_right_B; return; } break; case RS_right_B: if (touches==0) { cstatus=RS_idle; return; } if ((x1!=old_x)||(y1!=old_y)) { old_x=x1; old_y=y1; move_to(cliente,old_x,old_y); } if (touches==1) { click_r(cliente,0); cstatus=RS_right_A; return; } break; case RS_three_A: if (touches==0) { cstatus=RS_idle; return; } break; } }