22 #include <linux/module.h>
26 #include <linux/i2c.h>
27 #include <linux/slab.h>
38 #define itd_dbg(args...) do { \
40 printk(KERN_DEBUG "ITD1000: " args);\
44 #define itd_warn(args...) do { \
45 printk(KERN_WARNING "ITD1000: " args); \
48 #define itd_info(args...) do { \
49 printk(KERN_INFO "ITD1000: " args); \
57 .
addr = state->
cfg->i2c_address, .flags = 0, .buf =
buf, .len = len+1
75 { .addr = state->
cfg->i2c_address, .flags = 0, .buf = &
reg, .len = 1 },
76 { .addr = state->
cfg->i2c_address, .flags =
I2C_M_RD, .buf = &
val, .len = 1 },
80 itd1000_write_regs(state, (reg - 1) & 0xff, &state->
shadow[(reg - 1) & 0xff], 1);
83 itd_warn(
"itd1000 I2C read failed\n");
91 int ret = itd1000_write_regs(state, r, &v, 1);
101 } itd1000_lpf_pga[] = {
103 { 5200000, 0x8, 0x3 },
104 { 12200000, 0x4, 0x3 },
105 { 15400000, 0x2, 0x3 },
106 { 19800000, 0x2, 0x3 },
107 { 21500000, 0x2, 0x3 },
108 { 24500000, 0x2, 0x3 },
109 { 28400000, 0x2, 0x3 },
110 { 33400000, 0x2, 0x3 },
111 { 34400000, 0x1, 0x4 },
112 { 34400000, 0x1, 0x4 },
113 { 38400000, 0x1, 0x4 },
114 { 38400000, 0x1, 0x4 },
115 { 40400000, 0x1, 0x4 },
116 { 45400000, 0x1, 0x4 },
122 u8 con1 = itd1000_read_reg(state,
CON1) & 0xfd;
123 u8 pllfh = itd1000_read_reg(state,
PLLFH) & 0x0f;
125 u8 bw = itd1000_read_reg(state,
BW) & 0xf0;
127 itd_dbg(
"symbol_rate = %d\n", symbol_rate);
130 itd1000_write_reg(state,
CON1, con1 | (1 << 1));
132 for (i = 0; i <
ARRAY_SIZE(itd1000_lpf_pga); i++)
133 if (symbol_rate < itd1000_lpf_pga[i].symbol_rate) {
134 itd_dbg(
"symrate: index: %d pgaext: %x, bbgvmin: %x\n", i, itd1000_lpf_pga[i].
pgaext, itd1000_lpf_pga[i].bbgvmin);
135 itd1000_write_reg(state,
PLLFH, pllfh | (itd1000_lpf_pga[i].
pgaext << 4));
136 itd1000_write_reg(state,
BBGVMIN, bbgvmin | (itd1000_lpf_pga[i].bbgvmin));
137 itd1000_write_reg(state,
BW, bw | (i & 0x0f));
141 itd1000_write_reg(state,
CON1, con1 | (0 << 1));
147 } itd1000_vcorg[] = {
168 u8 gvbb_i2c = itd1000_read_reg(state,
GVBB_I2C) & 0xbf;
173 itd1000_write_reg(state,
GVBB_I2C, gvbb_i2c | (1 << 6));
175 for (i = 0; i <
ARRAY_SIZE(itd1000_vcorg); i++) {
176 if (freq_khz < itd1000_vcorg[i].
fmax_rg) {
177 itd1000_write_reg(state,
VCO_CHP1_I2C, vco_chp1_i2c | (itd1000_vcorg[i].
vcorg << 4));
180 adcout = itd1000_read_reg(state,
PLLLOCK) & 0x0f;
182 itd_dbg(
"VCO: %dkHz: %d -> ADCOUT: %d %02x\n", freq_khz, itd1000_vcorg[i].
vcorg, adcout, vco_chp1_i2c);
185 if (!(itd1000_vcorg[i].
vcorg == 7 || itd1000_vcorg[i].
vcorg == 15))
186 itd1000_write_reg(state,
VCO_CHP1_I2C, vco_chp1_i2c | ((itd1000_vcorg[i].
vcorg + 1) << 4));
187 }
else if (adcout < 2) {
188 if (!(itd1000_vcorg[i].
vcorg == 1 || itd1000_vcorg[i].
vcorg == 9))
189 itd1000_write_reg(state,
VCO_CHP1_I2C, vco_chp1_i2c | ((itd1000_vcorg[i].
vcorg - 1) << 4));
196 static const struct {
199 } itd1000_fre_values[] = {
200 { 1075000, { 0x59, 0x1d, 0x1c, 0x17, 0x16, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
201 { 1250000, { 0x89, 0x1e, 0x1d, 0x17, 0x15, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
202 { 1450000, { 0x89, 0x1e, 0x1d, 0x17, 0x15, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
203 { 1650000, { 0x69, 0x1e, 0x1d, 0x17, 0x15, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
204 { 1750000, { 0x69, 0x1e, 0x17, 0x15, 0x14, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
205 { 1850000, { 0x69, 0x1d, 0x17, 0x16, 0x14, 0x0f, 0x0e, 0x0d, 0x0b, 0x0a } },
206 { 1900000, { 0x69, 0x1d, 0x17, 0x15, 0x14, 0x0f, 0x0e, 0x0d, 0x0b, 0x0a } },
207 { 1950000, { 0x69, 0x1d, 0x17, 0x16, 0x14, 0x13, 0x0e, 0x0d, 0x0b, 0x0a } },
208 { 2050000, { 0x69, 0x1e, 0x1d, 0x17, 0x16, 0x14, 0x13, 0x0e, 0x0b, 0x0a } },
209 { 2150000, { 0x69, 0x1d, 0x1c, 0x17, 0x15, 0x14, 0x13, 0x0f, 0x0e, 0x0b } }
221 plln = (freq_khz * 1000) / 2 /
FREF;
224 tmp = plln % 1000000;
231 state->
frequency = ((plln * 1000) + (pllf * 1000)/1048576) * 2*
FREF;
232 itd_dbg(
"frequency: %dkHz (wanted) %dkHz (set), PLLF = %d, PLLN = %d\n", freq_khz, state->
frequency, pllf, plln);
234 itd1000_write_reg(state,
PLLNH, 0x80);
235 itd1000_write_reg(state,
PLLNL, plln & 0xff);
236 itd1000_write_reg(state,
PLLFH, (itd1000_read_reg(state,
PLLFH) & 0xf0) | ((pllf >> 16) & 0x0f));
237 itd1000_write_reg(state,
PLLFM, (pllf >> 8) & 0xff);
238 itd1000_write_reg(state,
PLLFL, (pllf >> 0) & 0xff);
240 for (i = 0; i <
ARRAY_SIZE(itd1000_fre_values); i++) {
241 if (freq_khz <= itd1000_fre_values[i].
freq) {
242 itd_dbg(
"fre_values: %d\n", i);
243 itd1000_write_reg(state,
RFTR, itd1000_fre_values[i].
values[0]);
244 for (j = 0; j < 9; j++)
245 itd1000_write_reg(state,
RFST1+j, itd1000_fre_values[i].values[j+1]);
250 itd1000_set_vco(state, freq_khz);
253 static int itd1000_set_parameters(
struct dvb_frontend *fe)
262 pllcon1 = itd1000_read_reg(state,
PLLCON1) & 0x7f;
263 itd1000_write_reg(state,
PLLCON1, pllcon1 | (1 << 7));
264 itd1000_write_reg(state,
PLLCON1, pllcon1);
281 static u8 itd1000_init_tab[][2] = {
312 static u8 itd1000_reinit_tab[][2] = {
326 for (i = 0; i <
ARRAY_SIZE(itd1000_init_tab); i++)
327 itd1000_write_reg(state, itd1000_init_tab[i][0], itd1000_init_tab[i][1]);
329 for (i = 0; i <
ARRAY_SIZE(itd1000_reinit_tab); i++)
330 itd1000_write_reg(state, itd1000_reinit_tab[i][0], itd1000_reinit_tab[i][1]);
349 .name =
"Integrant ITD1000",
350 .frequency_min = 950000,
351 .frequency_max = 2150000,
352 .frequency_step = 125,
355 .release = itd1000_release,
357 .init = itd1000_init,
358 .sleep = itd1000_sleep,
360 .set_params = itd1000_set_parameters,
361 .get_frequency = itd1000_get_frequency,
362 .get_bandwidth = itd1000_get_bandwidth
378 i = itd1000_read_reg(state, 0);
383 itd_info(
"successfully identified (ID: %d)\n", i);
386 for (i = 0x65; i < 0x9c; i++)
387 state->
shadow[i] = itd1000_read_reg(state, i);