2 * Support for Legend Silicon GB20600 (a.k.a DMB-TH) demodulator
3 * LGS8913, LGS8GL5, LGS8G75
4 * experimental support LGS8G42, LGS8G52
6 * Copyright (C) 2007-2009 David T.L. Wong <davidtlwong@gmail.com>
7 * Copyright (C) 2008 Sirius International (Hong Kong) Limited
8 * Timothy Lee <timothy.lee@siriushk.com> (for initial work on LGS8GL5)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <asm/div64.h>
27 #include <linux/firmware.h>
29 #include "dvb_frontend.h"
32 #include "lgs8gxx_priv.h"
34 #define dprintk(args...) \
37 printk(KERN_DEBUG "lgs8gxx: " args); \
41 static int fake_signal_str
= 1;
43 module_param(debug
, int, 0644);
44 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
46 module_param(fake_signal_str
, int, 0644);
47 MODULE_PARM_DESC(fake_signal_str
, "fake signal strength for LGS8913."
48 "Signal strength calculation is slow.(default:on).");
50 /* LGS8GXX internal helper functions */
52 static int lgs8gxx_write_reg(struct lgs8gxx_state
*priv
, u8 reg
, u8 data
)
55 u8 buf
[] = { reg
, data
};
56 struct i2c_msg msg
= { .flags
= 0, .buf
= buf
, .len
= 2 };
58 msg
.addr
= priv
->config
->demod_address
;
59 if (priv
->config
->prod
!= LGS8GXX_PROD_LGS8G75
&& reg
>= 0xC0)
63 dprintk("%s: reg=0x%02X, data=0x%02X\n", __func__
, reg
, data
);
65 ret
= i2c_transfer(priv
->i2c
, &msg
, 1);
68 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
69 __func__
, reg
, data
, ret
);
71 return (ret
!= 1) ? -1 : 0;
74 static int lgs8gxx_read_reg(struct lgs8gxx_state
*priv
, u8 reg
, u8
*p_data
)
81 struct i2c_msg msg
[] = {
82 { .flags
= 0, .buf
= b0
, .len
= 1 },
83 { .flags
= I2C_M_RD
, .buf
= b1
, .len
= 1 },
86 dev_addr
= priv
->config
->demod_address
;
87 if (priv
->config
->prod
!= LGS8GXX_PROD_LGS8G75
&& reg
>= 0xC0)
89 msg
[1].addr
= msg
[0].addr
= dev_addr
;
91 ret
= i2c_transfer(priv
->i2c
, msg
, 2);
93 dprintk("%s: error reg=0x%x, ret=%i\n", __func__
, reg
, ret
);
99 dprintk("%s: reg=0x%02X, data=0x%02X\n", __func__
, reg
, b1
[0]);
103 static int lgs8gxx_soft_reset(struct lgs8gxx_state
*priv
)
105 lgs8gxx_write_reg(priv
, 0x02, 0x00);
107 lgs8gxx_write_reg(priv
, 0x02, 0x01);
113 static int wait_reg_mask(struct lgs8gxx_state
*priv
, u8 reg
, u8 mask
,
114 u8 val
, u8 delay
, u8 tries
)
119 for (i
= 0; i
< tries
; i
++) {
120 lgs8gxx_read_reg(priv
, reg
, &t
);
122 if ((t
& mask
) == val
)
130 static int lgs8gxx_set_ad_mode(struct lgs8gxx_state
*priv
)
132 const struct lgs8gxx_config
*config
= priv
->config
;
135 if_conf
= 0x10; /* AGC output on, RF_AGC output off; */
138 ((config
->ext_adc
) ? 0x80 : 0x00) |
139 ((config
->if_neg_center
) ? 0x04 : 0x00) |
140 ((config
->if_freq
== 0) ? 0x08 : 0x00) | /* Baseband */
141 ((config
->adc_signed
) ? 0x02 : 0x00) |
142 ((config
->if_neg_edge
) ? 0x01 : 0x00);
144 if (config
->ext_adc
&&
145 (config
->prod
== LGS8GXX_PROD_LGS8G52
)) {
146 lgs8gxx_write_reg(priv
, 0xBA, 0x40);
149 lgs8gxx_write_reg(priv
, 0x07, if_conf
);
154 static int lgs8gxx_set_if_freq(struct lgs8gxx_state
*priv
, u32 freq
/*in kHz*/)
160 if_clk
= priv
->config
->if_clk_freq
;
167 v32
= val
& 0xFFFFFFFF;
168 dprintk("Set IF Freq to %dkHz\n", freq
);
171 dprintk("Set IF Freq to baseband\n");
173 dprintk("AFC_INIT_FREQ = 0x%08X\n", v32
);
175 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
176 lgs8gxx_write_reg(priv
, 0x08, 0xFF & (v32
));
177 lgs8gxx_write_reg(priv
, 0x09, 0xFF & (v32
>> 8));
178 lgs8gxx_write_reg(priv
, 0x0A, 0xFF & (v32
>> 16));
179 lgs8gxx_write_reg(priv
, 0x0B, 0xFF & (v32
>> 24));
181 lgs8gxx_write_reg(priv
, 0x09, 0xFF & (v32
));
182 lgs8gxx_write_reg(priv
, 0x0A, 0xFF & (v32
>> 8));
183 lgs8gxx_write_reg(priv
, 0x0B, 0xFF & (v32
>> 16));
184 lgs8gxx_write_reg(priv
, 0x0C, 0xFF & (v32
>> 24));
190 static int lgs8gxx_get_afc_phase(struct lgs8gxx_state
*priv
)
197 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
)
202 for (i
= 0; i
< 4; i
++) {
203 lgs8gxx_read_reg(priv
, reg_addr
, &t
);
210 val
*= priv
->config
->if_clk_freq
;
212 dprintk("AFC = %u kHz\n", (u32
)val
);
216 static int lgs8gxx_set_mode_auto(struct lgs8gxx_state
*priv
)
219 u8 prod
= priv
->config
->prod
;
221 if (prod
== LGS8GXX_PROD_LGS8913
)
222 lgs8gxx_write_reg(priv
, 0xC6, 0x01);
224 if (prod
== LGS8GXX_PROD_LGS8G75
) {
225 lgs8gxx_read_reg(priv
, 0x0C, &t
);
227 lgs8gxx_write_reg(priv
, 0x0C, t
| 0x80);
228 lgs8gxx_write_reg(priv
, 0x39, 0x00);
229 lgs8gxx_write_reg(priv
, 0x3D, 0x04);
230 } else if (prod
== LGS8GXX_PROD_LGS8913
||
231 prod
== LGS8GXX_PROD_LGS8GL5
||
232 prod
== LGS8GXX_PROD_LGS8G42
||
233 prod
== LGS8GXX_PROD_LGS8G52
||
234 prod
== LGS8GXX_PROD_LGS8G54
) {
235 lgs8gxx_read_reg(priv
, 0x7E, &t
);
236 lgs8gxx_write_reg(priv
, 0x7E, t
| 0x01);
238 /* clear FEC self reset */
239 lgs8gxx_read_reg(priv
, 0xC5, &t
);
240 lgs8gxx_write_reg(priv
, 0xC5, t
& 0xE0);
243 if (prod
== LGS8GXX_PROD_LGS8913
) {
244 /* FEC auto detect */
245 lgs8gxx_write_reg(priv
, 0xC1, 0x03);
247 lgs8gxx_read_reg(priv
, 0x7C, &t
);
248 t
= (t
& 0x8C) | 0x03;
249 lgs8gxx_write_reg(priv
, 0x7C, t
);
252 lgs8gxx_read_reg(priv
, 0xC3, &t
);
253 t
= (t
& 0xEF) | 0x10;
254 lgs8gxx_write_reg(priv
, 0xC3, t
);
257 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G52
)
258 lgs8gxx_write_reg(priv
, 0xD9, 0x40);
263 static int lgs8gxx_set_mode_manual(struct lgs8gxx_state
*priv
)
268 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
270 lgs8gxx_read_reg(priv
, 0x0C, &t
);
272 lgs8gxx_write_reg(priv
, 0x0C, t
);
274 lgs8gxx_read_reg(priv
, 0x0C, &t
);
275 lgs8gxx_read_reg(priv
, 0x19, &t2
);
277 if (((t
&0x03) == 0x01) && (t2
&0x01)) {
278 lgs8gxx_write_reg(priv
, 0x6E, 0x05);
279 lgs8gxx_write_reg(priv
, 0x39, 0x02);
280 lgs8gxx_write_reg(priv
, 0x39, 0x03);
281 lgs8gxx_write_reg(priv
, 0x3D, 0x05);
282 lgs8gxx_write_reg(priv
, 0x3E, 0x28);
283 lgs8gxx_write_reg(priv
, 0x53, 0x80);
285 lgs8gxx_write_reg(priv
, 0x6E, 0x3F);
286 lgs8gxx_write_reg(priv
, 0x39, 0x00);
287 lgs8gxx_write_reg(priv
, 0x3D, 0x04);
290 lgs8gxx_soft_reset(priv
);
294 /* turn off auto-detect; manual settings */
295 lgs8gxx_write_reg(priv
, 0x7E, 0);
296 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8913
)
297 lgs8gxx_write_reg(priv
, 0xC1, 0);
299 ret
= lgs8gxx_read_reg(priv
, 0xC5, &t
);
300 t
= (t
& 0xE0) | 0x06;
301 lgs8gxx_write_reg(priv
, 0xC5, t
);
303 lgs8gxx_soft_reset(priv
);
308 static int lgs8gxx_is_locked(struct lgs8gxx_state
*priv
, u8
*locked
)
313 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
)
314 ret
= lgs8gxx_read_reg(priv
, 0x13, &t
);
316 ret
= lgs8gxx_read_reg(priv
, 0x4B, &t
);
320 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
)
321 *locked
= ((t
& 0x80) == 0x80) ? 1 : 0;
323 *locked
= ((t
& 0xC0) == 0xC0) ? 1 : 0;
327 /* Wait for Code Acquisition Lock */
328 static int lgs8gxx_wait_ca_lock(struct lgs8gxx_state
*priv
, u8
*locked
)
333 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
343 ret
= wait_reg_mask(priv
, reg
, mask
, val
, 50, 40);
344 *locked
= (ret
== 0) ? 1 : 0;
349 static int lgs8gxx_is_autodetect_finished(struct lgs8gxx_state
*priv
,
355 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
365 ret
= wait_reg_mask(priv
, reg
, mask
, val
, 10, 20);
366 *finished
= (ret
== 0) ? 1 : 0;
371 static int lgs8gxx_autolock_gi(struct lgs8gxx_state
*priv
, u8 gi
, u8 cpn
,
379 dprintk("try GI 945\n");
380 else if (gi
== GI_595
)
381 dprintk("try GI 595\n");
382 else if (gi
== GI_420
)
383 dprintk("try GI 420\n");
384 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
385 lgs8gxx_read_reg(priv
, 0x0C, &t1
);
386 lgs8gxx_read_reg(priv
, 0x18, &t2
);
390 t2
|= cpn
? 0x01 : 0x00;
391 lgs8gxx_write_reg(priv
, 0x0C, t1
);
392 lgs8gxx_write_reg(priv
, 0x18, t2
);
394 lgs8gxx_write_reg(priv
, 0x04, gi
);
396 lgs8gxx_soft_reset(priv
);
397 err
= lgs8gxx_wait_ca_lock(priv
, locked
);
398 if (err
|| !(*locked
))
400 err
= lgs8gxx_is_autodetect_finished(priv
, &ad_fini
);
404 dprintk("auto detect finished\n");
411 static int lgs8gxx_auto_detect(struct lgs8gxx_state
*priv
,
412 u8
*detected_param
, u8
*gi
)
416 u8 locked
= 0, tmp_gi
;
418 dprintk("%s\n", __func__
);
420 lgs8gxx_set_mode_auto(priv
);
421 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
422 lgs8gxx_write_reg(priv
, 0x67, 0xAA);
423 lgs8gxx_write_reg(priv
, 0x6E, 0x3F);
426 lgs8gxx_write_reg(priv
, 0x03, 00);
429 for (i
= 0; i
< 2; i
++) {
430 for (j
= 0; j
< 2; j
++) {
432 err
= lgs8gxx_autolock_gi(priv
, GI_945
, j
, &locked
);
438 for (j
= 0; j
< 2; j
++) {
440 err
= lgs8gxx_autolock_gi(priv
, GI_420
, j
, &locked
);
447 err
= lgs8gxx_autolock_gi(priv
, GI_595
, 1, &locked
);
455 if ((err
== 0) && (locked
== 1)) {
458 if (priv
->config
->prod
!= LGS8GXX_PROD_LGS8G75
) {
459 lgs8gxx_read_reg(priv
, 0xA2, &t
);
462 lgs8gxx_read_reg(priv
, 0x1F, &t
);
463 *detected_param
= t
& 0x3F;
466 if (tmp_gi
== GI_945
)
467 dprintk("GI 945 locked\n");
468 else if (tmp_gi
== GI_595
)
469 dprintk("GI 595 locked\n");
470 else if (tmp_gi
== GI_420
)
471 dprintk("GI 420 locked\n");
481 static void lgs8gxx_auto_lock(struct lgs8gxx_state
*priv
)
485 u8 detected_param
= 0;
487 err
= lgs8gxx_auto_detect(priv
, &detected_param
, &gi
);
490 dprintk("lgs8gxx_auto_detect failed\n");
492 dprintk("detected param = 0x%02X\n", detected_param
);
494 /* Apply detected parameters */
495 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8913
) {
496 u8 inter_leave_len
= detected_param
& TIM_MASK
;
497 /* Fix 8913 time interleaver detection bug */
498 inter_leave_len
= (inter_leave_len
== TIM_MIDDLE
) ? 0x60 : 0x40;
499 detected_param
&= CF_MASK
| SC_MASK
| LGS_FEC_MASK
;
500 detected_param
|= inter_leave_len
;
502 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
504 lgs8gxx_read_reg(priv
, 0x19, &t
);
506 t
|= detected_param
<< 1;
507 lgs8gxx_write_reg(priv
, 0x19, t
);
509 lgs8gxx_write_reg(priv
, 0x7D, detected_param
);
510 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8913
)
511 lgs8gxx_write_reg(priv
, 0xC0, detected_param
);
513 /* lgs8gxx_soft_reset(priv); */
515 /* Enter manual mode */
516 lgs8gxx_set_mode_manual(priv
);
520 priv
->curr_gi
= 945; break;
522 priv
->curr_gi
= 595; break;
524 priv
->curr_gi
= 420; break;
526 priv
->curr_gi
= 945; break;
530 static int lgs8gxx_set_mpeg_mode(struct lgs8gxx_state
*priv
,
531 u8 serial
, u8 clk_pol
, u8 clk_gated
)
536 reg_addr
= (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) ? 0x30 : 0xC2;
537 ret
= lgs8gxx_read_reg(priv
, reg_addr
, &t
);
542 t
|= serial
? TS_SERIAL
: TS_PARALLEL
;
543 t
|= clk_pol
? TS_CLK_INVERTED
: TS_CLK_NORMAL
;
544 t
|= clk_gated
? TS_CLK_GATED
: TS_CLK_FREERUN
;
546 ret
= lgs8gxx_write_reg(priv
, reg_addr
, t
);
553 /* A/D input peak-to-peak voltage range */
554 static int lgs8g75_set_adc_vpp(struct lgs8gxx_state
*priv
,
557 u8 r26
= 0x73, r27
= 0x90;
559 if (priv
->config
->prod
!= LGS8GXX_PROD_LGS8G75
)
562 r26
|= (sel
& 0x01) << 7;
563 r27
|= (sel
& 0x02) >> 1;
564 lgs8gxx_write_reg(priv
, 0x26, r26
);
565 lgs8gxx_write_reg(priv
, 0x27, r27
);
570 /* LGS8913 demod frontend functions */
572 static int lgs8913_init(struct lgs8gxx_state
*priv
)
576 /* LGS8913 specific */
577 lgs8gxx_write_reg(priv
, 0xc1, 0x3);
579 lgs8gxx_read_reg(priv
, 0x7c, &t
);
580 lgs8gxx_write_reg(priv
, 0x7c, (t
&0x8c) | 0x3);
582 /* LGS8913 specific */
583 lgs8gxx_read_reg(priv
, 0xc3, &t
);
584 lgs8gxx_write_reg(priv
, 0xc3, t
&0x10);
590 static int lgs8g75_init_data(struct lgs8gxx_state
*priv
)
592 const struct firmware
*fw
;
596 rc
= request_firmware(&fw
, "lgs8g75.fw", &priv
->i2c
->dev
);
600 lgs8gxx_write_reg(priv
, 0xC6, 0x40);
602 lgs8gxx_write_reg(priv
, 0x3D, 0x04);
603 lgs8gxx_write_reg(priv
, 0x39, 0x00);
605 lgs8gxx_write_reg(priv
, 0x3A, 0x00);
606 lgs8gxx_write_reg(priv
, 0x38, 0x00);
607 lgs8gxx_write_reg(priv
, 0x3B, 0x00);
608 lgs8gxx_write_reg(priv
, 0x38, 0x00);
610 for (i
= 0; i
< fw
->size
; i
++) {
611 lgs8gxx_write_reg(priv
, 0x38, 0x00);
612 lgs8gxx_write_reg(priv
, 0x3A, (u8
)(i
&0xff));
613 lgs8gxx_write_reg(priv
, 0x3B, (u8
)(i
>>8));
614 lgs8gxx_write_reg(priv
, 0x3C, fw
->data
[i
]);
617 lgs8gxx_write_reg(priv
, 0x38, 0x00);
619 release_firmware(fw
);
623 static int lgs8gxx_init(struct dvb_frontend
*fe
)
625 struct lgs8gxx_state
*priv
=
626 (struct lgs8gxx_state
*)fe
->demodulator_priv
;
627 const struct lgs8gxx_config
*config
= priv
->config
;
630 dprintk("%s\n", __func__
);
632 lgs8gxx_read_reg(priv
, 0, &data
);
633 dprintk("reg 0 = 0x%02X\n", data
);
635 if (config
->prod
== LGS8GXX_PROD_LGS8G75
)
636 lgs8g75_set_adc_vpp(priv
, config
->adc_vpp
);
638 /* Setup MPEG output format */
639 err
= lgs8gxx_set_mpeg_mode(priv
, config
->serial_ts
,
641 config
->ts_clk_gated
);
645 if (config
->prod
== LGS8GXX_PROD_LGS8913
)
647 lgs8gxx_set_if_freq(priv
, priv
->config
->if_freq
);
648 lgs8gxx_set_ad_mode(priv
);
653 static void lgs8gxx_release(struct dvb_frontend
*fe
)
655 struct lgs8gxx_state
*state
= fe
->demodulator_priv
;
656 dprintk("%s\n", __func__
);
662 static int lgs8gxx_write(struct dvb_frontend
*fe
, const u8 buf
[], int len
)
664 struct lgs8gxx_state
*priv
= fe
->demodulator_priv
;
669 return lgs8gxx_write_reg(priv
, buf
[0], buf
[1]);
672 static int lgs8gxx_set_fe(struct dvb_frontend
*fe
)
675 struct lgs8gxx_state
*priv
= fe
->demodulator_priv
;
677 dprintk("%s\n", __func__
);
680 if (fe
->ops
.tuner_ops
.set_params
) {
681 fe
->ops
.tuner_ops
.set_params(fe
);
682 if (fe
->ops
.i2c_gate_ctrl
)
683 fe
->ops
.i2c_gate_ctrl(fe
, 0);
686 /* start auto lock */
687 lgs8gxx_auto_lock(priv
);
694 static int lgs8gxx_get_fe(struct dvb_frontend
*fe
)
696 struct dtv_frontend_properties
*fe_params
= &fe
->dtv_property_cache
;
697 dprintk("%s\n", __func__
);
699 /* TODO: get real readings from device */
700 /* inversion status */
701 fe_params
->inversion
= INVERSION_OFF
;
704 fe_params
->bandwidth_hz
= 8000000;
706 fe_params
->code_rate_HP
= FEC_AUTO
;
707 fe_params
->code_rate_LP
= FEC_AUTO
;
709 fe_params
->modulation
= QAM_AUTO
;
711 /* transmission mode */
712 fe_params
->transmission_mode
= TRANSMISSION_MODE_AUTO
;
715 fe_params
->guard_interval
= GUARD_INTERVAL_AUTO
;
718 fe_params
->hierarchy
= HIERARCHY_NONE
;
724 int lgs8gxx_get_tune_settings(struct dvb_frontend
*fe
,
725 struct dvb_frontend_tune_settings
*fesettings
)
727 /* FIXME: copy from tda1004x.c */
728 fesettings
->min_delay_ms
= 800;
729 fesettings
->step_size
= 0;
730 fesettings
->max_drift
= 0;
734 static int lgs8gxx_read_status(struct dvb_frontend
*fe
, fe_status_t
*fe_status
)
736 struct lgs8gxx_state
*priv
= fe
->demodulator_priv
;
740 dprintk("%s\n", __func__
);
743 lgs8gxx_get_afc_phase(priv
);
744 lgs8gxx_is_locked(priv
, &locked
);
745 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
747 *fe_status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
748 FE_HAS_VITERBI
| FE_HAS_SYNC
| FE_HAS_LOCK
;
752 ret
= lgs8gxx_read_reg(priv
, 0x4B, &t
);
756 dprintk("Reg 0x4B: 0x%02X\n", t
);
759 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8913
) {
760 if ((t
& 0x40) == 0x40)
761 *fe_status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
;
762 if ((t
& 0x80) == 0x80)
763 *fe_status
|= FE_HAS_VITERBI
| FE_HAS_SYNC
|
766 if ((t
& 0x80) == 0x80)
767 *fe_status
|= FE_HAS_SIGNAL
| FE_HAS_CARRIER
|
768 FE_HAS_VITERBI
| FE_HAS_SYNC
| FE_HAS_LOCK
;
772 dprintk("%s: fe_status=0x%x\n", __func__
, *fe_status
);
776 static int lgs8gxx_read_signal_agc(struct lgs8gxx_state
*priv
, u16
*signal
)
781 dprintk("%s()\n", __func__
);
782 lgs8gxx_read_reg(priv
, 0x3F, &agc_lvl
[0]);
783 lgs8gxx_read_reg(priv
, 0x3E, &agc_lvl
[1]);
789 dprintk("agc_lvl: 0x%04X\n", v
);
806 *signal
= cat
* 65535 / 5;
811 static int lgs8913_read_signal_strength(struct lgs8gxx_state
*priv
, u16
*signal
)
814 s16 max_strength
= 0;
816 u16 i
, gi
= priv
->curr_gi
;
818 dprintk("%s\n", __func__
);
820 ret
= lgs8gxx_read_reg(priv
, 0x4B, &t
);
824 if (fake_signal_str
) {
825 if ((t
& 0xC0) == 0xC0) {
826 dprintk("Fake signal strength\n");
833 dprintk("gi = %d\n", gi
);
834 for (i
= 0; i
< gi
; i
++) {
837 lgs8gxx_write_reg(priv
, 0x84, 0x03 & (i
>> 8));
838 lgs8gxx_write_reg(priv
, 0x83, i
& 0xFF);
840 lgs8gxx_read_reg(priv
, 0x94, &str
);
841 if (max_strength
< str
)
845 *signal
= max_strength
;
846 dprintk("%s: signal=0x%02X\n", __func__
, *signal
);
848 lgs8gxx_read_reg(priv
, 0x95, &t
);
849 dprintk("%s: AVG Noise=0x%02X\n", __func__
, t
);
854 static int lgs8g75_read_signal_strength(struct lgs8gxx_state
*priv
, u16
*signal
)
859 dprintk("%s\n", __func__
);
861 lgs8gxx_read_reg(priv
, 0xB1, &t
);
864 lgs8gxx_read_reg(priv
, 0xB0, &t
);
868 dprintk("%s: signal=0x%02X\n", __func__
, *signal
);
873 static int lgs8gxx_read_signal_strength(struct dvb_frontend
*fe
, u16
*signal
)
875 struct lgs8gxx_state
*priv
= fe
->demodulator_priv
;
877 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8913
)
878 return lgs8913_read_signal_strength(priv
, signal
);
879 else if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
)
880 return lgs8g75_read_signal_strength(priv
, signal
);
882 return lgs8gxx_read_signal_agc(priv
, signal
);
885 static int lgs8gxx_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
887 struct lgs8gxx_state
*priv
= fe
->demodulator_priv
;
891 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
)
892 lgs8gxx_read_reg(priv
, 0x34, &t
);
894 lgs8gxx_read_reg(priv
, 0x95, &t
);
895 dprintk("AVG Noise=0x%02X\n", t
);
898 dprintk("snr=0x%x\n", *snr
);
903 static int lgs8gxx_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
906 dprintk("%s: ucblocks=0x%x\n", __func__
, *ucblocks
);
910 static void packet_counter_start(struct lgs8gxx_state
*priv
)
914 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
915 lgs8gxx_read_reg(priv
, 0x30, &orig
);
918 lgs8gxx_write_reg(priv
, 0x30, t
);
920 lgs8gxx_write_reg(priv
, 0x30, t
);
922 lgs8gxx_write_reg(priv
, 0x30, t
);
924 lgs8gxx_write_reg(priv
, 0xC6, 0x01);
925 lgs8gxx_write_reg(priv
, 0xC6, 0x41);
926 lgs8gxx_write_reg(priv
, 0xC6, 0x01);
930 static void packet_counter_stop(struct lgs8gxx_state
*priv
)
934 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
935 lgs8gxx_read_reg(priv
, 0x30, &t
);
937 lgs8gxx_write_reg(priv
, 0x30, t
);
939 lgs8gxx_write_reg(priv
, 0xC6, 0x81);
943 static int lgs8gxx_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
945 struct lgs8gxx_state
*priv
= fe
->demodulator_priv
;
946 u8 reg_err
, reg_total
, t
;
947 u32 total_cnt
= 0, err_cnt
= 0;
950 dprintk("%s\n", __func__
);
952 packet_counter_start(priv
);
954 packet_counter_stop(priv
);
956 if (priv
->config
->prod
== LGS8GXX_PROD_LGS8G75
) {
957 reg_total
= 0x28; reg_err
= 0x2C;
959 reg_total
= 0xD0; reg_err
= 0xD4;
962 for (i
= 0; i
< 4; i
++) {
964 lgs8gxx_read_reg(priv
, reg_total
+3-i
, &t
);
967 for (i
= 0; i
< 4; i
++) {
969 lgs8gxx_read_reg(priv
, reg_err
+3-i
, &t
);
972 dprintk("error=%d total=%d\n", err_cnt
, total_cnt
);
977 *ber
= err_cnt
* 100 / total_cnt
;
979 dprintk("%s: ber=0x%x\n", __func__
, *ber
);
983 static int lgs8gxx_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
985 struct lgs8gxx_state
*priv
= fe
->demodulator_priv
;
987 if (priv
->config
->tuner_address
== 0)
990 u8 v
= 0x80 | priv
->config
->tuner_address
;
991 return lgs8gxx_write_reg(priv
, 0x01, v
);
993 return lgs8gxx_write_reg(priv
, 0x01, 0);
996 static struct dvb_frontend_ops lgs8gxx_ops
= {
997 .delsys
= { SYS_DMBTH
},
999 .name
= "Legend Silicon LGS8913/LGS8GXX DMB-TH",
1000 .frequency_min
= 474000000,
1001 .frequency_max
= 858000000,
1002 .frequency_stepsize
= 10000,
1006 FE_CAN_TRANSMISSION_MODE_AUTO
|
1007 FE_CAN_GUARD_INTERVAL_AUTO
1010 .release
= lgs8gxx_release
,
1012 .init
= lgs8gxx_init
,
1013 .write
= lgs8gxx_write
,
1014 .i2c_gate_ctrl
= lgs8gxx_i2c_gate_ctrl
,
1016 .set_frontend
= lgs8gxx_set_fe
,
1017 .get_frontend
= lgs8gxx_get_fe
,
1018 .get_tune_settings
= lgs8gxx_get_tune_settings
,
1020 .read_status
= lgs8gxx_read_status
,
1021 .read_ber
= lgs8gxx_read_ber
,
1022 .read_signal_strength
= lgs8gxx_read_signal_strength
,
1023 .read_snr
= lgs8gxx_read_snr
,
1024 .read_ucblocks
= lgs8gxx_read_ucblocks
,
1027 struct dvb_frontend
*lgs8gxx_attach(const struct lgs8gxx_config
*config
,
1028 struct i2c_adapter
*i2c
)
1030 struct lgs8gxx_state
*priv
= NULL
;
1033 dprintk("%s()\n", __func__
);
1035 if (config
== NULL
|| i2c
== NULL
)
1038 priv
= kzalloc(sizeof(struct lgs8gxx_state
), GFP_KERNEL
);
1042 priv
->config
= config
;
1045 /* check if the demod is there */
1046 if (lgs8gxx_read_reg(priv
, 0, &data
) != 0) {
1047 dprintk("%s lgs8gxx not found at i2c addr 0x%02X\n",
1048 __func__
, priv
->config
->demod_address
);
1052 lgs8gxx_read_reg(priv
, 1, &data
);
1054 memcpy(&priv
->frontend
.ops
, &lgs8gxx_ops
,
1055 sizeof(struct dvb_frontend_ops
));
1056 priv
->frontend
.demodulator_priv
= priv
;
1058 if (config
->prod
== LGS8GXX_PROD_LGS8G75
)
1059 lgs8g75_init_data(priv
);
1061 return &priv
->frontend
;
1064 dprintk("%s() error_out\n", __func__
);
1069 EXPORT_SYMBOL(lgs8gxx_attach
);
1071 MODULE_DESCRIPTION("Legend Silicon LGS8913/LGS8GXX DMB-TH demodulator driver");
1072 MODULE_AUTHOR("David T. L. Wong <davidtlwong@gmail.com>");
1073 MODULE_LICENSE("GPL");