2 * Driver for Pixcir I2C touchscreen controllers.
4 * Copyright (C) 2010-2011 Pixcir, Inc.
6 * pixcir_i2c_ts.c V3.0 from v3.0 support TangoC solution and remove the previous soltutions
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <linux/module.h>
22 #include <linux/delay.h>
23 #include <linux/earlysuspend.h>
24 #include <linux/hrtimer.h>
25 #include <linux/i2c.h>
26 #include <linux/input.h>
27 #include <linux/input/mt.h>
28 #include <linux/interrupt.h>
30 #include <linux/gpio.h>
31 #include <mach/iomux.h>
32 #include <linux/platform_device.h>
34 #include <linux/slab.h>
35 #include <asm/uaccess.h>
36 #include <linux/proc_fs.h>
38 #include "pixcir_i2c_ts.h"
40 #define PIXCIR_DEBUG 0
42 #define pixcir_dbg(msg...) printk(msg);
44 #define pixcir_dbg(msg...)
47 static int ts_dbg_enable = 0;
50 ({if(ts_dbg_enable == 1) printk(msg);})
51 /*********************************Bee-0928-TOP****************************************/
53 #define SLAVE_ADDR 0x5c
59 #define I2C_MINORS 256
61 #define CALIBRATION_FLAG 1
63 static unsigned char status_reg = 0;
64 static struct workqueue_struct *pixcir_wq;
65 static struct pixcir_i2c_ts_data *this_data;
68 unsigned char brn; //broken line number
69 unsigned char id; //finger ID
73 unsigned char pre_active;
76 static struct point_data point[MAX_SUPPORT_POINT];
81 struct list_head list;
82 struct i2c_adapter *adap;
86 static struct i2c_driver pixcir_i2c_ts_driver;
87 static struct class *i2c_dev_class;
88 static LIST_HEAD( i2c_dev_list);
89 static DEFINE_SPINLOCK( i2c_dev_list_lock);
91 static void return_i2c_dev(struct i2c_dev *i2c_dev)
93 spin_lock(&i2c_dev_list_lock);
94 list_del(&i2c_dev->list);
95 spin_unlock(&i2c_dev_list_lock);
99 static struct i2c_dev *i2c_dev_get_by_minor(unsigned index)
101 struct i2c_dev *i2c_dev;
104 spin_lock(&i2c_dev_list_lock);
105 list_for_each_entry(i2c_dev, &i2c_dev_list, list)
107 if (i2c_dev->adap->nr == index)
111 found: spin_unlock(&i2c_dev_list_lock);
115 static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
117 struct i2c_dev *i2c_dev;
119 if (adap->nr >= I2C_MINORS) {
120 printk(KERN_ERR "i2c-dev: Out of device minors (%d)\n",
122 return ERR_PTR(-ENODEV);
125 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);
127 return ERR_PTR(-ENOMEM);
129 i2c_dev->adap = adap;
131 spin_lock(&i2c_dev_list_lock);
132 list_add_tail(&i2c_dev->list, &i2c_dev_list);
133 spin_unlock(&i2c_dev_list_lock);
136 /*********************************Bee-0928-bottom**************************************/
138 struct pixcir_i2c_ts_data {
139 struct i2c_client *client;
140 struct input_dev *input,*input_key_dev;
144 int gpio_reset_active_low;
145 int pendown_iomux_mode;
146 int resetpin_iomux_mode;
147 char pendown_iomux_name[IOMUX_NAME_SIZE];
148 char resetpin_iomux_name[IOMUX_NAME_SIZE];
149 struct work_struct work;
150 //const struct pixcir_ts_platform_data *chip;
152 struct early_suspend early_suspend;
155 #ifdef CONFIG_HAS_EARLYSUSPEND
156 static void pixcir_ts_early_suspend(struct early_suspend *h);
157 static void pixcir_ts_late_resume(struct early_suspend *h);
160 int tp_pixcir_write_reg(struct i2c_client *client,const char *buf ,int count)
162 struct i2c_msg msg[] = {
164 .addr = client->addr,
171 //ret = i2c_transfer(adap, &msg, 1);
172 if (i2c_transfer(client->adapter, msg, 1) < 0)
174 printk("write the address (0x%x) of the ssd2533 fail.",buf[0]);
180 int tp_pixcir_read_reg(struct i2c_client *client,u8 addr,u8 *buf,u8 len)
182 u8 msgbuf[1] = { addr };
183 struct i2c_msg msgs[] = {
185 .addr = client->addr,
191 .addr = client->addr,
197 if (i2c_transfer(client->adapter, msgs, 2) < 0)
199 printk("read the address (0x%x) of the ssd2533 fail.",addr);
205 static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
207 struct pixcir_i2c_ts_data *tsdata = data;
210 u8 touch, button, pix_id;
211 u8 rdbuf[27], wrbuf[1] = { 0 };
215 ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf));
216 if (ret != sizeof(wrbuf)) {
217 dev_err(&tsdata->client->dev,
218 "%s: i2c_master_send failed(), ret=%d\n",
223 ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf));
224 if (ret != sizeof(rdbuf)) {
225 dev_err(&tsdata->client->dev,
226 "%s: i2c_master_recv failed(), ret=%d\n",
231 touch = rdbuf[0] & 0x07;
235 for (i = 0; i < MAX_SUPPORT_POINT; i++) {
236 point[i].pre_active = point[i].active;
240 for (i = 0; i < touch; i++) {
241 pix_id = (*(p + 4)) & 0x7;
243 point[pix_id].brn = (*(p + 4)) >> 3;
244 point[pix_id].id = (*(p + 4)) & 0x7;
245 point[pix_id].posx = (*(p + 1) << 8) + (*(p));
246 point[pix_id].posy = (*(p + 3) << 8) + (*(p + 2));
248 if (point[pix_id].posy < 40 || point[pix_id].posy > 520 || point[pix_id].posx < 40) {
249 //point[i].active = 0;
251 point[pix_id].active = 1;
253 point[pix_id].posy -= 40;
254 point[pix_id].posx -= 40;
256 if(point[pix_id].posy < 0)
257 point[pix_id].posy=1;
259 if(point[pix_id].posx < 0)
260 point[pix_id].posx=1;
264 DBG("[id = %d]x = %d y = %d\n", pix_id, point[pix_id].posy, point[pix_id].posx);
268 for (i = 0; i < MAX_SUPPORT_POINT; i++) {
269 if (!point[i].active && point[i].pre_active) {
270 input_mt_slot(tsdata->input, point[i].id);
271 input_mt_report_slot_state(tsdata->input, MT_TOOL_FINGER, false);
274 if (point[i].active) {
275 input_mt_slot(tsdata->input, point[i].id);
276 input_mt_report_slot_state(tsdata->input, MT_TOOL_FINGER, true);
277 input_report_abs(tsdata->input, ABS_MT_TOUCH_MAJOR, 1);
278 input_report_abs(tsdata->input, ABS_MT_POSITION_X, point[i].posy);
279 input_report_abs(tsdata->input, ABS_MT_POSITION_Y, point[i].posx);
282 DBG("%d[id = %d] = %2d active= %d pre_active = %d x = %5d y = %5d \n",
283 i, point[i].id, point[i].brn, point[i].active, point[i].pre_active, point[i].posy, point[i].posx);
286 input_sync(tsdata->input);
290 static void pixcir_ts_work_func(struct work_struct *work)
292 struct pixcir_i2c_ts_data *tsdata = this_data;
295 while (!tsdata->exiting) {
297 pixcir_ts_poscheck(tsdata);
298 if (attb_read_val()){
299 DBG("%s: >>>>>touch release\n\n",__FUNCTION__);
300 for (i = 0; i < MAX_SUPPORT_POINT; i++) {
301 point[i].pre_active = point[i].active;
303 if (!point[i].active && point[i].pre_active) {
304 input_mt_slot(tsdata->input, point[i].id);
305 input_mt_report_slot_state(tsdata->input, MT_TOOL_FINGER, false);
308 input_sync(tsdata->input);
309 enable_irq(tsdata->client->irq);
317 static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)
319 struct pixcir_i2c_ts_data *ts = dev_id;
320 DBG("%s: >>>>>>>>>\n\n",__FUNCTION__);
323 disable_irq_nosync(ts->client->irq);
325 queue_work(pixcir_wq, &ts->work);
331 #ifdef CONFIG_PM_SLEEP
332 static int pixcir_i2c_ts_suspend(struct device *dev)
334 struct i2c_client *client = to_i2c_client(dev);
335 pixcir_dbg("%s\n",__FUNCTION__);
337 if (device_may_wakeup(&client->dev))
338 enable_irq_wake(client->irq);
343 static int pixcir_i2c_ts_resume(struct device *dev)
345 struct i2c_client *client = to_i2c_client(dev);
346 pixcir_dbg("%s\n",__FUNCTION__);
348 if (device_may_wakeup(&client->dev))
349 disable_irq_wake(client->irq);
354 static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops,
355 pixcir_i2c_ts_suspend, pixcir_i2c_ts_resume);
357 static int __devinit setup_resetPin(struct i2c_client *client, struct pixcir_i2c_ts_data *ts)
359 struct pixcir_platform_data *pdata = client->dev.platform_data;
362 pixcir_dbg("%s\n",__FUNCTION__);
365 ts->gpio_reset = pdata->gpio_reset;
366 ts->gpio_reset_active_low = pdata->gpio_reset_active_low;
367 ts->resetpin_iomux_mode = pdata->resetpin_iomux_mode;
370 if(pdata->resetpin_iomux_name != NULL)
371 strcpy(ts->resetpin_iomux_name,pdata->resetpin_iomux_name);
373 //pixcir_dbg("%s=%d,%s,%d,%d\n",__FUNCTION__,ts->gpio_reset,ts->resetpin_iomux_name,ts->resetpin_iomux_mode,ts->gpio_reset_active_low);
374 if (!gpio_is_valid(ts->gpio_reset)) {
375 dev_err(&client->dev, "no gpio_reset?\n");
379 rk29_mux_api_set(ts->resetpin_iomux_name,ts->resetpin_iomux_mode);
382 err = gpio_request(ts->gpio_reset, "pixcir_resetPin");
384 dev_err(&client->dev, "failed to request resetPin GPIO%d\n",
389 err = gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
391 dev_err(&client->dev, "failed to pulldown resetPin GPIO%d,err%d\n",
393 gpio_free(ts->gpio_reset);
397 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
403 static int __devinit setup_pendown(struct i2c_client *client, struct pixcir_i2c_ts_data *ts)
406 struct pixcir_i2c_ts_data *pdata = client->dev.platform_data;
408 pixcir_dbg("%s\n",__FUNCTION__);
410 dev_dbg(&client->dev, "no IRQ?\n");
414 if (!gpio_is_valid(pdata->gpio_pendown)) {
415 dev_err(&client->dev, "no gpio_pendown?\n");
419 ts->gpio_pendown = pdata->gpio_pendown;
420 strcpy(ts->pendown_iomux_name,pdata->pendown_iomux_name);
421 ts->pendown_iomux_mode = pdata->pendown_iomux_mode;
423 pixcir_dbg("%s=%d,%s,%d\n",__FUNCTION__,ts->gpio_pendown,ts->pendown_iomux_name,ts->pendown_iomux_mode);
425 if (!gpio_is_valid(ts->gpio_pendown)) {
426 dev_err(&client->dev, "no gpio_pendown?\n");
430 rk29_mux_api_set(ts->pendown_iomux_name,ts->pendown_iomux_mode);
431 err = gpio_request(ts->gpio_pendown, "gt801_pendown");
433 dev_err(&client->dev, "failed to request pendown GPIO%d\n",
438 err = gpio_pull_updown(ts->gpio_pendown, GPIOPullUp);
440 dev_err(&client->dev, "failed to pullup pendown GPIO%d\n",
442 gpio_free(ts->gpio_pendown);
449 static ssize_t pixcir_proc_write(struct file *file, const char __user *buffer,
450 size_t count, loff_t *data)
455 rc = get_user(c, buffer);
467 static const struct file_operations pixcir_proc_fops = {
468 .owner = THIS_MODULE,
469 .write = pixcir_proc_write,
471 static int __devinit pixcir_i2c_ts_probe(struct i2c_client *client,
472 const struct i2c_device_id *id)
474 //const struct pixcir_ts_platform_data *pdata = client->dev.platform_data;
475 struct pixcir_i2c_ts_data *tsdata;
476 struct pixcir_platform_data *pdata;
478 struct i2c_dev *i2c_dev;
480 struct proc_dir_entry *pixcir_proc_entry;
483 // dev_err(&client->dev, "platform data not defined\n");
486 pixcir_dbg("%s\n",__FUNCTION__);
488 tsdata = kzalloc(sizeof(*tsdata), GFP_KERNEL);
489 tsdata->input = input_allocate_device();
490 if (!tsdata || !(tsdata->input)) {
491 dev_err(&client->dev, "Failed to allocate driver data!\n");
496 pixcir_wq = create_singlethread_workqueue("pixcir_tp_wq");
498 printk(KERN_ERR"%s: create workqueue failed\n", __FUNCTION__);
502 INIT_WORK(&tsdata->work, pixcir_ts_work_func);
505 tsdata->exiting = false;
506 //tsdata->input = input;
507 //tsdata->chip = pdata;
509 tsdata->client = client;
510 i2c_set_clientdata(client, tsdata);
511 pdata = client->dev.platform_data;
513 //error = setup_resetPin(client,tsdata);
516 printk("%s:setup_resetPin fail\n",__FUNCTION__);
519 tsdata->input->phys = "/dev/input/event2";
520 tsdata->input->name = "pixcir_ts-touchscreen";//client->name;
521 tsdata->input->id.bustype = BUS_I2C;
522 tsdata->input->dev.parent = &client->dev;
526 /*set_bit(EV_SYN, tsdata->input->evbit);
527 set_bit(EV_KEY, tsdata->input->evbit);
528 set_bit(EV_ABS, tsdata->input->evbit);
529 set_bit(BTN_TOUCH, tsdata->input->keybit);
530 set_bit(BTN_2, tsdata->input->keybit);//*/
532 //tsdata->input->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_ABS) ;
533 //tsdata->input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
534 /*tsdata->input->absbit[0] = BIT_MASK(ABS_MT_POSITION_X) | BIT_MASK(ABS_MT_POSITION_Y) |
535 BIT_MASK(ABS_MT_TOUCH_MAJOR) | BIT_MASK(ABS_MT_WIDTH_MAJOR); // for android*/
536 //tsdata->input->keybit[BIT_WORD(BTN_START)] = BIT_MASK(BTN_START);
538 //input_set_abs_params(input, ABS_X, 0, X_MAX, 0, 0);
539 //input_set_abs_params(input, ABS_Y, 0, Y_MAX, 0, 0);
541 __set_bit(INPUT_PROP_DIRECT, tsdata->input->propbit);
542 __set_bit(EV_ABS, tsdata->input->evbit);
544 input_mt_init_slots(tsdata->input, MAX_SUPPORT_POINT);
545 input_set_abs_params(tsdata->input, ABS_MT_POSITION_X, pdata->x_min, pdata->x_max, 0, 0);
546 input_set_abs_params(tsdata->input, ABS_MT_POSITION_Y, pdata->y_min, pdata->y_max, 0, 0);
547 //input_set_abs_params(tsdata->input, ABS_MT_WIDTH_MAJOR, 0, 16, 0, 0);
548 //input_set_abs_params(tsdata->input, ABS_MT_PRESSURE, 0, 255, 0, 0);
549 input_set_abs_params(tsdata->input, ABS_MT_TOUCH_MAJOR, 0, 1, 0, 0);
550 //input_set_abs_params(tsdata->input, ABS_MT_TRACKING_ID, 0, 5, 0, 0);
551 input_set_drvdata(tsdata->input, tsdata);
552 //init int and reset ports
553 error = gpio_request(client->irq, "TS_INT"); //Request IO
555 dev_err(&client->dev, "Failed to request GPIO:%d, ERRNO:%d\n",(int)client->irq, error);
558 rk29_mux_api_set(pdata->pendown_iomux_name, pdata->pendown_iomux_mode);
560 gpio_direction_input(client->irq);
561 gpio_set_value(client->irq,GPIO_HIGH);
562 gpio_pull_updown(client->irq, 0);
564 error = gpio_request(pdata->gpio_reset, "pixcir_resetPin");
566 dev_err(&client->dev, "failed to request resetPin GPIO%d\n", pdata->gpio_reset);
569 rk29_mux_api_set(pdata->resetpin_iomux_name, pdata->resetpin_iomux_mode);
571 gpio_pull_updown(pdata->gpio_reset, 1);
572 gpio_direction_output(pdata->gpio_reset, 0);
573 msleep(20); //delay at least 1ms
574 gpio_direction_input(pdata->gpio_reset);
575 gpio_pull_updown(pdata->gpio_reset, 0);
578 gpio_pull_updown(pdata->gpio_reset, 1);
580 gpio_direction_output(pdata->gpio_reset, 0);
581 gpio_set_value(pdata->gpio_reset,GPIO_HIGH);//GPIO_LOW
583 gpio_set_value(pdata->gpio_reset,GPIO_LOW);//GPIO_HIGH
585 // gpio_direction_input(pdata->gpio_reset);
586 printk("pdata->gpio_reset = %d\n",gpio_get_value(pdata->gpio_reset));
587 //printk("ts->gpio_irq = %d\n",gpio_get_value(pdata->gpio_pendown));
588 printk("pdata->gpio_pendown = %d\n",gpio_get_value(client->irq));
591 //**********************************************
595 tp_pixcir_write_reg(client,buffer,2);
597 //********************************************************//
599 client->irq = gpio_to_irq(client->irq);
600 error = request_irq(client->irq, pixcir_ts_isr, IRQF_TRIGGER_FALLING, client->name, (void *)tsdata);
602 dev_err(&client->dev, "request_irq failed\n");
604 error = request_threaded_irq(client->irq, NULL, pixcir_ts_isr,
605 IRQF_TRIGGER_FALLING,
606 client->name, tsdata);*/
609 dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
614 error = input_register_device(tsdata->input);
618 i2c_set_clientdata(client, tsdata);
619 device_init_wakeup(&client->dev, 1);
621 /*********************************Bee-0928-TOP****************************************/
622 i2c_dev = get_free_i2c_dev(client->adapter);
623 if (IS_ERR(i2c_dev)) {
624 error = PTR_ERR(i2c_dev);
628 dev = device_create(i2c_dev_class, &client->adapter->dev, MKDEV(I2C_MAJOR,
629 client->adapter->nr), NULL, "pixcir_i2c_ts%d", 0);
631 error = PTR_ERR(dev);
634 /*********************************Bee-0928-BOTTOM****************************************/
635 #ifdef CONFIG_HAS_EARLYSUSPEND
636 tsdata->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
637 tsdata->early_suspend.suspend = pixcir_ts_early_suspend;
638 tsdata->early_suspend.resume = pixcir_ts_late_resume;
639 register_early_suspend(&tsdata->early_suspend);
641 pixcir_proc_entry = proc_create("driver/pixcir", 0777, NULL, &pixcir_proc_fops);
643 dev_err(&tsdata->client->dev, "insmod successfully!\n");
648 free_irq(client->irq, tsdata);
650 input_free_device(tsdata->input);
655 static int __devexit pixcir_i2c_ts_remove(struct i2c_client *client)
658 struct i2c_dev *i2c_dev;
659 struct pixcir_i2c_ts_data *tsdata = i2c_get_clientdata(client);
661 unregister_early_suspend(&tsdata->early_suspend);
662 device_init_wakeup(&client->dev, 0);
664 tsdata->exiting = true;
666 free_irq(client->irq, tsdata);
668 /*********************************Bee-0928-TOP****************************************/
669 i2c_dev = get_free_i2c_dev(client->adapter);
670 if (IS_ERR(i2c_dev)) {
671 error = PTR_ERR(i2c_dev);
675 return_i2c_dev(i2c_dev);
676 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, client->adapter->nr));
677 /*********************************Bee-0928-BOTTOM****************************************/
679 input_unregister_device(tsdata->input);
685 /*************************************Bee-0928****************************************/
687 /*************************************Bee-0928****************************************/
688 static int pixcir_open(struct inode *inode, struct file *file)
691 struct i2c_client *client;
692 struct i2c_adapter *adapter;
693 struct i2c_dev *i2c_dev;
696 printk("enter pixcir_open function\n");
698 subminor = iminor(inode);
701 i2c_dev = i2c_dev_get_by_minor(subminor);
703 printk("error i2c_dev\n");
707 adapter = i2c_get_adapter(i2c_dev->adap->nr);
712 client = kzalloc(sizeof(*client), GFP_KERNEL);
714 i2c_put_adapter(adapter);
718 snprintf(client->name, I2C_NAME_SIZE, "pixcir_i2c_ts%d", adapter->nr);
719 client->driver = &pixcir_i2c_ts_driver;
720 client->adapter = adapter;
722 file->private_data = client;
727 /*************************************Bee-0928****************************************/
729 /*************************************Bee-0928****************************************/
730 static long pixcir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
732 //printk("ioctl function\n");
733 struct i2c_client *client = (struct i2c_client *) file->private_data;
735 printk("cmd = %d,arg = %d\n", cmd, arg);
740 case CALIBRATION_FLAG: //CALIBRATION_FLAG = 1
742 printk("CALIBRATION\n");
744 client->addr = SLAVE_ADDR;
746 status_reg = CALIBRATION_FLAG;
750 break;//return -ENOTTY;
756 /***********************************Bee-0928****************************************/
758 /***********************************Bee-0928****************************************/
759 static ssize_t pixcir_write(struct file *file,const char __user *buf,size_t count, loff_t *ppos)
761 struct i2c_client *client;
765 pixcir_dbg("%s\n",__FUNCTION__);
767 client = file->private_data;
769 //printk("pixcir_write function\n");
772 case CALIBRATION_FLAG: //CALIBRATION_FLAG=1
773 tmp = kmalloc(count,GFP_KERNEL);
777 if (copy_from_user(tmp,buf,count)) {
778 printk("CALIBRATION_FLAG copy_from_user error\n");
783 ret = i2c_master_send(client,tmp,count);
785 dev_err(&client->dev,
786 "%s: i2c_master_recv failed(), ret=%d\n",
790 while(!attb_read_val());//waiting to finish the calibration.(pixcir application_note_710_v3 p43)
803 /***********************************Bee-0928****************************************/
805 /***********************************Bee-0928****************************************/
806 static int pixcir_release(struct inode *inode, struct file *file)
808 struct i2c_client *client = file->private_data;
810 printk("enter pixcir_release funtion\n");
812 i2c_put_adapter(client->adapter);
814 file->private_data = NULL;
819 /*********************************Bee-0928-TOP****************************************/
820 static const struct file_operations pixcir_i2c_ts_fops =
821 { .owner = THIS_MODULE,
822 .write = pixcir_write,
824 .unlocked_ioctl = pixcir_ioctl,
825 .release = pixcir_release,
827 /*********************************Bee-0928-BOTTOM****************************************/
829 static int pixcir_ts_suspend(struct i2c_client *client, pm_message_t mesg)
831 struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client);
832 DBG("%s\n",__FUNCTION__);
835 disable_irq(client->irq);
836 //gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
840 static int pixcir_ts_resume(struct i2c_client *client)
842 struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client);
843 DBG("%s\n",__FUNCTION__);
846 enable_irq(client->irq);
847 //gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
851 #ifdef CONFIG_HAS_EARLYSUSPEND
852 static void pixcir_ts_early_suspend(struct early_suspend *h)
854 struct pixcir_i2c_ts_data *ts;
855 DBG("%s\n",__FUNCTION__);
856 ts = container_of(h, struct pixcir_i2c_ts_data, early_suspend);
857 pixcir_ts_suspend(ts->client, PMSG_SUSPEND);
860 static void pixcir_ts_late_resume(struct early_suspend *h)
862 struct pixcir_i2c_ts_data *ts;
863 DBG("%s\n",__FUNCTION__);
864 ts = container_of(h, struct pixcir_i2c_ts_data, early_suspend);
865 pixcir_ts_resume(ts->client);
869 static const struct i2c_device_id pixcir_i2c_ts_id[] = {
873 MODULE_DEVICE_TABLE(i2c, pixcir_i2c_ts_id);
875 static struct i2c_driver pixcir_i2c_ts_driver = {
877 .owner = THIS_MODULE,
879 //.pm = &pixcir_dev_pm_ops,
881 #ifndef CONFIG_HAS_EARLYSUSPEND
882 .suspend = pixcir_ts_suspend,
883 .resume = pixcir_ts_resume,
885 .probe = pixcir_i2c_ts_probe,
886 .remove = __devexit_p(pixcir_i2c_ts_remove),
887 .id_table = pixcir_i2c_ts_id,
890 static int __init pixcir_i2c_ts_init(void)
894 pixcir_dbg("%s\n",__FUNCTION__);
896 pixcir_wq = create_singlethread_workqueue("pixcir_wq");
900 /*********************************Bee-0928-TOP****************************************/
901 ret = register_chrdev(I2C_MAJOR,"pixcir_i2c_ts",&pixcir_i2c_ts_fops);
903 printk(KERN_ERR "%s:register chrdev failed\n",__FILE__);
907 i2c_dev_class = class_create(THIS_MODULE, "pixcir_i2c_dev");
908 if (IS_ERR(i2c_dev_class)) {
909 ret = PTR_ERR(i2c_dev_class);
910 class_destroy(i2c_dev_class);
912 /********************************Bee-0928-BOTTOM******************************************/
916 return i2c_add_driver(&pixcir_i2c_ts_driver);
918 module_init(pixcir_i2c_ts_init);
920 static void __exit pixcir_i2c_ts_exit(void)
922 i2c_del_driver(&pixcir_i2c_ts_driver);
924 destroy_workqueue(pixcir_wq);
925 /********************************Bee-0928-TOP******************************************/
926 class_destroy(i2c_dev_class);
927 unregister_chrdev(I2C_MAJOR,"pixcir_i2c_ts");
928 /********************************Bee-0928-BOTTOM******************************************/
930 module_exit(pixcir_i2c_ts_exit);
932 MODULE_AUTHOR("Jianchun Bian <jcbian@pixcir.com.cn>");
933 MODULE_DESCRIPTION("Pixcir I2C Touchscreen Driver");
934 MODULE_LICENSE("GPL");