aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/input/touchscreen/auo-pixcir-ts.c163
1 files changed, 69 insertions, 94 deletions
diff --git a/drivers/input/touchscreen/auo-pixcir-ts.c b/drivers/input/touchscreen/auo-pixcir-ts.c
index dfa6d5463ef7..d3f9f6b0f9b7 100644
--- a/drivers/input/touchscreen/auo-pixcir-ts.c
+++ b/drivers/input/touchscreen/auo-pixcir-ts.c
@@ -533,13 +533,21 @@ static struct auo_pixcir_ts_platdata *auo_pixcir_parse_dt(struct device *dev)
533} 533}
534#endif 534#endif
535 535
536static void auo_pixcir_reset(void *data)
537{
538 struct auo_pixcir_ts *ts = data;
539
540 gpio_set_value(ts->pdata->gpio_rst, 0);
541}
542
536static int auo_pixcir_probe(struct i2c_client *client, 543static int auo_pixcir_probe(struct i2c_client *client,
537 const struct i2c_device_id *id) 544 const struct i2c_device_id *id)
538{ 545{
539 const struct auo_pixcir_ts_platdata *pdata; 546 const struct auo_pixcir_ts_platdata *pdata;
540 struct auo_pixcir_ts *ts; 547 struct auo_pixcir_ts *ts;
541 struct input_dev *input_dev; 548 struct input_dev *input_dev;
542 int ret; 549 int version;
550 int error;
543 551
544 pdata = dev_get_platdata(&client->dev); 552 pdata = dev_get_platdata(&client->dev);
545 if (!pdata) { 553 if (!pdata) {
@@ -548,60 +556,30 @@ static int auo_pixcir_probe(struct i2c_client *client,
548 return PTR_ERR(pdata); 556 return PTR_ERR(pdata);
549 } 557 }
550 558
551 ts = kzalloc(sizeof(struct auo_pixcir_ts), GFP_KERNEL); 559 ts = devm_kzalloc(&client->dev,
560 sizeof(struct auo_pixcir_ts), GFP_KERNEL);
552 if (!ts) 561 if (!ts)
553 return -ENOMEM; 562 return -ENOMEM;
554 563
555 ret = gpio_request(pdata->gpio_int, "auo_pixcir_ts_int"); 564 input_dev = devm_input_allocate_device(&client->dev);
556 if (ret) { 565 if (!input_dev) {
557 dev_err(&client->dev, "request of gpio %d failed, %d\n", 566 dev_err(&client->dev, "could not allocate input device\n");
558 pdata->gpio_int, ret); 567 return -ENOMEM;
559 goto err_gpio_int;
560 }
561
562 ret = gpio_direction_input(pdata->gpio_int);
563 if (ret) {
564 dev_err(&client->dev, "setting direction of gpio %d failed %d\n",
565 pdata->gpio_int, ret);
566 goto err_gpio_dir;
567 }
568
569 ret = gpio_request(pdata->gpio_rst, "auo_pixcir_ts_rst");
570 if (ret) {
571 dev_err(&client->dev, "request of gpio %d failed, %d\n",
572 pdata->gpio_rst, ret);
573 goto err_gpio_dir;
574 }
575
576 ret = gpio_direction_output(pdata->gpio_rst, 1);
577 if (ret) {
578 dev_err(&client->dev, "setting direction of gpio %d failed %d\n",
579 pdata->gpio_rst, ret);
580 goto err_gpio_rst;
581 } 568 }
582 569
583 msleep(200);
584
585 ts->pdata = pdata; 570 ts->pdata = pdata;
586 ts->client = client; 571 ts->client = client;
572 ts->input = input_dev;
587 ts->touch_ind_mode = 0; 573 ts->touch_ind_mode = 0;
574 ts->stopped = true;
588 init_waitqueue_head(&ts->wait); 575 init_waitqueue_head(&ts->wait);
589 576
590 snprintf(ts->phys, sizeof(ts->phys), 577 snprintf(ts->phys, sizeof(ts->phys),
591 "%s/input0", dev_name(&client->dev)); 578 "%s/input0", dev_name(&client->dev));
592 579
593 input_dev = input_allocate_device();
594 if (!input_dev) {
595 dev_err(&client->dev, "could not allocate input device\n");
596 goto err_input_alloc;
597 }
598
599 ts->input = input_dev;
600
601 input_dev->name = "AUO-Pixcir touchscreen"; 580 input_dev->name = "AUO-Pixcir touchscreen";
602 input_dev->phys = ts->phys; 581 input_dev->phys = ts->phys;
603 input_dev->id.bustype = BUS_I2C; 582 input_dev->id.bustype = BUS_I2C;
604 input_dev->dev.parent = &client->dev;
605 583
606 input_dev->open = auo_pixcir_input_open; 584 input_dev->open = auo_pixcir_input_open;
607 input_dev->close = auo_pixcir_input_close; 585 input_dev->close = auo_pixcir_input_close;
@@ -626,72 +604,70 @@ static int auo_pixcir_probe(struct i2c_client *client,
626 AUO_PIXCIR_MAX_AREA, 0, 0); 604 AUO_PIXCIR_MAX_AREA, 0, 0);
627 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0); 605 input_set_abs_params(input_dev, ABS_MT_ORIENTATION, 0, 1, 0, 0);
628 606
629 ret = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
630 if (ret < 0)
631 goto err_fw_vers;
632 dev_info(&client->dev, "firmware version 0x%X\n", ret);
633
634 ret = auo_pixcir_int_config(ts, pdata->int_setting);
635 if (ret)
636 goto err_fw_vers;
637
638 input_set_drvdata(ts->input, ts); 607 input_set_drvdata(ts->input, ts);
639 ts->stopped = true;
640 608
641 ret = request_threaded_irq(client->irq, NULL, auo_pixcir_interrupt, 609 error = devm_gpio_request_one(&client->dev, pdata->gpio_int,
642 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 610 GPIOF_DIR_IN, "auo_pixcir_ts_int");
643 input_dev->name, ts); 611 if (error) {
644 if (ret) { 612 dev_err(&client->dev, "request of gpio %d failed, %d\n",
645 dev_err(&client->dev, "irq %d requested failed\n", client->irq); 613 pdata->gpio_int, error);
646 goto err_fw_vers; 614 return error;
647 } 615 }
648 616
649 /* stop device and put it into deep sleep until it is opened */ 617 error = devm_gpio_request_one(&client->dev, pdata->gpio_rst,
650 ret = auo_pixcir_stop(ts); 618 GPIOF_DIR_OUT | GPIOF_INIT_HIGH,
651 if (ret < 0) 619 "auo_pixcir_ts_rst");
652 goto err_input_register; 620 if (error) {
653 621 dev_err(&client->dev, "request of gpio %d failed, %d\n",
654 ret = input_register_device(input_dev); 622 pdata->gpio_rst, error);
655 if (ret) { 623 return error;
656 dev_err(&client->dev, "could not register input device\n");
657 goto err_input_register;
658 } 624 }
659 625
660 i2c_set_clientdata(client, ts); 626 error = devm_add_action(&client->dev, auo_pixcir_reset, ts);
661 627 if (error) {
662 return 0; 628 auo_pixcir_reset(ts);
663 629 dev_err(&client->dev, "failed to register reset action, %d\n",
664err_input_register: 630 error);
665 free_irq(client->irq, ts); 631 return error;
666err_fw_vers: 632 }
667 input_free_device(input_dev);
668err_input_alloc:
669 gpio_set_value(pdata->gpio_rst, 0);
670err_gpio_rst:
671 gpio_free(pdata->gpio_rst);
672err_gpio_dir:
673 gpio_free(pdata->gpio_int);
674err_gpio_int:
675 kfree(ts);
676 633
677 return ret; 634 msleep(200);
678}
679 635
680static int auo_pixcir_remove(struct i2c_client *client) 636 version = i2c_smbus_read_byte_data(client, AUO_PIXCIR_REG_VERSION);
681{ 637 if (version < 0) {
682 struct auo_pixcir_ts *ts = i2c_get_clientdata(client); 638 error = version;
683 const struct auo_pixcir_ts_platdata *pdata = ts->pdata; 639 return error;
640 }
684 641
685 free_irq(client->irq, ts); 642 dev_info(&client->dev, "firmware version 0x%X\n", version);
686 643
687 input_unregister_device(ts->input); 644 error = auo_pixcir_int_config(ts, pdata->int_setting);
645 if (error)
646 return error;
688 647
689 gpio_set_value(pdata->gpio_rst, 0); 648 error = devm_request_threaded_irq(&client->dev, client->irq,
690 gpio_free(pdata->gpio_rst); 649 NULL, auo_pixcir_interrupt,
650 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
651 input_dev->name, ts);
652 if (error) {
653 dev_err(&client->dev, "irq %d requested failed, %d\n",
654 client->irq, error);
655 return error;
656 }
691 657
692 gpio_free(pdata->gpio_int); 658 /* stop device and put it into deep sleep until it is opened */
659 error = auo_pixcir_stop(ts);
660 if (error)
661 return error;
662
663 error = input_register_device(input_dev);
664 if (error) {
665 dev_err(&client->dev, "could not register input device, %d\n",
666 error);
667 return error;
668 }
693 669
694 kfree(ts); 670 i2c_set_clientdata(client, ts);
695 671
696 return 0; 672 return 0;
697} 673}
@@ -718,7 +694,6 @@ static struct i2c_driver auo_pixcir_driver = {
718 .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable), 694 .of_match_table = of_match_ptr(auo_pixcir_ts_dt_idtable),
719 }, 695 },
720 .probe = auo_pixcir_probe, 696 .probe = auo_pixcir_probe,
721 .remove = auo_pixcir_remove,
722 .id_table = auo_pixcir_idtable, 697 .id_table = auo_pixcir_idtable,
723}; 698};
724 699