diff options
-rw-r--r-- | drivers/media/dvb/frontends/tda1004x.c | 246 |
1 files changed, 125 insertions, 121 deletions
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c index 687ad9cf3384..6dd428b7c9e8 100644 --- a/drivers/media/dvb/frontends/tda1004x.c +++ b/drivers/media/dvb/frontends/tda1004x.c | |||
@@ -35,9 +35,10 @@ | |||
35 | #include "dvb_frontend.h" | 35 | #include "dvb_frontend.h" |
36 | #include "tda1004x.h" | 36 | #include "tda1004x.h" |
37 | 37 | ||
38 | #define TDA1004X_DEMOD_TDA10045 0 | 38 | enum tda1004x_demod { |
39 | #define TDA1004X_DEMOD_TDA10046 1 | 39 | TDA1004X_DEMOD_TDA10045, |
40 | 40 | TDA1004X_DEMOD_TDA10046, | |
41 | }; | ||
41 | 42 | ||
42 | struct tda1004x_state { | 43 | struct tda1004x_state { |
43 | struct i2c_adapter* i2c; | 44 | struct i2c_adapter* i2c; |
@@ -46,8 +47,8 @@ struct tda1004x_state { | |||
46 | struct dvb_frontend frontend; | 47 | struct dvb_frontend frontend; |
47 | 48 | ||
48 | /* private demod data */ | 49 | /* private demod data */ |
49 | u8 initialised:1; | 50 | u8 initialised; |
50 | u8 demod_type; | 51 | enum tda1004x_demod demod_type; |
51 | }; | 52 | }; |
52 | 53 | ||
53 | 54 | ||
@@ -139,7 +140,7 @@ static int tda1004x_write_byteI(struct tda1004x_state *state, int reg, int data) | |||
139 | { | 140 | { |
140 | int ret; | 141 | int ret; |
141 | u8 buf[] = { reg, data }; | 142 | u8 buf[] = { reg, data }; |
142 | struct i2c_msg msg = { .addr=0, .flags=0, .buf=buf, .len=2 }; | 143 | struct i2c_msg msg = { .flags = 0, .buf = buf, .len = 2 }; |
143 | 144 | ||
144 | dprintk("%s: reg=0x%x, data=0x%x\n", __FUNCTION__, reg, data); | 145 | dprintk("%s: reg=0x%x, data=0x%x\n", __FUNCTION__, reg, data); |
145 | 146 | ||
@@ -160,8 +161,8 @@ static int tda1004x_read_byte(struct tda1004x_state *state, int reg) | |||
160 | int ret; | 161 | int ret; |
161 | u8 b0[] = { reg }; | 162 | u8 b0[] = { reg }; |
162 | u8 b1[] = { 0 }; | 163 | u8 b1[] = { 0 }; |
163 | struct i2c_msg msg[] = {{ .addr=0, .flags=0, .buf=b0, .len=1}, | 164 | struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 }, |
164 | { .addr=0, .flags=I2C_M_RD, .buf=b1, .len = 1}}; | 165 | { .flags = I2C_M_RD, .buf = b1, .len = 1 }}; |
165 | 166 | ||
166 | dprintk("%s: reg=0x%x\n", __FUNCTION__, reg); | 167 | dprintk("%s: reg=0x%x\n", __FUNCTION__, reg); |
167 | 168 | ||
@@ -294,7 +295,7 @@ static int tda1004x_do_upload(struct tda1004x_state *state, | |||
294 | u8 dspCodeCounterReg, u8 dspCodeInReg) | 295 | u8 dspCodeCounterReg, u8 dspCodeInReg) |
295 | { | 296 | { |
296 | u8 buf[65]; | 297 | u8 buf[65]; |
297 | struct i2c_msg fw_msg = {.addr = 0,.flags = 0,.buf = buf,.len = 0 }; | 298 | struct i2c_msg fw_msg = { .flags = 0, .buf = buf, .len = 0 }; |
298 | int tx_size; | 299 | int tx_size; |
299 | int pos = 0; | 300 | int pos = 0; |
300 | 301 | ||
@@ -304,12 +305,10 @@ static int tda1004x_do_upload(struct tda1004x_state *state, | |||
304 | 305 | ||
305 | buf[0] = dspCodeInReg; | 306 | buf[0] = dspCodeInReg; |
306 | while (pos != len) { | 307 | while (pos != len) { |
307 | |||
308 | // work out how much to send this time | 308 | // work out how much to send this time |
309 | tx_size = len - pos; | 309 | tx_size = len - pos; |
310 | if (tx_size > 0x10) { | 310 | if (tx_size > 0x10) |
311 | tx_size = 0x10; | 311 | tx_size = 0x10; |
312 | } | ||
313 | 312 | ||
314 | // send the chunk | 313 | // send the chunk |
315 | memcpy(buf + 1, mem + pos, tx_size); | 314 | memcpy(buf + 1, mem + pos, tx_size); |
@@ -322,6 +321,7 @@ static int tda1004x_do_upload(struct tda1004x_state *state, | |||
322 | 321 | ||
323 | dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, pos); | 322 | dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, pos); |
324 | } | 323 | } |
324 | |||
325 | return 0; | 325 | return 0; |
326 | } | 326 | } |
327 | 327 | ||
@@ -335,9 +335,8 @@ static int tda1004x_check_upload_ok(struct tda1004x_state *state, u8 dspVersion) | |||
335 | 335 | ||
336 | data1 = tda1004x_read_byte(state, TDA1004X_DSP_DATA1); | 336 | data1 = tda1004x_read_byte(state, TDA1004X_DSP_DATA1); |
337 | data2 = tda1004x_read_byte(state, TDA1004X_DSP_DATA2); | 337 | data2 = tda1004x_read_byte(state, TDA1004X_DSP_DATA2); |
338 | if (data1 != 0x67 || data2 != dspVersion) { | 338 | if ((data1 != 0x67) || (data2 != dspVersion)) |
339 | return -EIO; | 339 | return -EIO; |
340 | } | ||
341 | 340 | ||
342 | return 0; | 341 | return 0; |
343 | } | 342 | } |
@@ -348,9 +347,9 @@ static int tda10045_fwupload(struct dvb_frontend* fe) | |||
348 | int ret; | 347 | int ret; |
349 | const struct firmware *fw; | 348 | const struct firmware *fw; |
350 | 349 | ||
351 | |||
352 | /* don't re-upload unless necessary */ | 350 | /* don't re-upload unless necessary */ |
353 | if (tda1004x_check_upload_ok(state, 0x2c) == 0) return 0; | 351 | if (tda1004x_check_upload_ok(state, 0x2c) == 0) |
352 | return 0; | ||
354 | 353 | ||
355 | /* request the firmware, this will block until someone uploads it */ | 354 | /* request the firmware, this will block until someone uploads it */ |
356 | printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE); | 355 | printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE); |
@@ -394,7 +393,8 @@ static int tda10046_fwupload(struct dvb_frontend* fe) | |||
394 | msleep(100); | 393 | msleep(100); |
395 | 394 | ||
396 | /* don't re-upload unless necessary */ | 395 | /* don't re-upload unless necessary */ |
397 | if (tda1004x_check_upload_ok(state, 0x20) == 0) return 0; | 396 | if (tda1004x_check_upload_ok(state, 0x20) == 0) |
397 | return 0; | ||
398 | 398 | ||
399 | /* request the firmware, this will block until someone uploads it */ | 399 | /* request the firmware, this will block until someone uploads it */ |
400 | printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10046_DEFAULT_FIRMWARE); | 400 | printk("tda1004x: waiting for firmware upload (%s)...\n", TDA10046_DEFAULT_FIRMWARE); |
@@ -419,7 +419,7 @@ static int tda10046_fwupload(struct dvb_frontend* fe) | |||
419 | 419 | ||
420 | /* wait for DSP to initialise */ | 420 | /* wait for DSP to initialise */ |
421 | timeout = jiffies + HZ; | 421 | timeout = jiffies + HZ; |
422 | while(!(tda1004x_read_byte(state, TDA1004X_STATUS_CD) & 0x20)) { | 422 | while (!(tda1004x_read_byte(state, TDA1004X_STATUS_CD) & 0x20)) { |
423 | if (time_after(jiffies, timeout)) { | 423 | if (time_after(jiffies, timeout)) { |
424 | printk("tda1004x: DSP failed to initialised.\n"); | 424 | printk("tda1004x: DSP failed to initialised.\n"); |
425 | return -EIO; | 425 | return -EIO; |
@@ -483,7 +483,8 @@ static int tda10045_init(struct dvb_frontend* fe) | |||
483 | 483 | ||
484 | dprintk("%s\n", __FUNCTION__); | 484 | dprintk("%s\n", __FUNCTION__); |
485 | 485 | ||
486 | if (state->initialised) return 0; | 486 | if (state->initialised) |
487 | return 0; | ||
487 | 488 | ||
488 | if (tda10045_fwupload(fe)) { | 489 | if (tda10045_fwupload(fe)) { |
489 | printk("tda1004x: firmware upload failed\n"); | 490 | printk("tda1004x: firmware upload failed\n"); |
@@ -523,7 +524,8 @@ static int tda10046_init(struct dvb_frontend* fe) | |||
523 | struct tda1004x_state* state = fe->demodulator_priv; | 524 | struct tda1004x_state* state = fe->demodulator_priv; |
524 | dprintk("%s\n", __FUNCTION__); | 525 | dprintk("%s\n", __FUNCTION__); |
525 | 526 | ||
526 | if (state->initialised) return 0; | 527 | if (state->initialised) |
528 | return 0; | ||
527 | 529 | ||
528 | if (tda10046_fwupload(fe)) { | 530 | if (tda10046_fwupload(fe)) { |
529 | printk("tda1004x: firmware upload failed\n"); | 531 | printk("tda1004x: firmware upload failed\n"); |
@@ -621,12 +623,14 @@ static int tda1004x_set_fe(struct dvb_frontend* fe, | |||
621 | 623 | ||
622 | // set HP FEC | 624 | // set HP FEC |
623 | tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_HP); | 625 | tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_HP); |
624 | if (tmp < 0) return tmp; | 626 | if (tmp < 0) |
627 | return tmp; | ||
625 | tda1004x_write_mask(state, TDA1004X_IN_CONF2, 7, tmp); | 628 | tda1004x_write_mask(state, TDA1004X_IN_CONF2, 7, tmp); |
626 | 629 | ||
627 | // set LP FEC | 630 | // set LP FEC |
628 | tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_LP); | 631 | tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_LP); |
629 | if (tmp < 0) return tmp; | 632 | if (tmp < 0) |
633 | return tmp; | ||
630 | tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0x38, tmp << 3); | 634 | tda1004x_write_mask(state, TDA1004X_IN_CONF2, 0x38, tmp << 3); |
631 | 635 | ||
632 | // set constellation | 636 | // set constellation |
@@ -671,7 +675,7 @@ static int tda1004x_set_fe(struct dvb_frontend* fe, | |||
671 | } | 675 | } |
672 | 676 | ||
673 | // set bandwidth | 677 | // set bandwidth |
674 | switch(state->demod_type) { | 678 | switch (state->demod_type) { |
675 | case TDA1004X_DEMOD_TDA10045: | 679 | case TDA1004X_DEMOD_TDA10045: |
676 | tda10045h_set_bandwidth(state, fe_params->u.ofdm.bandwidth); | 680 | tda10045h_set_bandwidth(state, fe_params->u.ofdm.bandwidth); |
677 | break; | 681 | break; |
@@ -683,7 +687,8 @@ static int tda1004x_set_fe(struct dvb_frontend* fe, | |||
683 | 687 | ||
684 | // set inversion | 688 | // set inversion |
685 | inversion = fe_params->inversion; | 689 | inversion = fe_params->inversion; |
686 | if (state->config->invert) inversion = inversion ? INVERSION_OFF : INVERSION_ON; | 690 | if (state->config->invert) |
691 | inversion = inversion ? INVERSION_OFF : INVERSION_ON; | ||
687 | switch (inversion) { | 692 | switch (inversion) { |
688 | case INVERSION_OFF: | 693 | case INVERSION_OFF: |
689 | tda1004x_write_mask(state, TDA1004X_CONFC1, 0x20, 0); | 694 | tda1004x_write_mask(state, TDA1004X_CONFC1, 0x20, 0); |
@@ -750,19 +755,19 @@ static int tda1004x_set_fe(struct dvb_frontend* fe, | |||
750 | } | 755 | } |
751 | 756 | ||
752 | // start the lock | 757 | // start the lock |
753 | switch(state->demod_type) { | 758 | switch (state->demod_type) { |
754 | case TDA1004X_DEMOD_TDA10045: | 759 | case TDA1004X_DEMOD_TDA10045: |
755 | tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8); | 760 | tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 8); |
756 | tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 0); | 761 | tda1004x_write_mask(state, TDA1004X_CONFC4, 8, 0); |
757 | msleep(10); | ||
758 | break; | 762 | break; |
759 | 763 | ||
760 | case TDA1004X_DEMOD_TDA10046: | 764 | case TDA1004X_DEMOD_TDA10046: |
761 | tda1004x_write_mask(state, TDA1004X_AUTO, 0x40, 0x40); | 765 | tda1004x_write_mask(state, TDA1004X_AUTO, 0x40, 0x40); |
762 | msleep(10); | ||
763 | break; | 766 | break; |
764 | } | 767 | } |
765 | 768 | ||
769 | msleep(10); | ||
770 | |||
766 | return 0; | 771 | return 0; |
767 | } | 772 | } |
768 | 773 | ||
@@ -773,13 +778,13 @@ static int tda1004x_get_fe(struct dvb_frontend* fe, struct dvb_frontend_paramete | |||
773 | 778 | ||
774 | // inversion status | 779 | // inversion status |
775 | fe_params->inversion = INVERSION_OFF; | 780 | fe_params->inversion = INVERSION_OFF; |
776 | if (tda1004x_read_byte(state, TDA1004X_CONFC1) & 0x20) { | 781 | if (tda1004x_read_byte(state, TDA1004X_CONFC1) & 0x20) |
777 | fe_params->inversion = INVERSION_ON; | 782 | fe_params->inversion = INVERSION_ON; |
778 | } | 783 | if (state->config->invert) |
779 | if (state->config->invert) fe_params->inversion = fe_params->inversion ? INVERSION_OFF : INVERSION_ON; | 784 | fe_params->inversion = fe_params->inversion ? INVERSION_OFF : INVERSION_ON; |
780 | 785 | ||
781 | // bandwidth | 786 | // bandwidth |
782 | switch(state->demod_type) { | 787 | switch (state->demod_type) { |
783 | case TDA1004X_DEMOD_TDA10045: | 788 | case TDA1004X_DEMOD_TDA10045: |
784 | switch (tda1004x_read_byte(state, TDA10045H_WREF_LSB)) { | 789 | switch (tda1004x_read_byte(state, TDA10045H_WREF_LSB)) { |
785 | case 0x14: | 790 | case 0x14: |
@@ -830,9 +835,8 @@ static int tda1004x_get_fe(struct dvb_frontend* fe, struct dvb_frontend_paramete | |||
830 | 835 | ||
831 | // transmission mode | 836 | // transmission mode |
832 | fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; | 837 | fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K; |
833 | if (tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x10) { | 838 | if (tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x10) |
834 | fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; | 839 | fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K; |
835 | } | ||
836 | 840 | ||
837 | // guard interval | 841 | // guard interval |
838 | switch ((tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x0c) >> 2) { | 842 | switch ((tda1004x_read_byte(state, TDA1004X_OUT_CONF1) & 0x0c) >> 2) { |
@@ -880,30 +884,33 @@ static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status | |||
880 | 884 | ||
881 | // read status | 885 | // read status |
882 | status = tda1004x_read_byte(state, TDA1004X_STATUS_CD); | 886 | status = tda1004x_read_byte(state, TDA1004X_STATUS_CD); |
883 | if (status == -1) { | 887 | if (status == -1) |
884 | return -EIO; | 888 | return -EIO; |
885 | } | ||
886 | 889 | ||
887 | // decode | 890 | // decode |
888 | *fe_status = 0; | 891 | *fe_status = 0; |
889 | if (status & 4) *fe_status |= FE_HAS_SIGNAL; | 892 | if (status & 4) |
890 | if (status & 2) *fe_status |= FE_HAS_CARRIER; | 893 | *fe_status |= FE_HAS_SIGNAL; |
891 | if (status & 8) *fe_status |= FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; | 894 | if (status & 2) |
895 | *fe_status |= FE_HAS_CARRIER; | ||
896 | if (status & 8) | ||
897 | *fe_status |= FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; | ||
892 | 898 | ||
893 | // if we don't already have VITERBI (i.e. not LOCKED), see if the viterbi | 899 | // if we don't already have VITERBI (i.e. not LOCKED), see if the viterbi |
894 | // is getting anything valid | 900 | // is getting anything valid |
895 | if (!(*fe_status & FE_HAS_VITERBI)) { | 901 | if (!(*fe_status & FE_HAS_VITERBI)) { |
896 | // read the CBER | 902 | // read the CBER |
897 | cber = tda1004x_read_byte(state, TDA1004X_CBER_LSB); | 903 | cber = tda1004x_read_byte(state, TDA1004X_CBER_LSB); |
898 | if (cber == -1) return -EIO; | 904 | if (cber == -1) |
905 | return -EIO; | ||
899 | status = tda1004x_read_byte(state, TDA1004X_CBER_MSB); | 906 | status = tda1004x_read_byte(state, TDA1004X_CBER_MSB); |
900 | if (status == -1) return -EIO; | 907 | if (status == -1) |
908 | return -EIO; | ||
901 | cber |= (status << 8); | 909 | cber |= (status << 8); |
902 | tda1004x_read_byte(state, TDA1004X_CBER_RESET); | 910 | tda1004x_read_byte(state, TDA1004X_CBER_RESET); |
903 | 911 | ||
904 | if (cber != 65535) { | 912 | if (cber != 65535) |
905 | *fe_status |= FE_HAS_VITERBI; | 913 | *fe_status |= FE_HAS_VITERBI; |
906 | } | ||
907 | } | 914 | } |
908 | 915 | ||
909 | // if we DO have some valid VITERBI output, but don't already have SYNC | 916 | // if we DO have some valid VITERBI output, but don't already have SYNC |
@@ -911,20 +918,22 @@ static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status | |||
911 | if ((*fe_status & FE_HAS_VITERBI) && (!(*fe_status & FE_HAS_SYNC))) { | 918 | if ((*fe_status & FE_HAS_VITERBI) && (!(*fe_status & FE_HAS_SYNC))) { |
912 | // read the VBER | 919 | // read the VBER |
913 | vber = tda1004x_read_byte(state, TDA1004X_VBER_LSB); | 920 | vber = tda1004x_read_byte(state, TDA1004X_VBER_LSB); |
914 | if (vber == -1) return -EIO; | 921 | if (vber == -1) |
922 | return -EIO; | ||
915 | status = tda1004x_read_byte(state, TDA1004X_VBER_MID); | 923 | status = tda1004x_read_byte(state, TDA1004X_VBER_MID); |
916 | if (status == -1) return -EIO; | 924 | if (status == -1) |
925 | return -EIO; | ||
917 | vber |= (status << 8); | 926 | vber |= (status << 8); |
918 | status = tda1004x_read_byte(state, TDA1004X_VBER_MSB); | 927 | status = tda1004x_read_byte(state, TDA1004X_VBER_MSB); |
919 | if (status == -1) return -EIO; | 928 | if (status == -1) |
929 | return -EIO; | ||
920 | vber |= ((status << 16) & 0x0f); | 930 | vber |= ((status << 16) & 0x0f); |
921 | tda1004x_read_byte(state, TDA1004X_CVBER_LUT); | 931 | tda1004x_read_byte(state, TDA1004X_CVBER_LUT); |
922 | 932 | ||
923 | // if RS has passed some valid TS packets, then we must be | 933 | // if RS has passed some valid TS packets, then we must be |
924 | // getting some SYNC bytes | 934 | // getting some SYNC bytes |
925 | if (vber < 16632) { | 935 | if (vber < 16632) |
926 | *fe_status |= FE_HAS_SYNC; | 936 | *fe_status |= FE_HAS_SYNC; |
927 | } | ||
928 | } | 937 | } |
929 | 938 | ||
930 | // success | 939 | // success |
@@ -941,7 +950,7 @@ static int tda1004x_read_signal_strength(struct dvb_frontend* fe, u16 * signal) | |||
941 | dprintk("%s\n", __FUNCTION__); | 950 | dprintk("%s\n", __FUNCTION__); |
942 | 951 | ||
943 | // determine the register to use | 952 | // determine the register to use |
944 | switch(state->demod_type) { | 953 | switch (state->demod_type) { |
945 | case TDA1004X_DEMOD_TDA10045: | 954 | case TDA1004X_DEMOD_TDA10045: |
946 | reg = TDA10045H_S_AGC; | 955 | reg = TDA10045H_S_AGC; |
947 | break; | 956 | break; |
@@ -972,9 +981,8 @@ static int tda1004x_read_snr(struct dvb_frontend* fe, u16 * snr) | |||
972 | tmp = tda1004x_read_byte(state, TDA1004X_SNR); | 981 | tmp = tda1004x_read_byte(state, TDA1004X_SNR); |
973 | if (tmp < 0) | 982 | if (tmp < 0) |
974 | return -EIO; | 983 | return -EIO; |
975 | if (tmp) { | 984 | if (tmp) |
976 | tmp = 255 - tmp; | 985 | tmp = 255 - tmp; |
977 | } | ||
978 | 986 | ||
979 | *snr = ((tmp << 8) | tmp); | 987 | *snr = ((tmp << 8) | tmp); |
980 | dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr); | 988 | dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr); |
@@ -1009,11 +1017,11 @@ static int tda1004x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) | |||
1009 | break; | 1017 | break; |
1010 | } | 1018 | } |
1011 | 1019 | ||
1012 | if (tmp != 0x7f) { | 1020 | if (tmp != 0x7f) |
1013 | *ucblocks = tmp; | 1021 | *ucblocks = tmp; |
1014 | } else { | 1022 | else |
1015 | *ucblocks = 0xffffffff; | 1023 | *ucblocks = 0xffffffff; |
1016 | } | 1024 | |
1017 | dprintk("%s: ucblocks=0x%x\n", __FUNCTION__, *ucblocks); | 1025 | dprintk("%s: ucblocks=0x%x\n", __FUNCTION__, *ucblocks); |
1018 | return 0; | 1026 | return 0; |
1019 | } | 1027 | } |
@@ -1027,10 +1035,12 @@ static int tda1004x_read_ber(struct dvb_frontend* fe, u32* ber) | |||
1027 | 1035 | ||
1028 | // read it in | 1036 | // read it in |
1029 | tmp = tda1004x_read_byte(state, TDA1004X_CBER_LSB); | 1037 | tmp = tda1004x_read_byte(state, TDA1004X_CBER_LSB); |
1030 | if (tmp < 0) return -EIO; | 1038 | if (tmp < 0) |
1039 | return -EIO; | ||
1031 | *ber = tmp << 1; | 1040 | *ber = tmp << 1; |
1032 | tmp = tda1004x_read_byte(state, TDA1004X_CBER_MSB); | 1041 | tmp = tda1004x_read_byte(state, TDA1004X_CBER_MSB); |
1033 | if (tmp < 0) return -EIO; | 1042 | if (tmp < 0) |
1043 | return -EIO; | ||
1034 | *ber |= (tmp << 9); | 1044 | *ber |= (tmp << 9); |
1035 | tda1004x_read_byte(state, TDA1004X_CBER_RESET); | 1045 | tda1004x_read_byte(state, TDA1004X_CBER_RESET); |
1036 | 1046 | ||
@@ -1042,7 +1052,7 @@ static int tda1004x_sleep(struct dvb_frontend* fe) | |||
1042 | { | 1052 | { |
1043 | struct tda1004x_state* state = fe->demodulator_priv; | 1053 | struct tda1004x_state* state = fe->demodulator_priv; |
1044 | 1054 | ||
1045 | switch(state->demod_type) { | 1055 | switch (state->demod_type) { |
1046 | case TDA1004X_DEMOD_TDA10045: | 1056 | case TDA1004X_DEMOD_TDA10045: |
1047 | tda1004x_write_mask(state, TDA1004X_CONFADC1, 0x10, 0x10); | 1057 | tda1004x_write_mask(state, TDA1004X_CONFADC1, 0x10, 0x10); |
1048 | break; | 1058 | break; |
@@ -1066,74 +1076,11 @@ static int tda1004x_get_tune_settings(struct dvb_frontend* fe, struct dvb_fronte | |||
1066 | 1076 | ||
1067 | static void tda1004x_release(struct dvb_frontend* fe) | 1077 | static void tda1004x_release(struct dvb_frontend* fe) |
1068 | { | 1078 | { |
1069 | struct tda1004x_state* state = (struct tda1004x_state*) fe->demodulator_priv; | 1079 | struct tda1004x_state *state = fe->demodulator_priv; |
1070 | kfree(state); | 1080 | kfree(state); |
1071 | } | 1081 | } |
1072 | 1082 | ||
1073 | static struct dvb_frontend_ops tda10045_ops; | ||
1074 | |||
1075 | struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, | ||
1076 | struct i2c_adapter* i2c) | ||
1077 | { | ||
1078 | struct tda1004x_state* state = NULL; | ||
1079 | |||
1080 | /* allocate memory for the internal state */ | ||
1081 | state = (struct tda1004x_state*) kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL); | ||
1082 | if (state == NULL) goto error; | ||
1083 | |||
1084 | /* setup the state */ | ||
1085 | state->config = config; | ||
1086 | state->i2c = i2c; | ||
1087 | memcpy(&state->ops, &tda10045_ops, sizeof(struct dvb_frontend_ops)); | ||
1088 | state->initialised = 0; | ||
1089 | state->demod_type = TDA1004X_DEMOD_TDA10045; | ||
1090 | |||
1091 | /* check if the demod is there */ | ||
1092 | if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x25) goto error; | ||
1093 | |||
1094 | /* create dvb_frontend */ | ||
1095 | state->frontend.ops = &state->ops; | ||
1096 | state->frontend.demodulator_priv = state; | ||
1097 | return &state->frontend; | ||
1098 | |||
1099 | error: | ||
1100 | kfree(state); | ||
1101 | return NULL; | ||
1102 | } | ||
1103 | |||
1104 | static struct dvb_frontend_ops tda10046_ops; | ||
1105 | |||
1106 | struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config, | ||
1107 | struct i2c_adapter* i2c) | ||
1108 | { | ||
1109 | struct tda1004x_state* state = NULL; | ||
1110 | |||
1111 | /* allocate memory for the internal state */ | ||
1112 | state = (struct tda1004x_state*) kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL); | ||
1113 | if (state == NULL) goto error; | ||
1114 | |||
1115 | /* setup the state */ | ||
1116 | state->config = config; | ||
1117 | state->i2c = i2c; | ||
1118 | memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops)); | ||
1119 | state->initialised = 0; | ||
1120 | state->demod_type = TDA1004X_DEMOD_TDA10046; | ||
1121 | |||
1122 | /* check if the demod is there */ | ||
1123 | if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) goto error; | ||
1124 | |||
1125 | /* create dvb_frontend */ | ||
1126 | state->frontend.ops = &state->ops; | ||
1127 | state->frontend.demodulator_priv = state; | ||
1128 | return &state->frontend; | ||
1129 | |||
1130 | error: | ||
1131 | if (state) kfree(state); | ||
1132 | return NULL; | ||
1133 | } | ||
1134 | |||
1135 | static struct dvb_frontend_ops tda10045_ops = { | 1083 | static struct dvb_frontend_ops tda10045_ops = { |
1136 | |||
1137 | .info = { | 1084 | .info = { |
1138 | .name = "Philips TDA10045H DVB-T", | 1085 | .name = "Philips TDA10045H DVB-T", |
1139 | .type = FE_OFDM, | 1086 | .type = FE_OFDM, |
@@ -1163,8 +1110,36 @@ static struct dvb_frontend_ops tda10045_ops = { | |||
1163 | .read_ucblocks = tda1004x_read_ucblocks, | 1110 | .read_ucblocks = tda1004x_read_ucblocks, |
1164 | }; | 1111 | }; |
1165 | 1112 | ||
1166 | static struct dvb_frontend_ops tda10046_ops = { | 1113 | struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, |
1114 | struct i2c_adapter* i2c) | ||
1115 | { | ||
1116 | struct tda1004x_state *state; | ||
1117 | |||
1118 | /* allocate memory for the internal state */ | ||
1119 | state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL); | ||
1120 | if (!state) | ||
1121 | return NULL; | ||
1122 | |||
1123 | /* setup the state */ | ||
1124 | state->config = config; | ||
1125 | state->i2c = i2c; | ||
1126 | memcpy(&state->ops, &tda10045_ops, sizeof(struct dvb_frontend_ops)); | ||
1127 | state->initialised = 0; | ||
1128 | state->demod_type = TDA1004X_DEMOD_TDA10045; | ||
1129 | |||
1130 | /* check if the demod is there */ | ||
1131 | if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x25) { | ||
1132 | kfree(state); | ||
1133 | return NULL; | ||
1134 | } | ||
1135 | |||
1136 | /* create dvb_frontend */ | ||
1137 | state->frontend.ops = &state->ops; | ||
1138 | state->frontend.demodulator_priv = state; | ||
1139 | return &state->frontend; | ||
1140 | } | ||
1167 | 1141 | ||
1142 | static struct dvb_frontend_ops tda10046_ops = { | ||
1168 | .info = { | 1143 | .info = { |
1169 | .name = "Philips TDA10046H DVB-T", | 1144 | .name = "Philips TDA10046H DVB-T", |
1170 | .type = FE_OFDM, | 1145 | .type = FE_OFDM, |
@@ -1194,6 +1169,35 @@ static struct dvb_frontend_ops tda10046_ops = { | |||
1194 | .read_ucblocks = tda1004x_read_ucblocks, | 1169 | .read_ucblocks = tda1004x_read_ucblocks, |
1195 | }; | 1170 | }; |
1196 | 1171 | ||
1172 | struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config, | ||
1173 | struct i2c_adapter* i2c) | ||
1174 | { | ||
1175 | struct tda1004x_state *state; | ||
1176 | |||
1177 | /* allocate memory for the internal state */ | ||
1178 | state = kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL); | ||
1179 | if (!state) | ||
1180 | return NULL; | ||
1181 | |||
1182 | /* setup the state */ | ||
1183 | state->config = config; | ||
1184 | state->i2c = i2c; | ||
1185 | memcpy(&state->ops, &tda10046_ops, sizeof(struct dvb_frontend_ops)); | ||
1186 | state->initialised = 0; | ||
1187 | state->demod_type = TDA1004X_DEMOD_TDA10046; | ||
1188 | |||
1189 | /* check if the demod is there */ | ||
1190 | if (tda1004x_read_byte(state, TDA1004X_CHIPID) != 0x46) { | ||
1191 | kfree(state); | ||
1192 | return NULL; | ||
1193 | } | ||
1194 | |||
1195 | /* create dvb_frontend */ | ||
1196 | state->frontend.ops = &state->ops; | ||
1197 | state->frontend.demodulator_priv = state; | ||
1198 | return &state->frontend; | ||
1199 | } | ||
1200 | |||
1197 | module_param(debug, int, 0644); | 1201 | module_param(debug, int, 0644); |
1198 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); | 1202 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); |
1199 | 1203 | ||