xref: /freebsd/sys/dev/atopcase/atopcase_reg.h (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2021-2023 Val Packett <val@packett.cool>
5  * Copyright (c) 2023 Vladimir Kondratyev <wulf@FreeBSD.org>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #ifndef _ATOPCASE_REG_H_
30 #define	_ATOPCASE_REG_H_
31 
32 #include <sys/types.h>
33 
34 #define	ATOPCASE_PACKET_SIZE	256
35 #define	ATOPCASE_DATA_SIZE	246
36 #define	ATOPCASE_PKT_PER_MSG	2
37 #define	ATOPCASE_MSG_SIZE	(ATOPCASE_DATA_SIZE * ATOPCASE_PKT_PER_MSG)
38 
39 /* Read == device-initiated, Write == host-initiated or reply to that */
40 #define	ATOPCASE_DIR_READ		0x20
41 #define	ATOPCASE_DIR_WRITE		0x40
42 #define	ATOPCASE_DIR_NOTHING		0x80
43 
44 #define	ATOPCASE_DEV_MGMT		0x00
45 #define	ATOPCASE_DEV_KBRD		0x01
46 #define	ATOPCASE_DEV_TPAD		0x02
47 #define	ATOPCASE_DEV_INFO		0xD0
48 
49 #define	ATOPCASE_BKL_REPORT_ID		0xB0
50 
51 #define	ATOPCASE_INFO_DEVICE		0x01
52 #define	ATOPCASE_INFO_IFACE		0x02
53 #define	ATOPCASE_INFO_DESCRIPTOR	0x10
54 
55 #define	ATOPCASE_MSG_TYPE_SET_REPORT(dev,rid)	((rid << 8) | 0x50 | dev)
56 #define	ATOPCASE_MSG_TYPE_REPORT(dev)		((dev << 8) | 0x10)
57 #define	ATOPCASE_MSG_TYPE_INFO(inf)		((inf << 8) | 0x20)
58 
59 struct atopcase_bl_payload {
60 	uint8_t report_id;
61 	uint8_t device;
62 	uint16_t level;
63 	uint16_t status;
64 } __packed;
65 
66 struct atopcase_device_info_payload {
67 	uint16_t unknown[2];
68 	uint16_t num_devs;
69 	uint16_t vid;
70 	uint16_t pid;
71 	uint16_t ver;
72 	uint16_t vendor_off;
73 	uint16_t vendor_len;
74 	uint16_t product_off;
75 	uint16_t product_len;
76 	uint16_t serial_off;
77 	uint16_t serial_len;
78 } __packed;
79 
80 struct atopcase_iface_info_payload {
81 	uint8_t unknown0;
82 	uint8_t iface_num;
83 	uint8_t unknown1[3];
84 	uint8_t country_code;
85 	uint16_t max_input_report_len;
86 	uint16_t max_output_report_len;
87 	uint16_t max_control_report_len;
88 	uint16_t name_off;
89 	uint16_t name_len;
90 } __packed;
91 
92 struct atopcase_header {
93 	uint16_t type;
94 	uint8_t type_arg; /* means "device" for ATOPCASE_MSG_TYPE_DESCRIPTOR */
95 	uint8_t seq_no;
96 	uint16_t resp_len;
97 	uint16_t len;
98 } __packed;
99 
100 struct atopcase_packet {
101 	uint8_t direction;
102 	uint8_t device;
103 	uint16_t offset;
104 	uint16_t remaining;
105 	uint16_t length;
106 	uint8_t data[ATOPCASE_DATA_SIZE];
107 	uint16_t checksum;
108 } __packed;
109 
110 #endif /* _ATOPCASE_REG_H_ */
111