162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * ISHTP-HID glue driver's definitions. 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (c) 2014-2016, Intel Corporation. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci#ifndef ISHTP_HID__H 862306a36Sopenharmony_ci#define ISHTP_HID__H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci/* The fixed ISH product and vendor id */ 1162306a36Sopenharmony_ci#define ISH_HID_VENDOR 0x8086 1262306a36Sopenharmony_ci#define ISH_HID_PRODUCT 0x22D8 1362306a36Sopenharmony_ci#define ISH_HID_VERSION 0x0200 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#define CMD_MASK 0x7F 1662306a36Sopenharmony_ci#define IS_RESPONSE 0x80 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* Used to dump to Linux trace buffer, if enabled */ 1962306a36Sopenharmony_ciextern ishtp_print_log ishtp_hid_print_trace; 2062306a36Sopenharmony_ci#define hid_ishtp_trace(client, ...) \ 2162306a36Sopenharmony_ci (ishtp_hid_print_trace)(NULL, __VA_ARGS__) 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci/* ISH HID message structure */ 2462306a36Sopenharmony_cistruct hostif_msg_hdr { 2562306a36Sopenharmony_ci uint8_t command; /* Bit 7: is_response */ 2662306a36Sopenharmony_ci uint8_t device_id; 2762306a36Sopenharmony_ci uint8_t status; 2862306a36Sopenharmony_ci uint8_t flags; 2962306a36Sopenharmony_ci uint16_t size; 3062306a36Sopenharmony_ci} __packed; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_cistruct hostif_msg { 3362306a36Sopenharmony_ci struct hostif_msg_hdr hdr; 3462306a36Sopenharmony_ci} __packed; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistruct hostif_msg_to_sensor { 3762306a36Sopenharmony_ci struct hostif_msg_hdr hdr; 3862306a36Sopenharmony_ci uint8_t report_id; 3962306a36Sopenharmony_ci} __packed; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_cistruct device_info { 4262306a36Sopenharmony_ci uint32_t dev_id; 4362306a36Sopenharmony_ci uint8_t dev_class; 4462306a36Sopenharmony_ci uint16_t pid; 4562306a36Sopenharmony_ci uint16_t vid; 4662306a36Sopenharmony_ci} __packed; 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_cistruct ishtp_version { 4962306a36Sopenharmony_ci uint8_t major; 5062306a36Sopenharmony_ci uint8_t minor; 5162306a36Sopenharmony_ci uint8_t hotfix; 5262306a36Sopenharmony_ci uint16_t build; 5362306a36Sopenharmony_ci} __packed; 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/* struct for ISHTP aggregated input data */ 5662306a36Sopenharmony_cistruct report_list { 5762306a36Sopenharmony_ci uint16_t total_size; 5862306a36Sopenharmony_ci uint8_t num_of_reports; 5962306a36Sopenharmony_ci uint8_t flags; 6062306a36Sopenharmony_ci struct { 6162306a36Sopenharmony_ci uint16_t size_of_report; 6262306a36Sopenharmony_ci uint8_t report[1]; 6362306a36Sopenharmony_ci } __packed reports[1]; 6462306a36Sopenharmony_ci} __packed; 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* HOSTIF commands */ 6762306a36Sopenharmony_ci#define HOSTIF_HID_COMMAND_BASE 0 6862306a36Sopenharmony_ci#define HOSTIF_GET_HID_DESCRIPTOR 0 6962306a36Sopenharmony_ci#define HOSTIF_GET_REPORT_DESCRIPTOR 1 7062306a36Sopenharmony_ci#define HOSTIF_GET_FEATURE_REPORT 2 7162306a36Sopenharmony_ci#define HOSTIF_SET_FEATURE_REPORT 3 7262306a36Sopenharmony_ci#define HOSTIF_GET_INPUT_REPORT 4 7362306a36Sopenharmony_ci#define HOSTIF_PUBLISH_INPUT_REPORT 5 7462306a36Sopenharmony_ci#define HOSTIF_PUBLISH_INPUT_REPORT_LIST 6 7562306a36Sopenharmony_ci#define HOSTIF_DM_COMMAND_BASE 32 7662306a36Sopenharmony_ci#define HOSTIF_DM_ENUM_DEVICES 33 7762306a36Sopenharmony_ci#define HOSTIF_DM_ADD_DEVICE 34 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci#define MAX_HID_DEVICES 32 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/** 8262306a36Sopenharmony_ci * struct ishtp_cl_data - Encapsulate per ISH TP HID Client 8362306a36Sopenharmony_ci * @enum_device_done: Enum devices response complete flag 8462306a36Sopenharmony_ci * @hid_descr_done: HID descriptor complete flag 8562306a36Sopenharmony_ci * @report_descr_done: Get report descriptor complete flag 8662306a36Sopenharmony_ci * @init_done: Init process completed successfully 8762306a36Sopenharmony_ci * @suspended: System is under suspend state or in progress 8862306a36Sopenharmony_ci * @num_hid_devices: Number of HID devices enumerated in this client 8962306a36Sopenharmony_ci * @cur_hid_dev: This keeps track of the device index for which 9062306a36Sopenharmony_ci * initialization and registration with HID core 9162306a36Sopenharmony_ci * in progress. 9262306a36Sopenharmony_ci * @hid_devices: Store vid/pid/devid for each enumerated HID device 9362306a36Sopenharmony_ci * @report_descr: Stores the raw report descriptors for each HID device 9462306a36Sopenharmony_ci * @report_descr_size: Report description of size of above repo_descr[] 9562306a36Sopenharmony_ci * @hid_sensor_hubs: Pointer to hid_device for all HID device, so that 9662306a36Sopenharmony_ci * when clients are removed, they can be freed 9762306a36Sopenharmony_ci * @hid_descr: Pointer to hid descriptor for each enumerated hid 9862306a36Sopenharmony_ci * device 9962306a36Sopenharmony_ci * @hid_descr_size: Size of each above report descriptor 10062306a36Sopenharmony_ci * @init_wait: Wait queue to wait during initialization, where the 10162306a36Sopenharmony_ci * client send message to ISH FW and wait for response 10262306a36Sopenharmony_ci * @ishtp_hid_wait: The wait for get report during wait callback from hid 10362306a36Sopenharmony_ci * core 10462306a36Sopenharmony_ci * @bad_recv_cnt: Running count of packets received with error 10562306a36Sopenharmony_ci * @multi_packet_cnt: Count of fragmented packet count 10662306a36Sopenharmony_ci * 10762306a36Sopenharmony_ci * This structure is used to store completion flags and per client data like 10862306a36Sopenharmony_ci * report description, number of HID devices etc. 10962306a36Sopenharmony_ci */ 11062306a36Sopenharmony_cistruct ishtp_cl_data { 11162306a36Sopenharmony_ci /* completion flags */ 11262306a36Sopenharmony_ci bool enum_devices_done; 11362306a36Sopenharmony_ci bool hid_descr_done; 11462306a36Sopenharmony_ci bool report_descr_done; 11562306a36Sopenharmony_ci bool init_done; 11662306a36Sopenharmony_ci bool suspended; 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci unsigned int num_hid_devices; 11962306a36Sopenharmony_ci unsigned int cur_hid_dev; 12062306a36Sopenharmony_ci unsigned int hid_dev_count; 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci struct device_info *hid_devices; 12362306a36Sopenharmony_ci unsigned char *report_descr[MAX_HID_DEVICES]; 12462306a36Sopenharmony_ci int report_descr_size[MAX_HID_DEVICES]; 12562306a36Sopenharmony_ci struct hid_device *hid_sensor_hubs[MAX_HID_DEVICES]; 12662306a36Sopenharmony_ci unsigned char *hid_descr[MAX_HID_DEVICES]; 12762306a36Sopenharmony_ci int hid_descr_size[MAX_HID_DEVICES]; 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci wait_queue_head_t init_wait; 13062306a36Sopenharmony_ci wait_queue_head_t ishtp_resume_wait; 13162306a36Sopenharmony_ci struct ishtp_cl *hid_ishtp_cl; 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci /* Statistics */ 13462306a36Sopenharmony_ci unsigned int bad_recv_cnt; 13562306a36Sopenharmony_ci int multi_packet_cnt; 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci struct work_struct work; 13862306a36Sopenharmony_ci struct work_struct resume_work; 13962306a36Sopenharmony_ci struct ishtp_cl_device *cl_device; 14062306a36Sopenharmony_ci}; 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci/** 14362306a36Sopenharmony_ci * struct ishtp_hid_data - Per instance HID data 14462306a36Sopenharmony_ci * @index: Device index in the order of enumeration 14562306a36Sopenharmony_ci * @request_done: Get Feature/Input report complete flag 14662306a36Sopenharmony_ci * used during get/set request from hid core 14762306a36Sopenharmony_ci * @client_data: Link to the client instance 14862306a36Sopenharmony_ci * @hid_wait: Completion waitq 14962306a36Sopenharmony_ci * 15062306a36Sopenharmony_ci * @raw_get_req: Flag indicating raw get request ongoing 15162306a36Sopenharmony_ci * @raw_buf: raw request buffer filled on receiving get report 15262306a36Sopenharmony_ci * @raw_buf_size: raw request buffer size 15362306a36Sopenharmony_ci * Used to tie hid hid->driver data to driver client instance 15462306a36Sopenharmony_ci */ 15562306a36Sopenharmony_cistruct ishtp_hid_data { 15662306a36Sopenharmony_ci int index; 15762306a36Sopenharmony_ci bool request_done; 15862306a36Sopenharmony_ci struct ishtp_cl_data *client_data; 15962306a36Sopenharmony_ci wait_queue_head_t hid_wait; 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci /* raw request */ 16262306a36Sopenharmony_ci bool raw_get_req; 16362306a36Sopenharmony_ci u8 *raw_buf; 16462306a36Sopenharmony_ci size_t raw_buf_size; 16562306a36Sopenharmony_ci}; 16662306a36Sopenharmony_ci 16762306a36Sopenharmony_ci/* Interface functions between HID LL driver and ISH TP client */ 16862306a36Sopenharmony_civoid hid_ishtp_set_feature(struct hid_device *hid, char *buf, unsigned int len, 16962306a36Sopenharmony_ci int report_id); 17062306a36Sopenharmony_civoid hid_ishtp_get_report(struct hid_device *hid, int report_id, 17162306a36Sopenharmony_ci int report_type); 17262306a36Sopenharmony_ciint ishtp_hid_probe(unsigned int cur_hid_dev, 17362306a36Sopenharmony_ci struct ishtp_cl_data *client_data); 17462306a36Sopenharmony_civoid ishtp_hid_remove(struct ishtp_cl_data *client_data); 17562306a36Sopenharmony_ciint ishtp_hid_link_ready_wait(struct ishtp_cl_data *client_data); 17662306a36Sopenharmony_civoid ishtp_hid_wakeup(struct hid_device *hid); 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci#endif /* ISHTP_HID__H */ 179