xref: /linux/drivers/net/wireless/mediatek/mt76/mt76x02_mcu.h (revision f320d812b7bbd30abb5699971051e8b494df6278)
10e3d6777SRyder Lee /* SPDX-License-Identifier: ISC */
2dce9dc8dSLorenzo Bianconi /*
3dce9dc8dSLorenzo Bianconi  * Copyright (C) 2018 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
4dce9dc8dSLorenzo Bianconi  */
5dce9dc8dSLorenzo Bianconi 
6dce9dc8dSLorenzo Bianconi #ifndef __MT76x02_MCU_H
7e3469c5eSColin Ian King #define __MT76x02_MCU_H
8dce9dc8dSLorenzo Bianconi 
9499cd0aaSLorenzo Bianconi #include "mt76x02.h"
10499cd0aaSLorenzo Bianconi 
11dce9dc8dSLorenzo Bianconi #define MT_MCU_RESET_CTL		0x070C
12dce9dc8dSLorenzo Bianconi #define MT_MCU_INT_LEVEL		0x0718
13dce9dc8dSLorenzo Bianconi #define MT_MCU_COM_REG0			0x0730
14dce9dc8dSLorenzo Bianconi #define MT_MCU_COM_REG1			0x0734
15dce9dc8dSLorenzo Bianconi #define MT_MCU_COM_REG2			0x0738
16dce9dc8dSLorenzo Bianconi #define MT_MCU_COM_REG3			0x073C
17dce9dc8dSLorenzo Bianconi 
18dce9dc8dSLorenzo Bianconi #define MT_INBAND_PACKET_MAX_LEN	192
19dce9dc8dSLorenzo Bianconi #define MT_MCU_MEMMAP_WLAN		0x410000
20dce9dc8dSLorenzo Bianconi 
21db2803bbSLorenzo Bianconi #define MT_MCU_PCIE_REMAP_BASE4		0x074C
22db2803bbSLorenzo Bianconi 
23db2803bbSLorenzo Bianconi #define MT_MCU_SEMAPHORE_00		0x07B0
24db2803bbSLorenzo Bianconi #define MT_MCU_SEMAPHORE_01		0x07B4
25db2803bbSLorenzo Bianconi #define MT_MCU_SEMAPHORE_02		0x07B8
26db2803bbSLorenzo Bianconi #define MT_MCU_SEMAPHORE_03		0x07BC
27db2803bbSLorenzo Bianconi 
28db2803bbSLorenzo Bianconi #define MT_MCU_ILM_ADDR			0x80000
29db2803bbSLorenzo Bianconi 
30dce9dc8dSLorenzo Bianconi enum mcu_cmd {
31dce9dc8dSLorenzo Bianconi 	CMD_FUN_SET_OP = 1,
32dce9dc8dSLorenzo Bianconi 	CMD_LOAD_CR = 2,
33dce9dc8dSLorenzo Bianconi 	CMD_INIT_GAIN_OP = 3,
34dce9dc8dSLorenzo Bianconi 	CMD_DYNC_VGA_OP = 6,
35dce9dc8dSLorenzo Bianconi 	CMD_TDLS_CH_SW = 7,
36dce9dc8dSLorenzo Bianconi 	CMD_BURST_WRITE = 8,
37dce9dc8dSLorenzo Bianconi 	CMD_READ_MODIFY_WRITE = 9,
38dce9dc8dSLorenzo Bianconi 	CMD_RANDOM_READ = 10,
39dce9dc8dSLorenzo Bianconi 	CMD_BURST_READ = 11,
40dce9dc8dSLorenzo Bianconi 	CMD_RANDOM_WRITE = 12,
41dce9dc8dSLorenzo Bianconi 	CMD_LED_MODE_OP = 16,
42dce9dc8dSLorenzo Bianconi 	CMD_POWER_SAVING_OP = 20,
43dce9dc8dSLorenzo Bianconi 	CMD_WOW_CONFIG = 21,
44dce9dc8dSLorenzo Bianconi 	CMD_WOW_QUERY = 22,
45dce9dc8dSLorenzo Bianconi 	CMD_WOW_FEATURE = 24,
46dce9dc8dSLorenzo Bianconi 	CMD_CARRIER_DETECT_OP = 28,
47dce9dc8dSLorenzo Bianconi 	CMD_RADOR_DETECT_OP = 29,
48dce9dc8dSLorenzo Bianconi 	CMD_SWITCH_CHANNEL_OP = 30,
49dce9dc8dSLorenzo Bianconi 	CMD_CALIBRATION_OP = 31,
50dce9dc8dSLorenzo Bianconi 	CMD_BEACON_OP = 32,
51dce9dc8dSLorenzo Bianconi 	CMD_ANTENNA_OP = 33,
52dce9dc8dSLorenzo Bianconi };
53dce9dc8dSLorenzo Bianconi 
54dce9dc8dSLorenzo Bianconi enum mcu_power_mode {
55dce9dc8dSLorenzo Bianconi 	RADIO_OFF = 0x30,
56dce9dc8dSLorenzo Bianconi 	RADIO_ON = 0x31,
57dce9dc8dSLorenzo Bianconi 	RADIO_OFF_AUTO_WAKEUP = 0x32,
58dce9dc8dSLorenzo Bianconi 	RADIO_OFF_ADVANCE = 0x33,
59dce9dc8dSLorenzo Bianconi 	RADIO_ON_ADVANCE = 0x34,
60dce9dc8dSLorenzo Bianconi };
61dce9dc8dSLorenzo Bianconi 
62dce9dc8dSLorenzo Bianconi enum mcu_function {
63dce9dc8dSLorenzo Bianconi 	Q_SELECT = 1,
64dce9dc8dSLorenzo Bianconi 	BW_SETTING = 2,
65dce9dc8dSLorenzo Bianconi 	USB2_SW_DISCONNECT = 2,
66dce9dc8dSLorenzo Bianconi 	USB3_SW_DISCONNECT = 3,
67dce9dc8dSLorenzo Bianconi 	LOG_FW_DEBUG_MSG = 4,
68dce9dc8dSLorenzo Bianconi 	GET_FW_VERSION = 5,
69dce9dc8dSLorenzo Bianconi };
70dce9dc8dSLorenzo Bianconi 
7179394f40SLorenzo Bianconi struct mt76x02_fw_header {
7279394f40SLorenzo Bianconi 	__le32 ilm_len;
7379394f40SLorenzo Bianconi 	__le32 dlm_len;
7479394f40SLorenzo Bianconi 	__le16 build_ver;
7579394f40SLorenzo Bianconi 	__le16 fw_ver;
7679394f40SLorenzo Bianconi 	u8 pad[4];
7779394f40SLorenzo Bianconi 	char build_time[16];
7879394f40SLorenzo Bianconi };
7979394f40SLorenzo Bianconi 
8079394f40SLorenzo Bianconi struct mt76x02_patch_header {
8179394f40SLorenzo Bianconi 	char build_time[16];
8279394f40SLorenzo Bianconi 	char platform[4];
8379394f40SLorenzo Bianconi 	char hw_version[4];
8479394f40SLorenzo Bianconi 	char patch_version[4];
8579394f40SLorenzo Bianconi 	u8 pad[2];
8679394f40SLorenzo Bianconi };
8779394f40SLorenzo Bianconi 
88499cd0aaSLorenzo Bianconi int mt76x02_mcu_cleanup(struct mt76x02_dev *dev);
894ece1e0aSStanislaw Gruszka int mt76x02_mcu_calibrate(struct mt76x02_dev *dev, int type, u32 param);
90a74d6336SStanislaw Gruszka int mt76x02_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
91a74d6336SStanislaw Gruszka 			 int len, bool wait_resp);
92*f320d812SFelix Fietkau int mt76x02_mcu_parse_response(struct mt76_dev *mdev, int cmd,
93*f320d812SFelix Fietkau 			       struct sk_buff *skb, int seq);
943d2d61b5SStanislaw Gruszka int mt76x02_mcu_function_select(struct mt76x02_dev *dev, enum mcu_function func,
953d2d61b5SStanislaw Gruszka 				u32 val);
96c6950536SStanislaw Gruszka int mt76x02_mcu_set_radio_state(struct mt76x02_dev *dev, bool on);
97499cd0aaSLorenzo Bianconi void mt76x02_set_ethtool_fwver(struct mt76x02_dev *dev,
9822509324SDavide Caratti 			       const struct mt76x02_fw_header *h);
9936fd09ddSLorenzo Bianconi 
100dce9dc8dSLorenzo Bianconi #endif /* __MT76x02_MCU_H */
101