aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/dvb/frontends/cx24113.c70
1 files changed, 39 insertions, 31 deletions
diff --git a/drivers/media/dvb/frontends/cx24113.c b/drivers/media/dvb/frontends/cx24113.c
index e2e5df9de1ec..8850f2303ec6 100644
--- a/drivers/media/dvb/frontends/cx24113.c
+++ b/drivers/media/dvb/frontends/cx24113.c
@@ -50,46 +50,46 @@ struct cx24113_state {
50 u8 rev; 50 u8 rev;
51 u8 ver; 51 u8 ver;
52 52
53 u8 icp_mode:1; 53 u8 icp_mode:1;
54 54
55#define ICP_LEVEL1 0 55#define ICP_LEVEL1 0
56#define ICP_LEVEL2 1 56#define ICP_LEVEL2 1
57#define ICP_LEVEL3 2 57#define ICP_LEVEL3 2
58#define ICP_LEVEL4 3 58#define ICP_LEVEL4 3
59 u8 icp_man:2; 59 u8 icp_man:2;
60 u8 icp_auto_low:2; 60 u8 icp_auto_low:2;
61 u8 icp_auto_mlow:2; 61 u8 icp_auto_mlow:2;
62 u8 icp_auto_mhi:2; 62 u8 icp_auto_mhi:2;
63 u8 icp_auto_hi:2; 63 u8 icp_auto_hi:2;
64 u8 icp_dig; 64 u8 icp_dig;
65 65
66#define LNA_MIN_GAIN 0 66#define LNA_MIN_GAIN 0
67#define LNA_MID_GAIN 1 67#define LNA_MID_GAIN 1
68#define LNA_MAX_GAIN 2 68#define LNA_MAX_GAIN 2
69 u8 lna_gain:2; 69 u8 lna_gain:2;
70 70
71 u8 acp_on:1; 71 u8 acp_on:1;
72 72
73 u8 vco_mode:2; 73 u8 vco_mode:2;
74 u8 vco_shift:1; 74 u8 vco_shift:1;
75#define VCOBANDSEL_6 0x80 75#define VCOBANDSEL_6 0x80
76#define VCOBANDSEL_5 0x01 76#define VCOBANDSEL_5 0x01
77#define VCOBANDSEL_4 0x02 77#define VCOBANDSEL_4 0x02
78#define VCOBANDSEL_3 0x04 78#define VCOBANDSEL_3 0x04
79#define VCOBANDSEL_2 0x08 79#define VCOBANDSEL_2 0x08
80#define VCOBANDSEL_1 0x10 80#define VCOBANDSEL_1 0x10
81 u8 vco_band; 81 u8 vco_band;
82 82
83#define VCODIV4 4 83#define VCODIV4 4
84#define VCODIV2 2 84#define VCODIV2 2
85 u8 vcodiv; 85 u8 vcodiv;
86 86
87 u8 bs_delay:4; 87 u8 bs_delay:4;
88 u16 bs_freqcnt:13; 88 u16 bs_freqcnt:13;
89 u16 bs_rdiv; 89 u16 bs_rdiv;
90 u8 prescaler_mode:1; 90 u8 prescaler_mode:1;
91 91
92 u8 rfvga_bias_ctrl; 92 u8 rfvga_bias_ctrl;
93 93
94 s16 tuner_gain_thres; 94 s16 tuner_gain_thres;
95 u8 gain_level; 95 u8 gain_level;
@@ -345,12 +345,12 @@ static void cx24113_calc_pll_nf(struct cx24113_state *state, u16 *n, s32 *f)
345 } 345 }
346 F = freq_hz; 346 F = freq_hz;
347 F *= (u64) (R * vcodiv * 262144); 347 F *= (u64) (R * vcodiv * 262144);
348 dprintk("1 N: %d, F: %lld, R: %d\n", N, F, R); 348 dprintk("1 N: %d, F: %lld, R: %d\n", N, F, R);
349 do_div(F, state->config->xtal_khz*1000 * factor * 2); 349 do_div(F, state->config->xtal_khz*1000 * factor * 2);
350 dprintk("2 N: %d, F: %lld, R: %d\n", N, F, R); 350 dprintk("2 N: %d, F: %lld, R: %d\n", N, F, R);
351 F -= (N + 32) * 262144; 351 F -= (N + 32) * 262144;
352 352
353 dprintk("3 N: %d, F: %lld, R: %d\n", N, F, R); 353 dprintk("3 N: %d, F: %lld, R: %d\n", N, F, R);
354 354
355 if (state->Fwindow_enabled) { 355 if (state->Fwindow_enabled) {
356 if (F > (262144 / 2 - 1638)) 356 if (F > (262144 / 2 - 1638))
@@ -392,21 +392,21 @@ static int cx24113_set_frequency(struct cx24113_state *state, u32 frequency)
392 u16 n = 6; 392 u16 n = 6;
393 s32 f = 0; 393 s32 f = 0;
394 394
395 r = cx24113_readreg(state, 0x14); 395 r = cx24113_readreg(state, 0x14);
396 cx24113_writereg(state, 0x14, r & 0x3f); 396 cx24113_writereg(state, 0x14, r & 0x3f);
397 397
398 r = cx24113_readreg(state, 0x10); 398 r = cx24113_readreg(state, 0x10);
399 cx24113_writereg(state, 0x10, r & 0xbf); 399 cx24113_writereg(state, 0x10, r & 0xbf);
400 400
401 state->frequency = frequency; 401 state->frequency = frequency;
402 402
403 dprintk("tuning to frequency: %d\n", frequency); 403 dprintk("tuning to frequency: %d\n", frequency);
404 404
405 cx24113_calc_pll_nf(state, &n, &f); 405 cx24113_calc_pll_nf(state, &n, &f);
406 cx24113_set_nfr(state, n, f, state->refdiv); 406 cx24113_set_nfr(state, n, f, state->refdiv);
407 407
408 r = cx24113_readreg(state, 0x18) & 0xbf; 408 r = cx24113_readreg(state, 0x18) & 0xbf;
409 if (state->vcodiv != VCODIV2) 409 if (state->vcodiv != VCODIV2)
410 r |= 1 << 6; 410 r |= 1 << 6;
411 cx24113_writereg(state, 0x18, r); 411 cx24113_writereg(state, 0x18, r);
412 412
@@ -527,7 +527,7 @@ static int cx24113_release(struct dvb_frontend *fe)
527{ 527{
528 struct cx24113_state *state = fe->tuner_priv; 528 struct cx24113_state *state = fe->tuner_priv;
529 dprintk("\n"); 529 dprintk("\n");
530 fe->tuner_priv = NULL; 530 fe->tuner_priv = NULL;
531 kfree(state); 531 kfree(state);
532 return 0; 532 return 0;
533} 533}
@@ -557,6 +557,7 @@ struct dvb_frontend *cx24113_attach(struct dvb_frontend *fe,
557 /* allocate memory for the internal state */ 557 /* allocate memory for the internal state */
558 struct cx24113_state *state = 558 struct cx24113_state *state =
559 kzalloc(sizeof(struct cx24113_state), GFP_KERNEL); 559 kzalloc(sizeof(struct cx24113_state), GFP_KERNEL);
560 int rc;
560 if (state == NULL) { 561 if (state == NULL) {
561 err("Unable to kmalloc\n"); 562 err("Unable to kmalloc\n");
562 goto error; 563 goto error;
@@ -572,15 +573,22 @@ struct dvb_frontend *cx24113_attach(struct dvb_frontend *fe,
572 * after power on */ 573 * after power on */
573 cx24113_readreg(state, 0x00); 574 cx24113_readreg(state, 0x00);
574 575
575 switch (state->rev = cx24113_readreg(state, 0x00)) { 576 rc = cx24113_readreg(state, 0x00);
577 if (rc < 0) {
578 info("cx24113 not found.\n");
579 goto error;
580 }
581 state->rev = rc;
582
583 switch (rc) {
576 case 0x43: 584 case 0x43:
577 info("unknown device\n"); 585 info("detected Cx24113 variant\n");
578 break; 586 break;
579 case REV_CX24113: 587 case REV_CX24113:
580 info("CX24113\n"); 588 info("sucessfully detected\n");
581 break; 589 break;
582 default: 590 default:
583 err("unsupported revision: %x\n", state->rev); 591 err("unsupported device id: %x\n", state->rev);
584 goto error; 592 goto error;
585 } 593 }
586 state->ver = cx24113_readreg(state, 0x01); 594 state->ver = cx24113_readreg(state, 0x01);