xref: /freebsd/sys/dev/rtwn/rtl8812a/r12a_rom_image.h (revision a90b9d0159070121c221b966469c3e36d912bf82)
1 /*-
2  * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #ifndef R12A_ROM_IMAGE_H
28 #define R12A_ROM_IMAGE_H
29 
30 #include <dev/rtwn/rtl8812a/r12a_rom_defs.h>
31 
32 #define R12A_DEF_TX_PWR_2G	0x2d
33 #define R12A_DEF_TX_PWR_5G	0xfe
34 
35 struct r12a_tx_pwr_2g {
36 	uint8_t		cck[R12A_GROUP_2G];
37 	uint8_t		ht40[R12A_GROUP_2G - 1];
38 } __packed;
39 
40 struct r12a_tx_pwr_diff_2g {
41 	uint8_t		ht20_ofdm;
42 	struct {
43 		uint8_t	ht40_ht20;
44 		uint8_t	ofdm_cck;
45 	} __packed	diff123[R12A_MAX_TX_COUNT - 1];
46 } __packed;
47 
48 struct r12a_tx_pwr_5g {
49 	uint8_t		ht40[R12A_GROUP_5G];
50 } __packed;
51 
52 struct r12a_tx_pwr_diff_5g {
53 	uint8_t		ht20_ofdm;
54 	uint8_t		ht40_ht20[R12A_MAX_TX_COUNT - 1];
55 	uint8_t		ofdm_ofdm[2];
56 	uint8_t		ht80_ht160[R12A_MAX_TX_COUNT];
57 } __packed;
58 
59 struct r12a_tx_pwr {
60 	struct r12a_tx_pwr_2g		pwr_2g;
61 	struct r12a_tx_pwr_diff_2g	pwr_diff_2g;
62 	struct r12a_tx_pwr_5g		pwr_5g;
63 	struct r12a_tx_pwr_diff_5g	pwr_diff_5g;
64 } __packed;
65 
66 /*
67  * RTL8812AU/RTL8821AU ROM image.
68  */
69 struct r12a_rom {
70 	uint8_t			reserved1[16];
71 	struct r12a_tx_pwr	tx_pwr[R12A_MAX_RF_PATH];
72 	uint8_t			channel_plan;
73 	uint8_t			crystalcap;
74 #define R12A_ROM_CRYSTALCAP_DEF		0x20
75 
76 	uint8_t			thermal_meter;
77 	uint8_t			iqk_lck;
78 	uint8_t			pa_type;
79 #define R12A_ROM_IS_PA_EXT_2GHZ(pa_type)	(((pa_type) & 0x30) == 0x30)
80 #define R12A_ROM_IS_PA_EXT_5GHZ(pa_type)	(((pa_type) & 0x03) == 0x03)
81 #define R21A_ROM_IS_PA_EXT_2GHZ(pa_type)	(((pa_type) & 0x10) == 0x10)
82 #define R21A_ROM_IS_PA_EXT_5GHZ(pa_type)	(((pa_type) & 0x01) == 0x01)
83 
84 	uint8_t			lna_type_2g;
85 #define R12A_ROM_IS_LNA_EXT(lna_type)		(((lna_type) & 0x88) == 0x88)
86 #define R21A_ROM_IS_LNA_EXT(lna_type)		(((lna_type) & 0x08) == 0x08)
87 
88 #define R12A_GET_ROM_PA_TYPE(lna_type, chain)		\
89 	(((lna_type) >> ((chain) * 4 + 2)) & 0x01)
90 #define R12A_GET_ROM_LNA_TYPE(lna_type, chain)	\
91 	(((lna_type) >> ((chain) * 4)) & 0x03)
92 
93 	uint8_t			reserved2;
94 	uint8_t			lna_type_5g;
95 	uint8_t			reserved3;
96 	uint8_t			rf_board_opt;
97 #define R12A_BOARD_TYPE_COMBO_MF	5
98 
99 	uint8_t			rf_feature_opt;
100 	uint8_t			rf_bt_opt;
101 #define R12A_RF_BT_OPT_ANT_NUM		0x01
102 
103 	uint8_t			version;
104 	uint8_t			customer_id;
105 	uint8_t			tx_bbswing_2g;
106 	uint8_t			tx_bbswing_5g;
107 	uint8_t			tx_pwr_calib_rate;
108 	uint8_t			rf_ant_opt;
109 	uint8_t			rfe_option;
110 	uint8_t			reserved4[5];
111 	uint16_t		vid_12a;
112 	uint16_t		pid_12a;
113 	uint8_t			reserved5[3];
114 	uint8_t			macaddr_12a[IEEE80211_ADDR_LEN];
115 	uint8_t			reserved6[2];
116 	uint8_t			string_12a[8];	/* "Realtek " */
117 	uint8_t			reserved7[25];
118 	uint16_t		vid_21a;
119 	uint16_t		pid_21a;
120 	uint8_t			reserved8[3];
121 	uint8_t			macaddr_21a[IEEE80211_ADDR_LEN];
122 	uint8_t			reserved9[2];
123 	uint8_t			string_21a[8];	/* "Realtek " */
124 	uint8_t			reserved10[2];
125 	uint8_t			string_ven[23];	/* XXX variable length? */
126 	uint8_t			reserved11[208];
127 } __packed;
128 
129 _Static_assert(sizeof(struct r12a_rom) == R12A_EFUSE_MAP_LEN,
130     "R12A_EFUSE_MAP_LEN must be equal to sizeof(struct r12a_rom)!");
131 
132 #endif	/* R12A_ROM_IMAGE_H */
133