rf.c 20 KB

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