Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * ISHTP-HID glue driver's definitions.
0004  *
0005  * Copyright (c) 2014-2016, Intel Corporation.
0006  */
0007 #ifndef ISHTP_HID__H
0008 #define ISHTP_HID__H
0009 
0010 /* The fixed ISH product and vendor id */
0011 #define ISH_HID_VENDOR  0x8086
0012 #define ISH_HID_PRODUCT 0x22D8
0013 #define ISH_HID_VERSION 0x0200
0014 
0015 #define CMD_MASK    0x7F
0016 #define IS_RESPONSE 0x80
0017 
0018 /* Used to dump to Linux trace buffer, if enabled */
0019 extern ishtp_print_log ishtp_hid_print_trace;
0020 #define hid_ishtp_trace(client, ...) \
0021     (ishtp_hid_print_trace)(NULL, __VA_ARGS__)
0022 
0023 /* ISH HID message structure */
0024 struct hostif_msg_hdr {
0025     uint8_t command; /* Bit 7: is_response */
0026     uint8_t device_id;
0027     uint8_t status;
0028     uint8_t flags;
0029     uint16_t size;
0030 } __packed;
0031 
0032 struct hostif_msg {
0033     struct hostif_msg_hdr   hdr;
0034 } __packed;
0035 
0036 struct hostif_msg_to_sensor {
0037     struct hostif_msg_hdr   hdr;
0038     uint8_t report_id;
0039 } __packed;
0040 
0041 struct device_info {
0042     uint32_t dev_id;
0043     uint8_t dev_class;
0044     uint16_t pid;
0045     uint16_t vid;
0046 } __packed;
0047 
0048 struct ishtp_version {
0049     uint8_t major;
0050     uint8_t minor;
0051     uint8_t hotfix;
0052     uint16_t build;
0053 } __packed;
0054 
0055 /* struct for ISHTP aggregated input data */
0056 struct report_list {
0057     uint16_t total_size;
0058     uint8_t num_of_reports;
0059     uint8_t flags;
0060     struct {
0061         uint16_t    size_of_report;
0062         uint8_t report[1];
0063     } __packed reports[1];
0064 } __packed;
0065 
0066 /* HOSTIF commands */
0067 #define HOSTIF_HID_COMMAND_BASE         0
0068 #define HOSTIF_GET_HID_DESCRIPTOR       0
0069 #define HOSTIF_GET_REPORT_DESCRIPTOR        1
0070 #define HOSTIF_GET_FEATURE_REPORT       2
0071 #define HOSTIF_SET_FEATURE_REPORT       3
0072 #define HOSTIF_GET_INPUT_REPORT         4
0073 #define HOSTIF_PUBLISH_INPUT_REPORT     5
0074 #define HOSTIF_PUBLISH_INPUT_REPORT_LIST    6
0075 #define HOSTIF_DM_COMMAND_BASE          32
0076 #define HOSTIF_DM_ENUM_DEVICES          33
0077 #define HOSTIF_DM_ADD_DEVICE            34
0078 
0079 #define MAX_HID_DEVICES             32
0080 
0081 /**
0082  * struct ishtp_cl_data - Encapsulate per ISH TP HID Client
0083  * @enum_device_done:   Enum devices response complete flag
0084  * @hid_descr_done: HID descriptor complete flag
0085  * @report_descr_done:  Get report descriptor complete flag
0086  * @init_done:      Init process completed successfully
0087  * @suspended:      System is under suspend state or in progress
0088  * @num_hid_devices:    Number of HID devices enumerated in this client
0089  * @cur_hid_dev:    This keeps track of the device index for which
0090  *          initialization and registration with HID core
0091  *          in progress.
0092  * @hid_devices:    Store vid/pid/devid for each enumerated HID device
0093  * @report_descr:   Stores the raw report descriptors for each HID device
0094  * @report_descr_size:  Report description of size of above repo_descr[]
0095  * @hid_sensor_hubs:    Pointer to hid_device for all HID device, so that
0096  *          when clients are removed, they can be freed
0097  * @hid_descr:      Pointer to hid descriptor for each enumerated hid
0098  *          device
0099  * @hid_descr_size: Size of each above report descriptor
0100  * @init_wait:      Wait queue to wait during initialization, where the
0101  *          client send message to ISH FW and wait for response
0102  * @ishtp_hid_wait: The wait for get report during wait callback from hid
0103  *          core
0104  * @bad_recv_cnt:   Running count of packets received with error
0105  * @multi_packet_cnt:   Count of fragmented packet count
0106  *
0107  * This structure is used to store completion flags and per client data like
0108  * report description, number of HID devices etc.
0109  */
0110 struct ishtp_cl_data {
0111     /* completion flags */
0112     bool enum_devices_done;
0113     bool hid_descr_done;
0114     bool report_descr_done;
0115     bool init_done;
0116     bool suspended;
0117 
0118     unsigned int num_hid_devices;
0119     unsigned int cur_hid_dev;
0120     unsigned int hid_dev_count;
0121 
0122     struct device_info *hid_devices;
0123     unsigned char *report_descr[MAX_HID_DEVICES];
0124     int report_descr_size[MAX_HID_DEVICES];
0125     struct hid_device *hid_sensor_hubs[MAX_HID_DEVICES];
0126     unsigned char *hid_descr[MAX_HID_DEVICES];
0127     int hid_descr_size[MAX_HID_DEVICES];
0128 
0129     wait_queue_head_t init_wait;
0130     wait_queue_head_t ishtp_resume_wait;
0131     struct ishtp_cl *hid_ishtp_cl;
0132 
0133     /* Statistics */
0134     unsigned int bad_recv_cnt;
0135     int multi_packet_cnt;
0136 
0137     struct work_struct work;
0138     struct work_struct resume_work;
0139     struct ishtp_cl_device *cl_device;
0140 };
0141 
0142 /**
0143  * struct ishtp_hid_data - Per instance HID data
0144  * @index:      Device index in the order of enumeration
0145  * @request_done:   Get Feature/Input report complete flag
0146  *          used during get/set request from hid core
0147  * @client_data:    Link to the client instance
0148  * @hid_wait:       Completion waitq
0149  *
0150  * @raw_get_req:    Flag indicating raw get request ongoing
0151  * @raw_buf:        raw request buffer filled on receiving get report
0152  * @raw_buf_size:   raw request buffer size
0153  * Used to tie hid hid->driver data to driver client instance
0154  */
0155 struct ishtp_hid_data {
0156     int index;
0157     bool request_done;
0158     struct ishtp_cl_data *client_data;
0159     wait_queue_head_t hid_wait;
0160 
0161     /* raw request */
0162     bool raw_get_req;
0163     u8 *raw_buf;
0164     size_t raw_buf_size;
0165 };
0166 
0167 /* Interface functions between HID LL driver and ISH TP client */
0168 void hid_ishtp_set_feature(struct hid_device *hid, char *buf, unsigned int len,
0169                int report_id);
0170 void hid_ishtp_get_report(struct hid_device *hid, int report_id,
0171               int report_type);
0172 int ishtp_hid_probe(unsigned int cur_hid_dev,
0173             struct ishtp_cl_data *client_data);
0174 void ishtp_hid_remove(struct ishtp_cl_data *client_data);
0175 int ishtp_hid_link_ready_wait(struct ishtp_cl_data *client_data);
0176 void ishtp_hid_wakeup(struct hid_device *hid);
0177 
0178 #endif  /* ISHTP_HID__H */