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