Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
[pandora-kernel.git] / drivers / staging / rt2860 / chips / rt3090.c
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         rt3090.c
29
30         Abstract:
31         Specific funcitons and variables for RT3070
32
33         Revision History:
34         Who         When          What
35         --------    ----------    ----------------------------------------------
36 */
37
38 #ifdef RT3090
39
40 #include "../rt_config.h"
41
42 #ifndef RTMP_RF_RW_SUPPORT
43 #error "You Should Enable compile flag RTMP_RF_RW_SUPPORT for this chip"
44 #endif /* RTMP_RF_RW_SUPPORT // */
45
46 void NICInitRT3090RFRegisters(struct rt_rtmp_adapter *pAd)
47 {
48         int i;
49         /* Driver must read EEPROM to get RfIcType before initial RF registers */
50         /* Initialize RF register to default value */
51         if (IS_RT3090(pAd)) {
52                 /* Init RF calibration */
53                 /* Driver should toggle RF R30 bit7 before init RF registers */
54                 u32 RfReg = 0, data;
55
56                 RT30xxReadRFRegister(pAd, RF_R30, (u8 *)& RfReg);
57                 RfReg |= 0x80;
58                 RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg);
59                 RTMPusecDelay(1000);
60                 RfReg &= 0x7F;
61                 RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg);
62
63                 /* init R24, R31 */
64                 RT30xxWriteRFRegister(pAd, RF_R24, 0x0F);
65                 RT30xxWriteRFRegister(pAd, RF_R31, 0x0F);
66
67                 /* RT309x version E has fixed this issue */
68                 if ((pAd->NicConfig2.field.DACTestBit == 1)
69                     && ((pAd->MACVersion & 0xffff) < 0x0211)) {
70                         /* patch tx EVM issue temporarily */
71                         RTMP_IO_READ32(pAd, LDO_CFG0, &data);
72                         data = ((data & 0xE0FFFFFF) | 0x0D000000);
73                         RTMP_IO_WRITE32(pAd, LDO_CFG0, data);
74                 } else {
75                         RTMP_IO_READ32(pAd, LDO_CFG0, &data);
76                         data = ((data & 0xE0FFFFFF) | 0x01000000);
77                         RTMP_IO_WRITE32(pAd, LDO_CFG0, data);
78                 }
79
80                 /* patch LNA_PE_G1 failed issue */
81                 RTMP_IO_READ32(pAd, GPIO_SWITCH, &data);
82                 data &= ~(0x20);
83                 RTMP_IO_WRITE32(pAd, GPIO_SWITCH, data);
84
85                 /* Initialize RF register to default value */
86                 for (i = 0; i < NUM_RF_REG_PARMS; i++) {
87                         RT30xxWriteRFRegister(pAd,
88                                               RT30xx_RFRegTable[i].Register,
89                                               RT30xx_RFRegTable[i].Value);
90                 }
91
92                 /* Driver should set RF R6 bit6 on before calibration */
93                 RT30xxReadRFRegister(pAd, RF_R06, (u8 *)& RfReg);
94                 RfReg |= 0x40;
95                 RT30xxWriteRFRegister(pAd, RF_R06, (u8)RfReg);
96
97                 /*For RF filter Calibration */
98                 RTMPFilterCalibration(pAd);
99
100                 /* Initialize RF R27 register, set RF R27 must be behind RTMPFilterCalibration() */
101                 if ((pAd->MACVersion & 0xffff) < 0x0211)
102                         RT30xxWriteRFRegister(pAd, RF_R27, 0x3);
103
104                 /* set led open drain enable */
105                 RTMP_IO_READ32(pAd, OPT_14, &data);
106                 data |= 0x01;
107                 RTMP_IO_WRITE32(pAd, OPT_14, data);
108
109                 /* set default antenna as main */
110                 if (pAd->RfIcType == RFIC_3020)
111                         AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt);
112
113                 /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */
114                 RT30xxLoadRFNormalModeSetup(pAd);
115         }
116
117 }
118
119 #endif /* RT3090 // */