zd_rf_uw2453.c 15 KB

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