/*
* 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/>.
*/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "rtlsdr_i2c.h"
#include "tuner_r82xx.h"
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define MHZ(x) ((x)*1000*1000)
#define KHZ(x) ((x)*1000)
/*
* Static constants
*/
/* Those initial values start from REG_SHADOW_START */
static const uint8_t r82xx_init_array[NUM_REGS] = {
0x83, 0x32, 0x75, /* 05 to 07 */
0xc0, 0x40, 0xd6, 0x6c, /* 08 to 0b */
0xf5, 0x63, 0x75, 0x68, /* 0c to 0f */
0x6c, 0x83, 0x80, 0x00, /* 10 to 13 */
0x0f, 0x00, 0xc0, 0x30, /* 14 to 17 */
0x48, 0xcc, 0x60, 0x00, /* 18 to 1b */
0x54, 0xae, 0x4a, 0xc0 /* 1c to 1f */
};
/* Tuner frequency ranges */
static const struct r82xx_freq_range freq_ranges[] = {
{
/* .freq = */ 0, /* Start freq, in MHz */
/* .open_d = */ 0x08, /* low */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0xdf, /* R27[7:0] band2,band0 */
/* .xtal_cap20p = */ 0x02, /* R16[1:0] 20pF (10) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 50, /* Start freq, in MHz */
/* .open_d = */ 0x08, /* low */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0xbe, /* R27[7:0] band4,band1 */
/* .xtal_cap20p = */ 0x02, /* R16[1:0] 20pF (10) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 55, /* Start freq, in MHz */
/* .open_d = */ 0x08, /* low */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x8b, /* R27[7:0] band7,band4 */
/* .xtal_cap20p = */ 0x02, /* R16[1:0] 20pF (10) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 60, /* Start freq, in MHz */
/* .open_d = */ 0x08, /* low */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x7b, /* R27[7:0] band8,band4 */
/* .xtal_cap20p = */ 0x02, /* R16[1:0] 20pF (10) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 65, /* Start freq, in MHz */
/* .open_d = */ 0x08, /* low */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x69, /* R27[7:0] band9,band6 */
/* .xtal_cap20p = */ 0x02, /* R16[1:0] 20pF (10) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 70, /* Start freq, in MHz */
/* .open_d = */ 0x08, /* low */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x58, /* R27[7:0] band10,band7 */
/* .xtal_cap20p = */ 0x02, /* R16[1:0] 20pF (10) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 75, /* Start freq, in MHz */
/* .open_d = */ 0x00, /* high */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x44, /* R27[7:0] band11,band11 */
/* .xtal_cap20p = */ 0x02, /* R16[1:0] 20pF (10) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 80, /* Start freq, in MHz */
/* .open_d = */ 0x00, /* high */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x44, /* R27[7:0] band11,band11 */
/* .xtal_cap20p = */ 0x02, /* R16[1:0] 20pF (10) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 90, /* Start freq, in MHz */
/* .open_d = */ 0x00, /* high */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x34, /* R27[7:0] band12,band11 */
/* .xtal_cap20p = */ 0x01, /* R16[1:0] 10pF (01) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 100, /* Start freq, in MHz */
/* .open_d = */ 0x00, /* high */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x34, /* R27[7:0] band12,band11 */
/* .xtal_cap20p = */ 0x01, /* R16[1:0] 10pF (01) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_cap0p = */ 0x00,
}, {
/* .freq = */ 110, /* Start freq, in MHz */
/* .open_d = */ 0x00, /* high */
/* .rf_mux_ploy = */ 0x02, /* R26[7:6]=0 (LPF) R26[1:0]=2 (low) */
/* .tf_c = */ 0x24, /* R27[7:0] band13,band11 */
/* .xtal_cap20p = */ 0x01, /* R16[1:0] 10pF (01) */
/* .xtal_cap10p = */ 0x01,
/* .xtal_
|