use new driver for R8XX tuners

Signed-off-by: Steve Markgraf <steve@steve-m.de>
master
Steve Markgraf 11 years ago
parent fda22c6a1d
commit 230930e975
  1. 196
      include/tuner_r820t.h
  2. 116
      include/tuner_r82xx.h
  3. 4
      src/CMakeLists.txt
  4. 2
      src/Makefile.am
  5. 59
      src/librtlsdr.c
  6. 3050
      src/tuner_r820t.c
  7. 1252
      src/tuner_r82xx.c

@ -1,196 +0,0 @@
#ifndef _R820T_TUNER_H
#define _R820T_TUNER_H
#define R820T_I2C_ADDR 0x34
#define R820T_CHECK_ADDR 0x00
#define R820T_CHECK_VAL 0x69
#define R820T_IF_FREQ 3570000
//***************************************************************
//* INCLUDES.H
//***************************************************************
#define VERSION "R820T_v1.49_ASTRO"
#define VER_NUM 49
#define USE_16M_XTAL FALSE
#define R828_Xtal 28800
#define USE_DIPLEXER FALSE
#define TUNER_CLK_OUT TRUE
#ifndef _UINT_X_
#define _UINT_X_ 1
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
#endif
#define TRUE 1
#define FALSE 0
#define FUNCTION_SUCCESS 0
#define FUNCTION_ERROR -1
typedef enum _R828_ErrCode
{
RT_Success,
RT_Fail
}R828_ErrCode;
typedef enum _Rafael_Chip_Type //Don't modify chip list
{
R828 = 0,
R828D,
R828S,
R820T,
R820C,
R620D,
R620S
}Rafael_Chip_Type;
//----------------------------------------------------------//
// R828 Parameter //
//----------------------------------------------------------//
extern UINT8 R828_ADDRESS;
#define DIP_FREQ 320000
#define IMR_TRIAL 9
#define VCO_pwr_ref 0x02
extern UINT32 R828_IF_khz;
extern UINT32 R828_CAL_LO_khz;
extern UINT8 R828_IMR_point_num;
extern UINT8 R828_IMR_done_flag;
extern UINT8 Rafael_Chip;
typedef enum _R828_Standard_Type //Don't remove standand list!!
{
NTSC_MN = 0,
PAL_I,
PAL_DK,
PAL_B_7M, //no use
PAL_BGH_8M, //for PAL B/G, PAL G/H
SECAM_L,
SECAM_L1_INV, //for SECAM L'
SECAM_L1, //no use
ATV_SIZE,
DVB_T_6M = ATV_SIZE,
DVB_T_7M,
DVB_T_7M_2,
DVB_T_8M,
DVB_T2_6M,
DVB_T2_7M,
DVB_T2_7M_2,
DVB_T2_8M,
DVB_T2_1_7M,
DVB_T2_10M,
DVB_C_8M,
DVB_C_6M,
ISDB_T,
DTMB,
R828_ATSC,
FM,
STD_SIZE
}R828_Standard_Type;
extern UINT8 R828_Fil_Cal_flag[STD_SIZE];
typedef enum _R828_SetFreq_Type
{
FAST_MODE = TRUE,
NORMAL_MODE = FALSE
}R828_SetFreq_Type;
typedef enum _R828_LoopThrough_Type
{
LOOP_THROUGH = TRUE,
SIGLE_IN = FALSE
}R828_LoopThrough_Type;
typedef enum _R828_InputMode_Type
{
AIR_IN = 0,
CABLE_IN_1,
CABLE_IN_2
}R828_InputMode_Type;
typedef enum _R828_IfAgc_Type
{
IF_AGC1 = 0,
IF_AGC2
}R828_IfAgc_Type;
typedef enum _R828_GPIO_Type
{
HI_SIG = TRUE,
LO_SIG = FALSE
}R828_GPIO_Type;
typedef struct _R828_Set_Info
{
UINT32 RF_Hz;
UINT32 RF_KHz;
R828_Standard_Type R828_Standard;
R828_LoopThrough_Type RT_Input;
R828_InputMode_Type RT_InputMode;
R828_IfAgc_Type R828_IfAgc_Select;
}R828_Set_Info;
typedef struct _R828_RF_Gain_Info
{
UINT8 RF_gain1;
UINT8 RF_gain2;
UINT8 RF_gain_comb;
}R828_RF_Gain_Info;
typedef enum _R828_RF_Gain_TYPE
{
RF_AUTO = 0,
RF_MANUAL
}R828_RF_Gain_TYPE;
typedef struct _R828_I2C_LEN_TYPE
{
UINT8 RegAddr;
UINT8 Data[50];
UINT8 Len;
}R828_I2C_LEN_TYPE;
typedef struct _R828_I2C_TYPE
{
UINT8 RegAddr;
UINT8 Data;
}R828_I2C_TYPE;
//----------------------------------------------------------//
// R828 Function //
//----------------------------------------------------------//
R828_ErrCode R828_Init(void *pTuner);
R828_ErrCode R828_Standby(void *pTuner, R828_LoopThrough_Type R828_LoopSwitch);
R828_ErrCode R828_GPIO(void *pTuner, R828_GPIO_Type R828_GPIO_Conrl);
R828_ErrCode R828_SetStandard(void *pTuner, R828_Standard_Type RT_Standard);
R828_ErrCode R828_SetFrequency(void *pTuner, R828_Set_Info R828_INFO, R828_SetFreq_Type R828_SetFreqMode);
R828_ErrCode R828_GetRfGain(void *pTuner, R828_RF_Gain_Info *pR828_rf_gain);
R828_ErrCode R828_SetRfGain(void *pTuner, int gain);
R828_ErrCode R828_RfGainMode(void *pTuner, int manual);
int
r820t_SetRfFreqHz(
void *pTuner,
unsigned long RfFreqHz
);
int
r820t_SetStandardMode(
void *pTuner,
int StandardMode
);
int
r820t_SetStandby(
void *pTuner,
int LoopThroughType
);
#endif /* _R820T_TUNER_H */

@ -0,0 +1,116 @@
/*
* Rafael Micro R820T/R828D driver
*
* Copyright (C) 2013 Mauro Carvalho Chehab <mchehab@redhat.com>
* Copyright (C) 2013 Steve Markgraf <steve@steve-m.de>
*
* This driver is a heavily modified version of the driver found in the
* Linux kernel:
* http://git.linuxtv.org/linux-2.6.git/history/HEAD:/drivers/media/tuners/r820t.c
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef R82XX_H
#define R82XX_H
#define R820T_I2C_ADDR 0x34
#define R820T_CHECK_ADDR 0x00
#define R820T_CHECK_VAL 0x69
#define R82XX_IF_FREQ 3570000
#define REG_SHADOW_START 5
#define NUM_REGS 30
#define NUM_IMR 5
#define IMR_TRIAL 9
#define VER_NUM 49
enum r82xx_chip {
CHIP_R820T,
CHIP_R620D,
CHIP_R828D,
CHIP_R828,
CHIP_R828S,
CHIP_R820C,
};
enum r82xx_tuner_type {
TUNER_RADIO = 1,
TUNER_ANALOG_TV,
TUNER_DIGITAL_TV
};
enum r82xx_xtal_cap_value {
XTAL_LOW_CAP_30P = 0,
XTAL_LOW_CAP_20P,
XTAL_LOW_CAP_10P,
XTAL_LOW_CAP_0P,
XTAL_HIGH_CAP_0P
};
struct r82xx_config {
uint8_t i2c_addr;
uint32_t xtal;
enum r82xx_chip rafael_chip;
unsigned int max_i2c_msg_len;
int use_diplexer;
int use_predetect;
};
struct r82xx_priv {
struct r82xx_config *cfg;
uint8_t regs[NUM_REGS];
uint8_t buf[NUM_REGS + 1];
enum r82xx_xtal_cap_value xtal_cap_sel;
uint16_t pll; /* kHz */
uint32_t int_freq;
uint8_t fil_cal_code;
int has_lock;
int init_done;
/* Store current mode */
uint32_t delsys;
enum r82xx_tuner_type type;
uint32_t bw; /* in MHz */
void *rtl_dev;
};
struct r82xx_freq_range {
uint32_t freq;
uint8_t open_d;
uint8_t rf_mux_ploy;
uint8_t tf_c;
uint8_t xtal_cap20p;
uint8_t xtal_cap10p;
uint8_t xtal_cap0p;
};
enum r82xx_delivery_system {
SYS_UNDEFINED,
SYS_DVBT,
SYS_DVBT2,
SYS_ISDBT,
};
int r82xx_standby(struct r82xx_priv *priv);
int r82xx_init(struct r82xx_priv *priv);
int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq);
int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain);
#endif

@ -26,7 +26,7 @@ add_library(rtlsdr_shared SHARED
tuner_fc0012.c tuner_fc0012.c
tuner_fc0013.c tuner_fc0013.c
tuner_fc2580.c tuner_fc2580.c
tuner_r820t.c tuner_r82xx.c
) )
target_link_libraries(rtlsdr_shared target_link_libraries(rtlsdr_shared
@ -44,7 +44,7 @@ add_library(rtlsdr_static STATIC
tuner_fc0012.c tuner_fc0012.c
tuner_fc0013.c tuner_fc0013.c
tuner_fc2580.c tuner_fc2580.c
tuner_r820t.c tuner_r82xx.c
) )
if(WIN32) if(WIN32)

@ -7,7 +7,7 @@ AM_CFLAGS = ${CFLAGS} -fPIC ${SYMBOL_VISIBILITY}
lib_LTLIBRARIES = librtlsdr.la lib_LTLIBRARIES = librtlsdr.la
librtlsdr_la_SOURCES = librtlsdr.c tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r820t.c librtlsdr_la_SOURCES = librtlsdr.c tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c
librtlsdr_la_LDFLAGS = -version-info $(LIBVERSION) librtlsdr_la_LDFLAGS = -version-info $(LIBVERSION)
bin_PROGRAMS = rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power bin_PROGRAMS = rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power

@ -1,6 +1,6 @@
/* /*
* rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
* Copyright (C) 2012 by Steve Markgraf <steve@steve-m.de> * Copyright (C) 2012-2013 by Steve Markgraf <steve@steve-m.de>
* Copyright (C) 2012 by Dimitri Stolnikov <horiz0n@gmx.net> * Copyright (C) 2012 by Dimitri Stolnikov <horiz0n@gmx.net>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -47,7 +47,7 @@
#include "tuner_fc0012.h" #include "tuner_fc0012.h"
#include "tuner_fc0013.h" #include "tuner_fc0013.h"
#include "tuner_fc2580.h" #include "tuner_fc2580.h"
#include "tuner_r820t.h" #include "tuner_r82xx.h"
typedef struct rtlsdr_tuner_iface { typedef struct rtlsdr_tuner_iface {
/* tuner interface */ /* tuner interface */
@ -89,6 +89,9 @@ struct rtlsdr_dev {
int corr; /* ppm */ int corr; /* ppm */
int gain; /* tenth dB */ int gain; /* tenth dB */
struct e4k_state e4k_s; struct e4k_state e4k_s;
struct r82xx_config r82xx_c;
struct r82xx_priv r82xx_p;
/* status */
int dev_lost; int dev_lost;
int driver_active; int driver_active;
unsigned int xfer_errors; unsigned int xfer_errors;
@ -179,16 +182,38 @@ int fc2580_set_gain(void *dev, int gain) { return 0; }
int fc2580_set_gain_mode(void *dev, int manual) { return 0; } int fc2580_set_gain_mode(void *dev, int manual) { return 0; }
int r820t_init(void *dev) { int r820t_init(void *dev) {
int r = R828_Init(dev); rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
r820t_SetStandardMode(dev, DVB_T_6M); devt->r82xx_p.rtl_dev = dev;
return r; devt->r82xx_c.i2c_addr = R820T_I2C_ADDR;
rtlsdr_get_xtal_freq(devt, NULL, &devt->r82xx_c.xtal);
devt->r82xx_c.rafael_chip = CHIP_R820T;
devt->r82xx_c.max_i2c_msg_len = 2;
devt->r82xx_c.use_diplexer = 0;
devt->r82xx_c.use_predetect = 0;
devt->r82xx_p.cfg = &devt->r82xx_c;
return r82xx_init(&devt->r82xx_p);
}
int r820t_exit(void *dev) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_standby(&devt->r82xx_p);
} }
int r820t_exit(void *dev) { return r820t_SetStandby(dev, 0); }
int r820t_set_freq(void *dev, uint32_t freq) { return r820t_SetRfFreqHz(dev, freq); }
int r820t_set_bw(void *dev, int bw) { return 0; }
int r820t_set_gain(void *dev, int gain) { return R828_SetRfGain(dev, gain); }
int r820t_set_gain_mode(void *dev, int manual) { return R828_RfGainMode(dev, manual); }
int r820t_set_freq(void *dev, uint32_t freq) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_freq(&devt->r82xx_p, freq);
}
int r820t_set_bw(void *dev, int bw) { return 0; }
int r820t_set_gain(void *dev, int gain) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_gain(&devt->r82xx_p, 1, gain);
}
int r820t_set_gain_mode(void *dev, int manual) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
return r82xx_set_gain(&devt->r82xx_p, manual, 0);
}
/* definition order must match enum rtlsdr_tuner */ /* definition order must match enum rtlsdr_tuner */
static rtlsdr_tuner_iface_t tuners[] = { static rtlsdr_tuner_iface_t tuners[] = {
{ {
@ -652,8 +677,9 @@ int rtlsdr_set_xtal_freq(rtlsdr_dev_t *dev, uint32_t rtl_freq, uint32_t tuner_fr
else else
dev->tun_xtal = tuner_freq; dev->tun_xtal = tuner_freq;
/* read corrected clock value into e4k structure */ /* read corrected clock value into e4k and r82xx structure */
if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc)) if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc) ||
rtlsdr_get_xtal_freq(dev, NULL, &dev->r82xx_c.xtal))
return -3; return -3;
/* update xtal-dependent settings */ /* update xtal-dependent settings */
@ -829,8 +855,9 @@ int rtlsdr_set_freq_correction(rtlsdr_dev_t *dev, int ppm)
r |= rtlsdr_set_sample_freq_correction(dev, ppm); r |= rtlsdr_set_sample_freq_correction(dev, ppm);
/* read corrected clock value into e4k structure */ /* read corrected clock value into e4k and r82xx structure */
if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc)) if (rtlsdr_get_xtal_freq(dev, NULL, &dev->e4k_s.vco.fosc) ||
rtlsdr_get_xtal_freq(dev, NULL, &dev->r82xx_c.xtal))
return -3; return -3;
if (dev->freq) /* retune to apply new correction value */ if (dev->freq) /* retune to apply new correction value */
@ -1077,7 +1104,7 @@ int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
} }
if (dev->tuner_type == RTLSDR_TUNER_R820T) { if (dev->tuner_type == RTLSDR_TUNER_R820T) {
r |= rtlsdr_set_if_freq(dev, R820T_IF_FREQ); r |= rtlsdr_set_if_freq(dev, R82XX_IF_FREQ);
/* enable spectrum inversion */ /* enable spectrum inversion */
r |= rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1); r |= rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1);
@ -1418,7 +1445,7 @@ int rtlsdr_open(rtlsdr_dev_t **out_dev, uint32_t index)
/* the R820T uses 3.57 MHz IF for the DVB-T 6 MHz mode, and /* the R820T uses 3.57 MHz IF for the DVB-T 6 MHz mode, and
* 4.57 MHz for the 8 MHz mode */ * 4.57 MHz for the 8 MHz mode */
rtlsdr_set_if_freq(dev, R820T_IF_FREQ); rtlsdr_set_if_freq(dev, R82XX_IF_FREQ);
/* enable spectrum inversion */ /* enable spectrum inversion */
rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1); rtlsdr_demod_write_reg(dev, 1, 0x15, 0x01, 1);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save