aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tda8290.c
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2007-05-29 21:54:06 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2007-07-18 13:23:48 -0400
commitb208319993ceff7ebfcc6bb914fe94d29e48a891 (patch)
tree0a0697806b221c7711914dbdfe2bd3972c206b23 /drivers/media/video/tda8290.c
parent56584c9ea9a6dcd672f97ebfeebc4903e8b903bc (diff)
V4L/DVB (5719): Tuner: Move device-specific private data out of tuner struct
Create private data struct for device specific private data. Signed-off-by: Michael Krufky <mkrufky@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/tda8290.c')
-rw-r--r--drivers/media/video/tda8290.c105
1 files changed, 65 insertions, 40 deletions
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index 1a1bef0e9c3d..7bdf968bf6e5 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -25,6 +25,16 @@
25 25
26/* ---------------------------------------------------------------------- */ 26/* ---------------------------------------------------------------------- */
27 27
28struct tda8290_priv {
29 unsigned char tda8290_easy_mode;
30 unsigned char tda827x_lpsel;
31 unsigned char tda827x_addr;
32 unsigned char tda827x_ver;
33 unsigned int sgIF;
34};
35
36/* ---------------------------------------------------------------------- */
37
28struct tda827x_data { 38struct tda827x_data {
29 u32 lomax; 39 u32 lomax;
30 u8 spd; 40 u8 spd;
@@ -76,7 +86,8 @@ static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
76 u32 N; 86 u32 N;
77 int i; 87 int i;
78 struct tuner *t = i2c_get_clientdata(c); 88 struct tuner *t = i2c_get_clientdata(c);
79 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0}; 89 struct tda8290_priv *priv = t->priv;
90 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0};
80 91
81 if (t->mode == V4L2_TUNER_RADIO) 92 if (t->mode == V4L2_TUNER_RADIO)
82 freq = freq / 1000; 93 freq = freq / 1000;
@@ -95,7 +106,7 @@ static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
95 tuner_reg[1] = (unsigned char)(N>>8); 106 tuner_reg[1] = (unsigned char)(N>>8);
96 tuner_reg[2] = (unsigned char) N; 107 tuner_reg[2] = (unsigned char) N;
97 tuner_reg[3] = 0x40; 108 tuner_reg[3] = 0x40;
98 tuner_reg[4] = 0x52 + (t->tda827x_lpsel << 5); 109 tuner_reg[4] = 0x52 + (priv->tda827x_lpsel << 5);
99 tuner_reg[5] = (tda827x_analog[i].spd << 6) + (tda827x_analog[i].div1p5 <<5) + 110 tuner_reg[5] = (tda827x_analog[i].spd << 6) + (tda827x_analog[i].div1p5 <<5) +
100 (tda827x_analog[i].bs <<3) + tda827x_analog[i].bp; 111 (tda827x_analog[i].bs <<3) + tda827x_analog[i].bp;
101 tuner_reg[6] = 0x8f + (tda827x_analog[i].gc3 << 4); 112 tuner_reg[6] = 0x8f + (tda827x_analog[i].gc3 << 4);
@@ -146,8 +157,9 @@ static void tda827x_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
146static void tda827x_agcf(struct i2c_client *c) 157static void tda827x_agcf(struct i2c_client *c)
147{ 158{
148 struct tuner *t = i2c_get_clientdata(c); 159 struct tuner *t = i2c_get_clientdata(c);
160 struct tda8290_priv *priv = t->priv;
149 unsigned char data[] = {0x80, 0x0c}; 161 unsigned char data[] = {0x80, 0x0c};
150 struct i2c_msg msg = {.addr = t->tda827x_addr, .buf = data, 162 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
151 .flags = 0, .len = 2}; 163 .flags = 0, .len = 2};
152 i2c_transfer(c->adapter, &msg, 1); 164 i2c_transfer(c->adapter, &msg, 1);
153} 165}
@@ -234,7 +246,8 @@ static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
234 u32 N; 246 u32 N;
235 int i; 247 int i;
236 struct tuner *t = i2c_get_clientdata(c); 248 struct tuner *t = i2c_get_clientdata(c);
237 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags = 0, .buf = tuner_reg}; 249 struct tda8290_priv *priv = t->priv;
250 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0, .buf = tuner_reg};
238 251
239 tda827xa_lna_gain( c, 1); 252 tda827xa_lna_gain( c, 1);
240 msleep(10); 253 msleep(10);
@@ -271,7 +284,7 @@ static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
271 tuner_reg[1] = 0xff; 284 tuner_reg[1] = 0xff;
272 tuner_reg[2] = 0xe0; 285 tuner_reg[2] = 0xe0;
273 tuner_reg[3] = 0; 286 tuner_reg[3] = 0;
274 tuner_reg[4] = 0x99 + (t->tda827x_lpsel << 1); 287 tuner_reg[4] = 0x99 + (priv->tda827x_lpsel << 1);
275 msg.len = 5; 288 msg.len = 5;
276 i2c_transfer(c->adapter, &msg, 1); 289 i2c_transfer(c->adapter, &msg, 1);
277 290
@@ -311,15 +324,16 @@ static void tda827xa_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
311 i2c_transfer(c->adapter, &msg, 1); 324 i2c_transfer(c->adapter, &msg, 1);
312 325
313 tuner_reg[0] = 0xc0; 326 tuner_reg[0] = 0xc0;
314 tuner_reg[1] = 0x19 + (t->tda827x_lpsel << 1); 327 tuner_reg[1] = 0x19 + (priv->tda827x_lpsel << 1);
315 i2c_transfer(c->adapter, &msg, 1); 328 i2c_transfer(c->adapter, &msg, 1);
316} 329}
317 330
318static void tda827xa_agcf(struct i2c_client *c) 331static void tda827xa_agcf(struct i2c_client *c)
319{ 332{
320 struct tuner *t = i2c_get_clientdata(c); 333 struct tuner *t = i2c_get_clientdata(c);
334 struct tda8290_priv *priv = t->priv;
321 unsigned char data[] = {0x80, 0x2c}; 335 unsigned char data[] = {0x80, 0x2c};
322 struct i2c_msg msg = {.addr = t->tda827x_addr, .buf = data, 336 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
323 .flags = 0, .len = 2}; 337 .flags = 0, .len = 2};
324 i2c_transfer(c->adapter, &msg, 1); 338 i2c_transfer(c->adapter, &msg, 1);
325} 339}
@@ -347,8 +361,9 @@ static void tda8290_i2c_bridge(struct i2c_client *c, int close)
347static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq) 361static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
348{ 362{
349 struct tuner *t = i2c_get_clientdata(c); 363 struct tuner *t = i2c_get_clientdata(c);
364 struct tda8290_priv *priv = t->priv;
350 unsigned char soft_reset[] = { 0x00, 0x00 }; 365 unsigned char soft_reset[] = { 0x00, 0x00 };
351 unsigned char easy_mode[] = { 0x01, t->tda8290_easy_mode }; 366 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
352 unsigned char expert_mode[] = { 0x01, 0x80 }; 367 unsigned char expert_mode[] = { 0x01, 0x80 };
353 unsigned char agc_out_on[] = { 0x02, 0x00 }; 368 unsigned char agc_out_on[] = { 0x02, 0x00 };
354 unsigned char gainset_off[] = { 0x28, 0x14 }; 369 unsigned char gainset_off[] = { 0x28, 0x14 };
@@ -375,18 +390,18 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
375 i2c_master_send(c, soft_reset, 2); 390 i2c_master_send(c, soft_reset, 2);
376 msleep(1); 391 msleep(1);
377 392
378 expert_mode[1] = t->tda8290_easy_mode + 0x80; 393 expert_mode[1] = priv->tda8290_easy_mode + 0x80;
379 i2c_master_send(c, expert_mode, 2); 394 i2c_master_send(c, expert_mode, 2);
380 i2c_master_send(c, gainset_off, 2); 395 i2c_master_send(c, gainset_off, 2);
381 i2c_master_send(c, if_agc_spd, 2); 396 i2c_master_send(c, if_agc_spd, 2);
382 if (t->tda8290_easy_mode & 0x60) 397 if (priv->tda8290_easy_mode & 0x60)
383 i2c_master_send(c, adc_head_9, 2); 398 i2c_master_send(c, adc_head_9, 2);
384 else 399 else
385 i2c_master_send(c, adc_head_6, 2); 400 i2c_master_send(c, adc_head_6, 2);
386 i2c_master_send(c, pll_bw_nom, 2); 401 i2c_master_send(c, pll_bw_nom, 2);
387 402
388 tda8290_i2c_bridge(c, 1); 403 tda8290_i2c_bridge(c, 1);
389 if (t->tda827x_ver != 0) 404 if (priv->tda827x_ver != 0)
390 tda827xa_tune(c, ifc, freq); 405 tda827xa_tune(c, ifc, freq);
391 else 406 else
392 tda827x_tune(c, ifc, freq); 407 tda827x_tune(c, ifc, freq);
@@ -418,7 +433,7 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
418 if ((agc_stat > 115) || !(pll_stat & 0x80)) { 433 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
419 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", 434 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
420 agc_stat, pll_stat & 0x80); 435 agc_stat, pll_stat & 0x80);
421 if (t->tda827x_ver != 0) 436 if (priv->tda827x_ver != 0)
422 tda827xa_agcf(c); 437 tda827xa_agcf(c);
423 else 438 else
424 tda827x_agcf(c); 439 tda827x_agcf(c);
@@ -437,7 +452,7 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
437 } 452 }
438 453
439 /* l/ l' deadlock? */ 454 /* l/ l' deadlock? */
440 if(t->tda8290_easy_mode & 0x60) { 455 if(priv->tda8290_easy_mode & 0x60) {
441 i2c_master_send(c, &addr_adc_sat, 1); 456 i2c_master_send(c, &addr_adc_sat, 1);
442 i2c_master_recv(c, &adc_sat, 1); 457 i2c_master_recv(c, &adc_sat, 1);
443 i2c_master_send(c, &addr_pll_stat, 1); 458 i2c_master_send(c, &addr_pll_stat, 1);
@@ -459,41 +474,42 @@ static int tda8290_tune(struct i2c_client *c, u16 ifc, unsigned int freq)
459 474
460static void set_audio(struct tuner *t) 475static void set_audio(struct tuner *t)
461{ 476{
477 struct tda8290_priv *priv = t->priv;
462 char* mode; 478 char* mode;
463 479
464 t->tda827x_lpsel = 0; 480 priv->tda827x_lpsel = 0;
465 if (t->std & V4L2_STD_MN) { 481 if (t->std & V4L2_STD_MN) {
466 t->sgIF = 92; 482 priv->sgIF = 92;
467 t->tda8290_easy_mode = 0x01; 483 priv->tda8290_easy_mode = 0x01;
468 t->tda827x_lpsel = 1; 484 priv->tda827x_lpsel = 1;
469 mode = "MN"; 485 mode = "MN";
470 } else if (t->std & V4L2_STD_B) { 486 } else if (t->std & V4L2_STD_B) {
471 t->sgIF = 108; 487 priv->sgIF = 108;
472 t->tda8290_easy_mode = 0x02; 488 priv->tda8290_easy_mode = 0x02;
473 mode = "B"; 489 mode = "B";
474 } else if (t->std & V4L2_STD_GH) { 490 } else if (t->std & V4L2_STD_GH) {
475 t->sgIF = 124; 491 priv->sgIF = 124;
476 t->tda8290_easy_mode = 0x04; 492 priv->tda8290_easy_mode = 0x04;
477 mode = "GH"; 493 mode = "GH";
478 } else if (t->std & V4L2_STD_PAL_I) { 494 } else if (t->std & V4L2_STD_PAL_I) {
479 t->sgIF = 124; 495 priv->sgIF = 124;
480 t->tda8290_easy_mode = 0x08; 496 priv->tda8290_easy_mode = 0x08;
481 mode = "I"; 497 mode = "I";
482 } else if (t->std & V4L2_STD_DK) { 498 } else if (t->std & V4L2_STD_DK) {
483 t->sgIF = 124; 499 priv->sgIF = 124;
484 t->tda8290_easy_mode = 0x10; 500 priv->tda8290_easy_mode = 0x10;
485 mode = "DK"; 501 mode = "DK";
486 } else if (t->std & V4L2_STD_SECAM_L) { 502 } else if (t->std & V4L2_STD_SECAM_L) {
487 t->sgIF = 124; 503 priv->sgIF = 124;
488 t->tda8290_easy_mode = 0x20; 504 priv->tda8290_easy_mode = 0x20;
489 mode = "L"; 505 mode = "L";
490 } else if (t->std & V4L2_STD_SECAM_LC) { 506 } else if (t->std & V4L2_STD_SECAM_LC) {
491 t->sgIF = 20; 507 priv->sgIF = 20;
492 t->tda8290_easy_mode = 0x40; 508 priv->tda8290_easy_mode = 0x40;
493 mode = "LC"; 509 mode = "LC";
494 } else { 510 } else {
495 t->sgIF = 124; 511 priv->sgIF = 124;
496 t->tda8290_easy_mode = 0x10; 512 priv->tda8290_easy_mode = 0x10;
497 mode = "xx"; 513 mode = "xx";
498 } 514 }
499 tuner_dbg("setting tda8290 to system %s\n", mode); 515 tuner_dbg("setting tda8290 to system %s\n", mode);
@@ -502,9 +518,10 @@ static void set_audio(struct tuner *t)
502static void set_tv_freq(struct i2c_client *c, unsigned int freq) 518static void set_tv_freq(struct i2c_client *c, unsigned int freq)
503{ 519{
504 struct tuner *t = i2c_get_clientdata(c); 520 struct tuner *t = i2c_get_clientdata(c);
521 struct tda8290_priv *priv = t->priv;
505 522
506 set_audio(t); 523 set_audio(t);
507 tda8290_tune(c, t->sgIF, freq); 524 tda8290_tune(c, priv->sgIF, freq);
508} 525}
509 526
510static void set_radio_freq(struct i2c_client *c, unsigned int freq) 527static void set_radio_freq(struct i2c_client *c, unsigned int freq)
@@ -528,13 +545,14 @@ static int has_signal(struct i2c_client *c)
528static void standby(struct i2c_client *c) 545static void standby(struct i2c_client *c)
529{ 546{
530 struct tuner *t = i2c_get_clientdata(c); 547 struct tuner *t = i2c_get_clientdata(c);
548 struct tda8290_priv *priv = t->priv;
531 unsigned char cb1[] = { 0x30, 0xD0 }; 549 unsigned char cb1[] = { 0x30, 0xD0 };
532 unsigned char tda8290_standby[] = { 0x00, 0x02 }; 550 unsigned char tda8290_standby[] = { 0x00, 0x02 };
533 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; 551 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
534 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; 552 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
535 553
536 tda8290_i2c_bridge(c, 1); 554 tda8290_i2c_bridge(c, 1);
537 if (t->tda827x_ver != 0) 555 if (priv->tda827x_ver != 0)
538 cb1[1] = 0x90; 556 cb1[1] = 0x90;
539 i2c_transfer(c->adapter, &msg, 1); 557 i2c_transfer(c->adapter, &msg, 1);
540 tda8290_i2c_bridge(c, 0); 558 tda8290_i2c_bridge(c, 0);
@@ -560,13 +578,14 @@ static void tda8290_init_if(struct i2c_client *c)
560static void tda8290_init_tuner(struct i2c_client *c) 578static void tda8290_init_tuner(struct i2c_client *c)
561{ 579{
562 struct tuner *t = i2c_get_clientdata(c); 580 struct tuner *t = i2c_get_clientdata(c);
581 struct tda8290_priv *priv = t->priv;
563 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, 582 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
564 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; 583 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
565 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, 584 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
566 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b }; 585 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
567 struct i2c_msg msg = {.addr = t->tda827x_addr, .flags=0, 586 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0,
568 .buf=tda8275_init, .len = 14}; 587 .buf=tda8275_init, .len = 14};
569 if (t->tda827x_ver != 0) 588 if (priv->tda827x_ver != 0)
570 msg.buf = tda8275a_init; 589 msg.buf = tda8275a_init;
571 590
572 tda8290_i2c_bridge(c, 1); 591 tda8290_i2c_bridge(c, 1);
@@ -578,12 +597,18 @@ static void tda8290_init_tuner(struct i2c_client *c)
578 597
579int tda8290_init(struct i2c_client *c) 598int tda8290_init(struct i2c_client *c)
580{ 599{
600 struct tda8290_priv *priv = NULL;
581 struct tuner *t = i2c_get_clientdata(c); 601 struct tuner *t = i2c_get_clientdata(c);
582 u8 data; 602 u8 data;
583 int i, ret, tuners_found; 603 int i, ret, tuners_found;
584 u32 tuner_addrs; 604 u32 tuner_addrs;
585 struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1}; 605 struct i2c_msg msg = {.flags=I2C_M_RD, .buf=&data, .len = 1};
586 606
607 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
608 if (priv == NULL)
609 return -ENOMEM;
610 t->priv = priv;
611
587 tda8290_i2c_bridge(c, 1); 612 tda8290_i2c_bridge(c, 1);
588 /* probe for tuner chip */ 613 /* probe for tuner chip */
589 tuners_found = 0; 614 tuners_found = 0;
@@ -618,7 +643,7 @@ int tda8290_init(struct i2c_client *c)
618 tuner_addrs = tuner_addrs & 0xff; 643 tuner_addrs = tuner_addrs & 0xff;
619 tuner_info ("setting tuner address to %x\n", tuner_addrs); 644 tuner_info ("setting tuner address to %x\n", tuner_addrs);
620 } 645 }
621 t->tda827x_addr = tuner_addrs; 646 priv->tda827x_addr = tuner_addrs;
622 msg.addr = tuner_addrs; 647 msg.addr = tuner_addrs;
623 648
624 tda8290_i2c_bridge(c, 1); 649 tda8290_i2c_bridge(c, 1);
@@ -627,10 +652,10 @@ int tda8290_init(struct i2c_client *c)
627 tuner_warn ("TDA827x access failed!\n"); 652 tuner_warn ("TDA827x access failed!\n");
628 if ((data & 0x3c) == 0) { 653 if ((data & 0x3c) == 0) {
629 strlcpy(c->name, "tda8290+75", sizeof(c->name)); 654 strlcpy(c->name, "tda8290+75", sizeof(c->name));
630 t->tda827x_ver = 0; 655 priv->tda827x_ver = 0;
631 } else { 656 } else {
632 strlcpy(c->name, "tda8290+75a", sizeof(c->name)); 657 strlcpy(c->name, "tda8290+75a", sizeof(c->name));
633 t->tda827x_ver = 2; 658 priv->tda827x_ver = 2;
634 } 659 }
635 tuner_info("type set to %s\n", c->name); 660 tuner_info("type set to %s\n", c->name);
636 661
@@ -638,7 +663,7 @@ int tda8290_init(struct i2c_client *c)
638 t->set_radio_freq = set_radio_freq; 663 t->set_radio_freq = set_radio_freq;
639 t->has_signal = has_signal; 664 t->has_signal = has_signal;
640 t->standby = standby; 665 t->standby = standby;
641 t->tda827x_lpsel = 0; 666 priv->tda827x_lpsel = 0;
642 t->mode = V4L2_TUNER_ANALOG_TV; 667 t->mode = V4L2_TUNER_ANALOG_TV;
643 668
644 tda8290_init_tuner(c); 669 tda8290_init_tuner(c);