示例#1
0
static int ct363_init(struct ct36x_data *ts)
{
	int ret = 0, fwchksum, binchksum, updcnt = 5;
	struct ct363_priv *ct363 = NULL;
	
	ret = ct363_init_hw(ts);
	if(ret < 0)
		return ret;

	 /* Hardware reset */
	ct363_reset_hw(ts);
	// Get binary Checksum
	binchksum = ct36x_chip_get_binchksum();
	ct36x_dbg(ts, "CT363 init: binchksum = %d\n", binchksum);

	ret = ct36x_chip_get_fwchksum(ts);
	if(ret < 0){
		dev_err(ts->dev, "CT36X chip: Failed to get fwchksum\n");
		return ret;
	}
	fwchksum = ret;
	ct36x_dbg(ts, "CT363 init: fwchksum = %d\n", fwchksum);
	while(binchksum != fwchksum && updcnt--) {
		/* Update Firmware */
		ret = ct36x_chip_go_bootloader(ts);
		if(ret < 0){
			dev_err(ts->dev, "CT36X chip: Failed to go bootloader\n");
			return ret;
		}
		 /* Hardware reset */
		ct363_reset_hw(ts);

		ret = ct36x_chip_get_fwchksum(ts);
		if(ret < 0){
			dev_err(ts->dev, "CT36X chip: Failed to get fwchksum\n");
			return ret;
		}
		fwchksum = ret;
		ct36x_dbg(ts, "CT363 update FW: fwchksum = %d\n", fwchksum);
	}
	if(binchksum != fwchksum){
		dev_err(ts->dev, "Fail to update FW\n");
		return -ENODEV;
	}

	/* Hardware reset */
	ct363_reset_hw(ts);
	msleep(5);

	ts->point_num = CT363_POINT_NUM;
	
	ct363 = kzalloc(sizeof(struct ct363_priv), GFP_KERNEL);
	if(!ct363){
		dev_err(ts->dev, "No memory for ct36x");
		return -ENOMEM;
	}
	ts->priv = ct363;

	return 0;
}
示例#2
0
static ssize_t ct36x_ts_write(struct file *file, const char __user *buffer, size_t count, loff_t *offset)
{
	int cmd = 0;
	int rslt = 0;
	
	if ( CT36X_TS_CORE_DEBUG ) {
	printk(">>>>> %s() called <<<<< \n", __FUNCTION__);
	}

	/* search cmd */
	cmd = ct36x_ts_cmd(ct36x_cmd_list_cmd, buffer[0]);

	/* execute cmd */
	if ( ct36x_ts.state == CT36X_STATE_NORMAL )
	switch ( cmd ) {
		case CT36X_TS_CHIP_ID:
		break;

		case CT36X_TS_CHIP_RESET:
		printk("%s(): CT36X_TS_CHIP_RESET\n", __FUNCTION__);
		#ifdef CONFIG_OF
		ct36x_platform_hw_reset(&ct36x_ts);
		#else
		ct36x_platform_hw_reset(plat_data);
		#endif
		break;

		case CT36X_TS_FW_VER:
		break;

		case CT36X_TS_FW_CHKSUM:
		printk("%s(): CT36X_TS_FW_CHKSUM\n", __FUNCTION__);
		rslt = ct36x_chip_get_fwchksum(ct36x_ts.client, ct36x_ts.data.buf);
		printk("%s(): Fw checksum: 0x%x\n", __FUNCTION__, rslt);
		break;

		case CT36X_TS_FW_UPDATE:
		printk("%s(): CT36X_TS_FW_UPDATE\n", __FUNCTION__);
		ct36x_chip_go_bootloader(ct36x_ts.client, ct36x_ts.data.buf);
		break;

		case CT36X_TS_BIN_VER:
		break;

		case CT36X_TS_BIN_CHKSUM:
		printk("%s(): CT36X_TS_BIN_CHKSUM\n", __FUNCTION__);
		rslt = ct36x_chip_get_binchksum(ct36x_ts.data.buf);
		printk("%s(): bin checksum: 0x%x\n", __FUNCTION__, rslt);
		break;

		default:
		printk("%s(): No such command (0x%x). \n", __FUNCTION__, buffer[0]);
		break;
	}


	return count;
}
static ssize_t ct36x_ts_write(struct file *file, const char __user *buffer, size_t count, loff_t *offset)
{
	int cmd = 0;
	int rslt = 0;
	
	if ( CT36X_TS_CORE_DEBUG ) {
	printk(">>>>> %s() called <<<<< \n", __FUNCTION__);
	printk("%s(): count=0x%x \n", __FUNCTION__, count);
	}

	// search cmd
	cmd = ct36x_ts_cmd(ct36x_cmd_list_cmd, buffer[0]);

	switch ( cmd ) {
		case CT36X_TS_CHIP_ID:
		break;

		case CT36X_TS_CHIP_RESET:
		printk("%s(): CT36X_TS_CHIP_RESET\n", __FUNCTION__);
		ct36x_platform_hw_reset(&ct36x_ts);
		break;

		case CT36X_TS_FW_VER:
		break;

		case CT36X_TS_FW_CHKSUM:
		printk("%s(): CT36X_TS_FW_CHKSUM\n", __FUNCTION__);
		rslt = ct36x_chip_get_fwchksum(ct36x_ts.client, ct36x_ts.data.buf);
		printk("%s(): Fw checksum: 0x%x\n", __FUNCTION__, rslt);
		break;

		case CT36X_TS_FW_UPDATE:
#if defined (CONFIG_TOUCHSCREEN_CT36X_FLASH)
		printk("%s(): CT36X_TS_FW_UPDATE\n", __FUNCTION__);
		ct36x_chip_go_bootloader(ct36x_ts.client, ct36x_ts.data.buf);
#else
		printk("%s(): CT36X_TS_FW_UPDATE IGNORED\n", __FUNCTION__);
#endif
		break;

		case CT36X_TS_BIN_VER:
		break;

		case CT36X_TS_BIN_CHKSUM:
		printk("%s(): CT36X_TS_BIN_CHKSUM\n", __FUNCTION__);
		rslt = ct36x_chip_get_binchksum(ct36x_ts.data.buf);
		printk("%s(): bin checksum: 0x%x\n", __FUNCTION__, rslt);
		break;

		default:
		printk("%s(): No such command (0x%x). \n", __FUNCTION__, buffer[0]);
		break;
	}


	return count;
}
int ct36x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	int err = -1;
	int binchksum, fwchksum;
	int updcnt;
	struct ct36x_ts_info *ts;
	struct ct36x_platform_data *pdata;
	struct device *dev;

	if ( CT36X_TS_CORE_DEBUG )
	printk(">>>>> %s() called <<<<< \n", __FUNCTION__);

	dev = &client->dev;

	pdata = dev->platform_data;

	if ( pdata ) {
		ct36x_ts.i2c_address = client->addr;
		ct36x_ts.rst = pdata->rst;
		ct36x_ts.ss = pdata->ss;
		ct36x_platform_get_cfg(&ct36x_ts);

		ct36x_ts.client = client;
		i2c_set_clientdata(client, &ct36x_ts);
	} else {
		printk("No platform data for device %s.\n", DRIVER_NAME);
	}
	ts = (struct ct36x_ts_info *)i2c_get_clientdata(client);

	/* Create Proc Entry File */
	ts->proc_entry = create_proc_entry(DRIVER_NAME, 0666/*S_IFREG | S_IRUGO | S_IWUSR*/, NULL);
	if ( ts->proc_entry == NULL ) {
		dev_err(dev, "Failed creating proc dir entry file.\n");
	} else {
		ts->proc_entry->proc_fops = &ct36x_ts_fops;
	}

	/* Check I2C Functionality */
	err = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
	if ( !err ) {
		dev_err(dev, "Check I2C Functionality Failed.\n");
		goto ERR_I2C_CHK;
	}

	/* Request platform resources (gpio/interrupt pins) */
	err = ct36x_platform_get_resource(ts);
	if ( err ) {
		dev_err(dev, "Unable to request platform resource for device %s.\n", DRIVER_NAME);
		goto ERR_PLAT_RSC;
	}

	/* Hardware reset */
	ct36x_platform_hw_reset(ts);

	// Get binary Checksum
	binchksum = ct36x_chip_get_binchksum(ts->data.buf);
	if ( CT36X_TS_CORE_DEBUG )
	printk("Bin checksum: 0x%x\n", binchksum);

	// Get firmware Checksum
	fwchksum = ct36x_chip_get_fwchksum(client, ts->data.buf);
	if ( CT36X_TS_CORE_DEBUG )
	printk("Fw checksum: 0x%x\n", fwchksum);

	updcnt = 5;
	while ( binchksum != fwchksum && updcnt--) {
		/* Update Firmware */
		ct36x_chip_go_bootloader(client, ts->data.buf);

		/* Hardware reset */
		ct36x_platform_hw_reset(ts);

		// Get firmware Checksum
		fwchksum = ct36x_chip_get_fwchksum(client, ts->data.buf);
		if ( CT36X_TS_CORE_DEBUG )
		printk("Fw checksum: 0x%x\n", fwchksum);
	}

	printk("Fw update %s. 0x%x, 0x%x\n", binchksum != fwchksum ? "Failed" : "Success", binchksum, fwchksum);

	/* Hardware reset */
	ct36x_platform_hw_reset(ts);

	/* allocate input device */
	ts->input = input_allocate_device();
	if ( !ts->input ) {
		dev_err(dev, "Unable to allocate input device for device %s.\n", DRIVER_NAME);
		err = -ENOMEM;
		goto ERR_INPUT_ALLOC;
	}

	/* config input device */
	__set_bit(EV_SYN, ts->input->evbit);
	__set_bit(EV_KEY, ts->input->evbit);
	__set_bit(EV_ABS, ts->input->evbit);

	__set_bit(INPUT_PROP_DIRECT, ts->input->propbit);

	input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, CT36X_TS_ABS_X_MAX, 0, 0);
	input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, CT36X_TS_ABS_Y_MAX, 0, 0);

	ts->input->name = DRIVER_NAME;
	ts->input->id.bustype =	BUS_I2C;

	/* register input device */
	err = input_register_device(ts->input);
	if ( err ) {
		dev_err(dev, "Unable to register input device for device %s.\n", DRIVER_NAME);
		goto ERR_INPUT_REGIS;
	}

	/* Create work queue */
	INIT_WORK(&ts->event_work, ct36x_ts_workfunc);
	ts->workqueue = create_singlethread_workqueue(dev_name(&client->dev));

	/* Init irq */
	err = request_irq(ts->irq, ct36x_ts_irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, DRIVER_NAME, ts);
	if ( err ) {
		dev_err(dev, "Unable to request irq for device %s.\n", DRIVER_NAME);
		goto ERR_IRQ_REQ;
	}

	/* Set device is ready */
	ts->ready = 1;
	ts->state = CT36X_STATE_NORMAL;

	/* register early suspend */
#ifdef CONFIG_HAS_EARLYSUSPEND
	ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	ts->early_suspend.suspend = ct36x_early_suspend;
	ts->early_suspend.resume = ct36x_early_resume;
	register_early_suspend(&ts->early_suspend);
#endif

	/* power denoisy*/
	//ct36x_chip_set_adapter_on(client, ts->data.buf);
	//ct36x_chip_set_adapter_off(client, ts->data.buf);
	ct36x_ts_adapter(0);
	
	return 0;

	ERR_IRQ_REQ:
	destroy_workqueue(ts->workqueue);
	ERR_INPUT_REGIS:
	input_free_device(ts->input);
	ERR_INPUT_ALLOC:
	ERR_PLAT_RSC:
	ct36x_platform_put_resource(ts);
	ERR_I2C_CHK:
	return err;
}
示例#5
0
int ct36x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
	int err = -1;
	int binchksum;
	int updcnt;
	struct ct36x_ts_info *ts;
	struct device *dev;

	if ( CT36X_TS_CORE_DEBUG )
	printk(">>>>> %s() called <<<<< \n", __FUNCTION__);

	dev = &client->dev;
#ifdef CONFIG_OF
	if (ts_com->owner != NULL) return -ENODEV;
	memset(ts_com, 0 ,sizeof(struct touch_pdata));
	ts_com = (struct touch_pdata*)client->dev.platform_data;
	printk("ts_com->owner = %s\n", ts_com->owner);
	ct36x_platform_get_cfg(&ct36x_ts);
	ct36x_ts.client = client;
	i2c_set_clientdata(client, &ct36x_ts);
	ts_com->hardware_reset = ct36x_hw_reset;
	ts_com->read_version = ct36x_read_version;
	ts_com->upgrade_touch = ct36x_upgrade_touch;
#else
	struct ct36x_platform_data *pdata;
	pdata = dev->platform_data;

	if ( pdata ) {
		ct36x_ts.i2c_address = client->addr;
		ct36x_ts.irq = pdata->irq;
		ct36x_ts.rst = pdata->rst;
		ct36x_ts.ss = pdata->ss;
		ct36x_platform_get_cfg(&ct36x_ts);

		ct36x_ts.client = client;
		i2c_set_clientdata(client, &ct36x_ts);
	} else {
		printk("No platform data for device %s.\n", DRIVER_NAME);
	}
	
	plat_data = dev->platform_data;
#endif
	ts = (struct ct36x_ts_info *)i2c_get_clientdata(client);

	/* Create Proc Entry File */
	//ts->proc_entry = create_proc_entry(DRIVER_NAME, 0666/*S_IFREG | S_IRUGO | S_IWUSR*/, NULL);
	ts->proc_entry = proc_create(DRIVER_NAME, 0666/*S_IFREG | S_IRUGO | S_IWUSR*/, NULL, &ct36x_ts_fops);
	if ( ts->proc_entry == NULL ) {
		dev_err(dev, "Failed creating proc dir entry file.\n");
	}
	//else {
		//ts->proc_entry->proc_fops = &ct36x_ts_fops;
	//}

	/* register early suspend */
#ifdef CONFIG_HAS_EARLYSUSPEND
	ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
	ts->early_suspend.suspend = ct36x_early_suspend;
	ts->early_suspend.resume = ct36x_early_resume;
	register_early_suspend(&ts->early_suspend);
#endif

	/* Check I2C Functionality */
	err = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
	if ( !err ) {
		dev_err(dev, "Check I2C Functionality Failed.\n");
		goto ERR_I2C_CHK;
	}

	/* Request platform resources (gpio/interrupt pins) */
	err = ct36x_platform_get_resource(ts);
	if ( err ) {
		dev_err(dev, "Unable to request platform resource for device %s.\n", DRIVER_NAME);
		goto ERR_PLAT_RSC;
	}

	/* Hardware reset */
	#ifdef CONFIG_OF
	ct36x_platform_hw_reset(ts);
	#else
	ct36x_platform_hw_reset(pdata);
	#endif

	updcnt = 5;
	while (updcnt--) {
		if (ct36x_test_read(client, client->addr, (char *)&binchksum, 1) == 1) 
			break;
	}
	if (updcnt <= 0) {
		printk("ct36x touch not exit!\n");
		goto ERR_PLAT_RSC;
	}
	binchksum = 0;

#ifdef LATE_UPGRADE
	ts_com->upgrade_task = kthread_run(ct36x_late_upgrade, NULL, "ct36x_late_upgrade");
	if (!ts_com->upgrade_task)
		printk("%s creat upgrade process failed\n", __func__);
	else
		printk("%s creat upgrade process sucessful\n", __func__);
#else
	// Get binary Checksum
	binchksum = ct36x_chip_get_binchksum(ts->data.buf);
	if ( CT36X_TS_CORE_DEBUG )
	printk("Bin checksum: 0x%x\n", binchksum);

	// Get firmware Checksum
	fwchksum = ct36x_chip_get_fwchksum(client, ts->data.buf);
	if ( CT36X_TS_CORE_DEBUG )
	printk("Fw checksum: 0x%x\n", fwchksum);
	//while(1){}
	updcnt = 2;
	while ( binchksum != fwchksum && updcnt--) {
		/* Update Firmware */
		ct36x_chip_go_bootloader(client, ts->data.buf);

		/* Hardware reset */
		#ifdef CONFIG_OF
		ct36x_platform_hw_reset(&ct36x_ts);
		#else
		ct36x_platform_hw_reset(plat_data);
		#endif

		// Get firmware Checksum
		fwchksum = ct36x_chip_get_fwchksum(client, ts->data.buf);

		if ( CT36X_TS_CORE_DEBUG )
		printk("Fw checksum: 0x%x\n", fwchksum);
	}
#if defined(CONFIG_TOUCHSCREEN_CT36X_CHIP_CT365)
	ct36x_check_trim(ct36x_ts.client);
#endif
	printk("Fw update %s. 0x%x, 0x%x\n", binchksum != fwchksum ? "Failed" : "Success", binchksum, fwchksum);

	/* Hardware reset */
	#ifdef CONFIG_OF
	ct36x_platform_hw_reset(&ct36x_ts);
	#else
	ct36x_platform_hw_reset(plat_data);
	#endif
#endif
	/* allocate input device */
	ts->input = input_allocate_device();
	if ( !ts->input ) {
		dev_err(dev, "Unable to allocate input device for device %s.\n", DRIVER_NAME);
		err = -ENOMEM;
		goto ERR_INPUT_ALLOC;
	}

	/* config input device */
	__set_bit(EV_SYN, ts->input->evbit);
	__set_bit(EV_KEY, ts->input->evbit);
	__set_bit(EV_ABS, ts->input->evbit);

	__set_bit(INPUT_PROP_DIRECT, ts->input->propbit);
	input_mt_init_slots(ts->input, CT36X_TS_POINT_NUM, 0);

	//input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, CT36X_TS_ABS_X_MAX, 0, 0);
	//input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, CT36X_TS_ABS_Y_MAX, 0, 0);
	#ifdef CONFIG_OF
	if (ts_com->pol & 4)
		swap(ts_com->xres, ts_com->yres);
	input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts_com->xres, 0, 0);
	input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts_com->yres, 0, 0);
	#else
	input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, plat_data->x_max, 0, 0);
	input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, plat_data->y_max, 0, 0);
	#endif
	input_set_abs_params(ts->input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
	input_set_abs_params(ts->input, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
	ts->input->name = DRIVER_NAME;
	ts->input->id.bustype =	BUS_I2C;

	/* register input device */
	err = input_register_device(ts->input);
	if ( err ) {
		dev_err(dev, "Unable to register input device for device %s.\n", DRIVER_NAME);
		goto ERR_INPUT_REGIS;
	}

	/* Create work queue */
	INIT_WORK(&ts->event_work, ct36x_ts_workfunc);
	ts->workqueue = create_singlethread_workqueue(dev_name(&client->dev));

	/* Init irq */
	//gpio_set_status(GPIO_FT_IRQ, gpio_status_in);
  //gpio_irq_set(170, GPIO_IRQ(FT_IRQ-INT_GPIO_0, GPIO_IRQ_FALLING));
	//err = request_irq(ts->irq, ct36x_ts_irq, IRQF_TRIGGER_FALLING | IRQF_ONESHOT, DRIVER_NAME, ts);
	#ifndef CONFIG_OF
	if (pdata->init_gpio) {
  	pdata->init_gpio();
	}
	#endif
	err = request_irq(ts->irq, ct36x_ts_irq, IRQF_DISABLED,  DRIVER_NAME, ts);
	#ifdef LATE_UPGRADE
	disable_irq(ts->irq);
	#endif
	if ( err ) {
		dev_err(dev, "Unable to request irq for device %s.\n", DRIVER_NAME);
		goto ERR_IRQ_REQ;
	}

	/* Set device is ready */
	ts->state = CT36X_STATE_NORMAL;

	/* power denoisy*/
	//ct36x_chip_set_adapter_on(client, ts->data.buf);
	//ct36x_chip_set_adapter_off(client, ts->data.buf);
	//ct36x_ts_adapter(0);
	create_init(client->dev, ts_com);
	printk("%s: over\n",__func__);
	return 0;

	ERR_IRQ_REQ:
	destroy_workqueue(ts->workqueue);
	ERR_INPUT_REGIS:
	input_free_device(ts->input);
	ERR_INPUT_ALLOC:
	ERR_PLAT_RSC:
	ct36x_platform_put_resource(ts);
	ERR_I2C_CHK:
#ifdef CONFIG_HAS_EARLYSUSPEND
	unregister_early_suspend(&ts->early_suspend);
#endif
	remove_proc_entry(DRIVER_NAME, NULL);
	ts_com->owner = NULL;
	return err;
}