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