Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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