3 * Touch Screen I2C Driver for EETI Controller
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 // Release Date: 2010/11/08
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/kernel.h>
22 #include <linux/interrupt.h>
23 #include <linux/wait.h>
24 #include <linux/delay.h>
25 #include <linux/platform_device.h>
26 #include <linux/freezer.h>
27 #include <linux/proc_fs.h>
28 #include <linux/clk.h>
29 #include <linux/i2c.h>
30 #include <linux/gpio.h>
31 #include <linux/device.h>
32 #include <linux/cdev.h>
34 #include <asm/system.h>
35 #include <asm/uaccess.h>
36 #include <linux/poll.h>
37 #include <linux/kfifo.h>
38 #include <linux/version.h>
39 #include <linux/input.h>
40 #include <linux/irq.h>
41 #include <linux/async.h>
42 #include <mach/board.h>
45 #ifdef CONFIG_EETI_EGALAX_DEBUG
46 #define TS_DEBUG(fmt,args...) printk( KERN_DEBUG "[egalax_i2c]: " fmt, ## args)
47 #define DBG() printk("[%s]:%d => \n",__FUNCTION__,__LINE__)
49 #define TS_DEBUG(fmt,args...)
53 //#define _NON_INPUT_DEV // define this to disable register input device
55 static int global_major = 0; // dynamic major by default
56 static int global_minor = 0;
57 #define EETI_I2C_RATE (200*1000)
58 #define MAX_I2C_LEN 10
59 #define FIFO_SIZE PAGE_SIZE
60 #define MAX_SUPPORT_POINT 5
61 #define REPORTID_MOUSE 0x01
62 #define REPORTID_VENDOR 0x03
63 #define REPORTID_MTOUCH 0x04
66 #define EGALAX_IOC_MAGIC 0x72
67 #define EGALAX_IOCWAKEUP _IO(EGALAX_IOC_MAGIC, 1)
68 #define EGALAX_IOC_MAXNR 1
77 struct workqueue_struct *ktouch_wq;
78 struct work_struct work;
79 struct mutex mutex_wq;
80 struct i2c_client *client;
86 struct egalax_char_dev
90 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
91 struct kfifo* pDataKFiFo;
93 struct kfifo DataKFiFo;
95 unsigned char *pFiFoBuf;
98 wait_queue_head_t fifo_inq;
101 static struct _egalax_i2c *p_egalax_i2c_dev = NULL; // allocated in egalax_i2c_probe
102 static struct egalax_char_dev *p_char_dev = NULL; // allocated in init_module
103 static atomic_t egalax_char_available = ATOMIC_INIT(1);
104 static struct class *egalax_class;
105 #ifndef _NON_INPUT_DEV
106 static struct input_dev *input_dev = NULL;
107 static struct point_data PointBuf[MAX_SUPPORT_POINT];
108 #endif //#ifndef _NON_INPUT_DEV
110 static int egalax_cdev_open(struct inode *inode, struct file *filp)
112 struct egalax_char_dev *cdev;
116 cdev = container_of(inode->i_cdev, struct egalax_char_dev, cdev);
119 TS_DEBUG(" No such char device node \n");
123 if( !atomic_dec_and_test(&egalax_char_available) )
125 atomic_inc(&egalax_char_available);
126 return -EBUSY; /* already open */
130 filp->private_data = cdev;// Used by the read and write metheds
132 TS_DEBUG(" egalax_cdev_open done \n");
133 try_module_get(THIS_MODULE);
137 static int egalax_cdev_release(struct inode *inode, struct file *filp)
139 struct egalax_char_dev *cdev; // device information
143 cdev = container_of(inode->i_cdev, struct egalax_char_dev, cdev);
146 TS_DEBUG(" No such char device node \n");
150 atomic_inc(&egalax_char_available); /* release the device */
152 filp->private_data = NULL;
154 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
155 kfifo_reset( cdev->pDataKFiFo );
157 kfifo_reset( &cdev->DataKFiFo );
160 TS_DEBUG(" egalax_cdev_release done \n");
161 module_put(THIS_MODULE);
165 #define MAX_READ_BUF_LEN 50
166 static char fifo_read_buf[MAX_READ_BUF_LEN];
167 static ssize_t egalax_cdev_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
169 int read_cnt, ret, fifoLen;
170 struct egalax_char_dev *cdev = file->private_data;
174 if( down_interruptible(&cdev->sem) )
177 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
178 fifoLen = kfifo_len(cdev->pDataKFiFo);
180 fifoLen = kfifo_len(&cdev->DataKFiFo);
183 while( fifoLen<1 ) /* nothing to read */
185 up(&cdev->sem); /* release the lock */
186 if( file->f_flags & O_NONBLOCK )
189 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
190 if( wait_event_interruptible(cdev->fifo_inq, kfifo_len( cdev->pDataKFiFo )>0) )
192 if( wait_event_interruptible(cdev->fifo_inq, kfifo_len( &cdev->DataKFiFo )>0) )
195 return -ERESTARTSYS; /* signal: tell the fs layer to handle it */
198 if( down_interruptible(&cdev->sem) )
202 if(count > MAX_READ_BUF_LEN)
203 count = MAX_READ_BUF_LEN;
205 TS_DEBUG("\"%s\" reading: real fifo data\n", current->comm);
206 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
207 read_cnt = kfifo_get(cdev->pDataKFiFo, fifo_read_buf, count);
209 read_cnt = kfifo_out_locked(&cdev->DataKFiFo, fifo_read_buf, count, &cdev->FiFoLock);
212 ret = copy_to_user(buf, fifo_read_buf, read_cnt)?-EFAULT:read_cnt;
219 static ssize_t egalax_cdev_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
222 struct egalax_char_dev *cdev = file->private_data;
227 if( down_interruptible(&cdev->sem) )
230 if (count > MAX_I2C_LEN)
233 tmp = kmalloc(count,GFP_KERNEL);
240 if(copy_from_user(tmp, buf, count))
247 ret = i2c_master_normal_send(p_egalax_i2c_dev->client, tmp, count,EETI_I2C_RATE);
248 TS_DEBUG("I2C writing %zu bytes.\n", count);
257 static int wakeup_controller(int gpio)
263 if( (ret=gpio_request(gpio, "Touch Wakeup GPIO"))!=0 )
265 printk(KERN_ERR "[egalax_i2c]: Failed to request GPIO for Touch Wakeup GPIO. Err:%d\n", ret);
270 gpio_direction_output(gpio, 0);
271 for(i=0; i<100; i++);
272 gpio_direction_input(gpio);
273 printk(KERN_ERR "[egalax_i2c]: INT wakeup touch controller done\n");
279 static int egalax_cdev_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long args)
281 //struct egalax_char_dev *cdev = file->private_data;
284 if(_IOC_TYPE(cmd) != EGALAX_IOC_MAGIC)
286 if(_IOC_NR(cmd) > EGALAX_IOC_MAXNR)
289 if(_IOC_DIR(cmd) & _IOC_READ)
290 ret = !access_ok(VERIFY_WRITE, (void __user*)args, _IOC_SIZE(cmd));
291 else if(_IOC_DIR(cmd) & _IOC_WRITE)
292 ret = !access_ok(VERIFY_READ, (void __user*)args, _IOC_SIZE(cmd));
297 //printk(KERN_ERR "Handle device ioctl command\n");
300 case EGALAX_IOCWAKEUP:
301 ret = wakeup_controller(irq_to_gpio(p_egalax_i2c_dev->irq));
311 static unsigned int egalax_cdev_poll(struct file *filp, struct poll_table_struct *wait)
313 struct egalax_char_dev *cdev = filp->private_data;
314 unsigned int mask = 0;
318 poll_wait(filp, &cdev->fifo_inq, wait);
320 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
321 fifoLen = kfifo_len(cdev->pDataKFiFo);
323 fifoLen = kfifo_len(&cdev->DataKFiFo);
327 mask |= POLLIN | POLLRDNORM; /* readable */
328 if( (FIFO_SIZE - fifoLen) > MAX_I2C_LEN )
329 mask |= POLLOUT | POLLWRNORM; /* writable */
335 #ifndef _NON_INPUT_DEV
336 static int LastUpdateID = 0;
337 static void ProcessReport(unsigned char *buf, int buflen)
340 short X=0, Y=0, ContactID=0, Status=0;
341 if(buflen!=MAX_I2C_LEN || buf[0]!=0x04) // check buffer len & header
344 Status = buf[1]&0x01;
345 ContactID = (buf[1]&0x7C)>>2;
346 X = ((buf[3]<<8) + buf[2])>>4;
347 Y = ((buf[5]<<8) + buf[4])>>4;
349 PointBuf[ContactID].Status = Status;
350 PointBuf[ContactID].X = X;
351 PointBuf[ContactID].Y = Y;
353 TS_DEBUG("Get Point[%d] Update: Status=%d X=%d Y=%d\n", ContactID, Status, X, Y);
356 if( !Status || (ContactID <= LastUpdateID) )
358 for(i=0; i<MAX_SUPPORT_POINT;i++)
360 if(PointBuf[i].Status >= 0)
362 input_report_abs(input_dev, ABS_MT_TRACKING_ID, i);
363 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, PointBuf[i].Status);
364 input_report_abs(input_dev, ABS_MT_WIDTH_MAJOR, 0);
365 input_report_abs(input_dev, ABS_MT_POSITION_X, PointBuf[i].X);
366 input_report_abs(input_dev, ABS_MT_POSITION_Y, PointBuf[i].Y);
368 input_mt_sync(input_dev);
370 if(PointBuf[i].Status == 0)
371 PointBuf[i].Status--;
374 input_sync(input_dev);
375 TS_DEBUG("Input sync point data done!\n");
378 LastUpdateID = ContactID;
381 static struct input_dev * allocate_Input_Dev(void)
384 struct input_dev *pInputDev=NULL;
386 pInputDev = input_allocate_device();
387 if(pInputDev == NULL)
389 TS_DEBUG("Failed to allocate input device\n");
390 return NULL;//-ENOMEM;
393 pInputDev->name = "eGalax Touch Screen";
394 pInputDev->phys = "I2C";
395 pInputDev->id.bustype = BUS_I2C;
396 pInputDev->id.vendor = 0x0EEF;
397 pInputDev->id.product = 0x0020;
399 set_bit(EV_ABS, pInputDev->evbit);
401 input_set_abs_params(pInputDev, ABS_MT_POSITION_X, 0, CONFIG_EETI_EGALAX_MAX_X, 0, 0);
402 input_set_abs_params(pInputDev, ABS_MT_POSITION_Y, 0, CONFIG_EETI_EGALAX_MAX_Y, 0, 0);
403 input_set_abs_params(pInputDev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);
404 input_set_abs_params(pInputDev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
405 input_set_abs_params(pInputDev, ABS_MT_TRACKING_ID, 0, 10, 0, 0);
407 ret = input_register_device(pInputDev);
410 TS_DEBUG("Unable to register input device.\n");
411 input_free_device(pInputDev);
417 #endif //#ifndef _NON_INPUT_DEV
419 static int egalax_i2c_measure(struct i2c_client *client, char skip_packet)
421 u8 x_buf[MAX_I2C_LEN];
425 count = i2c_master_normal_recv(client, x_buf, MAX_I2C_LEN,EETI_I2C_RATE);
426 }while(count==EAGAIN && --loop);
428 if( count<0 || (x_buf[0]!=REPORTID_VENDOR && x_buf[0]!=REPORTID_MTOUCH) )
430 TS_DEBUG("I2C read error data with Len=%d hedaer=%d\n", count, x_buf[0]);
434 TS_DEBUG("egalax_i2c read data with Len=%d\n", count);
435 if(x_buf[0]==REPORTID_VENDOR)
436 TS_DEBUG("egalax_i2c get command packet\n");
438 if( skip_packet > 0 )
441 #ifndef _NON_INPUT_DEV
442 if( count>0 && x_buf[0]==REPORTID_MTOUCH )
444 ProcessReport(x_buf, count);
448 #endif //#ifndef _NON_INPUT_DEV
450 if( count>0 && p_char_dev->OpenCnts>0 ) // If someone reading now! put the data into the buffer!
452 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
453 kfifo_put(p_char_dev->pDataKFiFo, x_buf, count);
455 kfifo_in_locked(&p_char_dev->DataKFiFo, x_buf, count, &p_char_dev->FiFoLock);
457 wake_up_interruptible( &p_char_dev->fifo_inq );
463 static void egalax_i2c_wq(struct work_struct *work)
465 struct _egalax_i2c *egalax_i2c = container_of(work, struct _egalax_i2c, work);
466 struct i2c_client *client = egalax_i2c->client;
467 int gpio = client->irq;
468 TS_DEBUG("egalax_i2c_wq run\n");
469 mutex_lock(&egalax_i2c->mutex_wq);
471 /*continue recv data*/
472 while( !gpio_get_value(gpio) && egalax_i2c->work_state>0 )
474 egalax_i2c_measure(client, egalax_i2c->skip_packet);
475 schedule_timeout_interruptible(HZ/100);
478 #ifndef _NON_INPUT_DEV
479 if (gpio_get_value(gpio) && egalax_i2c->work_state > 0 && !egalax_i2c->skip_packet) {
481 for(i = 0; i < MAX_SUPPORT_POINT; i++) {
482 if (PointBuf[i].Status > 0) {
483 TS_DEBUG("point %d still down\n", i);
484 input_report_abs(input_dev, ABS_MT_TRACKING_ID, i);
485 input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, 0);
486 input_report_abs(input_dev, ABS_MT_WIDTH_MAJOR, 0);
487 input_report_abs(input_dev, ABS_MT_POSITION_X, PointBuf[i].X);
488 input_report_abs(input_dev, ABS_MT_POSITION_Y, PointBuf[i].Y);
490 input_mt_sync(input_dev);
491 PointBuf[i].Status = 0;
496 input_sync(input_dev);
500 if( egalax_i2c->skip_packet > 0 )
501 egalax_i2c->skip_packet = 0;
503 mutex_unlock(&egalax_i2c->mutex_wq);
505 if( egalax_i2c->work_state > 0 )
506 enable_irq(p_egalax_i2c_dev->irq);
508 TS_DEBUG("egalax_i2c_wq leave\n");
511 static irqreturn_t egalax_i2c_interrupt(int irq, void *dev_id)
513 struct _egalax_i2c *egalax_i2c = (struct _egalax_i2c *)dev_id;
514 TS_DEBUG("egalax_i2c_interrupt with irq:%d\n", irq);
515 disable_irq_nosync(irq);
516 queue_work(egalax_i2c->ktouch_wq, &egalax_i2c->work);
522 void egalax_i2c_set_standby(struct i2c_client *client, int enable)
524 struct eeti_egalax_platform_data *mach_info = client->dev.platform_data;
525 unsigned display_on = mach_info->disp_on_pin;
526 unsigned lcd_standby = mach_info->standby_pin;
528 int display_on_pol = mach_info->disp_on_value;
529 int lcd_standby_pol = mach_info->standby_value;
531 printk("%s : %s, enable = %d", __FILE__, __FUNCTION__,enable);
532 if(display_on != INVALID_GPIO)
534 gpio_direction_output(display_on, 0);
535 gpio_set_value(display_on, enable ? display_on_pol : !display_on_pol);
537 if(lcd_standby != INVALID_GPIO)
539 gpio_direction_output(lcd_standby, 0);
540 gpio_set_value(lcd_standby, enable ? lcd_standby_pol : !lcd_standby_pol);
545 static int egalax_i2c_suspend(struct i2c_client *client, pm_message_t mesg)
547 struct _egalax_i2c *egalax_i2c = i2c_get_clientdata(client);
548 u8 cmdbuf[MAX_I2C_LEN]={0x03, 0x05, 0x0A, 0x03, 0x36, 0x3F, 0x02, 0, 0, 0};
550 i2c_master_normal_send(client, cmdbuf, MAX_I2C_LEN, EETI_I2C_RATE);
552 egalax_i2c->work_state = 0;
553 disable_irq(p_egalax_i2c_dev->irq);
554 cancel_work_sync(&egalax_i2c->work);
556 printk(KERN_DEBUG "[egalax_i2c]: device suspend done\n");
558 if(device_may_wakeup(&client->dev))
560 enable_irq_wake(p_egalax_i2c_dev->irq);
564 printk(KERN_DEBUG "[egalax_i2c]: device_may_wakeup false\n");
566 egalax_i2c_set_standby(client, 0);
570 static int egalax_i2c_resume(struct i2c_client *client)
572 struct _egalax_i2c *egalax_i2c = i2c_get_clientdata(client);
573 egalax_i2c_set_standby(client, 1);
574 if(device_may_wakeup(&client->dev))
576 disable_irq_wake(p_egalax_i2c_dev->irq);
580 printk(KERN_DEBUG "[egalax_i2c]: device_may_wakeup false\n");
583 wakeup_controller(irq_to_gpio(p_egalax_i2c_dev->irq));
584 egalax_i2c->work_state = 1;
585 enable_irq(p_egalax_i2c_dev->irq);
587 printk(KERN_DEBUG "[egalax_i2c]: device wakeup done\n");
592 #define egalax_i2c_suspend NULL
593 #define egalax_i2c_resume NULL
596 static int __devinit egalax_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
599 int gpio = client->irq;
600 struct eeti_egalax_platform_data *pdata = pdata = client->dev.platform_data;
602 printk(KERN_DEBUG "[egalax_i2c]: start probe\n");
604 p_egalax_i2c_dev = (struct _egalax_i2c *)kzalloc(sizeof(struct _egalax_i2c), GFP_KERNEL);
605 if (!p_egalax_i2c_dev)
607 printk(KERN_ERR "[egalax_i2c]: request memory failed\n");
612 #ifndef _NON_INPUT_DEV
613 input_dev = allocate_Input_Dev();
616 printk(KERN_ERR "[egalax_i2c]: allocate_Input_Dev failed\n");
620 TS_DEBUG("egalax_i2c register input device done\n");
621 memset(PointBuf, 0, sizeof(struct point_data)*MAX_SUPPORT_POINT);
622 #endif //#ifndef _NON_INPUT_DEV
624 if (pdata->init_platform_hw)
625 pdata->init_platform_hw();
627 p_egalax_i2c_dev->client = client;
628 mutex_init(&p_egalax_i2c_dev->mutex_wq);
630 p_egalax_i2c_dev->ktouch_wq = create_workqueue("egalax_touch_wq");
631 INIT_WORK(&p_egalax_i2c_dev->work, egalax_i2c_wq);
633 i2c_set_clientdata(client, p_egalax_i2c_dev);
635 if( gpio_get_value(gpio) )
636 p_egalax_i2c_dev->skip_packet = 0;
638 p_egalax_i2c_dev->skip_packet = 1;
640 p_egalax_i2c_dev->work_state = 1;
642 p_egalax_i2c_dev->irq = gpio_to_irq(client->irq);
644 ret = request_irq(p_egalax_i2c_dev->irq, egalax_i2c_interrupt, IRQF_TRIGGER_LOW,
645 client->name, p_egalax_i2c_dev);
648 printk(KERN_ERR "[egalax_i2c]: request irq(%d) failed\n", p_egalax_i2c_dev->irq);
651 TS_DEBUG("egalax_i2c request irq(%d) gpio(%d) with result:%d\n", p_egalax_i2c_dev->irq, gpio, ret);
654 device_init_wakeup(&client->dev, 0);
657 printk(KERN_DEBUG "[egalax_i2c]: probe done\n");
661 i2c_set_clientdata(client, NULL);
662 destroy_workqueue(p_egalax_i2c_dev->ktouch_wq);
663 free_irq(p_egalax_i2c_dev->irq, p_egalax_i2c_dev);
664 #ifndef _NON_INPUT_DEV
665 input_unregister_device(input_dev);
666 input_free_device(input_dev);
668 #endif //#ifndef _NON_INPUT_DEV
671 kfree(p_egalax_i2c_dev);
672 p_egalax_i2c_dev = NULL;
674 printk(KERN_DEBUG "[egalax_i2c]: probe failed\n");
678 static int __devexit egalax_i2c_remove(struct i2c_client *client)
680 struct _egalax_i2c *egalax_i2c = i2c_get_clientdata(client);
684 #ifndef _NON_INPUT_DEV
687 TS_DEBUG("unregister input device\n");
688 input_unregister_device(input_dev);
689 input_free_device(input_dev);
692 #endif //#ifndef _NON_INPUT_DEV
694 if(p_egalax_i2c_dev->ktouch_wq)
696 destroy_workqueue(p_egalax_i2c_dev->ktouch_wq);
699 if(p_egalax_i2c_dev->irq)
701 free_irq(p_egalax_i2c_dev->irq, egalax_i2c);
704 i2c_set_clientdata(client, NULL);
706 p_egalax_i2c_dev = NULL;
711 static struct i2c_device_id egalax_i2c_idtable[] = {
716 MODULE_DEVICE_TABLE(i2c, egalax_i2c_idtable);
718 static struct i2c_driver egalax_i2c_driver = {
720 .name = "egalax_i2c",
722 .id_table = egalax_i2c_idtable,
723 .probe = egalax_i2c_probe,
724 .remove = __devexit_p(egalax_i2c_remove),
725 .suspend = egalax_i2c_suspend,
726 .resume = egalax_i2c_resume,
729 static const struct file_operations egalax_cdev_fops = {
730 .owner = THIS_MODULE,
731 .read = egalax_cdev_read,
732 .write = egalax_cdev_write,
733 .unlocked_ioctl = egalax_cdev_ioctl,
734 .poll = egalax_cdev_poll,
735 .open = egalax_cdev_open,
736 .release= egalax_cdev_release,
739 static void egalax_i2c_ts_exit(void)
741 dev_t devno = MKDEV(global_major, global_minor);
746 TS_DEBUG("unregister character device\n");
747 if( p_char_dev->pFiFoBuf )
748 kfree(p_char_dev->pFiFoBuf);
750 cdev_del(&p_char_dev->cdev);
755 unregister_chrdev_region( devno, 1);
757 if(!IS_ERR(egalax_class))
759 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
760 class_device_destroy(egalax_class, devno);
762 device_destroy(egalax_class, devno);
764 class_destroy(egalax_class);
767 i2c_del_driver(&egalax_i2c_driver);
769 printk(KERN_DEBUG "[egalax_i2c]: driver exit\n");
772 static struct egalax_char_dev* setup_chardev(dev_t dev)
774 struct egalax_char_dev *pCharDev;
777 pCharDev = kmalloc(1*sizeof(struct egalax_char_dev), GFP_KERNEL);
780 memset(pCharDev, 0, sizeof(struct egalax_char_dev));
782 spin_lock_init( &pCharDev->FiFoLock );
783 pCharDev->pFiFoBuf = kmalloc(sizeof(unsigned char)*FIFO_SIZE, GFP_KERNEL);
784 if(!pCharDev->pFiFoBuf)
786 memset(pCharDev->pFiFoBuf, 0, sizeof(unsigned char)*FIFO_SIZE);
788 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
789 pCharDev->pDataKFiFo = kfifo_init(pCharDev->pFiFoBuf, FIFO_SIZE, GFP_KERNEL, &pCharDev->FiFoLock);
790 if( pCharDev->pDataKFiFo==NULL )
793 kfifo_init(&pCharDev->DataKFiFo, pCharDev->pFiFoBuf, FIFO_SIZE);
794 if( !kfifo_initialized(&pCharDev->DataKFiFo) )
798 pCharDev->OpenCnts = 0;
799 cdev_init(&pCharDev->cdev, &egalax_cdev_fops);
800 pCharDev->cdev.owner = THIS_MODULE;
801 sema_init(&pCharDev->sem, 1);
802 init_waitqueue_head(&pCharDev->fifo_inq);
804 result = cdev_add(&pCharDev->cdev, dev, 1);
807 TS_DEBUG(KERN_ERR "Error cdev ioctldev added\n");
814 kfree(pCharDev->pFiFoBuf);
821 static void __init egalax_i2c_ts_init_async(void *unused, async_cookie_t cookie)
828 // Asking for a dynamic major unless directed otherwise at load time.
831 devno = MKDEV(global_major, global_minor);
832 result = register_chrdev_region(devno, 1, "egalax_i2c");
836 result = alloc_chrdev_region(&devno, global_minor, 1, "egalax_i2c");
837 global_major = MAJOR(devno);
842 TS_DEBUG(" egalax_i2c cdev can't get major number\n");
846 // allocate the character device
847 p_char_dev = setup_chardev(devno);
854 egalax_class = class_create(THIS_MODULE, "egalax_i2c");
855 if(IS_ERR(egalax_class))
857 TS_DEBUG("Err: failed in creating class.\n");
862 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
863 class_device_create(egalax_class, NULL, devno, NULL, "egalax_i2c");
865 device_create(egalax_class, NULL, devno, NULL, "egalax_i2c");
867 TS_DEBUG("register egalax_i2c cdev, major: %d \n",global_major);
869 printk(KERN_DEBUG "[egalax_i2c]: init done\n");
870 i2c_add_driver(&egalax_i2c_driver);
874 egalax_i2c_ts_exit();
877 static int __init egalax_i2c_ts_init(void)
879 async_schedule(egalax_i2c_ts_init_async, NULL);
882 module_init(egalax_i2c_ts_init);
883 module_exit(egalax_i2c_ts_exit);
885 MODULE_DESCRIPTION("egalax touch screen i2c driver");
886 MODULE_LICENSE("GPL");