xref: /OK3568_Linux_fs/kernel/drivers/input/mouse/elan_i2c.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Elan I2C/SMBus Touchpad driver
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (c) 2013 ELAN Microelectronics Corp.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Author: 林政維 (Duson Lin) <dusonlin@emc.com.tw>
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * Based on cyapa driver:
10*4882a593Smuzhiyun  * copyright (c) 2011-2012 Cypress Semiconductor, Inc.
11*4882a593Smuzhiyun  * copyright (c) 2011-2012 Google, Inc.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * Trademarks are the property of their respective owners.
14*4882a593Smuzhiyun  */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #ifndef _ELAN_I2C_H
17*4882a593Smuzhiyun #define _ELAN_I2C_H
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include <linux/types.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #define ETP_ENABLE_ABS		0x0001
22*4882a593Smuzhiyun #define ETP_ENABLE_CALIBRATE	0x0002
23*4882a593Smuzhiyun #define ETP_DISABLE_CALIBRATE	0x0000
24*4882a593Smuzhiyun #define ETP_DISABLE_POWER	0x0001
25*4882a593Smuzhiyun #define ETP_PRESSURE_OFFSET	25
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #define ETP_CALIBRATE_MAX_LEN	3
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun #define ETP_FEATURE_REPORT_MK	BIT(0)
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #define ETP_REPORT_ID		0x5D
32*4882a593Smuzhiyun #define ETP_TP_REPORT_ID	0x5E
33*4882a593Smuzhiyun #define ETP_TP_REPORT_ID2	0x5F
34*4882a593Smuzhiyun #define ETP_REPORT_ID2		0x60	/* High precision report */
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define ETP_REPORT_ID_OFFSET	2
37*4882a593Smuzhiyun #define ETP_TOUCH_INFO_OFFSET	3
38*4882a593Smuzhiyun #define ETP_FINGER_DATA_OFFSET	4
39*4882a593Smuzhiyun #define ETP_HOVER_INFO_OFFSET	30
40*4882a593Smuzhiyun #define ETP_MK_DATA_OFFSET	33	/* For high precision reports */
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun #define ETP_MAX_REPORT_LEN	39
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #define ETP_MAX_FINGERS		5
45*4882a593Smuzhiyun #define ETP_FINGER_DATA_LEN	5
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /* IAP Firmware handling */
48*4882a593Smuzhiyun #define ETP_PRODUCT_ID_FORMAT_STRING	"%d.0"
49*4882a593Smuzhiyun #define ETP_FW_NAME		"elan_i2c_" ETP_PRODUCT_ID_FORMAT_STRING ".bin"
50*4882a593Smuzhiyun #define ETP_IAP_START_ADDR	0x0083
51*4882a593Smuzhiyun #define ETP_FW_IAP_PAGE_ERR	(1 << 5)
52*4882a593Smuzhiyun #define ETP_FW_IAP_INTF_ERR	(1 << 4)
53*4882a593Smuzhiyun #define ETP_FW_PAGE_SIZE	64
54*4882a593Smuzhiyun #define ETP_FW_PAGE_SIZE_128	128
55*4882a593Smuzhiyun #define ETP_FW_PAGE_SIZE_512	512
56*4882a593Smuzhiyun #define ETP_FW_SIGNATURE_SIZE	6
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun struct i2c_client;
59*4882a593Smuzhiyun struct completion;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun enum tp_mode {
62*4882a593Smuzhiyun 	IAP_MODE = 1,
63*4882a593Smuzhiyun 	MAIN_MODE
64*4882a593Smuzhiyun };
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun struct elan_transport_ops {
67*4882a593Smuzhiyun 	int (*initialize)(struct i2c_client *client);
68*4882a593Smuzhiyun 	int (*sleep_control)(struct i2c_client *, bool sleep);
69*4882a593Smuzhiyun 	int (*power_control)(struct i2c_client *, bool enable);
70*4882a593Smuzhiyun 	int (*set_mode)(struct i2c_client *client, u8 mode);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	int (*calibrate)(struct i2c_client *client);
73*4882a593Smuzhiyun 	int (*calibrate_result)(struct i2c_client *client, u8 *val);
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	int (*get_baseline_data)(struct i2c_client *client,
76*4882a593Smuzhiyun 				 bool max_baseliune, u8 *value);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	int (*get_version)(struct i2c_client *client, u8 pattern, bool iap,
79*4882a593Smuzhiyun 			   u8 *version);
80*4882a593Smuzhiyun 	int (*get_sm_version)(struct i2c_client *client, u8 pattern,
81*4882a593Smuzhiyun 			      u16 *ic_type, u8 *version, u8 *clickpad);
82*4882a593Smuzhiyun 	int (*get_checksum)(struct i2c_client *client, bool iap, u16 *csum);
83*4882a593Smuzhiyun 	int (*get_product_id)(struct i2c_client *client, u16 *id);
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun 	int (*get_max)(struct i2c_client *client,
86*4882a593Smuzhiyun 		       unsigned int *max_x, unsigned int *max_y);
87*4882a593Smuzhiyun 	int (*get_resolution)(struct i2c_client *client,
88*4882a593Smuzhiyun 			      u8 *hw_res_x, u8 *hw_res_y);
89*4882a593Smuzhiyun 	int (*get_num_traces)(struct i2c_client *client,
90*4882a593Smuzhiyun 			      unsigned int *x_tracenum,
91*4882a593Smuzhiyun 			      unsigned int *y_tracenum);
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	int (*iap_get_mode)(struct i2c_client *client, enum tp_mode *mode);
94*4882a593Smuzhiyun 	int (*iap_reset)(struct i2c_client *client);
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	int (*prepare_fw_update)(struct i2c_client *client, u16 ic_type,
97*4882a593Smuzhiyun 				 u8 iap_version, u16 fw_page_size);
98*4882a593Smuzhiyun 	int (*write_fw_block)(struct i2c_client *client, u16 fw_page_size,
99*4882a593Smuzhiyun 			      const u8 *page, u16 checksum, int idx);
100*4882a593Smuzhiyun 	int (*finish_fw_update)(struct i2c_client *client,
101*4882a593Smuzhiyun 				struct completion *reset_done);
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	int (*get_report_features)(struct i2c_client *client, u8 pattern,
104*4882a593Smuzhiyun 				   unsigned int *features,
105*4882a593Smuzhiyun 				   unsigned int *report_len);
106*4882a593Smuzhiyun 	int (*get_report)(struct i2c_client *client, u8 *report,
107*4882a593Smuzhiyun 			  unsigned int report_len);
108*4882a593Smuzhiyun 	int (*get_pressure_adjustment)(struct i2c_client *client,
109*4882a593Smuzhiyun 				       int *adjustment);
110*4882a593Smuzhiyun 	int (*get_pattern)(struct i2c_client *client, u8 *pattern);
111*4882a593Smuzhiyun };
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun extern const struct elan_transport_ops elan_smbus_ops, elan_i2c_ops;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun #endif /* _ELAN_I2C_H */
116