File Index
Files and directories
Sign in
FILE

hid-over-spi.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/hid-over-spi.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/* Copyright 2024 Intel Corporation */
  3
  4#ifndef _HID_OVER_SPI_H_
  5#define _HID_OVER_SPI_H_
  6
  7#include <linux/bits.h>
  8#include <linux/types.h>
  9
 10/* Input report type definition in HIDSPI protocol */
 11enum input_report_type {
 12	INVALID_INPUT_REPORT_TYPE_0	= 0,
 13	DATA				= 1,
 14	INVALID_TYPE_2			= 2,
 15	RESET_RESPONSE			= 3,
 16	COMMAND_RESPONSE		= 4,
 17	GET_FEATURE_RESPONSE		= 5,
 18	INVALID_TYPE_6			= 6,
 19	DEVICE_DESCRIPTOR_RESPONSE	= 7,
 20	REPORT_DESCRIPTOR_RESPONSE	= 8,
 21	SET_FEATURE_RESPONSE		= 9,
 22	OUTPUT_REPORT_RESPONSE		= 10,
 23	GET_INPUT_REPORT_RESPONSE	= 11,
 24	INVALID_INPUT_REPORT_TYPE	= 0xF,
 25};
 26
 27/* Output report type definition in HIDSPI protocol */
 28enum output_report_type {
 29	INVALID_OUTPUT_REPORT_TYPE_0	= 0,
 30	DEVICE_DESCRIPTOR		= 1,
 31	REPORT_DESCRIPTOR		= 2,
 32	SET_FEATURE			= 3,
 33	GET_FEATURE			= 4,
 34	OUTPUT_REPORT			= 5,
 35	GET_INPUT_REPORT		= 6,
 36	COMMAND_CONTENT			= 7,
 37};
 38
 39/* Set power command ID for output report */
 40#define HIDSPI_SET_POWER_CMD_ID  1
 41
 42/* Power state definition in HIDSPI protocol */
 43enum hidspi_power_state {
 44	HIDSPI_ON	= 1,
 45	HIDSPI_SLEEP	= 2,
 46	HIDSPI_OFF	= 3,
 47};
 48
 49/**
 50 * Input report header definition in HIDSPI protocol
 51 * Report header size is 32bits, it includes:
 52 * protocol_ver:     [0:3] Current supported HIDSPI protocol version, must be 0x3
 53 * reserved0:        [4:7] Reserved bits
 54 * input_report_len: [8:21] Input report length in number bytes divided by 4
 55 * last_frag_flag:   [22]Indicate if this packet is last fragment.
 56 *                       1 - indicates last fragment
 57 *                       0 - indicates additional fragments
 58 * reserved1:        [23] Reserved bits
 59 * @sync_const:      [24:31] Used to validate input report header, must be 0x5A
 60 */
 61#define HIDSPI_INPUT_HEADER_SIZE		sizeof(u32)
 62#define HIDSPI_INPUT_HEADER_VER			GENMASK(3, 0)
 63#define HIDSPI_INPUT_HEADER_REPORT_LEN		GENMASK(21, 8)
 64#define HIDSPI_INPUT_HEADER_LAST_FLAG		BIT(22)
 65#define HIDSPI_INPUT_HEADER_SYNC		GENMASK(31, 24)
 66
 67/**
 68 * struct input_report_body_header - Input report body header definition in HIDSPI protocol
 69 * @input_report_type: indicate input report type, reference to enum input_report_type
 70 * @content_len: this input report body packet length
 71 * @content_id: indicate this input report's report id
 72 */
 73struct input_report_body_header {
 74	u8 input_report_type;
 75	__le16 content_len;
 76	u8 content_id;
 77} __packed;
 78
 79#define HIDSPI_INPUT_BODY_HEADER_SIZE	sizeof(struct input_report_body_header)
 80
 81/**
 82 * struct input_report_body - Input report body definition in HIDSPI protocol
 83 * @body_hdr: input report body header
 84 * @content: input report body content
 85 */
 86struct input_report_body {
 87	struct input_report_body_header body_hdr;
 88	u8 content[];
 89} __packed;
 90
 91#define HIDSPI_INPUT_BODY_SIZE(content_len)	((content_len) + HIDSPI_INPUT_BODY_HEADER_SIZE)
 92
 93/**
 94 * struct output_report_header - Output report header definition in HIDSPI protocol
 95 * @report_type: output report type, reference to enum output_report_type
 96 * @content_len: length of content
 97 * @content_id: 0x00 - descriptors
 98 *              report id - Set/Feature feature or Input/Output Reports
 99 *              command opcode - for commands
100 */
101struct output_report_header {
102	u8 report_type;
103	__le16 content_len;
104	u8 content_id;
105} __packed;
106
107#define HIDSPI_OUTPUT_REPORT_HEADER_SIZE	sizeof(struct output_report_header)
108
109/**
110 * struct output_report - Output report definition in HIDSPI protocol
111 * @output_hdr: output report header
112 * @content: output report content
113 */
114struct output_report {
115	struct output_report_header output_hdr;
116	u8 content[];
117} __packed;
118
119#define HIDSPI_OUTPUT_REPORT_SIZE(content_len)	((content_len) + HIDSPI_OUTPUT_REPORT_HEADER_SIZE)
120
121/**
122 * struct hidspi_dev_descriptor - HIDSPI device descriptor definition
123 * @dev_desc_len: The length of the complete device descriptor, fixed to 0x18 (24).
124 * @bcd_ver: The version number of the HIDSPI protocol supported.
125 *           In binary coded decimal (BCD) format. Must be fixed to 0x0300.
126 * @rep_desc_len: The length of the report descriptor
127 * @max_input_len: The length of the largest possible HID input (or feature) report
128 * @max_output_len: The length of the largest output (or feature) report
129 * @max_frag_len: The length of the largest fragment, where a fragment represents
130 *                the body of an input report.
131 * @vendor_id: Device manufacturers vendor ID
132 * @product_id: Device unique model/product ID
133 * @version_id: Device’s unique version
134 * @flags: Specify flags for the device’s operation
135 * @reserved: Reserved and should be 0
136 */
137struct hidspi_dev_descriptor {
138	__le16 dev_desc_len;
139	__le16 bcd_ver;
140	__le16 rep_desc_len;
141	__le16 max_input_len;
142	__le16 max_output_len;
143	__le16 max_frag_len;
144	__le16 vendor_id;
145	__le16 product_id;
146	__le16 version_id;
147	__le16 flags;
148	__le32 reserved;
149};
150
151#define HIDSPI_DEVICE_DESCRIPTOR_SIZE		sizeof(struct hidspi_dev_descriptor)
152#define HIDSPI_INPUT_DEVICE_DESCRIPTOR_SIZE	\
153	(HIDSPI_INPUT_BODY_HEADER_SIZE + HIDSPI_DEVICE_DESCRIPTOR_SIZE)
154
155#endif /* _HID_OVER_SPI_H_ */
~/ Read-only file preview.