zd_rf_uw2453.c 15 KB

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