16 #include "ieee80211/dot11d.h"
24 u32 bangdata = (data << 4) | (adr & 0xf);
49 for (i = 15; i >= 0; i--) {
50 bit = (bangdata & (1 <<
i)) >>
i;
58 bit = (bangdata & (1 <<
i)) >>
i;
79 static const u16 rtl8225bcd_rxgain[] = {
80 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409,
81 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541,
82 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583,
83 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644,
84 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688,
85 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745,
86 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789,
87 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793,
88 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d,
89 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9,
90 0x07aa, 0x07ab, 0x07ac, 0x07ad, 0x07b0, 0x07b1, 0x07b2, 0x07b3,
91 0x07b4, 0x07b5, 0x07b8, 0x07b9, 0x07ba, 0x07bb, 0x07bb
95 static const u8 rtl8225_agc[] = {
96 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e,
97 0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96,
98 0x95, 0x94, 0x93, 0x92, 0x91, 0x90, 0x8f, 0x8e,
99 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86,
100 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x3f, 0x3e,
101 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36,
102 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x2f, 0x2e,
103 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26,
104 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 0x1f, 0x1e,
105 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16,
106 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e,
107 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06,
108 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01,
109 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
110 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
111 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
114 static const u8 rtl8225_gain[] = {
115 0x23, 0x88, 0x7c, 0xa5,
116 0x23, 0x88, 0x7c, 0xb5,
117 0x23, 0x88, 0x7c, 0xc5,
118 0x33, 0x80, 0x79, 0xc5,
119 0x43, 0x78, 0x76, 0xc5,
120 0x53, 0x60, 0x73, 0xc5,
121 0x63, 0x58, 0x70, 0xc5,
124 static const u8 rtl8225_tx_gain_cck_ofdm[] = {
125 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e
128 static const u8 rtl8225_tx_power_cck[] = {
129 0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02,
130 0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02,
131 0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02,
132 0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02,
133 0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03,
134 0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03
137 static const u8 rtl8225_tx_power_cck_ch14[] = {
138 0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00,
139 0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00,
140 0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00,
141 0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00,
142 0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00,
143 0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00
146 static const u8 rtl8225_tx_power_ofdm[] = {
147 0x80, 0x90, 0xa2, 0xb5, 0xcb, 0xe4
150 static const u32 rtl8225_chan[] = {
152 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380,
153 0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x074A,
156 static void rtl8225_SetTXPowerLevel(
struct net_device *dev,
short ch)
163 const u8 *cck_power_table;
164 u8 max_cck_power_level;
165 u8 max_ofdm_power_level;
166 u8 min_ofdm_power_level;
167 u8 cck_power_level = 0xff & priv->
chtxpwr[ch];
170 max_cck_power_level = 35;
171 max_ofdm_power_level = 35;
172 min_ofdm_power_level = 0;
174 if (cck_power_level > max_cck_power_level)
175 cck_power_level = max_cck_power_level;
177 GainIdx = cck_power_level % 6;
178 GainSetting = cck_power_level / 6;
181 cck_power_table = rtl8225_tx_power_cck_ch14;
183 cck_power_table = rtl8225_tx_power_cck;
186 rtl8225_tx_gain_cck_ofdm[GainSetting] >> 1);
188 for (i = 0; i < 8; i++) {
189 power = cck_power_table[GainIdx * 8 +
i];
197 if (ofdm_power_level > (max_ofdm_power_level - min_ofdm_power_level))
198 ofdm_power_level = max_ofdm_power_level;
200 ofdm_power_level += min_ofdm_power_level;
202 if (ofdm_power_level > 35)
203 ofdm_power_level = 35;
205 GainIdx = ofdm_power_level % 6;
206 GainSetting = ofdm_power_level / 6;
215 rtl8225_tx_gain_cck_ofdm[GainSetting] >> 1);
217 power = rtl8225_tx_power_ofdm[GainIdx];
226 static const u8 rtl8225z2_threshold[] = {
227 0x8d, 0x8d, 0x8d, 0x8d, 0x9d, 0xad, 0xbd,
230 static const u8 rtl8225z2_gain_bg[] = {
240 static const u8 rtl8225z2_gain_a[] = {
250 static const u16 rtl8225z2_rxgain[] = {
251 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409,
252 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541,
253 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583,
254 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644,
255 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688,
256 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745,
257 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789,
258 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793,
259 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d,
260 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9,
261 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03b0, 0x03b1, 0x03b2, 0x03b3,
262 0x03b4, 0x03b5, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bb
266 static const u8 ZEBRA2_CCK_OFDM_GAIN_SETTING[] = {
267 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
268 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
269 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
270 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
271 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
272 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
275 static const u8 rtl8225z2_tx_power_ofdm[] = {
276 0x42, 0x00, 0x40, 0x00, 0x40
279 static const u8 rtl8225z2_tx_power_cck_ch14[] = {
280 0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00
283 static const u8 rtl8225z2_tx_power_cck[] = {
284 0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04
289 const u8 *rtl8225_gain;
290 struct r8180_priv *priv = ieee80211_priv(dev);
294 rtl8225_gain = rtl8225z2_gain_bg;
296 rtl8225_gain = rtl8225z2_gain_a;
306 u32 data2Write = ((
u32)(adr & 0x1f)) << 27;
309 u16 oval, oval2, oval3,
tmp;
335 mask = (low2high) ? 0x01 : (((
u32)0x01)<<(32-1));
337 for (i = 0; i < wLength/2; i++) {
338 bit = ((data2Write&
mask) != 0) ? 1 : 0;
349 mask = (low2high) ? (mask<<1) : (mask>>1);
361 bit = ((data2Write&
mask) != 0) ? 1 : 0;
373 mask = (low2high) ? (mask<<1) : (mask>>1);
378 mask = (low2high) ? 0x01 : (((
u32)0x01) << (12-1));
386 for (i = 0; i < rLength; i++) {
401 mask = (low2high) ? (mask<<1) : (mask>>1);
419 if (read_rtl8225(dev, 8) != 0x588)
422 if (read_rtl8225(dev, 9) != 0x700)
426 write_rtl8225(dev, 0, 0xb7);
449 bool bUseDefault =
true;
460 tmp = (2 * PowerInDbm);
470 tmp = (4 * PowerInDbm) - 52;
488 else if (PowerInDbm > 35)
491 TxPwrIdx = (
u8)PowerInDbm;
499 struct r8180_priv *priv = ieee80211_priv(dev);
500 u8 max_cck_power_level;
501 u8 max_ofdm_power_level;
502 u8 min_ofdm_power_level;
503 char cck_power_level = (
char)(0xff & priv->
chtxpwr[ch]);
514 if (cck_power_level > CckMaxPwrIdx)
515 cck_power_level = CckMaxPwrIdx;
516 if (ofdm_power_level > OfdmMaxPwrIdx)
517 ofdm_power_level = OfdmMaxPwrIdx;
520 max_cck_power_level = 15;
521 max_ofdm_power_level = 25;
522 min_ofdm_power_level = 10;
524 if (cck_power_level > 35)
525 cck_power_level = 35;
528 (ZEBRA2_CCK_OFDM_GAIN_SETTING[(
u8)cck_power_level]));
532 if (ofdm_power_level > 35)
533 ofdm_power_level = 35;
544 ZEBRA2_CCK_OFDM_GAIN_SETTING[(
u8)ofdm_power_level]);
546 if (ofdm_power_level <= 11) {
551 if (ofdm_power_level <= 17) {
569 if ((
RF_ReadReg(dev, 0x7) & 0x0F80) != rtl8225_chan[ch])
578 static void rtl8225_host_pci_init(
struct net_device *dev)
595 static void rtl8225_rf_set_chan(
struct net_device *dev,
short ch)
597 struct r8180_priv *priv = ieee80211_priv(dev);
602 rtl8225_SetTXPowerLevel(dev, ch);
604 write_rtl8225(dev, 0x7, rtl8225_chan[ch]);
634 struct r8180_priv *priv = ieee80211_priv(dev);
642 rtl8225_host_pci_init(dev);
658 write_rtl8225(dev, 0x0, 0x2bf);
mdelay(1);
659 write_rtl8225(dev, 0x1, 0xee0);
mdelay(1);
660 write_rtl8225(dev, 0x2, 0x44d);
mdelay(1);
661 write_rtl8225(dev, 0x3, 0x441);
mdelay(1);
662 write_rtl8225(dev, 0x4, 0x8c3);
mdelay(1);
663 write_rtl8225(dev, 0x5, 0xc72);
mdelay(1);
664 write_rtl8225(dev, 0x6, 0xe6);
mdelay(1);
665 write_rtl8225(dev, 0x7, rtl8225_chan[channel]);
mdelay(1);
666 write_rtl8225(dev, 0x8, 0x3f);
mdelay(1);
667 write_rtl8225(dev, 0x9, 0x335);
mdelay(1);
668 write_rtl8225(dev, 0xa, 0x9d4);
mdelay(1);
669 write_rtl8225(dev, 0
xb, 0x7bb);
mdelay(1);
670 write_rtl8225(dev, 0
xc, 0x850);
mdelay(1);
671 write_rtl8225(dev, 0xd, 0xcdf);
mdelay(1);
672 write_rtl8225(dev, 0
xe, 0x2b);
mdelay(1);
673 write_rtl8225(dev, 0xf, 0x114);
677 write_rtl8225(dev, 0x0, 0x1b7);
679 for (i = 0; i < 95; i++) {
680 write_rtl8225(dev, 0x1, (
u8)(i + 1));
681 write_rtl8225(dev, 0x2, rtl8225z2_rxgain[i]);
684 write_rtl8225(dev, 0x3, 0x80);
685 write_rtl8225(dev, 0x5, 0x4);
687 write_rtl8225(dev, 0x0, 0xb7);
689 write_rtl8225(dev, 0x2, 0xc4d);
695 data = read_rtl8225(dev, 6);
696 if (!(data & 0x00000080)) {
697 write_rtl8225(dev, 0x02, 0x0c4d);
699 write_rtl8225(dev, 0x02, 0x044d);
701 data = read_rtl8225(dev, 6);
702 if (!(data & 0x00000080))
703 DMESGW(
"RF Calibration Failed!!!!\n");
708 write_rtl8225(dev, 0x0, 0x2bf);
710 for (i = 0; i < 128; i++) {
711 data = rtl8225_agc[
i];
811 rtl8225_rf_set_chan(dev, priv->
chan);
816 struct r8180_priv *priv = ieee80211_priv(dev);
819 write_rtl8225(dev, 0x5, 0x1865);
835 write_rtl8225(dev, 0x5, 0x1864);
853 #define MAX_DOZE_WAITING_TIMES_85B 20
854 #define MAX_POLLING_24F_TIMES_87SE 10
855 #define LPS_MAX_SLEEP_WAITING_TIMES_87SE 5
860 struct r8180_priv *priv = ieee80211_priv(dev);
861 u8 btCR9346, btConfig3;
862 bool bActionAllowed =
true, bTurnOffBB =
true;
879 switch (eRFPowerState) {
906 for (QueueID = 0, i = 0; QueueID < 6;) {
915 bActionAllowed =
false;
922 if (bActionAllowed) {
942 if ((tmp24F == 0x01) ||
973 for (QueueID = 0, i = 0; QueueID < 6;) {
1007 if ((tmp24F == 0x01) || (tmp24F == 0x09)) {
1036 btCR9346 &= ~(0xC0);
1039 if (bResult && bActionAllowed)
1044 return bResult && bActionAllowed;