aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/mouse
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2015-09-03 13:01:44 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2015-09-03 13:01:44 -0400
commit01b944fe1cd4e21a2a9ed51adbdbafe2d5e905ba (patch)
tree85f506cf9fce3d8fd47cf624dd8698472bffc13f /drivers/input/mouse
parente51e38494a8ecc18650efb0c840600637891de2c (diff)
parent58f1eae48e5372200553de07b5ecc7574803ee91 (diff)
Merge branch 'next' into for-linus
Prepare first round of input updates for 4.3 merge window.
Diffstat (limited to 'drivers/input/mouse')
-rw-r--r--drivers/input/mouse/Kconfig2
-rw-r--r--drivers/input/mouse/Makefile2
-rw-r--r--drivers/input/mouse/cyapa.c183
-rw-r--r--drivers/input/mouse/cyapa.h157
-rw-r--r--drivers/input/mouse/cyapa_gen3.c15
-rw-r--r--drivers/input/mouse/cyapa_gen5.c1255
-rw-r--r--drivers/input/mouse/cyapa_gen6.c749
-rw-r--r--drivers/input/mouse/elan_i2c_core.c31
-rw-r--r--drivers/input/mouse/psmouse-base.c6
-rw-r--r--drivers/input/mouse/sentelic.c14
-rw-r--r--drivers/input/mouse/synaptics_i2c.c1
11 files changed, 1751 insertions, 664 deletions
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index d7820d1152d2..17f97e5e11e7 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -341,7 +341,7 @@ config MOUSE_VSXXXAA
341 341
342config MOUSE_GPIO 342config MOUSE_GPIO
343 tristate "GPIO mouse" 343 tristate "GPIO mouse"
344 depends on GPIOLIB 344 depends on GPIOLIB || COMPILE_TEST
345 select INPUT_POLLDEV 345 select INPUT_POLLDEV
346 help 346 help
347 This driver simulates a mouse on GPIO lines of various CPUs (and some 347 This driver simulates a mouse on GPIO lines of various CPUs (and some
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index 793300bfbddd..ee6a6e9563d4 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -24,7 +24,7 @@ obj-$(CONFIG_MOUSE_SYNAPTICS_I2C) += synaptics_i2c.o
24obj-$(CONFIG_MOUSE_SYNAPTICS_USB) += synaptics_usb.o 24obj-$(CONFIG_MOUSE_SYNAPTICS_USB) += synaptics_usb.o
25obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o 25obj-$(CONFIG_MOUSE_VSXXXAA) += vsxxxaa.o
26 26
27cyapatp-objs := cyapa.o cyapa_gen3.o cyapa_gen5.o 27cyapatp-objs := cyapa.o cyapa_gen3.o cyapa_gen5.o cyapa_gen6.o
28psmouse-objs := psmouse-base.o synaptics.o focaltech.o 28psmouse-objs := psmouse-base.o synaptics.o focaltech.o
29 29
30psmouse-$(CONFIG_MOUSE_PS2_ALPS) += alps.o 30psmouse-$(CONFIG_MOUSE_PS2_ALPS) += alps.o
diff --git a/drivers/input/mouse/cyapa.c b/drivers/input/mouse/cyapa.c
index efe148474e7f..eb76b61418f3 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-2014 Cypress Semiconductor, Inc. 9 * Copyright (C) 2011-2015 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
@@ -21,10 +21,12 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/regulator/consumer.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/uaccess.h> 26#include <linux/uaccess.h>
26#include <linux/pm_runtime.h> 27#include <linux/pm_runtime.h>
27#include <linux/acpi.h> 28#include <linux/acpi.h>
29#include <linux/of.h>
28#include "cyapa.h" 30#include "cyapa.h"
29 31
30 32
@@ -39,11 +41,33 @@ const char product_id[] = "CYTRA";
39 41
40static int cyapa_reinitialize(struct cyapa *cyapa); 42static int cyapa_reinitialize(struct cyapa *cyapa);
41 43
42static inline bool cyapa_is_bootloader_mode(struct cyapa *cyapa) 44bool cyapa_is_pip_bl_mode(struct cyapa *cyapa)
43{ 45{
46 if (cyapa->gen == CYAPA_GEN6 && cyapa->state == CYAPA_STATE_GEN6_BL)
47 return true;
48
44 if (cyapa->gen == CYAPA_GEN5 && cyapa->state == CYAPA_STATE_GEN5_BL) 49 if (cyapa->gen == CYAPA_GEN5 && cyapa->state == CYAPA_STATE_GEN5_BL)
45 return true; 50 return true;
46 51
52 return false;
53}
54
55bool cyapa_is_pip_app_mode(struct cyapa *cyapa)
56{
57 if (cyapa->gen == CYAPA_GEN6 && cyapa->state == CYAPA_STATE_GEN6_APP)
58 return true;
59
60 if (cyapa->gen == CYAPA_GEN5 && cyapa->state == CYAPA_STATE_GEN5_APP)
61 return true;
62
63 return false;
64}
65
66static bool cyapa_is_bootloader_mode(struct cyapa *cyapa)
67{
68 if (cyapa_is_pip_bl_mode(cyapa))
69 return true;
70
47 if (cyapa->gen == CYAPA_GEN3 && 71 if (cyapa->gen == CYAPA_GEN3 &&
48 cyapa->state >= CYAPA_STATE_BL_BUSY && 72 cyapa->state >= CYAPA_STATE_BL_BUSY &&
49 cyapa->state <= CYAPA_STATE_BL_ACTIVE) 73 cyapa->state <= CYAPA_STATE_BL_ACTIVE)
@@ -54,7 +78,7 @@ static inline bool cyapa_is_bootloader_mode(struct cyapa *cyapa)
54 78
55static inline bool cyapa_is_operational_mode(struct cyapa *cyapa) 79static inline bool cyapa_is_operational_mode(struct cyapa *cyapa)
56{ 80{
57 if (cyapa->gen == CYAPA_GEN5 && cyapa->state == CYAPA_STATE_GEN5_APP) 81 if (cyapa_is_pip_app_mode(cyapa))
58 return true; 82 return true;
59 83
60 if (cyapa->gen == CYAPA_GEN3 && cyapa->state == CYAPA_STATE_OP) 84 if (cyapa->gen == CYAPA_GEN3 && cyapa->state == CYAPA_STATE_OP)
@@ -188,6 +212,15 @@ static int cyapa_get_state(struct cyapa *cyapa)
188 if (!error) 212 if (!error)
189 goto out_detected; 213 goto out_detected;
190 } 214 }
215 if (cyapa->gen == CYAPA_GEN_UNKNOWN ||
216 cyapa->gen == CYAPA_GEN6 ||
217 cyapa->gen == CYAPA_GEN5) {
218 error = cyapa_pip_state_parse(cyapa,
219 status, BL_STATUS_SIZE);
220 if (!error)
221 goto out_detected;
222 }
223 /* For old Gen5 trackpads detecting. */
191 if ((cyapa->gen == CYAPA_GEN_UNKNOWN || 224 if ((cyapa->gen == CYAPA_GEN_UNKNOWN ||
192 cyapa->gen == CYAPA_GEN5) && 225 cyapa->gen == CYAPA_GEN5) &&
193 !smbus && even_addr) { 226 !smbus && even_addr) {
@@ -284,6 +317,9 @@ static int cyapa_check_is_operational(struct cyapa *cyapa)
284 return error; 317 return error;
285 318
286 switch (cyapa->gen) { 319 switch (cyapa->gen) {
320 case CYAPA_GEN6:
321 cyapa->ops = &cyapa_gen6_ops;
322 break;
287 case CYAPA_GEN5: 323 case CYAPA_GEN5:
288 cyapa->ops = &cyapa_gen5_ops; 324 cyapa->ops = &cyapa_gen5_ops;
289 break; 325 break;
@@ -306,7 +342,7 @@ static int cyapa_check_is_operational(struct cyapa *cyapa)
306 342
307/* 343/*
308 * Returns 0 on device detected, negative errno on no device detected. 344 * Returns 0 on device detected, negative errno on no device detected.
309 * And when the device is detected and opertaional, it will be reset to 345 * And when the device is detected and operational, it will be reset to
310 * full power active mode automatically. 346 * full power active mode automatically.
311 */ 347 */
312static int cyapa_detect(struct cyapa *cyapa) 348static int cyapa_detect(struct cyapa *cyapa)
@@ -333,6 +369,7 @@ static int cyapa_open(struct input_dev *input)
333{ 369{
334 struct cyapa *cyapa = input_get_drvdata(input); 370 struct cyapa *cyapa = input_get_drvdata(input);
335 struct i2c_client *client = cyapa->client; 371 struct i2c_client *client = cyapa->client;
372 struct device *dev = &client->dev;
336 int error; 373 int error;
337 374
338 error = mutex_lock_interruptible(&cyapa->state_sync_lock); 375 error = mutex_lock_interruptible(&cyapa->state_sync_lock);
@@ -346,10 +383,9 @@ static int cyapa_open(struct input_dev *input)
346 * when in operational mode. 383 * when in operational mode.
347 */ 384 */
348 error = cyapa->ops->set_power_mode(cyapa, 385 error = cyapa->ops->set_power_mode(cyapa,
349 PWR_MODE_FULL_ACTIVE, 0); 386 PWR_MODE_FULL_ACTIVE, 0, false);
350 if (error) { 387 if (error) {
351 dev_warn(&client->dev, 388 dev_warn(dev, "set active power failed: %d\n", error);
352 "set active power failed: %d\n", error);
353 goto out; 389 goto out;
354 } 390 }
355 } else { 391 } else {
@@ -361,10 +397,14 @@ static int cyapa_open(struct input_dev *input)
361 } 397 }
362 398
363 enable_irq(client->irq); 399 enable_irq(client->irq);
364 if (!pm_runtime_enabled(&client->dev)) { 400 if (!pm_runtime_enabled(dev)) {
365 pm_runtime_set_active(&client->dev); 401 pm_runtime_set_active(dev);
366 pm_runtime_enable(&client->dev); 402 pm_runtime_enable(dev);
367 } 403 }
404
405 pm_runtime_get_sync(dev);
406 pm_runtime_mark_last_busy(dev);
407 pm_runtime_put_sync_autosuspend(dev);
368out: 408out:
369 mutex_unlock(&cyapa->state_sync_lock); 409 mutex_unlock(&cyapa->state_sync_lock);
370 return error; 410 return error;
@@ -374,16 +414,17 @@ static void cyapa_close(struct input_dev *input)
374{ 414{
375 struct cyapa *cyapa = input_get_drvdata(input); 415 struct cyapa *cyapa = input_get_drvdata(input);
376 struct i2c_client *client = cyapa->client; 416 struct i2c_client *client = cyapa->client;
417 struct device *dev = &cyapa->client->dev;
377 418
378 mutex_lock(&cyapa->state_sync_lock); 419 mutex_lock(&cyapa->state_sync_lock);
379 420
380 disable_irq(client->irq); 421 disable_irq(client->irq);
381 if (pm_runtime_enabled(&client->dev)) 422 if (pm_runtime_enabled(dev))
382 pm_runtime_disable(&client->dev); 423 pm_runtime_disable(dev);
383 pm_runtime_set_suspended(&client->dev); 424 pm_runtime_set_suspended(dev);
384 425
385 if (cyapa->operational) 426 if (cyapa->operational)
386 cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0); 427 cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
387 428
388 mutex_unlock(&cyapa->state_sync_lock); 429 mutex_unlock(&cyapa->state_sync_lock);
389} 430}
@@ -443,6 +484,7 @@ static int cyapa_create_input_dev(struct cyapa *cyapa)
443 if (cyapa->gen >= CYAPA_GEN5) { 484 if (cyapa->gen >= CYAPA_GEN5) {
444 input_set_abs_params(input, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); 485 input_set_abs_params(input, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);
445 input_set_abs_params(input, ABS_MT_WIDTH_MINOR, 0, 255, 0, 0); 486 input_set_abs_params(input, ABS_MT_WIDTH_MINOR, 0, 255, 0, 0);
487 input_set_abs_params(input, ABS_DISTANCE, 0, 1, 0, 0);
446 } 488 }
447 489
448 input_abs_set_res(input, ABS_MT_POSITION_X, 490 input_abs_set_res(input, ABS_MT_POSITION_X,
@@ -492,7 +534,7 @@ static void cyapa_enable_irq_for_cmd(struct cyapa *cyapa)
492 */ 534 */
493 if (!input || cyapa->operational) 535 if (!input || cyapa->operational)
494 cyapa->ops->set_power_mode(cyapa, 536 cyapa->ops->set_power_mode(cyapa,
495 PWR_MODE_FULL_ACTIVE, 0); 537 PWR_MODE_FULL_ACTIVE, 0, false);
496 /* Gen3 always using polling mode for command. */ 538 /* Gen3 always using polling mode for command. */
497 if (cyapa->gen >= CYAPA_GEN5) 539 if (cyapa->gen >= CYAPA_GEN5)
498 enable_irq(cyapa->client->irq); 540 enable_irq(cyapa->client->irq);
@@ -507,7 +549,8 @@ static void cyapa_disable_irq_for_cmd(struct cyapa *cyapa)
507 if (cyapa->gen >= CYAPA_GEN5) 549 if (cyapa->gen >= CYAPA_GEN5)
508 disable_irq(cyapa->client->irq); 550 disable_irq(cyapa->client->irq);
509 if (!input || cyapa->operational) 551 if (!input || cyapa->operational)
510 cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0); 552 cyapa->ops->set_power_mode(cyapa,
553 PWR_MODE_OFF, 0, false);
511 } 554 }
512} 555}
513 556
@@ -563,6 +606,8 @@ static int cyapa_initialize(struct cyapa *cyapa)
563 error = cyapa_gen3_ops.initialize(cyapa); 606 error = cyapa_gen3_ops.initialize(cyapa);
564 if (!error) 607 if (!error)
565 error = cyapa_gen5_ops.initialize(cyapa); 608 error = cyapa_gen5_ops.initialize(cyapa);
609 if (!error)
610 error = cyapa_gen6_ops.initialize(cyapa);
566 if (error) 611 if (error)
567 return error; 612 return error;
568 613
@@ -572,7 +617,7 @@ static int cyapa_initialize(struct cyapa *cyapa)
572 617
573 /* Power down the device until we need it. */ 618 /* Power down the device until we need it. */
574 if (cyapa->operational) 619 if (cyapa->operational)
575 cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0); 620 cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0, false);
576 621
577 return 0; 622 return 0;
578} 623}
@@ -588,7 +633,8 @@ static int cyapa_reinitialize(struct cyapa *cyapa)
588 633
589 /* Avoid command failures when TP was in OFF state. */ 634 /* Avoid command failures when TP was in OFF state. */
590 if (cyapa->operational) 635 if (cyapa->operational)
591 cyapa->ops->set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0); 636 cyapa->ops->set_power_mode(cyapa,
637 PWR_MODE_FULL_ACTIVE, 0, false);
592 638
593 error = cyapa_detect(cyapa); 639 error = cyapa_detect(cyapa);
594 if (error) 640 if (error)
@@ -607,7 +653,8 @@ out:
607 if (!input || !input->users) { 653 if (!input || !input->users) {
608 /* Reset to power OFF state to save power when no user open. */ 654 /* Reset to power OFF state to save power when no user open. */
609 if (cyapa->operational) 655 if (cyapa->operational)
610 cyapa->ops->set_power_mode(cyapa, PWR_MODE_OFF, 0); 656 cyapa->ops->set_power_mode(cyapa,
657 PWR_MODE_OFF, 0, false);
611 } else if (!error && cyapa->operational) { 658 } else if (!error && cyapa->operational) {
612 /* 659 /*
613 * Make sure only enable runtime PM when device is 660 * Make sure only enable runtime PM when device is
@@ -615,6 +662,10 @@ out:
615 */ 662 */
616 pm_runtime_set_active(dev); 663 pm_runtime_set_active(dev);
617 pm_runtime_enable(dev); 664 pm_runtime_enable(dev);
665
666 pm_runtime_get_sync(dev);
667 pm_runtime_mark_last_busy(dev);
668 pm_runtime_put_sync_autosuspend(dev);
618 } 669 }
619 670
620 return error; 671 return error;
@@ -624,27 +675,44 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
624{ 675{
625 struct cyapa *cyapa = dev_id; 676 struct cyapa *cyapa = dev_id;
626 struct device *dev = &cyapa->client->dev; 677 struct device *dev = &cyapa->client->dev;
678 int error;
627 679
628 pm_runtime_get_sync(dev);
629 if (device_may_wakeup(dev)) 680 if (device_may_wakeup(dev))
630 pm_wakeup_event(dev, 0); 681 pm_wakeup_event(dev, 0);
631 682
632 /* Interrupt event maybe cuased by host command to trackpad device. */ 683 /* Interrupt event can be caused by host command to trackpad device. */
633 if (cyapa->ops->irq_cmd_handler(cyapa)) { 684 if (cyapa->ops->irq_cmd_handler(cyapa)) {
634 /* 685 /*
635 * Interrupt event maybe from trackpad device input reporting. 686 * Interrupt event maybe from trackpad device input reporting.
636 */ 687 */
637 if (!cyapa->input) { 688 if (!cyapa->input) {
638 /* 689 /*
639 * Still in probling or in firware image 690 * Still in probing or in firmware image
640 * udpating or reading. 691 * updating or reading.
641 */ 692 */
642 cyapa->ops->sort_empty_output_data(cyapa, 693 cyapa->ops->sort_empty_output_data(cyapa,
643 NULL, NULL, NULL); 694 NULL, NULL, NULL);
644 goto out; 695 goto out;
645 } 696 }
646 697
647 if (!cyapa->operational || cyapa->ops->irq_handler(cyapa)) { 698 if (cyapa->operational) {
699 error = cyapa->ops->irq_handler(cyapa);
700
701 /*
702 * Apply runtime power management to touch report event
703 * except the events caused by the command responses.
704 * Note:
705 * It will introduce about 20~40 ms additional delay
706 * time in receiving for first valid touch report data.
707 * The time is used to execute device runtime resume
708 * process.
709 */
710 pm_runtime_get_sync(dev);
711 pm_runtime_mark_last_busy(dev);
712 pm_runtime_put_sync_autosuspend(dev);
713 }
714
715 if (!cyapa->operational || error) {
648 if (!mutex_trylock(&cyapa->state_sync_lock)) { 716 if (!mutex_trylock(&cyapa->state_sync_lock)) {
649 cyapa->ops->sort_empty_output_data(cyapa, 717 cyapa->ops->sort_empty_output_data(cyapa,
650 NULL, NULL, NULL); 718 NULL, NULL, NULL);
@@ -656,8 +724,6 @@ static irqreturn_t cyapa_irq(int irq, void *dev_id)
656 } 724 }
657 725
658out: 726out:
659 pm_runtime_mark_last_busy(dev);
660 pm_runtime_put_sync_autosuspend(dev);
661 return IRQ_HANDLED; 727 return IRQ_HANDLED;
662} 728}
663 729
@@ -1051,12 +1117,12 @@ static ssize_t cyapa_update_fw_store(struct device *dev,
1051 dev_dbg(dev, "firmware update successfully done.\n"); 1117 dev_dbg(dev, "firmware update successfully done.\n");
1052 1118
1053 /* 1119 /*
1054 * Redetect trackpad device states because firmware update process 1120 * Re-detect trackpad device states because firmware update process
1055 * will reset trackpad device into bootloader mode. 1121 * will reset trackpad device into bootloader mode.
1056 */ 1122 */
1057 ret = cyapa_reinitialize(cyapa); 1123 ret = cyapa_reinitialize(cyapa);
1058 if (ret) { 1124 if (ret) {
1059 dev_err(dev, "failed to redetect after updated: %d\n", ret); 1125 dev_err(dev, "failed to re-detect after updated: %d\n", ret);
1060 error = error ? error : ret; 1126 error = error ? error : ret;
1061 } 1127 }
1062 1128
@@ -1120,9 +1186,11 @@ static char *cyapa_state_to_string(struct cyapa *cyapa)
1120 case CYAPA_STATE_BL_ACTIVE: 1186 case CYAPA_STATE_BL_ACTIVE:
1121 return "bootloader active"; 1187 return "bootloader active";
1122 case CYAPA_STATE_GEN5_BL: 1188 case CYAPA_STATE_GEN5_BL:
1189 case CYAPA_STATE_GEN6_BL:
1123 return "bootloader"; 1190 return "bootloader";
1124 case CYAPA_STATE_OP: 1191 case CYAPA_STATE_OP:
1125 case CYAPA_STATE_GEN5_APP: 1192 case CYAPA_STATE_GEN5_APP:
1193 case CYAPA_STATE_GEN6_APP:
1126 return "operational"; /* Normal valid state. */ 1194 return "operational"; /* Normal valid state. */
1127 default: 1195 default:
1128 return "invalid mode"; 1196 return "invalid mode";
@@ -1175,6 +1243,13 @@ static void cyapa_remove_sysfs_group(void *data)
1175 sysfs_remove_group(&cyapa->client->dev.kobj, &cyapa_sysfs_group); 1243 sysfs_remove_group(&cyapa->client->dev.kobj, &cyapa_sysfs_group);
1176} 1244}
1177 1245
1246static void cyapa_disable_regulator(void *data)
1247{
1248 struct cyapa *cyapa = data;
1249
1250 regulator_disable(cyapa->vcc);
1251}
1252
1178static int cyapa_probe(struct i2c_client *client, 1253static int cyapa_probe(struct i2c_client *client,
1179 const struct i2c_device_id *dev_id) 1254 const struct i2c_device_id *dev_id)
1180{ 1255{
@@ -1208,6 +1283,27 @@ static int cyapa_probe(struct i2c_client *client,
1208 sprintf(cyapa->phys, "i2c-%d-%04x/input0", client->adapter->nr, 1283 sprintf(cyapa->phys, "i2c-%d-%04x/input0", client->adapter->nr,
1209 client->addr); 1284 client->addr);
1210 1285
1286 cyapa->vcc = devm_regulator_get(dev, "vcc");
1287 if (IS_ERR(cyapa->vcc)) {
1288 error = PTR_ERR(cyapa->vcc);
1289 dev_err(dev, "failed to get vcc regulator: %d\n", error);
1290 return error;
1291 }
1292
1293 error = regulator_enable(cyapa->vcc);
1294 if (error) {
1295 dev_err(dev, "failed to enable regulator: %d\n", error);
1296 return error;
1297 }
1298
1299 error = devm_add_action(dev, cyapa_disable_regulator, cyapa);
1300 if (error) {
1301 cyapa_disable_regulator(cyapa);
1302 dev_err(dev, "failed to add disable regulator action: %d\n",
1303 error);
1304 return error;
1305 }
1306
1211 error = cyapa_initialize(cyapa); 1307 error = cyapa_initialize(cyapa);
1212 if (error) { 1308 if (error) {
1213 dev_err(dev, "failed to detect and initialize tp device.\n"); 1309 dev_err(dev, "failed to detect and initialize tp device.\n");
@@ -1296,12 +1392,19 @@ static int __maybe_unused cyapa_suspend(struct device *dev)
1296 power_mode = device_may_wakeup(dev) ? cyapa->suspend_power_mode 1392 power_mode = device_may_wakeup(dev) ? cyapa->suspend_power_mode
1297 : PWR_MODE_OFF; 1393 : PWR_MODE_OFF;
1298 error = cyapa->ops->set_power_mode(cyapa, power_mode, 1394 error = cyapa->ops->set_power_mode(cyapa, power_mode,
1299 cyapa->suspend_sleep_time); 1395 cyapa->suspend_sleep_time, true);
1300 if (error) 1396 if (error)
1301 dev_err(dev, "suspend set power mode failed: %d\n", 1397 dev_err(dev, "suspend set power mode failed: %d\n",
1302 error); 1398 error);
1303 } 1399 }
1304 1400
1401 /*
1402 * Disable proximity interrupt when system idle, want true touch to
1403 * wake the system.
1404 */
1405 if (cyapa->dev_pwr_mode != PWR_MODE_OFF)
1406 cyapa->ops->set_proximity(cyapa, false);
1407
1305 if (device_may_wakeup(dev)) 1408 if (device_may_wakeup(dev))
1306 cyapa->irq_wake = (enable_irq_wake(client->irq) == 0); 1409 cyapa->irq_wake = (enable_irq_wake(client->irq) == 0);
1307 1410
@@ -1322,7 +1425,10 @@ static int __maybe_unused cyapa_resume(struct device *dev)
1322 cyapa->irq_wake = false; 1425 cyapa->irq_wake = false;
1323 } 1426 }
1324 1427
1325 /* Update device states and runtime PM states. */ 1428 /*
1429 * Update device states and runtime PM states.
1430 * Re-Enable proximity interrupt after enter operational mode.
1431 */
1326 error = cyapa_reinitialize(cyapa); 1432 error = cyapa_reinitialize(cyapa);
1327 if (error) 1433 if (error)
1328 dev_warn(dev, "failed to reinitialize TP device: %d\n", error); 1434 dev_warn(dev, "failed to reinitialize TP device: %d\n", error);
@@ -1340,7 +1446,8 @@ static int __maybe_unused cyapa_runtime_suspend(struct device *dev)
1340 1446
1341 error = cyapa->ops->set_power_mode(cyapa, 1447 error = cyapa->ops->set_power_mode(cyapa,
1342 cyapa->runtime_suspend_power_mode, 1448 cyapa->runtime_suspend_power_mode,
1343 cyapa->runtime_suspend_sleep_time); 1449 cyapa->runtime_suspend_sleep_time,
1450 false);
1344 if (error) 1451 if (error)
1345 dev_warn(dev, "runtime suspend failed: %d\n", error); 1452 dev_warn(dev, "runtime suspend failed: %d\n", error);
1346 1453
@@ -1352,7 +1459,8 @@ static int __maybe_unused cyapa_runtime_resume(struct device *dev)
1352 struct cyapa *cyapa = dev_get_drvdata(dev); 1459 struct cyapa *cyapa = dev_get_drvdata(dev);
1353 int error; 1460 int error;
1354 1461
1355 error = cyapa->ops->set_power_mode(cyapa, PWR_MODE_FULL_ACTIVE, 0); 1462 error = cyapa->ops->set_power_mode(cyapa,
1463 PWR_MODE_FULL_ACTIVE, 0, false);
1356 if (error) 1464 if (error)
1357 dev_warn(dev, "runtime resume failed: %d\n", error); 1465 dev_warn(dev, "runtime resume failed: %d\n", error);
1358 1466
@@ -1374,17 +1482,26 @@ MODULE_DEVICE_TABLE(i2c, cyapa_id_table);
1374static const struct acpi_device_id cyapa_acpi_id[] = { 1482static const struct acpi_device_id cyapa_acpi_id[] = {
1375 { "CYAP0000", 0 }, /* Gen3 trackpad with 0x67 I2C address. */ 1483 { "CYAP0000", 0 }, /* Gen3 trackpad with 0x67 I2C address. */
1376 { "CYAP0001", 0 }, /* Gen5 trackpad with 0x24 I2C address. */ 1484 { "CYAP0001", 0 }, /* Gen5 trackpad with 0x24 I2C address. */
1485 { "CYAP0002", 0 }, /* Gen6 trackpad with 0x24 I2C address. */
1377 { } 1486 { }
1378}; 1487};
1379MODULE_DEVICE_TABLE(acpi, cyapa_acpi_id); 1488MODULE_DEVICE_TABLE(acpi, cyapa_acpi_id);
1380#endif 1489#endif
1381 1490
1491#ifdef CONFIG_OF
1492static const struct of_device_id cyapa_of_match[] = {
1493 { .compatible = "cypress,cyapa" },
1494 { /* sentinel */ }
1495};
1496MODULE_DEVICE_TABLE(of, cyapa_of_match);
1497#endif
1498
1382static struct i2c_driver cyapa_driver = { 1499static struct i2c_driver cyapa_driver = {
1383 .driver = { 1500 .driver = {
1384 .name = "cyapa", 1501 .name = "cyapa",
1385 .owner = THIS_MODULE,
1386 .pm = &cyapa_pm_ops, 1502 .pm = &cyapa_pm_ops,
1387 .acpi_match_table = ACPI_PTR(cyapa_acpi_id), 1503 .acpi_match_table = ACPI_PTR(cyapa_acpi_id),
1504 .of_match_table = of_match_ptr(cyapa_of_match),
1388 }, 1505 },
1389 1506
1390 .probe = cyapa_probe, 1507 .probe = cyapa_probe,
diff --git a/drivers/input/mouse/cyapa.h b/drivers/input/mouse/cyapa.h
index adc9ed5dcb0e..b812bba8cdd7 100644
--- a/drivers/input/mouse/cyapa.h
+++ b/drivers/input/mouse/cyapa.h
@@ -3,7 +3,7 @@
3 * 3 *
4 * Author: Dudley Du <dudl@cypress.com> 4 * Author: Dudley Du <dudl@cypress.com>
5 * 5 *
6 * Copyright (C) 2014 Cypress Semiconductor, Inc. 6 * Copyright (C) 2014-2015 Cypress Semiconductor, Inc.
7 * 7 *
8 * This file is subject to the terms and conditions of the GNU General Public 8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for 9 * License. See the file COPYING in the main directory of this archive for
@@ -19,13 +19,14 @@
19#define CYAPA_GEN_UNKNOWN 0x00 /* unknown protocol. */ 19#define CYAPA_GEN_UNKNOWN 0x00 /* unknown protocol. */
20#define CYAPA_GEN3 0x03 /* support MT-protocol B with tracking ID. */ 20#define CYAPA_GEN3 0x03 /* support MT-protocol B with tracking ID. */
21#define CYAPA_GEN5 0x05 /* support TrueTouch GEN5 trackpad device. */ 21#define CYAPA_GEN5 0x05 /* support TrueTouch GEN5 trackpad device. */
22#define CYAPA_GEN6 0x06 /* support TrueTouch GEN6 trackpad device. */
22 23
23#define CYAPA_NAME "Cypress APA Trackpad (cyapa)" 24#define CYAPA_NAME "Cypress APA Trackpad (cyapa)"
24 25
25/* 26/*
26 * Macros for SMBus communication 27 * Macros for SMBus communication
27 */ 28 */
28#define SMBUS_READ 0x01 29#define SMBUS_READ 0x01
29#define SMBUS_WRITE 0x00 30#define SMBUS_WRITE 0x00
30#define SMBUS_ENCODE_IDX(cmd, idx) ((cmd) | (((idx) & 0x03) << 1)) 31#define SMBUS_ENCODE_IDX(cmd, idx) ((cmd) | (((idx) & 0x03) << 1))
31#define SMBUS_ENCODE_RW(cmd, rw) ((cmd) | ((rw) & 0x01)) 32#define SMBUS_ENCODE_RW(cmd, rw) ((cmd) | ((rw) & 0x01))
@@ -159,12 +160,89 @@
159 160
160#define AUTOSUSPEND_DELAY 2000 /* unit : ms */ 161#define AUTOSUSPEND_DELAY 2000 /* unit : ms */
161 162
162#define UNINIT_SLEEP_TIME 0xFFFF
163#define UNINIT_PWR_MODE 0xFF
164
165#define BTN_ONLY_MODE_NAME "buttononly" 163#define BTN_ONLY_MODE_NAME "buttononly"
166#define OFF_MODE_NAME "off" 164#define OFF_MODE_NAME "off"
167 165
166/* Common macros for PIP interface. */
167#define PIP_HID_DESCRIPTOR_ADDR 0x0001
168#define PIP_REPORT_DESCRIPTOR_ADDR 0x0002
169#define PIP_INPUT_REPORT_ADDR 0x0003
170#define PIP_OUTPUT_REPORT_ADDR 0x0004
171#define PIP_CMD_DATA_ADDR 0x0006
172
173#define PIP_RETRIEVE_DATA_STRUCTURE 0x24
174#define PIP_CMD_CALIBRATE 0x28
175#define PIP_BL_CMD_VERIFY_APP_INTEGRITY 0x31
176#define PIP_BL_CMD_GET_BL_INFO 0x38
177#define PIP_BL_CMD_PROGRAM_VERIFY_ROW 0x39
178#define PIP_BL_CMD_LAUNCH_APP 0x3b
179#define PIP_BL_CMD_INITIATE_BL 0x48
180#define PIP_INVALID_CMD 0xff
181
182#define PIP_HID_DESCRIPTOR_SIZE 32
183#define PIP_HID_APP_REPORT_ID 0xf7
184#define PIP_HID_BL_REPORT_ID 0xff
185
186#define PIP_BL_CMD_REPORT_ID 0x40
187#define PIP_BL_RESP_REPORT_ID 0x30
188#define PIP_APP_CMD_REPORT_ID 0x2f
189#define PIP_APP_RESP_REPORT_ID 0x1f
190
191#define PIP_READ_SYS_INFO_CMD_LENGTH 7
192#define PIP_BL_READ_APP_INFO_CMD_LENGTH 13
193#define PIP_MIN_BL_CMD_LENGTH 13
194#define PIP_MIN_BL_RESP_LENGTH 11
195#define PIP_MIN_APP_CMD_LENGTH 7
196#define PIP_MIN_APP_RESP_LENGTH 5
197#define PIP_UNSUPPORTED_CMD_RESP_LENGTH 6
198#define PIP_READ_SYS_INFO_RESP_LENGTH 71
199#define PIP_BL_APP_INFO_RESP_LENGTH 30
200#define PIP_BL_GET_INFO_RESP_LENGTH 19
201
202#define PIP_BL_PLATFORM_VER_SHIFT 4
203#define PIP_BL_PLATFORM_VER_MASK 0x0f
204
205#define PIP_PRODUCT_FAMILY_MASK 0xf000
206#define PIP_PRODUCT_FAMILY_TRACKPAD 0x1000
207
208#define PIP_DEEP_SLEEP_STATE_ON 0x00
209#define PIP_DEEP_SLEEP_STATE_OFF 0x01
210#define PIP_DEEP_SLEEP_STATE_MASK 0x03
211#define PIP_APP_DEEP_SLEEP_REPORT_ID 0xf0
212#define PIP_DEEP_SLEEP_RESP_LENGTH 5
213#define PIP_DEEP_SLEEP_OPCODE 0x08
214#define PIP_DEEP_SLEEP_OPCODE_MASK 0x0f
215
216#define PIP_RESP_LENGTH_OFFSET 0
217#define PIP_RESP_LENGTH_SIZE 2
218#define PIP_RESP_REPORT_ID_OFFSET 2
219#define PIP_RESP_RSVD_OFFSET 3
220#define PIP_RESP_RSVD_KEY 0x00
221#define PIP_RESP_BL_SOP_OFFSET 4
222#define PIP_SOP_KEY 0x01 /* Start of Packet */
223#define PIP_EOP_KEY 0x17 /* End of Packet */
224#define PIP_RESP_APP_CMD_OFFSET 4
225#define GET_PIP_CMD_CODE(reg) ((reg) & 0x7f)
226#define PIP_RESP_STATUS_OFFSET 5
227
228#define VALID_CMD_RESP_HEADER(resp, cmd) \
229 (((resp)[PIP_RESP_REPORT_ID_OFFSET] == PIP_APP_RESP_REPORT_ID) && \
230 ((resp)[PIP_RESP_RSVD_OFFSET] == PIP_RESP_RSVD_KEY) && \
231 (GET_PIP_CMD_CODE((resp)[PIP_RESP_APP_CMD_OFFSET]) == (cmd)))
232
233#define PIP_CMD_COMPLETE_SUCCESS(resp_data) \
234 ((resp_data)[PIP_RESP_STATUS_OFFSET] == 0x00)
235
236/* Variables to record latest gen5 trackpad power states. */
237#define UNINIT_SLEEP_TIME 0xffff
238#define UNINIT_PWR_MODE 0xff
239#define PIP_DEV_SET_PWR_STATE(cyapa, s) ((cyapa)->dev_pwr_mode = (s))
240#define PIP_DEV_GET_PWR_STATE(cyapa) ((cyapa)->dev_pwr_mode)
241#define PIP_DEV_SET_SLEEP_TIME(cyapa, t) ((cyapa)->dev_sleep_time = (t))
242#define PIP_DEV_GET_SLEEP_TIME(cyapa) ((cyapa)->dev_sleep_time)
243#define PIP_DEV_UNINIT_SLEEP_TIME(cyapa) \
244 (((cyapa)->dev_sleep_time) == UNINIT_SLEEP_TIME)
245
168/* The touch.id is used as the MT slot id, thus max MT slot is 15 */ 246/* The touch.id is used as the MT slot id, thus max MT slot is 15 */
169#define CYAPA_MAX_MT_SLOTS 15 247#define CYAPA_MAX_MT_SLOTS 15
170 248
@@ -195,10 +273,12 @@ struct cyapa_dev_ops {
195 int (*sort_empty_output_data)(struct cyapa *, 273 int (*sort_empty_output_data)(struct cyapa *,
196 u8 *, int *, cb_sort); 274 u8 *, int *, cb_sort);
197 275
198 int (*set_power_mode)(struct cyapa *, u8, u16); 276 int (*set_power_mode)(struct cyapa *, u8, u16, bool);
277
278 int (*set_proximity)(struct cyapa *, bool);
199}; 279};
200 280
201struct cyapa_gen5_cmd_states { 281struct cyapa_pip_cmd_states {
202 struct mutex cmd_lock; 282 struct mutex cmd_lock;
203 struct completion cmd_ready; 283 struct completion cmd_ready;
204 atomic_t cmd_issued; 284 atomic_t cmd_issued;
@@ -214,7 +294,7 @@ struct cyapa_gen5_cmd_states {
214}; 294};
215 295
216union cyapa_cmd_states { 296union cyapa_cmd_states {
217 struct cyapa_gen5_cmd_states gen5; 297 struct cyapa_pip_cmd_states pip;
218}; 298};
219 299
220enum cyapa_state { 300enum cyapa_state {
@@ -225,6 +305,14 @@ enum cyapa_state {
225 CYAPA_STATE_OP, 305 CYAPA_STATE_OP,
226 CYAPA_STATE_GEN5_BL, 306 CYAPA_STATE_GEN5_BL,
227 CYAPA_STATE_GEN5_APP, 307 CYAPA_STATE_GEN5_APP,
308 CYAPA_STATE_GEN6_BL,
309 CYAPA_STATE_GEN6_APP,
310};
311
312struct gen6_interval_setting {
313 u16 active_interval;
314 u16 lp1_interval;
315 u16 lp2_interval;
228}; 316};
229 317
230/* The main device structure */ 318/* The main device structure */
@@ -233,6 +321,7 @@ struct cyapa {
233 u8 status[BL_STATUS_SIZE]; 321 u8 status[BL_STATUS_SIZE];
234 bool operational; /* true: ready for data reporting; false: not. */ 322 bool operational; /* true: ready for data reporting; false: not. */
235 323
324 struct regulator *vcc;
236 struct i2c_client *client; 325 struct i2c_client *client;
237 struct input_dev *input; 326 struct input_dev *input;
238 char phys[32]; /* Device physical location */ 327 char phys[32]; /* Device physical location */
@@ -246,9 +335,11 @@ struct cyapa {
246 u16 runtime_suspend_sleep_time; 335 u16 runtime_suspend_sleep_time;
247 u8 dev_pwr_mode; 336 u8 dev_pwr_mode;
248 u16 dev_sleep_time; 337 u16 dev_sleep_time;
338 struct gen6_interval_setting gen6_interval_setting;
249 339
250 /* Read from query data region. */ 340 /* Read from query data region. */
251 char product_id[16]; 341 char product_id[16];
342 u8 platform_ver; /* Platform version. */
252 u8 fw_maj_ver; /* Firmware major version. */ 343 u8 fw_maj_ver; /* Firmware major version. */
253 u8 fw_min_ver; /* Firmware minor version. */ 344 u8 fw_min_ver; /* Firmware minor version. */
254 u8 btn_capability; 345 u8 btn_capability;
@@ -259,7 +350,7 @@ struct cyapa {
259 int physical_size_y; 350 int physical_size_y;
260 351
261 /* Used in ttsp and truetouch based trackpad devices. */ 352 /* Used in ttsp and truetouch based trackpad devices. */
262 u8 x_origin; /* X Axis Origin: 0 = left side; 1 = rigth side. */ 353 u8 x_origin; /* X Axis Origin: 0 = left side; 1 = right side. */
263 u8 y_origin; /* Y Axis Origin: 0 = top; 1 = bottom. */ 354 u8 y_origin; /* Y Axis Origin: 0 = top; 1 = bottom. */
264 int electrodes_x; /* Number of electrodes on the X Axis*/ 355 int electrodes_x; /* Number of electrodes on the X Axis*/
265 int electrodes_y; /* Number of electrodes on the Y Axis*/ 356 int electrodes_y; /* Number of electrodes on the Y Axis*/
@@ -282,9 +373,9 @@ struct cyapa {
282 373
283 374
284ssize_t cyapa_i2c_reg_read_block(struct cyapa *cyapa, u8 reg, size_t len, 375ssize_t cyapa_i2c_reg_read_block(struct cyapa *cyapa, u8 reg, size_t len,
285 u8 *values); 376 u8 *values);
286ssize_t cyapa_smbus_read_block(struct cyapa *cyapa, u8 cmd, size_t len, 377ssize_t cyapa_smbus_read_block(struct cyapa *cyapa, u8 cmd, size_t len,
287 u8 *values); 378 u8 *values);
288 379
289ssize_t cyapa_read_block(struct cyapa *cyapa, u8 cmd_idx, u8 *values); 380ssize_t cyapa_read_block(struct cyapa *cyapa, u8 cmd_idx, u8 *values);
290 381
@@ -293,9 +384,51 @@ int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout);
293u8 cyapa_sleep_time_to_pwr_cmd(u16 sleep_time); 384u8 cyapa_sleep_time_to_pwr_cmd(u16 sleep_time);
294u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode); 385u16 cyapa_pwr_cmd_to_sleep_time(u8 pwr_mode);
295 386
296 387ssize_t cyapa_i2c_pip_read(struct cyapa *cyapa, u8 *buf, size_t size);
388ssize_t cyapa_i2c_pip_write(struct cyapa *cyapa, u8 *buf, size_t size);
389int cyapa_empty_pip_output_data(struct cyapa *cyapa,
390 u8 *buf, int *len, cb_sort func);
391int cyapa_i2c_pip_cmd_irq_sync(struct cyapa *cyapa,
392 u8 *cmd, int cmd_len,
393 u8 *resp_data, int *resp_len,
394 unsigned long timeout,
395 cb_sort func,
396 bool irq_mode);
397int cyapa_pip_state_parse(struct cyapa *cyapa, u8 *reg_data, int len);
398bool cyapa_pip_sort_system_info_data(struct cyapa *cyapa, u8 *buf, int len);
399bool cyapa_sort_tsg_pip_bl_resp_data(struct cyapa *cyapa, u8 *data, int len);
400int cyapa_pip_deep_sleep(struct cyapa *cyapa, u8 state);
401bool cyapa_sort_tsg_pip_app_resp_data(struct cyapa *cyapa, u8 *data, int len);
402int cyapa_pip_bl_exit(struct cyapa *cyapa);
403int cyapa_pip_bl_enter(struct cyapa *cyapa);
404
405
406bool cyapa_is_pip_bl_mode(struct cyapa *cyapa);
407bool cyapa_is_pip_app_mode(struct cyapa *cyapa);
408int cyapa_pip_cmd_state_initialize(struct cyapa *cyapa);
409
410int cyapa_pip_resume_scanning(struct cyapa *cyapa);
411int cyapa_pip_suspend_scanning(struct cyapa *cyapa);
412
413int cyapa_pip_check_fw(struct cyapa *cyapa, const struct firmware *fw);
414int cyapa_pip_bl_initiate(struct cyapa *cyapa, const struct firmware *fw);
415int cyapa_pip_do_fw_update(struct cyapa *cyapa, const struct firmware *fw);
416int cyapa_pip_bl_activate(struct cyapa *cyapa);
417int cyapa_pip_bl_deactivate(struct cyapa *cyapa);
418ssize_t cyapa_pip_do_calibrate(struct device *dev,
419 struct device_attribute *attr,
420 const char *buf, size_t count);
421int cyapa_pip_set_proximity(struct cyapa *cyapa, bool enable);
422
423bool cyapa_pip_irq_cmd_handler(struct cyapa *cyapa);
424int cyapa_pip_irq_handler(struct cyapa *cyapa);
425
426
427extern u8 pip_read_sys_info[];
428extern u8 pip_bl_read_app_info[];
297extern const char product_id[]; 429extern const char product_id[];
298extern const struct cyapa_dev_ops cyapa_gen3_ops; 430extern const struct cyapa_dev_ops cyapa_gen3_ops;
299extern const struct cyapa_dev_ops cyapa_gen5_ops; 431extern const struct cyapa_dev_ops cyapa_gen5_ops;
432extern const struct cyapa_dev_ops cyapa_gen6_ops;
300 433
301#endif 434#endif
diff --git a/drivers/input/mouse/cyapa_gen3.c b/drivers/input/mouse/cyapa_gen3.c
index 3faf01c1b191..1a9d12ae7538 100644
--- a/drivers/input/mouse/cyapa_gen3.c
+++ b/drivers/input/mouse/cyapa_gen3.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-2014 Cypress Semiconductor, Inc. 9 * Copyright (C) 2011-2015 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
@@ -950,7 +950,7 @@ static u16 cyapa_get_wait_time_for_pwr_cmd(u8 pwr_mode)
950 * Device power mode can only be set when device is in operational mode. 950 * Device power mode can only be set when device is in operational mode.
951 */ 951 */
952static int cyapa_gen3_set_power_mode(struct cyapa *cyapa, u8 power_mode, 952static int cyapa_gen3_set_power_mode(struct cyapa *cyapa, u8 power_mode,
953 u16 always_unused) 953 u16 always_unused, bool is_suspend_unused)
954{ 954{
955 int ret; 955 int ret;
956 u8 power; 956 u8 power;
@@ -999,6 +999,11 @@ static int cyapa_gen3_set_power_mode(struct cyapa *cyapa, u8 power_mode,
999 return ret; 999 return ret;
1000} 1000}
1001 1001
1002static int cyapa_gen3_set_proximity(struct cyapa *cyapa, bool enable)
1003{
1004 return -EOPNOTSUPP;
1005}
1006
1002static int cyapa_gen3_get_query_data(struct cyapa *cyapa) 1007static int cyapa_gen3_get_query_data(struct cyapa *cyapa)
1003{ 1008{
1004 u8 query_data[QUERY_DATA_SIZE]; 1009 u8 query_data[QUERY_DATA_SIZE];
@@ -1107,7 +1112,7 @@ static int cyapa_gen3_do_operational_check(struct cyapa *cyapa)
1107 * may cause problems, so we set the power mode first here. 1112 * may cause problems, so we set the power mode first here.
1108 */ 1113 */
1109 error = cyapa_gen3_set_power_mode(cyapa, 1114 error = cyapa_gen3_set_power_mode(cyapa,
1110 PWR_MODE_FULL_ACTIVE, 0); 1115 PWR_MODE_FULL_ACTIVE, 0, false);
1111 if (error) 1116 if (error)
1112 dev_err(dev, "%s: set full power mode failed: %d\n", 1117 dev_err(dev, "%s: set full power mode failed: %d\n",
1113 __func__, error); 1118 __func__, error);
@@ -1156,7 +1161,7 @@ static bool cyapa_gen3_irq_cmd_handler(struct cyapa *cyapa)
1156 * so, stop cyapa_gen3_irq_handler to continue process to 1161 * so, stop cyapa_gen3_irq_handler to continue process to
1157 * avoid unwanted to error detecting and processing. 1162 * avoid unwanted to error detecting and processing.
1158 * 1163 *
1159 * And also, avoid the periodicly accerted interrupts to be processed 1164 * And also, avoid the periodically asserted interrupts to be processed
1160 * as touch inputs when gen3 failed to launch into application mode, 1165 * as touch inputs when gen3 failed to launch into application mode,
1161 * which will cause gen3 stays in bootloader mode. 1166 * which will cause gen3 stays in bootloader mode.
1162 */ 1167 */
@@ -1243,4 +1248,6 @@ const struct cyapa_dev_ops cyapa_gen3_ops = {
1243 .irq_cmd_handler = cyapa_gen3_irq_cmd_handler, 1248 .irq_cmd_handler = cyapa_gen3_irq_cmd_handler,
1244 .sort_empty_output_data = cyapa_gen3_empty_output_data, 1249 .sort_empty_output_data = cyapa_gen3_empty_output_data,
1245 .set_power_mode = cyapa_gen3_set_power_mode, 1250 .set_power_mode = cyapa_gen3_set_power_mode,
1251
1252 .set_proximity = cyapa_gen3_set_proximity,
1246}; 1253};
diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
index afc39e799da2..118ba977181e 100644
--- a/drivers/input/mouse/cyapa_gen5.c
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Author: Dudley Du <dudl@cypress.com> 4 * Author: Dudley Du <dudl@cypress.com>
5 * 5 *
6 * Copyright (C) 2014 Cypress Semiconductor, Inc. 6 * Copyright (C) 2014-2015 Cypress Semiconductor, Inc.
7 * 7 *
8 * This file is subject to the terms and conditions of the GNU General Public 8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for 9 * License. See the file COPYING in the main directory of this archive for
@@ -19,15 +19,11 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <asm/unaligned.h> 20#include <asm/unaligned.h>
21#include <linux/crc-itu-t.h> 21#include <linux/crc-itu-t.h>
22#include <linux/pm_runtime.h>
22#include "cyapa.h" 23#include "cyapa.h"
23 24
24 25
25/* Macro of Gen5 */ 26/* Macro of TSG firmware image */
26#define RECORD_EVENT_NONE 0
27#define RECORD_EVENT_TOUCHDOWN 1
28#define RECORD_EVENT_DISPLACE 2
29#define RECORD_EVENT_LIFTOFF 3
30
31#define CYAPA_TSG_FLASH_MAP_BLOCK_SIZE 0x80 27#define CYAPA_TSG_FLASH_MAP_BLOCK_SIZE 0x80
32#define CYAPA_TSG_IMG_FW_HDR_SIZE 13 28#define CYAPA_TSG_IMG_FW_HDR_SIZE 13
33#define CYAPA_TSG_FW_ROW_SIZE (CYAPA_TSG_FLASH_MAP_BLOCK_SIZE) 29#define CYAPA_TSG_FW_ROW_SIZE (CYAPA_TSG_FLASH_MAP_BLOCK_SIZE)
@@ -44,43 +40,55 @@
44 40
45#define CYAPA_TSG_MAX_CMD_SIZE 256 41#define CYAPA_TSG_MAX_CMD_SIZE 256
46 42
47#define GEN5_BL_CMD_VERIFY_APP_INTEGRITY 0x31 43/* Macro of PIP interface */
48#define GEN5_BL_CMD_GET_BL_INFO 0x38 44#define PIP_BL_INITIATE_RESP_LEN 11
49#define GEN5_BL_CMD_PROGRAM_VERIFY_ROW 0x39 45#define PIP_BL_FAIL_EXIT_RESP_LEN 11
50#define GEN5_BL_CMD_LAUNCH_APP 0x3b 46#define PIP_BL_FAIL_EXIT_STATUS_CODE 0x0c
51#define GEN5_BL_CMD_INITIATE_BL 0x48 47#define PIP_BL_VERIFY_INTEGRITY_RESP_LEN 12
52 48#define PIP_BL_INTEGRITY_CHEKC_PASS 0x00
53#define GEN5_HID_DESCRIPTOR_ADDR 0x0001 49#define PIP_BL_BLOCK_WRITE_RESP_LEN 11
54#define GEN5_REPORT_DESCRIPTOR_ADDR 0x0002 50
55#define GEN5_INPUT_REPORT_ADDR 0x0003 51#define PIP_TOUCH_REPORT_ID 0x01
56#define GEN5_OUTPUT_REPORT_ADDR 0x0004 52#define PIP_BTN_REPORT_ID 0x03
57#define GEN5_CMD_DATA_ADDR 0x0006 53#define PIP_WAKEUP_EVENT_REPORT_ID 0x04
58 54#define PIP_PUSH_BTN_REPORT_ID 0x06
59#define GEN5_TOUCH_REPORT_HEAD_SIZE 7 55#define GEN5_OLD_PUSH_BTN_REPORT_ID 0x05 /* Special for old Gen5 TP. */
60#define GEN5_TOUCH_REPORT_MAX_SIZE 127 56#define PIP_PROXIMITY_REPORT_ID 0x07
61#define GEN5_BTN_REPORT_HEAD_SIZE 6 57
62#define GEN5_BTN_REPORT_MAX_SIZE 14 58#define PIP_PROXIMITY_REPORT_SIZE 6
63#define GEN5_WAKEUP_EVENT_SIZE 4 59#define PIP_PROXIMITY_DISTANCE_OFFSET 0x05
64#define GEN5_RAW_DATA_HEAD_SIZE 24 60#define PIP_PROXIMITY_DISTANCE_MASK 0x01
65 61
66#define GEN5_BL_CMD_REPORT_ID 0x40 62#define PIP_TOUCH_REPORT_HEAD_SIZE 7
67#define GEN5_BL_RESP_REPORT_ID 0x30 63#define PIP_TOUCH_REPORT_MAX_SIZE 127
68#define GEN5_APP_CMD_REPORT_ID 0x2f 64#define PIP_BTN_REPORT_HEAD_SIZE 6
69#define GEN5_APP_RESP_REPORT_ID 0x1f 65#define PIP_BTN_REPORT_MAX_SIZE 14
70 66#define PIP_WAKEUP_EVENT_SIZE 4
71#define GEN5_APP_DEEP_SLEEP_REPORT_ID 0xf0 67
72#define GEN5_DEEP_SLEEP_RESP_LENGTH 5 68#define PIP_NUMBER_OF_TOUCH_OFFSET 5
69#define PIP_NUMBER_OF_TOUCH_MASK 0x1f
70#define PIP_BUTTONS_OFFSET 5
71#define PIP_BUTTONS_MASK 0x0f
72#define PIP_GET_EVENT_ID(reg) (((reg) >> 5) & 0x03)
73#define PIP_GET_TOUCH_ID(reg) ((reg) & 0x1f)
74#define PIP_TOUCH_TYPE_FINGER 0x00
75#define PIP_TOUCH_TYPE_PROXIMITY 0x01
76#define PIP_TOUCH_TYPE_HOVER 0x02
77#define PIP_GET_TOUCH_TYPE(reg) ((reg) & 0x07)
73 78
74#define GEN5_CMD_GET_PARAMETER 0x05 79#define RECORD_EVENT_NONE 0
75#define GEN5_CMD_SET_PARAMETER 0x06 80#define RECORD_EVENT_TOUCHDOWN 1
76#define GEN5_PARAMETER_ACT_INTERVL_ID 0x4d 81#define RECORD_EVENT_DISPLACE 2
77#define GEN5_PARAMETER_ACT_INTERVL_SIZE 1 82#define RECORD_EVENT_LIFTOFF 3
78#define GEN5_PARAMETER_ACT_LFT_INTERVL_ID 0x4f
79#define GEN5_PARAMETER_ACT_LFT_INTERVL_SIZE 2
80#define GEN5_PARAMETER_LP_INTRVL_ID 0x4c
81#define GEN5_PARAMETER_LP_INTRVL_SIZE 2
82 83
83#define GEN5_PARAMETER_DISABLE_PIP_REPORT 0x08 84#define PIP_SENSING_MODE_MUTUAL_CAP_FINE 0x00
85#define PIP_SENSING_MODE_SELF_CAP 0x02
86
87#define PIP_SET_PROXIMITY 0x49
88
89/* Macro of Gen5 */
90#define GEN5_BL_MAX_OUTPUT_LENGTH 0x0100
91#define GEN5_APP_MAX_OUTPUT_LENGTH 0x00fe
84 92
85#define GEN5_POWER_STATE_ACTIVE 0x01 93#define GEN5_POWER_STATE_ACTIVE 0x01
86#define GEN5_POWER_STATE_LOOK_FOR_TOUCH 0x02 94#define GEN5_POWER_STATE_LOOK_FOR_TOUCH 0x02
@@ -89,46 +97,19 @@
89#define GEN5_POWER_STATE_BTN_ONLY 0x05 97#define GEN5_POWER_STATE_BTN_ONLY 0x05
90#define GEN5_POWER_STATE_OFF 0x06 98#define GEN5_POWER_STATE_OFF 0x06
91 99
92#define GEN5_DEEP_SLEEP_STATE_MASK 0x03
93#define GEN5_DEEP_SLEEP_STATE_ON 0x00
94#define GEN5_DEEP_SLEEP_STATE_OFF 0x01
95
96#define GEN5_DEEP_SLEEP_OPCODE 0x08
97#define GEN5_DEEP_SLEEP_OPCODE_MASK 0x0f
98
99#define GEN5_POWER_READY_MAX_INTRVL_TIME 50 /* Unit: ms */ 100#define GEN5_POWER_READY_MAX_INTRVL_TIME 50 /* Unit: ms */
100#define GEN5_POWER_IDLE_MAX_INTRVL_TIME 250 /* Unit: ms */ 101#define GEN5_POWER_IDLE_MAX_INTRVL_TIME 250 /* Unit: ms */
101 102
102#define GEN5_CMD_REPORT_ID_OFFSET 4 103#define GEN5_CMD_GET_PARAMETER 0x05
103 104#define GEN5_CMD_SET_PARAMETER 0x06
104#define GEN5_RESP_REPORT_ID_OFFSET 2 105#define GEN5_PARAMETER_ACT_INTERVL_ID 0x4d
105#define GEN5_RESP_RSVD_OFFSET 3 106#define GEN5_PARAMETER_ACT_INTERVL_SIZE 1
106#define GEN5_RESP_RSVD_KEY 0x00 107#define GEN5_PARAMETER_ACT_LFT_INTERVL_ID 0x4f
107#define GEN5_RESP_BL_SOP_OFFSET 4 108#define GEN5_PARAMETER_ACT_LFT_INTERVL_SIZE 2
108#define GEN5_SOP_KEY 0x01 /* Start of Packet */ 109#define GEN5_PARAMETER_LP_INTRVL_ID 0x4c
109#define GEN5_EOP_KEY 0x17 /* End of Packet */ 110#define GEN5_PARAMETER_LP_INTRVL_SIZE 2
110#define GEN5_RESP_APP_CMD_OFFSET 4 111
111#define GET_GEN5_CMD_CODE(reg) ((reg) & 0x7f) 112#define GEN5_PARAMETER_DISABLE_PIP_REPORT 0x08
112
113#define VALID_CMD_RESP_HEADER(resp, cmd) \
114 (((resp)[GEN5_RESP_REPORT_ID_OFFSET] == GEN5_APP_RESP_REPORT_ID) && \
115 ((resp)[GEN5_RESP_RSVD_OFFSET] == GEN5_RESP_RSVD_KEY) && \
116 (GET_GEN5_CMD_CODE((resp)[GEN5_RESP_APP_CMD_OFFSET]) == (cmd)))
117
118#define GEN5_MIN_BL_CMD_LENGTH 13
119#define GEN5_MIN_BL_RESP_LENGTH 11
120#define GEN5_MIN_APP_CMD_LENGTH 7
121#define GEN5_MIN_APP_RESP_LENGTH 5
122#define GEN5_UNSUPPORTED_CMD_RESP_LENGTH 6
123
124#define GEN5_RESP_LENGTH_OFFSET 0x00
125#define GEN5_RESP_LENGTH_SIZE 2
126
127#define GEN5_HID_DESCRIPTOR_SIZE 32
128#define GEN5_BL_HID_REPORT_ID 0xff
129#define GEN5_APP_HID_REPORT_ID 0xf7
130#define GEN5_BL_MAX_OUTPUT_LENGTH 0x0100
131#define GEN5_APP_MAX_OUTPUT_LENGTH 0x00fe
132 113
133#define GEN5_BL_REPORT_DESCRIPTOR_SIZE 0x1d 114#define GEN5_BL_REPORT_DESCRIPTOR_SIZE 0x1d
134#define GEN5_BL_REPORT_DESCRIPTOR_ID 0xfe 115#define GEN5_BL_REPORT_DESCRIPTOR_ID 0xfe
@@ -136,26 +117,6 @@
136#define GEN5_APP_CONTRACT_REPORT_DESCRIPTOR_SIZE 0xfa 117#define GEN5_APP_CONTRACT_REPORT_DESCRIPTOR_SIZE 0xfa
137#define GEN5_APP_REPORT_DESCRIPTOR_ID 0xf6 118#define GEN5_APP_REPORT_DESCRIPTOR_ID 0xf6
138 119
139#define GEN5_TOUCH_REPORT_ID 0x01
140#define GEN5_BTN_REPORT_ID 0x03
141#define GEN5_WAKEUP_EVENT_REPORT_ID 0x04
142#define GEN5_OLD_PUSH_BTN_REPORT_ID 0x05
143#define GEN5_PUSH_BTN_REPORT_ID 0x06
144
145#define GEN5_CMD_COMPLETE_SUCCESS(status) ((status) == 0x00)
146
147#define GEN5_BL_INITIATE_RESP_LEN 11
148#define GEN5_BL_FAIL_EXIT_RESP_LEN 11
149#define GEN5_BL_FAIL_EXIT_STATUS_CODE 0x0c
150#define GEN5_BL_VERIFY_INTEGRITY_RESP_LEN 12
151#define GEN5_BL_INTEGRITY_CHEKC_PASS 0x00
152#define GEN5_BL_BLOCK_WRITE_RESP_LEN 11
153#define GEN5_BL_READ_APP_INFO_RESP_LEN 31
154#define GEN5_CMD_CALIBRATE 0x28
155#define CYAPA_SENSING_MODE_MUTUAL_CAP_FINE 0x00
156#define CYAPA_SENSING_MODE_SELF_CAP 0x02
157
158#define GEN5_CMD_RETRIEVE_DATA_STRUCTURE 0x24
159#define GEN5_RETRIEVE_MUTUAL_PWC_DATA 0x00 120#define GEN5_RETRIEVE_MUTUAL_PWC_DATA 0x00
160#define GEN5_RETRIEVE_SELF_CAP_PWC_DATA 0x01 121#define GEN5_RETRIEVE_SELF_CAP_PWC_DATA 0x01
161 122
@@ -170,28 +131,19 @@
170#define GEN5_PANEL_SCAN_SELF_BASELINE 0x04 131#define GEN5_PANEL_SCAN_SELF_BASELINE 0x04
171#define GEN5_PANEL_SCAN_SELF_DIFFCOUNT 0x05 132#define GEN5_PANEL_SCAN_SELF_DIFFCOUNT 0x05
172 133
173/* The offset only valid for reterive PWC and panel scan commands */ 134/* The offset only valid for retrieve PWC and panel scan commands */
174#define GEN5_RESP_DATA_STRUCTURE_OFFSET 10 135#define GEN5_RESP_DATA_STRUCTURE_OFFSET 10
175#define GEN5_PWC_DATA_ELEMENT_SIZE_MASK 0x07 136#define GEN5_PWC_DATA_ELEMENT_SIZE_MASK 0x07
176 137
177#define GEN5_NUMBER_OF_TOUCH_OFFSET 5
178#define GEN5_NUMBER_OF_TOUCH_MASK 0x1f
179#define GEN5_BUTTONS_OFFSET 5
180#define GEN5_BUTTONS_MASK 0x0f
181#define GEN5_GET_EVENT_ID(reg) (((reg) >> 5) & 0x03)
182#define GEN5_GET_TOUCH_ID(reg) ((reg) & 0x1f)
183
184#define GEN5_PRODUCT_FAMILY_MASK 0xf000
185#define GEN5_PRODUCT_FAMILY_TRACKPAD 0x1000
186 138
187#define TSG_INVALID_CMD 0xff 139struct cyapa_pip_touch_record {
188
189struct cyapa_gen5_touch_record {
190 /* 140 /*
191 * Bit 7 - 3: reserved 141 * Bit 7 - 3: reserved
192 * Bit 2 - 0: touch type; 142 * Bit 2 - 0: touch type;
193 * 0 : standard finger; 143 * 0 : standard finger;
194 * 1 - 15 : reserved. 144 * 1 : proximity (Start supported in Gen5 TP).
145 * 2 : finger hover (defined, but not used yet.)
146 * 3 - 15 : reserved.
195 */ 147 */
196 u8 touch_type; 148 u8 touch_type;
197 149
@@ -221,7 +173,14 @@ struct cyapa_gen5_touch_record {
221 /* Bit 15 - 8 of Y-axis coordinate of the touch in pixel. */ 173 /* Bit 15 - 8 of Y-axis coordinate of the touch in pixel. */
222 u8 y_hi; 174 u8 y_hi;
223 175
224 /* Touch intensity in counts, pressure value. */ 176 /*
177 * The meaning of this value is different when touch_type is different.
178 * For standard finger type:
179 * Touch intensity in counts, pressure value.
180 * For proximity type (Start supported in Gen5 TP):
181 * The distance, in surface units, between the contact and
182 * the surface.
183 **/
225 u8 z; 184 u8 z;
226 185
227 /* 186 /*
@@ -260,9 +219,9 @@ struct cyapa_gen5_touch_record {
260 u8 orientation; 219 u8 orientation;
261} __packed; 220} __packed;
262 221
263struct cyapa_gen5_report_data { 222struct cyapa_pip_report_data {
264 u8 report_head[GEN5_TOUCH_REPORT_HEAD_SIZE]; 223 u8 report_head[PIP_TOUCH_REPORT_HEAD_SIZE];
265 struct cyapa_gen5_touch_record touch_records[10]; 224 struct cyapa_pip_touch_record touch_records[10];
266} __packed; 225} __packed;
267 226
268struct cyapa_tsg_bin_image_head { 227struct cyapa_tsg_bin_image_head {
@@ -272,6 +231,12 @@ struct cyapa_tsg_bin_image_head {
272 u8 fw_major_version; 231 u8 fw_major_version;
273 u8 fw_minor_version; 232 u8 fw_minor_version;
274 u8 fw_revision_control_number[8]; 233 u8 fw_revision_control_number[8];
234 u8 silicon_id_hi;
235 u8 silicon_id_lo;
236 u8 chip_revision;
237 u8 family_id;
238 u8 bl_ver_maj;
239 u8 bl_ver_min;
275} __packed; 240} __packed;
276 241
277struct cyapa_tsg_bin_image_data_record { 242struct cyapa_tsg_bin_image_data_record {
@@ -288,36 +253,36 @@ struct cyapa_tsg_bin_image {
288 struct cyapa_tsg_bin_image_data_record records[0]; 253 struct cyapa_tsg_bin_image_data_record records[0];
289} __packed; 254} __packed;
290 255
291struct gen5_bl_packet_start { 256struct pip_bl_packet_start {
292 u8 sop; /* Start of packet, must be 01h */ 257 u8 sop; /* Start of packet, must be 01h */
293 u8 cmd_code; 258 u8 cmd_code;
294 __le16 data_length; /* Size of data parameter start from data[0] */ 259 __le16 data_length; /* Size of data parameter start from data[0] */
295} __packed; 260} __packed;
296 261
297struct gen5_bl_packet_end { 262struct pip_bl_packet_end {
298 __le16 crc; 263 __le16 crc;
299 u8 eop; /* End of packet, must be 17h */ 264 u8 eop; /* End of packet, must be 17h */
300} __packed; 265} __packed;
301 266
302struct gen5_bl_cmd_head { 267struct pip_bl_cmd_head {
303 __le16 addr; /* Output report register address, must be 0004h */ 268 __le16 addr; /* Output report register address, must be 0004h */
304 /* Size of packet not including output report register address */ 269 /* Size of packet not including output report register address */
305 __le16 length; 270 __le16 length;
306 u8 report_id; /* Bootloader output report id, must be 40h */ 271 u8 report_id; /* Bootloader output report id, must be 40h */
307 u8 rsvd; /* Reserved, must be 0 */ 272 u8 rsvd; /* Reserved, must be 0 */
308 struct gen5_bl_packet_start packet_start; 273 struct pip_bl_packet_start packet_start;
309 u8 data[0]; /* Command data variable based on commands */ 274 u8 data[0]; /* Command data variable based on commands */
310} __packed; 275} __packed;
311 276
312/* Initiate bootload command data structure. */ 277/* Initiate bootload command data structure. */
313struct gen5_bl_initiate_cmd_data { 278struct pip_bl_initiate_cmd_data {
314 /* Key must be "A5h 01h 02h 03h FFh FEh FDh 5Ah" */ 279 /* Key must be "A5h 01h 02h 03h FFh FEh FDh 5Ah" */
315 u8 key[CYAPA_TSG_BL_KEY_SIZE]; 280 u8 key[CYAPA_TSG_BL_KEY_SIZE];
316 u8 metadata_raw_parameter[CYAPA_TSG_FLASH_MAP_METADATA_SIZE]; 281 u8 metadata_raw_parameter[CYAPA_TSG_FLASH_MAP_METADATA_SIZE];
317 __le16 metadata_crc; 282 __le16 metadata_crc;
318} __packed; 283} __packed;
319 284
320struct gen5_bl_metadata_row_params { 285struct tsg_bl_metadata_row_params {
321 __le16 size; 286 __le16 size;
322 __le16 maximum_size; 287 __le16 maximum_size;
323 __le32 app_start; 288 __le32 app_start;
@@ -332,13 +297,13 @@ struct gen5_bl_metadata_row_params {
332} __packed; 297} __packed;
333 298
334/* Bootload program and verify row command data structure */ 299/* Bootload program and verify row command data structure */
335struct gen5_bl_flash_row_head { 300struct tsg_bl_flash_row_head {
336 u8 flash_array_id; 301 u8 flash_array_id;
337 __le16 flash_row_id; 302 __le16 flash_row_id;
338 u8 flash_data[0]; 303 u8 flash_data[0];
339} __packed; 304} __packed;
340 305
341struct gen5_app_cmd_head { 306struct pip_app_cmd_head {
342 __le16 addr; /* Output report register address, must be 0004h */ 307 __le16 addr; /* Output report register address, must be 0004h */
343 /* Size of packet not including output report register address */ 308 /* Size of packet not including output report register address */
344 __le16 length; 309 __le16 length;
@@ -369,30 +334,26 @@ struct gen5_retrieve_panel_scan_data {
369 u8 data_id; 334 u8 data_id;
370} __packed; 335} __packed;
371 336
372/* Variables to record latest gen5 trackpad power states. */ 337u8 pip_read_sys_info[] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x02 };
373#define GEN5_DEV_SET_PWR_STATE(cyapa, s) ((cyapa)->dev_pwr_mode = (s)) 338u8 pip_bl_read_app_info[] = { 0x04, 0x00, 0x0b, 0x00, 0x40, 0x00,
374#define GEN5_DEV_GET_PWR_STATE(cyapa) ((cyapa)->dev_pwr_mode) 339 0x01, 0x3c, 0x00, 0x00, 0xb0, 0x42, 0x17
375#define GEN5_DEV_SET_SLEEP_TIME(cyapa, t) ((cyapa)->dev_sleep_time = (t)) 340 };
376#define GEN5_DEV_GET_SLEEP_TIME(cyapa) ((cyapa)->dev_sleep_time)
377#define GEN5_DEV_UNINIT_SLEEP_TIME(cyapa) \
378 (((cyapa)->dev_sleep_time) == UNINIT_SLEEP_TIME)
379
380 341
381static u8 cyapa_gen5_bl_cmd_key[] = { 0xa5, 0x01, 0x02, 0x03, 342static u8 cyapa_pip_bl_cmd_key[] = { 0xa5, 0x01, 0x02, 0x03,
382 0xff, 0xfe, 0xfd, 0x5a }; 343 0xff, 0xfe, 0xfd, 0x5a };
383 344
384static int cyapa_gen5_initialize(struct cyapa *cyapa) 345int cyapa_pip_cmd_state_initialize(struct cyapa *cyapa)
385{ 346{
386 struct cyapa_gen5_cmd_states *gen5_pip = &cyapa->cmd_states.gen5; 347 struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
387 348
388 init_completion(&gen5_pip->cmd_ready); 349 init_completion(&pip->cmd_ready);
389 atomic_set(&gen5_pip->cmd_issued, 0); 350 atomic_set(&pip->cmd_issued, 0);
390 mutex_init(&gen5_pip->cmd_lock); 351 mutex_init(&pip->cmd_lock);
391 352
392 gen5_pip->resp_sort_func = NULL; 353 pip->resp_sort_func = NULL;
393 gen5_pip->in_progress_cmd = TSG_INVALID_CMD; 354 pip->in_progress_cmd = PIP_INVALID_CMD;
394 gen5_pip->resp_data = NULL; 355 pip->resp_data = NULL;
395 gen5_pip->resp_len = NULL; 356 pip->resp_len = NULL;
396 357
397 cyapa->dev_pwr_mode = UNINIT_PWR_MODE; 358 cyapa->dev_pwr_mode = UNINIT_PWR_MODE;
398 cyapa->dev_sleep_time = UNINIT_SLEEP_TIME; 359 cyapa->dev_sleep_time = UNINIT_SLEEP_TIME;
@@ -401,7 +362,7 @@ static int cyapa_gen5_initialize(struct cyapa *cyapa)
401} 362}
402 363
403/* Return negative errno, or else the number of bytes read. */ 364/* Return negative errno, or else the number of bytes read. */
404static ssize_t cyapa_i2c_pip_read(struct cyapa *cyapa, u8 *buf, size_t size) 365ssize_t cyapa_i2c_pip_read(struct cyapa *cyapa, u8 *buf, size_t size)
405{ 366{
406 int ret; 367 int ret;
407 368
@@ -415,14 +376,13 @@ static ssize_t cyapa_i2c_pip_read(struct cyapa *cyapa, u8 *buf, size_t size)
415 376
416 if (ret != size) 377 if (ret != size)
417 return (ret < 0) ? ret : -EIO; 378 return (ret < 0) ? ret : -EIO;
418
419 return size; 379 return size;
420} 380}
421 381
422/** 382/**
423 * Return a negative errno code else zero on success. 383 * Return a negative errno code else zero on success.
424 */ 384 */
425static ssize_t cyapa_i2c_pip_write(struct cyapa *cyapa, u8 *buf, size_t size) 385ssize_t cyapa_i2c_pip_write(struct cyapa *cyapa, u8 *buf, size_t size)
426{ 386{
427 int ret; 387 int ret;
428 388
@@ -441,10 +401,10 @@ static ssize_t cyapa_i2c_pip_write(struct cyapa *cyapa, u8 *buf, size_t size)
441 * This function is aimed to dump all not read data in Gen5 trackpad 401 * This function is aimed to dump all not read data in Gen5 trackpad
442 * before send any command, otherwise, the interrupt line will be blocked. 402 * before send any command, otherwise, the interrupt line will be blocked.
443 */ 403 */
444static int cyapa_empty_pip_output_data(struct cyapa *cyapa, 404int cyapa_empty_pip_output_data(struct cyapa *cyapa,
445 u8 *buf, int *len, cb_sort func) 405 u8 *buf, int *len, cb_sort func)
446{ 406{
447 struct cyapa_gen5_cmd_states *gen5_pip = &cyapa->cmd_states.gen5; 407 struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
448 int length; 408 int length;
449 int report_count; 409 int report_count;
450 int empty_count; 410 int empty_count;
@@ -476,13 +436,13 @@ static int cyapa_empty_pip_output_data(struct cyapa *cyapa,
476 if (empty_count > 5) 436 if (empty_count > 5)
477 return 0; 437 return 0;
478 438
479 error = cyapa_i2c_pip_read(cyapa, gen5_pip->empty_buf, 439 error = cyapa_i2c_pip_read(cyapa, pip->empty_buf,
480 GEN5_RESP_LENGTH_SIZE); 440 PIP_RESP_LENGTH_SIZE);
481 if (error < 0) 441 if (error < 0)
482 return error; 442 return error;
483 443
484 length = get_unaligned_le16(gen5_pip->empty_buf); 444 length = get_unaligned_le16(pip->empty_buf);
485 if (length == GEN5_RESP_LENGTH_SIZE) { 445 if (length == PIP_RESP_LENGTH_SIZE) {
486 empty_count++; 446 empty_count++;
487 continue; 447 continue;
488 } else if (length > CYAPA_REG_MAP_SIZE) { 448 } else if (length > CYAPA_REG_MAP_SIZE) {
@@ -490,11 +450,11 @@ static int cyapa_empty_pip_output_data(struct cyapa *cyapa,
490 return -EINVAL; 450 return -EINVAL;
491 } else if (length == 0) { 451 } else if (length == 0) {
492 /* Application or bootloader launch data polled out. */ 452 /* Application or bootloader launch data polled out. */
493 length = GEN5_RESP_LENGTH_SIZE; 453 length = PIP_RESP_LENGTH_SIZE;
494 if (buf && buf_len && func && 454 if (buf && buf_len && func &&
495 func(cyapa, gen5_pip->empty_buf, length)) { 455 func(cyapa, pip->empty_buf, length)) {
496 length = min(buf_len, length); 456 length = min(buf_len, length);
497 memcpy(buf, gen5_pip->empty_buf, length); 457 memcpy(buf, pip->empty_buf, length);
498 *len = length; 458 *len = length;
499 /* Response found, success. */ 459 /* Response found, success. */
500 return 0; 460 return 0;
@@ -502,19 +462,19 @@ static int cyapa_empty_pip_output_data(struct cyapa *cyapa,
502 continue; 462 continue;
503 } 463 }
504 464
505 error = cyapa_i2c_pip_read(cyapa, gen5_pip->empty_buf, length); 465 error = cyapa_i2c_pip_read(cyapa, pip->empty_buf, length);
506 if (error < 0) 466 if (error < 0)
507 return error; 467 return error;
508 468
509 report_count--; 469 report_count--;
510 empty_count = 0; 470 empty_count = 0;
511 length = get_unaligned_le16(gen5_pip->empty_buf); 471 length = get_unaligned_le16(pip->empty_buf);
512 if (length <= GEN5_RESP_LENGTH_SIZE) { 472 if (length <= PIP_RESP_LENGTH_SIZE) {
513 empty_count++; 473 empty_count++;
514 } else if (buf && buf_len && func && 474 } else if (buf && buf_len && func &&
515 func(cyapa, gen5_pip->empty_buf, length)) { 475 func(cyapa, pip->empty_buf, length)) {
516 length = min(buf_len, length); 476 length = min(buf_len, length);
517 memcpy(buf, gen5_pip->empty_buf, length); 477 memcpy(buf, pip->empty_buf, length);
518 *len = length; 478 *len = length;
519 /* Response found, success. */ 479 /* Response found, success. */
520 return 0; 480 return 0;
@@ -531,24 +491,24 @@ static int cyapa_do_i2c_pip_cmd_irq_sync(
531 u8 *cmd, size_t cmd_len, 491 u8 *cmd, size_t cmd_len,
532 unsigned long timeout) 492 unsigned long timeout)
533{ 493{
534 struct cyapa_gen5_cmd_states *gen5_pip = &cyapa->cmd_states.gen5; 494 struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
535 int error; 495 int error;
536 496
537 /* Wait for interrupt to set ready completion */ 497 /* Wait for interrupt to set ready completion */
538 init_completion(&gen5_pip->cmd_ready); 498 init_completion(&pip->cmd_ready);
539 499
540 atomic_inc(&gen5_pip->cmd_issued); 500 atomic_inc(&pip->cmd_issued);
541 error = cyapa_i2c_pip_write(cyapa, cmd, cmd_len); 501 error = cyapa_i2c_pip_write(cyapa, cmd, cmd_len);
542 if (error) { 502 if (error) {
543 atomic_dec(&gen5_pip->cmd_issued); 503 atomic_dec(&pip->cmd_issued);
544 return (error < 0) ? error : -EIO; 504 return (error < 0) ? error : -EIO;
545 } 505 }
546 506
547 /* Wait for interrupt to indicate command is completed. */ 507 /* Wait for interrupt to indicate command is completed. */
548 timeout = wait_for_completion_timeout(&gen5_pip->cmd_ready, 508 timeout = wait_for_completion_timeout(&pip->cmd_ready,
549 msecs_to_jiffies(timeout)); 509 msecs_to_jiffies(timeout));
550 if (timeout == 0) { 510 if (timeout == 0) {
551 atomic_dec(&gen5_pip->cmd_issued); 511 atomic_dec(&pip->cmd_issued);
552 return -ETIMEDOUT; 512 return -ETIMEDOUT;
553 } 513 }
554 514
@@ -562,15 +522,15 @@ static int cyapa_do_i2c_pip_cmd_polling(
562 unsigned long timeout, 522 unsigned long timeout,
563 cb_sort func) 523 cb_sort func)
564{ 524{
565 struct cyapa_gen5_cmd_states *gen5_pip = &cyapa->cmd_states.gen5; 525 struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
566 int tries; 526 int tries;
567 int length; 527 int length;
568 int error; 528 int error;
569 529
570 atomic_inc(&gen5_pip->cmd_issued); 530 atomic_inc(&pip->cmd_issued);
571 error = cyapa_i2c_pip_write(cyapa, cmd, cmd_len); 531 error = cyapa_i2c_pip_write(cyapa, cmd, cmd_len);
572 if (error) { 532 if (error) {
573 atomic_dec(&gen5_pip->cmd_issued); 533 atomic_dec(&pip->cmd_issued);
574 return error < 0 ? error : -EIO; 534 return error < 0 ? error : -EIO;
575 } 535 }
576 536
@@ -591,11 +551,11 @@ static int cyapa_do_i2c_pip_cmd_polling(
591 error = error ? error : -ETIMEDOUT; 551 error = error ? error : -ETIMEDOUT;
592 } 552 }
593 553
594 atomic_dec(&gen5_pip->cmd_issued); 554 atomic_dec(&pip->cmd_issued);
595 return error; 555 return error;
596} 556}
597 557
598static int cyapa_i2c_pip_cmd_irq_sync( 558int cyapa_i2c_pip_cmd_irq_sync(
599 struct cyapa *cyapa, 559 struct cyapa *cyapa,
600 u8 *cmd, int cmd_len, 560 u8 *cmd, int cmd_len,
601 u8 *resp_data, int *resp_len, 561 u8 *resp_data, int *resp_len,
@@ -603,34 +563,34 @@ static int cyapa_i2c_pip_cmd_irq_sync(
603 cb_sort func, 563 cb_sort func,
604 bool irq_mode) 564 bool irq_mode)
605{ 565{
606 struct cyapa_gen5_cmd_states *gen5_pip = &cyapa->cmd_states.gen5; 566 struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
607 int error; 567 int error;
608 568
609 if (!cmd || !cmd_len) 569 if (!cmd || !cmd_len)
610 return -EINVAL; 570 return -EINVAL;
611 571
612 /* Commands must be serialized. */ 572 /* Commands must be serialized. */
613 error = mutex_lock_interruptible(&gen5_pip->cmd_lock); 573 error = mutex_lock_interruptible(&pip->cmd_lock);
614 if (error) 574 if (error)
615 return error; 575 return error;
616 576
617 gen5_pip->resp_sort_func = func; 577 pip->resp_sort_func = func;
618 gen5_pip->resp_data = resp_data; 578 pip->resp_data = resp_data;
619 gen5_pip->resp_len = resp_len; 579 pip->resp_len = resp_len;
620 580
621 if (cmd_len >= GEN5_MIN_APP_CMD_LENGTH && 581 if (cmd_len >= PIP_MIN_APP_CMD_LENGTH &&
622 cmd[4] == GEN5_APP_CMD_REPORT_ID) { 582 cmd[4] == PIP_APP_CMD_REPORT_ID) {
623 /* Application command */ 583 /* Application command */
624 gen5_pip->in_progress_cmd = cmd[6] & 0x7f; 584 pip->in_progress_cmd = cmd[6] & 0x7f;
625 } else if (cmd_len >= GEN5_MIN_BL_CMD_LENGTH && 585 } else if (cmd_len >= PIP_MIN_BL_CMD_LENGTH &&
626 cmd[4] == GEN5_BL_CMD_REPORT_ID) { 586 cmd[4] == PIP_BL_CMD_REPORT_ID) {
627 /* Bootloader command */ 587 /* Bootloader command */
628 gen5_pip->in_progress_cmd = cmd[7]; 588 pip->in_progress_cmd = cmd[7];
629 } 589 }
630 590
631 /* Send command data, wait and read output response data's length. */ 591 /* Send command data, wait and read output response data's length. */
632 if (irq_mode) { 592 if (irq_mode) {
633 gen5_pip->is_irq_mode = true; 593 pip->is_irq_mode = true;
634 error = cyapa_do_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len, 594 error = cyapa_do_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len,
635 timeout); 595 timeout);
636 if (error == -ETIMEDOUT && resp_data && 596 if (error == -ETIMEDOUT && resp_data &&
@@ -646,54 +606,54 @@ static int cyapa_i2c_pip_cmd_irq_sync(
646 error = error ? error : -ETIMEDOUT; 606 error = error ? error : -ETIMEDOUT;
647 } 607 }
648 } else { 608 } else {
649 gen5_pip->is_irq_mode = false; 609 pip->is_irq_mode = false;
650 error = cyapa_do_i2c_pip_cmd_polling(cyapa, cmd, cmd_len, 610 error = cyapa_do_i2c_pip_cmd_polling(cyapa, cmd, cmd_len,
651 resp_data, resp_len, timeout, func); 611 resp_data, resp_len, timeout, func);
652 } 612 }
653 613
654 gen5_pip->resp_sort_func = NULL; 614 pip->resp_sort_func = NULL;
655 gen5_pip->resp_data = NULL; 615 pip->resp_data = NULL;
656 gen5_pip->resp_len = NULL; 616 pip->resp_len = NULL;
657 gen5_pip->in_progress_cmd = TSG_INVALID_CMD; 617 pip->in_progress_cmd = PIP_INVALID_CMD;
658 618
659 mutex_unlock(&gen5_pip->cmd_lock); 619 mutex_unlock(&pip->cmd_lock);
660 return error; 620 return error;
661} 621}
662 622
663static bool cyapa_gen5_sort_tsg_pip_bl_resp_data(struct cyapa *cyapa, 623bool cyapa_sort_tsg_pip_bl_resp_data(struct cyapa *cyapa,
664 u8 *data, int len) 624 u8 *data, int len)
665{ 625{
666 if (!data || len < GEN5_MIN_BL_RESP_LENGTH) 626 if (!data || len < PIP_MIN_BL_RESP_LENGTH)
667 return false; 627 return false;
668 628
669 /* Bootloader input report id 30h */ 629 /* Bootloader input report id 30h */
670 if (data[GEN5_RESP_REPORT_ID_OFFSET] == GEN5_BL_RESP_REPORT_ID && 630 if (data[PIP_RESP_REPORT_ID_OFFSET] == PIP_BL_RESP_REPORT_ID &&
671 data[GEN5_RESP_RSVD_OFFSET] == GEN5_RESP_RSVD_KEY && 631 data[PIP_RESP_RSVD_OFFSET] == PIP_RESP_RSVD_KEY &&
672 data[GEN5_RESP_BL_SOP_OFFSET] == GEN5_SOP_KEY) 632 data[PIP_RESP_BL_SOP_OFFSET] == PIP_SOP_KEY)
673 return true; 633 return true;
674 634
675 return false; 635 return false;
676} 636}
677 637
678static bool cyapa_gen5_sort_tsg_pip_app_resp_data(struct cyapa *cyapa, 638bool cyapa_sort_tsg_pip_app_resp_data(struct cyapa *cyapa,
679 u8 *data, int len) 639 u8 *data, int len)
680{ 640{
681 struct cyapa_gen5_cmd_states *gen5_pip = &cyapa->cmd_states.gen5; 641 struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
682 int resp_len; 642 int resp_len;
683 643
684 if (!data || len < GEN5_MIN_APP_RESP_LENGTH) 644 if (!data || len < PIP_MIN_APP_RESP_LENGTH)
685 return false; 645 return false;
686 646
687 if (data[GEN5_RESP_REPORT_ID_OFFSET] == GEN5_APP_RESP_REPORT_ID && 647 if (data[PIP_RESP_REPORT_ID_OFFSET] == PIP_APP_RESP_REPORT_ID &&
688 data[GEN5_RESP_RSVD_OFFSET] == GEN5_RESP_RSVD_KEY) { 648 data[PIP_RESP_RSVD_OFFSET] == PIP_RESP_RSVD_KEY) {
689 resp_len = get_unaligned_le16(&data[GEN5_RESP_LENGTH_OFFSET]); 649 resp_len = get_unaligned_le16(&data[PIP_RESP_LENGTH_OFFSET]);
690 if (GET_GEN5_CMD_CODE(data[GEN5_RESP_APP_CMD_OFFSET]) == 0x00 && 650 if (GET_PIP_CMD_CODE(data[PIP_RESP_APP_CMD_OFFSET]) == 0x00 &&
691 resp_len == GEN5_UNSUPPORTED_CMD_RESP_LENGTH && 651 resp_len == PIP_UNSUPPORTED_CMD_RESP_LENGTH &&
692 data[5] == gen5_pip->in_progress_cmd) { 652 data[5] == pip->in_progress_cmd) {
693 /* Unsupported command code */ 653 /* Unsupported command code */
694 return false; 654 return false;
695 } else if (GET_GEN5_CMD_CODE(data[GEN5_RESP_APP_CMD_OFFSET]) == 655 } else if (GET_PIP_CMD_CODE(data[PIP_RESP_APP_CMD_OFFSET]) ==
696 gen5_pip->in_progress_cmd) { 656 pip->in_progress_cmd) {
697 /* Correct command response received */ 657 /* Correct command response received */
698 return true; 658 return true;
699 } 659 }
@@ -702,10 +662,10 @@ static bool cyapa_gen5_sort_tsg_pip_app_resp_data(struct cyapa *cyapa,
702 return false; 662 return false;
703} 663}
704 664
705static bool cyapa_gen5_sort_application_launch_data(struct cyapa *cyapa, 665static bool cyapa_sort_pip_application_launch_data(struct cyapa *cyapa,
706 u8 *buf, int len) 666 u8 *buf, int len)
707{ 667{
708 if (buf == NULL || len < GEN5_RESP_LENGTH_SIZE) 668 if (buf == NULL || len < PIP_RESP_LENGTH_SIZE)
709 return false; 669 return false;
710 670
711 /* 671 /*
@@ -718,25 +678,25 @@ static bool cyapa_gen5_sort_application_launch_data(struct cyapa *cyapa,
718 return false; 678 return false;
719} 679}
720 680
721static bool cyapa_gen5_sort_hid_descriptor_data(struct cyapa *cyapa, 681static bool cyapa_sort_gen5_hid_descriptor_data(struct cyapa *cyapa,
722 u8 *buf, int len) 682 u8 *buf, int len)
723{ 683{
724 int resp_len; 684 int resp_len;
725 int max_output_len; 685 int max_output_len;
726 686
727 /* Check hid descriptor. */ 687 /* Check hid descriptor. */
728 if (len != GEN5_HID_DESCRIPTOR_SIZE) 688 if (len != PIP_HID_DESCRIPTOR_SIZE)
729 return false; 689 return false;
730 690
731 resp_len = get_unaligned_le16(&buf[GEN5_RESP_LENGTH_OFFSET]); 691 resp_len = get_unaligned_le16(&buf[PIP_RESP_LENGTH_OFFSET]);
732 max_output_len = get_unaligned_le16(&buf[16]); 692 max_output_len = get_unaligned_le16(&buf[16]);
733 if (resp_len == GEN5_HID_DESCRIPTOR_SIZE) { 693 if (resp_len == PIP_HID_DESCRIPTOR_SIZE) {
734 if (buf[GEN5_RESP_REPORT_ID_OFFSET] == GEN5_BL_HID_REPORT_ID && 694 if (buf[PIP_RESP_REPORT_ID_OFFSET] == PIP_HID_BL_REPORT_ID &&
735 max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) { 695 max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) {
736 /* BL mode HID Descriptor */ 696 /* BL mode HID Descriptor */
737 return true; 697 return true;
738 } else if ((buf[GEN5_RESP_REPORT_ID_OFFSET] == 698 } else if ((buf[PIP_RESP_REPORT_ID_OFFSET] ==
739 GEN5_APP_HID_REPORT_ID) && 699 PIP_HID_APP_REPORT_ID) &&
740 max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) { 700 max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) {
741 /* APP mode HID Descriptor */ 701 /* APP mode HID Descriptor */
742 return true; 702 return true;
@@ -746,21 +706,21 @@ static bool cyapa_gen5_sort_hid_descriptor_data(struct cyapa *cyapa,
746 return false; 706 return false;
747} 707}
748 708
749static bool cyapa_gen5_sort_deep_sleep_data(struct cyapa *cyapa, 709static bool cyapa_sort_pip_deep_sleep_data(struct cyapa *cyapa,
750 u8 *buf, int len) 710 u8 *buf, int len)
751{ 711{
752 if (len == GEN5_DEEP_SLEEP_RESP_LENGTH && 712 if (len == PIP_DEEP_SLEEP_RESP_LENGTH &&
753 buf[GEN5_RESP_REPORT_ID_OFFSET] == 713 buf[PIP_RESP_REPORT_ID_OFFSET] ==
754 GEN5_APP_DEEP_SLEEP_REPORT_ID && 714 PIP_APP_DEEP_SLEEP_REPORT_ID &&
755 (buf[4] & GEN5_DEEP_SLEEP_OPCODE_MASK) == 715 (buf[4] & PIP_DEEP_SLEEP_OPCODE_MASK) ==
756 GEN5_DEEP_SLEEP_OPCODE) 716 PIP_DEEP_SLEEP_OPCODE)
757 return true; 717 return true;
758 return false; 718 return false;
759} 719}
760 720
761static int gen5_idle_state_parse(struct cyapa *cyapa) 721static int gen5_idle_state_parse(struct cyapa *cyapa)
762{ 722{
763 u8 resp_data[GEN5_HID_DESCRIPTOR_SIZE]; 723 u8 resp_data[PIP_HID_DESCRIPTOR_SIZE];
764 int max_output_len; 724 int max_output_len;
765 int length; 725 int length;
766 u8 cmd[2]; 726 u8 cmd[2];
@@ -778,9 +738,9 @@ static int gen5_idle_state_parse(struct cyapa *cyapa)
778 if (ret != 3) 738 if (ret != 3)
779 return ret < 0 ? ret : -EIO; 739 return ret < 0 ? ret : -EIO;
780 740
781 length = get_unaligned_le16(&resp_data[GEN5_RESP_LENGTH_OFFSET]); 741 length = get_unaligned_le16(&resp_data[PIP_RESP_LENGTH_OFFSET]);
782 if (length == GEN5_RESP_LENGTH_SIZE) { 742 if (length == PIP_RESP_LENGTH_SIZE) {
783 /* Normal state of Gen5 with no data to respose */ 743 /* Normal state of Gen5 with no data to response */
784 cyapa->gen = CYAPA_GEN5; 744 cyapa->gen = CYAPA_GEN5;
785 745
786 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL); 746 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
@@ -788,30 +748,30 @@ static int gen5_idle_state_parse(struct cyapa *cyapa)
788 /* Read description from trackpad device */ 748 /* Read description from trackpad device */
789 cmd[0] = 0x01; 749 cmd[0] = 0x01;
790 cmd[1] = 0x00; 750 cmd[1] = 0x00;
791 length = GEN5_HID_DESCRIPTOR_SIZE; 751 length = PIP_HID_DESCRIPTOR_SIZE;
792 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 752 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
793 cmd, GEN5_RESP_LENGTH_SIZE, 753 cmd, PIP_RESP_LENGTH_SIZE,
794 resp_data, &length, 754 resp_data, &length,
795 300, 755 300,
796 cyapa_gen5_sort_hid_descriptor_data, 756 cyapa_sort_gen5_hid_descriptor_data,
797 false); 757 false);
798 if (error) 758 if (error)
799 return error; 759 return error;
800 760
801 length = get_unaligned_le16( 761 length = get_unaligned_le16(
802 &resp_data[GEN5_RESP_LENGTH_OFFSET]); 762 &resp_data[PIP_RESP_LENGTH_OFFSET]);
803 max_output_len = get_unaligned_le16(&resp_data[16]); 763 max_output_len = get_unaligned_le16(&resp_data[16]);
804 if ((length == GEN5_HID_DESCRIPTOR_SIZE || 764 if ((length == PIP_HID_DESCRIPTOR_SIZE ||
805 length == GEN5_RESP_LENGTH_SIZE) && 765 length == PIP_RESP_LENGTH_SIZE) &&
806 (resp_data[GEN5_RESP_REPORT_ID_OFFSET] == 766 (resp_data[PIP_RESP_REPORT_ID_OFFSET] ==
807 GEN5_BL_HID_REPORT_ID) && 767 PIP_HID_BL_REPORT_ID) &&
808 max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) { 768 max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) {
809 /* BL mode HID Description read */ 769 /* BL mode HID Description read */
810 cyapa->state = CYAPA_STATE_GEN5_BL; 770 cyapa->state = CYAPA_STATE_GEN5_BL;
811 } else if ((length == GEN5_HID_DESCRIPTOR_SIZE || 771 } else if ((length == PIP_HID_DESCRIPTOR_SIZE ||
812 length == GEN5_RESP_LENGTH_SIZE) && 772 length == PIP_RESP_LENGTH_SIZE) &&
813 (resp_data[GEN5_RESP_REPORT_ID_OFFSET] == 773 (resp_data[PIP_RESP_REPORT_ID_OFFSET] ==
814 GEN5_APP_HID_REPORT_ID) && 774 PIP_HID_APP_REPORT_ID) &&
815 max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) { 775 max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) {
816 /* APP mode HID Description read */ 776 /* APP mode HID Description read */
817 cyapa->state = CYAPA_STATE_GEN5_APP; 777 cyapa->state = CYAPA_STATE_GEN5_APP;
@@ -839,14 +799,14 @@ static int gen5_hid_description_header_parse(struct cyapa *cyapa, u8 *reg_data)
839 * or report any touch or button data. 799 * or report any touch or button data.
840 */ 800 */
841 ret = cyapa_i2c_pip_read(cyapa, resp_data, 801 ret = cyapa_i2c_pip_read(cyapa, resp_data,
842 GEN5_HID_DESCRIPTOR_SIZE); 802 PIP_HID_DESCRIPTOR_SIZE);
843 if (ret != GEN5_HID_DESCRIPTOR_SIZE) 803 if (ret != PIP_HID_DESCRIPTOR_SIZE)
844 return ret < 0 ? ret : -EIO; 804 return ret < 0 ? ret : -EIO;
845 length = get_unaligned_le16(&resp_data[GEN5_RESP_LENGTH_OFFSET]); 805 length = get_unaligned_le16(&resp_data[PIP_RESP_LENGTH_OFFSET]);
846 max_output_len = get_unaligned_le16(&resp_data[16]); 806 max_output_len = get_unaligned_le16(&resp_data[16]);
847 if (length == GEN5_RESP_LENGTH_SIZE) { 807 if (length == PIP_RESP_LENGTH_SIZE) {
848 if (reg_data[GEN5_RESP_REPORT_ID_OFFSET] == 808 if (reg_data[PIP_RESP_REPORT_ID_OFFSET] ==
849 GEN5_BL_HID_REPORT_ID) { 809 PIP_HID_BL_REPORT_ID) {
850 /* 810 /*
851 * BL mode HID Description has been previously 811 * BL mode HID Description has been previously
852 * read out. 812 * read out.
@@ -861,15 +821,15 @@ static int gen5_hid_description_header_parse(struct cyapa *cyapa, u8 *reg_data)
861 cyapa->gen = CYAPA_GEN5; 821 cyapa->gen = CYAPA_GEN5;
862 cyapa->state = CYAPA_STATE_GEN5_APP; 822 cyapa->state = CYAPA_STATE_GEN5_APP;
863 } 823 }
864 } else if (length == GEN5_HID_DESCRIPTOR_SIZE && 824 } else if (length == PIP_HID_DESCRIPTOR_SIZE &&
865 resp_data[2] == GEN5_BL_HID_REPORT_ID && 825 resp_data[2] == PIP_HID_BL_REPORT_ID &&
866 max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) { 826 max_output_len == GEN5_BL_MAX_OUTPUT_LENGTH) {
867 /* BL mode HID Description read. */ 827 /* BL mode HID Description read. */
868 cyapa->gen = CYAPA_GEN5; 828 cyapa->gen = CYAPA_GEN5;
869 cyapa->state = CYAPA_STATE_GEN5_BL; 829 cyapa->state = CYAPA_STATE_GEN5_BL;
870 } else if (length == GEN5_HID_DESCRIPTOR_SIZE && 830 } else if (length == PIP_HID_DESCRIPTOR_SIZE &&
871 (resp_data[GEN5_RESP_REPORT_ID_OFFSET] == 831 (resp_data[PIP_RESP_REPORT_ID_OFFSET] ==
872 GEN5_APP_HID_REPORT_ID) && 832 PIP_HID_APP_REPORT_ID) &&
873 max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) { 833 max_output_len == GEN5_APP_MAX_OUTPUT_LENGTH) {
874 /* APP mode HID Description read. */ 834 /* APP mode HID Description read. */
875 cyapa->gen = CYAPA_GEN5; 835 cyapa->gen = CYAPA_GEN5;
@@ -886,22 +846,22 @@ static int gen5_report_data_header_parse(struct cyapa *cyapa, u8 *reg_data)
886{ 846{
887 int length; 847 int length;
888 848
889 length = get_unaligned_le16(&reg_data[GEN5_RESP_LENGTH_OFFSET]); 849 length = get_unaligned_le16(&reg_data[PIP_RESP_LENGTH_OFFSET]);
890 switch (reg_data[GEN5_RESP_REPORT_ID_OFFSET]) { 850 switch (reg_data[PIP_RESP_REPORT_ID_OFFSET]) {
891 case GEN5_TOUCH_REPORT_ID: 851 case PIP_TOUCH_REPORT_ID:
892 if (length < GEN5_TOUCH_REPORT_HEAD_SIZE || 852 if (length < PIP_TOUCH_REPORT_HEAD_SIZE ||
893 length > GEN5_TOUCH_REPORT_MAX_SIZE) 853 length > PIP_TOUCH_REPORT_MAX_SIZE)
894 return -EINVAL; 854 return -EINVAL;
895 break; 855 break;
896 case GEN5_BTN_REPORT_ID: 856 case PIP_BTN_REPORT_ID:
897 case GEN5_OLD_PUSH_BTN_REPORT_ID: 857 case GEN5_OLD_PUSH_BTN_REPORT_ID:
898 case GEN5_PUSH_BTN_REPORT_ID: 858 case PIP_PUSH_BTN_REPORT_ID:
899 if (length < GEN5_BTN_REPORT_HEAD_SIZE || 859 if (length < PIP_BTN_REPORT_HEAD_SIZE ||
900 length > GEN5_BTN_REPORT_MAX_SIZE) 860 length > PIP_BTN_REPORT_MAX_SIZE)
901 return -EINVAL; 861 return -EINVAL;
902 break; 862 break;
903 case GEN5_WAKEUP_EVENT_REPORT_ID: 863 case PIP_WAKEUP_EVENT_REPORT_ID:
904 if (length != GEN5_WAKEUP_EVENT_SIZE) 864 if (length != PIP_WAKEUP_EVENT_SIZE)
905 return -EINVAL; 865 return -EINVAL;
906 break; 866 break;
907 default: 867 default:
@@ -915,7 +875,7 @@ static int gen5_report_data_header_parse(struct cyapa *cyapa, u8 *reg_data)
915 875
916static int gen5_cmd_resp_header_parse(struct cyapa *cyapa, u8 *reg_data) 876static int gen5_cmd_resp_header_parse(struct cyapa *cyapa, u8 *reg_data)
917{ 877{
918 struct cyapa_gen5_cmd_states *gen5_pip = &cyapa->cmd_states.gen5; 878 struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
919 int length; 879 int length;
920 int ret; 880 int ret;
921 881
@@ -924,15 +884,15 @@ static int gen5_cmd_resp_header_parse(struct cyapa *cyapa, u8 *reg_data)
924 * otherwise Gen5 trackpad cannot response next command 884 * otherwise Gen5 trackpad cannot response next command
925 * or report any touch or button data. 885 * or report any touch or button data.
926 */ 886 */
927 length = get_unaligned_le16(&reg_data[GEN5_RESP_LENGTH_OFFSET]); 887 length = get_unaligned_le16(&reg_data[PIP_RESP_LENGTH_OFFSET]);
928 ret = cyapa_i2c_pip_read(cyapa, gen5_pip->empty_buf, length); 888 ret = cyapa_i2c_pip_read(cyapa, pip->empty_buf, length);
929 if (ret != length) 889 if (ret != length)
930 return ret < 0 ? ret : -EIO; 890 return ret < 0 ? ret : -EIO;
931 891
932 if (length == GEN5_RESP_LENGTH_SIZE) { 892 if (length == PIP_RESP_LENGTH_SIZE) {
933 /* Previous command has read the data through out. */ 893 /* Previous command has read the data through out. */
934 if (reg_data[GEN5_RESP_REPORT_ID_OFFSET] == 894 if (reg_data[PIP_RESP_REPORT_ID_OFFSET] ==
935 GEN5_BL_RESP_REPORT_ID) { 895 PIP_BL_RESP_REPORT_ID) {
936 /* Gen5 BL command response data detected */ 896 /* Gen5 BL command response data detected */
937 cyapa->gen = CYAPA_GEN5; 897 cyapa->gen = CYAPA_GEN5;
938 cyapa->state = CYAPA_STATE_GEN5_BL; 898 cyapa->state = CYAPA_STATE_GEN5_BL;
@@ -941,21 +901,21 @@ static int gen5_cmd_resp_header_parse(struct cyapa *cyapa, u8 *reg_data)
941 cyapa->gen = CYAPA_GEN5; 901 cyapa->gen = CYAPA_GEN5;
942 cyapa->state = CYAPA_STATE_GEN5_APP; 902 cyapa->state = CYAPA_STATE_GEN5_APP;
943 } 903 }
944 } else if ((gen5_pip->empty_buf[GEN5_RESP_REPORT_ID_OFFSET] == 904 } else if ((pip->empty_buf[PIP_RESP_REPORT_ID_OFFSET] ==
945 GEN5_BL_RESP_REPORT_ID) && 905 PIP_BL_RESP_REPORT_ID) &&
946 (gen5_pip->empty_buf[GEN5_RESP_RSVD_OFFSET] == 906 (pip->empty_buf[PIP_RESP_RSVD_OFFSET] ==
947 GEN5_RESP_RSVD_KEY) && 907 PIP_RESP_RSVD_KEY) &&
948 (gen5_pip->empty_buf[GEN5_RESP_BL_SOP_OFFSET] == 908 (pip->empty_buf[PIP_RESP_BL_SOP_OFFSET] ==
949 GEN5_SOP_KEY) && 909 PIP_SOP_KEY) &&
950 (gen5_pip->empty_buf[length - 1] == 910 (pip->empty_buf[length - 1] ==
951 GEN5_EOP_KEY)) { 911 PIP_EOP_KEY)) {
952 /* Gen5 BL command response data detected */ 912 /* Gen5 BL command response data detected */
953 cyapa->gen = CYAPA_GEN5; 913 cyapa->gen = CYAPA_GEN5;
954 cyapa->state = CYAPA_STATE_GEN5_BL; 914 cyapa->state = CYAPA_STATE_GEN5_BL;
955 } else if (gen5_pip->empty_buf[GEN5_RESP_REPORT_ID_OFFSET] == 915 } else if (pip->empty_buf[PIP_RESP_REPORT_ID_OFFSET] ==
956 GEN5_APP_RESP_REPORT_ID && 916 PIP_APP_RESP_REPORT_ID &&
957 gen5_pip->empty_buf[GEN5_RESP_RSVD_OFFSET] == 917 pip->empty_buf[PIP_RESP_RSVD_OFFSET] ==
958 GEN5_RESP_RSVD_KEY) { 918 PIP_RESP_RSVD_KEY) {
959 /* Gen5 APP command response data detected */ 919 /* Gen5 APP command response data detected */
960 cyapa->gen = CYAPA_GEN5; 920 cyapa->gen = CYAPA_GEN5;
961 cyapa->state = CYAPA_STATE_GEN5_APP; 921 cyapa->state = CYAPA_STATE_GEN5_APP;
@@ -977,12 +937,12 @@ static int cyapa_gen5_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
977 cyapa->state = CYAPA_STATE_NO_DEVICE; 937 cyapa->state = CYAPA_STATE_NO_DEVICE;
978 938
979 /* Parse based on Gen5 characteristic registers and bits */ 939 /* Parse based on Gen5 characteristic registers and bits */
980 length = get_unaligned_le16(&reg_data[GEN5_RESP_LENGTH_OFFSET]); 940 length = get_unaligned_le16(&reg_data[PIP_RESP_LENGTH_OFFSET]);
981 if (length == 0 || length == GEN5_RESP_LENGTH_SIZE) { 941 if (length == 0 || length == PIP_RESP_LENGTH_SIZE) {
982 gen5_idle_state_parse(cyapa); 942 gen5_idle_state_parse(cyapa);
983 } else if (length == GEN5_HID_DESCRIPTOR_SIZE && 943 } else if (length == PIP_HID_DESCRIPTOR_SIZE &&
984 (reg_data[2] == GEN5_BL_HID_REPORT_ID || 944 (reg_data[2] == PIP_HID_BL_REPORT_ID ||
985 reg_data[2] == GEN5_APP_HID_REPORT_ID)) { 945 reg_data[2] == PIP_HID_APP_REPORT_ID)) {
986 gen5_hid_description_header_parse(cyapa, reg_data); 946 gen5_hid_description_header_parse(cyapa, reg_data);
987 } else if ((length == GEN5_APP_REPORT_DESCRIPTOR_SIZE || 947 } else if ((length == GEN5_APP_REPORT_DESCRIPTOR_SIZE ||
988 length == GEN5_APP_CONTRACT_REPORT_DESCRIPTOR_SIZE) && 948 length == GEN5_APP_CONTRACT_REPORT_DESCRIPTOR_SIZE) &&
@@ -992,17 +952,17 @@ static int cyapa_gen5_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
992 cyapa->state = CYAPA_STATE_GEN5_APP; 952 cyapa->state = CYAPA_STATE_GEN5_APP;
993 } else if (length == GEN5_BL_REPORT_DESCRIPTOR_SIZE && 953 } else if (length == GEN5_BL_REPORT_DESCRIPTOR_SIZE &&
994 reg_data[2] == GEN5_BL_REPORT_DESCRIPTOR_ID) { 954 reg_data[2] == GEN5_BL_REPORT_DESCRIPTOR_ID) {
995 /* 0x1D 0x00 0xFE is Gen5 BL report descriptior header. */ 955 /* 0x1D 0x00 0xFE is Gen5 BL report descriptor header. */
996 cyapa->gen = CYAPA_GEN5; 956 cyapa->gen = CYAPA_GEN5;
997 cyapa->state = CYAPA_STATE_GEN5_BL; 957 cyapa->state = CYAPA_STATE_GEN5_BL;
998 } else if (reg_data[2] == GEN5_TOUCH_REPORT_ID || 958 } else if (reg_data[2] == PIP_TOUCH_REPORT_ID ||
999 reg_data[2] == GEN5_BTN_REPORT_ID || 959 reg_data[2] == PIP_BTN_REPORT_ID ||
1000 reg_data[2] == GEN5_OLD_PUSH_BTN_REPORT_ID || 960 reg_data[2] == GEN5_OLD_PUSH_BTN_REPORT_ID ||
1001 reg_data[2] == GEN5_PUSH_BTN_REPORT_ID || 961 reg_data[2] == PIP_PUSH_BTN_REPORT_ID ||
1002 reg_data[2] == GEN5_WAKEUP_EVENT_REPORT_ID) { 962 reg_data[2] == PIP_WAKEUP_EVENT_REPORT_ID) {
1003 gen5_report_data_header_parse(cyapa, reg_data); 963 gen5_report_data_header_parse(cyapa, reg_data);
1004 } else if (reg_data[2] == GEN5_BL_RESP_REPORT_ID || 964 } else if (reg_data[2] == PIP_BL_RESP_REPORT_ID ||
1005 reg_data[2] == GEN5_APP_RESP_REPORT_ID) { 965 reg_data[2] == PIP_APP_RESP_REPORT_ID) {
1006 gen5_cmd_resp_header_parse(cyapa, reg_data); 966 gen5_cmd_resp_header_parse(cyapa, reg_data);
1007 } 967 }
1008 968
@@ -1023,14 +983,25 @@ static int cyapa_gen5_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
1023 return -EAGAIN; 983 return -EAGAIN;
1024} 984}
1025 985
1026static int cyapa_gen5_bl_initiate(struct cyapa *cyapa, 986static struct cyapa_tsg_bin_image_data_record *
1027 const struct firmware *fw) 987cyapa_get_image_record_data_num(const struct firmware *fw,
988 int *record_num)
989{
990 int head_size;
991
992 head_size = fw->data[0] + 1;
993 *record_num = (fw->size - head_size) /
994 sizeof(struct cyapa_tsg_bin_image_data_record);
995 return (struct cyapa_tsg_bin_image_data_record *)&fw->data[head_size];
996}
997
998int cyapa_pip_bl_initiate(struct cyapa *cyapa, const struct firmware *fw)
1028{ 999{
1029 struct cyapa_tsg_bin_image *image; 1000 struct cyapa_tsg_bin_image_data_record *image_records;
1030 struct gen5_bl_cmd_head *bl_cmd_head; 1001 struct pip_bl_cmd_head *bl_cmd_head;
1031 struct gen5_bl_packet_start *bl_packet_start; 1002 struct pip_bl_packet_start *bl_packet_start;
1032 struct gen5_bl_initiate_cmd_data *cmd_data; 1003 struct pip_bl_initiate_cmd_data *cmd_data;
1033 struct gen5_bl_packet_end *bl_packet_end; 1004 struct pip_bl_packet_end *bl_packet_end;
1034 u8 cmd[CYAPA_TSG_MAX_CMD_SIZE]; 1005 u8 cmd[CYAPA_TSG_MAX_CMD_SIZE];
1035 int cmd_len; 1006 int cmd_len;
1036 u16 cmd_data_len; 1007 u16 cmd_data_len;
@@ -1046,30 +1017,28 @@ static int cyapa_gen5_bl_initiate(struct cyapa *cyapa,
1046 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL); 1017 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
1047 1018
1048 memset(cmd, 0, CYAPA_TSG_MAX_CMD_SIZE); 1019 memset(cmd, 0, CYAPA_TSG_MAX_CMD_SIZE);
1049 bl_cmd_head = (struct gen5_bl_cmd_head *)cmd; 1020 bl_cmd_head = (struct pip_bl_cmd_head *)cmd;
1050 cmd_data_len = CYAPA_TSG_BL_KEY_SIZE + CYAPA_TSG_FLASH_MAP_BLOCK_SIZE; 1021 cmd_data_len = CYAPA_TSG_BL_KEY_SIZE + CYAPA_TSG_FLASH_MAP_BLOCK_SIZE;
1051 cmd_len = sizeof(struct gen5_bl_cmd_head) + cmd_data_len + 1022 cmd_len = sizeof(struct pip_bl_cmd_head) + cmd_data_len +
1052 sizeof(struct gen5_bl_packet_end); 1023 sizeof(struct pip_bl_packet_end);
1053 1024
1054 put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &bl_cmd_head->addr); 1025 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &bl_cmd_head->addr);
1055 put_unaligned_le16(cmd_len - 2, &bl_cmd_head->length); 1026 put_unaligned_le16(cmd_len - 2, &bl_cmd_head->length);
1056 bl_cmd_head->report_id = GEN5_BL_CMD_REPORT_ID; 1027 bl_cmd_head->report_id = PIP_BL_CMD_REPORT_ID;
1057 1028
1058 bl_packet_start = &bl_cmd_head->packet_start; 1029 bl_packet_start = &bl_cmd_head->packet_start;
1059 bl_packet_start->sop = GEN5_SOP_KEY; 1030 bl_packet_start->sop = PIP_SOP_KEY;
1060 bl_packet_start->cmd_code = GEN5_BL_CMD_INITIATE_BL; 1031 bl_packet_start->cmd_code = PIP_BL_CMD_INITIATE_BL;
1061 /* 8 key bytes and 128 bytes block size */ 1032 /* 8 key bytes and 128 bytes block size */
1062 put_unaligned_le16(cmd_data_len, &bl_packet_start->data_length); 1033 put_unaligned_le16(cmd_data_len, &bl_packet_start->data_length);
1063 1034
1064 cmd_data = (struct gen5_bl_initiate_cmd_data *)bl_cmd_head->data; 1035 cmd_data = (struct pip_bl_initiate_cmd_data *)bl_cmd_head->data;
1065 memcpy(cmd_data->key, cyapa_gen5_bl_cmd_key, CYAPA_TSG_BL_KEY_SIZE); 1036 memcpy(cmd_data->key, cyapa_pip_bl_cmd_key, CYAPA_TSG_BL_KEY_SIZE);
1037
1038 image_records = cyapa_get_image_record_data_num(fw, &records_num);
1066 1039
1067 /* Copy 60 bytes Meta Data Row Parameters */
1068 image = (struct cyapa_tsg_bin_image *)fw->data;
1069 records_num = (fw->size - sizeof(struct cyapa_tsg_bin_image_head)) /
1070 sizeof(struct cyapa_tsg_bin_image_data_record);
1071 /* APP_INTEGRITY row is always the last row block */ 1040 /* APP_INTEGRITY row is always the last row block */
1072 data = image->records[records_num - 1].record_data; 1041 data = image_records[records_num - 1].record_data;
1073 memcpy(cmd_data->metadata_raw_parameter, data, 1042 memcpy(cmd_data->metadata_raw_parameter, data,
1074 CYAPA_TSG_FLASH_MAP_METADATA_SIZE); 1043 CYAPA_TSG_FLASH_MAP_METADATA_SIZE);
1075 1044
@@ -1077,47 +1046,47 @@ static int cyapa_gen5_bl_initiate(struct cyapa *cyapa,
1077 CYAPA_TSG_FLASH_MAP_METADATA_SIZE); 1046 CYAPA_TSG_FLASH_MAP_METADATA_SIZE);
1078 put_unaligned_le16(meta_data_crc, &cmd_data->metadata_crc); 1047 put_unaligned_le16(meta_data_crc, &cmd_data->metadata_crc);
1079 1048
1080 bl_packet_end = (struct gen5_bl_packet_end *)(bl_cmd_head->data + 1049 bl_packet_end = (struct pip_bl_packet_end *)(bl_cmd_head->data +
1081 cmd_data_len); 1050 cmd_data_len);
1082 cmd_crc = crc_itu_t(0xffff, (u8 *)bl_packet_start, 1051 cmd_crc = crc_itu_t(0xffff, (u8 *)bl_packet_start,
1083 sizeof(struct gen5_bl_packet_start) + cmd_data_len); 1052 sizeof(struct pip_bl_packet_start) + cmd_data_len);
1084 put_unaligned_le16(cmd_crc, &bl_packet_end->crc); 1053 put_unaligned_le16(cmd_crc, &bl_packet_end->crc);
1085 bl_packet_end->eop = GEN5_EOP_KEY; 1054 bl_packet_end->eop = PIP_EOP_KEY;
1086 1055
1087 resp_len = sizeof(resp_data); 1056 resp_len = sizeof(resp_data);
1088 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 1057 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
1089 cmd, cmd_len, 1058 cmd, cmd_len,
1090 resp_data, &resp_len, 12000, 1059 resp_data, &resp_len, 12000,
1091 cyapa_gen5_sort_tsg_pip_bl_resp_data, true); 1060 cyapa_sort_tsg_pip_bl_resp_data, true);
1092 if (error || resp_len != GEN5_BL_INITIATE_RESP_LEN || 1061 if (error || resp_len != PIP_BL_INITIATE_RESP_LEN ||
1093 resp_data[2] != GEN5_BL_RESP_REPORT_ID || 1062 resp_data[2] != PIP_BL_RESP_REPORT_ID ||
1094 !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) 1063 !PIP_CMD_COMPLETE_SUCCESS(resp_data))
1095 return error ? error : -EAGAIN; 1064 return error ? error : -EAGAIN;
1096 1065
1097 return 0; 1066 return 0;
1098} 1067}
1099 1068
1100static bool cyapa_gen5_sort_bl_exit_data(struct cyapa *cyapa, u8 *buf, int len) 1069static bool cyapa_sort_pip_bl_exit_data(struct cyapa *cyapa, u8 *buf, int len)
1101{ 1070{
1102 if (buf == NULL || len < GEN5_RESP_LENGTH_SIZE) 1071 if (buf == NULL || len < PIP_RESP_LENGTH_SIZE)
1103 return false; 1072 return false;
1104 1073
1105 if (buf[0] == 0 && buf[1] == 0) 1074 if (buf[0] == 0 && buf[1] == 0)
1106 return true; 1075 return true;
1107 1076
1108 /* Exit bootloader failed for some reason. */ 1077 /* Exit bootloader failed for some reason. */
1109 if (len == GEN5_BL_FAIL_EXIT_RESP_LEN && 1078 if (len == PIP_BL_FAIL_EXIT_RESP_LEN &&
1110 buf[GEN5_RESP_REPORT_ID_OFFSET] == 1079 buf[PIP_RESP_REPORT_ID_OFFSET] ==
1111 GEN5_BL_RESP_REPORT_ID && 1080 PIP_BL_RESP_REPORT_ID &&
1112 buf[GEN5_RESP_RSVD_OFFSET] == GEN5_RESP_RSVD_KEY && 1081 buf[PIP_RESP_RSVD_OFFSET] == PIP_RESP_RSVD_KEY &&
1113 buf[GEN5_RESP_BL_SOP_OFFSET] == GEN5_SOP_KEY && 1082 buf[PIP_RESP_BL_SOP_OFFSET] == PIP_SOP_KEY &&
1114 buf[10] == GEN5_EOP_KEY) 1083 buf[10] == PIP_EOP_KEY)
1115 return true; 1084 return true;
1116 1085
1117 return false; 1086 return false;
1118} 1087}
1119 1088
1120static int cyapa_gen5_bl_exit(struct cyapa *cyapa) 1089int cyapa_pip_bl_exit(struct cyapa *cyapa)
1121{ 1090{
1122 1091
1123 u8 bl_gen5_bl_exit[] = { 0x04, 0x00, 1092 u8 bl_gen5_bl_exit[] = { 0x04, 0x00,
@@ -1132,13 +1101,13 @@ static int cyapa_gen5_bl_exit(struct cyapa *cyapa)
1132 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 1101 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
1133 bl_gen5_bl_exit, sizeof(bl_gen5_bl_exit), 1102 bl_gen5_bl_exit, sizeof(bl_gen5_bl_exit),
1134 resp_data, &resp_len, 1103 resp_data, &resp_len,
1135 5000, cyapa_gen5_sort_bl_exit_data, false); 1104 5000, cyapa_sort_pip_bl_exit_data, false);
1136 if (error) 1105 if (error)
1137 return error; 1106 return error;
1138 1107
1139 if (resp_len == GEN5_BL_FAIL_EXIT_RESP_LEN || 1108 if (resp_len == PIP_BL_FAIL_EXIT_RESP_LEN ||
1140 resp_data[GEN5_RESP_REPORT_ID_OFFSET] == 1109 resp_data[PIP_RESP_REPORT_ID_OFFSET] ==
1141 GEN5_BL_RESP_REPORT_ID) 1110 PIP_BL_RESP_REPORT_ID)
1142 return -EAGAIN; 1111 return -EAGAIN;
1143 1112
1144 if (resp_data[0] == 0x00 && resp_data[1] == 0x00) 1113 if (resp_data[0] == 0x00 && resp_data[1] == 0x00)
@@ -1147,7 +1116,7 @@ static int cyapa_gen5_bl_exit(struct cyapa *cyapa)
1147 return -ENODEV; 1116 return -ENODEV;
1148} 1117}
1149 1118
1150static int cyapa_gen5_bl_enter(struct cyapa *cyapa) 1119int cyapa_pip_bl_enter(struct cyapa *cyapa)
1151{ 1120{
1152 u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2F, 0x00, 0x01 }; 1121 u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2F, 0x00, 0x01 };
1153 u8 resp_data[2]; 1122 u8 resp_data[2];
@@ -1157,15 +1126,12 @@ static int cyapa_gen5_bl_enter(struct cyapa *cyapa)
1157 error = cyapa_poll_state(cyapa, 500); 1126 error = cyapa_poll_state(cyapa, 500);
1158 if (error < 0) 1127 if (error < 0)
1159 return error; 1128 return error;
1160 if (cyapa->gen != CYAPA_GEN5)
1161 return -EINVAL;
1162 1129
1163 /* Already in Gen5 BL. Skipping exit. */ 1130 /* Already in bootloader mode, Skipping exit. */
1164 if (cyapa->state == CYAPA_STATE_GEN5_BL) 1131 if (cyapa_is_pip_bl_mode(cyapa))
1165 return 0; 1132 return 0;
1166 1133 else if (!cyapa_is_pip_app_mode(cyapa))
1167 if (cyapa->state != CYAPA_STATE_GEN5_APP) 1134 return -EINVAL;
1168 return -EAGAIN;
1169 1135
1170 /* Try to dump all buffered report data before any send command. */ 1136 /* Try to dump all buffered report data before any send command. */
1171 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL); 1137 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
@@ -1179,39 +1145,79 @@ static int cyapa_gen5_bl_enter(struct cyapa *cyapa)
1179 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 1145 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
1180 cmd, sizeof(cmd), 1146 cmd, sizeof(cmd),
1181 resp_data, &resp_len, 1147 resp_data, &resp_len,
1182 5000, cyapa_gen5_sort_application_launch_data, 1148 5000, cyapa_sort_pip_application_launch_data,
1183 true); 1149 true);
1184 if (error || resp_data[0] != 0x00 || resp_data[1] != 0x00) 1150 if (error || resp_data[0] != 0x00 || resp_data[1] != 0x00)
1185 return error < 0 ? error : -EAGAIN; 1151 return error < 0 ? error : -EAGAIN;
1186 1152
1187 cyapa->operational = false; 1153 cyapa->operational = false;
1188 cyapa->state = CYAPA_STATE_GEN5_BL; 1154 if (cyapa->gen == CYAPA_GEN5)
1155 cyapa->state = CYAPA_STATE_GEN5_BL;
1156 else if (cyapa->gen == CYAPA_GEN6)
1157 cyapa->state = CYAPA_STATE_GEN6_BL;
1189 return 0; 1158 return 0;
1190} 1159}
1191 1160
1192static int cyapa_gen5_check_fw(struct cyapa *cyapa, const struct firmware *fw) 1161static int cyapa_pip_fw_head_check(struct cyapa *cyapa,
1162 struct cyapa_tsg_bin_image_head *image_head)
1163{
1164 if (image_head->head_size != 0x0C && image_head->head_size != 0x12)
1165 return -EINVAL;
1166
1167 switch (cyapa->gen) {
1168 case CYAPA_GEN6:
1169 if (image_head->family_id != 0x9B ||
1170 image_head->silicon_id_hi != 0x0B)
1171 return -EINVAL;
1172 break;
1173 case CYAPA_GEN5:
1174 /* Gen5 without proximity support. */
1175 if (cyapa->platform_ver < 2) {
1176 if (image_head->head_size == 0x0C)
1177 break;
1178 return -EINVAL;
1179 }
1180
1181 if (image_head->family_id != 0x91 ||
1182 image_head->silicon_id_hi != 0x02)
1183 return -EINVAL;
1184 break;
1185 default:
1186 return -EINVAL;
1187 }
1188
1189 return 0;
1190}
1191
1192int cyapa_pip_check_fw(struct cyapa *cyapa, const struct firmware *fw)
1193{ 1193{
1194 struct device *dev = &cyapa->client->dev; 1194 struct device *dev = &cyapa->client->dev;
1195 const struct cyapa_tsg_bin_image *image = (const void *)fw->data; 1195 struct cyapa_tsg_bin_image_data_record *image_records;
1196 const struct cyapa_tsg_bin_image_data_record *app_integrity; 1196 const struct cyapa_tsg_bin_image_data_record *app_integrity;
1197 const struct gen5_bl_metadata_row_params *metadata; 1197 const struct tsg_bl_metadata_row_params *metadata;
1198 size_t flash_records_count; 1198 int flash_records_count;
1199 u32 fw_app_start, fw_upgrade_start; 1199 u32 fw_app_start, fw_upgrade_start;
1200 u16 fw_app_len, fw_upgrade_len; 1200 u16 fw_app_len, fw_upgrade_len;
1201 u16 app_crc; 1201 u16 app_crc;
1202 u16 app_integrity_crc; 1202 u16 app_integrity_crc;
1203 int record_index;
1204 int i; 1203 int i;
1205 1204
1206 flash_records_count = (fw->size - 1205 /* Verify the firmware image not miss-used for Gen5 and Gen6. */
1207 sizeof(struct cyapa_tsg_bin_image_head)) / 1206 if (cyapa_pip_fw_head_check(cyapa,
1208 sizeof(struct cyapa_tsg_bin_image_data_record); 1207 (struct cyapa_tsg_bin_image_head *)fw->data)) {
1208 dev_err(dev, "%s: firmware image not match TP device.\n",
1209 __func__);
1210 return -EINVAL;
1211 }
1212
1213 image_records =
1214 cyapa_get_image_record_data_num(fw, &flash_records_count);
1209 1215
1210 /* 1216 /*
1211 * APP_INTEGRITY row is always the last row block, 1217 * APP_INTEGRITY row is always the last row block,
1212 * and the row id must be 0x01ff. 1218 * and the row id must be 0x01ff.
1213 */ 1219 */
1214 app_integrity = &image->records[flash_records_count - 1]; 1220 app_integrity = &image_records[flash_records_count - 1];
1215 1221
1216 if (app_integrity->flash_array_id != 0x00 || 1222 if (app_integrity->flash_array_id != 0x00 ||
1217 get_unaligned_be16(&app_integrity->row_number) != 0x01ff) { 1223 get_unaligned_be16(&app_integrity->row_number) != 0x01ff) {
@@ -1242,14 +1248,11 @@ static int cyapa_gen5_check_fw(struct cyapa *cyapa, const struct firmware *fw)
1242 return -EINVAL; 1248 return -EINVAL;
1243 } 1249 }
1244 1250
1245 /* 1251 /* Verify application image CRC. */
1246 * Verify application image CRC
1247 */
1248 record_index = fw_app_start / CYAPA_TSG_FW_ROW_SIZE -
1249 CYAPA_TSG_IMG_START_ROW_NUM;
1250 app_crc = 0xffffU; 1252 app_crc = 0xffffU;
1251 for (i = 0; i < fw_app_len / CYAPA_TSG_FW_ROW_SIZE; i++) { 1253 for (i = 0; i < fw_app_len / CYAPA_TSG_FW_ROW_SIZE; i++) {
1252 const u8 *data = image->records[record_index + i].record_data; 1254 const u8 *data = image_records[i].record_data;
1255
1253 app_crc = crc_itu_t(app_crc, data, CYAPA_TSG_FW_ROW_SIZE); 1256 app_crc = crc_itu_t(app_crc, data, CYAPA_TSG_FW_ROW_SIZE);
1254 } 1257 }
1255 1258
@@ -1261,13 +1264,13 @@ static int cyapa_gen5_check_fw(struct cyapa *cyapa, const struct firmware *fw)
1261 return 0; 1264 return 0;
1262} 1265}
1263 1266
1264static int cyapa_gen5_write_fw_block(struct cyapa *cyapa, 1267static int cyapa_pip_write_fw_block(struct cyapa *cyapa,
1265 struct cyapa_tsg_bin_image_data_record *flash_record) 1268 struct cyapa_tsg_bin_image_data_record *flash_record)
1266{ 1269{
1267 struct gen5_bl_cmd_head *bl_cmd_head; 1270 struct pip_bl_cmd_head *bl_cmd_head;
1268 struct gen5_bl_packet_start *bl_packet_start; 1271 struct pip_bl_packet_start *bl_packet_start;
1269 struct gen5_bl_flash_row_head *flash_row_head; 1272 struct tsg_bl_flash_row_head *flash_row_head;
1270 struct gen5_bl_packet_end *bl_packet_end; 1273 struct pip_bl_packet_end *bl_packet_end;
1271 u8 cmd[CYAPA_TSG_MAX_CMD_SIZE]; 1274 u8 cmd[CYAPA_TSG_MAX_CMD_SIZE];
1272 u16 cmd_len; 1275 u16 cmd_len;
1273 u8 flash_array_id; 1276 u8 flash_array_id;
@@ -1286,71 +1289,68 @@ static int cyapa_gen5_write_fw_block(struct cyapa *cyapa,
1286 record_data = flash_record->record_data; 1289 record_data = flash_record->record_data;
1287 1290
1288 memset(cmd, 0, CYAPA_TSG_MAX_CMD_SIZE); 1291 memset(cmd, 0, CYAPA_TSG_MAX_CMD_SIZE);
1289 bl_cmd_head = (struct gen5_bl_cmd_head *)cmd; 1292 bl_cmd_head = (struct pip_bl_cmd_head *)cmd;
1290 bl_packet_start = &bl_cmd_head->packet_start; 1293 bl_packet_start = &bl_cmd_head->packet_start;
1291 cmd_len = sizeof(struct gen5_bl_cmd_head) + 1294 cmd_len = sizeof(struct pip_bl_cmd_head) +
1292 sizeof(struct gen5_bl_flash_row_head) + 1295 sizeof(struct tsg_bl_flash_row_head) +
1293 CYAPA_TSG_FLASH_MAP_BLOCK_SIZE + 1296 CYAPA_TSG_FLASH_MAP_BLOCK_SIZE +
1294 sizeof(struct gen5_bl_packet_end); 1297 sizeof(struct pip_bl_packet_end);
1295 1298
1296 put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &bl_cmd_head->addr); 1299 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &bl_cmd_head->addr);
1297 /* Don't include 2 bytes register address */ 1300 /* Don't include 2 bytes register address */
1298 put_unaligned_le16(cmd_len - 2, &bl_cmd_head->length); 1301 put_unaligned_le16(cmd_len - 2, &bl_cmd_head->length);
1299 bl_cmd_head->report_id = GEN5_BL_CMD_REPORT_ID; 1302 bl_cmd_head->report_id = PIP_BL_CMD_REPORT_ID;
1300 bl_packet_start->sop = GEN5_SOP_KEY; 1303 bl_packet_start->sop = PIP_SOP_KEY;
1301 bl_packet_start->cmd_code = GEN5_BL_CMD_PROGRAM_VERIFY_ROW; 1304 bl_packet_start->cmd_code = PIP_BL_CMD_PROGRAM_VERIFY_ROW;
1302 1305
1303 /* 1 (Flash Array ID) + 2 (Flash Row ID) + 128 (flash data) */ 1306 /* 1 (Flash Array ID) + 2 (Flash Row ID) + 128 (flash data) */
1304 data_len = sizeof(struct gen5_bl_flash_row_head) + record_len; 1307 data_len = sizeof(struct tsg_bl_flash_row_head) + record_len;
1305 put_unaligned_le16(data_len, &bl_packet_start->data_length); 1308 put_unaligned_le16(data_len, &bl_packet_start->data_length);
1306 1309
1307 flash_row_head = (struct gen5_bl_flash_row_head *)bl_cmd_head->data; 1310 flash_row_head = (struct tsg_bl_flash_row_head *)bl_cmd_head->data;
1308 flash_row_head->flash_array_id = flash_array_id; 1311 flash_row_head->flash_array_id = flash_array_id;
1309 put_unaligned_le16(flash_row_id, &flash_row_head->flash_row_id); 1312 put_unaligned_le16(flash_row_id, &flash_row_head->flash_row_id);
1310 memcpy(flash_row_head->flash_data, record_data, record_len); 1313 memcpy(flash_row_head->flash_data, record_data, record_len);
1311 1314
1312 bl_packet_end = (struct gen5_bl_packet_end *)(bl_cmd_head->data + 1315 bl_packet_end = (struct pip_bl_packet_end *)(bl_cmd_head->data +
1313 data_len); 1316 data_len);
1314 crc = crc_itu_t(0xffff, (u8 *)bl_packet_start, 1317 crc = crc_itu_t(0xffff, (u8 *)bl_packet_start,
1315 sizeof(struct gen5_bl_packet_start) + data_len); 1318 sizeof(struct pip_bl_packet_start) + data_len);
1316 put_unaligned_le16(crc, &bl_packet_end->crc); 1319 put_unaligned_le16(crc, &bl_packet_end->crc);
1317 bl_packet_end->eop = GEN5_EOP_KEY; 1320 bl_packet_end->eop = PIP_EOP_KEY;
1318 1321
1319 resp_len = sizeof(resp_data); 1322 resp_len = sizeof(resp_data);
1320 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len, 1323 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len,
1321 resp_data, &resp_len, 1324 resp_data, &resp_len,
1322 500, cyapa_gen5_sort_tsg_pip_bl_resp_data, true); 1325 500, cyapa_sort_tsg_pip_bl_resp_data, true);
1323 if (error || resp_len != GEN5_BL_BLOCK_WRITE_RESP_LEN || 1326 if (error || resp_len != PIP_BL_BLOCK_WRITE_RESP_LEN ||
1324 resp_data[2] != GEN5_BL_RESP_REPORT_ID || 1327 resp_data[2] != PIP_BL_RESP_REPORT_ID ||
1325 !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) 1328 !PIP_CMD_COMPLETE_SUCCESS(resp_data))
1326 return error < 0 ? error : -EAGAIN; 1329 return error < 0 ? error : -EAGAIN;
1327 1330
1328 return 0; 1331 return 0;
1329} 1332}
1330 1333
1331static int cyapa_gen5_do_fw_update(struct cyapa *cyapa, 1334int cyapa_pip_do_fw_update(struct cyapa *cyapa,
1332 const struct firmware *fw) 1335 const struct firmware *fw)
1333{ 1336{
1334 struct device *dev = &cyapa->client->dev; 1337 struct device *dev = &cyapa->client->dev;
1335 struct cyapa_tsg_bin_image_data_record *flash_record; 1338 struct cyapa_tsg_bin_image_data_record *image_records;
1336 struct cyapa_tsg_bin_image *image =
1337 (struct cyapa_tsg_bin_image *)fw->data;
1338 int flash_records_count; 1339 int flash_records_count;
1339 int i; 1340 int i;
1340 int error; 1341 int error;
1341 1342
1342 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL); 1343 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
1343 1344
1344 flash_records_count = 1345 image_records =
1345 (fw->size - sizeof(struct cyapa_tsg_bin_image_head)) / 1346 cyapa_get_image_record_data_num(fw, &flash_records_count);
1346 sizeof(struct cyapa_tsg_bin_image_data_record); 1347
1347 /* 1348 /*
1348 * The last flash row 0x01ff has been written through bl_initiate 1349 * The last flash row 0x01ff has been written through bl_initiate
1349 * command, so DO NOT write flash 0x01ff to trackpad device. 1350 * command, so DO NOT write flash 0x01ff to trackpad device.
1350 */ 1351 */
1351 for (i = 0; i < (flash_records_count - 1); i++) { 1352 for (i = 0; i < (flash_records_count - 1); i++) {
1352 flash_record = &image->records[i]; 1353 error = cyapa_pip_write_fw_block(cyapa, &image_records[i]);
1353 error = cyapa_gen5_write_fw_block(cyapa, flash_record);
1354 if (error) { 1354 if (error) {
1355 dev_err(dev, "%s: Gen5 FW update aborted: %d\n", 1355 dev_err(dev, "%s: Gen5 FW update aborted: %d\n",
1356 __func__, error); 1356 __func__, error);
@@ -1372,9 +1372,9 @@ static int cyapa_gen5_change_power_state(struct cyapa *cyapa, u8 power_state)
1372 resp_len = sizeof(resp_data); 1372 resp_len = sizeof(resp_data);
1373 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd), 1373 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
1374 resp_data, &resp_len, 1374 resp_data, &resp_len,
1375 500, cyapa_gen5_sort_tsg_pip_app_resp_data, false); 1375 500, cyapa_sort_tsg_pip_app_resp_data, false);
1376 if (error || !VALID_CMD_RESP_HEADER(resp_data, 0x08) || 1376 if (error || !VALID_CMD_RESP_HEADER(resp_data, 0x08) ||
1377 !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) 1377 !PIP_CMD_COMPLETE_SUCCESS(resp_data))
1378 return error < 0 ? error : -EINVAL; 1378 return error < 0 ? error : -EINVAL;
1379 1379
1380 return 0; 1380 return 0;
@@ -1383,7 +1383,7 @@ static int cyapa_gen5_change_power_state(struct cyapa *cyapa, u8 power_state)
1383static int cyapa_gen5_set_interval_time(struct cyapa *cyapa, 1383static int cyapa_gen5_set_interval_time(struct cyapa *cyapa,
1384 u8 parameter_id, u16 interval_time) 1384 u8 parameter_id, u16 interval_time)
1385{ 1385{
1386 struct gen5_app_cmd_head *app_cmd_head; 1386 struct pip_app_cmd_head *app_cmd_head;
1387 struct gen5_app_set_parameter_data *parameter_data; 1387 struct gen5_app_set_parameter_data *parameter_data;
1388 u8 cmd[CYAPA_TSG_MAX_CMD_SIZE]; 1388 u8 cmd[CYAPA_TSG_MAX_CMD_SIZE];
1389 int cmd_len; 1389 int cmd_len;
@@ -1393,10 +1393,10 @@ static int cyapa_gen5_set_interval_time(struct cyapa *cyapa,
1393 int error; 1393 int error;
1394 1394
1395 memset(cmd, 0, CYAPA_TSG_MAX_CMD_SIZE); 1395 memset(cmd, 0, CYAPA_TSG_MAX_CMD_SIZE);
1396 app_cmd_head = (struct gen5_app_cmd_head *)cmd; 1396 app_cmd_head = (struct pip_app_cmd_head *)cmd;
1397 parameter_data = (struct gen5_app_set_parameter_data *) 1397 parameter_data = (struct gen5_app_set_parameter_data *)
1398 app_cmd_head->parameter_data; 1398 app_cmd_head->parameter_data;
1399 cmd_len = sizeof(struct gen5_app_cmd_head) + 1399 cmd_len = sizeof(struct pip_app_cmd_head) +
1400 sizeof(struct gen5_app_set_parameter_data); 1400 sizeof(struct gen5_app_set_parameter_data);
1401 1401
1402 switch (parameter_id) { 1402 switch (parameter_id) {
@@ -1413,14 +1413,14 @@ static int cyapa_gen5_set_interval_time(struct cyapa *cyapa,
1413 return -EINVAL; 1413 return -EINVAL;
1414 } 1414 }
1415 1415
1416 put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &app_cmd_head->addr); 1416 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &app_cmd_head->addr);
1417 /* 1417 /*
1418 * Don't include unused parameter value bytes and 1418 * Don't include unused parameter value bytes and
1419 * 2 bytes register address. 1419 * 2 bytes register address.
1420 */ 1420 */
1421 put_unaligned_le16(cmd_len - (4 - parameter_size) - 2, 1421 put_unaligned_le16(cmd_len - (4 - parameter_size) - 2,
1422 &app_cmd_head->length); 1422 &app_cmd_head->length);
1423 app_cmd_head->report_id = GEN5_APP_CMD_REPORT_ID; 1423 app_cmd_head->report_id = PIP_APP_CMD_REPORT_ID;
1424 app_cmd_head->cmd_code = GEN5_CMD_SET_PARAMETER; 1424 app_cmd_head->cmd_code = GEN5_CMD_SET_PARAMETER;
1425 parameter_data->parameter_id = parameter_id; 1425 parameter_data->parameter_id = parameter_id;
1426 parameter_data->parameter_size = parameter_size; 1426 parameter_data->parameter_size = parameter_size;
@@ -1428,7 +1428,7 @@ static int cyapa_gen5_set_interval_time(struct cyapa *cyapa,
1428 resp_len = sizeof(resp_data); 1428 resp_len = sizeof(resp_data);
1429 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len, 1429 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len,
1430 resp_data, &resp_len, 1430 resp_data, &resp_len,
1431 500, cyapa_gen5_sort_tsg_pip_app_resp_data, false); 1431 500, cyapa_sort_tsg_pip_app_resp_data, false);
1432 if (error || resp_data[5] != parameter_id || 1432 if (error || resp_data[5] != parameter_id ||
1433 resp_data[6] != parameter_size || 1433 resp_data[6] != parameter_size ||
1434 !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_SET_PARAMETER)) 1434 !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_SET_PARAMETER))
@@ -1440,7 +1440,7 @@ static int cyapa_gen5_set_interval_time(struct cyapa *cyapa,
1440static int cyapa_gen5_get_interval_time(struct cyapa *cyapa, 1440static int cyapa_gen5_get_interval_time(struct cyapa *cyapa,
1441 u8 parameter_id, u16 *interval_time) 1441 u8 parameter_id, u16 *interval_time)
1442{ 1442{
1443 struct gen5_app_cmd_head *app_cmd_head; 1443 struct pip_app_cmd_head *app_cmd_head;
1444 struct gen5_app_get_parameter_data *parameter_data; 1444 struct gen5_app_get_parameter_data *parameter_data;
1445 u8 cmd[CYAPA_TSG_MAX_CMD_SIZE]; 1445 u8 cmd[CYAPA_TSG_MAX_CMD_SIZE];
1446 int cmd_len; 1446 int cmd_len;
@@ -1451,10 +1451,10 @@ static int cyapa_gen5_get_interval_time(struct cyapa *cyapa,
1451 int error; 1451 int error;
1452 1452
1453 memset(cmd, 0, CYAPA_TSG_MAX_CMD_SIZE); 1453 memset(cmd, 0, CYAPA_TSG_MAX_CMD_SIZE);
1454 app_cmd_head = (struct gen5_app_cmd_head *)cmd; 1454 app_cmd_head = (struct pip_app_cmd_head *)cmd;
1455 parameter_data = (struct gen5_app_get_parameter_data *) 1455 parameter_data = (struct gen5_app_get_parameter_data *)
1456 app_cmd_head->parameter_data; 1456 app_cmd_head->parameter_data;
1457 cmd_len = sizeof(struct gen5_app_cmd_head) + 1457 cmd_len = sizeof(struct pip_app_cmd_head) +
1458 sizeof(struct gen5_app_get_parameter_data); 1458 sizeof(struct gen5_app_get_parameter_data);
1459 1459
1460 *interval_time = 0; 1460 *interval_time = 0;
@@ -1472,17 +1472,17 @@ static int cyapa_gen5_get_interval_time(struct cyapa *cyapa,
1472 return -EINVAL; 1472 return -EINVAL;
1473 } 1473 }
1474 1474
1475 put_unaligned_le16(GEN5_HID_DESCRIPTOR_ADDR, &app_cmd_head->addr); 1475 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &app_cmd_head->addr);
1476 /* Don't include 2 bytes register address */ 1476 /* Don't include 2 bytes register address */
1477 put_unaligned_le16(cmd_len - 2, &app_cmd_head->length); 1477 put_unaligned_le16(cmd_len - 2, &app_cmd_head->length);
1478 app_cmd_head->report_id = GEN5_APP_CMD_REPORT_ID; 1478 app_cmd_head->report_id = PIP_APP_CMD_REPORT_ID;
1479 app_cmd_head->cmd_code = GEN5_CMD_GET_PARAMETER; 1479 app_cmd_head->cmd_code = GEN5_CMD_GET_PARAMETER;
1480 parameter_data->parameter_id = parameter_id; 1480 parameter_data->parameter_id = parameter_id;
1481 1481
1482 resp_len = sizeof(resp_data); 1482 resp_len = sizeof(resp_data);
1483 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len, 1483 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, cmd_len,
1484 resp_data, &resp_len, 1484 resp_data, &resp_len,
1485 500, cyapa_gen5_sort_tsg_pip_app_resp_data, false); 1485 500, cyapa_sort_tsg_pip_app_resp_data, false);
1486 if (error || resp_data[5] != parameter_id || resp_data[6] == 0 || 1486 if (error || resp_data[5] != parameter_id || resp_data[6] == 0 ||
1487 !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_GET_PARAMETER)) 1487 !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_GET_PARAMETER))
1488 return error < 0 ? error : -EINVAL; 1488 return error < 0 ? error : -EINVAL;
@@ -1497,18 +1497,18 @@ static int cyapa_gen5_get_interval_time(struct cyapa *cyapa,
1497 1497
1498static int cyapa_gen5_disable_pip_report(struct cyapa *cyapa) 1498static int cyapa_gen5_disable_pip_report(struct cyapa *cyapa)
1499{ 1499{
1500 struct gen5_app_cmd_head *app_cmd_head; 1500 struct pip_app_cmd_head *app_cmd_head;
1501 u8 cmd[10]; 1501 u8 cmd[10];
1502 u8 resp_data[7]; 1502 u8 resp_data[7];
1503 int resp_len; 1503 int resp_len;
1504 int error; 1504 int error;
1505 1505
1506 memset(cmd, 0, sizeof(cmd)); 1506 memset(cmd, 0, sizeof(cmd));
1507 app_cmd_head = (struct gen5_app_cmd_head *)cmd; 1507 app_cmd_head = (struct pip_app_cmd_head *)cmd;
1508 1508
1509 put_unaligned_le16(GEN5_HID_DESCRIPTOR_ADDR, &app_cmd_head->addr); 1509 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &app_cmd_head->addr);
1510 put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length); 1510 put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length);
1511 app_cmd_head->report_id = GEN5_APP_CMD_REPORT_ID; 1511 app_cmd_head->report_id = PIP_APP_CMD_REPORT_ID;
1512 app_cmd_head->cmd_code = GEN5_CMD_SET_PARAMETER; 1512 app_cmd_head->cmd_code = GEN5_CMD_SET_PARAMETER;
1513 app_cmd_head->parameter_data[0] = GEN5_PARAMETER_DISABLE_PIP_REPORT; 1513 app_cmd_head->parameter_data[0] = GEN5_PARAMETER_DISABLE_PIP_REPORT;
1514 app_cmd_head->parameter_data[1] = 0x01; 1514 app_cmd_head->parameter_data[1] = 0x01;
@@ -1516,7 +1516,7 @@ static int cyapa_gen5_disable_pip_report(struct cyapa *cyapa)
1516 resp_len = sizeof(resp_data); 1516 resp_len = sizeof(resp_data);
1517 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd), 1517 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
1518 resp_data, &resp_len, 1518 resp_data, &resp_len,
1519 500, cyapa_gen5_sort_tsg_pip_app_resp_data, false); 1519 500, cyapa_sort_tsg_pip_app_resp_data, false);
1520 if (error || resp_data[5] != GEN5_PARAMETER_DISABLE_PIP_REPORT || 1520 if (error || resp_data[5] != GEN5_PARAMETER_DISABLE_PIP_REPORT ||
1521 !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_SET_PARAMETER) || 1521 !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_SET_PARAMETER) ||
1522 resp_data[6] != 0x01) 1522 resp_data[6] != 0x01)
@@ -1525,26 +1525,48 @@ static int cyapa_gen5_disable_pip_report(struct cyapa *cyapa)
1525 return 0; 1525 return 0;
1526} 1526}
1527 1527
1528static int cyapa_gen5_deep_sleep(struct cyapa *cyapa, u8 state) 1528int cyapa_pip_set_proximity(struct cyapa *cyapa, bool enable)
1529{
1530 u8 cmd[] = { 0x04, 0x00, 0x06, 0x00, 0x2f, 0x00, PIP_SET_PROXIMITY,
1531 (u8)!!enable
1532 };
1533 u8 resp_data[6];
1534 int resp_len;
1535 int error;
1536
1537 resp_len = sizeof(resp_data);
1538 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
1539 resp_data, &resp_len,
1540 500, cyapa_sort_tsg_pip_app_resp_data, false);
1541 if (error || !VALID_CMD_RESP_HEADER(resp_data, PIP_SET_PROXIMITY) ||
1542 !PIP_CMD_COMPLETE_SUCCESS(resp_data)) {
1543 error = (error == -ETIMEDOUT) ? -EOPNOTSUPP : error;
1544 return error < 0 ? error : -EINVAL;
1545 }
1546
1547 return 0;
1548}
1549
1550int cyapa_pip_deep_sleep(struct cyapa *cyapa, u8 state)
1529{ 1551{
1530 u8 cmd[] = { 0x05, 0x00, 0x00, 0x08}; 1552 u8 cmd[] = { 0x05, 0x00, 0x00, 0x08};
1531 u8 resp_data[5]; 1553 u8 resp_data[5];
1532 int resp_len; 1554 int resp_len;
1533 int error; 1555 int error;
1534 1556
1535 cmd[2] = state & GEN5_DEEP_SLEEP_STATE_MASK; 1557 cmd[2] = state & PIP_DEEP_SLEEP_STATE_MASK;
1536 resp_len = sizeof(resp_data); 1558 resp_len = sizeof(resp_data);
1537 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd), 1559 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
1538 resp_data, &resp_len, 1560 resp_data, &resp_len,
1539 500, cyapa_gen5_sort_deep_sleep_data, false); 1561 500, cyapa_sort_pip_deep_sleep_data, false);
1540 if (error || ((resp_data[3] & GEN5_DEEP_SLEEP_STATE_MASK) != state)) 1562 if (error || ((resp_data[3] & PIP_DEEP_SLEEP_STATE_MASK) != state))
1541 return -EINVAL; 1563 return -EINVAL;
1542 1564
1543 return 0; 1565 return 0;
1544} 1566}
1545 1567
1546static int cyapa_gen5_set_power_mode(struct cyapa *cyapa, 1568static int cyapa_gen5_set_power_mode(struct cyapa *cyapa,
1547 u8 power_mode, u16 sleep_time) 1569 u8 power_mode, u16 sleep_time, bool is_suspend)
1548{ 1570{
1549 struct device *dev = &cyapa->client->dev; 1571 struct device *dev = &cyapa->client->dev;
1550 u8 power_state; 1572 u8 power_state;
@@ -1553,43 +1575,40 @@ static int cyapa_gen5_set_power_mode(struct cyapa *cyapa,
1553 if (cyapa->state != CYAPA_STATE_GEN5_APP) 1575 if (cyapa->state != CYAPA_STATE_GEN5_APP)
1554 return 0; 1576 return 0;
1555 1577
1556 /* Dump all the report data before do power mode commmands. */ 1578 if (PIP_DEV_GET_PWR_STATE(cyapa) == UNINIT_PWR_MODE) {
1557 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
1558
1559 if (GEN5_DEV_GET_PWR_STATE(cyapa) == UNINIT_PWR_MODE) {
1560 /* 1579 /*
1561 * Assume TP in deep sleep mode when driver is loaded, 1580 * Assume TP in deep sleep mode when driver is loaded,
1562 * avoid driver unload and reload command IO issue caused by TP 1581 * avoid driver unload and reload command IO issue caused by TP
1563 * has been set into deep sleep mode when unloading. 1582 * has been set into deep sleep mode when unloading.
1564 */ 1583 */
1565 GEN5_DEV_SET_PWR_STATE(cyapa, PWR_MODE_OFF); 1584 PIP_DEV_SET_PWR_STATE(cyapa, PWR_MODE_OFF);
1566 } 1585 }
1567 1586
1568 if (GEN5_DEV_UNINIT_SLEEP_TIME(cyapa) && 1587 if (PIP_DEV_UNINIT_SLEEP_TIME(cyapa) &&
1569 GEN5_DEV_GET_PWR_STATE(cyapa) != PWR_MODE_OFF) 1588 PIP_DEV_GET_PWR_STATE(cyapa) != PWR_MODE_OFF)
1570 if (cyapa_gen5_get_interval_time(cyapa, 1589 if (cyapa_gen5_get_interval_time(cyapa,
1571 GEN5_PARAMETER_LP_INTRVL_ID, 1590 GEN5_PARAMETER_LP_INTRVL_ID,
1572 &cyapa->dev_sleep_time) != 0) 1591 &cyapa->dev_sleep_time) != 0)
1573 GEN5_DEV_SET_SLEEP_TIME(cyapa, UNINIT_SLEEP_TIME); 1592 PIP_DEV_SET_SLEEP_TIME(cyapa, UNINIT_SLEEP_TIME);
1574 1593
1575 if (GEN5_DEV_GET_PWR_STATE(cyapa) == power_mode) { 1594 if (PIP_DEV_GET_PWR_STATE(cyapa) == power_mode) {
1576 if (power_mode == PWR_MODE_OFF || 1595 if (power_mode == PWR_MODE_OFF ||
1577 power_mode == PWR_MODE_FULL_ACTIVE || 1596 power_mode == PWR_MODE_FULL_ACTIVE ||
1578 power_mode == PWR_MODE_BTN_ONLY || 1597 power_mode == PWR_MODE_BTN_ONLY ||
1579 GEN5_DEV_GET_SLEEP_TIME(cyapa) == sleep_time) { 1598 PIP_DEV_GET_SLEEP_TIME(cyapa) == sleep_time) {
1580 /* Has in correct power mode state, early return. */ 1599 /* Has in correct power mode state, early return. */
1581 return 0; 1600 return 0;
1582 } 1601 }
1583 } 1602 }
1584 1603
1585 if (power_mode == PWR_MODE_OFF) { 1604 if (power_mode == PWR_MODE_OFF) {
1586 error = cyapa_gen5_deep_sleep(cyapa, GEN5_DEEP_SLEEP_STATE_OFF); 1605 error = cyapa_pip_deep_sleep(cyapa, PIP_DEEP_SLEEP_STATE_OFF);
1587 if (error) { 1606 if (error) {
1588 dev_err(dev, "enter deep sleep fail: %d\n", error); 1607 dev_err(dev, "enter deep sleep fail: %d\n", error);
1589 return error; 1608 return error;
1590 } 1609 }
1591 1610
1592 GEN5_DEV_SET_PWR_STATE(cyapa, PWR_MODE_OFF); 1611 PIP_DEV_SET_PWR_STATE(cyapa, PWR_MODE_OFF);
1593 return 0; 1612 return 0;
1594 } 1613 }
1595 1614
@@ -1598,8 +1617,8 @@ static int cyapa_gen5_set_power_mode(struct cyapa *cyapa,
1598 * state directly, must be wake up from sleep firstly, then 1617 * state directly, must be wake up from sleep firstly, then
1599 * continue to do next power sate change. 1618 * continue to do next power sate change.
1600 */ 1619 */
1601 if (GEN5_DEV_GET_PWR_STATE(cyapa) == PWR_MODE_OFF) { 1620 if (PIP_DEV_GET_PWR_STATE(cyapa) == PWR_MODE_OFF) {
1602 error = cyapa_gen5_deep_sleep(cyapa, GEN5_DEEP_SLEEP_STATE_ON); 1621 error = cyapa_pip_deep_sleep(cyapa, PIP_DEEP_SLEEP_STATE_ON);
1603 if (error) { 1622 if (error) {
1604 dev_err(dev, "deep sleep wake fail: %d\n", error); 1623 dev_err(dev, "deep sleep wake fail: %d\n", error);
1605 return error; 1624 return error;
@@ -1614,7 +1633,7 @@ static int cyapa_gen5_set_power_mode(struct cyapa *cyapa,
1614 return error; 1633 return error;
1615 } 1634 }
1616 1635
1617 GEN5_DEV_SET_PWR_STATE(cyapa, PWR_MODE_FULL_ACTIVE); 1636 PIP_DEV_SET_PWR_STATE(cyapa, PWR_MODE_FULL_ACTIVE);
1618 } else if (power_mode == PWR_MODE_BTN_ONLY) { 1637 } else if (power_mode == PWR_MODE_BTN_ONLY) {
1619 error = cyapa_gen5_change_power_state(cyapa, 1638 error = cyapa_gen5_change_power_state(cyapa,
1620 GEN5_POWER_STATE_BTN_ONLY); 1639 GEN5_POWER_STATE_BTN_ONLY);
@@ -1623,19 +1642,19 @@ static int cyapa_gen5_set_power_mode(struct cyapa *cyapa,
1623 return error; 1642 return error;
1624 } 1643 }
1625 1644
1626 GEN5_DEV_SET_PWR_STATE(cyapa, PWR_MODE_BTN_ONLY); 1645 PIP_DEV_SET_PWR_STATE(cyapa, PWR_MODE_BTN_ONLY);
1627 } else { 1646 } else {
1628 /* 1647 /*
1629 * Continue to change power mode even failed to set 1648 * Continue to change power mode even failed to set
1630 * interval time, it won't affect the power mode change. 1649 * interval time, it won't affect the power mode change.
1631 * except the sleep interval time is not correct. 1650 * except the sleep interval time is not correct.
1632 */ 1651 */
1633 if (GEN5_DEV_UNINIT_SLEEP_TIME(cyapa) || 1652 if (PIP_DEV_UNINIT_SLEEP_TIME(cyapa) ||
1634 sleep_time != GEN5_DEV_GET_SLEEP_TIME(cyapa)) 1653 sleep_time != PIP_DEV_GET_SLEEP_TIME(cyapa))
1635 if (cyapa_gen5_set_interval_time(cyapa, 1654 if (cyapa_gen5_set_interval_time(cyapa,
1636 GEN5_PARAMETER_LP_INTRVL_ID, 1655 GEN5_PARAMETER_LP_INTRVL_ID,
1637 sleep_time) == 0) 1656 sleep_time) == 0)
1638 GEN5_DEV_SET_SLEEP_TIME(cyapa, sleep_time); 1657 PIP_DEV_SET_SLEEP_TIME(cyapa, sleep_time);
1639 1658
1640 if (sleep_time <= GEN5_POWER_READY_MAX_INTRVL_TIME) 1659 if (sleep_time <= GEN5_POWER_READY_MAX_INTRVL_TIME)
1641 power_state = GEN5_POWER_STATE_READY; 1660 power_state = GEN5_POWER_STATE_READY;
@@ -1658,17 +1677,17 @@ static int cyapa_gen5_set_power_mode(struct cyapa *cyapa,
1658 * is suspending which may cause interrupt line unable to be 1677 * is suspending which may cause interrupt line unable to be
1659 * asserted again. 1678 * asserted again.
1660 */ 1679 */
1661 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL); 1680 if (is_suspend)
1662 cyapa_gen5_disable_pip_report(cyapa); 1681 cyapa_gen5_disable_pip_report(cyapa);
1663 1682
1664 GEN5_DEV_SET_PWR_STATE(cyapa, 1683 PIP_DEV_SET_PWR_STATE(cyapa,
1665 cyapa_sleep_time_to_pwr_cmd(sleep_time)); 1684 cyapa_sleep_time_to_pwr_cmd(sleep_time));
1666 } 1685 }
1667 1686
1668 return 0; 1687 return 0;
1669} 1688}
1670 1689
1671static int cyapa_gen5_resume_scanning(struct cyapa *cyapa) 1690int cyapa_pip_resume_scanning(struct cyapa *cyapa)
1672{ 1691{
1673 u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x04 }; 1692 u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x04 };
1674 u8 resp_data[6]; 1693 u8 resp_data[6];
@@ -1682,7 +1701,7 @@ static int cyapa_gen5_resume_scanning(struct cyapa *cyapa)
1682 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 1701 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
1683 cmd, sizeof(cmd), 1702 cmd, sizeof(cmd),
1684 resp_data, &resp_len, 1703 resp_data, &resp_len,
1685 500, cyapa_gen5_sort_tsg_pip_app_resp_data, true); 1704 500, cyapa_sort_tsg_pip_app_resp_data, true);
1686 if (error || !VALID_CMD_RESP_HEADER(resp_data, 0x04)) 1705 if (error || !VALID_CMD_RESP_HEADER(resp_data, 0x04))
1687 return -EINVAL; 1706 return -EINVAL;
1688 1707
@@ -1692,7 +1711,7 @@ static int cyapa_gen5_resume_scanning(struct cyapa *cyapa)
1692 return 0; 1711 return 0;
1693} 1712}
1694 1713
1695static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa) 1714int cyapa_pip_suspend_scanning(struct cyapa *cyapa)
1696{ 1715{
1697 u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x03 }; 1716 u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x03 };
1698 u8 resp_data[6]; 1717 u8 resp_data[6];
@@ -1706,7 +1725,7 @@ static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa)
1706 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 1725 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
1707 cmd, sizeof(cmd), 1726 cmd, sizeof(cmd),
1708 resp_data, &resp_len, 1727 resp_data, &resp_len,
1709 500, cyapa_gen5_sort_tsg_pip_app_resp_data, true); 1728 500, cyapa_sort_tsg_pip_app_resp_data, true);
1710 if (error || !VALID_CMD_RESP_HEADER(resp_data, 0x03)) 1729 if (error || !VALID_CMD_RESP_HEADER(resp_data, 0x03))
1711 return -EINVAL; 1730 return -EINVAL;
1712 1731
@@ -1716,10 +1735,10 @@ static int cyapa_gen5_suspend_scanning(struct cyapa *cyapa)
1716 return 0; 1735 return 0;
1717} 1736}
1718 1737
1719static int cyapa_gen5_calibrate_pwcs(struct cyapa *cyapa, 1738static int cyapa_pip_calibrate_pwcs(struct cyapa *cyapa,
1720 u8 calibrate_sensing_mode_type) 1739 u8 calibrate_sensing_mode_type)
1721{ 1740{
1722 struct gen5_app_cmd_head *app_cmd_head; 1741 struct pip_app_cmd_head *app_cmd_head;
1723 u8 cmd[8]; 1742 u8 cmd[8];
1724 u8 resp_data[6]; 1743 u8 resp_data[6];
1725 int resp_len; 1744 int resp_len;
@@ -1729,25 +1748,25 @@ static int cyapa_gen5_calibrate_pwcs(struct cyapa *cyapa,
1729 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL); 1748 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
1730 1749
1731 memset(cmd, 0, sizeof(cmd)); 1750 memset(cmd, 0, sizeof(cmd));
1732 app_cmd_head = (struct gen5_app_cmd_head *)cmd; 1751 app_cmd_head = (struct pip_app_cmd_head *)cmd;
1733 put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &app_cmd_head->addr); 1752 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &app_cmd_head->addr);
1734 put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length); 1753 put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length);
1735 app_cmd_head->report_id = GEN5_APP_CMD_REPORT_ID; 1754 app_cmd_head->report_id = PIP_APP_CMD_REPORT_ID;
1736 app_cmd_head->cmd_code = GEN5_CMD_CALIBRATE; 1755 app_cmd_head->cmd_code = PIP_CMD_CALIBRATE;
1737 app_cmd_head->parameter_data[0] = calibrate_sensing_mode_type; 1756 app_cmd_head->parameter_data[0] = calibrate_sensing_mode_type;
1738 resp_len = sizeof(resp_data); 1757 resp_len = sizeof(resp_data);
1739 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 1758 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
1740 cmd, sizeof(cmd), 1759 cmd, sizeof(cmd),
1741 resp_data, &resp_len, 1760 resp_data, &resp_len,
1742 5000, cyapa_gen5_sort_tsg_pip_app_resp_data, true); 1761 5000, cyapa_sort_tsg_pip_app_resp_data, true);
1743 if (error || !VALID_CMD_RESP_HEADER(resp_data, GEN5_CMD_CALIBRATE) || 1762 if (error || !VALID_CMD_RESP_HEADER(resp_data, PIP_CMD_CALIBRATE) ||
1744 !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) 1763 !PIP_CMD_COMPLETE_SUCCESS(resp_data))
1745 return error < 0 ? error : -EAGAIN; 1764 return error < 0 ? error : -EAGAIN;
1746 1765
1747 return 0; 1766 return 0;
1748} 1767}
1749 1768
1750static ssize_t cyapa_gen5_do_calibrate(struct device *dev, 1769ssize_t cyapa_pip_do_calibrate(struct device *dev,
1751 struct device_attribute *attr, 1770 struct device_attribute *attr,
1752 const char *buf, size_t count) 1771 const char *buf, size_t count)
1753{ 1772{
@@ -1755,25 +1774,25 @@ static ssize_t cyapa_gen5_do_calibrate(struct device *dev,
1755 int error, calibrate_error; 1774 int error, calibrate_error;
1756 1775
1757 /* 1. Suspend Scanning*/ 1776 /* 1. Suspend Scanning*/
1758 error = cyapa_gen5_suspend_scanning(cyapa); 1777 error = cyapa_pip_suspend_scanning(cyapa);
1759 if (error) 1778 if (error)
1760 return error; 1779 return error;
1761 1780
1762 /* 2. Do mutual capacitance fine calibrate. */ 1781 /* 2. Do mutual capacitance fine calibrate. */
1763 calibrate_error = cyapa_gen5_calibrate_pwcs(cyapa, 1782 calibrate_error = cyapa_pip_calibrate_pwcs(cyapa,
1764 CYAPA_SENSING_MODE_MUTUAL_CAP_FINE); 1783 PIP_SENSING_MODE_MUTUAL_CAP_FINE);
1765 if (calibrate_error) 1784 if (calibrate_error)
1766 goto resume_scanning; 1785 goto resume_scanning;
1767 1786
1768 /* 3. Do self capacitance calibrate. */ 1787 /* 3. Do self capacitance calibrate. */
1769 calibrate_error = cyapa_gen5_calibrate_pwcs(cyapa, 1788 calibrate_error = cyapa_pip_calibrate_pwcs(cyapa,
1770 CYAPA_SENSING_MODE_SELF_CAP); 1789 PIP_SENSING_MODE_SELF_CAP);
1771 if (calibrate_error) 1790 if (calibrate_error)
1772 goto resume_scanning; 1791 goto resume_scanning;
1773 1792
1774resume_scanning: 1793resume_scanning:
1775 /* 4. Resume Scanning*/ 1794 /* 4. Resume Scanning*/
1776 error = cyapa_gen5_resume_scanning(cyapa); 1795 error = cyapa_pip_resume_scanning(cyapa);
1777 if (error || calibrate_error) 1796 if (error || calibrate_error)
1778 return error ? error : calibrate_error; 1797 return error ? error : calibrate_error;
1779 1798
@@ -1856,7 +1875,7 @@ static void cyapa_gen5_guess_electrodes(struct cyapa *cyapa,
1856 * If the input value of @data_size is not 0, than means read the mutual or 1875 * If the input value of @data_size is not 0, than means read the mutual or
1857 * self local PWC data. The @idac_max, @idac_min and @idac_ave are used to 1876 * self local PWC data. The @idac_max, @idac_min and @idac_ave are used to
1858 * return the max, min and average value of the mutual or self local PWC data. 1877 * return the max, min and average value of the mutual or self local PWC data.
1859 * Note, in order to raed mutual local PWC data, must read invoke this function 1878 * Note, in order to read mutual local PWC data, must read invoke this function
1860 * to read the mutual global idac data firstly to set the correct Rx number 1879 * to read the mutual global idac data firstly to set the correct Rx number
1861 * value, otherwise, the read mutual idac and PWC data may not correct. 1880 * value, otherwise, the read mutual idac and PWC data may not correct.
1862 */ 1881 */
@@ -1864,7 +1883,7 @@ static int cyapa_gen5_read_idac_data(struct cyapa *cyapa,
1864 u8 cmd_code, u8 idac_data_type, int *data_size, 1883 u8 cmd_code, u8 idac_data_type, int *data_size,
1865 int *idac_max, int *idac_min, int *idac_ave) 1884 int *idac_max, int *idac_min, int *idac_ave)
1866{ 1885{
1867 struct gen5_app_cmd_head *cmd_head; 1886 struct pip_app_cmd_head *cmd_head;
1868 u8 cmd[12]; 1887 u8 cmd[12];
1869 u8 resp_data[256]; 1888 u8 resp_data[256];
1870 int resp_len; 1889 int resp_len;
@@ -1879,7 +1898,7 @@ static int cyapa_gen5_read_idac_data(struct cyapa *cyapa,
1879 int i; 1898 int i;
1880 int error; 1899 int error;
1881 1900
1882 if (cmd_code != GEN5_CMD_RETRIEVE_DATA_STRUCTURE || 1901 if (cmd_code != PIP_RETRIEVE_DATA_STRUCTURE ||
1883 (idac_data_type != GEN5_RETRIEVE_MUTUAL_PWC_DATA && 1902 (idac_data_type != GEN5_RETRIEVE_MUTUAL_PWC_DATA &&
1884 idac_data_type != GEN5_RETRIEVE_SELF_CAP_PWC_DATA) || 1903 idac_data_type != GEN5_RETRIEVE_SELF_CAP_PWC_DATA) ||
1885 !data_size || !idac_max || !idac_min || !idac_ave) 1904 !data_size || !idac_max || !idac_min || !idac_ave)
@@ -1935,10 +1954,10 @@ static int cyapa_gen5_read_idac_data(struct cyapa *cyapa,
1935 } 1954 }
1936 1955
1937 memset(cmd, 0, sizeof(cmd)); 1956 memset(cmd, 0, sizeof(cmd));
1938 cmd_head = (struct gen5_app_cmd_head *)cmd; 1957 cmd_head = (struct pip_app_cmd_head *)cmd;
1939 put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &cmd_head->addr); 1958 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &cmd_head->addr);
1940 put_unaligned_le16(sizeof(cmd) - 2, &cmd_head->length); 1959 put_unaligned_le16(sizeof(cmd) - 2, &cmd_head->length);
1941 cmd_head->report_id = GEN5_APP_CMD_REPORT_ID; 1960 cmd_head->report_id = PIP_APP_CMD_REPORT_ID;
1942 cmd_head->cmd_code = cmd_code; 1961 cmd_head->cmd_code = cmd_code;
1943 do { 1962 do {
1944 read_elements = (256 - GEN5_RESP_DATA_STRUCTURE_OFFSET) / 1963 read_elements = (256 - GEN5_RESP_DATA_STRUCTURE_OFFSET) /
@@ -1953,11 +1972,11 @@ static int cyapa_gen5_read_idac_data(struct cyapa *cyapa,
1953 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 1972 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
1954 cmd, sizeof(cmd), 1973 cmd, sizeof(cmd),
1955 resp_data, &resp_len, 1974 resp_data, &resp_len,
1956 500, cyapa_gen5_sort_tsg_pip_app_resp_data, 1975 500, cyapa_sort_tsg_pip_app_resp_data,
1957 true); 1976 true);
1958 if (error || resp_len < GEN5_RESP_DATA_STRUCTURE_OFFSET || 1977 if (error || resp_len < GEN5_RESP_DATA_STRUCTURE_OFFSET ||
1959 !VALID_CMD_RESP_HEADER(resp_data, cmd_code) || 1978 !VALID_CMD_RESP_HEADER(resp_data, cmd_code) ||
1960 !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]) || 1979 !PIP_CMD_COMPLETE_SUCCESS(resp_data) ||
1961 resp_data[6] != idac_data_type) 1980 resp_data[6] != idac_data_type)
1962 return (error < 0) ? error : -EAGAIN; 1981 return (error < 0) ? error : -EAGAIN;
1963 read_len = get_unaligned_le16(&resp_data[7]); 1982 read_len = get_unaligned_le16(&resp_data[7]);
@@ -1997,7 +2016,7 @@ static int cyapa_gen5_read_idac_data(struct cyapa *cyapa,
1997 tmp_count < cyapa->aligned_electrodes_rx && 2016 tmp_count < cyapa->aligned_electrodes_rx &&
1998 read_global_idac) { 2017 read_global_idac) {
1999 /* 2018 /*
2000 * The value gap betwen global and local mutual 2019 * The value gap between global and local mutual
2001 * idac data must bigger than 50%. 2020 * idac data must bigger than 50%.
2002 * Normally, global value bigger than 50, 2021 * Normally, global value bigger than 50,
2003 * local values less than 10. 2022 * local values less than 10.
@@ -2061,7 +2080,7 @@ static int cyapa_gen5_read_mutual_idac_data(struct cyapa *cyapa,
2061 2080
2062 data_size = 0; 2081 data_size = 0;
2063 error = cyapa_gen5_read_idac_data(cyapa, 2082 error = cyapa_gen5_read_idac_data(cyapa,
2064 GEN5_CMD_RETRIEVE_DATA_STRUCTURE, 2083 PIP_RETRIEVE_DATA_STRUCTURE,
2065 GEN5_RETRIEVE_MUTUAL_PWC_DATA, 2084 GEN5_RETRIEVE_MUTUAL_PWC_DATA,
2066 &data_size, 2085 &data_size,
2067 gidac_mutual_max, gidac_mutual_min, gidac_mutual_ave); 2086 gidac_mutual_max, gidac_mutual_min, gidac_mutual_ave);
@@ -2069,7 +2088,7 @@ static int cyapa_gen5_read_mutual_idac_data(struct cyapa *cyapa,
2069 return error; 2088 return error;
2070 2089
2071 error = cyapa_gen5_read_idac_data(cyapa, 2090 error = cyapa_gen5_read_idac_data(cyapa,
2072 GEN5_CMD_RETRIEVE_DATA_STRUCTURE, 2091 PIP_RETRIEVE_DATA_STRUCTURE,
2073 GEN5_RETRIEVE_MUTUAL_PWC_DATA, 2092 GEN5_RETRIEVE_MUTUAL_PWC_DATA,
2074 &data_size, 2093 &data_size,
2075 lidac_mutual_max, lidac_mutual_min, lidac_mutual_ave); 2094 lidac_mutual_max, lidac_mutual_min, lidac_mutual_ave);
@@ -2088,7 +2107,7 @@ static int cyapa_gen5_read_self_idac_data(struct cyapa *cyapa,
2088 2107
2089 data_size = 0; 2108 data_size = 0;
2090 error = cyapa_gen5_read_idac_data(cyapa, 2109 error = cyapa_gen5_read_idac_data(cyapa,
2091 GEN5_CMD_RETRIEVE_DATA_STRUCTURE, 2110 PIP_RETRIEVE_DATA_STRUCTURE,
2092 GEN5_RETRIEVE_SELF_CAP_PWC_DATA, 2111 GEN5_RETRIEVE_SELF_CAP_PWC_DATA,
2093 &data_size, 2112 &data_size,
2094 lidac_self_max, lidac_self_min, lidac_self_ave); 2113 lidac_self_max, lidac_self_min, lidac_self_ave);
@@ -2098,7 +2117,7 @@ static int cyapa_gen5_read_self_idac_data(struct cyapa *cyapa,
2098 *gidac_self_tx = *lidac_self_min; 2117 *gidac_self_tx = *lidac_self_min;
2099 2118
2100 error = cyapa_gen5_read_idac_data(cyapa, 2119 error = cyapa_gen5_read_idac_data(cyapa,
2101 GEN5_CMD_RETRIEVE_DATA_STRUCTURE, 2120 PIP_RETRIEVE_DATA_STRUCTURE,
2102 GEN5_RETRIEVE_SELF_CAP_PWC_DATA, 2121 GEN5_RETRIEVE_SELF_CAP_PWC_DATA,
2103 &data_size, 2122 &data_size,
2104 lidac_self_max, lidac_self_min, lidac_self_ave); 2123 lidac_self_max, lidac_self_min, lidac_self_ave);
@@ -2107,27 +2126,27 @@ static int cyapa_gen5_read_self_idac_data(struct cyapa *cyapa,
2107 2126
2108static ssize_t cyapa_gen5_execute_panel_scan(struct cyapa *cyapa) 2127static ssize_t cyapa_gen5_execute_panel_scan(struct cyapa *cyapa)
2109{ 2128{
2110 struct gen5_app_cmd_head *app_cmd_head; 2129 struct pip_app_cmd_head *app_cmd_head;
2111 u8 cmd[7]; 2130 u8 cmd[7];
2112 u8 resp_data[6]; 2131 u8 resp_data[6];
2113 int resp_len; 2132 int resp_len;
2114 int error; 2133 int error;
2115 2134
2116 memset(cmd, 0, sizeof(cmd)); 2135 memset(cmd, 0, sizeof(cmd));
2117 app_cmd_head = (struct gen5_app_cmd_head *)cmd; 2136 app_cmd_head = (struct pip_app_cmd_head *)cmd;
2118 put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &app_cmd_head->addr); 2137 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &app_cmd_head->addr);
2119 put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length); 2138 put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length);
2120 app_cmd_head->report_id = GEN5_APP_CMD_REPORT_ID; 2139 app_cmd_head->report_id = PIP_APP_CMD_REPORT_ID;
2121 app_cmd_head->cmd_code = GEN5_CMD_EXECUTE_PANEL_SCAN; 2140 app_cmd_head->cmd_code = GEN5_CMD_EXECUTE_PANEL_SCAN;
2122 resp_len = sizeof(resp_data); 2141 resp_len = sizeof(resp_data);
2123 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 2142 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
2124 cmd, sizeof(cmd), 2143 cmd, sizeof(cmd),
2125 resp_data, &resp_len, 2144 resp_data, &resp_len,
2126 500, cyapa_gen5_sort_tsg_pip_app_resp_data, true); 2145 500, cyapa_sort_tsg_pip_app_resp_data, true);
2127 if (error || resp_len != sizeof(resp_data) || 2146 if (error || resp_len != sizeof(resp_data) ||
2128 !VALID_CMD_RESP_HEADER(resp_data, 2147 !VALID_CMD_RESP_HEADER(resp_data,
2129 GEN5_CMD_EXECUTE_PANEL_SCAN) || 2148 GEN5_CMD_EXECUTE_PANEL_SCAN) ||
2130 !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) 2149 !PIP_CMD_COMPLETE_SUCCESS(resp_data))
2131 return error ? error : -EAGAIN; 2150 return error ? error : -EAGAIN;
2132 2151
2133 return 0; 2152 return 0;
@@ -2138,7 +2157,7 @@ static int cyapa_gen5_read_panel_scan_raw_data(struct cyapa *cyapa,
2138 int *raw_data_max, int *raw_data_min, int *raw_data_ave, 2157 int *raw_data_max, int *raw_data_min, int *raw_data_ave,
2139 u8 *buffer) 2158 u8 *buffer)
2140{ 2159{
2141 struct gen5_app_cmd_head *app_cmd_head; 2160 struct pip_app_cmd_head *app_cmd_head;
2142 struct gen5_retrieve_panel_scan_data *panel_sacn_data; 2161 struct gen5_retrieve_panel_scan_data *panel_sacn_data;
2143 u8 cmd[12]; 2162 u8 cmd[12];
2144 u8 resp_data[256]; /* Max bytes can transfer one time. */ 2163 u8 resp_data[256]; /* Max bytes can transfer one time. */
@@ -2166,10 +2185,10 @@ static int cyapa_gen5_read_panel_scan_raw_data(struct cyapa *cyapa,
2166 /* Assume max element size is 4 currently. */ 2185 /* Assume max element size is 4 currently. */
2167 read_elements = (256 - GEN5_RESP_DATA_STRUCTURE_OFFSET) / 4; 2186 read_elements = (256 - GEN5_RESP_DATA_STRUCTURE_OFFSET) / 4;
2168 read_len = read_elements * 4; 2187 read_len = read_elements * 4;
2169 app_cmd_head = (struct gen5_app_cmd_head *)cmd; 2188 app_cmd_head = (struct pip_app_cmd_head *)cmd;
2170 put_unaligned_le16(GEN5_OUTPUT_REPORT_ADDR, &app_cmd_head->addr); 2189 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &app_cmd_head->addr);
2171 put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length); 2190 put_unaligned_le16(sizeof(cmd) - 2, &app_cmd_head->length);
2172 app_cmd_head->report_id = GEN5_APP_CMD_REPORT_ID; 2191 app_cmd_head->report_id = PIP_APP_CMD_REPORT_ID;
2173 app_cmd_head->cmd_code = cmd_code; 2192 app_cmd_head->cmd_code = cmd_code;
2174 panel_sacn_data = (struct gen5_retrieve_panel_scan_data *) 2193 panel_sacn_data = (struct gen5_retrieve_panel_scan_data *)
2175 app_cmd_head->parameter_data; 2194 app_cmd_head->parameter_data;
@@ -2183,10 +2202,10 @@ static int cyapa_gen5_read_panel_scan_raw_data(struct cyapa *cyapa,
2183 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 2202 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
2184 cmd, sizeof(cmd), 2203 cmd, sizeof(cmd),
2185 resp_data, &resp_len, 2204 resp_data, &resp_len,
2186 500, cyapa_gen5_sort_tsg_pip_app_resp_data, true); 2205 500, cyapa_sort_tsg_pip_app_resp_data, true);
2187 if (error || resp_len < GEN5_RESP_DATA_STRUCTURE_OFFSET || 2206 if (error || resp_len < GEN5_RESP_DATA_STRUCTURE_OFFSET ||
2188 !VALID_CMD_RESP_HEADER(resp_data, cmd_code) || 2207 !VALID_CMD_RESP_HEADER(resp_data, cmd_code) ||
2189 !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5]) || 2208 !PIP_CMD_COMPLETE_SUCCESS(resp_data) ||
2190 resp_data[6] != raw_data_type) 2209 resp_data[6] != raw_data_type)
2191 return error ? error : -EAGAIN; 2210 return error ? error : -EAGAIN;
2192 2211
@@ -2245,11 +2264,11 @@ static ssize_t cyapa_gen5_show_baseline(struct device *dev,
2245 int error, resume_error; 2264 int error, resume_error;
2246 int size; 2265 int size;
2247 2266
2248 if (cyapa->state != CYAPA_STATE_GEN5_APP) 2267 if (!cyapa_is_pip_app_mode(cyapa))
2249 return -EBUSY; 2268 return -EBUSY;
2250 2269
2251 /* 1. Suspend Scanning*/ 2270 /* 1. Suspend Scanning*/
2252 error = cyapa_gen5_suspend_scanning(cyapa); 2271 error = cyapa_pip_suspend_scanning(cyapa);
2253 if (error) 2272 if (error)
2254 return error; 2273 return error;
2255 2274
@@ -2270,7 +2289,7 @@ static ssize_t cyapa_gen5_show_baseline(struct device *dev,
2270 if (error) 2289 if (error)
2271 goto resume_scanning; 2290 goto resume_scanning;
2272 2291
2273 /* 4. Execuate panel scan. It must be executed before read data. */ 2292 /* 4. Execute panel scan. It must be executed before read data. */
2274 error = cyapa_gen5_execute_panel_scan(cyapa); 2293 error = cyapa_gen5_execute_panel_scan(cyapa);
2275 if (error) 2294 if (error)
2276 goto resume_scanning; 2295 goto resume_scanning;
@@ -2343,7 +2362,7 @@ static ssize_t cyapa_gen5_show_baseline(struct device *dev,
2343 2362
2344resume_scanning: 2363resume_scanning:
2345 /* 11. Resume Scanning*/ 2364 /* 11. Resume Scanning*/
2346 resume_error = cyapa_gen5_resume_scanning(cyapa); 2365 resume_error = cyapa_pip_resume_scanning(cyapa);
2347 if (resume_error || error) 2366 if (resume_error || error)
2348 return resume_error ? resume_error : error; 2367 return resume_error ? resume_error : error;
2349 2368
@@ -2364,7 +2383,7 @@ resume_scanning:
2364 return size; 2383 return size;
2365} 2384}
2366 2385
2367static bool cyapa_gen5_sort_system_info_data(struct cyapa *cyapa, 2386bool cyapa_pip_sort_system_info_data(struct cyapa *cyapa,
2368 u8 *buf, int len) 2387 u8 *buf, int len)
2369{ 2388{
2370 /* Check the report id and command code */ 2389 /* Check the report id and command code */
@@ -2376,20 +2395,17 @@ static bool cyapa_gen5_sort_system_info_data(struct cyapa *cyapa,
2376 2395
2377static int cyapa_gen5_bl_query_data(struct cyapa *cyapa) 2396static int cyapa_gen5_bl_query_data(struct cyapa *cyapa)
2378{ 2397{
2379 u8 bl_query_data_cmd[] = { 0x04, 0x00, 0x0b, 0x00, 0x40, 0x00, 2398 u8 resp_data[PIP_BL_APP_INFO_RESP_LENGTH];
2380 0x01, 0x3c, 0x00, 0x00, 0xb0, 0x42, 0x17
2381 };
2382 u8 resp_data[GEN5_BL_READ_APP_INFO_RESP_LEN];
2383 int resp_len; 2399 int resp_len;
2384 int error; 2400 int error;
2385 2401
2386 resp_len = GEN5_BL_READ_APP_INFO_RESP_LEN; 2402 resp_len = sizeof(resp_data);
2387 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 2403 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
2388 bl_query_data_cmd, sizeof(bl_query_data_cmd), 2404 pip_bl_read_app_info, PIP_BL_READ_APP_INFO_CMD_LENGTH,
2389 resp_data, &resp_len, 2405 resp_data, &resp_len,
2390 500, cyapa_gen5_sort_tsg_pip_bl_resp_data, false); 2406 500, cyapa_sort_tsg_pip_bl_resp_data, false);
2391 if (error || resp_len != GEN5_BL_READ_APP_INFO_RESP_LEN || 2407 if (error || resp_len < PIP_BL_APP_INFO_RESP_LENGTH ||
2392 !GEN5_CMD_COMPLETE_SUCCESS(resp_data[5])) 2408 !PIP_CMD_COMPLETE_SUCCESS(resp_data))
2393 return error ? error : -EIO; 2409 return error ? error : -EIO;
2394 2410
2395 memcpy(&cyapa->product_id[0], &resp_data[8], 5); 2411 memcpy(&cyapa->product_id[0], &resp_data[8], 5);
@@ -2402,34 +2418,42 @@ static int cyapa_gen5_bl_query_data(struct cyapa *cyapa)
2402 cyapa->fw_maj_ver = resp_data[22]; 2418 cyapa->fw_maj_ver = resp_data[22];
2403 cyapa->fw_min_ver = resp_data[23]; 2419 cyapa->fw_min_ver = resp_data[23];
2404 2420
2421 cyapa->platform_ver = (resp_data[26] >> PIP_BL_PLATFORM_VER_SHIFT) &
2422 PIP_BL_PLATFORM_VER_MASK;
2423
2405 return 0; 2424 return 0;
2406} 2425}
2407 2426
2408static int cyapa_gen5_get_query_data(struct cyapa *cyapa) 2427static int cyapa_gen5_get_query_data(struct cyapa *cyapa)
2409{ 2428{
2410 u8 get_system_information[] = { 2429 u8 resp_data[PIP_READ_SYS_INFO_RESP_LENGTH];
2411 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x02
2412 };
2413 u8 resp_data[71];
2414 int resp_len; 2430 int resp_len;
2415 u16 product_family; 2431 u16 product_family;
2416 int error; 2432 int error;
2417 2433
2418 resp_len = sizeof(resp_data); 2434 resp_len = sizeof(resp_data);
2419 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, 2435 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
2420 get_system_information, sizeof(get_system_information), 2436 pip_read_sys_info, PIP_READ_SYS_INFO_CMD_LENGTH,
2421 resp_data, &resp_len, 2437 resp_data, &resp_len,
2422 2000, cyapa_gen5_sort_system_info_data, false); 2438 2000, cyapa_pip_sort_system_info_data, false);
2423 if (error || resp_len < sizeof(resp_data)) 2439 if (error || resp_len < sizeof(resp_data))
2424 return error ? error : -EIO; 2440 return error ? error : -EIO;
2425 2441
2426 product_family = get_unaligned_le16(&resp_data[7]); 2442 product_family = get_unaligned_le16(&resp_data[7]);
2427 if ((product_family & GEN5_PRODUCT_FAMILY_MASK) != 2443 if ((product_family & PIP_PRODUCT_FAMILY_MASK) !=
2428 GEN5_PRODUCT_FAMILY_TRACKPAD) 2444 PIP_PRODUCT_FAMILY_TRACKPAD)
2429 return -EINVAL; 2445 return -EINVAL;
2430 2446
2431 cyapa->fw_maj_ver = resp_data[15]; 2447 cyapa->platform_ver = (resp_data[49] >> PIP_BL_PLATFORM_VER_SHIFT) &
2432 cyapa->fw_min_ver = resp_data[16]; 2448 PIP_BL_PLATFORM_VER_MASK;
2449 if (cyapa->gen == CYAPA_GEN5 && cyapa->platform_ver < 2) {
2450 /* Gen5 firmware that does not support proximity. */
2451 cyapa->fw_maj_ver = resp_data[15];
2452 cyapa->fw_min_ver = resp_data[16];
2453 } else {
2454 cyapa->fw_maj_ver = resp_data[9];
2455 cyapa->fw_min_ver = resp_data[10];
2456 }
2433 2457
2434 cyapa->electrodes_x = resp_data[52]; 2458 cyapa->electrodes_x = resp_data[52];
2435 cyapa->electrodes_y = resp_data[53]; 2459 cyapa->electrodes_y = resp_data[53];
@@ -2472,9 +2496,9 @@ static int cyapa_gen5_do_operational_check(struct cyapa *cyapa)
2472 2496
2473 switch (cyapa->state) { 2497 switch (cyapa->state) {
2474 case CYAPA_STATE_GEN5_BL: 2498 case CYAPA_STATE_GEN5_BL:
2475 error = cyapa_gen5_bl_exit(cyapa); 2499 error = cyapa_pip_bl_exit(cyapa);
2476 if (error) { 2500 if (error) {
2477 /* Rry to update trackpad product information. */ 2501 /* Try to update trackpad product information. */
2478 cyapa_gen5_bl_query_data(cyapa); 2502 cyapa_gen5_bl_query_data(cyapa);
2479 goto out; 2503 goto out;
2480 } 2504 }
@@ -2486,14 +2510,23 @@ static int cyapa_gen5_do_operational_check(struct cyapa *cyapa)
2486 * If trackpad device in deep sleep mode, 2510 * If trackpad device in deep sleep mode,
2487 * the app command will fail. 2511 * the app command will fail.
2488 * So always try to reset trackpad device to full active when 2512 * So always try to reset trackpad device to full active when
2489 * the device state is requeried. 2513 * the device state is required.
2490 */ 2514 */
2491 error = cyapa_gen5_set_power_mode(cyapa, 2515 error = cyapa_gen5_set_power_mode(cyapa,
2492 PWR_MODE_FULL_ACTIVE, 0); 2516 PWR_MODE_FULL_ACTIVE, 0, false);
2493 if (error) 2517 if (error)
2494 dev_warn(dev, "%s: failed to set power active mode.\n", 2518 dev_warn(dev, "%s: failed to set power active mode.\n",
2495 __func__); 2519 __func__);
2496 2520
2521 /* By default, the trackpad proximity function is enabled. */
2522 if (cyapa->platform_ver >= 2) {
2523 error = cyapa_pip_set_proximity(cyapa, true);
2524 if (error)
2525 dev_warn(dev,
2526 "%s: failed to enable proximity.\n",
2527 __func__);
2528 }
2529
2497 /* Get trackpad product information. */ 2530 /* Get trackpad product information. */
2498 error = cyapa_gen5_get_query_data(cyapa); 2531 error = cyapa_gen5_get_query_data(cyapa);
2499 if (error) 2532 if (error)
@@ -2518,14 +2551,14 @@ out:
2518 * Return false, do not continue process 2551 * Return false, do not continue process
2519 * Return true, continue process. 2552 * Return true, continue process.
2520 */ 2553 */
2521static bool cyapa_gen5_irq_cmd_handler(struct cyapa *cyapa) 2554bool cyapa_pip_irq_cmd_handler(struct cyapa *cyapa)
2522{ 2555{
2523 struct cyapa_gen5_cmd_states *gen5_pip = &cyapa->cmd_states.gen5; 2556 struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
2524 int length; 2557 int length;
2525 2558
2526 if (atomic_read(&gen5_pip->cmd_issued)) { 2559 if (atomic_read(&pip->cmd_issued)) {
2527 /* Polling command response data. */ 2560 /* Polling command response data. */
2528 if (gen5_pip->is_irq_mode == false) 2561 if (pip->is_irq_mode == false)
2529 return false; 2562 return false;
2530 2563
2531 /* 2564 /*
@@ -2533,59 +2566,64 @@ static bool cyapa_gen5_irq_cmd_handler(struct cyapa *cyapa)
2533 * these output data may caused by user put finger on 2566 * these output data may caused by user put finger on
2534 * trackpad when host waiting the command response. 2567 * trackpad when host waiting the command response.
2535 */ 2568 */
2536 cyapa_i2c_pip_read(cyapa, gen5_pip->irq_cmd_buf, 2569 cyapa_i2c_pip_read(cyapa, pip->irq_cmd_buf,
2537 GEN5_RESP_LENGTH_SIZE); 2570 PIP_RESP_LENGTH_SIZE);
2538 length = get_unaligned_le16(gen5_pip->irq_cmd_buf); 2571 length = get_unaligned_le16(pip->irq_cmd_buf);
2539 length = (length <= GEN5_RESP_LENGTH_SIZE) ? 2572 length = (length <= PIP_RESP_LENGTH_SIZE) ?
2540 GEN5_RESP_LENGTH_SIZE : length; 2573 PIP_RESP_LENGTH_SIZE : length;
2541 if (length > GEN5_RESP_LENGTH_SIZE) 2574 if (length > PIP_RESP_LENGTH_SIZE)
2542 cyapa_i2c_pip_read(cyapa, 2575 cyapa_i2c_pip_read(cyapa,
2543 gen5_pip->irq_cmd_buf, length); 2576 pip->irq_cmd_buf, length);
2544 2577 if (!(pip->resp_sort_func &&
2545 if (!(gen5_pip->resp_sort_func && 2578 pip->resp_sort_func(cyapa,
2546 gen5_pip->resp_sort_func(cyapa, 2579 pip->irq_cmd_buf, length))) {
2547 gen5_pip->irq_cmd_buf, length))) {
2548 /* 2580 /*
2549 * Work around the Gen5 V1 firmware 2581 * Cover the Gen5 V1 firmware issue.
2550 * that does not assert interrupt signalling 2582 * The issue is no interrupt would be asserted from
2551 * that command response is ready if user 2583 * trackpad device to host for the command response
2552 * keeps touching the trackpad while command 2584 * ready event. Because when there was a finger touch
2553 * is sent to the device. 2585 * on trackpad device, and the firmware output queue
2586 * won't be empty (always with touch report data), so
2587 * the interrupt signal won't be asserted again until
2588 * the output queue was previous emptied.
2589 * This issue would happen in the scenario that
2590 * user always has his/her fingers touched on the
2591 * trackpad device during system booting/rebooting.
2554 */ 2592 */
2555 length = 0; 2593 length = 0;
2556 if (gen5_pip->resp_len) 2594 if (pip->resp_len)
2557 length = *gen5_pip->resp_len; 2595 length = *pip->resp_len;
2558 cyapa_empty_pip_output_data(cyapa, 2596 cyapa_empty_pip_output_data(cyapa,
2559 gen5_pip->resp_data, 2597 pip->resp_data,
2560 &length, 2598 &length,
2561 gen5_pip->resp_sort_func); 2599 pip->resp_sort_func);
2562 if (gen5_pip->resp_len && length != 0) { 2600 if (pip->resp_len && length != 0) {
2563 *gen5_pip->resp_len = length; 2601 *pip->resp_len = length;
2564 atomic_dec(&gen5_pip->cmd_issued); 2602 atomic_dec(&pip->cmd_issued);
2565 complete(&gen5_pip->cmd_ready); 2603 complete(&pip->cmd_ready);
2566 } 2604 }
2567 return false; 2605 return false;
2568 } 2606 }
2569 2607
2570 if (gen5_pip->resp_data && gen5_pip->resp_len) { 2608 if (pip->resp_data && pip->resp_len) {
2571 *gen5_pip->resp_len = (*gen5_pip->resp_len < length) ? 2609 *pip->resp_len = (*pip->resp_len < length) ?
2572 *gen5_pip->resp_len : length; 2610 *pip->resp_len : length;
2573 memcpy(gen5_pip->resp_data, gen5_pip->irq_cmd_buf, 2611 memcpy(pip->resp_data, pip->irq_cmd_buf,
2574 *gen5_pip->resp_len); 2612 *pip->resp_len);
2575 } 2613 }
2576 atomic_dec(&gen5_pip->cmd_issued); 2614 atomic_dec(&pip->cmd_issued);
2577 complete(&gen5_pip->cmd_ready); 2615 complete(&pip->cmd_ready);
2578 return false; 2616 return false;
2579 } 2617 }
2580 2618
2581 return true; 2619 return true;
2582} 2620}
2583 2621
2584static void cyapa_gen5_report_buttons(struct cyapa *cyapa, 2622static void cyapa_pip_report_buttons(struct cyapa *cyapa,
2585 const struct cyapa_gen5_report_data *report_data) 2623 const struct cyapa_pip_report_data *report_data)
2586{ 2624{
2587 struct input_dev *input = cyapa->input; 2625 struct input_dev *input = cyapa->input;
2588 u8 buttons = report_data->report_head[GEN5_BUTTONS_OFFSET]; 2626 u8 buttons = report_data->report_head[PIP_BUTTONS_OFFSET];
2589 2627
2590 buttons = (buttons << CAPABILITY_BTN_SHIFT) & CAPABILITY_BTN_MASK; 2628 buttons = (buttons << CAPABILITY_BTN_SHIFT) & CAPABILITY_BTN_MASK;
2591 2629
@@ -2605,12 +2643,23 @@ static void cyapa_gen5_report_buttons(struct cyapa *cyapa,
2605 input_sync(input); 2643 input_sync(input);
2606} 2644}
2607 2645
2608static void cyapa_gen5_report_slot_data(struct cyapa *cyapa, 2646static void cyapa_pip_report_proximity(struct cyapa *cyapa,
2609 const struct cyapa_gen5_touch_record *touch) 2647 const struct cyapa_pip_report_data *report_data)
2610{ 2648{
2611 struct input_dev *input = cyapa->input; 2649 struct input_dev *input = cyapa->input;
2612 u8 event_id = GEN5_GET_EVENT_ID(touch->touch_tip_event_id); 2650 u8 distance = report_data->report_head[PIP_PROXIMITY_DISTANCE_OFFSET] &
2613 int slot = GEN5_GET_TOUCH_ID(touch->touch_tip_event_id); 2651 PIP_PROXIMITY_DISTANCE_MASK;
2652
2653 input_report_abs(input, ABS_DISTANCE, distance);
2654 input_sync(input);
2655}
2656
2657static void cyapa_pip_report_slot_data(struct cyapa *cyapa,
2658 const struct cyapa_pip_touch_record *touch)
2659{
2660 struct input_dev *input = cyapa->input;
2661 u8 event_id = PIP_GET_EVENT_ID(touch->touch_tip_event_id);
2662 int slot = PIP_GET_TOUCH_ID(touch->touch_tip_event_id);
2614 int x, y; 2663 int x, y;
2615 2664
2616 if (event_id == RECORD_EVENT_LIFTOFF) 2665 if (event_id == RECORD_EVENT_LIFTOFF)
@@ -2621,11 +2670,12 @@ static void cyapa_gen5_report_slot_data(struct cyapa *cyapa,
2621 x = (touch->x_hi << 8) | touch->x_lo; 2670 x = (touch->x_hi << 8) | touch->x_lo;
2622 if (cyapa->x_origin) 2671 if (cyapa->x_origin)
2623 x = cyapa->max_abs_x - x; 2672 x = cyapa->max_abs_x - x;
2624 input_report_abs(input, ABS_MT_POSITION_X, x);
2625 y = (touch->y_hi << 8) | touch->y_lo; 2673 y = (touch->y_hi << 8) | touch->y_lo;
2626 if (cyapa->y_origin) 2674 if (cyapa->y_origin)
2627 y = cyapa->max_abs_y - y; 2675 y = cyapa->max_abs_y - y;
2676 input_report_abs(input, ABS_MT_POSITION_X, x);
2628 input_report_abs(input, ABS_MT_POSITION_Y, y); 2677 input_report_abs(input, ABS_MT_POSITION_Y, y);
2678 input_report_abs(input, ABS_DISTANCE, 0);
2629 input_report_abs(input, ABS_MT_PRESSURE, 2679 input_report_abs(input, ABS_MT_PRESSURE,
2630 touch->z); 2680 touch->z);
2631 input_report_abs(input, ABS_MT_TOUCH_MAJOR, 2681 input_report_abs(input, ABS_MT_TOUCH_MAJOR,
@@ -2642,50 +2692,49 @@ static void cyapa_gen5_report_slot_data(struct cyapa *cyapa,
2642 touch->orientation); 2692 touch->orientation);
2643} 2693}
2644 2694
2645static void cyapa_gen5_report_touches(struct cyapa *cyapa, 2695static void cyapa_pip_report_touches(struct cyapa *cyapa,
2646 const struct cyapa_gen5_report_data *report_data) 2696 const struct cyapa_pip_report_data *report_data)
2647{ 2697{
2648 struct input_dev *input = cyapa->input; 2698 struct input_dev *input = cyapa->input;
2649 unsigned int touch_num; 2699 unsigned int touch_num;
2650 int i; 2700 int i;
2651 2701
2652 touch_num = report_data->report_head[GEN5_NUMBER_OF_TOUCH_OFFSET] & 2702 touch_num = report_data->report_head[PIP_NUMBER_OF_TOUCH_OFFSET] &
2653 GEN5_NUMBER_OF_TOUCH_MASK; 2703 PIP_NUMBER_OF_TOUCH_MASK;
2654 2704
2655 for (i = 0; i < touch_num; i++) 2705 for (i = 0; i < touch_num; i++)
2656 cyapa_gen5_report_slot_data(cyapa, 2706 cyapa_pip_report_slot_data(cyapa,
2657 &report_data->touch_records[i]); 2707 &report_data->touch_records[i]);
2658 2708
2659 input_mt_sync_frame(input); 2709 input_mt_sync_frame(input);
2660 input_sync(input); 2710 input_sync(input);
2661} 2711}
2662 2712
2663static int cyapa_gen5_irq_handler(struct cyapa *cyapa) 2713int cyapa_pip_irq_handler(struct cyapa *cyapa)
2664{ 2714{
2665 struct device *dev = &cyapa->client->dev; 2715 struct device *dev = &cyapa->client->dev;
2666 struct cyapa_gen5_report_data report_data; 2716 struct cyapa_pip_report_data report_data;
2667 int ret;
2668 u8 report_id;
2669 unsigned int report_len; 2717 unsigned int report_len;
2718 u8 report_id;
2719 int ret;
2670 2720
2671 if (cyapa->gen != CYAPA_GEN5 || 2721 if (!cyapa_is_pip_app_mode(cyapa)) {
2672 cyapa->state != CYAPA_STATE_GEN5_APP) {
2673 dev_err(dev, "invalid device state, gen=%d, state=0x%02x\n", 2722 dev_err(dev, "invalid device state, gen=%d, state=0x%02x\n",
2674 cyapa->gen, cyapa->state); 2723 cyapa->gen, cyapa->state);
2675 return -EINVAL; 2724 return -EINVAL;
2676 } 2725 }
2677 2726
2678 ret = cyapa_i2c_pip_read(cyapa, (u8 *)&report_data, 2727 ret = cyapa_i2c_pip_read(cyapa, (u8 *)&report_data,
2679 GEN5_RESP_LENGTH_SIZE); 2728 PIP_RESP_LENGTH_SIZE);
2680 if (ret != GEN5_RESP_LENGTH_SIZE) { 2729 if (ret != PIP_RESP_LENGTH_SIZE) {
2681 dev_err(dev, "failed to read length bytes, (%d)\n", ret); 2730 dev_err(dev, "failed to read length bytes, (%d)\n", ret);
2682 return -EINVAL; 2731 return -EINVAL;
2683 } 2732 }
2684 2733
2685 report_len = get_unaligned_le16( 2734 report_len = get_unaligned_le16(
2686 &report_data.report_head[GEN5_RESP_LENGTH_OFFSET]); 2735 &report_data.report_head[PIP_RESP_LENGTH_OFFSET]);
2687 if (report_len < GEN5_RESP_LENGTH_SIZE) { 2736 if (report_len < PIP_RESP_LENGTH_SIZE) {
2688 /* Invliad length or internal reset happened. */ 2737 /* Invalid length or internal reset happened. */
2689 dev_err(dev, "invalid report_len=%d. bytes: %02x %02x\n", 2738 dev_err(dev, "invalid report_len=%d. bytes: %02x %02x\n",
2690 report_len, report_data.report_head[0], 2739 report_len, report_data.report_head[0],
2691 report_data.report_head[1]); 2740 report_data.report_head[1]);
@@ -2693,7 +2742,7 @@ static int cyapa_gen5_irq_handler(struct cyapa *cyapa)
2693 } 2742 }
2694 2743
2695 /* Idle, no data for report. */ 2744 /* Idle, no data for report. */
2696 if (report_len == GEN5_RESP_LENGTH_SIZE) 2745 if (report_len == PIP_RESP_LENGTH_SIZE)
2697 return 0; 2746 return 0;
2698 2747
2699 ret = cyapa_i2c_pip_read(cyapa, (u8 *)&report_data, report_len); 2748 ret = cyapa_i2c_pip_read(cyapa, (u8 *)&report_data, report_len);
@@ -2703,70 +2752,92 @@ static int cyapa_gen5_irq_handler(struct cyapa *cyapa)
2703 return -EINVAL; 2752 return -EINVAL;
2704 } 2753 }
2705 2754
2706 report_id = report_data.report_head[GEN5_RESP_REPORT_ID_OFFSET]; 2755 report_id = report_data.report_head[PIP_RESP_REPORT_ID_OFFSET];
2707 if (report_id == GEN5_WAKEUP_EVENT_REPORT_ID && 2756 if (report_id == PIP_WAKEUP_EVENT_REPORT_ID &&
2708 report_len == GEN5_WAKEUP_EVENT_SIZE) { 2757 report_len == PIP_WAKEUP_EVENT_SIZE) {
2709 /* 2758 /*
2710 * Device wake event from deep sleep mode for touch. 2759 * Device wake event from deep sleep mode for touch.
2711 * This interrupt event is used to wake system up. 2760 * This interrupt event is used to wake system up.
2761 *
2762 * Note:
2763 * It will introduce about 20~40 ms additional delay
2764 * time in receiving for first valid touch report data.
2765 * The time is used to execute device runtime resume
2766 * process.
2712 */ 2767 */
2768 pm_runtime_get_sync(dev);
2769 pm_runtime_mark_last_busy(dev);
2770 pm_runtime_put_sync_autosuspend(dev);
2713 return 0; 2771 return 0;
2714 } else if (report_id != GEN5_TOUCH_REPORT_ID && 2772 } else if (report_id != PIP_TOUCH_REPORT_ID &&
2715 report_id != GEN5_BTN_REPORT_ID && 2773 report_id != PIP_BTN_REPORT_ID &&
2716 report_id != GEN5_OLD_PUSH_BTN_REPORT_ID && 2774 report_id != GEN5_OLD_PUSH_BTN_REPORT_ID &&
2717 report_id != GEN5_PUSH_BTN_REPORT_ID) { 2775 report_id != PIP_PUSH_BTN_REPORT_ID &&
2776 report_id != PIP_PROXIMITY_REPORT_ID) {
2718 /* Running in BL mode or unknown response data read. */ 2777 /* Running in BL mode or unknown response data read. */
2719 dev_err(dev, "invalid report_id=0x%02x\n", report_id); 2778 dev_err(dev, "invalid report_id=0x%02x\n", report_id);
2720 return -EINVAL; 2779 return -EINVAL;
2721 } 2780 }
2722 2781
2723 if (report_id == GEN5_TOUCH_REPORT_ID && 2782 if (report_id == PIP_TOUCH_REPORT_ID &&
2724 (report_len < GEN5_TOUCH_REPORT_HEAD_SIZE || 2783 (report_len < PIP_TOUCH_REPORT_HEAD_SIZE ||
2725 report_len > GEN5_TOUCH_REPORT_MAX_SIZE)) { 2784 report_len > PIP_TOUCH_REPORT_MAX_SIZE)) {
2726 /* Invalid report data length for finger packet. */ 2785 /* Invalid report data length for finger packet. */
2727 dev_err(dev, "invalid touch packet length=%d\n", report_len); 2786 dev_err(dev, "invalid touch packet length=%d\n", report_len);
2728 return 0; 2787 return 0;
2729 } 2788 }
2730 2789
2731 if ((report_id == GEN5_BTN_REPORT_ID || 2790 if ((report_id == PIP_BTN_REPORT_ID ||
2732 report_id == GEN5_OLD_PUSH_BTN_REPORT_ID || 2791 report_id == GEN5_OLD_PUSH_BTN_REPORT_ID ||
2733 report_id == GEN5_PUSH_BTN_REPORT_ID) && 2792 report_id == PIP_PUSH_BTN_REPORT_ID) &&
2734 (report_len < GEN5_BTN_REPORT_HEAD_SIZE || 2793 (report_len < PIP_BTN_REPORT_HEAD_SIZE ||
2735 report_len > GEN5_BTN_REPORT_MAX_SIZE)) { 2794 report_len > PIP_BTN_REPORT_MAX_SIZE)) {
2736 /* Invalid report data length of button packet. */ 2795 /* Invalid report data length of button packet. */
2737 dev_err(dev, "invalid button packet length=%d\n", report_len); 2796 dev_err(dev, "invalid button packet length=%d\n", report_len);
2738 return 0; 2797 return 0;
2739 } 2798 }
2740 2799
2741 if (report_id == GEN5_TOUCH_REPORT_ID) 2800 if (report_id == PIP_PROXIMITY_REPORT_ID &&
2742 cyapa_gen5_report_touches(cyapa, &report_data); 2801 report_len != PIP_PROXIMITY_REPORT_SIZE) {
2802 /* Invalid report data length of proximity packet. */
2803 dev_err(dev, "invalid proximity data, length=%d\n", report_len);
2804 return 0;
2805 }
2806
2807 if (report_id == PIP_TOUCH_REPORT_ID)
2808 cyapa_pip_report_touches(cyapa, &report_data);
2809 else if (report_id == PIP_PROXIMITY_REPORT_ID)
2810 cyapa_pip_report_proximity(cyapa, &report_data);
2743 else 2811 else
2744 cyapa_gen5_report_buttons(cyapa, &report_data); 2812 cyapa_pip_report_buttons(cyapa, &report_data);
2745 2813
2746 return 0; 2814 return 0;
2747} 2815}
2748 2816
2749static int cyapa_gen5_bl_activate(struct cyapa *cyapa) { return 0; } 2817int cyapa_pip_bl_activate(struct cyapa *cyapa) { return 0; }
2750static int cyapa_gen5_bl_deactivate(struct cyapa *cyapa) { return 0; } 2818int cyapa_pip_bl_deactivate(struct cyapa *cyapa) { return 0; }
2819
2751 2820
2752const struct cyapa_dev_ops cyapa_gen5_ops = { 2821const struct cyapa_dev_ops cyapa_gen5_ops = {
2753 .check_fw = cyapa_gen5_check_fw, 2822 .check_fw = cyapa_pip_check_fw,
2754 .bl_enter = cyapa_gen5_bl_enter, 2823 .bl_enter = cyapa_pip_bl_enter,
2755 .bl_initiate = cyapa_gen5_bl_initiate, 2824 .bl_initiate = cyapa_pip_bl_initiate,
2756 .update_fw = cyapa_gen5_do_fw_update, 2825 .update_fw = cyapa_pip_do_fw_update,
2757 .bl_activate = cyapa_gen5_bl_activate, 2826 .bl_activate = cyapa_pip_bl_activate,
2758 .bl_deactivate = cyapa_gen5_bl_deactivate, 2827 .bl_deactivate = cyapa_pip_bl_deactivate,
2759 2828
2760 .show_baseline = cyapa_gen5_show_baseline, 2829 .show_baseline = cyapa_gen5_show_baseline,
2761 .calibrate_store = cyapa_gen5_do_calibrate, 2830 .calibrate_store = cyapa_pip_do_calibrate,
2762 2831
2763 .initialize = cyapa_gen5_initialize, 2832 .initialize = cyapa_pip_cmd_state_initialize,
2764 2833
2765 .state_parse = cyapa_gen5_state_parse, 2834 .state_parse = cyapa_gen5_state_parse,
2766 .operational_check = cyapa_gen5_do_operational_check, 2835 .operational_check = cyapa_gen5_do_operational_check,
2767 2836
2768 .irq_handler = cyapa_gen5_irq_handler, 2837 .irq_handler = cyapa_pip_irq_handler,
2769 .irq_cmd_handler = cyapa_gen5_irq_cmd_handler, 2838 .irq_cmd_handler = cyapa_pip_irq_cmd_handler,
2770 .sort_empty_output_data = cyapa_empty_pip_output_data, 2839 .sort_empty_output_data = cyapa_empty_pip_output_data,
2771 .set_power_mode = cyapa_gen5_set_power_mode, 2840 .set_power_mode = cyapa_gen5_set_power_mode,
2841
2842 .set_proximity = cyapa_pip_set_proximity,
2772}; 2843};
diff --git a/drivers/input/mouse/cyapa_gen6.c b/drivers/input/mouse/cyapa_gen6.c
new file mode 100644
index 000000000000..5f191071d44a
--- /dev/null
+++ b/drivers/input/mouse/cyapa_gen6.c
@@ -0,0 +1,749 @@
1/*
2 * Cypress APA trackpad with I2C interface
3 *
4 * Author: Dudley Du <dudl@cypress.com>
5 *
6 * Copyright (C) 2015 Cypress Semiconductor, Inc.
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive for
10 * more details.
11 */
12
13#include <linux/delay.h>
14#include <linux/i2c.h>
15#include <linux/input.h>
16#include <linux/input/mt.h>
17#include <linux/mutex.h>
18#include <linux/completion.h>
19#include <linux/slab.h>
20#include <asm/unaligned.h>
21#include <linux/crc-itu-t.h>
22#include "cyapa.h"
23
24
25#define GEN6_ENABLE_CMD_IRQ 0x41
26#define GEN6_DISABLE_CMD_IRQ 0x42
27#define GEN6_ENABLE_DEV_IRQ 0x43
28#define GEN6_DISABLE_DEV_IRQ 0x44
29
30#define GEN6_POWER_MODE_ACTIVE 0x01
31#define GEN6_POWER_MODE_LP_MODE1 0x02
32#define GEN6_POWER_MODE_LP_MODE2 0x03
33#define GEN6_POWER_MODE_BTN_ONLY 0x04
34
35#define GEN6_SET_POWER_MODE_INTERVAL 0x47
36#define GEN6_GET_POWER_MODE_INTERVAL 0x48
37
38#define GEN6_MAX_RX_NUM 14
39#define GEN6_RETRIEVE_DATA_ID_RX_ATTENURATOR_IDAC 0x00
40#define GEN6_RETRIEVE_DATA_ID_ATTENURATOR_TRIM 0x12
41
42
43struct pip_app_cmd_head {
44 __le16 addr;
45 __le16 length;
46 u8 report_id;
47 u8 resv; /* Reserved, must be 0 */
48 u8 cmd_code; /* bit7: resv, set to 0; bit6~0: command code.*/
49} __packed;
50
51struct pip_app_resp_head {
52 __le16 length;
53 u8 report_id;
54 u8 resv; /* Reserved, must be 0 */
55 u8 cmd_code; /* bit7: TGL; bit6~0: command code.*/
56 /*
57 * The value of data_status can be the first byte of data or
58 * the command status or the unsupported command code depending on the
59 * requested command code.
60 */
61 u8 data_status;
62} __packed;
63
64struct pip_fixed_info {
65 u8 silicon_id_high;
66 u8 silicon_id_low;
67 u8 family_id;
68};
69
70static u8 pip_get_bl_info[] = {
71 0x04, 0x00, 0x0B, 0x00, 0x40, 0x00, 0x01, 0x38,
72 0x00, 0x00, 0x70, 0x9E, 0x17
73};
74
75static bool cyapa_sort_pip_hid_descriptor_data(struct cyapa *cyapa,
76 u8 *buf, int len)
77{
78 if (len != PIP_HID_DESCRIPTOR_SIZE)
79 return false;
80
81 if (buf[PIP_RESP_REPORT_ID_OFFSET] == PIP_HID_APP_REPORT_ID ||
82 buf[PIP_RESP_REPORT_ID_OFFSET] == PIP_HID_BL_REPORT_ID)
83 return true;
84
85 return false;
86}
87
88static int cyapa_get_pip_fixed_info(struct cyapa *cyapa,
89 struct pip_fixed_info *pip_info, bool is_bootloader)
90{
91 u8 resp_data[PIP_READ_SYS_INFO_RESP_LENGTH];
92 int resp_len;
93 u16 product_family;
94 int error;
95
96 if (is_bootloader) {
97 /* Read Bootloader Information to determine Gen5 or Gen6. */
98 resp_len = sizeof(resp_data);
99 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
100 pip_get_bl_info, sizeof(pip_get_bl_info),
101 resp_data, &resp_len,
102 2000, cyapa_sort_tsg_pip_bl_resp_data,
103 false);
104 if (error || resp_len < PIP_BL_GET_INFO_RESP_LENGTH)
105 return error ? error : -EIO;
106
107 pip_info->family_id = resp_data[8];
108 pip_info->silicon_id_low = resp_data[10];
109 pip_info->silicon_id_high = resp_data[11];
110
111 return 0;
112 }
113
114 /* Get App System Information to determine Gen5 or Gen6. */
115 resp_len = sizeof(resp_data);
116 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
117 pip_read_sys_info, PIP_READ_SYS_INFO_CMD_LENGTH,
118 resp_data, &resp_len,
119 2000, cyapa_pip_sort_system_info_data, false);
120 if (error || resp_len < PIP_READ_SYS_INFO_RESP_LENGTH)
121 return error ? error : -EIO;
122
123 product_family = get_unaligned_le16(&resp_data[7]);
124 if ((product_family & PIP_PRODUCT_FAMILY_MASK) !=
125 PIP_PRODUCT_FAMILY_TRACKPAD)
126 return -EINVAL;
127
128 pip_info->family_id = resp_data[19];
129 pip_info->silicon_id_low = resp_data[21];
130 pip_info->silicon_id_high = resp_data[22];
131
132 return 0;
133
134}
135
136int cyapa_pip_state_parse(struct cyapa *cyapa, u8 *reg_data, int len)
137{
138 u8 cmd[] = { 0x01, 0x00};
139 struct pip_fixed_info pip_info;
140 u8 resp_data[PIP_HID_DESCRIPTOR_SIZE];
141 int resp_len;
142 bool is_bootloader;
143 int error;
144
145 cyapa->state = CYAPA_STATE_NO_DEVICE;
146
147 /* Try to wake from it deep sleep state if it is. */
148 cyapa_pip_deep_sleep(cyapa, PIP_DEEP_SLEEP_STATE_ON);
149
150 /* Empty the buffer queue to get fresh data with later commands. */
151 cyapa_empty_pip_output_data(cyapa, NULL, NULL, NULL);
152
153 /*
154 * Read description info from trackpad device to determine running in
155 * APP mode or Bootloader mode.
156 */
157 resp_len = PIP_HID_DESCRIPTOR_SIZE;
158 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
159 cmd, sizeof(cmd),
160 resp_data, &resp_len,
161 300,
162 cyapa_sort_pip_hid_descriptor_data,
163 false);
164 if (error)
165 return error;
166
167 if (resp_data[PIP_RESP_REPORT_ID_OFFSET] == PIP_HID_BL_REPORT_ID)
168 is_bootloader = true;
169 else if (resp_data[PIP_RESP_REPORT_ID_OFFSET] == PIP_HID_APP_REPORT_ID)
170 is_bootloader = false;
171 else
172 return -EAGAIN;
173
174 /* Get PIP fixed information to determine Gen5 or Gen6. */
175 memset(&pip_info, 0, sizeof(struct pip_fixed_info));
176 error = cyapa_get_pip_fixed_info(cyapa, &pip_info, is_bootloader);
177 if (error)
178 return error;
179
180 if (pip_info.family_id == 0x9B && pip_info.silicon_id_high == 0x0B) {
181 cyapa->gen = CYAPA_GEN6;
182 cyapa->state = is_bootloader ? CYAPA_STATE_GEN6_BL
183 : CYAPA_STATE_GEN6_APP;
184 } else if (pip_info.family_id == 0x91 &&
185 pip_info.silicon_id_high == 0x02) {
186 cyapa->gen = CYAPA_GEN5;
187 cyapa->state = is_bootloader ? CYAPA_STATE_GEN5_BL
188 : CYAPA_STATE_GEN5_APP;
189 }
190
191 return 0;
192}
193
194static int cyapa_gen6_read_sys_info(struct cyapa *cyapa)
195{
196 u8 resp_data[PIP_READ_SYS_INFO_RESP_LENGTH];
197 int resp_len;
198 u16 product_family;
199 u8 rotat_align;
200 int error;
201
202 /* Get App System Information to determine Gen5 or Gen6. */
203 resp_len = sizeof(resp_data);
204 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
205 pip_read_sys_info, PIP_READ_SYS_INFO_CMD_LENGTH,
206 resp_data, &resp_len,
207 2000, cyapa_pip_sort_system_info_data, false);
208 if (error || resp_len < sizeof(resp_data))
209 return error ? error : -EIO;
210
211 product_family = get_unaligned_le16(&resp_data[7]);
212 if ((product_family & PIP_PRODUCT_FAMILY_MASK) !=
213 PIP_PRODUCT_FAMILY_TRACKPAD)
214 return -EINVAL;
215
216 cyapa->platform_ver = (resp_data[67] >> PIP_BL_PLATFORM_VER_SHIFT) &
217 PIP_BL_PLATFORM_VER_MASK;
218 cyapa->fw_maj_ver = resp_data[9];
219 cyapa->fw_min_ver = resp_data[10];
220
221 cyapa->electrodes_x = resp_data[33];
222 cyapa->electrodes_y = resp_data[34];
223
224 cyapa->physical_size_x = get_unaligned_le16(&resp_data[35]) / 100;
225 cyapa->physical_size_y = get_unaligned_le16(&resp_data[37]) / 100;
226
227 cyapa->max_abs_x = get_unaligned_le16(&resp_data[39]);
228 cyapa->max_abs_y = get_unaligned_le16(&resp_data[41]);
229
230 cyapa->max_z = get_unaligned_le16(&resp_data[43]);
231
232 cyapa->x_origin = resp_data[45] & 0x01;
233 cyapa->y_origin = resp_data[46] & 0x01;
234
235 cyapa->btn_capability = (resp_data[70] << 3) & CAPABILITY_BTN_MASK;
236
237 memcpy(&cyapa->product_id[0], &resp_data[51], 5);
238 cyapa->product_id[5] = '-';
239 memcpy(&cyapa->product_id[6], &resp_data[56], 6);
240 cyapa->product_id[12] = '-';
241 memcpy(&cyapa->product_id[13], &resp_data[62], 2);
242 cyapa->product_id[15] = '\0';
243
244 rotat_align = resp_data[68];
245 if (rotat_align) {
246 cyapa->electrodes_rx = cyapa->electrodes_y;
247 cyapa->electrodes_rx = cyapa->electrodes_y;
248 } else {
249 cyapa->electrodes_rx = cyapa->electrodes_x;
250 cyapa->electrodes_rx = cyapa->electrodes_y;
251 }
252 cyapa->aligned_electrodes_rx = (cyapa->electrodes_rx + 3) & ~3u;
253
254 if (!cyapa->electrodes_x || !cyapa->electrodes_y ||
255 !cyapa->physical_size_x || !cyapa->physical_size_y ||
256 !cyapa->max_abs_x || !cyapa->max_abs_y || !cyapa->max_z)
257 return -EINVAL;
258
259 return 0;
260}
261
262static int cyapa_gen6_bl_read_app_info(struct cyapa *cyapa)
263{
264 u8 resp_data[PIP_BL_APP_INFO_RESP_LENGTH];
265 int resp_len;
266 int error;
267
268 resp_len = sizeof(resp_data);
269 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
270 pip_bl_read_app_info, PIP_BL_READ_APP_INFO_CMD_LENGTH,
271 resp_data, &resp_len,
272 500, cyapa_sort_tsg_pip_bl_resp_data, false);
273 if (error || resp_len < PIP_BL_APP_INFO_RESP_LENGTH ||
274 !PIP_CMD_COMPLETE_SUCCESS(resp_data))
275 return error ? error : -EIO;
276
277 cyapa->fw_maj_ver = resp_data[8];
278 cyapa->fw_min_ver = resp_data[9];
279
280 cyapa->platform_ver = (resp_data[12] >> PIP_BL_PLATFORM_VER_SHIFT) &
281 PIP_BL_PLATFORM_VER_MASK;
282
283 memcpy(&cyapa->product_id[0], &resp_data[13], 5);
284 cyapa->product_id[5] = '-';
285 memcpy(&cyapa->product_id[6], &resp_data[18], 6);
286 cyapa->product_id[12] = '-';
287 memcpy(&cyapa->product_id[13], &resp_data[24], 2);
288 cyapa->product_id[15] = '\0';
289
290 return 0;
291
292}
293
294static int cyapa_gen6_config_dev_irq(struct cyapa *cyapa, u8 cmd_code)
295{
296 u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, cmd_code };
297 u8 resp_data[6];
298 int resp_len;
299 int error;
300
301 resp_len = sizeof(resp_data);
302 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
303 resp_data, &resp_len,
304 500, cyapa_sort_tsg_pip_app_resp_data, false);
305 if (error || !VALID_CMD_RESP_HEADER(resp_data, cmd_code) ||
306 !PIP_CMD_COMPLETE_SUCCESS(resp_data)
307 )
308 return error < 0 ? error : -EINVAL;
309
310 return 0;
311}
312
313static int cyapa_gen6_set_proximity(struct cyapa *cyapa, bool enable)
314{
315 int error;
316
317 cyapa_gen6_config_dev_irq(cyapa, GEN6_DISABLE_CMD_IRQ);
318 error = cyapa_pip_set_proximity(cyapa, enable);
319 cyapa_gen6_config_dev_irq(cyapa, GEN6_ENABLE_CMD_IRQ);
320
321 return error;
322}
323
324static int cyapa_gen6_change_power_state(struct cyapa *cyapa, u8 power_mode)
325{
326 u8 cmd[] = { 0x04, 0x00, 0x06, 0x00, 0x2f, 0x00, 0x46, power_mode };
327 u8 resp_data[6];
328 int resp_len;
329 int error;
330
331 resp_len = sizeof(resp_data);
332 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
333 resp_data, &resp_len,
334 500, cyapa_sort_tsg_pip_app_resp_data, false);
335 if (error || !VALID_CMD_RESP_HEADER(resp_data, 0x46))
336 return error < 0 ? error : -EINVAL;
337
338 /* New power state applied in device not match the set power state. */
339 if (resp_data[5] != power_mode)
340 return -EAGAIN;
341
342 return 0;
343}
344
345static int cyapa_gen6_set_interval_setting(struct cyapa *cyapa,
346 struct gen6_interval_setting *interval_setting)
347{
348 struct gen6_set_interval_cmd {
349 __le16 addr;
350 __le16 length;
351 u8 report_id;
352 u8 rsvd; /* Reserved, must be 0 */
353 u8 cmd_code;
354 __le16 active_interval;
355 __le16 lp1_interval;
356 __le16 lp2_interval;
357 } __packed set_interval_cmd;
358 u8 resp_data[11];
359 int resp_len;
360 int error;
361
362 memset(&set_interval_cmd, 0, sizeof(set_interval_cmd));
363 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &set_interval_cmd.addr);
364 put_unaligned_le16(sizeof(set_interval_cmd) - 2,
365 &set_interval_cmd.length);
366 set_interval_cmd.report_id = PIP_APP_CMD_REPORT_ID;
367 set_interval_cmd.cmd_code = GEN6_SET_POWER_MODE_INTERVAL;
368 put_unaligned_le16(interval_setting->active_interval,
369 &set_interval_cmd.active_interval);
370 put_unaligned_le16(interval_setting->lp1_interval,
371 &set_interval_cmd.lp1_interval);
372 put_unaligned_le16(interval_setting->lp2_interval,
373 &set_interval_cmd.lp2_interval);
374
375 resp_len = sizeof(resp_data);
376 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
377 (u8 *)&set_interval_cmd, sizeof(set_interval_cmd),
378 resp_data, &resp_len,
379 500, cyapa_sort_tsg_pip_app_resp_data, false);
380 if (error ||
381 !VALID_CMD_RESP_HEADER(resp_data, GEN6_SET_POWER_MODE_INTERVAL))
382 return error < 0 ? error : -EINVAL;
383
384 /* Get the real set intervals from response. */
385 interval_setting->active_interval = get_unaligned_le16(&resp_data[5]);
386 interval_setting->lp1_interval = get_unaligned_le16(&resp_data[7]);
387 interval_setting->lp2_interval = get_unaligned_le16(&resp_data[9]);
388
389 return 0;
390}
391
392static int cyapa_gen6_get_interval_setting(struct cyapa *cyapa,
393 struct gen6_interval_setting *interval_setting)
394{
395 u8 cmd[] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00,
396 GEN6_GET_POWER_MODE_INTERVAL };
397 u8 resp_data[11];
398 int resp_len;
399 int error;
400
401 resp_len = sizeof(resp_data);
402 error = cyapa_i2c_pip_cmd_irq_sync(cyapa, cmd, sizeof(cmd),
403 resp_data, &resp_len,
404 500, cyapa_sort_tsg_pip_app_resp_data, false);
405 if (error ||
406 !VALID_CMD_RESP_HEADER(resp_data, GEN6_GET_POWER_MODE_INTERVAL))
407 return error < 0 ? error : -EINVAL;
408
409 interval_setting->active_interval = get_unaligned_le16(&resp_data[5]);
410 interval_setting->lp1_interval = get_unaligned_le16(&resp_data[7]);
411 interval_setting->lp2_interval = get_unaligned_le16(&resp_data[9]);
412
413 return 0;
414}
415
416static int cyapa_gen6_deep_sleep(struct cyapa *cyapa, u8 state)
417{
418 u8 ping[] = { 0x04, 0x00, 0x05, 0x00, 0x2f, 0x00, 0x00 };
419
420 if (state == PIP_DEEP_SLEEP_STATE_ON)
421 /*
422 * Send ping command to notify device prepare for wake up
423 * when it's in deep sleep mode. At this time, device will
424 * response nothing except an I2C NAK.
425 */
426 cyapa_i2c_pip_write(cyapa, ping, sizeof(ping));
427
428 return cyapa_pip_deep_sleep(cyapa, state);
429}
430
431static int cyapa_gen6_set_power_mode(struct cyapa *cyapa,
432 u8 power_mode, u16 sleep_time, bool is_suspend)
433{
434 struct device *dev = &cyapa->client->dev;
435 struct gen6_interval_setting *interval_setting =
436 &cyapa->gen6_interval_setting;
437 u8 lp_mode;
438 int error;
439
440 if (cyapa->state != CYAPA_STATE_GEN6_APP)
441 return 0;
442
443 if (PIP_DEV_GET_PWR_STATE(cyapa) == UNINIT_PWR_MODE) {
444 /*
445 * Assume TP in deep sleep mode when driver is loaded,
446 * avoid driver unload and reload command IO issue caused by TP
447 * has been set into deep sleep mode when unloading.
448 */
449 PIP_DEV_SET_PWR_STATE(cyapa, PWR_MODE_OFF);
450 }
451
452 if (PIP_DEV_UNINIT_SLEEP_TIME(cyapa) &&
453 PIP_DEV_GET_PWR_STATE(cyapa) != PWR_MODE_OFF)
454 PIP_DEV_SET_SLEEP_TIME(cyapa, UNINIT_SLEEP_TIME);
455
456 if (PIP_DEV_GET_PWR_STATE(cyapa) == power_mode) {
457 if (power_mode == PWR_MODE_OFF ||
458 power_mode == PWR_MODE_FULL_ACTIVE ||
459 power_mode == PWR_MODE_BTN_ONLY ||
460 PIP_DEV_GET_SLEEP_TIME(cyapa) == sleep_time) {
461 /* Has in correct power mode state, early return. */
462 return 0;
463 }
464 }
465
466 if (power_mode == PWR_MODE_OFF) {
467 cyapa_gen6_config_dev_irq(cyapa, GEN6_DISABLE_CMD_IRQ);
468
469 error = cyapa_gen6_deep_sleep(cyapa, PIP_DEEP_SLEEP_STATE_OFF);
470 if (error) {
471 dev_err(dev, "enter deep sleep fail: %d\n", error);
472 return error;
473 }
474
475 PIP_DEV_SET_PWR_STATE(cyapa, PWR_MODE_OFF);
476 return 0;
477 }
478
479 /*
480 * When trackpad in power off mode, it cannot change to other power
481 * state directly, must be wake up from sleep firstly, then
482 * continue to do next power sate change.
483 */
484 if (PIP_DEV_GET_PWR_STATE(cyapa) == PWR_MODE_OFF) {
485 error = cyapa_gen6_deep_sleep(cyapa, PIP_DEEP_SLEEP_STATE_ON);
486 if (error) {
487 dev_err(dev, "deep sleep wake fail: %d\n", error);
488 return error;
489 }
490 }
491
492 /*
493 * Disable device assert interrupts for command response to avoid
494 * disturbing system suspending or hibernating process.
495 */
496 cyapa_gen6_config_dev_irq(cyapa, GEN6_DISABLE_CMD_IRQ);
497
498 if (power_mode == PWR_MODE_FULL_ACTIVE) {
499 error = cyapa_gen6_change_power_state(cyapa,
500 GEN6_POWER_MODE_ACTIVE);
501 if (error) {
502 dev_err(dev, "change to active fail: %d\n", error);
503 goto out;
504 }
505
506 PIP_DEV_SET_PWR_STATE(cyapa, PWR_MODE_FULL_ACTIVE);
507
508 /* Sync the interval setting from device. */
509 cyapa_gen6_get_interval_setting(cyapa, interval_setting);
510
511 } else if (power_mode == PWR_MODE_BTN_ONLY) {
512 error = cyapa_gen6_change_power_state(cyapa,
513 GEN6_POWER_MODE_BTN_ONLY);
514 if (error) {
515 dev_err(dev, "fail to button only mode: %d\n", error);
516 goto out;
517 }
518
519 PIP_DEV_SET_PWR_STATE(cyapa, PWR_MODE_BTN_ONLY);
520 } else {
521 /*
522 * Gen6 internally supports to 2 low power scan interval time,
523 * so can help to switch power mode quickly.
524 * such as runtime suspend and system suspend.
525 */
526 if (interval_setting->lp1_interval == sleep_time) {
527 lp_mode = GEN6_POWER_MODE_LP_MODE1;
528 } else if (interval_setting->lp2_interval == sleep_time) {
529 lp_mode = GEN6_POWER_MODE_LP_MODE2;
530 } else {
531 if (interval_setting->lp1_interval == 0) {
532 interval_setting->lp1_interval = sleep_time;
533 lp_mode = GEN6_POWER_MODE_LP_MODE1;
534 } else {
535 interval_setting->lp2_interval = sleep_time;
536 lp_mode = GEN6_POWER_MODE_LP_MODE2;
537 }
538 cyapa_gen6_set_interval_setting(cyapa,
539 interval_setting);
540 }
541
542 error = cyapa_gen6_change_power_state(cyapa, lp_mode);
543 if (error) {
544 dev_err(dev, "set power state to 0x%02x failed: %d\n",
545 lp_mode, error);
546 goto out;
547 }
548
549 PIP_DEV_SET_SLEEP_TIME(cyapa, sleep_time);
550 PIP_DEV_SET_PWR_STATE(cyapa,
551 cyapa_sleep_time_to_pwr_cmd(sleep_time));
552 }
553
554out:
555 cyapa_gen6_config_dev_irq(cyapa, GEN6_ENABLE_CMD_IRQ);
556 return error;
557}
558
559static int cyapa_gen6_initialize(struct cyapa *cyapa)
560{
561 return 0;
562}
563
564static int cyapa_pip_retrieve_data_structure(struct cyapa *cyapa,
565 u16 read_offset, u16 read_len, u8 data_id,
566 u8 *data, int *data_buf_lens)
567{
568 struct retrieve_data_struct_cmd {
569 struct pip_app_cmd_head head;
570 __le16 read_offset;
571 __le16 read_length;
572 u8 data_id;
573 } __packed cmd;
574 u8 resp_data[GEN6_MAX_RX_NUM + 10];
575 int resp_len;
576 int error;
577
578 memset(&cmd, 0, sizeof(cmd));
579 put_unaligned_le16(PIP_OUTPUT_REPORT_ADDR, &cmd.head.addr);
580 put_unaligned_le16(sizeof(cmd), &cmd.head.length - 2);
581 cmd.head.report_id = PIP_APP_CMD_REPORT_ID;
582 cmd.head.cmd_code = PIP_RETRIEVE_DATA_STRUCTURE;
583 put_unaligned_le16(read_offset, &cmd.read_offset);
584 put_unaligned_le16(read_len, &cmd.read_length);
585 cmd.data_id = data_id;
586
587 resp_len = sizeof(resp_data);
588 error = cyapa_i2c_pip_cmd_irq_sync(cyapa,
589 (u8 *)&cmd, sizeof(cmd),
590 resp_data, &resp_len,
591 500, cyapa_sort_tsg_pip_app_resp_data,
592 true);
593 if (error || !PIP_CMD_COMPLETE_SUCCESS(resp_data) ||
594 resp_data[6] != data_id ||
595 !VALID_CMD_RESP_HEADER(resp_data, PIP_RETRIEVE_DATA_STRUCTURE))
596 return (error < 0) ? error : -EAGAIN;
597
598 read_len = get_unaligned_le16(&resp_data[7]);
599 if (*data_buf_lens < read_len) {
600 *data_buf_lens = read_len;
601 return -ENOBUFS;
602 }
603
604 memcpy(data, &resp_data[10], read_len);
605 *data_buf_lens = read_len;
606 return 0;
607}
608
609static ssize_t cyapa_gen6_show_baseline(struct device *dev,
610 struct device_attribute *attr, char *buf)
611{
612 struct cyapa *cyapa = dev_get_drvdata(dev);
613 u8 data[GEN6_MAX_RX_NUM];
614 int data_len;
615 int size = 0;
616 int i;
617 int error;
618 int resume_error;
619
620 if (!cyapa_is_pip_app_mode(cyapa))
621 return -EBUSY;
622
623 /* 1. Suspend Scanning*/
624 error = cyapa_pip_suspend_scanning(cyapa);
625 if (error)
626 return error;
627
628 /* 2. IDAC and RX Attenuator Calibration Data (Center Frequency). */
629 data_len = sizeof(data);
630 error = cyapa_pip_retrieve_data_structure(cyapa, 0, data_len,
631 GEN6_RETRIEVE_DATA_ID_RX_ATTENURATOR_IDAC,
632 data, &data_len);
633 if (error)
634 goto resume_scanning;
635
636 size = scnprintf(buf, PAGE_SIZE, "%d %d %d %d %d %d ",
637 data[0], /* RX Attenuator Mutual */
638 data[1], /* IDAC Mutual */
639 data[2], /* RX Attenuator Self RX */
640 data[3], /* IDAC Self RX */
641 data[4], /* RX Attenuator Self TX */
642 data[5] /* IDAC Self TX */
643 );
644
645 /* 3. Read Attenuator Trim. */
646 data_len = sizeof(data);
647 error = cyapa_pip_retrieve_data_structure(cyapa, 0, data_len,
648 GEN6_RETRIEVE_DATA_ID_ATTENURATOR_TRIM,
649 data, &data_len);
650 if (error)
651 goto resume_scanning;
652
653 /* set attenuator trim values. */
654 for (i = 0; i < data_len; i++)
655 size += scnprintf(buf + size, PAGE_SIZE - size, "%d ", data[i]);
656 size += scnprintf(buf + size, PAGE_SIZE - size, "\n");
657
658resume_scanning:
659 /* 4. Resume Scanning*/
660 resume_error = cyapa_pip_resume_scanning(cyapa);
661 if (resume_error || error) {
662 memset(buf, 0, PAGE_SIZE);
663 return resume_error ? resume_error : error;
664 }
665
666 return size;
667}
668
669static int cyapa_gen6_operational_check(struct cyapa *cyapa)
670{
671 struct device *dev = &cyapa->client->dev;
672 int error;
673
674 if (cyapa->gen != CYAPA_GEN6)
675 return -ENODEV;
676
677 switch (cyapa->state) {
678 case CYAPA_STATE_GEN6_BL:
679 error = cyapa_pip_bl_exit(cyapa);
680 if (error) {
681 /* Try to update trackpad product information. */
682 cyapa_gen6_bl_read_app_info(cyapa);
683 goto out;
684 }
685
686 cyapa->state = CYAPA_STATE_GEN6_APP;
687
688 case CYAPA_STATE_GEN6_APP:
689 /*
690 * If trackpad device in deep sleep mode,
691 * the app command will fail.
692 * So always try to reset trackpad device to full active when
693 * the device state is required.
694 */
695 error = cyapa_gen6_set_power_mode(cyapa,
696 PWR_MODE_FULL_ACTIVE, 0, false);
697 if (error)
698 dev_warn(dev, "%s: failed to set power active mode.\n",
699 __func__);
700
701 /* By default, the trackpad proximity function is enabled. */
702 error = cyapa_pip_set_proximity(cyapa, true);
703 if (error)
704 dev_warn(dev, "%s: failed to enable proximity.\n",
705 __func__);
706
707 /* Get trackpad product information. */
708 error = cyapa_gen6_read_sys_info(cyapa);
709 if (error)
710 goto out;
711 /* Only support product ID starting with CYTRA */
712 if (memcmp(cyapa->product_id, product_id,
713 strlen(product_id)) != 0) {
714 dev_err(dev, "%s: unknown product ID (%s)\n",
715 __func__, cyapa->product_id);
716 error = -EINVAL;
717 }
718 break;
719 default:
720 error = -EINVAL;
721 }
722
723out:
724 return error;
725}
726
727const struct cyapa_dev_ops cyapa_gen6_ops = {
728 .check_fw = cyapa_pip_check_fw,
729 .bl_enter = cyapa_pip_bl_enter,
730 .bl_initiate = cyapa_pip_bl_initiate,
731 .update_fw = cyapa_pip_do_fw_update,
732 .bl_activate = cyapa_pip_bl_activate,
733 .bl_deactivate = cyapa_pip_bl_deactivate,
734
735 .show_baseline = cyapa_gen6_show_baseline,
736 .calibrate_store = cyapa_pip_do_calibrate,
737
738 .initialize = cyapa_gen6_initialize,
739
740 .state_parse = cyapa_pip_state_parse,
741 .operational_check = cyapa_gen6_operational_check,
742
743 .irq_handler = cyapa_pip_irq_handler,
744 .irq_cmd_handler = cyapa_pip_irq_cmd_handler,
745 .sort_empty_output_data = cyapa_empty_pip_output_data,
746 .set_power_mode = cyapa_gen6_set_power_mode,
747
748 .set_proximity = cyapa_gen6_set_proximity,
749};
diff --git a/drivers/input/mouse/elan_i2c_core.c b/drivers/input/mouse/elan_i2c_core.c
index 5b5f403d8ce6..e2b7420eed97 100644
--- a/drivers/input/mouse/elan_i2c_core.c
+++ b/drivers/input/mouse/elan_i2c_core.c
@@ -4,7 +4,7 @@
4 * Copyright (c) 2013 ELAN Microelectronics Corp. 4 * Copyright (c) 2013 ELAN Microelectronics Corp.
5 * 5 *
6 * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw> 6 * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw>
7 * Version: 1.5.9 7 * Version: 1.6.0
8 * 8 *
9 * Based on cyapa driver: 9 * Based on cyapa driver:
10 * copyright (c) 2011-2012 Cypress Semiconductor, Inc. 10 * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
@@ -40,7 +40,7 @@
40#include "elan_i2c.h" 40#include "elan_i2c.h"
41 41
42#define DRIVER_NAME "elan_i2c" 42#define DRIVER_NAME "elan_i2c"
43#define ELAN_DRIVER_VERSION "1.5.9" 43#define ELAN_DRIVER_VERSION "1.6.0"
44#define ETP_MAX_PRESSURE 255 44#define ETP_MAX_PRESSURE 255
45#define ETP_FWIDTH_REDUCE 90 45#define ETP_FWIDTH_REDUCE 90
46#define ETP_FINGER_WIDTH 15 46#define ETP_FINGER_WIDTH 15
@@ -84,7 +84,7 @@ struct elan_tp_data {
84 int pressure_adjustment; 84 int pressure_adjustment;
85 u8 mode; 85 u8 mode;
86 u8 ic_type; 86 u8 ic_type;
87 u16 fw_vaildpage_count; 87 u16 fw_validpage_count;
88 u16 fw_signature_address; 88 u16 fw_signature_address;
89 89
90 bool irq_wake; 90 bool irq_wake;
@@ -94,25 +94,28 @@ struct elan_tp_data {
94 bool baseline_ready; 94 bool baseline_ready;
95}; 95};
96 96
97static int elan_get_fwinfo(u8 ic_type, u16 *vaildpage_count, 97static int elan_get_fwinfo(u8 iap_version, u16 *validpage_count,
98 u16 *signature_address) 98 u16 *signature_address)
99{ 99{
100 switch(ic_type) { 100 switch (iap_version) {
101 case 0x08:
102 *validpage_count = 512;
103 break;
101 case 0x09: 104 case 0x09:
102 *vaildpage_count = 768; 105 *validpage_count = 768;
103 break; 106 break;
104 case 0x0D: 107 case 0x0D:
105 *vaildpage_count = 896; 108 *validpage_count = 896;
106 break; 109 break;
107 default: 110 default:
108 /* unknown ic type clear value */ 111 /* unknown ic type clear value */
109 *vaildpage_count = 0; 112 *validpage_count = 0;
110 *signature_address = 0; 113 *signature_address = 0;
111 return -ENXIO; 114 return -ENXIO;
112 } 115 }
113 116
114 *signature_address = 117 *signature_address =
115 (*vaildpage_count * ETP_FW_PAGE_SIZE) - ETP_FW_SIGNATURE_SIZE; 118 (*validpage_count * ETP_FW_PAGE_SIZE) - ETP_FW_SIGNATURE_SIZE;
116 119
117 return 0; 120 return 0;
118} 121}
@@ -261,11 +264,11 @@ static int elan_query_device_info(struct elan_tp_data *data)
261 if (error) 264 if (error)
262 return error; 265 return error;
263 266
264 error = elan_get_fwinfo(data->ic_type, &data->fw_vaildpage_count, 267 error = elan_get_fwinfo(data->iap_version, &data->fw_validpage_count,
265 &data->fw_signature_address); 268 &data->fw_signature_address);
266 if (error) { 269 if (error) {
267 dev_err(&data->client->dev, 270 dev_err(&data->client->dev,
268 "unknown ic type %d\n", data->ic_type); 271 "unknown iap version %d\n", data->iap_version);
269 return error; 272 return error;
270 } 273 }
271 274
@@ -353,7 +356,7 @@ static int __elan_update_firmware(struct elan_tp_data *data,
353 iap_start_addr = get_unaligned_le16(&fw->data[ETP_IAP_START_ADDR * 2]); 356 iap_start_addr = get_unaligned_le16(&fw->data[ETP_IAP_START_ADDR * 2]);
354 357
355 boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE; 358 boot_page_count = (iap_start_addr * 2) / ETP_FW_PAGE_SIZE;
356 for (i = boot_page_count; i < data->fw_vaildpage_count; i++) { 359 for (i = boot_page_count; i < data->fw_validpage_count; i++) {
357 u16 checksum = 0; 360 u16 checksum = 0;
358 const u8 *page = &fw->data[i * ETP_FW_PAGE_SIZE]; 361 const u8 *page = &fw->data[i * ETP_FW_PAGE_SIZE];
359 362
@@ -1165,6 +1168,8 @@ MODULE_DEVICE_TABLE(i2c, elan_id);
1165#ifdef CONFIG_ACPI 1168#ifdef CONFIG_ACPI
1166static const struct acpi_device_id elan_acpi_id[] = { 1169static const struct acpi_device_id elan_acpi_id[] = {
1167 { "ELAN0000", 0 }, 1170 { "ELAN0000", 0 },
1171 { "ELAN0100", 0 },
1172 { "ELAN0600", 0 },
1168 { } 1173 { }
1169}; 1174};
1170MODULE_DEVICE_TABLE(acpi, elan_acpi_id); 1175MODULE_DEVICE_TABLE(acpi, elan_acpi_id);
@@ -1181,10 +1186,10 @@ MODULE_DEVICE_TABLE(of, elan_of_match);
1181static struct i2c_driver elan_driver = { 1186static struct i2c_driver elan_driver = {
1182 .driver = { 1187 .driver = {
1183 .name = DRIVER_NAME, 1188 .name = DRIVER_NAME,
1184 .owner = THIS_MODULE,
1185 .pm = &elan_pm_ops, 1189 .pm = &elan_pm_ops,
1186 .acpi_match_table = ACPI_PTR(elan_acpi_id), 1190 .acpi_match_table = ACPI_PTR(elan_acpi_id),
1187 .of_match_table = of_match_ptr(elan_of_match), 1191 .of_match_table = of_match_ptr(elan_of_match),
1192 .probe_type = PROBE_PREFER_ASYNCHRONOUS,
1188 }, 1193 },
1189 .probe = elan_probe, 1194 .probe = elan_probe,
1190 .id_table = elan_id, 1195 .id_table = elan_id,
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index 7c4ba43d253e..ad18dab0ac47 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -47,7 +47,7 @@ MODULE_LICENSE("GPL");
47static unsigned int psmouse_max_proto = PSMOUSE_AUTO; 47static unsigned int psmouse_max_proto = PSMOUSE_AUTO;
48static int psmouse_set_maxproto(const char *val, const struct kernel_param *); 48static int psmouse_set_maxproto(const char *val, const struct kernel_param *);
49static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp); 49static int psmouse_get_maxproto(char *buffer, const struct kernel_param *kp);
50static struct kernel_param_ops param_ops_proto_abbrev = { 50static const struct kernel_param_ops param_ops_proto_abbrev = {
51 .set = psmouse_set_maxproto, 51 .set = psmouse_set_maxproto,
52 .get = psmouse_get_maxproto, 52 .get = psmouse_get_maxproto,
53}; 53};
@@ -1540,6 +1540,10 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1540 if (error) 1540 if (error)
1541 goto err_clear_drvdata; 1541 goto err_clear_drvdata;
1542 1542
1543 /* give PT device some time to settle down before probing */
1544 if (serio->id.type == SERIO_PS_PSTHRU)
1545 usleep_range(10000, 15000);
1546
1543 if (psmouse_probe(psmouse) < 0) { 1547 if (psmouse_probe(psmouse) < 0) {
1544 error = -ENODEV; 1548 error = -ENODEV;
1545 goto err_close_serio; 1549 goto err_close_serio;
diff --git a/drivers/input/mouse/sentelic.c b/drivers/input/mouse/sentelic.c
index cc7e0d4a8f93..11c32ac8234b 100644
--- a/drivers/input/mouse/sentelic.c
+++ b/drivers/input/mouse/sentelic.c
@@ -432,7 +432,7 @@ static int fsp_onpad_hscr(struct psmouse *psmouse, bool enable)
432static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data, 432static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data,
433 const char *buf, size_t count) 433 const char *buf, size_t count)
434{ 434{
435 int reg, val; 435 unsigned int reg, val;
436 char *rest; 436 char *rest;
437 ssize_t retval; 437 ssize_t retval;
438 438
@@ -440,7 +440,7 @@ static ssize_t fsp_attr_set_setreg(struct psmouse *psmouse, void *data,
440 if (rest == buf || *rest != ' ' || reg > 0xff) 440 if (rest == buf || *rest != ' ' || reg > 0xff)
441 return -EINVAL; 441 return -EINVAL;
442 442
443 retval = kstrtoint(rest + 1, 16, &val); 443 retval = kstrtouint(rest + 1, 16, &val);
444 if (retval) 444 if (retval)
445 return retval; 445 return retval;
446 446
@@ -476,9 +476,10 @@ static ssize_t fsp_attr_set_getreg(struct psmouse *psmouse, void *data,
476 const char *buf, size_t count) 476 const char *buf, size_t count)
477{ 477{
478 struct fsp_data *pad = psmouse->private; 478 struct fsp_data *pad = psmouse->private;
479 int reg, val, err; 479 unsigned int reg, val;
480 int err;
480 481
481 err = kstrtoint(buf, 16, &reg); 482 err = kstrtouint(buf, 16, &reg);
482 if (err) 483 if (err)
483 return err; 484 return err;
484 485
@@ -511,9 +512,10 @@ static ssize_t fsp_attr_show_pagereg(struct psmouse *psmouse,
511static ssize_t fsp_attr_set_pagereg(struct psmouse *psmouse, void *data, 512static ssize_t fsp_attr_set_pagereg(struct psmouse *psmouse, void *data,
512 const char *buf, size_t count) 513 const char *buf, size_t count)
513{ 514{
514 int val, err; 515 unsigned int val;
516 int err;
515 517
516 err = kstrtoint(buf, 16, &val); 518 err = kstrtouint(buf, 16, &val);
517 if (err) 519 if (err)
518 return err; 520 return err;
519 521
diff --git a/drivers/input/mouse/synaptics_i2c.c b/drivers/input/mouse/synaptics_i2c.c
index ffceedcaf3c8..aa7c5da60800 100644
--- a/drivers/input/mouse/synaptics_i2c.c
+++ b/drivers/input/mouse/synaptics_i2c.c
@@ -655,7 +655,6 @@ MODULE_DEVICE_TABLE(i2c, synaptics_i2c_id_table);
655static struct i2c_driver synaptics_i2c_driver = { 655static struct i2c_driver synaptics_i2c_driver = {
656 .driver = { 656 .driver = {
657 .name = DRIVER_NAME, 657 .name = DRIVER_NAME,
658 .owner = THIS_MODULE,
659 .pm = &synaptics_i2c_pm, 658 .pm = &synaptics_i2c_pm,
660 }, 659 },
661 660