Input: elan_i2c - do not constantly re-query pattern ID
[sfrench/cifs-2.6.git] / drivers / input / mouse / elan_i2c_i2c.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Elan I2C/SMBus Touchpad driver - I2C interface
4  *
5  * Copyright (c) 2013 ELAN Microelectronics Corp.
6  *
7  * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw>
8  *
9  * Based on cyapa driver:
10  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
11  * copyright (c) 2011-2012 Google, Inc.
12  *
13  * Trademarks are the property of their respective owners.
14  */
15
16 #include <linux/completion.h>
17 #include <linux/delay.h>
18 #include <linux/i2c.h>
19 #include <linux/interrupt.h>
20 #include <linux/jiffies.h>
21 #include <linux/kernel.h>
22 #include <linux/slab.h>
23 #include <linux/sched.h>
24 #include <asm/unaligned.h>
25
26 #include "elan_i2c.h"
27
28 /* Elan i2c commands */
29 #define ETP_I2C_RESET                   0x0100
30 #define ETP_I2C_WAKE_UP                 0x0800
31 #define ETP_I2C_SLEEP                   0x0801
32 #define ETP_I2C_DESC_CMD                0x0001
33 #define ETP_I2C_REPORT_DESC_CMD         0x0002
34 #define ETP_I2C_STAND_CMD               0x0005
35 #define ETP_I2C_PATTERN_CMD             0x0100
36 #define ETP_I2C_UNIQUEID_CMD            0x0101
37 #define ETP_I2C_FW_VERSION_CMD          0x0102
38 #define ETP_I2C_IC_TYPE_CMD             0x0103
39 #define ETP_I2C_OSM_VERSION_CMD         0x0103
40 #define ETP_I2C_NSM_VERSION_CMD         0x0104
41 #define ETP_I2C_XY_TRACENUM_CMD         0x0105
42 #define ETP_I2C_MAX_X_AXIS_CMD          0x0106
43 #define ETP_I2C_MAX_Y_AXIS_CMD          0x0107
44 #define ETP_I2C_RESOLUTION_CMD          0x0108
45 #define ETP_I2C_PRESSURE_CMD            0x010A
46 #define ETP_I2C_IAP_VERSION_CMD         0x0110
47 #define ETP_I2C_IC_TYPE_P0_CMD          0x0110
48 #define ETP_I2C_IAP_VERSION_P0_CMD      0x0111
49 #define ETP_I2C_SET_CMD                 0x0300
50 #define ETP_I2C_POWER_CMD               0x0307
51 #define ETP_I2C_FW_CHECKSUM_CMD         0x030F
52 #define ETP_I2C_IAP_CTRL_CMD            0x0310
53 #define ETP_I2C_IAP_CMD                 0x0311
54 #define ETP_I2C_IAP_RESET_CMD           0x0314
55 #define ETP_I2C_IAP_CHECKSUM_CMD        0x0315
56 #define ETP_I2C_CALIBRATE_CMD           0x0316
57 #define ETP_I2C_MAX_BASELINE_CMD        0x0317
58 #define ETP_I2C_MIN_BASELINE_CMD        0x0318
59 #define ETP_I2C_IAP_TYPE_REG            0x0040
60 #define ETP_I2C_IAP_TYPE_CMD            0x0304
61
62 #define ETP_I2C_REPORT_LEN              34
63 #define ETP_I2C_DESC_LENGTH             30
64 #define ETP_I2C_REPORT_DESC_LENGTH      158
65 #define ETP_I2C_INF_LENGTH              2
66 #define ETP_I2C_IAP_PASSWORD            0x1EA5
67 #define ETP_I2C_IAP_RESET               0xF0F0
68 #define ETP_I2C_MAIN_MODE_ON            (1 << 9)
69 #define ETP_I2C_IAP_REG_L               0x01
70 #define ETP_I2C_IAP_REG_H               0x06
71
72 static int elan_i2c_read_block(struct i2c_client *client,
73                                u16 reg, u8 *val, u16 len)
74 {
75         __le16 buf[] = {
76                 cpu_to_le16(reg),
77         };
78         struct i2c_msg msgs[] = {
79                 {
80                         .addr = client->addr,
81                         .flags = client->flags & I2C_M_TEN,
82                         .len = sizeof(buf),
83                         .buf = (u8 *)buf,
84                 },
85                 {
86                         .addr = client->addr,
87                         .flags = (client->flags & I2C_M_TEN) | I2C_M_RD,
88                         .len = len,
89                         .buf = val,
90                 }
91         };
92         int ret;
93
94         ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
95         return ret == ARRAY_SIZE(msgs) ? 0 : (ret < 0 ? ret : -EIO);
96 }
97
98 static int elan_i2c_read_cmd(struct i2c_client *client, u16 reg, u8 *val)
99 {
100         int retval;
101
102         retval = elan_i2c_read_block(client, reg, val, ETP_I2C_INF_LENGTH);
103         if (retval < 0) {
104                 dev_err(&client->dev, "reading cmd (0x%04x) fail.\n", reg);
105                 return retval;
106         }
107
108         return 0;
109 }
110
111 static int elan_i2c_write_cmd(struct i2c_client *client, u16 reg, u16 cmd)
112 {
113         __le16 buf[] = {
114                 cpu_to_le16(reg),
115                 cpu_to_le16(cmd),
116         };
117         struct i2c_msg msg = {
118                 .addr = client->addr,
119                 .flags = client->flags & I2C_M_TEN,
120                 .len = sizeof(buf),
121                 .buf = (u8 *)buf,
122         };
123         int ret;
124
125         ret = i2c_transfer(client->adapter, &msg, 1);
126         if (ret != 1) {
127                 if (ret >= 0)
128                         ret = -EIO;
129                 dev_err(&client->dev, "writing cmd (0x%04x) failed: %d\n",
130                         reg, ret);
131                 return ret;
132         }
133
134         return 0;
135 }
136
137 static int elan_i2c_initialize(struct i2c_client *client)
138 {
139         struct device *dev = &client->dev;
140         int error;
141         u8 val[256];
142
143         error = elan_i2c_write_cmd(client, ETP_I2C_STAND_CMD, ETP_I2C_RESET);
144         if (error) {
145                 dev_err(dev, "device reset failed: %d\n", error);
146                 return error;
147         }
148
149         /* Wait for the device to reset */
150         msleep(100);
151
152         /* get reset acknowledgement 0000 */
153         error = i2c_master_recv(client, val, ETP_I2C_INF_LENGTH);
154         if (error < 0) {
155                 dev_err(dev, "failed to read reset response: %d\n", error);
156                 return error;
157         }
158
159         error = elan_i2c_read_block(client, ETP_I2C_DESC_CMD,
160                                     val, ETP_I2C_DESC_LENGTH);
161         if (error) {
162                 dev_err(dev, "cannot get device descriptor: %d\n", error);
163                 return error;
164         }
165
166         error = elan_i2c_read_block(client, ETP_I2C_REPORT_DESC_CMD,
167                                     val, ETP_I2C_REPORT_DESC_LENGTH);
168         if (error) {
169                 dev_err(dev, "fetching report descriptor failed.: %d\n", error);
170                 return error;
171         }
172
173         return 0;
174 }
175
176 static int elan_i2c_sleep_control(struct i2c_client *client, bool sleep)
177 {
178         return elan_i2c_write_cmd(client, ETP_I2C_STAND_CMD,
179                                   sleep ? ETP_I2C_SLEEP : ETP_I2C_WAKE_UP);
180 }
181
182 static int elan_i2c_power_control(struct i2c_client *client, bool enable)
183 {
184         u8 val[2];
185         u16 reg;
186         int error;
187
188         error = elan_i2c_read_cmd(client, ETP_I2C_POWER_CMD, val);
189         if (error) {
190                 dev_err(&client->dev,
191                         "failed to read current power state: %d\n",
192                         error);
193                 return error;
194         }
195
196         reg = le16_to_cpup((__le16 *)val);
197         if (enable)
198                 reg &= ~ETP_DISABLE_POWER;
199         else
200                 reg |= ETP_DISABLE_POWER;
201
202         error = elan_i2c_write_cmd(client, ETP_I2C_POWER_CMD, reg);
203         if (error) {
204                 dev_err(&client->dev,
205                         "failed to write current power state: %d\n",
206                         error);
207                 return error;
208         }
209
210         return 0;
211 }
212
213 static int elan_i2c_set_mode(struct i2c_client *client, u8 mode)
214 {
215         return elan_i2c_write_cmd(client, ETP_I2C_SET_CMD, mode);
216 }
217
218
219 static int elan_i2c_calibrate(struct i2c_client *client)
220 {
221         return elan_i2c_write_cmd(client, ETP_I2C_CALIBRATE_CMD, 1);
222 }
223
224 static int elan_i2c_calibrate_result(struct i2c_client *client, u8 *val)
225 {
226         return elan_i2c_read_block(client, ETP_I2C_CALIBRATE_CMD, val, 1);
227 }
228
229 static int elan_i2c_get_baseline_data(struct i2c_client *client,
230                                       bool max_baseline, u8 *value)
231 {
232         int error;
233         u8 val[3];
234
235         error = elan_i2c_read_cmd(client,
236                                   max_baseline ? ETP_I2C_MAX_BASELINE_CMD :
237                                                  ETP_I2C_MIN_BASELINE_CMD,
238                                   val);
239         if (error)
240                 return error;
241
242         *value = le16_to_cpup((__le16 *)val);
243
244         return 0;
245 }
246
247 static int elan_i2c_get_pattern(struct i2c_client *client, u8 *pattern)
248 {
249         int error;
250         u8 val[3];
251
252         error = elan_i2c_read_cmd(client, ETP_I2C_PATTERN_CMD, val);
253         if (error) {
254                 dev_err(&client->dev, "failed to get pattern: %d\n", error);
255                 return error;
256         }
257
258         /*
259          * Not all versions of firmware implement "get pattern" command.
260          * When this command is not implemented the device will respond
261          * with 0xFF 0xFF, which we will treat as "old" pattern 0.
262          */
263         *pattern = val[0] == 0xFF && val[1] == 0xFF ? 0 : val[1];
264
265         return 0;
266 }
267
268 static int elan_i2c_get_version(struct i2c_client *client,
269                                 u8 pattern, bool iap, u8 *version)
270 {
271         int error;
272         u16 cmd;
273         u8 val[3];
274
275         if (!iap)
276                 cmd = ETP_I2C_FW_VERSION_CMD;
277         else if (pattern == 0)
278                 cmd = ETP_I2C_IAP_VERSION_P0_CMD;
279         else
280                 cmd = ETP_I2C_IAP_VERSION_CMD;
281
282         error = elan_i2c_read_cmd(client, cmd, val);
283         if (error) {
284                 dev_err(&client->dev, "failed to get %s version: %d\n",
285                         iap ? "IAP" : "FW", error);
286                 return error;
287         }
288
289         if (pattern >= 0x01)
290                 *version = iap ? val[1] : val[0];
291         else
292                 *version = val[0];
293         return 0;
294 }
295
296 static int elan_i2c_get_sm_version(struct i2c_client *client, u8 pattern,
297                                    u16 *ic_type, u8 *version, u8 *clickpad)
298 {
299         int error;
300         u8 val[3];
301
302         if (pattern >= 0x01) {
303                 error = elan_i2c_read_cmd(client, ETP_I2C_IC_TYPE_CMD, val);
304                 if (error) {
305                         dev_err(&client->dev, "failed to get ic type: %d\n",
306                                 error);
307                         return error;
308                 }
309                 *ic_type = be16_to_cpup((__be16 *)val);
310
311                 error = elan_i2c_read_cmd(client, ETP_I2C_NSM_VERSION_CMD,
312                                           val);
313                 if (error) {
314                         dev_err(&client->dev, "failed to get SM version: %d\n",
315                                 error);
316                         return error;
317                 }
318                 *version = val[1];
319                 *clickpad = val[0] & 0x10;
320         } else {
321                 error = elan_i2c_read_cmd(client, ETP_I2C_OSM_VERSION_CMD, val);
322                 if (error) {
323                         dev_err(&client->dev, "failed to get SM version: %d\n",
324                                 error);
325                         return error;
326                 }
327                 *version = val[0];
328
329                 error = elan_i2c_read_cmd(client, ETP_I2C_IC_TYPE_P0_CMD, val);
330                 if (error) {
331                         dev_err(&client->dev, "failed to get ic type: %d\n",
332                                 error);
333                         return error;
334                 }
335                 *ic_type = val[0];
336
337                 error = elan_i2c_read_cmd(client, ETP_I2C_NSM_VERSION_CMD,
338                                           val);
339                 if (error) {
340                         dev_err(&client->dev, "failed to get SM version: %d\n",
341                                 error);
342                         return error;
343                 }
344                 *clickpad = val[0] & 0x10;
345         }
346
347         return 0;
348 }
349
350 static int elan_i2c_get_product_id(struct i2c_client *client, u16 *id)
351 {
352         int error;
353         u8 val[3];
354
355         error = elan_i2c_read_cmd(client, ETP_I2C_UNIQUEID_CMD, val);
356         if (error) {
357                 dev_err(&client->dev, "failed to get product ID: %d\n", error);
358                 return error;
359         }
360
361         *id = le16_to_cpup((__le16 *)val);
362         return 0;
363 }
364
365 static int elan_i2c_get_checksum(struct i2c_client *client,
366                                  bool iap, u16 *csum)
367 {
368         int error;
369         u8 val[3];
370
371         error = elan_i2c_read_cmd(client,
372                                   iap ? ETP_I2C_IAP_CHECKSUM_CMD :
373                                         ETP_I2C_FW_CHECKSUM_CMD,
374                                   val);
375         if (error) {
376                 dev_err(&client->dev, "failed to get %s checksum: %d\n",
377                         iap ? "IAP" : "FW", error);
378                 return error;
379         }
380
381         *csum = le16_to_cpup((__le16 *)val);
382         return 0;
383 }
384
385 static int elan_i2c_get_max(struct i2c_client *client,
386                             unsigned int *max_x, unsigned int *max_y)
387 {
388         int error;
389         u8 val[3];
390
391         error = elan_i2c_read_cmd(client, ETP_I2C_MAX_X_AXIS_CMD, val);
392         if (error) {
393                 dev_err(&client->dev, "failed to get X dimension: %d\n", error);
394                 return error;
395         }
396
397         *max_x = le16_to_cpup((__le16 *)val) & 0x0fff;
398
399         error = elan_i2c_read_cmd(client, ETP_I2C_MAX_Y_AXIS_CMD, val);
400         if (error) {
401                 dev_err(&client->dev, "failed to get Y dimension: %d\n", error);
402                 return error;
403         }
404
405         *max_y = le16_to_cpup((__le16 *)val) & 0x0fff;
406
407         return 0;
408 }
409
410 static int elan_i2c_get_resolution(struct i2c_client *client,
411                                    u8 *hw_res_x, u8 *hw_res_y)
412 {
413         int error;
414         u8 val[3];
415
416         error = elan_i2c_read_cmd(client, ETP_I2C_RESOLUTION_CMD, val);
417         if (error) {
418                 dev_err(&client->dev, "failed to get resolution: %d\n", error);
419                 return error;
420         }
421
422         *hw_res_x = val[0];
423         *hw_res_y = val[1];
424
425         return 0;
426 }
427
428 static int elan_i2c_get_num_traces(struct i2c_client *client,
429                                    unsigned int *x_traces,
430                                    unsigned int *y_traces)
431 {
432         int error;
433         u8 val[3];
434
435         error = elan_i2c_read_cmd(client, ETP_I2C_XY_TRACENUM_CMD, val);
436         if (error) {
437                 dev_err(&client->dev, "failed to get trace info: %d\n", error);
438                 return error;
439         }
440
441         *x_traces = val[0];
442         *y_traces = val[1];
443
444         return 0;
445 }
446
447 static int elan_i2c_get_pressure_adjustment(struct i2c_client *client,
448                                             int *adjustment)
449 {
450         int error;
451         u8 val[3];
452
453         error = elan_i2c_read_cmd(client, ETP_I2C_PRESSURE_CMD, val);
454         if (error) {
455                 dev_err(&client->dev, "failed to get pressure format: %d\n",
456                         error);
457                 return error;
458         }
459
460         if ((val[0] >> 4) & 0x1)
461                 *adjustment = 0;
462         else
463                 *adjustment = ETP_PRESSURE_OFFSET;
464
465         return 0;
466 }
467
468 static int elan_i2c_iap_get_mode(struct i2c_client *client, enum tp_mode *mode)
469 {
470         int error;
471         u16 constant;
472         u8 val[3];
473
474         error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CTRL_CMD, val);
475         if (error) {
476                 dev_err(&client->dev,
477                         "failed to read iap control register: %d\n",
478                         error);
479                 return error;
480         }
481
482         constant = le16_to_cpup((__le16 *)val);
483         dev_dbg(&client->dev, "iap control reg: 0x%04x.\n", constant);
484
485         *mode = (constant & ETP_I2C_MAIN_MODE_ON) ? MAIN_MODE : IAP_MODE;
486
487         return 0;
488 }
489
490 static int elan_i2c_iap_reset(struct i2c_client *client)
491 {
492         int error;
493
494         error = elan_i2c_write_cmd(client, ETP_I2C_IAP_RESET_CMD,
495                                    ETP_I2C_IAP_RESET);
496         if (error) {
497                 dev_err(&client->dev, "cannot reset IC: %d\n", error);
498                 return error;
499         }
500
501         return 0;
502 }
503
504 static int elan_i2c_set_flash_key(struct i2c_client *client)
505 {
506         int error;
507
508         error = elan_i2c_write_cmd(client, ETP_I2C_IAP_CMD,
509                                    ETP_I2C_IAP_PASSWORD);
510         if (error) {
511                 dev_err(&client->dev, "cannot set flash key: %d\n", error);
512                 return error;
513         }
514
515         return 0;
516 }
517
518 static int elan_read_write_iap_type(struct i2c_client *client)
519 {
520         int error;
521         u16 constant;
522         u8 val[3];
523         int retry = 3;
524
525         do {
526                 error = elan_i2c_write_cmd(client, ETP_I2C_IAP_TYPE_CMD,
527                                            ETP_I2C_IAP_TYPE_REG);
528                 if (error) {
529                         dev_err(&client->dev,
530                                 "cannot write iap type: %d\n", error);
531                         return error;
532                 }
533
534                 error = elan_i2c_read_cmd(client, ETP_I2C_IAP_TYPE_CMD, val);
535                 if (error) {
536                         dev_err(&client->dev,
537                                 "failed to read iap type register: %d\n",
538                                 error);
539                         return error;
540                 }
541                 constant = le16_to_cpup((__le16 *)val);
542                 dev_dbg(&client->dev, "iap type reg: 0x%04x\n", constant);
543
544                 if (constant == ETP_I2C_IAP_TYPE_REG)
545                         return 0;
546
547         } while (--retry > 0);
548
549         dev_err(&client->dev, "cannot set iap type\n");
550         return -EIO;
551 }
552
553 static int elan_i2c_prepare_fw_update(struct i2c_client *client, u16 ic_type,
554                                       u8 iap_version)
555 {
556         struct device *dev = &client->dev;
557         int error;
558         enum tp_mode mode;
559         u8 val[3];
560         u16 password;
561
562         /* Get FW in which mode (IAP_MODE/MAIN_MODE)  */
563         error = elan_i2c_iap_get_mode(client, &mode);
564         if (error)
565                 return error;
566
567         if (mode == IAP_MODE) {
568                 /* Reset IC */
569                 error = elan_i2c_iap_reset(client);
570                 if (error)
571                         return error;
572
573                 msleep(30);
574         }
575
576         /* Set flash key*/
577         error = elan_i2c_set_flash_key(client);
578         if (error)
579                 return error;
580
581         /* Wait for F/W IAP initialization */
582         msleep(mode == MAIN_MODE ? 100 : 30);
583
584         /* Check if we are in IAP mode or not */
585         error = elan_i2c_iap_get_mode(client, &mode);
586         if (error)
587                 return error;
588
589         if (mode == MAIN_MODE) {
590                 dev_err(dev, "wrong mode: %d\n", mode);
591                 return -EIO;
592         }
593
594         if (ic_type >= 0x0D && iap_version >= 1) {
595                 error = elan_read_write_iap_type(client);
596                 if (error)
597                         return error;
598         }
599
600         /* Set flash key again */
601         error = elan_i2c_set_flash_key(client);
602         if (error)
603                 return error;
604
605         /* Wait for F/W IAP initialization */
606         msleep(30);
607
608         /* read back to check we actually enabled successfully. */
609         error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CMD, val);
610         if (error) {
611                 dev_err(dev, "cannot read iap password: %d\n",
612                         error);
613                 return error;
614         }
615
616         password = le16_to_cpup((__le16 *)val);
617         if (password != ETP_I2C_IAP_PASSWORD) {
618                 dev_err(dev, "wrong iap password: 0x%X\n", password);
619                 return -EIO;
620         }
621
622         return 0;
623 }
624
625 static int elan_i2c_write_fw_block(struct i2c_client *client, u16 fw_page_size,
626                                    const u8 *page, u16 checksum, int idx)
627 {
628         struct device *dev = &client->dev;
629         u8 *page_store;
630         u8 val[3];
631         u16 result;
632         int ret, error;
633
634         page_store = kmalloc(fw_page_size + 4, GFP_KERNEL);
635         if (!page_store)
636                 return -ENOMEM;
637
638         page_store[0] = ETP_I2C_IAP_REG_L;
639         page_store[1] = ETP_I2C_IAP_REG_H;
640         memcpy(&page_store[2], page, fw_page_size);
641         /* recode checksum at last two bytes */
642         put_unaligned_le16(checksum, &page_store[fw_page_size + 2]);
643
644         ret = i2c_master_send(client, page_store, fw_page_size + 4);
645         if (ret != fw_page_size + 4) {
646                 error = ret < 0 ? ret : -EIO;
647                 dev_err(dev, "Failed to write page %d: %d\n", idx, error);
648                 goto exit;
649         }
650
651         /* Wait for F/W to update one page ROM data. */
652         msleep(fw_page_size == ETP_FW_PAGE_SIZE_512 ? 50 : 35);
653
654         error = elan_i2c_read_cmd(client, ETP_I2C_IAP_CTRL_CMD, val);
655         if (error) {
656                 dev_err(dev, "Failed to read IAP write result: %d\n", error);
657                 goto exit;
658         }
659
660         result = le16_to_cpup((__le16 *)val);
661         if (result & (ETP_FW_IAP_PAGE_ERR | ETP_FW_IAP_INTF_ERR)) {
662                 dev_err(dev, "IAP reports failed write: %04hx\n",
663                         result);
664                 error = -EIO;
665                 goto exit;
666         }
667
668 exit:
669         kfree(page_store);
670         return error;
671 }
672
673 static int elan_i2c_finish_fw_update(struct i2c_client *client,
674                                      struct completion *completion)
675 {
676         struct device *dev = &client->dev;
677         int error;
678         int len;
679         u8 buffer[ETP_I2C_REPORT_LEN];
680
681         len = i2c_master_recv(client, buffer, ETP_I2C_REPORT_LEN);
682         if (len != ETP_I2C_REPORT_LEN) {
683                 error = len < 0 ? len : -EIO;
684                 dev_warn(dev, "failed to read I2C data after FW WDT reset: %d (%d)\n",
685                         error, len);
686         }
687
688         reinit_completion(completion);
689         enable_irq(client->irq);
690
691         error = elan_i2c_write_cmd(client, ETP_I2C_STAND_CMD, ETP_I2C_RESET);
692         if (error) {
693                 dev_err(dev, "device reset failed: %d\n", error);
694         } else if (!wait_for_completion_timeout(completion,
695                                                 msecs_to_jiffies(300))) {
696                 dev_err(dev, "timeout waiting for device reset\n");
697                 error = -ETIMEDOUT;
698         }
699
700         disable_irq(client->irq);
701
702         if (error)
703                 return error;
704
705         len = i2c_master_recv(client, buffer, ETP_I2C_INF_LENGTH);
706         if (len != ETP_I2C_INF_LENGTH) {
707                 error = len < 0 ? len : -EIO;
708                 dev_err(dev, "failed to read INT signal: %d (%d)\n",
709                         error, len);
710                 return error;
711         }
712
713         return 0;
714 }
715
716 static int elan_i2c_get_report(struct i2c_client *client, u8 *report)
717 {
718         int len;
719
720         len = i2c_master_recv(client, report, ETP_I2C_REPORT_LEN);
721         if (len < 0) {
722                 dev_err(&client->dev, "failed to read report data: %d\n", len);
723                 return len;
724         }
725
726         if (len != ETP_I2C_REPORT_LEN) {
727                 dev_err(&client->dev,
728                         "wrong report length (%d vs %d expected)\n",
729                         len, ETP_I2C_REPORT_LEN);
730                 return -EIO;
731         }
732
733         return 0;
734 }
735
736 const struct elan_transport_ops elan_i2c_ops = {
737         .initialize             = elan_i2c_initialize,
738         .sleep_control          = elan_i2c_sleep_control,
739         .power_control          = elan_i2c_power_control,
740         .set_mode               = elan_i2c_set_mode,
741
742         .calibrate              = elan_i2c_calibrate,
743         .calibrate_result       = elan_i2c_calibrate_result,
744
745         .get_baseline_data      = elan_i2c_get_baseline_data,
746
747         .get_version            = elan_i2c_get_version,
748         .get_sm_version         = elan_i2c_get_sm_version,
749         .get_product_id         = elan_i2c_get_product_id,
750         .get_checksum           = elan_i2c_get_checksum,
751         .get_pressure_adjustment = elan_i2c_get_pressure_adjustment,
752
753         .get_max                = elan_i2c_get_max,
754         .get_resolution         = elan_i2c_get_resolution,
755         .get_num_traces         = elan_i2c_get_num_traces,
756
757         .iap_get_mode           = elan_i2c_iap_get_mode,
758         .iap_reset              = elan_i2c_iap_reset,
759
760         .prepare_fw_update      = elan_i2c_prepare_fw_update,
761         .write_fw_block         = elan_i2c_write_fw_block,
762         .finish_fw_update       = elan_i2c_finish_fw_update,
763
764         .get_pattern            = elan_i2c_get_pattern,
765
766         .get_report             = elan_i2c_get_report,
767 };