Skip to content
Permalink
Browse files

driver: tejeez's no-mod direct sampling

  • Loading branch information...
keenerd committed Jan 25, 2014
1 parent 7940fa0 commit b36ea08cc7241113f3b01196f521d305c5e04bac
Showing with 70 additions and 4 deletions.
  1. +1 −0 include/tuner_r82xx.h
  2. +29 −3 src/librtlsdr.c
  3. +40 −1 src/tuner_r82xx.c
@@ -115,5 +115,6 @@ 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);
int r82xx_set_nomod(struct r82xx_priv *priv);

#endif
@@ -1132,13 +1132,36 @@ int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
if (!dev)
return -1;

if (on) {
/* set up normal direct sampling */
if (on == 1 || on == 2) {
if (dev->tuner && dev->tuner->exit) {
rtlsdr_set_i2c_repeater(dev, 1);
r = dev->tuner->exit(dev);
rtlsdr_set_i2c_repeater(dev, 0);
}
}

/* set up no-mod direct sampling */
if (on == 3 && dev->tuner) {
if (dev->tuner_type == RTLSDR_TUNER_E4000) {
fprintf(stderr, "Tuning E4000 to 3708 MHz\n");
rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->init(dev);
dev->tuner->set_freq(dev, 3708000000u);
e4000_set_bw(dev, 15000000);
rtlsdr_set_i2c_repeater(dev, 0);
}
if (dev->tuner_type == RTLSDR_TUNER_R820T) {
rtlsdr_dev_t* devt = (rtlsdr_dev_t*)dev;
rtlsdr_set_i2c_repeater(dev, 1);
dev->tuner->init(dev);
r82xx_set_nomod(&devt->r82xx_p);
rtlsdr_set_i2c_repeater(dev, 0);
}
}

/* common to all direct modes */
if (on) {
/* disable Zero-IF mode */
r |= rtlsdr_demod_write_reg(dev, 1, 0xb1, 0x1a, 1);

@@ -1149,11 +1172,14 @@ int rtlsdr_set_direct_sampling(rtlsdr_dev_t *dev, int on)
r |= rtlsdr_demod_write_reg(dev, 0, 0x08, 0x4d, 1);

/* swap I and Q ADC, this allows to select between two inputs */
r |= rtlsdr_demod_write_reg(dev, 0, 0x06, (on > 1) ? 0x90 : 0x80, 1);
r |= rtlsdr_demod_write_reg(dev, 0, 0x06, (on == 2) ? 0x90 : 0x80, 1);

fprintf(stderr, "Enabled direct sampling mode, input %i\n", on);
dev->direct_sampling = on;
} else {
}

/* disable direct sampling */
if (!on) {
if (dev->tuner && dev->tuner->init) {
rtlsdr_set_i2c_repeater(dev, 1);
r |= dev->tuner->init(dev);
@@ -783,7 +783,20 @@ static int r82xx_set_tv_standard(struct r82xx_priv *priv,
flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */
polyfil_cur = 0x60; /* r25[6:5]:min */
} else {
if (bw <= 6) {
if (bw < 6) {
/* narrowest bandwidth? */
if_khz = 3570;
filt_cal_lo = 56000; /* 52000->56000 */
filt_gain = 0x10; /* +3db, 6mhz on */
img_r = 0x00; /* image negative */
filt_q = 0x10; /* r10[4]:low q(1'b1) */
hp_cor = 0x6a; /* 1.7m disable, +2cap, 1.25mhz */
ext_enable = 0x60; /* r30[6]=1 ext enable; r30[5]:1 ext at lna max-1 */
loop_through = 0x00; /* r5[7], lt on */
lt_att = 0x00; /* r31[7], lt att enable */
flt_ext_widest = 0x00; /* r15[7]: flt_ext_wide off */
polyfil_cur = 0x60; /* r25[6:5]:min */
} else if (bw == 6) {
if_khz = 3570;
filt_cal_lo = 56000; /* 52000->56000 */
filt_gain = 0x10; /* +3db, 6mhz on */
@@ -1105,6 +1118,32 @@ int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq)
return rc;
}

int r82xx_set_nomod(struct r82xx_priv *priv)
{
int rc = -1;

fprintf(stderr, "Using R820T no-mod direct sampling mode\n");

rc = r82xx_set_tv_standard(priv, 8, TUNER_DIGITAL_TV, 0);
if (rc < 0)
goto err;

/* experimentally determined magic numbers
* needs more experimenting with all the registers */
rc = r82xx_set_mux(priv, 300000000);
if (rc < 0)
goto err;

r82xx_set_pll(priv, 25000000);

err:
if (rc < 0)
fprintf(stderr, "%s: failed=%d\n", __FUNCTION__, rc);
return rc;
}



/*
* r82xx standby logic
*/

0 comments on commit b36ea08

Please sign in to comment.
You can’t perform that action at this time.