baseband.c 20 KB

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