diff options
author | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-12-15 23:32:42 -0500 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2014-12-15 23:32:42 -0500 |
commit | f20c86cd75f1c8c728dafd0218645ff3c5e8545d (patch) | |
tree | b9100463df79eeafbef87a0bbbaaba4740313120 /drivers/input/mouse | |
parent | a1f9a4072655843fc03186acbad65990cc05dd2d (diff) | |
parent | 1d6a01365fd63fbf7c2709a183e2936728c8efad (diff) |
Merge branch 'next' into for-linus
Prepare input updates for 3.19.
Diffstat (limited to 'drivers/input/mouse')
-rw-r--r-- | drivers/input/mouse/Kconfig | 30 | ||||
-rw-r--r-- | drivers/input/mouse/Makefile | 5 | ||||
-rw-r--r-- | drivers/input/mouse/cyapa.c | 289 | ||||
-rw-r--r-- | drivers/input/mouse/elan_i2c.h | 86 | ||||
-rw-r--r-- | drivers/input/mouse/elan_i2c_core.c | 1137 | ||||
-rw-r--r-- | drivers/input/mouse/elan_i2c_i2c.c | 611 | ||||
-rw-r--r-- | drivers/input/mouse/elan_i2c_smbus.c | 514 | ||||
-rw-r--r-- | drivers/input/mouse/lifebook.h | 6 | ||||
-rw-r--r-- | drivers/input/mouse/navpoint.c | 6 | ||||
-rw-r--r-- | drivers/input/mouse/synaptics_i2c.c | 6 |
10 files changed, 2546 insertions, 144 deletions
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig index 366fc7ad5eb6..d8b46b0f2dbe 100644 --- a/drivers/input/mouse/Kconfig +++ b/drivers/input/mouse/Kconfig | |||
@@ -215,6 +215,36 @@ config MOUSE_CYAPA | |||
215 | To compile this driver as a module, choose M here: the module will be | 215 | To compile this driver as a module, choose M here: the module will be |
216 | called cyapa. | 216 | called cyapa. |
217 | 217 | ||
218 | config MOUSE_ELAN_I2C | ||
219 | tristate "ELAN I2C Touchpad support" | ||
220 | depends on I2C | ||
221 | help | ||
222 | This driver adds support for Elan I2C/SMbus Trackpads. | ||
223 | |||
224 | Say Y here if you have a ELAN I2C/SMbus Touchpad. | ||
225 | |||
226 | To compile this driver as a module, choose M here: the module will be | ||
227 | called elan_i2c. | ||
228 | |||
229 | config MOUSE_ELAN_I2C_I2C | ||
230 | bool "Enable I2C support" | ||
231 | depends on MOUSE_ELAN_I2C | ||
232 | default y | ||
233 | help | ||
234 | Say Y here if Elan Touchpad in your system is connected to | ||
235 | a standard I2C controller. | ||
236 | |||
237 | If unsure, say Y. | ||
238 | |||
239 | config MOUSE_ELAN_I2C_SMBUS | ||
240 | bool "Enable SMbus support" | ||
241 | depends on MOUSE_ELAN_I2C | ||
242 | help | ||
243 | Say Y here if Elan Touchpad in your system is connected to | ||
244 | a SMbus adapter. | ||
245 | |||
246 | If unsure, say Y. | ||
247 | |||
218 | config MOUSE_INPORT | 248 | config MOUSE_INPORT |
219 | tristate "InPort/MS/ATIXL busmouse" | 249 | tristate "InPort/MS/ATIXL busmouse" |
220 | depends on ISA | 250 | depends on ISA |
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile index dda507f8b3a2..560003dcac37 100644 --- a/drivers/input/mouse/Makefile +++ b/drivers/input/mouse/Makefile | |||
@@ -9,6 +9,7 @@ obj-$(CONFIG_MOUSE_APPLETOUCH) += appletouch.o | |||
9 | obj-$(CONFIG_MOUSE_ATARI) += atarimouse.o | 9 | obj-$(CONFIG_MOUSE_ATARI) += atarimouse.o |
10 | obj-$(CONFIG_MOUSE_BCM5974) += bcm5974.o | 10 | obj-$(CONFIG_MOUSE_BCM5974) += bcm5974.o |
11 | obj-$(CONFIG_MOUSE_CYAPA) += cyapa.o | 11 | obj-$(CONFIG_MOUSE_CYAPA) += cyapa.o |
12 | obj-$(CONFIG_MOUSE_ELAN_I2C) += elan_i2c.o | ||
12 | obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o | 13 | obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o |
13 | obj-$(CONFIG_MOUSE_INPORT) += inport.o | 14 | obj-$(CONFIG_MOUSE_INPORT) += inport.o |
14 | obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o | 15 | obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o |
@@ -34,3 +35,7 @@ psmouse-$(CONFIG_MOUSE_PS2_SENTELIC) += sentelic.o | |||
34 | psmouse-$(CONFIG_MOUSE_PS2_TRACKPOINT) += trackpoint.o | 35 | psmouse-$(CONFIG_MOUSE_PS2_TRACKPOINT) += trackpoint.o |
35 | psmouse-$(CONFIG_MOUSE_PS2_TOUCHKIT) += touchkit_ps2.o | 36 | psmouse-$(CONFIG_MOUSE_PS2_TOUCHKIT) += touchkit_ps2.o |
36 | psmouse-$(CONFIG_MOUSE_PS2_CYPRESS) += cypress_ps2.o | 37 | psmouse-$(CONFIG_MOUSE_PS2_CYPRESS) += cypress_ps2.o |
38 | |||
39 | elan_i2c-objs := elan_i2c_core.o | ||
40 | elan_i2c-$(CONFIG_MOUSE_ELAN_I2C_I2C) += elan_i2c_i2c.o | ||
41 | elan_i2c-$(CONFIG_MOUSE_ELAN_I2C_SMBUS) += elan_i2c_smbus.o | ||
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c index b409c3d7d4fb..1bece8cad46f 100644 --- a/drivers/input/mouse/cyapa.c +++ b/drivers/input/mouse/cyapa.c | |||
@@ -6,7 +6,7 @@ | |||
6 | * Daniel Kurtz <djkurtz@chromium.org> | 6 | * Daniel Kurtz <djkurtz@chromium.org> |
7 | * Benson Leung <bleung@chromium.org> | 7 | * Benson Leung <bleung@chromium.org> |
8 | * | 8 | * |
9 | * Copyright (C) 2011-2012 Cypress Semiconductor, Inc. | 9 | * Copyright (C) 2011-2014 Cypress Semiconductor, Inc. |
10 | * Copyright (C) 2011-2012 Google, Inc. | 10 | * Copyright (C) 2011-2012 Google, Inc. |
11 | * | 11 | * |
12 | * This file is subject to the terms and conditions of the GNU General Public | 12 | * This file is subject to the terms and conditions of the GNU General Public |
@@ -206,7 +206,6 @@ struct cyapa { | |||
206 | struct i2c_client *client; | 206 | struct i2c_client *client; |
207 | struct input_dev *input; | 207 | struct input_dev *input; |
208 | char phys[32]; /* device physical location */ | 208 | char phys[32]; /* device physical location */ |
209 | int irq; | ||
210 | bool irq_wake; /* irq wake is enabled */ | 209 | bool irq_wake; /* irq wake is enabled */ |
211 | bool smbus; | 210 | bool smbus; |
212 | 211 | ||
@@ -422,8 +421,8 @@ static ssize_t cyapa_read_block(struct cyapa *cyapa, u8 cmd_idx, u8 *values) | |||
422 | */ | 421 | */ |
423 | static int cyapa_get_state(struct cyapa *cyapa) | 422 | static int cyapa_get_state(struct cyapa *cyapa) |
424 | { | 423 | { |
425 | int ret; | ||
426 | u8 status[BL_STATUS_SIZE]; | 424 | u8 status[BL_STATUS_SIZE]; |
425 | int error; | ||
427 | 426 | ||
428 | cyapa->state = CYAPA_STATE_NO_DEVICE; | 427 | cyapa->state = CYAPA_STATE_NO_DEVICE; |
429 | 428 | ||
@@ -433,18 +432,18 @@ static int cyapa_get_state(struct cyapa *cyapa) | |||
433 | * If the device is in operation mode, this will be the DATA regs. | 432 | * If the device is in operation mode, this will be the DATA regs. |
434 | * | 433 | * |
435 | */ | 434 | */ |
436 | ret = cyapa_i2c_reg_read_block(cyapa, BL_HEAD_OFFSET, BL_STATUS_SIZE, | 435 | error = cyapa_i2c_reg_read_block(cyapa, BL_HEAD_OFFSET, BL_STATUS_SIZE, |
437 | status); | 436 | status); |
438 | 437 | ||
439 | /* | 438 | /* |
440 | * On smbus systems in OP mode, the i2c_reg_read will fail with | 439 | * On smbus systems in OP mode, the i2c_reg_read will fail with |
441 | * -ETIMEDOUT. In this case, try again using the smbus equivalent | 440 | * -ETIMEDOUT. In this case, try again using the smbus equivalent |
442 | * command. This should return a BL_HEAD indicating CYAPA_STATE_OP. | 441 | * command. This should return a BL_HEAD indicating CYAPA_STATE_OP. |
443 | */ | 442 | */ |
444 | if (cyapa->smbus && (ret == -ETIMEDOUT || ret == -ENXIO)) | 443 | if (cyapa->smbus && (error == -ETIMEDOUT || error == -ENXIO)) |
445 | ret = cyapa_read_block(cyapa, CYAPA_CMD_BL_STATUS, status); | 444 | error = cyapa_read_block(cyapa, CYAPA_CMD_BL_STATUS, status); |
446 | 445 | ||
447 | if (ret != BL_STATUS_SIZE) | 446 | if (error != BL_STATUS_SIZE) |
448 | goto error; | 447 | goto error; |
449 | 448 | ||
450 | if ((status[REG_OP_STATUS] & OP_STATUS_SRC) == OP_STATUS_SRC) { | 449 | if ((status[REG_OP_STATUS] & OP_STATUS_SRC) == OP_STATUS_SRC) { |
@@ -454,7 +453,7 @@ static int cyapa_get_state(struct cyapa *cyapa) | |||
454 | cyapa->state = CYAPA_STATE_OP; | 453 | cyapa->state = CYAPA_STATE_OP; |
455 | break; | 454 | break; |
456 | default: | 455 | default: |
457 | ret = -EAGAIN; | 456 | error = -EAGAIN; |
458 | goto error; | 457 | goto error; |
459 | } | 458 | } |
460 | } else { | 459 | } else { |
@@ -468,7 +467,7 @@ static int cyapa_get_state(struct cyapa *cyapa) | |||
468 | 467 | ||
469 | return 0; | 468 | return 0; |
470 | error: | 469 | error: |
471 | return (ret < 0) ? ret : -EAGAIN; | 470 | return (error < 0) ? error : -EAGAIN; |
472 | } | 471 | } |
473 | 472 | ||
474 | /* | 473 | /* |
@@ -487,31 +486,31 @@ error: | |||
487 | */ | 486 | */ |
488 | static int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout) | 487 | static int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout) |
489 | { | 488 | { |
490 | int ret; | 489 | int error; |
491 | int tries = timeout / 100; | 490 | int tries = timeout / 100; |
492 | 491 | ||
493 | ret = cyapa_get_state(cyapa); | 492 | error = cyapa_get_state(cyapa); |
494 | while ((ret || cyapa->state >= CYAPA_STATE_BL_BUSY) && tries--) { | 493 | while ((error || cyapa->state >= CYAPA_STATE_BL_BUSY) && tries--) { |
495 | msleep(100); | 494 | msleep(100); |
496 | ret = cyapa_get_state(cyapa); | 495 | error = cyapa_get_state(cyapa); |
497 | } | 496 | } |
498 | return (ret == -EAGAIN || ret == -ETIMEDOUT) ? -ETIMEDOUT : ret; | 497 | return (error == -EAGAIN || error == -ETIMEDOUT) ? -ETIMEDOUT : error; |
499 | } | 498 | } |
500 | 499 | ||
501 | static int cyapa_bl_deactivate(struct cyapa *cyapa) | 500 | static int cyapa_bl_deactivate(struct cyapa *cyapa) |
502 | { | 501 | { |
503 | int ret; | 502 | int error; |
504 | 503 | ||
505 | ret = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_deactivate), | 504 | error = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_deactivate), |
506 | bl_deactivate); | 505 | bl_deactivate); |
507 | if (ret < 0) | 506 | if (error) |
508 | return ret; | 507 | return error; |
509 | 508 | ||
510 | /* wait for bootloader to switch to idle state; should take < 100ms */ | 509 | /* wait for bootloader to switch to idle state; should take < 100ms */ |
511 | msleep(100); | 510 | msleep(100); |
512 | ret = cyapa_poll_state(cyapa, 500); | 511 | error = cyapa_poll_state(cyapa, 500); |
513 | if (ret < 0) | 512 | if (error) |
514 | return ret; | 513 | return error; |
515 | if (cyapa->state != CYAPA_STATE_BL_IDLE) | 514 | if (cyapa->state != CYAPA_STATE_BL_IDLE) |
516 | return -EAGAIN; | 515 | return -EAGAIN; |
517 | return 0; | 516 | return 0; |
@@ -532,11 +531,11 @@ static int cyapa_bl_deactivate(struct cyapa *cyapa) | |||
532 | */ | 531 | */ |
533 | static int cyapa_bl_exit(struct cyapa *cyapa) | 532 | static int cyapa_bl_exit(struct cyapa *cyapa) |
534 | { | 533 | { |
535 | int ret; | 534 | int error; |
536 | 535 | ||
537 | ret = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_exit), bl_exit); | 536 | error = cyapa_i2c_reg_write_block(cyapa, 0, sizeof(bl_exit), bl_exit); |
538 | if (ret < 0) | 537 | if (error) |
539 | return ret; | 538 | return error; |
540 | 539 | ||
541 | /* | 540 | /* |
542 | * Wait for bootloader to exit, and operation mode to start. | 541 | * Wait for bootloader to exit, and operation mode to start. |
@@ -548,9 +547,9 @@ static int cyapa_bl_exit(struct cyapa *cyapa) | |||
548 | * updated to new firmware, it must first calibrate its sensors, which | 547 | * updated to new firmware, it must first calibrate its sensors, which |
549 | * can take up to an additional 2 seconds. | 548 | * can take up to an additional 2 seconds. |
550 | */ | 549 | */ |
551 | ret = cyapa_poll_state(cyapa, 2000); | 550 | error = cyapa_poll_state(cyapa, 2000); |
552 | if (ret < 0) | 551 | if (error < 0) |
553 | return ret; | 552 | return error; |
554 | if (cyapa->state != CYAPA_STATE_OP) | 553 | if (cyapa->state != CYAPA_STATE_OP) |
555 | return -EAGAIN; | 554 | return -EAGAIN; |
556 | 555 | ||
@@ -577,10 +576,13 @@ static int cyapa_set_power_mode(struct cyapa *cyapa, u8 power_mode) | |||
577 | power = ret & ~PWR_MODE_MASK; | 576 | power = ret & ~PWR_MODE_MASK; |
578 | power |= power_mode & PWR_MODE_MASK; | 577 | power |= power_mode & PWR_MODE_MASK; |
579 | ret = cyapa_write_byte(cyapa, CYAPA_CMD_POWER_MODE, power); | 578 | ret = cyapa_write_byte(cyapa, CYAPA_CMD_POWER_MODE, power); |
580 | if (ret < 0) | 579 | if (ret < 0) { |
581 | dev_err(dev, "failed to set power_mode 0x%02x err = %d\n", | 580 | dev_err(dev, "failed to set power_mode 0x%02x err = %d\n", |
582 | power_mode, ret); | 581 | power_mode, ret); |
583 | return ret; | 582 | return ret; |
583 | } | ||
584 | |||
585 | return 0; | ||
584 | } | 586 | } |
585 | 587 | ||
586 | static int cyapa_get_query_data(struct cyapa *cyapa) | 588 | static int cyapa_get_query_data(struct cyapa *cyapa) |
@@ -637,28 +639,28 @@ static int cyapa_check_is_operational(struct cyapa *cyapa) | |||
637 | { | 639 | { |
638 | struct device *dev = &cyapa->client->dev; | 640 | struct device *dev = &cyapa->client->dev; |
639 | static const char unique_str[] = "CYTRA"; | 641 | static const char unique_str[] = "CYTRA"; |
640 | int ret; | 642 | int error; |
641 | 643 | ||
642 | ret = cyapa_poll_state(cyapa, 2000); | 644 | error = cyapa_poll_state(cyapa, 2000); |
643 | if (ret < 0) | 645 | if (error) |
644 | return ret; | 646 | return error; |
645 | switch (cyapa->state) { | 647 | switch (cyapa->state) { |
646 | case CYAPA_STATE_BL_ACTIVE: | 648 | case CYAPA_STATE_BL_ACTIVE: |
647 | ret = cyapa_bl_deactivate(cyapa); | 649 | error = cyapa_bl_deactivate(cyapa); |
648 | if (ret) | 650 | if (error) |
649 | return ret; | 651 | return error; |
650 | 652 | ||
651 | /* Fallthrough state */ | 653 | /* Fallthrough state */ |
652 | case CYAPA_STATE_BL_IDLE: | 654 | case CYAPA_STATE_BL_IDLE: |
653 | ret = cyapa_bl_exit(cyapa); | 655 | error = cyapa_bl_exit(cyapa); |
654 | if (ret) | 656 | if (error) |
655 | return ret; | 657 | return error; |
656 | 658 | ||
657 | /* Fallthrough state */ | 659 | /* Fallthrough state */ |
658 | case CYAPA_STATE_OP: | 660 | case CYAPA_STATE_OP: |
659 | ret = cyapa_get_query_data(cyapa); | 661 | error = cyapa_get_query_data(cyapa); |
660 | if (ret < 0) | 662 | if (error) |
661 | return ret; | 663 | return error; |
662 | 664 | ||
663 | /* only support firmware protocol gen3 */ | 665 | /* only support firmware protocol gen3 */ |
664 | if (cyapa->gen != CYAPA_GEN3) { | 666 | if (cyapa->gen != CYAPA_GEN3) { |
@@ -753,18 +755,42 @@ static u8 cyapa_check_adapter_functionality(struct i2c_client *client) | |||
753 | return ret; | 755 | return ret; |
754 | } | 756 | } |
755 | 757 | ||
758 | static int cyapa_open(struct input_dev *input) | ||
759 | { | ||
760 | struct cyapa *cyapa = input_get_drvdata(input); | ||
761 | struct i2c_client *client = cyapa->client; | ||
762 | int error; | ||
763 | |||
764 | error = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE); | ||
765 | if (error) { | ||
766 | dev_err(&client->dev, "set active power failed: %d\n", error); | ||
767 | return error; | ||
768 | } | ||
769 | |||
770 | enable_irq(client->irq); | ||
771 | return 0; | ||
772 | } | ||
773 | |||
774 | static void cyapa_close(struct input_dev *input) | ||
775 | { | ||
776 | struct cyapa *cyapa = input_get_drvdata(input); | ||
777 | |||
778 | disable_irq(cyapa->client->irq); | ||
779 | cyapa_set_power_mode(cyapa, PWR_MODE_OFF); | ||
780 | } | ||
781 | |||
756 | static int cyapa_create_input_dev(struct cyapa *cyapa) | 782 | static int cyapa_create_input_dev(struct cyapa *cyapa) |
757 | { | 783 | { |
758 | struct device *dev = &cyapa->client->dev; | 784 | struct device *dev = &cyapa->client->dev; |
759 | int ret; | ||
760 | struct input_dev *input; | 785 | struct input_dev *input; |
786 | int error; | ||
761 | 787 | ||
762 | if (!cyapa->physical_size_x || !cyapa->physical_size_y) | 788 | if (!cyapa->physical_size_x || !cyapa->physical_size_y) |
763 | return -EINVAL; | 789 | return -EINVAL; |
764 | 790 | ||
765 | input = cyapa->input = input_allocate_device(); | 791 | input = devm_input_allocate_device(dev); |
766 | if (!input) { | 792 | if (!input) { |
767 | dev_err(dev, "allocate memory for input device failed\n"); | 793 | dev_err(dev, "failed to allocate memory for input device.\n"); |
768 | return -ENOMEM; | 794 | return -ENOMEM; |
769 | } | 795 | } |
770 | 796 | ||
@@ -772,14 +798,17 @@ static int cyapa_create_input_dev(struct cyapa *cyapa) | |||
772 | input->phys = cyapa->phys; | 798 | input->phys = cyapa->phys; |
773 | input->id.bustype = BUS_I2C; | 799 | input->id.bustype = BUS_I2C; |
774 | input->id.version = 1; | 800 | input->id.version = 1; |
775 | input->id.product = 0; /* means any product in eventcomm. */ | 801 | input->id.product = 0; /* Means any product in eventcomm. */ |
776 | input->dev.parent = &cyapa->client->dev; | 802 | input->dev.parent = &cyapa->client->dev; |
777 | 803 | ||
804 | input->open = cyapa_open; | ||
805 | input->close = cyapa_close; | ||
806 | |||
778 | input_set_drvdata(input, cyapa); | 807 | input_set_drvdata(input, cyapa); |
779 | 808 | ||
780 | __set_bit(EV_ABS, input->evbit); | 809 | __set_bit(EV_ABS, input->evbit); |
781 | 810 | ||
782 | /* finger position */ | 811 | /* Finger position */ |
783 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, cyapa->max_abs_x, 0, | 812 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, cyapa->max_abs_x, 0, |
784 | 0); | 813 | 0); |
785 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cyapa->max_abs_y, 0, | 814 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, cyapa->max_abs_y, 0, |
@@ -801,35 +830,25 @@ static int cyapa_create_input_dev(struct cyapa *cyapa) | |||
801 | if (cyapa->btn_capability == CAPABILITY_LEFT_BTN_MASK) | 830 | if (cyapa->btn_capability == CAPABILITY_LEFT_BTN_MASK) |
802 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); | 831 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); |
803 | 832 | ||
804 | /* handle pointer emulation and unused slots in core */ | 833 | /* Handle pointer emulation and unused slots in core */ |
805 | ret = input_mt_init_slots(input, CYAPA_MAX_MT_SLOTS, | 834 | error = input_mt_init_slots(input, CYAPA_MAX_MT_SLOTS, |
806 | INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED); | 835 | INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED); |
807 | if (ret) { | 836 | if (error) { |
808 | dev_err(dev, "allocate memory for MT slots failed, %d\n", ret); | 837 | dev_err(dev, "failed to initialize MT slots: %d\n", error); |
809 | goto err_free_device; | 838 | return error; |
810 | } | 839 | } |
811 | 840 | ||
812 | /* Register the device in input subsystem */ | 841 | cyapa->input = input; |
813 | ret = input_register_device(input); | ||
814 | if (ret) { | ||
815 | dev_err(dev, "input device register failed, %d\n", ret); | ||
816 | goto err_free_device; | ||
817 | } | ||
818 | return 0; | 842 | return 0; |
819 | |||
820 | err_free_device: | ||
821 | input_free_device(input); | ||
822 | cyapa->input = NULL; | ||
823 | return ret; | ||
824 | } | 843 | } |
825 | 844 | ||
826 | static int cyapa_probe(struct i2c_client *client, | 845 | static int cyapa_probe(struct i2c_client *client, |
827 | const struct i2c_device_id *dev_id) | 846 | const struct i2c_device_id *dev_id) |
828 | { | 847 | { |
829 | int ret; | ||
830 | u8 adapter_func; | ||
831 | struct cyapa *cyapa; | ||
832 | struct device *dev = &client->dev; | 848 | struct device *dev = &client->dev; |
849 | struct cyapa *cyapa; | ||
850 | u8 adapter_func; | ||
851 | int error; | ||
833 | 852 | ||
834 | adapter_func = cyapa_check_adapter_functionality(client); | 853 | adapter_func = cyapa_check_adapter_functionality(client); |
835 | if (adapter_func == CYAPA_ADAPTER_FUNC_NONE) { | 854 | if (adapter_func == CYAPA_ADAPTER_FUNC_NONE) { |
@@ -837,11 +856,9 @@ static int cyapa_probe(struct i2c_client *client, | |||
837 | return -EIO; | 856 | return -EIO; |
838 | } | 857 | } |
839 | 858 | ||
840 | cyapa = kzalloc(sizeof(struct cyapa), GFP_KERNEL); | 859 | cyapa = devm_kzalloc(dev, sizeof(struct cyapa), GFP_KERNEL); |
841 | if (!cyapa) { | 860 | if (!cyapa) |
842 | dev_err(dev, "allocate memory for cyapa failed\n"); | ||
843 | return -ENOMEM; | 861 | return -ENOMEM; |
844 | } | ||
845 | 862 | ||
846 | cyapa->gen = CYAPA_GEN3; | 863 | cyapa->gen = CYAPA_GEN3; |
847 | cyapa->client = client; | 864 | cyapa->client = client; |
@@ -852,67 +869,61 @@ static int cyapa_probe(struct i2c_client *client, | |||
852 | /* i2c isn't supported, use smbus */ | 869 | /* i2c isn't supported, use smbus */ |
853 | if (adapter_func == CYAPA_ADAPTER_FUNC_SMBUS) | 870 | if (adapter_func == CYAPA_ADAPTER_FUNC_SMBUS) |
854 | cyapa->smbus = true; | 871 | cyapa->smbus = true; |
872 | |||
855 | cyapa->state = CYAPA_STATE_NO_DEVICE; | 873 | cyapa->state = CYAPA_STATE_NO_DEVICE; |
856 | ret = cyapa_check_is_operational(cyapa); | ||
857 | if (ret) { | ||
858 | dev_err(dev, "device not operational, %d\n", ret); | ||
859 | goto err_mem_free; | ||
860 | } | ||
861 | 874 | ||
862 | ret = cyapa_create_input_dev(cyapa); | 875 | error = cyapa_check_is_operational(cyapa); |
863 | if (ret) { | 876 | if (error) { |
864 | dev_err(dev, "create input_dev instance failed, %d\n", ret); | 877 | dev_err(dev, "device not operational, %d\n", error); |
865 | goto err_mem_free; | 878 | return error; |
866 | } | 879 | } |
867 | 880 | ||
868 | ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE); | 881 | /* Power down the device until we need it */ |
869 | if (ret) { | 882 | error = cyapa_set_power_mode(cyapa, PWR_MODE_OFF); |
870 | dev_err(dev, "set active power failed, %d\n", ret); | 883 | if (error) { |
871 | goto err_unregister_device; | 884 | dev_err(dev, "failed to quiesce the device: %d\n", error); |
885 | return error; | ||
872 | } | 886 | } |
873 | 887 | ||
874 | cyapa->irq = client->irq; | 888 | error = cyapa_create_input_dev(cyapa); |
875 | ret = request_threaded_irq(cyapa->irq, | 889 | if (error) |
876 | NULL, | 890 | return error; |
877 | cyapa_irq, | 891 | |
878 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, | 892 | error = devm_request_threaded_irq(dev, client->irq, |
879 | "cyapa", | 893 | NULL, cyapa_irq, |
880 | cyapa); | 894 | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, |
881 | if (ret) { | 895 | "cyapa", cyapa); |
882 | dev_err(dev, "IRQ request failed: %d\n, ", ret); | 896 | if (error) { |
883 | goto err_unregister_device; | 897 | dev_err(dev, "failed to request threaded irq: %d\n", error); |
898 | return error; | ||
884 | } | 899 | } |
885 | 900 | ||
886 | return 0; | 901 | /* Disable IRQ until the device is opened */ |
902 | disable_irq(client->irq); | ||
887 | 903 | ||
888 | err_unregister_device: | 904 | /* Register the device in input subsystem */ |
889 | input_unregister_device(cyapa->input); | 905 | error = input_register_device(cyapa->input); |
890 | err_mem_free: | 906 | if (error) { |
891 | kfree(cyapa); | 907 | dev_err(dev, "failed to register input device: %d\n", error); |
892 | 908 | return error; | |
893 | return ret; | 909 | } |
894 | } | ||
895 | |||
896 | static int cyapa_remove(struct i2c_client *client) | ||
897 | { | ||
898 | struct cyapa *cyapa = i2c_get_clientdata(client); | ||
899 | |||
900 | free_irq(cyapa->irq, cyapa); | ||
901 | input_unregister_device(cyapa->input); | ||
902 | cyapa_set_power_mode(cyapa, PWR_MODE_OFF); | ||
903 | kfree(cyapa); | ||
904 | 910 | ||
905 | return 0; | 911 | return 0; |
906 | } | 912 | } |
907 | 913 | ||
908 | #ifdef CONFIG_PM_SLEEP | 914 | static int __maybe_unused cyapa_suspend(struct device *dev) |
909 | static int cyapa_suspend(struct device *dev) | ||
910 | { | 915 | { |
911 | int ret; | 916 | struct i2c_client *client = to_i2c_client(dev); |
917 | struct cyapa *cyapa = i2c_get_clientdata(client); | ||
918 | struct input_dev *input = cyapa->input; | ||
912 | u8 power_mode; | 919 | u8 power_mode; |
913 | struct cyapa *cyapa = dev_get_drvdata(dev); | 920 | int error; |
914 | 921 | ||
915 | disable_irq(cyapa->irq); | 922 | error = mutex_lock_interruptible(&input->mutex); |
923 | if (error) | ||
924 | return error; | ||
925 | |||
926 | disable_irq(client->irq); | ||
916 | 927 | ||
917 | /* | 928 | /* |
918 | * Set trackpad device to idle mode if wakeup is allowed, | 929 | * Set trackpad device to idle mode if wakeup is allowed, |
@@ -920,31 +931,44 @@ static int cyapa_suspend(struct device *dev) | |||
920 | */ | 931 | */ |
921 | power_mode = device_may_wakeup(dev) ? PWR_MODE_IDLE | 932 | power_mode = device_may_wakeup(dev) ? PWR_MODE_IDLE |
922 | : PWR_MODE_OFF; | 933 | : PWR_MODE_OFF; |
923 | ret = cyapa_set_power_mode(cyapa, power_mode); | 934 | error = cyapa_set_power_mode(cyapa, power_mode); |
924 | if (ret < 0) | 935 | if (error) |
925 | dev_err(dev, "set power mode failed, %d\n", ret); | 936 | dev_err(dev, "resume: set power mode to %d failed: %d\n", |
937 | power_mode, error); | ||
926 | 938 | ||
927 | if (device_may_wakeup(dev)) | 939 | if (device_may_wakeup(dev)) |
928 | cyapa->irq_wake = (enable_irq_wake(cyapa->irq) == 0); | 940 | cyapa->irq_wake = (enable_irq_wake(client->irq) == 0); |
941 | |||
942 | mutex_unlock(&input->mutex); | ||
943 | |||
929 | return 0; | 944 | return 0; |
930 | } | 945 | } |
931 | 946 | ||
932 | static int cyapa_resume(struct device *dev) | 947 | static int __maybe_unused cyapa_resume(struct device *dev) |
933 | { | 948 | { |
934 | int ret; | 949 | struct i2c_client *client = to_i2c_client(dev); |
935 | struct cyapa *cyapa = dev_get_drvdata(dev); | 950 | struct cyapa *cyapa = i2c_get_clientdata(client); |
951 | struct input_dev *input = cyapa->input; | ||
952 | u8 power_mode; | ||
953 | int error; | ||
954 | |||
955 | mutex_lock(&input->mutex); | ||
936 | 956 | ||
937 | if (device_may_wakeup(dev) && cyapa->irq_wake) | 957 | if (device_may_wakeup(dev) && cyapa->irq_wake) |
938 | disable_irq_wake(cyapa->irq); | 958 | disable_irq_wake(client->irq); |
959 | |||
960 | power_mode = input->users ? PWR_MODE_FULL_ACTIVE : PWR_MODE_OFF; | ||
961 | error = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE); | ||
962 | if (error) | ||
963 | dev_warn(dev, "resume: set power mode to %d failed: %d\n", | ||
964 | power_mode, error); | ||
965 | |||
966 | enable_irq(client->irq); | ||
939 | 967 | ||
940 | ret = cyapa_set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE); | 968 | mutex_unlock(&input->mutex); |
941 | if (ret) | ||
942 | dev_warn(dev, "resume active power failed, %d\n", ret); | ||
943 | 969 | ||
944 | enable_irq(cyapa->irq); | ||
945 | return 0; | 970 | return 0; |
946 | } | 971 | } |
947 | #endif /* CONFIG_PM_SLEEP */ | ||
948 | 972 | ||
949 | static SIMPLE_DEV_PM_OPS(cyapa_pm_ops, cyapa_suspend, cyapa_resume); | 973 | static SIMPLE_DEV_PM_OPS(cyapa_pm_ops, cyapa_suspend, cyapa_resume); |
950 | 974 | ||
@@ -962,7 +986,6 @@ static struct i2c_driver cyapa_driver = { | |||
962 | }, | 986 | }, |
963 | 987 | ||
964 | .probe = cyapa_probe, | 988 | .probe = cyapa_probe, |
965 | .remove = cyapa_remove, | ||
966 | .id_table = cyapa_id_table, | 989 | .id_table = cyapa_id_table, |
967 | }; | 990 | }; |
968 | 991 | ||
diff --git a/drivers/input/mouse/elan_i2c.h b/drivers/input/mouse/elan_i2c.h new file mode 100644 index 000000000000..2e838626205f --- /dev/null +++ b/drivers/input/mouse/elan_i2c.h | |||
@@ -0,0 +1,86 @@ | |||
1 | /* | ||
2 | * Elan I2C/SMBus Touchpad driver | ||
3 | * | ||
4 | * Copyright (c) 2013 ELAN Microelectronics Corp. | ||
5 | * | ||
6 | * Author: æž—æ”¿ç¶ (Duson Lin) <dusonlin@emc.com.tw> | ||
7 | * Version: 1.5.5 | ||
8 | * | ||
9 | * Based on cyapa driver: | ||
10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. | ||
11 | * copyright (c) 2011-2012 Google, Inc. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License version 2 as published | ||
15 | * by the Free Software Foundation. | ||
16 | * | ||
17 | * Trademarks are the property of their respective owners. | ||
18 | */ | ||
19 | |||
20 | #ifndef _ELAN_I2C_H | ||
21 | #define _ELAN_i2C_H | ||
22 | |||
23 | #include <linux/types.h> | ||
24 | |||
25 | #define ETP_ENABLE_ABS 0x0001 | ||
26 | #define ETP_ENABLE_CALIBRATE 0x0002 | ||
27 | #define ETP_DISABLE_CALIBRATE 0x0000 | ||
28 | #define ETP_DISABLE_POWER 0x0001 | ||
29 | |||
30 | /* IAP Firmware handling */ | ||
31 | #define ETP_FW_NAME "elan_i2c.bin" | ||
32 | #define ETP_IAP_START_ADDR 0x0083 | ||
33 | #define ETP_FW_IAP_PAGE_ERR (1 << 5) | ||
34 | #define ETP_FW_IAP_INTF_ERR (1 << 4) | ||
35 | #define ETP_FW_PAGE_SIZE 64 | ||
36 | #define ETP_FW_PAGE_COUNT 768 | ||
37 | #define ETP_FW_SIZE (ETP_FW_PAGE_SIZE * ETP_FW_PAGE_COUNT) | ||
38 | |||
39 | struct i2c_client; | ||
40 | struct completion; | ||
41 | |||
42 | enum tp_mode { | ||
43 | IAP_MODE = 1, | ||
44 | MAIN_MODE | ||
45 | }; | ||
46 | |||
47 | struct elan_transport_ops { | ||
48 | int (*initialize)(struct i2c_client *client); | ||
49 | int (*sleep_control)(struct i2c_client *, bool sleep); | ||
50 | int (*power_control)(struct i2c_client *, bool enable); | ||
51 | int (*set_mode)(struct i2c_client *client, u8 mode); | ||
52 | |||
53 | int (*calibrate)(struct i2c_client *client); | ||
54 | int (*calibrate_result)(struct i2c_client *client, u8 *val); | ||
55 | |||
56 | int (*get_baseline_data)(struct i2c_client *client, | ||
57 | bool max_baseliune, u8 *value); | ||
58 | |||
59 | int (*get_version)(struct i2c_client *client, bool iap, u8 *version); | ||
60 | int (*get_sm_version)(struct i2c_client *client, u8 *version); | ||
61 | int (*get_checksum)(struct i2c_client *client, bool iap, u16 *csum); | ||
62 | int (*get_product_id)(struct i2c_client *client, u8 *id); | ||
63 | |||
64 | int (*get_max)(struct i2c_client *client, | ||
65 | unsigned int *max_x, unsigned int *max_y); | ||
66 | int (*get_resolution)(struct i2c_client *client, | ||
67 | u8 *hw_res_x, u8 *hw_res_y); | ||
68 | int (*get_num_traces)(struct i2c_client *client, | ||
69 | unsigned int *x_tracenum, | ||
70 | unsigned int *y_tracenum); | ||
71 | |||
72 | int (*iap_get_mode)(struct i2c_client *client, enum tp_mode *mode); | ||
73 | int (*iap_reset)(struct i2c_client *client); | ||
74 | |||
75 | int (*prepare_fw_update)(struct i2c_client *client); | ||
76 | int (*write_fw_block)(struct i2c_client *client, | ||
77 | const u8 *page, u16 checksum, int idx); | ||
78 | int (*finish_fw_update)(struct i2c_client *client, | ||
79 | struct completion *reset_done); | ||
80 | |||
81 | int (*get_report)(struct i2c_client *client, u8 *report); | ||
82 | }; | ||
83 | |||
84 | extern const struct elan_transport_ops elan_smbus_ops, elan_i2c_ops; | ||
85 | |||
86 | #endif /* _ELAN_I2C_H */ | ||
diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c new file mode 100644 index 000000000000..0cb2be48d537 --- /dev/null +++ b/drivers/input/mouse/elan_i2c_core.c | |||
@@ -0,0 +1,1137 @@ | |||
1 | /* | ||
2 | * Elan I2C/SMBus Touchpad driver | ||
3 | * | ||
4 | * Copyright (c) 2013 ELAN Microelectronics Corp. | ||
5 | * | ||
6 | * Author: æž—æ”¿ç¶ (Duson Lin) <dusonlin@emc.com.tw> | ||
7 | * Version: 1.5.5 | ||
8 | * | ||
9 | * Based on cyapa driver: | ||
10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. | ||
11 | * copyright (c) 2011-2012 Google, Inc. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License version 2 as published | ||
15 | * by the Free Software Foundation. | ||
16 | * | ||
17 | * Trademarks are the property of their respective owners. | ||
18 | */ | ||
19 | |||
20 | #include <linux/acpi.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/device.h> | ||
23 | #include <linux/firmware.h> | ||
24 | #include <linux/i2c.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/input/mt.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/module.h> | ||
29 | #include <linux/slab.h> | ||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/sched.h> | ||
32 | #include <linux/input.h> | ||
33 | #include <linux/uaccess.h> | ||
34 | #include <linux/jiffies.h> | ||
35 | #include <linux/completion.h> | ||
36 | #include <linux/of.h> | ||
37 | #include <linux/regulator/consumer.h> | ||
38 | #include <asm/unaligned.h> | ||
39 | |||
40 | #include "elan_i2c.h" | ||
41 | |||
42 | #define DRIVER_NAME "elan_i2c" | ||
43 | #define ELAN_DRIVER_VERSION "1.5.5" | ||
44 | #define ETP_PRESSURE_OFFSET 25 | ||
45 | #define ETP_MAX_PRESSURE 255 | ||
46 | #define ETP_FWIDTH_REDUCE 90 | ||
47 | #define ETP_FINGER_WIDTH 15 | ||
48 | #define ETP_RETRY_COUNT 3 | ||
49 | |||
50 | #define ETP_MAX_FINGERS 5 | ||
51 | #define ETP_FINGER_DATA_LEN 5 | ||
52 | #define ETP_REPORT_ID 0x5D | ||
53 | #define ETP_REPORT_ID_OFFSET 2 | ||
54 | #define ETP_TOUCH_INFO_OFFSET 3 | ||
55 | #define ETP_FINGER_DATA_OFFSET 4 | ||
56 | #define ETP_MAX_REPORT_LEN 34 | ||
57 | |||
58 | /* The main device structure */ | ||
59 | struct elan_tp_data { | ||
60 | struct i2c_client *client; | ||
61 | struct input_dev *input; | ||
62 | struct regulator *vcc; | ||
63 | |||
64 | const struct elan_transport_ops *ops; | ||
65 | |||
66 | /* for fw update */ | ||
67 | struct completion fw_completion; | ||
68 | bool in_fw_update; | ||
69 | |||
70 | struct mutex sysfs_mutex; | ||
71 | |||
72 | unsigned int max_x; | ||
73 | unsigned int max_y; | ||
74 | unsigned int width_x; | ||
75 | unsigned int width_y; | ||
76 | unsigned int x_res; | ||
77 | unsigned int y_res; | ||
78 | |||
79 | u8 product_id; | ||
80 | u8 fw_version; | ||
81 | u8 sm_version; | ||
82 | u8 iap_version; | ||
83 | u16 fw_checksum; | ||
84 | |||
85 | u8 mode; | ||
86 | |||
87 | bool irq_wake; | ||
88 | |||
89 | u8 min_baseline; | ||
90 | u8 max_baseline; | ||
91 | bool baseline_ready; | ||
92 | }; | ||
93 | |||
94 | static int elan_enable_power(struct elan_tp_data *data) | ||
95 | { | ||
96 | int repeat = ETP_RETRY_COUNT; | ||
97 | int error; | ||
98 | |||
99 | error = regulator_enable(data->vcc); | ||
100 | if (error) { | ||
101 | dev_err(&data->client->dev, | ||
102 | "Failed to enable regulator: %d\n", error); | ||
103 | return error; | ||
104 | } | ||
105 | |||
106 | do { | ||
107 | error = data->ops->power_control(data->client, true); | ||
108 | if (error >= 0) | ||
109 | return 0; | ||
110 | |||
111 | msleep(30); | ||
112 | } while (--repeat > 0); | ||
113 | |||
114 | return error; | ||
115 | } | ||
116 | |||
117 | static int elan_disable_power(struct elan_tp_data *data) | ||
118 | { | ||
119 | int repeat = ETP_RETRY_COUNT; | ||
120 | int error; | ||
121 | |||
122 | do { | ||
123 | error = data->ops->power_control(data->client, false); | ||
124 | if (!error) { | ||
125 | error = regulator_disable(data->vcc); | ||
126 | if (error) { | ||
127 | dev_err(&data->client->dev, | ||
128 | "Failed to disable regulator: %d\n", | ||
129 | error); | ||
130 | /* Attempt to power the chip back up */ | ||
131 | data->ops->power_control(data->client, true); | ||
132 | break; | ||
133 | } | ||
134 | |||
135 | return 0; | ||
136 | } | ||
137 | |||
138 | msleep(30); | ||
139 | } while (--repeat > 0); | ||
140 | |||
141 | return error; | ||
142 | } | ||
143 | |||
144 | static int elan_sleep(struct elan_tp_data *data) | ||
145 | { | ||
146 | int repeat = ETP_RETRY_COUNT; | ||
147 | int error; | ||
148 | |||
149 | do { | ||
150 | error = data->ops->sleep_control(data->client, true); | ||
151 | if (!error) | ||
152 | return 0; | ||
153 | |||
154 | msleep(30); | ||
155 | } while (--repeat > 0); | ||
156 | |||
157 | return error; | ||
158 | } | ||
159 | |||
160 | static int __elan_initialize(struct elan_tp_data *data) | ||
161 | { | ||
162 | struct i2c_client *client = data->client; | ||
163 | int error; | ||
164 | |||
165 | error = data->ops->initialize(client); | ||
166 | if (error) { | ||
167 | dev_err(&client->dev, "device initialize failed: %d\n", error); | ||
168 | return error; | ||
169 | } | ||
170 | |||
171 | data->mode |= ETP_ENABLE_ABS; | ||
172 | error = data->ops->set_mode(client, data->mode); | ||
173 | if (error) { | ||
174 | dev_err(&client->dev, | ||
175 | "failed to switch to absolute mode: %d\n", error); | ||
176 | return error; | ||
177 | } | ||
178 | |||
179 | error = data->ops->sleep_control(client, false); | ||
180 | if (error) { | ||
181 | dev_err(&client->dev, | ||
182 | "failed to wake device up: %d\n", error); | ||
183 | return error; | ||
184 | } | ||
185 | |||
186 | return 0; | ||
187 | } | ||
188 | |||
189 | static int elan_initialize(struct elan_tp_data *data) | ||
190 | { | ||
191 | int repeat = ETP_RETRY_COUNT; | ||
192 | int error; | ||
193 | |||
194 | do { | ||
195 | error = __elan_initialize(data); | ||
196 | if (!error) | ||
197 | return 0; | ||
198 | |||
199 | repeat--; | ||
200 | msleep(30); | ||
201 | } while (--repeat > 0); | ||
202 | |||
203 | return error; | ||
204 | } | ||
205 | |||
206 | static int elan_query_device_info(struct elan_tp_data *data) | ||
207 | { | ||
208 | int error; | ||
209 | |||
210 | error = data->ops->get_product_id(data->client, &data->product_id); | ||
211 | if (error) | ||
212 | return error; | ||
213 | |||
214 | error = data->ops->get_version(data->client, false, &data->fw_version); | ||
215 | if (error) | ||
216 | return error; | ||
217 | |||
218 | error = data->ops->get_checksum(data->client, false, | ||
219 | &data->fw_checksum); | ||
220 | if (error) | ||
221 | return error; | ||
222 | |||
223 | error = data->ops->get_sm_version(data->client, &data->sm_version); | ||
224 | if (error) | ||
225 | return error; | ||
226 | |||
227 | error = data->ops->get_version(data->client, true, &data->iap_version); | ||
228 | if (error) | ||
229 | return error; | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static unsigned int elan_convert_resolution(u8 val) | ||
235 | { | ||
236 | /* | ||
237 | * (value from firmware) * 10 + 790 = dpi | ||
238 | * | ||
239 | * We also have to convert dpi to dots/mm (*10/254 to avoid floating | ||
240 | * point). | ||
241 | */ | ||
242 | |||
243 | return ((int)(char)val * 10 + 790) * 10 / 254; | ||
244 | } | ||
245 | |||
246 | static int elan_query_device_parameters(struct elan_tp_data *data) | ||
247 | { | ||
248 | unsigned int x_traces, y_traces; | ||
249 | u8 hw_x_res, hw_y_res; | ||
250 | int error; | ||
251 | |||
252 | error = data->ops->get_max(data->client, &data->max_x, &data->max_y); | ||
253 | if (error) | ||
254 | return error; | ||
255 | |||
256 | error = data->ops->get_num_traces(data->client, &x_traces, &y_traces); | ||
257 | if (error) | ||
258 | return error; | ||
259 | |||
260 | data->width_x = data->max_x / x_traces; | ||
261 | data->width_y = data->max_y / y_traces; | ||
262 | |||
263 | error = data->ops->get_resolution(data->client, &hw_x_res, &hw_y_res); | ||
264 | if (error) | ||
265 | return error; | ||
266 | |||
267 | data->x_res = elan_convert_resolution(hw_x_res); | ||
268 | data->y_res = elan_convert_resolution(hw_y_res); | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | /* | ||
274 | ********************************************************** | ||
275 | * IAP firmware updater related routines | ||
276 | ********************************************************** | ||
277 | */ | ||
278 | static int elan_write_fw_block(struct elan_tp_data *data, | ||
279 | const u8 *page, u16 checksum, int idx) | ||
280 | { | ||
281 | int retry = ETP_RETRY_COUNT; | ||
282 | int error; | ||
283 | |||
284 | do { | ||
285 | error = data->ops->write_fw_block(data->client, | ||
286 | page, checksum, idx); | ||
287 | if (!error) | ||
288 | return 0; | ||
289 | |||
290 | dev_dbg(&data->client->dev, | ||
291 | "IAP retrying page %d (error: %d)\n", idx, error); | ||
292 | } while (--retry > 0); | ||
293 | |||
294 | return error; | ||
295 | } | ||
296 | |||
297 | static int __elan_update_firmware(struct elan_tp_data *data, | ||
298 | const struct firmware *fw) | ||
299 | { | ||
300 | struct i2c_client *client = data->client; | ||
301 | struct device *dev = &client->dev; | ||
302 | int i, j; | ||
303 | int error; | ||
304 | u16 iap_start_addr; | ||
305 | u16 boot_page_count; | ||
306 | u16 sw_checksum = 0, fw_checksum = 0; | ||
307 | |||
308 | error = data->ops->prepare_fw_update(client); | ||
309 | if (error) | ||
310 | return error; | ||
311 | |||
312 | iap_start_addr = get_unaligned_le16(&fw->data[ETP_IAP_START_ADDR * 2]); | ||
313 | |||
314 | boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE; | ||
315 | for (i = boot_page_count; i < ETP_FW_PAGE_COUNT; i++) { | ||
316 | u16 checksum = 0; | ||
317 | const u8 *page = &fw->data[i * ETP_FW_PAGE_SIZE]; | ||
318 | |||
319 | for (j = 0; j < ETP_FW_PAGE_SIZE; j += 2) | ||
320 | checksum += ((page[j + 1] << 8) | page[j]); | ||
321 | |||
322 | error = elan_write_fw_block(data, page, checksum, i); | ||
323 | if (error) { | ||
324 | dev_err(dev, "write page %d fail: %d\n", i, error); | ||
325 | return error; | ||
326 | } | ||
327 | |||
328 | sw_checksum += checksum; | ||
329 | } | ||
330 | |||
331 | /* Wait WDT reset and power on reset */ | ||
332 | msleep(600); | ||
333 | |||
334 | error = data->ops->finish_fw_update(client, &data->fw_completion); | ||
335 | if (error) | ||
336 | return error; | ||
337 | |||
338 | error = data->ops->get_checksum(client, true, &fw_checksum); | ||
339 | if (error) | ||
340 | return error; | ||
341 | |||
342 | if (sw_checksum != fw_checksum) { | ||
343 | dev_err(dev, "checksum diff sw=[%04X], fw=[%04X]\n", | ||
344 | sw_checksum, fw_checksum); | ||
345 | return -EIO; | ||
346 | } | ||
347 | |||
348 | return 0; | ||
349 | } | ||
350 | |||
351 | static int elan_update_firmware(struct elan_tp_data *data, | ||
352 | const struct firmware *fw) | ||
353 | { | ||
354 | struct i2c_client *client = data->client; | ||
355 | int retval; | ||
356 | |||
357 | dev_dbg(&client->dev, "Starting firmware update....\n"); | ||
358 | |||
359 | disable_irq(client->irq); | ||
360 | data->in_fw_update = true; | ||
361 | |||
362 | retval = __elan_update_firmware(data, fw); | ||
363 | if (retval) { | ||
364 | dev_err(&client->dev, "firmware update failed: %d\n", retval); | ||
365 | data->ops->iap_reset(client); | ||
366 | } else { | ||
367 | /* Reinitialize TP after fw is updated */ | ||
368 | elan_initialize(data); | ||
369 | elan_query_device_info(data); | ||
370 | } | ||
371 | |||
372 | data->in_fw_update = false; | ||
373 | enable_irq(client->irq); | ||
374 | |||
375 | return retval; | ||
376 | } | ||
377 | |||
378 | /* | ||
379 | ******************************************************************* | ||
380 | * SYSFS attributes | ||
381 | ******************************************************************* | ||
382 | */ | ||
383 | static ssize_t elan_sysfs_read_fw_checksum(struct device *dev, | ||
384 | struct device_attribute *attr, | ||
385 | char *buf) | ||
386 | { | ||
387 | struct i2c_client *client = to_i2c_client(dev); | ||
388 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
389 | |||
390 | return sprintf(buf, "0x%04x\n", data->fw_checksum); | ||
391 | } | ||
392 | |||
393 | static ssize_t elan_sysfs_read_product_id(struct device *dev, | ||
394 | struct device_attribute *attr, | ||
395 | char *buf) | ||
396 | { | ||
397 | struct i2c_client *client = to_i2c_client(dev); | ||
398 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
399 | |||
400 | return sprintf(buf, "%d.0\n", data->product_id); | ||
401 | } | ||
402 | |||
403 | static ssize_t elan_sysfs_read_fw_ver(struct device *dev, | ||
404 | struct device_attribute *attr, | ||
405 | char *buf) | ||
406 | { | ||
407 | struct i2c_client *client = to_i2c_client(dev); | ||
408 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
409 | |||
410 | return sprintf(buf, "%d.0\n", data->fw_version); | ||
411 | } | ||
412 | |||
413 | static ssize_t elan_sysfs_read_sm_ver(struct device *dev, | ||
414 | struct device_attribute *attr, | ||
415 | char *buf) | ||
416 | { | ||
417 | struct i2c_client *client = to_i2c_client(dev); | ||
418 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
419 | |||
420 | return sprintf(buf, "%d.0\n", data->sm_version); | ||
421 | } | ||
422 | |||
423 | static ssize_t elan_sysfs_read_iap_ver(struct device *dev, | ||
424 | struct device_attribute *attr, | ||
425 | char *buf) | ||
426 | { | ||
427 | struct i2c_client *client = to_i2c_client(dev); | ||
428 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
429 | |||
430 | return sprintf(buf, "%d.0\n", data->iap_version); | ||
431 | } | ||
432 | |||
433 | static ssize_t elan_sysfs_update_fw(struct device *dev, | ||
434 | struct device_attribute *attr, | ||
435 | const char *buf, size_t count) | ||
436 | { | ||
437 | struct i2c_client *client = to_i2c_client(dev); | ||
438 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
439 | const struct firmware *fw; | ||
440 | int error; | ||
441 | |||
442 | error = request_firmware(&fw, ETP_FW_NAME, dev); | ||
443 | if (error) { | ||
444 | dev_err(dev, "cannot load firmware %s: %d\n", | ||
445 | ETP_FW_NAME, error); | ||
446 | return error; | ||
447 | } | ||
448 | |||
449 | /* Firmware must be exactly PAGE_NUM * PAGE_SIZE bytes */ | ||
450 | if (fw->size != ETP_FW_SIZE) { | ||
451 | dev_err(dev, "invalid firmware size = %zu, expected %d.\n", | ||
452 | fw->size, ETP_FW_SIZE); | ||
453 | error = -EBADF; | ||
454 | goto out_release_fw; | ||
455 | } | ||
456 | |||
457 | error = mutex_lock_interruptible(&data->sysfs_mutex); | ||
458 | if (error) | ||
459 | goto out_release_fw; | ||
460 | |||
461 | error = elan_update_firmware(data, fw); | ||
462 | |||
463 | mutex_unlock(&data->sysfs_mutex); | ||
464 | |||
465 | out_release_fw: | ||
466 | release_firmware(fw); | ||
467 | return error ?: count; | ||
468 | } | ||
469 | |||
470 | static ssize_t calibrate_store(struct device *dev, | ||
471 | struct device_attribute *attr, | ||
472 | const char *buf, size_t count) | ||
473 | { | ||
474 | struct i2c_client *client = to_i2c_client(dev); | ||
475 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
476 | int tries = 20; | ||
477 | int retval; | ||
478 | int error; | ||
479 | u8 val[3]; | ||
480 | |||
481 | retval = mutex_lock_interruptible(&data->sysfs_mutex); | ||
482 | if (retval) | ||
483 | return retval; | ||
484 | |||
485 | disable_irq(client->irq); | ||
486 | |||
487 | data->mode |= ETP_ENABLE_CALIBRATE; | ||
488 | retval = data->ops->set_mode(client, data->mode); | ||
489 | if (retval) { | ||
490 | dev_err(dev, "failed to enable calibration mode: %d\n", | ||
491 | retval); | ||
492 | goto out; | ||
493 | } | ||
494 | |||
495 | retval = data->ops->calibrate(client); | ||
496 | if (retval) { | ||
497 | dev_err(dev, "failed to start calibration: %d\n", | ||
498 | retval); | ||
499 | goto out_disable_calibrate; | ||
500 | } | ||
501 | |||
502 | val[0] = 0xff; | ||
503 | do { | ||
504 | /* Wait 250ms before checking if calibration has completed. */ | ||
505 | msleep(250); | ||
506 | |||
507 | retval = data->ops->calibrate_result(client, val); | ||
508 | if (retval) | ||
509 | dev_err(dev, "failed to check calibration result: %d\n", | ||
510 | retval); | ||
511 | else if (val[0] == 0) | ||
512 | break; /* calibration done */ | ||
513 | |||
514 | } while (--tries); | ||
515 | |||
516 | if (tries == 0) { | ||
517 | dev_err(dev, "failed to calibrate. Timeout.\n"); | ||
518 | retval = -ETIMEDOUT; | ||
519 | } | ||
520 | |||
521 | out_disable_calibrate: | ||
522 | data->mode &= ~ETP_ENABLE_CALIBRATE; | ||
523 | error = data->ops->set_mode(data->client, data->mode); | ||
524 | if (error) { | ||
525 | dev_err(dev, "failed to disable calibration mode: %d\n", | ||
526 | error); | ||
527 | if (!retval) | ||
528 | retval = error; | ||
529 | } | ||
530 | out: | ||
531 | enable_irq(client->irq); | ||
532 | mutex_unlock(&data->sysfs_mutex); | ||
533 | return retval ?: count; | ||
534 | } | ||
535 | |||
536 | static ssize_t elan_sysfs_read_mode(struct device *dev, | ||
537 | struct device_attribute *attr, | ||
538 | char *buf) | ||
539 | { | ||
540 | struct i2c_client *client = to_i2c_client(dev); | ||
541 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
542 | int error; | ||
543 | enum tp_mode mode; | ||
544 | |||
545 | error = mutex_lock_interruptible(&data->sysfs_mutex); | ||
546 | if (error) | ||
547 | return error; | ||
548 | |||
549 | error = data->ops->iap_get_mode(data->client, &mode); | ||
550 | |||
551 | mutex_unlock(&data->sysfs_mutex); | ||
552 | |||
553 | if (error) | ||
554 | return error; | ||
555 | |||
556 | return sprintf(buf, "%d\n", (int)mode); | ||
557 | } | ||
558 | |||
559 | static DEVICE_ATTR(product_id, S_IRUGO, elan_sysfs_read_product_id, NULL); | ||
560 | static DEVICE_ATTR(firmware_version, S_IRUGO, elan_sysfs_read_fw_ver, NULL); | ||
561 | static DEVICE_ATTR(sample_version, S_IRUGO, elan_sysfs_read_sm_ver, NULL); | ||
562 | static DEVICE_ATTR(iap_version, S_IRUGO, elan_sysfs_read_iap_ver, NULL); | ||
563 | static DEVICE_ATTR(fw_checksum, S_IRUGO, elan_sysfs_read_fw_checksum, NULL); | ||
564 | static DEVICE_ATTR(mode, S_IRUGO, elan_sysfs_read_mode, NULL); | ||
565 | static DEVICE_ATTR(update_fw, S_IWUSR, NULL, elan_sysfs_update_fw); | ||
566 | |||
567 | static DEVICE_ATTR_WO(calibrate); | ||
568 | |||
569 | static struct attribute *elan_sysfs_entries[] = { | ||
570 | &dev_attr_product_id.attr, | ||
571 | &dev_attr_firmware_version.attr, | ||
572 | &dev_attr_sample_version.attr, | ||
573 | &dev_attr_iap_version.attr, | ||
574 | &dev_attr_fw_checksum.attr, | ||
575 | &dev_attr_calibrate.attr, | ||
576 | &dev_attr_mode.attr, | ||
577 | &dev_attr_update_fw.attr, | ||
578 | NULL, | ||
579 | }; | ||
580 | |||
581 | static const struct attribute_group elan_sysfs_group = { | ||
582 | .attrs = elan_sysfs_entries, | ||
583 | }; | ||
584 | |||
585 | static ssize_t acquire_store(struct device *dev, struct device_attribute *attr, | ||
586 | const char *buf, size_t count) | ||
587 | { | ||
588 | struct i2c_client *client = to_i2c_client(dev); | ||
589 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
590 | int error; | ||
591 | int retval; | ||
592 | |||
593 | retval = mutex_lock_interruptible(&data->sysfs_mutex); | ||
594 | if (retval) | ||
595 | return retval; | ||
596 | |||
597 | disable_irq(client->irq); | ||
598 | |||
599 | data->baseline_ready = false; | ||
600 | |||
601 | data->mode |= ETP_ENABLE_CALIBRATE; | ||
602 | retval = data->ops->set_mode(data->client, data->mode); | ||
603 | if (retval) { | ||
604 | dev_err(dev, "Failed to enable calibration mode to get baseline: %d\n", | ||
605 | retval); | ||
606 | goto out; | ||
607 | } | ||
608 | |||
609 | msleep(250); | ||
610 | |||
611 | retval = data->ops->get_baseline_data(data->client, true, | ||
612 | &data->max_baseline); | ||
613 | if (retval) { | ||
614 | dev_err(dev, "Failed to read max baseline form device: %d\n", | ||
615 | retval); | ||
616 | goto out_disable_calibrate; | ||
617 | } | ||
618 | |||
619 | retval = data->ops->get_baseline_data(data->client, false, | ||
620 | &data->min_baseline); | ||
621 | if (retval) { | ||
622 | dev_err(dev, "Failed to read min baseline form device: %d\n", | ||
623 | retval); | ||
624 | goto out_disable_calibrate; | ||
625 | } | ||
626 | |||
627 | data->baseline_ready = true; | ||
628 | |||
629 | out_disable_calibrate: | ||
630 | data->mode &= ~ETP_ENABLE_CALIBRATE; | ||
631 | error = data->ops->set_mode(data->client, data->mode); | ||
632 | if (error) { | ||
633 | dev_err(dev, "Failed to disable calibration mode after acquiring baseline: %d\n", | ||
634 | error); | ||
635 | if (!retval) | ||
636 | retval = error; | ||
637 | } | ||
638 | out: | ||
639 | enable_irq(client->irq); | ||
640 | mutex_unlock(&data->sysfs_mutex); | ||
641 | return retval ?: count; | ||
642 | } | ||
643 | |||
644 | static ssize_t min_show(struct device *dev, | ||
645 | struct device_attribute *attr, char *buf) | ||
646 | { | ||
647 | struct i2c_client *client = to_i2c_client(dev); | ||
648 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
649 | int retval; | ||
650 | |||
651 | retval = mutex_lock_interruptible(&data->sysfs_mutex); | ||
652 | if (retval) | ||
653 | return retval; | ||
654 | |||
655 | if (!data->baseline_ready) { | ||
656 | retval = -ENODATA; | ||
657 | goto out; | ||
658 | } | ||
659 | |||
660 | retval = snprintf(buf, PAGE_SIZE, "%d", data->min_baseline); | ||
661 | |||
662 | out: | ||
663 | mutex_unlock(&data->sysfs_mutex); | ||
664 | return retval; | ||
665 | } | ||
666 | |||
667 | static ssize_t max_show(struct device *dev, | ||
668 | struct device_attribute *attr, char *buf) | ||
669 | { | ||
670 | struct i2c_client *client = to_i2c_client(dev); | ||
671 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
672 | int retval; | ||
673 | |||
674 | retval = mutex_lock_interruptible(&data->sysfs_mutex); | ||
675 | if (retval) | ||
676 | return retval; | ||
677 | |||
678 | if (!data->baseline_ready) { | ||
679 | retval = -ENODATA; | ||
680 | goto out; | ||
681 | } | ||
682 | |||
683 | retval = snprintf(buf, PAGE_SIZE, "%d", data->max_baseline); | ||
684 | |||
685 | out: | ||
686 | mutex_unlock(&data->sysfs_mutex); | ||
687 | return retval; | ||
688 | } | ||
689 | |||
690 | |||
691 | static DEVICE_ATTR_WO(acquire); | ||
692 | static DEVICE_ATTR_RO(min); | ||
693 | static DEVICE_ATTR_RO(max); | ||
694 | |||
695 | static struct attribute *elan_baseline_sysfs_entries[] = { | ||
696 | &dev_attr_acquire.attr, | ||
697 | &dev_attr_min.attr, | ||
698 | &dev_attr_max.attr, | ||
699 | NULL, | ||
700 | }; | ||
701 | |||
702 | static const struct attribute_group elan_baseline_sysfs_group = { | ||
703 | .name = "baseline", | ||
704 | .attrs = elan_baseline_sysfs_entries, | ||
705 | }; | ||
706 | |||
707 | static const struct attribute_group *elan_sysfs_groups[] = { | ||
708 | &elan_sysfs_group, | ||
709 | &elan_baseline_sysfs_group, | ||
710 | NULL | ||
711 | }; | ||
712 | |||
713 | /* | ||
714 | ****************************************************************** | ||
715 | * Elan isr functions | ||
716 | ****************************************************************** | ||
717 | */ | ||
718 | static void elan_report_contact(struct elan_tp_data *data, | ||
719 | int contact_num, bool contact_valid, | ||
720 | u8 *finger_data) | ||
721 | { | ||
722 | struct input_dev *input = data->input; | ||
723 | unsigned int pos_x, pos_y; | ||
724 | unsigned int pressure, mk_x, mk_y; | ||
725 | unsigned int area_x, area_y, major, minor, new_pressure; | ||
726 | |||
727 | |||
728 | if (contact_valid) { | ||
729 | pos_x = ((finger_data[0] & 0xf0) << 4) | | ||
730 | finger_data[1]; | ||
731 | pos_y = ((finger_data[0] & 0x0f) << 8) | | ||
732 | finger_data[2]; | ||
733 | mk_x = (finger_data[3] & 0x0f); | ||
734 | mk_y = (finger_data[3] >> 4); | ||
735 | pressure = finger_data[4]; | ||
736 | |||
737 | if (pos_x > data->max_x || pos_y > data->max_y) { | ||
738 | dev_dbg(input->dev.parent, | ||
739 | "[%d] x=%d y=%d over max (%d, %d)", | ||
740 | contact_num, pos_x, pos_y, | ||
741 | data->max_x, data->max_y); | ||
742 | return; | ||
743 | } | ||
744 | |||
745 | /* | ||
746 | * To avoid treating large finger as palm, let's reduce the | ||
747 | * width x and y per trace. | ||
748 | */ | ||
749 | area_x = mk_x * (data->width_x - ETP_FWIDTH_REDUCE); | ||
750 | area_y = mk_y * (data->width_y - ETP_FWIDTH_REDUCE); | ||
751 | |||
752 | major = max(area_x, area_y); | ||
753 | minor = min(area_x, area_y); | ||
754 | |||
755 | new_pressure = pressure + ETP_PRESSURE_OFFSET; | ||
756 | if (new_pressure > ETP_MAX_PRESSURE) | ||
757 | new_pressure = ETP_MAX_PRESSURE; | ||
758 | |||
759 | input_mt_slot(input, contact_num); | ||
760 | input_mt_report_slot_state(input, MT_TOOL_FINGER, true); | ||
761 | input_report_abs(input, ABS_MT_POSITION_X, pos_x); | ||
762 | input_report_abs(input, ABS_MT_POSITION_Y, data->max_y - pos_y); | ||
763 | input_report_abs(input, ABS_MT_PRESSURE, new_pressure); | ||
764 | input_report_abs(input, ABS_TOOL_WIDTH, mk_x); | ||
765 | input_report_abs(input, ABS_MT_TOUCH_MAJOR, major); | ||
766 | input_report_abs(input, ABS_MT_TOUCH_MINOR, minor); | ||
767 | } else { | ||
768 | input_mt_slot(input, contact_num); | ||
769 | input_mt_report_slot_state(input, MT_TOOL_FINGER, false); | ||
770 | } | ||
771 | } | ||
772 | |||
773 | static void elan_report_absolute(struct elan_tp_data *data, u8 *packet) | ||
774 | { | ||
775 | struct input_dev *input = data->input; | ||
776 | u8 *finger_data = &packet[ETP_FINGER_DATA_OFFSET]; | ||
777 | int i; | ||
778 | u8 tp_info = packet[ETP_TOUCH_INFO_OFFSET]; | ||
779 | bool contact_valid; | ||
780 | |||
781 | for (i = 0; i < ETP_MAX_FINGERS; i++) { | ||
782 | contact_valid = tp_info & (1U << (3 + i)); | ||
783 | elan_report_contact(data, i, contact_valid, finger_data); | ||
784 | |||
785 | if (contact_valid) | ||
786 | finger_data += ETP_FINGER_DATA_LEN; | ||
787 | } | ||
788 | |||
789 | input_report_key(input, BTN_LEFT, tp_info & 0x01); | ||
790 | input_mt_report_pointer_emulation(input, true); | ||
791 | input_sync(input); | ||
792 | } | ||
793 | |||
794 | static irqreturn_t elan_isr(int irq, void *dev_id) | ||
795 | { | ||
796 | struct elan_tp_data *data = dev_id; | ||
797 | struct device *dev = &data->client->dev; | ||
798 | int error; | ||
799 | u8 report[ETP_MAX_REPORT_LEN]; | ||
800 | |||
801 | /* | ||
802 | * When device is connected to i2c bus, when all IAP page writes | ||
803 | * complete, the driver will receive interrupt and must read | ||
804 | * 0000 to confirm that IAP is finished. | ||
805 | */ | ||
806 | if (data->in_fw_update) { | ||
807 | complete(&data->fw_completion); | ||
808 | goto out; | ||
809 | } | ||
810 | |||
811 | error = data->ops->get_report(data->client, report); | ||
812 | if (error) | ||
813 | goto out; | ||
814 | |||
815 | if (report[ETP_REPORT_ID_OFFSET] != ETP_REPORT_ID) | ||
816 | dev_err(dev, "invalid report id data (%x)\n", | ||
817 | report[ETP_REPORT_ID_OFFSET]); | ||
818 | else | ||
819 | elan_report_absolute(data, report); | ||
820 | |||
821 | out: | ||
822 | return IRQ_HANDLED; | ||
823 | } | ||
824 | |||
825 | /* | ||
826 | ****************************************************************** | ||
827 | * Elan initialization functions | ||
828 | ****************************************************************** | ||
829 | */ | ||
830 | static int elan_setup_input_device(struct elan_tp_data *data) | ||
831 | { | ||
832 | struct device *dev = &data->client->dev; | ||
833 | struct input_dev *input; | ||
834 | unsigned int max_width = max(data->width_x, data->width_y); | ||
835 | unsigned int min_width = min(data->width_x, data->width_y); | ||
836 | int error; | ||
837 | |||
838 | input = devm_input_allocate_device(dev); | ||
839 | if (!input) | ||
840 | return -ENOMEM; | ||
841 | |||
842 | input->name = "Elan Touchpad"; | ||
843 | input->id.bustype = BUS_I2C; | ||
844 | input_set_drvdata(input, data); | ||
845 | |||
846 | error = input_mt_init_slots(input, ETP_MAX_FINGERS, | ||
847 | INPUT_MT_POINTER | INPUT_MT_DROP_UNUSED); | ||
848 | if (error) { | ||
849 | dev_err(dev, "failed to initialize MT slots: %d\n", error); | ||
850 | return error; | ||
851 | } | ||
852 | |||
853 | __set_bit(EV_ABS, input->evbit); | ||
854 | __set_bit(INPUT_PROP_POINTER, input->propbit); | ||
855 | __set_bit(INPUT_PROP_BUTTONPAD, input->propbit); | ||
856 | __set_bit(BTN_LEFT, input->keybit); | ||
857 | |||
858 | /* Set up ST parameters */ | ||
859 | input_set_abs_params(input, ABS_X, 0, data->max_x, 0, 0); | ||
860 | input_set_abs_params(input, ABS_Y, 0, data->max_y, 0, 0); | ||
861 | input_abs_set_res(input, ABS_X, data->x_res); | ||
862 | input_abs_set_res(input, ABS_Y, data->y_res); | ||
863 | input_set_abs_params(input, ABS_PRESSURE, 0, ETP_MAX_PRESSURE, 0, 0); | ||
864 | input_set_abs_params(input, ABS_TOOL_WIDTH, 0, ETP_FINGER_WIDTH, 0, 0); | ||
865 | |||
866 | /* And MT parameters */ | ||
867 | input_set_abs_params(input, ABS_MT_POSITION_X, 0, data->max_x, 0, 0); | ||
868 | input_set_abs_params(input, ABS_MT_POSITION_Y, 0, data->max_y, 0, 0); | ||
869 | input_abs_set_res(input, ABS_MT_POSITION_X, data->x_res); | ||
870 | input_abs_set_res(input, ABS_MT_POSITION_Y, data->y_res); | ||
871 | input_set_abs_params(input, ABS_MT_PRESSURE, 0, | ||
872 | ETP_MAX_PRESSURE, 0, 0); | ||
873 | input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, | ||
874 | ETP_FINGER_WIDTH * max_width, 0, 0); | ||
875 | input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, | ||
876 | ETP_FINGER_WIDTH * min_width, 0, 0); | ||
877 | |||
878 | data->input = input; | ||
879 | |||
880 | return 0; | ||
881 | } | ||
882 | |||
883 | static void elan_disable_regulator(void *_data) | ||
884 | { | ||
885 | struct elan_tp_data *data = _data; | ||
886 | |||
887 | regulator_disable(data->vcc); | ||
888 | } | ||
889 | |||
890 | static void elan_remove_sysfs_groups(void *_data) | ||
891 | { | ||
892 | struct elan_tp_data *data = _data; | ||
893 | |||
894 | sysfs_remove_groups(&data->client->dev.kobj, elan_sysfs_groups); | ||
895 | } | ||
896 | |||
897 | static int elan_probe(struct i2c_client *client, | ||
898 | const struct i2c_device_id *dev_id) | ||
899 | { | ||
900 | const struct elan_transport_ops *transport_ops; | ||
901 | struct device *dev = &client->dev; | ||
902 | struct elan_tp_data *data; | ||
903 | unsigned long irqflags; | ||
904 | int error; | ||
905 | |||
906 | if (IS_ENABLED(CONFIG_MOUSE_ELAN_I2C_I2C) && | ||
907 | i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | ||
908 | transport_ops = &elan_i2c_ops; | ||
909 | } else if (IS_ENABLED(CONFIG_MOUSE_ELAN_I2C_SMBUS) && | ||
910 | i2c_check_functionality(client->adapter, | ||
911 | I2C_FUNC_SMBUS_BYTE_DATA | | ||
912 | I2C_FUNC_SMBUS_BLOCK_DATA | | ||
913 | I2C_FUNC_SMBUS_I2C_BLOCK)) { | ||
914 | transport_ops = &elan_smbus_ops; | ||
915 | } else { | ||
916 | dev_err(dev, "not a supported I2C/SMBus adapter\n"); | ||
917 | return -EIO; | ||
918 | } | ||
919 | |||
920 | data = devm_kzalloc(&client->dev, sizeof(struct elan_tp_data), | ||
921 | GFP_KERNEL); | ||
922 | if (!data) | ||
923 | return -ENOMEM; | ||
924 | |||
925 | i2c_set_clientdata(client, data); | ||
926 | |||
927 | data->ops = transport_ops; | ||
928 | data->client = client; | ||
929 | init_completion(&data->fw_completion); | ||
930 | mutex_init(&data->sysfs_mutex); | ||
931 | |||
932 | data->vcc = devm_regulator_get(&client->dev, "vcc"); | ||
933 | if (IS_ERR(data->vcc)) { | ||
934 | error = PTR_ERR(data->vcc); | ||
935 | if (error != -EPROBE_DEFER) | ||
936 | dev_err(&client->dev, | ||
937 | "Failed to get 'vcc' regulator: %d\n", | ||
938 | error); | ||
939 | return error; | ||
940 | } | ||
941 | |||
942 | error = regulator_enable(data->vcc); | ||
943 | if (error) { | ||
944 | dev_err(&client->dev, | ||
945 | "Failed to enable regulator: %d\n", error); | ||
946 | return error; | ||
947 | } | ||
948 | |||
949 | error = devm_add_action(&client->dev, | ||
950 | elan_disable_regulator, data); | ||
951 | if (error) { | ||
952 | regulator_disable(data->vcc); | ||
953 | dev_err(&client->dev, | ||
954 | "Failed to add disable regulator action: %d\n", | ||
955 | error); | ||
956 | return error; | ||
957 | } | ||
958 | |||
959 | /* Initialize the touchpad. */ | ||
960 | error = elan_initialize(data); | ||
961 | if (error) | ||
962 | return error; | ||
963 | |||
964 | error = elan_query_device_info(data); | ||
965 | if (error) | ||
966 | return error; | ||
967 | |||
968 | error = elan_query_device_parameters(data); | ||
969 | if (error) | ||
970 | return error; | ||
971 | |||
972 | dev_dbg(&client->dev, | ||
973 | "Elan Touchpad Information:\n" | ||
974 | " Module product ID: 0x%04x\n" | ||
975 | " Firmware Version: 0x%04x\n" | ||
976 | " Sample Version: 0x%04x\n" | ||
977 | " IAP Version: 0x%04x\n" | ||
978 | " Max ABS X,Y: %d,%d\n" | ||
979 | " Width X,Y: %d,%d\n" | ||
980 | " Resolution X,Y: %d,%d (dots/mm)\n", | ||
981 | data->product_id, | ||
982 | data->fw_version, | ||
983 | data->sm_version, | ||
984 | data->iap_version, | ||
985 | data->max_x, data->max_y, | ||
986 | data->width_x, data->width_y, | ||
987 | data->x_res, data->y_res); | ||
988 | |||
989 | /* Set up input device properties based on queried parameters. */ | ||
990 | error = elan_setup_input_device(data); | ||
991 | if (error) | ||
992 | return error; | ||
993 | |||
994 | /* | ||
995 | * Systems using device tree should set up interrupt via DTS, | ||
996 | * the rest will use the default falling edge interrupts. | ||
997 | */ | ||
998 | irqflags = client->dev.of_node ? 0 : IRQF_TRIGGER_FALLING; | ||
999 | |||
1000 | error = devm_request_threaded_irq(&client->dev, client->irq, | ||
1001 | NULL, elan_isr, | ||
1002 | irqflags | IRQF_ONESHOT, | ||
1003 | client->name, data); | ||
1004 | if (error) { | ||
1005 | dev_err(&client->dev, "cannot register irq=%d\n", client->irq); | ||
1006 | return error; | ||
1007 | } | ||
1008 | |||
1009 | error = sysfs_create_groups(&client->dev.kobj, elan_sysfs_groups); | ||
1010 | if (error) { | ||
1011 | dev_err(&client->dev, "failed to create sysfs attributes: %d\n", | ||
1012 | error); | ||
1013 | return error; | ||
1014 | } | ||
1015 | |||
1016 | error = devm_add_action(&client->dev, | ||
1017 | elan_remove_sysfs_groups, data); | ||
1018 | if (error) { | ||
1019 | elan_remove_sysfs_groups(data); | ||
1020 | dev_err(&client->dev, | ||
1021 | "Failed to add sysfs cleanup action: %d\n", | ||
1022 | error); | ||
1023 | return error; | ||
1024 | } | ||
1025 | |||
1026 | error = input_register_device(data->input); | ||
1027 | if (error) { | ||
1028 | dev_err(&client->dev, "failed to register input device: %d\n", | ||
1029 | error); | ||
1030 | return error; | ||
1031 | } | ||
1032 | |||
1033 | /* | ||
1034 | * Systems using device tree should set up wakeup via DTS, | ||
1035 | * the rest will configure device as wakeup source by default. | ||
1036 | */ | ||
1037 | if (!client->dev.of_node) | ||
1038 | device_init_wakeup(&client->dev, true); | ||
1039 | |||
1040 | return 0; | ||
1041 | } | ||
1042 | |||
1043 | static int __maybe_unused elan_suspend(struct device *dev) | ||
1044 | { | ||
1045 | struct i2c_client *client = to_i2c_client(dev); | ||
1046 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
1047 | int ret; | ||
1048 | |||
1049 | /* | ||
1050 | * We are taking the mutex to make sure sysfs operations are | ||
1051 | * complete before we attempt to bring the device into low[er] | ||
1052 | * power mode. | ||
1053 | */ | ||
1054 | ret = mutex_lock_interruptible(&data->sysfs_mutex); | ||
1055 | if (ret) | ||
1056 | return ret; | ||
1057 | |||
1058 | disable_irq(client->irq); | ||
1059 | |||
1060 | if (device_may_wakeup(dev)) { | ||
1061 | ret = elan_sleep(data); | ||
1062 | /* Enable wake from IRQ */ | ||
1063 | data->irq_wake = (enable_irq_wake(client->irq) == 0); | ||
1064 | } else { | ||
1065 | ret = elan_disable_power(data); | ||
1066 | } | ||
1067 | |||
1068 | mutex_unlock(&data->sysfs_mutex); | ||
1069 | return ret; | ||
1070 | } | ||
1071 | |||
1072 | static int __maybe_unused elan_resume(struct device *dev) | ||
1073 | { | ||
1074 | struct i2c_client *client = to_i2c_client(dev); | ||
1075 | struct elan_tp_data *data = i2c_get_clientdata(client); | ||
1076 | int error; | ||
1077 | |||
1078 | if (device_may_wakeup(dev) && data->irq_wake) { | ||
1079 | disable_irq_wake(client->irq); | ||
1080 | data->irq_wake = false; | ||
1081 | } | ||
1082 | |||
1083 | error = elan_enable_power(data); | ||
1084 | if (error) | ||
1085 | dev_err(dev, "power up when resuming failed: %d\n", error); | ||
1086 | |||
1087 | error = elan_initialize(data); | ||
1088 | if (error) | ||
1089 | dev_err(dev, "initialize when resuming failed: %d\n", error); | ||
1090 | |||
1091 | enable_irq(data->client->irq); | ||
1092 | |||
1093 | return 0; | ||
1094 | } | ||
1095 | |||
1096 | static SIMPLE_DEV_PM_OPS(elan_pm_ops, elan_suspend, elan_resume); | ||
1097 | |||
1098 | static const struct i2c_device_id elan_id[] = { | ||
1099 | { DRIVER_NAME, 0 }, | ||
1100 | { }, | ||
1101 | }; | ||
1102 | MODULE_DEVICE_TABLE(i2c, elan_id); | ||
1103 | |||
1104 | #ifdef CONFIG_ACPI | ||
1105 | static const struct acpi_device_id elan_acpi_id[] = { | ||
1106 | { "ELAN0000", 0 }, | ||
1107 | { } | ||
1108 | }; | ||
1109 | MODULE_DEVICE_TABLE(acpi, elan_acpi_id); | ||
1110 | #endif | ||
1111 | |||
1112 | #ifdef CONFIG_OF | ||
1113 | static const struct of_device_id elan_of_match[] = { | ||
1114 | { .compatible = "elan,ekth3000" }, | ||
1115 | { /* sentinel */ } | ||
1116 | }; | ||
1117 | MODULE_DEVICE_TABLE(of, elan_of_match); | ||
1118 | #endif | ||
1119 | |||
1120 | static struct i2c_driver elan_driver = { | ||
1121 | .driver = { | ||
1122 | .name = DRIVER_NAME, | ||
1123 | .owner = THIS_MODULE, | ||
1124 | .pm = &elan_pm_ops, | ||
1125 | .acpi_match_table = ACPI_PTR(elan_acpi_id), | ||
1126 | .of_match_table = of_match_ptr(elan_of_match), | ||
1127 | }, | ||
1128 | .probe = elan_probe, | ||
1129 | .id_table = elan_id, | ||
1130 | }; | ||
1131 | |||
1132 | module_i2c_driver(elan_driver); | ||
1133 | |||
1134 | MODULE_AUTHOR("Duson Lin <dusonlin@emc.com.tw>"); | ||
1135 | MODULE_DESCRIPTION("Elan I2C/SMBus Touchpad driver"); | ||
1136 | MODULE_LICENSE("GPL"); | ||
1137 | MODULE_VERSION(ELAN_DRIVER_VERSION); | ||
diff --git a/drivers/input/mouse/elan_i2c_i2c.c b/drivers/input/mouse/elan_i2c_i2c.c new file mode 100644 index 000000000000..97d4937fc244 --- /dev/null +++ b/drivers/input/mouse/elan_i2c_i2c.c | |||
@@ -0,0 +1,611 @@ | |||
1 | /* | ||
2 | * Elan I2C/SMBus Touchpad driver - I2C interface | ||
3 | * | ||
4 | * Copyright (c) 2013 ELAN Microelectronics Corp. | ||
5 | * | ||
6 | * Author: æž—æ”¿ç¶ (Duson Lin) <dusonlin@emc.com.tw> | ||
7 | * Version: 1.5.5 | ||
8 | * | ||
9 | * Based on cyapa driver: | ||
10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. | ||
11 | * copyright (c) 2011-2012 Google, Inc. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License version 2 as published | ||
15 | * by the Free Software Foundation. | ||
16 | * | ||
17 | * Trademarks are the property of their respective owners. | ||
18 | */ | ||
19 | |||
20 | #include <linux/completion.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/i2c.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/jiffies.h> | ||
25 | #include <linux/kernel.h> | ||
26 | #include <linux/sched.h> | ||
27 | #include <asm/unaligned.h> | ||
28 | |||
29 | #include "elan_i2c.h" | ||
30 | |||
31 | /* Elan i2c commands */ | ||
32 | #define ETP_I2C_RESET 0x0100 | ||
33 | #define ETP_I2C_WAKE_UP 0x0800 | ||
34 | #define ETP_I2C_SLEEP 0x0801 | ||
35 | #define ETP_I2C_DESC_CMD 0x0001 | ||
36 | #define ETP_I2C_REPORT_DESC_CMD 0x0002 | ||
37 | #define ETP_I2C_STAND_CMD 0x0005 | ||
38 | #define ETP_I2C_UNIQUEID_CMD 0x0101 | ||
39 | #define ETP_I2C_FW_VERSION_CMD 0x0102 | ||
40 | #define ETP_I2C_SM_VERSION_CMD 0x0103 | ||
41 | #define ETP_I2C_XY_TRACENUM_CMD 0x0105 | ||
42 | #define ETP_I2C_MAX_X_AXIS_CMD 0x0106 | ||
43 | #define ETP_I2C_MAX_Y_AXIS_CMD 0x0107 | ||
44 | #define ETP_I2C_RESOLUTION_CMD 0x0108 | ||
45 | #define ETP_I2C_IAP_VERSION_CMD 0x0110 | ||
46 | #define ETP_I2C_SET_CMD 0x0300 | ||
47 | #define ETP_I2C_POWER_CMD 0x0307 | ||
48 | #define ETP_I2C_FW_CHECKSUM_CMD 0x030F | ||
49 | #define ETP_I2C_IAP_CTRL_CMD 0x0310 | ||
50 | #define ETP_I2C_IAP_CMD 0x0311 | ||
51 | #define ETP_I2C_IAP_RESET_CMD 0x0314 | ||
52 | #define ETP_I2C_IAP_CHECKSUM_CMD 0x0315 | ||
53 | #define ETP_I2C_CALIBRATE_CMD 0x0316 | ||
54 | #define ETP_I2C_MAX_BASELINE_CMD 0x0317 | ||
55 | #define ETP_I2C_MIN_BASELINE_CMD 0x0318 | ||
56 | |||
57 | #define ETP_I2C_REPORT_LEN 34 | ||
58 | #define ETP_I2C_DESC_LENGTH 30 | ||
59 | #define ETP_I2C_REPORT_DESC_LENGTH 158 | ||
60 | #define ETP_I2C_INF_LENGTH 2 | ||
61 | #define ETP_I2C_IAP_PASSWORD 0x1EA5 | ||
62 | #define ETP_I2C_IAP_RESET 0xF0F0 | ||
63 | #define ETP_I2C_MAIN_MODE_ON (1 << 9) | ||
64 | #define ETP_I2C_IAP_REG_L 0x01 | ||
65 | #define ETP_I2C_IAP_REG_H 0x06 | ||
66 | |||
67 | static int elan_i2c_read_block(struct i2c_client *client, | ||
68 | u16 reg, u8 *val, u16 len) | ||
69 | { | ||
70 | __le16 buf[] = { | ||
71 | cpu_to_le16(reg), | ||
72 | }; | ||
73 | struct i2c_msg msgs[] = { | ||
74 | { | ||
75 | .addr = client->addr, | ||
76 | .flags = client->flags & I2C_M_TEN, | ||
77 | .len = sizeof(buf), | ||
78 | .buf = (u8 *)buf, | ||
79 | }, | ||
80 | { | ||
81 | .addr = client->addr, | ||
82 | .flags = (client->flags & I2C_M_TEN) | I2C_M_RD, | ||
83 | .len = len, | ||
84 | .buf = val, | ||
85 | } | ||
86 | }; | ||
87 | int ret; | ||
88 | |||
89 | ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); | ||
90 | return ret == ARRAY_SIZE(msgs) ? 0 : (ret < 0 ? ret : -EIO); | ||
91 | } | ||
92 | |||
93 | static int elan_i2c_read_cmd(struct i2c_client *client, u16 reg, u8 *val) | ||
94 | { | ||
95 | int retval; | ||
96 | |||
97 | retval = elan_i2c_read_block(client, reg, val, ETP_I2C_INF_LENGTH); | ||
98 | if (retval < 0) { | ||
99 | dev_err(&client->dev, "reading cmd (0x%04x) fail.\n", reg); | ||
100 | return retval; | ||
101 | } | ||
102 | |||
103 | return 0; | ||
104 | } | ||
105 | |||
106 | static int elan_i2c_write_cmd(struct i2c_client *client, u16 reg, u16 cmd) | ||
107 | { | ||
108 | __le16 buf[] = { | ||
109 | cpu_to_le16(reg), | ||
110 | cpu_to_le16(cmd), | ||
111 | }; | ||
112 | struct i2c_msg msg = { | ||
113 | .addr = client->addr, | ||
114 | .flags = client->flags & I2C_M_TEN, | ||
115 | .len = sizeof(buf), | ||
116 | .buf = (u8 *)buf, | ||
117 | }; | ||
118 | int ret; | ||
119 | |||
120 | ret = i2c_transfer(client->adapter, &msg, 1); | ||
121 | return ret == 1 ? 0 : (ret < 0 ? ret : -EIO); | ||
122 | } | ||
123 | |||
124 | static int elan_i2c_initialize(struct i2c_client *client) | ||
125 | { | ||
126 | struct device *dev = &client->dev; | ||
127 | int error; | ||
128 | u8 val[256]; | ||
129 | |||
130 | error = elan_i2c_write_cmd(client, ETP_I2C_STAND_CMD, ETP_I2C_RESET); | ||
131 | if (error) { | ||
132 | dev_err(dev, "device reset failed: %d\n", error); | ||
133 | return error; | ||
134 | } | ||
135 | |||
136 | /* Wait for the device to reset */ | ||
137 | msleep(100); | ||
138 | |||
139 | /* get reset acknowledgement 0000 */ | ||
140 | error = i2c_master_recv(client, val, ETP_I2C_INF_LENGTH); | ||
141 | if (error < 0) { | ||
142 | dev_err(dev, "failed to read reset response: %d\n", error); | ||
143 | return error; | ||
144 | } | ||
145 | |||
146 | error = elan_i2c_read_block(client, ETP_I2C_DESC_CMD, | ||
147 | val, ETP_I2C_DESC_LENGTH); | ||
148 | if (error) { | ||
149 | dev_err(dev, "cannot get device descriptor: %d\n", error); | ||
150 | return error; | ||
151 | } | ||
152 | |||
153 | error = elan_i2c_read_block(client, ETP_I2C_REPORT_DESC_CMD, | ||
154 | val, ETP_I2C_REPORT_DESC_LENGTH); | ||
155 | if (error) { | ||
156 | dev_err(dev, "fetching report descriptor failed.: %d\n", error); | ||
157 | return error; | ||
158 | } | ||
159 | |||
160 | return 0; | ||
161 | } | ||
162 | |||
163 | static int elan_i2c_sleep_control(struct i2c_client *client, bool sleep) | ||
164 | { | ||
165 | return elan_i2c_write_cmd(client, ETP_I2C_STAND_CMD, | ||
166 | sleep ? ETP_I2C_SLEEP : ETP_I2C_WAKE_UP); | ||
167 | } | ||
168 | |||
169 | static int elan_i2c_power_control(struct i2c_client *client, bool enable) | ||
170 | { | ||
171 | u8 val[2]; | ||
172 | u16 reg; | ||
173 | int error; | ||
174 | |||
175 | error = elan_i2c_read_cmd(client, ETP_I2C_POWER_CMD, val); | ||
176 | if (error) { | ||
177 | dev_err(&client->dev, | ||
178 | "failed to read current power state: %d\n", | ||
179 | error); | ||
180 | return error; | ||
181 | } | ||
182 | |||
183 | reg = le16_to_cpup((__le16 *)val); | ||
184 | if (enable) | ||
185 | reg &= ~ETP_DISABLE_POWER; | ||
186 | else | ||
187 | reg |= ETP_DISABLE_POWER; | ||
188 | |||
189 | error = elan_i2c_write_cmd(client, ETP_I2C_POWER_CMD, reg); | ||
190 | if (error) { | ||
191 | dev_err(&client->dev, | ||
192 | "failed to write current power state: %d\n", | ||
193 | error); | ||
194 | return error; | ||
195 | } | ||
196 | |||
197 | return 0; | ||
198 | } | ||
199 | |||
200 | static int elan_i2c_set_mode(struct i2c_client *client, u8 mode) | ||
201 | { | ||
202 | return elan_i2c_write_cmd(client, ETP_I2C_SET_CMD, mode); | ||
203 | } | ||
204 | |||
205 | |||
206 | static int elan_i2c_calibrate(struct i2c_client *client) | ||
207 | { | ||
208 | return elan_i2c_write_cmd(client, ETP_I2C_CALIBRATE_CMD, 1); | ||
209 | } | ||
210 | |||
211 | static int elan_i2c_calibrate_result(struct i2c_client *client, u8 *val) | ||
212 | { | ||
213 | return elan_i2c_read_block(client, ETP_I2C_CALIBRATE_CMD, val, 1); | ||
214 | } | ||
215 | |||
216 | static int elan_i2c_get_baseline_data(struct i2c_client *client, | ||
217 | bool max_baseline, u8 *value) | ||
218 | { | ||
219 | int error; | ||
220 | u8 val[3]; | ||
221 | |||
222 | error = elan_i2c_read_cmd(client, | ||
223 | max_baseline ? ETP_I2C_MAX_BASELINE_CMD : | ||
224 | ETP_I2C_MIN_BASELINE_CMD, | ||
225 | val); | ||
226 | if (error) | ||
227 | return error; | ||
228 | |||
229 | *value = le16_to_cpup((__le16 *)val); | ||
230 | |||
231 | return 0; | ||
232 | } | ||
233 | |||
234 | static int elan_i2c_get_version(struct i2c_client *client, | ||
235 | bool iap, u8 *version) | ||
236 | { | ||
237 | int error; | ||
238 | u8 val[3]; | ||
239 | |||
240 | error = elan_i2c_read_cmd(client, | ||
241 | iap ? ETP_I2C_IAP_VERSION_CMD : | ||
242 | ETP_I2C_FW_VERSION_CMD, | ||
243 | val); | ||
244 | if (error) { | ||
245 | dev_err(&client->dev, "failed to get %s version: %d\n", | ||
246 | iap ? "IAP" : "FW", error); | ||
247 | return error; | ||
248 | } | ||
249 | |||
250 | *version = val[0]; | ||
251 | return 0; | ||
252 | } | ||
253 | |||
254 | static int elan_i2c_get_sm_version(struct i2c_client *client, u8 *version) | ||
255 | { | ||
256 | int error; | ||
257 | u8 val[3]; | ||
258 | |||
259 | error = elan_i2c_read_cmd(client, ETP_I2C_SM_VERSION_CMD, val); | ||
260 | if (error) { | ||
261 | dev_err(&client->dev, "failed to get SM version: %d\n", error); | ||
262 | return error; | ||
263 | } | ||
264 | |||
265 | *version = val[0]; | ||
266 | return 0; | ||
267 | } | ||
268 | |||
269 | static int elan_i2c_get_product_id(struct i2c_client *client, u8 *id) | ||
270 | { | ||
271 | int error; | ||
272 | u8 val[3]; | ||
273 | |||
274 | error = elan_i2c_read_cmd(client, ETP_I2C_UNIQUEID_CMD, val); | ||
275 | if (error) { | ||
276 | dev_err(&client->dev, "failed to get product ID: %d\n", error); | ||
277 | return error; | ||
278 | } | ||
279 | |||
280 | *id = val[0]; | ||
281 | return 0; | ||
282 | } | ||
283 | |||
284 | static int elan_i2c_get_checksum(struct i2c_client *client, | ||
285 | bool iap, u16 *csum) | ||
286 | { | ||
287 | int error; | ||
288 | u8 val[3]; | ||
289 | |||
290 | error = elan_i2c_read_cmd(client, | ||
291 | iap ? ETP_I2C_IAP_CHECKSUM_CMD : | ||
292 | ETP_I2C_FW_CHECKSUM_CMD, | ||
293 | val); | ||
294 | if (error) { | ||
295 | dev_err(&client->dev, "failed to get %s checksum: %d\n", | ||
296 | iap ? "IAP" : "FW", error); | ||
297 | return error; | ||
298 | } | ||
299 | |||
300 | *csum = le16_to_cpup((__le16 *)val); | ||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | static int elan_i2c_get_max(struct i2c_client *client, | ||
305 | unsigned int *max_x, unsigned int *max_y) | ||
306 | { | ||
307 | int error; | ||
308 | u8 val[3]; | ||
309 | |||
310 | error = elan_i2c_read_cmd(client, ETP_I2C_MAX_X_AXIS_CMD, val); | ||
311 | if (error) { | ||
312 | dev_err(&client->dev, "failed to get X dimension: %d\n", error); | ||
313 | return error; | ||
314 | } | ||
315 | |||
316 | *max_x = le16_to_cpup((__le16 *)val) & 0x0fff; | ||
317 | |||
318 | error = elan_i2c_read_cmd(client, ETP_I2C_MAX_Y_AXIS_CMD, val); | ||
319 | if (error) { | ||
320 | dev_err(&client->dev, "failed to get Y dimension: %d\n", error); | ||
321 | return error; | ||
322 | } | ||
323 | |||
324 | *max_y = le16_to_cpup((__le16 *)val) & 0x0fff; | ||
325 | |||
326 | return 0; | ||
327 | } | ||
328 | |||
329 | static int elan_i2c_get_resolution(struct i2c_client *client, | ||
330 | u8 *hw_res_x, u8 *hw_res_y) | ||
331 | { | ||
332 | int error; | ||
333 | u8 val[3]; | ||
334 | |||
335 | error = elan_i2c_read_cmd(client, ETP_I2C_RESOLUTION_CMD, val); | ||
336 | if (error) { | ||
337 | dev_err(&client->dev, "failed to get resolution: %d\n", error); | ||
338 | return error; | ||
339 | } | ||
340 | |||
341 | *hw_res_x = val[0]; | ||
342 | *hw_res_y = val[1]; | ||
343 | |||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | static int elan_i2c_get_num_traces(struct i2c_client *client, | ||
348 | unsigned int *x_traces, | ||
349 | unsigned int *y_traces) | ||
350 | { | ||
351 | int error; | ||
352 | u8 val[3]; | ||
353 | |||
354 | error = elan_i2c_read_cmd(client, ETP_I2C_XY_TRACENUM_CMD, val); | ||
355 | if (error) { | ||
356 | dev_err(&client->dev, "failed to get trace info: %d\n", error); | ||
357 | return error; | ||
358 | } | ||
359 | |||
360 | *x_traces = val[0] - 1; | ||
361 | *y_traces = val[1] - 1; | ||
362 | |||
363 | return 0; | ||
364 | } | ||
365 | |||
366 | static int elan_i2c_iap_get_mode(struct i2c_client *client, enum tp_mode *mode) | ||
367 | { | ||
368 | int error; | ||
369 | u16 constant; | ||
370 | u8 val[3]; | ||
371 | |||
372 | error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CTRL_CMD, val); | ||
373 | if (error) { | ||
374 | dev_err(&client->dev, | ||
375 | "failed to read iap control register: %d\n", | ||
376 | error); | ||
377 | return error; | ||
378 | } | ||
379 | |||
380 | constant = le16_to_cpup((__le16 *)val); | ||
381 | dev_dbg(&client->dev, "iap control reg: 0x%04x.\n", constant); | ||
382 | |||
383 | *mode = (constant & ETP_I2C_MAIN_MODE_ON) ? MAIN_MODE : IAP_MODE; | ||
384 | |||
385 | return 0; | ||
386 | } | ||
387 | |||
388 | static int elan_i2c_iap_reset(struct i2c_client *client) | ||
389 | { | ||
390 | int error; | ||
391 | |||
392 | error = elan_i2c_write_cmd(client, ETP_I2C_IAP_RESET_CMD, | ||
393 | ETP_I2C_IAP_RESET); | ||
394 | if (error) { | ||
395 | dev_err(&client->dev, "cannot reset IC: %d\n", error); | ||
396 | return error; | ||
397 | } | ||
398 | |||
399 | return 0; | ||
400 | } | ||
401 | |||
402 | static int elan_i2c_set_flash_key(struct i2c_client *client) | ||
403 | { | ||
404 | int error; | ||
405 | |||
406 | error = elan_i2c_write_cmd(client, ETP_I2C_IAP_CMD, | ||
407 | ETP_I2C_IAP_PASSWORD); | ||
408 | if (error) { | ||
409 | dev_err(&client->dev, "cannot set flash key: %d\n", error); | ||
410 | return error; | ||
411 | } | ||
412 | |||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | static int elan_i2c_prepare_fw_update(struct i2c_client *client) | ||
417 | { | ||
418 | struct device *dev = &client->dev; | ||
419 | int error; | ||
420 | enum tp_mode mode; | ||
421 | u8 val[3]; | ||
422 | u16 password; | ||
423 | |||
424 | /* Get FW in which mode (IAP_MODE/MAIN_MODE) */ | ||
425 | error = elan_i2c_iap_get_mode(client, &mode); | ||
426 | if (error) | ||
427 | return error; | ||
428 | |||
429 | if (mode == IAP_MODE) { | ||
430 | /* Reset IC */ | ||
431 | error = elan_i2c_iap_reset(client); | ||
432 | if (error) | ||
433 | return error; | ||
434 | |||
435 | msleep(30); | ||
436 | } | ||
437 | |||
438 | /* Set flash key*/ | ||
439 | error = elan_i2c_set_flash_key(client); | ||
440 | if (error) | ||
441 | return error; | ||
442 | |||
443 | /* Wait for F/W IAP initialization */ | ||
444 | msleep(mode == MAIN_MODE ? 100 : 30); | ||
445 | |||
446 | /* Check if we are in IAP mode or not */ | ||
447 | error = elan_i2c_iap_get_mode(client, &mode); | ||
448 | if (error) | ||
449 | return error; | ||
450 | |||
451 | if (mode == MAIN_MODE) { | ||
452 | dev_err(dev, "wrong mode: %d\n", mode); | ||
453 | return -EIO; | ||
454 | } | ||
455 | |||
456 | /* Set flash key again */ | ||
457 | error = elan_i2c_set_flash_key(client); | ||
458 | if (error) | ||
459 | return error; | ||
460 | |||
461 | /* Wait for F/W IAP initialization */ | ||
462 | msleep(30); | ||
463 | |||
464 | /* read back to check we actually enabled successfully. */ | ||
465 | error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CMD, val); | ||
466 | if (error) { | ||
467 | dev_err(dev, "cannot read iap password: %d\n", | ||
468 | error); | ||
469 | return error; | ||
470 | } | ||
471 | |||
472 | password = le16_to_cpup((__le16 *)val); | ||
473 | if (password != ETP_I2C_IAP_PASSWORD) { | ||
474 | dev_err(dev, "wrong iap password: 0x%X\n", password); | ||
475 | return -EIO; | ||
476 | } | ||
477 | |||
478 | return 0; | ||
479 | } | ||
480 | |||
481 | static int elan_i2c_write_fw_block(struct i2c_client *client, | ||
482 | const u8 *page, u16 checksum, int idx) | ||
483 | { | ||
484 | struct device *dev = &client->dev; | ||
485 | u8 page_store[ETP_FW_PAGE_SIZE + 4]; | ||
486 | u8 val[3]; | ||
487 | u16 result; | ||
488 | int ret, error; | ||
489 | |||
490 | page_store[0] = ETP_I2C_IAP_REG_L; | ||
491 | page_store[1] = ETP_I2C_IAP_REG_H; | ||
492 | memcpy(&page_store[2], page, ETP_FW_PAGE_SIZE); | ||
493 | /* recode checksum at last two bytes */ | ||
494 | put_unaligned_le16(checksum, &page_store[ETP_FW_PAGE_SIZE + 2]); | ||
495 | |||
496 | ret = i2c_master_send(client, page_store, sizeof(page_store)); | ||
497 | if (ret != sizeof(page_store)) { | ||
498 | error = ret < 0 ? ret : -EIO; | ||
499 | dev_err(dev, "Failed to write page %d: %d\n", idx, error); | ||
500 | return error; | ||
501 | } | ||
502 | |||
503 | /* Wait for F/W to update one page ROM data. */ | ||
504 | msleep(20); | ||
505 | |||
506 | error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CTRL_CMD, val); | ||
507 | if (error) { | ||
508 | dev_err(dev, "Failed to read IAP write result: %d\n", error); | ||
509 | return error; | ||
510 | } | ||
511 | |||
512 | result = le16_to_cpup((__le16 *)val); | ||
513 | if (result & (ETP_FW_IAP_PAGE_ERR | ETP_FW_IAP_INTF_ERR)) { | ||
514 | dev_err(dev, "IAP reports failed write: %04hx\n", | ||
515 | result); | ||
516 | return -EIO; | ||
517 | } | ||
518 | |||
519 | return 0; | ||
520 | } | ||
521 | |||
522 | static int elan_i2c_finish_fw_update(struct i2c_client *client, | ||
523 | struct completion *completion) | ||
524 | { | ||
525 | struct device *dev = &client->dev; | ||
526 | long ret; | ||
527 | int error; | ||
528 | int len; | ||
529 | u8 buffer[ETP_I2C_INF_LENGTH]; | ||
530 | |||
531 | reinit_completion(completion); | ||
532 | enable_irq(client->irq); | ||
533 | |||
534 | error = elan_i2c_write_cmd(client, ETP_I2C_STAND_CMD, ETP_I2C_RESET); | ||
535 | if (!error) | ||
536 | ret = wait_for_completion_interruptible_timeout(completion, | ||
537 | msecs_to_jiffies(300)); | ||
538 | disable_irq(client->irq); | ||
539 | |||
540 | if (error) { | ||
541 | dev_err(dev, "device reset failed: %d\n", error); | ||
542 | return error; | ||
543 | } else if (ret == 0) { | ||
544 | dev_err(dev, "timeout waiting for device reset\n"); | ||
545 | return -ETIMEDOUT; | ||
546 | } else if (ret < 0) { | ||
547 | error = ret; | ||
548 | dev_err(dev, "error waiting for device reset: %d\n", error); | ||
549 | return error; | ||
550 | } | ||
551 | |||
552 | len = i2c_master_recv(client, buffer, ETP_I2C_INF_LENGTH); | ||
553 | if (len != ETP_I2C_INF_LENGTH) { | ||
554 | error = len < 0 ? len : -EIO; | ||
555 | dev_err(dev, "failed to read INT signal: %d (%d)\n", | ||
556 | error, len); | ||
557 | return error; | ||
558 | } | ||
559 | |||
560 | return 0; | ||
561 | } | ||
562 | |||
563 | static int elan_i2c_get_report(struct i2c_client *client, u8 *report) | ||
564 | { | ||
565 | int len; | ||
566 | |||
567 | len = i2c_master_recv(client, report, ETP_I2C_REPORT_LEN); | ||
568 | if (len < 0) { | ||
569 | dev_err(&client->dev, "failed to read report data: %d\n", len); | ||
570 | return len; | ||
571 | } | ||
572 | |||
573 | if (len != ETP_I2C_REPORT_LEN) { | ||
574 | dev_err(&client->dev, | ||
575 | "wrong report length (%d vs %d expected)\n", | ||
576 | len, ETP_I2C_REPORT_LEN); | ||
577 | return -EIO; | ||
578 | } | ||
579 | |||
580 | return 0; | ||
581 | } | ||
582 | |||
583 | const struct elan_transport_ops elan_i2c_ops = { | ||
584 | .initialize = elan_i2c_initialize, | ||
585 | .sleep_control = elan_i2c_sleep_control, | ||
586 | .power_control = elan_i2c_power_control, | ||
587 | .set_mode = elan_i2c_set_mode, | ||
588 | |||
589 | .calibrate = elan_i2c_calibrate, | ||
590 | .calibrate_result = elan_i2c_calibrate_result, | ||
591 | |||
592 | .get_baseline_data = elan_i2c_get_baseline_data, | ||
593 | |||
594 | .get_version = elan_i2c_get_version, | ||
595 | .get_sm_version = elan_i2c_get_sm_version, | ||
596 | .get_product_id = elan_i2c_get_product_id, | ||
597 | .get_checksum = elan_i2c_get_checksum, | ||
598 | |||
599 | .get_max = elan_i2c_get_max, | ||
600 | .get_resolution = elan_i2c_get_resolution, | ||
601 | .get_num_traces = elan_i2c_get_num_traces, | ||
602 | |||
603 | .iap_get_mode = elan_i2c_iap_get_mode, | ||
604 | .iap_reset = elan_i2c_iap_reset, | ||
605 | |||
606 | .prepare_fw_update = elan_i2c_prepare_fw_update, | ||
607 | .write_fw_block = elan_i2c_write_fw_block, | ||
608 | .finish_fw_update = elan_i2c_finish_fw_update, | ||
609 | |||
610 | .get_report = elan_i2c_get_report, | ||
611 | }; | ||
diff --git a/drivers/input/mouse/elan_i2c_smbus.c b/drivers/input/mouse/elan_i2c_smbus.c new file mode 100644 index 000000000000..359bf8583d54 --- /dev/null +++ b/drivers/input/mouse/elan_i2c_smbus.c | |||
@@ -0,0 +1,514 @@ | |||
1 | /* | ||
2 | * Elan I2C/SMBus Touchpad driver - SMBus interface | ||
3 | * | ||
4 | * Copyright (c) 2013 ELAN Microelectronics Corp. | ||
5 | * | ||
6 | * Author: æž—æ”¿ç¶ (Duson Lin) <dusonlin@emc.com.tw> | ||
7 | * Version: 1.5.5 | ||
8 | * | ||
9 | * Based on cyapa driver: | ||
10 | * copyright (c) 2011-2012 Cypress Semiconductor, Inc. | ||
11 | * copyright (c) 2011-2012 Google, Inc. | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or modify it | ||
14 | * under the terms of the GNU General Public License version 2 as published | ||
15 | * by the Free Software Foundation. | ||
16 | * | ||
17 | * Trademarks are the property of their respective owners. | ||
18 | */ | ||
19 | |||
20 | #include <linux/delay.h> | ||
21 | #include <linux/i2c.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/kernel.h> | ||
24 | |||
25 | #include "elan_i2c.h" | ||
26 | |||
27 | /* Elan SMbus commands */ | ||
28 | #define ETP_SMBUS_IAP_CMD 0x00 | ||
29 | #define ETP_SMBUS_ENABLE_TP 0x20 | ||
30 | #define ETP_SMBUS_SLEEP_CMD 0x21 | ||
31 | #define ETP_SMBUS_IAP_PASSWORD_WRITE 0x29 | ||
32 | #define ETP_SMBUS_IAP_PASSWORD_READ 0x80 | ||
33 | #define ETP_SMBUS_WRITE_FW_BLOCK 0x2A | ||
34 | #define ETP_SMBUS_IAP_RESET_CMD 0x2B | ||
35 | #define ETP_SMBUS_RANGE_CMD 0xA0 | ||
36 | #define ETP_SMBUS_FW_VERSION_CMD 0xA1 | ||
37 | #define ETP_SMBUS_XY_TRACENUM_CMD 0xA2 | ||
38 | #define ETP_SMBUS_SM_VERSION_CMD 0xA3 | ||
39 | #define ETP_SMBUS_UNIQUEID_CMD 0xA3 | ||
40 | #define ETP_SMBUS_RESOLUTION_CMD 0xA4 | ||
41 | #define ETP_SMBUS_HELLOPACKET_CMD 0xA7 | ||
42 | #define ETP_SMBUS_PACKET_QUERY 0xA8 | ||
43 | #define ETP_SMBUS_IAP_VERSION_CMD 0xAC | ||
44 | #define ETP_SMBUS_IAP_CTRL_CMD 0xAD | ||
45 | #define ETP_SMBUS_IAP_CHECKSUM_CMD 0xAE | ||
46 | #define ETP_SMBUS_FW_CHECKSUM_CMD 0xAF | ||
47 | #define ETP_SMBUS_MAX_BASELINE_CMD 0xC3 | ||
48 | #define ETP_SMBUS_MIN_BASELINE_CMD 0xC4 | ||
49 | #define ETP_SMBUS_CALIBRATE_QUERY 0xC5 | ||
50 | |||
51 | #define ETP_SMBUS_REPORT_LEN 32 | ||
52 | #define ETP_SMBUS_REPORT_OFFSET 2 | ||
53 | #define ETP_SMBUS_HELLOPACKET_LEN 5 | ||
54 | #define ETP_SMBUS_IAP_PASSWORD 0x1234 | ||
55 | #define ETP_SMBUS_IAP_MODE_ON (1 << 6) | ||
56 | |||
57 | static int elan_smbus_initialize(struct i2c_client *client) | ||
58 | { | ||
59 | u8 check[ETP_SMBUS_HELLOPACKET_LEN] = { 0x55, 0x55, 0x55, 0x55, 0x55 }; | ||
60 | u8 values[ETP_SMBUS_HELLOPACKET_LEN] = { 0, 0, 0, 0, 0 }; | ||
61 | int len, error; | ||
62 | |||
63 | /* Get hello packet */ | ||
64 | len = i2c_smbus_read_block_data(client, | ||
65 | ETP_SMBUS_HELLOPACKET_CMD, values); | ||
66 | if (len != ETP_SMBUS_HELLOPACKET_LEN) { | ||
67 | dev_err(&client->dev, "hello packet length fail: %d\n", len); | ||
68 | error = len < 0 ? len : -EIO; | ||
69 | return error; | ||
70 | } | ||
71 | |||
72 | /* compare hello packet */ | ||
73 | if (memcmp(values, check, ETP_SMBUS_HELLOPACKET_LEN)) { | ||
74 | dev_err(&client->dev, "hello packet fail [%*px]\n", | ||
75 | ETP_SMBUS_HELLOPACKET_LEN, values); | ||
76 | return -ENXIO; | ||
77 | } | ||
78 | |||
79 | /* enable tp */ | ||
80 | error = i2c_smbus_write_byte(client, ETP_SMBUS_ENABLE_TP); | ||
81 | if (error) { | ||
82 | dev_err(&client->dev, "failed to enable touchpad: %d\n", error); | ||
83 | return error; | ||
84 | } | ||
85 | |||
86 | return 0; | ||
87 | } | ||
88 | |||
89 | static int elan_smbus_set_mode(struct i2c_client *client, u8 mode) | ||
90 | { | ||
91 | u8 cmd[4] = { 0x00, 0x07, 0x00, mode }; | ||
92 | |||
93 | return i2c_smbus_write_block_data(client, ETP_SMBUS_IAP_CMD, | ||
94 | sizeof(cmd), cmd); | ||
95 | } | ||
96 | |||
97 | static int elan_smbus_sleep_control(struct i2c_client *client, bool sleep) | ||
98 | { | ||
99 | if (sleep) | ||
100 | return i2c_smbus_write_byte(client, ETP_SMBUS_SLEEP_CMD); | ||
101 | else | ||
102 | return 0; /* XXX should we send ETP_SMBUS_ENABLE_TP here? */ | ||
103 | } | ||
104 | |||
105 | static int elan_smbus_power_control(struct i2c_client *client, bool enable) | ||
106 | { | ||
107 | return 0; /* A no-op */ | ||
108 | } | ||
109 | |||
110 | static int elan_smbus_calibrate(struct i2c_client *client) | ||
111 | { | ||
112 | u8 cmd[4] = { 0x00, 0x08, 0x00, 0x01 }; | ||
113 | |||
114 | return i2c_smbus_write_block_data(client, ETP_SMBUS_IAP_CMD, | ||
115 | sizeof(cmd), cmd); | ||
116 | } | ||
117 | |||
118 | static int elan_smbus_calibrate_result(struct i2c_client *client, u8 *val) | ||
119 | { | ||
120 | int error; | ||
121 | |||
122 | error = i2c_smbus_read_block_data(client, | ||
123 | ETP_SMBUS_CALIBRATE_QUERY, val); | ||
124 | if (error < 0) | ||
125 | return error; | ||
126 | |||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | static int elan_smbus_get_baseline_data(struct i2c_client *client, | ||
131 | bool max_baseline, u8 *value) | ||
132 | { | ||
133 | int error; | ||
134 | u8 val[3]; | ||
135 | |||
136 | error = i2c_smbus_read_block_data(client, | ||
137 | max_baseline ? | ||
138 | ETP_SMBUS_MAX_BASELINE_CMD : | ||
139 | ETP_SMBUS_MIN_BASELINE_CMD, | ||
140 | val); | ||
141 | if (error < 0) | ||
142 | return error; | ||
143 | |||
144 | *value = be16_to_cpup((__be16 *)val); | ||
145 | |||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | static int elan_smbus_get_version(struct i2c_client *client, | ||
150 | bool iap, u8 *version) | ||
151 | { | ||
152 | int error; | ||
153 | u8 val[3]; | ||
154 | |||
155 | error = i2c_smbus_read_block_data(client, | ||
156 | iap ? ETP_SMBUS_IAP_VERSION_CMD : | ||
157 | ETP_SMBUS_FW_VERSION_CMD, | ||
158 | val); | ||
159 | if (error < 0) { | ||
160 | dev_err(&client->dev, "failed to get %s version: %d\n", | ||
161 | iap ? "IAP" : "FW", error); | ||
162 | return error; | ||
163 | } | ||
164 | |||
165 | *version = val[2]; | ||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static int elan_smbus_get_sm_version(struct i2c_client *client, u8 *version) | ||
170 | { | ||
171 | int error; | ||
172 | u8 val[3]; | ||
173 | |||
174 | error = i2c_smbus_read_block_data(client, | ||
175 | ETP_SMBUS_SM_VERSION_CMD, val); | ||
176 | if (error < 0) { | ||
177 | dev_err(&client->dev, "failed to get SM version: %d\n", error); | ||
178 | return error; | ||
179 | } | ||
180 | |||
181 | *version = val[0]; /* XXX Why 0 and not 2 as in IAP/FW versions? */ | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | static int elan_smbus_get_product_id(struct i2c_client *client, u8 *id) | ||
186 | { | ||
187 | int error; | ||
188 | u8 val[3]; | ||
189 | |||
190 | error = i2c_smbus_read_block_data(client, | ||
191 | ETP_SMBUS_UNIQUEID_CMD, val); | ||
192 | if (error < 0) { | ||
193 | dev_err(&client->dev, "failed to get product ID: %d\n", error); | ||
194 | return error; | ||
195 | } | ||
196 | |||
197 | *id = val[1]; | ||
198 | return 0; | ||
199 | } | ||
200 | |||
201 | static int elan_smbus_get_checksum(struct i2c_client *client, | ||
202 | bool iap, u16 *csum) | ||
203 | { | ||
204 | int error; | ||
205 | u8 val[3]; | ||
206 | |||
207 | error = i2c_smbus_read_block_data(client, | ||
208 | iap ? ETP_SMBUS_FW_CHECKSUM_CMD : | ||
209 | ETP_SMBUS_IAP_CHECKSUM_CMD, | ||
210 | val); | ||
211 | if (error < 0) { | ||
212 | dev_err(&client->dev, "failed to get %s checksum: %d\n", | ||
213 | iap ? "IAP" : "FW", error); | ||
214 | return error; | ||
215 | } | ||
216 | |||
217 | *csum = be16_to_cpup((__be16 *)val); | ||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static int elan_smbus_get_max(struct i2c_client *client, | ||
222 | unsigned int *max_x, unsigned int *max_y) | ||
223 | { | ||
224 | int error; | ||
225 | u8 val[3]; | ||
226 | |||
227 | error = i2c_smbus_read_block_data(client, ETP_SMBUS_RANGE_CMD, val); | ||
228 | if (error) { | ||
229 | dev_err(&client->dev, "failed to get dimensions: %d\n", error); | ||
230 | return error; | ||
231 | } | ||
232 | |||
233 | *max_x = (0x0f & val[0]) << 8 | val[1]; | ||
234 | *max_y = (0xf0 & val[0]) << 4 | val[2]; | ||
235 | |||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | static int elan_smbus_get_resolution(struct i2c_client *client, | ||
240 | u8 *hw_res_x, u8 *hw_res_y) | ||
241 | { | ||
242 | int error; | ||
243 | u8 val[3]; | ||
244 | |||
245 | error = i2c_smbus_read_block_data(client, | ||
246 | ETP_SMBUS_RESOLUTION_CMD, val); | ||
247 | if (error) { | ||
248 | dev_err(&client->dev, "failed to get resolution: %d\n", error); | ||
249 | return error; | ||
250 | } | ||
251 | |||
252 | *hw_res_x = val[1] & 0x0F; | ||
253 | *hw_res_y = (val[1] & 0xF0) >> 4; | ||
254 | |||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | static int elan_smbus_get_num_traces(struct i2c_client *client, | ||
259 | unsigned int *x_traces, | ||
260 | unsigned int *y_traces) | ||
261 | { | ||
262 | int error; | ||
263 | u8 val[3]; | ||
264 | |||
265 | error = i2c_smbus_read_block_data(client, | ||
266 | ETP_SMBUS_XY_TRACENUM_CMD, val); | ||
267 | if (error) { | ||
268 | dev_err(&client->dev, "failed to get trace info: %d\n", error); | ||
269 | return error; | ||
270 | } | ||
271 | |||
272 | *x_traces = val[1] - 1; | ||
273 | *y_traces = val[2] - 1; | ||
274 | |||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static int elan_smbus_iap_get_mode(struct i2c_client *client, | ||
279 | enum tp_mode *mode) | ||
280 | { | ||
281 | int error; | ||
282 | u16 constant; | ||
283 | u8 val[3]; | ||
284 | |||
285 | error = i2c_smbus_read_block_data(client, ETP_SMBUS_IAP_CTRL_CMD, val); | ||
286 | if (error < 0) { | ||
287 | dev_err(&client->dev, "failed to read iap ctrol register: %d\n", | ||
288 | error); | ||
289 | return error; | ||
290 | } | ||
291 | |||
292 | constant = be16_to_cpup((__be16 *)val); | ||
293 | dev_dbg(&client->dev, "iap control reg: 0x%04x.\n", constant); | ||
294 | |||
295 | *mode = (constant & ETP_SMBUS_IAP_MODE_ON) ? IAP_MODE : MAIN_MODE; | ||
296 | |||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | static int elan_smbus_iap_reset(struct i2c_client *client) | ||
301 | { | ||
302 | int error; | ||
303 | |||
304 | error = i2c_smbus_write_byte(client, ETP_SMBUS_IAP_RESET_CMD); | ||
305 | if (error) { | ||
306 | dev_err(&client->dev, "cannot reset IC: %d\n", error); | ||
307 | return error; | ||
308 | } | ||
309 | |||
310 | return 0; | ||
311 | } | ||
312 | |||
313 | static int elan_smbus_set_flash_key(struct i2c_client *client) | ||
314 | { | ||
315 | int error; | ||
316 | u8 cmd[4] = { 0x00, 0x0B, 0x00, 0x5A }; | ||
317 | |||
318 | error = i2c_smbus_write_block_data(client, ETP_SMBUS_IAP_CMD, | ||
319 | sizeof(cmd), cmd); | ||
320 | if (error) { | ||
321 | dev_err(&client->dev, "cannot set flash key: %d\n", error); | ||
322 | return error; | ||
323 | } | ||
324 | |||
325 | return 0; | ||
326 | } | ||
327 | |||
328 | static int elan_smbus_prepare_fw_update(struct i2c_client *client) | ||
329 | { | ||
330 | struct device *dev = &client->dev; | ||
331 | int len; | ||
332 | int error; | ||
333 | enum tp_mode mode; | ||
334 | u8 val[3]; | ||
335 | u8 cmd[4] = {0x0F, 0x78, 0x00, 0x06}; | ||
336 | u16 password; | ||
337 | |||
338 | /* Get FW in which mode (IAP_MODE/MAIN_MODE) */ | ||
339 | error = elan_smbus_iap_get_mode(client, &mode); | ||
340 | if (error) | ||
341 | return error; | ||
342 | |||
343 | if (mode == MAIN_MODE) { | ||
344 | |||
345 | /* set flash key */ | ||
346 | error = elan_smbus_set_flash_key(client); | ||
347 | if (error) | ||
348 | return error; | ||
349 | |||
350 | /* write iap password */ | ||
351 | if (i2c_smbus_write_byte(client, | ||
352 | ETP_SMBUS_IAP_PASSWORD_WRITE) < 0) { | ||
353 | dev_err(dev, "cannot write iap password\n"); | ||
354 | return -EIO; | ||
355 | } | ||
356 | |||
357 | error = i2c_smbus_write_block_data(client, ETP_SMBUS_IAP_CMD, | ||
358 | sizeof(cmd), cmd); | ||
359 | if (error) { | ||
360 | dev_err(dev, "failed to write iap password: %d\n", | ||
361 | error); | ||
362 | return error; | ||
363 | } | ||
364 | |||
365 | /* | ||
366 | * Read back password to make sure we enabled flash | ||
367 | * successfully. | ||
368 | */ | ||
369 | len = i2c_smbus_read_block_data(client, | ||
370 | ETP_SMBUS_IAP_PASSWORD_READ, | ||
371 | val); | ||
372 | if (len < sizeof(u16)) { | ||
373 | error = len < 0 ? len : -EIO; | ||
374 | dev_err(dev, "failed to read iap password: %d\n", | ||
375 | error); | ||
376 | return error; | ||
377 | } | ||
378 | |||
379 | password = be16_to_cpup((__be16 *)val); | ||
380 | if (password != ETP_SMBUS_IAP_PASSWORD) { | ||
381 | dev_err(dev, "wrong iap password = 0x%X\n", password); | ||
382 | return -EIO; | ||
383 | } | ||
384 | |||
385 | /* Wait 30ms for MAIN_MODE change to IAP_MODE */ | ||
386 | msleep(30); | ||
387 | } | ||
388 | |||
389 | error = elan_smbus_set_flash_key(client); | ||
390 | if (error) | ||
391 | return error; | ||
392 | |||
393 | /* Reset IC */ | ||
394 | error = elan_smbus_iap_reset(client); | ||
395 | if (error) | ||
396 | return error; | ||
397 | |||
398 | return 0; | ||
399 | } | ||
400 | |||
401 | |||
402 | static int elan_smbus_write_fw_block(struct i2c_client *client, | ||
403 | const u8 *page, u16 checksum, int idx) | ||
404 | { | ||
405 | struct device *dev = &client->dev; | ||
406 | int error; | ||
407 | u16 result; | ||
408 | u8 val[3]; | ||
409 | |||
410 | /* | ||
411 | * Due to the limitation of smbus protocol limiting | ||
412 | * transfer to 32 bytes at a time, we must split block | ||
413 | * in 2 transfers. | ||
414 | */ | ||
415 | error = i2c_smbus_write_block_data(client, | ||
416 | ETP_SMBUS_WRITE_FW_BLOCK, | ||
417 | ETP_FW_PAGE_SIZE / 2, | ||
418 | page); | ||
419 | if (error) { | ||
420 | dev_err(dev, "Failed to write page %d (part %d): %d\n", | ||
421 | idx, 1, error); | ||
422 | return error; | ||
423 | } | ||
424 | |||
425 | error = i2c_smbus_write_block_data(client, | ||
426 | ETP_SMBUS_WRITE_FW_BLOCK, | ||
427 | ETP_FW_PAGE_SIZE / 2, | ||
428 | page + ETP_FW_PAGE_SIZE / 2); | ||
429 | if (error) { | ||
430 | dev_err(dev, "Failed to write page %d (part %d): %d\n", | ||
431 | idx, 2, error); | ||
432 | return error; | ||
433 | } | ||
434 | |||
435 | |||
436 | /* Wait for F/W to update one page ROM data. */ | ||
437 | usleep_range(8000, 10000); | ||
438 | |||
439 | error = i2c_smbus_read_block_data(client, | ||
440 | ETP_SMBUS_IAP_CTRL_CMD, val); | ||
441 | if (error < 0) { | ||
442 | dev_err(dev, "Failed to read IAP write result: %d\n", | ||
443 | error); | ||
444 | return error; | ||
445 | } | ||
446 | |||
447 | result = be16_to_cpup((__be16 *)val); | ||
448 | if (result & (ETP_FW_IAP_PAGE_ERR | ETP_FW_IAP_INTF_ERR)) { | ||
449 | dev_err(dev, "IAP reports failed write: %04hx\n", | ||
450 | result); | ||
451 | return -EIO; | ||
452 | } | ||
453 | |||
454 | return 0; | ||
455 | } | ||
456 | |||
457 | static int elan_smbus_get_report(struct i2c_client *client, u8 *report) | ||
458 | { | ||
459 | int len; | ||
460 | |||
461 | len = i2c_smbus_read_block_data(client, | ||
462 | ETP_SMBUS_PACKET_QUERY, | ||
463 | &report[ETP_SMBUS_REPORT_OFFSET]); | ||
464 | if (len < 0) { | ||
465 | dev_err(&client->dev, "failed to read report data: %d\n", len); | ||
466 | return len; | ||
467 | } | ||
468 | |||
469 | if (len != ETP_SMBUS_REPORT_LEN) { | ||
470 | dev_err(&client->dev, | ||
471 | "wrong report length (%d vs %d expected)\n", | ||
472 | len, ETP_SMBUS_REPORT_LEN); | ||
473 | return -EIO; | ||
474 | } | ||
475 | |||
476 | return 0; | ||
477 | } | ||
478 | |||
479 | static int elan_smbus_finish_fw_update(struct i2c_client *client, | ||
480 | struct completion *fw_completion) | ||
481 | { | ||
482 | /* No special handling unlike I2C transport */ | ||
483 | return 0; | ||
484 | } | ||
485 | |||
486 | const struct elan_transport_ops elan_smbus_ops = { | ||
487 | .initialize = elan_smbus_initialize, | ||
488 | .sleep_control = elan_smbus_sleep_control, | ||
489 | .power_control = elan_smbus_power_control, | ||
490 | .set_mode = elan_smbus_set_mode, | ||
491 | |||
492 | .calibrate = elan_smbus_calibrate, | ||
493 | .calibrate_result = elan_smbus_calibrate_result, | ||
494 | |||
495 | .get_baseline_data = elan_smbus_get_baseline_data, | ||
496 | |||
497 | .get_version = elan_smbus_get_version, | ||
498 | .get_sm_version = elan_smbus_get_sm_version, | ||
499 | .get_product_id = elan_smbus_get_product_id, | ||
500 | .get_checksum = elan_smbus_get_checksum, | ||
501 | |||
502 | .get_max = elan_smbus_get_max, | ||
503 | .get_resolution = elan_smbus_get_resolution, | ||
504 | .get_num_traces = elan_smbus_get_num_traces, | ||
505 | |||
506 | .iap_get_mode = elan_smbus_iap_get_mode, | ||
507 | .iap_reset = elan_smbus_iap_reset, | ||
508 | |||
509 | .prepare_fw_update = elan_smbus_prepare_fw_update, | ||
510 | .write_fw_block = elan_smbus_write_fw_block, | ||
511 | .finish_fw_update = elan_smbus_finish_fw_update, | ||
512 | |||
513 | .get_report = elan_smbus_get_report, | ||
514 | }; | ||
diff --git a/drivers/input/mouse/lifebook.h b/drivers/input/mouse/lifebook.h index 4c4326c6f504..0baf02a70a99 100644 --- a/drivers/input/mouse/lifebook.h +++ b/drivers/input/mouse/lifebook.h | |||
@@ -16,14 +16,14 @@ void lifebook_module_init(void); | |||
16 | int lifebook_detect(struct psmouse *psmouse, bool set_properties); | 16 | int lifebook_detect(struct psmouse *psmouse, bool set_properties); |
17 | int lifebook_init(struct psmouse *psmouse); | 17 | int lifebook_init(struct psmouse *psmouse); |
18 | #else | 18 | #else |
19 | inline void lifebook_module_init(void) | 19 | static inline void lifebook_module_init(void) |
20 | { | 20 | { |
21 | } | 21 | } |
22 | inline int lifebook_detect(struct psmouse *psmouse, bool set_properties) | 22 | static inline int lifebook_detect(struct psmouse *psmouse, bool set_properties) |
23 | { | 23 | { |
24 | return -ENOSYS; | 24 | return -ENOSYS; |
25 | } | 25 | } |
26 | inline int lifebook_init(struct psmouse *psmouse) | 26 | static inline int lifebook_init(struct psmouse *psmouse) |
27 | { | 27 | { |
28 | return -ENOSYS; | 28 | return -ENOSYS; |
29 | } | 29 | } |
diff --git a/drivers/input/mouse/navpoint.c b/drivers/input/mouse/navpoint.c index 1ccc88af1f0b..69017279e8d7 100644 --- a/drivers/input/mouse/navpoint.c +++ b/drivers/input/mouse/navpoint.c | |||
@@ -318,8 +318,7 @@ static int navpoint_remove(struct platform_device *pdev) | |||
318 | return 0; | 318 | return 0; |
319 | } | 319 | } |
320 | 320 | ||
321 | #ifdef CONFIG_PM_SLEEP | 321 | static int __maybe_unused navpoint_suspend(struct device *dev) |
322 | static int navpoint_suspend(struct device *dev) | ||
323 | { | 322 | { |
324 | struct platform_device *pdev = to_platform_device(dev); | 323 | struct platform_device *pdev = to_platform_device(dev); |
325 | struct navpoint *navpoint = platform_get_drvdata(pdev); | 324 | struct navpoint *navpoint = platform_get_drvdata(pdev); |
@@ -333,7 +332,7 @@ static int navpoint_suspend(struct device *dev) | |||
333 | return 0; | 332 | return 0; |
334 | } | 333 | } |
335 | 334 | ||
336 | static int navpoint_resume(struct device *dev) | 335 | static int __maybe_unused navpoint_resume(struct device *dev) |
337 | { | 336 | { |
338 | struct platform_device *pdev = to_platform_device(dev); | 337 | struct platform_device *pdev = to_platform_device(dev); |
339 | struct navpoint *navpoint = platform_get_drvdata(pdev); | 338 | struct navpoint *navpoint = platform_get_drvdata(pdev); |
@@ -346,7 +345,6 @@ static int navpoint_resume(struct device *dev) | |||
346 | 345 | ||
347 | return 0; | 346 | return 0; |
348 | } | 347 | } |
349 | #endif | ||
350 | 348 | ||
351 | static SIMPLE_DEV_PM_OPS(navpoint_pm_ops, navpoint_suspend, navpoint_resume); | 349 | static SIMPLE_DEV_PM_OPS(navpoint_pm_ops, navpoint_suspend, navpoint_resume); |
352 | 350 | ||
diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c index ad822608f6ee..878f18498f3b 100644 --- a/drivers/input/mouse/synaptics_i2c.c +++ b/drivers/input/mouse/synaptics_i2c.c | |||
@@ -614,8 +614,7 @@ static int synaptics_i2c_remove(struct i2c_client *client) | |||
614 | return 0; | 614 | return 0; |
615 | } | 615 | } |
616 | 616 | ||
617 | #ifdef CONFIG_PM_SLEEP | 617 | static int __maybe_unused synaptics_i2c_suspend(struct device *dev) |
618 | static int synaptics_i2c_suspend(struct device *dev) | ||
619 | { | 618 | { |
620 | struct i2c_client *client = to_i2c_client(dev); | 619 | struct i2c_client *client = to_i2c_client(dev); |
621 | struct synaptics_i2c *touch = i2c_get_clientdata(client); | 620 | struct synaptics_i2c *touch = i2c_get_clientdata(client); |
@@ -628,7 +627,7 @@ static int synaptics_i2c_suspend(struct device *dev) | |||
628 | return 0; | 627 | return 0; |
629 | } | 628 | } |
630 | 629 | ||
631 | static int synaptics_i2c_resume(struct device *dev) | 630 | static int __maybe_unused synaptics_i2c_resume(struct device *dev) |
632 | { | 631 | { |
633 | int ret; | 632 | int ret; |
634 | struct i2c_client *client = to_i2c_client(dev); | 633 | struct i2c_client *client = to_i2c_client(dev); |
@@ -643,7 +642,6 @@ static int synaptics_i2c_resume(struct device *dev) | |||
643 | 642 | ||
644 | return 0; | 643 | return 0; |
645 | } | 644 | } |
646 | #endif | ||
647 | 645 | ||
648 | static SIMPLE_DEV_PM_OPS(synaptics_i2c_pm, synaptics_i2c_suspend, | 646 | static SIMPLE_DEV_PM_OPS(synaptics_i2c_pm, synaptics_i2c_suspend, |
649 | synaptics_i2c_resume); | 647 | synaptics_i2c_resume); |