r819xU_phy.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
  1. #include "r8192U.h"
  2. #include "r8192U_hw.h"
  3. #include "r819xU_phy.h"
  4. #include "r819xU_phyreg.h"
  5. #include "r8190_rtl8256.h"
  6. #include "r8192U_dm.h"
  7. #include "r819xU_firmware_img.h"
  8. #include "dot11d.h"
  9. #include <linux/bitops.h>
  10. static u32 RF_CHANNEL_TABLE_ZEBRA[] = {
  11. 0,
  12. 0x085c, /* 2412 1 */
  13. 0x08dc, /* 2417 2 */
  14. 0x095c, /* 2422 3 */
  15. 0x09dc, /* 2427 4 */
  16. 0x0a5c, /* 2432 5 */
  17. 0x0adc, /* 2437 6 */
  18. 0x0b5c, /* 2442 7 */
  19. 0x0bdc, /* 2447 8 */
  20. 0x0c5c, /* 2452 9 */
  21. 0x0cdc, /* 2457 10 */
  22. 0x0d5c, /* 2462 11 */
  23. 0x0ddc, /* 2467 12 */
  24. 0x0e5c, /* 2472 13 */
  25. 0x0f72, /* 2484 */
  26. };
  27. #define rtl819XPHY_REG_1T2RArray Rtl8192UsbPHY_REG_1T2RArray
  28. #define rtl819XMACPHY_Array_PG Rtl8192UsbMACPHY_Array_PG
  29. #define rtl819XMACPHY_Array Rtl8192UsbMACPHY_Array
  30. #define rtl819XRadioA_Array Rtl8192UsbRadioA_Array
  31. #define rtl819XRadioB_Array Rtl8192UsbRadioB_Array
  32. #define rtl819XRadioC_Array Rtl8192UsbRadioC_Array
  33. #define rtl819XRadioD_Array Rtl8192UsbRadioD_Array
  34. #define rtl819XAGCTAB_Array Rtl8192UsbAGCTAB_Array
  35. /******************************************************************************
  36. * function: This function reads BB parameters from header file we generate,
  37. * and does register read/write
  38. * input: u32 bitmask //taget bit pos in the addr to be modified
  39. * output: none
  40. * return: u32 return the shift bit position of the mask
  41. ******************************************************************************/
  42. static u32 rtl8192_CalculateBitShift(u32 bitmask)
  43. {
  44. u32 i;
  45. i = ffs(bitmask) - 1;
  46. return i;
  47. }
  48. /******************************************************************************
  49. * function: This function checks different RF type to execute legal judgement.
  50. * If RF Path is illegal, we will return false.
  51. * input: net_device *dev
  52. * u32 eRFPath
  53. * output: none
  54. * return: 0(illegal, false), 1(legal, true)
  55. *****************************************************************************/
  56. u8 rtl8192_phy_CheckIsLegalRFPath(struct net_device *dev, u32 eRFPath)
  57. {
  58. u8 ret = 1;
  59. struct r8192_priv *priv = ieee80211_priv(dev);
  60. if (priv->rf_type == RF_2T4R) {
  61. ret = 0;
  62. } else if (priv->rf_type == RF_1T2R) {
  63. if (eRFPath == RF90_PATH_A || eRFPath == RF90_PATH_B)
  64. ret = 1;
  65. else if (eRFPath == RF90_PATH_C || eRFPath == RF90_PATH_D)
  66. ret = 0;
  67. }
  68. return ret;
  69. }
  70. /******************************************************************************
  71. * function: This function sets specific bits to BB register
  72. * input: net_device *dev
  73. * u32 reg_addr //target addr to be modified
  74. * u32 bitmask //taget bit pos to be modified
  75. * u32 data //value to be write
  76. * output: none
  77. * return: none
  78. * notice:
  79. ******************************************************************************/
  80. void rtl8192_setBBreg(struct net_device *dev, u32 reg_addr, u32 bitmask,
  81. u32 data)
  82. {
  83. u32 reg, bitshift;
  84. if (bitmask != bMaskDWord) {
  85. read_nic_dword(dev, reg_addr, &reg);
  86. bitshift = rtl8192_CalculateBitShift(bitmask);
  87. reg &= ~bitmask;
  88. reg |= data << bitshift;
  89. write_nic_dword(dev, reg_addr, reg);
  90. } else {
  91. write_nic_dword(dev, reg_addr, data);
  92. }
  93. }
  94. /******************************************************************************
  95. * function: This function reads specific bits from BB register
  96. * input: net_device *dev
  97. * u32 reg_addr //target addr to be readback
  98. * u32 bitmask //taget bit pos to be readback
  99. * output: none
  100. * return: u32 data //the readback register value
  101. * notice:
  102. ******************************************************************************/
  103. u32 rtl8192_QueryBBReg(struct net_device *dev, u32 reg_addr, u32 bitmask)
  104. {
  105. u32 reg, bitshift;
  106. read_nic_dword(dev, reg_addr, &reg);
  107. bitshift = rtl8192_CalculateBitShift(bitmask);
  108. return (reg & bitmask) >> bitshift;
  109. }
  110. static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
  111. u32 offset);
  112. static void phy_FwRFSerialWrite(struct net_device *dev,
  113. RF90_RADIO_PATH_E eRFPath, u32 offset,
  114. u32 data);
  115. /******************************************************************************
  116. * function: This function reads register from RF chip
  117. * input: net_device *dev
  118. * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
  119. * u32 offset //target address to be read
  120. * output: none
  121. * return: u32 readback value
  122. * notice: There are three types of serial operations:
  123. * (1) Software serial write.
  124. * (2)Hardware LSSI-Low Speed Serial Interface.
  125. * (3)Hardware HSSI-High speed serial write.
  126. * Driver here need to implement (1) and (2)
  127. * ---need more spec for this information.
  128. ******************************************************************************/
  129. static u32 rtl8192_phy_RFSerialRead(struct net_device *dev,
  130. RF90_RADIO_PATH_E eRFPath, u32 offset)
  131. {
  132. struct r8192_priv *priv = ieee80211_priv(dev);
  133. u32 ret = 0;
  134. u32 new_offset = 0;
  135. BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
  136. rtl8192_setBBreg(dev, pPhyReg->rfLSSIReadBack, bLSSIReadBackData, 0);
  137. /* Make sure RF register offset is correct */
  138. offset &= 0x3f;
  139. /* Switch page for 8256 RF IC */
  140. if (priv->rf_chip == RF_8256) {
  141. if (offset >= 31) {
  142. priv->RfReg0Value[eRFPath] |= 0x140;
  143. /* Switch to Reg_Mode2 for Reg 31-45 */
  144. rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
  145. bMaskDWord,
  146. priv->RfReg0Value[eRFPath]<<16);
  147. /* Modify offset */
  148. new_offset = offset - 30;
  149. } else if (offset >= 16) {
  150. priv->RfReg0Value[eRFPath] |= 0x100;
  151. priv->RfReg0Value[eRFPath] &= (~0x40);
  152. /* Switch to Reg_Mode1 for Reg16-30 */
  153. rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
  154. bMaskDWord,
  155. priv->RfReg0Value[eRFPath]<<16);
  156. new_offset = offset - 15;
  157. } else {
  158. new_offset = offset;
  159. }
  160. } else {
  161. RT_TRACE((COMP_PHY|COMP_ERR),
  162. "check RF type here, need to be 8256\n");
  163. new_offset = offset;
  164. }
  165. /* Put desired read addr to LSSI control Register */
  166. rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadAddress,
  167. new_offset);
  168. /* Issue a posedge trigger */
  169. rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x0);
  170. rtl8192_setBBreg(dev, pPhyReg->rfHSSIPara2, bLSSIReadEdge, 0x1);
  171. /* TODO: we should not delay such a long time. Ask for help from SD3 */
  172. usleep_range(1000, 1000);
  173. ret = rtl8192_QueryBBReg(dev, pPhyReg->rfLSSIReadBack,
  174. bLSSIReadBackData);
  175. /* Switch back to Reg_Mode0 */
  176. if (priv->rf_chip == RF_8256) {
  177. priv->RfReg0Value[eRFPath] &= 0xebf;
  178. rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord,
  179. priv->RfReg0Value[eRFPath] << 16);
  180. }
  181. return ret;
  182. }
  183. /******************************************************************************
  184. * function: This function writes data to RF register
  185. * input: net_device *dev
  186. * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
  187. * u32 offset //target address to be written
  188. * u32 data //the new register data to be written
  189. * output: none
  190. * return: none
  191. * notice: For RF8256 only.
  192. * ===========================================================================
  193. * Reg Mode RegCTL[1] RegCTL[0] Note
  194. * (Reg00[12]) (Reg00[10])
  195. * ===========================================================================
  196. * Reg_Mode0 0 x Reg 0 ~ 15(0x0 ~ 0xf)
  197. * ---------------------------------------------------------------------------
  198. * Reg_Mode1 1 0 Reg 16 ~ 30(0x1 ~ 0xf)
  199. * ---------------------------------------------------------------------------
  200. * Reg_Mode2 1 1 Reg 31 ~ 45(0x1 ~ 0xf)
  201. * ---------------------------------------------------------------------------
  202. *****************************************************************************/
  203. static void rtl8192_phy_RFSerialWrite(struct net_device *dev,
  204. RF90_RADIO_PATH_E eRFPath, u32 offset,
  205. u32 data)
  206. {
  207. struct r8192_priv *priv = ieee80211_priv(dev);
  208. u32 DataAndAddr = 0, new_offset = 0;
  209. BB_REGISTER_DEFINITION_T *pPhyReg = &priv->PHYRegDef[eRFPath];
  210. offset &= 0x3f;
  211. if (priv->rf_chip == RF_8256) {
  212. if (offset >= 31) {
  213. priv->RfReg0Value[eRFPath] |= 0x140;
  214. rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
  215. bMaskDWord,
  216. priv->RfReg0Value[eRFPath] << 16);
  217. new_offset = offset - 30;
  218. } else if (offset >= 16) {
  219. priv->RfReg0Value[eRFPath] |= 0x100;
  220. priv->RfReg0Value[eRFPath] &= (~0x40);
  221. rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
  222. bMaskDWord,
  223. priv->RfReg0Value[eRFPath]<<16);
  224. new_offset = offset - 15;
  225. } else {
  226. new_offset = offset;
  227. }
  228. } else {
  229. RT_TRACE((COMP_PHY|COMP_ERR),
  230. "check RF type here, need to be 8256\n");
  231. new_offset = offset;
  232. }
  233. /* Put write addr in [5:0] and write data in [31:16] */
  234. DataAndAddr = (data<<16) | (new_offset&0x3f);
  235. /* Write operation */
  236. rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset, bMaskDWord, DataAndAddr);
  237. if (offset == 0x0)
  238. priv->RfReg0Value[eRFPath] = data;
  239. /* Switch back to Reg_Mode0 */
  240. if (priv->rf_chip == RF_8256) {
  241. if (offset != 0) {
  242. priv->RfReg0Value[eRFPath] &= 0xebf;
  243. rtl8192_setBBreg(dev, pPhyReg->rf3wireOffset,
  244. bMaskDWord,
  245. priv->RfReg0Value[eRFPath] << 16);
  246. }
  247. }
  248. }
  249. /******************************************************************************
  250. * function: This function set specific bits to RF register
  251. * input: net_device dev
  252. * RF90_RADIO_PATH_E eRFPath //radio path of A/B/C/D
  253. * u32 reg_addr //target addr to be modified
  254. * u32 bitmask //taget bit pos to be modified
  255. * u32 data //value to be written
  256. * output: none
  257. * return: none
  258. * notice:
  259. *****************************************************************************/
  260. void rtl8192_phy_SetRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
  261. u32 reg_addr, u32 bitmask, u32 data)
  262. {
  263. struct r8192_priv *priv = ieee80211_priv(dev);
  264. u32 reg, bitshift;
  265. if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
  266. return;
  267. if (priv->Rf_Mode == RF_OP_By_FW) {
  268. if (bitmask != bMask12Bits) {
  269. /* RF data is 12 bits only */
  270. reg = phy_FwRFSerialRead(dev, eRFPath, reg_addr);
  271. bitshift = rtl8192_CalculateBitShift(bitmask);
  272. reg &= ~bitmask;
  273. reg |= data << bitshift;
  274. phy_FwRFSerialWrite(dev, eRFPath, reg_addr, reg);
  275. } else {
  276. phy_FwRFSerialWrite(dev, eRFPath, reg_addr, data);
  277. }
  278. udelay(200);
  279. } else {
  280. if (bitmask != bMask12Bits) {
  281. /* RF data is 12 bits only */
  282. reg = rtl8192_phy_RFSerialRead(dev, eRFPath, reg_addr);
  283. bitshift = rtl8192_CalculateBitShift(bitmask);
  284. reg &= ~bitmask;
  285. reg |= data << bitshift;
  286. rtl8192_phy_RFSerialWrite(dev, eRFPath, reg_addr, reg);
  287. } else {
  288. rtl8192_phy_RFSerialWrite(dev, eRFPath, reg_addr, data);
  289. }
  290. }
  291. }
  292. /******************************************************************************
  293. * function: This function reads specific bits from RF register
  294. * input: net_device *dev
  295. * u32 reg_addr //target addr to be readback
  296. * u32 bitmask //taget bit pos to be readback
  297. * output: none
  298. * return: u32 data //the readback register value
  299. * notice:
  300. *****************************************************************************/
  301. u32 rtl8192_phy_QueryRFReg(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
  302. u32 reg_addr, u32 bitmask)
  303. {
  304. u32 reg, bitshift;
  305. struct r8192_priv *priv = ieee80211_priv(dev);
  306. if (!rtl8192_phy_CheckIsLegalRFPath(dev, eRFPath))
  307. return 0;
  308. if (priv->Rf_Mode == RF_OP_By_FW) {
  309. reg = phy_FwRFSerialRead(dev, eRFPath, reg_addr);
  310. udelay(200);
  311. } else {
  312. reg = rtl8192_phy_RFSerialRead(dev, eRFPath, reg_addr);
  313. }
  314. bitshift = rtl8192_CalculateBitShift(bitmask);
  315. reg = (reg & bitmask) >> bitshift;
  316. return reg;
  317. }
  318. /******************************************************************************
  319. * function: We support firmware to execute RF-R/W.
  320. * input: net_device *dev
  321. * RF90_RADIO_PATH_E eRFPath
  322. * u32 offset
  323. * output: none
  324. * return: u32
  325. * notice:
  326. ****************************************************************************/
  327. static u32 phy_FwRFSerialRead(struct net_device *dev, RF90_RADIO_PATH_E eRFPath,
  328. u32 offset)
  329. {
  330. u32 reg = 0;
  331. u32 data = 0;
  332. u8 time = 0;
  333. u32 tmp;
  334. /* Firmware RF Write control.
  335. * We can not execute the scheme in the initial step.
  336. * Otherwise, RF-R/W will waste much time.
  337. * This is only for site survey. */
  338. /* 1. Read operation need not insert data. bit 0-11 */
  339. /* 2. Write RF register address. bit 12-19 */
  340. data |= ((offset&0xFF)<<12);
  341. /* 3. Write RF path. bit 20-21 */
  342. data |= ((eRFPath&0x3)<<20);
  343. /* 4. Set RF read indicator. bit 22=0 */
  344. /* 5. Trigger Fw to operate the command. bit 31 */
  345. data |= 0x80000000;
  346. /* 6. We can not execute read operation if bit 31 is 1. */
  347. read_nic_dword(dev, QPNR, &tmp);
  348. while (tmp & 0x80000000) {
  349. /* If FW can not finish RF-R/W for more than ?? times.
  350. We must reset FW. */
  351. if (time++ < 100) {
  352. udelay(10);
  353. read_nic_dword(dev, QPNR, &tmp);
  354. } else {
  355. break;
  356. }
  357. }
  358. /* 7. Execute read operation. */
  359. write_nic_dword(dev, QPNR, data);
  360. /* 8. Check if firmware send back RF content. */
  361. read_nic_dword(dev, QPNR, &tmp);
  362. while (tmp & 0x80000000) {
  363. /* If FW can not finish RF-R/W for more than ?? times.
  364. We must reset FW. */
  365. if (time++ < 100) {
  366. udelay(10);
  367. read_nic_dword(dev, QPNR, &tmp);
  368. } else {
  369. return 0;
  370. }
  371. }
  372. read_nic_dword(dev, RF_DATA, &reg);
  373. return reg;
  374. }
  375. /******************************************************************************
  376. * function: We support firmware to execute RF-R/W.
  377. * input: net_device *dev
  378. * RF90_RADIO_PATH_E eRFPath
  379. * u32 offset
  380. * u32 data
  381. * output: none
  382. * return: none
  383. * notice:
  384. ****************************************************************************/
  385. static void phy_FwRFSerialWrite(struct net_device *dev,
  386. RF90_RADIO_PATH_E eRFPath, u32 offset, u32 data)
  387. {
  388. u8 time = 0;
  389. u32 tmp;
  390. /* Firmware RF Write control.
  391. * We can not execute the scheme in the initial step.
  392. * Otherwise, RF-R/W will waste much time.
  393. * This is only for site survey. */
  394. /* 1. Set driver write bit and 12 bit data. bit 0-11 */
  395. /* 2. Write RF register address. bit 12-19 */
  396. data |= ((offset&0xFF)<<12);
  397. /* 3. Write RF path. bit 20-21 */
  398. data |= ((eRFPath&0x3)<<20);
  399. /* 4. Set RF write indicator. bit 22=1 */
  400. data |= 0x400000;
  401. /* 5. Trigger Fw to operate the command. bit 31=1 */
  402. data |= 0x80000000;
  403. /* 6. Write operation. We can not write if bit 31 is 1. */
  404. read_nic_dword(dev, QPNR, &tmp);
  405. while (tmp & 0x80000000) {
  406. /* If FW can not finish RF-R/W for more than ?? times.
  407. We must reset FW. */
  408. if (time++ < 100) {
  409. udelay(10);
  410. read_nic_dword(dev, QPNR, &tmp);
  411. } else {
  412. break;
  413. }
  414. }
  415. /* 7. No matter check bit. We always force the write.
  416. Because FW will not accept the command. */
  417. write_nic_dword(dev, QPNR, data);
  418. /* According to test, we must delay 20us to wait firmware
  419. to finish RF write operation. */
  420. /* We support delay in firmware side now. */
  421. }
  422. /******************************************************************************
  423. * function: This function reads BB parameters from header file we generate,
  424. * and do register read/write
  425. * input: net_device *dev
  426. * output: none
  427. * return: none
  428. * notice: BB parameters may change all the time, so please make
  429. * sure it has been synced with the newest.
  430. *****************************************************************************/
  431. void rtl8192_phy_configmac(struct net_device *dev)
  432. {
  433. u32 dwArrayLen = 0, i;
  434. u32 *pdwArray = NULL;
  435. struct r8192_priv *priv = ieee80211_priv(dev);
  436. if (priv->btxpowerdata_readfromEEPORM) {
  437. RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array_PG\n");
  438. dwArrayLen = MACPHY_Array_PGLength;
  439. pdwArray = rtl819XMACPHY_Array_PG;
  440. } else {
  441. RT_TRACE(COMP_PHY, "Rtl819XMACPHY_Array\n");
  442. dwArrayLen = MACPHY_ArrayLength;
  443. pdwArray = rtl819XMACPHY_Array;
  444. }
  445. for (i = 0; i < dwArrayLen; i = i+3) {
  446. if (pdwArray[i] == 0x318)
  447. pdwArray[i+2] = 0x00000800;
  448. RT_TRACE(COMP_DBG,
  449. "Rtl8190MACPHY_Array[0]=%x Rtl8190MACPHY_Array[1]=%x Rtl8190MACPHY_Array[2]=%x\n",
  450. pdwArray[i], pdwArray[i+1], pdwArray[i+2]);
  451. rtl8192_setBBreg(dev, pdwArray[i], pdwArray[i+1],
  452. pdwArray[i+2]);
  453. }
  454. }
  455. /******************************************************************************
  456. * function: This function does dirty work
  457. * input: net_device *dev
  458. * u8 ConfigType
  459. * output: none
  460. * return: none
  461. * notice: BB parameters may change all the time, so please make
  462. * sure it has been synced with the newest.
  463. *****************************************************************************/
  464. void rtl8192_phyConfigBB(struct net_device *dev, u8 ConfigType)
  465. {
  466. u32 i;
  467. #ifdef TO_DO_LIST
  468. u32 *rtl8192PhyRegArrayTable = NULL, *rtl8192AgcTabArrayTable = NULL;
  469. if (Adapter->bInHctTest) {
  470. PHY_REGArrayLen = PHY_REGArrayLengthDTM;
  471. AGCTAB_ArrayLen = AGCTAB_ArrayLengthDTM;
  472. Rtl8190PHY_REGArray_Table = Rtl819XPHY_REGArrayDTM;
  473. Rtl8190AGCTAB_Array_Table = Rtl819XAGCTAB_ArrayDTM;
  474. }
  475. #endif
  476. if (ConfigType == BaseBand_Config_PHY_REG) {
  477. for (i = 0; i < PHY_REG_1T2RArrayLength; i += 2) {
  478. rtl8192_setBBreg(dev, rtl819XPHY_REG_1T2RArray[i],
  479. bMaskDWord,
  480. rtl819XPHY_REG_1T2RArray[i+1]);
  481. RT_TRACE(COMP_DBG,
  482. "i: %x, Rtl819xUsbPHY_REGArray[0]=%x Rtl819xUsbPHY_REGArray[1]=%x\n",
  483. i, rtl819XPHY_REG_1T2RArray[i],
  484. rtl819XPHY_REG_1T2RArray[i+1]);
  485. }
  486. } else if (ConfigType == BaseBand_Config_AGC_TAB) {
  487. for (i = 0; i < AGCTAB_ArrayLength; i += 2) {
  488. rtl8192_setBBreg(dev, rtl819XAGCTAB_Array[i],
  489. bMaskDWord, rtl819XAGCTAB_Array[i+1]);
  490. RT_TRACE(COMP_DBG,
  491. "i: %x, rtl819XAGCTAB_Array[0]=%x rtl819XAGCTAB_Array[1]=%x\n",
  492. i, rtl819XAGCTAB_Array[i],
  493. rtl819XAGCTAB_Array[i+1]);
  494. }
  495. }
  496. }
  497. /******************************************************************************
  498. * function: This function initializes Register definition offset for
  499. * Radio Path A/B/C/D
  500. * input: net_device *dev
  501. * output: none
  502. * return: none
  503. * notice: Initialization value here is constant and it should never
  504. * be changed
  505. *****************************************************************************/
  506. static void rtl8192_InitBBRFRegDef(struct net_device *dev)
  507. {
  508. struct r8192_priv *priv = ieee80211_priv(dev);
  509. /* RF Interface Software Control */
  510. /* 16 LSBs if read 32-bit from 0x870 */
  511. priv->PHYRegDef[RF90_PATH_A].rfintfs = rFPGA0_XAB_RFInterfaceSW;
  512. /* 16 MSBs if read 32-bit from 0x870 (16-bit for 0x872) */
  513. priv->PHYRegDef[RF90_PATH_B].rfintfs = rFPGA0_XAB_RFInterfaceSW;
  514. /* 16 LSBs if read 32-bit from 0x874 */
  515. priv->PHYRegDef[RF90_PATH_C].rfintfs = rFPGA0_XCD_RFInterfaceSW;
  516. /* 16 MSBs if read 32-bit from 0x874 (16-bit for 0x876) */
  517. priv->PHYRegDef[RF90_PATH_D].rfintfs = rFPGA0_XCD_RFInterfaceSW;
  518. /* RF Interface Readback Value */
  519. /* 16 LSBs if read 32-bit from 0x8E0 */
  520. priv->PHYRegDef[RF90_PATH_A].rfintfi = rFPGA0_XAB_RFInterfaceRB;
  521. /* 16 MSBs if read 32-bit from 0x8E0 (16-bit for 0x8E2) */
  522. priv->PHYRegDef[RF90_PATH_B].rfintfi = rFPGA0_XAB_RFInterfaceRB;
  523. /* 16 LSBs if read 32-bit from 0x8E4 */
  524. priv->PHYRegDef[RF90_PATH_C].rfintfi = rFPGA0_XCD_RFInterfaceRB;
  525. /* 16 MSBs if read 32-bit from 0x8E4 (16-bit for 0x8E6) */
  526. priv->PHYRegDef[RF90_PATH_D].rfintfi = rFPGA0_XCD_RFInterfaceRB;
  527. /* RF Interface Output (and Enable) */
  528. /* 16 LSBs if read 32-bit from 0x860 */
  529. priv->PHYRegDef[RF90_PATH_A].rfintfo = rFPGA0_XA_RFInterfaceOE;
  530. /* 16 LSBs if read 32-bit from 0x864 */
  531. priv->PHYRegDef[RF90_PATH_B].rfintfo = rFPGA0_XB_RFInterfaceOE;
  532. /* 16 LSBs if read 32-bit from 0x868 */
  533. priv->PHYRegDef[RF90_PATH_C].rfintfo = rFPGA0_XC_RFInterfaceOE;
  534. /* 16 LSBs if read 32-bit from 0x86C */
  535. priv->PHYRegDef[RF90_PATH_D].rfintfo = rFPGA0_XD_RFInterfaceOE;
  536. /* RF Interface (Output and) Enable */
  537. /* 16 MSBs if read 32-bit from 0x860 (16-bit for 0x862) */
  538. priv->PHYRegDef[RF90_PATH_A].rfintfe = rFPGA0_XA_RFInterfaceOE;
  539. /* 16 MSBs if read 32-bit from 0x864 (16-bit for 0x866) */
  540. priv->PHYRegDef[RF90_PATH_B].rfintfe = rFPGA0_XB_RFInterfaceOE;
  541. /* 16 MSBs if read 32-bit from 0x86A (16-bit for 0x86A) */
  542. priv->PHYRegDef[RF90_PATH_C].rfintfe = rFPGA0_XC_RFInterfaceOE;
  543. /* 16 MSBs if read 32-bit from 0x86C (16-bit for 0x86E) */
  544. priv->PHYRegDef[RF90_PATH_D].rfintfe = rFPGA0_XD_RFInterfaceOE;
  545. /* Addr of LSSI. Write RF register by driver */
  546. priv->PHYRegDef[RF90_PATH_A].rf3wireOffset = rFPGA0_XA_LSSIParameter;
  547. priv->PHYRegDef[RF90_PATH_B].rf3wireOffset = rFPGA0_XB_LSSIParameter;
  548. priv->PHYRegDef[RF90_PATH_C].rf3wireOffset = rFPGA0_XC_LSSIParameter;
  549. priv->PHYRegDef[RF90_PATH_D].rf3wireOffset = rFPGA0_XD_LSSIParameter;
  550. /* RF parameter */
  551. /* BB Band Select */
  552. priv->PHYRegDef[RF90_PATH_A].rfLSSI_Select = rFPGA0_XAB_RFParameter;
  553. priv->PHYRegDef[RF90_PATH_B].rfLSSI_Select = rFPGA0_XAB_RFParameter;
  554. priv->PHYRegDef[RF90_PATH_C].rfLSSI_Select = rFPGA0_XCD_RFParameter;
  555. priv->PHYRegDef[RF90_PATH_D].rfLSSI_Select = rFPGA0_XCD_RFParameter;
  556. /* Tx AGC Gain Stage (same for all path. Should we remove this?) */
  557. priv->PHYRegDef[RF90_PATH_A].rfTxGainStage = rFPGA0_TxGainStage;
  558. priv->PHYRegDef[RF90_PATH_B].rfTxGainStage = rFPGA0_TxGainStage;
  559. priv->PHYRegDef[RF90_PATH_C].rfTxGainStage = rFPGA0_TxGainStage;
  560. priv->PHYRegDef[RF90_PATH_D].rfTxGainStage = rFPGA0_TxGainStage;
  561. /* Tranceiver A~D HSSI Parameter-1 */
  562. /* wire control parameter1 */
  563. priv->PHYRegDef[RF90_PATH_A].rfHSSIPara1 = rFPGA0_XA_HSSIParameter1;
  564. priv->PHYRegDef[RF90_PATH_B].rfHSSIPara1 = rFPGA0_XB_HSSIParameter1;
  565. priv->PHYRegDef[RF90_PATH_C].rfHSSIPara1 = rFPGA0_XC_HSSIParameter1;
  566. priv->PHYRegDef[RF90_PATH_D].rfHSSIPara1 = rFPGA0_XD_HSSIParameter1;
  567. /* Tranceiver A~D HSSI Parameter-2 */
  568. /* wire control parameter2 */
  569. priv->PHYRegDef[RF90_PATH_A].rfHSSIPara2 = rFPGA0_XA_HSSIParameter2;
  570. priv->PHYRegDef[RF90_PATH_B].rfHSSIPara2 = rFPGA0_XB_HSSIParameter2;
  571. priv->PHYRegDef[RF90_PATH_C].rfHSSIPara2 = rFPGA0_XC_HSSIParameter2;
  572. priv->PHYRegDef[RF90_PATH_D].rfHSSIPara2 = rFPGA0_XD_HSSIParameter2;
  573. /* RF Switch Control */
  574. /* TR/Ant switch control */
  575. priv->PHYRegDef[RF90_PATH_A].rfSwitchControl = rFPGA0_XAB_SwitchControl;
  576. priv->PHYRegDef[RF90_PATH_B].rfSwitchControl = rFPGA0_XAB_SwitchControl;
  577. priv->PHYRegDef[RF90_PATH_C].rfSwitchControl = rFPGA0_XCD_SwitchControl;
  578. priv->PHYRegDef[RF90_PATH_D].rfSwitchControl = rFPGA0_XCD_SwitchControl;
  579. /* AGC control 1 */
  580. priv->PHYRegDef[RF90_PATH_A].rfAGCControl1 = rOFDM0_XAAGCCore1;
  581. priv->PHYRegDef[RF90_PATH_B].rfAGCControl1 = rOFDM0_XBAGCCore1;
  582. priv->PHYRegDef[RF90_PATH_C].rfAGCControl1 = rOFDM0_XCAGCCore1;
  583. priv->PHYRegDef[RF90_PATH_D].rfAGCControl1 = rOFDM0_XDAGCCore1;
  584. /* AGC control 2 */
  585. priv->PHYRegDef[RF90_PATH_A].rfAGCControl2 = rOFDM0_XAAGCCore2;
  586. priv->PHYRegDef[RF90_PATH_B].rfAGCControl2 = rOFDM0_XBAGCCore2;
  587. priv->PHYRegDef[RF90_PATH_C].rfAGCControl2 = rOFDM0_XCAGCCore2;
  588. priv->PHYRegDef[RF90_PATH_D].rfAGCControl2 = rOFDM0_XDAGCCore2;
  589. /* RX AFE control 1 */
  590. priv->PHYRegDef[RF90_PATH_A].rfRxIQImbalance = rOFDM0_XARxIQImbalance;
  591. priv->PHYRegDef[RF90_PATH_B].rfRxIQImbalance = rOFDM0_XBRxIQImbalance;
  592. priv->PHYRegDef[RF90_PATH_C].rfRxIQImbalance = rOFDM0_XCRxIQImbalance;
  593. priv->PHYRegDef[RF90_PATH_D].rfRxIQImbalance = rOFDM0_XDRxIQImbalance;
  594. /* RX AFE control 1 */
  595. priv->PHYRegDef[RF90_PATH_A].rfRxAFE = rOFDM0_XARxAFE;
  596. priv->PHYRegDef[RF90_PATH_B].rfRxAFE = rOFDM0_XBRxAFE;
  597. priv->PHYRegDef[RF90_PATH_C].rfRxAFE = rOFDM0_XCRxAFE;
  598. priv->PHYRegDef[RF90_PATH_D].rfRxAFE = rOFDM0_XDRxAFE;
  599. /* Tx AFE control 1 */
  600. priv->PHYRegDef[RF90_PATH_A].rfTxIQImbalance = rOFDM0_XATxIQImbalance;
  601. priv->PHYRegDef[RF90_PATH_B].rfTxIQImbalance = rOFDM0_XBTxIQImbalance;
  602. priv->PHYRegDef[RF90_PATH_C].rfTxIQImbalance = rOFDM0_XCTxIQImbalance;
  603. priv->PHYRegDef[RF90_PATH_D].rfTxIQImbalance = rOFDM0_XDTxIQImbalance;
  604. /* Tx AFE control 2 */
  605. priv->PHYRegDef[RF90_PATH_A].rfTxAFE = rOFDM0_XATxAFE;
  606. priv->PHYRegDef[RF90_PATH_B].rfTxAFE = rOFDM0_XBTxAFE;
  607. priv->PHYRegDef[RF90_PATH_C].rfTxAFE = rOFDM0_XCTxAFE;
  608. priv->PHYRegDef[RF90_PATH_D].rfTxAFE = rOFDM0_XDTxAFE;
  609. /* Tranceiver LSSI Readback */
  610. priv->PHYRegDef[RF90_PATH_A].rfLSSIReadBack = rFPGA0_XA_LSSIReadBack;
  611. priv->PHYRegDef[RF90_PATH_B].rfLSSIReadBack = rFPGA0_XB_LSSIReadBack;
  612. priv->PHYRegDef[RF90_PATH_C].rfLSSIReadBack = rFPGA0_XC_LSSIReadBack;
  613. priv->PHYRegDef[RF90_PATH_D].rfLSSIReadBack = rFPGA0_XD_LSSIReadBack;
  614. }
  615. /******************************************************************************
  616. * function: This function is to write register and then readback to make
  617. * sure whether BB and RF is OK
  618. * input: net_device *dev
  619. * HW90_BLOCK_E CheckBlock
  620. * RF90_RADIO_PATH_E eRFPath //only used when checkblock is
  621. * //HW90_BLOCK_RF
  622. * output: none
  623. * return: return whether BB and RF is ok (0:OK, 1:Fail)
  624. * notice: This function may be removed in the ASIC
  625. ******************************************************************************/
  626. u8 rtl8192_phy_checkBBAndRF(struct net_device *dev, HW90_BLOCK_E CheckBlock,
  627. RF90_RADIO_PATH_E eRFPath)
  628. {
  629. u8 ret = 0;
  630. u32 i, CheckTimes = 4, reg = 0;
  631. u32 WriteAddr[4];
  632. u32 WriteData[] = {0xfffff027, 0xaa55a02f, 0x00000027, 0x55aa502f};
  633. /* Initialize register address offset to be checked */
  634. WriteAddr[HW90_BLOCK_MAC] = 0x100;
  635. WriteAddr[HW90_BLOCK_PHY0] = 0x900;
  636. WriteAddr[HW90_BLOCK_PHY1] = 0x800;
  637. WriteAddr[HW90_BLOCK_RF] = 0x3;
  638. RT_TRACE(COMP_PHY, "%s(), CheckBlock: %d\n", __func__, CheckBlock);
  639. for (i = 0; i < CheckTimes; i++) {
  640. /* Write data to register and readback */
  641. switch (CheckBlock) {
  642. case HW90_BLOCK_MAC:
  643. RT_TRACE(COMP_ERR,
  644. "PHY_CheckBBRFOK(): Never Write 0x100 here!\n");
  645. break;
  646. case HW90_BLOCK_PHY0:
  647. case HW90_BLOCK_PHY1:
  648. write_nic_dword(dev, WriteAddr[CheckBlock],
  649. WriteData[i]);
  650. read_nic_dword(dev, WriteAddr[CheckBlock], &reg);
  651. break;
  652. case HW90_BLOCK_RF:
  653. WriteData[i] &= 0xfff;
  654. rtl8192_phy_SetRFReg(dev, eRFPath,
  655. WriteAddr[HW90_BLOCK_RF],
  656. bMask12Bits, WriteData[i]);
  657. /* TODO: we should not delay for such a long time.
  658. Ask SD3 */
  659. usleep_range(1000, 1000);
  660. reg = rtl8192_phy_QueryRFReg(dev, eRFPath,
  661. WriteAddr[HW90_BLOCK_RF],
  662. bMask12Bits);
  663. usleep_range(1000, 1000);
  664. break;
  665. default:
  666. ret = 1;
  667. break;
  668. }
  669. /* Check whether readback data is correct */
  670. if (reg != WriteData[i]) {
  671. RT_TRACE((COMP_PHY|COMP_ERR),
  672. "error reg: %x, WriteData: %x\n",
  673. reg, WriteData[i]);
  674. ret = 1;
  675. break;
  676. }
  677. }
  678. return ret;
  679. }
  680. /******************************************************************************
  681. * function: This function initializes BB&RF
  682. * input: net_device *dev
  683. * output: none
  684. * return: none
  685. * notice: Initialization value may change all the time, so please make
  686. * sure it has been synced with the newest.
  687. ******************************************************************************/
  688. static void rtl8192_BB_Config_ParaFile(struct net_device *dev)
  689. {
  690. struct r8192_priv *priv = ieee80211_priv(dev);
  691. u8 reg_u8 = 0, eCheckItem = 0, status = 0;
  692. u32 reg_u32 = 0;
  693. /**************************************
  694. * <1> Initialize BaseBand
  695. *************************************/
  696. /* --set BB Global Reset-- */
  697. read_nic_byte(dev, BB_GLOBAL_RESET, &reg_u8);
  698. write_nic_byte(dev, BB_GLOBAL_RESET, (reg_u8|BB_GLOBAL_RESET_BIT));
  699. mdelay(50);
  700. /* ---set BB reset Active--- */
  701. read_nic_dword(dev, CPU_GEN, &reg_u32);
  702. write_nic_dword(dev, CPU_GEN, (reg_u32&(~CPU_GEN_BB_RST)));
  703. /* ----Ckeck FPGAPHY0 and PHY1 board is OK---- */
  704. /* TODO: this function should be removed on ASIC */
  705. for (eCheckItem = (HW90_BLOCK_E)HW90_BLOCK_PHY0;
  706. eCheckItem <= HW90_BLOCK_PHY1; eCheckItem++) {
  707. /* don't care RF path */
  708. status = rtl8192_phy_checkBBAndRF(dev, (HW90_BLOCK_E)eCheckItem,
  709. (RF90_RADIO_PATH_E)0);
  710. if (status != 0) {
  711. RT_TRACE((COMP_ERR | COMP_PHY),
  712. "PHY_RF8256_Config(): Check PHY%d Fail!!\n",
  713. eCheckItem-1);
  714. return;
  715. }
  716. }
  717. /* ---- Set CCK and OFDM Block "OFF"---- */
  718. rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn|bOFDMEn, 0x0);
  719. /* ----BB Register Initilazation---- */
  720. /* ==m==>Set PHY REG From Header<==m== */
  721. rtl8192_phyConfigBB(dev, BaseBand_Config_PHY_REG);
  722. /* ----Set BB reset de-Active---- */
  723. read_nic_dword(dev, CPU_GEN, &reg_u32);
  724. write_nic_dword(dev, CPU_GEN, (reg_u32|CPU_GEN_BB_RST));
  725. /* ----BB AGC table Initialization---- */
  726. /* ==m==>Set PHY REG From Header<==m== */
  727. rtl8192_phyConfigBB(dev, BaseBand_Config_AGC_TAB);
  728. /* ----Enable XSTAL ---- */
  729. write_nic_byte_E(dev, 0x5e, 0x00);
  730. if (priv->card_8192_version == (u8)VERSION_819xU_A) {
  731. /* Antenna gain offset from B/C/D to A */
  732. reg_u32 = priv->AntennaTxPwDiff[1]<<4 |
  733. priv->AntennaTxPwDiff[0];
  734. rtl8192_setBBreg(dev, rFPGA0_TxGainStage, (bXBTxAGC|bXCTxAGC),
  735. reg_u32);
  736. /* XSTALLCap */
  737. reg_u32 = priv->CrystalCap & 0xf;
  738. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, bXtalCap,
  739. reg_u32);
  740. }
  741. /* Check if the CCK HighPower is turned ON.
  742. This is used to calculate PWDB. */
  743. priv->bCckHighPower = (u8)rtl8192_QueryBBReg(dev,
  744. rFPGA0_XA_HSSIParameter2,
  745. 0x200);
  746. }
  747. /******************************************************************************
  748. * function: This function initializes BB&RF
  749. * input: net_device *dev
  750. * output: none
  751. * return: none
  752. * notice: Initialization value may change all the time, so please make
  753. * sure it has been synced with the newest.
  754. *****************************************************************************/
  755. void rtl8192_BBConfig(struct net_device *dev)
  756. {
  757. rtl8192_InitBBRFRegDef(dev);
  758. /* config BB&RF. As hardCode based initialization has not been well
  759. * implemented, so use file first.
  760. * FIXME: should implement it for hardcode? */
  761. rtl8192_BB_Config_ParaFile(dev);
  762. }
  763. /******************************************************************************
  764. * function: This function obtains the initialization value of Tx power Level
  765. * offset
  766. * input: net_device *dev
  767. * output: none
  768. * return: none
  769. *****************************************************************************/
  770. void rtl8192_phy_getTxPower(struct net_device *dev)
  771. {
  772. struct r8192_priv *priv = ieee80211_priv(dev);
  773. u8 tmp;
  774. read_nic_dword(dev, rTxAGC_Rate18_06,
  775. &priv->MCSTxPowerLevelOriginalOffset[0]);
  776. read_nic_dword(dev, rTxAGC_Rate54_24,
  777. &priv->MCSTxPowerLevelOriginalOffset[1]);
  778. read_nic_dword(dev, rTxAGC_Mcs03_Mcs00,
  779. &priv->MCSTxPowerLevelOriginalOffset[2]);
  780. read_nic_dword(dev, rTxAGC_Mcs07_Mcs04,
  781. &priv->MCSTxPowerLevelOriginalOffset[3]);
  782. read_nic_dword(dev, rTxAGC_Mcs11_Mcs08,
  783. &priv->MCSTxPowerLevelOriginalOffset[4]);
  784. read_nic_dword(dev, rTxAGC_Mcs15_Mcs12,
  785. &priv->MCSTxPowerLevelOriginalOffset[5]);
  786. /* Read rx initial gain */
  787. read_nic_byte(dev, rOFDM0_XAAGCCore1, &priv->DefaultInitialGain[0]);
  788. read_nic_byte(dev, rOFDM0_XBAGCCore1, &priv->DefaultInitialGain[1]);
  789. read_nic_byte(dev, rOFDM0_XCAGCCore1, &priv->DefaultInitialGain[2]);
  790. read_nic_byte(dev, rOFDM0_XDAGCCore1, &priv->DefaultInitialGain[3]);
  791. RT_TRACE(COMP_INIT,
  792. "Default initial gain (c50=0x%x, c58=0x%x, c60=0x%x, c68=0x%x)\n",
  793. priv->DefaultInitialGain[0], priv->DefaultInitialGain[1],
  794. priv->DefaultInitialGain[2], priv->DefaultInitialGain[3]);
  795. /* Read framesync */
  796. read_nic_byte(dev, rOFDM0_RxDetector3, &priv->framesync);
  797. read_nic_byte(dev, rOFDM0_RxDetector2, &tmp);
  798. priv->framesyncC34 = tmp;
  799. RT_TRACE(COMP_INIT, "Default framesync (0x%x) = 0x%x\n",
  800. rOFDM0_RxDetector3, priv->framesync);
  801. /* Read SIFS (save the value read fome MACPHY_REG.txt) */
  802. read_nic_word(dev, SIFS, &priv->SifsTime);
  803. }
  804. /******************************************************************************
  805. * function: This function sets the initialization value of Tx power Level
  806. * offset
  807. * input: net_device *dev
  808. * u8 channel
  809. * output: none
  810. * return: none
  811. ******************************************************************************/
  812. void rtl8192_phy_setTxPower(struct net_device *dev, u8 channel)
  813. {
  814. struct r8192_priv *priv = ieee80211_priv(dev);
  815. u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
  816. u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
  817. switch (priv->rf_chip) {
  818. case RF_8256:
  819. /* need further implement */
  820. PHY_SetRF8256CCKTxPower(dev, powerlevel);
  821. PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
  822. break;
  823. default:
  824. RT_TRACE((COMP_PHY|COMP_ERR),
  825. "error RF chipID(8225 or 8258) in function %s()\n",
  826. __func__);
  827. break;
  828. }
  829. }
  830. /******************************************************************************
  831. * function: This function checks Rf chip to do RF config
  832. * input: net_device *dev
  833. * output: none
  834. * return: only 8256 is supported
  835. ******************************************************************************/
  836. void rtl8192_phy_RFConfig(struct net_device *dev)
  837. {
  838. struct r8192_priv *priv = ieee80211_priv(dev);
  839. switch (priv->rf_chip) {
  840. case RF_8256:
  841. PHY_RF8256_Config(dev);
  842. break;
  843. default:
  844. RT_TRACE(COMP_ERR, "error chip id\n");
  845. break;
  846. }
  847. }
  848. /******************************************************************************
  849. * function: This function updates Initial gain
  850. * input: net_device *dev
  851. * output: none
  852. * return: As Windows has not implemented this, wait for complement
  853. ******************************************************************************/
  854. void rtl8192_phy_updateInitGain(struct net_device *dev)
  855. {
  856. }
  857. /******************************************************************************
  858. * function: This function read RF parameters from general head file,
  859. * and do RF 3-wire
  860. * input: net_device *dev
  861. * RF90_RADIO_PATH_E eRFPath
  862. * output: none
  863. * return: return code show if RF configuration is successful(0:pass, 1:fail)
  864. * notice: Delay may be required for RF configuration
  865. *****************************************************************************/
  866. u8 rtl8192_phy_ConfigRFWithHeaderFile(struct net_device *dev,
  867. RF90_RADIO_PATH_E eRFPath)
  868. {
  869. int i;
  870. switch (eRFPath) {
  871. case RF90_PATH_A:
  872. for (i = 0; i < RadioA_ArrayLength; i = i+2) {
  873. if (rtl819XRadioA_Array[i] == 0xfe) {
  874. mdelay(100);
  875. continue;
  876. }
  877. rtl8192_phy_SetRFReg(dev, eRFPath,
  878. rtl819XRadioA_Array[i],
  879. bMask12Bits,
  880. rtl819XRadioA_Array[i+1]);
  881. mdelay(1);
  882. }
  883. break;
  884. case RF90_PATH_B:
  885. for (i = 0; i < RadioB_ArrayLength; i = i+2) {
  886. if (rtl819XRadioB_Array[i] == 0xfe) {
  887. mdelay(100);
  888. continue;
  889. }
  890. rtl8192_phy_SetRFReg(dev, eRFPath,
  891. rtl819XRadioB_Array[i],
  892. bMask12Bits,
  893. rtl819XRadioB_Array[i+1]);
  894. mdelay(1);
  895. }
  896. break;
  897. case RF90_PATH_C:
  898. for (i = 0; i < RadioC_ArrayLength; i = i+2) {
  899. if (rtl819XRadioC_Array[i] == 0xfe) {
  900. mdelay(100);
  901. continue;
  902. }
  903. rtl8192_phy_SetRFReg(dev, eRFPath,
  904. rtl819XRadioC_Array[i],
  905. bMask12Bits,
  906. rtl819XRadioC_Array[i+1]);
  907. mdelay(1);
  908. }
  909. break;
  910. case RF90_PATH_D:
  911. for (i = 0; i < RadioD_ArrayLength; i = i+2) {
  912. if (rtl819XRadioD_Array[i] == 0xfe) {
  913. mdelay(100);
  914. continue;
  915. }
  916. rtl8192_phy_SetRFReg(dev, eRFPath,
  917. rtl819XRadioD_Array[i],
  918. bMask12Bits,
  919. rtl819XRadioD_Array[i+1]);
  920. mdelay(1);
  921. }
  922. break;
  923. default:
  924. break;
  925. }
  926. return 0;
  927. }
  928. /******************************************************************************
  929. * function: This function sets Tx Power of the channel
  930. * input: net_device *dev
  931. * u8 channel
  932. * output: none
  933. * return: none
  934. * notice:
  935. ******************************************************************************/
  936. static void rtl8192_SetTxPowerLevel(struct net_device *dev, u8 channel)
  937. {
  938. struct r8192_priv *priv = ieee80211_priv(dev);
  939. u8 powerlevel = priv->TxPowerLevelCCK[channel-1];
  940. u8 powerlevelOFDM24G = priv->TxPowerLevelOFDM24G[channel-1];
  941. switch (priv->rf_chip) {
  942. case RF_8225:
  943. #ifdef TO_DO_LIST
  944. PHY_SetRF8225CckTxPower(Adapter, powerlevel);
  945. PHY_SetRF8225OfdmTxPower(Adapter, powerlevelOFDM24G);
  946. #endif
  947. break;
  948. case RF_8256:
  949. PHY_SetRF8256CCKTxPower(dev, powerlevel);
  950. PHY_SetRF8256OFDMTxPower(dev, powerlevelOFDM24G);
  951. break;
  952. case RF_8258:
  953. break;
  954. default:
  955. RT_TRACE(COMP_ERR, "unknown rf chip ID in %s()\n", __func__);
  956. break;
  957. }
  958. }
  959. /******************************************************************************
  960. * function: This function sets RF state on or off
  961. * input: net_device *dev
  962. * RT_RF_POWER_STATE eRFPowerState //Power State to set
  963. * output: none
  964. * return: none
  965. * notice:
  966. *****************************************************************************/
  967. bool rtl8192_SetRFPowerState(struct net_device *dev,
  968. RT_RF_POWER_STATE eRFPowerState)
  969. {
  970. bool bResult = true;
  971. struct r8192_priv *priv = ieee80211_priv(dev);
  972. if (eRFPowerState == priv->ieee80211->eRFPowerState)
  973. return false;
  974. if (priv->SetRFPowerStateInProgress)
  975. return false;
  976. priv->SetRFPowerStateInProgress = true;
  977. switch (priv->rf_chip) {
  978. case RF_8256:
  979. switch (eRFPowerState) {
  980. case eRfOn:
  981. /* RF-A, RF-B */
  982. /* enable RF-Chip A/B - 0x860[4] */
  983. rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT(4),
  984. 0x1);
  985. /* analog to digital on - 0x88c[9:8] */
  986. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300,
  987. 0x3);
  988. /* digital to analog on - 0x880[4:3] */
  989. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18,
  990. 0x3);
  991. /* rx antenna on - 0xc04[1:0] */
  992. rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x3, 0x3);
  993. /* rx antenna on - 0xd04[1:0] */
  994. rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x3, 0x3);
  995. /* analog to digital part2 on - 0x880[6:5] */
  996. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60,
  997. 0x3);
  998. break;
  999. case eRfSleep:
  1000. break;
  1001. case eRfOff:
  1002. /* RF-A, RF-B */
  1003. /* disable RF-Chip A/B - 0x860[4] */
  1004. rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT(4),
  1005. 0x0);
  1006. /* analog to digital off, for power save */
  1007. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0xf00,
  1008. 0x0); /* 0x88c[11:8] */
  1009. /* digital to analog off, for power save - 0x880[4:3] */
  1010. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18,
  1011. 0x0);
  1012. /* rx antenna off - 0xc04[3:0] */
  1013. rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);
  1014. /* rx antenna off - 0xd04[3:0] */
  1015. rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
  1016. /* analog to digital part2 off, for power save */
  1017. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60,
  1018. 0x0); /* 0x880[6:5] */
  1019. break;
  1020. default:
  1021. bResult = false;
  1022. RT_TRACE(COMP_ERR, "%s(): unknown state to set: 0x%X\n",
  1023. __func__, eRFPowerState);
  1024. break;
  1025. }
  1026. break;
  1027. default:
  1028. RT_TRACE(COMP_ERR, "Not support rf_chip(%x)\n", priv->rf_chip);
  1029. break;
  1030. }
  1031. #ifdef TO_DO_LIST
  1032. if (bResult) {
  1033. /* Update current RF state variable. */
  1034. pHalData->eRFPowerState = eRFPowerState;
  1035. switch (pHalData->RFChipID) {
  1036. case RF_8256:
  1037. switch (pHalData->eRFPowerState) {
  1038. case eRfOff:
  1039. /* If Rf off reason is from IPS,
  1040. LED should blink with no link */
  1041. if (pMgntInfo->RfOffReason == RF_CHANGE_BY_IPS)
  1042. Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
  1043. else
  1044. /* Turn off LED if RF is not ON. */
  1045. Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_OFF);
  1046. break;
  1047. case eRfOn:
  1048. /* Turn on RF we are still linked, which might
  1049. happen when we quickly turn off and on HW RF.
  1050. */
  1051. if (pMgntInfo->bMediaConnect)
  1052. Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_LINK);
  1053. else
  1054. /* Turn off LED if RF is not ON. */
  1055. Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_NO_LINK);
  1056. break;
  1057. default:
  1058. break;
  1059. }
  1060. break;
  1061. default:
  1062. RT_TRACE(COMP_RF, DBG_LOUD, "%s(): Unknown RF type\n",
  1063. __func__);
  1064. break;
  1065. }
  1066. }
  1067. #endif
  1068. priv->SetRFPowerStateInProgress = false;
  1069. return bResult;
  1070. }
  1071. /******************************************************************************
  1072. * function: This function sets command table variable (struct SwChnlCmd).
  1073. * input: SwChnlCmd *CmdTable //table to be set
  1074. * u32 CmdTableIdx //variable index in table to be set
  1075. * u32 CmdTableSz //table size
  1076. * SwChnlCmdID CmdID //command ID to set
  1077. * u32 Para1
  1078. * u32 Para2
  1079. * u32 msDelay
  1080. * output:
  1081. * return: true if finished, false otherwise
  1082. * notice:
  1083. ******************************************************************************/
  1084. static u8 rtl8192_phy_SetSwChnlCmdArray(SwChnlCmd *CmdTable, u32 CmdTableIdx,
  1085. u32 CmdTableSz, SwChnlCmdID CmdID,
  1086. u32 Para1, u32 Para2, u32 msDelay)
  1087. {
  1088. SwChnlCmd *pCmd;
  1089. if (CmdTable == NULL) {
  1090. RT_TRACE(COMP_ERR, "%s(): CmdTable cannot be NULL\n", __func__);
  1091. return false;
  1092. }
  1093. if (CmdTableIdx >= CmdTableSz) {
  1094. RT_TRACE(COMP_ERR, "%s(): Access invalid index, please check size of the table, CmdTableIdx:%d, CmdTableSz:%d\n",
  1095. __func__, CmdTableIdx, CmdTableSz);
  1096. return false;
  1097. }
  1098. pCmd = CmdTable + CmdTableIdx;
  1099. pCmd->CmdID = CmdID;
  1100. pCmd->Para1 = Para1;
  1101. pCmd->Para2 = Para2;
  1102. pCmd->msDelay = msDelay;
  1103. return true;
  1104. }
  1105. /******************************************************************************
  1106. * function: This function sets channel step by step
  1107. * input: net_device *dev
  1108. * u8 channel
  1109. * u8 *stage //3 stages
  1110. * u8 *step
  1111. * u32 *delay //whether need to delay
  1112. * output: store new stage, step and delay for next step
  1113. * (combine with function above)
  1114. * return: true if finished, false otherwise
  1115. * notice: Wait for simpler function to replace it
  1116. *****************************************************************************/
  1117. static u8 rtl8192_phy_SwChnlStepByStep(struct net_device *dev, u8 channel,
  1118. u8 *stage, u8 *step, u32 *delay)
  1119. {
  1120. struct r8192_priv *priv = ieee80211_priv(dev);
  1121. SwChnlCmd PreCommonCmd[MAX_PRECMD_CNT];
  1122. u32 PreCommonCmdCnt;
  1123. SwChnlCmd PostCommonCmd[MAX_POSTCMD_CNT];
  1124. u32 PostCommonCmdCnt;
  1125. SwChnlCmd RfDependCmd[MAX_RFDEPENDCMD_CNT];
  1126. u32 RfDependCmdCnt;
  1127. SwChnlCmd *CurrentCmd = NULL;
  1128. u8 eRFPath;
  1129. RT_TRACE(COMP_CH, "%s() stage: %d, step: %d, channel: %d\n",
  1130. __func__, *stage, *step, channel);
  1131. if (!IsLegalChannel(priv->ieee80211, channel)) {
  1132. RT_TRACE(COMP_ERR, "set to illegal channel: %d\n", channel);
  1133. /* return true to tell upper caller function this channel
  1134. setting is finished! Or it will in while loop. */
  1135. return true;
  1136. }
  1137. /* FIXME: need to check whether channel is legal or not here */
  1138. /* <1> Fill up pre common command. */
  1139. PreCommonCmdCnt = 0;
  1140. rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++,
  1141. MAX_PRECMD_CNT, CmdID_SetTxPowerLevel,
  1142. 0, 0, 0);
  1143. rtl8192_phy_SetSwChnlCmdArray(PreCommonCmd, PreCommonCmdCnt++,
  1144. MAX_PRECMD_CNT, CmdID_End, 0, 0, 0);
  1145. /* <2> Fill up post common command. */
  1146. PostCommonCmdCnt = 0;
  1147. rtl8192_phy_SetSwChnlCmdArray(PostCommonCmd, PostCommonCmdCnt++,
  1148. MAX_POSTCMD_CNT, CmdID_End, 0, 0, 0);
  1149. /* <3> Fill up RF dependent command. */
  1150. RfDependCmdCnt = 0;
  1151. switch (priv->rf_chip) {
  1152. case RF_8225:
  1153. if (!(channel >= 1 && channel <= 14)) {
  1154. RT_TRACE(COMP_ERR,
  1155. "illegal channel for Zebra 8225: %d\n",
  1156. channel);
  1157. return true;
  1158. }
  1159. rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
  1160. MAX_RFDEPENDCMD_CNT,
  1161. CmdID_RF_WriteReg,
  1162. rZebra1_Channel,
  1163. RF_CHANNEL_TABLE_ZEBRA[channel],
  1164. 10);
  1165. rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
  1166. MAX_RFDEPENDCMD_CNT,
  1167. CmdID_End, 0, 0, 0);
  1168. break;
  1169. case RF_8256:
  1170. /* TEST!! This is not the table for 8256!! */
  1171. if (!(channel >= 1 && channel <= 14)) {
  1172. RT_TRACE(COMP_ERR,
  1173. "illegal channel for Zebra 8256: %d\n",
  1174. channel);
  1175. return true;
  1176. }
  1177. rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
  1178. MAX_RFDEPENDCMD_CNT,
  1179. CmdID_RF_WriteReg,
  1180. rZebra1_Channel, channel, 10);
  1181. rtl8192_phy_SetSwChnlCmdArray(RfDependCmd, RfDependCmdCnt++,
  1182. MAX_RFDEPENDCMD_CNT,
  1183. CmdID_End, 0, 0, 0);
  1184. break;
  1185. case RF_8258:
  1186. break;
  1187. default:
  1188. RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
  1189. return true;
  1190. }
  1191. do {
  1192. switch (*stage) {
  1193. case 0:
  1194. CurrentCmd = &PreCommonCmd[*step];
  1195. break;
  1196. case 1:
  1197. CurrentCmd = &RfDependCmd[*step];
  1198. break;
  1199. case 2:
  1200. CurrentCmd = &PostCommonCmd[*step];
  1201. break;
  1202. }
  1203. if (CurrentCmd->CmdID == CmdID_End) {
  1204. if ((*stage) == 2) {
  1205. (*delay) = CurrentCmd->msDelay;
  1206. return true;
  1207. }
  1208. (*stage)++;
  1209. (*step) = 0;
  1210. continue;
  1211. }
  1212. switch (CurrentCmd->CmdID) {
  1213. case CmdID_SetTxPowerLevel:
  1214. if (priv->card_8192_version == (u8)VERSION_819xU_A)
  1215. /* consider it later! */
  1216. rtl8192_SetTxPowerLevel(dev, channel);
  1217. break;
  1218. case CmdID_WritePortUlong:
  1219. write_nic_dword(dev, CurrentCmd->Para1,
  1220. CurrentCmd->Para2);
  1221. break;
  1222. case CmdID_WritePortUshort:
  1223. write_nic_word(dev, CurrentCmd->Para1,
  1224. (u16)CurrentCmd->Para2);
  1225. break;
  1226. case CmdID_WritePortUchar:
  1227. write_nic_byte(dev, CurrentCmd->Para1,
  1228. (u8)CurrentCmd->Para2);
  1229. break;
  1230. case CmdID_RF_WriteReg:
  1231. for (eRFPath = 0; eRFPath < RF90_PATH_MAX; eRFPath++) {
  1232. rtl8192_phy_SetRFReg(dev,
  1233. (RF90_RADIO_PATH_E)eRFPath,
  1234. CurrentCmd->Para1,
  1235. bZebra1_ChannelNum,
  1236. CurrentCmd->Para2);
  1237. }
  1238. break;
  1239. default:
  1240. break;
  1241. }
  1242. break;
  1243. } while (true);
  1244. (*delay) = CurrentCmd->msDelay;
  1245. (*step)++;
  1246. return false;
  1247. }
  1248. /******************************************************************************
  1249. * function: This function does actually set channel work
  1250. * input: net_device *dev
  1251. * u8 channel
  1252. * output: none
  1253. * return: none
  1254. * notice: We should not call this function directly
  1255. *****************************************************************************/
  1256. static void rtl8192_phy_FinishSwChnlNow(struct net_device *dev, u8 channel)
  1257. {
  1258. struct r8192_priv *priv = ieee80211_priv(dev);
  1259. u32 delay = 0;
  1260. while (!rtl8192_phy_SwChnlStepByStep(dev, channel, &priv->SwChnlStage,
  1261. &priv->SwChnlStep, &delay)) {
  1262. if (!priv->up)
  1263. break;
  1264. }
  1265. }
  1266. /******************************************************************************
  1267. * function: Callback routine of the work item for switch channel.
  1268. * input: net_device *dev
  1269. *
  1270. * output: none
  1271. * return: none
  1272. *****************************************************************************/
  1273. void rtl8192_SwChnl_WorkItem(struct net_device *dev)
  1274. {
  1275. struct r8192_priv *priv = ieee80211_priv(dev);
  1276. RT_TRACE(COMP_CH, "==> SwChnlCallback819xUsbWorkItem(), chan:%d\n",
  1277. priv->chan);
  1278. rtl8192_phy_FinishSwChnlNow(dev, priv->chan);
  1279. RT_TRACE(COMP_CH, "<== SwChnlCallback819xUsbWorkItem()\n");
  1280. }
  1281. /******************************************************************************
  1282. * function: This function scheduled actual work item to set channel
  1283. * input: net_device *dev
  1284. * u8 channel //channel to set
  1285. * output: none
  1286. * return: return code show if workitem is scheduled (1:pass, 0:fail)
  1287. * notice: Delay may be required for RF configuration
  1288. ******************************************************************************/
  1289. u8 rtl8192_phy_SwChnl(struct net_device *dev, u8 channel)
  1290. {
  1291. struct r8192_priv *priv = ieee80211_priv(dev);
  1292. RT_TRACE(COMP_CH, "%s(), SwChnlInProgress: %d\n", __func__,
  1293. priv->SwChnlInProgress);
  1294. if (!priv->up)
  1295. return false;
  1296. if (priv->SwChnlInProgress)
  1297. return false;
  1298. /* -------------------------------------------- */
  1299. switch (priv->ieee80211->mode) {
  1300. case WIRELESS_MODE_A:
  1301. case WIRELESS_MODE_N_5G:
  1302. if (channel <= 14) {
  1303. RT_TRACE(COMP_ERR, "WIRELESS_MODE_A but channel<=14\n");
  1304. return false;
  1305. }
  1306. break;
  1307. case WIRELESS_MODE_B:
  1308. if (channel > 14) {
  1309. RT_TRACE(COMP_ERR, "WIRELESS_MODE_B but channel>14\n");
  1310. return false;
  1311. }
  1312. break;
  1313. case WIRELESS_MODE_G:
  1314. case WIRELESS_MODE_N_24G:
  1315. if (channel > 14) {
  1316. RT_TRACE(COMP_ERR, "WIRELESS_MODE_G but channel>14\n");
  1317. return false;
  1318. }
  1319. break;
  1320. }
  1321. /* -------------------------------------------- */
  1322. priv->SwChnlInProgress = true;
  1323. if (channel == 0)
  1324. channel = 1;
  1325. priv->chan = channel;
  1326. priv->SwChnlStage = 0;
  1327. priv->SwChnlStep = 0;
  1328. if (priv->up)
  1329. rtl8192_SwChnl_WorkItem(dev);
  1330. priv->SwChnlInProgress = false;
  1331. return true;
  1332. }
  1333. /******************************************************************************
  1334. * function: Callback routine of the work item for set bandwidth mode.
  1335. * input: net_device *dev
  1336. * output: none
  1337. * return: none
  1338. * notice: I doubt whether SetBWModeInProgress flag is necessary as we can
  1339. * test whether current work in the queue or not.//do I?
  1340. *****************************************************************************/
  1341. void rtl8192_SetBWModeWorkItem(struct net_device *dev)
  1342. {
  1343. struct r8192_priv *priv = ieee80211_priv(dev);
  1344. u8 regBwOpMode;
  1345. RT_TRACE(COMP_SWBW, "%s() Switch to %s bandwidth\n", __func__,
  1346. priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20?"20MHz":"40MHz");
  1347. if (priv->rf_chip == RF_PSEUDO_11N) {
  1348. priv->SetBWModeInProgress = false;
  1349. return;
  1350. }
  1351. /* <1> Set MAC register */
  1352. read_nic_byte(dev, BW_OPMODE, &regBwOpMode);
  1353. switch (priv->CurrentChannelBW) {
  1354. case HT_CHANNEL_WIDTH_20:
  1355. regBwOpMode |= BW_OPMODE_20MHZ;
  1356. /* We have not verify whether this register works */
  1357. write_nic_byte(dev, BW_OPMODE, regBwOpMode);
  1358. break;
  1359. case HT_CHANNEL_WIDTH_20_40:
  1360. regBwOpMode &= ~BW_OPMODE_20MHZ;
  1361. /* We have not verify whether this register works */
  1362. write_nic_byte(dev, BW_OPMODE, regBwOpMode);
  1363. break;
  1364. default:
  1365. RT_TRACE(COMP_ERR,
  1366. "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",
  1367. priv->CurrentChannelBW);
  1368. break;
  1369. }
  1370. /* <2> Set PHY related register */
  1371. switch (priv->CurrentChannelBW) {
  1372. case HT_CHANNEL_WIDTH_20:
  1373. rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x0);
  1374. rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x0);
  1375. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1,
  1376. 0x00100000, 1);
  1377. /* Correct the tx power for CCK rate in 20M. */
  1378. priv->cck_present_attentuation =
  1379. priv->cck_present_attentuation_20Mdefault +
  1380. priv->cck_present_attentuation_difference;
  1381. if (priv->cck_present_attentuation > 22)
  1382. priv->cck_present_attentuation = 22;
  1383. if (priv->cck_present_attentuation < 0)
  1384. priv->cck_present_attentuation = 0;
  1385. RT_TRACE(COMP_INIT,
  1386. "20M, pHalData->CCKPresentAttentuation = %d\n",
  1387. priv->cck_present_attentuation);
  1388. if (priv->chan == 14 && !priv->bcck_in_ch14) {
  1389. priv->bcck_in_ch14 = true;
  1390. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  1391. } else if (priv->chan != 14 && priv->bcck_in_ch14) {
  1392. priv->bcck_in_ch14 = false;
  1393. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  1394. } else {
  1395. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  1396. }
  1397. break;
  1398. case HT_CHANNEL_WIDTH_20_40:
  1399. rtl8192_setBBreg(dev, rFPGA0_RFMOD, bRFMOD, 0x1);
  1400. rtl8192_setBBreg(dev, rFPGA1_RFMOD, bRFMOD, 0x1);
  1401. rtl8192_setBBreg(dev, rCCK0_System, bCCKSideBand,
  1402. priv->nCur40MhzPrimeSC>>1);
  1403. rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x00100000, 0);
  1404. rtl8192_setBBreg(dev, rOFDM1_LSTF, 0xC00,
  1405. priv->nCur40MhzPrimeSC);
  1406. priv->cck_present_attentuation =
  1407. priv->cck_present_attentuation_40Mdefault +
  1408. priv->cck_present_attentuation_difference;
  1409. if (priv->cck_present_attentuation > 22)
  1410. priv->cck_present_attentuation = 22;
  1411. if (priv->cck_present_attentuation < 0)
  1412. priv->cck_present_attentuation = 0;
  1413. RT_TRACE(COMP_INIT,
  1414. "40M, pHalData->CCKPresentAttentuation = %d\n",
  1415. priv->cck_present_attentuation);
  1416. if (priv->chan == 14 && !priv->bcck_in_ch14) {
  1417. priv->bcck_in_ch14 = true;
  1418. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  1419. } else if (priv->chan != 14 && priv->bcck_in_ch14) {
  1420. priv->bcck_in_ch14 = false;
  1421. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  1422. } else {
  1423. dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
  1424. }
  1425. break;
  1426. default:
  1427. RT_TRACE(COMP_ERR,
  1428. "SetChannelBandwidth819xUsb(): unknown Bandwidth: %#X\n",
  1429. priv->CurrentChannelBW);
  1430. break;
  1431. }
  1432. /* Skip over setting of J-mode in BB register here.
  1433. Default value is "None J mode". */
  1434. /* <3> Set RF related register */
  1435. switch (priv->rf_chip) {
  1436. case RF_8225:
  1437. #ifdef TO_DO_LIST
  1438. PHY_SetRF8225Bandwidth(Adapter, pHalData->CurrentChannelBW);
  1439. #endif
  1440. break;
  1441. case RF_8256:
  1442. PHY_SetRF8256Bandwidth(dev, priv->CurrentChannelBW);
  1443. break;
  1444. case RF_8258:
  1445. break;
  1446. case RF_PSEUDO_11N:
  1447. break;
  1448. default:
  1449. RT_TRACE(COMP_ERR, "Unknown RFChipID: %d\n", priv->rf_chip);
  1450. break;
  1451. }
  1452. priv->SetBWModeInProgress = false;
  1453. RT_TRACE(COMP_SWBW, "<==SetBWMode819xUsb(), %d\n",
  1454. atomic_read(&priv->ieee80211->atm_swbw));
  1455. }
  1456. /******************************************************************************
  1457. * function: This function schedules bandwidth switch work.
  1458. * input: struct net_deviceq *dev
  1459. * HT_CHANNEL_WIDTH bandwidth //20M or 40M
  1460. * HT_EXTCHNL_OFFSET offset //Upper, Lower, or Don't care
  1461. * output: none
  1462. * return: none
  1463. * notice: I doubt whether SetBWModeInProgress flag is necessary as we can
  1464. * test whether current work in the queue or not.//do I?
  1465. *****************************************************************************/
  1466. void rtl8192_SetBWMode(struct net_device *dev, HT_CHANNEL_WIDTH bandwidth,
  1467. HT_EXTCHNL_OFFSET offset)
  1468. {
  1469. struct r8192_priv *priv = ieee80211_priv(dev);
  1470. if (priv->SetBWModeInProgress)
  1471. return;
  1472. priv->SetBWModeInProgress = true;
  1473. priv->CurrentChannelBW = bandwidth;
  1474. if (offset == HT_EXTCHNL_OFFSET_LOWER)
  1475. priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_UPPER;
  1476. else if (offset == HT_EXTCHNL_OFFSET_UPPER)
  1477. priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_LOWER;
  1478. else
  1479. priv->nCur40MhzPrimeSC = HAL_PRIME_CHNL_OFFSET_DONT_CARE;
  1480. rtl8192_SetBWModeWorkItem(dev);
  1481. }
  1482. void InitialGain819xUsb(struct net_device *dev, u8 Operation)
  1483. {
  1484. struct r8192_priv *priv = ieee80211_priv(dev);
  1485. priv->InitialGainOperateType = Operation;
  1486. if (priv->up)
  1487. queue_delayed_work(priv->priv_wq, &priv->initialgain_operate_wq, 0);
  1488. }
  1489. void InitialGainOperateWorkItemCallBack(struct work_struct *work)
  1490. {
  1491. struct delayed_work *dwork = container_of(work, struct delayed_work,
  1492. work);
  1493. struct r8192_priv *priv = container_of(dwork, struct r8192_priv,
  1494. initialgain_operate_wq);
  1495. struct net_device *dev = priv->ieee80211->dev;
  1496. #define SCAN_RX_INITIAL_GAIN 0x17
  1497. #define POWER_DETECTION_TH 0x08
  1498. u32 bitmask;
  1499. u8 initial_gain;
  1500. u8 Operation;
  1501. Operation = priv->InitialGainOperateType;
  1502. switch (Operation) {
  1503. case IG_Backup:
  1504. RT_TRACE(COMP_SCAN, "IG_Backup, backup the initial gain.\n");
  1505. initial_gain = SCAN_RX_INITIAL_GAIN;
  1506. bitmask = bMaskByte0;
  1507. if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
  1508. /* FW DIG OFF */
  1509. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8);
  1510. priv->initgain_backup.xaagccore1 =
  1511. (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bitmask);
  1512. priv->initgain_backup.xbagccore1 =
  1513. (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bitmask);
  1514. priv->initgain_backup.xcagccore1 =
  1515. (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bitmask);
  1516. priv->initgain_backup.xdagccore1 =
  1517. (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bitmask);
  1518. bitmask = bMaskByte2;
  1519. priv->initgain_backup.cca =
  1520. (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, bitmask);
  1521. RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc50 is %x\n",
  1522. priv->initgain_backup.xaagccore1);
  1523. RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc58 is %x\n",
  1524. priv->initgain_backup.xbagccore1);
  1525. RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc60 is %x\n",
  1526. priv->initgain_backup.xcagccore1);
  1527. RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xc68 is %x\n",
  1528. priv->initgain_backup.xdagccore1);
  1529. RT_TRACE(COMP_SCAN, "Scan InitialGainBackup 0xa0a is %x\n",
  1530. priv->initgain_backup.cca);
  1531. RT_TRACE(COMP_SCAN, "Write scan initial gain = 0x%x\n",
  1532. initial_gain);
  1533. write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
  1534. write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
  1535. write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
  1536. write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
  1537. RT_TRACE(COMP_SCAN, "Write scan 0xa0a = 0x%x\n",
  1538. POWER_DETECTION_TH);
  1539. write_nic_byte(dev, 0xa0a, POWER_DETECTION_TH);
  1540. break;
  1541. case IG_Restore:
  1542. RT_TRACE(COMP_SCAN, "IG_Restore, restore the initial gain.\n");
  1543. bitmask = 0x7f; /* Bit0 ~ Bit6 */
  1544. if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
  1545. /* FW DIG OFF */
  1546. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8);
  1547. rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bitmask,
  1548. (u32)priv->initgain_backup.xaagccore1);
  1549. rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bitmask,
  1550. (u32)priv->initgain_backup.xbagccore1);
  1551. rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, bitmask,
  1552. (u32)priv->initgain_backup.xcagccore1);
  1553. rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, bitmask,
  1554. (u32)priv->initgain_backup.xdagccore1);
  1555. bitmask = bMaskByte2;
  1556. rtl8192_setBBreg(dev, rCCK0_CCA, bitmask,
  1557. (u32)priv->initgain_backup.cca);
  1558. RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc50 is %x\n",
  1559. priv->initgain_backup.xaagccore1);
  1560. RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc58 is %x\n",
  1561. priv->initgain_backup.xbagccore1);
  1562. RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc60 is %x\n",
  1563. priv->initgain_backup.xcagccore1);
  1564. RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xc68 is %x\n",
  1565. priv->initgain_backup.xdagccore1);
  1566. RT_TRACE(COMP_SCAN, "Scan BBInitialGainRestore 0xa0a is %x\n",
  1567. priv->initgain_backup.cca);
  1568. rtl8192_phy_setTxPower(dev, priv->ieee80211->current_network.channel);
  1569. if (dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
  1570. /* FW DIG ON */
  1571. rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1);
  1572. break;
  1573. default:
  1574. RT_TRACE(COMP_SCAN, "Unknown IG Operation.\n");
  1575. break;
  1576. }
  1577. }