baseband.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
  4. * All rights reserved.
  5. *
  6. * File: baseband.c
  7. *
  8. * Purpose: Implement functions to access baseband
  9. *
  10. * Author: Jerry Chen
  11. *
  12. * Date: Jun. 5, 2002
  13. *
  14. * Functions:
  15. * vnt_get_frame_time - Calculate data frame transmitting time
  16. * vnt_get_phy_field - Calculate PhyLength, PhyService and Phy
  17. * Signal parameter for baseband Tx
  18. * vnt_vt3184_init - VIA VT3184 baseband chip init code
  19. *
  20. * Revision History:
  21. *
  22. *
  23. */
  24. #include "mac.h"
  25. #include "baseband.h"
  26. #include "rf.h"
  27. #include "usbpipe.h"
  28. static u8 vnt_vt3184_agc[] = {
  29. 0x00, 0x00, 0x02, 0x02, 0x04, 0x04, 0x06, 0x06,
  30. 0x08, 0x08, 0x0a, 0x0a, 0x0c, 0x0c, 0x0e, 0x0e, /* 0x0f */
  31. 0x10, 0x10, 0x12, 0x12, 0x14, 0x14, 0x16, 0x16,
  32. 0x18, 0x18, 0x1a, 0x1a, 0x1c, 0x1c, 0x1e, 0x1e, /* 0x1f */
  33. 0x20, 0x20, 0x22, 0x22, 0x24, 0x24, 0x26, 0x26,
  34. 0x28, 0x28, 0x2a, 0x2a, 0x2c, 0x2c, 0x2e, 0x2e, /* 0x2f */
  35. 0x30, 0x30, 0x32, 0x32, 0x34, 0x34, 0x36, 0x36,
  36. 0x38, 0x38, 0x3a, 0x3a, 0x3c, 0x3c, 0x3e, 0x3e /* 0x3f */
  37. };
  38. static u8 vnt_vt3184_al2230[] = {
  39. 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
  40. 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42. 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
  45. 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
  46. 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
  47. 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
  48. 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
  49. 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
  51. 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
  52. 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
  53. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
  55. 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
  57. 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
  59. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  60. 0x18, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00, 0x18, /* 0xaf */
  61. 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
  62. 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
  63. 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x0e, 0x0a,
  64. 0x0e, 0x00, 0x82, 0xa7, 0x3c, 0x10, 0x30, 0x05, /* 0xcf */
  65. 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
  66. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
  67. 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x12,
  68. 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x05, /* 0xef */
  69. 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
  71. };
  72. /* {{RobertYu:20060515, new BB setting for VT3226D0 */
  73. static u8 vnt_vt3184_vt3226d0[] = {
  74. 0x31, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00,
  75. 0x70, 0x45, 0x2a, 0x76, 0x00, 0x00, 0x80, 0x00, /* 0x0f */
  76. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  77. 0x00, 0x00, 0x00, 0x8e, 0x0a, 0x00, 0x00, 0x00, /* 0x1f */
  78. 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x00,
  79. 0x00, 0x00, 0x00, 0x00, 0x00, 0x4a, 0x00, 0x0c, /* 0x2f */
  80. 0x26, 0x5b, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa,
  81. 0xff, 0xff, 0x79, 0x00, 0x00, 0x0b, 0x48, 0x04, /* 0x3f */
  82. 0x00, 0x08, 0x00, 0x08, 0x08, 0x14, 0x05, 0x09,
  83. 0x00, 0x00, 0x00, 0x00, 0x09, 0x73, 0x00, 0xc5, /* 0x4f */
  84. 0x00, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85. 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x5f */
  86. 0xe4, 0x80, 0x00, 0x00, 0x00, 0x00, 0x98, 0x0a,
  87. 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, /* 0x6f */
  88. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  89. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x7f */
  90. 0x8c, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
  91. 0x08, 0x00, 0x1f, 0xb7, 0x88, 0x47, 0xaa, 0x00, /* 0x8f */
  92. 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xeb,
  93. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, /* 0x9f */
  94. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  95. 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, /* 0xaf */
  96. 0x38, 0x30, 0x00, 0x00, 0xff, 0x0f, 0xe4, 0xe2,
  97. 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x00, 0x00, /* 0xbf */
  98. 0x18, 0x20, 0x07, 0x18, 0xff, 0xff, 0x10, 0x0a,
  99. 0x0e, 0x00, 0x84, 0xa7, 0x3c, 0x10, 0x24, 0x05, /* 0xcf */
  100. 0x40, 0x12, 0x00, 0x00, 0x10, 0x28, 0x80, 0x2a,
  101. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xdf */
  102. 0x00, 0xf3, 0x00, 0x00, 0x00, 0x10, 0x00, 0x10,
  103. 0x00, 0xf4, 0x00, 0xff, 0x79, 0x20, 0x30, 0x08, /* 0xef */
  104. 0x00, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  105. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 0xff */
  106. };
  107. static const u16 vnt_frame_time[MAX_RATE] = {
  108. 10, 20, 55, 110, 24, 36, 48, 72, 96, 144, 192, 216
  109. };
  110. /*
  111. * Description: Calculate data frame transmitting time
  112. *
  113. * Parameters:
  114. * In:
  115. * preamble_type - Preamble Type
  116. * pkt_type - PK_TYPE_11A, PK_TYPE_11B, PK_TYPE_11GB, PK_TYPE_11GA
  117. * frame_length - Baseband Type
  118. * tx_rate - Tx Rate
  119. * Out:
  120. *
  121. * Return Value: FrameTime
  122. *
  123. */
  124. unsigned int vnt_get_frame_time(u8 preamble_type, u8 pkt_type,
  125. unsigned int frame_length, u16 tx_rate)
  126. {
  127. unsigned int frame_time;
  128. unsigned int preamble;
  129. unsigned int tmp;
  130. unsigned int rate = 0;
  131. if (tx_rate > RATE_54M)
  132. return 0;
  133. rate = (unsigned int)vnt_frame_time[tx_rate];
  134. if (tx_rate <= 3) {
  135. if (preamble_type == 1)
  136. preamble = 96;
  137. else
  138. preamble = 192;
  139. frame_time = (frame_length * 80) / rate;
  140. tmp = (frame_time * rate) / 80;
  141. if (frame_length != tmp)
  142. frame_time++;
  143. return preamble + frame_time;
  144. }
  145. frame_time = (frame_length * 8 + 22) / rate;
  146. tmp = ((frame_time * rate) - 22) / 8;
  147. if (frame_length != tmp)
  148. frame_time++;
  149. frame_time = frame_time * 4;
  150. if (pkt_type != PK_TYPE_11A)
  151. frame_time += 6;
  152. return 20 + frame_time;
  153. }
  154. /*
  155. * Description: Calculate Length, Service, and Signal fields of Phy for Tx
  156. *
  157. * Parameters:
  158. * In:
  159. * priv - Device Structure
  160. * frame_length - Tx Frame Length
  161. * tx_rate - Tx Rate
  162. * Out:
  163. * struct vnt_phy_field *phy
  164. * - pointer to Phy Length field
  165. * - pointer to Phy Service field
  166. * - pointer to Phy Signal field
  167. *
  168. * Return Value: none
  169. *
  170. */
  171. void vnt_get_phy_field(struct vnt_private *priv, u32 frame_length,
  172. u16 tx_rate, u8 pkt_type, struct vnt_phy_field *phy)
  173. {
  174. u32 bit_count;
  175. u32 count = 0;
  176. u32 tmp;
  177. int ext_bit;
  178. u8 preamble_type = priv->preamble_type;
  179. bit_count = frame_length * 8;
  180. ext_bit = false;
  181. switch (tx_rate) {
  182. case RATE_1M:
  183. count = bit_count;
  184. phy->signal = 0x00;
  185. break;
  186. case RATE_2M:
  187. count = bit_count / 2;
  188. if (preamble_type == 1)
  189. phy->signal = 0x09;
  190. else
  191. phy->signal = 0x01;
  192. break;
  193. case RATE_5M:
  194. count = (bit_count * 10) / 55;
  195. tmp = (count * 55) / 10;
  196. if (tmp != bit_count)
  197. count++;
  198. if (preamble_type == 1)
  199. phy->signal = 0x0a;
  200. else
  201. phy->signal = 0x02;
  202. break;
  203. case RATE_11M:
  204. count = bit_count / 11;
  205. tmp = count * 11;
  206. if (tmp != bit_count) {
  207. count++;
  208. if ((bit_count - tmp) <= 3)
  209. ext_bit = true;
  210. }
  211. if (preamble_type == 1)
  212. phy->signal = 0x0b;
  213. else
  214. phy->signal = 0x03;
  215. break;
  216. case RATE_6M:
  217. if (pkt_type == PK_TYPE_11A)
  218. phy->signal = 0x9b;
  219. else
  220. phy->signal = 0x8b;
  221. break;
  222. case RATE_9M:
  223. if (pkt_type == PK_TYPE_11A)
  224. phy->signal = 0x9f;
  225. else
  226. phy->signal = 0x8f;
  227. break;
  228. case RATE_12M:
  229. if (pkt_type == PK_TYPE_11A)
  230. phy->signal = 0x9a;
  231. else
  232. phy->signal = 0x8a;
  233. break;
  234. case RATE_18M:
  235. if (pkt_type == PK_TYPE_11A)
  236. phy->signal = 0x9e;
  237. else
  238. phy->signal = 0x8e;
  239. break;
  240. case RATE_24M:
  241. if (pkt_type == PK_TYPE_11A)
  242. phy->signal = 0x99;
  243. else
  244. phy->signal = 0x89;
  245. break;
  246. case RATE_36M:
  247. if (pkt_type == PK_TYPE_11A)
  248. phy->signal = 0x9d;
  249. else
  250. phy->signal = 0x8d;
  251. break;
  252. case RATE_48M:
  253. if (pkt_type == PK_TYPE_11A)
  254. phy->signal = 0x98;
  255. else
  256. phy->signal = 0x88;
  257. break;
  258. case RATE_54M:
  259. if (pkt_type == PK_TYPE_11A)
  260. phy->signal = 0x9c;
  261. else
  262. phy->signal = 0x8c;
  263. break;
  264. default:
  265. if (pkt_type == PK_TYPE_11A)
  266. phy->signal = 0x9c;
  267. else
  268. phy->signal = 0x8c;
  269. break;
  270. }
  271. if (pkt_type == PK_TYPE_11B) {
  272. phy->service = 0x00;
  273. if (ext_bit)
  274. phy->service |= 0x80;
  275. phy->len = cpu_to_le16((u16)count);
  276. } else {
  277. phy->service = 0x00;
  278. phy->len = cpu_to_le16((u16)frame_length);
  279. }
  280. }
  281. /*
  282. * Description: Set Antenna mode
  283. *
  284. * Parameters:
  285. * In:
  286. * priv - Device Structure
  287. * antenna_mode - Antenna Mode
  288. * Out:
  289. * none
  290. *
  291. * Return Value: none
  292. *
  293. */
  294. void vnt_set_antenna_mode(struct vnt_private *priv, u8 antenna_mode)
  295. {
  296. switch (antenna_mode) {
  297. case ANT_TXA:
  298. case ANT_TXB:
  299. break;
  300. case ANT_RXA:
  301. priv->bb_rx_conf &= 0xFC;
  302. break;
  303. case ANT_RXB:
  304. priv->bb_rx_conf &= 0xFE;
  305. priv->bb_rx_conf |= 0x02;
  306. break;
  307. }
  308. vnt_control_out(priv, MESSAGE_TYPE_SET_ANTMD,
  309. (u16)antenna_mode, 0, 0, NULL);
  310. }
  311. /*
  312. * Description: Set Antenna mode
  313. *
  314. * Parameters:
  315. * In:
  316. * pDevice - Device Structure
  317. * byAntennaMode - Antenna Mode
  318. * Out:
  319. * none
  320. *
  321. * Return Value: none
  322. *
  323. */
  324. int vnt_vt3184_init(struct vnt_private *priv)
  325. {
  326. int status;
  327. u16 length;
  328. u8 *addr;
  329. u8 *agc;
  330. u16 length_agc;
  331. u8 array[256];
  332. u8 data;
  333. status = vnt_control_in(priv, MESSAGE_TYPE_READ, 0,
  334. MESSAGE_REQUEST_EEPROM, EEP_MAX_CONTEXT_SIZE,
  335. priv->eeprom);
  336. if (status != STATUS_SUCCESS)
  337. return false;
  338. priv->rf_type = priv->eeprom[EEP_OFS_RFTYPE];
  339. dev_dbg(&priv->usb->dev, "RF Type %d\n", priv->rf_type);
  340. if ((priv->rf_type == RF_AL2230) ||
  341. (priv->rf_type == RF_AL2230S)) {
  342. priv->bb_rx_conf = vnt_vt3184_al2230[10];
  343. length = sizeof(vnt_vt3184_al2230);
  344. addr = vnt_vt3184_al2230;
  345. agc = vnt_vt3184_agc;
  346. length_agc = sizeof(vnt_vt3184_agc);
  347. priv->bb_vga[0] = 0x1C;
  348. priv->bb_vga[1] = 0x10;
  349. priv->bb_vga[2] = 0x0;
  350. priv->bb_vga[3] = 0x0;
  351. } else if (priv->rf_type == RF_AIROHA7230) {
  352. priv->bb_rx_conf = vnt_vt3184_al2230[10];
  353. length = sizeof(vnt_vt3184_al2230);
  354. addr = vnt_vt3184_al2230;
  355. agc = vnt_vt3184_agc;
  356. length_agc = sizeof(vnt_vt3184_agc);
  357. addr[0xd7] = 0x06;
  358. priv->bb_vga[0] = 0x1c;
  359. priv->bb_vga[1] = 0x10;
  360. priv->bb_vga[2] = 0x0;
  361. priv->bb_vga[3] = 0x0;
  362. } else if ((priv->rf_type == RF_VT3226) ||
  363. (priv->rf_type == RF_VT3226D0)) {
  364. priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
  365. length = sizeof(vnt_vt3184_vt3226d0);
  366. addr = vnt_vt3184_vt3226d0;
  367. agc = vnt_vt3184_agc;
  368. length_agc = sizeof(vnt_vt3184_agc);
  369. priv->bb_vga[0] = 0x20;
  370. priv->bb_vga[1] = 0x10;
  371. priv->bb_vga[2] = 0x0;
  372. priv->bb_vga[3] = 0x0;
  373. /* Fix VT3226 DFC system timing issue */
  374. vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
  375. SOFTPWRCTL_RFLEOPT);
  376. } else if (priv->rf_type == RF_VT3342A0) {
  377. priv->bb_rx_conf = vnt_vt3184_vt3226d0[10];
  378. length = sizeof(vnt_vt3184_vt3226d0);
  379. addr = vnt_vt3184_vt3226d0;
  380. agc = vnt_vt3184_agc;
  381. length_agc = sizeof(vnt_vt3184_agc);
  382. priv->bb_vga[0] = 0x20;
  383. priv->bb_vga[1] = 0x10;
  384. priv->bb_vga[2] = 0x0;
  385. priv->bb_vga[3] = 0x0;
  386. /* Fix VT3226 DFC system timing issue */
  387. vnt_mac_reg_bits_on(priv, MAC_REG_SOFTPWRCTL2,
  388. SOFTPWRCTL_RFLEOPT);
  389. } else {
  390. return true;
  391. }
  392. memcpy(array, addr, length);
  393. vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
  394. MESSAGE_REQUEST_BBREG, length, array);
  395. memcpy(array, agc, length_agc);
  396. vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
  397. MESSAGE_REQUEST_BBAGC, length_agc, array);
  398. if ((priv->rf_type == RF_VT3226) ||
  399. (priv->rf_type == RF_VT3342A0)) {
  400. vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
  401. MAC_REG_ITRTMSET, 0x23);
  402. vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
  403. } else if (priv->rf_type == RF_VT3226D0) {
  404. vnt_control_out_u8(priv, MESSAGE_REQUEST_MACREG,
  405. MAC_REG_ITRTMSET, 0x11);
  406. vnt_mac_reg_bits_on(priv, MAC_REG_PAPEDELAY, 0x01);
  407. }
  408. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x04, 0x7f);
  409. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);
  410. vnt_rf_table_download(priv);
  411. /* Fix for TX USB resets from vendors driver */
  412. vnt_control_in(priv, MESSAGE_TYPE_READ, USB_REG4,
  413. MESSAGE_REQUEST_MEM, sizeof(data), &data);
  414. data |= 0x2;
  415. vnt_control_out(priv, MESSAGE_TYPE_WRITE, USB_REG4,
  416. MESSAGE_REQUEST_MEM, sizeof(data), &data);
  417. return true;
  418. }
  419. /*
  420. * Description: Set ShortSlotTime mode
  421. *
  422. * Parameters:
  423. * In:
  424. * priv - Device Structure
  425. * Out:
  426. * none
  427. *
  428. * Return Value: none
  429. *
  430. */
  431. void vnt_set_short_slot_time(struct vnt_private *priv)
  432. {
  433. u8 bb_vga = 0;
  434. if (priv->short_slot_time)
  435. priv->bb_rx_conf &= 0xdf;
  436. else
  437. priv->bb_rx_conf |= 0x20;
  438. vnt_control_in_u8(priv, MESSAGE_REQUEST_BBREG, 0xe7, &bb_vga);
  439. if (bb_vga == priv->bb_vga[0])
  440. priv->bb_rx_conf |= 0x20;
  441. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
  442. }
  443. void vnt_set_vga_gain_offset(struct vnt_private *priv, u8 data)
  444. {
  445. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xE7, data);
  446. /* patch for 3253B0 Baseband with Cardbus module */
  447. if (priv->short_slot_time)
  448. priv->bb_rx_conf &= 0xdf; /* 1101 1111 */
  449. else
  450. priv->bb_rx_conf |= 0x20; /* 0010 0000 */
  451. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0a, priv->bb_rx_conf);
  452. }
  453. /*
  454. * Description: vnt_set_deep_sleep
  455. *
  456. * Parameters:
  457. * In:
  458. * priv - Device Structure
  459. * Out:
  460. * none
  461. *
  462. * Return Value: none
  463. *
  464. */
  465. void vnt_set_deep_sleep(struct vnt_private *priv)
  466. {
  467. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x17);/* CR12 */
  468. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0xB9);/* CR13 */
  469. }
  470. void vnt_exit_deep_sleep(struct vnt_private *priv)
  471. {
  472. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0c, 0x00);/* CR12 */
  473. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0x0d, 0x01);/* CR13 */
  474. }
  475. void vnt_update_pre_ed_threshold(struct vnt_private *priv, int scanning)
  476. {
  477. u8 cr_201 = 0x0, cr_206 = 0x0;
  478. u8 ed_inx = priv->bb_pre_ed_index;
  479. switch (priv->rf_type) {
  480. case RF_AL2230:
  481. case RF_AL2230S:
  482. case RF_AIROHA7230:
  483. if (scanning) { /* Max sensitivity */
  484. ed_inx = 0;
  485. cr_206 = 0x30;
  486. break;
  487. }
  488. if (priv->bb_pre_ed_rssi <= 45) {
  489. ed_inx = 20;
  490. cr_201 = 0xff;
  491. } else if (priv->bb_pre_ed_rssi <= 46) {
  492. ed_inx = 19;
  493. cr_201 = 0x1a;
  494. } else if (priv->bb_pre_ed_rssi <= 47) {
  495. ed_inx = 18;
  496. cr_201 = 0x15;
  497. } else if (priv->bb_pre_ed_rssi <= 49) {
  498. ed_inx = 17;
  499. cr_201 = 0xe;
  500. } else if (priv->bb_pre_ed_rssi <= 51) {
  501. ed_inx = 16;
  502. cr_201 = 0x9;
  503. } else if (priv->bb_pre_ed_rssi <= 53) {
  504. ed_inx = 15;
  505. cr_201 = 0x6;
  506. } else if (priv->bb_pre_ed_rssi <= 55) {
  507. ed_inx = 14;
  508. cr_201 = 0x3;
  509. } else if (priv->bb_pre_ed_rssi <= 56) {
  510. ed_inx = 13;
  511. cr_201 = 0x2;
  512. cr_206 = 0xa0;
  513. } else if (priv->bb_pre_ed_rssi <= 57) {
  514. ed_inx = 12;
  515. cr_201 = 0x2;
  516. cr_206 = 0x20;
  517. } else if (priv->bb_pre_ed_rssi <= 58) {
  518. ed_inx = 11;
  519. cr_201 = 0x1;
  520. cr_206 = 0xa0;
  521. } else if (priv->bb_pre_ed_rssi <= 59) {
  522. ed_inx = 10;
  523. cr_201 = 0x1;
  524. cr_206 = 0x54;
  525. } else if (priv->bb_pre_ed_rssi <= 60) {
  526. ed_inx = 9;
  527. cr_201 = 0x1;
  528. cr_206 = 0x18;
  529. } else if (priv->bb_pre_ed_rssi <= 61) {
  530. ed_inx = 8;
  531. cr_206 = 0xe3;
  532. } else if (priv->bb_pre_ed_rssi <= 62) {
  533. ed_inx = 7;
  534. cr_206 = 0xb9;
  535. } else if (priv->bb_pre_ed_rssi <= 63) {
  536. ed_inx = 6;
  537. cr_206 = 0x93;
  538. } else if (priv->bb_pre_ed_rssi <= 64) {
  539. ed_inx = 5;
  540. cr_206 = 0x79;
  541. } else if (priv->bb_pre_ed_rssi <= 65) {
  542. ed_inx = 4;
  543. cr_206 = 0x62;
  544. } else if (priv->bb_pre_ed_rssi <= 66) {
  545. ed_inx = 3;
  546. cr_206 = 0x51;
  547. } else if (priv->bb_pre_ed_rssi <= 67) {
  548. ed_inx = 2;
  549. cr_206 = 0x43;
  550. } else if (priv->bb_pre_ed_rssi <= 68) {
  551. ed_inx = 1;
  552. cr_206 = 0x36;
  553. } else {
  554. ed_inx = 0;
  555. cr_206 = 0x30;
  556. }
  557. break;
  558. case RF_VT3226:
  559. case RF_VT3226D0:
  560. if (scanning) { /* Max sensitivity */
  561. ed_inx = 0;
  562. cr_206 = 0x24;
  563. break;
  564. }
  565. if (priv->bb_pre_ed_rssi <= 41) {
  566. ed_inx = 22;
  567. cr_201 = 0xff;
  568. } else if (priv->bb_pre_ed_rssi <= 42) {
  569. ed_inx = 21;
  570. cr_201 = 0x36;
  571. } else if (priv->bb_pre_ed_rssi <= 43) {
  572. ed_inx = 20;
  573. cr_201 = 0x26;
  574. } else if (priv->bb_pre_ed_rssi <= 45) {
  575. ed_inx = 19;
  576. cr_201 = 0x18;
  577. } else if (priv->bb_pre_ed_rssi <= 47) {
  578. ed_inx = 18;
  579. cr_201 = 0x11;
  580. } else if (priv->bb_pre_ed_rssi <= 49) {
  581. ed_inx = 17;
  582. cr_201 = 0xa;
  583. } else if (priv->bb_pre_ed_rssi <= 51) {
  584. ed_inx = 16;
  585. cr_201 = 0x7;
  586. } else if (priv->bb_pre_ed_rssi <= 53) {
  587. ed_inx = 15;
  588. cr_201 = 0x4;
  589. } else if (priv->bb_pre_ed_rssi <= 55) {
  590. ed_inx = 14;
  591. cr_201 = 0x2;
  592. cr_206 = 0xc0;
  593. } else if (priv->bb_pre_ed_rssi <= 56) {
  594. ed_inx = 13;
  595. cr_201 = 0x2;
  596. cr_206 = 0x30;
  597. } else if (priv->bb_pre_ed_rssi <= 57) {
  598. ed_inx = 12;
  599. cr_201 = 0x1;
  600. cr_206 = 0xb0;
  601. } else if (priv->bb_pre_ed_rssi <= 58) {
  602. ed_inx = 11;
  603. cr_201 = 0x1;
  604. cr_206 = 0x70;
  605. } else if (priv->bb_pre_ed_rssi <= 59) {
  606. ed_inx = 10;
  607. cr_201 = 0x1;
  608. cr_206 = 0x30;
  609. } else if (priv->bb_pre_ed_rssi <= 60) {
  610. ed_inx = 9;
  611. cr_206 = 0xea;
  612. } else if (priv->bb_pre_ed_rssi <= 61) {
  613. ed_inx = 8;
  614. cr_206 = 0xc0;
  615. } else if (priv->bb_pre_ed_rssi <= 62) {
  616. ed_inx = 7;
  617. cr_206 = 0x9c;
  618. } else if (priv->bb_pre_ed_rssi <= 63) {
  619. ed_inx = 6;
  620. cr_206 = 0x80;
  621. } else if (priv->bb_pre_ed_rssi <= 64) {
  622. ed_inx = 5;
  623. cr_206 = 0x68;
  624. } else if (priv->bb_pre_ed_rssi <= 65) {
  625. ed_inx = 4;
  626. cr_206 = 0x52;
  627. } else if (priv->bb_pre_ed_rssi <= 66) {
  628. ed_inx = 3;
  629. cr_206 = 0x43;
  630. } else if (priv->bb_pre_ed_rssi <= 67) {
  631. ed_inx = 2;
  632. cr_206 = 0x36;
  633. } else if (priv->bb_pre_ed_rssi <= 68) {
  634. ed_inx = 1;
  635. cr_206 = 0x2d;
  636. } else {
  637. ed_inx = 0;
  638. cr_206 = 0x24;
  639. }
  640. break;
  641. case RF_VT3342A0:
  642. if (scanning) { /* need Max sensitivity */
  643. ed_inx = 0;
  644. cr_206 = 0x38;
  645. break;
  646. }
  647. if (priv->bb_pre_ed_rssi <= 41) {
  648. ed_inx = 20;
  649. cr_201 = 0xff;
  650. } else if (priv->bb_pre_ed_rssi <= 42) {
  651. ed_inx = 19;
  652. cr_201 = 0x36;
  653. } else if (priv->bb_pre_ed_rssi <= 43) {
  654. ed_inx = 18;
  655. cr_201 = 0x26;
  656. } else if (priv->bb_pre_ed_rssi <= 45) {
  657. ed_inx = 17;
  658. cr_201 = 0x18;
  659. } else if (priv->bb_pre_ed_rssi <= 47) {
  660. ed_inx = 16;
  661. cr_201 = 0x11;
  662. } else if (priv->bb_pre_ed_rssi <= 49) {
  663. ed_inx = 15;
  664. cr_201 = 0xa;
  665. } else if (priv->bb_pre_ed_rssi <= 51) {
  666. ed_inx = 14;
  667. cr_201 = 0x7;
  668. } else if (priv->bb_pre_ed_rssi <= 53) {
  669. ed_inx = 13;
  670. cr_201 = 0x4;
  671. } else if (priv->bb_pre_ed_rssi <= 55) {
  672. ed_inx = 12;
  673. cr_201 = 0x2;
  674. cr_206 = 0xc0;
  675. } else if (priv->bb_pre_ed_rssi <= 56) {
  676. ed_inx = 11;
  677. cr_201 = 0x2;
  678. cr_206 = 0x30;
  679. } else if (priv->bb_pre_ed_rssi <= 57) {
  680. ed_inx = 10;
  681. cr_201 = 0x1;
  682. cr_206 = 0xb0;
  683. } else if (priv->bb_pre_ed_rssi <= 58) {
  684. ed_inx = 9;
  685. cr_201 = 0x1;
  686. cr_206 = 0x70;
  687. } else if (priv->bb_pre_ed_rssi <= 59) {
  688. ed_inx = 8;
  689. cr_201 = 0x1;
  690. cr_206 = 0x30;
  691. } else if (priv->bb_pre_ed_rssi <= 60) {
  692. ed_inx = 7;
  693. cr_206 = 0xea;
  694. } else if (priv->bb_pre_ed_rssi <= 61) {
  695. ed_inx = 6;
  696. cr_206 = 0xc0;
  697. } else if (priv->bb_pre_ed_rssi <= 62) {
  698. ed_inx = 5;
  699. cr_206 = 0x9c;
  700. } else if (priv->bb_pre_ed_rssi <= 63) {
  701. ed_inx = 4;
  702. cr_206 = 0x80;
  703. } else if (priv->bb_pre_ed_rssi <= 64) {
  704. ed_inx = 3;
  705. cr_206 = 0x68;
  706. } else if (priv->bb_pre_ed_rssi <= 65) {
  707. ed_inx = 2;
  708. cr_206 = 0x52;
  709. } else if (priv->bb_pre_ed_rssi <= 66) {
  710. ed_inx = 1;
  711. cr_206 = 0x43;
  712. } else {
  713. ed_inx = 0;
  714. cr_206 = 0x38;
  715. }
  716. break;
  717. }
  718. if (ed_inx == priv->bb_pre_ed_index && !scanning)
  719. return;
  720. priv->bb_pre_ed_index = ed_inx;
  721. dev_dbg(&priv->usb->dev, "%s bb_pre_ed_rssi %d\n",
  722. __func__, priv->bb_pre_ed_rssi);
  723. if (!cr_201 && !cr_206)
  724. return;
  725. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xc9, cr_201);
  726. vnt_control_out_u8(priv, MESSAGE_REQUEST_BBREG, 0xce, cr_206);
  727. }