2 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
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.
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.
17 #ifndef __MT76x2_MCU_H
18 #define __MT76x2_MCU_H
20 /* Register definitions */
21 #define MT_MCU_CPU_CTL 0x0704
22 #define MT_MCU_CLOCK_CTL 0x0708
23 #define MT_MCU_RESET_CTL 0x070C
24 #define MT_MCU_INT_LEVEL 0x0718
25 #define MT_MCU_COM_REG0 0x0730
26 #define MT_MCU_COM_REG1 0x0734
27 #define MT_MCU_COM_REG2 0x0738
28 #define MT_MCU_COM_REG3 0x073C
29 #define MT_MCU_PCIE_REMAP_BASE1 0x0740
30 #define MT_MCU_PCIE_REMAP_BASE2 0x0744
31 #define MT_MCU_PCIE_REMAP_BASE3 0x0748
32 #define MT_MCU_PCIE_REMAP_BASE4 0x074C
34 #define MT_LED_CTRL 0x0770
35 #define MT_LED_CTRL_REPLAY(_n) BIT(0 + (8 * (_n)))
36 #define MT_LED_CTRL_POLARITY(_n) BIT(1 + (8 * (_n)))
37 #define MT_LED_CTRL_TX_BLINK_MODE(_n) BIT(2 + (8 * (_n)))
38 #define MT_LED_CTRL_KICK(_n) BIT(7 + (8 * (_n)))
40 #define MT_LED_TX_BLINK_0 0x0774
41 #define MT_LED_TX_BLINK_1 0x0778
43 #define MT_LED_S0_BASE 0x077C
44 #define MT_LED_S0(_n) (MT_LED_S0_BASE + 8 * (_n))
45 #define MT_LED_S1_BASE 0x0780
46 #define MT_LED_S1(_n) (MT_LED_S1_BASE + 8 * (_n))
47 #define MT_LED_STATUS_OFF_MASK GENMASK(31, 24)
48 #define MT_LED_STATUS_OFF(_v) (((_v) << __ffs(MT_LED_STATUS_OFF_MASK)) & \
49 MT_LED_STATUS_OFF_MASK)
50 #define MT_LED_STATUS_ON_MASK GENMASK(23, 16)
51 #define MT_LED_STATUS_ON(_v) (((_v) << __ffs(MT_LED_STATUS_ON_MASK)) & \
52 MT_LED_STATUS_ON_MASK)
53 #define MT_LED_STATUS_DURATION_MASK GENMASK(15, 8)
54 #define MT_LED_STATUS_DURATION(_v) (((_v) << __ffs(MT_LED_STATUS_DURATION_MASK)) & \
55 MT_LED_STATUS_DURATION_MASK)
57 #define MT_MCU_SEMAPHORE_00 0x07B0
58 #define MT_MCU_SEMAPHORE_01 0x07B4
59 #define MT_MCU_SEMAPHORE_02 0x07B8
60 #define MT_MCU_SEMAPHORE_03 0x07BC
62 #define MT_MCU_ROM_PATCH_OFFSET 0x80000
63 #define MT_MCU_ROM_PATCH_ADDR 0x90000
65 #define MT_MCU_ILM_OFFSET 0x80000
66 #define MT_MCU_ILM_ADDR 0x80000
68 #define MT_MCU_DLM_OFFSET 0x100000
69 #define MT_MCU_DLM_ADDR 0x90000
70 #define MT_MCU_DLM_ADDR_E3 0x90800
79 CMD_READ_MODIFY_WRITE = 9,
82 CMD_RANDOM_WRITE = 12,
84 CMD_POWER_SAVING_OP = 20,
88 CMD_CARRIER_DETECT_OP = 28,
89 CMD_RADOR_DETECT_OP = 29,
90 CMD_SWITCH_CHANNEL_OP = 30,
91 CMD_CALIBRATION_OP = 31,
99 USB2_SW_DISCONNECT = 2,
100 USB3_SW_DISCONNECT = 3,
101 LOG_FW_DEBUG_MSG = 4,
105 enum mcu_power_mode {
108 RADIO_OFF_AUTO_WAKEUP = 0x32,
109 RADIO_OFF_ADVANCE = 0x33,
110 RADIO_ON_ADVANCE = 0x34,
113 enum mcu_calibration {
131 enum mt76x2_mcu_cr_mode {
135 MT_HL_TEMP_CR_UPDATE,
138 struct mt76x2_tssi_comp {
147 } __packed __aligned(4);
149 int mt76x2_mcu_calibrate(struct mt76x2_dev *dev, enum mcu_calibration type,
151 int mt76x2_mcu_tssi_comp(struct mt76x2_dev *dev, struct mt76x2_tssi_comp *tssi_data);
152 int mt76x2_mcu_init_gain(struct mt76x2_dev *dev, u8 channel, u32 gain,