1*1ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
26948300cSKalle Valo /* ZD1211 USB-WLAN driver for Linux
36948300cSKalle Valo *
46948300cSKalle Valo * Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
56948300cSKalle Valo * Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
66948300cSKalle Valo */
76948300cSKalle Valo
86948300cSKalle Valo #include <linux/kernel.h>
96948300cSKalle Valo #include <linux/slab.h>
106948300cSKalle Valo
116948300cSKalle Valo #include "zd_rf.h"
126948300cSKalle Valo #include "zd_usb.h"
136948300cSKalle Valo #include "zd_chip.h"
146948300cSKalle Valo
156948300cSKalle Valo /* This RF programming code is based upon the code found in v2.16.0.0 of the
166948300cSKalle Valo * ZyDAS vendor driver. Unlike other RF's, Ubec publish full technical specs
176948300cSKalle Valo * for this RF on their website, so we're able to understand more than
186948300cSKalle Valo * usual as to what is going on. Thumbs up for Ubec for doing that. */
196948300cSKalle Valo
206948300cSKalle Valo /* The 3-wire serial interface provides access to 8 write-only registers.
216948300cSKalle Valo * The data format is a 4 bit register address followed by a 20 bit value. */
226948300cSKalle Valo #define UW2453_REGWRITE(reg, val) ((((reg) & 0xf) << 20) | ((val) & 0xfffff))
236948300cSKalle Valo
246948300cSKalle Valo /* For channel tuning, we have to configure registers 1 (synthesizer), 2 (synth
256948300cSKalle Valo * fractional divide ratio) and 3 (VCO config).
266948300cSKalle Valo *
276948300cSKalle Valo * We configure the RF to produce an interrupt when the PLL is locked onto
286948300cSKalle Valo * the configured frequency. During initialization, we run through a variety
296948300cSKalle Valo * of different VCO configurations on channel 1 until we detect a PLL lock.
306948300cSKalle Valo * When this happens, we remember which VCO configuration produced the lock
316948300cSKalle Valo * and use it later. Actually, we use the configuration *after* the one that
326948300cSKalle Valo * produced the lock, which seems odd, but it works.
336948300cSKalle Valo *
346948300cSKalle Valo * If we do not see a PLL lock on any standard VCO config, we fall back on an
356948300cSKalle Valo * autocal configuration, which has a fixed (as opposed to per-channel) VCO
366948300cSKalle Valo * config and different synth values from the standard set (divide ratio
376948300cSKalle Valo * is still shared with the standard set). */
386948300cSKalle Valo
396948300cSKalle Valo /* The per-channel synth values for all standard VCO configurations. These get
406948300cSKalle Valo * written to register 1. */
416948300cSKalle Valo static const u8 uw2453_std_synth[] = {
426948300cSKalle Valo RF_CHANNEL( 1) = 0x47,
436948300cSKalle Valo RF_CHANNEL( 2) = 0x47,
446948300cSKalle Valo RF_CHANNEL( 3) = 0x67,
456948300cSKalle Valo RF_CHANNEL( 4) = 0x67,
466948300cSKalle Valo RF_CHANNEL( 5) = 0x67,
476948300cSKalle Valo RF_CHANNEL( 6) = 0x67,
486948300cSKalle Valo RF_CHANNEL( 7) = 0x57,
496948300cSKalle Valo RF_CHANNEL( 8) = 0x57,
506948300cSKalle Valo RF_CHANNEL( 9) = 0x57,
516948300cSKalle Valo RF_CHANNEL(10) = 0x57,
526948300cSKalle Valo RF_CHANNEL(11) = 0x77,
536948300cSKalle Valo RF_CHANNEL(12) = 0x77,
546948300cSKalle Valo RF_CHANNEL(13) = 0x77,
556948300cSKalle Valo RF_CHANNEL(14) = 0x4f,
566948300cSKalle Valo };
576948300cSKalle Valo
586948300cSKalle Valo /* This table stores the synthesizer fractional divide ratio for *all* VCO
596948300cSKalle Valo * configurations (both standard and autocal). These get written to register 2.
606948300cSKalle Valo */
616948300cSKalle Valo static const u16 uw2453_synth_divide[] = {
626948300cSKalle Valo RF_CHANNEL( 1) = 0x999,
636948300cSKalle Valo RF_CHANNEL( 2) = 0x99b,
646948300cSKalle Valo RF_CHANNEL( 3) = 0x998,
656948300cSKalle Valo RF_CHANNEL( 4) = 0x99a,
666948300cSKalle Valo RF_CHANNEL( 5) = 0x999,
676948300cSKalle Valo RF_CHANNEL( 6) = 0x99b,
686948300cSKalle Valo RF_CHANNEL( 7) = 0x998,
696948300cSKalle Valo RF_CHANNEL( 8) = 0x99a,
706948300cSKalle Valo RF_CHANNEL( 9) = 0x999,
716948300cSKalle Valo RF_CHANNEL(10) = 0x99b,
726948300cSKalle Valo RF_CHANNEL(11) = 0x998,
736948300cSKalle Valo RF_CHANNEL(12) = 0x99a,
746948300cSKalle Valo RF_CHANNEL(13) = 0x999,
756948300cSKalle Valo RF_CHANNEL(14) = 0xccc,
766948300cSKalle Valo };
776948300cSKalle Valo
786948300cSKalle Valo /* Here is the data for all the standard VCO configurations. We shrink our
796948300cSKalle Valo * table a little by observing that both channels in a consecutive pair share
806948300cSKalle Valo * the same value. We also observe that the high 4 bits ([0:3] in the specs)
816948300cSKalle Valo * are all 'Reserved' and are always set to 0x4 - we chop them off in the data
826948300cSKalle Valo * below. */
836948300cSKalle Valo #define CHAN_TO_PAIRIDX(a) ((a - 1) / 2)
846948300cSKalle Valo #define RF_CHANPAIR(a,b) [CHAN_TO_PAIRIDX(a)]
856948300cSKalle Valo static const u16 uw2453_std_vco_cfg[][7] = {
866948300cSKalle Valo { /* table 1 */
876948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x664d,
886948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x604d,
896948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x6675,
906948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x6475,
916948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x6655,
926948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x6455,
936948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x6665,
946948300cSKalle Valo },
956948300cSKalle Valo { /* table 2 */
966948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x666d,
976948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x606d,
986948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x664d,
996948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x644d,
1006948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x6675,
1016948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x6475,
1026948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x6655,
1036948300cSKalle Valo },
1046948300cSKalle Valo { /* table 3 */
1056948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x665d,
1066948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x605d,
1076948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x666d,
1086948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x646d,
1096948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x664d,
1106948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x644d,
1116948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x6675,
1126948300cSKalle Valo },
1136948300cSKalle Valo { /* table 4 */
1146948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x667d,
1156948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x607d,
1166948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x665d,
1176948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x645d,
1186948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x666d,
1196948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x646d,
1206948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x664d,
1216948300cSKalle Valo },
1226948300cSKalle Valo { /* table 5 */
1236948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x6643,
1246948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x6043,
1256948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x667d,
1266948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x647d,
1276948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x665d,
1286948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x645d,
1296948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x666d,
1306948300cSKalle Valo },
1316948300cSKalle Valo { /* table 6 */
1326948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x6663,
1336948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x6063,
1346948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x6643,
1356948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x6443,
1366948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x667d,
1376948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x647d,
1386948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x665d,
1396948300cSKalle Valo },
1406948300cSKalle Valo { /* table 7 */
1416948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x6653,
1426948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x6053,
1436948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x6663,
1446948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x6463,
1456948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x6643,
1466948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x6443,
1476948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x667d,
1486948300cSKalle Valo },
1496948300cSKalle Valo { /* table 8 */
1506948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x6673,
1516948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x6073,
1526948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x6653,
1536948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x6453,
1546948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x6663,
1556948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x6463,
1566948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x6643,
1576948300cSKalle Valo },
1586948300cSKalle Valo { /* table 9 */
1596948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x664b,
1606948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x604b,
1616948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x6673,
1626948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x6473,
1636948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x6653,
1646948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x6453,
1656948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x6663,
1666948300cSKalle Valo },
1676948300cSKalle Valo { /* table 10 */
1686948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x666b,
1696948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x606b,
1706948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x664b,
1716948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x644b,
1726948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x6673,
1736948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x6473,
1746948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x6653,
1756948300cSKalle Valo },
1766948300cSKalle Valo { /* table 11 */
1776948300cSKalle Valo RF_CHANPAIR( 1, 2) = 0x665b,
1786948300cSKalle Valo RF_CHANPAIR( 3, 4) = 0x605b,
1796948300cSKalle Valo RF_CHANPAIR( 5, 6) = 0x666b,
1806948300cSKalle Valo RF_CHANPAIR( 7, 8) = 0x646b,
1816948300cSKalle Valo RF_CHANPAIR( 9, 10) = 0x664b,
1826948300cSKalle Valo RF_CHANPAIR(11, 12) = 0x644b,
1836948300cSKalle Valo RF_CHANPAIR(13, 14) = 0x6673,
1846948300cSKalle Valo },
1856948300cSKalle Valo
1866948300cSKalle Valo };
1876948300cSKalle Valo
1886948300cSKalle Valo /* The per-channel synth values for autocal. These get written to register 1. */
1896948300cSKalle Valo static const u16 uw2453_autocal_synth[] = {
1906948300cSKalle Valo RF_CHANNEL( 1) = 0x6847,
1916948300cSKalle Valo RF_CHANNEL( 2) = 0x6847,
1926948300cSKalle Valo RF_CHANNEL( 3) = 0x6867,
1936948300cSKalle Valo RF_CHANNEL( 4) = 0x6867,
1946948300cSKalle Valo RF_CHANNEL( 5) = 0x6867,
1956948300cSKalle Valo RF_CHANNEL( 6) = 0x6867,
1966948300cSKalle Valo RF_CHANNEL( 7) = 0x6857,
1976948300cSKalle Valo RF_CHANNEL( 8) = 0x6857,
1986948300cSKalle Valo RF_CHANNEL( 9) = 0x6857,
1996948300cSKalle Valo RF_CHANNEL(10) = 0x6857,
2006948300cSKalle Valo RF_CHANNEL(11) = 0x6877,
2016948300cSKalle Valo RF_CHANNEL(12) = 0x6877,
2026948300cSKalle Valo RF_CHANNEL(13) = 0x6877,
2036948300cSKalle Valo RF_CHANNEL(14) = 0x684f,
2046948300cSKalle Valo };
2056948300cSKalle Valo
2066948300cSKalle Valo /* The VCO configuration for autocal (all channels) */
2076948300cSKalle Valo static const u16 UW2453_AUTOCAL_VCO_CFG = 0x6662;
2086948300cSKalle Valo
2096948300cSKalle Valo /* TX gain settings. The array index corresponds to the TX power integration
2106948300cSKalle Valo * values found in the EEPROM. The values get written to register 7. */
2116948300cSKalle Valo static u32 uw2453_txgain[] = {
2126948300cSKalle Valo [0x00] = 0x0e313,
2136948300cSKalle Valo [0x01] = 0x0fb13,
2146948300cSKalle Valo [0x02] = 0x0e093,
2156948300cSKalle Valo [0x03] = 0x0f893,
2166948300cSKalle Valo [0x04] = 0x0ea93,
2176948300cSKalle Valo [0x05] = 0x1f093,
2186948300cSKalle Valo [0x06] = 0x1f493,
2196948300cSKalle Valo [0x07] = 0x1f693,
2206948300cSKalle Valo [0x08] = 0x1f393,
2216948300cSKalle Valo [0x09] = 0x1f35b,
2226948300cSKalle Valo [0x0a] = 0x1e6db,
2236948300cSKalle Valo [0x0b] = 0x1ff3f,
2246948300cSKalle Valo [0x0c] = 0x1ffff,
2256948300cSKalle Valo [0x0d] = 0x361d7,
2266948300cSKalle Valo [0x0e] = 0x37fbf,
2276948300cSKalle Valo [0x0f] = 0x3ff8b,
2286948300cSKalle Valo [0x10] = 0x3ff33,
2296948300cSKalle Valo [0x11] = 0x3fb3f,
2306948300cSKalle Valo [0x12] = 0x3ffff,
2316948300cSKalle Valo };
2326948300cSKalle Valo
2336948300cSKalle Valo /* RF-specific structure */
2346948300cSKalle Valo struct uw2453_priv {
2356948300cSKalle Valo /* index into synth/VCO config tables where PLL lock was found
2366948300cSKalle Valo * -1 means autocal */
2376948300cSKalle Valo int config;
2386948300cSKalle Valo };
2396948300cSKalle Valo
2406948300cSKalle Valo #define UW2453_PRIV(rf) ((struct uw2453_priv *) (rf)->priv)
2416948300cSKalle Valo
uw2453_synth_set_channel(struct zd_chip * chip,int channel,bool autocal)2426948300cSKalle Valo static int uw2453_synth_set_channel(struct zd_chip *chip, int channel,
2436948300cSKalle Valo bool autocal)
2446948300cSKalle Valo {
2456948300cSKalle Valo int r;
2466948300cSKalle Valo int idx = channel - 1;
2476948300cSKalle Valo u32 val;
2486948300cSKalle Valo
2496948300cSKalle Valo if (autocal)
2506948300cSKalle Valo val = UW2453_REGWRITE(1, uw2453_autocal_synth[idx]);
2516948300cSKalle Valo else
2526948300cSKalle Valo val = UW2453_REGWRITE(1, uw2453_std_synth[idx]);
2536948300cSKalle Valo
2546948300cSKalle Valo r = zd_rfwrite_locked(chip, val, RF_RV_BITS);
2556948300cSKalle Valo if (r)
2566948300cSKalle Valo return r;
2576948300cSKalle Valo
2586948300cSKalle Valo return zd_rfwrite_locked(chip,
2596948300cSKalle Valo UW2453_REGWRITE(2, uw2453_synth_divide[idx]), RF_RV_BITS);
2606948300cSKalle Valo }
2616948300cSKalle Valo
uw2453_write_vco_cfg(struct zd_chip * chip,u16 value)2626948300cSKalle Valo static int uw2453_write_vco_cfg(struct zd_chip *chip, u16 value)
2636948300cSKalle Valo {
2646948300cSKalle Valo /* vendor driver always sets these upper bits even though the specs say
2656948300cSKalle Valo * they are reserved */
2666948300cSKalle Valo u32 val = 0x40000 | value;
2676948300cSKalle Valo return zd_rfwrite_locked(chip, UW2453_REGWRITE(3, val), RF_RV_BITS);
2686948300cSKalle Valo }
2696948300cSKalle Valo
uw2453_init_mode(struct zd_chip * chip)2706948300cSKalle Valo static int uw2453_init_mode(struct zd_chip *chip)
2716948300cSKalle Valo {
2726948300cSKalle Valo static const u32 rv[] = {
2736948300cSKalle Valo UW2453_REGWRITE(0, 0x25f98), /* enter IDLE mode */
2746948300cSKalle Valo UW2453_REGWRITE(0, 0x25f9a), /* enter CAL_VCO mode */
2756948300cSKalle Valo UW2453_REGWRITE(0, 0x25f94), /* enter RX/TX mode */
2766948300cSKalle Valo UW2453_REGWRITE(0, 0x27fd4), /* power down RSSI circuit */
2776948300cSKalle Valo };
2786948300cSKalle Valo
2796948300cSKalle Valo return zd_rfwritev_locked(chip, rv, ARRAY_SIZE(rv), RF_RV_BITS);
2806948300cSKalle Valo }
2816948300cSKalle Valo
uw2453_set_tx_gain_level(struct zd_chip * chip,int channel)2826948300cSKalle Valo static int uw2453_set_tx_gain_level(struct zd_chip *chip, int channel)
2836948300cSKalle Valo {
2846948300cSKalle Valo u8 int_value = chip->pwr_int_values[channel - 1];
2856948300cSKalle Valo
2866948300cSKalle Valo if (int_value >= ARRAY_SIZE(uw2453_txgain)) {
2876948300cSKalle Valo dev_dbg_f(zd_chip_dev(chip), "can't configure TX gain for "
2886948300cSKalle Valo "int value %x on channel %d\n", int_value, channel);
2896948300cSKalle Valo return 0;
2906948300cSKalle Valo }
2916948300cSKalle Valo
2926948300cSKalle Valo return zd_rfwrite_locked(chip,
2936948300cSKalle Valo UW2453_REGWRITE(7, uw2453_txgain[int_value]), RF_RV_BITS);
2946948300cSKalle Valo }
2956948300cSKalle Valo
uw2453_init_hw(struct zd_rf * rf)2966948300cSKalle Valo static int uw2453_init_hw(struct zd_rf *rf)
2976948300cSKalle Valo {
2986948300cSKalle Valo int i, r;
2996948300cSKalle Valo int found_config = -1;
3006948300cSKalle Valo u16 intr_status;
3016948300cSKalle Valo struct zd_chip *chip = zd_rf_to_chip(rf);
3026948300cSKalle Valo
3036948300cSKalle Valo static const struct zd_ioreq16 ioreqs[] = {
3046948300cSKalle Valo { ZD_CR10, 0x89 }, { ZD_CR15, 0x20 },
3056948300cSKalle Valo { ZD_CR17, 0x28 }, /* 6112 no change */
3066948300cSKalle Valo { ZD_CR23, 0x38 }, { ZD_CR24, 0x20 }, { ZD_CR26, 0x93 },
3076948300cSKalle Valo { ZD_CR27, 0x15 }, { ZD_CR28, 0x3e }, { ZD_CR29, 0x00 },
3086948300cSKalle Valo { ZD_CR33, 0x28 }, { ZD_CR34, 0x30 },
3096948300cSKalle Valo { ZD_CR35, 0x43 }, /* 6112 3e->43 */
3106948300cSKalle Valo { ZD_CR41, 0x24 }, { ZD_CR44, 0x32 },
3116948300cSKalle Valo { ZD_CR46, 0x92 }, /* 6112 96->92 */
3126948300cSKalle Valo { ZD_CR47, 0x1e },
3136948300cSKalle Valo { ZD_CR48, 0x04 }, /* 5602 Roger */
3146948300cSKalle Valo { ZD_CR49, 0xfa }, { ZD_CR79, 0x58 }, { ZD_CR80, 0x30 },
3156948300cSKalle Valo { ZD_CR81, 0x30 }, { ZD_CR87, 0x0a }, { ZD_CR89, 0x04 },
3166948300cSKalle Valo { ZD_CR91, 0x00 }, { ZD_CR92, 0x0a }, { ZD_CR98, 0x8d },
3176948300cSKalle Valo { ZD_CR99, 0x28 }, { ZD_CR100, 0x02 },
3186948300cSKalle Valo { ZD_CR101, 0x09 }, /* 6112 13->1f 6220 1f->13 6407 13->9 */
3196948300cSKalle Valo { ZD_CR102, 0x27 },
3206948300cSKalle Valo { ZD_CR106, 0x1c }, /* 5d07 5112 1f->1c 6220 1c->1f
3216948300cSKalle Valo * 6221 1f->1c
3226948300cSKalle Valo */
3236948300cSKalle Valo { ZD_CR107, 0x1c }, /* 6220 1c->1a 5221 1a->1c */
3246948300cSKalle Valo { ZD_CR109, 0x13 },
3256948300cSKalle Valo { ZD_CR110, 0x1f }, /* 6112 13->1f 6221 1f->13 6407 13->0x09 */
3266948300cSKalle Valo { ZD_CR111, 0x13 }, { ZD_CR112, 0x1f }, { ZD_CR113, 0x27 },
3276948300cSKalle Valo { ZD_CR114, 0x23 }, /* 6221 27->23 */
3286948300cSKalle Valo { ZD_CR115, 0x24 }, /* 6112 24->1c 6220 1c->24 */
3296948300cSKalle Valo { ZD_CR116, 0x24 }, /* 6220 1c->24 */
3306948300cSKalle Valo { ZD_CR117, 0xfa }, /* 6112 fa->f8 6220 f8->f4 6220 f4->fa */
3316948300cSKalle Valo { ZD_CR118, 0xf0 }, /* 5d07 6112 f0->f2 6220 f2->f0 */
3326948300cSKalle Valo { ZD_CR119, 0x1a }, /* 6112 1a->10 6220 10->14 6220 14->1a */
3336948300cSKalle Valo { ZD_CR120, 0x4f },
3346948300cSKalle Valo { ZD_CR121, 0x1f }, /* 6220 4f->1f */
3356948300cSKalle Valo { ZD_CR122, 0xf0 }, { ZD_CR123, 0x57 }, { ZD_CR125, 0xad },
3366948300cSKalle Valo { ZD_CR126, 0x6c }, { ZD_CR127, 0x03 },
3376948300cSKalle Valo { ZD_CR128, 0x14 }, /* 6302 12->11 */
3386948300cSKalle Valo { ZD_CR129, 0x12 }, /* 6301 10->0f */
3396948300cSKalle Valo { ZD_CR130, 0x10 }, { ZD_CR137, 0x50 }, { ZD_CR138, 0xa8 },
3406948300cSKalle Valo { ZD_CR144, 0xac }, { ZD_CR146, 0x20 }, { ZD_CR252, 0xff },
3416948300cSKalle Valo { ZD_CR253, 0xff },
3426948300cSKalle Valo };
3436948300cSKalle Valo
3446948300cSKalle Valo static const u32 rv[] = {
3456948300cSKalle Valo UW2453_REGWRITE(4, 0x2b), /* configure receiver gain */
3466948300cSKalle Valo UW2453_REGWRITE(5, 0x19e4f), /* configure transmitter gain */
3476948300cSKalle Valo UW2453_REGWRITE(6, 0xf81ad), /* enable RX/TX filter tuning */
3486948300cSKalle Valo UW2453_REGWRITE(7, 0x3fffe), /* disable TX gain in test mode */
3496948300cSKalle Valo
3506948300cSKalle Valo /* enter CAL_FIL mode, TX gain set by registers, RX gain set by pins,
3516948300cSKalle Valo * RSSI circuit powered down, reduced RSSI range */
3526948300cSKalle Valo UW2453_REGWRITE(0, 0x25f9c), /* 5d01 cal_fil */
3536948300cSKalle Valo
3546948300cSKalle Valo /* synthesizer configuration for channel 1 */
3556948300cSKalle Valo UW2453_REGWRITE(1, 0x47),
3566948300cSKalle Valo UW2453_REGWRITE(2, 0x999),
3576948300cSKalle Valo
3586948300cSKalle Valo /* disable manual VCO band selection */
3596948300cSKalle Valo UW2453_REGWRITE(3, 0x7602),
3606948300cSKalle Valo
3616948300cSKalle Valo /* enable manual VCO band selection, configure current level */
3626948300cSKalle Valo UW2453_REGWRITE(3, 0x46063),
3636948300cSKalle Valo };
3646948300cSKalle Valo
3656948300cSKalle Valo r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
3666948300cSKalle Valo if (r)
3676948300cSKalle Valo return r;
3686948300cSKalle Valo
3696948300cSKalle Valo r = zd_rfwritev_locked(chip, rv, ARRAY_SIZE(rv), RF_RV_BITS);
3706948300cSKalle Valo if (r)
3716948300cSKalle Valo return r;
3726948300cSKalle Valo
3736948300cSKalle Valo r = uw2453_init_mode(chip);
3746948300cSKalle Valo if (r)
3756948300cSKalle Valo return r;
3766948300cSKalle Valo
3776948300cSKalle Valo /* Try all standard VCO configuration settings on channel 1 */
3786948300cSKalle Valo for (i = 0; i < ARRAY_SIZE(uw2453_std_vco_cfg) - 1; i++) {
3796948300cSKalle Valo /* Configure synthesizer for channel 1 */
3806948300cSKalle Valo r = uw2453_synth_set_channel(chip, 1, false);
3816948300cSKalle Valo if (r)
3826948300cSKalle Valo return r;
3836948300cSKalle Valo
3846948300cSKalle Valo /* Write VCO config */
3856948300cSKalle Valo r = uw2453_write_vco_cfg(chip, uw2453_std_vco_cfg[i][0]);
3866948300cSKalle Valo if (r)
3876948300cSKalle Valo return r;
3886948300cSKalle Valo
3896948300cSKalle Valo /* ack interrupt event */
3906948300cSKalle Valo r = zd_iowrite16_locked(chip, 0x0f, UW2453_INTR_REG);
3916948300cSKalle Valo if (r)
3926948300cSKalle Valo return r;
3936948300cSKalle Valo
3946948300cSKalle Valo /* check interrupt status */
3956948300cSKalle Valo r = zd_ioread16_locked(chip, &intr_status, UW2453_INTR_REG);
3966948300cSKalle Valo if (r)
3976948300cSKalle Valo return r;
3986948300cSKalle Valo
3996948300cSKalle Valo if (!(intr_status & 0xf)) {
4006948300cSKalle Valo dev_dbg_f(zd_chip_dev(chip),
4016948300cSKalle Valo "PLL locked on configuration %d\n", i);
4026948300cSKalle Valo found_config = i;
4036948300cSKalle Valo break;
4046948300cSKalle Valo }
4056948300cSKalle Valo }
4066948300cSKalle Valo
4076948300cSKalle Valo if (found_config == -1) {
4086948300cSKalle Valo /* autocal */
4096948300cSKalle Valo dev_dbg_f(zd_chip_dev(chip),
4106948300cSKalle Valo "PLL did not lock, using autocal\n");
4116948300cSKalle Valo
4126948300cSKalle Valo r = uw2453_synth_set_channel(chip, 1, true);
4136948300cSKalle Valo if (r)
4146948300cSKalle Valo return r;
4156948300cSKalle Valo
4166948300cSKalle Valo r = uw2453_write_vco_cfg(chip, UW2453_AUTOCAL_VCO_CFG);
4176948300cSKalle Valo if (r)
4186948300cSKalle Valo return r;
4196948300cSKalle Valo }
4206948300cSKalle Valo
4216948300cSKalle Valo /* To match the vendor driver behaviour, we use the configuration after
4226948300cSKalle Valo * the one that produced a lock. */
4236948300cSKalle Valo UW2453_PRIV(rf)->config = found_config + 1;
4246948300cSKalle Valo
4256948300cSKalle Valo return zd_iowrite16_locked(chip, 0x06, ZD_CR203);
4266948300cSKalle Valo }
4276948300cSKalle Valo
uw2453_set_channel(struct zd_rf * rf,u8 channel)4286948300cSKalle Valo static int uw2453_set_channel(struct zd_rf *rf, u8 channel)
4296948300cSKalle Valo {
4306948300cSKalle Valo int r;
4316948300cSKalle Valo u16 vco_cfg;
4326948300cSKalle Valo int config = UW2453_PRIV(rf)->config;
4336948300cSKalle Valo bool autocal = (config == -1);
4346948300cSKalle Valo struct zd_chip *chip = zd_rf_to_chip(rf);
4356948300cSKalle Valo
4366948300cSKalle Valo static const struct zd_ioreq16 ioreqs[] = {
4376948300cSKalle Valo { ZD_CR80, 0x30 }, { ZD_CR81, 0x30 }, { ZD_CR79, 0x58 },
4386948300cSKalle Valo { ZD_CR12, 0xf0 }, { ZD_CR77, 0x1b }, { ZD_CR78, 0x58 },
4396948300cSKalle Valo };
4406948300cSKalle Valo
4416948300cSKalle Valo r = uw2453_synth_set_channel(chip, channel, autocal);
4426948300cSKalle Valo if (r)
4436948300cSKalle Valo return r;
4446948300cSKalle Valo
4456948300cSKalle Valo if (autocal)
4466948300cSKalle Valo vco_cfg = UW2453_AUTOCAL_VCO_CFG;
4476948300cSKalle Valo else
4486948300cSKalle Valo vco_cfg = uw2453_std_vco_cfg[config][CHAN_TO_PAIRIDX(channel)];
4496948300cSKalle Valo
4506948300cSKalle Valo r = uw2453_write_vco_cfg(chip, vco_cfg);
4516948300cSKalle Valo if (r)
4526948300cSKalle Valo return r;
4536948300cSKalle Valo
4546948300cSKalle Valo r = uw2453_init_mode(chip);
4556948300cSKalle Valo if (r)
4566948300cSKalle Valo return r;
4576948300cSKalle Valo
4586948300cSKalle Valo r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
4596948300cSKalle Valo if (r)
4606948300cSKalle Valo return r;
4616948300cSKalle Valo
4626948300cSKalle Valo r = uw2453_set_tx_gain_level(chip, channel);
4636948300cSKalle Valo if (r)
4646948300cSKalle Valo return r;
4656948300cSKalle Valo
4666948300cSKalle Valo return zd_iowrite16_locked(chip, 0x06, ZD_CR203);
4676948300cSKalle Valo }
4686948300cSKalle Valo
uw2453_switch_radio_on(struct zd_rf * rf)4696948300cSKalle Valo static int uw2453_switch_radio_on(struct zd_rf *rf)
4706948300cSKalle Valo {
4716948300cSKalle Valo int r;
4726948300cSKalle Valo struct zd_chip *chip = zd_rf_to_chip(rf);
4736948300cSKalle Valo struct zd_ioreq16 ioreqs[] = {
4746948300cSKalle Valo { ZD_CR11, 0x00 }, { ZD_CR251, 0x3f },
4756948300cSKalle Valo };
4766948300cSKalle Valo
4776948300cSKalle Valo /* enter RXTX mode */
4786948300cSKalle Valo r = zd_rfwrite_locked(chip, UW2453_REGWRITE(0, 0x25f94), RF_RV_BITS);
4796948300cSKalle Valo if (r)
4806948300cSKalle Valo return r;
4816948300cSKalle Valo
4826948300cSKalle Valo if (zd_chip_is_zd1211b(chip))
4836948300cSKalle Valo ioreqs[1].value = 0x7f;
4846948300cSKalle Valo
4856948300cSKalle Valo return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
4866948300cSKalle Valo }
4876948300cSKalle Valo
uw2453_switch_radio_off(struct zd_rf * rf)4886948300cSKalle Valo static int uw2453_switch_radio_off(struct zd_rf *rf)
4896948300cSKalle Valo {
4906948300cSKalle Valo int r;
4916948300cSKalle Valo struct zd_chip *chip = zd_rf_to_chip(rf);
4926948300cSKalle Valo static const struct zd_ioreq16 ioreqs[] = {
4936948300cSKalle Valo { ZD_CR11, 0x04 }, { ZD_CR251, 0x2f },
4946948300cSKalle Valo };
4956948300cSKalle Valo
4966948300cSKalle Valo /* enter IDLE mode */
4976948300cSKalle Valo /* FIXME: shouldn't we go to SLEEP? sent email to zydas */
4986948300cSKalle Valo r = zd_rfwrite_locked(chip, UW2453_REGWRITE(0, 0x25f90), RF_RV_BITS);
4996948300cSKalle Valo if (r)
5006948300cSKalle Valo return r;
5016948300cSKalle Valo
5026948300cSKalle Valo return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
5036948300cSKalle Valo }
5046948300cSKalle Valo
uw2453_clear(struct zd_rf * rf)5056948300cSKalle Valo static void uw2453_clear(struct zd_rf *rf)
5066948300cSKalle Valo {
5076948300cSKalle Valo kfree(rf->priv);
5086948300cSKalle Valo }
5096948300cSKalle Valo
zd_rf_init_uw2453(struct zd_rf * rf)5106948300cSKalle Valo int zd_rf_init_uw2453(struct zd_rf *rf)
5116948300cSKalle Valo {
5126948300cSKalle Valo rf->init_hw = uw2453_init_hw;
5136948300cSKalle Valo rf->set_channel = uw2453_set_channel;
5146948300cSKalle Valo rf->switch_radio_on = uw2453_switch_radio_on;
5156948300cSKalle Valo rf->switch_radio_off = uw2453_switch_radio_off;
5166948300cSKalle Valo rf->patch_6m_band_edge = zd_rf_generic_patch_6m;
5176948300cSKalle Valo rf->clear = uw2453_clear;
5186948300cSKalle Valo /* we have our own TX integration code */
5196948300cSKalle Valo rf->update_channel_int = 0;
5206948300cSKalle Valo
5216948300cSKalle Valo rf->priv = kmalloc(sizeof(struct uw2453_priv), GFP_KERNEL);
5226948300cSKalle Valo if (rf->priv == NULL)
5236948300cSKalle Valo return -ENOMEM;
5246948300cSKalle Valo
5256948300cSKalle Valo return 0;
5266948300cSKalle Valo }
5276948300cSKalle Valo
528