rf.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  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: rf.c
  17. *
  18. * Purpose: rf function code
  19. *
  20. * Author: Jerry Chen
  21. *
  22. * Date: Feb. 19, 2004
  23. *
  24. * Functions:
  25. * vnt_rf_write_embedded - Embedded write RF register via MAC
  26. *
  27. * Revision History:
  28. * RF_VT3226: RobertYu:20051111, VT3226C0 and before
  29. * RF_VT3226D0: RobertYu:20051228
  30. * RF_VT3342A0: RobertYu:20060609
  31. *
  32. */
  33. #include "mac.h"
  34. #include "rf.h"
  35. #include "baseband.h"
  36. #include "usbpipe.h"
  37. #define CB_AL2230_INIT_SEQ 15
  38. #define AL2230_PWR_IDX_LEN 64
  39. #define CB_AL7230_INIT_SEQ 16
  40. #define AL7230_PWR_IDX_LEN 64
  41. #define CB_VT3226_INIT_SEQ 11
  42. #define VT3226_PWR_IDX_LEN 64
  43. #define CB_VT3342_INIT_SEQ 13
  44. #define VT3342_PWR_IDX_LEN 64
  45. static u8 al2230_init_table[CB_AL2230_INIT_SEQ][3] = {
  46. {0x03, 0xf7, 0x90},
  47. {0x03, 0x33, 0x31},
  48. {0x01, 0xb8, 0x02},
  49. {0x00, 0xff, 0xf3},
  50. {0x00, 0x05, 0xa4},
  51. {0x0f, 0x4d, 0xc5},
  52. {0x08, 0x05, 0xb6},
  53. {0x01, 0x47, 0xc7},
  54. {0x00, 0x06, 0x88},
  55. {0x04, 0x03, 0xb9},
  56. {0x00, 0xdb, 0xba},
  57. {0x00, 0x09, 0x9b},
  58. {0x0b, 0xdf, 0xfc},
  59. {0x00, 0x00, 0x0d},
  60. {0x00, 0x58, 0x0f}
  61. };
  62. static u8 al2230_channel_table0[CB_MAX_CHANNEL_24G][3] = {
  63. {0x03, 0xf7, 0x90},
  64. {0x03, 0xf7, 0x90},
  65. {0x03, 0xe7, 0x90},
  66. {0x03, 0xe7, 0x90},
  67. {0x03, 0xf7, 0xa0},
  68. {0x03, 0xf7, 0xa0},
  69. {0x03, 0xe7, 0xa0},
  70. {0x03, 0xe7, 0xa0},
  71. {0x03, 0xf7, 0xb0},
  72. {0x03, 0xf7, 0xb0},
  73. {0x03, 0xe7, 0xb0},
  74. {0x03, 0xe7, 0xb0},
  75. {0x03, 0xf7, 0xc0},
  76. {0x03, 0xe7, 0xc0}
  77. };
  78. static u8 al2230_channel_table1[CB_MAX_CHANNEL_24G][3] = {
  79. {0x03, 0x33, 0x31},
  80. {0x0b, 0x33, 0x31},
  81. {0x03, 0x33, 0x31},
  82. {0x0b, 0x33, 0x31},
  83. {0x03, 0x33, 0x31},
  84. {0x0b, 0x33, 0x31},
  85. {0x03, 0x33, 0x31},
  86. {0x0b, 0x33, 0x31},
  87. {0x03, 0x33, 0x31},
  88. {0x0b, 0x33, 0x31},
  89. {0x03, 0x33, 0x31},
  90. {0x0b, 0x33, 0x31},
  91. {0x03, 0x33, 0x31},
  92. {0x06, 0x66, 0x61}
  93. };
  94. static u8 al7230_init_table[CB_AL7230_INIT_SEQ][3] = {
  95. {0x20, 0x37, 0x90},
  96. {0x13, 0x33, 0x31},
  97. {0x84, 0x1f, 0xf2},
  98. {0x3f, 0xdf, 0xa3},
  99. {0x7f, 0xd7, 0x84},
  100. {0x80, 0x2b, 0x55},
  101. {0x56, 0xaf, 0x36},
  102. {0xce, 0x02, 0x07},
  103. {0x6e, 0xbc, 0x98},
  104. {0x22, 0x1b, 0xb9},
  105. {0xe0, 0x00, 0x0a},
  106. {0x08, 0x03, 0x1b},
  107. {0x00, 0x0a, 0x3c},
  108. {0xff, 0xff, 0xfd},
  109. {0x00, 0x00, 0x0e},
  110. {0x1a, 0xba, 0x8f}
  111. };
  112. static u8 al7230_init_table_amode[CB_AL7230_INIT_SEQ][3] = {
  113. {0x2f, 0xf5, 0x20},
  114. {0x00, 0x00, 0x01},
  115. {0x45, 0x1f, 0xe2},
  116. {0x5f, 0xdf, 0xa3},
  117. {0x6f, 0xd7, 0x84},
  118. {0x85, 0x3f, 0x55},
  119. {0x56, 0xaf, 0x36},
  120. {0xce, 0x02, 0x07},
  121. {0x6e, 0xbc, 0x98},
  122. {0x22, 0x1b, 0xb9},
  123. {0xe0, 0x60, 0x0a},
  124. {0x08, 0x03, 0x1b},
  125. {0x00, 0x14, 0x7c},
  126. {0xff, 0xff, 0xfd},
  127. {0x00, 0x00, 0x0e},
  128. {0x12, 0xba, 0xcf}
  129. };
  130. static u8 al7230_channel_table0[CB_MAX_CHANNEL][3] = {
  131. {0x20, 0x37, 0x90},
  132. {0x20, 0x37, 0x90},
  133. {0x20, 0x37, 0x90},
  134. {0x20, 0x37, 0x90},
  135. {0x20, 0x37, 0xa0},
  136. {0x20, 0x37, 0xa0},
  137. {0x20, 0x37, 0xa0},
  138. {0x20, 0x37, 0xa0},
  139. {0x20, 0x37, 0xb0},
  140. {0x20, 0x37, 0xb0},
  141. {0x20, 0x37, 0xb0},
  142. {0x20, 0x37, 0xb0},
  143. {0x20, 0x37, 0xc0},
  144. {0x20, 0x37, 0xc0},
  145. {0x0f, 0xf5, 0x20}, /* channel 15 Tf = 4915MHz */
  146. {0x2f, 0xf5, 0x20},
  147. {0x0f, 0xf5, 0x20},
  148. {0x0f, 0xf5, 0x20},
  149. {0x2f, 0xf5, 0x20},
  150. {0x0f, 0xf5, 0x20},
  151. {0x2f, 0xf5, 0x30},
  152. {0x2f, 0xf5, 0x30},
  153. {0x0f, 0xf5, 0x40},
  154. {0x2f, 0xf5, 0x40},
  155. {0x0f, 0xf5, 0x40},
  156. {0x0f, 0xf5, 0x40},
  157. {0x2f, 0xf5, 0x40},
  158. {0x2f, 0xf5, 0x50},
  159. {0x2f, 0xf5, 0x60},
  160. {0x2f, 0xf5, 0x60},
  161. {0x2f, 0xf5, 0x70},
  162. {0x2f, 0xf5, 0x70},
  163. {0x2f, 0xf5, 0x70},
  164. {0x2f, 0xf5, 0x70},
  165. {0x2f, 0xf5, 0x70},
  166. {0x2f, 0xf5, 0x70},
  167. {0x2f, 0xf5, 0x80},
  168. {0x2f, 0xf5, 0x80},
  169. {0x2f, 0xf5, 0x80},
  170. {0x2f, 0xf5, 0x90},
  171. {0x2f, 0xf5, 0xc0},
  172. {0x2f, 0xf5, 0xc0},
  173. {0x2f, 0xf5, 0xc0},
  174. {0x2f, 0xf5, 0xd0},
  175. {0x2f, 0xf5, 0xd0},
  176. {0x2f, 0xf5, 0xd0},
  177. {0x2f, 0xf5, 0xe0},
  178. {0x2f, 0xf5, 0xe0},
  179. {0x2f, 0xf5, 0xe0},
  180. {0x2f, 0xf5, 0xf0},
  181. {0x2f, 0xf5, 0xf0},
  182. {0x2f, 0xf6, 0x00},
  183. {0x2f, 0xf6, 0x00},
  184. {0x2f, 0xf6, 0x00},
  185. {0x2f, 0xf6, 0x10},
  186. {0x2f, 0xf6, 0x10}
  187. };
  188. static u8 al7230_channel_table1[CB_MAX_CHANNEL][3] = {
  189. {0x13, 0x33, 0x31},
  190. {0x1b, 0x33, 0x31},
  191. {0x03, 0x33, 0x31},
  192. {0x0b, 0x33, 0x31},
  193. {0x13, 0x33, 0x31},
  194. {0x1b, 0x33, 0x31},
  195. {0x03, 0x33, 0x31},
  196. {0x0b, 0x33, 0x31},
  197. {0x13, 0x33, 0x31},
  198. {0x1b, 0x33, 0x31},
  199. {0x03, 0x33, 0x31},
  200. {0x0b, 0x33, 0x31},
  201. {0x13, 0x33, 0x31},
  202. {0x06, 0x66, 0x61},
  203. {0x1d, 0x55, 0x51}, /* channel = 15, Tf = 4915MHz */
  204. {0x00, 0x00, 0x01},
  205. {0x02, 0xaa, 0xa1},
  206. {0x08, 0x00, 0x01},
  207. {0x0a, 0xaa, 0xa1},
  208. {0x0d, 0x55, 0x51},
  209. {0x15, 0x55, 0x51},
  210. {0x00, 0x00, 0x01},
  211. {0x1d, 0x55, 0x51},
  212. {0x00, 0x00, 0x01},
  213. {0x02, 0xaa, 0xa1},
  214. {0x08, 0x00, 0x01},
  215. {0x0a, 0xaa, 0xa1},
  216. {0x15, 0x55, 0x51},
  217. {0x05, 0x55, 0x51},
  218. {0x0a, 0xaa, 0xa1},
  219. {0x10, 0x00, 0x01},
  220. {0x15, 0x55, 0x51},
  221. {0x1a, 0xaa, 0xa1},
  222. {0x00, 0x00, 0x01},
  223. {0x05, 0x55, 0x51},
  224. {0x0a, 0xaa, 0xa1},
  225. {0x15, 0x55, 0x51},
  226. {0x00, 0x00, 0x01},
  227. {0x0a, 0xaa, 0xa1},
  228. {0x15, 0x55, 0x51},
  229. {0x15, 0x55, 0x51},
  230. {0x00, 0x00, 0x01},
  231. {0x0a, 0xaa, 0xa1},
  232. {0x15, 0x55, 0x51},
  233. {0x00, 0x00, 0x01},
  234. {0x0a, 0xaa, 0xa1},
  235. {0x15, 0x55, 0x51},
  236. {0x00, 0x00, 0x01},
  237. {0x0a, 0xaa, 0xa1},
  238. {0x15, 0x55, 0x51},
  239. {0x00, 0x00, 0x01},
  240. {0x18, 0x00, 0x01},
  241. {0x02, 0xaa, 0xa1},
  242. {0x0d, 0x55, 0x51},
  243. {0x18, 0x00, 0x01},
  244. {0x02, 0xaa, 0xb1}
  245. };
  246. static u8 al7230_channel_table2[CB_MAX_CHANNEL][3] = {
  247. {0x7f, 0xd7, 0x84},
  248. {0x7f, 0xd7, 0x84},
  249. {0x7f, 0xd7, 0x84},
  250. {0x7f, 0xd7, 0x84},
  251. {0x7f, 0xd7, 0x84},
  252. {0x7f, 0xd7, 0x84},
  253. {0x7f, 0xd7, 0x84},
  254. {0x7f, 0xd7, 0x84},
  255. {0x7f, 0xd7, 0x84},
  256. {0x7f, 0xd7, 0x84},
  257. {0x7f, 0xd7, 0x84},
  258. {0x7f, 0xd7, 0x84},
  259. {0x7f, 0xd7, 0x84},
  260. {0x7f, 0xd7, 0x84},
  261. {0x7f, 0xd7, 0x84}, /* channel = 15 Tf = 4915MHz */
  262. {0x6f, 0xd7, 0x84},
  263. {0x7f, 0xd7, 0x84},
  264. {0x7f, 0xd7, 0x84},
  265. {0x7f, 0xd7, 0x84},
  266. {0x7f, 0xd7, 0x84},
  267. {0x7f, 0xd7, 0x84},
  268. {0x6f, 0xd7, 0x84},
  269. {0x7f, 0xd7, 0x84},
  270. {0x6f, 0xd7, 0x84},
  271. {0x7f, 0xd7, 0x84},
  272. {0x7f, 0xd7, 0x84},
  273. {0x7f, 0xd7, 0x84},
  274. {0x7f, 0xd7, 0x84},
  275. {0x7f, 0xd7, 0x84},
  276. {0x7f, 0xd7, 0x84},
  277. {0x7f, 0xd7, 0x84},
  278. {0x7f, 0xd7, 0x84},
  279. {0x7f, 0xd7, 0x84},
  280. {0x6f, 0xd7, 0x84},
  281. {0x7f, 0xd7, 0x84},
  282. {0x7f, 0xd7, 0x84},
  283. {0x7f, 0xd7, 0x84},
  284. {0x6f, 0xd7, 0x84},
  285. {0x7f, 0xd7, 0x84},
  286. {0x7f, 0xd7, 0x84},
  287. {0x7f, 0xd7, 0x84},
  288. {0x6f, 0xd7, 0x84},
  289. {0x7f, 0xd7, 0x84},
  290. {0x7f, 0xd7, 0x84},
  291. {0x6f, 0xd7, 0x84},
  292. {0x7f, 0xd7, 0x84},
  293. {0x7f, 0xd7, 0x84},
  294. {0x6f, 0xd7, 0x84},
  295. {0x7f, 0xd7, 0x84},
  296. {0x7f, 0xd7, 0x84},
  297. {0x6f, 0xd7, 0x84},
  298. {0x7f, 0xd7, 0x84},
  299. {0x7f, 0xd7, 0x84},
  300. {0x7f, 0xd7, 0x84},
  301. {0x7f, 0xd7, 0x84},
  302. {0x7f, 0xd7, 0x84}
  303. };
  304. static u8 vt3226_init_table[CB_VT3226_INIT_SEQ][3] = {
  305. {0x03, 0xff, 0x80},
  306. {0x02, 0x82, 0xa1},
  307. {0x03, 0xc6, 0xa2},
  308. {0x01, 0x97, 0x93},
  309. {0x03, 0x66, 0x64},
  310. {0x00, 0x61, 0xa5},
  311. {0x01, 0x7b, 0xd6},
  312. {0x00, 0x80, 0x17},
  313. {0x03, 0xf8, 0x08},
  314. {0x00, 0x02, 0x39},
  315. {0x02, 0x00, 0x2a}
  316. };
  317. static u8 vt3226d0_init_table[CB_VT3226_INIT_SEQ][3] = {
  318. {0x03, 0xff, 0x80},
  319. {0x03, 0x02, 0x21},
  320. {0x03, 0xc6, 0xa2},
  321. {0x01, 0x97, 0x93},
  322. {0x03, 0x66, 0x64},
  323. {0x00, 0x71, 0xa5},
  324. {0x01, 0x15, 0xc6},
  325. {0x01, 0x2e, 0x07},
  326. {0x00, 0x58, 0x08},
  327. {0x00, 0x02, 0x79},
  328. {0x02, 0x01, 0xaa}
  329. };
  330. static u8 vt3226_channel_table0[CB_MAX_CHANNEL_24G][3] = {
  331. {0x01, 0x97, 0x83},
  332. {0x01, 0x97, 0x83},
  333. {0x01, 0x97, 0x93},
  334. {0x01, 0x97, 0x93},
  335. {0x01, 0x97, 0x93},
  336. {0x01, 0x97, 0x93},
  337. {0x01, 0x97, 0xa3},
  338. {0x01, 0x97, 0xa3},
  339. {0x01, 0x97, 0xa3},
  340. {0x01, 0x97, 0xa3},
  341. {0x01, 0x97, 0xb3},
  342. {0x01, 0x97, 0xb3},
  343. {0x01, 0x97, 0xb3},
  344. {0x03, 0x37, 0xc3}
  345. };
  346. static u8 vt3226_channel_table1[CB_MAX_CHANNEL_24G][3] = {
  347. {0x02, 0x66, 0x64},
  348. {0x03, 0x66, 0x64},
  349. {0x00, 0x66, 0x64},
  350. {0x01, 0x66, 0x64},
  351. {0x02, 0x66, 0x64},
  352. {0x03, 0x66, 0x64},
  353. {0x00, 0x66, 0x64},
  354. {0x01, 0x66, 0x64},
  355. {0x02, 0x66, 0x64},
  356. {0x03, 0x66, 0x64},
  357. {0x00, 0x66, 0x64},
  358. {0x01, 0x66, 0x64},
  359. {0x02, 0x66, 0x64},
  360. {0x00, 0xcc, 0xc4}
  361. };
  362. static const u32 vt3226d0_lo_current_table[CB_MAX_CHANNEL_24G] = {
  363. 0x0135c600,
  364. 0x0135c600,
  365. 0x0235c600,
  366. 0x0235c600,
  367. 0x0235c600,
  368. 0x0335c600,
  369. 0x0335c600,
  370. 0x0335c600,
  371. 0x0335c600,
  372. 0x0335c600,
  373. 0x0335c600,
  374. 0x0335c600,
  375. 0x0335c600,
  376. 0x0135c600
  377. };
  378. static u8 vt3342a0_init_table[CB_VT3342_INIT_SEQ][3] = { /* 11b/g mode */
  379. {0x03, 0xff, 0x80},
  380. {0x02, 0x08, 0x81},
  381. {0x00, 0xc6, 0x02},
  382. {0x03, 0xc5, 0x13},
  383. {0x00, 0xee, 0xe4},
  384. {0x00, 0x71, 0xa5},
  385. {0x01, 0x75, 0x46},
  386. {0x01, 0x40, 0x27},
  387. {0x01, 0x54, 0x08},
  388. {0x00, 0x01, 0x69},
  389. {0x02, 0x00, 0xaa},
  390. {0x00, 0x08, 0xcb},
  391. {0x01, 0x70, 0x0c}
  392. };
  393. static u8 vt3342_channel_table0[CB_MAX_CHANNEL][3] = {
  394. {0x02, 0x05, 0x03},
  395. {0x01, 0x15, 0x03},
  396. {0x03, 0xc5, 0x03},
  397. {0x02, 0x65, 0x03},
  398. {0x01, 0x15, 0x13},
  399. {0x03, 0xc5, 0x13},
  400. {0x02, 0x05, 0x13},
  401. {0x01, 0x15, 0x13},
  402. {0x03, 0xc5, 0x13},
  403. {0x02, 0x65, 0x13},
  404. {0x01, 0x15, 0x23},
  405. {0x03, 0xc5, 0x23},
  406. {0x02, 0x05, 0x23},
  407. {0x00, 0xd5, 0x23},
  408. {0x01, 0x15, 0x13}, /* channel = 15 Tf = 4915MHz */
  409. {0x01, 0x15, 0x13},
  410. {0x01, 0x15, 0x13},
  411. {0x01, 0x15, 0x13},
  412. {0x01, 0x15, 0x13},
  413. {0x01, 0x15, 0x13},
  414. {0x01, 0x15, 0x13},
  415. {0x01, 0x15, 0x13},
  416. {0x01, 0x15, 0x13},
  417. {0x01, 0x15, 0x13},
  418. {0x01, 0x15, 0x13},
  419. {0x01, 0x15, 0x13},
  420. {0x01, 0x15, 0x13},
  421. {0x01, 0x15, 0x13},
  422. {0x01, 0x15, 0x13},
  423. {0x01, 0x55, 0x63},
  424. {0x01, 0x55, 0x63},
  425. {0x02, 0xa5, 0x63},
  426. {0x02, 0xa5, 0x63},
  427. {0x00, 0x05, 0x73},
  428. {0x00, 0x05, 0x73},
  429. {0x01, 0x55, 0x73},
  430. {0x02, 0xa5, 0x73},
  431. {0x00, 0x05, 0x83},
  432. {0x01, 0x55, 0x83},
  433. {0x02, 0xa5, 0x83},
  434. {0x02, 0xa5, 0x83},
  435. {0x02, 0xa5, 0x83},
  436. {0x02, 0xa5, 0x83},
  437. {0x02, 0xa5, 0x83},
  438. {0x02, 0xa5, 0x83},
  439. {0x02, 0xa5, 0x83},
  440. {0x02, 0xa5, 0x83},
  441. {0x02, 0xa5, 0x83},
  442. {0x02, 0xa5, 0x83},
  443. {0x02, 0xa5, 0x83},
  444. {0x02, 0xa5, 0x83},
  445. {0x00, 0x05, 0xF3},
  446. {0x01, 0x56, 0x03},
  447. {0x02, 0xa6, 0x03},
  448. {0x00, 0x06, 0x03},
  449. {0x00, 0x06, 0x03}
  450. };
  451. static u8 vt3342_channel_table1[CB_MAX_CHANNEL][3] = {
  452. {0x01, 0x99, 0x94},
  453. {0x02, 0x44, 0x44},
  454. {0x02, 0xee, 0xe4},
  455. {0x03, 0x99, 0x94},
  456. {0x00, 0x44, 0x44},
  457. {0x00, 0xee, 0xe4},
  458. {0x01, 0x99, 0x94},
  459. {0x02, 0x44, 0x44},
  460. {0x02, 0xee, 0xe4},
  461. {0x03, 0x99, 0x94},
  462. {0x00, 0x44, 0x44},
  463. {0x00, 0xee, 0xe4},
  464. {0x01, 0x99, 0x94},
  465. {0x03, 0x33, 0x34},
  466. {0x00, 0x44, 0x44}, /* channel = 15 Tf = 4915MHz */
  467. {0x00, 0x44, 0x44},
  468. {0x00, 0x44, 0x44},
  469. {0x00, 0x44, 0x44},
  470. {0x00, 0x44, 0x44},
  471. {0x00, 0x44, 0x44},
  472. {0x00, 0x44, 0x44},
  473. {0x00, 0x44, 0x44},
  474. {0x00, 0x44, 0x44},
  475. {0x00, 0x44, 0x44},
  476. {0x00, 0x44, 0x44},
  477. {0x00, 0x44, 0x44},
  478. {0x00, 0x44, 0x44},
  479. {0x00, 0x44, 0x44},
  480. {0x00, 0x44, 0x44},
  481. {0x01, 0x55, 0x54},
  482. {0x01, 0x55, 0x54},
  483. {0x02, 0xaa, 0xa4},
  484. {0x02, 0xaa, 0xa4},
  485. {0x00, 0x00, 0x04},
  486. {0x00, 0x00, 0x04},
  487. {0x01, 0x55, 0x54},
  488. {0x02, 0xaa, 0xa4},
  489. {0x00, 0x00, 0x04},
  490. {0x01, 0x55, 0x54},
  491. {0x02, 0xaa, 0xa4},
  492. {0x02, 0xaa, 0xa4},
  493. {0x02, 0xaa, 0xa4},
  494. {0x02, 0xaa, 0xa4},
  495. {0x02, 0xaa, 0xa4},
  496. {0x02, 0xaa, 0xa4},
  497. {0x02, 0xaa, 0xa4},
  498. {0x02, 0xaa, 0xa4},
  499. {0x02, 0xaa, 0xa4},
  500. {0x02, 0xaa, 0xa4},
  501. {0x02, 0xaa, 0xa4},
  502. {0x02, 0xaa, 0xa4},
  503. {0x03, 0x00, 0x04},
  504. {0x00, 0x55, 0x54},
  505. {0x01, 0xaa, 0xa4},
  506. {0x03, 0x00, 0x04},
  507. {0x03, 0x00, 0x04}
  508. };
  509. /* Power Table */
  510. static const u32 al2230_power_table[AL2230_PWR_IDX_LEN] = {
  511. 0x04040900,
  512. 0x04041900,
  513. 0x04042900,
  514. 0x04043900,
  515. 0x04044900,
  516. 0x04045900,
  517. 0x04046900,
  518. 0x04047900,
  519. 0x04048900,
  520. 0x04049900,
  521. 0x0404a900,
  522. 0x0404b900,
  523. 0x0404c900,
  524. 0x0404d900,
  525. 0x0404e900,
  526. 0x0404f900,
  527. 0x04050900,
  528. 0x04051900,
  529. 0x04052900,
  530. 0x04053900,
  531. 0x04054900,
  532. 0x04055900,
  533. 0x04056900,
  534. 0x04057900,
  535. 0x04058900,
  536. 0x04059900,
  537. 0x0405a900,
  538. 0x0405b900,
  539. 0x0405c900,
  540. 0x0405d900,
  541. 0x0405e900,
  542. 0x0405f900,
  543. 0x04060900,
  544. 0x04061900,
  545. 0x04062900,
  546. 0x04063900,
  547. 0x04064900,
  548. 0x04065900,
  549. 0x04066900,
  550. 0x04067900,
  551. 0x04068900,
  552. 0x04069900,
  553. 0x0406a900,
  554. 0x0406b900,
  555. 0x0406c900,
  556. 0x0406d900,
  557. 0x0406e900,
  558. 0x0406f900,
  559. 0x04070900,
  560. 0x04071900,
  561. 0x04072900,
  562. 0x04073900,
  563. 0x04074900,
  564. 0x04075900,
  565. 0x04076900,
  566. 0x04077900,
  567. 0x04078900,
  568. 0x04079900,
  569. 0x0407a900,
  570. 0x0407b900,
  571. 0x0407c900,
  572. 0x0407d900,
  573. 0x0407e900,
  574. 0x0407f900
  575. };
  576. /*
  577. * Description: Write to IF/RF, by embedded programming
  578. */
  579. int vnt_rf_write_embedded(struct vnt_private *priv, u32 data)
  580. {
  581. u8 reg_data[4];
  582. data |= (VNT_RF_REG_LEN << 3) | IFREGCTL_REGW;
  583. reg_data[0] = (u8)data;
  584. reg_data[1] = (u8)(data >> 8);
  585. reg_data[2] = (u8)(data >> 16);
  586. reg_data[3] = (u8)(data >> 24);
  587. vnt_control_out(priv, MESSAGE_TYPE_WRITE_IFRF,
  588. 0, 0, ARRAY_SIZE(reg_data), reg_data);
  589. return true;
  590. }
  591. /* Set Tx power by rate and channel number */
  592. int vnt_rf_setpower(struct vnt_private *priv, u32 rate, u32 channel)
  593. {
  594. u8 power = priv->cck_pwr;
  595. if (channel == 0)
  596. return -EINVAL;
  597. switch (rate) {
  598. case RATE_1M:
  599. case RATE_2M:
  600. case RATE_5M:
  601. case RATE_11M:
  602. channel--;
  603. if (channel < sizeof(priv->cck_pwr_tbl))
  604. power = priv->cck_pwr_tbl[channel];
  605. break;
  606. case RATE_6M:
  607. case RATE_9M:
  608. case RATE_12M:
  609. case RATE_18M:
  610. case RATE_24M:
  611. case RATE_36M:
  612. case RATE_48M:
  613. case RATE_54M:
  614. if (channel > CB_MAX_CHANNEL_24G)
  615. power = priv->ofdm_a_pwr_tbl[channel-15];
  616. else
  617. power = priv->ofdm_pwr_tbl[channel-1];
  618. break;
  619. }
  620. return vnt_rf_set_txpower(priv, power, rate);
  621. }
  622. static u8 vnt_rf_addpower(struct vnt_private *priv)
  623. {
  624. s32 rssi = -priv->current_rssi;
  625. if (!rssi)
  626. return 7;
  627. if (priv->rf_type == RF_VT3226D0) {
  628. if (rssi < -70)
  629. return 9;
  630. else if (rssi < -65)
  631. return 7;
  632. else if (rssi < -60)
  633. return 5;
  634. } else {
  635. if (rssi < -80)
  636. return 9;
  637. else if (rssi < -75)
  638. return 7;
  639. else if (rssi < -70)
  640. return 5;
  641. }
  642. return 0;
  643. }
  644. /* Set Tx power by power level and rate */
  645. int vnt_rf_set_txpower(struct vnt_private *priv, u8 power, u32 rate)
  646. {
  647. u32 power_setting = 0;
  648. int ret = true;
  649. power += vnt_rf_addpower(priv);
  650. if (power > VNT_RF_MAX_POWER)
  651. power = VNT_RF_MAX_POWER;
  652. if (priv->power == power)
  653. return true;
  654. priv->power = power;
  655. switch (priv->rf_type) {
  656. case RF_AL2230:
  657. if (power >= AL2230_PWR_IDX_LEN)
  658. return false;
  659. ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]);
  660. if (rate <= RATE_11M)
  661. ret &= vnt_rf_write_embedded(priv, 0x0001b400);
  662. else
  663. ret &= vnt_rf_write_embedded(priv, 0x0005a400);
  664. break;
  665. case RF_AL2230S:
  666. if (power >= AL2230_PWR_IDX_LEN)
  667. return false;
  668. ret &= vnt_rf_write_embedded(priv, al2230_power_table[power]);
  669. if (rate <= RATE_11M) {
  670. ret &= vnt_rf_write_embedded(priv, 0x040c1400);
  671. ret &= vnt_rf_write_embedded(priv, 0x00299b00);
  672. } else {
  673. ret &= vnt_rf_write_embedded(priv, 0x0005a400);
  674. ret &= vnt_rf_write_embedded(priv, 0x00099b00);
  675. }
  676. break;
  677. case RF_AIROHA7230:
  678. if (rate <= RATE_11M)
  679. ret &= vnt_rf_write_embedded(priv, 0x111bb900);
  680. else
  681. ret &= vnt_rf_write_embedded(priv, 0x221bb900);
  682. if (power >= AL7230_PWR_IDX_LEN)
  683. return false;
  684. /*
  685. * 0x080F1B00 for 3 wire control TxGain(D10)
  686. * and 0x31 as TX Gain value
  687. */
  688. power_setting = 0x080c0b00 | (power << 12);
  689. ret &= vnt_rf_write_embedded(priv, power_setting);
  690. break;
  691. case RF_VT3226:
  692. if (power >= VT3226_PWR_IDX_LEN)
  693. return false;
  694. power_setting = ((0x3f - power) << 20) | (0x17 << 8);
  695. ret &= vnt_rf_write_embedded(priv, power_setting);
  696. break;
  697. case RF_VT3226D0:
  698. if (power >= VT3226_PWR_IDX_LEN)
  699. return false;
  700. if (rate <= RATE_11M) {
  701. u16 hw_value = priv->hw->conf.chandef.chan->hw_value;
  702. power_setting = ((0x3f - power) << 20) | (0xe07 << 8);
  703. ret &= vnt_rf_write_embedded(priv, power_setting);
  704. ret &= vnt_rf_write_embedded(priv, 0x03c6a200);
  705. dev_dbg(&priv->usb->dev,
  706. "%s 11b channel [%d]\n", __func__, hw_value);
  707. hw_value--;
  708. if (hw_value < ARRAY_SIZE(vt3226d0_lo_current_table))
  709. ret &= vnt_rf_write_embedded(priv,
  710. vt3226d0_lo_current_table[hw_value]);
  711. ret &= vnt_rf_write_embedded(priv, 0x015C0800);
  712. } else {
  713. dev_dbg(&priv->usb->dev,
  714. "@@@@ vnt_rf_set_txpower> 11G mode\n");
  715. power_setting = ((0x3f - power) << 20) | (0x7 << 8);
  716. ret &= vnt_rf_write_embedded(priv, power_setting);
  717. ret &= vnt_rf_write_embedded(priv, 0x00C6A200);
  718. ret &= vnt_rf_write_embedded(priv, 0x016BC600);
  719. ret &= vnt_rf_write_embedded(priv, 0x00900800);
  720. }
  721. break;
  722. case RF_VT3342A0:
  723. if (power >= VT3342_PWR_IDX_LEN)
  724. return false;
  725. power_setting = ((0x3f - power) << 20) | (0x27 << 8);
  726. ret &= vnt_rf_write_embedded(priv, power_setting);
  727. break;
  728. default:
  729. break;
  730. }
  731. return ret;
  732. }
  733. /* Convert rssi to dbm */
  734. void vnt_rf_rssi_to_dbm(struct vnt_private *priv, u8 rssi, long *dbm)
  735. {
  736. u8 idx = (((rssi & 0xc0) >> 6) & 0x03);
  737. long b = (rssi & 0x3f);
  738. long a = 0;
  739. u8 airoharf[4] = {0, 18, 0, 40};
  740. switch (priv->rf_type) {
  741. case RF_AL2230:
  742. case RF_AL2230S:
  743. case RF_AIROHA7230:
  744. case RF_VT3226:
  745. case RF_VT3226D0:
  746. case RF_VT3342A0:
  747. a = airoharf[idx];
  748. break;
  749. default:
  750. break;
  751. }
  752. *dbm = -1 * (a + b * 2);
  753. }
  754. void vnt_rf_table_download(struct vnt_private *priv)
  755. {
  756. u16 length1 = 0, length2 = 0, length3 = 0;
  757. u8 *addr1 = NULL, *addr2 = NULL, *addr3 = NULL;
  758. u16 length, value;
  759. u8 array[256];
  760. switch (priv->rf_type) {
  761. case RF_AL2230:
  762. case RF_AL2230S:
  763. length1 = CB_AL2230_INIT_SEQ * 3;
  764. length2 = CB_MAX_CHANNEL_24G * 3;
  765. length3 = CB_MAX_CHANNEL_24G * 3;
  766. addr1 = &al2230_init_table[0][0];
  767. addr2 = &al2230_channel_table0[0][0];
  768. addr3 = &al2230_channel_table1[0][0];
  769. break;
  770. case RF_AIROHA7230:
  771. length1 = CB_AL7230_INIT_SEQ * 3;
  772. length2 = CB_MAX_CHANNEL * 3;
  773. length3 = CB_MAX_CHANNEL * 3;
  774. addr1 = &al7230_init_table[0][0];
  775. addr2 = &al7230_channel_table0[0][0];
  776. addr3 = &al7230_channel_table1[0][0];
  777. break;
  778. case RF_VT3226:
  779. length1 = CB_VT3226_INIT_SEQ * 3;
  780. length2 = CB_MAX_CHANNEL_24G * 3;
  781. length3 = CB_MAX_CHANNEL_24G * 3;
  782. addr1 = &vt3226_init_table[0][0];
  783. addr2 = &vt3226_channel_table0[0][0];
  784. addr3 = &vt3226_channel_table1[0][0];
  785. break;
  786. case RF_VT3226D0:
  787. length1 = CB_VT3226_INIT_SEQ * 3;
  788. length2 = CB_MAX_CHANNEL_24G * 3;
  789. length3 = CB_MAX_CHANNEL_24G * 3;
  790. addr1 = &vt3226d0_init_table[0][0];
  791. addr2 = &vt3226_channel_table0[0][0];
  792. addr3 = &vt3226_channel_table1[0][0];
  793. break;
  794. case RF_VT3342A0:
  795. length1 = CB_VT3342_INIT_SEQ * 3;
  796. length2 = CB_MAX_CHANNEL * 3;
  797. length3 = CB_MAX_CHANNEL * 3;
  798. addr1 = &vt3342a0_init_table[0][0];
  799. addr2 = &vt3342_channel_table0[0][0];
  800. addr3 = &vt3342_channel_table1[0][0];
  801. break;
  802. }
  803. /* Init Table */
  804. memcpy(array, addr1, length1);
  805. vnt_control_out(priv, MESSAGE_TYPE_WRITE, 0,
  806. MESSAGE_REQUEST_RF_INIT, length1, array);
  807. /* Channel Table 0 */
  808. value = 0;
  809. while (length2 > 0) {
  810. if (length2 >= 64)
  811. length = 64;
  812. else
  813. length = length2;
  814. memcpy(array, addr2, length);
  815. vnt_control_out(priv, MESSAGE_TYPE_WRITE,
  816. value, MESSAGE_REQUEST_RF_CH0, length, array);
  817. length2 -= length;
  818. value += length;
  819. addr2 += length;
  820. }
  821. /* Channel table 1 */
  822. value = 0;
  823. while (length3 > 0) {
  824. if (length3 >= 64)
  825. length = 64;
  826. else
  827. length = length3;
  828. memcpy(array, addr3, length);
  829. vnt_control_out(priv, MESSAGE_TYPE_WRITE,
  830. value, MESSAGE_REQUEST_RF_CH1, length, array);
  831. length3 -= length;
  832. value += length;
  833. addr3 += length;
  834. }
  835. if (priv->rf_type == RF_AIROHA7230) {
  836. length1 = CB_AL7230_INIT_SEQ * 3;
  837. length2 = CB_MAX_CHANNEL * 3;
  838. addr1 = &al7230_init_table_amode[0][0];
  839. addr2 = &al7230_channel_table2[0][0];
  840. memcpy(array, addr1, length1);
  841. /* Init Table 2 */
  842. vnt_control_out(priv, MESSAGE_TYPE_WRITE,
  843. 0, MESSAGE_REQUEST_RF_INIT2, length1, array);
  844. /* Channel Table 0 */
  845. value = 0;
  846. while (length2 > 0) {
  847. if (length2 >= 64)
  848. length = 64;
  849. else
  850. length = length2;
  851. memcpy(array, addr2, length);
  852. vnt_control_out(priv, MESSAGE_TYPE_WRITE,
  853. value, MESSAGE_REQUEST_RF_CH2, length, array);
  854. length2 -= length;
  855. value += length;
  856. addr2 += length;
  857. }
  858. }
  859. }