zd_rf_uw2453.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /* ZD1211 USB-WLAN driver for Linux
  2. *
  3. * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
  4. * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/slab.h>
  22. #include "zd_rf.h"
  23. #include "zd_usb.h"
  24. #include "zd_chip.h"
  25. /* This RF programming code is based upon the code found in v2.16.0.0 of the
  26. * ZyDAS vendor driver. Unlike other RF's, Ubec publish full technical specs
  27. * for this RF on their website, so we're able to understand more than
  28. * usual as to what is going on. Thumbs up for Ubec for doing that. */
  29. /* The 3-wire serial interface provides access to 8 write-only registers.
  30. * The data format is a 4 bit register address followed by a 20 bit value. */
  31. #define UW2453_REGWRITE(reg, val) ((((reg) & 0xf) << 20) | ((val) & 0xfffff))
  32. /* For channel tuning, we have to configure registers 1 (synthesizer), 2 (synth
  33. * fractional divide ratio) and 3 (VCO config).
  34. *
  35. * We configure the RF to produce an interrupt when the PLL is locked onto
  36. * the configured frequency. During initialization, we run through a variety
  37. * of different VCO configurations on channel 1 until we detect a PLL lock.
  38. * When this happens, we remember which VCO configuration produced the lock
  39. * and use it later. Actually, we use the configuration *after* the one that
  40. * produced the lock, which seems odd, but it works.
  41. *
  42. * If we do not see a PLL lock on any standard VCO config, we fall back on an
  43. * autocal configuration, which has a fixed (as opposed to per-channel) VCO
  44. * config and different synth values from the standard set (divide ratio
  45. * is still shared with the standard set). */
  46. /* The per-channel synth values for all standard VCO configurations. These get
  47. * written to register 1. */
  48. static const u8 uw2453_std_synth[] = {
  49. RF_CHANNEL( 1) = 0x47,
  50. RF_CHANNEL( 2) = 0x47,
  51. RF_CHANNEL( 3) = 0x67,
  52. RF_CHANNEL( 4) = 0x67,
  53. RF_CHANNEL( 5) = 0x67,
  54. RF_CHANNEL( 6) = 0x67,
  55. RF_CHANNEL( 7) = 0x57,
  56. RF_CHANNEL( 8) = 0x57,
  57. RF_CHANNEL( 9) = 0x57,
  58. RF_CHANNEL(10) = 0x57,
  59. RF_CHANNEL(11) = 0x77,
  60. RF_CHANNEL(12) = 0x77,
  61. RF_CHANNEL(13) = 0x77,
  62. RF_CHANNEL(14) = 0x4f,
  63. };
  64. /* This table stores the synthesizer fractional divide ratio for *all* VCO
  65. * configurations (both standard and autocal). These get written to register 2.
  66. */
  67. static const u16 uw2453_synth_divide[] = {
  68. RF_CHANNEL( 1) = 0x999,
  69. RF_CHANNEL( 2) = 0x99b,
  70. RF_CHANNEL( 3) = 0x998,
  71. RF_CHANNEL( 4) = 0x99a,
  72. RF_CHANNEL( 5) = 0x999,
  73. RF_CHANNEL( 6) = 0x99b,
  74. RF_CHANNEL( 7) = 0x998,
  75. RF_CHANNEL( 8) = 0x99a,
  76. RF_CHANNEL( 9) = 0x999,
  77. RF_CHANNEL(10) = 0x99b,
  78. RF_CHANNEL(11) = 0x998,
  79. RF_CHANNEL(12) = 0x99a,
  80. RF_CHANNEL(13) = 0x999,
  81. RF_CHANNEL(14) = 0xccc,
  82. };
  83. /* Here is the data for all the standard VCO configurations. We shrink our
  84. * table a little by observing that both channels in a consecutive pair share
  85. * the same value. We also observe that the high 4 bits ([0:3] in the specs)
  86. * are all 'Reserved' and are always set to 0x4 - we chop them off in the data
  87. * below. */
  88. #define CHAN_TO_PAIRIDX(a) ((a - 1) / 2)
  89. #define RF_CHANPAIR(a,b) [CHAN_TO_PAIRIDX(a)]
  90. static const u16 uw2453_std_vco_cfg[][7] = {
  91. { /* table 1 */
  92. RF_CHANPAIR( 1, 2) = 0x664d,
  93. RF_CHANPAIR( 3, 4) = 0x604d,
  94. RF_CHANPAIR( 5, 6) = 0x6675,
  95. RF_CHANPAIR( 7, 8) = 0x6475,
  96. RF_CHANPAIR( 9, 10) = 0x6655,
  97. RF_CHANPAIR(11, 12) = 0x6455,
  98. RF_CHANPAIR(13, 14) = 0x6665,
  99. },
  100. { /* table 2 */
  101. RF_CHANPAIR( 1, 2) = 0x666d,
  102. RF_CHANPAIR( 3, 4) = 0x606d,
  103. RF_CHANPAIR( 5, 6) = 0x664d,
  104. RF_CHANPAIR( 7, 8) = 0x644d,
  105. RF_CHANPAIR( 9, 10) = 0x6675,
  106. RF_CHANPAIR(11, 12) = 0x6475,
  107. RF_CHANPAIR(13, 14) = 0x6655,
  108. },
  109. { /* table 3 */
  110. RF_CHANPAIR( 1, 2) = 0x665d,
  111. RF_CHANPAIR( 3, 4) = 0x605d,
  112. RF_CHANPAIR( 5, 6) = 0x666d,
  113. RF_CHANPAIR( 7, 8) = 0x646d,
  114. RF_CHANPAIR( 9, 10) = 0x664d,
  115. RF_CHANPAIR(11, 12) = 0x644d,
  116. RF_CHANPAIR(13, 14) = 0x6675,
  117. },
  118. { /* table 4 */
  119. RF_CHANPAIR( 1, 2) = 0x667d,
  120. RF_CHANPAIR( 3, 4) = 0x607d,
  121. RF_CHANPAIR( 5, 6) = 0x665d,
  122. RF_CHANPAIR( 7, 8) = 0x645d,
  123. RF_CHANPAIR( 9, 10) = 0x666d,
  124. RF_CHANPAIR(11, 12) = 0x646d,
  125. RF_CHANPAIR(13, 14) = 0x664d,
  126. },
  127. { /* table 5 */
  128. RF_CHANPAIR( 1, 2) = 0x6643,
  129. RF_CHANPAIR( 3, 4) = 0x6043,
  130. RF_CHANPAIR( 5, 6) = 0x667d,
  131. RF_CHANPAIR( 7, 8) = 0x647d,
  132. RF_CHANPAIR( 9, 10) = 0x665d,
  133. RF_CHANPAIR(11, 12) = 0x645d,
  134. RF_CHANPAIR(13, 14) = 0x666d,
  135. },
  136. { /* table 6 */
  137. RF_CHANPAIR( 1, 2) = 0x6663,
  138. RF_CHANPAIR( 3, 4) = 0x6063,
  139. RF_CHANPAIR( 5, 6) = 0x6643,
  140. RF_CHANPAIR( 7, 8) = 0x6443,
  141. RF_CHANPAIR( 9, 10) = 0x667d,
  142. RF_CHANPAIR(11, 12) = 0x647d,
  143. RF_CHANPAIR(13, 14) = 0x665d,
  144. },
  145. { /* table 7 */
  146. RF_CHANPAIR( 1, 2) = 0x6653,
  147. RF_CHANPAIR( 3, 4) = 0x6053,
  148. RF_CHANPAIR( 5, 6) = 0x6663,
  149. RF_CHANPAIR( 7, 8) = 0x6463,
  150. RF_CHANPAIR( 9, 10) = 0x6643,
  151. RF_CHANPAIR(11, 12) = 0x6443,
  152. RF_CHANPAIR(13, 14) = 0x667d,
  153. },
  154. { /* table 8 */
  155. RF_CHANPAIR( 1, 2) = 0x6673,
  156. RF_CHANPAIR( 3, 4) = 0x6073,
  157. RF_CHANPAIR( 5, 6) = 0x6653,
  158. RF_CHANPAIR( 7, 8) = 0x6453,
  159. RF_CHANPAIR( 9, 10) = 0x6663,
  160. RF_CHANPAIR(11, 12) = 0x6463,
  161. RF_CHANPAIR(13, 14) = 0x6643,
  162. },
  163. { /* table 9 */
  164. RF_CHANPAIR( 1, 2) = 0x664b,
  165. RF_CHANPAIR( 3, 4) = 0x604b,
  166. RF_CHANPAIR( 5, 6) = 0x6673,
  167. RF_CHANPAIR( 7, 8) = 0x6473,
  168. RF_CHANPAIR( 9, 10) = 0x6653,
  169. RF_CHANPAIR(11, 12) = 0x6453,
  170. RF_CHANPAIR(13, 14) = 0x6663,
  171. },
  172. { /* table 10 */
  173. RF_CHANPAIR( 1, 2) = 0x666b,
  174. RF_CHANPAIR( 3, 4) = 0x606b,
  175. RF_CHANPAIR( 5, 6) = 0x664b,
  176. RF_CHANPAIR( 7, 8) = 0x644b,
  177. RF_CHANPAIR( 9, 10) = 0x6673,
  178. RF_CHANPAIR(11, 12) = 0x6473,
  179. RF_CHANPAIR(13, 14) = 0x6653,
  180. },
  181. { /* table 11 */
  182. RF_CHANPAIR( 1, 2) = 0x665b,
  183. RF_CHANPAIR( 3, 4) = 0x605b,
  184. RF_CHANPAIR( 5, 6) = 0x666b,
  185. RF_CHANPAIR( 7, 8) = 0x646b,
  186. RF_CHANPAIR( 9, 10) = 0x664b,
  187. RF_CHANPAIR(11, 12) = 0x644b,
  188. RF_CHANPAIR(13, 14) = 0x6673,
  189. },
  190. };
  191. /* The per-channel synth values for autocal. These get written to register 1. */
  192. static const u16 uw2453_autocal_synth[] = {
  193. RF_CHANNEL( 1) = 0x6847,
  194. RF_CHANNEL( 2) = 0x6847,
  195. RF_CHANNEL( 3) = 0x6867,
  196. RF_CHANNEL( 4) = 0x6867,
  197. RF_CHANNEL( 5) = 0x6867,
  198. RF_CHANNEL( 6) = 0x6867,
  199. RF_CHANNEL( 7) = 0x6857,
  200. RF_CHANNEL( 8) = 0x6857,
  201. RF_CHANNEL( 9) = 0x6857,
  202. RF_CHANNEL(10) = 0x6857,
  203. RF_CHANNEL(11) = 0x6877,
  204. RF_CHANNEL(12) = 0x6877,
  205. RF_CHANNEL(13) = 0x6877,
  206. RF_CHANNEL(14) = 0x684f,
  207. };
  208. /* The VCO configuration for autocal (all channels) */
  209. static const u16 UW2453_AUTOCAL_VCO_CFG = 0x6662;
  210. /* TX gain settings. The array index corresponds to the TX power integration
  211. * values found in the EEPROM. The values get written to register 7. */
  212. static u32 uw2453_txgain[] = {
  213. [0x00] = 0x0e313,
  214. [0x01] = 0x0fb13,
  215. [0x02] = 0x0e093,
  216. [0x03] = 0x0f893,
  217. [0x04] = 0x0ea93,
  218. [0x05] = 0x1f093,
  219. [0x06] = 0x1f493,
  220. [0x07] = 0x1f693,
  221. [0x08] = 0x1f393,
  222. [0x09] = 0x1f35b,
  223. [0x0a] = 0x1e6db,
  224. [0x0b] = 0x1ff3f,
  225. [0x0c] = 0x1ffff,
  226. [0x0d] = 0x361d7,
  227. [0x0e] = 0x37fbf,
  228. [0x0f] = 0x3ff8b,
  229. [0x10] = 0x3ff33,
  230. [0x11] = 0x3fb3f,
  231. [0x12] = 0x3ffff,
  232. };
  233. /* RF-specific structure */
  234. struct uw2453_priv {
  235. /* index into synth/VCO config tables where PLL lock was found
  236. * -1 means autocal */
  237. int config;
  238. };
  239. #define UW2453_PRIV(rf) ((struct uw2453_priv *) (rf)->priv)
  240. static int uw2453_synth_set_channel(struct zd_chip *chip, int channel,
  241. bool autocal)
  242. {
  243. int r;
  244. int idx = channel - 1;
  245. u32 val;
  246. if (autocal)
  247. val = UW2453_REGWRITE(1, uw2453_autocal_synth[idx]);
  248. else
  249. val = UW2453_REGWRITE(1, uw2453_std_synth[idx]);
  250. r = zd_rfwrite_locked(chip, val, RF_RV_BITS);
  251. if (r)
  252. return r;
  253. return zd_rfwrite_locked(chip,
  254. UW2453_REGWRITE(2, uw2453_synth_divide[idx]), RF_RV_BITS);
  255. }
  256. static int uw2453_write_vco_cfg(struct zd_chip *chip, u16 value)
  257. {
  258. /* vendor driver always sets these upper bits even though the specs say
  259. * they are reserved */
  260. u32 val = 0x40000 | value;
  261. return zd_rfwrite_locked(chip, UW2453_REGWRITE(3, val), RF_RV_BITS);
  262. }
  263. static int uw2453_init_mode(struct zd_chip *chip)
  264. {
  265. static const u32 rv[] = {
  266. UW2453_REGWRITE(0, 0x25f98), /* enter IDLE mode */
  267. UW2453_REGWRITE(0, 0x25f9a), /* enter CAL_VCO mode */
  268. UW2453_REGWRITE(0, 0x25f94), /* enter RX/TX mode */
  269. UW2453_REGWRITE(0, 0x27fd4), /* power down RSSI circuit */
  270. };
  271. return zd_rfwritev_locked(chip, rv, ARRAY_SIZE(rv), RF_RV_BITS);
  272. }
  273. static int uw2453_set_tx_gain_level(struct zd_chip *chip, int channel)
  274. {
  275. u8 int_value = chip->pwr_int_values[channel - 1];
  276. if (int_value >= ARRAY_SIZE(uw2453_txgain)) {
  277. dev_dbg_f(zd_chip_dev(chip), "can't configure TX gain for "
  278. "int value %x on channel %d\n", int_value, channel);
  279. return 0;
  280. }
  281. return zd_rfwrite_locked(chip,
  282. UW2453_REGWRITE(7, uw2453_txgain[int_value]), RF_RV_BITS);
  283. }
  284. static int uw2453_init_hw(struct zd_rf *rf)
  285. {
  286. int i, r;
  287. int found_config = -1;
  288. u16 intr_status;
  289. struct zd_chip *chip = zd_rf_to_chip(rf);
  290. static const struct zd_ioreq16 ioreqs[] = {
  291. { ZD_CR10, 0x89 }, { ZD_CR15, 0x20 },
  292. { ZD_CR17, 0x28 }, /* 6112 no change */
  293. { ZD_CR23, 0x38 }, { ZD_CR24, 0x20 }, { ZD_CR26, 0x93 },
  294. { ZD_CR27, 0x15 }, { ZD_CR28, 0x3e }, { ZD_CR29, 0x00 },
  295. { ZD_CR33, 0x28 }, { ZD_CR34, 0x30 },
  296. { ZD_CR35, 0x43 }, /* 6112 3e->43 */
  297. { ZD_CR41, 0x24 }, { ZD_CR44, 0x32 },
  298. { ZD_CR46, 0x92 }, /* 6112 96->92 */
  299. { ZD_CR47, 0x1e },
  300. { ZD_CR48, 0x04 }, /* 5602 Roger */
  301. { ZD_CR49, 0xfa }, { ZD_CR79, 0x58 }, { ZD_CR80, 0x30 },
  302. { ZD_CR81, 0x30 }, { ZD_CR87, 0x0a }, { ZD_CR89, 0x04 },
  303. { ZD_CR91, 0x00 }, { ZD_CR92, 0x0a }, { ZD_CR98, 0x8d },
  304. { ZD_CR99, 0x28 }, { ZD_CR100, 0x02 },
  305. { ZD_CR101, 0x09 }, /* 6112 13->1f 6220 1f->13 6407 13->9 */
  306. { ZD_CR102, 0x27 },
  307. { ZD_CR106, 0x1c }, /* 5d07 5112 1f->1c 6220 1c->1f
  308. * 6221 1f->1c
  309. */
  310. { ZD_CR107, 0x1c }, /* 6220 1c->1a 5221 1a->1c */
  311. { ZD_CR109, 0x13 },
  312. { ZD_CR110, 0x1f }, /* 6112 13->1f 6221 1f->13 6407 13->0x09 */
  313. { ZD_CR111, 0x13 }, { ZD_CR112, 0x1f }, { ZD_CR113, 0x27 },
  314. { ZD_CR114, 0x23 }, /* 6221 27->23 */
  315. { ZD_CR115, 0x24 }, /* 6112 24->1c 6220 1c->24 */
  316. { ZD_CR116, 0x24 }, /* 6220 1c->24 */
  317. { ZD_CR117, 0xfa }, /* 6112 fa->f8 6220 f8->f4 6220 f4->fa */
  318. { ZD_CR118, 0xf0 }, /* 5d07 6112 f0->f2 6220 f2->f0 */
  319. { ZD_CR119, 0x1a }, /* 6112 1a->10 6220 10->14 6220 14->1a */
  320. { ZD_CR120, 0x4f },
  321. { ZD_CR121, 0x1f }, /* 6220 4f->1f */
  322. { ZD_CR122, 0xf0 }, { ZD_CR123, 0x57 }, { ZD_CR125, 0xad },
  323. { ZD_CR126, 0x6c }, { ZD_CR127, 0x03 },
  324. { ZD_CR128, 0x14 }, /* 6302 12->11 */
  325. { ZD_CR129, 0x12 }, /* 6301 10->0f */
  326. { ZD_CR130, 0x10 }, { ZD_CR137, 0x50 }, { ZD_CR138, 0xa8 },
  327. { ZD_CR144, 0xac }, { ZD_CR146, 0x20 }, { ZD_CR252, 0xff },
  328. { ZD_CR253, 0xff },
  329. };
  330. static const u32 rv[] = {
  331. UW2453_REGWRITE(4, 0x2b), /* configure receiver gain */
  332. UW2453_REGWRITE(5, 0x19e4f), /* configure transmitter gain */
  333. UW2453_REGWRITE(6, 0xf81ad), /* enable RX/TX filter tuning */
  334. UW2453_REGWRITE(7, 0x3fffe), /* disable TX gain in test mode */
  335. /* enter CAL_FIL mode, TX gain set by registers, RX gain set by pins,
  336. * RSSI circuit powered down, reduced RSSI range */
  337. UW2453_REGWRITE(0, 0x25f9c), /* 5d01 cal_fil */
  338. /* synthesizer configuration for channel 1 */
  339. UW2453_REGWRITE(1, 0x47),
  340. UW2453_REGWRITE(2, 0x999),
  341. /* disable manual VCO band selection */
  342. UW2453_REGWRITE(3, 0x7602),
  343. /* enable manual VCO band selection, configure current level */
  344. UW2453_REGWRITE(3, 0x46063),
  345. };
  346. r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  347. if (r)
  348. return r;
  349. r = zd_rfwritev_locked(chip, rv, ARRAY_SIZE(rv), RF_RV_BITS);
  350. if (r)
  351. return r;
  352. r = uw2453_init_mode(chip);
  353. if (r)
  354. return r;
  355. /* Try all standard VCO configuration settings on channel 1 */
  356. for (i = 0; i < ARRAY_SIZE(uw2453_std_vco_cfg) - 1; i++) {
  357. /* Configure synthesizer for channel 1 */
  358. r = uw2453_synth_set_channel(chip, 1, false);
  359. if (r)
  360. return r;
  361. /* Write VCO config */
  362. r = uw2453_write_vco_cfg(chip, uw2453_std_vco_cfg[i][0]);
  363. if (r)
  364. return r;
  365. /* ack interrupt event */
  366. r = zd_iowrite16_locked(chip, 0x0f, UW2453_INTR_REG);
  367. if (r)
  368. return r;
  369. /* check interrupt status */
  370. r = zd_ioread16_locked(chip, &intr_status, UW2453_INTR_REG);
  371. if (r)
  372. return r;
  373. if (!(intr_status & 0xf)) {
  374. dev_dbg_f(zd_chip_dev(chip),
  375. "PLL locked on configuration %d\n", i);
  376. found_config = i;
  377. break;
  378. }
  379. }
  380. if (found_config == -1) {
  381. /* autocal */
  382. dev_dbg_f(zd_chip_dev(chip),
  383. "PLL did not lock, using autocal\n");
  384. r = uw2453_synth_set_channel(chip, 1, true);
  385. if (r)
  386. return r;
  387. r = uw2453_write_vco_cfg(chip, UW2453_AUTOCAL_VCO_CFG);
  388. if (r)
  389. return r;
  390. }
  391. /* To match the vendor driver behaviour, we use the configuration after
  392. * the one that produced a lock. */
  393. UW2453_PRIV(rf)->config = found_config + 1;
  394. return zd_iowrite16_locked(chip, 0x06, ZD_CR203);
  395. }
  396. static int uw2453_set_channel(struct zd_rf *rf, u8 channel)
  397. {
  398. int r;
  399. u16 vco_cfg;
  400. int config = UW2453_PRIV(rf)->config;
  401. bool autocal = (config == -1);
  402. struct zd_chip *chip = zd_rf_to_chip(rf);
  403. static const struct zd_ioreq16 ioreqs[] = {
  404. { ZD_CR80, 0x30 }, { ZD_CR81, 0x30 }, { ZD_CR79, 0x58 },
  405. { ZD_CR12, 0xf0 }, { ZD_CR77, 0x1b }, { ZD_CR78, 0x58 },
  406. };
  407. r = uw2453_synth_set_channel(chip, channel, autocal);
  408. if (r)
  409. return r;
  410. if (autocal)
  411. vco_cfg = UW2453_AUTOCAL_VCO_CFG;
  412. else
  413. vco_cfg = uw2453_std_vco_cfg[config][CHAN_TO_PAIRIDX(channel)];
  414. r = uw2453_write_vco_cfg(chip, vco_cfg);
  415. if (r)
  416. return r;
  417. r = uw2453_init_mode(chip);
  418. if (r)
  419. return r;
  420. r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  421. if (r)
  422. return r;
  423. r = uw2453_set_tx_gain_level(chip, channel);
  424. if (r)
  425. return r;
  426. return zd_iowrite16_locked(chip, 0x06, ZD_CR203);
  427. }
  428. static int uw2453_switch_radio_on(struct zd_rf *rf)
  429. {
  430. int r;
  431. struct zd_chip *chip = zd_rf_to_chip(rf);
  432. struct zd_ioreq16 ioreqs[] = {
  433. { ZD_CR11, 0x00 }, { ZD_CR251, 0x3f },
  434. };
  435. /* enter RXTX mode */
  436. r = zd_rfwrite_locked(chip, UW2453_REGWRITE(0, 0x25f94), RF_RV_BITS);
  437. if (r)
  438. return r;
  439. if (zd_chip_is_zd1211b(chip))
  440. ioreqs[1].value = 0x7f;
  441. return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  442. }
  443. static int uw2453_switch_radio_off(struct zd_rf *rf)
  444. {
  445. int r;
  446. struct zd_chip *chip = zd_rf_to_chip(rf);
  447. static const struct zd_ioreq16 ioreqs[] = {
  448. { ZD_CR11, 0x04 }, { ZD_CR251, 0x2f },
  449. };
  450. /* enter IDLE mode */
  451. /* FIXME: shouldn't we go to SLEEP? sent email to zydas */
  452. r = zd_rfwrite_locked(chip, UW2453_REGWRITE(0, 0x25f90), RF_RV_BITS);
  453. if (r)
  454. return r;
  455. return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  456. }
  457. static void uw2453_clear(struct zd_rf *rf)
  458. {
  459. kfree(rf->priv);
  460. }
  461. int zd_rf_init_uw2453(struct zd_rf *rf)
  462. {
  463. rf->init_hw = uw2453_init_hw;
  464. rf->set_channel = uw2453_set_channel;
  465. rf->switch_radio_on = uw2453_switch_radio_on;
  466. rf->switch_radio_off = uw2453_switch_radio_off;
  467. rf->patch_6m_band_edge = zd_rf_generic_patch_6m;
  468. rf->clear = uw2453_clear;
  469. /* we have our own TX integration code */
  470. rf->update_channel_int = 0;
  471. rf->priv = kmalloc(sizeof(struct uw2453_priv), GFP_KERNEL);
  472. if (rf->priv == NULL)
  473. return -ENOMEM;
  474. return 0;
  475. }