Merge tag 'block-5.13-2021-05-14' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / drivers / input / mouse / elan_i2c.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Elan I2C/SMBus Touchpad driver
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 #ifndef _ELAN_I2C_H
17 #define _ELAN_I2C_H
18
19 #include <linux/types.h>
20
21 #define ETP_ENABLE_ABS          0x0001
22 #define ETP_ENABLE_CALIBRATE    0x0002
23 #define ETP_DISABLE_CALIBRATE   0x0000
24 #define ETP_DISABLE_POWER       0x0001
25 #define ETP_PRESSURE_OFFSET     25
26
27 #define ETP_CALIBRATE_MAX_LEN   3
28
29 #define ETP_FEATURE_REPORT_MK   BIT(0)
30
31 #define ETP_REPORT_ID           0x5D
32 #define ETP_TP_REPORT_ID        0x5E
33 #define ETP_TP_REPORT_ID2       0x5F
34 #define ETP_REPORT_ID2          0x60    /* High precision report */
35
36 #define ETP_REPORT_ID_OFFSET    2
37 #define ETP_TOUCH_INFO_OFFSET   3
38 #define ETP_FINGER_DATA_OFFSET  4
39 #define ETP_HOVER_INFO_OFFSET   30
40 #define ETP_MK_DATA_OFFSET      33      /* For high precision reports */
41
42 #define ETP_MAX_REPORT_LEN      39
43
44 #define ETP_MAX_FINGERS         5
45 #define ETP_FINGER_DATA_LEN     5
46
47 /* IAP Firmware handling */
48 #define ETP_PRODUCT_ID_FORMAT_STRING    "%d.0"
49 #define ETP_FW_NAME             "elan_i2c_" ETP_PRODUCT_ID_FORMAT_STRING ".bin"
50 #define ETP_IAP_START_ADDR      0x0083
51 #define ETP_FW_IAP_PAGE_ERR     (1 << 5)
52 #define ETP_FW_IAP_INTF_ERR     (1 << 4)
53 #define ETP_FW_PAGE_SIZE        64
54 #define ETP_FW_PAGE_SIZE_128    128
55 #define ETP_FW_PAGE_SIZE_512    512
56 #define ETP_FW_SIGNATURE_SIZE   6
57
58 #define ETP_PRODUCT_ID_DELBIN   0x00C2
59 #define ETP_PRODUCT_ID_VOXEL    0x00BF
60 #define ETP_PRODUCT_ID_MAGPIE   0x0120
61 #define ETP_PRODUCT_ID_BOBBA    0x0121
62
63 struct i2c_client;
64 struct completion;
65
66 enum tp_mode {
67         IAP_MODE = 1,
68         MAIN_MODE
69 };
70
71 struct elan_transport_ops {
72         int (*initialize)(struct i2c_client *client);
73         int (*sleep_control)(struct i2c_client *, bool sleep);
74         int (*power_control)(struct i2c_client *, bool enable);
75         int (*set_mode)(struct i2c_client *client, u8 mode);
76
77         int (*calibrate)(struct i2c_client *client);
78         int (*calibrate_result)(struct i2c_client *client, u8 *val);
79
80         int (*get_baseline_data)(struct i2c_client *client,
81                                  bool max_baseline, u8 *value);
82
83         int (*get_version)(struct i2c_client *client, u8 pattern, bool iap,
84                            u8 *version);
85         int (*get_sm_version)(struct i2c_client *client, u8 pattern,
86                               u16 *ic_type, u8 *version, u8 *clickpad);
87         int (*get_checksum)(struct i2c_client *client, bool iap, u16 *csum);
88         int (*get_product_id)(struct i2c_client *client, u16 *id);
89
90         int (*get_max)(struct i2c_client *client,
91                        unsigned int *max_x, unsigned int *max_y);
92         int (*get_resolution)(struct i2c_client *client,
93                               u8 *hw_res_x, u8 *hw_res_y);
94         int (*get_num_traces)(struct i2c_client *client,
95                               unsigned int *x_tracenum,
96                               unsigned int *y_tracenum);
97
98         int (*iap_get_mode)(struct i2c_client *client, enum tp_mode *mode);
99         int (*iap_reset)(struct i2c_client *client);
100
101         int (*prepare_fw_update)(struct i2c_client *client, u16 ic_type,
102                                  u8 iap_version, u16 fw_page_size);
103         int (*write_fw_block)(struct i2c_client *client, u16 fw_page_size,
104                               const u8 *page, u16 checksum, int idx);
105         int (*finish_fw_update)(struct i2c_client *client,
106                                 struct completion *reset_done);
107
108         int (*get_report_features)(struct i2c_client *client, u8 pattern,
109                                    unsigned int *features,
110                                    unsigned int *report_len);
111         int (*get_report)(struct i2c_client *client, u8 *report,
112                           unsigned int report_len);
113         int (*get_pressure_adjustment)(struct i2c_client *client,
114                                        int *adjustment);
115         int (*get_pattern)(struct i2c_client *client, u8 *pattern);
116 };
117
118 extern const struct elan_transport_ops elan_smbus_ops, elan_i2c_ops;
119
120 #endif /* _ELAN_I2C_H */