rt2500usb.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. /*
  2. Copyright (C) 2004 - 2007 rt2x00 SourceForge Project
  3. <http://rt2x00.serialmonkey.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the
  14. Free Software Foundation, Inc.,
  15. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. Module: rt2500usb
  19. Abstract: rt2500usb device specific routines.
  20. Supported chipsets: RT2570.
  21. */
  22. #include <linux/delay.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/init.h>
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/usb.h>
  28. #include "rt2x00.h"
  29. #include "rt2x00usb.h"
  30. #include "rt2500usb.h"
  31. /*
  32. * Register access.
  33. * All access to the CSR registers will go through the methods
  34. * rt2500usb_register_read and rt2500usb_register_write.
  35. * BBP and RF register require indirect register access,
  36. * and use the CSR registers BBPCSR and RFCSR to achieve this.
  37. * These indirect registers work with busy bits,
  38. * and we will try maximal REGISTER_BUSY_COUNT times to access
  39. * the register while taking a REGISTER_BUSY_DELAY us delay
  40. * between each attampt. When the busy bit is still set at that time,
  41. * the access attempt is considered to have failed,
  42. * and we will print an error.
  43. * If the usb_cache_mutex is already held then the _lock variants must
  44. * be used instead.
  45. */
  46. static inline void rt2500usb_register_read(struct rt2x00_dev *rt2x00dev,
  47. const unsigned int offset,
  48. u16 *value)
  49. {
  50. __le16 reg;
  51. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
  52. USB_VENDOR_REQUEST_IN, offset,
  53. &reg, sizeof(u16), REGISTER_TIMEOUT);
  54. *value = le16_to_cpu(reg);
  55. }
  56. static inline void rt2500usb_register_read_lock(struct rt2x00_dev *rt2x00dev,
  57. const unsigned int offset,
  58. u16 *value)
  59. {
  60. __le16 reg;
  61. rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_READ,
  62. USB_VENDOR_REQUEST_IN, offset,
  63. &reg, sizeof(u16), REGISTER_TIMEOUT);
  64. *value = le16_to_cpu(reg);
  65. }
  66. static inline void rt2500usb_register_multiread(struct rt2x00_dev *rt2x00dev,
  67. const unsigned int offset,
  68. void *value, const u16 length)
  69. {
  70. int timeout = REGISTER_TIMEOUT * (length / sizeof(u16));
  71. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_READ,
  72. USB_VENDOR_REQUEST_IN, offset,
  73. value, length, timeout);
  74. }
  75. static inline void rt2500usb_register_write(struct rt2x00_dev *rt2x00dev,
  76. const unsigned int offset,
  77. u16 value)
  78. {
  79. __le16 reg = cpu_to_le16(value);
  80. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
  81. USB_VENDOR_REQUEST_OUT, offset,
  82. &reg, sizeof(u16), REGISTER_TIMEOUT);
  83. }
  84. static inline void rt2500usb_register_write_lock(struct rt2x00_dev *rt2x00dev,
  85. const unsigned int offset,
  86. u16 value)
  87. {
  88. __le16 reg = cpu_to_le16(value);
  89. rt2x00usb_vendor_req_buff_lock(rt2x00dev, USB_MULTI_WRITE,
  90. USB_VENDOR_REQUEST_OUT, offset,
  91. &reg, sizeof(u16), REGISTER_TIMEOUT);
  92. }
  93. static inline void rt2500usb_register_multiwrite(struct rt2x00_dev *rt2x00dev,
  94. const unsigned int offset,
  95. void *value, const u16 length)
  96. {
  97. int timeout = REGISTER_TIMEOUT * (length / sizeof(u16));
  98. rt2x00usb_vendor_request_buff(rt2x00dev, USB_MULTI_WRITE,
  99. USB_VENDOR_REQUEST_OUT, offset,
  100. value, length, timeout);
  101. }
  102. static u16 rt2500usb_bbp_check(struct rt2x00_dev *rt2x00dev)
  103. {
  104. u16 reg;
  105. unsigned int i;
  106. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  107. rt2500usb_register_read_lock(rt2x00dev, PHY_CSR8, &reg);
  108. if (!rt2x00_get_field16(reg, PHY_CSR8_BUSY))
  109. break;
  110. udelay(REGISTER_BUSY_DELAY);
  111. }
  112. return reg;
  113. }
  114. static void rt2500usb_bbp_write(struct rt2x00_dev *rt2x00dev,
  115. const unsigned int word, const u8 value)
  116. {
  117. u16 reg;
  118. mutex_lock(&rt2x00dev->usb_cache_mutex);
  119. /*
  120. * Wait until the BBP becomes ready.
  121. */
  122. reg = rt2500usb_bbp_check(rt2x00dev);
  123. if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
  124. ERROR(rt2x00dev, "PHY_CSR8 register busy. Write failed.\n");
  125. mutex_unlock(&rt2x00dev->usb_cache_mutex);
  126. return;
  127. }
  128. /*
  129. * Write the data into the BBP.
  130. */
  131. reg = 0;
  132. rt2x00_set_field16(&reg, PHY_CSR7_DATA, value);
  133. rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
  134. rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 0);
  135. rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
  136. mutex_unlock(&rt2x00dev->usb_cache_mutex);
  137. }
  138. static void rt2500usb_bbp_read(struct rt2x00_dev *rt2x00dev,
  139. const unsigned int word, u8 *value)
  140. {
  141. u16 reg;
  142. mutex_lock(&rt2x00dev->usb_cache_mutex);
  143. /*
  144. * Wait until the BBP becomes ready.
  145. */
  146. reg = rt2500usb_bbp_check(rt2x00dev);
  147. if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
  148. ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
  149. return;
  150. }
  151. /*
  152. * Write the request into the BBP.
  153. */
  154. reg = 0;
  155. rt2x00_set_field16(&reg, PHY_CSR7_REG_ID, word);
  156. rt2x00_set_field16(&reg, PHY_CSR7_READ_CONTROL, 1);
  157. rt2500usb_register_write_lock(rt2x00dev, PHY_CSR7, reg);
  158. /*
  159. * Wait until the BBP becomes ready.
  160. */
  161. reg = rt2500usb_bbp_check(rt2x00dev);
  162. if (rt2x00_get_field16(reg, PHY_CSR8_BUSY)) {
  163. ERROR(rt2x00dev, "PHY_CSR8 register busy. Read failed.\n");
  164. *value = 0xff;
  165. mutex_unlock(&rt2x00dev->usb_cache_mutex);
  166. return;
  167. }
  168. rt2500usb_register_read_lock(rt2x00dev, PHY_CSR7, &reg);
  169. *value = rt2x00_get_field16(reg, PHY_CSR7_DATA);
  170. mutex_unlock(&rt2x00dev->usb_cache_mutex);
  171. }
  172. static void rt2500usb_rf_write(struct rt2x00_dev *rt2x00dev,
  173. const unsigned int word, const u32 value)
  174. {
  175. u16 reg;
  176. unsigned int i;
  177. if (!word)
  178. return;
  179. mutex_lock(&rt2x00dev->usb_cache_mutex);
  180. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  181. rt2500usb_register_read_lock(rt2x00dev, PHY_CSR10, &reg);
  182. if (!rt2x00_get_field16(reg, PHY_CSR10_RF_BUSY))
  183. goto rf_write;
  184. udelay(REGISTER_BUSY_DELAY);
  185. }
  186. mutex_unlock(&rt2x00dev->usb_cache_mutex);
  187. ERROR(rt2x00dev, "PHY_CSR10 register busy. Write failed.\n");
  188. return;
  189. rf_write:
  190. reg = 0;
  191. rt2x00_set_field16(&reg, PHY_CSR9_RF_VALUE, value);
  192. rt2500usb_register_write_lock(rt2x00dev, PHY_CSR9, reg);
  193. reg = 0;
  194. rt2x00_set_field16(&reg, PHY_CSR10_RF_VALUE, value >> 16);
  195. rt2x00_set_field16(&reg, PHY_CSR10_RF_NUMBER_OF_BITS, 20);
  196. rt2x00_set_field16(&reg, PHY_CSR10_RF_IF_SELECT, 0);
  197. rt2x00_set_field16(&reg, PHY_CSR10_RF_BUSY, 1);
  198. rt2500usb_register_write_lock(rt2x00dev, PHY_CSR10, reg);
  199. rt2x00_rf_write(rt2x00dev, word, value);
  200. mutex_unlock(&rt2x00dev->usb_cache_mutex);
  201. }
  202. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  203. #define CSR_OFFSET(__word) ( CSR_REG_BASE + ((__word) * sizeof(u16)) )
  204. static void rt2500usb_read_csr(struct rt2x00_dev *rt2x00dev,
  205. const unsigned int word, u32 *data)
  206. {
  207. rt2500usb_register_read(rt2x00dev, CSR_OFFSET(word), (u16 *) data);
  208. }
  209. static void rt2500usb_write_csr(struct rt2x00_dev *rt2x00dev,
  210. const unsigned int word, u32 data)
  211. {
  212. rt2500usb_register_write(rt2x00dev, CSR_OFFSET(word), data);
  213. }
  214. static const struct rt2x00debug rt2500usb_rt2x00debug = {
  215. .owner = THIS_MODULE,
  216. .csr = {
  217. .read = rt2500usb_read_csr,
  218. .write = rt2500usb_write_csr,
  219. .word_size = sizeof(u16),
  220. .word_count = CSR_REG_SIZE / sizeof(u16),
  221. },
  222. .eeprom = {
  223. .read = rt2x00_eeprom_read,
  224. .write = rt2x00_eeprom_write,
  225. .word_size = sizeof(u16),
  226. .word_count = EEPROM_SIZE / sizeof(u16),
  227. },
  228. .bbp = {
  229. .read = rt2500usb_bbp_read,
  230. .write = rt2500usb_bbp_write,
  231. .word_size = sizeof(u8),
  232. .word_count = BBP_SIZE / sizeof(u8),
  233. },
  234. .rf = {
  235. .read = rt2x00_rf_read,
  236. .write = rt2500usb_rf_write,
  237. .word_size = sizeof(u32),
  238. .word_count = RF_SIZE / sizeof(u32),
  239. },
  240. };
  241. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  242. /*
  243. * Configuration handlers.
  244. */
  245. static void rt2500usb_config_mac_addr(struct rt2x00_dev *rt2x00dev,
  246. __le32 *mac)
  247. {
  248. rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR2, mac,
  249. (3 * sizeof(__le16)));
  250. }
  251. static void rt2500usb_config_bssid(struct rt2x00_dev *rt2x00dev,
  252. __le32 *bssid)
  253. {
  254. rt2500usb_register_multiwrite(rt2x00dev, MAC_CSR5, bssid,
  255. (3 * sizeof(__le16)));
  256. }
  257. static void rt2500usb_config_type(struct rt2x00_dev *rt2x00dev, const int type,
  258. const int tsf_sync)
  259. {
  260. u16 reg;
  261. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
  262. /*
  263. * Enable beacon config
  264. */
  265. rt2500usb_register_read(rt2x00dev, TXRX_CSR20, &reg);
  266. rt2x00_set_field16(&reg, TXRX_CSR20_OFFSET,
  267. (PREAMBLE + get_duration(IEEE80211_HEADER, 20)) >> 6);
  268. if (type == IEEE80211_IF_TYPE_STA)
  269. rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW, 0);
  270. else
  271. rt2x00_set_field16(&reg, TXRX_CSR20_BCN_EXPECT_WINDOW, 2);
  272. rt2500usb_register_write(rt2x00dev, TXRX_CSR20, reg);
  273. /*
  274. * Enable synchronisation.
  275. */
  276. rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
  277. rt2x00_set_field16(&reg, TXRX_CSR18_OFFSET, 0);
  278. rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
  279. rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
  280. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_COUNT, 1);
  281. rt2x00_set_field16(&reg, TXRX_CSR19_TBCN,
  282. (tsf_sync == TSF_SYNC_BEACON));
  283. rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
  284. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, tsf_sync);
  285. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  286. }
  287. static void rt2500usb_config_preamble(struct rt2x00_dev *rt2x00dev,
  288. const int short_preamble,
  289. const int ack_timeout,
  290. const int ack_consume_time)
  291. {
  292. u16 reg;
  293. /*
  294. * When in atomic context, reschedule and let rt2x00lib
  295. * call this function again.
  296. */
  297. if (in_atomic()) {
  298. queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->config_work);
  299. return;
  300. }
  301. rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  302. rt2x00_set_field16(&reg, TXRX_CSR1_ACK_TIMEOUT, ack_timeout);
  303. rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  304. rt2500usb_register_read(rt2x00dev, TXRX_CSR10, &reg);
  305. rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
  306. !!short_preamble);
  307. rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
  308. }
  309. static void rt2500usb_config_phymode(struct rt2x00_dev *rt2x00dev,
  310. const int phymode,
  311. const int basic_rate_mask)
  312. {
  313. rt2500usb_register_write(rt2x00dev, TXRX_CSR11, basic_rate_mask);
  314. if (phymode == HWMODE_B) {
  315. rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x000b);
  316. rt2500usb_register_write(rt2x00dev, MAC_CSR12, 0x0040);
  317. } else {
  318. rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0005);
  319. rt2500usb_register_write(rt2x00dev, MAC_CSR12, 0x016c);
  320. }
  321. }
  322. static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
  323. struct rf_channel *rf, const int txpower)
  324. {
  325. /*
  326. * Set TXpower.
  327. */
  328. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  329. /*
  330. * For RT2525E we should first set the channel to half band higher.
  331. */
  332. if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
  333. static const u32 vals[] = {
  334. 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
  335. 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
  336. 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
  337. 0x00000902, 0x00000906
  338. };
  339. rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
  340. if (rf->rf4)
  341. rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
  342. }
  343. rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
  344. rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
  345. rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
  346. if (rf->rf4)
  347. rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
  348. }
  349. static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  350. const int txpower)
  351. {
  352. u32 rf3;
  353. rt2x00_rf_read(rt2x00dev, 3, &rf3);
  354. rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  355. rt2500usb_rf_write(rt2x00dev, 3, rf3);
  356. }
  357. static void rt2500usb_config_antenna(struct rt2x00_dev *rt2x00dev,
  358. struct antenna_setup *ant)
  359. {
  360. u8 r2;
  361. u8 r14;
  362. u16 csr5;
  363. u16 csr6;
  364. rt2500usb_bbp_read(rt2x00dev, 2, &r2);
  365. rt2500usb_bbp_read(rt2x00dev, 14, &r14);
  366. rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
  367. rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
  368. /*
  369. * Configure the TX antenna.
  370. */
  371. switch (ant->tx) {
  372. case ANTENNA_HW_DIVERSITY:
  373. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
  374. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
  375. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
  376. break;
  377. case ANTENNA_A:
  378. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
  379. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
  380. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
  381. break;
  382. case ANTENNA_SW_DIVERSITY:
  383. /*
  384. * NOTE: We should never come here because rt2x00lib is
  385. * supposed to catch this and send us the correct antenna
  386. * explicitely. However we are nog going to bug about this.
  387. * Instead, just default to antenna B.
  388. */
  389. case ANTENNA_B:
  390. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
  391. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
  392. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
  393. break;
  394. }
  395. /*
  396. * Configure the RX antenna.
  397. */
  398. switch (ant->rx) {
  399. case ANTENNA_HW_DIVERSITY:
  400. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
  401. break;
  402. case ANTENNA_A:
  403. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
  404. break;
  405. case ANTENNA_SW_DIVERSITY:
  406. /*
  407. * NOTE: We should never come here because rt2x00lib is
  408. * supposed to catch this and send us the correct antenna
  409. * explicitely. However we are nog going to bug about this.
  410. * Instead, just default to antenna B.
  411. */
  412. case ANTENNA_B:
  413. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
  414. break;
  415. }
  416. /*
  417. * RT2525E and RT5222 need to flip TX I/Q
  418. */
  419. if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
  420. rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  421. rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
  422. rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
  423. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
  424. /*
  425. * RT2525E does not need RX I/Q Flip.
  426. */
  427. if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
  428. rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
  429. } else {
  430. rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
  431. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
  432. }
  433. rt2500usb_bbp_write(rt2x00dev, 2, r2);
  434. rt2500usb_bbp_write(rt2x00dev, 14, r14);
  435. rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
  436. rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
  437. }
  438. static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
  439. struct rt2x00lib_conf *libconf)
  440. {
  441. u16 reg;
  442. rt2500usb_register_write(rt2x00dev, MAC_CSR10, libconf->slot_time);
  443. rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
  444. rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL,
  445. libconf->conf->beacon_int * 4);
  446. rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
  447. }
  448. static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
  449. const unsigned int flags,
  450. struct rt2x00lib_conf *libconf)
  451. {
  452. if (flags & CONFIG_UPDATE_PHYMODE)
  453. rt2500usb_config_phymode(rt2x00dev, libconf->phymode,
  454. libconf->basic_rates);
  455. if (flags & CONFIG_UPDATE_CHANNEL)
  456. rt2500usb_config_channel(rt2x00dev, &libconf->rf,
  457. libconf->conf->power_level);
  458. if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL))
  459. rt2500usb_config_txpower(rt2x00dev,
  460. libconf->conf->power_level);
  461. if (flags & CONFIG_UPDATE_ANTENNA)
  462. rt2500usb_config_antenna(rt2x00dev, &libconf->ant);
  463. if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
  464. rt2500usb_config_duration(rt2x00dev, libconf);
  465. }
  466. /*
  467. * LED functions.
  468. */
  469. static void rt2500usb_enable_led(struct rt2x00_dev *rt2x00dev)
  470. {
  471. u16 reg;
  472. rt2500usb_register_read(rt2x00dev, MAC_CSR21, &reg);
  473. rt2x00_set_field16(&reg, MAC_CSR21_ON_PERIOD, 70);
  474. rt2x00_set_field16(&reg, MAC_CSR21_OFF_PERIOD, 30);
  475. rt2500usb_register_write(rt2x00dev, MAC_CSR21, reg);
  476. rt2500usb_register_read(rt2x00dev, MAC_CSR20, &reg);
  477. rt2x00_set_field16(&reg, MAC_CSR20_LINK,
  478. (rt2x00dev->led_mode != LED_MODE_ASUS));
  479. rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY,
  480. (rt2x00dev->led_mode != LED_MODE_TXRX_ACTIVITY));
  481. rt2500usb_register_write(rt2x00dev, MAC_CSR20, reg);
  482. }
  483. static void rt2500usb_disable_led(struct rt2x00_dev *rt2x00dev)
  484. {
  485. u16 reg;
  486. rt2500usb_register_read(rt2x00dev, MAC_CSR20, &reg);
  487. rt2x00_set_field16(&reg, MAC_CSR20_LINK, 0);
  488. rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, 0);
  489. rt2500usb_register_write(rt2x00dev, MAC_CSR20, reg);
  490. }
  491. /*
  492. * Link tuning
  493. */
  494. static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
  495. struct link_qual *qual)
  496. {
  497. u16 reg;
  498. /*
  499. * Update FCS error count from register.
  500. */
  501. rt2500usb_register_read(rt2x00dev, STA_CSR0, &reg);
  502. qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
  503. /*
  504. * Update False CCA count from register.
  505. */
  506. rt2500usb_register_read(rt2x00dev, STA_CSR3, &reg);
  507. qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
  508. }
  509. static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev)
  510. {
  511. u16 eeprom;
  512. u16 value;
  513. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
  514. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
  515. rt2500usb_bbp_write(rt2x00dev, 24, value);
  516. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
  517. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
  518. rt2500usb_bbp_write(rt2x00dev, 25, value);
  519. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
  520. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
  521. rt2500usb_bbp_write(rt2x00dev, 61, value);
  522. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
  523. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
  524. rt2500usb_bbp_write(rt2x00dev, 17, value);
  525. rt2x00dev->link.vgc_level = value;
  526. }
  527. static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
  528. {
  529. int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
  530. u16 bbp_thresh;
  531. u16 vgc_bound;
  532. u16 sens;
  533. u16 r24;
  534. u16 r25;
  535. u16 r61;
  536. u16 r17_sens;
  537. u8 r17;
  538. u8 up_bound;
  539. u8 low_bound;
  540. /*
  541. * Determine the BBP tuning threshold and correctly
  542. * set BBP 24, 25 and 61.
  543. */
  544. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &bbp_thresh);
  545. bbp_thresh = rt2x00_get_field16(bbp_thresh, EEPROM_BBPTUNE_THRESHOLD);
  546. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &r24);
  547. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &r25);
  548. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &r61);
  549. if ((rssi + bbp_thresh) > 0) {
  550. r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_HIGH);
  551. r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_HIGH);
  552. r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_HIGH);
  553. } else {
  554. r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_LOW);
  555. r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_LOW);
  556. r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_LOW);
  557. }
  558. rt2500usb_bbp_write(rt2x00dev, 24, r24);
  559. rt2500usb_bbp_write(rt2x00dev, 25, r25);
  560. rt2500usb_bbp_write(rt2x00dev, 61, r61);
  561. /*
  562. * Read current r17 value, as well as the sensitivity values
  563. * for the r17 register.
  564. */
  565. rt2500usb_bbp_read(rt2x00dev, 17, &r17);
  566. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
  567. /*
  568. * A too low RSSI will cause too much false CCA which will
  569. * then corrupt the R17 tuning. To remidy this the tuning should
  570. * be stopped (While making sure the R17 value will not exceed limits)
  571. */
  572. if (rssi >= -40) {
  573. if (r17 != 0x60)
  574. rt2500usb_bbp_write(rt2x00dev, 17, 0x60);
  575. return;
  576. }
  577. /*
  578. * Special big-R17 for short distance
  579. */
  580. if (rssi >= -58) {
  581. sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_LOW);
  582. if (r17 != sens)
  583. rt2500usb_bbp_write(rt2x00dev, 17, sens);
  584. return;
  585. }
  586. /*
  587. * Special mid-R17 for middle distance
  588. */
  589. if (rssi >= -74) {
  590. sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_HIGH);
  591. if (r17 != sens)
  592. rt2500usb_bbp_write(rt2x00dev, 17, sens);
  593. return;
  594. }
  595. /*
  596. * Leave short or middle distance condition, restore r17
  597. * to the dynamic tuning range.
  598. */
  599. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
  600. vgc_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
  601. low_bound = 0x32;
  602. if (rssi >= -77)
  603. up_bound = vgc_bound;
  604. else
  605. up_bound = vgc_bound - (-77 - rssi);
  606. if (up_bound < low_bound)
  607. up_bound = low_bound;
  608. if (r17 > up_bound) {
  609. rt2500usb_bbp_write(rt2x00dev, 17, up_bound);
  610. rt2x00dev->link.vgc_level = up_bound;
  611. } else if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
  612. rt2500usb_bbp_write(rt2x00dev, 17, ++r17);
  613. rt2x00dev->link.vgc_level = r17;
  614. } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
  615. rt2500usb_bbp_write(rt2x00dev, 17, --r17);
  616. rt2x00dev->link.vgc_level = r17;
  617. }
  618. }
  619. /*
  620. * Initialization functions.
  621. */
  622. static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
  623. {
  624. u16 reg;
  625. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
  626. USB_MODE_TEST, REGISTER_TIMEOUT);
  627. rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
  628. 0x00f0, REGISTER_TIMEOUT);
  629. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  630. rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 1);
  631. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  632. rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
  633. rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
  634. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  635. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 1);
  636. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 1);
  637. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
  638. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  639. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  640. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
  641. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
  642. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
  643. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  644. rt2500usb_register_read(rt2x00dev, TXRX_CSR5, &reg);
  645. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0, 13);
  646. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0_VALID, 1);
  647. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1, 12);
  648. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1_VALID, 1);
  649. rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
  650. rt2500usb_register_read(rt2x00dev, TXRX_CSR6, &reg);
  651. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0, 10);
  652. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0_VALID, 1);
  653. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1, 11);
  654. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1_VALID, 1);
  655. rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
  656. rt2500usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
  657. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0, 7);
  658. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0_VALID, 1);
  659. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1, 6);
  660. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1_VALID, 1);
  661. rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
  662. rt2500usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
  663. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0, 5);
  664. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0_VALID, 1);
  665. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1, 0);
  666. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1_VALID, 0);
  667. rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
  668. rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
  669. rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
  670. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  671. return -EBUSY;
  672. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  673. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
  674. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
  675. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 1);
  676. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  677. if (rt2x00_rev(&rt2x00dev->chip) >= RT2570_VERSION_C) {
  678. rt2500usb_register_read(rt2x00dev, PHY_CSR2, &reg);
  679. rt2x00_set_field16(&reg, PHY_CSR2_LNA, 0);
  680. } else {
  681. reg = 0;
  682. rt2x00_set_field16(&reg, PHY_CSR2_LNA, 1);
  683. rt2x00_set_field16(&reg, PHY_CSR2_LNA_MODE, 3);
  684. }
  685. rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
  686. rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
  687. rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
  688. rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
  689. rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
  690. rt2500usb_register_read(rt2x00dev, MAC_CSR8, &reg);
  691. rt2x00_set_field16(&reg, MAC_CSR8_MAX_FRAME_UNIT,
  692. rt2x00dev->rx->data_size);
  693. rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
  694. rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  695. rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
  696. rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, 0xff);
  697. rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  698. rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
  699. rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON, 90);
  700. rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
  701. rt2500usb_register_read(rt2x00dev, PHY_CSR4, &reg);
  702. rt2x00_set_field16(&reg, PHY_CSR4_LOW_RF_LE, 1);
  703. rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
  704. rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  705. rt2x00_set_field16(&reg, TXRX_CSR1_AUTO_SEQUENCE, 1);
  706. rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  707. return 0;
  708. }
  709. static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  710. {
  711. unsigned int i;
  712. u16 eeprom;
  713. u8 value;
  714. u8 reg_id;
  715. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  716. rt2500usb_bbp_read(rt2x00dev, 0, &value);
  717. if ((value != 0xff) && (value != 0x00))
  718. goto continue_csr_init;
  719. NOTICE(rt2x00dev, "Waiting for BBP register.\n");
  720. udelay(REGISTER_BUSY_DELAY);
  721. }
  722. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  723. return -EACCES;
  724. continue_csr_init:
  725. rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
  726. rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
  727. rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
  728. rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
  729. rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
  730. rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
  731. rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
  732. rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
  733. rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
  734. rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
  735. rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
  736. rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
  737. rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
  738. rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
  739. rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
  740. rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
  741. rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
  742. rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
  743. rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
  744. rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
  745. rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
  746. rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
  747. rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
  748. rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
  749. rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
  750. rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
  751. rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
  752. rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
  753. rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
  754. rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
  755. rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
  756. DEBUG(rt2x00dev, "Start initialization from EEPROM...\n");
  757. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  758. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  759. if (eeprom != 0xffff && eeprom != 0x0000) {
  760. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  761. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  762. DEBUG(rt2x00dev, "BBP: 0x%02x, value: 0x%02x.\n",
  763. reg_id, value);
  764. rt2500usb_bbp_write(rt2x00dev, reg_id, value);
  765. }
  766. }
  767. DEBUG(rt2x00dev, "...End initialization from EEPROM.\n");
  768. return 0;
  769. }
  770. /*
  771. * Device state switch handlers.
  772. */
  773. static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  774. enum dev_state state)
  775. {
  776. u16 reg;
  777. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  778. rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX,
  779. state == STATE_RADIO_RX_OFF);
  780. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  781. }
  782. static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  783. {
  784. /*
  785. * Initialize all registers.
  786. */
  787. if (rt2500usb_init_registers(rt2x00dev) ||
  788. rt2500usb_init_bbp(rt2x00dev)) {
  789. ERROR(rt2x00dev, "Register initialization failed.\n");
  790. return -EIO;
  791. }
  792. /*
  793. * Enable LED
  794. */
  795. rt2500usb_enable_led(rt2x00dev);
  796. return 0;
  797. }
  798. static void rt2500usb_disable_radio(struct rt2x00_dev *rt2x00dev)
  799. {
  800. /*
  801. * Disable LED
  802. */
  803. rt2500usb_disable_led(rt2x00dev);
  804. rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x2121);
  805. rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x2121);
  806. /*
  807. * Disable synchronisation.
  808. */
  809. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
  810. rt2x00usb_disable_radio(rt2x00dev);
  811. }
  812. static int rt2500usb_set_state(struct rt2x00_dev *rt2x00dev,
  813. enum dev_state state)
  814. {
  815. u16 reg;
  816. u16 reg2;
  817. unsigned int i;
  818. char put_to_sleep;
  819. char bbp_state;
  820. char rf_state;
  821. put_to_sleep = (state != STATE_AWAKE);
  822. reg = 0;
  823. rt2x00_set_field16(&reg, MAC_CSR17_BBP_DESIRE_STATE, state);
  824. rt2x00_set_field16(&reg, MAC_CSR17_RF_DESIRE_STATE, state);
  825. rt2x00_set_field16(&reg, MAC_CSR17_PUT_TO_SLEEP, put_to_sleep);
  826. rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
  827. rt2x00_set_field16(&reg, MAC_CSR17_SET_STATE, 1);
  828. rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
  829. /*
  830. * Device is not guaranteed to be in the requested state yet.
  831. * We must wait until the register indicates that the
  832. * device has entered the correct state.
  833. */
  834. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  835. rt2500usb_register_read(rt2x00dev, MAC_CSR17, &reg2);
  836. bbp_state = rt2x00_get_field16(reg2, MAC_CSR17_BBP_CURR_STATE);
  837. rf_state = rt2x00_get_field16(reg2, MAC_CSR17_RF_CURR_STATE);
  838. if (bbp_state == state && rf_state == state)
  839. return 0;
  840. rt2500usb_register_write(rt2x00dev, MAC_CSR17, reg);
  841. msleep(30);
  842. }
  843. NOTICE(rt2x00dev, "Device failed to enter state %d, "
  844. "current device state: bbp %d and rf %d.\n",
  845. state, bbp_state, rf_state);
  846. return -EBUSY;
  847. }
  848. static int rt2500usb_set_device_state(struct rt2x00_dev *rt2x00dev,
  849. enum dev_state state)
  850. {
  851. int retval = 0;
  852. switch (state) {
  853. case STATE_RADIO_ON:
  854. retval = rt2500usb_enable_radio(rt2x00dev);
  855. break;
  856. case STATE_RADIO_OFF:
  857. rt2500usb_disable_radio(rt2x00dev);
  858. break;
  859. case STATE_RADIO_RX_ON:
  860. case STATE_RADIO_RX_OFF:
  861. rt2500usb_toggle_rx(rt2x00dev, state);
  862. break;
  863. case STATE_DEEP_SLEEP:
  864. case STATE_SLEEP:
  865. case STATE_STANDBY:
  866. case STATE_AWAKE:
  867. retval = rt2500usb_set_state(rt2x00dev, state);
  868. break;
  869. default:
  870. retval = -ENOTSUPP;
  871. break;
  872. }
  873. return retval;
  874. }
  875. /*
  876. * TX descriptor initialization
  877. */
  878. static void rt2500usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
  879. struct sk_buff *skb,
  880. struct txdata_entry_desc *desc,
  881. struct ieee80211_tx_control *control)
  882. {
  883. struct skb_desc *skbdesc = get_skb_desc(skb);
  884. __le32 *txd = skbdesc->desc;
  885. u32 word;
  886. /*
  887. * Start writing the descriptor words.
  888. */
  889. rt2x00_desc_read(txd, 1, &word);
  890. rt2x00_set_field32(&word, TXD_W1_IV_OFFSET, IEEE80211_HEADER);
  891. rt2x00_set_field32(&word, TXD_W1_AIFS, desc->aifs);
  892. rt2x00_set_field32(&word, TXD_W1_CWMIN, desc->cw_min);
  893. rt2x00_set_field32(&word, TXD_W1_CWMAX, desc->cw_max);
  894. rt2x00_desc_write(txd, 1, word);
  895. rt2x00_desc_read(txd, 2, &word);
  896. rt2x00_set_field32(&word, TXD_W2_PLCP_SIGNAL, desc->signal);
  897. rt2x00_set_field32(&word, TXD_W2_PLCP_SERVICE, desc->service);
  898. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_LOW, desc->length_low);
  899. rt2x00_set_field32(&word, TXD_W2_PLCP_LENGTH_HIGH, desc->length_high);
  900. rt2x00_desc_write(txd, 2, word);
  901. rt2x00_desc_read(txd, 0, &word);
  902. rt2x00_set_field32(&word, TXD_W0_RETRY_LIMIT, control->retry_limit);
  903. rt2x00_set_field32(&word, TXD_W0_MORE_FRAG,
  904. test_bit(ENTRY_TXD_MORE_FRAG, &desc->flags));
  905. rt2x00_set_field32(&word, TXD_W0_ACK,
  906. test_bit(ENTRY_TXD_ACK, &desc->flags));
  907. rt2x00_set_field32(&word, TXD_W0_TIMESTAMP,
  908. test_bit(ENTRY_TXD_REQ_TIMESTAMP, &desc->flags));
  909. rt2x00_set_field32(&word, TXD_W0_OFDM,
  910. test_bit(ENTRY_TXD_OFDM_RATE, &desc->flags));
  911. rt2x00_set_field32(&word, TXD_W0_NEW_SEQ,
  912. !!(control->flags & IEEE80211_TXCTL_FIRST_FRAGMENT));
  913. rt2x00_set_field32(&word, TXD_W0_IFS, desc->ifs);
  914. rt2x00_set_field32(&word, TXD_W0_DATABYTE_COUNT, skbdesc->data_len);
  915. rt2x00_set_field32(&word, TXD_W0_CIPHER, CIPHER_NONE);
  916. rt2x00_desc_write(txd, 0, word);
  917. }
  918. static int rt2500usb_get_tx_data_len(struct rt2x00_dev *rt2x00dev,
  919. struct sk_buff *skb)
  920. {
  921. int length;
  922. /*
  923. * The length _must_ be a multiple of 2,
  924. * but it must _not_ be a multiple of the USB packet size.
  925. */
  926. length = roundup(skb->len, 2);
  927. length += (2 * !(length % rt2x00dev->usb_maxpacket));
  928. return length;
  929. }
  930. /*
  931. * TX data initialization
  932. */
  933. static void rt2500usb_kick_tx_queue(struct rt2x00_dev *rt2x00dev,
  934. unsigned int queue)
  935. {
  936. u16 reg;
  937. if (queue != IEEE80211_TX_QUEUE_BEACON)
  938. return;
  939. rt2500usb_register_read(rt2x00dev, TXRX_CSR19, &reg);
  940. if (!rt2x00_get_field16(reg, TXRX_CSR19_BEACON_GEN)) {
  941. rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 1);
  942. /*
  943. * Beacon generation will fail initially.
  944. * To prevent this we need to register the TXRX_CSR19
  945. * register several times.
  946. */
  947. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  948. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
  949. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  950. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, 0);
  951. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  952. }
  953. }
  954. /*
  955. * RX control handlers
  956. */
  957. static void rt2500usb_fill_rxdone(struct data_entry *entry,
  958. struct rxdata_entry_desc *desc)
  959. {
  960. struct skb_desc *skbdesc = get_skb_desc(entry->skb);
  961. struct urb *urb = entry->priv;
  962. __le32 *rxd = (__le32 *)(entry->skb->data +
  963. (urb->actual_length - entry->ring->desc_size));
  964. u32 word0;
  965. u32 word1;
  966. rt2x00_desc_read(rxd, 0, &word0);
  967. rt2x00_desc_read(rxd, 1, &word1);
  968. desc->flags = 0;
  969. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  970. desc->flags |= RX_FLAG_FAILED_FCS_CRC;
  971. if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
  972. desc->flags |= RX_FLAG_FAILED_PLCP_CRC;
  973. /*
  974. * Obtain the status about this packet.
  975. */
  976. desc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  977. desc->rssi = rt2x00_get_field32(word1, RXD_W1_RSSI) -
  978. entry->ring->rt2x00dev->rssi_offset;
  979. desc->ofdm = rt2x00_get_field32(word0, RXD_W0_OFDM);
  980. desc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  981. desc->my_bss = !!rt2x00_get_field32(word0, RXD_W0_MY_BSS);
  982. /*
  983. * Set descriptor and data pointer.
  984. */
  985. skbdesc->desc = entry->skb->data + desc->size;
  986. skbdesc->desc_len = entry->ring->desc_size;
  987. skbdesc->data = entry->skb->data;
  988. skbdesc->data_len = desc->size;
  989. }
  990. /*
  991. * Interrupt functions.
  992. */
  993. static void rt2500usb_beacondone(struct urb *urb)
  994. {
  995. struct data_entry *entry = (struct data_entry *)urb->context;
  996. struct data_ring *ring = entry->ring;
  997. if (!test_bit(DEVICE_ENABLED_RADIO, &ring->rt2x00dev->flags))
  998. return;
  999. /*
  1000. * Check if this was the guardian beacon,
  1001. * if that was the case we need to send the real beacon now.
  1002. * Otherwise we should free the sk_buffer, the device
  1003. * should be doing the rest of the work now.
  1004. */
  1005. if (ring->index == 1) {
  1006. rt2x00_ring_index_done_inc(ring);
  1007. entry = rt2x00_get_data_entry(ring);
  1008. usb_submit_urb(entry->priv, GFP_ATOMIC);
  1009. rt2x00_ring_index_inc(ring);
  1010. } else if (ring->index_done == 1) {
  1011. entry = rt2x00_get_data_entry_done(ring);
  1012. if (entry->skb) {
  1013. dev_kfree_skb(entry->skb);
  1014. entry->skb = NULL;
  1015. }
  1016. rt2x00_ring_index_done_inc(ring);
  1017. }
  1018. }
  1019. /*
  1020. * Device probe functions.
  1021. */
  1022. static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1023. {
  1024. u16 word;
  1025. u8 *mac;
  1026. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1027. /*
  1028. * Start validation of the data that has been read.
  1029. */
  1030. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1031. if (!is_valid_ether_addr(mac)) {
  1032. DECLARE_MAC_BUF(macbuf);
  1033. random_ether_addr(mac);
  1034. EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
  1035. }
  1036. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1037. if (word == 0xffff) {
  1038. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1039. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1040. ANTENNA_SW_DIVERSITY);
  1041. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1042. ANTENNA_SW_DIVERSITY);
  1043. rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
  1044. LED_MODE_DEFAULT);
  1045. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1046. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1047. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
  1048. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1049. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1050. }
  1051. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1052. if (word == 0xffff) {
  1053. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1054. rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
  1055. rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
  1056. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1057. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1058. }
  1059. rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
  1060. if (word == 0xffff) {
  1061. rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
  1062. DEFAULT_RSSI_OFFSET);
  1063. rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
  1064. EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
  1065. }
  1066. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
  1067. if (word == 0xffff) {
  1068. rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
  1069. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
  1070. EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
  1071. }
  1072. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
  1073. if (word == 0xffff) {
  1074. rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
  1075. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
  1076. EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
  1077. }
  1078. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
  1079. if (word == 0xffff) {
  1080. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
  1081. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
  1082. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
  1083. EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
  1084. }
  1085. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
  1086. if (word == 0xffff) {
  1087. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
  1088. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
  1089. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
  1090. EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
  1091. }
  1092. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
  1093. if (word == 0xffff) {
  1094. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
  1095. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
  1096. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
  1097. EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
  1098. }
  1099. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
  1100. if (word == 0xffff) {
  1101. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
  1102. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
  1103. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
  1104. EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
  1105. }
  1106. return 0;
  1107. }
  1108. static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1109. {
  1110. u16 reg;
  1111. u16 value;
  1112. u16 eeprom;
  1113. /*
  1114. * Read EEPROM word for configuration.
  1115. */
  1116. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1117. /*
  1118. * Identify RF chipset.
  1119. */
  1120. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1121. rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1122. rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
  1123. if (!rt2x00_check_rev(&rt2x00dev->chip, 0)) {
  1124. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1125. return -ENODEV;
  1126. }
  1127. if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
  1128. !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
  1129. !rt2x00_rf(&rt2x00dev->chip, RF2524) &&
  1130. !rt2x00_rf(&rt2x00dev->chip, RF2525) &&
  1131. !rt2x00_rf(&rt2x00dev->chip, RF2525E) &&
  1132. !rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  1133. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1134. return -ENODEV;
  1135. }
  1136. /*
  1137. * Identify default antenna configuration.
  1138. */
  1139. rt2x00dev->default_ant.tx =
  1140. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1141. rt2x00dev->default_ant.rx =
  1142. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1143. /*
  1144. * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
  1145. * I am not 100% sure about this, but the legacy drivers do not
  1146. * indicate antenna swapping in software is required when
  1147. * diversity is enabled.
  1148. */
  1149. if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
  1150. rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
  1151. if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
  1152. rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
  1153. /*
  1154. * Store led mode, for correct led behaviour.
  1155. */
  1156. rt2x00dev->led_mode =
  1157. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
  1158. /*
  1159. * Check if the BBP tuning should be disabled.
  1160. */
  1161. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1162. if (rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE))
  1163. __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
  1164. /*
  1165. * Read the RSSI <-> dBm offset information.
  1166. */
  1167. rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
  1168. rt2x00dev->rssi_offset =
  1169. rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
  1170. return 0;
  1171. }
  1172. /*
  1173. * RF value list for RF2522
  1174. * Supports: 2.4 GHz
  1175. */
  1176. static const struct rf_channel rf_vals_bg_2522[] = {
  1177. { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
  1178. { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
  1179. { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
  1180. { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
  1181. { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
  1182. { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
  1183. { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
  1184. { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
  1185. { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
  1186. { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
  1187. { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
  1188. { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
  1189. { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
  1190. { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
  1191. };
  1192. /*
  1193. * RF value list for RF2523
  1194. * Supports: 2.4 GHz
  1195. */
  1196. static const struct rf_channel rf_vals_bg_2523[] = {
  1197. { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
  1198. { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
  1199. { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
  1200. { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
  1201. { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
  1202. { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
  1203. { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
  1204. { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
  1205. { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
  1206. { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
  1207. { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
  1208. { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
  1209. { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
  1210. { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
  1211. };
  1212. /*
  1213. * RF value list for RF2524
  1214. * Supports: 2.4 GHz
  1215. */
  1216. static const struct rf_channel rf_vals_bg_2524[] = {
  1217. { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
  1218. { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
  1219. { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
  1220. { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
  1221. { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
  1222. { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
  1223. { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
  1224. { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
  1225. { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
  1226. { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
  1227. { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
  1228. { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
  1229. { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
  1230. { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
  1231. };
  1232. /*
  1233. * RF value list for RF2525
  1234. * Supports: 2.4 GHz
  1235. */
  1236. static const struct rf_channel rf_vals_bg_2525[] = {
  1237. { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
  1238. { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
  1239. { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
  1240. { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
  1241. { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
  1242. { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
  1243. { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
  1244. { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
  1245. { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
  1246. { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
  1247. { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
  1248. { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
  1249. { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
  1250. { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
  1251. };
  1252. /*
  1253. * RF value list for RF2525e
  1254. * Supports: 2.4 GHz
  1255. */
  1256. static const struct rf_channel rf_vals_bg_2525e[] = {
  1257. { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
  1258. { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
  1259. { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
  1260. { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
  1261. { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
  1262. { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
  1263. { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
  1264. { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
  1265. { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
  1266. { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
  1267. { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
  1268. { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
  1269. { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
  1270. { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
  1271. };
  1272. /*
  1273. * RF value list for RF5222
  1274. * Supports: 2.4 GHz & 5.2 GHz
  1275. */
  1276. static const struct rf_channel rf_vals_5222[] = {
  1277. { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
  1278. { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
  1279. { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
  1280. { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
  1281. { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
  1282. { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
  1283. { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
  1284. { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
  1285. { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
  1286. { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
  1287. { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
  1288. { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
  1289. { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
  1290. { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
  1291. /* 802.11 UNI / HyperLan 2 */
  1292. { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
  1293. { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
  1294. { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
  1295. { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
  1296. { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
  1297. { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
  1298. { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
  1299. { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
  1300. /* 802.11 HyperLan 2 */
  1301. { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
  1302. { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
  1303. { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
  1304. { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
  1305. { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
  1306. { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
  1307. { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
  1308. { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
  1309. { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
  1310. { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
  1311. /* 802.11 UNII */
  1312. { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
  1313. { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
  1314. { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
  1315. { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
  1316. { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
  1317. };
  1318. static void rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1319. {
  1320. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1321. u8 *txpower;
  1322. unsigned int i;
  1323. /*
  1324. * Initialize all hw fields.
  1325. */
  1326. rt2x00dev->hw->flags =
  1327. IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE |
  1328. IEEE80211_HW_RX_INCLUDES_FCS |
  1329. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
  1330. rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
  1331. rt2x00dev->hw->max_signal = MAX_SIGNAL;
  1332. rt2x00dev->hw->max_rssi = MAX_RX_SSI;
  1333. rt2x00dev->hw->queues = 2;
  1334. SET_IEEE80211_DEV(rt2x00dev->hw, &rt2x00dev_usb(rt2x00dev)->dev);
  1335. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1336. rt2x00_eeprom_addr(rt2x00dev,
  1337. EEPROM_MAC_ADDR_0));
  1338. /*
  1339. * Convert tx_power array in eeprom.
  1340. */
  1341. txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
  1342. for (i = 0; i < 14; i++)
  1343. txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
  1344. /*
  1345. * Initialize hw_mode information.
  1346. */
  1347. spec->num_modes = 2;
  1348. spec->num_rates = 12;
  1349. spec->tx_power_a = NULL;
  1350. spec->tx_power_bg = txpower;
  1351. spec->tx_power_default = DEFAULT_TXPOWER;
  1352. if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
  1353. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
  1354. spec->channels = rf_vals_bg_2522;
  1355. } else if (rt2x00_rf(&rt2x00dev->chip, RF2523)) {
  1356. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
  1357. spec->channels = rf_vals_bg_2523;
  1358. } else if (rt2x00_rf(&rt2x00dev->chip, RF2524)) {
  1359. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
  1360. spec->channels = rf_vals_bg_2524;
  1361. } else if (rt2x00_rf(&rt2x00dev->chip, RF2525)) {
  1362. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
  1363. spec->channels = rf_vals_bg_2525;
  1364. } else if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
  1365. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
  1366. spec->channels = rf_vals_bg_2525e;
  1367. } else if (rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  1368. spec->num_channels = ARRAY_SIZE(rf_vals_5222);
  1369. spec->channels = rf_vals_5222;
  1370. spec->num_modes = 3;
  1371. }
  1372. }
  1373. static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1374. {
  1375. int retval;
  1376. /*
  1377. * Allocate eeprom data.
  1378. */
  1379. retval = rt2500usb_validate_eeprom(rt2x00dev);
  1380. if (retval)
  1381. return retval;
  1382. retval = rt2500usb_init_eeprom(rt2x00dev);
  1383. if (retval)
  1384. return retval;
  1385. /*
  1386. * Initialize hw specifications.
  1387. */
  1388. rt2500usb_probe_hw_mode(rt2x00dev);
  1389. /*
  1390. * This device requires the beacon ring
  1391. */
  1392. __set_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags);
  1393. /*
  1394. * Set the rssi offset.
  1395. */
  1396. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1397. return 0;
  1398. }
  1399. /*
  1400. * IEEE80211 stack callback functions.
  1401. */
  1402. static void rt2500usb_configure_filter(struct ieee80211_hw *hw,
  1403. unsigned int changed_flags,
  1404. unsigned int *total_flags,
  1405. int mc_count,
  1406. struct dev_addr_list *mc_list)
  1407. {
  1408. struct rt2x00_dev *rt2x00dev = hw->priv;
  1409. u16 reg;
  1410. /*
  1411. * Mask off any flags we are going to ignore from
  1412. * the total_flags field.
  1413. */
  1414. *total_flags &=
  1415. FIF_ALLMULTI |
  1416. FIF_FCSFAIL |
  1417. FIF_PLCPFAIL |
  1418. FIF_CONTROL |
  1419. FIF_OTHER_BSS |
  1420. FIF_PROMISC_IN_BSS;
  1421. /*
  1422. * Apply some rules to the filters:
  1423. * - Some filters imply different filters to be set.
  1424. * - Some things we can't filter out at all.
  1425. */
  1426. if (mc_count)
  1427. *total_flags |= FIF_ALLMULTI;
  1428. if (*total_flags & FIF_OTHER_BSS ||
  1429. *total_flags & FIF_PROMISC_IN_BSS)
  1430. *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
  1431. /*
  1432. * Check if there is any work left for us.
  1433. */
  1434. if (rt2x00dev->packet_filter == *total_flags)
  1435. return;
  1436. rt2x00dev->packet_filter = *total_flags;
  1437. /*
  1438. * When in atomic context, reschedule and let rt2x00lib
  1439. * call this function again.
  1440. */
  1441. if (in_atomic()) {
  1442. queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->filter_work);
  1443. return;
  1444. }
  1445. /*
  1446. * Start configuration steps.
  1447. * Note that the version error will always be dropped
  1448. * and broadcast frames will always be accepted since
  1449. * there is no filter for it at this time.
  1450. */
  1451. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  1452. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CRC,
  1453. !(*total_flags & FIF_FCSFAIL));
  1454. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_PHYSICAL,
  1455. !(*total_flags & FIF_PLCPFAIL));
  1456. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CONTROL,
  1457. !(*total_flags & FIF_CONTROL));
  1458. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_NOT_TO_ME,
  1459. !(*total_flags & FIF_PROMISC_IN_BSS));
  1460. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_TODS,
  1461. !(*total_flags & FIF_PROMISC_IN_BSS));
  1462. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_VERSION_ERROR, 1);
  1463. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_MULTICAST,
  1464. !(*total_flags & FIF_ALLMULTI));
  1465. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_BROADCAST, 0);
  1466. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  1467. }
  1468. static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
  1469. struct sk_buff *skb,
  1470. struct ieee80211_tx_control *control)
  1471. {
  1472. struct rt2x00_dev *rt2x00dev = hw->priv;
  1473. struct usb_device *usb_dev =
  1474. interface_to_usbdev(rt2x00dev_usb(rt2x00dev));
  1475. struct skb_desc *desc;
  1476. struct data_ring *ring;
  1477. struct data_entry *beacon;
  1478. struct data_entry *guardian;
  1479. int pipe = usb_sndbulkpipe(usb_dev, 1);
  1480. int length;
  1481. /*
  1482. * Just in case the ieee80211 doesn't set this,
  1483. * but we need this queue set for the descriptor
  1484. * initialization.
  1485. */
  1486. control->queue = IEEE80211_TX_QUEUE_BEACON;
  1487. ring = rt2x00lib_get_ring(rt2x00dev, control->queue);
  1488. /*
  1489. * Obtain 2 entries, one for the guardian byte,
  1490. * the second for the actual beacon.
  1491. */
  1492. guardian = rt2x00_get_data_entry(ring);
  1493. rt2x00_ring_index_inc(ring);
  1494. beacon = rt2x00_get_data_entry(ring);
  1495. /*
  1496. * Add the descriptor in front of the skb.
  1497. */
  1498. skb_push(skb, ring->desc_size);
  1499. memset(skb->data, 0, ring->desc_size);
  1500. /*
  1501. * Fill in skb descriptor
  1502. */
  1503. desc = get_skb_desc(skb);
  1504. desc->desc_len = ring->desc_size;
  1505. desc->data_len = skb->len - ring->desc_size;
  1506. desc->desc = skb->data;
  1507. desc->data = skb->data + ring->desc_size;
  1508. desc->ring = ring;
  1509. desc->entry = beacon;
  1510. rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
  1511. /*
  1512. * USB devices cannot blindly pass the skb->len as the
  1513. * length of the data to usb_fill_bulk_urb. Pass the skb
  1514. * to the driver to determine what the length should be.
  1515. */
  1516. length = rt2500usb_get_tx_data_len(rt2x00dev, skb);
  1517. usb_fill_bulk_urb(beacon->priv, usb_dev, pipe,
  1518. skb->data, length, rt2500usb_beacondone, beacon);
  1519. /*
  1520. * Second we need to create the guardian byte.
  1521. * We only need a single byte, so lets recycle
  1522. * the 'flags' field we are not using for beacons.
  1523. */
  1524. guardian->flags = 0;
  1525. usb_fill_bulk_urb(guardian->priv, usb_dev, pipe,
  1526. &guardian->flags, 1, rt2500usb_beacondone, guardian);
  1527. /*
  1528. * Send out the guardian byte.
  1529. */
  1530. usb_submit_urb(guardian->priv, GFP_ATOMIC);
  1531. /*
  1532. * Enable beacon generation.
  1533. */
  1534. rt2500usb_kick_tx_queue(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
  1535. return 0;
  1536. }
  1537. static const struct ieee80211_ops rt2500usb_mac80211_ops = {
  1538. .tx = rt2x00mac_tx,
  1539. .start = rt2x00mac_start,
  1540. .stop = rt2x00mac_stop,
  1541. .add_interface = rt2x00mac_add_interface,
  1542. .remove_interface = rt2x00mac_remove_interface,
  1543. .config = rt2x00mac_config,
  1544. .config_interface = rt2x00mac_config_interface,
  1545. .configure_filter = rt2500usb_configure_filter,
  1546. .get_stats = rt2x00mac_get_stats,
  1547. .bss_info_changed = rt2x00mac_bss_info_changed,
  1548. .conf_tx = rt2x00mac_conf_tx,
  1549. .get_tx_stats = rt2x00mac_get_tx_stats,
  1550. .beacon_update = rt2500usb_beacon_update,
  1551. };
  1552. static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
  1553. .probe_hw = rt2500usb_probe_hw,
  1554. .initialize = rt2x00usb_initialize,
  1555. .uninitialize = rt2x00usb_uninitialize,
  1556. .init_rxentry = rt2x00usb_init_rxentry,
  1557. .init_txentry = rt2x00usb_init_txentry,
  1558. .set_device_state = rt2500usb_set_device_state,
  1559. .link_stats = rt2500usb_link_stats,
  1560. .reset_tuner = rt2500usb_reset_tuner,
  1561. .link_tuner = rt2500usb_link_tuner,
  1562. .write_tx_desc = rt2500usb_write_tx_desc,
  1563. .write_tx_data = rt2x00usb_write_tx_data,
  1564. .get_tx_data_len = rt2500usb_get_tx_data_len,
  1565. .kick_tx_queue = rt2500usb_kick_tx_queue,
  1566. .fill_rxdone = rt2500usb_fill_rxdone,
  1567. .config_mac_addr = rt2500usb_config_mac_addr,
  1568. .config_bssid = rt2500usb_config_bssid,
  1569. .config_type = rt2500usb_config_type,
  1570. .config_preamble = rt2500usb_config_preamble,
  1571. .config = rt2500usb_config,
  1572. };
  1573. static const struct rt2x00_ops rt2500usb_ops = {
  1574. .name = KBUILD_MODNAME,
  1575. .rxd_size = RXD_DESC_SIZE,
  1576. .txd_size = TXD_DESC_SIZE,
  1577. .eeprom_size = EEPROM_SIZE,
  1578. .rf_size = RF_SIZE,
  1579. .lib = &rt2500usb_rt2x00_ops,
  1580. .hw = &rt2500usb_mac80211_ops,
  1581. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1582. .debugfs = &rt2500usb_rt2x00debug,
  1583. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1584. };
  1585. /*
  1586. * rt2500usb module information.
  1587. */
  1588. static struct usb_device_id rt2500usb_device_table[] = {
  1589. /* ASUS */
  1590. { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
  1591. { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
  1592. /* Belkin */
  1593. { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
  1594. { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
  1595. { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
  1596. /* Cisco Systems */
  1597. { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
  1598. { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
  1599. { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
  1600. /* Conceptronic */
  1601. { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
  1602. /* D-LINK */
  1603. { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
  1604. /* Gigabyte */
  1605. { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
  1606. { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
  1607. /* Hercules */
  1608. { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
  1609. /* Melco */
  1610. { USB_DEVICE(0x0411, 0x005e), USB_DEVICE_DATA(&rt2500usb_ops) },
  1611. { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
  1612. { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
  1613. { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
  1614. { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
  1615. /* MSI */
  1616. { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
  1617. { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
  1618. { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
  1619. /* Ralink */
  1620. { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
  1621. { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
  1622. { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
  1623. { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
  1624. /* Siemens */
  1625. { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
  1626. /* SMC */
  1627. { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
  1628. /* Spairon */
  1629. { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
  1630. /* Trust */
  1631. { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
  1632. /* Zinwell */
  1633. { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
  1634. { 0, }
  1635. };
  1636. MODULE_AUTHOR(DRV_PROJECT);
  1637. MODULE_VERSION(DRV_VERSION);
  1638. MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
  1639. MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
  1640. MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
  1641. MODULE_LICENSE("GPL");
  1642. static struct usb_driver rt2500usb_driver = {
  1643. .name = KBUILD_MODNAME,
  1644. .id_table = rt2500usb_device_table,
  1645. .probe = rt2x00usb_probe,
  1646. .disconnect = rt2x00usb_disconnect,
  1647. .suspend = rt2x00usb_suspend,
  1648. .resume = rt2x00usb_resume,
  1649. };
  1650. static int __init rt2500usb_init(void)
  1651. {
  1652. return usb_register(&rt2500usb_driver);
  1653. }
  1654. static void __exit rt2500usb_exit(void)
  1655. {
  1656. usb_deregister(&rt2500usb_driver);
  1657. }
  1658. module_init(rt2500usb_init);
  1659. module_exit(rt2500usb_exit);