blob: abdd03ff51acc17d08db950307f27939e8185e2f [file] [log] [blame]
developer42b63282022-06-16 13:33:13 +08001From 31be26088119f67efdc8dcb79c64765abb10d356 Mon Sep 17 00:00:00 2001
developerec4ebe42022-04-12 11:17:45 +08002From: Shayne Chen <shayne.chen@mediatek.com>
developer42b63282022-06-16 13:33:13 +08003Date: Mon, 6 Jun 2022 19:46:26 +0800
4Subject: [PATCH 1/7] mt76: mt7915: rework testmode init registers
developerec4ebe42022-04-12 11:17:45 +08005
6---
7 mt7915/mmio.c | 2 ++
8 mt7915/regs.h | 16 +++++++++++++--
9 mt7915/testmode.c | 52 ++++++++++++++++++++++++++++++++++-------------
10 3 files changed, 54 insertions(+), 16 deletions(-)
11
12diff --git a/mt7915/mmio.c b/mt7915/mmio.c
developer42b63282022-06-16 13:33:13 +080013index 46ee8a7d..71945ba9 100644
developerec4ebe42022-04-12 11:17:45 +080014--- a/mt7915/mmio.c
15+++ b/mt7915/mmio.c
developer42b63282022-06-16 13:33:13 +080016@@ -59,6 +59,7 @@ static const u32 mt7986_reg[] = {
developerec4ebe42022-04-12 11:17:45 +080017 };
18
19 static const u32 mt7915_offs[] = {
20+ [TMAC_TCR2] = 0x05c,
21 [TMAC_CDTR] = 0x090,
22 [TMAC_ODTR] = 0x094,
23 [TMAC_ATCR] = 0x098,
developer42b63282022-06-16 13:33:13 +080024@@ -132,6 +133,7 @@ static const u32 mt7915_offs[] = {
developerec4ebe42022-04-12 11:17:45 +080025 };
26
27 static const u32 mt7916_offs[] = {
28+ [TMAC_TCR2] = 0x004,
29 [TMAC_CDTR] = 0x0c8,
30 [TMAC_ODTR] = 0x0cc,
31 [TMAC_ATCR] = 0x00c,
32diff --git a/mt7915/regs.h b/mt7915/regs.h
developer42b63282022-06-16 13:33:13 +080033index 77fd448b..c7c9e411 100644
developerec4ebe42022-04-12 11:17:45 +080034--- a/mt7915/regs.h
35+++ b/mt7915/regs.h
developer42b63282022-06-16 13:33:13 +080036@@ -36,6 +36,7 @@ enum reg_rev {
developerec4ebe42022-04-12 11:17:45 +080037 };
38
39 enum offs_rev {
40+ TMAC_TCR2,
41 TMAC_CDTR,
42 TMAC_ODTR,
43 TMAC_ATCR,
developer42b63282022-06-16 13:33:13 +080044@@ -185,6 +186,12 @@ enum offs_rev {
45 #define MT_TRB_RXPSR0_RX_WTBL_PTR GENMASK(25, 16)
46 #define MT_TRB_RXPSR0_RX_RMAC_PTR GENMASK(9, 0)
developerec4ebe42022-04-12 11:17:45 +080047
48+#define MT_MDP_TOP_DBG_WDT_CTRL MT_MDP(0x0d0)
49+#define MT_MDP_TOP_DBG_WDT_CTRL_TDP_DIS_BLK BIT(7)
50+
51+#define MT_MDP_TOP_DBG_CTRL MT_MDP(0x0dc)
52+#define MT_MDP_TOP_DBG_CTRL_ENQ_MODE BIT(30)
53+
54 /* TMAC: band 0(0x820e4000), band 1(0x820f4000) */
55 #define MT_WF_TMAC_BASE(_band) ((_band) ? 0x820f4000 : 0x820e4000)
56 #define MT_WF_TMAC(_band, ofs) (MT_WF_TMAC_BASE(_band) + (ofs))
developer42b63282022-06-16 13:33:13 +080057@@ -193,6 +200,9 @@ enum offs_rev {
developerec4ebe42022-04-12 11:17:45 +080058 #define MT_TMAC_TCR0_TX_BLINK GENMASK(7, 6)
59 #define MT_TMAC_TCR0_TBTT_STOP_CTRL BIT(25)
60
61+#define MT_TMAC_TCR2(_band) MT_WF_TMAC(_band, __OFFS(TMAC_TCR2))
62+#define MT_TMAC_TCR2_SCH_DET_DIS BIT(19)
63+
64 #define MT_TMAC_CDTR(_band) MT_WF_TMAC(_band, __OFFS(TMAC_CDTR))
65 #define MT_TMAC_ODTR(_band) MT_WF_TMAC(_band, __OFFS(TMAC_ODTR))
66 #define MT_TIMEOUT_VAL_PLCP GENMASK(15, 0)
developer42b63282022-06-16 13:33:13 +080067@@ -464,8 +474,10 @@ enum offs_rev {
developerec4ebe42022-04-12 11:17:45 +080068 #define MT_AGG_PCR0_VHT_PROT BIT(13)
69 #define MT_AGG_PCR0_PTA_WIN_DIS BIT(15)
70
71-#define MT_AGG_PCR1_RTS0_NUM_THRES GENMASK(31, 23)
72-#define MT_AGG_PCR1_RTS0_LEN_THRES GENMASK(19, 0)
73+#define MT_AGG_PCR1_RTS0_NUM_THRES GENMASK(31, 23)
74+#define MT_AGG_PCR1_RTS0_LEN_THRES GENMASK(19, 0)
75+#define MT_AGG_PCR1_RTS0_NUM_THRES_MT7916 GENMASK(29, 24)
76+#define MT_AGG_PCR1_RTS0_LEN_THRES_MT7916 GENMASK(22, 0)
77
78 #define MT_AGG_ACR0(_band) MT_WF_AGG(_band, __OFFS(AGG_ACR0))
79 #define MT_AGG_ACR_CFEND_RATE GENMASK(13, 0)
80diff --git a/mt7915/testmode.c b/mt7915/testmode.c
81index 20f63644..8d7ec9e8 100644
82--- a/mt7915/testmode.c
83+++ b/mt7915/testmode.c
84@@ -30,7 +30,7 @@ struct reg_band {
85 { _list.band[0] = MT_##_reg(0, _idx); \
86 _list.band[1] = MT_##_reg(1, _idx); }
87
88-#define TM_REG_MAX_ID 17
89+#define TM_REG_MAX_ID 20
90 static struct reg_band reg_backup_list[TM_REG_MAX_ID];
91
92
93@@ -334,7 +334,7 @@ mt7915_tm_reg_backup_restore(struct mt7915_phy *phy)
94 {
95 int n_regs = ARRAY_SIZE(reg_backup_list);
96 struct mt7915_dev *dev = phy->dev;
97- u32 *b = phy->test.reg_backup;
98+ u32 *b = phy->test.reg_backup, val;
99 int i;
100
101 REG_BAND_IDX(reg_backup_list[0], AGG_PCR0, 0);
102@@ -346,18 +346,28 @@ mt7915_tm_reg_backup_restore(struct mt7915_phy *phy)
103 REG_BAND(reg_backup_list[6], AGG_MRCR);
104 REG_BAND(reg_backup_list[7], TMAC_TFCR0);
105 REG_BAND(reg_backup_list[8], TMAC_TCR0);
106- REG_BAND(reg_backup_list[9], AGG_ATCR1);
107- REG_BAND(reg_backup_list[10], AGG_ATCR3);
108- REG_BAND(reg_backup_list[11], TMAC_TRCR0);
109- REG_BAND(reg_backup_list[12], TMAC_ICR0);
110- REG_BAND_IDX(reg_backup_list[13], ARB_DRNGR0, 0);
111- REG_BAND_IDX(reg_backup_list[14], ARB_DRNGR0, 1);
112- REG_BAND(reg_backup_list[15], WF_RFCR);
113- REG_BAND(reg_backup_list[16], WF_RFCR1);
114+ REG_BAND(reg_backup_list[9], TMAC_TCR2);
115+ REG_BAND(reg_backup_list[10], AGG_ATCR1);
116+ REG_BAND(reg_backup_list[11], AGG_ATCR3);
117+ REG_BAND(reg_backup_list[12], TMAC_TRCR0);
118+ REG_BAND(reg_backup_list[13], TMAC_ICR0);
119+ REG_BAND_IDX(reg_backup_list[14], ARB_DRNGR0, 0);
120+ REG_BAND_IDX(reg_backup_list[15], ARB_DRNGR0, 1);
121+ REG_BAND(reg_backup_list[16], WF_RFCR);
122+ REG_BAND(reg_backup_list[17], WF_RFCR1);
123+
124+ if (is_mt7916(&dev->mt76)) {
125+ reg_backup_list[18].band[phy->band_idx] = MT_MDP_TOP_DBG_WDT_CTRL;
126+ reg_backup_list[19].band[phy->band_idx] = MT_MDP_TOP_DBG_CTRL;
127+ }
128
129 if (phy->mt76->test.state == MT76_TM_STATE_OFF) {
130- for (i = 0; i < n_regs; i++)
131- mt76_wr(dev, reg_backup_list[i].band[phy->band_idx], b[i]);
132+ for (i = 0; i < n_regs; i++) {
133+ u8 reg = reg_backup_list[i].band[phy->band_idx];
134+
135+ if (reg)
136+ mt76_wr(dev, reg, b[i]);
137+ }
138 return;
139 }
140
141@@ -377,8 +387,13 @@ mt7915_tm_reg_backup_restore(struct mt7915_phy *phy)
142 MT_AGG_PCR0_BW40_PROT | MT_AGG_PCR0_BW80_PROT);
143 mt76_set(dev, MT_AGG_PCR0(phy->band_idx, 0), MT_AGG_PCR0_PTA_WIN_DIS);
144
145- mt76_wr(dev, MT_AGG_PCR0(phy->band_idx, 1), MT_AGG_PCR1_RTS0_NUM_THRES |
146- MT_AGG_PCR1_RTS0_LEN_THRES);
147+ if (is_mt7915(&dev->mt76))
148+ val = MT_AGG_PCR1_RTS0_NUM_THRES | MT_AGG_PCR1_RTS0_LEN_THRES;
149+ else
150+ val = MT_AGG_PCR1_RTS0_NUM_THRES_MT7916 |
151+ MT_AGG_PCR1_RTS0_LEN_THRES_MT7916;
152+
153+ mt76_wr(dev, MT_AGG_PCR0(phy->band_idx, 1), val);
154
155 mt76_clear(dev, MT_AGG_MRCR(phy->band_idx), MT_AGG_MRCR_BAR_CNT_LIMIT |
156 MT_AGG_MRCR_LAST_RTS_CTS_RN | MT_AGG_MRCR_RTS_FAIL_LIMIT |
157@@ -391,10 +406,19 @@ mt7915_tm_reg_backup_restore(struct mt7915_phy *phy)
158
159 mt76_wr(dev, MT_TMAC_TFCR0(phy->band_idx), 0);
160 mt76_clear(dev, MT_TMAC_TCR0(phy->band_idx), MT_TMAC_TCR0_TBTT_STOP_CTRL);
161+ mt76_set(dev, MT_TMAC_TCR2(phy->band_idx), MT_TMAC_TCR2_SCH_DET_DIS);
162
163 /* config rx filter for testmode rx */
164 mt76_wr(dev, MT_WF_RFCR(phy->band_idx), 0xcf70a);
165 mt76_wr(dev, MT_WF_RFCR1(phy->band_idx), 0);
166+
167+ if (is_mt7916(&dev->mt76)) {
168+ /* enable MDP Tx block mode */
169+ mt76_clear(dev, MT_MDP_TOP_DBG_WDT_CTRL,
170+ MT_MDP_TOP_DBG_WDT_CTRL_TDP_DIS_BLK);
171+ mt76_clear(dev, MT_MDP_TOP_DBG_CTRL,
172+ MT_MDP_TOP_DBG_CTRL_ENQ_MODE);
173+ }
174 }
175
176 static void
177--
1782.18.0
179