xref: /linux/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.h (revision b7d3826c2ed6c3e626e7ae796c5df2c0d2551c6a)
1 /*
2  * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifndef __MT76x02_MCU_H
18 #define __MT76x02_MCU_H
19 
20 #define MT_MCU_RESET_CTL		0x070C
21 #define MT_MCU_INT_LEVEL		0x0718
22 #define MT_MCU_COM_REG0			0x0730
23 #define MT_MCU_COM_REG1			0x0734
24 #define MT_MCU_COM_REG2			0x0738
25 #define MT_MCU_COM_REG3			0x073C
26 
27 #define MT_INBAND_PACKET_MAX_LEN	192
28 #define MT_MCU_MEMMAP_WLAN		0x410000
29 
30 #define MT_MCU_PCIE_REMAP_BASE4		0x074C
31 
32 #define MT_MCU_SEMAPHORE_00		0x07B0
33 #define MT_MCU_SEMAPHORE_01		0x07B4
34 #define MT_MCU_SEMAPHORE_02		0x07B8
35 #define MT_MCU_SEMAPHORE_03		0x07BC
36 
37 #define MT_MCU_ILM_ADDR			0x80000
38 
39 enum mcu_cmd {
40 	CMD_FUN_SET_OP = 1,
41 	CMD_LOAD_CR = 2,
42 	CMD_INIT_GAIN_OP = 3,
43 	CMD_DYNC_VGA_OP = 6,
44 	CMD_TDLS_CH_SW = 7,
45 	CMD_BURST_WRITE = 8,
46 	CMD_READ_MODIFY_WRITE = 9,
47 	CMD_RANDOM_READ = 10,
48 	CMD_BURST_READ = 11,
49 	CMD_RANDOM_WRITE = 12,
50 	CMD_LED_MODE_OP = 16,
51 	CMD_POWER_SAVING_OP = 20,
52 	CMD_WOW_CONFIG = 21,
53 	CMD_WOW_QUERY = 22,
54 	CMD_WOW_FEATURE = 24,
55 	CMD_CARRIER_DETECT_OP = 28,
56 	CMD_RADOR_DETECT_OP = 29,
57 	CMD_SWITCH_CHANNEL_OP = 30,
58 	CMD_CALIBRATION_OP = 31,
59 	CMD_BEACON_OP = 32,
60 	CMD_ANTENNA_OP = 33,
61 };
62 
63 enum mcu_power_mode {
64 	RADIO_OFF = 0x30,
65 	RADIO_ON = 0x31,
66 	RADIO_OFF_AUTO_WAKEUP = 0x32,
67 	RADIO_OFF_ADVANCE = 0x33,
68 	RADIO_ON_ADVANCE = 0x34,
69 };
70 
71 enum mcu_function {
72 	Q_SELECT = 1,
73 	BW_SETTING = 2,
74 	USB2_SW_DISCONNECT = 2,
75 	USB3_SW_DISCONNECT = 3,
76 	LOG_FW_DEBUG_MSG = 4,
77 	GET_FW_VERSION = 5,
78 };
79 
80 struct mt76x02_fw_header {
81 	__le32 ilm_len;
82 	__le32 dlm_len;
83 	__le16 build_ver;
84 	__le16 fw_ver;
85 	u8 pad[4];
86 	char build_time[16];
87 };
88 
89 struct mt76x02_patch_header {
90 	char build_time[16];
91 	char platform[4];
92 	char hw_version[4];
93 	char patch_version[4];
94 	u8 pad[2];
95 };
96 
97 int mt76x02_mcu_cleanup(struct mt76_dev *dev);
98 int mt76x02_mcu_calibrate(struct mt76_dev *dev, int type,
99 			  u32 param, bool wait);
100 struct sk_buff *mt76x02_mcu_msg_alloc(const void *data, int len);
101 int mt76x02_mcu_msg_send(struct mt76_dev *dev, struct sk_buff *skb,
102 			 int cmd, bool wait_resp);
103 int mt76x02_mcu_function_select(struct mt76_dev *dev,
104 				enum mcu_function func,
105 				u32 val, bool wait_resp);
106 int mt76x02_mcu_set_radio_state(struct mt76_dev *dev, bool on,
107 				bool wait_resp);
108 void mt76x02_set_ethtool_fwver(struct mt76_dev *dev,
109 			       const struct mt76x02_fw_header *h);
110 
111 #endif /* __MT76x02_MCU_H */
112