⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zd_rf_uw2453.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* zd_rf_uw2453.c: Functions for the UW2453 RF controller * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <linux/kernel.h>#include "zd_rf.h"#include "zd_usb.h"#include "zd_chip.h"/* This RF programming code is based upon the code found in v2.16.0.0 of the * ZyDAS vendor driver. Unlike other RF's, Ubec publish full technical specs * for this RF on their website, so we're able to understand more than * usual as to what is going on. Thumbs up for Ubec for doing that. *//* The 3-wire serial interface provides access to 8 write-only registers. * The data format is a 4 bit register address followed by a 20 bit value. */#define UW2453_REGWRITE(reg, val) ((((reg) & 0xf) << 20) | ((val) & 0xfffff))/* For channel tuning, we have to configure registers 1 (synthesizer), 2 (synth * fractional divide ratio) and 3 (VCO config). * * We configure the RF to produce an interrupt when the PLL is locked onto * the configured frequency. During initialization, we run through a variety * of different VCO configurations on channel 1 until we detect a PLL lock. * When this happens, we remember which VCO configuration produced the lock * and use it later. Actually, we use the configuration *after* the one that * produced the lock, which seems odd, but it works. * * If we do not see a PLL lock on any standard VCO config, we fall back on an * autocal configuration, which has a fixed (as opposed to per-channel) VCO * config and different synth values from the standard set (divide ratio * is still shared with the standard set). *//* The per-channel synth values for all standard VCO configurations. These get * written to register 1. */static const u8 uw2453_std_synth[] = {	RF_CHANNEL( 1) = 0x47,	RF_CHANNEL( 2) = 0x47,	RF_CHANNEL( 3) = 0x67,	RF_CHANNEL( 4) = 0x67,	RF_CHANNEL( 5) = 0x67,	RF_CHANNEL( 6) = 0x67,	RF_CHANNEL( 7) = 0x57,	RF_CHANNEL( 8) = 0x57,	RF_CHANNEL( 9) = 0x57,	RF_CHANNEL(10) = 0x57,	RF_CHANNEL(11) = 0x77,	RF_CHANNEL(12) = 0x77,	RF_CHANNEL(13) = 0x77,	RF_CHANNEL(14) = 0x4f,};/* This table stores the synthesizer fractional divide ratio for *all* VCO * configurations (both standard and autocal). These get written to register 2. */static const u16 uw2453_synth_divide[] = {	RF_CHANNEL( 1) = 0x999,	RF_CHANNEL( 2) = 0x99b,	RF_CHANNEL( 3) = 0x998,	RF_CHANNEL( 4) = 0x99a,	RF_CHANNEL( 5) = 0x999,	RF_CHANNEL( 6) = 0x99b,	RF_CHANNEL( 7) = 0x998,	RF_CHANNEL( 8) = 0x99a,	RF_CHANNEL( 9) = 0x999,	RF_CHANNEL(10) = 0x99b,	RF_CHANNEL(11) = 0x998,	RF_CHANNEL(12) = 0x99a,	RF_CHANNEL(13) = 0x999,	RF_CHANNEL(14) = 0xccc,};/* Here is the data for all the standard VCO configurations. We shrink our * table a little by observing that both channels in a consecutive pair share * the same value. We also observe that the high 4 bits ([0:3] in the specs) * are all 'Reserved' and are always set to 0x4 - we chop them off in the data * below. */#define CHAN_TO_PAIRIDX(a) ((a - 1) / 2)#define RF_CHANPAIR(a,b) [CHAN_TO_PAIRIDX(a)]static const u16 uw2453_std_vco_cfg[][7] = {	{ /* table 1 */		RF_CHANPAIR( 1,  2) = 0x664d,		RF_CHANPAIR( 3,  4) = 0x604d,		RF_CHANPAIR( 5,  6) = 0x6675,		RF_CHANPAIR( 7,  8) = 0x6475,		RF_CHANPAIR( 9, 10) = 0x6655,		RF_CHANPAIR(11, 12) = 0x6455,		RF_CHANPAIR(13, 14) = 0x6665,	},	{ /* table 2 */		RF_CHANPAIR( 1,  2) = 0x666d,		RF_CHANPAIR( 3,  4) = 0x606d,		RF_CHANPAIR( 5,  6) = 0x664d,		RF_CHANPAIR( 7,  8) = 0x644d,		RF_CHANPAIR( 9, 10) = 0x6675,		RF_CHANPAIR(11, 12) = 0x6475,		RF_CHANPAIR(13, 14) = 0x6655,	},	{ /* table 3 */		RF_CHANPAIR( 1,  2) = 0x665d,		RF_CHANPAIR( 3,  4) = 0x605d,		RF_CHANPAIR( 5,  6) = 0x666d,		RF_CHANPAIR( 7,  8) = 0x646d,		RF_CHANPAIR( 9, 10) = 0x664d,		RF_CHANPAIR(11, 12) = 0x644d,		RF_CHANPAIR(13, 14) = 0x6675,	},	{ /* table 4 */		RF_CHANPAIR( 1,  2) = 0x667d,		RF_CHANPAIR( 3,  4) = 0x607d,		RF_CHANPAIR( 5,  6) = 0x665d,		RF_CHANPAIR( 7,  8) = 0x645d,		RF_CHANPAIR( 9, 10) = 0x666d,		RF_CHANPAIR(11, 12) = 0x646d,		RF_CHANPAIR(13, 14) = 0x664d,	},	{ /* table 5 */		RF_CHANPAIR( 1,  2) = 0x6643,		RF_CHANPAIR( 3,  4) = 0x6043,		RF_CHANPAIR( 5,  6) = 0x667d,		RF_CHANPAIR( 7,  8) = 0x647d,		RF_CHANPAIR( 9, 10) = 0x665d,		RF_CHANPAIR(11, 12) = 0x645d,		RF_CHANPAIR(13, 14) = 0x666d,	},	{ /* table 6 */		RF_CHANPAIR( 1,  2) = 0x6663,		RF_CHANPAIR( 3,  4) = 0x6063,		RF_CHANPAIR( 5,  6) = 0x6643,		RF_CHANPAIR( 7,  8) = 0x6443,		RF_CHANPAIR( 9, 10) = 0x667d,		RF_CHANPAIR(11, 12) = 0x647d,		RF_CHANPAIR(13, 14) = 0x665d,	},	{ /* table 7 */		RF_CHANPAIR( 1,  2) = 0x6653,		RF_CHANPAIR( 3,  4) = 0x6053,		RF_CHANPAIR( 5,  6) = 0x6663,		RF_CHANPAIR( 7,  8) = 0x6463,		RF_CHANPAIR( 9, 10) = 0x6643,		RF_CHANPAIR(11, 12) = 0x6443,		RF_CHANPAIR(13, 14) = 0x667d,	},	{ /* table 8 */		RF_CHANPAIR( 1,  2) = 0x6673,		RF_CHANPAIR( 3,  4) = 0x6073,		RF_CHANPAIR( 5,  6) = 0x6653,		RF_CHANPAIR( 7,  8) = 0x6453,		RF_CHANPAIR( 9, 10) = 0x6663,		RF_CHANPAIR(11, 12) = 0x6463,		RF_CHANPAIR(13, 14) = 0x6643,	},	{ /* table 9 */		RF_CHANPAIR( 1,  2) = 0x664b,		RF_CHANPAIR( 3,  4) = 0x604b,		RF_CHANPAIR( 5,  6) = 0x6673,		RF_CHANPAIR( 7,  8) = 0x6473,		RF_CHANPAIR( 9, 10) = 0x6653,		RF_CHANPAIR(11, 12) = 0x6453,		RF_CHANPAIR(13, 14) = 0x6663,	},	{ /* table 10 */		RF_CHANPAIR( 1,  2) = 0x666b,		RF_CHANPAIR( 3,  4) = 0x606b,		RF_CHANPAIR( 5,  6) = 0x664b,		RF_CHANPAIR( 7,  8) = 0x644b,		RF_CHANPAIR( 9, 10) = 0x6673,		RF_CHANPAIR(11, 12) = 0x6473,		RF_CHANPAIR(13, 14) = 0x6653,	},	{ /* table 11 */		RF_CHANPAIR( 1,  2) = 0x665b,		RF_CHANPAIR( 3,  4) = 0x605b,		RF_CHANPAIR( 5,  6) = 0x666b,		RF_CHANPAIR( 7,  8) = 0x646b,		RF_CHANPAIR( 9, 10) = 0x664b,		RF_CHANPAIR(11, 12) = 0x644b,		RF_CHANPAIR(13, 14) = 0x6673,	},};/* The per-channel synth values for autocal. These get written to register 1. */static const u16 uw2453_autocal_synth[] = {	RF_CHANNEL( 1) = 0x6847,	RF_CHANNEL( 2) = 0x6847,	RF_CHANNEL( 3) = 0x6867,	RF_CHANNEL( 4) = 0x6867,	RF_CHANNEL( 5) = 0x6867,	RF_CHANNEL( 6) = 0x6867,	RF_CHANNEL( 7) = 0x6857,	RF_CHANNEL( 8) = 0x6857,	RF_CHANNEL( 9) = 0x6857,	RF_CHANNEL(10) = 0x6857,	RF_CHANNEL(11) = 0x6877,	RF_CHANNEL(12) = 0x6877,	RF_CHANNEL(13) = 0x6877,	RF_CHANNEL(14) = 0x684f,};/* The VCO configuration for autocal (all channels) */static const u16 UW2453_AUTOCAL_VCO_CFG = 0x6662;/* TX gain settings. The array index corresponds to the TX power integration * values found in the EEPROM. The values get written to register 7. */static u32 uw2453_txgain[] = {	[0x00] = 0x0e313,	[0x01] = 0x0fb13,	[0x02] = 0x0e093,	[0x03] = 0x0f893,	[0x04] = 0x0ea93,	[0x05] = 0x1f093,	[0x06] = 0x1f493,	[0x07] = 0x1f693,	[0x08] = 0x1f393,	[0x09] = 0x1f35b,	[0x0a] = 0x1e6db,	[0x0b] = 0x1ff3f,	[0x0c] = 0x1ffff,	[0x0d] = 0x361d7,	[0x0e] = 0x37fbf,	[0x0f] = 0x3ff8b,	[0x10] = 0x3ff33,	[0x11] = 0x3fb3f,	[0x12] = 0x3ffff,};/* RF-specific structure */struct uw2453_priv {	/* index into synth/VCO config tables where PLL lock was found	 * -1 means autocal */	int config;};#define UW2453_PRIV(rf) ((struct uw2453_priv *) (rf)->priv)static int uw2453_synth_set_channel(struct zd_chip *chip, int channel,	bool autocal){	int r;	int idx = channel - 1;	u32 val;	if (autocal)		val = UW2453_REGWRITE(1, uw2453_autocal_synth[idx]);	else		val = UW2453_REGWRITE(1, uw2453_std_synth[idx]);	r = zd_rfwrite_locked(chip, val, RF_RV_BITS);	if (r)		return r;	return zd_rfwrite_locked(chip,		UW2453_REGWRITE(2, uw2453_synth_divide[idx]), RF_RV_BITS);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -