Esempio n. 1
0
/*******************************************************
Function:
    i2c read twice, compare the results
Input:
    client:  i2c device
    addr:    operate address
    rxbuf:   read data to store, if compare successful
    len:     bytes to read
Output:
    FAIL:    read failed
    SUCCESS: read successful
*********************************************************/
s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len)
{
    u8 buf[16] = {0};
    u8 confirm_buf[16] = {0};
    u8 retry = 0;

    while (retry++ < 3)
    {
        memset(buf, 0xAA, 16);
        buf[0] = (u8)(addr >> 8);
        buf[1] = (u8)(addr & 0xFF);
        gtp_i2c_read(client, buf, len + 2);

        memset(confirm_buf, 0xAB, 16);
        confirm_buf[0] = (u8)(addr >> 8);
        confirm_buf[1] = (u8)(addr & 0xFF);
        gtp_i2c_read(client, confirm_buf, len + 2);

        if (!memcmp(buf, confirm_buf, len+2))
        {
            break;
        }
    }
    if (retry < 3)
    {
        memcpy(rxbuf, confirm_buf+2, len);
        return SUCCESS;
    }
    else
    {
        GTP_ERROR("i2c read 0x%04X, %d bytes, double check failed!", addr, len);
        return FAIL;
    }
}
Esempio n. 2
0
static s32 tool_i2c_read_no_extra(u8 *buf, u16 len)
{
    s32 ret = -1;

    ret = gtp_i2c_read(gt_client, buf, len + GTP_ADDR_LENGTH);
    return ret;
}
static s32 tool_i2c_read_no_extra(u8* buf, u16 len)
{
   s32 ret = -1;
  /*   s32 i = 0;
    struct i2c_msg msgs[2];
    
    msgs[0].flags = !I2C_M_RD;
    msgs[0].addr  = gt_client->addr;
    msgs[0].len   = cmd_head.addr_len;
    msgs[0].buf   = &buf[0];
    
    msgs[1].flags = I2C_M_RD;
    msgs[1].addr  = gt_client->addr;
    msgs[1].len   = len;
    msgs[1].buf   = &buf[GTP_ADDR_LENGTH];

    for (i = 0; i < cmd_head.retry; i++)
    {
        ret=i2c_transfer(gt_client->adapter, msgs, 2);
        if (ret > 0)
        {
            break;
        }
    }
    return ret;
	*/


   ret = gtp_i2c_read(gt_client,buf,len + GTP_ADDR_LENGTH);
   return ret;
}
Esempio n. 4
0
static ssize_t show_tpd_vendor_version(struct device *dev,struct device_attribute *attr, char *buf)
{
  if(true){
    return 0;
  }else{
	#define GTP_REG_FW_VERSION	0x8144
	u8 rd_buf[4] = {GTP_REG_FW_VERSION>>8, GTP_REG_FW_VERSION&0xff};
	int ret;
	ret = gtp_i2c_read(i2c_client_point, rd_buf, sizeof(rd_buf));
	if (ret < 0) 
	{
		GTP_ERROR("[FW] error\n");
		return 0;
	}
	GTP_DEBUG("[FW] FM version = 0x%x\n", rd_buf[3]<<8 | rd_buf[2]&0xff);
    return sprintf(buf, "%x", rd_buf[3]<<8 | rd_buf[2]&0xff);
  }
}
static DEVICE_ATTR(tpd_vendor_version, S_IRUGO, show_tpd_vendor_version, NULL);

static struct device_attribute *gt9xx_attrs[] =
{
	&dev_attr_tpd_refresh_rate,
	&dev_attr_tpd_read_reg,
	&dev_attr_tpd_device_name,
	&dev_attr_tpd_vendor_name,
	&dev_attr_tpd_vendor_version,
};
//=============================================================

static int tpd_i2c_detect(struct i2c_client *client, struct i2c_board_info *info)
{
    strcpy(info->type, "mtk-tpd");
    return 0;
}
Esempio n. 5
0
static ssize_t show_tpd_vendor_name(struct device *dev,struct device_attribute *attr, char *buf)
{
	u8 rd_vendor_buf[16];
        s32 ret = -1;
        rd_vendor_buf[0] = GTP_REG_SENSOR_ID >> 8;
        rd_vendor_buf[1] = GTP_REG_SENSOR_ID & 0xff;
        ret = gtp_i2c_read(i2c_client_point, rd_vendor_buf, 3);

        if (ret < 0)
        {
            GTP_ERROR("gt9xx Read SENSOR ID failed");
            rd_vendor_buf[GTP_ADDR_LENGTH] = 3;
            return sprintf(buf, "%s", tpd_manufacturer_name[rd_vendor_buf[GTP_ADDR_LENGTH]]);
        }

        GTP_INFO("gt9xx vendor ID:%d", rd_vendor_buf[GTP_ADDR_LENGTH]);
        rd_vendor_buf[GTP_ADDR_LENGTH] &= 0x03;
    	
    	return sprintf(buf, "%s", tpd_manufacturer_name[rd_vendor_buf[GTP_ADDR_LENGTH]]);
}
Esempio n. 6
0
static ssize_t show_read_reg(struct device *dev,struct device_attribute *attr, char *buf)
{
	int ret, cnt, i;
	
	u8 i2c_buf[GTP_ADDR_LENGTH+100] = {g_attr_read_reg>>8, g_attr_read_reg& 0xff};

	if (g_attr_read_reg == 0xFFFF || g_attr_read_nbytes == 0)
	{
		return sprintf(buf, "0x%x,%d??\n"ATTR_READ_REAG_HINT, g_attr_read_reg, g_attr_read_nbytes);
	}

	ret = gtp_i2c_read(i2c_client_point, i2c_buf, g_attr_read_nbytes+GTP_ADDR_LENGTH);
	if (ret < 0) 
	{
		return sprintf(buf, "read failed\n"ATTR_READ_REAG_HINT);
	}

	cnt = sprintf(buf, "BASE:0x%x, bytes=%d\n", (i2c_buf[0]<<8 | i2c_buf[1]), g_attr_read_nbytes);
	for (i = 0; i< g_attr_read_nbytes; i++)
	{
		cnt += sprintf(buf+cnt, "0x%02x,", i2c_buf[GTP_ADDR_LENGTH+i]);
		if ((i+1)%10 == 0)	cnt += sprintf(buf+cnt, "\n");
	}
	cnt += sprintf(buf+cnt, "\n");

	g_attr_read_reg = 0xFFFF;
	g_attr_read_nbytes = 0;

	return cnt;
}

static ssize_t store_read_reg(struct device *dev,struct device_attribute *attr, const char *buf, size_t size)
{
	char *p;
	
	g_attr_read_reg = (u16)simple_strtol(buf, &p, 16);
	g_attr_read_nbytes = simple_strtol(p+1, NULL, 10);

	GTP_INFO("0x%x, %d", g_attr_read_reg, g_attr_read_nbytes);
	return size;
}
Esempio n. 7
0
            GTP_ERROR("proxmy sensor operate function no this parameter %d!\n", command);
            err = -1;
            break;
    }

    return err;
}
#endif

void tpd_getfw_info()
{
	#define GTP_REG_FW_VERSION	0x8144
	u8 buf[4] = {GTP_REG_FW_VERSION>>8, GTP_REG_FW_VERSION&0xff};
	int ret;

	ret = gtp_i2c_read(i2c_client_point, buf, sizeof(buf));
	if (ret < 0) 
	{
		GTP_ERROR("[FW] error\n");
		return;
	}

	GTP_DEBUG("[FW] FM version = 0x%x\n", buf[3]<<8 | buf[2]&0xff);

}

static int gt91xx_config_read_proc(char *page, char **start, off_t off, int count, int *eof, void *data)
{
    char *ptr = page;
    char temp_data[GTP_CONFIG_MAX_LENGTH + 2] = {0};
    int i;
Esempio n. 8
0
/*******************************************************
Function:
	Read goodix touchscreen version function.

Input:
	client:	i2c client struct.
	
Output:
	Executive outcomes.0---succeed.
*******************************************************/
s32 gtp_read_version(struct goodix_ts_data *ts)
{
        s32 ret = -1;
        s32 count = 0;
        u8 version_data[6] = {(u8)(GTP_REG_VERSION>>8), (u8)GTP_REG_VERSION, 0, 0, 0, 0};
        u8 version_comfirm[6] = {(u8)(GTP_REG_VERSION>>8), (u8)GTP_REG_VERSION, 0, 0, 0, 0};
	

        ret = gtp_i2c_read(ts->client,version_data, 6);
        if (ret <= 0)
        {
                GTP_ERROR("GTP read version failed"); 
                return ret;
        }
        dprintk(DEBUG_INIT, "Read version:%02x%02x", version_data[4], version_data[5]);
    
        while(count++ < 10)
        {
                gtp_i2c_read(ts->client, version_comfirm, 6);
                if((version_data[4] !=version_comfirm[4])||(version_data[5] != version_comfirm[5]))
                {
                        dprintk(DEBUG_INIT, "Comfirm version:%02x%02x", version_comfirm[4], version_comfirm[5]);
                        version_data[4] = version_comfirm[4];
                        version_data[5] = version_comfirm[5];
                        break;
                }
                msleep(5);
        }
        if(count == 11)
        {
                dprintk(DEBUG_INIT, "GTP chip version:%02x%02x_%02x%02x", version_data[3], version_data[2], version_data[4], version_data[5]);
                ts->version = (version_data[4]<<8)+version_data[5];
                ret = 0;
        }
        else
        {
                printk("GTP read version confirm error!");
                ret = 1;
        }
        return ret;
}

/*******************************************************
Function:
	Touch down report function.

Input:
	ts:private data.
	id:tracking id.
	x:input x.
	y:input y.
	w:input weight.
	
Output:
	None.
*******************************************************/
static void gtp_touch_down(struct goodix_ts_data* ts, s32 id, s32 x, s32 y, s32 w)
{
        dprintk(DEBUG_X_Y_INFO, "source data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);
        
        if(1 == exchange_x_y_flag){
                swap(x, y);
        }
        
        if(1 == revert_x_flag){
                x = ts->abs_x_max - x;
        }
        
        if(1 == revert_y_flag){
                y = ts->abs_y_max - y;
        }
        
        dprintk(DEBUG_X_Y_INFO,"report data:ID:%d, X:%d, Y:%d, W:%d\n", id, x, y, w);


        input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
        input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);			
        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w);
        input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w);
        input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
        input_mt_sync(ts->input_dev);

}

/*******************************************************
Function:
	Touch up report function.

Input:
	ts:private data.
	
Output:
	None.
*******************************************************/
static void gtp_touch_up(struct goodix_ts_data* ts)
{
        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
        input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
        input_mt_sync(ts->input_dev);
}
Esempio n. 9
0
        u8  point_index = 0;
        u8  point_tmp = 0;
        u8  touch_num = 0;
        u8  input_w = 0;
        u16 input_x = 0;
        u16 input_y = 0;
        u32 count = 0;
        u32 position = 0;	
        s32 ret = -1;

        struct goodix_ts_data *ts;
    
        GTP_DEBUG_FUNC();

        ts = container_of(work, struct goodix_ts_data, work);
        ret = gtp_i2c_read(ts->client, point_data, sizeof(point_data)/sizeof(point_data[0]));
        if (ret <= 0) 
        {
                goto exit_work_func;  
        }
        GTP_DEBUG_ARRAY(point_data, sizeof(point_data)/sizeof(point_data[0]));
        if(point_data[GTP_ADDR_LENGTH]&0x20)
        {
                if(point_data[3]==0xF0)
                {
                        GTP_DEBUG("Reload config!");
                        ret = gtp_send_cfg(ts->client);
                        if (ret)
                       {
                                GTP_ERROR("Send config error.");
                        }
Esempio n. 10
0
/*******************************************************
Function:
	GTP initialize function.

Input:
	ts:	i2c client private struct.
	
Output:
	Executive outcomes.0---succeed.
*******************************************************/
s32 gtp_init_panel(struct goodix_ts_data *ts)
{
        s32 ret = -1;
        u8 rd_cfg_buf[4];
        int index = -1;
        
        u8 cfg_info_group1[] = CTP_CFG_GROUP_DPT1;//dpt yiju
	u8 cfg_info_group2[] = CTP_CFG_GROUP;

	u8 * send_cfg_buf[2] = {cfg_info_group1,cfg_info_group2};
	
#if 0
        u8 cfg_info_group1[] = CTP_CFG_GROUP1;
        u8 cfg_info_group2[] = CTP_CFG_GROUP2;
        u8 cfg_info_group3[] = CTP_CFG_GROUP3;
        u8 * send_cfg_buf[3] = {cfg_info_group1, cfg_info_group2, cfg_info_group3};
        u8 cfg_info_len[3] = {sizeof(cfg_info_group1)/sizeof(cfg_info_group1[0]), 
                              sizeof(cfg_info_group2)/sizeof(cfg_info_group2[0]),
                              sizeof(cfg_info_group3)/sizeof(cfg_info_group3[0])};
        GTP_DEBUG("len1=%d,len2=%d,len3=%d",cfg_info_len[0],cfg_info_len[1],cfg_info_len[2]);
        if ((!cfg_info_len[1])&&(!cfg_info_len[2]))
        {	
                rd_cfg_buf[GTP_ADDR_LENGTH] = 0; 
        }
        else
        {   
                rd_cfg_buf[0] = (u8)(GTP_REG_SENSOR_ID>>8);
                rd_cfg_buf[1] = (u8)GTP_REG_SENSOR_ID;
                ret=gtp_i2c_read(ts->client, rd_cfg_buf, 3);
                if (ret <= 0)
                {
                        GTP_ERROR("Read SENSOR ID failed,default use group1 config!");
                        rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
                }
                rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x03;
        }
        GTP_DEBUG("SENSOR ID:%d", rd_cfg_buf[GTP_ADDR_LENGTH]);
        memcpy(config, send_cfg_buf[rd_cfg_buf[GTP_ADDR_LENGTH]], (GTP_CONFIG_LENGTH+GTP_ADDR_LENGTH));
#endif
        rd_cfg_buf[0] = (u8)(GTP_REG_SENSOR_ID>>8);
        rd_cfg_buf[1] = (u8)GTP_REG_SENSOR_ID;
        ret=gtp_i2c_read(ts->client, rd_cfg_buf, 3);
        if (ret <= 0)
        {
            printk("Read SENSOR ID failed,default use group1 config!");
            rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
        }
        rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x03;
	dprintk(DEBUG_INIT, "sensor ID =%d\n\n",rd_cfg_buf[GTP_ADDR_LENGTH]);

	index = 0;
	
	

	if(rd_cfg_buf[GTP_ADDR_LENGTH] == 2)
		index = 6;
	index = 0;//gandy

	memcpy(config, send_cfg_buf[index], sizeof(cfg_info_group1));

#if GTP_CUSTOM_CFG
        config[57] &= 0xf7;
        if(GTP_INT_TRIGGER&0x01)
        {
                config[57] += 0x08; 
        }
        config[59] = GTP_REFRESH;
        config[60] = GTP_MAX_TOUCH>5 ? 5 : GTP_MAX_TOUCH;
        config[61] = (u8)SCREEN_MAX_WIDTH;
        config[62] = (u8)(SCREEN_MAX_WIDTH >> 8);
        config[63] = (u8)SCREEN_MAX_X;
        config[64] = (u8)(SCREEN_MAX_Y >> 8);
#endif
        ts->abs_x_max = (config[62]<<8) + config[61];
        ts->abs_y_max = (config[64]<<8) + config[63];
        ts->max_touch_num = config[60];
        ts->int_trigger_type = ((config[57]>>3)&0x01);
        if ((!ts->abs_x_max)||(!ts->abs_y_max)||(!ts->max_touch_num))
        {
                GTP_ERROR("GTP resolution & max_touch_num invalid, use default value!");
                ts->abs_x_max = SCREEN_MAX_X;
                ts->abs_y_max = SCREEN_MAX_Y;
                ts->max_touch_num = GTP_MAX_TOUCH;
        }
    
        ret = gtp_send_cfg(ts->client);
        if (ret)
        {
                printk("Send config error.");
        }

        msleep(10);
        return 0;
}
static void goodix_ts_work_func(struct work_struct *work)
{
	struct goodix_ts_data *ts = NULL;
	static u16 pre_touch;
	static u8 pre_key;
	u8 end_cmd[3] = {
		GTP_READ_COOR_ADDR >> 8,
		GTP_READ_COOR_ADDR & 0xFF,
		0
	};
	u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1] = {
		GTP_READ_COOR_ADDR >> 8,
		GTP_READ_COOR_ADDR & 0xFF
	};
	u8 touch_num = 0;
	u8 finger = 0;
	u8 key_value = 0;
	u8 *coor_data = NULL;
	s32 input_x = 0;
	s32 input_y = 0;
	s32 input_w = 0;
	s32 id = 0;
	s32 i, ret;

	GTP_DEBUG_FUNC();

	ts = container_of(work, struct goodix_ts_data, work);
	if (ts->enter_update)
		return;

	ret = gtp_i2c_read(ts->client, point_data, 12);
	if (ret < 0) {
		GTP_ERROR("I2C transfer error. errno:%d\n ", ret);
		goto exit_work_func;
	}

	finger = point_data[GTP_ADDR_LENGTH];
	if ((finger & 0x80) == 0)
		goto exit_work_func;

	touch_num = finger & 0x0f;
	if (touch_num > GTP_MAX_TOUCH)
		goto exit_work_func;

	if (touch_num > 1) {
		u8 buf[8 * GTP_MAX_TOUCH] = {
			(GTP_READ_COOR_ADDR + 10) >> 8,
			(GTP_READ_COOR_ADDR + 10) & 0xff
		};
		ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1));
		memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1));
	}

#if GTP_HAVE_TOUCH_KEY
	key_value = point_data[3 + 8 * touch_num];
	if (key_value || pre_key) {
		for (i = 0; i < GTP_MAX_KEY_NUM; i++)
			input_report_key(ts->input_dev, touch_key_array[i],
						key_value & (0x01 << i));

		touch_num = 0;
		pre_touch = 0;
	}
#endif
	pre_key = key_value;

	GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger);

#if GTP_ICS_SLOT_REPORT
	if (pre_touch || touch_num) {
		s32 pos = 0;
		u16 touch_index = 0;

		coor_data = &point_data[3];
		if (touch_num) {
			id = coor_data[pos] & 0x0F;
			touch_index |= (0x01 << id);
		}

		GTP_DEBUG("id=%d, touch_index=0x%x, pre_touch=0x%x\n",\
					id, touch_index, pre_touch);
		for (i = 0; i < GTP_MAX_TOUCH; i++) {
			if (touch_index & (0x01<<i)) {
				input_x = coor_data[pos + 1]
						| coor_data[pos + 2] << 8;
				input_y = coor_data[pos + 3]
						| coor_data[pos + 4] << 8;
				input_w = coor_data[pos + 5]
						| coor_data[pos + 6] << 8;
				gtp_touch_down(ts, id, input_x, input_y,
								input_w);
				pre_touch |= 0x01 << i;
				pos += 8;
				id = coor_data[pos] & 0x0F;
				touch_index |= (0x01<<id);
			} else {
				gtp_touch_up(ts, i);
				pre_touch &= ~(0x01 << i);
			}
		}
	}
#else
	if (touch_num) {
		for (i = 0; i < touch_num; i++) {
			coor_data = &point_data[i * 8 + 3];
			id = coor_data[0] & 0x0F;
			input_x = coor_data[1] | coor_data[2] << 8;
			input_y = coor_data[3] | coor_data[4] << 8;
			input_w = coor_data[5] | coor_data[6] << 8;
			gtp_touch_down(ts, id, input_x, input_y, input_w);
		}
	} else if (pre_touch) {
		GTP_DEBUG("Touch Release!");
		gtp_touch_up(ts, 0);
	}

	pre_touch = touch_num;
	input_report_key(ts->input_dev, BTN_TOUCH, (touch_num || key_value));
#endif
	input_sync(ts->input_dev);
exit_work_func:
	if (!ts->gtp_rawdiff_mode) {
		ret = gtp_i2c_write(ts->client, end_cmd, 3);
		if (ret < 0)
			GTP_ERROR("I2C write end_cmd error!");
	}

	if (ts->use_irq)
		gtp_irq_enable(ts);
}

static enum hrtimer_restart goodix_ts_timer_handler(struct hrtimer *timer)
{
	struct goodix_ts_data *ts =
			container_of(timer, struct goodix_ts_data, timer);

	GTP_DEBUG_FUNC();

	queue_work(goodix_wq, &ts->work);
	hrtimer_start(&ts->timer, ktime_set(0, (GTP_POLL_TIME + 6) * 1000000),
						HRTIMER_MODE_REL);
	return HRTIMER_NORESTART;
}

static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)
{
	struct goodix_ts_data *ts = dev_id;

	GTP_DEBUG_FUNC();

	gtp_irq_disable(ts);
	queue_work(goodix_wq, &ts->work);

	return IRQ_HANDLED;
}

static void gtp_int_sync(struct i2c_client *client, s32 ms)
{
	struct gtp_platform_data *gtp_data = client->dev.platform_data;

	GTP_GPIO_OUTPUT(gtp_data->irq, 0);
	GTP_MSLEEP(ms);
	GTP_GPIO_AS_INT(gtp_data->irq);
}

void gtp_reset_guitar(struct i2c_client *client, s32 ms)
{
	struct gtp_platform_data *gtp_data = client->dev.platform_data;

	GTP_DEBUG_FUNC();

	/* begin select I2C slave addr */
	GTP_GPIO_OUTPUT(gtp_data->reset, 0);
	GTP_MSLEEP(ms);
	GTP_GPIO_OUTPUT(gtp_data->irq, client->addr == 0x14);

	GTP_MSLEEP(2);
	GTP_GPIO_OUTPUT(gtp_data->reset, 1);

	/* must > 3ms */
	GTP_MSLEEP(6);
	GTP_GPIO_AS_INPUT(gtp_data->reset);
	/* end select I2C slave addr */

	gtp_int_sync(client, 50);
}

static s32 gtp_init_panel(struct goodix_ts_data *ts)
{
	s32 ret;

#if GTP_DRIVER_SEND_CFG
	s32 i;
	u8 check_sum = 0;
	u8 rd_cfg_buf[16];

	u8 cfg_info_group1[] = CTP_CFG_GROUP1;
	u8 cfg_info_group2[] = CTP_CFG_GROUP2;
	u8 cfg_info_group3[] = CTP_CFG_GROUP3;
	u8 *send_cfg_buf[3] = {
		cfg_info_group1,
		cfg_info_group2,
		cfg_info_group3
	};
	u8 cfg_info_len[3] = {
		sizeof(cfg_info_group1) / sizeof(cfg_info_group1[0]),
		sizeof(cfg_info_group2) / sizeof(cfg_info_group2[0]),
		sizeof(cfg_info_group3) / sizeof(cfg_info_group3[0])
	};

	for (i = 0; i < 3; i++) {
		if (cfg_info_len[i] > ts->gtp_cfg_len)
			ts->gtp_cfg_len = cfg_info_len[i];
	}
	GTP_DEBUG("len1=%d, len2=%d, len3=%d, send_len:%d", cfg_info_len[0], \
			cfg_info_len[1], cfg_info_len[2], ts->gtp_cfg_len);

	if ((!cfg_info_len[1]) && (!cfg_info_len[2]))
		rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
	else {
		rd_cfg_buf[0] = GTP_REG_SENSOR_ID >> 8;
		rd_cfg_buf[1] = GTP_REG_SENSOR_ID & 0xff;
		ret = gtp_i2c_read(ts->client, rd_cfg_buf, 3);
		if (ret < 0) {
			GTP_ERROR("Read SENSOR ID failed, " \
				"default use group1 config!");
			rd_cfg_buf[GTP_ADDR_LENGTH] = 0;
		}
		rd_cfg_buf[GTP_ADDR_LENGTH] &= 0x07;
	}
	GTP_DEBUG("SENSOR ID:%d", rd_cfg_buf[GTP_ADDR_LENGTH]);

	memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);
	memcpy(&config[GTP_ADDR_LENGTH],
		send_cfg_buf[rd_cfg_buf[GTP_ADDR_LENGTH]], ts->gtp_cfg_len);

#if GTP_CUSTOM_CFG
	config[RESOLUTION_LOC] = (u8)ts->data->gtp_max_width;
	config[RESOLUTION_LOC + 1] = (u8)(ts->data->gtp_max_width>>8);
	config[RESOLUTION_LOC + 2] = (u8)ts->data->gtp_max_height;
	config[RESOLUTION_LOC + 3] = (u8)(ts->data->gtp_max_height>>8);

	if (GTP_INT_TRIGGER == 0)
		/* RISING */
		config[TRIGGER_LOC] &= 0xfe;
	else if (GTP_INT_TRIGGER == 1)
		/* FALLING */
		config[TRIGGER_LOC] |= 0x01;
#endif
	check_sum = 0;
	for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)
		check_sum += config[i];
	config[ts->gtp_cfg_len] = (~check_sum) + 1;
#else
	if (ts->gtp_cfg_len == 0)
		ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;

	ret = gtp_i2c_read(ts->client, config,
			ts->gtp_cfg_len + GTP_ADDR_LENGTH);
	if (ret < 0) {
		GTP_ERROR("GTP read resolution & max_touch_num failed, " \
				"use default value!");
		ts->abs_x_max = ts->data->gtp_max_width;
		ts->abs_y_max = ts->data->gtp_max_height;
		ts->int_trigger_type = GTP_INT_TRIGGER;
		return ret;
	}
#endif
	GTP_DEBUG_FUNC();

	ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8)
						+ config[RESOLUTION_LOC];
	ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8)
						+ config[RESOLUTION_LOC + 2];
	ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03;
	if ((!ts->abs_x_max) || (!ts->abs_y_max)) {
		GTP_ERROR("GTP resolution & max_touch_num invalid, " \
				"use default value!");
		ts->abs_x_max = ts->data->gtp_max_width;
		ts->abs_y_max = ts->data->gtp_max_height;
	}

	/* MUST delay >20ms before send cfg */
	GTP_MSLEEP(20);

	ret = gtp_send_cfg(ts->client);
	if (ret < 0) {
		GTP_ERROR("Send config error.");
		return ret;
	}

	GTP_DEBUG("X_MAX = %d,Y_MAX = %d,TRIGGER = 0x%02x",
			ts->abs_x_max, ts->abs_y_max, ts->int_trigger_type);
	GTP_MSLEEP(10);

	return 0;
}
	GTP_MSLEEP(10);

	return 0;
}

static s32 gtp_read_version(struct i2c_client *client, u16 *version)
{
	u8 buf[8] = {
		GTP_REG_VERSION >> 8,
		GTP_REG_VERSION & 0xff
	};
	s32 i, ret;

	GTP_DEBUG_FUNC();

	ret = gtp_i2c_read(client, buf, sizeof(buf));
	if (ret < 0) {
		GTP_ERROR("GTP read version failed");
		return ret;
	}

	if (version)
		*version = (buf[7] << 8) | buf[6];

	for (i = 2; i < 6; i++) {
		if (!buf[i])
			buf[i] = 0x30;
	}
	GTP_DEBUG("IC VERSION:%c%c%c%c_%02x%02x",
			buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);
	return ret;
Esempio n. 13
0
/**
 * ctp_detect - Device detection callback for automatic device creation
 * return value:  
 *                    = 0; success;
 *                    < 0; err
 */
static int ctp_detect(struct i2c_client *client, struct i2c_board_info *info)
{
	struct i2c_adapter *adapter = client->adapter;
    int ret;  
    u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff};
        if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)){
        	pr_err("i2c_check_functionality err\n======return=====\n");
                return -ENODEV;
        }


        if(twi_id == adapter->nr){
                pr_debug("%s: addr= %x\n",__func__,client->addr);
                msleep(50);
    			ret = gtp_i2c_read(client, buf, 6);
    			gtp_i2c_end_cmd(client);
				if(buf[3] != 0x18)
				{
					pr_debug("%s:IC is not gt818\n",__func__);
					return -ENODEV;
				}
    			GTP_INFO("IC VERSION:%02x%02x_%02x%02x", buf[3], buf[2], buf[5], buf[4]);
            	strlcpy(info->type, CTP_NAME, I2C_NAME_SIZE);
        	//printk("%s:I2C connection might be something wrong ! \n",__func__);
        	return 0;
	}else{
	        return -ENODEV;
	}
}

/**
 * ctp_print_info - sysconfig print function
 * return value:
 *
 */
static void ctp_print_info(struct ctp_config_info info,int debug_level)
{
	if(debug_level == DEBUG_INIT)
	{
		dprintk(DEBUG_INIT,"info.ctp_used:%d\n",info.ctp_used);
		dprintk(DEBUG_INIT,"info.twi_id:%d\n",info.twi_id);
		dprintk(DEBUG_INIT,"info.screen_max_x:%d\n",info.screen_max_x);
		dprintk(DEBUG_INIT,"info.screen_max_y:%d\n",info.screen_max_y);
		dprintk(DEBUG_INIT,"info.revert_x_flag:%d\n",info.revert_x_flag);
		dprintk(DEBUG_INIT,"info.revert_y_flag:%d\n",info.revert_y_flag);
		dprintk(DEBUG_INIT,"info.exchange_x_y_flag:%d\n",info.exchange_x_y_flag);
		dprintk(DEBUG_INIT,"info.irq_gpio_number:%d\n",info.irq_gpio.gpio);
		dprintk(DEBUG_INIT,"info.wakeup_gpio_number:%d\n",info.wakeup_gpio.gpio);
	}
}

/**
 * ctp_wakeup - function
 *
 */
static int ctp_wakeup(int status,int ms)
{
	dprintk(DEBUG_INIT,"***CTP*** %s:status:%d,ms = %d\n",__func__,status,ms);

	if (status == 0) {

		if(ms == 0) {
			__gpio_set_value(config_info.wakeup_gpio.gpio, 0);
		}else {
			__gpio_set_value(config_info.wakeup_gpio.gpio, 0);
			msleep(ms);
			__gpio_set_value(config_info.wakeup_gpio.gpio, 1);
		}
	}
	if (status == 1) {
		if(ms == 0) {
			__gpio_set_value(config_info.wakeup_gpio.gpio, 1);
		}else {
			__gpio_set_value(config_info.wakeup_gpio.gpio, 1);
			msleep(ms);
			__gpio_set_value(config_info.wakeup_gpio.gpio, 0);
		}
	}
	msleep(5);

	return 0;
}