zd_rf_uw2453.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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 "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. { CR10, 0x89 }, { CR15, 0x20 },
  291. { CR17, 0x28 }, /* 6112 no change */
  292. { CR23, 0x38 }, { CR24, 0x20 }, { CR26, 0x93 },
  293. { CR27, 0x15 }, { CR28, 0x3e }, { CR29, 0x00 },
  294. { CR33, 0x28 }, { CR34, 0x30 },
  295. { CR35, 0x43 }, /* 6112 3e->43 */
  296. { CR41, 0x24 }, { CR44, 0x32 },
  297. { CR46, 0x92 }, /* 6112 96->92 */
  298. { CR47, 0x1e },
  299. { CR48, 0x04 }, /* 5602 Roger */
  300. { CR49, 0xfa }, { CR79, 0x58 }, { CR80, 0x30 },
  301. { CR81, 0x30 }, { CR87, 0x0a }, { CR89, 0x04 },
  302. { CR91, 0x00 }, { CR92, 0x0a }, { CR98, 0x8d },
  303. { CR99, 0x28 }, { CR100, 0x02 },
  304. { CR101, 0x09 }, /* 6112 13->1f 6220 1f->13 6407 13->9 */
  305. { CR102, 0x27 },
  306. { CR106, 0x1c }, /* 5d07 5112 1f->1c 6220 1c->1f 6221 1f->1c */
  307. { CR107, 0x1c }, /* 6220 1c->1a 5221 1a->1c */
  308. { CR109, 0x13 },
  309. { CR110, 0x1f }, /* 6112 13->1f 6221 1f->13 6407 13->0x09 */
  310. { CR111, 0x13 }, { CR112, 0x1f }, { CR113, 0x27 },
  311. { CR114, 0x23 }, /* 6221 27->23 */
  312. { CR115, 0x24 }, /* 6112 24->1c 6220 1c->24 */
  313. { CR116, 0x24 }, /* 6220 1c->24 */
  314. { CR117, 0xfa }, /* 6112 fa->f8 6220 f8->f4 6220 f4->fa */
  315. { CR118, 0xf0 }, /* 5d07 6112 f0->f2 6220 f2->f0 */
  316. { CR119, 0x1a }, /* 6112 1a->10 6220 10->14 6220 14->1a */
  317. { CR120, 0x4f },
  318. { CR121, 0x1f }, /* 6220 4f->1f */
  319. { CR122, 0xf0 }, { CR123, 0x57 }, { CR125, 0xad },
  320. { CR126, 0x6c }, { CR127, 0x03 },
  321. { CR128, 0x14 }, /* 6302 12->11 */
  322. { CR129, 0x12 }, /* 6301 10->0f */
  323. { CR130, 0x10 }, { CR137, 0x50 }, { CR138, 0xa8 },
  324. { CR144, 0xac }, { CR146, 0x20 }, { CR252, 0xff },
  325. { CR253, 0xff },
  326. };
  327. static const u32 rv[] = {
  328. UW2453_REGWRITE(4, 0x2b), /* configure reciever gain */
  329. UW2453_REGWRITE(5, 0x19e4f), /* configure transmitter gain */
  330. UW2453_REGWRITE(6, 0xf81ad), /* enable RX/TX filter tuning */
  331. UW2453_REGWRITE(7, 0x3fffe), /* disable TX gain in test mode */
  332. /* enter CAL_FIL mode, TX gain set by registers, RX gain set by pins,
  333. * RSSI circuit powered down, reduced RSSI range */
  334. UW2453_REGWRITE(0, 0x25f9c), /* 5d01 cal_fil */
  335. /* synthesizer configuration for channel 1 */
  336. UW2453_REGWRITE(1, 0x47),
  337. UW2453_REGWRITE(2, 0x999),
  338. /* disable manual VCO band selection */
  339. UW2453_REGWRITE(3, 0x7602),
  340. /* enable manual VCO band selection, configure current level */
  341. UW2453_REGWRITE(3, 0x46063),
  342. };
  343. r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  344. if (r)
  345. return r;
  346. r = zd_rfwritev_locked(chip, rv, ARRAY_SIZE(rv), RF_RV_BITS);
  347. if (r)
  348. return r;
  349. r = uw2453_init_mode(chip);
  350. if (r)
  351. return r;
  352. /* Try all standard VCO configuration settings on channel 1 */
  353. for (i = 0; i < ARRAY_SIZE(uw2453_std_vco_cfg) - 1; i++) {
  354. /* Configure synthesizer for channel 1 */
  355. r = uw2453_synth_set_channel(chip, 1, false);
  356. if (r)
  357. return r;
  358. /* Write VCO config */
  359. r = uw2453_write_vco_cfg(chip, uw2453_std_vco_cfg[i][0]);
  360. if (r)
  361. return r;
  362. /* ack interrupt event */
  363. r = zd_iowrite16_locked(chip, 0x0f, UW2453_INTR_REG);
  364. if (r)
  365. return r;
  366. /* check interrupt status */
  367. r = zd_ioread16_locked(chip, &intr_status, UW2453_INTR_REG);
  368. if (r)
  369. return r;
  370. if (!(intr_status & 0xf)) {
  371. dev_dbg_f(zd_chip_dev(chip),
  372. "PLL locked on configuration %d\n", i);
  373. found_config = i;
  374. break;
  375. }
  376. }
  377. if (found_config == -1) {
  378. /* autocal */
  379. dev_dbg_f(zd_chip_dev(chip),
  380. "PLL did not lock, using autocal\n");
  381. r = uw2453_synth_set_channel(chip, 1, true);
  382. if (r)
  383. return r;
  384. r = uw2453_write_vco_cfg(chip, UW2453_AUTOCAL_VCO_CFG);
  385. if (r)
  386. return r;
  387. }
  388. /* To match the vendor driver behaviour, we use the configuration after
  389. * the one that produced a lock. */
  390. UW2453_PRIV(rf)->config = found_config + 1;
  391. return zd_iowrite16_locked(chip, 0x06, CR203);
  392. }
  393. static int uw2453_set_channel(struct zd_rf *rf, u8 channel)
  394. {
  395. int r;
  396. u16 vco_cfg;
  397. int config = UW2453_PRIV(rf)->config;
  398. bool autocal = (config == -1);
  399. struct zd_chip *chip = zd_rf_to_chip(rf);
  400. static const struct zd_ioreq16 ioreqs[] = {
  401. { CR80, 0x30 }, { CR81, 0x30 }, { CR79, 0x58 },
  402. { CR12, 0xf0 }, { CR77, 0x1b }, { CR78, 0x58 },
  403. };
  404. r = uw2453_synth_set_channel(chip, channel, autocal);
  405. if (r)
  406. return r;
  407. if (autocal)
  408. vco_cfg = UW2453_AUTOCAL_VCO_CFG;
  409. else
  410. vco_cfg = uw2453_std_vco_cfg[config][CHAN_TO_PAIRIDX(channel)];
  411. r = uw2453_write_vco_cfg(chip, vco_cfg);
  412. if (r)
  413. return r;
  414. r = uw2453_init_mode(chip);
  415. if (r)
  416. return r;
  417. r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  418. if (r)
  419. return r;
  420. r = uw2453_set_tx_gain_level(chip, channel);
  421. if (r)
  422. return r;
  423. return zd_iowrite16_locked(chip, 0x06, CR203);
  424. }
  425. static int uw2453_switch_radio_on(struct zd_rf *rf)
  426. {
  427. int r;
  428. struct zd_chip *chip = zd_rf_to_chip(rf);
  429. struct zd_ioreq16 ioreqs[] = {
  430. { CR11, 0x00 }, { CR251, 0x3f },
  431. };
  432. /* enter RXTX mode */
  433. r = zd_rfwrite_locked(chip, UW2453_REGWRITE(0, 0x25f94), RF_RV_BITS);
  434. if (r)
  435. return r;
  436. if (zd_chip_is_zd1211b(chip))
  437. ioreqs[1].value = 0x7f;
  438. return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  439. }
  440. static int uw2453_switch_radio_off(struct zd_rf *rf)
  441. {
  442. int r;
  443. struct zd_chip *chip = zd_rf_to_chip(rf);
  444. static const struct zd_ioreq16 ioreqs[] = {
  445. { CR11, 0x04 }, { CR251, 0x2f },
  446. };
  447. /* enter IDLE mode */
  448. /* FIXME: shouldn't we go to SLEEP? sent email to zydas */
  449. r = zd_rfwrite_locked(chip, UW2453_REGWRITE(0, 0x25f90), RF_RV_BITS);
  450. if (r)
  451. return r;
  452. return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
  453. }
  454. static void uw2453_clear(struct zd_rf *rf)
  455. {
  456. kfree(rf->priv);
  457. }
  458. int zd_rf_init_uw2453(struct zd_rf *rf)
  459. {
  460. rf->init_hw = uw2453_init_hw;
  461. rf->set_channel = uw2453_set_channel;
  462. rf->switch_radio_on = uw2453_switch_radio_on;
  463. rf->switch_radio_off = uw2453_switch_radio_off;
  464. rf->patch_6m_band_edge = zd_rf_generic_patch_6m;
  465. rf->clear = uw2453_clear;
  466. /* we have our own TX integration code */
  467. rf->update_channel_int = 0;
  468. rf->priv = kmalloc(sizeof(struct uw2453_priv), GFP_KERNEL);
  469. if (rf->priv == NULL)
  470. return -ENOMEM;
  471. return 0;
  472. }