xref: /linux/drivers/hid/intel-ish-hid/ishtp-hid.h (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * ISHTP-HID glue driver's definitions.
4  *
5  * Copyright (c) 2014-2016, Intel Corporation.
6  */
7 #ifndef ISHTP_HID__H
8 #define	ISHTP_HID__H
9 
10 /* The fixed ISH product and vendor id */
11 #define	ISH_HID_VENDOR	0x8086
12 #define	ISH_HID_PRODUCT	0x22D8
13 #define	ISH_HID_VERSION	0x0200
14 
15 #define	CMD_MASK	0x7F
16 #define	IS_RESPONSE	0x80
17 
18 /* Used to dump to Linux trace buffer, if enabled */
19 extern ishtp_print_log ishtp_hid_print_trace;
20 #define hid_ishtp_trace(client, ...) \
21 	(ishtp_hid_print_trace)(NULL, __VA_ARGS__)
22 
23 /* ISH HID message structure */
24 struct hostif_msg_hdr {
25 	uint8_t	command; /* Bit 7: is_response */
26 	uint8_t	device_id;
27 	uint8_t	status;
28 	uint8_t	flags;
29 	uint16_t size;
30 } __packed;
31 
32 struct hostif_msg {
33 	struct hostif_msg_hdr	hdr;
34 	uint8_t payload[];
35 } __packed;
36 
37 struct hostif_msg_to_sensor {
38 	struct hostif_msg_hdr	hdr;
39 	uint8_t	report_id;
40 } __packed;
41 
42 struct device_info {
43 	uint32_t dev_id;
44 	uint8_t dev_class;
45 	uint16_t pid;
46 	uint16_t vid;
47 } __packed;
48 
49 struct ishtp_version {
50 	uint8_t	major;
51 	uint8_t	minor;
52 	uint8_t	hotfix;
53 	uint16_t build;
54 } __packed;
55 
56 struct report {
57 	uint16_t size;
58 	struct hostif_msg_hdr msg;
59 } __packed;
60 
61 /* struct for ISHTP aggregated input data */
62 struct report_list {
63 	uint16_t total_size;
64 	uint8_t	num_of_reports;
65 	uint8_t	flags;
66 	struct report reports[];
67 } __packed;
68 
69 /* HOSTIF commands */
70 #define	HOSTIF_HID_COMMAND_BASE			0
71 #define	HOSTIF_GET_HID_DESCRIPTOR		0
72 #define	HOSTIF_GET_REPORT_DESCRIPTOR		1
73 #define HOSTIF_GET_FEATURE_REPORT		2
74 #define	HOSTIF_SET_FEATURE_REPORT		3
75 #define	HOSTIF_GET_INPUT_REPORT			4
76 #define	HOSTIF_PUBLISH_INPUT_REPORT		5
77 #define	HOSTIF_PUBLISH_INPUT_REPORT_LIST	6
78 #define	HOSTIF_DM_COMMAND_BASE			32
79 #define	HOSTIF_DM_ENUM_DEVICES			33
80 #define	HOSTIF_DM_ADD_DEVICE			34
81 
82 #define	MAX_HID_DEVICES				32
83 
84 /**
85  * struct ishtp_cl_data - Encapsulate per ISH TP HID Client
86  * @enum_device_done:	Enum devices response complete flag
87  * @hid_descr_done:	HID descriptor complete flag
88  * @report_descr_done:	Get report descriptor complete flag
89  * @init_done:		Init process completed successfully
90  * @suspended:		System is under suspend state or in progress
91  * @num_hid_devices:	Number of HID devices enumerated in this client
92  * @cur_hid_dev:	This keeps track of the device index for which
93  *			initialization and registration with HID core
94  *			in progress.
95  * @hid_devices:	Store vid/pid/devid for each enumerated HID device
96  * @report_descr:	Stores the raw report descriptors for each HID device
97  * @report_descr_size:	Report description of size of above repo_descr[]
98  * @hid_sensor_hubs:	Pointer to hid_device for all HID device, so that
99  *			when clients are removed, they can be freed
100  * @hid_descr:		Pointer to hid descriptor for each enumerated hid
101  *			device
102  * @hid_descr_size:	Size of each above report descriptor
103  * @init_wait:		Wait queue to wait during initialization, where the
104  *			client send message to ISH FW and wait for response
105  * @ishtp_hid_wait:	The wait for get report during wait callback from hid
106  *			core
107  * @bad_recv_cnt:	Running count of packets received with error
108  * @multi_packet_cnt:	Count of fragmented packet count
109  *
110  * This structure is used to store completion flags and per client data like
111  * report description, number of HID devices etc.
112  */
113 struct ishtp_cl_data {
114 	/* completion flags */
115 	bool enum_devices_done;
116 	bool hid_descr_done;
117 	bool report_descr_done;
118 	bool init_done;
119 	bool suspended;
120 
121 	unsigned int num_hid_devices;
122 	unsigned int cur_hid_dev;
123 	unsigned int hid_dev_count;
124 
125 	struct device_info *hid_devices;
126 	unsigned char *report_descr[MAX_HID_DEVICES];
127 	int report_descr_size[MAX_HID_DEVICES];
128 	struct hid_device *hid_sensor_hubs[MAX_HID_DEVICES];
129 	unsigned char *hid_descr[MAX_HID_DEVICES];
130 	int hid_descr_size[MAX_HID_DEVICES];
131 
132 	wait_queue_head_t init_wait;
133 	wait_queue_head_t ishtp_resume_wait;
134 	struct ishtp_cl *hid_ishtp_cl;
135 
136 	/* Statistics */
137 	unsigned int bad_recv_cnt;
138 	int multi_packet_cnt;
139 
140 	struct work_struct work;
141 	struct work_struct resume_work;
142 	struct ishtp_cl_device *cl_device;
143 };
144 
145 /**
146  * struct ishtp_hid_data - Per instance HID data
147  * @index:		Device index in the order of enumeration
148  * @request_done:	Get Feature/Input report complete flag
149  *			used during get/set request from hid core
150  * @client_data:	Link to the client instance
151  * @hid_wait:		Completion waitq
152  *
153  * @raw_get_req:	Flag indicating raw get request ongoing
154  * @raw_buf:		raw request buffer filled on receiving get report
155  * @raw_buf_size:	raw request buffer size
156  * Used to tie hid hid->driver data to driver client instance
157  */
158 struct ishtp_hid_data {
159 	int index;
160 	bool request_done;
161 	struct ishtp_cl_data *client_data;
162 	wait_queue_head_t hid_wait;
163 
164 	/* raw request */
165 	bool raw_get_req;
166 	u8 *raw_buf;
167 	size_t raw_buf_size;
168 };
169 
170 /* Interface functions between HID LL driver and ISH TP client */
171 void hid_ishtp_set_feature(struct hid_device *hid, char *buf, unsigned int len,
172 			   int report_id);
173 void hid_ishtp_get_report(struct hid_device *hid, int report_id,
174 			  int report_type);
175 int ishtp_hid_probe(unsigned int cur_hid_dev,
176 		    struct ishtp_cl_data *client_data);
177 void ishtp_hid_remove(struct ishtp_cl_data *client_data);
178 int ishtp_hid_link_ready_wait(struct ishtp_cl_data *client_data);
179 void ishtp_hid_wakeup(struct hid_device *hid);
180 
181 #endif	/* ISHTP_HID__H */
182