rt2500usb.c 57 KB

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