rt2500usb.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891
  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, 1);
  282. rt2x00_set_field16(&reg, TXRX_CSR19_BEACON_GEN, 0);
  283. rt2x00_set_field16(&reg, TXRX_CSR19_TSF_SYNC, tsf_sync);
  284. rt2500usb_register_write(rt2x00dev, TXRX_CSR19, reg);
  285. }
  286. static void rt2500usb_config_preamble(struct rt2x00_dev *rt2x00dev,
  287. const int short_preamble,
  288. const int ack_timeout,
  289. const int ack_consume_time)
  290. {
  291. u16 reg;
  292. /*
  293. * When in atomic context, reschedule and let rt2x00lib
  294. * call this function again.
  295. */
  296. if (in_atomic()) {
  297. queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->config_work);
  298. return;
  299. }
  300. rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  301. rt2x00_set_field16(&reg, TXRX_CSR1_ACK_TIMEOUT, ack_timeout);
  302. rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  303. rt2500usb_register_read(rt2x00dev, TXRX_CSR10, &reg);
  304. rt2x00_set_field16(&reg, TXRX_CSR10_AUTORESPOND_PREAMBLE,
  305. !!short_preamble);
  306. rt2500usb_register_write(rt2x00dev, TXRX_CSR10, reg);
  307. }
  308. static void rt2500usb_config_phymode(struct rt2x00_dev *rt2x00dev,
  309. const int phymode,
  310. const int basic_rate_mask)
  311. {
  312. rt2500usb_register_write(rt2x00dev, TXRX_CSR11, basic_rate_mask);
  313. if (phymode == HWMODE_B) {
  314. rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x000b);
  315. rt2500usb_register_write(rt2x00dev, MAC_CSR12, 0x0040);
  316. } else {
  317. rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0005);
  318. rt2500usb_register_write(rt2x00dev, MAC_CSR12, 0x016c);
  319. }
  320. }
  321. static void rt2500usb_config_channel(struct rt2x00_dev *rt2x00dev,
  322. struct rf_channel *rf, const int txpower)
  323. {
  324. /*
  325. * Set TXpower.
  326. */
  327. rt2x00_set_field32(&rf->rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  328. /*
  329. * For RT2525E we should first set the channel to half band higher.
  330. */
  331. if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
  332. static const u32 vals[] = {
  333. 0x000008aa, 0x000008ae, 0x000008ae, 0x000008b2,
  334. 0x000008b2, 0x000008b6, 0x000008b6, 0x000008ba,
  335. 0x000008ba, 0x000008be, 0x000008b7, 0x00000902,
  336. 0x00000902, 0x00000906
  337. };
  338. rt2500usb_rf_write(rt2x00dev, 2, vals[rf->channel - 1]);
  339. if (rf->rf4)
  340. rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
  341. }
  342. rt2500usb_rf_write(rt2x00dev, 1, rf->rf1);
  343. rt2500usb_rf_write(rt2x00dev, 2, rf->rf2);
  344. rt2500usb_rf_write(rt2x00dev, 3, rf->rf3);
  345. if (rf->rf4)
  346. rt2500usb_rf_write(rt2x00dev, 4, rf->rf4);
  347. }
  348. static void rt2500usb_config_txpower(struct rt2x00_dev *rt2x00dev,
  349. const int txpower)
  350. {
  351. u32 rf3;
  352. rt2x00_rf_read(rt2x00dev, 3, &rf3);
  353. rt2x00_set_field32(&rf3, RF3_TXPOWER, TXPOWER_TO_DEV(txpower));
  354. rt2500usb_rf_write(rt2x00dev, 3, rf3);
  355. }
  356. static void rt2500usb_config_antenna(struct rt2x00_dev *rt2x00dev,
  357. struct antenna_setup *ant)
  358. {
  359. u8 r2;
  360. u8 r14;
  361. u16 csr5;
  362. u16 csr6;
  363. rt2500usb_bbp_read(rt2x00dev, 2, &r2);
  364. rt2500usb_bbp_read(rt2x00dev, 14, &r14);
  365. rt2500usb_register_read(rt2x00dev, PHY_CSR5, &csr5);
  366. rt2500usb_register_read(rt2x00dev, PHY_CSR6, &csr6);
  367. /*
  368. * Configure the TX antenna.
  369. */
  370. switch (ant->tx) {
  371. case ANTENNA_HW_DIVERSITY:
  372. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 1);
  373. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 1);
  374. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 1);
  375. break;
  376. case ANTENNA_A:
  377. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 0);
  378. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 0);
  379. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 0);
  380. break;
  381. case ANTENNA_SW_DIVERSITY:
  382. /*
  383. * NOTE: We should never come here because rt2x00lib is
  384. * supposed to catch this and send us the correct antenna
  385. * explicitely. However we are nog going to bug about this.
  386. * Instead, just default to antenna B.
  387. */
  388. case ANTENNA_B:
  389. rt2x00_set_field8(&r2, BBP_R2_TX_ANTENNA, 2);
  390. rt2x00_set_field16(&csr5, PHY_CSR5_CCK, 2);
  391. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM, 2);
  392. break;
  393. }
  394. /*
  395. * Configure the RX antenna.
  396. */
  397. switch (ant->rx) {
  398. case ANTENNA_HW_DIVERSITY:
  399. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 1);
  400. break;
  401. case ANTENNA_A:
  402. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 0);
  403. break;
  404. case ANTENNA_SW_DIVERSITY:
  405. /*
  406. * NOTE: We should never come here because rt2x00lib is
  407. * supposed to catch this and send us the correct antenna
  408. * explicitely. However we are nog going to bug about this.
  409. * Instead, just default to antenna B.
  410. */
  411. case ANTENNA_B:
  412. rt2x00_set_field8(&r14, BBP_R14_RX_ANTENNA, 2);
  413. break;
  414. }
  415. /*
  416. * RT2525E and RT5222 need to flip TX I/Q
  417. */
  418. if (rt2x00_rf(&rt2x00dev->chip, RF2525E) ||
  419. rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  420. rt2x00_set_field8(&r2, BBP_R2_TX_IQ_FLIP, 1);
  421. rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 1);
  422. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 1);
  423. /*
  424. * RT2525E does not need RX I/Q Flip.
  425. */
  426. if (rt2x00_rf(&rt2x00dev->chip, RF2525E))
  427. rt2x00_set_field8(&r14, BBP_R14_RX_IQ_FLIP, 0);
  428. } else {
  429. rt2x00_set_field16(&csr5, PHY_CSR5_CCK_FLIP, 0);
  430. rt2x00_set_field16(&csr6, PHY_CSR6_OFDM_FLIP, 0);
  431. }
  432. rt2500usb_bbp_write(rt2x00dev, 2, r2);
  433. rt2500usb_bbp_write(rt2x00dev, 14, r14);
  434. rt2500usb_register_write(rt2x00dev, PHY_CSR5, csr5);
  435. rt2500usb_register_write(rt2x00dev, PHY_CSR6, csr6);
  436. }
  437. static void rt2500usb_config_duration(struct rt2x00_dev *rt2x00dev,
  438. struct rt2x00lib_conf *libconf)
  439. {
  440. u16 reg;
  441. rt2500usb_register_write(rt2x00dev, MAC_CSR10, libconf->slot_time);
  442. rt2500usb_register_read(rt2x00dev, TXRX_CSR18, &reg);
  443. rt2x00_set_field16(&reg, TXRX_CSR18_INTERVAL,
  444. libconf->conf->beacon_int * 4);
  445. rt2500usb_register_write(rt2x00dev, TXRX_CSR18, reg);
  446. }
  447. static void rt2500usb_config(struct rt2x00_dev *rt2x00dev,
  448. const unsigned int flags,
  449. struct rt2x00lib_conf *libconf)
  450. {
  451. if (flags & CONFIG_UPDATE_PHYMODE)
  452. rt2500usb_config_phymode(rt2x00dev, libconf->phymode,
  453. libconf->basic_rates);
  454. if (flags & CONFIG_UPDATE_CHANNEL)
  455. rt2500usb_config_channel(rt2x00dev, &libconf->rf,
  456. libconf->conf->power_level);
  457. if ((flags & CONFIG_UPDATE_TXPOWER) && !(flags & CONFIG_UPDATE_CHANNEL))
  458. rt2500usb_config_txpower(rt2x00dev,
  459. libconf->conf->power_level);
  460. if (flags & CONFIG_UPDATE_ANTENNA)
  461. rt2500usb_config_antenna(rt2x00dev, &libconf->ant);
  462. if (flags & (CONFIG_UPDATE_SLOT_TIME | CONFIG_UPDATE_BEACON_INT))
  463. rt2500usb_config_duration(rt2x00dev, libconf);
  464. }
  465. /*
  466. * LED functions.
  467. */
  468. static void rt2500usb_enable_led(struct rt2x00_dev *rt2x00dev)
  469. {
  470. u16 reg;
  471. rt2500usb_register_read(rt2x00dev, MAC_CSR21, &reg);
  472. rt2x00_set_field16(&reg, MAC_CSR21_ON_PERIOD, 70);
  473. rt2x00_set_field16(&reg, MAC_CSR21_OFF_PERIOD, 30);
  474. rt2500usb_register_write(rt2x00dev, MAC_CSR21, reg);
  475. rt2500usb_register_read(rt2x00dev, MAC_CSR20, &reg);
  476. rt2x00_set_field16(&reg, MAC_CSR20_LINK,
  477. (rt2x00dev->led_mode != LED_MODE_ASUS));
  478. rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY,
  479. (rt2x00dev->led_mode != LED_MODE_TXRX_ACTIVITY));
  480. rt2500usb_register_write(rt2x00dev, MAC_CSR20, reg);
  481. }
  482. static void rt2500usb_disable_led(struct rt2x00_dev *rt2x00dev)
  483. {
  484. u16 reg;
  485. rt2500usb_register_read(rt2x00dev, MAC_CSR20, &reg);
  486. rt2x00_set_field16(&reg, MAC_CSR20_LINK, 0);
  487. rt2x00_set_field16(&reg, MAC_CSR20_ACTIVITY, 0);
  488. rt2500usb_register_write(rt2x00dev, MAC_CSR20, reg);
  489. }
  490. /*
  491. * Link tuning
  492. */
  493. static void rt2500usb_link_stats(struct rt2x00_dev *rt2x00dev,
  494. struct link_qual *qual)
  495. {
  496. u16 reg;
  497. /*
  498. * Update FCS error count from register.
  499. */
  500. rt2500usb_register_read(rt2x00dev, STA_CSR0, &reg);
  501. qual->rx_failed = rt2x00_get_field16(reg, STA_CSR0_FCS_ERROR);
  502. /*
  503. * Update False CCA count from register.
  504. */
  505. rt2500usb_register_read(rt2x00dev, STA_CSR3, &reg);
  506. qual->false_cca = rt2x00_get_field16(reg, STA_CSR3_FALSE_CCA_ERROR);
  507. }
  508. static void rt2500usb_reset_tuner(struct rt2x00_dev *rt2x00dev)
  509. {
  510. u16 eeprom;
  511. u16 value;
  512. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &eeprom);
  513. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R24_LOW);
  514. rt2500usb_bbp_write(rt2x00dev, 24, value);
  515. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &eeprom);
  516. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R25_LOW);
  517. rt2500usb_bbp_write(rt2x00dev, 25, value);
  518. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &eeprom);
  519. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_R61_LOW);
  520. rt2500usb_bbp_write(rt2x00dev, 61, value);
  521. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &eeprom);
  522. value = rt2x00_get_field16(eeprom, EEPROM_BBPTUNE_VGCUPPER);
  523. rt2500usb_bbp_write(rt2x00dev, 17, value);
  524. rt2x00dev->link.vgc_level = value;
  525. }
  526. static void rt2500usb_link_tuner(struct rt2x00_dev *rt2x00dev)
  527. {
  528. int rssi = rt2x00_get_link_rssi(&rt2x00dev->link);
  529. u16 bbp_thresh;
  530. u16 vgc_bound;
  531. u16 sens;
  532. u16 r24;
  533. u16 r25;
  534. u16 r61;
  535. u16 r17_sens;
  536. u8 r17;
  537. u8 up_bound;
  538. u8 low_bound;
  539. /*
  540. * Determine the BBP tuning threshold and correctly
  541. * set BBP 24, 25 and 61.
  542. */
  543. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &bbp_thresh);
  544. bbp_thresh = rt2x00_get_field16(bbp_thresh, EEPROM_BBPTUNE_THRESHOLD);
  545. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &r24);
  546. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &r25);
  547. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &r61);
  548. if ((rssi + bbp_thresh) > 0) {
  549. r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_HIGH);
  550. r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_HIGH);
  551. r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_HIGH);
  552. } else {
  553. r24 = rt2x00_get_field16(r24, EEPROM_BBPTUNE_R24_LOW);
  554. r25 = rt2x00_get_field16(r25, EEPROM_BBPTUNE_R25_LOW);
  555. r61 = rt2x00_get_field16(r61, EEPROM_BBPTUNE_R61_LOW);
  556. }
  557. rt2500usb_bbp_write(rt2x00dev, 24, r24);
  558. rt2500usb_bbp_write(rt2x00dev, 25, r25);
  559. rt2500usb_bbp_write(rt2x00dev, 61, r61);
  560. /*
  561. * Read current r17 value, as well as the sensitivity values
  562. * for the r17 register.
  563. */
  564. rt2500usb_bbp_read(rt2x00dev, 17, &r17);
  565. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &r17_sens);
  566. /*
  567. * A too low RSSI will cause too much false CCA which will
  568. * then corrupt the R17 tuning. To remidy this the tuning should
  569. * be stopped (While making sure the R17 value will not exceed limits)
  570. */
  571. if (rssi >= -40) {
  572. if (r17 != 0x60)
  573. rt2500usb_bbp_write(rt2x00dev, 17, 0x60);
  574. return;
  575. }
  576. /*
  577. * Special big-R17 for short distance
  578. */
  579. if (rssi >= -58) {
  580. sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_LOW);
  581. if (r17 != sens)
  582. rt2500usb_bbp_write(rt2x00dev, 17, sens);
  583. return;
  584. }
  585. /*
  586. * Special mid-R17 for middle distance
  587. */
  588. if (rssi >= -74) {
  589. sens = rt2x00_get_field16(r17_sens, EEPROM_BBPTUNE_R17_HIGH);
  590. if (r17 != sens)
  591. rt2500usb_bbp_write(rt2x00dev, 17, sens);
  592. return;
  593. }
  594. /*
  595. * Leave short or middle distance condition, restore r17
  596. * to the dynamic tuning range.
  597. */
  598. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &vgc_bound);
  599. vgc_bound = rt2x00_get_field16(vgc_bound, EEPROM_BBPTUNE_VGCUPPER);
  600. low_bound = 0x32;
  601. if (rssi >= -77)
  602. up_bound = vgc_bound;
  603. else
  604. up_bound = vgc_bound - (-77 - rssi);
  605. if (up_bound < low_bound)
  606. up_bound = low_bound;
  607. if (r17 > up_bound) {
  608. rt2500usb_bbp_write(rt2x00dev, 17, up_bound);
  609. rt2x00dev->link.vgc_level = up_bound;
  610. } else if (rt2x00dev->link.qual.false_cca > 512 && r17 < up_bound) {
  611. rt2500usb_bbp_write(rt2x00dev, 17, ++r17);
  612. rt2x00dev->link.vgc_level = r17;
  613. } else if (rt2x00dev->link.qual.false_cca < 100 && r17 > low_bound) {
  614. rt2500usb_bbp_write(rt2x00dev, 17, --r17);
  615. rt2x00dev->link.vgc_level = r17;
  616. }
  617. }
  618. /*
  619. * Initialization functions.
  620. */
  621. static int rt2500usb_init_registers(struct rt2x00_dev *rt2x00dev)
  622. {
  623. u16 reg;
  624. rt2x00usb_vendor_request_sw(rt2x00dev, USB_DEVICE_MODE, 0x0001,
  625. USB_MODE_TEST, REGISTER_TIMEOUT);
  626. rt2x00usb_vendor_request_sw(rt2x00dev, USB_SINGLE_WRITE, 0x0308,
  627. 0x00f0, REGISTER_TIMEOUT);
  628. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  629. rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX, 1);
  630. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  631. rt2500usb_register_write(rt2x00dev, MAC_CSR13, 0x1111);
  632. rt2500usb_register_write(rt2x00dev, MAC_CSR14, 0x1e11);
  633. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  634. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 1);
  635. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 1);
  636. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
  637. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  638. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  639. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
  640. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
  641. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 0);
  642. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  643. rt2500usb_register_read(rt2x00dev, TXRX_CSR5, &reg);
  644. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0, 13);
  645. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID0_VALID, 1);
  646. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1, 12);
  647. rt2x00_set_field16(&reg, TXRX_CSR5_BBP_ID1_VALID, 1);
  648. rt2500usb_register_write(rt2x00dev, TXRX_CSR5, reg);
  649. rt2500usb_register_read(rt2x00dev, TXRX_CSR6, &reg);
  650. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0, 10);
  651. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID0_VALID, 1);
  652. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1, 11);
  653. rt2x00_set_field16(&reg, TXRX_CSR6_BBP_ID1_VALID, 1);
  654. rt2500usb_register_write(rt2x00dev, TXRX_CSR6, reg);
  655. rt2500usb_register_read(rt2x00dev, TXRX_CSR7, &reg);
  656. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0, 7);
  657. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID0_VALID, 1);
  658. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1, 6);
  659. rt2x00_set_field16(&reg, TXRX_CSR7_BBP_ID1_VALID, 1);
  660. rt2500usb_register_write(rt2x00dev, TXRX_CSR7, reg);
  661. rt2500usb_register_read(rt2x00dev, TXRX_CSR8, &reg);
  662. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0, 5);
  663. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID0_VALID, 1);
  664. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1, 0);
  665. rt2x00_set_field16(&reg, TXRX_CSR8_BBP_ID1_VALID, 0);
  666. rt2500usb_register_write(rt2x00dev, TXRX_CSR8, reg);
  667. rt2500usb_register_write(rt2x00dev, TXRX_CSR21, 0xe78f);
  668. rt2500usb_register_write(rt2x00dev, MAC_CSR9, 0xff1d);
  669. if (rt2x00dev->ops->lib->set_device_state(rt2x00dev, STATE_AWAKE))
  670. return -EBUSY;
  671. rt2500usb_register_read(rt2x00dev, MAC_CSR1, &reg);
  672. rt2x00_set_field16(&reg, MAC_CSR1_SOFT_RESET, 0);
  673. rt2x00_set_field16(&reg, MAC_CSR1_BBP_RESET, 0);
  674. rt2x00_set_field16(&reg, MAC_CSR1_HOST_READY, 1);
  675. rt2500usb_register_write(rt2x00dev, MAC_CSR1, reg);
  676. if (rt2x00_rev(&rt2x00dev->chip) >= RT2570_VERSION_C) {
  677. rt2500usb_register_read(rt2x00dev, PHY_CSR2, &reg);
  678. rt2x00_set_field16(&reg, PHY_CSR2_LNA, 0);
  679. } else {
  680. reg = 0;
  681. rt2x00_set_field16(&reg, PHY_CSR2_LNA, 1);
  682. rt2x00_set_field16(&reg, PHY_CSR2_LNA_MODE, 3);
  683. }
  684. rt2500usb_register_write(rt2x00dev, PHY_CSR2, reg);
  685. rt2500usb_register_write(rt2x00dev, MAC_CSR11, 0x0002);
  686. rt2500usb_register_write(rt2x00dev, MAC_CSR22, 0x0053);
  687. rt2500usb_register_write(rt2x00dev, MAC_CSR15, 0x01ee);
  688. rt2500usb_register_write(rt2x00dev, MAC_CSR16, 0x0000);
  689. rt2500usb_register_read(rt2x00dev, MAC_CSR8, &reg);
  690. rt2x00_set_field16(&reg, MAC_CSR8_MAX_FRAME_UNIT,
  691. rt2x00dev->rx->data_size);
  692. rt2500usb_register_write(rt2x00dev, MAC_CSR8, reg);
  693. rt2500usb_register_read(rt2x00dev, TXRX_CSR0, &reg);
  694. rt2x00_set_field16(&reg, TXRX_CSR0_IV_OFFSET, IEEE80211_HEADER);
  695. rt2x00_set_field16(&reg, TXRX_CSR0_KEY_ID, 0xff);
  696. rt2500usb_register_write(rt2x00dev, TXRX_CSR0, reg);
  697. rt2500usb_register_read(rt2x00dev, MAC_CSR18, &reg);
  698. rt2x00_set_field16(&reg, MAC_CSR18_DELAY_AFTER_BEACON, 90);
  699. rt2500usb_register_write(rt2x00dev, MAC_CSR18, reg);
  700. rt2500usb_register_read(rt2x00dev, PHY_CSR4, &reg);
  701. rt2x00_set_field16(&reg, PHY_CSR4_LOW_RF_LE, 1);
  702. rt2500usb_register_write(rt2x00dev, PHY_CSR4, reg);
  703. rt2500usb_register_read(rt2x00dev, TXRX_CSR1, &reg);
  704. rt2x00_set_field16(&reg, TXRX_CSR1_AUTO_SEQUENCE, 1);
  705. rt2500usb_register_write(rt2x00dev, TXRX_CSR1, reg);
  706. return 0;
  707. }
  708. static int rt2500usb_init_bbp(struct rt2x00_dev *rt2x00dev)
  709. {
  710. unsigned int i;
  711. u16 eeprom;
  712. u8 value;
  713. u8 reg_id;
  714. for (i = 0; i < REGISTER_BUSY_COUNT; i++) {
  715. rt2500usb_bbp_read(rt2x00dev, 0, &value);
  716. if ((value != 0xff) && (value != 0x00))
  717. goto continue_csr_init;
  718. NOTICE(rt2x00dev, "Waiting for BBP register.\n");
  719. udelay(REGISTER_BUSY_DELAY);
  720. }
  721. ERROR(rt2x00dev, "BBP register access failed, aborting.\n");
  722. return -EACCES;
  723. continue_csr_init:
  724. rt2500usb_bbp_write(rt2x00dev, 3, 0x02);
  725. rt2500usb_bbp_write(rt2x00dev, 4, 0x19);
  726. rt2500usb_bbp_write(rt2x00dev, 14, 0x1c);
  727. rt2500usb_bbp_write(rt2x00dev, 15, 0x30);
  728. rt2500usb_bbp_write(rt2x00dev, 16, 0xac);
  729. rt2500usb_bbp_write(rt2x00dev, 18, 0x18);
  730. rt2500usb_bbp_write(rt2x00dev, 19, 0xff);
  731. rt2500usb_bbp_write(rt2x00dev, 20, 0x1e);
  732. rt2500usb_bbp_write(rt2x00dev, 21, 0x08);
  733. rt2500usb_bbp_write(rt2x00dev, 22, 0x08);
  734. rt2500usb_bbp_write(rt2x00dev, 23, 0x08);
  735. rt2500usb_bbp_write(rt2x00dev, 24, 0x80);
  736. rt2500usb_bbp_write(rt2x00dev, 25, 0x50);
  737. rt2500usb_bbp_write(rt2x00dev, 26, 0x08);
  738. rt2500usb_bbp_write(rt2x00dev, 27, 0x23);
  739. rt2500usb_bbp_write(rt2x00dev, 30, 0x10);
  740. rt2500usb_bbp_write(rt2x00dev, 31, 0x2b);
  741. rt2500usb_bbp_write(rt2x00dev, 32, 0xb9);
  742. rt2500usb_bbp_write(rt2x00dev, 34, 0x12);
  743. rt2500usb_bbp_write(rt2x00dev, 35, 0x50);
  744. rt2500usb_bbp_write(rt2x00dev, 39, 0xc4);
  745. rt2500usb_bbp_write(rt2x00dev, 40, 0x02);
  746. rt2500usb_bbp_write(rt2x00dev, 41, 0x60);
  747. rt2500usb_bbp_write(rt2x00dev, 53, 0x10);
  748. rt2500usb_bbp_write(rt2x00dev, 54, 0x18);
  749. rt2500usb_bbp_write(rt2x00dev, 56, 0x08);
  750. rt2500usb_bbp_write(rt2x00dev, 57, 0x10);
  751. rt2500usb_bbp_write(rt2x00dev, 58, 0x08);
  752. rt2500usb_bbp_write(rt2x00dev, 61, 0x60);
  753. rt2500usb_bbp_write(rt2x00dev, 62, 0x10);
  754. rt2500usb_bbp_write(rt2x00dev, 75, 0xff);
  755. DEBUG(rt2x00dev, "Start initialization from EEPROM...\n");
  756. for (i = 0; i < EEPROM_BBP_SIZE; i++) {
  757. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBP_START + i, &eeprom);
  758. if (eeprom != 0xffff && eeprom != 0x0000) {
  759. reg_id = rt2x00_get_field16(eeprom, EEPROM_BBP_REG_ID);
  760. value = rt2x00_get_field16(eeprom, EEPROM_BBP_VALUE);
  761. DEBUG(rt2x00dev, "BBP: 0x%02x, value: 0x%02x.\n",
  762. reg_id, value);
  763. rt2500usb_bbp_write(rt2x00dev, reg_id, value);
  764. }
  765. }
  766. DEBUG(rt2x00dev, "...End initialization from EEPROM.\n");
  767. return 0;
  768. }
  769. /*
  770. * Device state switch handlers.
  771. */
  772. static void rt2500usb_toggle_rx(struct rt2x00_dev *rt2x00dev,
  773. enum dev_state state)
  774. {
  775. u16 reg;
  776. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  777. rt2x00_set_field16(&reg, TXRX_CSR2_DISABLE_RX,
  778. state == STATE_RADIO_RX_OFF);
  779. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  780. }
  781. static int rt2500usb_enable_radio(struct rt2x00_dev *rt2x00dev)
  782. {
  783. /*
  784. * Initialize all registers.
  785. */
  786. if (rt2500usb_init_registers(rt2x00dev) ||
  787. rt2500usb_init_bbp(rt2x00dev)) {
  788. ERROR(rt2x00dev, "Register initialization failed.\n");
  789. return -EIO;
  790. }
  791. rt2x00usb_enable_radio(rt2x00dev);
  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. __le32 *txd,
  880. struct txdata_entry_desc *desc,
  881. struct ieee80211_hdr *ieee80211hdr,
  882. unsigned int length,
  883. struct ieee80211_tx_control *control)
  884. {
  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, length);
  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 urb *urb = entry->priv;
  961. __le32 *rxd = (__le32 *)(entry->skb->data +
  962. (urb->actual_length - entry->ring->desc_size));
  963. u32 word0;
  964. u32 word1;
  965. rt2x00_desc_read(rxd, 0, &word0);
  966. rt2x00_desc_read(rxd, 1, &word1);
  967. desc->flags = 0;
  968. if (rt2x00_get_field32(word0, RXD_W0_CRC_ERROR))
  969. desc->flags |= RX_FLAG_FAILED_FCS_CRC;
  970. if (rt2x00_get_field32(word0, RXD_W0_PHYSICAL_ERROR))
  971. desc->flags |= RX_FLAG_FAILED_PLCP_CRC;
  972. /*
  973. * Obtain the status about this packet.
  974. */
  975. desc->signal = rt2x00_get_field32(word1, RXD_W1_SIGNAL);
  976. desc->rssi = rt2x00_get_field32(word1, RXD_W1_RSSI) -
  977. entry->ring->rt2x00dev->rssi_offset;
  978. desc->ofdm = rt2x00_get_field32(word0, RXD_W0_OFDM);
  979. desc->size = rt2x00_get_field32(word0, RXD_W0_DATABYTE_COUNT);
  980. return;
  981. }
  982. /*
  983. * Interrupt functions.
  984. */
  985. static void rt2500usb_beacondone(struct urb *urb)
  986. {
  987. struct data_entry *entry = (struct data_entry *)urb->context;
  988. struct data_ring *ring = entry->ring;
  989. if (!test_bit(DEVICE_ENABLED_RADIO, &ring->rt2x00dev->flags))
  990. return;
  991. /*
  992. * Check if this was the guardian beacon,
  993. * if that was the case we need to send the real beacon now.
  994. * Otherwise we should free the sk_buffer, the device
  995. * should be doing the rest of the work now.
  996. */
  997. if (ring->index == 1) {
  998. rt2x00_ring_index_done_inc(ring);
  999. entry = rt2x00_get_data_entry(ring);
  1000. usb_submit_urb(entry->priv, GFP_ATOMIC);
  1001. rt2x00_ring_index_inc(ring);
  1002. } else if (ring->index_done == 1) {
  1003. entry = rt2x00_get_data_entry_done(ring);
  1004. if (entry->skb) {
  1005. dev_kfree_skb(entry->skb);
  1006. entry->skb = NULL;
  1007. }
  1008. rt2x00_ring_index_done_inc(ring);
  1009. }
  1010. }
  1011. /*
  1012. * Device probe functions.
  1013. */
  1014. static int rt2500usb_validate_eeprom(struct rt2x00_dev *rt2x00dev)
  1015. {
  1016. u16 word;
  1017. u8 *mac;
  1018. rt2x00usb_eeprom_read(rt2x00dev, rt2x00dev->eeprom, EEPROM_SIZE);
  1019. /*
  1020. * Start validation of the data that has been read.
  1021. */
  1022. mac = rt2x00_eeprom_addr(rt2x00dev, EEPROM_MAC_ADDR_0);
  1023. if (!is_valid_ether_addr(mac)) {
  1024. DECLARE_MAC_BUF(macbuf);
  1025. random_ether_addr(mac);
  1026. EEPROM(rt2x00dev, "MAC: %s\n", print_mac(macbuf, mac));
  1027. }
  1028. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &word);
  1029. if (word == 0xffff) {
  1030. rt2x00_set_field16(&word, EEPROM_ANTENNA_NUM, 2);
  1031. rt2x00_set_field16(&word, EEPROM_ANTENNA_TX_DEFAULT,
  1032. ANTENNA_SW_DIVERSITY);
  1033. rt2x00_set_field16(&word, EEPROM_ANTENNA_RX_DEFAULT,
  1034. ANTENNA_SW_DIVERSITY);
  1035. rt2x00_set_field16(&word, EEPROM_ANTENNA_LED_MODE,
  1036. LED_MODE_DEFAULT);
  1037. rt2x00_set_field16(&word, EEPROM_ANTENNA_DYN_TXAGC, 0);
  1038. rt2x00_set_field16(&word, EEPROM_ANTENNA_HARDWARE_RADIO, 0);
  1039. rt2x00_set_field16(&word, EEPROM_ANTENNA_RF_TYPE, RF2522);
  1040. rt2x00_eeprom_write(rt2x00dev, EEPROM_ANTENNA, word);
  1041. EEPROM(rt2x00dev, "Antenna: 0x%04x\n", word);
  1042. }
  1043. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &word);
  1044. if (word == 0xffff) {
  1045. rt2x00_set_field16(&word, EEPROM_NIC_CARDBUS_ACCEL, 0);
  1046. rt2x00_set_field16(&word, EEPROM_NIC_DYN_BBP_TUNE, 0);
  1047. rt2x00_set_field16(&word, EEPROM_NIC_CCK_TX_POWER, 0);
  1048. rt2x00_eeprom_write(rt2x00dev, EEPROM_NIC, word);
  1049. EEPROM(rt2x00dev, "NIC: 0x%04x\n", word);
  1050. }
  1051. rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &word);
  1052. if (word == 0xffff) {
  1053. rt2x00_set_field16(&word, EEPROM_CALIBRATE_OFFSET_RSSI,
  1054. DEFAULT_RSSI_OFFSET);
  1055. rt2x00_eeprom_write(rt2x00dev, EEPROM_CALIBRATE_OFFSET, word);
  1056. EEPROM(rt2x00dev, "Calibrate offset: 0x%04x\n", word);
  1057. }
  1058. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE, &word);
  1059. if (word == 0xffff) {
  1060. rt2x00_set_field16(&word, EEPROM_BBPTUNE_THRESHOLD, 45);
  1061. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE, word);
  1062. EEPROM(rt2x00dev, "BBPtune: 0x%04x\n", word);
  1063. }
  1064. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_VGC, &word);
  1065. if (word == 0xffff) {
  1066. rt2x00_set_field16(&word, EEPROM_BBPTUNE_VGCUPPER, 0x40);
  1067. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_VGC, word);
  1068. EEPROM(rt2x00dev, "BBPtune vgc: 0x%04x\n", word);
  1069. }
  1070. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R17, &word);
  1071. if (word == 0xffff) {
  1072. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_LOW, 0x48);
  1073. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R17_HIGH, 0x41);
  1074. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R17, word);
  1075. EEPROM(rt2x00dev, "BBPtune r17: 0x%04x\n", word);
  1076. }
  1077. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R24, &word);
  1078. if (word == 0xffff) {
  1079. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_LOW, 0x40);
  1080. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R24_HIGH, 0x80);
  1081. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R24, word);
  1082. EEPROM(rt2x00dev, "BBPtune r24: 0x%04x\n", word);
  1083. }
  1084. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R25, &word);
  1085. if (word == 0xffff) {
  1086. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_LOW, 0x40);
  1087. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R25_HIGH, 0x50);
  1088. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R25, word);
  1089. EEPROM(rt2x00dev, "BBPtune r25: 0x%04x\n", word);
  1090. }
  1091. rt2x00_eeprom_read(rt2x00dev, EEPROM_BBPTUNE_R61, &word);
  1092. if (word == 0xffff) {
  1093. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_LOW, 0x60);
  1094. rt2x00_set_field16(&word, EEPROM_BBPTUNE_R61_HIGH, 0x6d);
  1095. rt2x00_eeprom_write(rt2x00dev, EEPROM_BBPTUNE_R61, word);
  1096. EEPROM(rt2x00dev, "BBPtune r61: 0x%04x\n", word);
  1097. }
  1098. return 0;
  1099. }
  1100. static int rt2500usb_init_eeprom(struct rt2x00_dev *rt2x00dev)
  1101. {
  1102. u16 reg;
  1103. u16 value;
  1104. u16 eeprom;
  1105. /*
  1106. * Read EEPROM word for configuration.
  1107. */
  1108. rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
  1109. /*
  1110. * Identify RF chipset.
  1111. */
  1112. value = rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RF_TYPE);
  1113. rt2500usb_register_read(rt2x00dev, MAC_CSR0, &reg);
  1114. rt2x00_set_chip(rt2x00dev, RT2570, value, reg);
  1115. if (!rt2x00_check_rev(&rt2x00dev->chip, 0)) {
  1116. ERROR(rt2x00dev, "Invalid RT chipset detected.\n");
  1117. return -ENODEV;
  1118. }
  1119. if (!rt2x00_rf(&rt2x00dev->chip, RF2522) &&
  1120. !rt2x00_rf(&rt2x00dev->chip, RF2523) &&
  1121. !rt2x00_rf(&rt2x00dev->chip, RF2524) &&
  1122. !rt2x00_rf(&rt2x00dev->chip, RF2525) &&
  1123. !rt2x00_rf(&rt2x00dev->chip, RF2525E) &&
  1124. !rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  1125. ERROR(rt2x00dev, "Invalid RF chipset detected.\n");
  1126. return -ENODEV;
  1127. }
  1128. /*
  1129. * Identify default antenna configuration.
  1130. */
  1131. rt2x00dev->default_ant.tx =
  1132. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TX_DEFAULT);
  1133. rt2x00dev->default_ant.rx =
  1134. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RX_DEFAULT);
  1135. /*
  1136. * When the eeprom indicates SW_DIVERSITY use HW_DIVERSITY instead.
  1137. * I am not 100% sure about this, but the legacy drivers do not
  1138. * indicate antenna swapping in software is required when
  1139. * diversity is enabled.
  1140. */
  1141. if (rt2x00dev->default_ant.tx == ANTENNA_SW_DIVERSITY)
  1142. rt2x00dev->default_ant.tx = ANTENNA_HW_DIVERSITY;
  1143. if (rt2x00dev->default_ant.rx == ANTENNA_SW_DIVERSITY)
  1144. rt2x00dev->default_ant.rx = ANTENNA_HW_DIVERSITY;
  1145. /*
  1146. * Store led mode, for correct led behaviour.
  1147. */
  1148. rt2x00dev->led_mode =
  1149. rt2x00_get_field16(eeprom, EEPROM_ANTENNA_LED_MODE);
  1150. /*
  1151. * Check if the BBP tuning should be disabled.
  1152. */
  1153. rt2x00_eeprom_read(rt2x00dev, EEPROM_NIC, &eeprom);
  1154. if (rt2x00_get_field16(eeprom, EEPROM_NIC_DYN_BBP_TUNE))
  1155. __set_bit(CONFIG_DISABLE_LINK_TUNING, &rt2x00dev->flags);
  1156. /*
  1157. * Read the RSSI <-> dBm offset information.
  1158. */
  1159. rt2x00_eeprom_read(rt2x00dev, EEPROM_CALIBRATE_OFFSET, &eeprom);
  1160. rt2x00dev->rssi_offset =
  1161. rt2x00_get_field16(eeprom, EEPROM_CALIBRATE_OFFSET_RSSI);
  1162. return 0;
  1163. }
  1164. /*
  1165. * RF value list for RF2522
  1166. * Supports: 2.4 GHz
  1167. */
  1168. static const struct rf_channel rf_vals_bg_2522[] = {
  1169. { 1, 0x00002050, 0x000c1fda, 0x00000101, 0 },
  1170. { 2, 0x00002050, 0x000c1fee, 0x00000101, 0 },
  1171. { 3, 0x00002050, 0x000c2002, 0x00000101, 0 },
  1172. { 4, 0x00002050, 0x000c2016, 0x00000101, 0 },
  1173. { 5, 0x00002050, 0x000c202a, 0x00000101, 0 },
  1174. { 6, 0x00002050, 0x000c203e, 0x00000101, 0 },
  1175. { 7, 0x00002050, 0x000c2052, 0x00000101, 0 },
  1176. { 8, 0x00002050, 0x000c2066, 0x00000101, 0 },
  1177. { 9, 0x00002050, 0x000c207a, 0x00000101, 0 },
  1178. { 10, 0x00002050, 0x000c208e, 0x00000101, 0 },
  1179. { 11, 0x00002050, 0x000c20a2, 0x00000101, 0 },
  1180. { 12, 0x00002050, 0x000c20b6, 0x00000101, 0 },
  1181. { 13, 0x00002050, 0x000c20ca, 0x00000101, 0 },
  1182. { 14, 0x00002050, 0x000c20fa, 0x00000101, 0 },
  1183. };
  1184. /*
  1185. * RF value list for RF2523
  1186. * Supports: 2.4 GHz
  1187. */
  1188. static const struct rf_channel rf_vals_bg_2523[] = {
  1189. { 1, 0x00022010, 0x00000c9e, 0x000e0111, 0x00000a1b },
  1190. { 2, 0x00022010, 0x00000ca2, 0x000e0111, 0x00000a1b },
  1191. { 3, 0x00022010, 0x00000ca6, 0x000e0111, 0x00000a1b },
  1192. { 4, 0x00022010, 0x00000caa, 0x000e0111, 0x00000a1b },
  1193. { 5, 0x00022010, 0x00000cae, 0x000e0111, 0x00000a1b },
  1194. { 6, 0x00022010, 0x00000cb2, 0x000e0111, 0x00000a1b },
  1195. { 7, 0x00022010, 0x00000cb6, 0x000e0111, 0x00000a1b },
  1196. { 8, 0x00022010, 0x00000cba, 0x000e0111, 0x00000a1b },
  1197. { 9, 0x00022010, 0x00000cbe, 0x000e0111, 0x00000a1b },
  1198. { 10, 0x00022010, 0x00000d02, 0x000e0111, 0x00000a1b },
  1199. { 11, 0x00022010, 0x00000d06, 0x000e0111, 0x00000a1b },
  1200. { 12, 0x00022010, 0x00000d0a, 0x000e0111, 0x00000a1b },
  1201. { 13, 0x00022010, 0x00000d0e, 0x000e0111, 0x00000a1b },
  1202. { 14, 0x00022010, 0x00000d1a, 0x000e0111, 0x00000a03 },
  1203. };
  1204. /*
  1205. * RF value list for RF2524
  1206. * Supports: 2.4 GHz
  1207. */
  1208. static const struct rf_channel rf_vals_bg_2524[] = {
  1209. { 1, 0x00032020, 0x00000c9e, 0x00000101, 0x00000a1b },
  1210. { 2, 0x00032020, 0x00000ca2, 0x00000101, 0x00000a1b },
  1211. { 3, 0x00032020, 0x00000ca6, 0x00000101, 0x00000a1b },
  1212. { 4, 0x00032020, 0x00000caa, 0x00000101, 0x00000a1b },
  1213. { 5, 0x00032020, 0x00000cae, 0x00000101, 0x00000a1b },
  1214. { 6, 0x00032020, 0x00000cb2, 0x00000101, 0x00000a1b },
  1215. { 7, 0x00032020, 0x00000cb6, 0x00000101, 0x00000a1b },
  1216. { 8, 0x00032020, 0x00000cba, 0x00000101, 0x00000a1b },
  1217. { 9, 0x00032020, 0x00000cbe, 0x00000101, 0x00000a1b },
  1218. { 10, 0x00032020, 0x00000d02, 0x00000101, 0x00000a1b },
  1219. { 11, 0x00032020, 0x00000d06, 0x00000101, 0x00000a1b },
  1220. { 12, 0x00032020, 0x00000d0a, 0x00000101, 0x00000a1b },
  1221. { 13, 0x00032020, 0x00000d0e, 0x00000101, 0x00000a1b },
  1222. { 14, 0x00032020, 0x00000d1a, 0x00000101, 0x00000a03 },
  1223. };
  1224. /*
  1225. * RF value list for RF2525
  1226. * Supports: 2.4 GHz
  1227. */
  1228. static const struct rf_channel rf_vals_bg_2525[] = {
  1229. { 1, 0x00022020, 0x00080c9e, 0x00060111, 0x00000a1b },
  1230. { 2, 0x00022020, 0x00080ca2, 0x00060111, 0x00000a1b },
  1231. { 3, 0x00022020, 0x00080ca6, 0x00060111, 0x00000a1b },
  1232. { 4, 0x00022020, 0x00080caa, 0x00060111, 0x00000a1b },
  1233. { 5, 0x00022020, 0x00080cae, 0x00060111, 0x00000a1b },
  1234. { 6, 0x00022020, 0x00080cb2, 0x00060111, 0x00000a1b },
  1235. { 7, 0x00022020, 0x00080cb6, 0x00060111, 0x00000a1b },
  1236. { 8, 0x00022020, 0x00080cba, 0x00060111, 0x00000a1b },
  1237. { 9, 0x00022020, 0x00080cbe, 0x00060111, 0x00000a1b },
  1238. { 10, 0x00022020, 0x00080d02, 0x00060111, 0x00000a1b },
  1239. { 11, 0x00022020, 0x00080d06, 0x00060111, 0x00000a1b },
  1240. { 12, 0x00022020, 0x00080d0a, 0x00060111, 0x00000a1b },
  1241. { 13, 0x00022020, 0x00080d0e, 0x00060111, 0x00000a1b },
  1242. { 14, 0x00022020, 0x00080d1a, 0x00060111, 0x00000a03 },
  1243. };
  1244. /*
  1245. * RF value list for RF2525e
  1246. * Supports: 2.4 GHz
  1247. */
  1248. static const struct rf_channel rf_vals_bg_2525e[] = {
  1249. { 1, 0x00022010, 0x0000089a, 0x00060111, 0x00000e1b },
  1250. { 2, 0x00022010, 0x0000089e, 0x00060111, 0x00000e07 },
  1251. { 3, 0x00022010, 0x0000089e, 0x00060111, 0x00000e1b },
  1252. { 4, 0x00022010, 0x000008a2, 0x00060111, 0x00000e07 },
  1253. { 5, 0x00022010, 0x000008a2, 0x00060111, 0x00000e1b },
  1254. { 6, 0x00022010, 0x000008a6, 0x00060111, 0x00000e07 },
  1255. { 7, 0x00022010, 0x000008a6, 0x00060111, 0x00000e1b },
  1256. { 8, 0x00022010, 0x000008aa, 0x00060111, 0x00000e07 },
  1257. { 9, 0x00022010, 0x000008aa, 0x00060111, 0x00000e1b },
  1258. { 10, 0x00022010, 0x000008ae, 0x00060111, 0x00000e07 },
  1259. { 11, 0x00022010, 0x000008ae, 0x00060111, 0x00000e1b },
  1260. { 12, 0x00022010, 0x000008b2, 0x00060111, 0x00000e07 },
  1261. { 13, 0x00022010, 0x000008b2, 0x00060111, 0x00000e1b },
  1262. { 14, 0x00022010, 0x000008b6, 0x00060111, 0x00000e23 },
  1263. };
  1264. /*
  1265. * RF value list for RF5222
  1266. * Supports: 2.4 GHz & 5.2 GHz
  1267. */
  1268. static const struct rf_channel rf_vals_5222[] = {
  1269. { 1, 0x00022020, 0x00001136, 0x00000101, 0x00000a0b },
  1270. { 2, 0x00022020, 0x0000113a, 0x00000101, 0x00000a0b },
  1271. { 3, 0x00022020, 0x0000113e, 0x00000101, 0x00000a0b },
  1272. { 4, 0x00022020, 0x00001182, 0x00000101, 0x00000a0b },
  1273. { 5, 0x00022020, 0x00001186, 0x00000101, 0x00000a0b },
  1274. { 6, 0x00022020, 0x0000118a, 0x00000101, 0x00000a0b },
  1275. { 7, 0x00022020, 0x0000118e, 0x00000101, 0x00000a0b },
  1276. { 8, 0x00022020, 0x00001192, 0x00000101, 0x00000a0b },
  1277. { 9, 0x00022020, 0x00001196, 0x00000101, 0x00000a0b },
  1278. { 10, 0x00022020, 0x0000119a, 0x00000101, 0x00000a0b },
  1279. { 11, 0x00022020, 0x0000119e, 0x00000101, 0x00000a0b },
  1280. { 12, 0x00022020, 0x000011a2, 0x00000101, 0x00000a0b },
  1281. { 13, 0x00022020, 0x000011a6, 0x00000101, 0x00000a0b },
  1282. { 14, 0x00022020, 0x000011ae, 0x00000101, 0x00000a1b },
  1283. /* 802.11 UNI / HyperLan 2 */
  1284. { 36, 0x00022010, 0x00018896, 0x00000101, 0x00000a1f },
  1285. { 40, 0x00022010, 0x0001889a, 0x00000101, 0x00000a1f },
  1286. { 44, 0x00022010, 0x0001889e, 0x00000101, 0x00000a1f },
  1287. { 48, 0x00022010, 0x000188a2, 0x00000101, 0x00000a1f },
  1288. { 52, 0x00022010, 0x000188a6, 0x00000101, 0x00000a1f },
  1289. { 66, 0x00022010, 0x000188aa, 0x00000101, 0x00000a1f },
  1290. { 60, 0x00022010, 0x000188ae, 0x00000101, 0x00000a1f },
  1291. { 64, 0x00022010, 0x000188b2, 0x00000101, 0x00000a1f },
  1292. /* 802.11 HyperLan 2 */
  1293. { 100, 0x00022010, 0x00008802, 0x00000101, 0x00000a0f },
  1294. { 104, 0x00022010, 0x00008806, 0x00000101, 0x00000a0f },
  1295. { 108, 0x00022010, 0x0000880a, 0x00000101, 0x00000a0f },
  1296. { 112, 0x00022010, 0x0000880e, 0x00000101, 0x00000a0f },
  1297. { 116, 0x00022010, 0x00008812, 0x00000101, 0x00000a0f },
  1298. { 120, 0x00022010, 0x00008816, 0x00000101, 0x00000a0f },
  1299. { 124, 0x00022010, 0x0000881a, 0x00000101, 0x00000a0f },
  1300. { 128, 0x00022010, 0x0000881e, 0x00000101, 0x00000a0f },
  1301. { 132, 0x00022010, 0x00008822, 0x00000101, 0x00000a0f },
  1302. { 136, 0x00022010, 0x00008826, 0x00000101, 0x00000a0f },
  1303. /* 802.11 UNII */
  1304. { 140, 0x00022010, 0x0000882a, 0x00000101, 0x00000a0f },
  1305. { 149, 0x00022020, 0x000090a6, 0x00000101, 0x00000a07 },
  1306. { 153, 0x00022020, 0x000090ae, 0x00000101, 0x00000a07 },
  1307. { 157, 0x00022020, 0x000090b6, 0x00000101, 0x00000a07 },
  1308. { 161, 0x00022020, 0x000090be, 0x00000101, 0x00000a07 },
  1309. };
  1310. static void rt2500usb_probe_hw_mode(struct rt2x00_dev *rt2x00dev)
  1311. {
  1312. struct hw_mode_spec *spec = &rt2x00dev->spec;
  1313. u8 *txpower;
  1314. unsigned int i;
  1315. /*
  1316. * Initialize all hw fields.
  1317. */
  1318. rt2x00dev->hw->flags =
  1319. IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE |
  1320. IEEE80211_HW_RX_INCLUDES_FCS |
  1321. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING;
  1322. rt2x00dev->hw->extra_tx_headroom = TXD_DESC_SIZE;
  1323. rt2x00dev->hw->max_signal = MAX_SIGNAL;
  1324. rt2x00dev->hw->max_rssi = MAX_RX_SSI;
  1325. rt2x00dev->hw->queues = 2;
  1326. SET_IEEE80211_DEV(rt2x00dev->hw, &rt2x00dev_usb(rt2x00dev)->dev);
  1327. SET_IEEE80211_PERM_ADDR(rt2x00dev->hw,
  1328. rt2x00_eeprom_addr(rt2x00dev,
  1329. EEPROM_MAC_ADDR_0));
  1330. /*
  1331. * Convert tx_power array in eeprom.
  1332. */
  1333. txpower = rt2x00_eeprom_addr(rt2x00dev, EEPROM_TXPOWER_START);
  1334. for (i = 0; i < 14; i++)
  1335. txpower[i] = TXPOWER_FROM_DEV(txpower[i]);
  1336. /*
  1337. * Initialize hw_mode information.
  1338. */
  1339. spec->num_modes = 2;
  1340. spec->num_rates = 12;
  1341. spec->tx_power_a = NULL;
  1342. spec->tx_power_bg = txpower;
  1343. spec->tx_power_default = DEFAULT_TXPOWER;
  1344. if (rt2x00_rf(&rt2x00dev->chip, RF2522)) {
  1345. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2522);
  1346. spec->channels = rf_vals_bg_2522;
  1347. } else if (rt2x00_rf(&rt2x00dev->chip, RF2523)) {
  1348. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2523);
  1349. spec->channels = rf_vals_bg_2523;
  1350. } else if (rt2x00_rf(&rt2x00dev->chip, RF2524)) {
  1351. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2524);
  1352. spec->channels = rf_vals_bg_2524;
  1353. } else if (rt2x00_rf(&rt2x00dev->chip, RF2525)) {
  1354. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525);
  1355. spec->channels = rf_vals_bg_2525;
  1356. } else if (rt2x00_rf(&rt2x00dev->chip, RF2525E)) {
  1357. spec->num_channels = ARRAY_SIZE(rf_vals_bg_2525e);
  1358. spec->channels = rf_vals_bg_2525e;
  1359. } else if (rt2x00_rf(&rt2x00dev->chip, RF5222)) {
  1360. spec->num_channels = ARRAY_SIZE(rf_vals_5222);
  1361. spec->channels = rf_vals_5222;
  1362. spec->num_modes = 3;
  1363. }
  1364. }
  1365. static int rt2500usb_probe_hw(struct rt2x00_dev *rt2x00dev)
  1366. {
  1367. int retval;
  1368. /*
  1369. * Allocate eeprom data.
  1370. */
  1371. retval = rt2500usb_validate_eeprom(rt2x00dev);
  1372. if (retval)
  1373. return retval;
  1374. retval = rt2500usb_init_eeprom(rt2x00dev);
  1375. if (retval)
  1376. return retval;
  1377. /*
  1378. * Initialize hw specifications.
  1379. */
  1380. rt2500usb_probe_hw_mode(rt2x00dev);
  1381. /*
  1382. * This device requires the beacon ring
  1383. */
  1384. __set_bit(DRIVER_REQUIRE_BEACON_RING, &rt2x00dev->flags);
  1385. /*
  1386. * Set the rssi offset.
  1387. */
  1388. rt2x00dev->rssi_offset = DEFAULT_RSSI_OFFSET;
  1389. return 0;
  1390. }
  1391. /*
  1392. * IEEE80211 stack callback functions.
  1393. */
  1394. static void rt2500usb_configure_filter(struct ieee80211_hw *hw,
  1395. unsigned int changed_flags,
  1396. unsigned int *total_flags,
  1397. int mc_count,
  1398. struct dev_addr_list *mc_list)
  1399. {
  1400. struct rt2x00_dev *rt2x00dev = hw->priv;
  1401. struct interface *intf = &rt2x00dev->interface;
  1402. u16 reg;
  1403. /*
  1404. * Mask off any flags we are going to ignore from
  1405. * the total_flags field.
  1406. */
  1407. *total_flags &=
  1408. FIF_ALLMULTI |
  1409. FIF_FCSFAIL |
  1410. FIF_PLCPFAIL |
  1411. FIF_CONTROL |
  1412. FIF_OTHER_BSS |
  1413. FIF_PROMISC_IN_BSS;
  1414. /*
  1415. * Apply some rules to the filters:
  1416. * - Some filters imply different filters to be set.
  1417. * - Some things we can't filter out at all.
  1418. * - Some filters are set based on interface type.
  1419. */
  1420. if (mc_count)
  1421. *total_flags |= FIF_ALLMULTI;
  1422. if (*total_flags & FIF_OTHER_BSS ||
  1423. *total_flags & FIF_PROMISC_IN_BSS)
  1424. *total_flags |= FIF_PROMISC_IN_BSS | FIF_OTHER_BSS;
  1425. if (is_interface_type(intf, IEEE80211_IF_TYPE_AP))
  1426. *total_flags |= FIF_PROMISC_IN_BSS;
  1427. /*
  1428. * Check if there is any work left for us.
  1429. */
  1430. if (intf->filter == *total_flags)
  1431. return;
  1432. intf->filter = *total_flags;
  1433. /*
  1434. * When in atomic context, reschedule and let rt2x00lib
  1435. * call this function again.
  1436. */
  1437. if (in_atomic()) {
  1438. queue_work(rt2x00dev->hw->workqueue, &rt2x00dev->filter_work);
  1439. return;
  1440. }
  1441. /*
  1442. * Start configuration steps.
  1443. * Note that the version error will always be dropped
  1444. * and broadcast frames will always be accepted since
  1445. * there is no filter for it at this time.
  1446. */
  1447. rt2500usb_register_read(rt2x00dev, TXRX_CSR2, &reg);
  1448. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CRC,
  1449. !(*total_flags & FIF_FCSFAIL));
  1450. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_PHYSICAL,
  1451. !(*total_flags & FIF_PLCPFAIL));
  1452. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_CONTROL,
  1453. !(*total_flags & FIF_CONTROL));
  1454. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_NOT_TO_ME,
  1455. !(*total_flags & FIF_PROMISC_IN_BSS));
  1456. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_TODS,
  1457. !(*total_flags & FIF_PROMISC_IN_BSS));
  1458. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_VERSION_ERROR, 1);
  1459. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_MULTICAST,
  1460. !(*total_flags & FIF_ALLMULTI));
  1461. rt2x00_set_field16(&reg, TXRX_CSR2_DROP_BROADCAST, 0);
  1462. rt2500usb_register_write(rt2x00dev, TXRX_CSR2, reg);
  1463. }
  1464. static int rt2500usb_beacon_update(struct ieee80211_hw *hw,
  1465. struct sk_buff *skb,
  1466. struct ieee80211_tx_control *control)
  1467. {
  1468. struct rt2x00_dev *rt2x00dev = hw->priv;
  1469. struct usb_device *usb_dev =
  1470. interface_to_usbdev(rt2x00dev_usb(rt2x00dev));
  1471. struct skb_desc *desc;
  1472. struct data_ring *ring;
  1473. struct data_entry *beacon;
  1474. struct data_entry *guardian;
  1475. int pipe = usb_sndbulkpipe(usb_dev, 1);
  1476. int length;
  1477. /*
  1478. * Just in case the ieee80211 doesn't set this,
  1479. * but we need this queue set for the descriptor
  1480. * initialization.
  1481. */
  1482. control->queue = IEEE80211_TX_QUEUE_BEACON;
  1483. ring = rt2x00lib_get_ring(rt2x00dev, control->queue);
  1484. /*
  1485. * Obtain 2 entries, one for the guardian byte,
  1486. * the second for the actual beacon.
  1487. */
  1488. guardian = rt2x00_get_data_entry(ring);
  1489. rt2x00_ring_index_inc(ring);
  1490. beacon = rt2x00_get_data_entry(ring);
  1491. /*
  1492. * Add the descriptor in front of the skb.
  1493. */
  1494. skb_push(skb, ring->desc_size);
  1495. memset(skb->data, 0, ring->desc_size);
  1496. /*
  1497. * Fill in skb descriptor
  1498. */
  1499. desc = get_skb_desc(skb);
  1500. desc->desc_len = ring->desc_size;
  1501. desc->data_len = skb->len - ring->desc_size;
  1502. desc->desc = skb->data;
  1503. desc->data = skb->data + ring->desc_size;
  1504. desc->ring = ring;
  1505. desc->entry = beacon;
  1506. rt2x00lib_write_tx_desc(rt2x00dev, skb, control);
  1507. /*
  1508. * USB devices cannot blindly pass the skb->len as the
  1509. * length of the data to usb_fill_bulk_urb. Pass the skb
  1510. * to the driver to determine what the length should be.
  1511. */
  1512. length = rt2500usb_get_tx_data_len(rt2x00dev, skb);
  1513. usb_fill_bulk_urb(beacon->priv, usb_dev, pipe,
  1514. skb->data, length, rt2500usb_beacondone, beacon);
  1515. /*
  1516. * Second we need to create the guardian byte.
  1517. * We only need a single byte, so lets recycle
  1518. * the 'flags' field we are not using for beacons.
  1519. */
  1520. guardian->flags = 0;
  1521. usb_fill_bulk_urb(guardian->priv, usb_dev, pipe,
  1522. &guardian->flags, 1, rt2500usb_beacondone, guardian);
  1523. /*
  1524. * Send out the guardian byte.
  1525. */
  1526. usb_submit_urb(guardian->priv, GFP_ATOMIC);
  1527. /*
  1528. * Enable beacon generation.
  1529. */
  1530. rt2500usb_kick_tx_queue(rt2x00dev, IEEE80211_TX_QUEUE_BEACON);
  1531. return 0;
  1532. }
  1533. static const struct ieee80211_ops rt2500usb_mac80211_ops = {
  1534. .tx = rt2x00mac_tx,
  1535. .start = rt2x00mac_start,
  1536. .stop = rt2x00mac_stop,
  1537. .add_interface = rt2x00mac_add_interface,
  1538. .remove_interface = rt2x00mac_remove_interface,
  1539. .config = rt2x00mac_config,
  1540. .config_interface = rt2x00mac_config_interface,
  1541. .configure_filter = rt2500usb_configure_filter,
  1542. .get_stats = rt2x00mac_get_stats,
  1543. .erp_ie_changed = rt2x00mac_erp_ie_changed,
  1544. .conf_tx = rt2x00mac_conf_tx,
  1545. .get_tx_stats = rt2x00mac_get_tx_stats,
  1546. .beacon_update = rt2500usb_beacon_update,
  1547. };
  1548. static const struct rt2x00lib_ops rt2500usb_rt2x00_ops = {
  1549. .probe_hw = rt2500usb_probe_hw,
  1550. .initialize = rt2x00usb_initialize,
  1551. .uninitialize = rt2x00usb_uninitialize,
  1552. .set_device_state = rt2500usb_set_device_state,
  1553. .link_stats = rt2500usb_link_stats,
  1554. .reset_tuner = rt2500usb_reset_tuner,
  1555. .link_tuner = rt2500usb_link_tuner,
  1556. .write_tx_desc = rt2500usb_write_tx_desc,
  1557. .write_tx_data = rt2x00usb_write_tx_data,
  1558. .get_tx_data_len = rt2500usb_get_tx_data_len,
  1559. .kick_tx_queue = rt2500usb_kick_tx_queue,
  1560. .fill_rxdone = rt2500usb_fill_rxdone,
  1561. .config_mac_addr = rt2500usb_config_mac_addr,
  1562. .config_bssid = rt2500usb_config_bssid,
  1563. .config_type = rt2500usb_config_type,
  1564. .config_preamble = rt2500usb_config_preamble,
  1565. .config = rt2500usb_config,
  1566. };
  1567. static const struct rt2x00_ops rt2500usb_ops = {
  1568. .name = KBUILD_MODNAME,
  1569. .rxd_size = RXD_DESC_SIZE,
  1570. .txd_size = TXD_DESC_SIZE,
  1571. .eeprom_size = EEPROM_SIZE,
  1572. .rf_size = RF_SIZE,
  1573. .lib = &rt2500usb_rt2x00_ops,
  1574. .hw = &rt2500usb_mac80211_ops,
  1575. #ifdef CONFIG_RT2X00_LIB_DEBUGFS
  1576. .debugfs = &rt2500usb_rt2x00debug,
  1577. #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
  1578. };
  1579. /*
  1580. * rt2500usb module information.
  1581. */
  1582. static struct usb_device_id rt2500usb_device_table[] = {
  1583. /* ASUS */
  1584. { USB_DEVICE(0x0b05, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
  1585. { USB_DEVICE(0x0b05, 0x1707), USB_DEVICE_DATA(&rt2500usb_ops) },
  1586. /* Belkin */
  1587. { USB_DEVICE(0x050d, 0x7050), USB_DEVICE_DATA(&rt2500usb_ops) },
  1588. { USB_DEVICE(0x050d, 0x7051), USB_DEVICE_DATA(&rt2500usb_ops) },
  1589. { USB_DEVICE(0x050d, 0x705a), USB_DEVICE_DATA(&rt2500usb_ops) },
  1590. /* Cisco Systems */
  1591. { USB_DEVICE(0x13b1, 0x000d), USB_DEVICE_DATA(&rt2500usb_ops) },
  1592. { USB_DEVICE(0x13b1, 0x0011), USB_DEVICE_DATA(&rt2500usb_ops) },
  1593. { USB_DEVICE(0x13b1, 0x001a), USB_DEVICE_DATA(&rt2500usb_ops) },
  1594. /* Conceptronic */
  1595. { USB_DEVICE(0x14b2, 0x3c02), USB_DEVICE_DATA(&rt2500usb_ops) },
  1596. /* D-LINK */
  1597. { USB_DEVICE(0x2001, 0x3c00), USB_DEVICE_DATA(&rt2500usb_ops) },
  1598. /* Gigabyte */
  1599. { USB_DEVICE(0x1044, 0x8001), USB_DEVICE_DATA(&rt2500usb_ops) },
  1600. { USB_DEVICE(0x1044, 0x8007), USB_DEVICE_DATA(&rt2500usb_ops) },
  1601. /* Hercules */
  1602. { USB_DEVICE(0x06f8, 0xe000), USB_DEVICE_DATA(&rt2500usb_ops) },
  1603. /* Melco */
  1604. { USB_DEVICE(0x0411, 0x0066), USB_DEVICE_DATA(&rt2500usb_ops) },
  1605. { USB_DEVICE(0x0411, 0x0067), USB_DEVICE_DATA(&rt2500usb_ops) },
  1606. { USB_DEVICE(0x0411, 0x008b), USB_DEVICE_DATA(&rt2500usb_ops) },
  1607. { USB_DEVICE(0x0411, 0x0097), USB_DEVICE_DATA(&rt2500usb_ops) },
  1608. /* MSI */
  1609. { USB_DEVICE(0x0db0, 0x6861), USB_DEVICE_DATA(&rt2500usb_ops) },
  1610. { USB_DEVICE(0x0db0, 0x6865), USB_DEVICE_DATA(&rt2500usb_ops) },
  1611. { USB_DEVICE(0x0db0, 0x6869), USB_DEVICE_DATA(&rt2500usb_ops) },
  1612. /* Ralink */
  1613. { USB_DEVICE(0x148f, 0x1706), USB_DEVICE_DATA(&rt2500usb_ops) },
  1614. { USB_DEVICE(0x148f, 0x2570), USB_DEVICE_DATA(&rt2500usb_ops) },
  1615. { USB_DEVICE(0x148f, 0x2573), USB_DEVICE_DATA(&rt2500usb_ops) },
  1616. { USB_DEVICE(0x148f, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
  1617. /* Siemens */
  1618. { USB_DEVICE(0x0681, 0x3c06), USB_DEVICE_DATA(&rt2500usb_ops) },
  1619. /* SMC */
  1620. { USB_DEVICE(0x0707, 0xee13), USB_DEVICE_DATA(&rt2500usb_ops) },
  1621. /* Spairon */
  1622. { USB_DEVICE(0x114b, 0x0110), USB_DEVICE_DATA(&rt2500usb_ops) },
  1623. /* Trust */
  1624. { USB_DEVICE(0x0eb0, 0x9020), USB_DEVICE_DATA(&rt2500usb_ops) },
  1625. /* Zinwell */
  1626. { USB_DEVICE(0x5a57, 0x0260), USB_DEVICE_DATA(&rt2500usb_ops) },
  1627. { 0, }
  1628. };
  1629. MODULE_AUTHOR(DRV_PROJECT);
  1630. MODULE_VERSION(DRV_VERSION);
  1631. MODULE_DESCRIPTION("Ralink RT2500 USB Wireless LAN driver.");
  1632. MODULE_SUPPORTED_DEVICE("Ralink RT2570 USB chipset based cards");
  1633. MODULE_DEVICE_TABLE(usb, rt2500usb_device_table);
  1634. MODULE_LICENSE("GPL");
  1635. static struct usb_driver rt2500usb_driver = {
  1636. .name = KBUILD_MODNAME,
  1637. .id_table = rt2500usb_device_table,
  1638. .probe = rt2x00usb_probe,
  1639. .disconnect = rt2x00usb_disconnect,
  1640. .suspend = rt2x00usb_suspend,
  1641. .resume = rt2x00usb_resume,
  1642. };
  1643. static int __init rt2500usb_init(void)
  1644. {
  1645. return usb_register(&rt2500usb_driver);
  1646. }
  1647. static void __exit rt2500usb_exit(void)
  1648. {
  1649. usb_deregister(&rt2500usb_driver);
  1650. }
  1651. module_init(rt2500usb_init);
  1652. module_exit(rt2500usb_exit);