1 /* drivers/input/touchscreen/IT7260_ts_i2c.c
3 * Copyright (C) 2007 Google, Inc.
5 * This software is licensed under the terms of the GNU General Public
6 * License version 2, as published by the Free Software Foundation, and
7 * may be copied, distributed, and modified under those terms.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/earlysuspend.h>
19 #include <linux/i2c.h>
20 #include <asm/uaccess.h>
21 #include <linux/input.h>
22 #include <linux/interrupt.h>
24 #include <linux/cdev.h>
25 #include <linux/platform_device.h>
26 #include "IT7260_ts.h"
28 // >>> [110308] protect touch panel [Derek]
29 #include <linux/timer.h>
30 #include <linux/gpio.h>
32 static struct timer_list tp_timer;
33 static void tp_irq_handler_reg(unsigned long arg);
35 // <<< [110308] protect touch panel [Derek]
37 extern void set_tp_status(int number, int status) ;
38 extern int get_tp_status(int number) ;
40 #define IT7260_I2C_NAME "IT7260"
41 #include <linux/gpio.h>
42 static int ite7260_major = 0; // dynamic major by default
43 static int ite7260_minor = 0;
44 static struct cdev ite7260_cdev;
45 static struct class *ite7260_class = NULL;
46 static dev_t ite7260_dev;
47 static struct input_dev *input_dev;
50 #define TS_DEBUG(fmt,args...) printk( KERN_DEBUG "[it7260_i2c]: " fmt, ## args)
51 #define DBG() printk("[%s]:%d => \n",__FUNCTION__,__LINE__)
53 #define TS_DEBUG(fmt,args...)
57 static struct workqueue_struct *IT7260_wq;
59 struct IT7260_ts_data {
60 struct i2c_client *client;
61 struct input_dev *input_dev;
63 struct work_struct work;
64 struct early_suspend early_suspend;
65 uint8_t debug_log_level;
67 #ifdef CONFIG_HAS_EARLYSUSPEND
68 static void IT7260_ts_early_suspend(struct early_suspend *h);
69 static void IT7260_ts_late_resume(struct early_suspend *h);
72 static struct IT7260_ts_data *gl_ts;
74 int i2cReadFromIt7260(struct i2c_client *client, unsigned char bufferIndex,
75 unsigned char dataBuffer[], unsigned short dataLength) {
77 struct i2c_msg msgs[2] = { { .addr = client->addr, .flags = I2C_M_NOSTART,
78 .len = 1, .buf = &bufferIndex }, { .addr = client->addr, .flags =
79 I2C_M_RD, .len = dataLength, .buf = dataBuffer } };
81 memset(dataBuffer, 0xFF, dataLength);
82 ret = i2c_transfer(client->adapter, msgs, 2);
86 int i2cWriteToIt7260(struct i2c_client *client, unsigned char bufferIndex,
87 unsigned char const dataBuffer[], unsigned short dataLength) {
88 unsigned char buffer4Write[256];
89 struct i2c_msg msgs[1] = { { .addr = client->addr, .flags = 0, .len =
90 dataLength + 1, .buf = buffer4Write } };
92 buffer4Write[0] = bufferIndex;
93 memcpy(&(buffer4Write[1]), dataBuffer, dataLength);
94 return i2c_transfer(client->adapter, msgs, 1);
97 static int IdentifyCapSensor(struct IT7260_ts_data *ts);
99 static void Read_Point(struct IT7260_ts_data *ts) {
100 unsigned char ucQuery = 0;
101 unsigned char pucPoint[14];
102 #ifdef HAS_8_BYTES_LIMIT
103 unsigned char cPoint[8];
104 unsigned char ePoint[6];
105 #endif //HAS_8_BYTES_LIMIT
107 int finger2_pressed = 0;
108 int xraw, yraw, xtmp, ytmp;
110 static int x[2] = { (int) -1, (int) -1 };
111 static int y[2] = { (int) -1, (int) -1 };
112 static bool finger[2] = { 0, 0 };
113 static bool flag = 0;
115 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
117 //pr_info("=error Read_Point=\n");
119 enable_irq(ts->client->irq);
122 if (ucQuery & 0x80) {
123 #ifdef HAS_8_BYTES_LIMIT
124 i2cReadFromIt7260(ts->client, 0xC0, cPoint, 8);
125 ret = i2cReadFromIt7260(ts->client, 0xE0, ePoint, 6);
127 pucPoint[i] = ePoint[i];
130 pucPoint[i+6] = cPoint[i];
132 #else //HAS_8_BYTES_LIMIT
133 ret = i2cReadFromIt7260(ts->client, 0xE0, pucPoint, 14);
134 #endif //HAS_8_BYTES_LIMIT
135 //pr_info("=Read_Point read ret[%d]--point[%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]=\n",
136 // ret,pucPoint[0],pucPoint[1],pucPoint[2],
137 // pucPoint[3],pucPoint[4],pucPoint[5],pucPoint[6],pucPoint[7],pucPoint[8],
138 // pucPoint[9],pucPoint[10],pucPoint[11],pucPoint[12],pucPoint[13]);
141 if (pucPoint[0] & 0xF0) {
143 enable_irq(ts->client->irq);
144 //pr_info("(pucPoint[0] & 0xF0) is true, it's a gesture\n") ;
145 //pr_info("pucPoint[0]=%x\n", pucPoint[0]);
149 if (pucPoint[1] & 0x01) {
151 enable_irq(ts->client->irq);
152 //pr_info("pucPoint 1 is 0x01, it's a palm\n") ;
156 if (!(pucPoint[0] & 0x08)) {
158 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 1);
159 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
160 //input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, pressure_point);
161 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
162 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x[0]);
163 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y[0]);
164 input_mt_sync(ts->input_dev);
169 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 2);
170 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
171 //input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, pressure_point);
172 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
173 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x[1]);
174 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y[1]);
175 input_mt_sync(ts->input_dev);
180 input_sync(ts->input_dev);
184 enable_irq(ts->client->irq);
185 //pr_info("(pucPoint[0] & 0x08) is false, means no more data\n") ;
189 if (pucPoint[0] & 0x04) {
191 enable_irq(ts->client->irq);
192 //pr_info("(pucPoint[0] & 0x04) is true, we don't support three fingers\n") ;
196 if (pucPoint[0] & 0x01) {
197 char pressure_point, z, w;
199 xraw = ((pucPoint[3] & 0x0F) << 8) + pucPoint[2];
200 yraw = ((pucPoint[3] & 0xF0) << 4) + pucPoint[4];
202 pressure_point = pucPoint[5] & 0x0f;
203 //pr_info("=Read_Point1 x=%d y=%d p=%d=\n",xraw,yraw,pressure_point);
205 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 1);
206 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1);
207 //input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, pressure_point);
208 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
209 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, xraw);
210 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, yraw);
211 input_mt_sync(ts->input_dev);
215 //pr_info("=input Read_Point1 x=%d y=%d p=%d=\n",xraw,yraw,pressure_point);
217 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 1);
218 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
219 //input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, pressure_point);
220 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
221 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x[0]);
222 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y[0]);
223 input_mt_sync(ts->input_dev);
227 if (pucPoint[0] & 0x02) {
228 char pressure_point, z, w;
229 xraw = ((pucPoint[7] & 0x0F) << 8) + pucPoint[6];
230 yraw = ((pucPoint[7] & 0xF0) << 4) + pucPoint[8];
232 pressure_point = pucPoint[9] & 0x0f;
234 //pr_info("=Read_Point2 x=%d y=%d p=%d=\n",xraw,yraw,pressure_point);
235 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 2);
236 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1);
237 //input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, pressure_point);
238 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
239 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, xraw);
240 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, yraw);
241 input_mt_sync(ts->input_dev);
245 //pr_info("input Read_Point2 x=%d y=%d p=%d=\n",xraw,yraw,pressure_point);
247 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 2);
248 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
249 //input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, pressure_point);
250 input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
251 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x[1]);
252 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y[1]);
253 input_mt_sync(ts->input_dev);
256 input_sync(ts->input_dev);
261 enable_irq(ts->client->irq);
262 //pr_info("=end Read_Point=\n");
264 //IdentifyCapSensor(gl_ts);
267 ///////////////////////////////////////////////////////////////////////////////////////
269 static void IT7260_ts_work_func(struct work_struct *work) {
273 struct i2c_msg msg[2];
276 //printk(KERN_INFO "=IT7260_ts_work_func=\n");
277 struct IT7260_ts_data *ts = container_of(work, struct IT7260_ts_data, work);
282 // >>> [110308] protect touch panel [Derek]
284 static irqreturn_t IT7260_ts_irq_handler(int irq, void *dev_id) {
285 struct IT7260_ts_data *ts = dev_id;
289 pr_info("=IT7260_ts_irq_handler=\n");
292 disable_irq_nosync(ts->client->irq);
293 queue_work(IT7260_wq, &ts->work);
296 // <<< [110308] protect touch panel [Derek]
298 /////////////////////////////////////////////////////////
299 void sendCalibrationCmd(void) {
301 struct IT7260_ts_data *ts = gl_ts;
302 unsigned char data[] = { 0x13, 0x00, 0x00, 0x00, 0x00 };
303 unsigned char resp[2];
305 ret = i2cWriteToIt7260(ts->client, 0x20, data, 5);
306 printk(KERN_INFO "IT7260 sent calibration command [%d]!!!\n", ret);
308 //MUST sleep 5 seconds here!
311 //Read out response to clear interrupt.
312 i2cReadFromIt7260(ts->client, 0xA0, resp, 2);
315 EXPORT_SYMBOL( sendCalibrationCmd);
317 // >>> [110308] protect touch panel [Derek]
318 static void tp_irq_handler_reg(unsigned long arg)
322 // <<< [110308] protect touch panel [Derek]
324 static int IdentifyCapSensor(struct IT7260_ts_data *ts) {
325 unsigned char ucQuery;
326 unsigned char pucCmd[80];
328 int test_read_count = 0;
329 //pr_info("=entry IdentifyCapSensor=\n");
330 //pr_info("=entry IdentifyCapSensor---name[%s]---addr[%x]-flags[%d]=\n",ts->client->name,ts->client->addr,ts->client->flags);
331 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
332 //pr_info("=IdentifyCapSensor read 0x80 =%d=\n",ucQuery);
337 while (ucQuery & 0x01) {
338 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
343 //pr_info("=IdentifyCapSensor write cmd=\n");
345 ret = i2cWriteToIt7260(ts->client, 0x20, pucCmd, 1);
347 printk(KERN_ERR "i2c_smbus_write_byte_data failed\n");
352 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
357 while ((ucQuery & 0x01) && (test_read_count < 0x2000)) {
359 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
364 //pr_info("=IdentifyCapSensor write read id=\n");
365 ret = i2cReadFromIt7260(ts->client, 0xA0, pucCmd, 8);
367 // "=IdentifyCapSensor read id--[%d][%x][%x][%x][%x][%x][%x][%x][%x][%x][%x]=\n",
368 // ret, pucCmd[0], pucCmd[1], pucCmd[2], pucCmd[3], pucCmd[4],
369 // pucCmd[5], pucCmd[6], pucCmd[7], pucCmd[8], pucCmd[9]);
373 static int IT7260_ts_probe(struct i2c_client *client,
374 const struct i2c_device_id *id) {
375 struct IT7260_ts_data *ts;
377 struct IT7260_i2c_platform_data *pdata;
378 unsigned long irqflags;
379 unsigned char ucQuery = 0;
380 u8 cmdbuf[2] = { 0x07, 0 };
382 irqflags = IRQF_TRIGGER_HIGH;
383 pr_info("=entry IT7260_ts_probe=\n");
385 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
386 printk(KERN_ERR "IT7260_ts_probe: need I2C_FUNC_I2C\n");
388 goto err_check_functionality_failed;
390 ts = kzalloc(sizeof(*ts), GFP_KERNEL);
393 goto err_check_functionality_failed;
397 ts->debug_log_level = 0x3;
398 ts->input_dev = input_dev;
400 i2c_set_clientdata(client, ts);
401 pdata = client->dev.platform_data;
404 //ret=IdentifyCapSensor(ts);
406 // goto err_power_failed;
408 // Ant start -- to identify if this device is exist
409 if (get_tp_status(1) == 0)
411 printk(KERN_ERR "The ite TP device is not exist\n");
413 goto err_power_failed;
415 set_tp_status(1, 1) ;
420 #ifdef CONFIG_HAS_EARLYSUSPEND
421 ts->early_suspend.level = EARLY_SUSPEND_LEVEL_STOP_DRAWING - 1;
422 ts->early_suspend.suspend = IT7260_ts_early_suspend;
423 ts->early_suspend.resume = IT7260_ts_late_resume;
424 register_early_suspend(&ts->early_suspend);
427 //IT7260_wq = create_singlethread_workqueue("IT7260_wq");
428 IT7260_wq = create_workqueue("IT7260_wq");
430 goto err_check_functionality_failed;
431 INIT_WORK(&ts->work, IT7260_ts_work_func);
433 // >>> [110308] protect touch panel [Derek]
434 init_timer(&tp_timer) ;
436 tp_timer.expires = jiffies + 30 * HZ;
437 tp_timer.function = &tp_irq_handler_reg;
439 add_timer(&tp_timer);
440 // >>> [110308] protect touch panel [Derek]
442 pr_info("IT7260_ts_probe-client->irq[%d]=\n", client->irq);
444 ret = request_irq(client->irq, IT7260_ts_irq_handler, IRQF_TRIGGER_LOW,
445 // ret = request_irq(client->irq, IT7260_ts_irq_handler, IRQF_DISABLED | IRQF_TRIGGER_LOW,
446 // ret = request_irq(client->irq, IT7260_ts_irq_handler, IRQF_SHARED | IRQF_TRIGGER_LOW,
448 pr_info("IT7260_ts_probe-request_irq[%d]=\n", ret);
452 dev_err(&client->dev, "request_irq failed\n");
456 pr_info("=end IT7260_ts_probe=\n");
458 //To reset point queue.
459 i2cWriteToIt7260(ts->client, 0x20, cmdbuf, 1);
461 i2cReadFromIt7260(ts->client, 0xA0, cmdbuf, 2);
465 err_power_failed: kfree(ts);
467 err_check_functionality_failed: return ret;
471 static int IT7260_ts_remove(struct i2c_client *client) {
475 static int IT7260_ts_suspend(struct i2c_client *client, pm_message_t mesg) {
477 u8 cmdbuf[] = { 0x04, 0x00, 0x02 };
479 printk(KERN_DEBUG "IT7260_ts_i2c call suspend\n");
480 if (i2cWriteToIt7260(client, 0x20, cmdbuf, 3) >= 0)
488 static int IT7260_ts_resume(struct i2c_client *client) {
489 unsigned char ucQuery;
491 printk(KERN_DEBUG "IT7260_ts_i2c call resume\n");
492 #ifdef INT_PIN_OPEN_DRAIN
493 //TODO: Here 2 is the pin number of INT pin, so please modify it to the one your system uses.
494 gpio_direction_output(2, 0);
496 #endif //INT_PIN_OPEN_DRAIN
497 i2cReadFromIt7260(client, 0x80, &ucQuery, 1);
498 #ifdef INT_PIN_OPEN_DRAIN
500 gpio_direction_output(2, 1);
502 gpio_direction_input(2);
503 #endif //INT_PIN_OPEN_DRAIN
507 #ifdef CONFIG_HAS_EARLYSUSPEND
508 static void IT7260_ts_early_suspend(struct early_suspend *h)
510 struct IT7260_ts_data *ts;
511 ts = container_of(h, struct IT7260_ts_data, early_suspend);
512 IT7260_ts_suspend(ts->client, PMSG_SUSPEND);
515 static void IT7260_ts_late_resume(struct early_suspend *h)
517 struct IT7260_ts_data *ts;
518 ts = container_of(h, struct IT7260_ts_data, early_suspend);
519 IT7260_ts_resume(ts->client);
523 static const struct i2c_device_id IT7260_ts_id[] = { { IT7260_I2C_NAME, 0 },
526 bool IT7260_Init(void) {
529 unsigned char ucQuery = 0;
530 unsigned char buffer[128];
531 struct IT7260_ts_data *ts = gl_ts;
533 // Identify Cap Sensor
535 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
536 } while (ucQuery & 0x01);
538 i2cWriteToIt7260(ts->client, 0x20, buffer, 1);
540 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
541 } while (ucQuery & 0x01);
543 memset(&buffer, 0, sizeof(buffer));
544 i2cReadFromIt7260(ts->client, 0xA0, buffer, 8);
545 pr_info("=IT7260_Init --[%x][%x][%x][%x][%x][%x]=\n", buffer[0], buffer[1],
546 buffer[2], buffer[3], buffer[4], buffer[5]);
547 if (buffer[1] != 'I' || buffer[2] != 'T' || buffer[3] != 'E') {
551 // Get firmware information
553 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
554 } while (ucQuery & 0x01);
557 i2cWriteToIt7260(ts->client, 0x20, buffer, 2);
559 i2cReadFromIt7260(ts->client, 0x80, &ucQuery, 1);
560 } while (ucQuery & 0x01);
561 memset(&buffer, 0, sizeof(buffer));
562 i2cReadFromIt7260(ts->client, 0xA0, buffer, 8);
564 //for (i = 5; i < 9; i++) {
565 for (i = 5; i < 8; i++) {
572 //// Reinitialize Firmware
573 //set_ite_i2c_nostop(1);
575 // ucQuery = i2c_smbus_read_byte_data(ts->client, 0x80);
576 //} while (ucQuery & 0x01);
578 //set_ite_i2c_nostop(0);
579 //i2c_smbus_write_byte_data(ts->client, 0x20, buffer[0]);
584 static struct i2c_driver IT7260_ts_driver = { .probe = IT7260_ts_probe,
585 .remove = IT7260_ts_remove,
586 #ifndef CONFIG_HAS_EARLYSUSPEND
587 .suspend = IT7260_ts_suspend, .resume = IT7260_ts_resume,
589 .id_table = IT7260_ts_id, .driver = { .name = "IT7260-ts", }, };
591 struct ite7260_data {
593 unsigned short bufferIndex;
594 unsigned short length;
595 unsigned short buffer[MAX_BUFFER_SIZE];
598 int ite7260_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
600 struct ite7260_data *dev = filp->private_data;
603 unsigned char ucQuery;
604 unsigned char buffer[MAX_BUFFER_SIZE];
605 struct ioctl_cmd168 data;
606 unsigned char datalen;
607 unsigned char ent[] = {0x60, 0x00, 0x49, 0x54, 0x37, 0x32};
608 unsigned char ext[] = {0x60, 0x80, 0x49, 0x54, 0x37, 0x32};
610 //pr_info("=ite7260_ioctl=\n");
611 memset(&data, 0, sizeof(struct ioctl_cmd168));
615 //pr_info("=IOCTL_SET=\n");
616 if (!access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd))) {
621 if ( copy_from_user(&data, (int __user *)arg, sizeof(struct ioctl_cmd168)) ) {
625 buffer[0] = (unsigned char) data.bufferIndex;
626 //pr_info("%.2X ", buffer[0]);
627 for (i = 1; i < data.length + 1; i++) {
628 buffer[i] = (unsigned char) data.buffer[i - 1];
629 //pr_info("%.2X ", buffer[i]);
631 if (!memcmp(&(buffer[1]), ent, sizeof(ent))) {
633 pr_info("Disabling IRQ.\n");
635 disable_irq(gl_ts->client->irq);
639 if (!memcmp(&(buffer[1]), ext, sizeof(ext))) {
641 pr_info("Enabling IRQ.\n");
643 enable_irq(gl_ts->client->irq);
647 //pr_info("=================================================\n");
648 //pr_info("name[%s]---addr[%x]-flags[%d]=\n",gl_ts->client->name,gl_ts->client->addr,gl_ts->client->flags);
649 datalen = (unsigned char) (data.length + 1);
650 //pr_info("datalen=%d\n", datalen);
651 //write_lock(&dev->lock);
652 retval = i2cWriteToIt7260(gl_ts->client,
653 (unsigned char) data.bufferIndex, &(buffer[1]), datalen - 1);
654 //write_unlock(&dev->lock);
655 //pr_info("SET:retval=%x\n", retval);
660 //pr_info("=IOCTL_GET=\n");
661 if (!access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd))) {
666 if (!access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd))) {
671 //pr_info("sizeof(struct ioctl_cmd168)=%d\n", sizeof(struct ioctl_cmd168));
672 if ( copy_from_user(&data, (int __user *)arg, sizeof(struct ioctl_cmd168)) ) {
677 //pr_info("=================================================\n");
678 //pr_info("name[%s]---addr[%x]-flags[%d]=\n",gl_ts->client->name,gl_ts->client->addr,gl_ts->client->flags);
679 //read_lock(&dev->lock);
680 retval = i2cReadFromIt7260(gl_ts->client,
681 (unsigned char) data.bufferIndex, (unsigned char*) buffer,
682 (unsigned char) data.length);
683 //read_unlock(&dev->lock);
684 //pr_info("GET:retval=%x\n", retval);
686 for (i = 0; i < data.length; i++) {
687 data.buffer[i] = (unsigned short) buffer[i];
689 //pr_info("GET:bufferIndex=%x, dataLength=%d, buffer[0]=%x, buffer[1]=%x, buffer[2]=%x, buffer[3]=%x\n", data.bufferIndex, data.length, buffer[0], buffer[1], buffer[2], buffer[3]);
690 //pr_info("GET:bufferIndex=%x, dataLength=%d, buffer[0]=%x, buffer[1]=%x, buffer[2]=%x, buffer[3]=%x\n", data.bufferIndex, data.length, data.buffer[0], data.buffer[1], data.buffer[2], data.buffer[3]);
691 //if (data.bufferIndex == 0x80)
692 // data.buffer[0] = 0x00;
693 if ( copy_to_user((int __user *)arg, &data, sizeof(struct ioctl_cmd168)) ) {
705 //pr_info("DONE! retval=%d\n", retval);
709 int ite7260_open(struct inode *inode, struct file *filp) {
711 struct ite7260_data *dev;
713 pr_info("=ite7260_open=\n");
714 dev = kmalloc(sizeof(struct ite7260_data), GFP_KERNEL);
719 /* initialize members */
720 rwlock_init(&dev->lock);
721 for (i = 0; i < MAX_BUFFER_SIZE; i++) {
722 dev->buffer[i] = 0xFF;
725 filp->private_data = dev;
727 return 0; /* success */
730 int ite7260_close(struct inode *inode, struct file *filp) {
731 struct ite7260_data *dev = filp->private_data;
737 return 0; /* success */
740 struct file_operations ite7260_fops = { .owner = THIS_MODULE, .open =
741 ite7260_open, .release = ite7260_close, .ioctl = ite7260_ioctl, };
743 static int __devinit IT7260_ts_init(void) {
744 dev_t dev = MKDEV(ite7260_major, 0);
748 struct device *class_dev = NULL;
752 // if(!IT7260_Init()) {
753 // TS_DEBUG("IT7260 cannot be connected or is in firmware upgrade mode.\n");
757 alloc_ret = alloc_chrdev_region(&dev, 0, 1, DEVICE_NAME);
759 TS_DEBUG("IT7260 cdev can't get major number\n");
762 ite7260_major = MAJOR(dev);
764 // allocate the character device
765 cdev_init(&ite7260_cdev, &ite7260_fops);
766 ite7260_cdev.owner = THIS_MODULE;
767 ite7260_cdev.ops = &ite7260_fops;
768 cdev_err = cdev_add(&ite7260_cdev, MKDEV(ite7260_major, ite7260_minor), 1);
774 ite7260_class = class_create(THIS_MODULE, DEVICE_NAME);
775 if(IS_ERR(ite7260_class)) {
776 TS_DEBUG("Err: failed in creating class.\n");
780 ite7260_dev = MKDEV(ite7260_major, ite7260_minor);
781 class_dev = device_create(ite7260_class, NULL, ite7260_dev, NULL, DEVICE_NAME);
782 if(class_dev == NULL)
784 TS_DEBUG("Err: failed in creating device.\n");
787 TS_DEBUG("=========================================\n");
788 TS_DEBUG("register IT7260 cdev, major: %d, minor: %d \n", ite7260_major, ite7260_minor);
789 TS_DEBUG("=========================================\n");
791 input_dev = input_allocate_device();
792 if (input_dev == NULL) {
794 printk(KERN_ERR "IT7260_ts_probe: Failed to allocate input device\n");
797 input_dev->name = "IT7260";
798 input_dev->phys = "I2C";
799 input_dev->id.bustype = BUS_I2C;
800 input_dev->id.vendor = 0x0001;
801 input_dev->id.product = 0x7260;
802 //set_bit(EV_SYN, input_dev->evbit);
803 //set_bit(EV_KEY, input_dev->evbit);
804 set_bit(EV_ABS, input_dev->evbit);
805 //set_bit(BTN_TOUCH, input_dev->keybit);
806 //set_bit(BTN_2, input_dev->keybit);
808 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, 1024, 0, 0);
809 input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, 600, 0, 0);
810 input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, 2, 0, 0);
811 input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 15, 0, 0);
812 input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 2, 0, 0);
813 input_set_abs_params(input_dev, ABS_X, 0, 1024, 0, 0);
814 input_set_abs_params(input_dev, ABS_Y, 0, 600, 0, 0);
815 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 1, 0, 0);
816 input_err = input_register_device(input_dev);
817 if (input_err) goto error;
818 pr_info("it7260 driver is on###############################################################\n");
820 return i2c_add_driver(&IT7260_ts_driver);
824 cdev_del(&ite7260_cdev);
827 unregister_chrdev_region(dev, 1);
830 input_free_device(input_dev);
833 destroy_workqueue(IT7260_wq);
838 static void __exit IT7260_ts_exit(void) {
839 dev_t dev = MKDEV(ite7260_major, ite7260_minor);
842 device_destroy(ite7260_class, ite7260_dev);
843 class_destroy(ite7260_class);
845 // unregister driver handle
846 cdev_del(&ite7260_cdev);
847 unregister_chrdev_region(dev, 1);
849 i2c_del_driver(&IT7260_ts_driver);
851 destroy_workqueue(IT7260_wq);
854 module_init( IT7260_ts_init);
855 module_exit( IT7260_ts_exit);
857 MODULE_DESCRIPTION("IT7260 Touchscreen Driver");
858 MODULE_LICENSE("GPL");