aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/frontends/ds3000.c
diff options
context:
space:
mode:
authorIgor M. Liplianin <liplianin@me.by>2011-02-25 16:41:24 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2011-03-21 19:32:27 -0400
commita5bf834b4a29b0c7f813ce1c456563c470d4181f (patch)
tree2db2e70b90b8f6327fef5f81470ef5b5b161897f /drivers/media/dvb/frontends/ds3000.c
parentcb8f74da107cf593eb50ac4968faaa5f49fbad4a (diff)
[media] ds3000: add carrier offset calculation
Signed-off-by: Igor M. Liplianin <liplianin@me.by> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb/frontends/ds3000.c')
-rw-r--r--drivers/media/dvb/frontends/ds3000.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
index 13f9193d4f4a..a0bf70f0d044 100644
--- a/drivers/media/dvb/frontends/ds3000.c
+++ b/drivers/media/dvb/frontends/ds3000.c
@@ -948,6 +948,25 @@ static int ds3000_get_property(struct dvb_frontend *fe,
948 return 0; 948 return 0;
949} 949}
950 950
951static int ds3000_set_carrier_offset(struct dvb_frontend *fe,
952 s32 carrier_offset_khz)
953{
954 struct ds3000_state *state = fe->demodulator_priv;
955 s32 tmp;
956
957 tmp = carrier_offset_khz;
958 tmp *= 65536;
959 tmp = (2 * tmp + DS3000_SAMPLE_RATE) / (2 * DS3000_SAMPLE_RATE);
960
961 if (tmp < 0)
962 tmp += 65536;
963
964 ds3000_writereg(state, 0x5f, tmp >> 8);
965 ds3000_writereg(state, 0x5e, tmp & 0xff);
966
967 return 0;
968}
969
951static int ds3000_tune(struct dvb_frontend *fe, 970static int ds3000_tune(struct dvb_frontend *fe,
952 struct dvb_frontend_parameters *p) 971 struct dvb_frontend_parameters *p)
953{ 972{
@@ -955,7 +974,8 @@ static int ds3000_tune(struct dvb_frontend *fe,
955 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 974 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
956 975
957 int i; 976 int i;
958 u8 status, mlpf, mlpf_new, mlpf_max, mlpf_min, nlpf; 977 u8 status, mlpf, mlpf_new, mlpf_max, mlpf_min, nlpf, div4;
978 s32 offset_khz;
959 u16 value, ndiv; 979 u16 value, ndiv;
960 u32 f3db; 980 u32 f3db;
961 981
@@ -970,9 +990,12 @@ static int ds3000_tune(struct dvb_frontend *fe,
970 ds3000_tuner_writereg(state, 0x60, 0x79); 990 ds3000_tuner_writereg(state, 0x60, 0x79);
971 ds3000_tuner_writereg(state, 0x08, 0x01); 991 ds3000_tuner_writereg(state, 0x08, 0x01);
972 ds3000_tuner_writereg(state, 0x00, 0x01); 992 ds3000_tuner_writereg(state, 0x00, 0x01);
993 div4 = 0;
994
973 /* calculate and set freq divider */ 995 /* calculate and set freq divider */
974 if (p->frequency < 1146000) { 996 if (p->frequency < 1146000) {
975 ds3000_tuner_writereg(state, 0x10, 0x11); 997 ds3000_tuner_writereg(state, 0x10, 0x11);
998 div4 = 1;
976 ndiv = ((p->frequency * (6 + 8) * 4) + 999 ndiv = ((p->frequency * (6 + 8) * 4) +
977 (DS3000_XTAL_FREQ / 2)) / 1000 (DS3000_XTAL_FREQ / 2)) /
978 DS3000_XTAL_FREQ - 1024; 1001 DS3000_XTAL_FREQ - 1024;
@@ -1076,6 +1099,9 @@ static int ds3000_tune(struct dvb_frontend *fe,
1076 ds3000_tuner_writereg(state, 0x50, 0x00); 1099 ds3000_tuner_writereg(state, 0x50, 0x00);
1077 msleep(60); 1100 msleep(60);
1078 1101
1102 offset_khz = (ndiv - ndiv % 2 + 1024) * DS3000_XTAL_FREQ
1103 / (6 + 8) / (div4 + 1) / 2 - p->frequency;
1104
1079 /* ds3000 global reset */ 1105 /* ds3000 global reset */
1080 ds3000_writereg(state, 0x07, 0x80); 1106 ds3000_writereg(state, 0x07, 0x80);
1081 ds3000_writereg(state, 0x07, 0x00); 1107 ds3000_writereg(state, 0x07, 0x00);
@@ -1179,7 +1205,7 @@ static int ds3000_tune(struct dvb_frontend *fe,
1179 /* start ds3000 build-in uC */ 1205 /* start ds3000 build-in uC */
1180 ds3000_writereg(state, 0xb2, 0x00); 1206 ds3000_writereg(state, 0xb2, 0x00);
1181 1207
1182 /* TODO: calculate and set carrier offset */ 1208 ds3000_set_carrier_offset(fe, offset_khz);
1183 1209
1184 for (i = 0; i < 30 ; i++) { 1210 for (i = 0; i < 30 ; i++) {
1185 ds3000_read_status(fe, &status); 1211 ds3000_read_status(fe, &status);