xref: /openbmc/linux/drivers/input/mouse/elan_i2c.h (revision 2634682f)
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 /* IAP Firmware handling */
32 #define ETP_PRODUCT_ID_FORMAT_STRING	"%d.0"
33 #define ETP_FW_NAME		"elan_i2c_" ETP_PRODUCT_ID_FORMAT_STRING ".bin"
34 #define ETP_IAP_START_ADDR	0x0083
35 #define ETP_FW_IAP_PAGE_ERR	(1 << 5)
36 #define ETP_FW_IAP_INTF_ERR	(1 << 4)
37 #define ETP_FW_PAGE_SIZE	64
38 #define ETP_FW_PAGE_SIZE_128	128
39 #define ETP_FW_PAGE_SIZE_512	512
40 #define ETP_FW_SIGNATURE_SIZE	6
41 
42 struct i2c_client;
43 struct completion;
44 
45 enum tp_mode {
46 	IAP_MODE = 1,
47 	MAIN_MODE
48 };
49 
50 struct elan_transport_ops {
51 	int (*initialize)(struct i2c_client *client);
52 	int (*sleep_control)(struct i2c_client *, bool sleep);
53 	int (*power_control)(struct i2c_client *, bool enable);
54 	int (*set_mode)(struct i2c_client *client, u8 mode);
55 
56 	int (*calibrate)(struct i2c_client *client);
57 	int (*calibrate_result)(struct i2c_client *client, u8 *val);
58 
59 	int (*get_baseline_data)(struct i2c_client *client,
60 				 bool max_baseliune, u8 *value);
61 
62 	int (*get_version)(struct i2c_client *client, u8 pattern, bool iap,
63 			   u8 *version);
64 	int (*get_sm_version)(struct i2c_client *client, u8 pattern,
65 			      u16 *ic_type, u8 *version, u8 *clickpad);
66 	int (*get_checksum)(struct i2c_client *client, bool iap, u16 *csum);
67 	int (*get_product_id)(struct i2c_client *client, u16 *id);
68 
69 	int (*get_max)(struct i2c_client *client,
70 		       unsigned int *max_x, unsigned int *max_y);
71 	int (*get_resolution)(struct i2c_client *client,
72 			      u8 *hw_res_x, u8 *hw_res_y);
73 	int (*get_num_traces)(struct i2c_client *client,
74 			      unsigned int *x_tracenum,
75 			      unsigned int *y_tracenum);
76 
77 	int (*iap_get_mode)(struct i2c_client *client, enum tp_mode *mode);
78 	int (*iap_reset)(struct i2c_client *client);
79 
80 	int (*prepare_fw_update)(struct i2c_client *client, u16 ic_type,
81 				 u8 iap_version);
82 	int (*write_fw_block)(struct i2c_client *client, u16 fw_page_size,
83 			      const u8 *page, u16 checksum, int idx);
84 	int (*finish_fw_update)(struct i2c_client *client,
85 				struct completion *reset_done);
86 
87 	int (*get_report_features)(struct i2c_client *client, u8 pattern,
88 				   unsigned int *features,
89 				   unsigned int *report_len);
90 	int (*get_report)(struct i2c_client *client, u8 *report,
91 			  unsigned int report_len);
92 	int (*get_pressure_adjustment)(struct i2c_client *client,
93 				       int *adjustment);
94 	int (*get_pattern)(struct i2c_client *client, u8 *pattern);
95 };
96 
97 extern const struct elan_transport_ops elan_smbus_ops, elan_i2c_ops;
98 
99 #endif /* _ELAN_I2C_H */
100