ishtp-hid.h 5.2 KB

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