24 #include <linux/module.h>
27 #include <linux/i2c.h>
28 #include <linux/slab.h>
39 #define dprintk(args...) do { if (debug) {printk(KERN_DEBUG "MT2060: " args); printk("\n"); }} while (0)
45 { .
addr = priv->
cfg->i2c_address, .flags = 0, .buf = &
reg, .len = 1 },
46 { .addr = priv->
cfg->i2c_address, .flags =
I2C_M_RD, .buf =
val, .len = 1 },
61 .addr = priv->
cfg->i2c_address, .flags = 0, .buf =
buf, .len = 2
75 .
addr = priv->
cfg->i2c_address, .flags = 0, .buf =
buf, .len = len
86 static u8 mt2060_config1[] = {
88 0x3F, 0x74, 0x00, 0x08, 0x93
92 static u8 mt2060_config2[] = {
94 0x20, 0x1E, 0x30, 0xff, 0x80, 0xff, 0x00, 0x2c, 0x42
99 #ifdef MT2060_SPURCHECK
102 static int mt2060_spurcalc(
u32 lo1,
u32 lo2,
u32 if2)
107 for (I = 1; I < 10; I++) {
108 J = ((2*I*lo1)/lo2+1)/2;
109 diff = I*(
int)lo1-J*(
int)lo2;
110 if (diff < 0) diff=-diff;
111 dia = (diff-(
int)if2);
112 if (dia < 0) dia=-dia;
113 if (diamin > dia) diamin=dia;
118 #define BANDWIDTH 4000 // kHz
121 static int mt2060_spurcheck(
u32 lo1,
u32 lo2,
u32 if2)
128 Spur=mt2060_spurcalc(lo1,lo2,if2);
129 if (Spur < BANDWIDTH) {
131 dprintk(
"Spurs before : f_lo1: %d f_lo2: %d (kHz)",
134 Sp1 = mt2060_spurcalc(lo1+I,lo2+I,if2);
135 Sp2 = mt2060_spurcalc(lo1-I,lo2-I,if2);
138 J=-J; I=-
I; Spur=Sp2;
142 while (Spur < BANDWIDTH) {
144 Spur = mt2060_spurcalc(lo1+I,lo2+I,if2);
146 dprintk(
"Spurs after : f_lo1: %d f_lo2: %d (kHz)",
147 (
int)(lo1+I),(
int)(lo2+I));
153 #define IF2 36150 // IF2 frequency = 36.150 MHz
154 #define FREF 16000 // Quartz oscillator 16 MHz
175 if (fe->
ops.i2c_gate_ctrl)
176 fe->
ops.i2c_gate_ctrl(fe, 1);
178 mt2060_writeregs(priv,b,2);
182 f_lo1 = freq + if1 * 1000;
183 f_lo1 = (f_lo1 / 250) * 250;
184 f_lo2 = f_lo1 - freq -
IF2;
186 f_lo2 = ((f_lo2 + 25) / 50) * 50;
189 #ifdef MT2060_SPURCHECK
191 num1 = mt2060_spurcheck(f_lo1,f_lo2,IF2);
196 num1 = f_lo1 / (
FREF / 64);
201 num2 = f_lo2 * 64 / (
FREF / 128);
205 if (freq <= 95000) lnaband = 0xB0;
else
206 if (freq <= 180000) lnaband = 0xA0;
else
207 if (freq <= 260000) lnaband = 0x90;
else
208 if (freq <= 335000) lnaband = 0x80;
else
209 if (freq <= 425000) lnaband = 0x70;
else
210 if (freq <= 480000) lnaband = 0x60;
else
211 if (freq <= 570000) lnaband = 0x50;
else
212 if (freq <= 645000) lnaband = 0x40;
else
213 if (freq <= 730000) lnaband = 0x30;
else
214 if (freq <= 810000) lnaband = 0x20;
else lnaband = 0x10;
217 b[1] = lnaband | ((num1 >>2) & 0x0F);
219 b[3] = (num2 & 0x0F) | ((num1 & 3) << 4);
221 b[5] = ((num2 >>12) & 1) | (div2 << 1);
223 dprintk(
"IF1: %dMHz",(
int)if1);
224 dprintk(
"PLL freq=%dkHz f_lo1=%dkHz f_lo2=%dkHz",(
int)freq,(
int)f_lo1,(
int)f_lo2);
225 dprintk(
"PLL div1=%d num1=%d div2=%d num2=%d",(
int)div1,(
int)num1,(
int)div2,(
int)num2);
226 dprintk(
"PLL [1..5]: %2x %2x %2x %2x %2x",(
int)b[1],(
int)b[2],(
int)b[3],(
int)b[4],(
int)b[5]);
228 mt2060_writeregs(priv,b,6);
234 if ((b[0] & 0x88)==0x88)
240 if (fe->
ops.i2c_gate_ctrl)
241 fe->
ops.i2c_gate_ctrl(fe, 0);
246 static void mt2060_calibrate(
struct mt2060_priv *priv)
251 if (mt2060_writeregs(priv,mt2060_config1,
sizeof(mt2060_config1)))
253 if (mt2060_writeregs(priv,mt2060_config2,
sizeof(mt2060_config2)))
257 mt2060_writereg(priv,
REG_VGAG, (priv->
cfg->clock_out << 6) | 0x30);
279 while (i++ < 10 && mt2060_readreg(priv,
REG_MISC_STAT, &b) == 0 && (b & (1 << 6)) == 0)
284 dprintk(
"calibration was successful: %d", (
int)priv->
fmfreq);
298 *frequency =
IF2 * 1000;
307 if (fe->
ops.i2c_gate_ctrl)
308 fe->
ops.i2c_gate_ctrl(fe, 1);
310 ret = mt2060_writereg(priv,
REG_VGAG,
311 (priv->
cfg->clock_out << 6) | 0x33);
313 if (fe->
ops.i2c_gate_ctrl)
314 fe->
ops.i2c_gate_ctrl(fe, 0);
324 if (fe->
ops.i2c_gate_ctrl)
325 fe->
ops.i2c_gate_ctrl(fe, 1);
327 ret = mt2060_writereg(priv,
REG_VGAG,
328 (priv->
cfg->clock_out << 6) | 0x30);
330 if (fe->
ops.i2c_gate_ctrl)
331 fe->
ops.i2c_gate_ctrl(fe, 0);
345 .name =
"Microtune MT2060",
346 .frequency_min = 48000000,
347 .frequency_max = 860000000,
348 .frequency_step = 50000,
351 .release = mt2060_release,
354 .sleep = mt2060_sleep,
356 .set_params = mt2060_set_params,
357 .get_frequency = mt2060_get_frequency,
358 .get_if_frequency = mt2060_get_if_frequency,
375 if (fe->
ops.i2c_gate_ctrl)
376 fe->
ops.i2c_gate_ctrl(fe, 1);
392 mt2060_calibrate(priv);
394 if (fe->
ops.i2c_gate_ctrl)
395 fe->
ops.i2c_gate_ctrl(fe, 0);