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 brn_pre;
70 unsigned char id; //finger ID
74 unsigned char pre_active;
77 static struct point_data point[MAX_SUPPORT_POINT];
82 struct list_head list;
83 struct i2c_adapter *adap;
87 static struct i2c_driver pixcir_i2c_ts_driver;
88 static struct class *i2c_dev_class;
89 static LIST_HEAD( i2c_dev_list);
90 static DEFINE_SPINLOCK( i2c_dev_list_lock);
92 static void return_i2c_dev(struct i2c_dev *i2c_dev)
94 spin_lock(&i2c_dev_list_lock);
95 list_del(&i2c_dev->list);
96 spin_unlock(&i2c_dev_list_lock);
100 static struct i2c_dev *i2c_dev_get_by_minor(unsigned index)
102 struct i2c_dev *i2c_dev;
105 spin_lock(&i2c_dev_list_lock);
106 list_for_each_entry(i2c_dev, &i2c_dev_list, list)
108 if (i2c_dev->adap->nr == index)
112 found: spin_unlock(&i2c_dev_list_lock);
116 static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
118 struct i2c_dev *i2c_dev;
120 if (adap->nr >= I2C_MINORS) {
121 printk(KERN_ERR "i2c-dev: Out of device minors (%d)\n",
123 return ERR_PTR(-ENODEV);
126 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);
128 return ERR_PTR(-ENOMEM);
130 i2c_dev->adap = adap;
132 spin_lock(&i2c_dev_list_lock);
133 list_add_tail(&i2c_dev->list, &i2c_dev_list);
134 spin_unlock(&i2c_dev_list_lock);
137 /*********************************Bee-0928-bottom**************************************/
139 struct pixcir_i2c_ts_data {
140 struct i2c_client *client;
141 struct input_dev *input,*input_key_dev;
145 int gpio_reset_active_low;
146 int pendown_iomux_mode;
147 int resetpin_iomux_mode;
148 char pendown_iomux_name[IOMUX_NAME_SIZE];
149 char resetpin_iomux_name[IOMUX_NAME_SIZE];
150 struct work_struct work;
151 //const struct pixcir_ts_platform_data *chip;
153 struct early_suspend early_suspend;
156 #ifdef CONFIG_HAS_EARLYSUSPEND
157 static void pixcir_ts_early_suspend(struct early_suspend *h);
158 static void pixcir_ts_late_resume(struct early_suspend *h);
161 int tp_pixcir_write_reg(struct i2c_client *client,const char *buf ,int count)
163 struct i2c_msg msg[] = {
165 .addr = client->addr,
172 //ret = i2c_transfer(adap, &msg, 1);
173 if (i2c_transfer(client->adapter, msg, 1) < 0)
175 printk("write the address (0x%x) of the ssd2533 fail.",buf[0]);
181 int tp_pixcir_read_reg(struct i2c_client *client,u8 addr,u8 *buf,u8 len)
183 u8 msgbuf[1] = { addr };
184 struct i2c_msg msgs[] = {
186 .addr = client->addr,
192 .addr = client->addr,
198 if (i2c_transfer(client->adapter, msgs, 2) < 0)
200 printk("read the address (0x%x) of the ssd2533 fail.",addr);
206 static void pixcir_ts_poscheck(struct pixcir_i2c_ts_data *data)
208 struct pixcir_i2c_ts_data *tsdata = data;
211 u8 touch, button, pix_id;
212 u8 rdbuf[27], wrbuf[1] = { 0 };
216 ret = i2c_master_send(tsdata->client, wrbuf, sizeof(wrbuf));
217 if (ret != sizeof(wrbuf)) {
218 dev_err(&tsdata->client->dev,
219 "%s: i2c_master_send failed(), ret=%d\n",
224 ret = i2c_master_recv(tsdata->client, rdbuf, sizeof(rdbuf));
225 if (ret != sizeof(rdbuf)) {
226 dev_err(&tsdata->client->dev,
227 "%s: i2c_master_recv failed(), ret=%d\n",
232 touch = rdbuf[0] & 0x07;
236 for (i = 0; i < MAX_SUPPORT_POINT; i++) {
237 point[i].pre_active = point[i].active;
241 for (i = 0; i < touch; i++) {
242 pix_id = (*(p + 4)) & 0x7;
244 point[pix_id].brn = (*(p + 4)) >> 3;
245 point[pix_id].id = (*(p + 4)) & 0x7;
246 point[pix_id].posx = (*(p + 1) << 8) + (*(p));
247 point[pix_id].posy = (*(p + 3) << 8) + (*(p + 2));
249 if (point[pix_id].posy < 40 || point[pix_id].posy > 520 || point[pix_id].posx < 40) {
250 //point[i].active = 0;
252 point[pix_id].active = 1;
254 point[pix_id].posy -= 40;
255 point[pix_id].posx -= 40;
257 if(point[pix_id].posy < 0)
258 point[pix_id].posy=1;
260 if(point[pix_id].posx < 0)
261 point[pix_id].posx=1;
265 DBG("[id = %d]x = %d y = %d\n", pix_id, point[pix_id].posy, point[pix_id].posx);
269 for (i = 0; i < MAX_SUPPORT_POINT; i++) {
270 if (!point[i].active && point[i].pre_active) {
271 input_mt_slot(tsdata->input, point[i].id);
272 input_mt_report_slot_state(tsdata->input, MT_TOOL_FINGER, false);
275 if (point[i].active) {
276 input_mt_slot(tsdata->input, point[i].id);
277 input_mt_report_slot_state(tsdata->input, MT_TOOL_FINGER, true);
278 input_report_abs(tsdata->input, ABS_MT_TOUCH_MAJOR, 1);
279 input_report_abs(tsdata->input, ABS_MT_POSITION_X, point[i].posy);
280 input_report_abs(tsdata->input, ABS_MT_POSITION_Y, point[i].posx);
283 DBG("%d[id = %d] = %2d active= %d pre_active = %d x = %5d y = %5d \n",
284 i, point[i].id, point[i].brn, point[i].active, point[i].pre_active, point[i].posy, point[i].posx);
287 input_sync(tsdata->input);
291 static void pixcir_ts_work_func(struct work_struct *work)
293 struct pixcir_i2c_ts_data *tsdata = this_data;
296 while (!tsdata->exiting) {
298 pixcir_ts_poscheck(tsdata);
299 if (attb_read_val()){
300 DBG("%s: >>>>>touch release\n\n",__FUNCTION__);
301 for (i = 0; i < MAX_SUPPORT_POINT; i++) {
302 point[i].pre_active = point[i].active;
304 if (!point[i].active && point[i].pre_active) {
305 input_mt_slot(tsdata->input, point[i].id);
306 input_mt_report_slot_state(tsdata->input, MT_TOOL_FINGER, false);
309 input_sync(tsdata->input);
310 enable_irq(tsdata->client->irq);
318 static irqreturn_t pixcir_ts_isr(int irq, void *dev_id)
320 struct pixcir_i2c_ts_data *ts = dev_id;
321 DBG("%s: >>>>>>>>>\n\n",__FUNCTION__);
324 disable_irq_nosync(ts->client->irq);
326 queue_work(pixcir_wq, &ts->work);
332 #ifdef CONFIG_PM_SLEEP
333 static int pixcir_i2c_ts_suspend(struct device *dev)
335 struct i2c_client *client = to_i2c_client(dev);
336 pixcir_dbg("%s\n",__FUNCTION__);
338 if (device_may_wakeup(&client->dev))
339 enable_irq_wake(client->irq);
344 static int pixcir_i2c_ts_resume(struct device *dev)
346 struct i2c_client *client = to_i2c_client(dev);
347 pixcir_dbg("%s\n",__FUNCTION__);
349 if (device_may_wakeup(&client->dev))
350 disable_irq_wake(client->irq);
355 static SIMPLE_DEV_PM_OPS(pixcir_dev_pm_ops,
356 pixcir_i2c_ts_suspend, pixcir_i2c_ts_resume);
358 static int __devinit setup_resetPin(struct i2c_client *client, struct pixcir_i2c_ts_data *ts)
360 struct pixcir_platform_data *pdata = client->dev.platform_data;
363 pixcir_dbg("%s\n",__FUNCTION__);
366 ts->gpio_reset = pdata->gpio_reset;
367 ts->gpio_reset_active_low = pdata->gpio_reset_active_low;
368 ts->resetpin_iomux_mode = pdata->resetpin_iomux_mode;
371 if(pdata->resetpin_iomux_name != NULL)
372 strcpy(ts->resetpin_iomux_name,pdata->resetpin_iomux_name);
374 //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);
375 if (!gpio_is_valid(ts->gpio_reset)) {
376 dev_err(&client->dev, "no gpio_reset?\n");
380 rk29_mux_api_set(ts->resetpin_iomux_name,ts->resetpin_iomux_mode);
383 err = gpio_request(ts->gpio_reset, "pixcir_resetPin");
385 dev_err(&client->dev, "failed to request resetPin GPIO%d\n",
390 err = gpio_direction_output(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
392 dev_err(&client->dev, "failed to pulldown resetPin GPIO%d,err%d\n",
394 gpio_free(ts->gpio_reset);
398 gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
404 static int __devinit setup_pendown(struct i2c_client *client, struct pixcir_i2c_ts_data *ts)
407 struct pixcir_i2c_ts_data *pdata = client->dev.platform_data;
409 pixcir_dbg("%s\n",__FUNCTION__);
411 dev_dbg(&client->dev, "no IRQ?\n");
415 if (!gpio_is_valid(pdata->gpio_pendown)) {
416 dev_err(&client->dev, "no gpio_pendown?\n");
420 ts->gpio_pendown = pdata->gpio_pendown;
421 strcpy(ts->pendown_iomux_name,pdata->pendown_iomux_name);
422 ts->pendown_iomux_mode = pdata->pendown_iomux_mode;
424 pixcir_dbg("%s=%d,%s,%d\n",__FUNCTION__,ts->gpio_pendown,ts->pendown_iomux_name,ts->pendown_iomux_mode);
426 if (!gpio_is_valid(ts->gpio_pendown)) {
427 dev_err(&client->dev, "no gpio_pendown?\n");
431 rk29_mux_api_set(ts->pendown_iomux_name,ts->pendown_iomux_mode);
432 err = gpio_request(ts->gpio_pendown, "gt801_pendown");
434 dev_err(&client->dev, "failed to request pendown GPIO%d\n",
439 err = gpio_pull_updown(ts->gpio_pendown, GPIOPullUp);
441 dev_err(&client->dev, "failed to pullup pendown GPIO%d\n",
443 gpio_free(ts->gpio_pendown);
450 static ssize_t pixcir_proc_write(struct file *file, const char __user *buffer,
451 size_t count, loff_t *data)
456 rc = get_user(c, buffer);
468 static const struct file_operations pixcir_proc_fops = {
469 .owner = THIS_MODULE,
470 .write = pixcir_proc_write,
472 static int __devinit pixcir_i2c_ts_probe(struct i2c_client *client,
473 const struct i2c_device_id *id)
475 //const struct pixcir_ts_platform_data *pdata = client->dev.platform_data;
476 struct pixcir_i2c_ts_data *tsdata;
477 struct pixcir_platform_data *pdata;
479 struct i2c_dev *i2c_dev;
481 struct proc_dir_entry *pixcir_proc_entry;
484 // dev_err(&client->dev, "platform data not defined\n");
487 pixcir_dbg("%s\n",__FUNCTION__);
489 tsdata = kzalloc(sizeof(*tsdata), GFP_KERNEL);
490 tsdata->input = input_allocate_device();
491 if (!tsdata || !(tsdata->input)) {
492 dev_err(&client->dev, "Failed to allocate driver data!\n");
497 pixcir_wq = create_singlethread_workqueue("pixcir_tp_wq");
499 printk(KERN_ERR"%s: create workqueue failed\n", __FUNCTION__);
503 INIT_WORK(&tsdata->work, pixcir_ts_work_func);
506 tsdata->exiting = false;
507 //tsdata->input = input;
508 //tsdata->chip = pdata;
510 tsdata->client = client;
511 i2c_set_clientdata(client, tsdata);
512 pdata = client->dev.platform_data;
514 //error = setup_resetPin(client,tsdata);
517 printk("%s:setup_resetPin fail\n",__FUNCTION__);
520 tsdata->input->phys = "/dev/input/event2";
521 tsdata->input->name = "pixcir_ts-touchscreen";//client->name;
522 tsdata->input->id.bustype = BUS_I2C;
523 tsdata->input->dev.parent = &client->dev;
527 /*set_bit(EV_SYN, tsdata->input->evbit);
528 set_bit(EV_KEY, tsdata->input->evbit);
529 set_bit(EV_ABS, tsdata->input->evbit);
530 set_bit(BTN_TOUCH, tsdata->input->keybit);
531 set_bit(BTN_2, tsdata->input->keybit);//*/
533 //tsdata->input->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_ABS) ;
534 //tsdata->input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
535 /*tsdata->input->absbit[0] = BIT_MASK(ABS_MT_POSITION_X) | BIT_MASK(ABS_MT_POSITION_Y) |
536 BIT_MASK(ABS_MT_TOUCH_MAJOR) | BIT_MASK(ABS_MT_WIDTH_MAJOR); // for android*/
537 //tsdata->input->keybit[BIT_WORD(BTN_START)] = BIT_MASK(BTN_START);
539 //input_set_abs_params(input, ABS_X, 0, X_MAX, 0, 0);
540 //input_set_abs_params(input, ABS_Y, 0, Y_MAX, 0, 0);
542 __set_bit(INPUT_PROP_DIRECT, tsdata->input->propbit);
543 __set_bit(EV_ABS, tsdata->input->evbit);
545 input_mt_init_slots(tsdata->input, MAX_SUPPORT_POINT);
546 input_set_abs_params(tsdata->input, ABS_MT_POSITION_X, pdata->x_min, pdata->x_max, 0, 0);
547 input_set_abs_params(tsdata->input, ABS_MT_POSITION_Y, pdata->y_min, pdata->y_max, 0, 0);
548 //input_set_abs_params(tsdata->input, ABS_MT_WIDTH_MAJOR, 0, 16, 0, 0);
549 //input_set_abs_params(tsdata->input, ABS_MT_PRESSURE, 0, 255, 0, 0);
550 input_set_abs_params(tsdata->input, ABS_MT_TOUCH_MAJOR, 0, 1, 0, 0);
551 //input_set_abs_params(tsdata->input, ABS_MT_TRACKING_ID, 0, 5, 0, 0);
552 input_set_drvdata(tsdata->input, tsdata);
553 //init int and reset ports
554 error = gpio_request(client->irq, "TS_INT"); //Request IO
556 dev_err(&client->dev, "Failed to request GPIO:%d, ERRNO:%d\n",(int)client->irq, error);
559 rk29_mux_api_set(pdata->pendown_iomux_name, pdata->pendown_iomux_mode);
561 gpio_direction_input(client->irq);
562 gpio_set_value(client->irq,GPIO_HIGH);
563 gpio_pull_updown(client->irq, 0);
565 error = gpio_request(pdata->gpio_reset, "pixcir_resetPin");
567 dev_err(&client->dev, "failed to request resetPin GPIO%d\n", pdata->gpio_reset);
570 rk29_mux_api_set(pdata->resetpin_iomux_name, pdata->resetpin_iomux_mode);
572 gpio_pull_updown(pdata->gpio_reset, 1);
573 gpio_direction_output(pdata->gpio_reset, 0);
574 msleep(20); //delay at least 1ms
575 gpio_direction_input(pdata->gpio_reset);
576 gpio_pull_updown(pdata->gpio_reset, 0);
579 gpio_pull_updown(pdata->gpio_reset, 1);
581 gpio_direction_output(pdata->gpio_reset, 0);
582 gpio_set_value(pdata->gpio_reset,GPIO_HIGH);//GPIO_LOW
584 gpio_set_value(pdata->gpio_reset,GPIO_LOW);//GPIO_HIGH
586 // gpio_direction_input(pdata->gpio_reset);
587 printk("pdata->gpio_reset = %d\n",gpio_get_value(pdata->gpio_reset));
588 //printk("ts->gpio_irq = %d\n",gpio_get_value(pdata->gpio_pendown));
589 printk("pdata->gpio_pendown = %d\n",gpio_get_value(client->irq));
592 //**********************************************
596 tp_pixcir_write_reg(client,buffer,2);
598 //********************************************************//
600 client->irq = gpio_to_irq(client->irq);
601 error = request_irq(client->irq, pixcir_ts_isr, IRQF_TRIGGER_FALLING, client->name, (void *)tsdata);
603 dev_err(&client->dev, "request_irq failed\n");
605 error = request_threaded_irq(client->irq, NULL, pixcir_ts_isr,
606 IRQF_TRIGGER_FALLING,
607 client->name, tsdata);*/
610 dev_err(&client->dev, "Unable to request touchscreen IRQ.\n");
615 error = input_register_device(tsdata->input);
619 i2c_set_clientdata(client, tsdata);
620 device_init_wakeup(&client->dev, 1);
622 /*********************************Bee-0928-TOP****************************************/
623 i2c_dev = get_free_i2c_dev(client->adapter);
624 if (IS_ERR(i2c_dev)) {
625 error = PTR_ERR(i2c_dev);
629 dev = device_create(i2c_dev_class, &client->adapter->dev, MKDEV(I2C_MAJOR,
630 client->adapter->nr), NULL, "pixcir_i2c_ts%d", 0);
632 error = PTR_ERR(dev);
635 /*********************************Bee-0928-BOTTOM****************************************/
636 #ifdef CONFIG_HAS_EARLYSUSPEND
637 tsdata->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
638 tsdata->early_suspend.suspend = pixcir_ts_early_suspend;
639 tsdata->early_suspend.resume = pixcir_ts_late_resume;
640 register_early_suspend(&tsdata->early_suspend);
642 pixcir_proc_entry = proc_create("driver/pixcir", 0777, NULL, &pixcir_proc_fops);
644 dev_err(&tsdata->client->dev, "insmod successfully!\n");
649 free_irq(client->irq, tsdata);
651 input_free_device(tsdata->input);
656 static int __devexit pixcir_i2c_ts_remove(struct i2c_client *client)
659 struct i2c_dev *i2c_dev;
660 struct pixcir_i2c_ts_data *tsdata = i2c_get_clientdata(client);
662 unregister_early_suspend(&tsdata->early_suspend);
663 device_init_wakeup(&client->dev, 0);
665 tsdata->exiting = true;
667 free_irq(client->irq, tsdata);
669 /*********************************Bee-0928-TOP****************************************/
670 i2c_dev = get_free_i2c_dev(client->adapter);
671 if (IS_ERR(i2c_dev)) {
672 error = PTR_ERR(i2c_dev);
676 return_i2c_dev(i2c_dev);
677 device_destroy(i2c_dev_class, MKDEV(I2C_MAJOR, client->adapter->nr));
678 /*********************************Bee-0928-BOTTOM****************************************/
680 input_unregister_device(tsdata->input);
686 /*************************************Bee-0928****************************************/
688 /*************************************Bee-0928****************************************/
689 static int pixcir_open(struct inode *inode, struct file *file)
692 struct i2c_client *client;
693 struct i2c_adapter *adapter;
694 struct i2c_dev *i2c_dev;
697 printk("enter pixcir_open function\n");
699 subminor = iminor(inode);
702 i2c_dev = i2c_dev_get_by_minor(subminor);
704 printk("error i2c_dev\n");
708 adapter = i2c_get_adapter(i2c_dev->adap->nr);
713 client = kzalloc(sizeof(*client), GFP_KERNEL);
715 i2c_put_adapter(adapter);
719 snprintf(client->name, I2C_NAME_SIZE, "pixcir_i2c_ts%d", adapter->nr);
720 client->driver = &pixcir_i2c_ts_driver;
721 client->adapter = adapter;
723 file->private_data = client;
728 /*************************************Bee-0928****************************************/
730 /*************************************Bee-0928****************************************/
731 static long pixcir_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
733 //printk("ioctl function\n");
734 struct i2c_client *client = (struct i2c_client *) file->private_data;
736 printk("cmd = %d,arg = %d\n", cmd, arg);
741 case CALIBRATION_FLAG: //CALIBRATION_FLAG = 1
743 printk("CALIBRATION\n");
745 client->addr = SLAVE_ADDR;
747 status_reg = CALIBRATION_FLAG;
751 break;//return -ENOTTY;
757 /***********************************Bee-0928****************************************/
759 /***********************************Bee-0928****************************************/
760 static ssize_t pixcir_write(struct file *file,const char __user *buf,size_t count, loff_t *ppos)
762 struct i2c_client *client;
766 pixcir_dbg("%s\n",__FUNCTION__);
768 client = file->private_data;
770 //printk("pixcir_write function\n");
773 case CALIBRATION_FLAG: //CALIBRATION_FLAG=1
774 tmp = kmalloc(count,GFP_KERNEL);
778 if (copy_from_user(tmp,buf,count)) {
779 printk("CALIBRATION_FLAG copy_from_user error\n");
784 ret = i2c_master_send(client,tmp,count);
786 dev_err(&client->dev,
787 "%s: i2c_master_recv failed(), ret=%d\n",
791 while(!attb_read_val());//waiting to finish the calibration.(pixcir application_note_710_v3 p43)
804 /***********************************Bee-0928****************************************/
806 /***********************************Bee-0928****************************************/
807 static int pixcir_release(struct inode *inode, struct file *file)
809 struct i2c_client *client = file->private_data;
811 printk("enter pixcir_release funtion\n");
813 i2c_put_adapter(client->adapter);
815 file->private_data = NULL;
820 /*********************************Bee-0928-TOP****************************************/
821 static const struct file_operations pixcir_i2c_ts_fops =
822 { .owner = THIS_MODULE,
823 .write = pixcir_write,
825 .unlocked_ioctl = pixcir_ioctl,
826 .release = pixcir_release,
828 /*********************************Bee-0928-BOTTOM****************************************/
830 static int pixcir_ts_suspend(struct i2c_client *client, pm_message_t mesg)
832 u8 wrbuf[] = {0x33,0x03};
834 struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client);
835 DBG("%s\n", __FUNCTION__);
837 ret = i2c_master_send(ts->client, wrbuf, sizeof(wrbuf));
838 if (ret != sizeof(wrbuf)) {
839 dev_err(&ts->client->dev,
840 "%s: i2c_master_send failed(), ret=%d\n",
845 ret = cancel_work_sync(&ts->work);
848 disable_irq(client->irq);
849 //gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_LOW:GPIO_HIGH);
853 static int pixcir_ts_resume(struct i2c_client *client)
856 struct pixcir_i2c_ts_data *ts = i2c_get_clientdata(client);
857 struct pixcir_platform_data *pdata = client->dev.platform_data;
858 DBG("%s: \n", __FUNCTION__);
860 gpio_set_value(pdata->gpio_reset,GPIO_HIGH);//GPIO_LOW
862 gpio_set_value(pdata->gpio_reset,GPIO_LOW);//GPIO_HIGH
866 enable_irq(client->irq);
867 //gpio_set_value(ts->gpio_reset, ts->gpio_reset_active_low? GPIO_HIGH:GPIO_LOW);
871 #ifdef CONFIG_HAS_EARLYSUSPEND
872 static void pixcir_ts_early_suspend(struct early_suspend *h)
874 struct pixcir_i2c_ts_data *ts;
875 DBG("%s\n",__FUNCTION__);
876 ts = container_of(h, struct pixcir_i2c_ts_data, early_suspend);
877 pixcir_ts_suspend(ts->client, PMSG_SUSPEND);
880 static void pixcir_ts_late_resume(struct early_suspend *h)
882 struct pixcir_i2c_ts_data *ts;
883 DBG("%s\n",__FUNCTION__);
884 ts = container_of(h, struct pixcir_i2c_ts_data, early_suspend);
885 pixcir_ts_resume(ts->client);
889 static const struct i2c_device_id pixcir_i2c_ts_id[] = {
893 MODULE_DEVICE_TABLE(i2c, pixcir_i2c_ts_id);
895 static struct i2c_driver pixcir_i2c_ts_driver = {
897 .owner = THIS_MODULE,
899 //.pm = &pixcir_dev_pm_ops,
901 #ifndef CONFIG_HAS_EARLYSUSPEND
902 .suspend = pixcir_ts_suspend,
903 .resume = pixcir_ts_resume,
905 .probe = pixcir_i2c_ts_probe,
906 .remove = __devexit_p(pixcir_i2c_ts_remove),
907 .id_table = pixcir_i2c_ts_id,
910 static int __init pixcir_i2c_ts_init(void)
914 pixcir_dbg("%s\n",__FUNCTION__);
916 pixcir_wq = create_singlethread_workqueue("pixcir_wq");
920 /*********************************Bee-0928-TOP****************************************/
921 ret = register_chrdev(I2C_MAJOR,"pixcir_i2c_ts",&pixcir_i2c_ts_fops);
923 printk(KERN_ERR "%s:register chrdev failed\n",__FILE__);
927 i2c_dev_class = class_create(THIS_MODULE, "pixcir_i2c_dev");
928 if (IS_ERR(i2c_dev_class)) {
929 ret = PTR_ERR(i2c_dev_class);
930 class_destroy(i2c_dev_class);
932 /********************************Bee-0928-BOTTOM******************************************/
936 return i2c_add_driver(&pixcir_i2c_ts_driver);
938 module_init(pixcir_i2c_ts_init);
940 static void __exit pixcir_i2c_ts_exit(void)
942 i2c_del_driver(&pixcir_i2c_ts_driver);
944 destroy_workqueue(pixcir_wq);
945 /********************************Bee-0928-TOP******************************************/
946 class_destroy(i2c_dev_class);
947 unregister_chrdev(I2C_MAJOR,"pixcir_i2c_ts");
948 /********************************Bee-0928-BOTTOM******************************************/
950 module_exit(pixcir_i2c_ts_exit);
952 MODULE_AUTHOR("Jianchun Bian <jcbian@pixcir.com.cn>");
953 MODULE_DESCRIPTION("Pixcir I2C Touchscreen Driver");
954 MODULE_LICENSE("GPL");