s32 init_wr_node(struct i2c_client *client)
{
    s32 i;

    gt_client = i2c_client_point;
    GTP_INFO("client %d.%d", (int)gt_client, (int)client);

    memset(&cmd_head, 0, sizeof(cmd_head));
    cmd_head.data = NULL;

    i = 5;

    while ((!cmd_head.data) && i)
    {
        cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);

        if (NULL != cmd_head.data)
        {
            break;
        }

        i--;
    }

    if (i)
    {
        DATA_LENGTH = i * DATA_LENGTH_UINT + GTP_ADDR_LENGTH;
        GTP_INFO("Applied memory size:%d.", DATA_LENGTH);
    }
    else
    {
        GTP_ERROR("Apply for memory failed.");
        return FAIL;
    }

    cmd_head.addr_len = 2;
    cmd_head.retry = 5;

    register_i2c_func();

    goodix_proc_entry = create_proc_entry(GOODIX_ENTRY_NAME, 0664, NULL);

    if (goodix_proc_entry == NULL)
    {
        GTP_ERROR("Couldn't create proc entry!");
        return FAIL;
    }
    else
    {
        GTP_INFO("Create proc entry success!");
        goodix_proc_entry->write_proc = goodix_tool_write;
        goodix_proc_entry->read_proc = goodix_tool_read;
    }

    return SUCCESS;
}
Beispiel #2
0
s32 init_wr_node(struct i2c_client *client)
{
	s32 i;

	gt_client = i2c_client_point;

	memset(&cmd_head, 0, sizeof(cmd_head));
	cmd_head.data = NULL;

	i = 5;

	while ((!cmd_head.data) && i) {
		cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);

		if (NULL != cmd_head.data) {
			break;
		}

		i--;
	}

	if (i) {
		DATA_LENGTH = i * DATA_LENGTH_UINT + GTP_ADDR_LENGTH;
		GTP_INFO("Applied memory size:%d.", DATA_LENGTH);
	} else {
		GTP_ERROR("Apply for memory failed.");
		return FAIL;
	}

	cmd_head.addr_len = 2;
	cmd_head.retry = 5;

	register_i2c_func();

	tool_set_proc_name(procname);
#if 0				/* fix 3.10 */
	goodix_proc_entry = create_proc_entry(gtp_tool_entry, 0664, NULL);

	if (goodix_proc_entry == NULL) {
		GTP_ERROR("Couldn't create proc entry!");
		return FAIL;
	} else {
		GTP_INFO("Create proc entry success!");
		goodix_proc_entry->write_proc = goodix_tool_write;
		goodix_proc_entry->read_proc = goodix_tool_read;
	}
#else
	if (proc_create(procname, 0660, NULL, &gt_tool_fops) == NULL) {
		GTP_ERROR("create_proc_entry %s failed", procname);
		return -1;
	}
#endif
	return SUCCESS;
}
s32 init_wr_node(struct i2c_client *client)
{
    s32 i;

    gt_client = client;
    memset(&cmd_head, 0, sizeof(cmd_head));
    cmd_head.data = NULL;

    i = 5;
    while ((!cmd_head.data) && i)
    {
        cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);
        if (NULL != cmd_head.data)
        {
            break;
        }
        i--;
    }
    if (i)
    {
        DATA_LENGTH = i * DATA_LENGTH_UINT + ADDR_MAX_LENGTH;
        NOTICE("Applied memory size:%d.\n", DATA_LENGTH);
    }
    else
    {
        WARNING("Apply for memory failed.\n");
        return fail;
    }

    cmd_head.addr_len = 2;
    cmd_head.retry = 5;

    register_i2c_func();

    goodix_proc_entry = create_proc_entry(GOODIX_ENTRY_NAME, 0666, NULL);
    if (goodix_proc_entry == NULL)
    {
        WARNING("Couldn't create proc entry!\n");
        return fail;
    }
    else
    {
        NOTICE("Create proc entry success!\n");
        goodix_proc_entry->write_proc = goodix_tool_write;
        goodix_proc_entry->read_proc = goodix_tool_read;
        //goodix_proc_entry->owner =THIS_MODULE;
    }

    return success;
}
int init_wr_node(struct i2c_client *client)
{
	int i;

	gt_client = client;
	memset(&cmd_head, 0, sizeof(cmd_head));
	cmd_head.data = NULL;

	i = 5;
	while ((!cmd_head.data) && i) {
		cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);
		if (NULL != cmd_head.data)
			break;
		i--;
	}
	if (i) {
		DATA_LENGTH = i * DATA_LENGTH_UINT + GTP_ADDR_LENGTH;
		GTP_INFO("Applied memory size:%d.", DATA_LENGTH);
	} else {
		GTP_ERROR("Apply for memory failed.");
		return -1;
	}

	cmd_head.addr_len = 2;
	cmd_head.retry = 5;

	register_i2c_func();

	tool_set_proc_name(procname);
	fops.read = NULL;
	fops.write = NULL;
	goodix_proc_entry =
		proc_create_data(procname, 0666, NULL, &fops, NULL);
	if (goodix_proc_entry == NULL) {
		GTP_ERROR("Couldn't create proc entry!");
		return -1;
	}
	/* else {
	   GTP_INFO("Create proc entry success!");
	   goodix_proc_entry->write_proc = goodix_tool_write;
	   goodix_proc_entry->read_proc = goodix_tool_read;
	   }
	 */

	return 0;
}
/*******************************************************
Function:
	Goodix tool write function.
Input:
  standard proc write function param.
Output:
	Return write length.
********************************************************/
static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigned long len, void *data)
{
    u64 ret = 0;
    GTP_DEBUG_FUNC();
    GTP_DEBUG_ARRAY((u8 *)buff, len);

    ret = copy_from_user(&cmd_head, buff, CMD_HEAD_LENGTH);

    if (ret)
    {
        GTP_ERROR("copy_from_user failed.");
    }

    GTP_DEBUG("wr  :0x%02x.", cmd_head.wr);
    GTP_DEBUG("flag:0x%02x.", cmd_head.flag);
    GTP_DEBUG("flag addr:0x%02x%02x.", cmd_head.flag_addr[0], cmd_head.flag_addr[1]);
    GTP_DEBUG("flag val:0x%02x.", cmd_head.flag_val);
    GTP_DEBUG("flag rel:0x%02x.", cmd_head.flag_relation);
    GTP_DEBUG("circle  :%d.", (s32)cmd_head.circle);
    GTP_DEBUG("times   :%d.", (s32)cmd_head.times);
    GTP_DEBUG("retry   :%d.", (s32)cmd_head.retry);
    GTP_DEBUG("delay   :%d.", (s32)cmd_head.delay);
    GTP_DEBUG("data len:%d.", (s32)cmd_head.data_len);
    GTP_DEBUG("addr len:%d.", (s32)cmd_head.addr_len);
    GTP_DEBUG("addr:0x%02x%02x.", cmd_head.addr[0], cmd_head.addr[1]);
    GTP_DEBUG("len:%d.", (s32)len);
    GTP_DEBUG("buf[20]:0x%02x.", buff[CMD_HEAD_LENGTH]);

    if (1 == cmd_head.wr)
    {
        //  copy_from_user(&cmd_head.data[cmd_head.addr_len], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (ret)
        {
            GTP_ERROR("copy_from_user failed.");
        }

        memcpy(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.addr, cmd_head.addr_len);

        GTP_DEBUG_ARRAY(cmd_head.data, cmd_head.data_len + cmd_head.addr_len);
        GTP_DEBUG_ARRAY((u8 *)&buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (1 == cmd_head.flag)
        {
            if (FAIL == comfirm())
            {
                GTP_ERROR("[WRITE]Comfirm fail!");
                return FAIL;
            }
        }
        else if (2 == cmd_head.flag)
        {
            //Need interrupt!
        }

        if (tool_i2c_write(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],
                           cmd_head.data_len + cmd_head.addr_len) <= 0)
        {
            GTP_ERROR("[WRITE]Write data failed!");
            return FAIL;
        }

        GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.data_len + cmd_head.addr_len);

        if (cmd_head.delay)
        {
            msleep(cmd_head.delay);
        }

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }
    else if (3 == cmd_head.wr)  //Write ic type
    {
        memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);
        register_i2c_func();

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }
    else if (5 == cmd_head.wr)
    {
        //memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }
    else if (7 == cmd_head.wr)//disable irq!
    {
        //     gtp_irq_disable(i2c_get_clientdata(gt_client));

        return CMD_HEAD_LENGTH;
    }
    else if (9 == cmd_head.wr) //enable irq!
    {
//       gtp_irq_enable(i2c_get_clientdata(gt_client));

        return CMD_HEAD_LENGTH;
    }
    else if (17 == cmd_head.wr)
    {
        //struct goodix_ts_data *ts = i2c_get_clientdata(gt_client);
        ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (ret)
        {
            GTP_DEBUG("copy_from_user failed.");
        }

        if (cmd_head.data[GTP_ADDR_LENGTH])
        {
            GTP_DEBUG("gtp enter rawdiff.");
            gtp_rawdiff_mode = true;
        }
        else
        {
            gtp_rawdiff_mode = false;
            GTP_DEBUG("gtp leave rawdiff.");
        }

        return CMD_HEAD_LENGTH;
    }

#ifdef UPDATE_FUNCTIONS
    else if (11 == cmd_head.wr)//Enter update mode!
    {
        if (FAIL == gup_enter_update_mode(gt_client))
        {
            return FAIL;
        }
    }
    else if (13 == cmd_head.wr)//Leave update mode!
    {
        gup_leave_update_mode();
    }
    else if (15 == cmd_head.wr) //Update firmware!
    {
        show_len = 0;
        total_len = 0;
        memset(cmd_head.data, 0, cmd_head.data_len + 1);
        memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (FAIL == gup_update_proc((void *)cmd_head.data))
        {
            return FAIL;
        }
    }

#endif

    return CMD_HEAD_LENGTH;
}
/*******************************************************
Function:
    Goodix tool write function.
Input:
  standard proc write function param.
Output:
    Return write length.
********************************************************/
static ssize_t goodix_tool_write(struct file *filp, const char __user *buff, size_t len, loff_t *off)
{
    s32 ret = 0;
    GTP_DEBUG_FUNC();
    GTP_DEBUG_ARRAY((u8 *)buff, len);
		
    if(gtp_resetting == 1)
    {
        //GTP_ERROR("[Write]tpd_halt =1 fail!");
	return FAIL;
    }

	ret = copy_from_user(&cmd_head, buff, CMD_HEAD_LENGTH);

    if (ret)
    {
        GTP_ERROR("copy_from_user failed.");
    }

    GTP_DEBUG("wr  :0x%02x.", cmd_head.wr);

    if (1 == cmd_head.wr)
    {
        //  copy_from_user(&cmd_head.data[cmd_head.addr_len], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (ret)
        {
            GTP_ERROR("copy_from_user failed.");
        }

        memcpy(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.addr, cmd_head.addr_len);

        GTP_DEBUG_ARRAY(cmd_head.data, cmd_head.data_len + cmd_head.addr_len);
        GTP_DEBUG_ARRAY((u8 *)&buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (1 == cmd_head.flag)
        {
            if (FAIL == comfirm())
            {
                GTP_ERROR("[WRITE]Comfirm fail!");
                return FAIL;
            }
        }
        else if (2 == cmd_head.flag)
        {
            //Need interrupt!
        }

        if (tool_i2c_write(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],
                           cmd_head.data_len + cmd_head.addr_len) <= 0)
        {
            GTP_ERROR("[WRITE]Write data failed!");
            return FAIL;
        }

        GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.data_len + cmd_head.addr_len);

        if (cmd_head.delay)
        {
            msleep(cmd_head.delay);
        }

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }
    else if (3 == cmd_head.wr)  //Write ic type
    {
        memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);
        register_i2c_func();

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }
    else if (5 == cmd_head.wr)
    {
        //memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }
    else if (7 == cmd_head.wr)//disable irq!
    {
        mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
    #if GTP_ESD_PROTECT
        gtp_esd_switch(i2c_client_point, SWITCH_OFF);
    #endif
        return CMD_HEAD_LENGTH;
    }
    else if (9 == cmd_head.wr) //enable irq!
    {
        mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
    #if GTP_ESD_PROTECT
        gtp_esd_switch(i2c_client_point, SWITCH_ON);
    #endif
        return CMD_HEAD_LENGTH;
    }
    else if (17 == cmd_head.wr)
    {
        ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (ret)
        {
            GTP_DEBUG("copy_from_user failed.");
        }

        if (cmd_head.data[GTP_ADDR_LENGTH])
        {
            GTP_DEBUG("gtp enter rawdiff.");
            gtp_rawdiff_mode = true;
        }
        else
        {
            gtp_rawdiff_mode = false;
            GTP_DEBUG("gtp leave rawdiff.");
        }

        return CMD_HEAD_LENGTH;
    }

#ifdef UPDATE_FUNCTIONS      
    else if (11 == cmd_head.wr) //Enter update mode!
    {
        if (FAIL == gup_enter_update_mode(gt_client))
        {
            return FAIL;
        }
    }
    else if (13 == cmd_head.wr)//Leave update mode!
    {
        gup_leave_update_mode();
    }
    else if (15 == cmd_head.wr) //Update firmware!
    {
        show_len = 0;
        total_len = 0;
        memset(cmd_head.data, 0, cmd_head.data_len + 1);
        memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
        if (FAIL == gup_update_proc((void *)cmd_head.data))
        {
            return FAIL;
        }
    }

#endif
    else if (19 == cmd_head.wr)  //load subsystem
    {
	    ret = copy_from_user(&cmd_head.data[0], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
		if(0 == cmd_head.data[0])
		{
			if (FAIL == gup_load_calibration1())
			{
				return FAIL;
			}
		}
		else if(1 == cmd_head.data[0])
		{
			if (FAIL == gup_load_calibration2())
			{
				return FAIL;
			}		
		}
        else if(2 == cmd_head.data[0])
        {
			if (FAIL == gup_recovery_calibration0())
			{
				return FAIL;
			}
        }
		else if(3 == cmd_head.data[0])
		{
			if (FAIL == gup_load_calibration0(NULL))
			{
				return FAIL;
			}
		}
	}	
#if HOTKNOT_BLOCK_RW
    else if (21 == cmd_head.wr)
    {
        u16 wait_hotknot_timeout = 0;
        u8  rqst_hotknot_state;
				
        ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], 
            &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (ret)
        {
            GTP_ERROR("copy_from_user failed.");
        }
        
        rqst_hotknot_state = cmd_head.data[GTP_ADDR_LENGTH];
        wait_hotknot_state |= rqst_hotknot_state;
        wait_hotknot_timeout = (cmd_head.data[GTP_ADDR_LENGTH + 1]<<8) + 
            cmd_head.data[GTP_ADDR_LENGTH + 2];
        GTP_DEBUG("Goodix tool received wait polling state:0x%x,timeout:%d, all wait state:0x%x",
            rqst_hotknot_state, wait_hotknot_timeout, wait_hotknot_state);
        got_hotknot_state &= (~rqst_hotknot_state);
        //got_hotknot_extra_state = 0;
        switch(rqst_hotknot_state)
        {
            set_current_state(TASK_INTERRUPTIBLE);
            case HN_DEVICE_PAIRED:
                hotknot_paired_flag = 0;
                wait_event_interruptible(bp_waiter, force_wake_flag || 
                    rqst_hotknot_state == (got_hotknot_state&rqst_hotknot_state));
                wait_hotknot_state &= (~rqst_hotknot_state);
                if(rqst_hotknot_state != (got_hotknot_state&rqst_hotknot_state))
                {
                    GTP_ERROR("Wait 0x%x block polling waiter failed.", rqst_hotknot_state);
                    force_wake_flag = 0;
                    return FAIL;
                }
            break;
            case HN_MASTER_SEND:
            case HN_SLAVE_RECEIVED:
                wait_event_interruptible_timeout(bp_waiter, force_wake_flag || 
                    rqst_hotknot_state == (got_hotknot_state&rqst_hotknot_state),
                    wait_hotknot_timeout);
                wait_hotknot_state &= (~rqst_hotknot_state);
                if(rqst_hotknot_state == (got_hotknot_state&rqst_hotknot_state))
                {
                    return got_hotknot_extra_state;
                }
                else
                {
                    GTP_ERROR("Wait 0x%x block polling waiter timeout.", rqst_hotknot_state);
                    force_wake_flag = 0;
                    return FAIL;
                }
            break;
            case HN_MASTER_DEPARTED:
            case HN_SLAVE_DEPARTED:
                wait_event_interruptible_timeout(bp_waiter, force_wake_flag || 
                    rqst_hotknot_state == (got_hotknot_state&rqst_hotknot_state),
                    wait_hotknot_timeout);
                wait_hotknot_state &= (~rqst_hotknot_state);
                if(rqst_hotknot_state != (got_hotknot_state&rqst_hotknot_state))
                {
                    GTP_ERROR("Wait 0x%x block polling waitor timeout.", rqst_hotknot_state);
                    force_wake_flag = 0;
                    return FAIL;
                }
            break;
            default:
                GTP_ERROR("Invalid rqst_hotknot_state in goodix_tool.");
            break;
        }
        force_wake_flag = 0;
    }
    else if(23 == cmd_head.wr)
    {
        GTP_DEBUG("Manual wakeup all block polling waiter!");
        got_hotknot_state = 0;
        wait_hotknot_state = 0;
        force_wake_flag = 1;
        hotknot_paired_flag = 0;
        wake_up_interruptible(&bp_waiter);
    }
#endif
    return CMD_HEAD_LENGTH;
}
s32 init_wr_node(struct i2c_client *client)
{
    s32 i;

    gt_client = i2c_client_point;

    memset(&cmd_head, 0, sizeof(cmd_head));
    cmd_head.data = NULL;

    i = 5;

    while ((!cmd_head.data) && i)
    {
        cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);

        if (NULL != cmd_head.data)
        {
            break;
        }

        i--;
    }

    if (i)
    {
        DATA_LENGTH = i * DATA_LENGTH_UINT + GTP_ADDR_LENGTH;
        GTP_INFO("Applied memory size:%d.", DATA_LENGTH);
    }
    else
    {
        GTP_ERROR("Apply for memory failed.");
        return FAIL;
    }

    cmd_head.addr_len = 2;
    cmd_head.retry = 5;

	memset(&cmd_head2, 0, sizeof(cmd_head2));
    cmd_head2.data = NULL;

    i = 5;

    while ((!cmd_head2.data) && i)
    {
        cmd_head2.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);

        if (NULL != cmd_head2.data)
        {
            break;
        }

        i--;
    }

    if (i)
    {
        DATA_LENGTH = i * DATA_LENGTH_UINT + GTP_ADDR_LENGTH;
        GTP_INFO("Applied memory size:%d.", DATA_LENGTH);
    }
    else
    {
        GTP_ERROR("Apply for memory failed.");
        return FAIL;
    }

    cmd_head2.addr_len = 2;
    cmd_head2.retry = 5;
	
    register_i2c_func();

    tool_set_proc_name(procname);
    goodix_proc_entry = proc_create(procname, 0660, 	NULL, &tool_ops);

    if (misc_register(&hotknot_misc_device))
    {
        printk("mtk_tpd: hotknot_device register failed\n");
        return FAIL;
    }
   
    if (goodix_proc_entry == NULL)
    {
        GTP_ERROR("Couldn't create proc entry!");
        return FAIL;
    }
    else
    {
        GTP_INFO("Create proc entry success!");
    }

    return SUCCESS;
}
Beispiel #8
0
/*******************************************************
Function:
	Goodix tool write function.
Input:
  standard proc write function param.
Output:
	Return write length.
********************************************************/
static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigned long len,
			     void *data)
{
	u64 ret = 0;
	GTP_DEBUG_FUNC();
	GTP_DEBUG_ARRAY((u8 *) buff, len);

	if(len < CMD_HEAD_LENGTH){
		GTP_ERROR("copy_from_user out of range, failed.");
		return -1;
	}
	ret = copy_from_user(&cmd_head, buff, CMD_HEAD_LENGTH);
	if (ret) {
		GTP_ERROR("copy_from_user failed.");
	}

	GTP_DEBUG("wr  :0x%02x.", cmd_head.wr);
	GTP_DEBUG("flag:0x%02x.", cmd_head.flag);
	GTP_DEBUG("flag addr:0x%02x%02x.", cmd_head.flag_addr[0], cmd_head.flag_addr[1]);
	GTP_DEBUG("flag val:0x%02x.", cmd_head.flag_val);
	GTP_DEBUG("flag rel:0x%02x.", cmd_head.flag_relation);
	GTP_DEBUG("circle  :%d.", (s32) cmd_head.circle);
	GTP_DEBUG("times   :%d.", (s32) cmd_head.times);
	GTP_DEBUG("retry   :%d.", (s32) cmd_head.retry);
	GTP_DEBUG("delay   :%d.", (s32) cmd_head.delay);
	GTP_DEBUG("data len:%d.", (s32) cmd_head.data_len);
	GTP_DEBUG("addr len:%d.", (s32) cmd_head.addr_len);
	GTP_DEBUG("addr:0x%02x%02x.", cmd_head.addr[0], cmd_head.addr[1]);
	GTP_DEBUG("len:%d.", (s32) len);
	GTP_DEBUG("buf[20]:0x%02x.", buff[CMD_HEAD_LENGTH]);

	if (1 == cmd_head.wr) {

		if((cmd_head.data == NULL)
			|| (cmd_head.data_len > (DATA_LENGTH - GTP_ADDR_LENGTH))
			|| (cmd_head.data_len > (len - CMD_HEAD_LENGTH)) )
		{
			GTP_ERROR("copy_from_user data out of range.");
			return -1;
		}
		ret =
		    copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH],
				   cmd_head.data_len);

		if (ret) {
			GTP_ERROR("copy_from_user failed.");
		}

		if((cmd_head.addr_len > sizeof(cmd_head.addr)))
		{
			GTP_ERROR("copy_from_user data out of range.");
			return -1;
		}
		memcpy(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.addr,
		       cmd_head.addr_len);

		GTP_DEBUG_ARRAY(cmd_head.data, cmd_head.data_len + cmd_head.addr_len);
		GTP_DEBUG_ARRAY((u8 *) &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

		if (1 == cmd_head.flag) {
			if (FAIL == comfirm()) {
				GTP_ERROR("[WRITE]Comfirm fail!");
				return FAIL;
			}
		} else if (2 == cmd_head.flag) {
			/* Need interrupt! */
		}

		if (tool_i2c_write(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],
				   cmd_head.data_len + cmd_head.addr_len) <= 0) {
			GTP_ERROR("[WRITE]Write data failed!");
			return FAIL;
		}

		GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],
				cmd_head.data_len + cmd_head.addr_len);

		if (cmd_head.delay) {
			msleep(cmd_head.delay);
		}

		return cmd_head.data_len + CMD_HEAD_LENGTH;
	} else if (3 == cmd_head.wr)	/* Write ic type */
	{
		if((cmd_head.data == NULL)
			|| (cmd_head.data_len > sizeof(IC_TYPE[16]))
			|| (cmd_head.data_len > (len - CMD_HEAD_LENGTH)) )
		{
			GTP_ERROR("copy_from_user data out of range.");
			return -1;
		}
		memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);
		register_i2c_func();

		return cmd_head.data_len + CMD_HEAD_LENGTH;
	} else if (5 == cmd_head.wr) {
		/* memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len); */

		return cmd_head.data_len + CMD_HEAD_LENGTH;
	} else if (7 == cmd_head.wr)	/* disable irq! */
	{
		mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
#if GTP_ESD_PROTECT
		gtp_esd_switch(i2c_client_point, SWITCH_OFF);
#endif
		return CMD_HEAD_LENGTH;
	} else if (9 == cmd_head.wr)	/* enable irq! */
	{
		mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
#if GTP_ESD_PROTECT
		gtp_esd_switch(i2c_client_point, SWITCH_ON);
#endif
		return CMD_HEAD_LENGTH;
	} else if (17 == cmd_head.wr) {

		if((cmd_head.data == NULL)
			|| (cmd_head.data_len > (DATA_LENGTH - GTP_ADDR_LENGTH))
			|| (cmd_head.data_len > (len - CMD_HEAD_LENGTH)) )
		{
			GTP_ERROR("copy_from_user data out of range.");
			return -1;
		}

		ret =
		    copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH],
				   cmd_head.data_len);

		if (ret) {
			GTP_DEBUG("copy_from_user failed.");
		}

		if (cmd_head.data[GTP_ADDR_LENGTH]) {
			GTP_DEBUG("gtp enter rawdiff.");
			gtp_rawdiff_mode = true;
		} else {
			gtp_rawdiff_mode = false;
			GTP_DEBUG("gtp leave rawdiff.");
		}

		return CMD_HEAD_LENGTH;
	}
#ifdef UPDATE_FUNCTIONS
	else if (11 == cmd_head.wr)	/* Enter update mode! */
	{
		if (FAIL == gup_enter_update_mode(gt_client)) {
			return FAIL;
		}
	} else if (13 == cmd_head.wr)	/* Leave update mode! */
	{
		gup_leave_update_mode();
	} else if (15 == cmd_head.wr)	/* Update firmware! */
	{
		show_len = 0;
		total_len = 0;
		memset(cmd_head.data, 0, cmd_head.data_len + 1);

		if((cmd_head.data == NULL)
			|| (cmd_head.data_len > DATA_LENGTH)
			|| (cmd_head.data_len > (len - CMD_HEAD_LENGTH)) )
		{
			GTP_ERROR("copy_from_user data out of range.");
			return -1;
		}
		copy_from_user(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

		GTP_DEBUG("update firmware, filename: %s", cmd_head.data);
		if (FAIL == gup_update_proc((void *)cmd_head.data)) {
			return FAIL;
		}
	}
#endif

	return CMD_HEAD_LENGTH;
}
static int goodix_tool_write(struct file *filp,
		const char __user *buff, unsigned long len, void *data)
{
	int ret = 0;

	GTP_DEBUG_FUNC();
	GTP_DEBUG_ARRAY((u8*)buff, len);

	ret = copy_from_user(&cmd_head, buff, CMD_HEAD_LENGTH);
	if (ret)
		GTP_ERROR("copy_from_user failed.");

	GTP_DEBUG("wr  :0x%02x.", cmd_head.wr);
	GTP_DEBUG("flag:0x%02x.", cmd_head.flag);
	GTP_DEBUG("flag addr:0x%02x%02x.",
			cmd_head.flag_addr[0], cmd_head.flag_addr[1]);
	GTP_DEBUG("flag val:0x%02x.", cmd_head.flag_val);
	GTP_DEBUG("flag rel:0x%02x.", cmd_head.flag_relation);
	GTP_DEBUG("circle  :%d.", (int)cmd_head.circle);
	GTP_DEBUG("times   :%d.", (int)cmd_head.times);
	GTP_DEBUG("retry   :%d.", (int)cmd_head.retry);
	GTP_DEBUG("delay   :%d.", (int)cmd_head.delay);
	GTP_DEBUG("data len:%d.", (int)cmd_head.data_len);
	GTP_DEBUG("addr len:%d.", (int)cmd_head.addr_len);
	GTP_DEBUG("addr:0x%02x%02x.", cmd_head.addr[0], cmd_head.addr[1]);
	GTP_DEBUG("len:%d.", (int)len);
	GTP_DEBUG("buf[20]:0x%02x.", buff[CMD_HEAD_LENGTH]);

	if (1 == cmd_head.wr) {
		/*  copy_from_user(&cmd_head.data[cmd_head.addr_len],
		    &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
		 */
		ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH],
				&buff[CMD_HEAD_LENGTH], cmd_head.data_len);
		if (ret)
			GTP_ERROR("copy_from_user failed.");
		memcpy(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],
					cmd_head.addr, cmd_head.addr_len);

		GTP_DEBUG_ARRAY(cmd_head.data,
				cmd_head.data_len + cmd_head.addr_len);
		GTP_DEBUG_ARRAY((u8*)&buff[CMD_HEAD_LENGTH], cmd_head.data_len);

		if (1 == cmd_head.flag) {
			if (comfirm() < 0) {
				GTP_ERROR("[WRITE]Comfirm fail!");
				return -1;
			}
		} else if (2 == cmd_head.flag) {
			/* Need interrupt! */
		}

		if (tool_i2c_write(&cmd_head.data[GTP_ADDR_LENGTH -
						cmd_head.addr_len],
					cmd_head.data_len +
						cmd_head.addr_len) <= 0) {
			GTP_ERROR("[WRITE]Write data failed!");
			return -1;
		}

		GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH -
					cmd_head.addr_len],
				cmd_head.data_len + cmd_head.addr_len);
		if (cmd_head.delay)
			msleep(cmd_head.delay);

		return cmd_head.data_len + CMD_HEAD_LENGTH;
	} else if (3 == cmd_head.wr) {
		/* Write ic type */
		ret = copy_from_user(&cmd_head.data[0],
				&buff[CMD_HEAD_LENGTH], cmd_head.data_len);
		if (ret)
			GTP_ERROR("copy_from_user failed.");
		memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);
		register_i2c_func();

		return cmd_head.data_len + CMD_HEAD_LENGTH;
	} else if (5 == cmd_head.wr) {
		/* memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len); */
		return cmd_head.data_len + CMD_HEAD_LENGTH;
	} else if (7 == cmd_head.wr) {
		/* disable irq! */
		gtp_irq_disable(i2c_get_clientdata(gt_client));

#if GTP_ESD_PROTECT
		gtp_esd_switch(gt_client, SWITCH_OFF);
#endif
		return CMD_HEAD_LENGTH;
	} else if (9 == cmd_head.wr) {
		/* enable irq! */
		gtp_irq_enable(i2c_get_clientdata(gt_client));

#if GTP_ESD_PROTECT
		gtp_esd_switch(gt_client, SWITCH_ON);
#endif
		return CMD_HEAD_LENGTH;
	} else if (17 == cmd_head.wr) {
		struct goodix_ts_data *ts = i2c_get_clientdata(gt_client);
		ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH],
				&buff[CMD_HEAD_LENGTH], cmd_head.data_len);
		if (ret)
			GTP_DEBUG("copy_from_user failed.");
		if (cmd_head.data[GTP_ADDR_LENGTH]) {
			GTP_DEBUG("gtp enter rawdiff.");
			ts->gtp_rawdiff_mode = true;
		} else {
			ts->gtp_rawdiff_mode = false;
			GTP_DEBUG("gtp leave rawdiff.");
		}
		return CMD_HEAD_LENGTH;
	}
#ifdef UPDATE_FUNCTIONS
	else if (11 == cmd_head.wr) {
		/* Enter update mode! */
		if (gup_enter_update_mode(gt_client) < 0)
			return -1;
	} else if (13 == cmd_head.wr) {
		/* Leave update mode! */
		gup_leave_update_mode();
	} else if (15 == cmd_head.wr) {
		/* Update firmware! */
		show_len = 0;
		total_len = 0;
		memset(cmd_head.data, 0, cmd_head.data_len + 1);
		memcpy(cmd_head.data,
				&buff[CMD_HEAD_LENGTH], cmd_head.data_len);

		if (gup_update_proc((void*)cmd_head.data) < 0)
			return -1;
	}
#endif
	return CMD_HEAD_LENGTH;
}
s32 init_wr_node(struct i2c_client *client)
{
    s32 i;
    const s8 entry_prefix[] = "GMNode_";
    s8 gtp_tool_entry[30];

    gt_client = i2c_client_point;
    GTP_INFO("client %d.%d", (int)gt_client, (int)client);

    memset(&cmd_head, 0, sizeof(cmd_head));
    cmd_head.data = NULL;

    i = 5;

    while ((!cmd_head.data) && i)
    {
        cmd_head.data = kzalloc(i * DATA_LENGTH_UINT, GFP_KERNEL);

        if (NULL != cmd_head.data)
        {
            break;
        }

        i--;
    }

    if (i)
    {
        DATA_LENGTH = i * DATA_LENGTH_UINT + GTP_ADDR_LENGTH;
        GTP_INFO("Applied memory size:%d.", DATA_LENGTH);
    }
    else
    {
        GTP_ERROR("Apply for memory failed.");
        return FAIL;
    }

    cmd_head.addr_len = 2;
    cmd_head.retry = 5;

    register_i2c_func();

 //   goodix_proc_entry = create_proc_entry(GOODIX_ENTRY_NAME, 0664, NULL);
 
    memset(gtp_tool_entry, 0, sizeof(gtp_tool_entry));
    i = sizeof(entry_prefix)/sizeof(s8);
    memcpy(gtp_tool_entry, entry_prefix, i-1);
    memcpy(&gtp_tool_entry[i-1], __DATE__, sizeof(__DATE__)/sizeof(s8));
#if 0 // fix 3.10
    goodix_proc_entry = create_proc_entry(gtp_tool_entry, 0664, NULL);

    if (goodix_proc_entry == NULL)
    {
        GTP_ERROR("Couldn't create proc entry!");
        return FAIL;
    }
    else
    {
        GTP_INFO("Create proc entry success!");
        goodix_proc_entry->write_proc = goodix_tool_write;
        goodix_proc_entry->read_proc = goodix_tool_read;
    }
#else
    if(proc_create(GOODIX_ENTRY_NAME, 0660, NULL, &gt_tool_fops)== NULL)
	{
        GTP_ERROR("create_proc_entry %s failed", gtp_tool_entry);
		return -1;
    }	
#endif
    return SUCCESS;
}
Beispiel #11
0
//static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigned long len, void *data)
ssize_t goodix_tool_write(struct file *filp, const char __user *buff, size_t len, loff_t *off)
{
    s32 ret = 0;

    GTP_DEBUG_FUNC();
    GTP_DEBUG_ARRAY((u8*)buff, len);

    ret = copy_from_user(&cmd_head, buff, CMD_HEAD_LENGTH);
    if(ret)
    {
        GTP_ERROR("copy_from_user failed.");
        return -EPERM;
    }


    GTP_DEBUG("[Operation]wr: %02X", cmd_head.wr);
    GTP_DEBUG("[Flag]flag: %02X, addr: %02X%02X, value: %02X, relation: %02X", cmd_head.flag, cmd_head.flag_addr[0],
              cmd_head.flag_addr[1], cmd_head.flag_val, cmd_head.flag_relation);
    GTP_DEBUG("[Retry]circle: %d, times: %d, retry: %d, delay: %d", (s32)cmd_head.circle, (s32)cmd_head.times,
              (s32)cmd_head.retry, (s32)cmd_head.delay);
    GTP_DEBUG("[Data]data len: %d, addr len: %d, addr: %02X%02X, buffer len: %d, data[0]: %02X", (s32)cmd_head.data_len,
              (s32)cmd_head.addr_len, cmd_head.addr[0], cmd_head.addr[1], (s32)len, buff[CMD_HEAD_LENGTH]);

    if (1 == cmd_head.wr)
    {
        ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        if(ret)
        {
            GTP_ERROR("copy_from_user failed.");
            return -EPERM;
        }
        memcpy(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len], cmd_head.addr, cmd_head.addr_len);

        GTP_DEBUG_ARRAY(cmd_head.data, cmd_head.data_len + cmd_head.addr_len);
        GTP_DEBUG_ARRAY((u8*)&buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (1 == cmd_head.flag)
        {
            if (FAIL == comfirm())
            {
                GTP_ERROR("[WRITE]Comfirm fail!");
                return -EPERM;
            }
        }
        else if (2 == cmd_head.flag)
        {
            //Need interrupt!
        }
        if (tool_i2c_write(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],
                           cmd_head.data_len + cmd_head.addr_len) <= 0)
        {
            GTP_ERROR("[WRITE]Write data failed!");
            return -EPERM;
        }

        GTP_DEBUG_ARRAY(&cmd_head.data[GTP_ADDR_LENGTH - cmd_head.addr_len],cmd_head.data_len + cmd_head.addr_len);
        if (cmd_head.delay)
        {
            msleep(cmd_head.delay);
        }
    }
    else if (3 == cmd_head.wr)  //Write ic type
    {
        ret = copy_from_user(&cmd_head.data[0], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        if(ret)
        {
            GTP_ERROR("copy_from_user failed.");
            return -EPERM;
        }
        memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);

        register_i2c_func();
    }
    else if (5 == cmd_head.wr)
    {
        //memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);
    }
    else if (7 == cmd_head.wr)//disable irq!
    {
        gtp_irq_disable(i2c_get_clientdata(gt_client));

#if GTP_ESD_PROTECT
        gtp_esd_switch(gt_client, SWITCH_OFF);
#endif
    }
    else if (9 == cmd_head.wr) //enable irq!
    {
        gtp_irq_enable(i2c_get_clientdata(gt_client));

#if GTP_ESD_PROTECT
        gtp_esd_switch(gt_client, SWITCH_ON);
#endif
    }
    else if(17 == cmd_head.wr)
    {
        struct goodix_ts_data *ts = i2c_get_clientdata(gt_client);
        ret = copy_from_user(&cmd_head.data[GTP_ADDR_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        if(ret)
        {
            GTP_DEBUG("copy_from_user failed.");
            return -EPERM;
        }
        if(cmd_head.data[GTP_ADDR_LENGTH])
        {
            GTP_INFO("gtp enter rawdiff.");
            ts->gtp_rawdiff_mode = true;
        }
        else
        {
            ts->gtp_rawdiff_mode = false;
            GTP_INFO("gtp leave rawdiff.");
        }
    }
#ifdef UPDATE_FUNCTIONS
    else if (11 == cmd_head.wr)//Enter update mode!
    {
        if (FAIL == gup_enter_update_mode(gt_client))
        {
            return -EPERM;
        }
    }
    else if (13 == cmd_head.wr)//Leave update mode!
    {
        gup_leave_update_mode();
    }
    else if (15 == cmd_head.wr) //Update firmware!
    {
        show_len = 0;
        total_len = 0;
        memset(cmd_head.data, 0, cmd_head.data_len + 1);
        memcpy(cmd_head.data, &buff[CMD_HEAD_LENGTH], cmd_head.data_len);

        if (FAIL == gup_update_proc((void*)cmd_head.data))
        {
            return -EPERM;
        }
    }

#endif

    return len;
}
static s32 goodix_tool_write(struct file *filp, const char __user *buff, unsigned long len, void *data)
{
    DEBUG_ARRAY((u8*)buff, len);
    
    copy_from_user(&cmd_head, buff, CMD_HEAD_LENGTH);

    DEBUG("wr  :0x%02x\n", cmd_head.wr);
    DEBUG("flag:0x%02x\n", cmd_head.flag);
    DEBUG("flag addr:0x%02x%02x\n", cmd_head.flag_addr[0], cmd_head.flag_addr[1]);
    DEBUG("flag val:0x%02x\n", cmd_head.flag_val);
    DEBUG("flag rel:0x%02x\n", cmd_head.flag_relation);
    DEBUG("circle  :%d\n", (s32)cmd_head.circle);
    DEBUG("times   :%d\n", (s32)cmd_head.times);
    DEBUG("retry   :%d\n", (s32)cmd_head.retry);
    DEBUG("delay   :%d\n", (s32)cmd_head.delay);
    DEBUG("data len:%d\n", (s32)cmd_head.data_len);
    DEBUG("addr len:%d\n", (s32)cmd_head.addr_len);
    DEBUG("addr:0x%02x%02x\n", cmd_head.addr[0], cmd_head.addr[1]);
    DEBUG("len:%d\n", (s32)len);
    DEBUG("buf[20]:0x%02x\n", buff[CMD_HEAD_LENGTH]);
    
    if (1 == cmd_head.wr)
    {
      //  copy_from_user(&cmd_head.data[cmd_head.addr_len], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        copy_from_user(&cmd_head.data[ADDR_MAX_LENGTH], &buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        memcpy(&cmd_head.data[ADDR_MAX_LENGTH - cmd_head.addr_len], cmd_head.addr, cmd_head.addr_len);

        DEBUG_ARRAY(cmd_head.data, cmd_head.data_len + cmd_head.addr_len);
        DEBUG_ARRAY((u8*)&buff[CMD_HEAD_LENGTH], cmd_head.data_len);
        
        if (1 == cmd_head.flag)
        {
            if (fail == comfirm())
            {
                WARNING("[WRITE]Comfirm fail!\n");
                return fail;
            }
        }
        else if (2 == cmd_head.flag)
        {
            //Need interrupt!
        }
        if (tool_i2c_write(&cmd_head.data[ADDR_MAX_LENGTH - cmd_head.addr_len],
            cmd_head.data_len + cmd_head.addr_len) <= 0)
        {
            WARNING("[WRITE]Write data failed!\n");
            return fail;
        }

        DEBUG_ARRAY(&cmd_head.data[ADDR_MAX_LENGTH - cmd_head.addr_len],cmd_head.data_len + cmd_head.addr_len);
        if (cmd_head.delay)
        {
            msleep(cmd_head.delay);
        }

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }
    else if (3 == cmd_head.wr)
    {
        memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);
        register_i2c_func();

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }
    else if (5 == cmd_head.wr)
    {
        //memcpy(IC_TYPE, cmd_head.data, cmd_head.data_len);

        return cmd_head.data_len + CMD_HEAD_LENGTH;
    }

    return CMD_HEAD_LENGTH;
}