22 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/string.h>
26 #include <linux/slab.h>
29 #include <asm/div64.h>
34 #define TDA10048_DEFAULT_FIRMWARE "dvb-fe-tda10048-1.0.fw"
35 #define TDA10048_DEFAULT_FIRMWARE_SIZE 24878
38 #define TDA10048_IDENTITY 0x00
39 #define TDA10048_VERSION 0x01
40 #define TDA10048_DSP_CODE_CPT 0x0C
41 #define TDA10048_DSP_CODE_IN 0x0E
42 #define TDA10048_IN_CONF1 0x10
43 #define TDA10048_IN_CONF2 0x11
44 #define TDA10048_IN_CONF3 0x12
45 #define TDA10048_OUT_CONF1 0x14
46 #define TDA10048_OUT_CONF2 0x15
47 #define TDA10048_OUT_CONF3 0x16
48 #define TDA10048_AUTO 0x18
49 #define TDA10048_SYNC_STATUS 0x1A
50 #define TDA10048_CONF_C4_1 0x1E
51 #define TDA10048_CONF_C4_2 0x1F
52 #define TDA10048_CODE_IN_RAM 0x20
53 #define TDA10048_CHANNEL_INFO1_R 0x22
54 #define TDA10048_CHANNEL_INFO2_R 0x23
55 #define TDA10048_CHANNEL_INFO1 0x24
56 #define TDA10048_CHANNEL_INFO2 0x25
57 #define TDA10048_TIME_ERROR_R 0x26
58 #define TDA10048_TIME_ERROR 0x27
59 #define TDA10048_FREQ_ERROR_LSB_R 0x28
60 #define TDA10048_FREQ_ERROR_MSB_R 0x29
61 #define TDA10048_FREQ_ERROR_LSB 0x2A
62 #define TDA10048_FREQ_ERROR_MSB 0x2B
63 #define TDA10048_IT_SEL 0x30
64 #define TDA10048_IT_STAT 0x32
65 #define TDA10048_DSP_AD_LSB 0x3C
66 #define TDA10048_DSP_AD_MSB 0x3D
67 #define TDA10048_DSP_REG_LSB 0x3E
68 #define TDA10048_DSP_REG_MSB 0x3F
69 #define TDA10048_CONF_TRISTATE1 0x44
70 #define TDA10048_CONF_TRISTATE2 0x45
71 #define TDA10048_CONF_POLARITY 0x46
72 #define TDA10048_GPIO_SP_DS0 0x48
73 #define TDA10048_GPIO_SP_DS1 0x49
74 #define TDA10048_GPIO_SP_DS2 0x4A
75 #define TDA10048_GPIO_SP_DS3 0x4B
76 #define TDA10048_GPIO_OUT_SEL 0x4C
77 #define TDA10048_GPIO_SELECT 0x4D
78 #define TDA10048_IC_MODE 0x4E
79 #define TDA10048_CONF_XO 0x50
80 #define TDA10048_CONF_PLL1 0x51
81 #define TDA10048_CONF_PLL2 0x52
82 #define TDA10048_CONF_PLL3 0x53
83 #define TDA10048_CONF_ADC 0x54
84 #define TDA10048_CONF_ADC_2 0x55
85 #define TDA10048_CONF_C1_1 0x60
86 #define TDA10048_CONF_C1_3 0x62
87 #define TDA10048_AGC_CONF 0x70
88 #define TDA10048_AGC_THRESHOLD_LSB 0x72
89 #define TDA10048_AGC_THRESHOLD_MSB 0x73
90 #define TDA10048_AGC_RENORM 0x74
91 #define TDA10048_AGC_GAINS 0x76
92 #define TDA10048_AGC_TUN_MIN 0x78
93 #define TDA10048_AGC_TUN_MAX 0x79
94 #define TDA10048_AGC_IF_MIN 0x7A
95 #define TDA10048_AGC_IF_MAX 0x7B
96 #define TDA10048_AGC_TUN_LEVEL 0x7E
97 #define TDA10048_AGC_IF_LEVEL 0x7F
98 #define TDA10048_DIG_AGC_LEVEL 0x81
99 #define TDA10048_FREQ_PHY2_LSB 0x86
100 #define TDA10048_FREQ_PHY2_MSB 0x87
101 #define TDA10048_TIME_INVWREF_LSB 0x88
102 #define TDA10048_TIME_INVWREF_MSB 0x89
103 #define TDA10048_TIME_WREF_LSB 0x8A
104 #define TDA10048_TIME_WREF_MID1 0x8B
105 #define TDA10048_TIME_WREF_MID2 0x8C
106 #define TDA10048_TIME_WREF_MSB 0x8D
107 #define TDA10048_NP_OUT 0xA2
108 #define TDA10048_CELL_ID_LSB 0xA4
109 #define TDA10048_CELL_ID_MSB 0xA5
110 #define TDA10048_EXTTPS_ODD 0xAA
111 #define TDA10048_EXTTPS_EVEN 0xAB
112 #define TDA10048_TPS_LENGTH 0xAC
113 #define TDA10048_FREE_REG_1 0xB2
114 #define TDA10048_FREE_REG_2 0xB3
115 #define TDA10048_CONF_C3_1 0xC0
116 #define TDA10048_CVBER_CTRL 0xC2
117 #define TDA10048_CBER_NMAX_LSB 0xC4
118 #define TDA10048_CBER_NMAX_MSB 0xC5
119 #define TDA10048_CBER_LSB 0xC6
120 #define TDA10048_CBER_MSB 0xC7
121 #define TDA10048_VBER_LSB 0xC8
122 #define TDA10048_VBER_MID 0xC9
123 #define TDA10048_VBER_MSB 0xCA
124 #define TDA10048_CVBER_LUT 0xCC
125 #define TDA10048_UNCOR_CTRL 0xCD
126 #define TDA10048_UNCOR_CPT_LSB 0xCE
127 #define TDA10048_UNCOR_CPT_MSB 0xCF
128 #define TDA10048_SOFT_IT_C3 0xD6
129 #define TDA10048_CONF_TS2 0xE0
130 #define TDA10048_CONF_TS1 0xE1
132 static unsigned int debug;
134 #define dprintk(level, fmt, arg...)\
135 do { if (debug >= level)\
136 printk(KERN_DEBUG "tda10048: " fmt, ## arg);\
159 static struct init_tab {
206 static struct pll_tab {
228 .flags = 0, .buf =
buf, .len = 2 };
230 dprintk(2,
"%s(reg = 0x%02x, data = 0x%02x)\n", __func__, reg, data);
235 printk(
"%s: writereg error (ret == %i)\n", __func__, ret);
237 return (ret != 1) ? -1 : 0;
248 .flags = 0, .buf = b0, .len = 1 },
250 .flags =
I2C_M_RD, .buf = b1, .len = 1 } };
252 dprintk(2,
"%s(reg = 0x%02x)\n", __func__, reg);
271 dprintk(2,
"%s(%d, ?, len = %d)\n", __func__, reg, len);
280 memcpy(buf + 1, data, len);
287 dprintk(2,
"%s(): write len = %d\n",
303 static int tda10048_set_phy2(
struct dvb_frontend *fe,
u32 sample_freq_hz,
309 dprintk(1,
"%s()\n", __func__);
311 if (sample_freq_hz == 0)
314 if (if_hz < (sample_freq_hz / 2)) {
319 do_div(t, sample_freq_hz);
324 t = sample_freq_hz - if_hz;
327 do_div(t, sample_freq_hz);
339 static int tda10048_set_wref(
struct dvb_frontend *fe,
u32 sample_freq_hz,
345 dprintk(1,
"%s()\n", __func__);
347 if (sample_freq_hz == 0)
356 z = 7 * sample_freq_hz;
369 static int tda10048_set_invwref(
struct dvb_frontend *fe,
u32 sample_freq_hz,
375 dprintk(1,
"%s()\n", __func__);
377 if (sample_freq_hz == 0)
395 static int tda10048_set_bandwidth(
struct dvb_frontend *fe,
399 dprintk(1,
"%s(bw=%d)\n", __func__, bw);
426 dprintk(1,
"%s(bw = %d)\n", __func__, bw);
446 (pll_tab[
i].if_freq_khz == if_freq_khz)) {
449 state->
xtal_hz = pll_tab[
i].clk_freq_khz * 1000;
477 static int tda10048_firmware_upload(
struct dvb_frontend *fe)
496 state->
i2c->dev.parent);
534 while (pos < fw->
size) {
536 if ((fw->
size - pos) > wlen)
542 &fw->
data[pos], cnt);
549 for (cnt = 0; cnt < 250 ; cnt += 10) {
572 static int tda10048_set_inversion(
struct dvb_frontend *fe,
int inversion)
576 dprintk(1,
"%s(%d)\n", __func__, inversion);
599 switch ((val & 0x60) >> 5) {
610 switch ((val & 0x18) >> 3) {
624 switch (val & 0x07) {
643 switch (val & 0x07) {
662 switch ((val & 0x0c) >> 2) {
676 switch (val & 0x03) {
692 dprintk(1,
"%s(%d)\n", __func__, enable);
708 dprintk(1,
"%s(%d)\n", __func__, serial);
727 static int tda10048_set_frontend(
struct dvb_frontend *fe)
740 if (fe->
ops.tuner_ops.set_params) {
742 if (fe->
ops.i2c_gate_ctrl)
743 fe->
ops.i2c_gate_ctrl(fe, 1);
745 fe->
ops.tuner_ops.set_params(fe);
747 if (fe->
ops.i2c_gate_ctrl)
748 fe->
ops.i2c_gate_ctrl(fe, 0);
766 dprintk(1,
"%s()\n", __func__);
774 tda10048_writereg(state, init_tab[i].reg, init_tab[i].data);
777 ret = tda10048_firmware_upload(fe);
783 tda10048_set_inversion(fe, config->
inversion);
786 tda10048_set_if(fe, 8000000);
787 tda10048_set_bandwidth(fe, 8000000);
790 tda10048_i2c_gate_ctrl(fe, 0);
804 dprintk(1,
"%s() status =0x%02x\n", __func__, reg);
824 static u32 cber_current;
828 dprintk(1,
"%s()\n", __func__);
836 cber_tmp *= 100000000;
838 cber_tmp = div_u64(cber_tmp, (cber_nmax * 32) + 1);
839 cber_current = (
u32)cber_tmp;
849 static int tda10048_read_signal_strength(
struct dvb_frontend *fe,
850 u16 *signal_strength)
855 dprintk(1,
"%s()\n", __func__);
857 *signal_strength = 65535;
861 *signal_strength -= (v << 8) | v;
867 static struct snr_tab {
1002 dprintk(1,
"%s()\n", __func__);
1006 if (v <= snr_tab[i].val) {
1007 *snr = snr_tab[
i].data;
1016 static int tda10048_read_ucblocks(
struct dvb_frontend *fe,
u32 *ucblocks)
1020 dprintk(1,
"%s()\n", __func__);
1025 if (*ucblocks == 0xFFFF)
1031 static int tda10048_get_frontend(
struct dvb_frontend *fe)
1036 dprintk(1,
"%s()\n", __func__);
1041 return tda10048_get_tps(state, p);
1044 static int tda10048_get_tune_settings(
struct dvb_frontend *fe,
1054 dprintk(1,
"%s()\n", __func__);
1058 static void tda10048_establish_defaults(
struct dvb_frontend *fe)
1067 "is not set (defaulting to %d)\n",
1075 "is not set (defaulting to %d)\n",
1083 "is not set (defaulting to %d)\n",
1091 "is not set (defaulting to %d)\n",
1104 dprintk(1,
"%s()\n", __func__);
1138 tda10048_establish_defaults(&state->
frontend);
1141 if (tda10048_set_if(&state->
frontend, 8000000) != 0)
1145 if (tda10048_set_bandwidth(&state->
frontend, 8000000) != 0)
1149 tda10048_i2c_gate_ctrl(&state->
frontend, 0);
1162 .name =
"NXP TDA10048HN DVB-T",
1163 .frequency_min = 177000000,
1164 .frequency_max = 858000000,
1165 .frequency_stepsize = 166666,
1173 .release = tda10048_release,
1174 .init = tda10048_init,
1175 .i2c_gate_ctrl = tda10048_i2c_gate_ctrl,
1176 .set_frontend = tda10048_set_frontend,
1177 .get_frontend = tda10048_get_frontend,
1178 .get_tune_settings = tda10048_get_tune_settings,
1179 .read_status = tda10048_read_status,
1180 .read_ber = tda10048_read_ber,
1181 .read_signal_strength = tda10048_read_signal_strength,
1182 .read_snr = tda10048_read_snr,
1183 .read_ucblocks = tda10048_read_ucblocks,