aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/pt1
diff options
context:
space:
mode:
authorhiranotaka@zng.jp <hiranotaka@zng.jp>2009-11-08 03:42:28 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-12-05 15:41:40 -0500
commitc4c1e295d2721470141843e31a69c4b1c131e0f7 (patch)
tree19234f512501ae80624ea5f23b47784dfbc4ef6a /drivers/media/dvb/pt1
parent012880be6e1c8503e2901f8de90cc1e711334989 (diff)
V4L/DVB (13394): pt1: Support FE_READ_SNR
Signed-off-by: HIRANO Takahito <hiranotaka@zng.info> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/dvb/pt1')
-rw-r--r--drivers/media/dvb/pt1/va1j5jf8007s.c55
-rw-r--r--drivers/media/dvb/pt1/va1j5jf8007t.c47
2 files changed, 102 insertions, 0 deletions
diff --git a/drivers/media/dvb/pt1/va1j5jf8007s.c b/drivers/media/dvb/pt1/va1j5jf8007s.c
index 2db940f8635f..a20927e10d70 100644
--- a/drivers/media/dvb/pt1/va1j5jf8007s.c
+++ b/drivers/media/dvb/pt1/va1j5jf8007s.c
@@ -48,6 +48,60 @@ struct va1j5jf8007s_state {
48 enum va1j5jf8007s_tune_state tune_state; 48 enum va1j5jf8007s_tune_state tune_state;
49}; 49};
50 50
51static int va1j5jf8007s_read_snr(struct dvb_frontend *fe, u16 *snr)
52{
53 struct va1j5jf8007s_state *state;
54 u8 addr;
55 int i;
56 u8 write_buf[1], read_buf[1];
57 struct i2c_msg msgs[2];
58 s32 word, x1, x2, x3, x4, x5, y;
59
60 state = fe->demodulator_priv;
61 addr = state->config->demod_address;
62
63 word = 0;
64 for (i = 0; i < 2; i++) {
65 write_buf[0] = 0xbc + i;
66
67 msgs[0].addr = addr;
68 msgs[0].flags = 0;
69 msgs[0].len = sizeof(write_buf);
70 msgs[0].buf = write_buf;
71
72 msgs[1].addr = addr;
73 msgs[1].flags = I2C_M_RD;
74 msgs[1].len = sizeof(read_buf);
75 msgs[1].buf = read_buf;
76
77 if (i2c_transfer(state->adap, msgs, 2) != 2)
78 return -EREMOTEIO;
79
80 word <<= 8;
81 word |= read_buf[0];
82 }
83
84 word -= 3000;
85 if (word < 0)
86 word = 0;
87
88 x1 = int_sqrt(word << 16) * ((15625ll << 21) / 1000000);
89 x2 = (s64)x1 * x1 >> 31;
90 x3 = (s64)x2 * x1 >> 31;
91 x4 = (s64)x2 * x2 >> 31;
92 x5 = (s64)x4 * x1 >> 31;
93
94 y = (58857ll << 23) / 1000;
95 y -= (s64)x1 * ((89565ll << 24) / 1000) >> 30;
96 y += (s64)x2 * ((88977ll << 24) / 1000) >> 28;
97 y -= (s64)x3 * ((50259ll << 25) / 1000) >> 27;
98 y += (s64)x4 * ((14341ll << 27) / 1000) >> 27;
99 y -= (s64)x5 * ((16346ll << 30) / 10000) >> 28;
100
101 *snr = y < 0 ? 0 : y >> 15;
102 return 0;
103}
104
51static int va1j5jf8007s_get_frontend_algo(struct dvb_frontend *fe) 105static int va1j5jf8007s_get_frontend_algo(struct dvb_frontend *fe)
52{ 106{
53 return DVBFE_ALGO_HW; 107 return DVBFE_ALGO_HW;
@@ -536,6 +590,7 @@ static struct dvb_frontend_ops va1j5jf8007s_ops = {
536 FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO, 590 FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO,
537 }, 591 },
538 592
593 .read_snr = va1j5jf8007s_read_snr,
539 .get_frontend_algo = va1j5jf8007s_get_frontend_algo, 594 .get_frontend_algo = va1j5jf8007s_get_frontend_algo,
540 .read_status = va1j5jf8007s_read_status, 595 .read_status = va1j5jf8007s_read_status,
541 .tune = va1j5jf8007s_tune, 596 .tune = va1j5jf8007s_tune,
diff --git a/drivers/media/dvb/pt1/va1j5jf8007t.c b/drivers/media/dvb/pt1/va1j5jf8007t.c
index 71117f4ca7e6..fe897343f4f8 100644
--- a/drivers/media/dvb/pt1/va1j5jf8007t.c
+++ b/drivers/media/dvb/pt1/va1j5jf8007t.c
@@ -46,6 +46,52 @@ struct va1j5jf8007t_state {
46 enum va1j5jf8007t_tune_state tune_state; 46 enum va1j5jf8007t_tune_state tune_state;
47}; 47};
48 48
49static int va1j5jf8007t_read_snr(struct dvb_frontend *fe, u16 *snr)
50{
51 struct va1j5jf8007t_state *state;
52 u8 addr;
53 int i;
54 u8 write_buf[1], read_buf[1];
55 struct i2c_msg msgs[2];
56 s32 word, x, y;
57
58 state = fe->demodulator_priv;
59 addr = state->config->demod_address;
60
61 word = 0;
62 for (i = 0; i < 3; i++) {
63 write_buf[0] = 0x8b + i;
64
65 msgs[0].addr = addr;
66 msgs[0].flags = 0;
67 msgs[0].len = sizeof(write_buf);
68 msgs[0].buf = write_buf;
69
70 msgs[1].addr = addr;
71 msgs[1].flags = I2C_M_RD;
72 msgs[1].len = sizeof(read_buf);
73 msgs[1].buf = read_buf;
74
75 if (i2c_transfer(state->adap, msgs, 2) != 2)
76 return -EREMOTEIO;
77
78 word <<= 8;
79 word |= read_buf[0];
80 }
81
82 if (!word)
83 return -EIO;
84
85 x = 10 * (intlog10(0x540000 * 100 / word) - (2 << 24));
86 y = (24ll << 46) / 1000000;
87 y = ((s64)y * x >> 30) - (16ll << 40) / 10000;
88 y = ((s64)y * x >> 29) + (398ll << 35) / 10000;
89 y = ((s64)y * x >> 30) + (5491ll << 29) / 10000;
90 y = ((s64)y * x >> 30) + (30965ll << 23) / 10000;
91 *snr = y >> 15;
92 return 0;
93}
94
49static int va1j5jf8007t_get_frontend_algo(struct dvb_frontend *fe) 95static int va1j5jf8007t_get_frontend_algo(struct dvb_frontend *fe)
50{ 96{
51 return DVBFE_ALGO_HW; 97 return DVBFE_ALGO_HW;
@@ -393,6 +439,7 @@ static struct dvb_frontend_ops va1j5jf8007t_ops = {
393 FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO, 439 FE_CAN_GUARD_INTERVAL_AUTO | FE_CAN_HIERARCHY_AUTO,
394 }, 440 },
395 441
442 .read_snr = va1j5jf8007t_read_snr,
396 .get_frontend_algo = va1j5jf8007t_get_frontend_algo, 443 .get_frontend_algo = va1j5jf8007t_get_frontend_algo,
397 .read_status = va1j5jf8007t_read_status, 444 .read_status = va1j5jf8007t_read_status,
398 .tune = va1j5jf8007t_tune, 445 .tune = va1j5jf8007t_tune,