36f438b82150e0a556dfb22dc6ae1455ab10b685
[pandora-kernel.git] / drivers / staging / rt2860 / chip / rtmp_phy.h
1 /*
2  *************************************************************************
3  * Ralink Tech Inc.
4  * 5F., No.36, Taiyuan St., Jhubei City,
5  * Hsinchu County 302,
6  * Taiwan, R.O.C.
7  *
8  * (c) Copyright 2002-2007, Ralink Technology, Inc.
9  *
10  * This program is free software; you can redistribute it and/or modify  *
11  * it under the terms of the GNU General Public License as published by  *
12  * the Free Software Foundation; either version 2 of the License, or     *
13  * (at your option) any later version.                                   *
14  *                                                                       *
15  * This program is distributed in the hope that it will be useful,       *
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  * GNU General Public License for more details.                          *
19  *                                                                       *
20  * You should have received a copy of the GNU General Public License     *
21  * along with this program; if not, write to the                         *
22  * Free Software Foundation, Inc.,                                       *
23  * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
24  *                                                                       *
25  *************************************************************************
26
27         Module Name:
28         rtmp_phy.h
29
30         Abstract:
31         Ralink Wireless Chip PHY(BBP/RF) related definition & structures
32
33         Revision History:
34         Who                     When              What
35         --------        ----------        ----------------------------------------------
36 */
37
38 #ifndef __RTMP_PHY_H__
39 #define __RTMP_PHY_H__
40
41
42 /*
43         RF sections
44 */
45 #define RF_R00                  0
46 #define RF_R01                  1
47 #define RF_R02                  2
48 #define RF_R03                  3
49 #define RF_R04                  4
50 #define RF_R05                  5
51 #define RF_R06                  6
52 #define RF_R07                  7
53 #define RF_R08                  8
54 #define RF_R09                  9
55 #define RF_R10                  10
56 #define RF_R11                  11
57 #define RF_R12                  12
58 #define RF_R13                  13
59 #define RF_R14                  14
60 #define RF_R15                  15
61 #define RF_R16                  16
62 #define RF_R17                  17
63 #define RF_R18                  18
64 #define RF_R19                  19
65 #define RF_R20                  20
66 #define RF_R21                  21
67 #define RF_R22                  22
68 #define RF_R23                  23
69 #define RF_R24                  24
70 #define RF_R25                  25
71 #define RF_R26                  26
72 #define RF_R27                  27
73 #define RF_R28                  28
74 #define RF_R29                  29
75 #define RF_R30                  30
76 #define RF_R31                  31
77
78
79 // value domain of pAd->RfIcType
80 #define RFIC_2820                   1       // 2.4G 2T3R
81 #define RFIC_2850                   2       // 2.4G/5G 2T3R
82 #define RFIC_2720                   3       // 2.4G 1T2R
83 #define RFIC_2750                   4       // 2.4G/5G 1T2R
84 #define RFIC_3020                   5       // 2.4G 1T1R
85 #define RFIC_2020                   6       // 2.4G B/G
86 #define RFIC_3021                   7       // 2.4G 1T2R
87 #define RFIC_3022                   8       // 2.4G 2T2R
88 #define RFIC_3052                   9       // 2.4G/5G 2T2R
89
90 /*
91         BBP sections
92 */
93 #define BBP_R0                  0  // version
94 #define BBP_R1                  1  // TSSI
95 #define BBP_R2                  2  // TX configure
96 #define BBP_R3                  3
97 #define BBP_R4                  4
98 #define BBP_R5                  5
99 #define BBP_R6                  6
100 #define BBP_R14                 14 // RX configure
101 #define BBP_R16                 16
102 #define BBP_R17                 17 // RX sensibility
103 #define BBP_R18                 18
104 #define BBP_R21                 21
105 #define BBP_R22                 22
106 #define BBP_R24                 24
107 #define BBP_R25                 25
108 #define BBP_R26                 26
109 #define BBP_R27                 27
110 #define BBP_R31                 31
111 #define BBP_R49                 49 //TSSI
112 #define BBP_R50                 50
113 #define BBP_R51                 51
114 #define BBP_R52                 52
115 #define BBP_R55                 55
116 #define BBP_R62                 62 // Rx SQ0 Threshold HIGH
117 #define BBP_R63                 63
118 #define BBP_R64                 64
119 #define BBP_R65                 65
120 #define BBP_R66                 66
121 #define BBP_R67                 67
122 #define BBP_R68                 68
123 #define BBP_R69                 69
124 #define BBP_R70                 70 // Rx AGC SQ CCK Xcorr threshold
125 #define BBP_R73                 73
126 #define BBP_R75                 75
127 #define BBP_R77                 77
128 #define BBP_R78                 78
129 #define BBP_R79                 79
130 #define BBP_R80                 80
131 #define BBP_R81                 81
132 #define BBP_R82                 82
133 #define BBP_R83                 83
134 #define BBP_R84                 84
135 #define BBP_R86                 86
136 #define BBP_R91                 91
137 #define BBP_R92                 92
138 #define BBP_R94                 94 // Tx Gain Control
139 #define BBP_R103                103
140 #define BBP_R105                105
141 #define BBP_R106                106
142 #define BBP_R113                113
143 #define BBP_R114                114
144 #define BBP_R115                115
145 #define BBP_R116                116
146 #define BBP_R117                117
147 #define BBP_R118                118
148 #define BBP_R119                119
149 #define BBP_R120                120
150 #define BBP_R121                121
151 #define BBP_R122                122
152 #define BBP_R123                123
153 #ifdef RT30xx
154 #define BBP_R138                138 // add by johnli, RF power sequence setup, ADC dynamic on/off control
155 #endif // RT30xx //
156
157 #define BBPR94_DEFAULT  0x06 // Add 1 value will gain 1db
158
159 //
160 // BBP & RF are using indirect access. Before write any value into it.
161 // We have to make sure there is no outstanding command pending via checking busy bit.
162 //
163 #define MAX_BUSY_COUNT  100         // Number of retry before failing access BBP & RF indirect register
164
165 //#define PHY_TR_SWITCH_TIME          5  // usec
166
167 //#define BBP_R17_LOW_SENSIBILITY     0x50
168 //#define BBP_R17_MID_SENSIBILITY     0x41
169 //#define BBP_R17_DYNAMIC_UP_BOUND    0x40
170
171 #define RSSI_FOR_VERY_LOW_SENSIBILITY   -35
172 #define RSSI_FOR_LOW_SENSIBILITY                -58
173 #define RSSI_FOR_MID_LOW_SENSIBILITY    -80
174 #define RSSI_FOR_MID_SENSIBILITY                -90
175
176 /*****************************************************************************
177         RF register Read/Write marco definition
178  *****************************************************************************/
179 #ifdef RTMP_MAC_PCI
180 #define RTMP_RF_IO_WRITE32(_A, _V)                  \
181 {                                                                                       \
182         if ((_A)->bPCIclkOff == FALSE)                  \
183         {                                                                                               \
184                 PHY_CSR4_STRUC  _value;                          \
185                 ULONG           _busyCnt = 0;                    \
186                                                                                         \
187                 do {                                            \
188                         RTMP_IO_READ32((_A), RF_CSR_CFG0, &_value.word);  \
189                         if (_value.field.Busy == IDLE)               \
190                                 break;                                  \
191                         _busyCnt++;                                  \
192                 }while (_busyCnt < MAX_BUSY_COUNT);                     \
193                 if(_busyCnt < MAX_BUSY_COUNT)                   \
194                 {                                               \
195                         RTMP_IO_WRITE32((_A), RF_CSR_CFG0, (_V));          \
196                 }                                               \
197         }                                                               \
198 }
199 #endif // RTMP_MAC_PCI //
200 #ifdef RTMP_MAC_USB
201 #define RTMP_RF_IO_WRITE32(_A, _V)                 RTUSBWriteRFRegister(_A, _V)
202 #endif // RTMP_MAC_USB //
203
204 #ifdef RT30xx
205 #define RTMP_RF_IO_READ8_BY_REG_ID(_A, _I, _pV)    RT30xxReadRFRegister(_A, _I, _pV)
206 #define RTMP_RF_IO_WRITE8_BY_REG_ID(_A, _I, _V)    RT30xxWriteRFRegister(_A, _I, _V)
207 #endif // RT30xx //
208
209 /*****************************************************************************
210         BBP register Read/Write marco definitions.
211         we read/write the bbp value by register's ID.
212         Generate PER to test BA
213  *****************************************************************************/
214 #ifdef RTMP_MAC_PCI
215 /*
216         basic marco for BBP read operation.
217         _pAd: the data structure pointer of RTMP_ADAPTER
218         _bbpID : the bbp register ID
219         _pV: data pointer used to save the value of queried bbp register.
220         _bViaMCU: if we need access the bbp via the MCU.
221 */
222 #define RTMP_BBP_IO_READ8(_pAd, _bbpID, _pV, _bViaMCU)                  \
223         do{                                                                                                                     \
224                 BBP_CSR_CFG_STRUC  BbpCsr;                                                              \
225                 int   _busyCnt, _secCnt, _regID;                                                \
226                                                                                                                                 \
227                 _regID = ((_bViaMCU) == TRUE ? H2M_BBP_AGENT : BBP_CSR_CFG);    \
228                 for (_busyCnt=0; _busyCnt<MAX_BUSY_COUNT; _busyCnt++)      \
229                 {                                                                                                       \
230                         RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word);             \
231                         if (BbpCsr.field.Busy == BUSY)                  \
232                                 continue;                                               \
233                         BbpCsr.word = 0;                                \
234                         BbpCsr.field.fRead = 1;                         \
235                         BbpCsr.field.BBP_RW_MODE = 1;                         \
236                         BbpCsr.field.Busy = 1;                          \
237                         BbpCsr.field.RegNum = _bbpID;                       \
238                         RTMP_IO_WRITE32(_pAd, _regID, BbpCsr.word);     \
239                         if ((_bViaMCU) == TRUE)                                                 \
240                         {                                                                                                       \
241                                 AsicSendCommandToMcu(_pAd, 0x80, 0xff, 0x0, 0x0); \
242                                 RTMPusecDelay(1000);    \
243                         }                                                       \
244                         for (_secCnt=0; _secCnt<MAX_BUSY_COUNT; _secCnt++)       \
245                         {                                               \
246                                 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \
247                                 if (BbpCsr.field.Busy == IDLE)              \
248                                         break;                                  \
249                         }                                               \
250                         if ((BbpCsr.field.Busy == IDLE) &&              \
251                                 (BbpCsr.field.RegNum == _bbpID))                \
252                         {                                               \
253                                 *(_pV) = (UCHAR)BbpCsr.field.Value;         \
254                                 break;                                      \
255                         }                                               \
256                 }                                                   \
257                 if (BbpCsr.field.Busy == BUSY)                      \
258                 {                                                   \
259                         DBGPRINT_ERR(("BBP(viaMCU=%d) read R%d fail\n", (_bViaMCU), _bbpID));      \
260                         *(_pV) = (_pAd)->BbpWriteLatch[_bbpID];               \
261                         if ((_bViaMCU) == TRUE)                         \
262                         {                                                                       \
263                                 RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word);                             \
264                                 BbpCsr.field.Busy = 0;                          \
265                                 RTMP_IO_WRITE32(_pAd, _regID, BbpCsr.word);                             \
266                         }                               \
267                 }                                                                                                       \
268         }while(0)
269
270 /*
271         This marco used for the BBP read operation which didn't need via MCU.
272 */
273 #define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)                     \
274         RTMP_BBP_IO_READ8((_A), (_I), (_pV), FALSE)
275
276 /*
277         This marco used for the BBP read operation which need via MCU.
278         But for some chipset which didn't have mcu (e.g., RBUS based chipset), we
279         will use this function too and didn't access the bbp register via the MCU.
280 */
281 // Read BBP register by register's ID. Generate PER to test BA
282 #define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)                                                \
283 {                                                                                                                                               \
284         BBP_CSR_CFG_STRUC       BbpCsr;                                                                                 \
285         int                                     i, k;                   \
286         BOOLEAN                                 brc;                    \
287         BbpCsr.field.Busy = IDLE;                       \
288         if ((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3)      \
289                 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE)   \
290                 && ((_A)->bPCIclkOff == FALSE)  \
291                 && ((_A)->brt30xxBanMcuCmd == FALSE))   \
292         {                                                                                                                                       \
293                 for (i=0; i<MAX_BUSY_COUNT; i++)                                                                        \
294                 {                                                                                                                                       \
295                         RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                                \
296                         if (BbpCsr.field.Busy == BUSY)                                                                  \
297                         {                                                                                                                               \
298                                 continue;                                                                                                       \
299                         }                                                                                                                               \
300                         BbpCsr.word = 0;                                                                                                \
301                         BbpCsr.field.fRead = 1;                                                                                 \
302                         BbpCsr.field.BBP_RW_MODE = 1;                                                                   \
303                         BbpCsr.field.Busy = 1;                                                                                  \
304                         BbpCsr.field.RegNum = _I;                                                                               \
305                         RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
306                         brc = AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0);                                   \
307                         if (brc == TRUE)                                                                                                                                \
308                         {                                                                                                                               \
309                                 for (k=0; k<MAX_BUSY_COUNT; k++)                                                                \
310                                 {                                                                                                                               \
311                                         RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                        \
312                                         if (BbpCsr.field.Busy == IDLE)                                                          \
313                                                 break;                                                                                                  \
314                                 }                                                                                                                               \
315                                 if ((BbpCsr.field.Busy == IDLE) &&                                                              \
316                                         (BbpCsr.field.RegNum == _I))                                                            \
317                                 {                                                                                                                               \
318                                         *(_pV) = (UCHAR)BbpCsr.field.Value;                                                     \
319                                         break;                                                                                                          \
320                                 }                                                                                                                               \
321                         }                                                                                                                               \
322                         else                                                                                                                            \
323                         {                                                                                                                               \
324                                 BbpCsr.field.Busy = 0;                                                                                  \
325                                 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
326                         }                                                                                                                               \
327                 }                                                                                                                                       \
328         }       \
329         else if (!((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3)       \
330                 && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE))  \
331                 && ((_A)->bPCIclkOff == FALSE)) \
332         {                                                                                                                                       \
333                 for (i=0; i<MAX_BUSY_COUNT; i++)                                                                        \
334                 {                                                                                                                                       \
335                         RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                                \
336                         if (BbpCsr.field.Busy == BUSY)                                                                  \
337                         {                                                                                                                               \
338                                 continue;                                                                                                       \
339                         }                                                                                                                               \
340                         BbpCsr.word = 0;                                                                                                \
341                         BbpCsr.field.fRead = 1;                                                                                 \
342                         BbpCsr.field.BBP_RW_MODE = 1;                                                                   \
343                         BbpCsr.field.Busy = 1;                                                                                  \
344                         BbpCsr.field.RegNum = _I;                                                                               \
345                         RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
346                         AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0);                                 \
347                         for (k=0; k<MAX_BUSY_COUNT; k++)                                                                \
348                         {                                                                                                                               \
349                                 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                        \
350                                 if (BbpCsr.field.Busy == IDLE)                                                          \
351                                         break;                                                                                                  \
352                         }                                                                                                                               \
353                         if ((BbpCsr.field.Busy == IDLE) &&                                                              \
354                                 (BbpCsr.field.RegNum == _I))                                                            \
355                         {                                                                                                                               \
356                                 *(_pV) = (UCHAR)BbpCsr.field.Value;                                                     \
357                                 break;                                                                                                          \
358                         }                                                                                                                               \
359                 }                                                                                                                                       \
360         }                                                                                                                                       \
361         else                                                                            \
362         {                                                                                                                                       \
363                 DBGPRINT_ERR((" , brt30xxBanMcuCmd = %d, Read BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I)));       \
364                 *(_pV) = (_A)->BbpWriteLatch[_I];                                                               \
365         }                                                                                                                                       \
366         if ((BbpCsr.field.Busy == BUSY) || ((_A)->bPCIclkOff == TRUE))                                                                          \
367         {                                                                                                                                       \
368                 DBGPRINT_ERR(("BBP read R%d=0x%x fail\n", _I, BbpCsr.word));    \
369                 *(_pV) = (_A)->BbpWriteLatch[_I];                                                               \
370         }                                                                                                                                       \
371 }
372
373 /*
374         basic marco for BBP write operation.
375         _pAd: the data structure pointer of RTMP_ADAPTER
376         _bbpID : the bbp register ID
377         _pV: data used to save the value of queried bbp register.
378         _bViaMCU: if we need access the bbp via the MCU.
379 */
380 #define RTMP_BBP_IO_WRITE8(_pAd, _bbpID, _pV, _bViaMCU)                 \
381         do{                                                                                                                     \
382                 BBP_CSR_CFG_STRUC  BbpCsr;                             \
383                 int             _busyCnt, _regID;                                                       \
384                                                                                                                                 \
385                 _regID = ((_bViaMCU) == TRUE ? H2M_BBP_AGENT : BBP_CSR_CFG);    \
386                 for (_busyCnt=0; _busyCnt<MAX_BUSY_COUNT; _busyCnt++)  \
387                 {                                                   \
388                         RTMP_IO_READ32((_pAd), BBP_CSR_CFG, &BbpCsr.word);     \
389                         if (BbpCsr.field.Busy == BUSY)                  \
390                                 continue;                                   \
391                         BbpCsr.word = 0;                                \
392                         BbpCsr.field.fRead = 0;                         \
393                         BbpCsr.field.BBP_RW_MODE = 1;                         \
394                         BbpCsr.field.Busy = 1;                          \
395                         BbpCsr.field.Value = _pV;                        \
396                         BbpCsr.field.RegNum = _bbpID;                       \
397                         RTMP_IO_WRITE32((_pAd), BBP_CSR_CFG, BbpCsr.word);     \
398                         if ((_bViaMCU) == TRUE)                                                                 \
399                         {                                                                                                               \
400                                 AsicSendCommandToMcu(_pAd, 0x80, 0xff, 0x0, 0x0);               \
401                                 if ((_pAd)->OpMode == OPMODE_AP)                                                \
402                                         RTMPusecDelay(1000);                                                    \
403                         }                                                                                                               \
404                         (_pAd)->BbpWriteLatch[_bbpID] = _pV;                                    \
405                         break;                                                                                                  \
406                 }                                                                                                               \
407                 if (_busyCnt == MAX_BUSY_COUNT)                                                         \
408                 {                                                                                                               \
409                         DBGPRINT_ERR(("BBP write R%d fail\n", _bbpID));                         \
410                         if((_bViaMCU) == TRUE)                                                                  \
411                         {                                                                                                               \
412                                 RTMP_IO_READ32(_pAd, H2M_BBP_AGENT, &BbpCsr.word);      \
413                                 BbpCsr.field.Busy = 0;                                                                  \
414                                 RTMP_IO_WRITE32(_pAd, H2M_BBP_AGENT, BbpCsr.word);      \
415                         }                                                                                                               \
416                 }                                                                                                               \
417         }while(0)
418
419
420 /*
421         This marco used for the BBP write operation which didn't need via MCU.
422 */
423 #define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _pV)                    \
424         RTMP_BBP_IO_WRITE8((_A), (_I), (_pV), FALSE)
425
426 /*
427         This marco used for the BBP write operation which need via MCU.
428         But for some chipset which didn't have mcu (e.g., RBUS based chipset), we
429         will use this function too and didn't access the bbp register via the MCU.
430 */
431 // Write BBP register by register's ID & value
432 #define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V)                                                \
433 {                                                                                                                                               \
434         BBP_CSR_CFG_STRUC       BbpCsr;                                                                                 \
435         INT                                     BusyCnt = 0;                                                                            \
436         BOOLEAN                                 brc;                    \
437         if (_I < MAX_NUM_OF_BBP_LATCH)                                                                          \
438         {                                                                                                                                       \
439                 if ((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3)      \
440                         && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE)   \
441                         && ((_A)->bPCIclkOff == FALSE)  \
442                         && ((_A)->brt30xxBanMcuCmd == FALSE))   \
443                 {                                                                                                                                       \
444                         if (_A->AccessBBPFailCount > 20)                                                                        \
445                         {                                                                                                                                       \
446                                 AsicResetBBPAgent(_A);                          \
447                                 _A->AccessBBPFailCount = 0;                                                                                     \
448                         }                                                                                                                                       \
449                         for (BusyCnt=0; BusyCnt<MAX_BUSY_COUNT; BusyCnt++)                                      \
450                         {                                                                                                                                       \
451                                 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                                \
452                                 if (BbpCsr.field.Busy == BUSY)                                                                  \
453                                         continue;                                                                                                       \
454                                 BbpCsr.word = 0;                                                                                                \
455                                 BbpCsr.field.fRead = 0;                                                                                 \
456                                 BbpCsr.field.BBP_RW_MODE = 1;                                                                   \
457                                 BbpCsr.field.Busy = 1;                                                                                  \
458                                 BbpCsr.field.Value = _V;                                                                                \
459                                 BbpCsr.field.RegNum = _I;                                                                               \
460                                 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
461                                 brc = AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0);                                   \
462                                 if (brc == TRUE)                                                                                                                                \
463                                 {                                                                                                                               \
464                                         (_A)->BbpWriteLatch[_I] = _V;                                                                   \
465                                 }                                                                                                                               \
466                                 else                                                                                                                            \
467                                 {                                                                                                                               \
468                                         BbpCsr.field.Busy = 0;                                                                                  \
469                                         RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
470                                 }                                                                                                                               \
471                                 break;                                                                                                                  \
472                         }                                                                                                                                       \
473                 }                                                                                                                                       \
474                 else if (!((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3)       \
475                         && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE))  \
476                         && ((_A)->bPCIclkOff == FALSE)) \
477                 {                                                                                                                                       \
478                         if (_A->AccessBBPFailCount > 20)                                                                        \
479                         {                                                                                                                                       \
480                                 AsicResetBBPAgent(_A);                          \
481                                 _A->AccessBBPFailCount = 0;                                                                                     \
482                         }                                                                                                                                       \
483                         for (BusyCnt=0; BusyCnt<MAX_BUSY_COUNT; BusyCnt++)                                      \
484                         {                                                                                                                                       \
485                                 RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word);                                \
486                                 if (BbpCsr.field.Busy == BUSY)                                                                  \
487                                         continue;                                                                                                       \
488                                 BbpCsr.word = 0;                                                                                                \
489                                 BbpCsr.field.fRead = 0;                                                                                 \
490                                 BbpCsr.field.BBP_RW_MODE = 1;                                                                   \
491                                 BbpCsr.field.Busy = 1;                                                                                  \
492                                 BbpCsr.field.Value = _V;                                                                                \
493                                 BbpCsr.field.RegNum = _I;                                                                               \
494                                 RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word);                                \
495                                 AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0);                                 \
496                                 (_A)->BbpWriteLatch[_I] = _V;                                                                   \
497                                 break;                                                                                                                  \
498                         }                                                                                                                                       \
499                 }                                                                                                                                       \
500                 else                                                                            \
501                 {                                                                                                                                       \
502                         DBGPRINT_ERR(("  brt30xxBanMcuCmd = %d. Write BBP %d \n",  (_A)->brt30xxBanMcuCmd, (_I)));      \
503                 }                                                                                                                                       \
504                 if ((BusyCnt == MAX_BUSY_COUNT) || ((_A)->bPCIclkOff == TRUE))                  \
505                 {                                                                                                                                       \
506                         if (BusyCnt == MAX_BUSY_COUNT)                                  \
507                                 (_A)->AccessBBPFailCount++;                                     \
508                         DBGPRINT_ERR(("BBP write R%d=0x%x fail. BusyCnt= %d.bPCIclkOff = %d. \n", _I, BbpCsr.word, BusyCnt, (_A)->bPCIclkOff ));        \
509                 }                                                                                                                                       \
510         }                                                                                                                                               \
511         else                                                                                                                                            \
512         {                                                                                                                                               \
513                 DBGPRINT_ERR(("****** BBP_Write_Latch Buffer exceeds max boundry ****** \n"));  \
514         }                                                                                                                                               \
515 }
516 #endif // RTMP_MAC_PCI //
517
518 #ifdef RTMP_MAC_USB
519 #define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)   RTUSBReadBBPRegister(_A, _I, _pV)
520 #define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V)   RTUSBWriteBBPRegister(_A, _I, _V)
521
522 #define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V)                     RTUSBWriteBBPRegister(_A, _I, _V)
523 #define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV)             RTUSBReadBBPRegister(_A, _I, _pV)
524 #endif // RTMP_MAC_USB //
525
526 #ifdef RT30xx
527 #define RTMP_ASIC_MMPS_DISABLE(_pAd)                                                    \
528         do{                                                                                                                     \
529                 UINT32 _macData; \
530                 UCHAR _bbpData = 0; \
531                 /* disable MMPS BBP control register */                                         \
532                 RTMP_BBP_IO_READ8_BY_REG_ID(_pAd, BBP_R3, &_bbpData);   \
533                 _bbpData &= ~(0x04);    /*bit 2*/                                                               \
534                 RTMP_BBP_IO_WRITE8_BY_REG_ID(_pAd, BBP_R3, _bbpData);   \
535                                                                                                                                 \
536                 /* disable MMPS MAC control register */                                         \
537                 RTMP_IO_READ32(_pAd, 0x1210, &_macData);                                \
538                 _macData &= ~(0x09);    /*bit 0, 3*/                                                    \
539                 RTMP_IO_WRITE32(_pAd, 0x1210, _macData);                                \
540         }while(0)
541
542
543 #define RTMP_ASIC_MMPS_ENABLE(_pAd)                                                     \
544         do{                                                                                                                     \
545                 UINT32 _macData; \
546                 UCHAR _bbpData = 0; \
547                 /* enable MMPS BBP control register */                                          \
548                 RTMP_BBP_IO_READ8_BY_REG_ID(_pAd, BBP_R3, &_bbpData);   \
549                 _bbpData |= (0x04);     /*bit 2*/                                                               \
550                 RTMP_BBP_IO_WRITE8_BY_REG_ID(_pAd, BBP_R3, _bbpData);   \
551                                                                                                                                 \
552                 /* enable MMPS MAC control register */                                          \
553                 RTMP_IO_READ32(_pAd, 0x1210, &_macData);                                \
554                 _macData |= (0x09);     /*bit 0, 3*/                                                    \
555                 RTMP_IO_WRITE32(_pAd, 0x1210, _macData);                                \
556         }while(0)
557
558 #endif // RT30xx //
559
560 #endif // __RTMP_PHY_H__ //