diff options
Diffstat (limited to 'drivers/media/video/tda8290.c')
-rw-r--r-- | drivers/media/video/tda8290.c | 144 |
1 files changed, 104 insertions, 40 deletions
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c index 027c8a074dfe..1a1bef0e9c3d 100644 --- a/drivers/media/video/tda8290.c +++ b/drivers/media/video/tda8290.c | |||
@@ -192,14 +192,52 @@ static struct tda827xa_data tda827xa_analog[] = { | |||
192 | { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */ | 192 | { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */ |
193 | }; | 193 | }; |
194 | 194 | ||
195 | static void tda827xa_lna_gain(struct i2c_client *c, int high) | ||
196 | { | ||
197 | struct tuner *t = i2c_get_clientdata(c); | ||
198 | unsigned char buf[] = {0x22, 0x01}; | ||
199 | int arg; | ||
200 | struct i2c_msg msg = {.addr = c->addr, .flags = 0, .buf = buf, .len = sizeof(buf)}; | ||
201 | if (t->config) { | ||
202 | if (high) | ||
203 | tuner_dbg("setting LNA to high gain\n"); | ||
204 | else | ||
205 | tuner_dbg("setting LNA to low gain\n"); | ||
206 | } | ||
207 | switch (t->config) { | ||
208 | case 0: /* no LNA */ | ||
209 | break; | ||
210 | case 1: /* switch is GPIO 0 of tda8290 */ | ||
211 | case 2: | ||
212 | /* turn Vsync on */ | ||
213 | if (t->std & V4L2_STD_MN) | ||
214 | arg = 1; | ||
215 | else | ||
216 | arg = 0; | ||
217 | if (t->tuner_callback) | ||
218 | t->tuner_callback(c->adapter->algo_data, 1, arg); | ||
219 | buf[1] = high ? 0 : 1; | ||
220 | if (t->config == 2) | ||
221 | buf[1] = high ? 1 : 0; | ||
222 | i2c_transfer(c->adapter, &msg, 1); | ||
223 | break; | ||
224 | case 3: /* switch with GPIO of saa713x */ | ||
225 | if (t->tuner_callback) | ||
226 | t->tuner_callback(c->adapter->algo_data, 0, high); | ||
227 | break; | ||
228 | } | ||
229 | } | ||
230 | |||
195 | static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq) | 231 | static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq) |
196 | { | 232 | { |
197 | unsigned char tuner_reg[14]; | 233 | unsigned char tuner_reg[11]; |
198 | unsigned char reg2[2]; | ||
199 | u32 N; | 234 | u32 N; |
200 | int i; | 235 | int i; |
201 | struct tuner *t = i2c_get_clientdata(c); | 236 | struct tuner *t = i2c_get_clientdata(c); |
202 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0}; | 237 | struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0, .buf = tuner_reg}; |
238 | |||
239 | tda827xa_lna_gain( c, 1); | ||
240 | msleep(10); | ||
203 | 241 | ||
204 | if (t->mode == V4L2_TUNER_RADIO) | 242 | if (t->mode == V4L2_TUNER_RADIO) |
205 | freq = freq / 1000; | 243 | freq = freq / 1000; |
@@ -222,48 +260,58 @@ static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq) | |||
222 | tuner_reg[5] = (tda827xa_analog[i].spd << 5) + (tda827xa_analog[i].svco << 3) + | 260 | tuner_reg[5] = (tda827xa_analog[i].spd << 5) + (tda827xa_analog[i].svco << 3) + |
223 | tda827xa_analog[i].sbs; | 261 | tda827xa_analog[i].sbs; |
224 | tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4); | 262 | tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4); |
225 | tuner_reg[7] = 0x0c; | 263 | tuner_reg[7] = 0x1c; |
226 | tuner_reg[8] = 4; | 264 | tuner_reg[8] = 4; |
227 | tuner_reg[9] = 0x20; | 265 | tuner_reg[9] = 0x20; |
228 | tuner_reg[10] = 0xff; | 266 | tuner_reg[10] = 0x00; |
229 | tuner_reg[11] = 0xe0; | 267 | msg.len = 11; |
230 | tuner_reg[12] = 0; | 268 | i2c_transfer(c->adapter, &msg, 1); |
231 | tuner_reg[13] = 0x39 + (t->tda827x_lpsel << 1); | ||
232 | 269 | ||
233 | msg.buf = tuner_reg; | 270 | tuner_reg[0] = 0x90; |
234 | msg.len = 14; | 271 | tuner_reg[1] = 0xff; |
272 | tuner_reg[2] = 0xe0; | ||
273 | tuner_reg[3] = 0; | ||
274 | tuner_reg[4] = 0x99 + (t->tda827x_lpsel << 1); | ||
275 | msg.len = 5; | ||
235 | i2c_transfer(c->adapter, &msg, 1); | 276 | i2c_transfer(c->adapter, &msg, 1); |
236 | 277 | ||
237 | msg.buf= reg2; | 278 | tuner_reg[0] = 0xa0; |
279 | tuner_reg[1] = 0xc0; | ||
238 | msg.len = 2; | 280 | msg.len = 2; |
239 | reg2[0] = 0x60; | ||
240 | reg2[1] = 0x3c; | ||
241 | i2c_transfer(c->adapter, &msg, 1); | 281 | i2c_transfer(c->adapter, &msg, 1); |
242 | 282 | ||
243 | reg2[0] = 0xa0; | 283 | tuner_reg[0] = 0x30; |
244 | reg2[1] = 0xc0; | 284 | tuner_reg[1] = 0x10 + tda827xa_analog[i].scr; |
245 | i2c_transfer(c->adapter, &msg, 1); | 285 | i2c_transfer(c->adapter, &msg, 1); |
246 | 286 | ||
247 | msleep(2); | 287 | msg.flags = I2C_M_RD; |
248 | reg2[0] = 0x30; | 288 | i2c_transfer(c->adapter, &msg, 1); |
249 | reg2[1] = 0x10 + tda827xa_analog[i].scr; | 289 | msg.flags = 0; |
290 | tuner_reg[1] >>= 4; | ||
291 | tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]); | ||
292 | if (tuner_reg[1] < 1) | ||
293 | tda827xa_lna_gain( c, 0); | ||
294 | |||
295 | msleep(100); | ||
296 | tuner_reg[0] = 0x60; | ||
297 | tuner_reg[1] = 0x3c; | ||
250 | i2c_transfer(c->adapter, &msg, 1); | 298 | i2c_transfer(c->adapter, &msg, 1); |
251 | 299 | ||
252 | msleep(550); | 300 | msleep(163); |
253 | reg2[0] = 0x50; | 301 | tuner_reg[0] = 0x50; |
254 | reg2[1] = 0x8f + (tda827xa_analog[i].gc3 << 4); | 302 | tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4); |
255 | i2c_transfer(c->adapter, &msg, 1); | 303 | i2c_transfer(c->adapter, &msg, 1); |
256 | 304 | ||
257 | reg2[0] = 0x80; | 305 | tuner_reg[0] = 0x80; |
258 | reg2[1] = 0x28; | 306 | tuner_reg[1] = 0x28; |
259 | i2c_transfer(c->adapter, &msg, 1); | 307 | i2c_transfer(c->adapter, &msg, 1); |
260 | 308 | ||
261 | reg2[0] = 0xb0; | 309 | tuner_reg[0] = 0xb0; |
262 | reg2[1] = 0x01; | 310 | tuner_reg[1] = 0x01; |
263 | i2c_transfer(c->adapter, &msg, 1); | 311 | i2c_transfer(c->adapter, &msg, 1); |
264 | 312 | ||
265 | reg2[0] = 0xc0; | 313 | tuner_reg[0] = 0xc0; |
266 | reg2[1] = 0x19 + (t->tda827x_lpsel << 1); | 314 | tuner_reg[1] = 0x19 + (t->tda827x_lpsel << 1); |
267 | i2c_transfer(c->adapter, &msg, 1); | 315 | i2c_transfer(c->adapter, &msg, 1); |
268 | } | 316 | } |
269 | 317 | ||
@@ -319,7 +367,9 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq) | |||
319 | unsigned char addr_pll_stat = 0x1b; | 367 | unsigned char addr_pll_stat = 0x1b; |
320 | unsigned char adc_sat, agc_stat, | 368 | unsigned char adc_sat, agc_stat, |
321 | pll_stat; | 369 | pll_stat; |
370 | int i; | ||
322 | 371 | ||
372 | tuner_dbg("tda827xa config is 0x%02x\n", t->config); | ||
323 | i2c_master_send(c, easy_mode, 2); | 373 | i2c_master_send(c, easy_mode, 2); |
324 | i2c_master_send(c, agc_out_on, 2); | 374 | i2c_master_send(c, agc_out_on, 2); |
325 | i2c_master_send(c, soft_reset, 2); | 375 | i2c_master_send(c, soft_reset, 2); |
@@ -340,17 +390,22 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq) | |||
340 | tda827xa_tune(c, ifc, freq); | 390 | tda827xa_tune(c, ifc, freq); |
341 | else | 391 | else |
342 | tda827x_tune(c, ifc, freq); | 392 | tda827x_tune(c, ifc, freq); |
393 | for (i = 0; i < 3; i++) { | ||
394 | i2c_master_send(c, &addr_pll_stat, 1); | ||
395 | i2c_master_recv(c, &pll_stat, 1); | ||
396 | if (pll_stat & 0x80) { | ||
397 | i2c_master_send(c, &addr_adc_sat, 1); | ||
398 | i2c_master_recv(c, &adc_sat, 1); | ||
399 | i2c_master_send(c, &addr_agc_stat, 1); | ||
400 | i2c_master_recv(c, &agc_stat, 1); | ||
401 | tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); | ||
402 | break; | ||
403 | } else { | ||
404 | tuner_dbg("tda8290 not locked, no signal?\n"); | ||
405 | msleep(100); | ||
406 | } | ||
407 | } | ||
343 | /* adjust headroom resp. gain */ | 408 | /* adjust headroom resp. gain */ |
344 | i2c_master_send(c, &addr_adc_sat, 1); | ||
345 | i2c_master_recv(c, &adc_sat, 1); | ||
346 | i2c_master_send(c, &addr_agc_stat, 1); | ||
347 | i2c_master_recv(c, &agc_stat, 1); | ||
348 | i2c_master_send(c, &addr_pll_stat, 1); | ||
349 | i2c_master_recv(c, &pll_stat, 1); | ||
350 | if (pll_stat & 0x80) | ||
351 | tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat); | ||
352 | else | ||
353 | tuner_dbg("tda8290 not locked, no signal?\n"); | ||
354 | if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) { | 409 | if ((agc_stat > 115) || (!(pll_stat & 0x80) && (adc_sat < 20))) { |
355 | tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n", | 410 | tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n", |
356 | agc_stat, adc_sat, pll_stat & 0x80); | 411 | agc_stat, adc_sat, pll_stat & 0x80); |
@@ -407,7 +462,6 @@ static void set_audio(struct tuner *t) | |||
407 | char* mode; | 462 | char* mode; |
408 | 463 | ||
409 | t->tda827x_lpsel = 0; | 464 | t->tda827x_lpsel = 0; |
410 | mode = "xx"; | ||
411 | if (t->std & V4L2_STD_MN) { | 465 | if (t->std & V4L2_STD_MN) { |
412 | t->sgIF = 92; | 466 | t->sgIF = 92; |
413 | t->tda8290_easy_mode = 0x01; | 467 | t->tda8290_easy_mode = 0x01; |
@@ -437,8 +491,12 @@ static void set_audio(struct tuner *t) | |||
437 | t->sgIF = 20; | 491 | t->sgIF = 20; |
438 | t->tda8290_easy_mode = 0x40; | 492 | t->tda8290_easy_mode = 0x40; |
439 | mode = "LC"; | 493 | mode = "LC"; |
494 | } else { | ||
495 | t->sgIF = 124; | ||
496 | t->tda8290_easy_mode = 0x10; | ||
497 | mode = "xx"; | ||
440 | } | 498 | } |
441 | tuner_dbg("setting tda8290 to system %s\n", mode); | 499 | tuner_dbg("setting tda8290 to system %s\n", mode); |
442 | } | 500 | } |
443 | 501 | ||
444 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) | 502 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) |
@@ -487,11 +545,16 @@ static void standby(struct i2c_client *c) | |||
487 | 545 | ||
488 | static void tda8290_init_if(struct i2c_client *c) | 546 | static void tda8290_init_if(struct i2c_client *c) |
489 | { | 547 | { |
548 | struct tuner *t = i2c_get_clientdata(c); | ||
490 | unsigned char set_VS[] = { 0x30, 0x6F }; | 549 | unsigned char set_VS[] = { 0x30, 0x6F }; |
550 | unsigned char set_GP00_CF[] = { 0x20, 0x01 }; | ||
491 | unsigned char set_GP01_CF[] = { 0x20, 0x0B }; | 551 | unsigned char set_GP01_CF[] = { 0x20, 0x0B }; |
492 | 552 | ||
553 | if ((t->config == 1) || (t->config == 2)) | ||
554 | i2c_master_send(c, set_GP00_CF, 2); | ||
555 | else | ||
556 | i2c_master_send(c, set_GP01_CF, 2); | ||
493 | i2c_master_send(c, set_VS, 2); | 557 | i2c_master_send(c, set_VS, 2); |
494 | i2c_master_send(c, set_GP01_CF, 2); | ||
495 | } | 558 | } |
496 | 559 | ||
497 | static void tda8290_init_tuner(struct i2c_client *c) | 560 | static void tda8290_init_tuner(struct i2c_client *c) |
@@ -576,6 +639,7 @@ int tda8290_init(struct i2c_client *c) | |||
576 | t->has_signal = has_signal; | 639 | t->has_signal = has_signal; |
577 | t->standby = standby; | 640 | t->standby = standby; |
578 | t->tda827x_lpsel = 0; | 641 | t->tda827x_lpsel = 0; |
642 | t->mode = V4L2_TUNER_ANALOG_TV; | ||
579 | 643 | ||
580 | tda8290_init_tuner(c); | 644 | tda8290_init_tuner(c); |
581 | tda8290_init_if(c); | 645 | tda8290_init_if(c); |