예제 #1
0
static int gt927_config_write_proc(struct file *file, const char *buffer, unsigned long count, void *data)
{
    s32 ret = 0;

    GTP_DEBUG("write count %ld\n", count);

    if (count > GTP_CONFIG_MAX_LENGTH)
    {
        GTP_ERROR("size not match [%d:%ld]\n", GTP_CONFIG_MAX_LENGTH, count);
        return -EFAULT;
    }

    if (copy_from_user(&config[2], buffer, count))
    {
        GTP_ERROR("copy from user fail\n");
        return -EFAULT;
    }

    ret = gtp_send_cfg(i2c_client_point);
    abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
    abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
    int_type = (config[TRIGGER_LOC]) & 0x03;

    if (ret < 0)
    {
        GTP_ERROR("send config failed.");
    }

    return count;
}
예제 #2
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;
        dprintk(DEBUG_INIT, "*****%s start!\n******\n", __func__);
        dprintk(DEBUG_INIT, " cfg_index :%d\n", cfg_index);
        
	memcpy(config, gt811_cfg_grp[cfg_index].config_info, gt811_cfg_grp[cfg_index].size);

#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;
}
예제 #3
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;
}
예제 #4
0
static int gt91xx_config_write_proc(struct file *file, const char *buffer, unsigned long count, void *data)
{
    s32 ret = 0;
    char temp[16] = {0}; // for store special format cmd
    char mode_str[8] = {0};
    unsigned int mode; 
    u8 buf[1];
    
    GTP_DEBUG("write count %ld", count);

    if (count > GTP_CONFIG_MAX_LENGTH)
    {
        GTP_ERROR("size not match [%d:%ld]", GTP_CONFIG_MAX_LENGTH, count);
        return -EFAULT;
    }

    /**********************************************/
    /* for store special format cmd  */
    if (copy_from_user(temp, buffer, sizeof(temp)))
		{
        GTP_ERROR("copy from user fail 2");
        return -EFAULT;
    }
    sscanf(temp, "%s %d", (char *)&mode_str, &mode);
    
    if(strcmp(mode_str, "switch") == 0)
    {
        if(mode == 0)// turn off
            tpd_off();
        else if(mode == 1)//turn on
            tpd_on();
        else
            GTP_ERROR("error mode :%d", mode);  
        return count;              	
    }
    //force clear config
    if(strcmp(mode_str, "clear_config") == 0)
    {
        GTP_INFO("Force clear config");
        buf[0] = 0x10;
        ret = i2c_write_bytes(i2c_client_point, GTP_REG_SLEEP, buf, 1);
        return count;              	
    }
   
    if (copy_from_user(&config[2], buffer, count))
    {
        GTP_ERROR("copy from user fail");
        return -EFAULT;
    }
    
    /***********clk operate reseved****************/
    /**********************************************/
    ret = gtp_send_cfg(i2c_client_point);
    abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];
    abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];
    int_type = (config[TRIGGER_LOC]) & 0x03;

    if (ret < 0)
    {
        GTP_ERROR("send config failed.");
    }

    return count;
}
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;
}