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